xref: /freebsd/sbin/ipf/libipf/printfieldhdr.c (revision ccb59683b98360afaf5b5bb641a68fea22c68d0b)
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: printfieldhdr.c,v 1.5.2.3 2012/07/22 08:04:24 darren_r Exp $
7  */
8 
9 #include "ipf.h"
10 #include <ctype.h>
11 
12 
13 void
14 printfieldhdr(wordtab_t *words, wordtab_t *field)
15 {
16 	wordtab_t *w;
17 	char *s, *t;
18 
19 	if (field->w_value == -2) {
20 		for (w = words; w->w_word != NULL; ) {
21 			if (w->w_value > 0) {
22 				printfieldhdr(words, w);
23 				w++;
24 				if (w->w_value > 0)
25 					putchar('\t');
26 			} else {
27 				w++;
28 			}
29 		}
30 		return;
31 	}
32 
33 	for (w = words; w->w_word != NULL; w++) {
34 		if (w->w_value == field->w_value) {
35 			if (w->w_word == field->w_word) {
36 				s = strdup(w->w_word);
37 			} else {
38 				s = NULL;
39 			}
40 
41 			if ((w->w_word != field->w_word) || (s == NULL)) {
42 				PRINTF("%s", field->w_word);
43 			} else {
44 				for (t = s; *t != '\0'; t++) {
45 					if (ISALPHA(*t) && ISLOWER(*t))
46 						*t = TOUPPER(*t);
47 				}
48 				PRINTF("%s", s);
49 				free(s);
50 			}
51 		}
52 	}
53 }
54