Deleted Added
full compact
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>
51#include <curses.h>
51#include <termcap.h>
52#include <term.h> /* for tparm */
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
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;
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);
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)
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);
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)
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
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);
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);
377 }
378}
379
380void
381endcolor()
382{
377 if (ansi_coloff)
378 putp(ansi_coloff);
383 tputs(ansi_coloff, 1, putch);
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') {
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}
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 ---