void Config::parse(const char *pos) { while (1) { char *eol = strchr(pos, '\n'); if (!eol) break; // parse if (!parse_blank(pos) && !parse_prefix(pos) && !parse_partition(pos) && !parse_node(pos)) fatal("unexpected line in config file:\n%s<END>", pos); pos = eol + 1; } }
static void parse_option(struct setterm_control *ctl, int ac, char **av) { int c; enum { OPT_TERM = CHAR_MAX + 1, OPT_RESET, OPT_RESIZE, OPT_INITIALIZE, OPT_CURSOR, OPT_REPEAT, OPT_APPCURSORKEYS, OPT_LINEWRAP, OPT_DEFAULT, OPT_FOREGROUND, OPT_BACKGROUND, OPT_ULCOLOR, OPT_HBCOLOR, OPT_INVERSESCREEN, OPT_BOLD, OPT_HALF_BRIGHT, OPT_BLINK, OPT_REVERSE, OPT_UNDERLINE, OPT_STORE, OPT_CLEAR, OPT_TABS, OPT_CLRTABS, OPT_REGTABS, OPT_BLANK, OPT_DUMP, OPT_APPEND, OPT_FILE, OPT_MSG, OPT_MSGLEVEL, OPT_POWERSAVE, OPT_POWERDOWN, OPT_BLENGTH, OPT_BFREQ, OPT_VERSION, OPT_HELP }; static const struct option longopts[] = { {"term", required_argument, NULL, OPT_TERM}, {"reset", no_argument, NULL, OPT_RESET}, {"resize", no_argument, NULL, OPT_RESIZE}, {"initialize", no_argument, NULL, OPT_INITIALIZE}, {"cursor", required_argument, NULL, OPT_CURSOR}, {"repeat", required_argument, NULL, OPT_REPEAT}, {"appcursorkeys", required_argument, NULL, OPT_APPCURSORKEYS}, {"linewrap", required_argument, NULL, OPT_LINEWRAP}, {"default", no_argument, NULL, OPT_DEFAULT}, {"foreground", required_argument, NULL, OPT_FOREGROUND}, {"background", required_argument, NULL, OPT_BACKGROUND}, {"ulcolor", required_argument, NULL, OPT_ULCOLOR}, {"hbcolor", required_argument, NULL, OPT_HBCOLOR}, {"inversescreen", required_argument, NULL, OPT_INVERSESCREEN}, {"bold", required_argument, NULL, OPT_BOLD}, {"half-bright", required_argument, NULL, OPT_HALF_BRIGHT}, {"blink", required_argument, NULL, OPT_BLINK}, {"reverse", required_argument, NULL, OPT_REVERSE}, {"underline", required_argument, NULL, OPT_UNDERLINE}, {"store", no_argument, NULL, OPT_STORE}, {"clear", required_argument, NULL, OPT_CLEAR}, {"tabs", optional_argument, NULL, OPT_TABS}, {"clrtabs", optional_argument, NULL, OPT_CLRTABS}, {"regtabs", optional_argument, NULL, OPT_REGTABS}, {"blank", optional_argument, NULL, OPT_BLANK}, {"dump", optional_argument, NULL, OPT_DUMP}, {"append", required_argument, NULL, OPT_APPEND}, {"file", required_argument, NULL, OPT_FILE}, {"msg", required_argument, NULL, OPT_MSG}, {"msglevel", required_argument, NULL, OPT_MSGLEVEL}, {"powersave", required_argument, NULL, OPT_POWERSAVE}, {"powerdown", optional_argument, NULL, OPT_POWERDOWN}, {"blength", optional_argument, NULL, OPT_BLENGTH}, {"bfreq", optional_argument, NULL, OPT_BFREQ}, {"version", no_argument, NULL, OPT_VERSION}, {"help", no_argument, NULL, OPT_HELP}, {NULL, 0, NULL, 0} }; static const ul_excl_t excl[] = { { OPT_DEFAULT, OPT_STORE }, { OPT_TABS, OPT_CLRTABS, OPT_REGTABS }, { OPT_MSG, OPT_MSGLEVEL }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; while ((c = getopt_long_only(ac, av, "", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); switch (c) { case OPT_TERM: ctl->opt_term = set_opt_flag(ctl->opt_term); ctl->opt_te_terminal_name = optarg; break; case OPT_RESET: ctl->opt_reset = set_opt_flag(ctl->opt_reset); break; case OPT_RESIZE: ctl->opt_resize = set_opt_flag(ctl->opt_resize); break; case OPT_INITIALIZE: ctl->opt_initialize = set_opt_flag(ctl->opt_initialize); break; case OPT_CURSOR: ctl->opt_cursor = set_opt_flag(ctl->opt_cursor); ctl->opt_cu_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_REPEAT: ctl->opt_repeat = set_opt_flag(ctl->opt_repeat); ctl->opt_rep_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_APPCURSORKEYS: ctl->opt_appcursorkeys = set_opt_flag(ctl->opt_appcursorkeys); ctl->opt_appck_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_LINEWRAP: ctl->opt_linewrap = set_opt_flag(ctl->opt_linewrap); ctl->opt_li_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_DEFAULT: ctl->opt_default = set_opt_flag(ctl->opt_default); break; case OPT_FOREGROUND: ctl->opt_foreground = set_opt_flag(ctl->opt_foreground); ctl->opt_fo_color = parse_febg_color(optarg); break; case OPT_BACKGROUND: ctl->opt_background = set_opt_flag(ctl->opt_background); ctl->opt_ba_color = parse_febg_color(optarg); break; case OPT_ULCOLOR: ctl->opt_ulcolor = set_opt_flag(ctl->opt_ulcolor); ctl->opt_ul_color = parse_ulhb_color(av, &optind); break; case OPT_HBCOLOR: ctl->opt_hbcolor = set_opt_flag(ctl->opt_hbcolor); ctl->opt_hb_color = parse_ulhb_color(av, &optind); break; case OPT_INVERSESCREEN: ctl->opt_inversescreen = set_opt_flag(ctl->opt_inversescreen); ctl->opt_invsc_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_BOLD: ctl->opt_bold = set_opt_flag(ctl->opt_bold); ctl->opt_bo_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_HALF_BRIGHT: ctl->opt_halfbright = set_opt_flag(ctl->opt_halfbright); ctl->opt_hb_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_BLINK: ctl->opt_blink = set_opt_flag(ctl->opt_blink); ctl->opt_bl_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_REVERSE: ctl->opt_reverse = set_opt_flag(ctl->opt_reverse); ctl->opt_re_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_UNDERLINE: ctl->opt_underline = set_opt_flag(ctl->opt_underline); ctl->opt_un_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_STORE: ctl->opt_store = set_opt_flag(ctl->opt_store); break; case OPT_CLEAR: ctl->opt_clear = set_opt_flag(ctl->opt_clear); ctl->opt_cl_all = parse_switch(optarg, _("argument error"), "all", "reset", NULL); break; case OPT_TABS: ctl->opt_tabs = set_opt_flag(ctl->opt_tabs); parse_tabs(av, optarg, &optind, ctl->opt_tb_array); break; case OPT_CLRTABS: ctl->opt_clrtabs = set_opt_flag(ctl->opt_clrtabs); parse_tabs(av, optarg, &optind, ctl->opt_tb_array); break; case OPT_REGTABS: ctl->opt_regtabs = set_opt_flag(ctl->opt_regtabs); ctl->opt_rt_len = parse_regtabs(av, optarg, &optind); break; case OPT_BLANK: ctl->opt_blank = set_opt_flag(ctl->opt_blank); ctl->opt_bl_min = parse_blank(av, optarg, &optind); break; case OPT_DUMP: ctl->opt_snap = set_opt_flag(ctl->opt_snap); ctl->opt_sn_num = parse_snap(av, optarg, &optind); break; case OPT_APPEND: ctl->opt_append = set_opt_flag(ctl->opt_append); ctl->opt_sn_num = parse_snap(av, optarg, &optind); break; case OPT_FILE: ctl->opt_snapfile = set_opt_flag(ctl->opt_snapfile); ctl->opt_sn_name = optarg; break; case OPT_MSG: ctl->opt_msg = set_opt_flag(ctl->opt_msg); ctl->opt_msg_on = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case OPT_MSGLEVEL: ctl->opt_msglevel = set_opt_flag(ctl->opt_msglevel); ctl->opt_msglevel_num = parse_msglevel(optarg); if (ctl->opt_msglevel_num == 0) { ctl->opt_msg = set_opt_flag(ctl->opt_msg); ctl->opt_msg_on |= 1; } break; case OPT_POWERSAVE: ctl->opt_powersave = set_opt_flag(ctl->opt_powersave); ctl->opt_ps_mode = parse_powersave(optarg); break; case OPT_POWERDOWN: ctl->opt_powerdown = set_opt_flag(ctl->opt_powerdown); ctl->opt_pd_min = parse_blank(av, optarg, &optind); break; case OPT_BLENGTH: ctl->opt_blength = set_opt_flag(ctl->opt_blength); ctl->opt_blength_l = parse_blength(av, optarg, &optind); break; case OPT_BFREQ: ctl->opt_bfreq = set_opt_flag(ctl->opt_bfreq); ctl->opt_bfreq_f = parse_bfreq(av, optarg, &optind); break; case OPT_VERSION: printf(UTIL_LINUX_VERSION); exit(EXIT_SUCCESS); case OPT_HELP: usage(); default: errtryhelp(EXIT_FAILURE); } } }