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 fp = fopen(
menu->mapp_spec,
"r");
45 if (fp == nullptr) {
48 exit(-1);
49 }
50 while ((fgets(in_buf,
MAXLEN, fp)) !=
nullptr) {
51 if (in_buf[0] == '\0')
52 continue;
53 in_fp_line++;
54
55
56 chrep(in_buf,
'\r',
'\0');
57 chrep(in_buf,
'\n',
'\0');
58 chrep(in_buf,
'\t',
' ');
59 in_buf_p = in_buf;
60 directive = *in_buf_p;
61 in_buf_p++;
62
65 l = strlen(tmp_buf);
66 if (l == 0)
67 continue;
68 if (directive == '#')
69 continue;
70 for (ltr = 0; ltr < 32; ltr++)
71 fltr[ltr] = true;
72 for (ltr = 32; ltr < 127; ltr++)
73 fltr[ltr] = false;
74 fltr['q'] = true;
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 if (*s != ' ')
186 if (!fltr[(int)(uintptr_t)*s]) {
187 ltr = *s;
188 fltr[ltr] = true;
189 break;
190 }
191 s++;
192 }
193 if (*s != '\0') {
194 menu->line[
menu->line_idx]->letter_pos =
195 s -
menu->line[
menu->line_idx]->choice_text;
196 ltr = *s;
197 } else {
198
199
200 for (ltr = '0'; ltr < 127; ltr++)
201 if (fltr[ltr] == false) {
202 fltr[ltr] = true;
203 break;
204 }
205 if (ltr > 126) {
206 Perror(
"Ran out of letters");
207 return 0;
208 }
209 }
210 }
211 menu->line[
menu->line_idx]->choice_letter = ltr;
212 menu->line[
menu->line_idx]->choice_text[1] = ltr;
213 }
215 if (
menu->text_max_len > (
menu->choice_max_len + 6))
217 else
218 menu->cols =
menu->choice_max_len + 6;
221 return 0;
222}
#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.
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
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.