]> andersk Git - moira.git/blobdiff - server/mr_util.c
Code style cleanup. (No functional changes)
[moira.git] / server / mr_util.c
index 1b5bb3378211aa12f5a529838b334c30190a1539..9b9e67d40feb170809aee5efd54cc1001604635d 100644 (file)
@@ -21,74 +21,78 @@ static char *rcsid_mr_util_c = "$Header$";
 
 extern char *whoami;
 
-char *
-requote(buf, cp, len)
-       char *buf;
-       register char *cp;
+char *requote(char *buf, register char *cp, int len)
 {
-       register int count = 0;
-       register unsigned char c;
-       if (len <= 2) return buf;
-       *buf++ = '"'; count++; len--;
-       for(; (count < 258) && (len > 1) && (c = *cp);
-           cp++, --len, ++count) {
-               if (c == '\\' || c == '"') *buf++ = '\\';
-               if (isprint(c)) *buf++ = c;
-               else {
-                       sprintf(buf, "\\%03o", c);
-                       buf = strchr(buf, '\0');
-               }
+  register int count = 0;
+  register unsigned char c;
+  if (len <= 2)
+    return buf;
+  *buf++ = '"';
+  count++;
+  len--;
+  for (; (count < 258) && (len > 1) && (c = *cp); cp++, --len, ++count)
+    {
+      if (c == '\\' || c == '"')
+       *buf++ = '\\';
+      if (isprint(c))
+       *buf++ = c;
+      else
+       {
+         sprintf(buf, "\\%03o", c);
+         buf = strchr(buf, '\0');
        }
-       if (len > 1) { *buf++ = '"'; count++; len--; }
-       if (len > 1) *buf = '\0';
-       return buf;
+    }
+  if (len > 1)
+    {
+      *buf++ = '"';
+      count++;
+      len--;
+    }
+  if (len > 1)
+    *buf = '\0';
+  return buf;
 }
 
-void log_args(tag, version, argc, argv)
-       char *tag;
-       int version;
-       int argc;
-       char **argv;
+void log_args(char *tag, int version, int argc, char **argv)
 {
-       char buf[BUFSIZ];
-       register int i;
-       register char *bp;
-       
-       i = strlen(tag);
-       sprintf(buf, "%s[%d]: ", tag, version);
-       for (bp = buf; *bp; bp++);
-       
-       for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++) {
-               if (i != 0) {
-                       *bp++ = ',';
-                       *bp++ = ' '; 
-               }
-               bp = requote(bp, argv[i], (buf - bp) + BUFSIZ);
+  char buf[BUFSIZ];
+  register int i;
+  register char *bp;
+
+  i = strlen(tag);
+  sprintf(buf, "%s[%d]: ", tag, version);
+  for (bp = buf; *bp; bp++)
+    ;
+
+  for (i = 0; i < argc && ((buf - bp) + BUFSIZ) > 2; i++)
+    {
+      if (i != 0)
+       {
+         *bp++ = ',';
+         *bp++ = ' ';
        }
-       *bp = '\0';
-       com_err(whoami, 0, "%s", buf);
+      bp = requote(bp, argv[i], (buf - bp) + BUFSIZ);
+    }
+  *bp = '\0';
+  com_err(whoami, 0, "%s", buf);
 }
-       
-void mr_com_err(whoami, code, fmt, pvar)
-       const char *whoami;
-       long code;
-       const char *fmt;
-       va_list pvar;
+
+void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar)
 {
-       extern client *cur_client;
-       
-       if (whoami) {
-               fputs(whoami, stderr);
-               if (cur_client) fprintf(stderr, "[#%d]", cur_client->id);
-               fputs(": ", stderr);
-       }
-       if (code) {
-               fputs(error_message(code), stderr);
-       }
-       if (fmt) {
-               _doprnt(fmt, pvar, stderr);
-       }
-       putc('\n', stderr);
+  extern client *cur_client;
+
+  if (whoami)
+    {
+      fputs(whoami, stderr);
+      if (cur_client)
+       fprintf(stderr, "[#%d]", cur_client->id);
+      fputs(": ", stderr);
+    }
+  if (code)
+    fputs(error_message(code), stderr);
+  if (fmt)
+    _doprnt(fmt, pvar, stderr);
+  putc('\n', stderr);
 }
 
 
@@ -97,51 +101,52 @@ void mr_com_err(whoami, code, fmt, pvar)
  * appears to be binary instead of ASCII, it will not be trimmed.
  */
 
-int mr_trim_args(argc, argv)
-int argc;
-char **argv;
+int mr_trim_args(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;
+  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 (!isspace(*p))
+           lastch = p;
        }
-       if (p != lastch) {
-           if (isspace(*lastch))
-             *lastch = 0;
-           else
-             if (*(++lastch)) *lastch = 0;
+      if (p != lastch)
+       {
+         if (isspace(*lastch))
+           *lastch = '\0';
+         else
+           if (*(++lastch))
+             *lastch = '\0';
        }
     }
-    return(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 **mr_copy_args(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);
+  char **a;
+  int i;
+
+  a = malloc(argc * sizeof(char *));
+  if (!a)
+    return a;
+  for (i = 0; i < argc; i++)
+    a[i] = strsave(argv[i]);
+  return a;
 }
This page took 0.042597 seconds and 4 git commands to generate.