Deleted Added
full compact
print.c (61271) print.c (61291)
1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Michael Fischbein.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
40#else
41static const char rcsid[] =
1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Michael Fischbein.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
40#else
41static const char rcsid[] =
42 "$FreeBSD: head/bin/ls/print.c 61271 2000-06-05 03:51:29Z joe $";
42 "$FreeBSD: head/bin/ls/print.c 61291 2000-06-05 19:39:39Z ache $";
43#endif
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/stat.h>
48
49#ifdef COLORLS
50#include <ctype.h>
43#endif
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/stat.h>
48
49#ifdef COLORLS
50#include <ctype.h>
51#include <curses.h>
51#include <termcap.h>
52#include <term.h> /* for tparm */
52#endif
53#include <err.h>
54#include <errno.h>
55#include <fts.h>
56#include <grp.h>
57#include <pwd.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
53#endif
54#include <err.h>
55#include <errno.h>
56#include <fts.h>
57#include <grp.h>
58#include <pwd.h>
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
61#ifdef COLORLS
62#include <term.h>
63#endif
64#include <time.h>
65#include <unistd.h>
66
67#include "ls.h"
68#include "extern.h"
69
70static int printaname __P((FTSENT *, u_long, u_long));
71static void printlink __P((FTSENT *));

--- 17 unchanged lines hidden (view full) ---

89 C_WSDIR, /* directory writeble to others, with sticky bit */
90 C_WDIR, /* directory writeble to others, without sticky bit */
91 C_NUMCOLORS /* just a place-holder */
92} Colors ;
93
94char *defcolors = "4x5x2x3x1x464301060203";
95
96static int colors[C_NUMCOLORS][2];
62#include <time.h>
63#include <unistd.h>
64
65#include "ls.h"
66#include "extern.h"
67
68static int printaname __P((FTSENT *, u_long, u_long));
69static void printlink __P((FTSENT *));

--- 17 unchanged lines hidden (view full) ---

87 C_WSDIR, /* directory writeble to others, with sticky bit */
88 C_WDIR, /* directory writeble to others, without sticky bit */
89 C_NUMCOLORS /* just a place-holder */
90} Colors ;
91
92char *defcolors = "4x5x2x3x1x464301060203";
93
94static int colors[C_NUMCOLORS][2];
95static int color_printed = 0;
97#endif
98
99void
100printscol(dp)
101 DISPLAY *dp;
102{
103 FTSENT *p;
104

--- 49 unchanged lines hidden (view full) ---

154 if (f_accesstime)
155 printtime(sp->st_atime);
156 else if (f_statustime)
157 printtime(sp->st_ctime);
158 else
159 printtime(sp->st_mtime);
160#ifdef COLORLS
161 if (f_color)
96#endif
97
98void
99printscol(dp)
100 DISPLAY *dp;
101{
102 FTSENT *p;
103

--- 49 unchanged lines hidden (view full) ---

153 if (f_accesstime)
154 printtime(sp->st_atime);
155 else if (f_statustime)
156 printtime(sp->st_ctime);
157 else
158 printtime(sp->st_mtime);
159#ifdef COLORLS
160 if (f_color)
162 (void)colortype(sp->st_mode);
161 color_printed = colortype(sp->st_mode);
163#endif
164 if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
165 else (void)printf("%s", p->fts_name);
166#ifdef COLORLS
162#endif
163 if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
164 else (void)printf("%s", p->fts_name);
165#ifdef COLORLS
167 if (f_color)
166 if (f_color && color_printed)
168 endcolor();
169#endif
170 if (f_type)
171 (void)printtype(sp->st_mode);
172 if (S_ISLNK(sp->st_mode))
173 printlink(p);
174 (void)putchar('\n');
175 }

--- 99 unchanged lines hidden (view full) ---

275 chcnt = 0;
276 if (f_inode)
277 chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
278 if (f_size)
279 chcnt += printf("%*qd ",
280 (int)sizefield, howmany(sp->st_blocks, blocksize));
281#ifdef COLORLS
282 if (f_color)
167 endcolor();
168#endif
169 if (f_type)
170 (void)printtype(sp->st_mode);
171 if (S_ISLNK(sp->st_mode))
172 printlink(p);
173 (void)putchar('\n');
174 }

--- 99 unchanged lines hidden (view full) ---

