File: mkmsg.c

package info (click to toggle)
ppxp 0.99120923-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,812 kB
  • ctags: 3,704
  • sloc: ansic: 24,532; tcl: 3,992; makefile: 517; sh: 80
file content (115 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

#include <version.h>

#define	GENCAT_TYPE	0

#if	__GLIBC__ >= 2
#undef	GENCAT_TYPE
#define	GENCAT_TYPE	1
#endif

#if	defined(__OpenBSD__) || defined(__NetBSD__)
#undef	GENCAT_TYPE
#define	GENCAT_TYPE	2
#endif

#if	GENCAT_TYPE == 2

#define	GENCAT_HEADER	"-h"

void
output(char *name, char *buff)
{
    static int num=0;

    if (!buff) {
	printf("$set 1 #%s_\n", name);
	name = "VERSION";
	buff = VERSION;
    }
    printf("%d %s\n", ++ num, buff);
}
#endif

#if	GENCAT_TYPE == 1

#define	GENCAT_HEADER	"-H"

void
output(char *name, char *buff)
{
    if (!buff) {
	printf("$set %s_\n\n", name);
	name = "VERSION";
	buff = VERSION;
    }
    printf("%s %s\n", name, buff);
}
#endif

#if	GENCAT_TYPE == 0

#define	GENCAT_HEADER	"-h"

void
output(char *name, char *buff)
{
    if (!buff) {
	printf("$set 1 #%s_\n\n", name);
	name = "VERSION";
	buff = VERSION;
    }
    printf("$ #%s\n# %s\n", name, buff);
}
#endif

int
main(int argc, char *argv[])
{
    char buff[8192], line[1024], name[100];
    char *p, *ret;
    unsigned sys;
    int defmsg;

    if (argc > 1) {
	if (argc == 2 && !strcmp(argv[1], "-print-hflag")) {
	    printf(GENCAT_HEADER"\n");
	    exit(0);
	}
	output(argv[1], NULL);
	defmsg = 0;
    } else {
	printf("/*\n"
	       " * Generated automatically by mkmsg\n"
	       " * DO NOT EDIT!!\n"
	       " */\n\n"
	       "static const char *strMsg[]={\n");
	defmsg = 1;
    }
    buff[0] = '\0';
    do {
	if ((ret = fgets(line, sizeof(line), stdin)) != NULL)
	    if ((p = strpbrk(line, "\r\n")) != NULL) *p = '\0';
	if (ret == NULL || (line[0] == '$' && strchr("\t ", line[1]))) {
	    if (buff[0]) {
		if (defmsg) {
		    printf("    \"%s\",\n", buff);
		    defmsg ++;
		} else
		    output(name, buff);
	    }
	    if (line[0] == '$') {
		p = &line[2];
		while (*p && strchr("\t ", *p)) p ++;
		strncpy(name, p, sizeof(name) - 1);
	    }
	    buff[0] = '\0';
	} else strcat(buff, line);
    } while (ret);
    if (defmsg) printf("};\n\n#define	MAX_STRMSGS %d\n", defmsg);
    return(0);
}