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

📄 argp-help.c

📁 gnu tar 源码包。 tar 软件是 Unix 系统下的一个打包软件
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* 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;  size_t inp_text_len = 0;  const char *trans_text;  void *input = 0;  int anything = 0;  const struct argp_child *child = argp->children;  if (argp->doc)    {      char *vt = strchr (argp->doc, '\v');      if (vt)	{	  if (post)	    inp_text = vt + 1;	  else	    {	      inp_text_len = vt - argp->doc;	      inp_text = __strndup (argp->doc, inp_text_len);	    }	}      else	inp_text = post ? 0 : argp->doc;      trans_text = inp_text ? dgettext (argp->argp_domain, inp_text) : NULL;    }  else    trans_text = inp_text = 0;  if (argp->help_filter)    /* We have to filter the doc strings.  */    {      input = __argp_input (argp, state);      text =	(*argp->help_filter) (post			      ? ARGP_KEY_HELP_POST_DOC			      : ARGP_KEY_HELP_PRE_DOC,			      trans_text, input);    }  else    text = (const char *) trans_text;  if (text)    {      if (pre_blank)	__argp_fmtstream_putc (stream, '\n');      __argp_fmtstream_puts (stream, text);      if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))	__argp_fmtstream_putc (stream, '\n');      anything = 1;    }  if (text && text != trans_text)    free ((char *) text);	/* Free TEXT returned from the help filter.  */  if (inp_text && inp_text_len)    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;#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)  __flockfile (stream);#endif  if (! uparams.valid)    fill_in_uparams (state);  fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);  if (! fs)    {#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)      __funlockfile (stream);#endif      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;    }#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)  __funlockfile (stream);#endif  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){  struct argp_state state;  memset (&state, 0, sizeof state);  state.root_argp = argp;  _help (argp, &state, stream, flags, name);}#ifdef weak_aliasweak_alias (__argp_help, argp_help)#endif#if ! (defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)char *__argp_short_program_name (void){# if HAVE_DECL_PROGRAM_INVOCATION_NAME  return __argp_base_name (program_invocation_name);# else  /* FIXME: What now? Miles suggests that it is better to use NULL,     but currently the value is passed on directly to fputs_unlocked,     so that requires more changes. */# if __GNUC__#  warning No reasonable value to return# endif /* __GNUC__ */  return "";# endif}#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 : __argp_short_program_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;#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)	  __flockfile (stream);#endif	  va_start (ap, fmt);#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    {	      char *buf;	      if (__asprintf (&buf, fmt, ap) < 0)		buf = NULL;	      __fwprintf (stream, L"%s: %s\n",			  state ? state->name : __argp_short_program_name (),			  buf);	      free (buf);	    }	  else#endif	    {	      fputs_unlocked (state			      ? state->name : __argp_short_program_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);#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)	  __funlockfile (stream);#endif	}    }}#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)	{#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)	  __flockfile (stream);#endif#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    __fwprintf (stream, L"%s",			state ? state->name : __argp_short_program_name ());	  else#endif	    fputs_unlocked (state			    ? state->name : __argp_short_program_name (),			    stream);	  if (fmt)	    {	      va_list ap;	      va_start (ap, fmt);#ifdef USE_IN_LIBIO	      if (_IO_fwide (stream, 0) > 0)		{		  char *buf;		  if (__asprintf (&buf, fmt, ap) < 0)		    buf = NULL;		  __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		{		  char const *s = NULL;		  putc_unlocked (':', stream);		  putc_unlocked (' ', stream);#if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P)		  s = __strerror_r (errnum, buf, sizeof buf);#elif HAVE_DECL_STRERROR_R		  if (__strerror_r (errnum, buf, sizeof buf) == 0)		    s = buf;#endif#if !_LIBC		  if (! s && ! (s = strerror (errnum)))		    s = dgettext (state->root_argp->argp_domain,				  "Unknown system error");#endif		  fputs (s, stream);		}	    }#ifdef USE_IN_LIBIO	  if (_IO_fwide (stream, 0) > 0)	    putwc_unlocked (L'\n', stream);	  else#endif	    putc_unlocked ('\n', stream);#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)	  __funlockfile (stream);#endif	  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 + -