home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / trim.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  53 lines

  1. ############################################################################
  2. #
  3. #    File:     trim.icn
  4. #
  5. #    Subject:  Program to trim lines in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 26, 1998
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program copies lines from standard input to standard out-
  18. #  put, truncating the lines at n characters and removing any trail-
  19. #  ing blanks and tabs. The default value for n is 80.  For example,
  20. #  
  21. #          trim 70 <grade.txt >grade.fix
  22. #  
  23. #  copies grade.txt to grade.fix, with lines longer than 70 charac-
  24. #  ters truncated to 70 characters and the trailing blanks removed
  25. #  from all lines.
  26. #  
  27. #     The -f option causes all lines to be n characters long by
  28. #  adding blanks to short lines; otherwise, short lines are left as
  29. #  is.
  30. #
  31. ############################################################################
  32. #
  33. #  Links: options
  34. #
  35. ############################################################################
  36.  
  37. link options
  38.  
  39. procedure main(args)
  40.    local n, pad, line, opts
  41.  
  42.    opts := options(args,"f")
  43.    if \opts["f"] then pad := 1 else pad := 0
  44.    n := (0 <= integer(args[1])) | 80
  45.  
  46.    while line := read() do {
  47.       line := line[1+:n]
  48.       line := trim(line, ' \t')
  49.       if pad = 1 then line := left(line,n)
  50.       write(line)
  51.       }
  52. end
  53.