]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
5cc7d26c | 9 | * Revision 1.10 1987-08-04 01:54:47 wesommer |
10 | * Changed messages. | |
a3cf6921 | 11 | * |
5cc7d26c | 12 | * Revision 1.9 87/08/04 01:50:13 wesommer |
13 | * Rearranged messages. | |
14 | * | |
b4182127 | 15 | * Revision 1.8 87/07/29 16:02:48 wesommer |
16 | * Use unsigned char rather than char to prevent sign extension | |
17 | * problem. | |
18 | * | |
caeb1b25 | 19 | * Revision 1.7 87/07/14 00:39:47 wesommer |
20 | * Changed interface to log_args. | |
21 | * | |
ac65c1d1 | 22 | * Revision 1.6 87/07/06 16:09:07 wesommer |
23 | * Only print ... if the string is too long.. | |
24 | * | |
69f63d24 | 25 | * Revision 1.5 87/06/30 20:05:52 wesommer |
26 | * Added range checking. | |
27 | * | |
5aa981ce | 28 | * Revision 1.4 87/06/21 16:42:19 wesommer |
29 | * Performance work, rearrangement of include files. | |
30 | * | |
c27b3454 | 31 | * Revision 1.3 87/06/04 01:35:28 wesommer |
32 | * Added better logging routines. | |
33 | * | |
229feb8a | 34 | * Revision 1.2 87/06/03 16:08:07 wesommer |
35 | * Fixes for lint. | |
36 | * | |
5dbd09a0 | 37 | * Revision 1.1 87/06/02 20:07:32 wesommer |
38 | * Initial revision | |
39 | * | |
a3cf6921 | 40 | */ |
41 | ||
42 | #ifndef lint | |
43 | static char *rcsid_sms_util_c = "$Header$"; | |
44 | #endif lint | |
45 | ||
a3cf6921 | 46 | #include "sms_server.h" |
a3cf6921 | 47 | |
48 | #include <ctype.h> | |
229feb8a | 49 | #include <strings.h> |
50 | ||
51 | extern char *whoami; | |
52 | ||
229feb8a | 53 | char * |
5aa981ce | 54 | requote(buf, cp, len) |
229feb8a | 55 | char *buf; |
a3cf6921 | 56 | register char *cp; |
57 | { | |
5aa981ce | 58 | register int count = 0; |
caeb1b25 | 59 | register unsigned char c; |
5aa981ce | 60 | if (len <= 2) return buf; |
61 | *buf++ = '"'; count++; len--; | |
62 | for(; (count < 40) && (len > 1) && (c = *cp); | |
63 | cp++, --len, ++count) { | |
229feb8a | 64 | if (c == '\\' || c == '"') *buf++ = '\\'; |
65 | if (isprint(c)) *buf++ = c; | |
66 | else { | |
67 | sprintf(buf, "\\%03o", c); | |
68 | buf = index(buf, '\0'); | |
69 | } | |
a3cf6921 | 70 | } |
5aa981ce | 71 | if (len > 1) { *buf++ = '"'; count++; len--; } |
69f63d24 | 72 | if (len > 3 && count >= 40) { |
5aa981ce | 73 | *buf++ = '.'; count++; len--; |
74 | *buf++ = '.'; count++; len--; | |
75 | *buf++ = '.'; count++; len--; | |
76 | } | |
77 | if (len > 1) *buf = '\0'; | |
229feb8a | 78 | return buf; |
a3cf6921 | 79 | } |
5aa981ce | 80 | |
ac65c1d1 | 81 | log_args(tag, argc, argv) |
82 | char *tag; | |
229feb8a | 83 | int argc; |
84 | char **argv; | |
85 | { | |
86 | char buf[BUFSIZ]; | |
87 | register int i; | |
88 | register char *bp = buf; | |
89 | ||
ac65c1d1 | 90 | i = strlen(tag); |
91 | bcopy(tag, bp, i+1); | |
92 | bp += i; | |
93 | *bp++ =':'; | |
94 | *bp++ =' '; | |
95 | ||
5aa981ce | 96 | for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) { |
229feb8a | 97 | if (i != 0) { |
98 | *bp++ = ','; | |
99 | *bp++ = ' '; | |
100 | } | |
5aa981ce | 101 | bp = requote(bp, argv[i], (buf - bp) + 1024); |
229feb8a | 102 | } |
103 | *bp = '\0'; | |
5cc7d26c | 104 | com_err(whoami, 0, "%s", buf); |
229feb8a | 105 | } |
106 | ||
b4182127 | 107 | void sms_com_err(whoami, code, fmt, pvar) |
a3cf6921 | 108 | char *whoami; |
109 | int code; | |
b4182127 | 110 | char *fmt; |
111 | caddr_t pvar; | |
a3cf6921 | 112 | { |
113 | extern char *error_message(); | |
114 | extern client *cur_client; | |
115 | ||
116 | struct iovec strings[7]; | |
b4182127 | 117 | |
a3cf6921 | 118 | if (whoami) { |
b4182127 | 119 | fputs(whoami, stderr); |
120 | if (cur_client) fprintf(stderr, "[#%d]", cur_client->id); | |
121 | fputs(": ", stderr); | |
a3cf6921 | 122 | } |
123 | if (code) { | |
b4182127 | 124 | fputs(error_message(code), stderr); |
125 | } | |
126 | if (fmt) { | |
127 | _doprnt(fmt, pvar, stderr); | |
a3cf6921 | 128 | } |
b4182127 | 129 | putc('\n', stderr); |
a3cf6921 | 130 | } |