|
|
1.1 ! root 1: /* Copyright (c) 1989, 1990 AT&T --- All Rights Reserved. */ ! 2: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. */ ! 3: /* The copyright notice does not imply actual or intended publication. */ ! 4: /* AUTHORS: */ ! 5: /* H. S. Baird - ATT-BL MH - first versions */ ! 6: ! 7: /* abort.h - three terse message, warning, and abort functions. ! 8: out(s,a,...) print message to stdout ! 9: err(s,a,...) print warning to stderr ! 10: abort(s,a,...) complain to stderr and exit abnormally. ! 11: The 's' argument is a printf string, and the 'a',... are (up to 15) arguments ! 12: matching %-fields. These routines prefix the program name and append `\n' to ! 13: the printf string, then write to: ! 14: `out': stdout ! 15: `err' & `abort': stderr ! 16: Abort also says " - abort", and exits abnormally. ! 17: This #include should be preceded by `#define CMDNAME "xxx"' so that `xxx:' ! 18: will be prefixed to msg and abort strings. */ ! 19: ! 20: #ifndef CMDNAME ! 21: #define CMDNAME "hsb" ! 22: #endif ! 23: ! 24: #define MSGMAX 120 ! 25: ! 26: #ifndef boolean ! 27: #define boolean int ! 28: #define T 1 ! 29: #define F 0 ! 30: #endif ! 31: ! 32: /* WARNING: these function-call versions do not port well: ! 33: e.g. floating-point arguments are botched on MIPS and SGI machines */ ! 34: ! 35: out(s,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) ! 36: char *s; ! 37: { static char m[MSGMAX]; ! 38: strcpy(m,CMDNAME); ! 39: strcat(m,": "); ! 40: strcat(m,s); ! 41: strcat(m,"\n"); ! 42: fprintf(stdout,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); ! 43: } ! 44: ! 45: err(s,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) ! 46: char *s; ! 47: { char m[MSGMAX]; ! 48: strcpy(m,CMDNAME); ! 49: strcat(m,": "); ! 50: strcat(m,s); ! 51: strcat(m,"\n"); ! 52: fprintf(stderr,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); ! 53: } ! 54: ! 55: abort(s,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) ! 56: char *s; ! 57: { static char m[MSGMAX]; ! 58: strcpy(m,s); ! 59: strcat(m," - abort"); ! 60: err(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); ! 61: exit(1); ! 62: } ! 63: ! 64: /* These hybrid macro/function forms ports well, but are awkward to use... */ ! 65: ! 66: char *_F(s) ! 67: char *s; ! 68: { static char m[MSGMAX]; ! 69: strcpy(m,CMDNAME); ! 70: strcat(m,": "); ! 71: strcat(m,s); ! 72: strcat(m,"\n"); ! 73: return(m); ! 74: } ! 75: ! 76: #define out0(Z) fprintf(stdout,_F(Z)) ! 77: #define out1(Z,A) fprintf(stdout,_F(Z),A) ! 78: #define out2(Z,A,B) fprintf(stdout,_F(Z),A,B) ! 79: #define out3(Z,A,B,C) fprintf(stdout,_F(Z),A,B,C) ! 80: #define out4(Z,A,B,C,D) fprintf(stdout,_F(Z),A,B,C,D) ! 81: #define out5(Z,A,B,C,D,E) fprintf(stdout,_F(Z),A,B,C,D,E) ! 82: #define out6(Z,A,B,C,D,E,F) fprintf(stdout,_F(Z),A,B,C,D,E,F) ! 83: #define out7(Z,A,B,C,D,E,F,G) fprintf(stdout,_F(Z),A,B,C,D,E,F,G) ! 84: #define out8(Z,A,B,C,D,E,F,G,H) fprintf(stdout,_F(Z),A,B,C,D,E,F,G,H) ! 85: #define out9(Z,A,B,C,D,E,F,G,H,I) fprintf(stdout,_F(Z),A,B,C,D,E,F,G,H,I) ! 86: #define out10(Z,A,B,C,D,E,F,G,H,I,J) fprintf(stdout,_F(Z),A,B,C,D,E,F,G,H,I,J) ! 87: #define out11(Z,A,B,C,D,E,F,G,H,I,J,K) fprintf(stdout,_F(Z),A,B,C,D,E,F,G,H,I,J,K) ! 88: ! 89: #define err0(Z) fprintf(stderr,_F(Z)) ! 90: #define err1(Z,A) fprintf(stderr,_F(Z),A) ! 91: #define err2(Z,A,B) fprintf(stderr,_F(Z),A,B) ! 92: #define err3(Z,A,B,C) fprintf(stderr,_F(Z),A,B,C) ! 93: #define err4(Z,A,B,C,D) fprintf(stderr,_F(Z),A,B,C,D) ! 94: #define err5(Z,A,B,C,D,E) fprintf(stderr,_F(Z),A,B,C,D,E) ! 95: #define err6(Z,A,B,C,D,E,F) fprintf(stderr,_F(Z),A,B,C,D,E,F) ! 96: #define err7(Z,A,B,C,D,E,F,G) fprintf(stderr,_F(Z),A,B,C,D,E,F,G) ! 97: #define err8(Z,A,B,C,D,E,F,G,H) fprintf(stderr,_F(Z),A,B,C,D,E,F,G,H) ! 98: #define err9(Z,A,B,C,D,E,F,G,H,I) fprintf(stderr,_F(Z),A,B,C,D,E,F,G,H,I) ! 99: #define err10(Z,A,B,C,D,E,F,G,H,I,J) fprintf(stderr,_F(Z),A,B,C,D,E,F,G,H,I,J) ! 100: #define err11(Z,A,B,C,D,E,F,G,H,I,J,K) fprintf(stderr,_F(Z),A,B,C,D,E,F,G,H,I,J,K) ! 101: ! 102: char *_G(s) ! 103: char *s; ! 104: { static char m[MSGMAX]; ! 105: strcpy(m,CMDNAME); ! 106: strcat(m,": "); ! 107: strcat(m,s); ! 108: strcat(m," - abort\n"); ! 109: return(m); ! 110: } ! 111: ! 112: #define abort0(Z) fprintf(stderr,_G(Z)) ! 113: #define abort1(Z,A) fprintf(stderr,_G(Z),A) ! 114: #define abort2(Z,A,B) fprintf(stderr,_G(Z),A,B) ! 115: #define abort3(Z,A,B,C) fprintf(stderr,_G(Z),A,B,C) ! 116: #define abort4(Z,A,B,C,D) fprintf(stderr,_G(Z),A,B,C,D) ! 117: #define abort5(Z,A,B,C,D,E) fprintf(stderr,_G(Z),A,B,C,D,E) ! 118: #define abort6(Z,A,B,C,D,E,F) fprintf(stderr,_G(Z),A,B,C,D,E,F) ! 119: #define abort7(Z,A,B,C,D,E,F,G) fprintf(stderr,_G(Z),A,B,C,D,E,F,G) ! 120: #define abort8(Z,A,B,C,D,E,F,G,H) fprintf(stderr,_G(Z),A,B,C,D,E,F,G,H) ! 121: #define abort9(Z,A,B,C,D,E,F,G,H,I) fprintf(stderr,_G(Z),A,B,C,D,E,F,G,H,I) ! 122: #define abort10(Z,A,B,C,D,E,F,G,H,I,J) fprintf(stderr,_G(Z),A,B,C,D,E,F,G,H,I,J) ! 123: #define abort11(Z,A,B,C,D,E,F,G,H,I,J,K) fprintf(stderr,_G(Z),A,B,C,D,E,F,G,H,I,J,K) ! 124: ! 125: boolean ask_more() ! 126: { FILE *tty; ! 127: char reply[20]; ! 128: static int skip = 0; ! 129: if(skip<=0) { ! 130: fputs("MORE? ",(tty=fopen("/dev/tty","w"))); fclose(tty); ! 131: fgets(reply,20,(tty=fopen("/dev/tty","r"))); fclose(tty); ! 132: switch (reply[0]) { ! 133: case '\0': case 'y': case 'Y': ! 134: return(T); ! 135: case 'n': case 'N': case 'q': case 'Q': ! 136: return(F); ! 137: case '0': case '1': case '2': case '3': case '4': ! 138: case '5': case '6': case '7': case '8': case '9': ! 139: skip = atoi(reply); ! 140: return(T); ! 141: case '*': ! 142: skip = INT_MAX; ! 143: return(T); ! 144: default: ! 145: skip = 0; ! 146: return(T); ! 147: }; ! 148: } ! 149: else skip--; ! 150: return(T); ! 151: } ! 152: ! 153: boolean ask_quit() ! 154: { FILE *tty; ! 155: char reply[20]; ! 156: fputs("QUIT? ",(tty=fopen("/dev/tty","w"))); fclose(tty); ! 157: fgets(reply,20,(tty=fopen("/dev/tty","r"))); fclose(tty); ! 158: switch (reply[0]) { ! 159: case 'y': case 'Y': ! 160: return(F); ! 161: case 'n': case 'N': case 'q': case 'Q': ! 162: return(T); ! 163: }; ! 164: return(F); ! 165: } ! 166:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.