rp

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

headers.c (775B)


      1 /* See LICENSE file for copyright and license details */
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 #include <strings.h>
      6 
      7 #include "arg.h"
      8 #include "ind.h"
      9 
     10 char *argv0;
     11 
     12 void headersusage(void) {
     13 	die("Usage: %s [-v] [header [header [...]]]\n", argv0);
     14 }
     15 
     16 int headersmain(int argc, char *argv[]) {
     17 	int i, vflag = 0;
     18 	char l[MAXLINESIZE];
     19 
     20 	ARGBEGIN {
     21 	case 'v':
     22 		vflag = 1;
     23 		break;
     24 	default:
     25 		headersusage();
     26 	} ARGEND;
     27 
     28 	if (argc < 1)
     29 		headersusage();
     30 
     31 	while (fgets(l, sizeof(l), stdin)) {
     32 		if (!strncmp("\n", l, 1))
     33 			break;
     34 		for (i = 0; i < argc; i++) {
     35 			if (!strncasecmp(l, argv[i], strlen(argv[i]))) {
     36 				if (vflag) {
     37 					printf("%s: %s", argv[i], l + strlen(argv[i])+2);
     38 				} else {
     39 					printf("%s", l + strlen(argv[i])+2);
     40 				}
     41 			}
     42 		}
     43 	}
     44 
     45 	return 0;
     46 }