]> git.pond.sub.org Git - empserver/blobdiff - src/client/servcmd.c
Indented with src/scripts/indent-emp.
[empserver] / src / client / servcmd.c
index d2d43adf38602dc35f507e3e3c4a6d5ee7cd1b6c..f15341fcc1254afa92cc3201410f1dc6cebcd80d 100644 (file)
 
 extern s_char *gettag();
 
-s_char num_teles[64];
-static s_char  the_prompt[1024];
-static int     mode;
-static int     nbtu;
-static int     nmin;
-FILE   *redir_fp;
-FILE   *pipe_fp;
-int    exec_fd;
+s_char num_teles[64];
+static s_char the_prompt[1024];
+static int mode;
+static int nbtu;
+static int nmin;
+FILE *redir_fp;
+FILE *pipe_fp;
+int exec_fd;
 
 void prompt();
 void doredir();
@@ -66,100 +66,97 @@ int sendeof();
 int termio();
 void _noecho();
 
-extern s_char  *SO;
-extern s_char  *SE;
+extern s_char *SO;
+extern s_char *SE;
 
 void
 servercmd(ioq, auxfi)
-       struct  ioqueue *ioq;
-       FILE *auxfi;
+struct ioqueue *ioq;
+FILE *auxfi;
 {
-       s_char *ioq_gets(struct ioqueue *, s_char *, int);
-       s_char  buf[1024];
-       s_char  *p;
-       int     code;
+    s_char *ioq_gets(struct ioqueue *, s_char *, int);
+    s_char buf[1024];
+    s_char *p;
+    int code;
 
-       while (ioq_gets(ioq, buf, sizeof(buf))) {
-               p = buf;
-               while (*p && !isspace(*p))
-                       p++;
-               *p++ = 0;
-               if (isalpha(*buf))
-                       code = 10 + (*buf - 'a');
-               else
-                       code = *buf - '0';
-               switch (code) {
-               case C_PROMPT:
-                       if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) {
-                               fprintf(stderr, "prompt: bad server prompt %s\n", p);
-                       }
-                       mode = code;
-                       sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin);
-                       prompt(auxfi);
-                       break;
-               case C_REDIR:
-                       doredir(p);
-                       break;
-               case C_PIPE:
-                       dopipe(p);
-                       break;
-               case C_FLUSH:
-                       mode = code;
-                       sprintf(the_prompt, "%s", p);
-                       prompt(auxfi);
-                       break;
-               case C_EXECUTE:
-                       doexecute(p, auxfi);
-                       break;
-               case C_INFORM:
-                       if (*p) {
-                               p[strlen(p)-1] = '\0';
-                               sprintf(num_teles, "(%s) ", p + 1);
-                               if (!redir_fp &&
-                                   !pipe_fp &&
-                                   !exec_fd) {
-                                       putchar('\07');
-                                       prompt(0);
-                               }
-                       }
-                       else
-                               *num_teles = '\0';
-                       break;
-               default:
-                       output(code, p, auxfi);
-                       break;
+    while (ioq_gets(ioq, buf, sizeof(buf))) {
+       p = buf;
+       while (*p && !isspace(*p))
+           p++;
+       *p++ = 0;
+       if (isalpha(*buf))
+           code = 10 + (*buf - 'a');
+       else
+           code = *buf - '0';
+       switch (code) {
+       case C_PROMPT:
+           if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) {
+               fprintf(stderr, "prompt: bad server prompt %s\n", p);
+           }
+           mode = code;
+           sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin);
+           prompt(auxfi);
+           break;
+       case C_REDIR:
+           doredir(p);
+           break;
+       case C_PIPE:
+           dopipe(p);
+           break;
+       case C_FLUSH:
+           mode = code;
+           sprintf(the_prompt, "%s", p);
+           prompt(auxfi);
+           break;
+       case C_EXECUTE:
+           doexecute(p, auxfi);
+           break;
+       case C_INFORM:
+           if (*p) {
+               p[strlen(p) - 1] = '\0';
+               sprintf(num_teles, "(%s) ", p + 1);
+               if (!redir_fp && !pipe_fp && !exec_fd) {
+                   putchar('\07');
+                   prompt(0);
                }
+           } else
+               *num_teles = '\0';
+           break;
+       default:
+           output(code, p, auxfi);
+           break;
        }
