6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
11 static char *rcsid_sms_util_c = "$Header$";
14 #include "sms_server.h"
18 #include <sys/types.h>
19 #include <zephyr/zephyr.h>
28 register int count = 0;
29 register unsigned char c;
30 if (len <= 2) return buf;
31 *buf++ = '"'; count++; len--;
32 for(; (count < 40) && (len > 1) && (c = *cp);
33 cp++, --len, ++count) {
34 if (c == '\\' || c == '"') *buf++ = '\\';
35 if (isprint(c)) *buf++ = c;
37 sprintf(buf, "\\%03o", c);
38 buf = index(buf, '\0');
41 if (len > 1) { *buf++ = '"'; count++; len--; }
42 if (len > 3 && count >= 40) {
43 *buf++ = '.'; count++; len--;
44 *buf++ = '.'; count++; len--;
45 *buf++ = '.'; count++; len--;
47 if (len > 1) *buf = '\0';
51 log_args(tag, version, argc, argv)
62 sprintf(buf, "%s[%d]: ", tag, version);
63 for (bp = buf; *bp; bp++);
65 for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) {
70 bp = requote(bp, argv[i], (buf - bp) + 1024);
73 com_err(whoami, 0, "%s", buf);
76 void sms_com_err(whoami, code, fmt, pvar)
82 extern char *error_message();
83 extern client *cur_client;
86 fputs(whoami, stderr);
87 if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
91 fputs(error_message(code), stderr);
94 _doprnt(fmt, pvar, stderr);
100 /* sms_trim_args: passed an argument vector, it will trim any trailing
101 * spaces on the args by writing a null into the string.
104 int sms_trim_args(argc, argv)
109 register char *p, *lastch;
111 for (arg = argv; argc--; arg++) {
112 for (lastch = p = *arg; *p; p++)
116 if (isspace(*lastch))
143 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
144 * errors while sending message.
147 send_zgram(inst, msg)
153 bzero (&znotice, sizeof (znotice));
154 znotice.z_kind = UNSAFE;
155 znotice.z_class = "SMS";
156 znotice.z_class_inst = inst;
157 znotice.z_default_format = "SMS $instance:\n $message\n";
158 (void) ZInitialize ();
159 znotice.z_message = msg;
160 znotice.z_message_len = strlen(msg) + 1;
161 znotice.z_opcode = "";
162 znotice.z_recipient = "";
163 ZSendNotice(&znotice, ZNOAUTH);