📄 misc.c
字号:
#ifndef lintstatic char *sccsid = "@(#)misc.c 4.5 ULTRIX 10/16/90";#endif/************************************************************************ * * * Copyright (c) 1989 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************/#include <stdio.h>#include <strings.h>#include <sys/ioctl.h>#include "lprsetup.h"#include "argstrings.h"/* * Adapted for ULTRIX-32 * from ULTRIX-11 version *//********************************************************************** * Modification History * * 04-Oct-90 - Adrian Thoms (thoms@wessex) * Fixed so that when a parameter is set it will actually appear * even when its value is the default in the template * * 13 Nov 89 Adrian Thoms (for Daren Seymour) * Bug fix * * 19-Jan-89 * * DJG#4 - Added routine GetRows which sets the global variable * "rows" to contain the number of rows on the output window * * DJG#3 - Added routines PrintHelp and sgetline for printing help * messages in a manner like "more" * * 05-Jan-89 * * DJG#2 - Modified getcmd to copy string entered as originally typed. * Previously could not find printer synonyms consisting of uppercase * characters. * * DJG#1 - Added a new functions SynonymMatch, and CommentOrEmpty. They are * used in the Modify command to find a printer name in a list of synonyms. * *********************************************************************/FILE *Popen();/******************************************************* * SynonymMatch - returns a pointer to the first * occurrance of the synonym in the list, it returns NULL * if it can not find one or if synonym is longer than list. * DJG#1 *******************************************************/char *SynonymMatch (list, synonym)char *list, *synonym;{#define SEPARATORS "|:" /* separators in synonym "list" */#define BLANK " " /* identifies end of synonym list */ char *token, *strtok(); char tmplist[BUFLEN]; strcpy (tmplist, list); /* because strtok corrupts string */ if (strlen (synonym) <= strlen (tmplist)) { /* get first token in list */ token = strtok (tmplist, SEPARATORS); while (token != NULL) { if (index (token, BLANK) == 0) { /* its a legal synonym */ if (strcmp (token, synonym) == 0) return (token); } else { /* its the last entry, which doesn't count */ return (NULL); } /* Get next token */ token = strtok (0, SEPARATORS); } } return (NULL);} /********************************************************* * CommentOrEmpty - Returns true if the line passed is a * comment or an empty line, false otherwise. The line is * from the /etc/printcap file. DJG#1 *********************************************************/intCommentOrEmpty (line)char line[];{ int i; if (line[0] == '#') { /* the line is a comment */ return (1); } else { /* its empty or something is on it */ for (i = 0; line[i] != '\0'; i++ ) { if (line[i] != ' ' && line[i] != '\t') { if (line[i] == '\n') /* the line is empty */ return (1); else /* somethings on it */ return (0); } } }}/********************************** YesNo - get a yes or no answer* Returns TRUE=(yes), FALSE=(no)**********************************/YesNo (def_ans)int def_ans;{ int ans, done; done = FALSE; ans = 0; while (NOT done) { ans = getcmd (); switch (ans) { case NOREPLY: done = TRUE; if (def_ans == 'y') ans = TRUE; else if (def_ans == 'n') ans = FALSE; break; case YES: done = TRUE; ans = TRUE; break; case NO: case QUIT: done = TRUE; ans = FALSE; break; case HELP: default: printf ("\nPlease answer yes or no [%c] ", def_ans); } } return (ans);}/******************************************************************* UseDefault* returns TRUE if NULL entered (meaning use default) or* FALSE after reading text to use in place of default******************************************************************/UseDefault (str, def, i)char *str, *def;int i; /* index into table of current symbol name */ /* which is used for more specific help messages */{ extern char symbolname[]; extern struct table tab[]; int done; /****************** * loop until done ******************/ done = FALSE; while (!done) { printf (" [%s] ? ", def); switch (getsymbol ()) { default: /* this should never match! */ case GOT_SYMBOL: strcpy (str, symbolname); return (FALSE); break; case NO: tab[i].used = NO; return (TRUE); break; case QUIT: return (QUIT); break; case HELP: realhelp(i); /* more specific help */ PrintHelp (h_default); /* a general help message */ printf ("\nEnter a value for '%s'? ", tab[i].name, def); break; case NOREPLY: if (str != def) strcpy (str, def); return (TRUE); break; } }}/********************************************** realhelp* provides specific help for a given* symbol index.*********************************************/realhelp(i)int i;{ extern struct table tab[]; switch(i) { case H_af: PrintHelp(h_af); break; case H_br: PrintHelp(h_br); break; case H_cf: PrintHelp(h_cf); break; case H_ct: PrintHelp(h_ct); break; case H_df: PrintHelp(h_df); break; case H_dn: PrintHelp(h_dn); break; case H_du: PrintHelp(h_du); break; case H_fc: PrintHelp(h_fc); break; case H_ff: PrintHelp(h_ff); break; case H_fo: PrintHelp(h_fo); break; case H_fs: PrintHelp(h_fs); break; case H_gf: PrintHelp(h_gf); break; case H_ic: PrintHelp(h_ic); break; case H_if: PrintHelp(h_if); break; case H_lf: PrintHelp(h_lf); break; case H_lo: PrintHelp(h_lo); break; case H_lp: PrintHelp(h_lp); break; case H_mc: PrintHelp(h_mc); break; case H_mx: PrintHelp(h_mx); break; case H_nf: PrintHelp(h_nf); break; case H_of: PrintHelp(h_of); break; case H_op: PrintHelp(h_op); break; case H_os: PrintHelp(h_os); break; case H_pl: PrintHelp(h_pl); break; case H_pp: PrintHelp(h_pp); break; case H_ps: PrintHelp(h_ps); break; case H_pw: PrintHelp(h_pw); break; case H_px: PrintHelp(h_px); break; case H_py: PrintHelp(h_py); break; case H_rf: PrintHelp(h_rf); break; case H_rm: PrintHelp(h_rm); break; case H_rp: PrintHelp(h_rp); break; case H_rs: PrintHelp(h_rs); break; case H_rw: PrintHelp(h_rw); break; case H_sb: PrintHelp(h_sb); break; case H_sc: PrintHelp(h_sc); break; case H_sd: PrintHelp(h_sd); break; case H_sf: PrintHelp(h_sf); break; case H_sh: PrintHelp(h_sh); break; case H_st: PrintHelp(h_st); break; case H_tf: PrintHelp(h_tf); break; case H_tr: PrintHelp(h_tr); break; case H_ts: PrintHelp(h_ts); break; case H_uv: PrintHelp(h_uv); break; case H_vf: PrintHelp(h_vf); break; case H_xc: PrintHelp(h_xc); break; case H_xf: PrintHelp(h_xf); break; case H_xs: PrintHelp(h_xs); break; case H_Da: PrintHelp(h_Da); break; case H_Dl: PrintHelp(h_Dl); break; case H_It: PrintHelp(h_It); break; case H_Lf: PrintHelp(h_Lf); break; case H_Lu: PrintHelp(h_Lu); break; case H_Ml: PrintHelp(h_Ml); break; case H_Nu: PrintHelp(h_Nu); break; case H_Or: PrintHelp(h_Or); break; case H_Ot: PrintHelp(h_Ot); break; case H_Ps: PrintHelp(h_Ps); break; case H_Sd: PrintHelp(h_Sd); break; case H_Si: PrintHelp(h_Si); break; case H_Ss: PrintHelp(h_Ss); break; case H_Ul: PrintHelp(h_Ul); break; case H_Xf: PrintHelp(h_Xf); break; default: printf("Sorry, no specific help is available for symbol '%s'\n", tab[i].name); break; }}/********************************************** MapLowerCase* maps the given string into lower-case.**********************************************/MapLowerCase (b)char *b;{ while (*b) { if (isascii (*b) && isupper (*b)) *b = tolower (*b); b++; }}HasBadChars (b)char *b;{ while (*b) { if ((NOT isalpha (*b)) && (NOT isdigit (*b)) && (*b != '_')) return (TRUE); b++; } return (FALSE);}/************************************************* Print the symbol table* print whole table, or just the 'used' symbols *************************************************/Print (flag)int flag;{ extern struct table tab[]; extern char pnum[]; extern char ptype[]; int i, j; printf ("\n\tPrinter #%s ",pnum); printf("\n\t----------"); if (strlen(pnum) > 1) printf("-"); /* add one for printers numbered 10...99 */ printf ("\nSymbol "); if (flag == ALL) printf ("used "); printf (" type value\n"); printf ("------ "); if (flag == ALL) printf ("---- "); /* under 'used' */ printf (" ---- -----\n"); /************************************************* * for each symbol, print name, type, used, value **************************************************/ for (i=0; tab[i].name != 0; i++) { /* don't print it, if not being used now */ if ((flag == USED) && (tab[i].used == NO)) continue; printf (" %s ", tab[i].name); if (flag == ALL) printf ("%s", tab[i].used == YES ? "YES " : " NO "); switch (tab[i].stype) { case BOOL: printf (" BOOL "); break; case INT: printf (" INT "); break; case STR: printf (" STR "); break; default: printf (" ??? ??????\n"); continue; /* get next symbol */ } /*** if ((flag == ALL) && (tab[i].used == NO)) { printf("\n"); continue; } ***/ if ((tab[i].nvalue != 0) && (tab[i].nvalue != '\0')) { printf (" %s", tab[i].nvalue); } else if ((tab[i].svalue != 0) && (tab[i].svalue != '\0')) { printf (" %s", tab[i].svalue); } printf("\n"); /* end the line */ }}/********************************************************************* Verified* print the current printcap data, ask if it is OK, and return* TRUE if it is OK, otherwise false. *********************************************************************/Verified (){ extern char pnum[]; int yn;/* * Clear all waiting input and output chars. * Actually we just want to clear any waiting input chars so * we have a chance to see the values before confirming them. * We have to sleep a second to let waiting output chars print. */ sleep (1); ioctl (0, TIOCFLUSH, 0); Print (USED); /* print values being used in current configuration */ printf ("\nAre these the final values for printer %s ? [y] ", pnum); fflush (stdout); yn = 'y'; if (YesNo (yn) == TRUE) { printf("\n"); return (TRUE); } else { printf("\n"); return (FALSE); }}/********************************************* DoSymbol - adds/modifies symbols.********************************************/DoSymbol (){ extern struct table tab[]; /* default printer table */ extern char symbolname[]; /* getcmd result */ extern char oldfilter[]; /* print filter before modify */ extern char ptype[]; /* for checking on 'af' use */ extern char isnotused[]; /* "...feature is not used in LP11... */ char newval[LEN]; /* new value entered */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -