xref: /netbsd-src/external/bsd/ipf/dist/lib/printfieldhdr.c (revision 64a05fe87b1061240121b2919b3f1dcb35684da5)
1*64a05fe8Schristos /*	$NetBSD: printfieldhdr.c,v 1.3 2013/10/20 03:09:11 christos Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
813885a66Sdarrenr  * Id: printfieldhdr.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos #include <ctype.h>
13bc4097aaSchristos 
14bc4097aaSchristos 
15bc4097aaSchristos void
printfieldhdr(words,field)16bc4097aaSchristos printfieldhdr(words, field)
17bc4097aaSchristos 	wordtab_t *words, *field;
18bc4097aaSchristos {
19bc4097aaSchristos 	wordtab_t *w;
20bc4097aaSchristos 	char *s, *t;
21bc4097aaSchristos 
22bc4097aaSchristos 	if (field->w_value == -2) {
23*64a05fe8Schristos 		for (w = words; w->w_word != NULL; ) {
24bc4097aaSchristos 			if (w->w_value > 0) {
25bc4097aaSchristos 				printfieldhdr(words, w);
26bc4097aaSchristos 				w++;
27bc4097aaSchristos 				if (w->w_value > 0)
28bc4097aaSchristos 					putchar('\t');
29bc4097aaSchristos 			} else {
30bc4097aaSchristos 				w++;
31bc4097aaSchristos 			}
32bc4097aaSchristos 		}
33bc4097aaSchristos 		return;
34bc4097aaSchristos 	}
35bc4097aaSchristos 
36bc4097aaSchristos 	for (w = words; w->w_word != NULL; w++) {
37bc4097aaSchristos 		if (w->w_value == field->w_value) {
38bc4097aaSchristos 			if (w->w_word == field->w_word) {
39bc4097aaSchristos 				s = strdup(w->w_word);
40bc4097aaSchristos 			} else {
41bc4097aaSchristos 				s = NULL;
42bc4097aaSchristos 			}
43bc4097aaSchristos 
44bc4097aaSchristos 			if ((w->w_word != field->w_word) || (s == NULL)) {
45bc4097aaSchristos 				PRINTF("%s", field->w_word);
46bc4097aaSchristos 			} else {
47bc4097aaSchristos 				for (t = s; *t != '\0'; t++) {
48bc4097aaSchristos 					if (ISALPHA(*t) && ISLOWER(*t))
49bc4097aaSchristos 						*t = TOUPPER(*t);
50bc4097aaSchristos 				}
51bc4097aaSchristos 				PRINTF("%s", s);
52bc4097aaSchristos 				free(s);
53bc4097aaSchristos 			}
54bc4097aaSchristos 		}
55bc4097aaSchristos 	}
56bc4097aaSchristos }
57