rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

rohrpost.c (1311B)


      1 /* See LICENSE file for copyright and license details */
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 
      6 #include "arg.h"
      7 #include "headers.h"
      8 #include "ind.h"
      9 #include "sieve.h"
     10 #include "util.h"
     11 
     12 char *argv0;
     13 
     14 void usage(void) {
     15 	die("Usage: %s [-hil] cmd [args]\n", argv0);
     16 }
     17 
     18 struct command {
     19 	char *cmd;
     20 	int flags;
     21 	int (*main)(int, char **);
     22 };
     23 
     24 /* The flag whether to output it on the -i(nstall) request. */
     25 enum {
     26 	DONTINSTALL = 0x00,
     27 	DOINSTALL   = 0x01
     28 };
     29 
     30 struct command cmds[] = {
     31 	{"rpheaders", DOINSTALL,   headersmain},
     32 	{"rpsieve",   DONTINSTALL,   sievemain},
     33 	{"rputil",    DOINSTALL,      utilmain},
     34 };
     35 
     36 int main(int argc, char *argv[]) {
     37 	unsigned long int i;
     38 	char *lsl;
     39 
     40 	for (i = 0; i < nelem(cmds); i++) {
     41 		lsl = strrchr(argv[0], '/');
     42 		if (lsl == NULL) {
     43 			lsl = argv[0];
     44 		} else {
     45 			lsl++;
     46 		}
     47 
     48 		if (!strcmp(lsl, cmds[i].cmd))
     49 			return cmds[i].main(argc, argv);
     50 	}
     51 
     52 	ARGBEGIN {
     53 	case 'i':
     54 		for (i = 0; i < nelem(cmds); i++) {
     55 			if (cmds[i].flags & DOINSTALL)
     56 				printf("%s\n", cmds[i].cmd);
     57 		}
     58 		return 0;
     59 	case 'l':
     60 		for (i = 0; i < nelem(cmds); i++)
     61 			printf("%s\n", cmds[i].cmd);
     62 		return 0;
     63 	default:
     64 		usage();
     65 	} ARGEND;
     66 
     67 	if (argc > 0) {
     68 		for (i = 0; i < nelem(cmds); i++) {
     69 			if (!strcmp(argv[0], cmds[i].cmd))
     70 				return cmds[i].main(argc, argv);
     71 		}
     72 	}
     73 
     74 	usage();
     75 }