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

📄 common.c

📁 android-w.song.android.widget
💻 C
📖 第 1 页 / 共 2 页
字号:
   number by setting *NUMOK == 0 and return -1. */intget_numeric_arg (list, fatal, count)     WORD_LIST *list;     int fatal;     intmax_t *count;{  char *arg;  if (count)    *count = 1;  if (list && list->word && ISOPTION (list->word->word, '-'))    list = list->next;  if (list)    {      arg = list->word->word;      if (arg == 0 || (legal_number (arg, count) == 0))	{	  sh_neednumarg (list->word->word ? list->word->word : "`'");	  if (fatal == 0)	    return 0;	  else if (fatal == 1)		/* fatal == 1; abort */	    throw_to_top_level ();	  else				/* fatal == 2; discard current command */	    {	      top_level_cleanup ();	      jump_to_top_level (DISCARD);	    }	}      no_args (list->next);    }  return (1);}/* Get an eight-bit status value from LIST */intget_exitstat (list)     WORD_LIST *list;{  int status;  intmax_t sval;  char *arg;  if (list && list->word && ISOPTION (list->word->word, '-'))    list = list->next;  if (list == 0)    return (last_command_exit_value);        arg = list->word->word;  if (arg == 0 || legal_number (arg, &sval) == 0)    {      sh_neednumarg (list->word->word ? list->word->word : "`'");      return 255;    }  no_args (list->next);  status = sval & 255;  return status;}/* Return the octal number parsed from STRING, or -1 to indicate   that the string contained a bad number. */intread_octal (string)     char *string;{  int result, digits;  result = digits = 0;  while (*string && ISOCTAL (*string))    {      digits++;      result = (result * 8) + (*string++ - '0');      if (result > 0777)	return -1;    }  if (digits == 0 || *string)    result = -1;  return (result);}/* **************************************************************** *//*								    *//*	     Manipulating the current working directory		    *//*								    *//* **************************************************************** *//* Return a consed string which is the current working directory.   FOR_WHOM is the name of the caller for error printing.  */char *the_current_working_directory = (char *)NULL;char *get_working_directory (for_whom)     char *for_whom;{  if (no_symbolic_links)    {      FREE (the_current_working_directory);      the_current_working_directory = (char *)NULL;    }  if (the_current_working_directory == 0)    {#if defined (GETCWD_BROKEN)      the_current_working_directory = getcwd (0, PATH_MAX);#else      the_current_working_directory = getcwd (0, 0);#endif      if (the_current_working_directory == 0)	{	  fprintf (stderr, _("%s: error retrieving current directory: %s: %s\n"),		   (for_whom && *for_whom) ? for_whom : get_name_for_error (),		   _(bash_getcwd_errstr), strerror (errno));	  return (char *)NULL;	}    }  return (savestring (the_current_working_directory));}/* Make NAME our internal idea of the current working directory. */voidset_working_directory (name)     char *name;{  FREE (the_current_working_directory);  the_current_working_directory = savestring (name);}/* **************************************************************** *//*								    *//*	     	Job control support functions			    *//*								    *//* **************************************************************** */#if defined (JOB_CONTROL)intget_job_by_name (name, flags)     const char *name;     int flags;{  register int i, wl, cl, match, job;  register PROCESS *p;  register JOB *j;  job = NO_JOB;  wl = strlen (name);  for (i = js.j_jobslots - 1; i >= 0; i--)    {      j = get_job_by_jid (i);      if (j == 0 || ((flags & JM_STOPPED) && J_JOBSTATE(j) != JSTOPPED))        continue;      p = j->pipe;      do        {	  if (flags & JM_EXACT)	    {	      cl = strlen (p->command);	      match = STREQN (p->command, name, cl);	    }	  else if (flags & JM_SUBSTRING)	    match = strcasestr (p->command, name) != (char *)0;	  else	    match = STREQN (p->command, name, wl);	  if (match == 0)	    {	      p = p->next;	      continue;	    }	  else if (flags & JM_FIRSTMATCH)	    return i;		/* return first match */	  else if (job != NO_JOB)	    {	      if (this_shell_builtin)	        builtin_error (_("%s: ambiguous job spec"), name);	      else	        report_error (_("%s: ambiguous job spec"), name);	      return (DUP_JOB);	    }	  else	    job = i;        }      while (p != j->pipe);    }  return (job);}/* Return the job spec found in LIST. */intget_job_spec (list)     WORD_LIST *list;{  register char *word;  int job, jflags;  if (list == 0)    return (js.j_current);  word = list->word->word;  if (*word == '\0')    return (NO_JOB);  if (*word == '%')    word++;  if (DIGIT (*word) && all_digits (word))    {      job = atoi (word);      return (job > js.j_jobslots ? NO_JOB : job - 1);    }  jflags = 0;  switch (*word)    {    case 0:    case '%':    case '+':      return (js.j_current);    case '-':      return (js.j_previous);    case '?':			/* Substring search requested. */      jflags |= JM_SUBSTRING;      word++;      /* FALLTHROUGH */    default:      return get_job_by_name (word, jflags);    }}#endif /* JOB_CONTROL *//* * NOTE:  `kill' calls this function with forcecols == 0 */intdisplay_signal_list (list, forcecols)     WORD_LIST *list;     int forcecols;{  register int i, column;  char *name;  int result, signum, dflags;  intmax_t lsignum;  result = EXECUTION_SUCCESS;  if (!list)    {      for (i = 1, column = 0; i < NSIG; i++)	{	  name = signal_name (i);	  if (STREQN (name, "SIGJUNK", 7) || STREQN (name, "Unknown", 7))	    continue;	  if (posixly_correct && !forcecols)	    {	      /* This is for the kill builtin.  POSIX.2 says the signal names		 are displayed without the `SIG' prefix. */	      if (STREQN (name, "SIG", 3))		name += 3;	      printf ("%s%s", name, (i == NSIG - 1) ? "" : " ");	    }	  else	    {	      printf ("%2d) %s", i, name);	      if (++column < 5)		printf ("\t");	      else		{		  printf ("\n");		  column = 0;		}	    }	}      if ((posixly_correct && !forcecols) || column != 0)	printf ("\n");      return result;    }  /* List individual signal names or numbers. */  while (list)    {      if (legal_number (list->word->word, &lsignum))	{	  /* This is specified by Posix.2 so that exit statuses can be	     mapped into signal numbers. */	  if (lsignum > 128)	    lsignum -= 128;	  if (lsignum < 0 || lsignum >= NSIG)	    {	      sh_invalidsig (list->word->word);	      result = EXECUTION_FAILURE;	      list = list->next;	      continue;	    }	  signum = lsignum;	  name = signal_name (signum);	  if (STREQN (name, "SIGJUNK", 7) || STREQN (name, "Unknown", 7))	    {	      list = list->next;	      continue;	    }#if defined (JOB_CONTROL)	  /* POSIX.2 says that `kill -l signum' prints the signal name without	     the `SIG' prefix. */	  printf ("%s\n", (this_shell_builtin == kill_builtin) ? name + 3 : name);#else	  printf ("%s\n", name);#endif	}      else	{	  dflags = DSIG_NOCASE;	  if (posixly_correct == 0 || this_shell_builtin != kill_builtin)	    dflags |= DSIG_SIGPREFIX;	  signum = decode_signal (list->word->word, dflags);	  if (signum == NO_SIG)	    {	      sh_invalidsig (list->word->word);	      result = EXECUTION_FAILURE;	      list = list->next;	      continue;	    }	  printf ("%d\n", signum);	}      list = list->next;    }  return (result);}/* **************************************************************** *//*								    *//*	    Finding builtin commands and their functions	    *//*								    *//* **************************************************************** *//* Perform a binary search and return the address of the builtin function   whose name is NAME.  If the function couldn't be found, or the builtin   is disabled or has no function associated with it, return NULL.   Return the address of the builtin.   DISABLED_OKAY means find it even if the builtin is disabled. */struct builtin *builtin_address_internal (name, disabled_okay)     char *name;     int disabled_okay;{  int hi, lo, mid, j;  hi = num_shell_builtins - 1;  lo = 0;  while (lo <= hi)    {      mid = (lo + hi) / 2;      j = shell_builtins[mid].name[0] - name[0];      if (j == 0)	j = strcmp (shell_builtins[mid].name, name);      if (j == 0)	{	  /* It must have a function pointer.  It must be enabled, or we	     must have explicitly allowed disabled functions to be found,	     and it must not have been deleted. */	  if (shell_builtins[mid].function &&	      ((shell_builtins[mid].flags & BUILTIN_DELETED) == 0) &&	      ((shell_builtins[mid].flags & BUILTIN_ENABLED) || disabled_okay))	    return (&shell_builtins[mid]);	  else	    return ((struct builtin *)NULL);	}      if (j > 0)	hi = mid - 1;      else	lo = mid + 1;    }  return ((struct builtin *)NULL);}/* Return the pointer to the function implementing builtin command NAME. */sh_builtin_func_t *find_shell_builtin (name)     char *name;{  current_builtin = builtin_address_internal (name, 0);  return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL);}/* Return the address of builtin with NAME, whether it is enabled or not. */sh_builtin_func_t *builtin_address (name)     char *name;{  current_builtin = builtin_address_internal (name, 1);  return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL);}/* Return the function implementing the builtin NAME, but only if it is a   POSIX.2 special builtin. */sh_builtin_func_t *find_special_builtin (name)     char *name;{  current_builtin = builtin_address_internal (name, 0);  return ((current_builtin && (current_builtin->flags & SPECIAL_BUILTIN)) ?  			current_builtin->function :  			(sh_builtin_func_t *)NULL);}  static intshell_builtin_compare (sbp1, sbp2)     struct builtin *sbp1, *sbp2;{  int result;  if ((result = sbp1->name[0] - sbp2->name[0]) == 0)    result = strcmp (sbp1->name, sbp2->name);  return (result);}/* Sort the table of shell builtins so that the binary search will work   in find_shell_builtin. */voidinitialize_shell_builtins (){  qsort (shell_builtins, num_shell_builtins, sizeof (struct builtin),    (QSFUNC *)shell_builtin_compare);}

⌨️ 快捷键说明

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