X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/437bee901aff5aba2a23f3949bda352be3d21c9e..245f8a92a68015a715f4821b4a32b4c39a00d8d7:/server/mr_util.c diff --git a/server/mr_util.c b/server/mr_util.c index c008e568..9926446e 100644 --- a/server/mr_util.c +++ b/server/mr_util.c @@ -9,11 +9,11 @@ */ #ifndef lint -static char *rcsid_sms_util_c = "$Header$"; +static char *rcsid_mr_util_c = "$Header$"; #endif lint #include -#include "sms_server.h" +#include "mr_server.h" #include #include @@ -74,7 +74,7 @@ log_args(tag, version, argc, argv) com_err(whoami, 0, "%s", buf); } -void sms_com_err(whoami, code, fmt, pvar) +void mr_com_err(whoami, code, fmt, pvar) char *whoami; int code; char *fmt; @@ -98,21 +98,32 @@ void sms_com_err(whoami, code, fmt, pvar) } -/* sms_trim_args: passed an argument vector, it will trim any trailing - * spaces on the args by writing a null into the string. +/* mr_trim_args: passed an argument vector, it will trim any trailing + * spaces on the args by writing a null into the string. If an argument + * appears to be binary instead of ASCII, it will not be trimmed. */ -int sms_trim_args(argc, argv) +int mr_trim_args(argc, argv) int argc; char **argv; { register char **arg; - register char *p, *lastch; + register unsigned char *p, *lastch; for (arg = argv; argc--; arg++) { - for (lastch = p = *arg; *p; p++) - if (!isspace(*p)) - lastch = p; + for (lastch = p = (unsigned char *) *arg; *p; p++) { + /* If any byte in the string has the high bit set, assume + * that it is binary and we do not want to trim it. + * Setting p = lastch will cause us not to trim the string + * when we break out of this inner loop. + */ + if (*p >= 0x80) { + p = lastch; + break; + } + if (!isspace(*p)) + lastch = p; + } if (p != lastch) { if (isspace(*lastch)) *lastch = 0; @@ -122,3 +133,21 @@ char **argv; } return(0); } + + +/* returns a copy of the argv and all of it's strings */ + +char **mr_copy_args(argv, argc) +char **argv; +int argc; +{ + char **a; + int i; + + a = (char **) malloc(argc * sizeof(char *)); + if (a == 0) + return(a); + for (i = 0; i < argc; i++) + a[i] = strsave(argv[i]); + return(a); +}