rc.c (48663B)
1 /* $Id$ */ 2 /* 3 * Initialization file etc. 4 */ 5 #include "fm.h" 6 #include "myctype.h" 7 #include "proto.h" 8 #include <stdio.h> 9 #include <errno.h> 10 #include "parsetag.h" 11 #include "local.h" 12 #include <stdlib.h> 13 14 struct param_ptr { 15 char *name; 16 int type; 17 int inputtype; 18 void *varptr; 19 char *comment; 20 void *select; 21 }; 22 23 struct param_section { 24 char *name; 25 struct param_ptr *params; 26 }; 27 28 struct rc_search_table { 29 struct param_ptr *param; 30 short uniq_pos; 31 }; 32 33 static struct rc_search_table *RC_search_table; 34 static int RC_table_size; 35 36 #define P_INT 0 37 #define P_SHORT 1 38 #define P_CHARINT 2 39 #define P_CHAR 3 40 #define P_STRING 4 41 #if defined(USE_SSL) && defined(USE_SSL_VERIFY) 42 #define P_SSLPATH 5 43 #endif 44 #ifdef USE_COLOR 45 #define P_COLOR 6 46 #endif 47 #ifdef USE_M17N 48 #define P_CODE 7 49 #endif 50 #define P_PIXELS 8 51 #define P_NZINT 9 52 #define P_SCALE 10 53 54 /* FIXME: gettextize here */ 55 #ifdef USE_M17N 56 static wc_ces OptionCharset = WC_CES_US_ASCII; /* FIXME: charset of source code */ 57 static int OptionEncode = FALSE; 58 #endif 59 60 #define CMT_HELPER N_("External Viewer Setup") 61 #define CMT_TABSTOP N_("Tab width in characters") 62 #define CMT_INDENT_INCR N_("Indent for HTML rendering") 63 #define CMT_PIXEL_PER_CHAR N_("Number of pixels per character (4.0...32.0)") 64 #define CMT_PIXEL_PER_LINE N_("Number of pixels per line (4.0...64.0)") 65 #define CMT_PAGERLINE N_("Number of remembered lines when used as a pager") 66 #define CMT_HISTORY N_("Use URL history") 67 #define CMT_HISTSIZE N_("Number of remembered URL") 68 #define CMT_SAVEHIST N_("Save URL history") 69 #define CMT_FRAME N_("Render frames automatically") 70 #define CMT_ARGV_IS_URL N_("Treat argument without scheme as URL") 71 #define CMT_TSELF N_("Use _self as default target") 72 #define CMT_OPEN_TAB_BLANK N_("Open link on new tab if target is _blank or _new") 73 #define CMT_OPEN_TAB_DL_LIST N_("Open download list panel on new tab") 74 #define CMT_DISPLINK N_("Display link URL automatically") 75 #define CMT_DISPLINKNUMBER N_("Display link numbers") 76 #define CMT_DECODE_URL N_("Display decoded URL") 77 #define CMT_DISPLINEINFO N_("Display current line number") 78 #define CMT_DISP_IMAGE N_("Display inline images") 79 #define CMT_PSEUDO_INLINES N_("Display pseudo-ALTs for inline images with no ALT or TITLE string") 80 #ifdef USE_IMAGE 81 #define CMT_AUTO_IMAGE N_("Load inline images automatically") 82 #define CMT_MAX_LOAD_IMAGE N_("Maximum processes for parallel image loading") 83 #define CMT_EXT_IMAGE_VIEWER N_("Use external image viewer") 84 #define CMT_IMAGE_SCALE N_("Scale of image (%)") 85 #define CMT_IMGDISPLAY N_("External command to display image") 86 #define CMT_IMAGE_MAP_LIST N_("Use link list of image map") 87 #endif 88 #define CMT_MULTICOL N_("Display file names in multi-column format") 89 #define CMT_ALT_ENTITY N_("Use ASCII equivalents to display entities") 90 #define CMT_GRAPHIC_CHAR N_("Character type for border of table and menu") 91 #define CMT_FOLD_TEXTAREA N_("Fold lines in TEXTAREA") 92 #define CMT_DISP_INS_DEL N_("Display INS, DEL, S and STRIKE element") 93 #define CMT_COLOR N_("Display with color") 94 #define CMT_B_COLOR N_("Color of normal character") 95 #define CMT_A_COLOR N_("Color of anchor") 96 #define CMT_I_COLOR N_("Color of image link") 97 #define CMT_F_COLOR N_("Color of form") 98 #define CMT_ACTIVE_STYLE N_("Enable coloring of active link") 99 #define CMT_C_COLOR N_("Color of currently active link") 100 #define CMT_VISITED_ANCHOR N_("Use visited link color") 101 #define CMT_V_COLOR N_("Color of visited link") 102 #define CMT_BG_COLOR N_("Color of background") 103 #define CMT_MARK_COLOR N_("Color of mark") 104 #define CMT_USE_PROXY N_("Use proxy") 105 #define CMT_HTTP_PROXY N_("URL of HTTP proxy host") 106 #ifdef USE_SSL 107 #define CMT_HTTPS_PROXY N_("URL of HTTPS proxy host") 108 #endif /* USE_SSL */ 109 #ifdef USE_GOPHER 110 #define CMT_GOPHER_PROXY N_("URL of GOPHER proxy host") 111 #endif /* USE_GOPHER */ 112 #define CMT_FTP_PROXY N_("URL of FTP proxy host") 113 #define CMT_NO_PROXY N_("Domains to be accessed directly (no proxy)") 114 #define CMT_NOPROXY_NETADDR N_("Check noproxy by network address") 115 #define CMT_NO_CACHE N_("Disable cache") 116 #ifdef USE_NNTP 117 #define CMT_NNTP_SERVER N_("News server") 118 #define CMT_NNTP_MODE N_("Mode of news server") 119 #define CMT_MAX_NEWS N_("Number of news messages") 120 #endif 121 #define CMT_DNS_ORDER N_("Order of name resolution") 122 #define CMT_DROOT N_("Directory corresponding to / (document root)") 123 #define CMT_PDROOT N_("Directory corresponding to /~user") 124 #define CMT_CGIBIN N_("Directory corresponding to /cgi-bin") 125 #define CMT_CONFIRM_QQ N_("Confirm when quitting with q") 126 #define CMT_CLOSE_TAB_BACK N_("Close tab if buffer is last when back") 127 #ifdef USE_MARK 128 #define CMT_USE_MARK N_("Enable mark operations") 129 #endif 130 #define CMT_EMACS_LIKE_LINEEDIT N_("Enable Emacs-style line editing") 131 #define CMT_VI_PREC_NUM N_("Enable vi-like numeric prefix") 132 #define CMT_LABEL_TOPLINE N_("Move cursor to top line when going to label") 133 #define CMT_NEXTPAGE_TOPLINE N_("Move cursor to top line when moving to next page") 134 #define CMT_FOLD_LINE N_("Fold lines of plain text file") 135 #define CMT_SHOW_NUM N_("Show line numbers") 136 #define CMT_SHOW_SRCH_STR N_("Show search string") 137 #define CMT_MIMETYPES N_("List of mime.types files") 138 #define CMT_MAILCAP N_("List of mailcap files") 139 #define CMT_URIMETHODMAP N_("List of urimethodmap files") 140 #define CMT_EDITOR N_("Editor") 141 #define CMT_MAILER N_("Mailer") 142 #define CMT_MAILTO_OPTIONS N_("How to call Mailer for mailto URLs with options") 143 #define CMT_EXTBRZ N_("External Browser") 144 #define CMT_EXTBRZ2 N_("Second External Browser") 145 #define CMT_EXTBRZ3 N_("Third External Browser") 146 #define CMT_DISABLE_SECRET_SECURITY_CHECK N_("Disable secret file security check") 147 #define CMT_PASSWDFILE N_("Password file") 148 #define CMT_PRE_FORM_FILE N_("File for setting form on loading") 149 #define CMT_FTPPASS N_("Password for anonymous FTP (your mail address)") 150 #define CMT_FTPPASS_HOSTNAMEGEN N_("Generate domain part of password for FTP") 151 #define CMT_USERAGENT N_("User-Agent identification string") 152 #define CMT_ACCEPTENCODING N_("Accept-Encoding header") 153 #define CMT_ACCEPTMEDIA N_("Accept header") 154 #define CMT_ACCEPTLANG N_("Accept-Language header") 155 #define CMT_MARK_ALL_PAGES N_("Treat URL-like strings as links in all pages") 156 #define CMT_WRAP N_("Wrap search") 157 #define CMT_VIEW_UNSEENOBJECTS N_("Display unseen objects (e.g. bgimage tag)") 158 #define CMT_AUTO_UNCOMPRESS N_("Uncompress compressed data automatically when downloading") 159 #ifdef __EMX__ 160 #define CMT_BGEXTVIEW N_("Run external viewer in a separate session") 161 #else 162 #define CMT_BGEXTVIEW N_("Run external viewer in the background") 163 #endif 164 #define CMT_EXT_DIRLIST N_("Use external program for directory listing") 165 #define CMT_DIRLIST_CMD N_("URL of directory listing command") 166 #ifdef USE_DICT 167 #define CMT_USE_DICTCOMMAND N_("Enable dictionary lookup through CGI") 168 #define CMT_DICTCOMMAND N_("URL of dictionary lookup command") 169 #endif /* USE_DICT */ 170 #define CMT_IGNORE_NULL_IMG_ALT N_("Display link name for images lacking ALT") 171 #define CMT_IFILE N_("Index file for directories") 172 #define CMT_RETRY_HTTP N_("Prepend http:// to URL automatically") 173 #define CMT_DEFAULT_URL N_("Default value for open-URL command") 174 #define CMT_DECODE_CTE N_("Decode Content-Transfer-Encoding when saving") 175 #define CMT_PRESERVE_TIMESTAMP N_("Preserve timestamp when saving") 176 #ifdef USE_MOUSE 177 #define CMT_MOUSE N_("Enable mouse") 178 #define CMT_REVERSE_MOUSE N_("Scroll in reverse direction of mouse drag") 179 #define CMT_RELATIVE_WHEEL_SCROLL N_("Behavior of wheel scroll speed") 180 #define CMT_RELATIVE_WHEEL_SCROLL_RATIO N_("(A only)Scroll by # (%) of screen") 181 #define CMT_FIXED_WHEEL_SCROLL_COUNT N_("(B only)Scroll by # lines") 182 #endif /* USE_MOUSE */ 183 #define CMT_CLEAR_BUF N_("Free memory of undisplayed buffers") 184 #define CMT_NOSENDREFERER N_("Suppress `Referer:' header") 185 #define CMT_IGNORE_CASE N_("Search case-insensitively") 186 #define CMT_USE_LESSOPEN N_("Use LESSOPEN") 187 #ifdef USE_SSL 188 #ifdef USE_SSL_VERIFY 189 #define CMT_SSL_VERIFY_SERVER N_("Perform SSL server verification") 190 #define CMT_SSL_CERT_FILE N_("PEM encoded certificate file of client") 191 #define CMT_SSL_KEY_FILE N_("PEM encoded private key file of client") 192 #define CMT_SSL_CA_PATH N_("Path to directory for PEM encoded certificates of CAs") 193 #define CMT_SSL_CA_FILE N_("File consisting of PEM encoded certificates of CAs") 194 #endif /* USE_SSL_VERIFY */ 195 #define CMT_SSL_FORBID_METHOD N_("List of forbidden SSL methods (2: SSLv2, 3: SSLv3, t:TLSv1)") 196 #endif /* USE_SSL */ 197 #ifdef USE_COOKIE 198 #define CMT_USECOOKIE N_("Enable cookie processing") 199 #define CMT_SHOWCOOKIE N_("Print a message when receiving a cookie") 200 #define CMT_ACCEPTCOOKIE N_("Accept cookies") 201 #define CMT_ACCEPTBADCOOKIE N_("Action to be taken on invalid cookie") 202 #define CMT_COOKIE_REJECT_DOMAINS N_("Domains to reject cookies from") 203 #define CMT_COOKIE_ACCEPT_DOMAINS N_("Domains to accept cookies from") 204 #define CMT_COOKIE_AVOID_WONG_NUMBER_OF_DOTS N_("Domains to avoid [wrong number of dots]") 205 #endif 206 #define CMT_FOLLOW_REDIRECTION N_("Number of redirections to follow") 207 #define CMT_META_REFRESH N_("Enable processing of meta-refresh tag") 208 209 #ifdef USE_MIGEMO 210 #define CMT_USE_MIGEMO N_("Enable Migemo (Roma-ji search)") 211 #define CMT_MIGEMO_COMMAND N_("Migemo command") 212 #endif /* USE_MIGEMO */ 213 214 #ifdef USE_M17N 215 #define CMT_DISPLAY_CHARSET N_("Display charset") 216 #define CMT_DOCUMENT_CHARSET N_("Default document charset") 217 #define CMT_AUTO_DETECT N_("Automatic charset detect when loading") 218 #define CMT_SYSTEM_CHARSET N_("System charset") 219 #define CMT_FOLLOW_LOCALE N_("System charset follows locale(LC_CTYPE)") 220 #define CMT_EXT_HALFDUMP N_("Output halfdump with display charset") 221 #define CMT_USE_WIDE N_("Use multi column characters") 222 #define CMT_USE_COMBINING N_("Use combining characters") 223 #define CMT_EAST_ASIAN_WIDTH N_("Use double width for some Unicode characters") 224 #define CMT_USE_LANGUAGE_TAG N_("Use Unicode language tags") 225 #define CMT_UCS_CONV N_("Charset conversion using Unicode map") 226 #define CMT_PRE_CONV N_("Charset conversion when loading") 227 #define CMT_SEARCH_CONV N_("Adjust search string for document charset") 228 #define CMT_FIX_WIDTH_CONV N_("Fix character width when conversion") 229 #define CMT_USE_GB12345_MAP N_("Use GB 12345 Unicode map instead of GB 2312's") 230 #define CMT_USE_JISX0201 N_("Use JIS X 0201 Roman for ISO-2022-JP") 231 #define CMT_USE_JISC6226 N_("Use JIS C 6226:1978 for ISO-2022-JP") 232 #define CMT_USE_JISX0201K N_("Use JIS X 0201 Katakana") 233 #define CMT_USE_JISX0212 N_("Use JIS X 0212:1990 (Supplemental Kanji)") 234 #define CMT_USE_JISX0213 N_("Use JIS X 0213:2000 (2000JIS)") 235 #define CMT_STRICT_ISO2022 N_("Strict ISO-2022-JP/KR/CN") 236 #define CMT_GB18030_AS_UCS N_("Treat 4 bytes char. of GB18030 as Unicode") 237 #define CMT_SIMPLE_PRESERVE_SPACE N_("Simple Preserve space") 238 #endif 239 240 #define CMT_KEYMAP_FILE N_("keymap file") 241 242 #define PI_TEXT 0 243 #define PI_ONOFF 1 244 #define PI_SEL_C 2 245 #ifdef USE_M17N 246 #define PI_CODE 3 247 #endif 248 249 struct sel_c { 250 int value; 251 char *cvalue; 252 char *text; 253 }; 254 255 #ifdef USE_COLOR 256 static struct sel_c colorstr[] = { 257 {0, "black", N_("black")}, 258 {1, "red", N_("red")}, 259 {2, "green", N_("green")}, 260 {3, "yellow", N_("yellow")}, 261 {4, "blue", N_("blue")}, 262 {5, "magenta", N_("magenta")}, 263 {6, "cyan", N_("cyan")}, 264 {7, "white", N_("white")}, 265 {8, "terminal", N_("terminal")}, 266 {0, NULL, NULL} 267 }; 268 #endif /* USE_COLOR */ 269 270 #if 1 /* ANSI-C ? */ 271 #define N_STR(x) #x 272 #define N_S(x) (x), N_STR(x) 273 #else /* for traditional cpp? */ 274 static char n_s[][2] = { 275 {'0', 0}, 276 {'1', 0}, 277 {'2', 0}, 278 }; 279 #define N_S(x) (x), n_s[(x)] 280 #endif 281 282 283 static struct sel_c defaulturls[] = { 284 {N_S(DEFAULT_URL_EMPTY), N_("none")}, 285 {N_S(DEFAULT_URL_CURRENT), N_("current URL")}, 286 {N_S(DEFAULT_URL_LINK), N_("link URL")}, 287 {0, NULL, NULL} 288 }; 289 290 static struct sel_c displayinsdel[] = { 291 {N_S(DISPLAY_INS_DEL_SIMPLE), N_("simple")}, 292 {N_S(DISPLAY_INS_DEL_NORMAL), N_("use tag")}, 293 {N_S(DISPLAY_INS_DEL_FONTIFY), N_("fontify")}, 294 {0, NULL, NULL} 295 }; 296 297 #ifdef USE_MOUSE 298 static struct sel_c wheelmode[] = { 299 {TRUE, "1", N_("A:relative to screen height")}, 300 {FALSE, "0", N_("B:fixed speed")}, 301 {0, NULL, NULL} 302 }; 303 #endif /* MOUSE */ 304 305 #ifdef INET6 306 static struct sel_c dnsorders[] = { 307 {N_S(DNS_ORDER_UNSPEC), N_("unspecified")}, 308 {N_S(DNS_ORDER_INET_INET6), N_("inet inet6")}, 309 {N_S(DNS_ORDER_INET6_INET), N_("inet6 inet")}, 310 {N_S(DNS_ORDER_INET_ONLY), N_("inet only")}, 311 {N_S(DNS_ORDER_INET6_ONLY), N_("inet6 only")}, 312 {0, NULL, NULL} 313 }; 314 #endif /* INET6 */ 315 316 #ifdef USE_COOKIE 317 static struct sel_c badcookiestr[] = { 318 {N_S(ACCEPT_BAD_COOKIE_DISCARD), N_("discard")}, 319 #if 0 320 {N_S(ACCEPT_BAD_COOKIE_ACCEPT), N_("accept")}, 321 #endif 322 {N_S(ACCEPT_BAD_COOKIE_ASK), N_("ask")}, 323 {0, NULL, NULL} 324 }; 325 #endif /* USE_COOKIE */ 326 327 static struct sel_c mailtooptionsstr[] = { 328 #ifdef USE_W3MMAILER 329 {N_S(MAILTO_OPTIONS_USE_W3MMAILER), N_("use internal mailer instead")}, 330 #endif 331 {N_S(MAILTO_OPTIONS_IGNORE), N_("ignore options and use only the address")}, 332 {N_S(MAILTO_OPTIONS_USE_MAILTO_URL), N_("use full mailto URL")}, 333 {0, NULL, NULL} 334 }; 335 336 #ifdef USE_M17N 337 static wc_ces_list *display_charset_str = NULL; 338 static wc_ces_list *document_charset_str = NULL; 339 static wc_ces_list *system_charset_str = NULL; 340 static struct sel_c auto_detect_str[] = { 341 {N_S(WC_OPT_DETECT_OFF), N_("OFF")}, 342 {N_S(WC_OPT_DETECT_ISO_2022), N_("Only ISO 2022")}, 343 {N_S(WC_OPT_DETECT_ON), N_("ON")}, 344 {0, NULL, NULL} 345 }; 346 #endif 347 348 static struct sel_c graphic_char_str[] = { 349 {N_S(GRAPHIC_CHAR_ASCII), N_("ASCII")}, 350 {N_S(GRAPHIC_CHAR_CHARSET), N_("charset specific")}, 351 {N_S(GRAPHIC_CHAR_DEC), N_("DEC special graphics")}, 352 {0, NULL, NULL} 353 }; 354 355 struct param_ptr params1[] = { 356 {"tabstop", P_NZINT, PI_TEXT, (void *)&Tabstop, CMT_TABSTOP, NULL}, 357 {"indent_incr", P_NZINT, PI_TEXT, (void *)&IndentIncr, CMT_INDENT_INCR, 358 NULL}, 359 {"pixel_per_char", P_PIXELS, PI_TEXT, (void *)&pixel_per_char, 360 CMT_PIXEL_PER_CHAR, NULL}, 361 #ifdef USE_IMAGE 362 {"pixel_per_line", P_PIXELS, PI_TEXT, (void *)&pixel_per_line, 363 CMT_PIXEL_PER_LINE, NULL}, 364 #endif 365 {"frame", P_CHARINT, PI_ONOFF, (void *)&RenderFrame, CMT_FRAME, NULL}, 366 {"target_self", P_CHARINT, PI_ONOFF, (void *)&TargetSelf, CMT_TSELF, NULL}, 367 {"open_tab_blank", P_INT, PI_ONOFF, (void *)&open_tab_blank, 368 CMT_OPEN_TAB_BLANK, NULL}, 369 {"open_tab_dl_list", P_INT, PI_ONOFF, (void *)&open_tab_dl_list, 370 CMT_OPEN_TAB_DL_LIST, NULL}, 371 {"display_link", P_INT, PI_ONOFF, (void *)&displayLink, CMT_DISPLINK, 372 NULL}, 373 {"display_link_number", P_INT, PI_ONOFF, (void *)&displayLinkNumber, 374 CMT_DISPLINKNUMBER, NULL}, 375 {"decode_url", P_INT, PI_ONOFF, (void *)&DecodeURL, CMT_DECODE_URL, NULL}, 376 {"display_lineinfo", P_INT, PI_ONOFF, (void *)&displayLineInfo, 377 CMT_DISPLINEINFO, NULL}, 378 {"ext_dirlist", P_INT, PI_ONOFF, (void *)&UseExternalDirBuffer, 379 CMT_EXT_DIRLIST, NULL}, 380 {"dirlist_cmd", P_STRING, PI_TEXT, (void *)&DirBufferCommand, 381 CMT_DIRLIST_CMD, NULL}, 382 #ifdef USE_DICT 383 {"use_dictcommand", P_INT, PI_ONOFF, (void *)&UseDictCommand, 384 CMT_USE_DICTCOMMAND, NULL}, 385 {"dictcommand", P_STRING, PI_TEXT, (void *)&DictCommand, 386 CMT_DICTCOMMAND, NULL}, 387 #endif /* USE_DICT */ 388 {"multicol", P_INT, PI_ONOFF, (void *)&multicolList, CMT_MULTICOL, NULL}, 389 {"alt_entity", P_CHARINT, PI_ONOFF, (void *)&UseAltEntity, CMT_ALT_ENTITY, 390 NULL}, 391 {"graphic_char", P_CHARINT, PI_SEL_C, (void *)&UseGraphicChar, 392 CMT_GRAPHIC_CHAR, (void *)graphic_char_str}, 393 {"fold_textarea", P_CHARINT, PI_ONOFF, (void *)&FoldTextarea, 394 CMT_FOLD_TEXTAREA, NULL}, 395 {"display_ins_del", P_INT, PI_SEL_C, (void *)&displayInsDel, 396 CMT_DISP_INS_DEL, displayinsdel}, 397 {"ignore_null_img_alt", P_INT, PI_ONOFF, (void *)&ignore_null_img_alt, 398 CMT_IGNORE_NULL_IMG_ALT, NULL}, 399 {"view_unseenobject", P_INT, PI_ONOFF, (void *)&view_unseenobject, 400 CMT_VIEW_UNSEENOBJECTS, NULL}, 401 /* XXX: emacs-w3m force to off display_image even if image options off */ 402 {"display_image", P_INT, PI_ONOFF, (void *)&displayImage, CMT_DISP_IMAGE, 403 NULL}, 404 {"pseudo_inlines", P_INT, PI_ONOFF, (void *)&pseudoInlines, 405 CMT_PSEUDO_INLINES, NULL}, 406 #ifdef USE_IMAGE 407 {"auto_image", P_INT, PI_ONOFF, (void *)&autoImage, CMT_AUTO_IMAGE, NULL}, 408 {"max_load_image", P_INT, PI_TEXT, (void *)&maxLoadImage, 409 CMT_MAX_LOAD_IMAGE, NULL}, 410 {"ext_image_viewer", P_INT, PI_ONOFF, (void *)&useExtImageViewer, 411 CMT_EXT_IMAGE_VIEWER, NULL}, 412 {"image_scale", P_SCALE, PI_TEXT, (void *)&image_scale, CMT_IMAGE_SCALE, 413 NULL}, 414 {"imgdisplay", P_STRING, PI_TEXT, (void *)&Imgdisplay, CMT_IMGDISPLAY, 415 NULL}, 416 {"image_map_list", P_INT, PI_ONOFF, (void *)&image_map_list, 417 CMT_IMAGE_MAP_LIST, NULL}, 418 #endif 419 {"fold_line", P_INT, PI_ONOFF, (void *)&FoldLine, CMT_FOLD_LINE, NULL}, 420 {"show_lnum", P_INT, PI_ONOFF, (void *)&showLineNum, CMT_SHOW_NUM, NULL}, 421 {"show_srch_str", P_INT, PI_ONOFF, (void *)&show_srch_str, 422 CMT_SHOW_SRCH_STR, NULL}, 423 {"label_topline", P_INT, PI_ONOFF, (void *)&label_topline, 424 CMT_LABEL_TOPLINE, NULL}, 425 {"nextpage_topline", P_INT, PI_ONOFF, (void *)&nextpage_topline, 426 CMT_NEXTPAGE_TOPLINE, NULL}, 427 {NULL, 0, 0, NULL, NULL, NULL}, 428 }; 429 430 #ifdef USE_COLOR 431 struct param_ptr params2[] = { 432 {"color", P_INT, PI_ONOFF, (void *)&useColor, CMT_COLOR, NULL}, 433 {"basic_color", P_COLOR, PI_SEL_C, (void *)&basic_color, CMT_B_COLOR, 434 (void *)colorstr}, 435 {"anchor_color", P_COLOR, PI_SEL_C, (void *)&anchor_color, CMT_A_COLOR, 436 (void *)colorstr}, 437 {"image_color", P_COLOR, PI_SEL_C, (void *)&image_color, CMT_I_COLOR, 438 (void *)colorstr}, 439 {"form_color", P_COLOR, PI_SEL_C, (void *)&form_color, CMT_F_COLOR, 440 (void *)colorstr}, 441 #ifdef USE_BG_COLOR 442 {"mark_color", P_COLOR, PI_SEL_C, (void *)&mark_color, CMT_MARK_COLOR, 443 (void *)colorstr}, 444 {"bg_color", P_COLOR, PI_SEL_C, (void *)&bg_color, CMT_BG_COLOR, 445 (void *)colorstr}, 446 #endif /* USE_BG_COLOR */ 447 {"active_style", P_INT, PI_ONOFF, (void *)&useActiveColor, 448 CMT_ACTIVE_STYLE, NULL}, 449 {"active_color", P_COLOR, PI_SEL_C, (void *)&active_color, CMT_C_COLOR, 450 (void *)colorstr}, 451 {"visited_anchor", P_INT, PI_ONOFF, (void *)&useVisitedColor, 452 CMT_VISITED_ANCHOR, NULL}, 453 {"visited_color", P_COLOR, PI_SEL_C, (void *)&visited_color, CMT_V_COLOR, 454 (void *)colorstr}, 455 {NULL, 0, 0, NULL, NULL, NULL}, 456 }; 457 #endif /* USE_COLOR */ 458 459 460 struct param_ptr params3[] = { 461 {"pagerline", P_NZINT, PI_TEXT, (void *)&PagerMax, CMT_PAGERLINE, NULL}, 462 #ifdef USE_HISTORY 463 {"use_history", P_INT, PI_ONOFF, (void *)&UseHistory, CMT_HISTORY, NULL}, 464 {"history", P_INT, PI_TEXT, (void *)&URLHistSize, CMT_HISTSIZE, NULL}, 465 {"save_hist", P_INT, PI_ONOFF, (void *)&SaveURLHist, CMT_SAVEHIST, NULL}, 466 #endif /* USE_HISTORY */ 467 {"confirm_qq", P_INT, PI_ONOFF, (void *)&confirm_on_quit, CMT_CONFIRM_QQ, 468 NULL}, 469 {"close_tab_back", P_INT, PI_ONOFF, (void *)&close_tab_back, 470 CMT_CLOSE_TAB_BACK, NULL}, 471 #ifdef USE_MARK 472 {"mark", P_INT, PI_ONOFF, (void *)&use_mark, CMT_USE_MARK, NULL}, 473 #endif 474 {"emacs_like_lineedit", P_INT, PI_ONOFF, (void *)&emacs_like_lineedit, 475 CMT_EMACS_LIKE_LINEEDIT, NULL}, 476 {"vi_prec_num", P_INT, PI_ONOFF, (void *)&vi_prec_num, CMT_VI_PREC_NUM, 477 NULL}, 478 {"mark_all_pages", P_INT, PI_ONOFF, (void *)&MarkAllPages, 479 CMT_MARK_ALL_PAGES, NULL}, 480 {"wrap_search", P_INT, PI_ONOFF, (void *)&WrapDefault, CMT_WRAP, NULL}, 481 {"ignorecase_search", P_INT, PI_ONOFF, (void *)&IgnoreCase, 482 CMT_IGNORE_CASE, NULL}, 483 #ifdef USE_MIGEMO 484 {"use_migemo", P_INT, PI_ONOFF, (void *)&use_migemo, CMT_USE_MIGEMO, 485 NULL}, 486 {"migemo_command", P_STRING, PI_TEXT, (void *)&migemo_command, 487 CMT_MIGEMO_COMMAND, NULL}, 488 #endif /* USE_MIGEMO */ 489 #ifdef USE_MOUSE 490 {"use_mouse", P_INT, PI_ONOFF, (void *)&use_mouse, CMT_MOUSE, NULL}, 491 {"reverse_mouse", P_INT, PI_ONOFF, (void *)&reverse_mouse, 492 CMT_REVERSE_MOUSE, NULL}, 493 {"relative_wheel_scroll", P_INT, PI_SEL_C, (void *)&relative_wheel_scroll, 494 CMT_RELATIVE_WHEEL_SCROLL, (void *)wheelmode}, 495 {"relative_wheel_scroll_ratio", P_INT, PI_TEXT, 496 (void *)&relative_wheel_scroll_ratio, 497 CMT_RELATIVE_WHEEL_SCROLL_RATIO, NULL}, 498 {"fixed_wheel_scroll_count", P_INT, PI_TEXT, 499 (void *)&fixed_wheel_scroll_count, 500 CMT_FIXED_WHEEL_SCROLL_COUNT, NULL}, 501 #endif /* USE_MOUSE */ 502 {"clear_buffer", P_INT, PI_ONOFF, (void *)&clear_buffer, CMT_CLEAR_BUF, 503 NULL}, 504 {"decode_cte", P_CHARINT, PI_ONOFF, (void *)&DecodeCTE, CMT_DECODE_CTE, 505 NULL}, 506 {"auto_uncompress", P_CHARINT, PI_ONOFF, (void *)&AutoUncompress, 507 CMT_AUTO_UNCOMPRESS, NULL}, 508 {"preserve_timestamp", P_CHARINT, PI_ONOFF, (void *)&PreserveTimestamp, 509 CMT_PRESERVE_TIMESTAMP, NULL}, 510 {"keymap_file", P_STRING, PI_TEXT, (void *)&keymap_file, CMT_KEYMAP_FILE, 511 NULL}, 512 {NULL, 0, 0, NULL, NULL, NULL}, 513 }; 514 515 struct param_ptr params4[] = { 516 {"use_proxy", P_CHARINT, PI_ONOFF, (void *)&use_proxy, CMT_USE_PROXY, 517 NULL}, 518 {"http_proxy", P_STRING, PI_TEXT, (void *)&HTTP_proxy, CMT_HTTP_PROXY, 519 NULL}, 520 #ifdef USE_SSL 521 {"https_proxy", P_STRING, PI_TEXT, (void *)&HTTPS_proxy, CMT_HTTPS_PROXY, 522 NULL}, 523 #endif /* USE_SSL */ 524 #ifdef USE_GOPHER 525 {"gopher_proxy", P_STRING, PI_TEXT, (void *)&GOPHER_proxy, 526 CMT_GOPHER_PROXY, NULL}, 527 #endif /* USE_GOPHER */ 528 {"ftp_proxy", P_STRING, PI_TEXT, (void *)&FTP_proxy, CMT_FTP_PROXY, NULL}, 529 {"no_proxy", P_STRING, PI_TEXT, (void *)&NO_proxy, CMT_NO_PROXY, NULL}, 530 {"noproxy_netaddr", P_INT, PI_ONOFF, (void *)&NOproxy_netaddr, 531 CMT_NOPROXY_NETADDR, NULL}, 532 {"no_cache", P_CHARINT, PI_ONOFF, (void *)&NoCache, CMT_NO_CACHE, NULL}, 533 534 {NULL, 0, 0, NULL, NULL, NULL}, 535 }; 536 537 struct param_ptr params5[] = { 538 {"document_root", P_STRING, PI_TEXT, (void *)&document_root, CMT_DROOT, 539 NULL}, 540 {"personal_document_root", P_STRING, PI_TEXT, 541 (void *)&personal_document_root, CMT_PDROOT, NULL}, 542 {"cgi_bin", P_STRING, PI_TEXT, (void *)&cgi_bin, CMT_CGIBIN, NULL}, 543 {"index_file", P_STRING, PI_TEXT, (void *)&index_file, CMT_IFILE, NULL}, 544 {NULL, 0, 0, NULL, NULL, NULL}, 545 }; 546 547 struct param_ptr params6[] = { 548 {"mime_types", P_STRING, PI_TEXT, (void *)&mimetypes_files, CMT_MIMETYPES, 549 NULL}, 550 {"mailcap", P_STRING, PI_TEXT, (void *)&mailcap_files, CMT_MAILCAP, NULL}, 551 #ifdef USE_EXTERNAL_URI_LOADER 552 {"urimethodmap", P_STRING, PI_TEXT, (void *)&urimethodmap_files, 553 CMT_URIMETHODMAP, NULL}, 554 #endif 555 {"editor", P_STRING, PI_TEXT, (void *)&Editor, CMT_EDITOR, NULL}, 556 {"mailto_options", P_INT, PI_SEL_C, (void *)&MailtoOptions, 557 CMT_MAILTO_OPTIONS, (void *)mailtooptionsstr}, 558 {"mailer", P_STRING, PI_TEXT, (void *)&Mailer, CMT_MAILER, NULL}, 559 {"extbrowser", P_STRING, PI_TEXT, (void *)&ExtBrowser, CMT_EXTBRZ, NULL}, 560 {"extbrowser2", P_STRING, PI_TEXT, (void *)&ExtBrowser2, CMT_EXTBRZ2, 561 NULL}, 562 {"extbrowser3", P_STRING, PI_TEXT, (void *)&ExtBrowser3, CMT_EXTBRZ3, 563 NULL}, 564 {"bgextviewer", P_INT, PI_ONOFF, (void *)&BackgroundExtViewer, 565 CMT_BGEXTVIEW, NULL}, 566 {"use_lessopen", P_INT, PI_ONOFF, (void *)&use_lessopen, CMT_USE_LESSOPEN, 567 NULL}, 568 {NULL, 0, 0, NULL, NULL, NULL}, 569 }; 570 571 #ifdef USE_SSL 572 struct param_ptr params7[] = { 573 {"ssl_forbid_method", P_STRING, PI_TEXT, (void *)&ssl_forbid_method, 574 CMT_SSL_FORBID_METHOD, NULL}, 575 #ifdef USE_SSL_VERIFY 576 {"ssl_verify_server", P_INT, PI_ONOFF, (void *)&ssl_verify_server, 577 CMT_SSL_VERIFY_SERVER, NULL}, 578 {"ssl_cert_file", P_SSLPATH, PI_TEXT, (void *)&ssl_cert_file, 579 CMT_SSL_CERT_FILE, NULL}, 580 {"ssl_key_file", P_SSLPATH, PI_TEXT, (void *)&ssl_key_file, 581 CMT_SSL_KEY_FILE, NULL}, 582 {"ssl_ca_path", P_SSLPATH, PI_TEXT, (void *)&ssl_ca_path, CMT_SSL_CA_PATH, 583 NULL}, 584 {"ssl_ca_file", P_SSLPATH, PI_TEXT, (void *)&ssl_ca_file, CMT_SSL_CA_FILE, 585 NULL}, 586 #endif /* USE_SSL_VERIFY */ 587 {NULL, 0, 0, NULL, NULL, NULL}, 588 }; 589 #endif /* USE_SSL */ 590 591 #ifdef USE_COOKIE 592 struct param_ptr params8[] = { 593 {"use_cookie", P_INT, PI_ONOFF, (void *)&use_cookie, CMT_USECOOKIE, NULL}, 594 {"show_cookie", P_INT, PI_ONOFF, (void *)&show_cookie, 595 CMT_SHOWCOOKIE, NULL}, 596 {"accept_cookie", P_INT, PI_ONOFF, (void *)&accept_cookie, 597 CMT_ACCEPTCOOKIE, NULL}, 598 {"accept_bad_cookie", P_INT, PI_SEL_C, (void *)&accept_bad_cookie, 599 CMT_ACCEPTBADCOOKIE, (void *)badcookiestr}, 600 {"cookie_reject_domains", P_STRING, PI_TEXT, 601 (void *)&cookie_reject_domains, CMT_COOKIE_REJECT_DOMAINS, NULL}, 602 {"cookie_accept_domains", P_STRING, PI_TEXT, 603 (void *)&cookie_accept_domains, CMT_COOKIE_ACCEPT_DOMAINS, NULL}, 604 {"cookie_avoid_wrong_number_of_dots", P_STRING, PI_TEXT, 605 (void *)&cookie_avoid_wrong_number_of_dots, 606 CMT_COOKIE_AVOID_WONG_NUMBER_OF_DOTS, NULL}, 607 {NULL, 0, 0, NULL, NULL, NULL}, 608 }; 609 #endif 610 611 struct param_ptr params9[] = { 612 {"passwd_file", P_STRING, PI_TEXT, (void *)&passwd_file, CMT_PASSWDFILE, 613 NULL}, 614 {"disable_secret_security_check", P_INT, PI_ONOFF, 615 (void *)&disable_secret_security_check, CMT_DISABLE_SECRET_SECURITY_CHECK, 616 NULL}, 617 {"ftppasswd", P_STRING, PI_TEXT, (void *)&ftppasswd, CMT_FTPPASS, NULL}, 618 {"ftppass_hostnamegen", P_INT, PI_ONOFF, (void *)&ftppass_hostnamegen, 619 CMT_FTPPASS_HOSTNAMEGEN, NULL}, 620 {"pre_form_file", P_STRING, PI_TEXT, (void *)&pre_form_file, 621 CMT_PRE_FORM_FILE, NULL}, 622 {"user_agent", P_STRING, PI_TEXT, (void *)&UserAgent, CMT_USERAGENT, NULL}, 623 {"no_referer", P_INT, PI_ONOFF, (void *)&NoSendReferer, CMT_NOSENDREFERER, 624 NULL}, 625 {"accept_language", P_STRING, PI_TEXT, (void *)&AcceptLang, CMT_ACCEPTLANG, 626 NULL}, 627 {"accept_encoding", P_STRING, PI_TEXT, (void *)&AcceptEncoding, 628 CMT_ACCEPTENCODING, 629 NULL}, 630 {"accept_media", P_STRING, PI_TEXT, (void *)&AcceptMedia, CMT_ACCEPTMEDIA, 631 NULL}, 632 {"argv_is_url", P_CHARINT, PI_ONOFF, (void *)&ArgvIsURL, CMT_ARGV_IS_URL, 633 NULL}, 634 {"retry_http", P_INT, PI_ONOFF, (void *)&retryAsHttp, CMT_RETRY_HTTP, 635 NULL}, 636 {"default_url", P_INT, PI_SEL_C, (void *)&DefaultURLString, 637 CMT_DEFAULT_URL, (void *)defaulturls}, 638 {"follow_redirection", P_INT, PI_TEXT, &FollowRedirection, 639 CMT_FOLLOW_REDIRECTION, NULL}, 640 {"meta_refresh", P_CHARINT, PI_ONOFF, (void *)&MetaRefresh, 641 CMT_META_REFRESH, NULL}, 642 #ifdef INET6 643 {"dns_order", P_INT, PI_SEL_C, (void *)&DNS_order, CMT_DNS_ORDER, 644 (void *)dnsorders}, 645 #endif /* INET6 */ 646 #ifdef USE_NNTP 647 {"nntpserver", P_STRING, PI_TEXT, (void *)&NNTP_server, CMT_NNTP_SERVER, 648 NULL}, 649 {"nntpmode", P_STRING, PI_TEXT, (void *)&NNTP_mode, CMT_NNTP_MODE, NULL}, 650 {"max_news", P_INT, PI_TEXT, (void *)&MaxNewsMessage, CMT_MAX_NEWS, NULL}, 651 #endif 652 {NULL, 0, 0, NULL, NULL, NULL}, 653 }; 654 655 #ifdef USE_M17N 656 struct param_ptr params10[] = { 657 {"display_charset", P_CODE, PI_CODE, (void *)&DisplayCharset, 658 CMT_DISPLAY_CHARSET, (void *)&display_charset_str}, 659 {"document_charset", P_CODE, PI_CODE, (void *)&DocumentCharset, 660 CMT_DOCUMENT_CHARSET, (void *)&document_charset_str}, 661 {"auto_detect", P_CHARINT, PI_SEL_C, (void *)&WcOption.auto_detect, 662 CMT_AUTO_DETECT, (void *)auto_detect_str}, 663 {"system_charset", P_CODE, PI_CODE, (void *)&SystemCharset, 664 CMT_SYSTEM_CHARSET, (void *)&system_charset_str}, 665 {"follow_locale", P_CHARINT, PI_ONOFF, (void *)&FollowLocale, 666 CMT_FOLLOW_LOCALE, NULL}, 667 {"ext_halfdump", P_CHARINT, PI_ONOFF, (void *)&ExtHalfdump, 668 CMT_EXT_HALFDUMP, NULL}, 669 {"use_wide", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_wide, CMT_USE_WIDE, 670 NULL}, 671 {"use_combining", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_combining, 672 CMT_USE_COMBINING, NULL}, 673 #ifdef USE_UNICODE 674 {"east_asian_width", P_CHARINT, PI_ONOFF, 675 (void *)&WcOption.east_asian_width, CMT_EAST_ASIAN_WIDTH, NULL}, 676 {"use_language_tag", P_CHARINT, PI_ONOFF, 677 (void *)&WcOption.use_language_tag, CMT_USE_LANGUAGE_TAG, NULL}, 678 {"ucs_conv", P_CHARINT, PI_ONOFF, (void *)&WcOption.ucs_conv, CMT_UCS_CONV, 679 NULL}, 680 #endif 681 {"pre_conv", P_CHARINT, PI_ONOFF, (void *)&WcOption.pre_conv, CMT_PRE_CONV, 682 NULL}, 683 {"search_conv", P_CHARINT, PI_ONOFF, (void *)&SearchConv, CMT_SEARCH_CONV, 684 NULL}, 685 {"fix_width_conv", P_CHARINT, PI_ONOFF, (void *)&WcOption.fix_width_conv, 686 CMT_FIX_WIDTH_CONV, NULL}, 687 #ifdef USE_UNICODE 688 {"use_gb12345_map", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_gb12345_map, 689 CMT_USE_GB12345_MAP, NULL}, 690 #endif 691 {"use_jisx0201", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_jisx0201, 692 CMT_USE_JISX0201, NULL}, 693 {"use_jisc6226", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_jisc6226, 694 CMT_USE_JISC6226, NULL}, 695 {"use_jisx0201k", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_jisx0201k, 696 CMT_USE_JISX0201K, NULL}, 697 {"use_jisx0212", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_jisx0212, 698 CMT_USE_JISX0212, NULL}, 699 {"use_jisx0213", P_CHARINT, PI_ONOFF, (void *)&WcOption.use_jisx0213, 700 CMT_USE_JISX0213, NULL}, 701 {"strict_iso2022", P_CHARINT, PI_ONOFF, (void *)&WcOption.strict_iso2022, 702 CMT_STRICT_ISO2022, NULL}, 703 #ifdef USE_UNICODE 704 {"gb18030_as_ucs", P_CHARINT, PI_ONOFF, (void *)&WcOption.gb18030_as_ucs, 705 CMT_GB18030_AS_UCS, NULL}, 706 #endif 707 {"simple_preserve_space", P_CHARINT, PI_ONOFF, (void *)&SimplePreserveSpace, 708 CMT_SIMPLE_PRESERVE_SPACE, NULL}, 709 {NULL, 0, 0, NULL, NULL, NULL}, 710 }; 711 #endif 712 713 struct param_section sections[] = { 714 {N_("Display Settings"), params1}, 715 #ifdef USE_COLOR 716 {N_("Color Settings"), params2}, 717 #endif /* USE_COLOR */ 718 {N_("Miscellaneous Settings"), params3}, 719 {N_("Directory Settings"), params5}, 720 {N_("External Program Settings"), params6}, 721 {N_("Network Settings"), params9}, 722 {N_("Proxy Settings"), params4}, 723 #ifdef USE_SSL 724 {N_("SSL Settings"), params7}, 725 #endif 726 #ifdef USE_COOKIE 727 {N_("Cookie Settings"), params8}, 728 #endif 729 #ifdef USE_M17N 730 {N_("Charset Settings"), params10}, 731 #endif 732 {NULL, NULL} 733 }; 734 735 static Str to_str(struct param_ptr *p); 736 737 static int 738 compare_table(struct rc_search_table *a, struct rc_search_table *b) 739 { 740 return strcmp(a->param->name, b->param->name); 741 } 742 743 static void 744 create_option_search_table() 745 { 746 int i, j, k; 747 int diff1, diff2; 748 char *p, *q; 749 750 /* count table size */ 751 RC_table_size = 0; 752 for (j = 0; sections[j].name != NULL; j++) { 753 i = 0; 754 while (sections[j].params[i].name) { 755 i++; 756 RC_table_size++; 757 } 758 } 759 760 RC_search_table = New_N(struct rc_search_table, RC_table_size); 761 k = 0; 762 for (j = 0; sections[j].name != NULL; j++) { 763 i = 0; 764 while (sections[j].params[i].name) { 765 RC_search_table[k].param = §ions[j].params[i]; 766 k++; 767 i++; 768 } 769 } 770 771 qsort(RC_search_table, RC_table_size, sizeof(struct rc_search_table), 772 (int (*)(const void *, const void *))compare_table); 773 774 diff1 = diff2 = 0; 775 for (i = 0; i < RC_table_size - 1; i++) { 776 p = RC_search_table[i].param->name; 777 q = RC_search_table[i + 1].param->name; 778 for (j = 0; p[j] != '\0' && q[j] != '\0' && p[j] == q[j]; j++) ; 779 diff1 = j; 780 if (diff1 > diff2) 781 RC_search_table[i].uniq_pos = diff1 + 1; 782 else 783 RC_search_table[i].uniq_pos = diff2 + 1; 784 diff2 = diff1; 785 } 786 } 787 788 struct param_ptr * 789 search_param(char *name) 790 { 791 size_t b, e, i; 792 int cmp; 793 int len = strlen(name); 794 795 for (b = 0, e = RC_table_size - 1; b <= e;) { 796 i = (b + e) / 2; 797 cmp = strncmp(name, RC_search_table[i].param->name, len); 798 799 if (!cmp) { 800 if (len >= RC_search_table[i].uniq_pos) { 801 return RC_search_table[i].param; 802 } 803 else { 804 while ((cmp = 805 strcmp(name, RC_search_table[i].param->name)) <= 0) 806 if (!cmp) 807 return RC_search_table[i].param; 808 else if (i == 0) 809 return NULL; 810 else 811 i--; 812 /* ambiguous */ 813 return NULL; 814 } 815 } 816 else if (cmp < 0) { 817 if (i == 0) 818 return NULL; 819 e = i - 1; 820 } 821 else 822 b = i + 1; 823 } 824 return NULL; 825 } 826 827 /* show parameter with bad options invokation */ 828 void 829 show_params(FILE * fp) 830 { 831 int i, j, l; 832 char *t = NULL; 833 char *cmt; 834 835 #ifdef USE_M17N 836 #ifdef ENABLE_NLS 837 OptionCharset = SystemCharset; /* FIXME */ 838 #endif 839 #endif 840 841 fputs("\nconfiguration parameters\n", fp); 842 for (j = 0; sections[j].name != NULL; j++) { 843 #ifdef USE_M17N 844 if (!OptionEncode) 845 cmt = 846 wc_conv(_(sections[j].name), OptionCharset, 847 InnerCharset)->ptr; 848 else 849 #endif 850 cmt = sections[j].name; 851 fprintf(fp, " section[%d]: %s\n", j, conv_to_system(cmt)); 852 i = 0; 853 while (sections[j].params[i].name) { 854 switch (sections[j].params[i].type) { 855 case P_INT: 856 case P_SHORT: 857 case P_CHARINT: 858 case P_NZINT: 859 t = (sections[j].params[i].inputtype == 860 PI_ONOFF) ? "bool" : "number"; 861 break; 862 case P_CHAR: 863 t = "char"; 864 break; 865 case P_STRING: 866 t = "string"; 867 break; 868 #if defined(USE_SSL) && defined(USE_SSL_VERIFY) 869 case P_SSLPATH: 870 t = "path"; 871 break; 872 #endif 873 #ifdef USE_COLOR 874 case P_COLOR: 875 t = "color"; 876 break; 877 #endif 878 #ifdef USE_M17N 879 case P_CODE: 880 t = "charset"; 881 break; 882 #endif 883 case P_PIXELS: 884 t = "number"; 885 break; 886 case P_SCALE: 887 t = "percent"; 888 break; 889 } 890 #ifdef USE_M17N 891 if (!OptionEncode) 892 cmt = wc_conv(_(sections[j].params[i].comment), 893 OptionCharset, InnerCharset)->ptr; 894 else 895 #endif 896 cmt = sections[j].params[i].comment; 897 l = 30 - (strlen(sections[j].params[i].name) + strlen(t)); 898 if (l < 0) 899 l = 1; 900 fprintf(fp, " -o %s=<%s>%*s%s\n", 901 sections[j].params[i].name, t, l, " ", 902 conv_to_system(cmt)); 903 i++; 904 } 905 } 906 } 907 908 int 909 str_to_bool(char *value, int old) 910 { 911 if (value == NULL) 912 return 1; 913 switch (TOLOWER(*value)) { 914 case '0': 915 case 'f': /* false */ 916 case 'n': /* no */ 917 case 'u': /* undef */ 918 return 0; 919 case 'o': 920 if (TOLOWER(value[1]) == 'f') /* off */ 921 return 0; 922 return 1; /* on */ 923 case 't': 924 if (TOLOWER(value[1]) == 'o') /* toggle */ 925 return !old; 926 return 1; /* true */ 927 case '!': 928 case 'r': /* reverse */ 929 case 'x': /* exchange */ 930 return !old; 931 } 932 return 1; 933 } 934 935 #ifdef USE_COLOR 936 static int 937 str_to_color(char *value) 938 { 939 if (value == NULL) 940 return 8; /* terminal */ 941 switch (TOLOWER(*value)) { 942 case '0': 943 return 0; /* black */ 944 case '1': 945 case 'r': 946 return 1; /* red */ 947 case '2': 948 case 'g': 949 return 2; /* green */ 950 case '3': 951 case 'y': 952 return 3; /* yellow */ 953 case '4': 954 return 4; /* blue */ 955 case '5': 956 case 'm': 957 return 5; /* magenta */ 958 case '6': 959 case 'c': 960 return 6; /* cyan */ 961 case '7': 962 case 'w': 963 return 7; /* white */ 964 case '8': 965 case 't': 966 return 8; /* terminal */ 967 case 'b': 968 if (!strncasecmp(value, "blu", 3)) 969 return 4; /* blue */ 970 else 971 return 0; /* black */ 972 } 973 return 8; /* terminal */ 974 } 975 #endif 976 977 static int 978 set_param(char *name, char *value) 979 { 980 struct param_ptr *p; 981 double ppc; 982 983 if (value == NULL) 984 return 0; 985 p = search_param(name); 986 if (p == NULL) 987 return 0; 988 switch (p->type) { 989 case P_INT: 990 if (atoi(value) >= 0) 991 *(int *)p->varptr = (p->inputtype == PI_ONOFF) 992 ? str_to_bool(value, *(int *)p->varptr) : atoi(value); 993 break; 994 case P_NZINT: 995 if (atoi(value) > 0) 996 *(int *)p->varptr = atoi(value); 997 break; 998 case P_SHORT: 999 *(short *)p->varptr = (p->inputtype == PI_ONOFF) 1000 ? str_to_bool(value, *(short *)p->varptr) : atoi(value); 1001 break; 1002 case P_CHARINT: 1003 *(char *)p->varptr = (p->inputtype == PI_ONOFF) 1004 ? str_to_bool(value, *(char *)p->varptr) : atoi(value); 1005 break; 1006 case P_CHAR: 1007 *(char *)p->varptr = value[0]; 1008 break; 1009 case P_STRING: 1010 *(char **)p->varptr = value; 1011 break; 1012 #if defined(USE_SSL) && defined(USE_SSL_VERIFY) 1013 case P_SSLPATH: 1014 if (value != NULL && value[0] != '\0') 1015 *(char **)p->varptr = rcFile(value); 1016 else 1017 *(char **)p->varptr = NULL; 1018 ssl_path_modified = 1; 1019 break; 1020 #endif 1021 #ifdef USE_COLOR 1022 case P_COLOR: 1023 *(int *)p->varptr = str_to_color(value); 1024 break; 1025 #endif 1026 #ifdef USE_M17N 1027 case P_CODE: 1028 *(wc_ces *) p->varptr = 1029 wc_guess_charset_short(value, *(wc_ces *) p->varptr); 1030 break; 1031 #endif 1032 case P_PIXELS: 1033 ppc = atof(value); 1034 if (ppc >= MINIMUM_PIXEL_PER_CHAR && ppc <= MAXIMUM_PIXEL_PER_CHAR * 2) 1035 *(double *)p->varptr = ppc; 1036 break; 1037 case P_SCALE: 1038 ppc = atof(value); 1039 if (ppc >= 10 && ppc <= 1000) 1040 *(double *)p->varptr = ppc; 1041 break; 1042 } 1043 return 1; 1044 } 1045 1046 int 1047 set_param_option(char *option) 1048 { 1049 Str tmp = Strnew(); 1050 char *p = option, *q; 1051 1052 while (*p && !IS_SPACE(*p) && *p != '=') 1053 Strcat_char(tmp, *p++); 1054 while (*p && IS_SPACE(*p)) 1055 p++; 1056 if (*p == '=') { 1057 p++; 1058 while (*p && IS_SPACE(*p)) 1059 p++; 1060 } 1061 Strlower(tmp); 1062 if (set_param(tmp->ptr, p)) 1063 goto option_assigned; 1064 q = tmp->ptr; 1065 if (!strncmp(q, "no", 2)) { /* -o noxxx, -o no-xxx, -o no_xxx */ 1066 q += 2; 1067 if (*q == '-' || *q == '_') 1068 q++; 1069 } 1070 else if (tmp->ptr[0] == '-') /* -o -xxx */ 1071 q++; 1072 else 1073 return 0; 1074 if (set_param(q, "0")) 1075 goto option_assigned; 1076 return 0; 1077 option_assigned: 1078 return 1; 1079 } 1080 1081 char * 1082 get_param_option(char *name) 1083 { 1084 struct param_ptr *p; 1085 1086 p = search_param(name); 1087 return p ? to_str(p)->ptr : NULL; 1088 } 1089 1090 static void 1091 interpret_rc(FILE * f) 1092 { 1093 Str line; 1094 Str tmp; 1095 char *p; 1096 1097 for (;;) { 1098 line = Strfgets(f); 1099 if (line->length == 0) /* end of file */ 1100 break; 1101 Strchop(line); 1102 if (line->length == 0) /* blank line */ 1103 continue; 1104 Strremovefirstspaces(line); 1105 if (line->ptr[0] == '#') /* comment */ 1106 continue; 1107 tmp = Strnew(); 1108 p = line->ptr; 1109 while (*p && !IS_SPACE(*p)) 1110 Strcat_char(tmp, *p++); 1111 while (*p && IS_SPACE(*p)) 1112 p++; 1113 Strlower(tmp); 1114 set_param(tmp->ptr, p); 1115 } 1116 } 1117 1118 void 1119 parse_proxy() 1120 { 1121 if (non_null(HTTP_proxy)) 1122 parseURL(HTTP_proxy, &HTTP_proxy_parsed, NULL); 1123 #ifdef USE_SSL 1124 if (non_null(HTTPS_proxy)) 1125 parseURL(HTTPS_proxy, &HTTPS_proxy_parsed, NULL); 1126 #endif /* USE_SSL */ 1127 #ifdef USE_GOPHER 1128 if (non_null(GOPHER_proxy)) 1129 parseURL(GOPHER_proxy, &GOPHER_proxy_parsed, NULL); 1130 #endif 1131 if (non_null(FTP_proxy)) 1132 parseURL(FTP_proxy, &FTP_proxy_parsed, NULL); 1133 if (non_null(NO_proxy)) 1134 set_no_proxy(NO_proxy); 1135 } 1136 1137 #ifdef USE_COOKIE 1138 void 1139 parse_cookie() 1140 { 1141 if (non_null(cookie_reject_domains)) 1142 Cookie_reject_domains = make_domain_list(cookie_reject_domains); 1143 if (non_null(cookie_accept_domains)) 1144 Cookie_accept_domains = make_domain_list(cookie_accept_domains); 1145 if (non_null(cookie_avoid_wrong_number_of_dots)) 1146 Cookie_avoid_wrong_number_of_dots_domains 1147 = make_domain_list(cookie_avoid_wrong_number_of_dots); 1148 } 1149 #endif 1150 1151 #ifdef __EMX__ 1152 static int 1153 do_mkdir(const char *dir, long mode) 1154 { 1155 char *r, abs[_MAX_PATH]; 1156 size_t n; 1157 1158 _abspath(abs, rc_dir, _MAX_PATH); /* Translate '\\' to '/' */ 1159 1160 if (!(n = strlen(abs))) 1161 return -1; 1162 1163 if (*(r = abs + n - 1) == '/') /* Ignore tailing slash if it is */ 1164 *r = 0; 1165 1166 return mkdir(abs, mode); 1167 } 1168 #else /* not __EMX__ */ 1169 #ifdef __MINGW32_VERSION 1170 #define do_mkdir(dir,mode) mkdir(dir) 1171 #else 1172 #define do_mkdir(dir,mode) mkdir(dir,mode) 1173 #endif /* not __MINW32_VERSION */ 1174 #endif /* not __EMX__ */ 1175 1176 void 1177 sync_with_option(void) 1178 { 1179 if (PagerMax < LINES) 1180 PagerMax = LINES; 1181 WrapSearch = WrapDefault; 1182 parse_proxy(); 1183 #ifdef USE_COOKIE 1184 parse_cookie(); 1185 #endif 1186 initMailcap(); 1187 initMimeTypes(); 1188 #ifdef USE_EXTERNAL_URI_LOADER 1189 initURIMethods(); 1190 #endif 1191 #ifdef USE_MIGEMO 1192 init_migemo(); 1193 #endif 1194 #ifdef USE_IMAGE 1195 if (fmInitialized && displayImage) 1196 initImage(); 1197 #else 1198 displayImage = FALSE; /* XXX */ 1199 #endif 1200 loadPasswd(); 1201 loadPreForm(); 1202 1203 if (AcceptLang == NULL || *AcceptLang == '\0') { 1204 /* TRANSLATORS: 1205 * AcceptLang default: this is used in Accept-Language: HTTP request 1206 * header. For example, ja.po should translate it as 1207 * "ja;q=1.0, en;q=0.5" like that. 1208 */ 1209 AcceptLang = _("en;q=1.0"); 1210 } 1211 if (AcceptEncoding == NULL || *AcceptEncoding == '\0') 1212 AcceptEncoding = acceptableEncoding(); 1213 if (AcceptMedia == NULL || *AcceptMedia == '\0') 1214 AcceptMedia = acceptableMimeTypes(); 1215 #ifdef USE_UNICODE 1216 update_utf8_symbol(); 1217 #endif 1218 if (fmInitialized) { 1219 initKeymap(FALSE); 1220 #ifdef USE_MOUSE 1221 initMouseAction(); 1222 #endif /* MOUSE */ 1223 #ifdef USE_MENU 1224 initMenu(); 1225 #endif /* MENU */ 1226 } 1227 } 1228 1229 void 1230 init_rc(void) 1231 { 1232 int i; 1233 struct stat st; 1234 FILE *f; 1235 1236 if (rc_dir != NULL) 1237 goto open_rc; 1238 1239 rc_dir = expandPath(RC_DIR); 1240 i = strlen(rc_dir); 1241 if (i > 1 && rc_dir[i - 1] == '/') 1242 rc_dir[i - 1] = '\0'; 1243 1244 #ifdef USE_M17N 1245 display_charset_str = wc_get_ces_list(); 1246 document_charset_str = display_charset_str; 1247 system_charset_str = display_charset_str; 1248 #endif 1249 1250 if (stat(rc_dir, &st) < 0) { 1251 if (errno == ENOENT) { /* no directory */ 1252 if (do_mkdir(rc_dir, 0700) < 0) { 1253 fprintf(stderr, "Can't create config directory (%s)!", rc_dir); 1254 goto rc_dir_err; 1255 } 1256 else { 1257 stat(rc_dir, &st); 1258 } 1259 } 1260 else { 1261 fprintf(stderr, "Can't open config directory (%s)!", rc_dir); 1262 goto rc_dir_err; 1263 } 1264 } 1265 if (!S_ISDIR(st.st_mode)) { 1266 /* not a directory */ 1267 fprintf(stderr, "%s is not a directory!", rc_dir); 1268 goto rc_dir_err; 1269 } 1270 if (!(st.st_mode & S_IWUSR)) { 1271 fprintf(stderr, "%s is not writable!", rc_dir); 1272 goto rc_dir_err; 1273 } 1274 no_rc_dir = FALSE; 1275 tmp_dir = rc_dir; 1276 1277 if (config_file == NULL) 1278 config_file = rcFile(CONFIG_FILE); 1279 1280 create_option_search_table(); 1281 1282 open_rc: 1283 /* open config file */ 1284 if ((f = fopen(etcFile(W3MCONFIG), "rt")) != NULL) { 1285 interpret_rc(f); 1286 fclose(f); 1287 } 1288 if ((f = fopen(confFile(CONFIG_FILE), "rt")) != NULL) { 1289 interpret_rc(f); 1290 fclose(f); 1291 } 1292 if (config_file && (f = fopen(config_file, "rt")) != NULL) { 1293 interpret_rc(f); 1294 fclose(f); 1295 } 1296 return; 1297 1298 rc_dir_err: 1299 no_rc_dir = TRUE; 1300 if (((tmp_dir = getenv("TMPDIR")) == NULL || *tmp_dir == '\0') && 1301 ((tmp_dir = getenv("TMP")) == NULL || *tmp_dir == '\0') && 1302 ((tmp_dir = getenv("TEMP")) == NULL || *tmp_dir == '\0')) 1303 tmp_dir = "/tmp"; 1304 create_option_search_table(); 1305 goto open_rc; 1306 } 1307 1308 1309 static char optionpanel_src1[] = 1310 "<html><head><title>Option Setting Panel</title></head><body>\ 1311 <h1 align=center>Option Setting Panel<br>(w3m version %s)</b></h1>\ 1312 <form method=post action=\"file:///$LIB/" W3MHELPERPANEL_CMDNAME "\">\ 1313 <input type=hidden name=mode value=panel>\ 1314 <input type=hidden name=cookie value=\"%s\">\ 1315 <input type=submit value=\"%s\">\ 1316 </form><br>\ 1317 <form method=internal action=option>"; 1318 1319 static Str optionpanel_str = NULL; 1320 1321 static Str 1322 to_str(struct param_ptr *p) 1323 { 1324 switch (p->type) { 1325 case P_INT: 1326 #ifdef USE_COLOR 1327 case P_COLOR: 1328 #endif 1329 #ifdef USE_M17N 1330 case P_CODE: 1331 return Sprintf("%d", (int)(*(wc_ces *) p->varptr)); 1332 #endif 1333 case P_NZINT: 1334 return Sprintf("%d", *(int *)p->varptr); 1335 case P_SHORT: 1336 return Sprintf("%d", *(short *)p->varptr); 1337 case P_CHARINT: 1338 return Sprintf("%d", *(char *)p->varptr); 1339 case P_CHAR: 1340 return Sprintf("%c", *(char *)p->varptr); 1341 case P_STRING: 1342 #if defined(USE_SSL) && defined(USE_SSL_VERIFY) 1343 case P_SSLPATH: 1344 #endif 1345 /* SystemCharset -> InnerCharset */ 1346 return Strnew_charp(conv_from_system(*(char **)p->varptr)); 1347 case P_PIXELS: 1348 case P_SCALE: 1349 return Sprintf("%g", *(double *)p->varptr); 1350 } 1351 /* not reached */ 1352 return NULL; 1353 } 1354 1355 Buffer * 1356 load_option_panel(void) 1357 { 1358 Str src; 1359 struct param_ptr *p; 1360 struct sel_c *s; 1361 #ifdef USE_M17N 1362 wc_ces_list *c; 1363 #endif 1364 int x, i; 1365 Str tmp; 1366 Buffer *buf; 1367 1368 if (optionpanel_str == NULL) 1369 optionpanel_str = Sprintf(optionpanel_src1, w3m_version, 1370 html_quote(localCookie()->ptr), _(CMT_HELPER)); 1371 #ifdef USE_M17N 1372 #ifdef ENABLE_NLS 1373 OptionCharset = SystemCharset; /* FIXME */ 1374 #endif 1375 if (!OptionEncode) { 1376 optionpanel_str = 1377 wc_Str_conv(optionpanel_str, OptionCharset, InnerCharset); 1378 for (i = 0; sections[i].name != NULL; i++) { 1379 sections[i].name = 1380 wc_conv(_(sections[i].name), OptionCharset, 1381 InnerCharset)->ptr; 1382 for (p = sections[i].params; p->name; p++) { 1383 p->comment = 1384 wc_conv(_(p->comment), OptionCharset, 1385 InnerCharset)->ptr; 1386 if (p->inputtype == PI_SEL_C 1387 #ifdef USE_COLOR 1388 && p->select != colorstr 1389 #endif 1390 ) { 1391 for (s = (struct sel_c *)p->select; s->text != NULL; s++) { 1392 s->text = 1393 wc_conv(_(s->text), OptionCharset, 1394 InnerCharset)->ptr; 1395 } 1396 } 1397 } 1398 } 1399 #ifdef USE_COLOR 1400 for (s = colorstr; s->text; s++) 1401 s->text = wc_conv(_(s->text), OptionCharset, 1402 InnerCharset)->ptr; 1403 #endif 1404 OptionEncode = TRUE; 1405 } 1406 #endif 1407 src = Strdup(optionpanel_str); 1408 1409 Strcat_charp(src, "<table><tr><td>"); 1410 for (i = 0; sections[i].name != NULL; i++) { 1411 Strcat_m_charp(src, "<h1>", sections[i].name, "</h1>", NULL); 1412 p = sections[i].params; 1413 Strcat_charp(src, "<table width=100% cellpadding=0>"); 1414 while (p->name) { 1415 Strcat_m_charp(src, "<tr><td>", p->comment, NULL); 1416 Strcat(src, Sprintf("</td><td width=%d>", 1417 (int)(28 * pixel_per_char))); 1418 switch (p->inputtype) { 1419 case PI_TEXT: 1420 Strcat_m_charp(src, "<input type=text name=", 1421 p->name, 1422 " value=\"", 1423 html_quote(to_str(p)->ptr), "\">", NULL); 1424 break; 1425 case PI_ONOFF: 1426 x = atoi(to_str(p)->ptr); 1427 Strcat_m_charp(src, "<input type=radio name=", 1428 p->name, 1429 " value=1", 1430 (x ? " checked" : ""), 1431 ">YES <input type=radio name=", 1432 p->name, 1433 " value=0", (x ? "" : " checked"), ">NO", NULL); 1434 break; 1435 case PI_SEL_C: 1436 tmp = to_str(p); 1437 Strcat_m_charp(src, "<select name=", p->name, ">", NULL); 1438 for (s = (struct sel_c *)p->select; s->text != NULL; s++) { 1439 Strcat_charp(src, "<option value="); 1440 Strcat(src, Sprintf("%s\n", s->cvalue)); 1441 if ((p->type != P_CHAR && s->value == atoi(tmp->ptr)) || 1442 (p->type == P_CHAR && (char)s->value == *(tmp->ptr))) 1443 Strcat_charp(src, " selected"); 1444 Strcat_char(src, '>'); 1445 Strcat_charp(src, s->text); 1446 } 1447 Strcat_charp(src, "</select>"); 1448 break; 1449 #ifdef USE_M17N 1450 case PI_CODE: 1451 tmp = to_str(p); 1452 Strcat_m_charp(src, "<select name=", p->name, ">", NULL); 1453 for (c = *(wc_ces_list **) p->select; c->desc != NULL; c++) { 1454 Strcat_charp(src, "<option value="); 1455 Strcat(src, Sprintf("%s\n", c->name)); 1456 if (c->id == atoi(tmp->ptr)) 1457 Strcat_charp(src, " selected"); 1458 Strcat_char(src, '>'); 1459 Strcat_charp(src, c->desc); 1460 } 1461 Strcat_charp(src, "</select>"); 1462 break; 1463 #endif 1464 } 1465 Strcat_charp(src, "</td></tr>\n"); 1466 p++; 1467 } 1468 Strcat_charp(src, 1469 "<tr><td></td><td><p><input type=submit value=\"OK\"></td></tr>"); 1470 Strcat_charp(src, "</table><hr width=50%>"); 1471 } 1472 Strcat_charp(src, "</table></form></body></html>"); 1473 buf = loadHTMLString(src); 1474 #ifdef USE_M17N 1475 if (buf) 1476 buf->document_charset = OptionCharset; 1477 #endif 1478 return buf; 1479 } 1480 1481 void 1482 panel_set_option(struct parsed_tagarg *arg) 1483 { 1484 FILE *f = NULL; 1485 char *p; 1486 1487 if (config_file == NULL) { 1488 disp_message("There's no config file... config not saved", FALSE); 1489 } 1490 else { 1491 f = fopen(config_file, "wt"); 1492 if (f == NULL) { 1493 disp_message("Can't write option!", FALSE); 1494 } 1495 } 1496 while (arg) { 1497 /* InnerCharset -> SystemCharset */ 1498 if (arg->value) { 1499 p = conv_to_system(arg->value); 1500 if (set_param(arg->arg, p)) { 1501 if (f) 1502 fprintf(f, "%s %s\n", arg->arg, p); 1503 } 1504 } 1505 arg = arg->next; 1506 } 1507 if (f) 1508 fclose(f); 1509 sync_with_option(); 1510 backBf(); 1511 } 1512 1513 char * 1514 rcFile(char *base) 1515 { 1516 if (base && 1517 (base[0] == '/' || 1518 (base[0] == '.' 1519 && (base[1] == '/' || (base[1] == '.' && base[2] == '/'))) 1520 || (base[0] == '~' && base[1] == '/'))) 1521 /* /file, ./file, ../file, ~/file */ 1522 return expandPath(base); 1523 return expandPath(Strnew_m_charp(rc_dir, "/", base, NULL)->ptr); 1524 } 1525 1526 char * 1527 auxbinFile(char *base) 1528 { 1529 return expandPath(Strnew_m_charp(w3m_auxbin_dir(), "/", base, NULL)->ptr); 1530 } 1531 1532 #if 0 /* not used */ 1533 char * 1534 libFile(char *base) 1535 { 1536 return expandPath(Strnew_m_charp(w3m_lib_dir(), "/", base, NULL)->ptr); 1537 } 1538 #endif 1539 1540 char * 1541 etcFile(char *base) 1542 { 1543 return expandPath(Strnew_m_charp(w3m_etc_dir(), "/", base, NULL)->ptr); 1544 } 1545 1546 char * 1547 confFile(char *base) 1548 { 1549 return expandPath(Strnew_m_charp(w3m_conf_dir(), "/", base, NULL)->ptr); 1550 } 1551 1552 #ifndef USE_HELP_CGI 1553 char * 1554 helpFile(char *base) 1555 { 1556 return expandPath(Strnew_m_charp(w3m_help_dir(), "/", base, NULL)->ptr); 1557 } 1558 #endif