6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
11 static char *rcsid_sms_util_c = "$Header$";
14 #include "sms_server.h"
26 register int count = 0;
27 register unsigned char c;
28 if (len <= 2) return buf;
29 *buf++ = '"'; count++; len--;
30 for(; (count < 40) && (len > 1) && (c = *cp);
31 cp++, --len, ++count) {
32 if (c == '\\' || c == '"') *buf++ = '\\';
33 if (isprint(c)) *buf++ = c;
35 sprintf(buf, "\\%03o", c);
36 buf = index(buf, '\0');
39 if (len > 1) { *buf++ = '"'; count++; len--; }
40 if (len > 3 && count >= 40) {
41 *buf++ = '.'; count++; len--;
42 *buf++ = '.'; count++; len--;
43 *buf++ = '.'; count++; len--;
45 if (len > 1) *buf = '\0';
49 log_args(tag, version, argc, argv)
60 sprintf(buf, "%s[%d]: ", tag, version);
61 for (bp = buf; *bp; bp++);
63 for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) {
68 bp = requote(bp, argv[i], (buf - bp) + 1024);
71 com_err(whoami, 0, "%s", buf);
74 void sms_com_err(whoami, code, fmt, pvar)
80 extern char *error_message();
81 extern client *cur_client;
84 fputs(whoami, stderr);
85 if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
89 fputs(error_message(code), stderr);
92 _doprnt(fmt, pvar, stderr);
98 /* sms_trim_args: passed an argument vector, it will trim any trailing
99 * spaces on the args by writing a null into the string.
102 int sms_trim_args(argc, argv)
107 register char *p, *lastch;
109 for (arg = argv; argc--; arg++) {
110 for (lastch = p = *arg; *p; p++)
114 if (isspace(*lastch))