274 chcnt = 0;
275 if (f_inode)
276 chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
277 if (f_size)
278 chcnt += printf("%*qd ",
279 (int)sizefield, howmany(sp->st_blocks, blocksize));
280#ifdef COLORLS
281 if (f_color)
283 (void)colortype(sp->st_mode);
282 color_printed = colortype(sp->st_mode);
284#endif
285 chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
286 : printf("%s", p->fts_name);
287#ifdef COLORLS
283#endif
284 chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
285 : printf("%s", p->fts_name);
286#ifdef COLORLS
288 if (f_color)
287 if (f_color && color_printed)
289 endcolor();
290#endif
291 if (f_type)
292 chcnt += printtype(sp->st_mode);
293 return (chcnt);
294}
295
296static void

--- 50 unchanged lines hidden (view full) ---

347 if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
348 (void)putchar('*');
349 return (1);
350 }
351 return (0);
352}
353
354#ifdef COLORLS
288 endcolor();
289#endif
290 if (f_type)
291 chcnt += printtype(sp->st_mode);
292 return (chcnt);
293}
294
295static void

--- 50 unchanged lines hidden (view full) ---

346 if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
347 (void)putchar('*');
348 return (1);
349 }
350 return (0);
351}
352
353#ifdef COLORLS
354int putch(c)
355 int c;
356{
357 return putc(c, stdout);
358}
359
360
355void
356printcolor(c)
357 Colors c;
358{
359 char *ansiseq;
360
361 if (colors[c][0] != -1) {
362 ansiseq = tparm(ansi_fgcol, colors[c][0]);
363 if (ansiseq)
361void
362printcolor(c)
363 Colors c;
364{
365 char *ansiseq;
366
367 if (colors[c][0] != -1) {
368 ansiseq = tparm(ansi_fgcol, colors[c][0]);
369 if (ansiseq)
364 putp(ansiseq);
370 tputs(ansiseq, 1, putch);
365 }
366
367 if (colors[c][1] != -1) {
368 ansiseq = tparm(ansi_bgcol, colors[c][1]);
369 if (ansiseq)
371 }
372
373 if (colors[c][1] != -1) {
374 ansiseq = tparm(ansi_bgcol, colors[c][1]);
375 if (ansiseq)
370 putp(ansiseq);
376 tputs(ansiseq, 1, putch);
371 }
372}
373
374void
375endcolor()
376{
377 }
378}
379
380void
381endcolor()
382{
377 if (ansi_coloff)
378 putp(ansi_coloff);
383 tputs(ansi_coloff, 1, putch);
379}
380
381int
382colortype(mode)
383 mode_t mode;
384{
385 switch(mode & S_IFMT) {
386 case S_IFDIR:

--- 47 unchanged lines hidden (view full) ---

434 c[1] = defcolors[2*i+1];
435 }
436 else {
437 c[0] = cs[2*i];
438 c[1] = cs[2*i+1];
439 }
440 for (j = 0 ; j < 2 ; j++) {
441 if ((c[j] < '0' || c[j] > '7') &&
384}
385
386int
387colortype(mode)
388 mode_t mode;
389{
390 switch(mode & S_IFMT) {
391 case S_IFDIR:

--- 47 unchanged lines hidden (view full) ---

439 c[1] = defcolors[2*i+1];
440 }
441 else {
442 c[0] = cs[2*i];
443 c[1] = cs[2*i+1];
444 }
445 for (j = 0 ; j < 2 ; j++) {
446 if ((c[j] < '0' || c[j] > '7') &&
442 tolower(c[j]) != 'x') {
447 tolower((unsigned char)c[j]) != 'x') {
443 fprintf(stderr,
444 "error: invalid character '%c' in LSCOLORS env var\n",
445 c[j]);
446 c[j] = defcolors[2*i+j];
447 }
448 if (c[j] == 'x')
449 colors[i][j] = -1;
450 else
451 colors[i][j] = c[j]-'0';
452 }
453 }
454}
448 fprintf(stderr,
449 "error: invalid character '%c' in LSCOLORS env var\n",
450 c[j]);
451 c[j] = defcolors[2*i+j];
452 }
453 if (c[j] == 'x')
454 colors[i][j] = -1;
455 else
456 colors[i][j] = c[j]-'0';
457 }
458 }
459}
460
461/* ARGSUSED */
462void colorquit(sig)
463 int sig;
464{
465 endcolor();
466 exit(1);
467}
455#endif /*COLORLS*/
456
457static void
458printlink(p)
459 FTSENT *p;
460{
461 int lnklen;
462 char name[MAXPATHLEN + 1], path[MAXPATHLEN + 1];

--- 17 unchanged lines hidden ---
468#endif /*COLORLS*/
469
470static void
471printlink(p)
472 FTSENT *p;
473{
474 int lnklen;
475 char name[MAXPATHLEN + 1], path[MAXPATHLEN + 1];

--- 17 unchanged lines hidden ---