home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / SCCS / S7.C < prev    next >
Encoding:
Text File  |  1995-07-04  |  1.3 KB  |  72 lines

  1. h28811
  2. s 00059/00000/00000
  3. d D 1.1 95/07/04 22:47:26 tim 1 0
  4. c 
  5. e
  6. u
  7. U
  8. f e 0
  9. t
  10. T
  11. I 1
  12. /* this program reads from std in and truncates lines to the first space
  13.    after the line limit -10. If the line goes beyond the line limit it is
  14.    immediatly truncated to the limit and output continues on the next line
  15.    NOTE files are assumed to have the last line ending in a newline */
  16.  
  17. #include <stdio.h>
  18. int linelen = 100 ;
  19. int lookspace ;
  20. main(argc, argv)
  21. int argc ;
  22. char * argv[] ;
  23. {
  24.     int ch ;
  25.     int i ;
  26.     if (argc == 2)
  27.         linelen = atoi(argv[1]) ;
  28.     /* minor sanity check incase the argument was bad */
  29.     if (linelen == 0)
  30.     {
  31.         linelen = 100 ;
  32.     }
  33.     /* where should we start looking for spaces */
  34.     if (linelen > 50)
  35.         lookspace = linelen - 10 ;
  36.     else 
  37.         lookspace = linelen -5 ;
  38.     if(lookspace <5)
  39.         lookspace == linelen ;
  40.  
  41.     i = 0 ;
  42.     while ((ch = getchar()) != EOF)
  43.     {
  44.         /* we have a newline */
  45.         if (ch == '\n')
  46.         {
  47.             putchar(ch) ;    
  48.             i = 0 ;
  49.         }
  50.         /* we have reached the limit, force a newline */
  51.         else if (i == linelen)
  52.         {
  53.             putchar('\n') ;
  54.             i = 0 ;
  55.             putchar(ch) ;
  56.         }
  57.         else if ((i > lookspace) && (ch == ' '))
  58.         {
  59.             putchar('\n') ;
  60.             i = 0 ;
  61.             /* we dont put the space here */
  62.         }
  63.         else
  64.         {
  65.             /* the line is OK and we dont have a newline */
  66.             i ++ ;
  67.             putchar(ch) ;
  68.         }
  69.     }
  70. }
  71. E 1
  72.