29 {
30 FILE *fp;
34 char *in_buf_p;
35 unsigned char ltr;
36 bool fltr[127];
37 int directive;
38 int l;
39 char *s;
40 int commands = 0;
41 int choices = 0;
42 int in_fp_line = 0;
44 for (ltr = 0; ltr < 32; ltr++)
45 fltr[ltr] = true;
46 for (ltr = 32; ltr < 127; ltr++)
47 fltr[ltr] = false;
48 fltr['q'] = true;
49 fp = fopen(
menu->mapp_spec,
"r");
50 if (fp == nullptr) {
53 exit(-1);
54 }
55 while ((fgets(in_buf,
MAXLEN, fp)) !=
nullptr) {
56 if (in_buf[0] == '\0')
57 continue;
58 in_fp_line++;
59
60
61 chrep(in_buf,
'\r',
'\0');
62 chrep(in_buf,
'\n',
'\0');
63 chrep(in_buf,
'\t',
' ');
64 in_buf_p = in_buf;
65 directive = *in_buf_p;
66 in_buf_p++;
67
70 l = strlen(tmp_buf);
71 if (l == 0)
72 continue;
73 if (directive == '#')
74 continue;
75 switch (directive) {
77 case '!':
79 break;
81 break;
82
83
85 menu->line[
menu->line_idx]->command_str = strdup(tmp_buf);
86 menu->line[
menu->line_idx]->command_type =
88 s =
menu->line[
menu->line_idx]->raw_text;
90 if (l >
menu->choice_max_len)
91 menu->choice_max_len = l;
92
93
94
95 if (*s == '-' || *s == '_') {
96 s++;
97 ltr = *s;
98 if (ltr > 31 && ltr < 127) {
99 if (!fltr[ltr]) {
100 fltr[ltr] = true;
101 menu->line[
menu->line_idx]->choice_letter = *s;
102 }
103 }
104 s++;
105 }
108 menu->line[
menu->line_idx]->choice_text = strdup(tmp_buf);
111 commands++;
112 break;
114 case ':':
115 if (choices > commands) {
117 "More choices than commands at line %d of",
118 in_fp_line);
122 abend(-1,
"unrecoverable error");
123 }
124 l = strlen(tmp_buf);
126 if (!
menu->title[0]) {
127
130 l += 4;
132 } else {
133
136 sprintf(tmp_str,
137 "2-malloc(%ld bytes) failed menu->line[%d]",
140 }
142 menu->line[
menu->line_idx]->raw_text = strdup(tmp_buf);
144 choices++;
145 }
146 break;
147 case '?':
148 break;
149 case ' ':
150 case '\0':
151 case '\n':
152 break;
153 default:
155 directive, in_fp_line);
159 }
160 }
161 fclose(fp);
163 for (
menu->line_idx = 0;
menu->line_idx <
menu->item_count;
165 menu->line[
menu->line_idx]->letter_pos = 1;
166
167
168 if (
menu->line[
menu->line_idx]->choice_letter !=
'\0') {
169 ltr =
menu->line[
menu->line_idx]->choice_letter;
170 s =
menu->line[
menu->line_idx]->choice_text + 5;
171 while (*s != '\0') {
172 if (*s == ltr) {
173 menu->line[
menu->line_idx]->letter_pos =
174 s -
menu->line[
menu->line_idx]->choice_text;
175 break;
176 }
177 s++;
178 }
179 fltr[ltr] = true;
180 } else {
181 s =
menu->line[
menu->line_idx]->choice_text + 5;
182
183
184 while (*s != '\0') {
185 ltr = *s;
186 if (ltr != ' ') {
187 if (!fltr[ltr]) {
188 fltr[ltr] = true;
189 break;
190 }
191 }
192 s++;
193 }
194 if (*s != '\0') {
195 menu->line[
menu->line_idx]->letter_pos =
196 s -
menu->line[
menu->line_idx]->choice_text;
197 ltr = *s;
198 } else {
199
200
201 for (ltr = '0'; ltr < 127; ltr++)
202 if (fltr[ltr] == false) {
203 fltr[ltr] = true;
204 break;
205 }
206 if (ltr > 126) {
207 Perror(
"Ran out of letters");
208 return 0;
209 }
210 }
211 }
212 menu->line[
menu->line_idx]->choice_letter = ltr;
213 menu->line[
menu->line_idx]->choice_text[1] = ltr;
214 }
216 if (
menu->text_max_len > (
menu->choice_max_len + 6))
218 else
219 menu->cols =
menu->choice_max_len + 6;
222 return 0;
223}
#define min(x, y)
min macro evaluates two expressions, returning least result
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
int Perror(char *)
Display a simple error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
int display_error(char *, char *, char *, char *)
Display an error message window or print to stderr.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
size_t trim(char *)
Trims leading and trailing spaces from string s in place.
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
bool chrep(char *, char, char)
Replaces all occurrences of old_chr in s with new_chr in place.
unsigned int get_command_type(char *)
Get command type from command string.
The Line strutures are attached to the Menu main structure.
The Menu structure is the main data structure for the menu application, containing all the informatio...