BOOL StringToColor(LPWORD lpColor, LPTSTR*str) { WORD wRet; wRet = str_to_color (str); if (wRet == (WORD)-1) { wRet=hex_clr (*str); chop_blank (str); if (wRet == (WORD)-1) return FALSE; } *lpColor = wRet; return TRUE; }
/* parses portsmanrc file and resets config if needed, returns 0 if everything was ok, ERROR_NO_RC_FILE if file could not be opened or a positive int of the line number where ERROR_CORRUPT_RC_FILE succeeded or an unknown keyword exist */ int parse_rc_file(char *filepath) { FILE *fd; extern Config config; bool readyKey = FALSE; bool validKey = FALSE; bool readyValue = FALSE; bool comment = FALSE; char tok[MAX_TOKEN]; char arg[MAX_TOKEN]; char *key; char *val; int i = 0, c = 0, line = 0; short sh = 0; if ((fd = fopen(filepath, "r")) == NULL) return ERROR_NO_RC_FILE; /* not present */ while (feof(fd) == 0) { c = fgetc(fd); /* get next char */ switch (c) { case '\t': break; case '#': comment = TRUE; /* until eol */ if (validKey && (i > 0)) /* ready value */ readyValue = TRUE; break; case '\n': /* eol */ line++; comment = FALSE; /* ready value */ if (validKey && (i > 0)) /* ready value */ readyValue = TRUE; else { validKey = FALSE; readyKey = FALSE; } break; case '=': if (!comment) { if (i > 0) readyKey = TRUE; else return line; } break; default: /* else it's a alphanum char */ if (!comment) if ((c != ' ') || ((c == ' ') && validKey)) tok[i++] = (char)c; break; } if (readyKey) { tok[i] = '\0'; /* terminate key token */ key = strdup(tok); i = 0; readyKey = FALSE; validKey = TRUE; } else if (readyValue) { tok[i] = '\0'; /* terminate value token */ val = tok; if (strcmp(key, "use.metacats") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.use_metacats = (sh == STATE_SELECTED) ? TRUE : FALSE; } } else if (strcmp(key, "titlebar.fcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.fcolors[CLR_TITLE] = sh; } } else if (strcmp(key, "titlebar.bcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.bcolors[CLR_TITLE] = sh; } } else if (strcmp(key, "browser.fcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.fcolors[CLR_BROWSE] = sh; } } else if (strcmp(key, "browser.bcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.bcolors[CLR_BROWSE] = sh; } } else if (strcmp(key, "statusbar.fcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.fcolors[CLR_STATUS] = sh; } } else if (strcmp(key, "statusbar.bcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.bcolors[CLR_STATUS] = sh; } } else if (strcmp(key, "cmdbar.fcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.fcolors[CLR_CMD] = sh; } } else if (strcmp(key, "cmdbar.bcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.bcolors[CLR_CMD] = sh; } } else if (strcmp(key, "selector.fcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.fcolors[CLR_SELECTOR] = sh; } } else if (strcmp(key, "selector.bcolor") == 0) { sh = str_to_color(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.bcolors[CLR_SELECTOR] = sh; } } else if (strcmp(key, "indexfile") == 0) { config.index_file = strdup(val); } else if (strcmp(key, "pkgdir") == 0) { config.inst_pkg_dir = strdup(val); } else if (strcmp(key, "portsdir") == 0) { config.ports_dir = strdup(val); } else if (strcmp(key, "make.cmd") == 0) { config.make_cmd = strdup(val); } else if (strcmp(key, "make.target.inst") == 0) { config.make_target[MK_TARGET_INST] = strdup(val); } else if (strcmp(key, "make.target.deinst") == 0) { config.make_target[MK_TARGET_DEINST] = strdup(val); } else if (strcmp(key, "make.target.update") == 0) { config.make_target[MK_TARGET_UPDATE] = strdup(val); } else if (strcmp(key, "make.option.force") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_FORCE] = sh; } } else if (strcmp(key, "make.option.pkg") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_PKG] = sh; } } else if (strcmp(key, "make.option.clean") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_CLEAN] = sh; } } else if (strcmp(key, "make.option.nochksum") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_NOCHKSUM] = sh; } } else if (strcmp(key, "make.option.nodeps") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_NODEPS] = sh; } } else if (strcmp(key, "make.option.forcepkgreg") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_FORCEPKGREG] = sh; } } else if (strcmp(key, "make.option.nopkgreg") == 0) { sh = str_to_state(val); if (sh == ERROR_CORRUPT_RC_FILE) { return (line); /* error */ } else { config.make_option[MK_OPTION_NOPKGREG] = sh; } } else if (strcmp(key, "make.option.force.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_FORCE] = strdup(arg); } else if (strcmp(key, "make.option.pkg.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_PKG] = strdup(arg); } else if (strcmp(key, "make.option.clean.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_CLEAN] = strdup(arg); } else if (strcmp(key, "make.option.nochksum.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_NOCHKSUM] = strdup(arg); } else if (strcmp(key, "make.option.nodeps.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_NODEPS] = strdup(arg); } else if (strcmp(key, "make.option.forcepkgreg.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_FORCEPKGREG] = strdup(arg); } else if (strcmp(key, "make.option.nopkgreg.arg") == 0) { sprintf(arg, "%s=yes", val); config.make_option_arg[MK_OPTION_NOPKGREG] = strdup(arg); } else if (strcmp(key, "rsync.cmd") == 0) { config.rsync_cmd = strdup(val); } else if (strcmp(key, "rsync.hostname") == 0) { if (!has_item(config.lrsynchosts, val, cmp_str)) add_list_item(config.lrsynchosts, strdup(val)); } else { return line; /* also error: unknown key */ } readyValue = FALSE; validKey = FALSE; free(key); i = 0; } } fclose(fd); return (0); }
static int set_param(char *name, char *value) { struct param_ptr *p; double ppc; if (value == NULL) return 0; p = search_param(name); if (p == NULL) return 0; switch (p->type) { case P_INT: if (atoi(value) >= 0) *(int *)p->varptr = (p->inputtype == PI_ONOFF) ? str_to_bool(value, *(int *)p->varptr) : atoi(value); break; case P_NZINT: if (atoi(value) > 0) *(int *)p->varptr = atoi(value); break; case P_SHORT: *(short *)p->varptr = (p->inputtype == PI_ONOFF) ? str_to_bool(value, *(short *)p->varptr) : atoi(value); break; case P_CHARINT: *(char *)p->varptr = (p->inputtype == PI_ONOFF) ? str_to_bool(value, *(char *)p->varptr) : atoi(value); break; case P_CHAR: *(char *)p->varptr = value[0]; break; case P_STRING: *(char **)p->varptr = value; break; #if defined(USE_SSL) && defined(USE_SSL_VERIFY) case P_SSLPATH: if (value != NULL && value[0] != '\0') *(char **)p->varptr = rcFile(value); else *(char **)p->varptr = NULL; ssl_path_modified = 1; break; #endif #ifdef USE_COLOR case P_COLOR: *(int *)p->varptr = str_to_color(value); break; #endif #ifdef USE_M17N case P_CODE: *(wc_ces *) p->varptr = wc_guess_charset_short(value, *(wc_ces *) p->varptr); break; #endif case P_PIXELS: ppc = atof(value); if (ppc >= MINIMUM_PIXEL_PER_CHAR && ppc <= MAXIMUM_PIXEL_PER_CHAR * 2) *(double *)p->varptr = ppc; break; case P_SCALE: ppc = atof(value); if (ppc >= 10 && ppc <= 1000) *(double *)p->varptr = ppc; break; } return 1; }