#-h- ll.r 1566 asc 27-apr-81 14:28:34 [002,100] #-h- defns 107 asc 27-apr-81 14:27:02 [002,100] # include ratdef define(HUGE,10000) # bigger than longest possible line define(MAXNAME,FILENAMESIZE) #-h- main 748 asc 27-apr-81 14:27:03 [002,100] # ll - prints length of shortest and longest lines DRIVER(ll) character arg(MAXLINE) integer open, getarg integer fd, i call query("usage: ll [file] ...") for (i = 1; getarg(i, arg, MAXNAME) ^= EOF; i = i + 1) { if (arg(1) == MINUS & arg(2) == EOS) fd = STDIN else fd = open(arg, READ) if (fd == ERR) call cant(arg) else { call doll(fd) if (fd != STDIN) { call putc(BLANK) call putlin(arg, STDOUT) call close(fd) } call putc(NEWLINE) } } if (i == 1) { # no args, do STDIN call doll(STDIN) call putc(NEWLINE) } DRETURN end #-h- doll 525 asc 27-apr-81 14:27:04 [002,100] # doll - determine longest and shortest lines in fd subroutine doll(fd) integer fd character getch character c integer len, minl, maxl minl = HUGE maxl = 0 len = 0 while (getch(c, fd) ^= EOF) if (c == NEWLINE) { if (len > maxl) maxl = len if (len < minl) minl = len len = 0 } else len = len + 1 if (minl == HUGE) minl = 0 call putdec(minl, 5) call putc(BLANK) call putdec(maxl, 5) return end #-h- ll.rof 618 asc 08-may-81 16:39:26 [002,100] .pl 60 .bp 1 .in 0 .he 'LL (1)'9/15/78'LL (1)' .sp 2 .in +3 .fi .ti -3 NAME .br ll - print line lengths .nf .sp .ti -3 SYNOPSIS .br ll [file] ... .fi .sp .ti -3 DESCRIPTION .br Ll prints the lengths of the shortest and longest lines in the named files. The name "-" may be used to refer to the standard input. If no files are given, ll reads the standard input. NEWLINE characters are not counted as part of the length of a line. .fi .sp .ti -3 FILES .br None .sp .ne 2 .ti -3 DIAGNOSTICS .br A message is issued if a named file could not be opened. .sp .ti -3 AUTHORS .br David Hanson and friends (U. of Arizona)