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

📄 chew.c

📁 gdb-6.0 linux 下的调试工具
💻 C
📖 第 1 页 / 共 2 页
字号:
  if (on)    {      cattext (&out, "@end itemize\n");    }  delete_string (tos);  *tos = out;  pc++;}/* Turn <<foo>> into @code{foo} in place at TOS*/static voiddo_fancy_stuff (){  unsigned int idx = 0;  string_type out;  init_string (&out);  while (at (tos, idx))    {      if (at (tos, idx) == '<'	  && at (tos, idx + 1) == '<'	  && !isspace ((unsigned char) at (tos, idx + 2)))	{	  /* This qualifies as a << startup.  */	  idx += 2;	  cattext (&out, "@code{");	  while (at (tos, idx)		 && at (tos, idx) != '>' )	    {	      catchar (&out, at (tos, idx));	      idx++;	    }	  cattext (&out, "}");	  idx += 2;	}      else	{	  catchar (&out, at (tos, idx));	  idx++;	}    }  delete_string (tos);  *tos = out;  pc++;}/* A command is all upper case,and alone on a line.  */static intiscommand (ptr, idx)     string_type *ptr;     unsigned int idx;{  unsigned int len = 0;  while (at (ptr, idx))    {      if (isupper ((unsigned char) at (ptr, idx))	  || at (ptr, idx) == ' ' || at (ptr, idx) == '_')	{	  len++;	  idx++;	}      else if (at (ptr, idx) == '\n')	{	  if (len > 3)	    return 1;	  return 0;	}      else	return 0;    }  return 0;}static intcopy_past_newline (ptr, idx, dst)     string_type *ptr;     unsigned int idx;     string_type *dst;{  int column = 0;  while (at (ptr, idx) && at (ptr, idx) != '\n')    {      if (at (ptr, idx) == '\t')	{	  /* Expand tabs.  Neither makeinfo nor TeX can cope well with	     them.  */	  do	    catchar (dst, ' ');	  while (++column & 7);	}      else	{	  catchar (dst, at (ptr, idx));	  column++;	}      idx++;    }  catchar (dst, at (ptr, idx));  idx++;  return idx;}static voidicopy_past_newline (){  tos++;  check_range ();  init_string (tos);  idx = copy_past_newline (ptr, idx, tos);  pc++;}/* indent   Take the string at the top of the stack, do some prettying.  */static voidkill_bogus_lines (){  int sl;  int idx = 0;  int c;  int dot = 0;  string_type out;  init_string (&out);  /* Drop leading nl.  */  while (at (tos, idx) == '\n')    {      idx++;    }  c = idx;  /* If the first char is a '.' prepend a newline so that it is     recognized properly later.  */  if (at (tos, idx) == '.')    catchar (&out, '\n');  /* Find the last char.  */  while (at (tos, idx))    {      idx++;    }  /* Find the last non white before the nl.  */  idx--;  while (idx && isspace ((unsigned char) at (tos, idx)))    idx--;  idx++;  /* Copy buffer upto last char, but blank lines before and after     dots don't count.  */  sl = 1;  while (c < idx)    {      if (at (tos, c) == '\n'	  && at (tos, c + 1) == '\n'	  && at (tos, c + 2) == '.')	{	  /* Ignore two newlines before a dot.  */	  c++;	}      else if (at (tos, c) == '.' && sl)	{	  /* remember that this line started with a dot.  */	  dot = 2;	}      else if (at (tos, c) == '\n'	       && at (tos, c + 1) == '\n'	       && dot)	{	  c++;	  /* Ignore two newlines when last line was dot.  */	}      catchar (&out, at (tos, c));      if (at (tos, c) == '\n')	{	  sl = 1;	  if (dot == 2)	    dot = 1;	  else	    dot = 0;	}      else	sl = 0;      c++;    }  /* Append nl.  */  catchar (&out, '\n');  pc++;  delete_string (tos);  *tos = out;}static voidindent (){  string_type out;  int tab = 0;  int idx = 0;  int ol = 0;  init_string (&out);  while (at (tos, idx))    {      switch (at (tos, idx))	{	case '\n':	  cattext (&out, "\n");	  idx++;	  if (tab && at (tos, idx))	    {	      cattext (&out, "    ");	    }	  ol = 0;	  break;	case '(':	  tab++;	  if (ol == 0)	    cattext (&out, "   ");	  idx++;	  cattext (&out, "(");	  ol = 1;	  break;	case ')':	  tab--;	  cattext (&out, ")");	  idx++;	  ol = 1;	  break;	default:	  catchar (&out, at (tos, idx));	  ol = 1;	  idx++;	  break;	}    }  pc++;  delete_string (tos);  *tos = out;}static voidget_stuff_in_command (){  tos++;  check_range ();  init_string (tos);  while (at (ptr, idx))    {      if (iscommand (ptr, idx))	break;      idx = copy_past_newline (ptr, idx, tos);    }  pc++;}static voidswap (){  string_type t;  t = tos[0];  tos[0] = tos[-1];  tos[-1] = t;  pc++;}static voidother_dup (){  tos++;  check_range ();  init_string (tos);  catstr (tos, tos - 1);  pc++;}static voiddrop (){  tos--;  check_range ();  pc++;}static voididrop (){  isp--;  icheck_range ();  pc++;}static voidicatstr (){  tos--;  check_range ();  catstr (tos, tos + 1);  delete_string (tos + 1);  pc++;}static voidskip_past_newline (){  while (at (ptr, idx)	 && at (ptr, idx) != '\n')    idx++;  idx++;  pc++;}static voidinternalmode (){  internal_mode = *(isp);  isp--;  icheck_range ();  pc++;}static voidmaybecatstr (){  if (internal_wanted == internal_mode)    {      catstr (tos - 1, tos);    }  delete_string (tos);  tos--;  check_range ();  pc++;}char *nextword (string, word)     char *string;     char **word;{  char *word_start;  int idx;  char *dst;  char *src;  int length = 0;  while (isspace ((unsigned char) *string) || *string == '-')    {      if (*string == '-')	{	  while (*string && *string != '\n')	    string++;	}      else	{	  string++;	}    }  if (!*string)    return 0;  word_start = string;  if (*string == '"')    {      do	{	  string++;	  length++;	  if (*string == '\\')	    {	      string += 2;	      length += 2;	    }	}      while (*string != '"');    }  else    {      while (!isspace ((unsigned char) *string))	{	  string++;	  length++;	}    }  *word = malloc (length + 1);  dst = *word;  src = word_start;  for (idx = 0; idx < length; idx++)    {      if (src[idx] == '\\')	switch (src[idx + 1])	  {	  case 'n':	    *dst++ = '\n';	    idx++;	    break;	  case '"':	  case '\\':	    *dst++ = src[idx + 1];	    idx++;	    break;	  default:	    *dst++ = '\\';	    break;	  }      else	*dst++ = src[idx];    }  *dst++ = 0;  if (*string)    return string + 1;  else    return 0;}dict_type *root;dict_type *lookup_word (word)     char *word;{  dict_type *ptr = root;  while (ptr)    {      if (strcmp (ptr->word, word) == 0)	return ptr;      ptr = ptr->next;    }  if (warning)    fprintf (stderr, "Can't find %s\n", word);  return 0;}static voidperform (){  tos = stack;  while (at (ptr, idx))    {      /* It's worth looking through the command list.  */      if (iscommand (ptr, idx))	{	  char *next;	  dict_type *word;	  (void) nextword (addr (ptr, idx), &next);	  word = lookup_word (next);	  if (word)	    {	      exec (word);	    }	  else	    {	      if (warning)		fprintf (stderr, "warning, %s is not recognised\n", next);	      skip_past_newline ();	    }	}      else	skip_past_newline ();    }}dict_type *newentry (word)     char *word;{  dict_type *new = (dict_type *) malloc (sizeof (dict_type));  new->word = word;  new->next = root;  root = new;  new->code = (stinst_type *) malloc (sizeof (stinst_type));  new->code_length = 1;  new->code_end = 0;  return new;}unsigned intadd_to_definition (entry, word)     dict_type *entry;     stinst_type word;{  if (entry->code_end == entry->code_length)    {      entry->code_length += 2;      entry->code =	(stinst_type *) realloc ((char *) (entry->code),				 entry->code_length * sizeof (word_type));    }  entry->code[entry->code_end] = word;  return entry->code_end++;}voidadd_intrinsic (name, func)     char *name;     void (*func) ();{  dict_type *new = newentry (name);  add_to_definition (new, func);  add_to_definition (new, 0);}voidadd_var (name)     char *name;{  dict_type *new = newentry (name);  add_to_definition (new, push_number);  add_to_definition (new, (stinst_type) (&(new->var)));  add_to_definition (new, 0);}voidcompile (string)     char *string;{  /* Add words to the dictionary.  */  char *word;  string = nextword (string, &word);  while (string && *string && word[0])    {      if (strcmp (word, "var") == 0)	{	  string = nextword (string, &word);	  add_var (word);	  string = nextword (string, &word);	}      else if (word[0] == ':')	{	  dict_type *ptr;	  /* Compile a word and add to dictionary.  */	  string = nextword (string, &word);	  ptr = newentry (word);	  string = nextword (string, &word);	  while (word[0] != ';')	    {	      switch (word[0])		{		case '"':		  /* got a string, embed magic push string		     function */		  add_to_definition (ptr, push_text);		  add_to_definition (ptr, (stinst_type) (word + 1));		  break;		case '0':		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':		  /* Got a number, embedd the magic push number		     function */		  add_to_definition (ptr, push_number);		  add_to_definition (ptr, (stinst_type) atol (word));		  break;		default:		  add_to_definition (ptr, call);		  add_to_definition (ptr, (stinst_type) lookup_word (word));		}	      string = nextword (string, &word);	    }	  add_to_definition (ptr, 0);	  string = nextword (string, &word);	}      else	{	  fprintf (stderr, "syntax error at %s\n", string - 1);	}    }}static voidbang (){  *(long *) ((isp[0])) = isp[-1];  isp -= 2;  icheck_range ();  pc++;}static voidatsign (){  isp[0] = *(long *) (isp[0]);  pc++;}static voidhello (){  printf ("hello\n");  pc++;}static voidstdout_ (){  isp++;  icheck_range ();  *isp = 1;  pc++;}static voidstderr_ (){  isp++;  icheck_range ();  *isp = 2;  pc++;}static voidprint (){  if (*isp == 1)    write_buffer (tos, stdout);  else if (*isp == 2)    write_buffer (tos, stderr);  else    fprintf (stderr, "print: illegal print destination `%ld'\n", *isp);  isp--;  tos--;  icheck_range ();  check_range ();  pc++;}static voidread_in (str, file)     string_type *str;     FILE *file;{  char buff[10000];  unsigned int r;  do    {      r = fread (buff, 1, sizeof (buff), file);      catbuf (str, buff, r);    }  while (r);  buff[0] = 0;  catbuf (str, buff, 1);}static voidusage (){  fprintf (stderr, "usage: -[d|i|g] <file >file\n");  exit (33);}/* There is no reliable way to declare exit.  Sometimes it returns   int, and sometimes it returns void.  Sometimes it changes between   OS releases.  Trying to get it declared correctly in the hosts file   is a pointless waste of time.  */static voidchew_exit (){  exit (0);}intmain (ac, av)     int ac;     char *av[];{  unsigned int i;  string_type buffer;  string_type pptr;  init_string (&buffer);  init_string (&pptr);  init_string (stack + 0);  tos = stack + 1;  ptr = &pptr;  add_intrinsic ("push_text", push_text);  add_intrinsic ("!", bang);  add_intrinsic ("@", atsign);  add_intrinsic ("hello", hello);  add_intrinsic ("stdout", stdout_);  add_intrinsic ("stderr", stderr_);  add_intrinsic ("print", print);  add_intrinsic ("skip_past_newline", skip_past_newline);  add_intrinsic ("catstr", icatstr);  add_intrinsic ("copy_past_newline", icopy_past_newline);  add_intrinsic ("dup", other_dup);  add_intrinsic ("drop", drop);  add_intrinsic ("idrop", idrop);  add_intrinsic ("remchar", remchar);  add_intrinsic ("get_stuff_in_command", get_stuff_in_command);  add_intrinsic ("do_fancy_stuff", do_fancy_stuff);  add_intrinsic ("bulletize", bulletize);  add_intrinsic ("courierize", courierize);  /* If the following line gives an error, exit() is not declared in the     ../hosts/foo.h file for this host.  Fix it there, not here!  */  /* No, don't fix it anywhere; see comment on chew_exit--Ian Taylor.  */  add_intrinsic ("exit", chew_exit);  add_intrinsic ("swap", swap);  add_intrinsic ("outputdots", outputdots);  add_intrinsic ("paramstuff", paramstuff);  add_intrinsic ("maybecatstr", maybecatstr);  add_intrinsic ("translatecomments", translatecomments);  add_intrinsic ("kill_bogus_lines", kill_bogus_lines);  add_intrinsic ("indent", indent);  add_intrinsic ("internalmode", internalmode);  add_intrinsic ("print_stack_level", print_stack_level);  add_intrinsic ("strip_trailing_newlines", strip_trailing_newlines);  /* Put a nl at the start.  */  catchar (&buffer, '\n');  read_in (&buffer, stdin);  remove_noncomments (&buffer, ptr);  for (i = 1; i < (unsigned int) ac; i++)    {      if (av[i][0] == '-')	{	  if (av[i][1] == 'f')	    {	      string_type b;	      FILE *f;	      init_string (&b);	      f = fopen (av[i + 1], "r");	      if (!f)		{		  fprintf (stderr, "Can't open the input file %s\n",			   av[i + 1]);		  return 33;		}	      read_in (&b, f);	      compile (b.ptr);	      perform ();	    }	  else if (av[i][1] == 'i')	    {	      internal_wanted = 1;	    }	  else if (av[i][1] == 'w')	    {	      warning = 1;	    }	  else	    usage ();	}    }  write_buffer (stack + 0, stdout);  if (tos != stack)    {      fprintf (stderr, "finishing with current stack level %d\n",	       tos - stack);      return 1;    }  return 0;}

⌨️ 快捷键说明

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