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 | #ifdef HAVE_CONFIG_H1 |
30 | # include "config.h" |
31 | #endif |
32 | |
33 | #include <X11/Xos.h> |
34 | #include <X11/Xlib.h> |
35 | #include <stdio.h> |
36 | #include <ctype.h> |
37 | #include <stdlib.h> |
38 | #include "xmodmap.h" |
39 | |
40 | #define NOTINFILEFILENAME"commandline" "commandline" |
41 | const char *inputFilename = NOTINFILEFILENAME"commandline"; |
42 | int lineno = 0; |
43 | |
44 | void process_file (const char *filename) |
45 | { |
46 | FILE *fp; |
47 | char buffer[BUFSIZ1024]; |
48 | |
49 | |
50 | |
51 | if (!filename) { |
52 | fp = stdin__stdinp; |
53 | inputFilename = "stdin"; |
54 | } else { |
55 | fp = fopen (filename, "r"); |
56 | if (!fp) { |
57 | fprintf (stderr__stderrp, "%s: unable to open file '%s' for reading\n", |
58 | ProgramName, filename); |
59 | parse_errors++; |
60 | return; |
61 | } |
62 | inputFilename = filename; |
63 | } |
64 | |
65 | |
66 | |
67 | |
68 | if (verbose) { |
69 | printf ("! %s:\n", inputFilename); |
70 | } |
71 | |
72 | for (lineno = 0; ; lineno++) { |
73 | buffer[0] = '\0'; |
74 | if (fgets (buffer, BUFSIZ1024, fp) == NULL((void*)0)) |
75 | break; |
76 | |
77 | process_line (buffer); |
78 | } |
79 | |
80 | inputFilename = NOTINFILEFILENAME"commandline"; |
81 | lineno = 0; |
82 | (void) fclose (fp); |
83 | } |
84 | |
85 | |
86 | void process_line (const char *line) |
87 | { |
88 | int len; |
89 | int i; |
90 | char *cp, *buffer; |
91 | |
92 | |
93 | len = strlen(line); |
94 | cp = buffer = strdup(line); |
| Value stored to 'cp' is never read |
95 | if (buffer == NULL((void*)0)) { |
96 | fprintf(stderr__stderrp, "%s: Could not allocate %d bytes\n", ProgramName, len); |
97 | Exit(-1); |
98 | } |
99 | |
100 | for (i = 0; i < len; i++) { |
101 | register char c = buffer[i]; |
102 | if (!(isspace(c) || c == '\n')) break; |
103 | } |
104 | if (i == len) goto done; |
105 | |
106 | cp = &buffer[i]; |
107 | |
108 | if (*cp == '!') goto done; |
109 | len -= (cp - buffer); |
110 | |
111 | |
112 | |
113 | |
114 | for (i = len-1; i >= 0; i--) { |
115 | register char c = cp[i]; |
116 | if (!(isspace(c) || c == '\n')) break; |
117 | } |
118 | if (i >= 0) cp[len = (i+1)] = '\0'; |
119 | |
120 | if (verbose) { |
121 | printf ("! %d: %s\n", lineno+1, cp); |
122 | } |
123 | |
124 | |
125 | handle_line (cp, len); |
126 | |
127 | done: |
128 | free(buffer); |
129 | } |