| @@ -1,19 +1,19 @@ | | | @@ -1,19 +1,19 @@ |
1 | $NetBSD: patch-ae,v 1.5 2015/07/09 11:44:09 jperkin Exp $ | | 1 | $NetBSD: patch-ae,v 1.6 2023/09/14 00:48:31 charlotte Exp $ |
2 | | | 2 | |
3 | Use nbcompat. | | 3 | Use nbcompat, and fix mangled datetime formatting. |
4 | | | 4 | |
5 | --- print.c.orig 1996-12-21 23:40:58.000000000 +0000 | | 5 | --- print.c.orig 1996-12-21 15:40:58.000000000 -0800 |
6 | +++ print.c | | 6 | +++ print.c 2023-09-13 17:30:15.209912546 -0700 |
7 | @@ -43,9 +43,15 @@ static char const sccsid[] = "@(#)print. | | 7 | @@ -43,9 +43,15 @@ static char const sccsid[] = "@(#)print. |
8 | #include <sys/param.h> | | 8 | #include <sys/param.h> |
9 | #include <sys/stat.h> | | 9 | #include <sys/stat.h> |
10 | | | 10 | |
11 | +#include <ctype.h> | | 11 | +#include <ctype.h> |
12 | #include <err.h> | | 12 | #include <err.h> |
13 | #include <errno.h> | | 13 | #include <errno.h> |
14 | +#if defined(HAVE_NBCOMPAT_H) | | 14 | +#if defined(HAVE_NBCOMPAT_H) |
15 | +#include <nbcompat.h> | | 15 | +#include <nbcompat.h> |
16 | +#include <nbcompat/fts.h> | | 16 | +#include <nbcompat/fts.h> |
17 | +#else | | 17 | +#else |
18 | #include <fts.h> | | 18 | #include <fts.h> |
19 | +#endif | | 19 | +#endif |
| @@ -57,100 +57,101 @@ Use nbcompat. | | | @@ -57,100 +57,101 @@ Use nbcompat. |
57 | + dp->s_block, (long long)howmany(sp->st_blocks, blocksize)); | | 57 | + dp->s_block, (long long)howmany(sp->st_blocks, blocksize)); |
58 | (void)strmode(sp->st_mode, buf); | | 58 | (void)strmode(sp->st_mode, buf); |
59 | np = p->fts_pointer; | | 59 | np = p->fts_pointer; |
60 | (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, | | 60 | (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, |
61 | sp->st_nlink, dp->s_user, np->user, dp->s_group, | | 61 | sp->st_nlink, dp->s_user, np->user, dp->s_group, |
62 | np->group); | | 62 | np->group); |
63 | +#ifndef __sun | | 63 | +#ifndef __sun |
64 | if (f_flags) | | 64 | if (f_flags) |
65 | (void)printf("%-*s ", dp->s_flags, np->flags); | | 65 | (void)printf("%-*s ", dp->s_flags, np->flags); |
66 | +#endif | | 66 | +#endif |
67 | if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) | | 67 | if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) |
68 | if (minor(sp->st_rdev) > 255) | | 68 | if (minor(sp->st_rdev) > 255) |
69 | (void)printf("%3d, 0x%08x ", | | 69 | (void)printf("%3d, 0x%08x ", |
70 | @@ -114,20 +142,24 @@ printlong(dp) | | 70 | @@ -114,19 +142,23 @@ printlong(dp) |
71 | (void)printf("%3d, %3d ", | | 71 | (void)printf("%3d, %3d ", |
72 | major(sp->st_rdev), minor(sp->st_rdev)); | | 72 | major(sp->st_rdev), minor(sp->st_rdev)); |
73 | else if (dp->bcfile) | | 73 | else if (dp->bcfile) |
74 | - (void)printf("%*s%*qd ", | | 74 | - (void)printf("%*s%*qd ", |
75 | - 8 - dp->s_size, "", dp->s_size, sp->st_size); | | 75 | - 8 - dp->s_size, "", dp->s_size, sp->st_size); |
76 | + (void)printf("%*s%*lld ", | | 76 | + (void)printf("%*s%*lld ", |
77 | + 8 - dp->s_size, "", dp->s_size, (long long)sp->st_size); | | 77 | + 8 - dp->s_size, "", dp->s_size, (long long)sp->st_size); |
78 | else | | 78 | else |
79 | - (void)printf("%*qd ", dp->s_size, sp->st_size); | | 79 | - (void)printf("%*qd ", dp->s_size, sp->st_size); |
80 | + (void)printf("%*lld ", dp->s_size, (long long)sp->st_size); | | 80 | + (void)printf("%*lld ", dp->s_size, (long long)sp->st_size); |
81 | if (f_accesstime) | | 81 | if (f_accesstime) |
82 | printtime(sp->st_atime); | | 82 | printtime(sp->st_atime); |
83 | else if (f_statustime) | | 83 | else if (f_statustime) |
84 | printtime(sp->st_ctime); | | 84 | printtime(sp->st_ctime); |
85 | else | | 85 | else |
86 | printtime(sp->st_mtime); | | 86 | printtime(sp->st_mtime); |
87 | + if (f_color) | | 87 | + if (f_color) |
88 | + (void)colortype(sp->st_mode); | | 88 | + (void)colortype(sp->st_mode); |
89 | (void)printf("%s", p->fts_name); | | 89 | (void)printf("%s", p->fts_name); |
90 | if (f_type) | | 90 | if (f_type) |
91 | (void)printtype(sp->st_mode); | | 91 | (void)printtype(sp->st_mode); |
92 | - if (S_ISLNK(sp->st_mode)) | | | |
93 | + if (f_color) | | 92 | + if (f_color) |
94 | + (void)printf("\033[m"); | | 93 | + (void)printf("\033[m"); |
95 | + if (S_ISLNK(sp->st_mode)) | | 94 | if (S_ISLNK(sp->st_mode)) |
96 | printlink(p); | | 95 | printlink(p); |
97 | (void)putchar('\n'); | | 96 | (void)putchar('\n'); |
98 | } | | 97 | @@ -190,7 +222,19 @@ printcol(dp) |
99 | @@ -190,10 +222,22 @@ printcol(dp) | | | |
100 | dp->s_block); | | 98 | dp->s_block); |
101 | if ((base += numrows) >= num) | | 99 | if ((base += numrows) >= num) |
102 | break; | | 100 | break; |
103 | - while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol){ | | 101 | - while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol){ |
104 | - (void)putchar('\t'); | | | |
105 | - chcnt = cnt; | | | |
106 | - } | | | |
107 | + | | 102 | + |
108 | + /* | | 103 | + /* |
109 | + * some terminals get confused if we mix tabs | | 104 | + * some terminals get confused if we mix tabs |
110 | + * with color sequences | | 105 | + * with color sequences |
111 | + */ | | 106 | + */ |
112 | + if (f_color) | | 107 | + if (f_color) |
113 | + while ((cnt = (chcnt + 1)) <= endcol) { | | 108 | + while ((cnt = (chcnt + 1)) <= endcol) { |
114 | + (void)putchar(' '); | | 109 | + (void)putchar(' '); |
115 | + chcnt = cnt; | | 110 | + chcnt = cnt; |
116 | + } | | 111 | + } |
117 | + else | | 112 | + else |
118 | + while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) | | 113 | + while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) |
119 | + <= endcol) { | | 114 | + <= endcol) { |
120 | + (void)putchar('\t'); | | 115 | (void)putchar('\t'); |
121 | + chcnt = cnt; | | 116 | chcnt = cnt; |
122 | + } | | 117 | } |
123 | endcol += colwidth; | | | |
124 | } | | | |
125 | (void)putchar('\n'); | | | |
126 | @@ -217,11 +261,15 @@ printaname(p, inodefield, sizefield) | | 118 | @@ -217,11 +261,15 @@ printaname(p, inodefield, sizefield) |
127 | if (f_inode) | | 119 | if (f_inode) |
128 | chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino); | | 120 | chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino); |
129 | if (f_size) | | 121 | if (f_size) |
130 | - chcnt += printf("%*qd ", | | 122 | - chcnt += printf("%*qd ", |
131 | - (int)sizefield, howmany(sp->st_blocks, blocksize)); | | 123 | - (int)sizefield, howmany(sp->st_blocks, blocksize)); |
132 | + chcnt += printf("%*lld ", | | 124 | + chcnt += printf("%*lld ", |
133 | + (int)sizefield, (long long)howmany(sp->st_blocks, blocksize)); | | 125 | + (int)sizefield, (long long)howmany(sp->st_blocks, blocksize)); |
134 | + if (f_color) | | 126 | + if (f_color) |
135 | + (void)colortype(sp->st_mode); | | 127 | + (void)colortype(sp->st_mode); |
136 | chcnt += printf("%s", p->fts_name); | | 128 | chcnt += printf("%s", p->fts_name); |
137 | if (f_type) | | 129 | if (f_type) |
138 | chcnt += printtype(sp->st_mode); | | 130 | chcnt += printtype(sp->st_mode); |
139 | + if (f_color) | | 131 | + if (f_color) |
140 | + printf("\033[m"); | | 132 | + printf("\033[m"); |
141 | return (chcnt); | | 133 | return (chcnt); |
142 | } | | 134 | } |
143 | | | 135 | |
| | | 136 | @@ -232,7 +280,7 @@ printtime(ftime) |
| | | 137 | int i; |
| | | 138 | char longstring[80]; |
| | | 139 | |
| | | 140 | - strftime(longstring, sizeof(longstring), "%c", localtime(&ftime)); |
| | | 141 | + snprintf(longstring, sizeof(longstring), "%s", ctime(&ftime)); |
| | | 142 | for (i = 4; i < 11; ++i) |
| | | 143 | (void)putchar(longstring[i]); |
| | | 144 | |
144 | @@ -281,6 +329,96 @@ printtype(mode) | | 145 | @@ -281,6 +329,96 @@ printtype(mode) |
145 | return (0); | | 146 | return (0); |
146 | } | | 147 | } |
147 | | | 148 | |
148 | +void | | 149 | +void |
149 | +printcolor(c) | | 150 | +printcolor(c) |
150 | + Colors c; | | 151 | + Colors c; |
151 | +{ | | 152 | +{ |
152 | + printf("\033["); | | 153 | + printf("\033["); |
153 | + if (colors[c][0] != -1) { | | 154 | + if (colors[c][0] != -1) { |
154 | + printf("3%d", colors[c][0]); | | 155 | + printf("3%d", colors[c][0]); |
155 | + if (colors[c][1] != -1) | | 156 | + if (colors[c][1] != -1) |
156 | + printf(";"); | | 157 | + printf(";"); |