📄 lyreadcfg.c
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTFile.h"#include "UCMap.h"#include "LYUtils.h"#include "LYStrings.h"#include "LYStructs.h"#include "LYGlobalDefs.h"#include "LYCharSets.h"#include "LYKeymap.h"#include "LYJump.h"#include "LYGetFile.h"#include "LYCgi.h"#include "LYCurses.h"#include "LYSignal.h"#include "LYBookmark.h"#include "LYReadCFG.h"#ifdef DIRED_SUPPORT#include "LYLocal.h"#endif /* DIRED_SUPPORT */#include "LYexit.h"#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x = NULL;}extern int HTNewsMaxChunk; /* Max news articles before chunking (HTNews.c) */extern int HTNewsChunkSize; /* Number of news articles per chunk (HTNews.c) */PUBLIC BOOLEAN have_read_cfg=FALSE;PUBLIC BOOLEAN LYUseNoviceLineTwo=TRUE;#ifdef VMS#define DISPLAY "DECW$DISPLAY"#else#define DISPLAY "DISPLAY"#endif /* VMS *//* * Translate a TRUE/FALSE field in a string buffer. */PRIVATE int is_true ARGS1( char *, string){ if (!strncasecomp(string,"TRUE",4)) return(TRUE); else return(FALSE);}/* * Find an unescaped colon in a string buffer. */PRIVATE char *find_colon ARGS1( char *, buffer){ char ch, *buf = buffer; if (buf == NULL) return NULL; while ((ch = *buf) != 0) { if (ch == ':') return buf; if (ch == '\\') { buf++; if (*buf == 0) break; } buf++; } return NULL;}/* * Function for freeing the DOWNLOADER and UPLOADER menus list. - FM */PRIVATE void free_item_list NOARGS{ lynx_html_item_type *cur; lynx_html_item_type *next; cur = downloaders; while (cur) { next = cur->next; FREE(cur->name); FREE(cur->command); FREE(cur); cur = next; } downloaders = NULL;#ifdef DIRED_SUPPORT cur = uploaders; while (cur) { next = cur->next; FREE(cur->name); FREE(cur->command); FREE(cur); cur = next; } uploaders = NULL;#endif /* DIRED_SUPPORT */#ifdef USE_EXTERNALS cur = externals; while (cur) { next = cur->next; FREE(cur->name); FREE(cur->command); FREE(cur); cur = next; } externals = NULL;#endif /* USE_EXTERNALS */ return;}/* * Process string buffer fields for DOWNLOADER or UPLOADER menus. */PRIVATE void add_item_to_list ARGS2( char *, buffer, lynx_html_item_type **, list_ptr){ char *colon, *next_colon; lynx_html_item_type *cur_item, *prev_item; /* * Make a linked list */ if (*list_ptr == NULL) { /* * First item. */ cur_item = (lynx_html_item_type *)calloc(sizeof(lynx_html_item_type),1); if (cur_item == NULL) perror("Out of memory in read_cfg"); *list_ptr = cur_item; atexit(free_item_list); } else { /* * Find the last item. */ for (prev_item = *list_ptr; prev_item->next != NULL; prev_item = prev_item->next) ; /* null body */ cur_item = (lynx_html_item_type *)calloc(sizeof(lynx_html_item_type),1); if (cur_item == NULL) perror("Out of memory in read_cfg"); else prev_item->next = cur_item; } cur_item->next = NULL; cur_item->name = NULL; cur_item->command = NULL; cur_item->always_enabled = FALSE; /* * Find first unescaped colon and process fields */ if ((colon = find_colon(buffer)) != NULL) { /* * Process name field */ cur_item->name = (char *)calloc((colon-buffer+1),sizeof(char)); if (cur_item->name == NULL) perror("Out of memory in read_cfg"); LYstrncpy(cur_item->name, buffer, (int)(colon-buffer)); remove_backslashes(cur_item->name); /* * Process TRUE/FALSE field */ if ((next_colon = find_colon(colon+1)) != NULL) { cur_item->command = (char *)calloc(next_colon-colon, sizeof(char)); if (cur_item->command == NULL) perror("Out of memory in read_cfg"); LYstrncpy(cur_item->command, colon+1, (int)(next_colon-(colon+1))); remove_backslashes(cur_item->command); cur_item->always_enabled = is_true(next_colon+1); } }}/* * Function for freeing the PRINTER menus list. - FM */PRIVATE void free_printer_item_list NOARGS{ lynx_printer_item_type *cur = printers; lynx_printer_item_type *next; while (cur) { next = cur->next; FREE(cur->name); FREE(cur->command); FREE(cur); cur = next; } printers = NULL; return;}/* * Process string buffer fields for PRINTER menus. */PRIVATE void add_printer_to_list ARGS2( char *, buffer, lynx_printer_item_type **, list_ptr){ char *colon, *next_colon; lynx_printer_item_type *cur_item, *prev_item; /* * Make a linked list. */ if (*list_ptr == NULL) { /* * First item. */ cur_item = (lynx_printer_item_type *)calloc(sizeof(lynx_printer_item_type),1); if (cur_item == NULL) perror("Out of memory in read_cfg"); *list_ptr = cur_item; atexit(free_printer_item_list); } else { /* * Find the last item. */ for (prev_item = *list_ptr; prev_item->next != NULL; prev_item = prev_item->next) ; /* null body */ cur_item = (lynx_printer_item_type *)calloc(sizeof(lynx_printer_item_type),1); if (cur_item == NULL) perror("Out of memory in read_cfg"); else prev_item->next = cur_item; } cur_item->next = NULL; cur_item->name = NULL; cur_item->command = NULL; cur_item->always_enabled = FALSE; /* * Find first unescaped colon and process fields. */ if ((colon = find_colon(buffer)) != NULL) { /* * Process name field. */ cur_item->name = (char *)calloc((colon-buffer+1), sizeof(char)); if (cur_item->name == NULL) perror("Out of memory in read_cfg"); LYstrncpy(cur_item->name, buffer, (int)(colon-buffer)); remove_backslashes(cur_item->name); /* * Process TRUE/FALSE field. */ if ((next_colon = find_colon(colon+1)) != NULL) { cur_item->command = (char *)calloc(next_colon-colon, sizeof(char)); if (cur_item->command == NULL) perror("Out of memory in read_cfg"); LYstrncpy(cur_item->command, colon+1, (int)(next_colon-(colon+1))); remove_backslashes(cur_item->command); cur_item->always_enabled = is_true(next_colon+1); } /* * Process pagelen field. */ if ((next_colon = find_colon(next_colon+1)) != NULL) { cur_item->pagelen = atoi(next_colon+1); } else { /* default to 66 lines */ cur_item->pagelen = 66; } }}#if defined(USE_COLOR_STYLE) || defined(USE_COLOR_TABLE)#ifdef USE_SLANG#define COLOR_WHITE 7#define COLOR_BLACK 0#endifint default_fg = COLOR_WHITE;int default_bg = COLOR_BLACK;static char *Color_Strings[16] ={ "black", "red", "green", "brown", "blue", "magenta", "cyan", "lightgray", "gray", "brightred", "brightgreen", "yellow", "brightblue", "brightmagenta", "brightcyan", "white"};#ifdef DOSPATH/* * PDCurses (and possibly some other implementations) use a non-ANSI set of * codes for colors. */PRIVATE int ColorCode ARGS1( int, color){ static int map[] = { 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 }; return map[color];}#else#define ColorCode(color) (color)#endif/* * Validator for COLOR fields. */PUBLIC int check_color ARGS2( char *, color, int, the_default){ int i; if (!strcasecomp(color, "default")) return the_default; if (!strcasecomp(color, "nocolor")) return NO_COLOR; for (i = 0; i < 16; i++) { if (!strcasecomp(color, Color_Strings[i])) return ColorCode(i); } return ERR_COLOR;}#endif /* USE_COLOR_STYLE || USE_COLOR_TABLE */#if defined(USE_COLOR_TABLE)/* * Exit routine for failed COLOR parsing. */PRIVATE void exit_with_color_syntax ARGS1( char *, error_line){ unsigned int i; fprintf (stderr, "\Syntax Error parsing COLOR in configuration file:\n\The line must be of the form:\n\COLOR:INTEGER:FOREGROUND:BACKGROUND\n\\n\Here FOREGROUND and BACKGROUND must be one of:\n\The special strings 'nocolor' or 'default', or\n" ); for (i = 0; i < 16; i += 4) { fprintf(stderr, "%16s %16s %16s %16s\n", Color_Strings[i], Color_Strings[i + 1], Color_Strings[i + 2], Color_Strings[i + 3]); } fprintf (stderr, "Offending line:\n%s\n",error_line);#ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL);#ifndef VMS (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */ exit(-1);}/* * Process string buffer fields for COLOR setting. */PRIVATE void parse_color ARGS1( char *, buffer){ int color; char *fg, *bg; char temp[501]; if (strlen(buffer) < sizeof(temp)) strcpy(temp, buffer); else strcpy(temp, "Color config line too long"); /* * We are expecting a line of the form: * INTEGER:FOREGROUND:BACKGROUND */ color = atoi(buffer); if (NULL == (fg = find_colon(buffer))) exit_with_color_syntax(temp); *fg++ = '\0'; if (NULL == (bg = find_colon(fg))) exit_with_color_syntax(temp); *bg++ = '\0';#if defined(USE_SLANG) if ((check_color(fg, default_fg) < 0) || (check_color(bg, default_bg) < 0)) exit_with_color_syntax(temp); SLtt_set_color(color, NULL, fg, bg);#else if (lynx_chg_color(color, check_color(fg, default_fg), check_color(bg, default_bg)) < 0) exit_with_color_syntax(temp);#endif}#endif /* USE_COLOR_TABLE *//* * Process the configuration file (lynx.cfg).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -