]> andersk Git - moira.git/blobdiff - server/mr_util.c
lint
[moira.git] / server / mr_util.c
index 6590666238dac14f19ee3bf8adbff54432cd0e42..9926446eb854d43c503a02da2c77089c04d1b95a 100644 (file)
@@ -4,49 +4,20 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
- *
- *     $Log$
- *     Revision 1.10  1987-08-04 01:54:47  wesommer
- *     Changed messages.
- *
- * Revision 1.9  87/08/04  01:50:13  wesommer
- * Rearranged messages.
- * 
- * Revision 1.8  87/07/29  16:02:48  wesommer
- * Use unsigned char rather than char to prevent sign extension
- * problem.
- * 
- * Revision 1.7  87/07/14  00:39:47  wesommer
- * Changed interface to log_args.
- * 
- * Revision 1.6  87/07/06  16:09:07  wesommer
- * Only print ... if the string is too long..
- * 
- * Revision 1.5  87/06/30  20:05:52  wesommer
- * Added range checking.
- * 
- * Revision 1.4  87/06/21  16:42:19  wesommer
- * Performance work, rearrangement of include files.
- * 
- * Revision 1.3  87/06/04  01:35:28  wesommer
- * Added better logging routines.
- * 
- * Revision 1.2  87/06/03  16:08:07  wesommer
- * Fixes for lint.
- * 
- * Revision 1.1  87/06/02  20:07:32  wesommer
- * Initial revision
- * 
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  */
 
 #ifndef lint
-static char *rcsid_sms_util_c = "$Header$";
+static char *rcsid_mr_util_c = "$Header$";
 #endif lint
 
-#include "sms_server.h"
+#include <mit-copyright.h>
+#include "mr_server.h"
 
 #include <ctype.h>
 #include <strings.h>
+#include <sys/types.h>
 
 extern char *whoami;
 
@@ -78,20 +49,19 @@ requote(buf, cp, len)
        return buf;
 }
 
-log_args(tag, argc, argv)
+log_args(tag, version, argc, argv)
        char *tag;
+       int version;
        int argc;
        char **argv;
 {
        char buf[BUFSIZ];
        register int i;
-       register char *bp = buf;
+       register char *bp;
        
        i = strlen(tag);
-       bcopy(tag, bp, i+1);
-       bp += i;
-       *bp++ =':';
-       *bp++ =' ';
+       sprintf(buf, "%s[%d]: ", tag, version);
+       for (bp = buf; *bp; bp++);
        
        for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) {
                if (i != 0) {
@@ -104,7 +74,7 @@ log_args(tag, 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;
@@ -113,8 +83,6 @@ void sms_com_err(whoami, code, fmt, pvar)
        extern char *error_message();
        extern client *cur_client;
        
-       struct iovec strings[7];
-
        if (whoami) {
                fputs(whoami, stderr);
                if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
@@ -128,3 +96,58 @@ void sms_com_err(whoami, code, fmt, pvar)
        }
        putc('\n', stderr);
 }
+
+
+/* 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 mr_trim_args(argc, argv)
+int argc;
+char **argv;
+{
+    register char **arg;
+    register unsigned char *p, *lastch;
+
+    for (arg = argv; argc--; arg++) {
+       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;
+           else
+             *(++lastch) = 0;
+       }
+    }
+    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);
+}
This page took 0.037485 seconds and 4 git commands to generate.