[BACK]Return to fold.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / fold

Diff for /src/usr.bin/fold/fold.c between version 1.5 and 1.6

version 1.5, 2001/11/19 19:02:14 version 1.6, 2002/06/17 07:06:12
Line 110 
Line 110 
                 fold(width);                  fold(width);
         else for (; *argv; ++argv)          else for (; *argv; ++argv)
                 if (!freopen(*argv, "r", stdin)) {                  if (!freopen(*argv, "r", stdin)) {
                         err (1, "%s", *argv);                          err(1, "%s", *argv);
                         /* NOTREACHED */                          /* NOTREACHED */
                 } else                  } else
                         fold(width);                          fold(width);
Line 141 
Line 141 
         while ((ch = getchar()) != EOF) {          while ((ch = getchar()) != EOF) {
                 if (ch == '\n') {                  if (ch == '\n') {
                         if (indx != 0)                          if (indx != 0)
                                 fwrite (buf, 1, indx, stdout);                                  fwrite(buf, 1, indx, stdout);
                         putchar('\n');                          putchar('\n');
                         col = indx = 0;                          col = indx = 0;
                         continue;                          continue;
                 }                  }
   
                 col = new_column_position (col, ch);                  col = new_column_position(col, ch);
                 if (col > width) {                  if (col > width) {
                         int i, last_space;                          int i, last_space;
   
                         if (split_words) {                          if (split_words) {
                                 for (i = 0, last_space = -1; i < indx; i++)                                  for (i = 0, last_space = -1; i < indx; i++)
                                         if(buf[i] == ' ') last_space = i;                                          if(buf[i] == ' ')
                                                   last_space = i;
                         }                          }
   
                         if (split_words && last_space != -1) {                          if (split_words && last_space != -1) {
                                 last_space++;                                  last_space++;
   
                                 fwrite (buf, 1, last_space, stdout);                                  fwrite(buf, 1, last_space, stdout);
                                 memmove (buf, buf+last_space, indx-last_space);                                  memmove(buf, buf+last_space, indx-last_space);
   
                                 indx -= last_space;                                  indx -= last_space;
                                 col = 0;                                  col = 0;
                                 for (i = 0; i < indx; i++) {                                  for (i = 0; i < indx; i++) {
                                         col = new_column_position (col, buf[i]);                                          col = new_column_position(col, buf[i]);
                                 }                                  }
                         } else {                          } else {
                                 fwrite (buf, 1, indx, stdout);                                  fwrite(buf, 1, indx, stdout);
                                 col = indx = 0;                                  col = indx = 0;
                         }                          }
                         putchar('\n');                          putchar('\n');
   
                         /* calculate the column position for the next line. */                          /* calculate the column position for the next line. */
                         col = new_column_position (col, ch);                          col = new_column_position(col, ch);
                 }                  }
   
                 if (indx + 1 > buf_max) {                  if (indx + 1 > buf_max) {
                         /* Allocate buffer in LINE_MAX increments */                          /* Allocate buffer in LINE_MAX increments */
                         buf_max += 2048;                          buf_max += 2048;
                         if((buf = realloc (buf, buf_max)) == NULL) {                          if((buf = realloc(buf, buf_max)) == NULL) {
                                 err (1, NULL);                                  err(1, NULL);
                                 /* NOTREACHED */                                  /* NOTREACHED */
                         }                          }
                 }                  }
Line 189 
Line 190 
         }          }
   
         if (indx != 0)          if (indx != 0)
                 fwrite (buf, 1, indx, stdout);                  fwrite(buf, 1, indx, stdout);
 }  }
   
 /*  /*
  * calculate the column position   * calculate the column position
  */   */
 static int  static int
 new_column_position (col, ch)  new_column_position(col, ch)
         int col;          int col;
         int ch;          int ch;
 {  {

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6