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"
20 #include <sys/types.h>
29 register int count = 0;
30 register unsigned char c;
31 if (len <= 2) return buf;
32 *buf++ = '"'; count++; len--;
33 for(; (count < 40) && (len > 1) && (c = *cp);
34 cp++, --len, ++count) {
35 if (c == '\\' || c == '"') *buf++ = '\\';
36 if (isprint(c)) *buf++ = c;
38 sprintf(buf, "\\%03o", c);
39 buf = index(buf, '\0');
42 if (len > 1) { *buf++ = '"'; count++; len--; }
43 if (len > 3 && count >= 40) {
44 *buf++ = '.'; count++; len--;
45 *buf++ = '.'; count++; len--;
46 *buf++ = '.'; count++; len--;
48 if (len > 1) *buf = '\0';
52 log_args(tag, version, argc, argv)
63 sprintf(buf, "%s[%d]: ", tag, version);
64 for (bp = buf; *bp; bp++);
66 for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) {
71 bp = requote(bp, argv[i], (buf - bp) + 1024);
74 com_err(whoami, 0, "%s", buf);
77 void mr_com_err(whoami, code, fmt, pvar)
83 extern char *error_message();
84 extern client *cur_client;
87 fputs(whoami, stderr);
88 if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
92 fputs(error_message(code), stderr);
95 _doprnt(fmt, pvar, stderr);
101 /* mr_trim_args: passed an argument vector, it will trim any trailing
102 * spaces on the args by writing a null into the string.
105 int mr_trim_args(argc, argv)
110 register char *p, *lastch;
112 for (arg = argv; argc--; arg++) {
113 for (lastch = p = *arg; *p; p++)
117 if (isspace(*lastch))
127 /* returns a copy of the argv and all of it's strings */
129 char **mr_copy_args(argv, argc)
136 a = (char **) malloc(argc * sizeof(char *));
139 for (i = 0; i < argc; i++)
140 a[i] = strsave(argv[i]);