⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argp-help.c

📁 俄罗斯高人Mamaich的Pocket gcc编译器(运行在PocketPC上)的全部源代码。
💻 C
📖 第 1 页 / 共 4 页
字号:
              cp = nl + 1;              nl = strchr (cp, '\n');              if (!nl)                {                  nl = cp;                  while (*nl != '\0') nl++;                }            }	  (*levels)++;	}      /* Manually do line wrapping so that it (probably) won't get wrapped at	 any embedded spaces.  */      space (stream, 1 + nl - cp);      __argp_fmtstream_write (stream, cp, nl - cp);    }  if (fdoc && fdoc != tdoc)    free ((char *)fdoc);	/* Free user's modified doc string.  */  if (child)    while (child->argp)      advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);  if (advance && multiple)    {      /* Need to increment our level.  */      if (*nl)	/* There's more we can do here.  */	{	  (*our_level)++;	  advance = 0;		/* Our parent shouldn't advance also. */	}      else if (*our_level > 0)	/* We had multiple levels, but used them up; reset to zero.  */	*our_level = 0;    }  return !advance;}/* Print the documentation for ARGP to STREAM; if POST is false, then   everything preceeding a `\v' character in the documentation strings (or   the whole string, for those with none) is printed, otherwise, everything   following the `\v' character (nothing for strings without).  Each separate   bit of documentation is separated a blank line, and if PRE_BLANK is true,   then the first is as well.  If FIRST_ONLY is true, only the first   occurrence is output.  Returns true if anything was output.  */static intargp_doc (const struct argp *argp, const struct argp_state *state,	  int post, int pre_blank, int first_only,	  argp_fmtstream_t stream){  const char *text;  const char *inp_text;  char *tmp_text;  void *input = 0;  int anything = 0;  size_t inp_text_limit = 0;  const char *doc = dgettext (argp->argp_domain, argp->doc);  const struct argp_child *child = argp->children;  if (doc)    {      char *vt = strchr (doc, '\v');      inp_text = post ? (vt ? vt + 1 : 0) : doc;      inp_text_limit = (!post && vt) ? (vt - doc) : 0;    }  else    inp_text = 0;  if (argp->help_filter)    /* We have to filter the doc strings.  */    {      if (inp_text_limit)        {          /* Copy INP_TEXT so that it's nul-terminated. */          tmp_text = _malloc_r (_REENT, inp_text_limit);          strncpy (tmp_text, inp_text, inp_text_limit);          _free_r (_REENT, inp_text);          inp_text = tmp_text;        }      input = __argp_input (argp, state);      text =	(*argp->help_filter) (post			      ? ARGP_KEY_HELP_POST_DOC			      : ARGP_KEY_HELP_PRE_DOC,			      inp_text, input);    }  else    text = (const char *) inp_text;  if (text)    {      if (pre_blank)	__argp_fmtstream_putc (stream, '\n');      if (text == inp_text && inp_text_limit)	__argp_fmtstream_write (stream, inp_text, inp_text_limit);      else	__argp_fmtstream_puts (stream, text);      if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))	__argp_fmtstream_putc (stream, '\n');      anything = 1;    }  if (text && text != inp_text)    free ((char *) text);	/* Free TEXT returned from the help filter.  */  if (inp_text && inp_text_limit && argp->help_filter)    free ((char *) inp_text);	/* We copied INP_TEXT, so free it now.  */  if (post && argp->help_filter)    /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text.  */    {      text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input);      if (text)	{	  if (anything || pre_blank)	    __argp_fmtstream_putc (stream, '\n');	  __argp_fmtstream_puts (stream, text);	  free ((char *) text);	  if (__argp_fmtstream_point (stream)	      > __argp_fmtstream_lmargin (stream))	    __argp_fmtstream_putc (stream, '\n');	  anything = 1;	}    }  if (child)    while (child->argp && !(first_only && anything))      anything |=	argp_doc ((child++)->argp, state,		  post, anything || pre_blank, first_only,		  stream);  return anything;}/* Output a usage message for ARGP to STREAM.  If called from   argp_state_help, STATE is the relevent parsing state.  FLAGS are from the   set ARGP_HELP_*.  NAME is what to use wherever a `program name' is   needed. */static void_help (const struct argp *argp, const struct argp_state *state, FILE *stream,       unsigned flags, char *name){  int anything = 0;		/* Whether we've output anything.  */  struct hol *hol = 0;  argp_fmtstream_t fs;  if (! stream)    return;  _flockfile (stream);  if (! uparams.valid)    fill_in_uparams (state);  fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);  if (! fs)    {      _funlockfile (stream);      return;    }  if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))    {      hol = argp_hol (argp, 0);      /* If present, these options always come last.  */      hol_set_group (hol, "help", -1);      hol_set_group (hol, "version", -1);      hol_sort (hol);    }  if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))    /* Print a short `Usage:' message.  */    {      int first_pattern = 1, more_patterns;      size_t num_pattern_levels = argp_args_levels (argp);      char *pattern_levels = alloca (num_pattern_levels);      memset (pattern_levels, 0, num_pattern_levels);      do	{	  int old_lm;	  int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);	  char *levels = pattern_levels;	  if (first_pattern)	    __argp_fmtstream_printf (fs, "%s %s",				     dgettext (argp->argp_domain, "Usage:"),				     name);	  else	    __argp_fmtstream_printf (fs, "%s %s",				     dgettext (argp->argp_domain, "  or: "),				     name);	  /* We set the lmargin as well as the wmargin, because hol_usage	     manually wraps options with newline to avoid annoying breaks.  */	  old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent);	  if (flags & ARGP_HELP_SHORT_USAGE)	    /* Just show where the options go.  */	    {	      if (hol->num_entries > 0)		__argp_fmtstream_puts (fs, dgettext (argp->argp_domain,						     " [OPTION...]"));	    }	  else	    /* Actually print the options.  */	    {	      hol_usage (hol, fs);	      flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once.  */	    }	  more_patterns = argp_args_usage (argp, state, &levels, 1, fs);	  __argp_fmtstream_set_wmargin (fs, old_wm);	  __argp_fmtstream_set_lmargin (fs, old_lm);	  __argp_fmtstream_putc (fs, '\n');	  anything = 1;	  first_pattern = 0;	}      while (more_patterns);    }  if (flags & ARGP_HELP_PRE_DOC)    anything |= argp_doc (argp, state, 0, 0, 1, fs);  if (flags & ARGP_HELP_SEE)    {      __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\Try `%s --help' or `%s --usage' for more information.\n"),			       name, name);      anything = 1;    }  if (flags & ARGP_HELP_LONG)    /* Print a long, detailed help message.  */    {      /* Print info about all the options.  */      if (hol->num_entries > 0)	{	  if (anything)	    __argp_fmtstream_putc (fs, '\n');	  hol_help (hol, state, fs);	  anything = 1;	}    }  if (flags & ARGP_HELP_POST_DOC)    /* Print any documentation strings at the end.  */    anything |= argp_doc (argp, state, 1, anything, 0, fs);  if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address)    {      if (anything)	__argp_fmtstream_putc (fs, '\n');      __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,					     "Report bugs to %s.\n"), 			       argp_program_bug_address);      anything = 1;    }  _funlockfile (stream);  if (hol)    hol_free (hol);  __argp_fmtstream_free (fs);}/* Output a usage message for ARGP to STREAM.  FLAGS are from the set   ARGP_HELP_*.  NAME is what to use wherever a `program name' is needed. */void __argp_help (const struct argp *argp, FILE *stream,		  unsigned flags, char *name){  _help (argp, 0, stream, flags, name);}#ifdef weak_aliasweak_alias (__argp_help, argp_help)#endif/* Output, if appropriate, a usage message for STATE to STREAM.  FLAGS are   from the set ARGP_HELP_*.  */void__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags){  if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream)    {      if (state && (state->flags & ARGP_LONG_ONLY))	flags |= ARGP_HELP_LONG_ONLY;      _help (state ? state->root_argp : 0, state, stream, flags,	     state ? state->name : program_invocation_short_name);      if (!state || ! (state->flags & ARGP_NO_EXIT))	{	  if (flags & ARGP_HELP_EXIT_ERR)	    exit (argp_err_exit_status);	  if (flags & ARGP_HELP_EXIT_OK)	    exit (0);	}  }}#ifdef weak_aliasweak_alias (__argp_state_help, argp_state_help)#endif/* If appropriate, print the printf string FMT and following args, preceded   by the program name and `:', to stderr, and followed by a `Try ... --help'   message, then exit (1).  */void__argp_error (const struct argp_state *state, const char *fmt, ...){  if (!state || !(state->flags & ARGP_NO_ERRS))    {      FILE *stream = state ? state->err_stream : stderr;      if (stream)	{	  va_list ap;	  _flockfile (stream);	  va_start (ap, fmt);#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    {	      char *buf;	      __asprintf (&buf, fmt, ap);	      __fwprintf (stream, L"%s: %s\n",			  state ? state->name : program_invocation_short_name,			  buf);	      free (buf);	    }	  else#endif	    {	      fputs (state			      ? state->name : program_invocation_short_name,			      stream);	      putc_unlocked (':', stream);	      putc_unlocked (' ', stream);	      vfprintf (stream, fmt, ap);	      putc_unlocked ('\n', stream);	    }	  __argp_state_help (state, stream, ARGP_HELP_STD_ERR);	  va_end (ap);	  _funlockfile (stream);	}    }}#ifdef weak_aliasweak_alias (__argp_error, argp_error)#endif/* Similar to the standard gnu error-reporting function error(), but will   respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print   to STATE->err_stream.  This is useful for argument parsing code that is   shared between program startup (when exiting is desired) and runtime   option parsing (when typically an error code is returned instead).  The   difference between this function and argp_error is that the latter is for   *parsing errors*, and the former is for other problems that occur during   parsing but don't reflect a (syntactic) problem with the input.  */void__argp_failure (const struct argp_state *state, int status, int errnum,		const char *fmt, ...){  if (!state || !(state->flags & ARGP_NO_ERRS))    {      FILE *stream = state ? state->err_stream : stderr;      if (stream)	{	  _flockfile (stream);#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    __fwprintf (stream, L"%s",			state ? state->name : program_invocation_short_name);	  else#endif	    fputs (state			    ? state->name : program_invocation_short_name,			    stream);	  if (fmt)	    {	      va_list ap;	      va_start (ap, fmt);#ifdef USE_IN_LIBIO	      if (_IO_fwide (stream, 0) > 0)		{		  char *buf;		  __asprintf (&buf, fmt, ap);		  __fwprintf (stream, L": %s", buf);		  free (buf);		}	      else#endif		{		  putc_unlocked (':', stream);		  putc_unlocked (' ', stream);		  vfprintf (stream, fmt, ap);		}	      va_end (ap);	    }	  if (errnum)	    {	      char buf[200];#ifdef USE_IN_LIBIO	      if (_IO_fwide (stream, 0) > 0)		__fwprintf (stream, L": %s",			    strerror_r (errnum, buf, sizeof (buf)));	      else#endif		{		  putc_unlocked (':', stream);		  putc_unlocked (' ', stream);		  fputs (strerror_r (errnum, buf, sizeof (buf)), stream);		}	    }#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    putwc_unlocked (L'\n', stream);	  else#endif	    putc_unlocked ('\n', stream);	  _funlockfile (stream);	  if (status && (!state || !(state->flags & ARGP_NO_EXIT)))	    exit (status);	}    }}#ifdef weak_aliasweak_alias (__argp_failure, argp_failure)#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -