/* * Color text that matches a regexp. */ int main(int argc, char **argv) { int ch; extern int optind; while ((ch = getopt(argc, argv, "bfhi")) != -1) { switch (ch) { case 'b': ++bflag; break; case 'f': ++fflag; break; case 'i': ++iflag; break; case 'h': usage(EXIT_SUCCESS); /* NOTREACHED */ case '?': default: usage(EXIT_FAILURE); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc < 2) usage(EXIT_FAILURE); if (istty(STDOUT_FILENO) || fflag) return color(argv[0], argv[1]); else return passthru(); }
int tc_init (FILE *fp, const char *term) { static char area[1024]; char buf[1024]; char *ap = area; char *af = ""; /* AF */ /* ansi foreground */ int i; /* clear all color strings */ for ( i = 0; i < 8; i++ ) colortab[i][0] = '\0'; if ( term == NULL || *term == '\0' || strcmp (term, "none") == 0 || strcmp (term, "dumb") == 0 ) return 0; if ( strcmp (term, "html") == 0 || strcmp (term, "HTML") == 0 ) { bold_on = "<B>"; bold_off = "</B>"; italic_on = "<I>"; italic_off = "</I>"; af = ""; maxcolor = 8; snprintf (colortab[TC_BLACK], sizeof colortab[0], "<font color=black>"); snprintf (colortab[TC_BLUE], sizeof colortab[0], "<font color=blue>"); snprintf (colortab[TC_GREEN], sizeof colortab[0], "<font color=green>"); snprintf (colortab[TC_CYAN], sizeof colortab[0], "<font color=cyan>"); snprintf (colortab[TC_RED], sizeof colortab[0], "<font color=red>"); snprintf (colortab[TC_MAGENTA], sizeof colortab[0], "<font color=magenta>"); snprintf (colortab[TC_YELLOW], sizeof colortab[0], "<font color=yellow>"); snprintf (colortab[TC_WHITE], sizeof colortab[0], "<font color=white>"); html = 1; return 0; } #if 0 if ( !istty (fp) ) return 0; #endif switch ( tgetent (buf, term) ) { case -1: perror ("termcap file"); return -1; case 0: fprintf (stderr, "unknown terminal %s\n", term); return -1; } if ( !(is1 = tgetstr ("is1", &ap)) ) is1 = ""; if ( !(is2 = tgetstr ("is2", &ap)) ) is2 = ""; if ( !(r1 = tgetstr ("r1", &ap)) ) r1 = ""; if ( !(r2 = tgetstr ("r2", &ap)) ) r2 = ""; /* if bold is not present */ if ( !(bold_on = tgetstr ("md", &ap)) ) /* use standout mode */ if ( !(bold_on = tgetstr ("so", &ap)) ) bold_on = bold_off = ""; else bold_off = tgetstr ("se", &ap); else bold_off = tgetstr ("me", &ap); /* if italic not present */ if ( !(italic_on = tgetstr ("ZH", &ap)) ) /* use underline mode */ if ( !(italic_on = tgetstr ("us", &ap)) ) italic_on = italic_off = ""; else italic_off = tgetstr ("ue", &ap); else italic_off = tgetstr ("ZR", &ap); maxcolor = tgetnum ("Co"); if ( maxcolor < 0 ) /* no colors ? */ return 0; if ( maxcolor > 8 ) maxcolor = 8; if ( (af = tgetstr ("AF", &ap)) ) /* set ansi color foreground */ { for ( i = 0; i < maxcolor; i++ ) snprintf (colortab[i], sizeof colortab[0], "%s", tparm (af, i)); } else if ( (af = tgetstr ("Sf", &ap)) ) /* or set color foreground */ { snprintf (colortab[TC_BLACK], sizeof colortab[0], "%s", tparm (af, 0)); snprintf (colortab[TC_BLUE], sizeof colortab[0], "%s", tparm (af, 1)); snprintf (colortab[TC_GREEN], sizeof colortab[0], "%s", tparm (af, 2)); snprintf (colortab[TC_CYAN], sizeof colortab[0], "%s", tparm (af, 3)); snprintf (colortab[TC_RED], sizeof colortab[0], "%s", tparm (af, 4)); snprintf (colortab[TC_MAGENTA], sizeof colortab[0], "%s", tparm (af, 5)); snprintf (colortab[TC_YELLOW], sizeof colortab[0], "%s", tparm (af, 6)); snprintf (colortab[TC_WHITE], sizeof colortab[0], "%s", tparm (af, 7)); } #if 0 if ( is1 && *is1 ) tc_printattr (fp, is1); if ( is2 && *is2 ) tc_printattr (fp, is2); #endif return 0; }
//char *rdz_by() { return istty() ? "[1;33m" : ""; } char *rdz_cl() { return istty() ? "[0;0m" : ""; }
char *rdz_bl() { return istty() ? "[1;34m" : ""; }
char *rdz_gr() { return istty() ? "[1;30m" : ""; }
char *rdz_cy() { return istty() ? "[0;36m" : ""; }
char *rdz_yl() { return istty() ? "[0;33m" : ""; }
char *rdz_gn() { return istty() ? "[0;32m" : ""; }
char *rdz_rd() { return istty() ? "[0;31m" : ""; }