Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/miscutils/man.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/miscutils/man.c
r3232 r3621 67 67 68 68 line = xmalloc_open_zipped_read_close(man_filename, NULL); 69 if (!line || strncmp(line, ".so ", 4) != 0) {69 if (!line || !is_prefixed_with(line, ".so ")) { 70 70 free(line); 71 71 goto ordinary_manpage; … … 103 103 ordinary_manpage: 104 104 close(STDIN_FILENO); 105 open_zipped(man_filename ); /* guaranteed to use fd 0 (STDIN_FILENO) */105 open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */ 106 106 /* "2>&1" is added so that nroff errors are shown in pager too. 107 107 * Otherwise it may show just empty screen */ 108 108 cmd = xasprintf( 109 man ? "gtbl | nroff -Tlatin1 -mandoc 2>&1 | %s" 109 /* replaced -Tlatin1 with -Tascii for non-UTF8 displays */ 110 man ? "gtbl | nroff -Tascii -mandoc 2>&1 | %s" 110 111 : "%s", 111 112 pager); … … 147 148 } 148 149 150 static char **add_MANPATH(char **man_path_list, int *count_mp, char *path) 151 { 152 if (path) while (*path) { 153 char *next_path; 154 char **path_element; 155 156 next_path = strchr(path, ':'); 157 if (next_path) { 158 if (next_path == path) /* "::"? */ 159 goto next; 160 *next_path = '\0'; 161 } 162 /* Do we already have path? */ 163 path_element = man_path_list; 164 if (path_element) while (*path_element) { 165 if (strcmp(*path_element, path) == 0) 166 goto skip; 167 path_element++; 168 } 169 man_path_list = xrealloc_vector(man_path_list, 4, *count_mp); 170 man_path_list[*count_mp] = xstrdup(path); 171 (*count_mp)++; 172 /* man_path_list is NULL terminated */ 173 /* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */ 174 skip: 175 if (!next_path) 176 break; 177 /* "path" may be a result of getenv(), be nice and don't mangle it */ 178 *next_path = ':'; 179 next: 180 path = next_path + 1; 181 } 182 return man_path_list; 183 } 184 149 185 int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 150 186 int man_main(int argc UNUSED_PARAM, char **argv) 151 187 { 152 188 parser_t *parser; 153 const char *pager; 154 char **man_path_list; 189 const char *pager = ENABLE_LESS ? "less" : "more"; 155 190 char *sec_list; 156 191 char *cur_path, *cur_sect; 157 int count_mp, cur_mp; 192 char **man_path_list; 193 int count_mp; 194 int cur_mp; 158 195 int opt, not_found; 159 196 char *token[2]; … … 163 200 argv += optind; 164 201 165 sec_list = xstrdup(" 1:2:3:4:5:6:7:8:9");166 /* Last valid man_path_list[] is [0x10] */ 202 sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); 203 167 204 count_mp = 0; 168 man_path_list = xzalloc(0x11 * sizeof(man_path_list[0])); 169 man_path_list[0] = getenv("MANPATH"); 170 if (!man_path_list[0]) /* default, may be overridden by /etc/man.conf */ 205 man_path_list = add_MANPATH(NULL, &count_mp, 206 getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ 207 ); 208 if (!man_path_list) { 209 /* default, may be overridden by /etc/man.conf */ 210 man_path_list = xzalloc(2 * sizeof(man_path_list[0])); 171 211 man_path_list[0] = (char*)"/usr/man"; 172 else 173 count_mp++; 174 pager = getenv("MANPAGER"); 175 if (!pager) { 176 pager = getenv("PAGER"); 177 if (!pager) 178 pager = "more"; 212 /* count_mp stays 0. 213 * Thus, man.conf will overwrite man_path_list[0] 214 * if a path is defined there. 215 */ 179 216 } 180 217 … … 191 228 if (!token[1]) 192 229 continue; 230 if (strcmp("DEFINE", token[0]) == 0) { 231 if (is_prefixed_with("pager", token[1])) { 232 pager = xstrdup(skip_whitespace(token[1]) + 5); 233 } 234 } else 193 235 if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */ 194 236 || strcmp("MANDATORY_MANPATH", token[0]) == 0 195 237 ) { 196 char *path = token[1]; 197 while (*path) { 198 char *next_path; 199 char **path_element; 200 201 next_path = strchr(path, ':'); 202 if (next_path) { 203 *next_path = '\0'; 204 if (next_path++ == path) /* "::"? */ 205 goto next; 206 } 207 /* Do we already have path? */ 208 path_element = man_path_list; 209 while (*path_element) { 210 if (strcmp(*path_element, path) == 0) 211 goto skip; 212 path_element++; 213 } 214 man_path_list = xrealloc_vector(man_path_list, 4, count_mp); 215 man_path_list[count_mp] = xstrdup(path); 216 count_mp++; 217 /* man_path_list is NULL terminated */ 218 /*man_path_list[count_mp] = NULL; - xrealloc_vector did it */ 219 skip: 220 if (!next_path) 221 break; 222 next: 223 path = next_path; 224 } 238 man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]); 225 239 } 226 240 if (strcmp("MANSECT", token[0]) == 0) { … … 230 244 } 231 245 config_close(parser); 246 247 { 248 /* environment overrides setting from man.config */ 249 char *env_pager = getenv("MANPAGER"); 250 if (!env_pager) 251 env_pager = getenv("PAGER"); 252 if (env_pager) 253 pager = env_pager; 254 } 232 255 233 256 not_found = 0;
Note:
See TracChangeset
for help on using the changeset viewer.