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

Diff for /src/usr.bin/mg/echo.c between version 1.23 and 1.24

version 1.23, 2002/07/03 03:47:59 version 1.24, 2002/07/03 17:25:38
Line 421 
Line 421 
         if (bclear(bp) == FALSE)          if (bclear(bp) == FALSE)
                 return FALSE;                  return FALSE;
   
         {       /* this {} present for historical reasons */          /*
            * first get the list of objects.  This list may contain only
            * the ones that complete what has been typed, or may be the
            * whole list of all objects of this type.  They are filtered
            * later in any case.  Set wholelist if the list has been
            * cons'ed up just for us, so we can free it later.  We have
            * to copy the buffer list for this function even though we
            * didn't for complt.  The sorting code does destructive
            * changes to the list, which we don't want to happen to the
            * main buffer list!
            */
           if ((flags & EFBUF) != 0)
                   wholelist = lh = copy_list(&(bheadp->b_list));
           else if ((flags & EFFUNC) != 0) {
                   buf[cpos] = '\0';
                   wholelist = lh = complete_function_list(buf, c);
           } else if ((flags & EFFILE) != 0) {
                   buf[cpos] = '\0';
                   wholelist = lh = make_file_list(buf);
                 /*                  /*
                  * first get the list of objects.  This list may contain only                   * We don't want to display stuff up to the / for file
                  * the ones that complete what has been typed, or may be the                   * names preflen is the list of a prefix of what the
                  * whole list of all objects of this type.  They are filtered                   * user typed that should not be displayed.
                  * later in any case.  Set wholelist if the list has been  
                  * cons'ed up just for us, so we can free it later.  We have  
                  * to copy the buffer list for this function even though we  
                  * didn't for complt.  The sorting code does destructive  
                  * changes to the list, which we don't want to happen to the  
                  * main buffer list!  
                  */                   */
                 if ((flags & EFBUF) != 0)                  cp = strrchr(buf, '/');
                         wholelist = lh = copy_list(&(bheadp->b_list));                  if (cp)
                 else if ((flags & EFFUNC) != 0) {                          preflen = cp - buf + 1;
                         buf[cpos] = '\0';          } else
                         wholelist = lh = complete_function_list(buf, c);                  panic("broken complt call: flags");
                 } else if ((flags & EFFILE) != 0) {  
                         buf[cpos] = '\0';  
                         wholelist = lh = make_file_list(buf);  
                         /*  
                          * We don't want to display stuff up to the / for file  
                          * names preflen is the list of a prefix of what the  
                          * user typed that should not be displayed.  
                          */  
                         cp = strrchr(buf, '/');  
                         if (cp)  
                                 preflen = cp - buf + 1;  
                 } else  
                         panic("broken complt call: flags");  
   
   
                 /*          /*
                  * Sort the list, since users expect to see it in alphabetic           * Sort the list, since users expect to see it in alphabetic
                  * order.           * order.
                  */           */
                 lh2 = lh;          lh2 = lh;
                 while (lh2 != NULL) {          while (lh2 != NULL) {
                         lh3 = lh2->l_next;                  lh3 = lh2->l_next;
                         while (lh3 != NULL) {                  while (lh3 != NULL) {
                                 if (strcmp(lh2->l_name, lh3->l_name) > 0) {                          if (strcmp(lh2->l_name, lh3->l_name) > 0) {
                                         cp = lh2->l_name;                                  cp = lh2->l_name;
                                         lh2->l_name = lh3->l_name;                                  lh2->l_name = lh3->l_name;
                                         lh3->l_name = cp;                                  lh3->l_name = cp;
                                 }  
                                 lh3 = lh3->l_next;  
                         }                          }
                         lh2 = lh2->l_next;                          lh3 = lh3->l_next;
                 }                  }
                   lh2 = lh2->l_next;
           }
   
                 /*          /*
                  * First find max width of object to be displayed, so we can           * First find max width of object to be displayed, so we can
                  * put several on a line.           * put several on a line.
                  */           */
                 maxwidth = 0;          maxwidth = 0;
                 lh2 = lh;          lh2 = lh;
                 while (lh2 != NULL) {          while (lh2 != NULL) {
                         for (i = 0; i < cpos; ++i) {                  for (i = 0; i < cpos; ++i) {
                                 if (buf[i] != lh2->l_name[i])                          if (buf[i] != lh2->l_name[i])
                                         break;                                  break;
                         }  
                         if (i == cpos) {  
                                 width = strlen(lh2->l_name);  
                                 if (width > maxwidth)  
                                         maxwidth = width;  
                         }  
                         lh2 = lh2->l_next;  
                 }                  }
                 maxwidth += 1 - preflen;                  if (i == cpos) {
                           width = strlen(lh2->l_name);
                           if (width > maxwidth)
                                   maxwidth = width;
                   }
                   lh2 = lh2->l_next;
           }
           maxwidth += 1 - preflen;
   
                 /*          /*
                  * Now do the display.  objects are written into linebuf until           * Now do the display.  objects are written into linebuf until
                  * it fills, and then put into the help buffer.           * it fills, and then put into the help buffer.
                  */           */
                 if ((linebuf = malloc((nrow + 1) * sizeof(char))) == NULL)          if ((linebuf = malloc((nrow + 1) * sizeof(char))) == NULL)
                         return FALSE;                  return FALSE;
                 width = 0;          width = 0;
   
                 /*          /*
                  * We're going to strlcat() into the buffer, so it has to be           * We're going to strlcat() into the buffer, so it has to be
                  * NUL terminated           * NUL terminated
                  */           */
                 linebuf[0] = '\0';          linebuf[0] = '\0';
                 for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) {          for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) {
                         for (i = 0; i < cpos; ++i) {                  for (i = 0; i < cpos; ++i) {
                                 if (buf[i] != lh2->l_name[i])                          if (buf[i] != lh2->l_name[i])
                                         break;                                  break;
                   }
                   /* if we have a match */
                   if (i == cpos) {
                           /* if it wraps */
                           if ((width + maxwidth) > ncol) {
                                   addline(bp, linebuf);
                                   linebuf[0] = '\0';
                                   width = 0;
                         }                          }
                         /* if we have a match */                          strlcat(linebuf, lh2->l_name + preflen, nrow+1);
                         if (i == cpos) {                          i = strlen(lh2->l_name + preflen);
                                 /* if it wraps */                          /* make all the objects nicely line up */
                                 if ((width + maxwidth) > ncol) {                          memset(linebuf + strlen(linebuf), ' ',
                                         addline(bp, linebuf);                              maxwidth - i);
                                         linebuf[0] = '\0';                          width += maxwidth;
                                         width = 0;                          linebuf[width] = '\0';
                                 }  
                                 strlcat(linebuf, lh2->l_name + preflen, nrow+1);                                i = strlen(lh2->l_name + preflen);  
                                 /* make all the objects nicely line up */  
                                 memset(linebuf + strlen(linebuf), ' ',  
                                         maxwidth - i);  
                                 width += maxwidth;  
                                 linebuf[width] = '\0';  
                         }  
                 }                  }
                 if (width > 0) {  
                         addline(bp, linebuf);  
                 }  
                 free(linebuf);  
         }          }
           if (width > 0)
                   addline(bp, linebuf);
           free(linebuf);
   
         /*          /*
          * Note that we free lists only if they are put in wholelist lists           * Note that we free lists only if they are put in wholelist lists
          * that were built just for us should be freed.  However when we use           * that were built just for us should be freed.  However when we use

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24