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

📄 general.c

📁 android-w.song.android.widget
💻 C
📖 第 1 页 / 共 2 页
字号:
{  if (string == 0 || *string == '\0')    return (0);  if (ABSPATH(string))    return (1);  if (string[0] == '.' && PATHSEP(string[1]))	/* . and ./ */    return (1);  if (string[0] == '.' && string[1] == '.' && PATHSEP(string[2]))	/* .. and ../ */    return (1);  return (0);}/* Return 1 if STRING is an absolute program name; it is absolute if it   contains any slashes.  This is used to decide whether or not to look   up through $PATH. */intabsolute_program (string)     const char *string;{  return ((char *)mbschr (string, '/') != (char *)NULL);}/* **************************************************************** *//*								    *//*		    Functions to manipulate pathnames		    *//*								    *//* **************************************************************** *//* Turn STRING (a pathname) into an absolute pathname, assuming that   DOT_PATH contains the symbolic location of `.'.  This always   returns a new string, even if STRING was an absolute pathname to   begin with. */char *make_absolute (string, dot_path)     char *string, *dot_path;{  char *result;  if (dot_path == 0 || ABSPATH(string))#ifdef __CYGWIN__    {      char pathbuf[PATH_MAX + 1];      cygwin_conv_to_full_posix_path (string, pathbuf);      result = savestring (pathbuf);    }#else    result = savestring (string);#endif  else    result = sh_makepath (dot_path, string, 0);  return (result);}/* Return the `basename' of the pathname in STRING (the stuff after the   last '/').  If STRING is `/', just return it. */char *base_pathname (string)     char *string;{  char *p;#if 0  if (absolute_pathname (string) == 0)    return (string);#endif  if (string[0] == '/' && string[1] == 0)    return (string);  p = (char *)strrchr (string, '/');  return (p ? ++p : string);}/* Return the full pathname of FILE.  Easy.  Filenames that begin   with a '/' are returned as themselves.  Other filenames have   the current working directory prepended.  A new string is   returned in either case. */char *full_pathname (file)     char *file;{  char *ret;  file = (*file == '~') ? bash_tilde_expand (file, 0) : savestring (file);  if (ABSPATH(file))    return (file);  ret = sh_makepath ((char *)NULL, file, (MP_DOCWD|MP_RMDOT));  free (file);  return (ret);}/* A slightly related function.  Get the prettiest name of this   directory possible. */static char tdir[PATH_MAX];/* Return a pretty pathname.  If the first part of the pathname is   the same as $HOME, then replace that with `~'.  */char *polite_directory_format (name)     char *name;{  char *home;  int l;  home = get_string_value ("HOME");  l = home ? strlen (home) : 0;  if (l > 1 && strncmp (home, name, l) == 0 && (!name[l] || name[l] == '/'))    {      strncpy (tdir + 1, name + l, sizeof(tdir) - 2);      tdir[0] = '~';      tdir[sizeof(tdir) - 1] = '\0';      return (tdir);    }  else    return (name);}/* Trim NAME.  If NAME begins with `~/', skip over tilde prefix.  Trim to   keep any tilde prefix and PROMPT_DIRTRIM trailing directory components   and replace the intervening characters with `...' */char *trim_pathname (name, maxlen)     char *name;     int maxlen;{  int nlen, ndirs;  intmax_t nskip;  char *nbeg, *nend, *ntail, *v;  if (name == 0 || (nlen = strlen (name)) == 0)    return name;  nend = name + nlen;  v = get_string_value ("PROMPT_DIRTRIM");  if (v == 0 || *v == 0)    return name;  if (legal_number (v, &nskip) == 0 || nskip <= 0)    return name;  /* Skip over tilde prefix */  nbeg = name;  if (name[0] == '~')    for (nbeg = name; *nbeg; nbeg++)      if (*nbeg == '/')	{	  nbeg++;	  break;	}  if (*nbeg == 0)    return name;  for (ndirs = 0, ntail = nbeg; *ntail; ntail++)    if (*ntail == '/')      ndirs++;  if (ndirs < nskip)    return name;  for (ntail = (*nend == '/') ? nend : nend - 1; ntail > nbeg; ntail--)    {      if (*ntail == '/')	nskip--;      if (nskip == 0)	break;    }  if (ntail == nbeg)    return name;  /* Now we want to return name[0..nbeg]+"..."+ntail, modifying name in place */  nlen = ntail - nbeg;  if (nlen <= 3)    return name;  *nbeg++ = '.';  *nbeg++ = '.';  *nbeg++ = '.';  nlen = nend - ntail;  memcpy (nbeg, ntail, nlen);  nbeg[nlen] = '\0';  return name;}/* Given a string containing units of information separated by colons,   return the next one pointed to by (P_INDEX), or NULL if there are no more.   Advance (P_INDEX) to the character after the colon. */char *extract_colon_unit (string, p_index)     char *string;     int *p_index;{  int i, start, len;  char *value;  if (string == 0)    return (string);  len = strlen (string);  if (*p_index >= len)    return ((char *)NULL);  i = *p_index;  /* Each call to this routine leaves the index pointing at a colon if     there is more to the path.  If I is > 0, then increment past the     `:'.  If I is 0, then the path has a leading colon.  Trailing colons     are handled OK by the `else' part of the if statement; an empty     string is returned in that case. */  if (i && string[i] == ':')    i++;  for (start = i; string[i] && string[i] != ':'; i++)    ;  *p_index = i;  if (i == start)    {      if (string[i])	(*p_index)++;      /* Return "" in the case of a trailing `:'. */      value = (char *)xmalloc (1);      value[0] = '\0';    }  else    value = substring (string, start, i);  return (value);}/* **************************************************************** *//*								    *//*		    Tilde Initialization and Expansion		    *//*								    *//* **************************************************************** */#if defined (PUSHD_AND_POPD)extern char *get_dirstack_from_string __P((char *));#endifstatic char **bash_tilde_prefixes;static char **bash_tilde_prefixes2;static char **bash_tilde_suffixes;static char **bash_tilde_suffixes2;/* If tilde_expand hasn't been able to expand the text, perhaps it   is a special shell expansion.  This function is installed as the   tilde_expansion_preexpansion_hook.  It knows how to expand ~- and ~+.   If PUSHD_AND_POPD is defined, ~[+-]N expands to directories from the   directory stack. */static char *bash_special_tilde_expansions (text)     char *text;{  char *result;  result = (char *)NULL;  if (text[0] == '+' && text[1] == '\0')    result = get_string_value ("PWD");  else if (text[0] == '-' && text[1] == '\0')    result = get_string_value ("OLDPWD");#if defined (PUSHD_AND_POPD)  else if (DIGIT (*text) || ((*text == '+' || *text == '-') && DIGIT (text[1])))    result = get_dirstack_from_string (text);#endif  return (result ? savestring (result) : (char *)NULL);}/* Initialize the tilde expander.  In Bash, we handle `~-' and `~+', as   well as handling special tilde prefixes; `:~" and `=~' are indications   that we should do tilde expansion. */voidtilde_initialize (){  static int times_called = 0;  /* Tell the tilde expander that we want a crack first. */  tilde_expansion_preexpansion_hook = bash_special_tilde_expansions;  /* Tell the tilde expander about special strings which start a tilde     expansion, and the special strings that end one.  Only do this once.     tilde_initialize () is called from within bashline_reinitialize (). */  if (times_called++ == 0)    {      bash_tilde_prefixes = strvec_create (3);      bash_tilde_prefixes[0] = "=~";      bash_tilde_prefixes[1] = ":~";      bash_tilde_prefixes[2] = (char *)NULL;      bash_tilde_prefixes2 = strvec_create (2);      bash_tilde_prefixes2[0] = ":~";      bash_tilde_prefixes2[1] = (char *)NULL;      tilde_additional_prefixes = bash_tilde_prefixes;      bash_tilde_suffixes = strvec_create (3);      bash_tilde_suffixes[0] = ":";      bash_tilde_suffixes[1] = "=~";	/* XXX - ?? */      bash_tilde_suffixes[2] = (char *)NULL;      tilde_additional_suffixes = bash_tilde_suffixes;      bash_tilde_suffixes2 = strvec_create (2);      bash_tilde_suffixes2[0] = ":";      bash_tilde_suffixes2[1] = (char *)NULL;    }}/* POSIX.2, 3.6.1:  A tilde-prefix consists of an unquoted tilde character   at the beginning of the word, followed by all of the characters preceding   the first unquoted slash in the word, or all the characters in the word   if there is no slash...If none of the characters in the tilde-prefix are   quoted, the characters in the tilde-prefix following the tilde shell be   treated as a possible login name. */#define TILDE_END(c)	((c) == '\0' || (c) == '/' || (c) == ':')static intunquoted_tilde_word (s)     const char *s;{  const char *r;  for (r = s; TILDE_END(*r) == 0; r++)    {      switch (*r)	{	case '\\':	case '\'':	case '"':	  return 0;	}    }  return 1;}/* Find the end of the tilde-prefix starting at S, and return the tilde   prefix in newly-allocated memory.  Return the length of the string in   *LENP.  FLAGS tells whether or not we're in an assignment context --   if so, `:' delimits the end of the tilde prefix as well. */char *bash_tilde_find_word (s, flags, lenp)     const char *s;     int flags, *lenp;{  const char *r;  char *ret;  int l;  for (r = s; *r && *r != '/'; r++)    {      /* Short-circuit immediately if we see a quote character.  Even though	 POSIX says that `the first unquoted slash' (or `:') terminates the	 tilde-prefix, in practice, any quoted portion of the tilde prefix	 will cause it to not be expanded. */      if (*r == '\\' || *r == '\'' || *r == '"')  	{	  ret = savestring (s);	  if (lenp)	    *lenp = 0;	  return ret;	}      else if (flags && *r == ':')	break;    }  l = r - s;  ret = xmalloc (l + 1);  strncpy (ret, s, l);  ret[l] = '\0';  if (lenp)    *lenp = l;  return ret;}    /* Tilde-expand S by running it through the tilde expansion library.   ASSIGN_P is 1 if this is a variable assignment, so the alternate   tilde prefixes should be enabled (`=~' and `:~', see above).  If   ASSIGN_P is 2, we are expanding the rhs of an assignment statement,   so `=~' is not valid. */char *bash_tilde_expand (s, assign_p)     const char *s;     int assign_p;{  int old_immed, old_term, r;  char *ret;  old_immed = interrupt_immediately;  old_term = terminate_immediately;  interrupt_immediately = terminate_immediately = 1;  tilde_additional_prefixes = assign_p == 0 ? (char **)0  					    : (assign_p == 2 ? bash_tilde_prefixes2 : bash_tilde_prefixes);  if (assign_p == 2)    tilde_additional_suffixes = bash_tilde_suffixes2;  r = (*s == '~') ? unquoted_tilde_word (s) : 1;  ret = r ? tilde_expand (s) : savestring (s);  interrupt_immediately = old_immed;  terminate_immediately = old_term;  return (ret);}/* **************************************************************** *//*								    *//*	  Functions to manipulate and search the group list	    *//*								    *//* **************************************************************** */static int ngroups, maxgroups;/* The set of groups that this user is a member of. */static GETGROUPS_T *group_array = (GETGROUPS_T *)NULL;#if !defined (NOGROUP)#  define NOGROUP (gid_t) -1#endifstatic voidinitialize_group_array (){  register int i;  if (maxgroups == 0)    maxgroups = getmaxgroups ();  ngroups = 0;  group_array = (GETGROUPS_T *)xrealloc (group_array, maxgroups * sizeof (GETGROUPS_T));#if defined (HAVE_GETGROUPS)  ngroups = getgroups (maxgroups, group_array);#endif  /* If getgroups returns nothing, or the OS does not support getgroups(),     make sure the groups array includes at least the current gid. */  if (ngroups == 0)    {      group_array[0] = current_user.gid;      ngroups = 1;    }  /* If the primary group is not in the groups array, add it as group_array[0]     and shuffle everything else up 1, if there's room. */  for (i = 0; i < ngroups; i++)    if (current_user.gid == (gid_t)group_array[i])      break;  if (i == ngroups && ngroups < maxgroups)    {      for (i = ngroups; i > 0; i--)	group_array[i] = group_array[i - 1];      group_array[0] = current_user.gid;      ngroups++;    }  /* If the primary group is not group_array[0], swap group_array[0] and     whatever the current group is.  The vast majority of systems should     not need this; a notable exception is Linux. */  if (group_array[0] != current_user.gid)    {      for (i = 0; i < ngroups; i++)	if (group_array[i] == current_user.gid)	  break;      if (i < ngroups)	{	  group_array[i] = group_array[0];	  group_array[0] = current_user.gid;	}    }}/* Return non-zero if GID is one that we have in our groups list. */int#if defined (__STDC__) || defined ( _MINIX)group_member (gid_t gid)#elsegroup_member (gid)     gid_t gid;#endif /* !__STDC__ && !_MINIX */{#if defined (HAVE_GETGROUPS)  register int i;#endif  /* Short-circuit if possible, maybe saving a call to getgroups(). */  if (gid == current_user.gid || gid == current_user.egid)    return (1);#if defined (HAVE_GETGROUPS)  if (ngroups == 0)    initialize_group_array ();  /* In case of error, the user loses. */  if (ngroups <= 0)    return (0);  /* Search through the list looking for GID. */  for (i = 0; i < ngroups; i++)    if (gid == (gid_t)group_array[i])      return (1);#endif  return (0);}char **get_group_list (ngp)     int *ngp;{  static char **group_vector = (char **)NULL;  register int i;  if (group_vector)    {      if (ngp)	*ngp = ngroups;      return group_vector;    }  if (ngroups == 0)    initialize_group_array ();  if (ngroups <= 0)    {      if (ngp)	*ngp = 0;      return (char **)NULL;    }  group_vector = strvec_create (ngroups);  for (i = 0; i < ngroups; i++)    group_vector[i] = itos (group_array[i]);  if (ngp)    *ngp = ngroups;  return group_vector;}int *get_group_array (ngp)     int *ngp;{  int i;  static int *group_iarray = (int *)NULL;  if (group_iarray)    {      if (ngp)	*ngp = ngroups;      return (group_iarray);    }  if (ngroups == 0)    initialize_group_array ();      if (ngroups <= 0)    {      if (ngp)	*ngp = 0;      return (int *)NULL;    }  group_iarray = (int *)xmalloc (ngroups * sizeof (int));  for (i = 0; i < ngroups; i++)    group_iarray[i] = (int)group_array[i];  if (ngp)    *ngp = ngroups;  return group_iarray;}

⌨️ 快捷键说明

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