"Fossies" - the Fresh Open Source Software Archive

Member "netbiff-0.9.18/nbproto.c" (21 Sep 2003, 1651 Bytes) of package /linux/privat/old/netbiff-0.9.18.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nbproto.c" see the Fossies "Dox" file reference documentation.

    1 #include "nbproto.h"
    2 #include "util.h"
    3 
    4 #include <stdio.h>
    5 #include <string.h>
    6 #include <stdarg.h>
    7 
    8 static char input[4096];
    9 static const char *status_messages[] = {
   10   "OK",
   11   "NO",
   12   "BAD",
   13   "* UPDATE",
   14   "* RESET",
   15   "* DATAREQUEST"
   16 };
   17 
   18 void netbiff_send(int status, char *fmt, ...) {
   19   va_list ap;
   20 
   21   fputs(status_messages[status], stdout);
   22   fputc(' ', stdout);
   23 
   24   va_start(ap, fmt);
   25   vfprintf(stdout, fmt, ap);
   26   va_end(ap);
   27 
   28   fputc('\n', stdout);
   29   fflush(stdout);
   30 }
   31 
   32 int netbiff_proto_next(char *s[]) {
   33   char *argv[2];
   34   int argc;
   35   int i;
   36 
   37   for(i = 0; i < NETBIFF_PROTO_MAXARGS; i++)
   38     s[i] = NULL;
   39 
   40   while(1) {
   41     if(!fgets(input, 4096, stdin))
   42       return NETBIFF_CMD_EOF;
   43 
   44     util_chomp(input);
   45     argc = util_split(" ", input, argv, 2);
   46     if(!argc)
   47       continue;
   48     
   49     if(!strcasecmp(argv[0], "POLL")) {
   50       if(argc > 1)
   51         s[0] = argv[1];
   52       return NETBIFF_CMD_POLL;
   53     }
   54     else if(!strcasecmp(argv[0], "FOLDER")) {
   55       if(argc < 2) {
   56         netbiff_send(BAD, "Command FOLDER requires an argument");
   57         continue;
   58       }
   59       s[0] = argv[1];
   60       return NETBIFF_CMD_FOLDER;
   61     }
   62     else if(!strcasecmp(argv[0], "QUIT")) {
   63       netbiff_send(OK, "BYE");
   64       fclose(stdout);
   65       fclose(stdin);
   66       return NETBIFF_CMD_QUIT;
   67     }
   68     else if(!strcasecmp(argv[0], "DATARESPONSE")) {
   69       if(argc < 2 || util_split(" ", argv[1], s, 2) < 2) {
   70         netbiff_send(BAD, "Command DATARESPONSE requires at least two"
   71             " arguments.\n");
   72         continue;
   73       }
   74       return NETBIFF_CMD_DATARESPONSE;
   75     }
   76     else {
   77       netbiff_send(BAD, "%s unimplemented.", argv[0]);
   78     }
   79   }
   80 }