rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | README | LICENSE

select.c (874B)


      1 /*
      2  * Copy me if you can.
      3  * by 20h
      4  */
      5 
      6 #include <unistd.h>
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <stdarg.h>
     10 
     11 #include "ind.h"
     12 #include "arg.h"
     13 #include "cfg.h"
     14 #include "llist.h"
     15 #include "select.h"
     16 
     17 void
     18 selectusage(char *argv0)
     19 {
     20 	die("usage: %s [-h] [-c cfg] [mailbox]\n", argv0);
     21 }
     22 
     23 int
     24 selectmain(int argc, char *argv[])
     25 {
     26 	config_t *cfg;
     27 	llistelem_t *result;
     28 	char *cfgn, *argv0;
     29 
     30 	cfgn = NULL;
     31 
     32 	ARGBEGIN(argv0) {
     33 	case 'c':
     34 		cfgn = EARGF(selectusage(argv0));
     35 		break;
     36 	default:
     37 		selectusage(argv0);
     38 	} ARGEND;
     39 
     40 	cfg = config_init(cfgn);
     41 
     42 	if (argc > 0) {
     43 		config_set(cfg, "selected", argv[0]);
     44 		printf("%s now selected.\n", argv[0]);
     45 		config_stop(cfg);
     46 	} else {
     47 		result = config_get(cfg, "selected");
     48 		if (result == NULL) {
     49 			fprintf(stderr, "No mailbox selected.\n");
     50 			return 1;
     51 		}
     52 		printf("%s\n", (char *)result->data);
     53 	}
     54 
     55 	return 0;
     56 }
     57