📄 args.c
字号:
if (*s1++ != *s2++) { ret = false; } } *start_param = s2; return ret;}/* Set the defaults. */void set_defaults (void){ const pro_ty *p; for (p = pro; p->p_name; p++) { if ((p->p_type == PRO_BOOL && p->p_special == ON) || p->p_type == PRO_INT) { *p->p_obj = p->p_default; } }}/* Set the defaults after options set */void set_defaults_after (void){ if (!exp_lc) /* if no -lc option was given */ { settings.comment_max_col = settings.max_col; }}/* Strings which can prefix an option, longest first. */static char *option_prefixes[] ={ "--", "-", "+", 0};static void arg_missing( const char *option){ fprintf (stderr, _("indent: missing argument to parameter %s\n"), option); exit (invocation_error);}static int option_prefix ( const char * arg){ char ** prefixes = option_prefixes; char * this_prefix = *prefixes; const char * argp = arg; int ret = 0; do { this_prefix = *prefixes; argp = arg; while (*this_prefix == *argp) { this_prefix++; argp++; } if (*this_prefix == '\0') { ret = this_prefix - *prefixes; break; } } while (*++prefixes); return ret;}/* Process an option ARG (e.g. "-l60"). PARAM is a possible value * for ARG, if PARAM is nonzero. EXPLICT should be nonzero iff the * argument is being explicitly specified (as opposed to being taken from a * PRO_SETTINGS group of settings). * * Returns 1 if the option had a value, returns 0 otherwise. * * 2002-06-13 D.Ingamells. Fixed check for int param without an int argument. */int set_option ( const char * option, const char * param, int explicit){ const pro_ty * p = pro; const char * param_start = NULL; int option_length = option_prefix (option); int val = 0; BOOLEAN found = false; if (option_length > 0) { if ((option_length == 1) && (*option == '-')) { /* Short option prefix */ option++; for (p = pro; p->p_name; p++) { if ((*p->p_name == *option) && eqin (p->p_name, option, ¶m_start)) { found = true; break; } } } else { /* Long prefix */ const long_option_conversion_ty *o = option_conversions; option += option_length; while (o->short_name) { if (eqin (o->long_name, option, ¶m_start)) { break; } o++; } /* Searching twice means we don't have to keep the two tables in * sync. */ if (o->short_name) { for (p = pro; p->p_name; p++) { if (!strcmp (p->p_name, o->short_name)) { found = true; break; } } } } } if (!found) { fprintf (stderr, _("indent: unknown option \"%s\"\n"), option - 1); exit (invocation_error); } else { /* If the parameter has been explicitly specified, we don't * want a group of bundled settings to override the explicit * setting. */ if (settings.verbose) { fprintf (stderr, _("option: %s\n"), p->p_name); } if (explicit || !*(p->p_explicit)) { if (explicit) { *(p->p_explicit) = 1; } switch (p->p_type) { case PRO_PRSTRING: /* This is not really an error, but zero exit values are returned only when code has been successfully formatted. */ printf (_("GNU indent %s\n"), (char *) p->p_obj); exit (invocation_error); case PRO_FUNCTION: ((void (*)()) p->p_obj) (); break; case PRO_SETTINGS: { char *t; /* current position */ t = (char *) p->p_obj; do { set_option (t, 0, 0); /* advance to character following next NUL */ while (*t++) { } } while (*t); } case PRO_IGN: break; case PRO_KEY: { char *str; if (*param_start == 0) { if (!(param_start = param)) { arg_missing(option); } else { val = 1; } } str = (char *) xmalloc (strlen (param_start) + 1); strcpy (str, param_start); addkey (str, rw_decl); } break; case PRO_BOOL: if (p->p_special == OFF) { *p->p_obj = false; } else { *p->p_obj = true; } break; case PRO_INT: if (*param_start == '\0') { param_start = param; if (param_start == NULL) { arg_missing(option); } else { val = 1; } } if (isdigit (*param_start) || ((*param_start == '-') && isdigit (*(param_start + 1)))) { *p->p_obj = atoi (param_start); } else { fprintf (stderr, _("indent: option ``%s'' requires a numeric parameter\n"), option - 1); exit (invocation_error); } break; default: fprintf (stderr, _("indent: set_option: internal error: p_type %d\n"), (int) p->p_type); exit (invocation_error); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -