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

📄 quotearg.c

📁 制作2.6内核的CLFS时 patch包
💻 C
📖 第 1 页 / 共 2 页
字号:
	c_and_shell_escape:	  if (quoting_style == shell_quoting_style)	    goto use_shell_always_quoting_style;	c_escape:	  if (backslash_escapes)	    {	      c = esc;	      goto store_escape;	    }	  break;	case '#': case '~':	  if (i != 0)	    break;	  /* Fall through.  */	case ' ':	case '!': /* special in bash */	case '"': case '$': case '&':	case '(': case ')': case '*': case ';':	case '<': case '>': case '[':	case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */	case '`': case '|':	  /* A shell special character.  In theory, '$' and '`' could	     be the first bytes of multibyte characters, which means	     we should check them with mbrtowc, but in practice this	     doesn't happen so it's not worth worrying about.  */	  if (quoting_style == shell_quoting_style)	    goto use_shell_always_quoting_style;	  break;	case '\'':	  switch (quoting_style)	    {	    case shell_quoting_style:	      goto use_shell_always_quoting_style;	    case shell_always_quoting_style:	      STORE ('\'');	      STORE ('\\');	      STORE ('\'');	      break;	    default:	      break;	    }	  break;	case '%': case '+': case ',': case '-': case '.': case '/':	case '0': case '1': case '2': case '3': case '4': case '5':	case '6': case '7': case '8': case '9': case ':': case '=':	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':	case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':	case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':	case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':	case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':	case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':	case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':	case 'o': case 'p': case 'q': case 'r': case 's': case 't':	case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':	case '{': case '}':	  /* These characters don't cause problems, no matter what the	     quoting style is.  They cannot start multibyte sequences.  */	  break;	default:	  /* If we have a multibyte sequence, copy it until we reach	     its end, find an error, or come back to the initial shift	     state.  For C-like styles, if the sequence has	     unprintable characters, escape the whole sequence, since	     we can't easily escape single characters within it.  */	  {	    /* Length of multibyte sequence found so far.  */	    size_t m;	    int printable;	    if (unibyte_locale)	      {		m = 1;		printable = isprint (c);	      }	    else	      {		mbstate_t mbstate;		memset (&mbstate, 0, sizeof mbstate);		m = 0;		printable = 1;		if (argsize == SIZE_MAX)		  argsize = strlen (arg);		do		  {		    wchar_t w;		    size_t bytes = mbrtowc (&w, &arg[i + m],					    argsize - (i + m), &mbstate);		    if (bytes == 0)		      break;		    else if (bytes == (size_t) -1)		      {			printable = 0;			break;		      }		    else if (bytes == (size_t) -2)		      {			printable = 0;			while (i + m < argsize && arg[i + m])			  m++;			break;		      }		    else		      {			if (! iswprint (w))			  printable = 0;			m += bytes;		      }		  }		while (! mbsinit (&mbstate));	      }	    if (1 < m || (backslash_escapes && ! printable))	      {		/* Output a multibyte sequence, or an escaped		   unprintable unibyte character.  */		size_t ilim = i + m;		for (;;)		  {		    if (backslash_escapes && ! printable)		      {			STORE ('\\');			STORE ('0' + (c >> 6));			STORE ('0' + ((c >> 3) & 7));			c = '0' + (c & 7);		      }		    if (ilim <= i + 1)		      break;		    STORE (c);		    c = arg[++i];		  }		goto store_c;	      }	  }	}      if (! (backslash_escapes	     && o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))	goto store_c;    store_escape:      STORE ('\\');    store_c:      STORE (c);    }  if (quote_string)    for (; *quote_string; quote_string++)      STORE (*quote_string);  if (len < buffersize)    buffer[len] = '\0';  return len; use_shell_always_quoting_style:  return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,				   shell_always_quoting_style, o);}/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of   argument ARG (of size ARGSIZE), using O to control quoting.   If O is null, use the default.   Terminate the output with a null character, and return the written   size of the output, not counting the terminating null.   If BUFFERSIZE is too small to store the output string, return the   value that would have been returned had BUFFERSIZE been large enough.   If ARGSIZE is -1, use the string length of the argument for ARGSIZE.  */size_tquotearg_buffer (char *buffer, size_t buffersize,		 char const *arg, size_t argsize,		 struct quoting_options const *o){  struct quoting_options const *p = o ? o : &default_quoting_options;  int e = errno;  size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,				       p->style, p);  errno = e;  return r;}/* Use storage slot N to return a quoted version of argument ARG.   ARG is of size ARGSIZE, but if that is -1, ARG is a null-terminated string.   OPTIONS specifies the quoting options.   The returned value points to static storage that can be   reused by the next call to this function with the same value of N.   N must be nonnegative.  N is deliberately declared with type "int"   to allow for future extensions (using negative values).  */static char *quotearg_n_options (int n, char const *arg, size_t argsize,		    struct quoting_options const *options){  int e = errno;  /* Preallocate a slot 0 buffer, so that the caller can always quote     one small component of a "memory exhausted" message in slot 0.  */  static char slot0[256];  static unsigned int nslots = 1;  unsigned int n0 = n;  struct slotvec    {      size_t size;      char *val;    };  static struct slotvec slotvec0 = {sizeof slot0, slot0};  static struct slotvec *slotvec = &slotvec0;  if (n < 0)    abort ();  if (nslots <= n0)    {      unsigned int n1 = n0 + 1;      size_t s = n1 * sizeof *slotvec;      if (SIZE_MAX / UINT_MAX <= sizeof *slotvec	  && n1 != s / sizeof *slotvec)	xalloc_die ();      if (slotvec == &slotvec0)	{	  slotvec = xmalloc (sizeof *slotvec);	  *slotvec = slotvec0;	}      slotvec = xrealloc (slotvec, s);      memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);      nslots = n1;    }  {    size_t size = slotvec[n].size;    char *val = slotvec[n].val;    size_t qsize = quotearg_buffer (val, size, arg, argsize, options);    if (size <= qsize)      {	slotvec[n].size = size = qsize + 1;	slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size);	quotearg_buffer (val, size, arg, argsize, options);      }    errno = e;    return val;  }}char *quotearg_n (int n, char const *arg){  return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);}char *quotearg (char const *arg){  return quotearg_n (0, arg);}/* Return quoting options for STYLE, with no extra quoting.  */static struct quoting_optionsquoting_options_from_style (enum quoting_style style){  struct quoting_options o;  o.style = style;  memset (o.quote_these_too, 0, sizeof o.quote_these_too);  return o;}char *quotearg_n_style (int n, enum quoting_style s, char const *arg){  struct quoting_options const o = quoting_options_from_style (s);  return quotearg_n_options (n, arg, SIZE_MAX, &o);}char *quotearg_n_style_mem (int n, enum quoting_style s,		      char const *arg, size_t argsize){  struct quoting_options const o = quoting_options_from_style (s);  return quotearg_n_options (n, arg, argsize, &o);}char *quotearg_style (enum quoting_style s, char const *arg){  return quotearg_n_style (0, s, arg);}char *quotearg_char (char const *arg, char ch){  struct quoting_options options;  options = default_quoting_options;  set_char_quoting (&options, ch, 1);  return quotearg_n_options (0, arg, SIZE_MAX, &options);}char *quotearg_colon (char const *arg){  return quotearg_char (arg, ':');}

⌨️ 快捷键说明

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