3 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
19 char *requote(char *buf, char *cp, int len)
28 for (; (count < 258) && (len > 1) && (c = *cp); cp++, --len, ++count)
30 if (c == '\\' || c == '"')
36 sprintf(buf, "\\%03o", c);
37 buf = strchr(buf, '\0');
51 void log_args(char *tag, int version, int argc, char **argv)
58 sprintf(buf, "%s[%d]: ", tag, version);
59 for (bp = buf; *bp; bp++)
62 for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++)
69 bp = requote(bp, argv[i], (buf - bp) + BUFSIZ);
72 com_err(whoami, 0, "%s", buf);
75 void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar)
77 extern client *cur_client;
81 fputs(whoami, stderr);
83 fprintf(stderr, "[#%d]", cur_client->id);
87 fputs(error_message(code), stderr);
89 vfprintf(stderr, fmt, pvar);
94 /* mr_trim_args: passed an argument vector, it will trim any trailing
95 * spaces on the args by writing a null into the string. If an argument
96 * appears to be binary instead of ASCII, it will not be trimmed.
99 int mr_trim_args(int argc, char **argv)
102 unsigned char *p, *lastch;
104 for (arg = argv; argc--; arg++)
106 for (lastch = p = (unsigned char *) *arg; *p; p++)
108 /* If any byte in the string has the high bit set, assume
109 * that it is binary and we do not want to trim it.
110 * Setting p = lastch will cause us not to trim the string
111 * when we break out of this inner loop.
123 if (isspace(*lastch))
134 /* returns a copy of the argv and all of it's strings */
136 char **mr_copy_args(char **argv, int argc)
141 a = malloc(argc * sizeof(char *));
144 for (i = 0; i < argc; i++)
145 a[i] = strdup(argv[i]);