1/*************************************************************************** 2 * LPRng - An Extended Print Spooler System 3 * 4 * Copyright 1988-1995 Patrick Powell, San Diego State University 5 * papowell@sdsu.edu 6 * See LICENSE for conditions of use. 7 * 8 *************************************************************************** 9 * MODULE: xlate.c 10 * PURPOSE: translate the FC, FS, SX, XS fields 11 * 12 * xlate ":fc#0000374:fs#0000003:xc#0:xs#0040040:" 13 * - makes best guesses about the various fields 14 **************************************************************************/ 15 16#include <stdio.h> 17#include <string.h> 18 19static char _id[] = "xlate.c,v 3.1 1996/12/28 21:40:53 papowell Exp"; 20 21struct bits{ 22char *name; 23int bitfields; 24char *comment; 25char *try; 26int mask; 27}; 28 29/* f flags - used with the TIOCGET and the struct sgttyb.sg_flags field */ 30struct bits tiocget[] = { 31{ "TANDEM",00000001, "send stopc on out q full", "tandem" }, 32{ "CBREAK",00000002, "half-cooked mode", "cbreak" }, 33{ "LCASE",00000004, "simulate lower case", "lcase" }, 34{ "ECHO",00000010, "echo input", "echo" }, 35{ "CRMOD",00000020, "map \\r to \\r\\n on output", "crmod" }, 36{ "RAW",00000040, "no i/o processing", "raw" }, 37{ "ODDP",00000100, "get/send odd parity", "oddp" }, 38{ "EVENP",00000200, "get/send even parity", "evenp" }, 39{ "ANYP",00000300, "get any parity/send none", "parity? anyp? pass8? (caution)" }, 40{ "NL0",0000000, "new line delay", "nl??",00001400 }, 41{ "NL1",00000400, "new line delay tty 37", "nl??",00001400 }, 42{ "NL2",00001000, "new line delay vt05", "nl??",00001400 }, 43{ "NL3",00001400, "new line delay", "nl??",00001400 }, 44{ "TAB0",00000000, "tab expansion delay", "tab??",00006000 }, 45{ "TAB1",00002000, "tab expansion delay tty 37", "tab??",00006000 }, 46{ "TAB2",00004000, "tab expansion delay", "tab??",00006000 }, 47{ "XTABS",00006000, "expand tabs on output", "tabs" }, 48{ "CR0",00000000, "cr??", "",00030000 }, 49{ "CR1",00010000, "tn 300", "cr??",00030000 }, 50{ "CR2",00020000, "tty 37", "cr??",00030000 }, 51{ "CR3",00030000, "concept 100", "cr??",00030000}, 52{ "FF1",00040000, "form feed delay tty 37", "ff??" }, 53{ "BS1",0010000, "backspace timing", "bs??" }, 54{ 0 } }; 55 56/* x flags - used with the TIOCLGET and the struct sgttyb.sg_flags field */ 57struct bits tiolget[] = { 58{ "CRTBS",00000001, "do backspacing for crt", "crterase" }, 59{ "PRTERA",00000002, "\\ ... / erase", "prterase" }, 60{ "CRTERA",00000004, "\"\\b\" to wipe out char", "crterase" }, 61{ "TILDE",00000010, "hazeltine tilde kludge", "don't even think about this" }, 62{ "MDMBUF",00000020, "start/stop output on carrier intr", "crtscts" }, 63{ "LITOUT",00000040, "literal output", "litout" }, 64{ "TOSTOP",00000100, "SIGSTOP on background output", "tostop" }, 65{ "FLUSHO",00000200, "flush output to terminal", "noflsh?? (caution)" }, 66{ "NOHANG",00000400, "no SIGHUP on carrier drop", "nohand" }, 67{ "CRTKIL",00002000, "kill line with \"\\b\"", "crtkill" }, 68{ "PASS8",00004000, "pass 8 bits", "pass8" }, 69{ "CTLECH",00010000, "echo control chars as ^X", "echok" }, 70{ "PENDIN",00020000, "tp->t_rawq needs reread", "don't even think about this" }, 71{ "DECCTQ",00040000, "only ^Q starts after ^S", "decctlq? -ixany? (caution)" }, 72{ "NOFLSH",00100000, "no output flush on signal", "noflsh" }, 73{ 0 } }; 74 75char *msg[] = { 76 "xlate optionstrings", 77 " Example", 78 " xlate \":fc#0000374:fs#0000003:xc#0:xs#0040040:\"", 79 0 80}; 81 82usage() 83{ 84 char **m; 85 for( m = msg; *m; ++m ){ 86 fprintf( stderr, "%s\n", *m ); 87 } 88 exit( 1 ); 89} 90 91 92main( argc, argv ) 93 int argc; 94 char *argv[]; 95{ 96 char *s, *end; 97 char *value; 98 int c, v, set; 99 struct bits *table; 100 101 if( argc != 2 ) usage(); 102 for( s = argv[1]; s && *s; s = end ){ 103 end = strchr( s, ':' ); 104 if( end ){ 105 *end++ = 0; 106 } 107 while( (c = *s) && isspace( c ) ) ++s; 108 if( c == 0 ) continue; 109 110 /* now translate option */ 111 value = strchr( s, '#' ); 112 if( value == 0 ) usage(); 113 *value++ = 0; 114 v = strtol( value, (char **)0, 0 ); 115 printf( "%s = %o\n", s, v); 116 switch( s[0] ){ 117 case 'f': table = tiocget; break; 118 case 'x': table = tiolget; break; 119 default: usage(); 120 } 121 switch( s[1] ){ 122 case 's': set = 1; break; 123 case 'c': set = 0; break; 124 default: usage(); 125 } 126 /* now we scan down the values */ 127 for(; table->name; ++table ){ 128 if( (table->bitfields & v) 129 && ( ((table->bitfields & v) ^ table->bitfields) 130 & (table->mask?table->mask:~0) ) == 0 ){ 131 printf( " %s %s (%s) try '%s%s'\n", 132 set?"set":"clear", 133 table->name, table->comment, 134 set? "":"-", table->try ); 135 } 136 } 137 } 138} 139