]> andersk Git - moira.git/blame - server/mr_util.c
Don't print error on successful change of FS
[moira.git] / server / mr_util.c
CommitLineData
a3cf6921 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
a3cf6921 8 */
9
10#ifndef lint
11static char *rcsid_sms_util_c = "$Header$";
12#endif lint
13
a3cf6921 14#include "sms_server.h"
a3cf6921 15
16#include <ctype.h>
229feb8a 17#include <strings.h>
c93d352e 18#include <sys/types.h>
229feb8a 19
20extern char *whoami;
21
229feb8a 22char *
5aa981ce 23requote(buf, cp, len)
229feb8a 24 char *buf;
a3cf6921 25 register char *cp;
26{
5aa981ce 27 register int count = 0;
caeb1b25 28 register unsigned char c;
5aa981ce 29 if (len <= 2) return buf;
30 *buf++ = '"'; count++; len--;
31 for(; (count < 40) && (len > 1) && (c = *cp);
32 cp++, --len, ++count) {
229feb8a 33 if (c == '\\' || c == '"') *buf++ = '\\';
34 if (isprint(c)) *buf++ = c;
35 else {
36 sprintf(buf, "\\%03o", c);
37 buf = index(buf, '\0');
38 }
a3cf6921 39 }
5aa981ce 40 if (len > 1) { *buf++ = '"'; count++; len--; }
69f63d24 41 if (len > 3 && count >= 40) {
5aa981ce 42 *buf++ = '.'; count++; len--;
43 *buf++ = '.'; count++; len--;
44 *buf++ = '.'; count++; len--;
45 }
46 if (len > 1) *buf = '\0';
229feb8a 47 return buf;
a3cf6921 48}
5aa981ce 49
2423a5db 50log_args(tag, version, argc, argv)
ac65c1d1 51 char *tag;
2423a5db 52 int version;
229feb8a 53 int argc;
54 char **argv;
55{
56 char buf[BUFSIZ];
57 register int i;
2423a5db 58 register char *bp;
229feb8a 59
ac65c1d1 60 i = strlen(tag);
2423a5db 61 sprintf(buf, "%s[%d]: ", tag, version);
62 for (bp = buf; *bp; bp++);
ac65c1d1 63
5aa981ce 64 for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) {
229feb8a 65 if (i != 0) {
66 *bp++ = ',';
67 *bp++ = ' ';
68 }
5aa981ce 69 bp = requote(bp, argv[i], (buf - bp) + 1024);
229feb8a 70 }
71 *bp = '\0';
5cc7d26c 72 com_err(whoami, 0, "%s", buf);
229feb8a 73}
74
b4182127 75void sms_com_err(whoami, code, fmt, pvar)
a3cf6921 76 char *whoami;
77 int code;
b4182127 78 char *fmt;
79 caddr_t pvar;
a3cf6921 80{
81 extern char *error_message();
82 extern client *cur_client;
83
a3cf6921 84 if (whoami) {
b4182127 85 fputs(whoami, stderr);
86 if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
87 fputs(": ", stderr);
a3cf6921 88 }
89 if (code) {
b4182127 90 fputs(error_message(code), stderr);
91 }
92 if (fmt) {
93 _doprnt(fmt, pvar, stderr);
a3cf6921 94 }
b4182127 95 putc('\n', stderr);
a3cf6921 96}
2423a5db 97
98
99/* sms_trim_args: passed an argument vector, it will trim any trailing
100 * spaces on the args by writing a null into the string.
101 */
102
103int sms_trim_args(argc, argv)
104int argc;
105char **argv;
106{
107 register char **arg;
108 register char *p, *lastch;
109
110 for (arg = argv; argc--; arg++) {
111 for (lastch = p = *arg; *p; p++)
112 if (!isspace(*p))
113 lastch = p;
114 if (p != lastch) {
115 if (isspace(*lastch))
116 *lastch = 0;
117 else
118 *(++lastch) = 0;
119 }
120 }
121 return(0);
122}
123
124
125trim(s)
126register char *s;
127{
128 register char *p;
129
130 for (p = s; *s; s++)
131 if (*s != ' ')
132 p = s;
133 if (p != s) {
134 if (*p == ' ')
135 *p = 0;
136 else
137 p[1] = 0;
138 }
139}
This page took 0.227561 seconds and 5 git commands to generate.