+    }
 }
 
 void
 prompt(auxfi)
-       FILE    *auxfi;
+FILE *auxfi;
 {
-       if (mode == C_PROMPT) {
-               if (redir_fp) {
-                       (void) fclose(redir_fp);
-                       redir_fp = 0;
-               } else if (pipe_fp) {
+    if (mode == C_PROMPT) {
+       if (redir_fp) {
+           (void)fclose(redir_fp);
+           redir_fp = 0;
+       } else if (pipe_fp) {
 #ifndef _WIN32
-                       (void) pclose(pipe_fp);
+           (void)pclose(pipe_fp);
 #endif
-                       pipe_fp = 0;
-               } else if (exec_fd > 0) {
-                       close(exec_fd);
-                       close(0);
-                       exec_fd = -1;
-                       open("/dev/tty", O_RDONLY, 0);
-               }
-       }
-       if (mode == C_PROMPT)
-               printf("\n");
-       printf("%s%s", num_teles, the_prompt);
-       (void) fflush(stdout);
-       if (auxfi) {
-           fprintf(auxfi, "\n%s%s", num_teles, the_prompt);
-           (void)fflush(auxfi);
+           pipe_fp = 0;
+       } else if (exec_fd > 0) {
+           close(exec_fd);
+           close(0);
+           exec_fd = -1;
+           open("/dev/tty", O_RDONLY, 0);
        }
+    }
+    if (mode == C_PROMPT)
+       printf("\n");
+    printf("%s%s", num_teles, the_prompt);
+    (void)fflush(stdout);
+    if (auxfi) {
+       fprintf(auxfi, "\n%s%s", num_teles, the_prompt);
+       (void)fflush(auxfi);
+    }
 }
 
 /*
@@ -167,51 +164,52 @@ prompt(auxfi)
  */
 void
 doredir(p)
-       s_char  *p;
+s_char *p;
 {
-       s_char  *how;
-       s_char  *name;
-       s_char  *tag;
-       int     mode;
-       int     fd;
+    s_char *how;
+    s_char *name;
+    s_char *tag;
+    int mode;
+    int fd;
 
-       if (redir_fp) {
-               (void) fclose(redir_fp);
-               redir_fp = 0;
-       }
-       how = p++;
-       if (*p && ((*p == '>') || (*p == '!')))
-               p++;
-       tag = gettag(p);
-       while (*p && isspace(*p))
-               p++;
-       name = p;
-       while (*p && !isspace(*p))
-               p++;
-       *p = 0;
-       if (tag == NULL) {
-               fprintf(stderr, "WARNING!  Server redirected output to file %s\n",name);
-               return;
-       }
-       mode = O_WRONLY | O_CREAT;
-       if (how[1] == '>')
-               mode |= O_APPEND;
-       else if (how[1] == '!')
-               mode |= O_TRUNC;
-       else
-               mode |= O_EXCL;
-       if (*name == 0) {
-               fprintf(stderr, "Null file name after redirect\n");
-               free(tag);
-               return;
-       }
-       if ((fd = open(name, mode, 0600)) < 0) {
-               fprintf(stderr, "Redirect open failed\n");
-               perror(name);
-       } else {
-               redir_fp = fdopen(fd, "w");
-       }
+    if (redir_fp) {
+       (void)fclose(redir_fp);
+       redir_fp = 0;
+    }
+    how = p++;
+    if (*p && ((*p == '>') || (*p == '!')))
+       p++;
+    tag = gettag(p);
+    while (*p && isspace(*p))
+       p++;
+    name = p;
+    while (*p && !isspace(*p))
+       p++;
+    *p = 0;
+    if (tag == NULL) {
+       fprintf(stderr, "WARNING!  Server redirected output to file %s\n",
+               name);
+       return;
+    }
+    mode = O_WRONLY | O_CREAT;
+    if (how[1] == '>')
+       mode |= O_APPEND;
+    else if (how[1] == '!')
+       mode |= O_TRUNC;
+    else
+       mode |= O_EXCL;
+    if (*name == 0) {
+       fprintf(stderr, "Null file name after redirect\n");
        free(tag);
+       return;
+    }
+    if ((fd = open(name, mode, 0600)) < 0) {
+       fprintf(stderr, "Redirect open failed\n");
+       perror(name);
+    } else {
+       redir_fp = fdopen(fd, "w");
+    }
+    free(tag);
 }
 
 /*
@@ -219,155 +217,156 @@ doredir(p)
  */
 void
 dopipe(p)
-       s_char  *p;
+s_char *p;
 {
-       extern  FILE *popen();
-       s_char  *tag;
+    extern FILE *popen();
+    s_char *tag;
 
-       if (*p == '|')
-               p++;
-       tag = gettag(p);
-       while (*p && isspace(*p))
-               p++;
-       if (tag == NULL) {
-               fprintf(stderr, "WARNING!  Server attempted to run: %s\n",p);
-               return;
-       }
-       if (*p == 0) {
-               fprintf(stderr, "Null program name after redirect\n");
-               free(tag);
-               return;
-       }
+    if (*p == '|')
+       p++;
+    tag = gettag(p);
+    while (*p && isspace(*p))
+       p++;
+    if (tag == NULL) {
+       fprintf(stderr, "WARNING!  Server attempted to run: %s\n", p);
+       return;
+    }
+    if (*p == 0) {
+       fprintf(stderr, "Null program name after redirect\n");
+       free(tag);
+       return;
+    }
 #ifndef _WIN32
-       if ((pipe_fp = popen(p, "w")) == 0) {
+    if ((pipe_fp = popen(p, "w")) == 0) {
 #else
-       if (1) {
+    if (1) {
 #endif
-               fprintf(stderr, "Pipe open failed\n");
-               perror(p);
-       }
-       free(tag);
+       fprintf(stderr, "Pipe open failed\n");
+       perror(p);
+    }
+    free(tag);
 }
 
 void
 doexecute(p, auxfi)
-       s_char  *p;
-       FILE    *auxfi;
+s_char *p;
+FILE *auxfi;
 {
-       extern  int sock;
-       int     fd;
-       s_char  *tag;
+    extern int sock;
+    int fd;
+    s_char *tag;
 
-       tag = gettag(p);
-       while (*p && isspace(*p))
-               p++;
-       if (tag == NULL) {
-               fprintf(stderr, "WARNING!  Server attempted unauthorized read of file %s\n",p);
-               return;
-       }
-       if (p == 0) {
-               fprintf(stderr, "Null file to execute\n");
-               free(tag);
-               return;
-       }
+    tag = gettag(p);
+    while (*p && isspace(*p))
+       p++;
+    if (tag == NULL) {
+       fprintf(stderr,
+               "WARNING!  Server attempted unauthorized read of file %s\n",
+               p);
+       return;
+    }
+    if (p == 0) {
+       fprintf(stderr, "Null file to execute\n");
+       free(tag);
+       return;
+    }
 #if !defined(_WIN32)
-       if ((fd = open(p, O_RDONLY, 0)) < 0) {
+    if ((fd = open(p, O_RDONLY, 0)) < 0) {
 #else
-       if ((fd = open(p, O_RDONLY|O_BINARY, 0)) < 0) {
+    if ((fd = open(p, O_RDONLY | O_BINARY, 0)) < 0) {
 #endif
-               fprintf(stderr, "Can't open execute file\n");
-               perror(p);
-               free(tag);
-               return;
-       }
-       /* copies 4k at a time to the socket */
-       while (termio(fd, sock, auxfi)) /*do copy*/;
-       /* Some platforms don't send the eof (cntl-D) at the end of
-           copying a file.  If emp_client hangs at the end of an
-          execute, include the following line and notify wolfpack
-          of the platform you are using.
-       sendeof(sock);
-       */
-       close(fd);
+       fprintf(stderr, "Can't open execute file\n");
+       perror(p);
        free(tag);
+       return;
+    }
+    /* copies 4k at a time to the socket */
+    while (termio(fd, sock, auxfi))    /*do copy */
+       ;
+    /* Some platforms don't send the eof (cntl-D) at the end of
+       copying a file.  If emp_client hangs at the end of an
+       execute, include the following line and notify wolfpack
+       of the platform you are using.
+       sendeof(sock);
+     */
+    close(fd);
+    free(tag);
 }
 
 void
 output(code, buf, auxfi)
-       int     code;
-       s_char  *buf;
-       FILE    *auxfi;
+int code;
+s_char *buf;
+FILE *auxfi;
 {
-       switch (code) {
-       case C_NOECHO:
-               _noecho(0);
-               break;
-       case C_FLUSH:
-               (void) fflush(stdout);
-               if (auxfi)
-                   (void) fflush(auxfi);
-               break;
-       case C_ABORT:
-               printf("Aborted\n");
-               if (auxfi)
-                   fprintf(auxfi, "Aborted\n");
-               break;
-       case C_CMDERR:
-       case C_BADCMD:
-               printf("Error; ");
-               if (auxfi)
-                   fprintf(auxfi, "Error; ");
-               break;
-       case C_EXIT:
-               printf("Exit: ");
-               if (auxfi)
-                   fprintf(auxfi, "Exit: ");
-               break;
-       case C_FLASH:
-               printf("\n");
-               break;
-       default:
-               break;
-       }
-       if (auxfi) {
-               fprintf(auxfi, "%s", buf);
-               if (code == C_FLUSH)
-                   (void) fflush(auxfi);
-               else
-                   (void) putc('\n', auxfi);
-       }
+    switch (code) {
+    case C_NOECHO:
+       _noecho(0);
+       break;
+    case C_FLUSH:
+       (void)fflush(stdout);
+       if (auxfi)
+           (void)fflush(auxfi);
+       break;
+    case C_ABORT:
+       printf("Aborted\n");
+       if (auxfi)
+           fprintf(auxfi, "Aborted\n");
+       break;
+    case C_CMDERR:
+    case C_BADCMD:
+       printf("Error; ");
+       if (auxfi)
+           fprintf(auxfi, "Error; ");
+       break;
+    case C_EXIT:
+       printf("Exit: ");
+       if (auxfi)
+           fprintf(auxfi, "Exit: ");
+       break;
+    case C_FLASH:
+       printf("\n");
+       break;
+    default:
+       break;
+    }
+    if (auxfi) {
+       fprintf(auxfi, "%s", buf);
+       if (code == C_FLUSH)
+           (void)fflush(auxfi);
+       else
+           (void)putc('\n', auxfi);
+    }
 
-       if (redir_fp)
-               fprintf(redir_fp, "%s\n", buf);
-       else if (pipe_fp)
-               fprintf(pipe_fp, "%s\n", buf);
-       else {
-               if (SO && SE)
-                       screen(buf);
-               else
-                       fputs(buf, stdout);
-               if (code == C_FLUSH)
-                       (void) fflush(stdout);
-               else
-                       (void) putc('\n', stdout);
-       }
+    if (redir_fp)
+       fprintf(redir_fp, "%s\n", buf);
+    else if (pipe_fp)
+       fprintf(pipe_fp, "%s\n", buf);
+    else {
+       if (SO && SE)
+           screen(buf);
+       else
+           fputs(buf, stdout);
+       if (code == C_FLUSH)
+           (void)fflush(stdout);
+       else
+           (void)putc('\n', stdout);
+    }
 }
 
 void
 screen(buf)
-       register s_char *buf;
+register s_char *buf;
 {
-       register s_char *sop;
-       register s_char c;
+    register s_char *sop;
+    register s_char c;
 
-       while ((c = *buf++)) {
-               if (c & 0x80) {
-                       for (sop = SO; putc(*sop, stdout); sop++)
-                               ;
-                       (void) putc(c & 0x7f, stdout);
-                       for (sop = SE; putc(*sop, stdout); sop++)
-                               ;
-               } else
-                       (void) putc(c, stdout);
-       }
+    while ((c = *buf++)) {
+       if (c & 0x80) {
+           for (sop = SO; putc(*sop, stdout); sop++) ;
+           (void)putc(c & 0x7f, stdout);
+           for (sop = SE; putc(*sop, stdout); sop++) ;
+       } else
+           (void)putc(c, stdout);
+    }
 }