xref: /minix3/minix/commands/minix-service/print.c (revision 08cbf5a04d9d252f1eec34cb0fea3101e5fa9b88)
1 
2 #include <stdarg.h>
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <pwd.h>
9 #include <unistd.h>
10 #include <limits.h>
11 #include <lib.h>
12 #include <minix/config.h>
13 #include <minix/com.h>
14 #include <minix/const.h>
15 #include <minix/type.h>
16 #include <minix/ipc.h>
17 #include <minix/rs.h>
18 #include <minix/syslib.h>
19 #include <minix/bitmap.h>
20 #include <paths.h>
21 #include <minix/sef.h>
22 #include <minix/dmap.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <configfile.h>
26 
27 #include <machine/archtypes.h>
28 #include <minix/timers.h>
29 #include <err.h>
30 
31 #include "config.h"
32 #include "proto.h"
33 #include "parse.h"
34 
35 #define MAXDEPTH 10
36 
37 static struct {
38 	const char *field, *str;
39 } configstack[MAXDEPTH];
40 
41 int depth = 0;
42 
43 void printstack(void)
44 {
45 	int i;
46 	for(i = 0; i < depth; i++)
47 		printf("%s %s,", configstack[i].field,
48 			configstack[i].str);
49 }
50 
51 void print(const char *field, const char *str)
52 {
53 	printstack();
54 	printf("%s %s\n", field, str);
55 }
56 
57 void push(const char *field, const char *str)
58 {
59 	assert(depth < MAXDEPTH);
60 	configstack[depth].field = field;
61 	configstack[depth].str = str;
62 	depth++;
63 	printstack();
64 	printf("\n");
65 }
66 
67 int main(int argc, char **argv)
68 {
69 	struct rs_config config;
70 	const char *label;
71 	uint16_t sub_vid, sub_did;
72         int id;
73 
74 	if(argc != 2) {
75 		fprintf(stderr, "usage: %s <config>\n", argv[0]);
76 		return 1;
77 	}
78 
79 	memset(&config, 0, sizeof(config));
80 	if(!(label = parse_config(NULL, 1, argv[1], &config)))
81 		errx(1, "parse_config failed");
82 
83 	push(KW_SERVICE, label);
84 	if(config.type) push(KW_TYPE, config.type);
85 
86 	if(config.descr) push(KW_DESCR, config.descr);
87 	if(config.rs_start.rss_nr_pci_id > 0) {
88 		printstack();
89 		printf("%s %s ", KW_PCI, KW_DEVICE);
90 		for(id = 0; id < config.rs_start.rss_nr_pci_id; id++) {
91 			sub_vid = config.rs_start.rss_pci_id[id].sub_vid;
92 			sub_did = config.rs_start.rss_pci_id[id].sub_did;
93 			/*
94 			 * The PCI driver interprets each of these two fields
95 			 * individually, so we must print them even if just one
96 			 * of them is set.  Correct matching of just one of
97 			 * the fields may be hard to do from a script though,
98 			 * so driver writers are advised to specify either both
99 			 * or neither of these two fields.
100 			 */
101 			if (sub_vid != NO_SUB_VID || sub_did != NO_SUB_DID)
102 				printf("%04X:%04X/%04X:%04X ",
103 					config.rs_start.rss_pci_id[id].vid,
104 					config.rs_start.rss_pci_id[id].did,
105 					sub_vid, sub_did);
106 			else
107 				printf("%04X:%04X ",
108 					config.rs_start.rss_pci_id[id].vid,
109 					config.rs_start.rss_pci_id[id].did);
110 		}
111 		printf("\n");
112 	}
113 }
114 
115