]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ipfilter/lib/printfieldhdr.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ipfilter / lib / printfieldhdr.c
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(words, field)
15         wordtab_t *words, *field;
16 {
17         wordtab_t *w;
18         char *s, *t;
19         int i;
20
21         if (field->w_value == -2) {
22                 for (i = 0, w = words; w->w_word != NULL; ) {
23                         if (w->w_value > 0) {
24                                 printfieldhdr(words, w);
25                                 w++;
26                                 if (w->w_value > 0)
27                                         putchar('\t');
28                         } else {
29                                 w++;
30                         }
31                 }
32                 return;
33         }
34
35         for (w = words; w->w_word != NULL; w++) {
36                 if (w->w_value == field->w_value) {
37                         if (w->w_word == field->w_word) {
38                                 s = strdup(w->w_word);
39                         } else {
40                                 s = NULL;
41                         }
42
43                         if ((w->w_word != field->w_word) || (s == NULL)) {
44                                 PRINTF("%s", field->w_word);
45                         } else {
46                                 for (t = s; *t != '\0'; t++) {
47                                         if (ISALPHA(*t) && ISLOWER(*t))
48                                                 *t = TOUPPER(*t);
49                                 }
50                                 PRINTF("%s", s);
51                                 free(s);
52                         }
53                 }
54         }
55 }