========== programs from chapter 1 ==========
# copy - copy input characters to output
   integer getc
   integer c
   while (getc(c) ~= EOF)
      call putc(c)
   stop
   end
# charcount - count characters in standard input
   character getc
   character c
   integer nc
   nc = 0
   while (getc(c) ~= EOF)
      nc = nc + 1
   call putdec(nc, 1)
   call putc(NEWLINE)
   stop
   end
# linecount - count lines in standard input
   character getc
   character c
   integer nl
   nl = 0
   while (getc(c) ~= EOF)
      if (c == NEWLINE)
         nl = nl + 1
   call putdec(nl, 1)
   call putc(NEWLINE)
   stop
   end
# wordcount - count words in standard input
   character getc
   character c
   integer inword, wc
   wc = 0
   inword = NO
   while (getc(c) ~= EOF)
      if (c == BLANK | c == NEWLINE | c == TAB)
         inword = NO
      else if (inword == NO) {
         inword = YES
         wc = wc + 1
         $@$
   call putdec(wc, 1)
   call putc(NEWLINE)
   stop
   end
# detab - convert tabs to equivalent number of blanks
   character getc
   character c
   integer tabpos
   integer col, i, tabs(MAXLINE)
   call settab(tabs)   # set initial tab stops
   col = 1
   while (getc(c) ~= EOF)
      if (c == TAB)
         repeat {
            call putc(BLANK)
            col = col + 1
            $@$ until (tabpos(col, tabs) == YES)
      else if (c == NEWLINE) {
         call putc(NEWLINE)
         col = 1
         $@$
      else {
         call putc(c)
         col = col + 1
         $@$
   stop
   end
# tabpos - return YES if col is a tab stop
   integer function tabpos(col, tabs)
   integer col, i, tabs(MAXLINE)
   if (col > MAXLINE)
      tabpos = YES
   else
      tabpos = tabs(col)
   return
   end
# settab - set initial tab stops
   subroutine settab(tabs)
   integer mod
   integer i, tabs(MAXLINE)
   for (i = 1; i <= MAXLINE; i = i + 1)
      if (mod(i, 8) == 1)
         tabs(i) = YES
      else
         tabs(i) = NO
   return
   end
#c  detab - convert tabs to equivalent number of blanks; Fortran version
   integer getc
   integer c
   integer tabpos
   integer col, i, tabs(MAXLINE)
#c
#c   set initial tab stops
   call settab(tabs)
   col = 1
10   if (getc(c) .eq. EOF)  goto 60
      if (c .ne. TAB)  goto 30
20         call putc(BLANK)
         col = col + 1
         if (tabpos(col, tabs) .ne. YES)  goto 20
         goto 50
#c      else if
30      if (c .ne. NEWLINE)  goto 40
         call putc(NEWLINE)
         col = 1
         goto 50
#c      else
40         call putc(c)
         col = col + 1
50      goto 10
60   stop
   end
#c  tabpos - return YES if col is a tab stop; Fortran version
   integer function tabpos(col, tabs)
   integer col, i, tabs(MAXLINE)
#c
   if (col .gt. MAXLINE) tabpos = YES
   if (col .le. MAXLINE) tabpos = tabs(col)
   return
   end
#c  settab - set initial tab stops; Fortran version
   subroutine settab(tabs)
   integer mod
   integer i, tabs(MAXLINE)
#c
   i = 1
10   if (i .gt. MAXLINE) goto 20
      if (mod(i, 8) .eq. 1) tabs(i) = YES
      if (mod(i, 8) .ne. 1) tabs(i) = NO
      i = i + 1
      goto 10
20   return
   end
/* copy _ copy input characters to output */
   copy: procedure options (main);
   declare getc entry (fixed binary) returns (fixed binary);
   declare putc entry (fixed binary);
   declare c fixed binary;
   do while (getc(c) ~= EOF);
      call putc(c);
      end;
   end copy;
/* detab _ convert tabs into equivalent number of blanks */
   detab: procedure options (main);
   declare getc entry (fixed binary) returns (fixed binary);
   declare putc entry (fixed binary);
   declare c fixed binary;
   declare settab entry ((*)fixed binary);
   declare tabpos entry (fixed bin, (*)fixed bin) returns (fixed bin);
   declare (col, tabs(MAXLINE)) fixed binary;
   call settab(tabs);   /* set initial tab stops */
   col = 1;
   do while (getc(c) ~= EOF);
      if c = TAB then do;
         loop:
         call putc(BLANK);
         col = col + 1;
         if tabpos(col, tabs) ~= YES then
            goto loop;
         end;
      else if c = NEWLINE then do;
         call putc(NEWLINE);
         col = 1;
         end;
      else do;
         call putc(c);
         col = col + 1;
         end;
      end;
   end detab;
/* tabpos _ return YES if col is a tab stop */
   tabpos: procedure (col, tabs) returns (fixed binary);
   declare (col, tabs(*)) fixed binary;
   if col > MAXLINE then
      return(YES);
   else
      return(tabs(col));
   end tabpos;
/* settab _ set initial tab stops */
   settab: procedure (tabs);
   declare (i, tabs(*)) fixed binary;
   do i = 1 to MAXLINE;
      if mod(i, 8) = 1 then
         tabs(i) = YES;
      else
         tabs(i) = NO;
      end;
   end settab;
