Print this page
4193 ls --color with filename arguments does not colorize


1013                 /* assume it is an error */
1014                 num_cols = 80;
1015 
1016         /* allocate space for flist and the associated  */
1017         /* data structures (lbufs)                      */
1018         maxfils = quantn;
1019         if (((flist = malloc(maxfils * sizeof (struct lbuf *))) == NULL) ||
1020             ((nxtlbf = malloc(quantn * sizeof (struct lbuf))) == NULL)) {
1021                 perror("ls");
1022                 exit(2);
1023         }
1024         if ((amino = (argc-optind)) == 0) {
1025                                         /*
1026                                          * case when no names are given
1027                                          * in ls-command and current
1028                                          * directory is to be used
1029                                          */
1030                 argv[optind] = dotp;
1031         }
1032 



1033         for (i = 0; i < (amino ? amino : 1); i++) {
1034 
1035                 /*
1036                  * If we are recursing, we need to make sure we don't
1037                  * get into an endless loop.  To keep track of the inodes
1038                  * (actually, just the directories) visited, we
1039                  * maintain a directory ancestry list for a file
1040                  * hierarchy.  As we go deeper into the hierarchy,
1041                  * a parent directory passes its directory list
1042                  * info (device id, inode number, and a pointer to
1043                  * its parent) to each of its children.  As we
1044                  * process a child that is a directory, we save
1045                  * its own personal directory list info.  We then
1046                  * check to see if the child has already been
1047                  * processed by comparing its device id and inode
1048                  * number from its own personal directory list info
1049                  * to that of each of its ancestors.  If there is a
1050                  * match, then we know we've detected a cycle.
1051                  */
1052                 if (Rflg) {


1080                         err = 2;
1081                         optind++;
1082                         continue;
1083                 }
1084                 ep->ln.namep = (*argv[optind] ? argv[optind] : dotp);
1085                 ep->lflags |= ISARG;
1086                 optind++;
1087                 nargs++;        /* count good arguments stored in flist */
1088                 if (acl_err)
1089                         err = 2;
1090         }
1091         colwidth = fixedwidth + filewidth;
1092         if (!Uflg)
1093                 qsort(flist, (unsigned)nargs, sizeof (struct lbuf *),
1094                     (int (*)(const void *, const void *))compar);
1095         for (i = 0; i < nargs; i++) {
1096                 if (flist[i]->ltype == 'd' && dflg == 0 || fflg)
1097                         break;
1098         }
1099 
1100         if (colorflg)
1101                 ls_color_init();
1102 
1103         pem(&flist[0], &flist[i], 0);
1104         for (; i < nargs; i++) {
1105                 pdirectory(flist[i]->ln.namep, Rflg ||
1106                     (amino > 1), nargs, 0, flist[i]->ancinfo);
1107                 if (nomocore)
1108                         exit(2);
1109                 /* -R: print subdirectories found */
1110                 while (dfirst || cdfirst) {
1111                         /* Place direct subdirs on front in right order */
1112                         while (cdfirst) {
1113                                 /* reverse cdfirst onto front of dfirst */
1114                                 dtemp = cdfirst;
1115                                 cdfirst = cdfirst -> dc_next;
1116                                 dtemp -> dc_next = dfirst;
1117                                 dfirst = dtemp;
1118                         }
1119                         /* take off first dir on dfirst & print it */
1120                         dtemp = dfirst;
1121                         dfirst = dfirst->dc_next;
1122                         pdirectory(dtemp->dc_name, 1, nargs,




1013                 /* assume it is an error */
1014                 num_cols = 80;
1015 
1016         /* allocate space for flist and the associated  */
1017         /* data structures (lbufs)                      */
1018         maxfils = quantn;
1019         if (((flist = malloc(maxfils * sizeof (struct lbuf *))) == NULL) ||
1020             ((nxtlbf = malloc(quantn * sizeof (struct lbuf))) == NULL)) {
1021                 perror("ls");
1022                 exit(2);
1023         }
1024         if ((amino = (argc-optind)) == 0) {
1025                                         /*
1026                                          * case when no names are given
1027                                          * in ls-command and current
1028                                          * directory is to be used
1029                                          */
1030                 argv[optind] = dotp;
1031         }
1032 
1033         if (colorflg)
1034                 ls_color_init();
1035 
1036         for (i = 0; i < (amino ? amino : 1); i++) {
1037 
1038                 /*
1039                  * If we are recursing, we need to make sure we don't
1040                  * get into an endless loop.  To keep track of the inodes
1041                  * (actually, just the directories) visited, we
1042                  * maintain a directory ancestry list for a file
1043                  * hierarchy.  As we go deeper into the hierarchy,
1044                  * a parent directory passes its directory list
1045                  * info (device id, inode number, and a pointer to
1046                  * its parent) to each of its children.  As we
1047                  * process a child that is a directory, we save
1048                  * its own personal directory list info.  We then
1049                  * check to see if the child has already been
1050                  * processed by comparing its device id and inode
1051                  * number from its own personal directory list info
1052                  * to that of each of its ancestors.  If there is a
1053                  * match, then we know we've detected a cycle.
1054                  */
1055                 if (Rflg) {


1083                         err = 2;
1084                         optind++;
1085                         continue;
1086                 }
1087                 ep->ln.namep = (*argv[optind] ? argv[optind] : dotp);
1088                 ep->lflags |= ISARG;
1089                 optind++;
1090                 nargs++;        /* count good arguments stored in flist */
1091                 if (acl_err)
1092                         err = 2;
1093         }
1094         colwidth = fixedwidth + filewidth;
1095         if (!Uflg)
1096                 qsort(flist, (unsigned)nargs, sizeof (struct lbuf *),
1097                     (int (*)(const void *, const void *))compar);
1098         for (i = 0; i < nargs; i++) {
1099                 if (flist[i]->ltype == 'd' && dflg == 0 || fflg)
1100                         break;
1101         }
1102 



1103         pem(&flist[0], &flist[i], 0);
1104         for (; i < nargs; i++) {
1105                 pdirectory(flist[i]->ln.namep, Rflg ||
1106                     (amino > 1), nargs, 0, flist[i]->ancinfo);
1107                 if (nomocore)
1108                         exit(2);
1109                 /* -R: print subdirectories found */
1110                 while (dfirst || cdfirst) {
1111                         /* Place direct subdirs on front in right order */
1112                         while (cdfirst) {
1113                                 /* reverse cdfirst onto front of dfirst */
1114                                 dtemp = cdfirst;
1115                                 cdfirst = cdfirst -> dc_next;
1116                                 dtemp -> dc_next = dfirst;
1117                                 dfirst = dtemp;
1118                         }
1119                         /* take off first dir on dfirst & print it */
1120                         dtemp = dfirst;
1121                         dfirst = dfirst->dc_next;
1122                         pdirectory(dtemp->dc_name, 1, nargs,