Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language SYMPL

(CDC Systems Programming Language)

Date:05/29/06
Author:Walter Spector
URL:n/a
Comments:0
Info:n/a
Score: (2.25 in 4 votes)
PRGM BOT99;
  BEGIN

  #
  ***  BOT99 - 99 BOTTLES OF BEER
  *
  *    PRINTS THE '99 BOTTLES OF BEER' SONG.
  *
  *    W. W. SPECTOR         04/02/14  (FOR THE CONTROLFREAKS)

  **   TO COMPILE AND RUN ON YOUR FAVORITE CDC CYBER (OR
  *    6000/7000) SERIES SYSTEM, USE THE FOLLOWING
  *    COMMANDS:
  *
  *    SYMPL,I=BOT99,L=0,S=SRVLIB.
  *    LGO.

  #

  XREF PROC ENDRUN;          # STOP PROGRAM #
  XREF PROC WRITEH;          # WRITE HOLLERITH STRING #
  XREF PROC WRITEO;          # WRITE ONE WORD #
  XREF PROC WRITER;          # WRITE LOGICAL RECORD #

  DEF OBUFL #64#;            # OUTPUT BUFFER LENGTH #

  ARRAY OBUF[0:OBUFL] S(1);  # OUTPUT BUFFER #
     ITEM ODATA;

  ARRAY OFET S(5);           # OUTPUT FILE ENV TABLE (FET) #
    BEGIN
    ITEM O$LFN   C(0,0,7);   # LOCAL FILE NAME #
    ITEM O$CBITS U(0,42,18); # VARIOUS BITS #
    ITEM O$FIRST I(1,0,60);  # FIRST WORD ADDRESS OF BUFFER #
    ITEM O$IN    I(2,0,60);  # 'IN' POINTER #
    ITEM O$OUT   I(3,0,60);  # 'OUT' POINTER #
    ITEM O$LIMIT I(4,0,60);  # LAST WORD OF BUFFER + 1 #
    END

  DEF NBOTS #99#;            # NO. OF BOTTLES TO START WITH #
  ITEM BOTTLES C(10);        # CURRENT BOTTLE (IN DECIMAL FORM) #
  ITEM IBOT I;               # CURRENT BOTTLE (IN INTEGER FORM) #

  #
  ***  START EXECUTION
  #

  C<0,6>O$LFN   = "OUTPUT";  # SET UP FET
  O$CBITS = 1;
  O$FIRST = LOC (OBUF);
  O$IN    = LOC (OBUF);
  O$OUT   = LOC (OBUF);
  O$LIMIT = LOC (OBUF) + OBUFL;

  CDD (NBOTS, BOTTLES);      # CONVERT FIRST BOTTLE TO DECIMAL #
  FOR IBOT=NBOTS STEP -1 UNTIL 1 DO
    BEGIN
    WRITEO (OFET, BOTTLES);
    WRITEH (OFET, " BOTTLES OF BEER ON THE WALL", 3);
    WRITEO (OFET, BOTTLES);
    WRITEH (OFET, " BOTTLES OF BEER ", 2);

    WRITEH (OFET, "           TAKE ONE DOWN, PASS IT AROUND,", 4);
    CDD (IBOT-1, BOTTLES);
    WRITEO (OFET, BOTTLES);  # CONVERT NEXT BOTTLE TO DECIMAL #
    WRITEH (OFET, " BOTTLES OF BEER ON THE WALL ", 3);
    WRITEH (OFET, " ", 1);
    END

  WRITER (OFET, TRUE);       # FLUSH BUFFER #
  ENDRUN;                    # TIME TO GO TO THE LIQUOR STORE #


  #
  ***  CDD - CONVERT AN INTEGER TO DECIMAL

  RESTRICTIONS:

    INPUT VALUE MUST BE POSITIVE AND AT MOST 10 DIGITS.
  #

  PROC CDD (INT, DEC);
    BEGIN

    DEF CDDL #10#;
    ITEM INT I;              # INTEGER TO BE CONVERTED (IN) #
    ITEM DEC C(CDDL);        # RESULTANT DECIMAL VALUE (OUT) #

    ITEM PINT I;
    ITEM TINT I;
    ITEM CPOS I;
    ITEM DIGIT I;
    ITEM ZERO C(1) = "0";
    ITEM I I;

    TINT = ABS (INT);
    CPOS = CDDL-1;
    FOR I=CDDL STEP -1 UNTIL 1 DO
      BEGIN
      PINT = TINT / 10;
      DIGIT = TINT - PINT*10;
      C<CPOS>DEC = ZERO + DIGIT;
      CPOS = CPOS - 1;
      IF PINT EQ 0 THEN GOTO CHKSGN;
      TINT = PINT;
      END

CHKSGN:
    IF INT LS 0 THEN
      BEGIN
      C<CPOS>DEC = "-";
      CPOS = CPOS - 1;
      END

    FOR I=CPOS STEP -1 UNTIL 0 DO
      C<I>DEC = " ";

    END # CDD #
    
END TERM

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: