rohrpost.c - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       rohrpost.c (2303B)
       ---
            1 /*
            2  * Copy me if you can.
            3  * by 20h
            4  */
            5 
            6 #include <unistd.h>
            7 #include <stdio.h>
            8 #include <stdarg.h>
            9 #include <stdlib.h>
           10 #include <string.h>
           11 
           12 #include "ind.h"
           13 #include "arg.h"
           14 #include "cfg.h"
           15 #include "mark.h"
           16 #include "cur.h"
           17 #include "select.h"
           18 #include "sieve.h"
           19 #include "folder.h"
           20 #include "inc.h"
           21 #include "stats.h"
           22 #include "capability.h"
           23 #include "pick.h"
           24 #include "flag.h"
           25 #include "copy.h"
           26 #include "remove.h"
           27 #include "scan.h"
           28 #include "view.h"
           29 #include "part.h"
           30 #include "add.h"
           31 #include "ids.h"
           32 #include "mime.h"
           33 #include "util.h"
           34 #include "path.h"
           35 
           36 void
           37 usage(char *argv0)
           38 {
           39         die("usage: %s [-hil] cmd [args] [range]\n", argv0);
           40 }
           41 
           42 struct command {
           43         char *cmd;
           44         int flags;
           45         int (*main)(int, char **);
           46 };
           47 
           48 /* The flag whether to output it on the -i(nstall) request. */
           49 enum {
           50         DONTINSTALL = 0x00,
           51         DOINSTALL = 0x01
           52 };
           53 
           54 struct command cmds[] = {
           55         {"rpadd", DOINSTALL, addmain},
           56         {"rpcfg", DOINSTALL, configmain},
           57         {"rpcp", DOINSTALL, copymain},
           58         {"rpcap", DOINSTALL, capabilitymain},
           59         {"rpflag", DONTINSTALL, flagmain},
           60         {"rpfold", DOINSTALL, foldermain},
           61         {"rpids", DOINSTALL, idsmain},
           62         {"rpmv", DOINSTALL, movemain},
           63         {"rppart", DOINSTALL, partmain},
           64         {"rppick", DOINSTALL, pickmain},
           65         {"rpscan", DONTINSTALL, scanmain},
           66         {"rpsieve", DOINSTALL, sievemain},
           67         {"rpstats", DOINSTALL, statsmain},
           68         {"rputil", DOINSTALL, utilmain},
           69         {"rpcur", DOINSTALL, curmain},
           70         {"rpinc", DONTINSTALL, incmain},
           71         {"rpmark", DOINSTALL, markmain},
           72         {"rprm", DOINSTALL, removemain},
           73         {"rpsel", DOINSTALL, selectmain},
           74         {"rpview", DONTINSTALL, viewmain},
           75         {"rppath", DOINSTALL, pathmain},
           76 };
           77 
           78 int
           79 main(int argc, char *argv[])
           80 {
           81         int i;
           82         char *lsl, *argv0;
           83 
           84         for (i = 0; i < nelem(cmds); i++) {
           85                 lsl = strrchr(argv[0], '/');
           86                 if (lsl == NULL) {
           87                         lsl = argv[0];
           88                 } else {
           89                         lsl++;
           90                 }
           91 
           92                 if (!strcmp(lsl, cmds[i].cmd))
           93                         return cmds[i].main(argc, argv);
           94         }
           95 
           96         ARGBEGIN(argv0) {
           97         case 'i':
           98                 for (i = 0; i < nelem(cmds); i++) {
           99                         if (cmds[i].flags & DOINSTALL)
          100                                 printf("%s\n", cmds[i].cmd);
          101                 }
          102                 return 0;
          103         case 'l':
          104                 for (i = 0; i < nelem(cmds); i++)
          105                         printf("%s\n", cmds[i].cmd);
          106                 return 0;
          107         default:
          108                 usage(argv0);
          109         } ARGEND;
          110 
          111         if (argc > 0) {
          112                 for (i = 0; i < nelem(cmds); i++) {
          113                         if (!strcmp(argv[0], cmds[i].cmd))
          114                                 return cmds[i].main(argc, argv);
          115                 }
          116         }
          117 
          118         usage(argv0);
          119 
          120         return 1;
          121 }
          122