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