6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
12 static char *rcsid_mr_util_c = "$Header$";
15 #include <mit-copyright.h>
16 #include "mr_server.h"
19 #include <sys/types.h>
28 register int count = 0;
29 register unsigned char c;
30 if (len <= 2) return buf;
31 *buf++ = '"'; count++; len--;
32 for(; (count < 258) && (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 > 1) *buf = '\0';
46 log_args(tag, version, argc, argv)
57 sprintf(buf, "%s[%d]: ", tag, version);
58 for (bp = buf; *bp; bp++);
60 for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++) {
65 bp = requote(bp, argv[i], (buf - bp) + BUFSIZ);
68 com_err(whoami, 0, "%s", buf);
71 void mr_com_err(whoami, code, fmt, pvar)
77 extern char *error_message();
78 extern client *cur_client;
81 fputs(whoami, stderr);
82 if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
86 fputs(error_message(code), stderr);
89 _doprnt(fmt, pvar, stderr);
95 /* mr_trim_args: passed an argument vector, it will trim any trailing
96 * spaces on the args by writing a null into the string. If an argument
97 * appears to be binary instead of ASCII, it will not be trimmed.
100 int mr_trim_args(argc, argv)
105 register unsigned char *p, *lastch;
107 for (arg = argv; argc--; arg++) {
108 for (lastch = p = (unsigned char *) *arg; *p; p++) {
109 /* If any byte in the string has the high bit set, assume
110 * that it is binary and we do not want to trim it.
111 * Setting p = lastch will cause us not to trim the string
112 * when we break out of this inner loop.
122 if (isspace(*lastch))
132 /* returns a copy of the argv and all of it's strings */
134 char **mr_copy_args(argv, argc)
141 a = (char **) malloc(argc * sizeof(char *));
144 for (i = 0; i < argc; i++)
145 a[i] = strsave(argv[i]);