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

📄 util.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	      (*root)->balance = 0;	    }	}     	}     }  else    {      /* Insert it on the right. */      if (insert_id_rec (&((*root)->right), new_id))	{	  /* The height increased. */	  (*root)->balance ++;	  switch ((*root)->balance)	    {	    case 0:  /* no height increase. */	      return (FALSE);	    case 1:  /* height increase. */	      return (FALSE);	    case 2:  /* we need to do a rebalancing act. */	      A = *root;	      B = (*root)->right;	      if (B->balance >= 0)		{		  /* Single Rotate. */		  A->right = B->left;		  B->left = A;		  *root = B;		  A->balance = 0;		  B->balance = 0;		}	      else		{		  /* Double Rotate. */		  *root = B->left;		  B->left = (*root)->right;		  A->right = (*root)->left;		  (*root)->left = A;		  (*root)->right = B;		  switch ((*root)->balance)		    {		    case -1:		      A->balance = 0;		      B->balance = 1;		      break;		    case  0:		      A->balance = 0;		      B->balance = 0;		      break;		    case  1:		      A->balance = -1;		      B->balance = 0;		      break;		    }		  (*root)->balance = 0;		}	    }     	}     }    /* If we fall through to here, the tree did not grow in height. */  return (FALSE);}/* Initialize variables for the symbol table tree. */voidinit_tree(){  name_tree  = NULL;  next_array = 1;  next_func  = 1;  next_var   = 4;  /* 0 => ibase, 1 => obase, 2 => scale, 3 => last. */}/* Lookup routines for symbol table names. */intlookup (name, namekind)     char *name;     int  namekind;{  id_rec *id;  /* Warn about non-standard name. */  if (strlen(name) != 1)    warn ("multiple letter name - %s", name);  /* Look for the id. */  id = find_id (name_tree, name);  if (id == NULL)    {      /* We need to make a new item. */      id = (id_rec *) bc_malloc (sizeof (id_rec));      id->id = strcopyof (name);      id->a_name = 0;      id->f_name = 0;      id->v_name = 0;      insert_id_rec (&name_tree, id);    }  /* Return the correct value. */  switch (namekind)    {          case ARRAY:      /* ARRAY variable numbers are returned as negative numbers. */      if (id->a_name != 0)	{	  free (name);	  return (-id->a_name);	}      id->a_name = next_array++;      a_names[id->a_name] = name;      if (id->a_name < MAX_STORE)	{	  if (id->a_name >= a_count)	    more_arrays ();	  return (-id->a_name);	}      yyerror ("Too many array variables");      exit (1);    case FUNCT:      if (id->f_name != 0)	{	  free(name);	  return (id->f_name);	}      id->f_name = next_func++;      f_names[id->f_name] = name;      if (id->f_name < MAX_STORE)	{	  if (id->f_name >= f_count)	    more_functions ();	  return (id->f_name);	}      yyerror ("Too many functions");      exit (1);    case SIMPLE:      if (id->v_name != 0)	{	  free(name);	  return (id->v_name);	}      id->v_name = next_var++;      v_names[id->v_name - 1] = name;      if (id->v_name <= MAX_STORE)	{	  if (id->v_name >= v_count)	    more_variables ();	  return (id->v_name);	}      yyerror ("Too many variables");      exit (1);    }}/* Print the welcome banner. */void welcome(){#if !__minix  printf ("This is free software with ABSOLUTELY NO WARRANTY.\n");  printf ("For details type `warranty'. \n");#endif}/* Print out the warranty information. */void warranty(prefix)     char *prefix;{  printf ("\n%s%s\n\n", prefix, BC_VERSION);  printf ("%s%s%s%s%s%s%s%s%s%s%s","    This program is free software; you can redistribute it and/or modify\n","    it under the terms of the GNU General Public License as published by\n","    the Free Software Foundation; either version 2 of the License , or\n","    (at your option) any later version.\n\n","    This program is distributed in the hope that it will be useful,\n","    but WITHOUT ANY WARRANTY; without even the implied warranty of\n","    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n","    GNU General Public License for more details.\n\n","    You should have received a copy of the GNU General Public License\n","    along with this program. If not, write to the Free Software\n","    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");}/* Print out the limits of this program. */voidlimits(){  printf ("BC_BASE_MAX     = %d\n",  BC_BASE_MAX);  printf ("BC_DIM_MAX      = %ld\n", (long) BC_DIM_MAX);  printf ("BC_SCALE_MAX    = %d\n",  BC_SCALE_MAX);  printf ("BC_STRING_MAX   = %d\n",  BC_STRING_MAX);  printf ("MAX Exponent    = %ld\n", (long) LONG_MAX);  printf ("MAX code        = %ld\n", (long) BC_MAX_SEGS * (long) BC_SEG_SIZE);  printf ("multiply digits = %ld\n", (long) LONG_MAX / (long) 90);  printf ("Number of vars  = %ld\n", (long) MAX_STORE);#ifdef OLD_EQ_OP  printf ("Old assignment operatiors are valid. (=-, =+, ...)\n");#endif }/* bc_malloc will check the return value so all other places do not   have to do it!  SIZE is the number of types to allocate. */char *bc_malloc (size)     int size;{  char *ptr;  ptr = (char *) malloc (size);  if (ptr == NULL)    out_of_memory ();  return ptr;}/* The following routines are error routines for various problems. *//* Malloc could not get enought memory. */voidout_of_memory(){  fprintf (stderr, "Fatal error: Out of memory for malloc.\n");  exit (1);}/* The standard yyerror routine.  Built with variable number of argumnets. */#ifndef VARARGS#ifdef __STDC__voidyyerror (char *str, ...)#elsevoidyyerror (str)     char *str;#endif#elsevoidyyerror (str, va_alist)     char *str;#endif{  char *name;  va_list args;#ifndef VARARGS      va_start (args, str);#else   va_start (args);#endif  if (is_std_in)    name = "(standard_in)";  else    name = g_argv[optind-1];  fprintf (stderr,"%s %d: ",name,line_no);  vfprintf (stderr, str, args);  fprintf (stderr, "\n");  had_error = TRUE;  va_end (args);}/* The routine to produce warnings about non-standard features   found during parsing. */#ifndef VARARGS#ifdef __STDC__void warn (char *mesg, ...)#elsevoidwarn (mesg)     char *mesg;#endif#elsevoidwarn (mesg, va_alist)     char *mesg;#endif{  char *name;  va_list args;#ifndef VARARGS     va_start (args, mesg);#else  va_start (args);#endif  if (std_only)    {      if (is_std_in)	name = "(standard_in)";      else	name = g_argv[optind-1];      fprintf (stderr,"%s %d: ",name,line_no);      vfprintf (stderr, mesg, args);      fprintf (stderr, "\n");      had_error = TRUE;    }  else    if (warn_not_std)      {	if (is_std_in)	  name = "(standard_in)";	else	  name = g_argv[optind-1];	fprintf (stderr,"%s %d: (Warning) ",name,line_no);	vfprintf (stderr, mesg, args);	fprintf (stderr, "\n");      }  va_end (args);}/* Runtime error will  print a message and stop the machine. */#ifndef VARARGS#ifdef __STDC__voidrt_error (char *mesg, ...)#elsevoidrt_error (mesg)     char *mesg;#endif#elsevoidrt_error (mesg, va_alist)     char *mesg;#endif{  va_list args;  char error_mesg [255];#ifndef VARARGS     va_start (args, mesg);#else  va_start (args);#endif  vsprintf (error_mesg, mesg, args);  va_end (args);    fprintf (stderr, "Runtime error (func=%s, adr=%d): %s\n",	   f_names[pc.pc_func], pc.pc_addr, error_mesg);  runtime_error = TRUE;}/* A runtime warning tells of some action taken by the processor that   may change the program execution but was not enough of a problem   to stop the execution. */#ifndef VARARGS#ifdef __STDC__voidrt_warn (char *mesg, ...)#elsevoidrt_warn (mesg)     char *mesg;#endif#elsevoidrt_warn (mesg, va_alist)     char *mesg;#endif{  va_list args;  char error_mesg [255];#ifndef VARARGS     va_start (args, mesg);#else  va_start (args);#endif  vsprintf (error_mesg, mesg, args);  va_end (args);  fprintf (stderr, "Runtime warning (func=%s, adr=%d): %s\n",	   f_names[pc.pc_func], pc.pc_addr, error_mesg);}

⌨️ 快捷键说明

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