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

📄 makeinfo.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
  return ((int) false);}/* Just like error (), but print the line number as well. */line_error (format, arg1, arg2, arg3, arg4, arg5)     char *format;{  remember_error ();  fprintf (stderr, "%s:%d: ", input_filename, line_number);  fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);  fprintf (stderr, ".\n");  return ((int) false);}warning (format, arg1, arg2, arg3, arg4, arg5)     char *format;{  if (print_warnings)    {      fprintf (stderr, "%s:%d: Warning: ", input_filename, line_number);      fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);      fprintf (stderr, ".\n");    }  return ((int) false);}/* Remember that an error has been printed.  If this is the first   error printed, then tell them which program is printing them.   If more than max_error_level have been printed, then exit the   program. */remember_error (){  errors_printed++;  if (max_error_level && (errors_printed > max_error_level))    {      fprintf (stderr, "Too many errors!  Gave up.");      flush_file_stack ();      cm_bye ();    }}/* **************************************************************** *//*								    *//*			Hacking Tokens and Strings		    *//*								    *//* **************************************************************** *//* Return the next token as a string pointer.  We cons the   string. */char *read_token (){  int i, character;  char *result;  /* Hack special case.  If the first character to be read is     self-delimiting, then that is the command itself. */  character = curchar ();  if (self_delimiting (character))    {      input_text_offset++;      result = savestring (" ");      *result = character;      return (result);    }  for (i = 0; ((input_text_offset != size_of_input_text)	       && (character = curchar ())	       && command_char (character));       i++, input_text_offset++);  result = xmalloc (i + 1);  strncpy (result, &input_text[input_text_offset - i], i);  result[i] = '\0';  return (result);}/* Return TRUE if CHARACTER is self-delimiting. */booleanself_delimiting (character)     int character;{  return (member (character, "{}:.@*'`,!?; \n"));}/* Clear whitespace from the front and end of string. */canon_white (string)     char *string;{  int len = strlen (string);  int x;  if (!len)    return;  for (x = 0; x < len; x++)    {      if (!whitespace (string[x]))	{	  strcpy (string, string + x);	  break;	}    }  len = strlen (string);  if (len)    len--;  while (len > -1 && cr_or_whitespace (string[len]))    len--;  string[len + 1] = '\0';}/* Bash STRING, replacing all whitespace with just one space. */fix_whitespace (string)     char *string;{  char *temp = xmalloc (strlen (string) + 1);  int string_index = 0;  int temp_index = 0;  int c;  canon_white (string);  while (string[string_index])    {      c = temp[temp_index++] = string[string_index++];      if (c == ' ' || c == '\n' || c == '\t')	{	  temp[temp_index - 1] = ' ';	  while ((c = string[string_index]) && (c == ' ' ||						c == '\t' ||						c == '\n'))	    string_index++;	}    }  temp[temp_index] = '\0';  strcpy (string, temp);  free (temp);}/* Discard text until the desired string is found.  The string is   included in the discarded text. */discard_until (string)     char *string;{  int temp = search_forward (string, input_text_offset);  int tt = (temp < 0) ? size_of_input_text : temp + strlen (string);  int from = input_text_offset;  /* Find out what line we are on. */  while (from != tt)    if (input_text[from++] == '\n')      line_number++;  if (temp < 0)    {      input_text_offset = size_of_input_text - strlen (string);      if (strcmp (string, "\n") != 0)	{	  line_error ("Expected `%s'", string);	  return;	}    }  else    input_text_offset = temp;  input_text_offset += strlen (string);}/* Read characters from the file until we are at MATCH.   Place the characters read into STRING.   On exit input_text_offset is after the match string.   Return the length of STRING. */get_until (match, string)     char *match, **string;{  int len;  int current_point = input_text_offset;  int x = current_point;  int new_point = search_forward (match, input_text_offset);  if (new_point < 0)    new_point = size_of_input_text;  len = new_point - current_point;  /* Keep track of which line number we are at. */  while (x != new_point)    if (input_text[x++] == '\n')      line_number++;  *string = xmalloc (len + 1);  strncpy (*string, &input_text[current_point], len);  (*string)[len] = '\0';  /* Now leave input_text_offset in a consistent state. */  input_text_offset = new_point + (strlen (match) - 1);  if (input_text_offset > size_of_input_text)    input_text_offset = size_of_input_text;}/* Read characters from the file until we are at MATCH or end of line.   Place the characters read into STRING.  */get_until_in_line (match, string)     char *match, **string;{  int real_bottom = size_of_input_text;  int temp = search_forward ("\n", input_text_offset);  if (temp < 0)    temp = size_of_input_text;  size_of_input_text = temp;  get_until (match, string);  size_of_input_text = real_bottom;}get_rest_of_line (string)     char **string;{  get_until ("\n", string);  canon_white (*string);  if (curchar () == '\n')    {				/* as opposed to the end of the file... */      line_number++;      input_text_offset++;    }}/* Read characters from the file until we are at MATCH or closing brace.   Place the characters read into STRING.  */get_until_in_braces (match, string)     char *match, **string;{  int i, brace = 0;  int match_len = strlen (match);  char *temp;  for (i = input_text_offset; i < size_of_input_text; i++)    {      if (input_text[i] == '{')	brace++;      if (input_text[i] == '}')	brace--;      if (input_text[i] == '\n')	line_number++;      if (brace < 0 ||	  (brace == 0 && strncmp (input_text + i, match, match_len) == 0))	break;    }  match_len = i - input_text_offset;  temp = xmalloc (2 + match_len);  strncpy (temp, input_text + input_text_offset, match_len);  temp[match_len] = '\0';  input_text_offset = i;  *string = temp;}/* **************************************************************** *//*								    *//*			Converting the File     		    *//*								    *//* **************************************************************** *//* Convert the file named by NAME.  The output is saved on the file   named as the argument to the @setfilename command. */convert (name)     char *name;{  char *real_output_filename, *expand_filename (), *filename_part ();  init_tag_table ();  init_indices ();  init_internals ();  init_paragraph ();  if (!find_and_load (name))    {      /* For some reason, the file couldn't be loaded.  Print a message	 to that affect, and split. */      fs_error (name);      return;    }  else    input_filename = savestring (name);  /* Search this file looking for the special string which starts conversion.     Once found, we may truly begin. */  input_text_offset = search_forward ("@setfilename", 0);  if (input_text_offset < 0)    {      error ("No `@setfilename' found in `%s'", name);      goto finished;    }  else    input_text_offset += strlen ("@setfilename");  get_until ("\n", &output_filename);	/* no braces expected. */  canon_white (output_filename);  printf ("Making info file `%s' from `%s'.\n", output_filename, name);  real_output_filename = expand_filename (output_filename, name);  output_stream = fopen (real_output_filename, "w");  if (output_stream == NULL)    {      fs_error (real_output_filename);      goto finished;    }  /* Make the displayable filename from output_filename.  Only the root     portion of the filename need be displayed. */  pretty_output_filename = filename_part (output_filename);  /* For this file only, count the number of newlines from the top of     the file to here.  This way, we keep track of line numbers for     error reporting.  Line_number starts at 1, since the user isn't     zero-based. */  {    int temp = 0;    line_number = 1;    while (temp != input_text_offset)      if (input_text[temp++] == '\n')	line_number++;  }  add_word_args ("Info file %s, produced by Makeinfo, -*- Text -*-\n\from input file %s.\n", output_filename, input_filename);  close_paragraph ();  reader_loop ();finished:  close_paragraph ();  flush_file_stack ();  if (output_stream != NULL)    {      output_pending_notes ();      free_pending_notes ();      if (tag_table != NULL)	{	  tag_table = (TAG_ENTRY *) reverse_list (tag_table);	  write_tag_table ();	}      fclose (output_stream);      /* If validating, then validate the entire file right now. */      if (validating)	validate_file (real_output_filename, tag_table);      /* This used to test  && !errors_printed.	 But some files might have legit warnings.  So split anyway.  */      if (splitting)	split_file (real_output_filename, 0);    }}free_and_clear (pointer)     char **pointer;{  if ((*pointer) != (char *) NULL)    {      free (*pointer);      *pointer = (char *) NULL;    }} /* Initialize some state. */init_internals (){  free_and_clear (&current_node);  free_and_clear (&output_filename);  free_and_clear (&command);  free_and_clear (&input_filename);  free_node_references ();  init_insertion_stack ();  init_brace_stack ();  command_index = 0;  in_menu = 0;}init_paragraph (){  free_and_clear (&output_paragraph);  output_paragraph = xmalloc (paragraph_buffer_len);  output_position = 0;  output_paragraph[0] = '\0';  output_paragraph_offset = 0;  output_column = 0;  paragraph_is_open = false;  current_indent = 0;}/* Okay, we are ready to start the conversion.  Call the reader on   some text, and fill the text as it is output.  Handle commands by   remembering things like open braces and the current file position on a   stack, and when the corresponding close brace is found, you can call   the function with the proper arguments. */reader_loop (){  int character;  boolean done = false;  int dash_count = 0;  while (!done)    {      if (input_text_offset >= size_of_input_text)	{	  if (filestack)	    {	      free (input_filename);	      free (input_text);	      popfile ();	    }	  else	    break;	}      character = curchar ();      if (!in_fixed_width_font &&	  (character == '\'' || character == '`') &&	  input_text[input_text_offset + 1] == character)	{	  input_text_offset++;	  character = '"';	}      if (character == '-')	{	  dash_count++;	  if (dash_count == 3 && !in_fixed_width_font)	    {	      input_text_offset++;	      continue;	    }	}      else	{	  dash_count = 0;	}      if (character == '\n')	{	  line_number++;	  if (in_menu && input_text_offset + 1 < size_of_input_text)	    {	      glean_node_from_menu ();	    }	  /* If the following line is all whitespace, advance to the carriage	     return on it. */	  {	    register int i = input_text_offset + 1;	    	    while (i < size_of_input_text && whitespace (input_text[i]))	      i++;	    	        if (i == size_of_input_text || input_text[i] == '\n')		  input_text_offset = i - 1;	  }	}            switch (character)	{	case COMMAND_PREFIX:	  read_command ();	  if (strcmp (command, "bye") == 0)	    {	      done = true;	      continue;	    }	  break;	case '{':	  /* Special case.  I'm not supposed to see this character by itself.	     If I do, it means there is a syntax error in the input text.	     Report the error here, but remember this brace on the stack so	     you can ignore its partner. */	  line_error ("Misplaced `{'");	  remember_brace (misplaced_brace);	  /* Don't advance input_text_offset since this happens in	     remember_brace ().	     input_text_offset++;           */	  break;	case '}':	  pop_and_call_brace ();	  input_text_offset++;	  break;	default:	  add_char (character);	  input_text_offset++;	}    }}/* Find the command corresponding to STRING.  If the command   is found, return a pointer to the data structure.  Otherwise   return (-1). */COMMAND *get_command_entry (string)     char *string;{  register int i;  for (i = 0; CommandTable[i].name; i++)    if (strcmp (CommandTable[i].name, string) == 0)      return (&CommandTable[i]);  /* This command is not in our predefined command table.  Perhaps     it is a user defined command. */  for (i = 0; i < user_command_array_len; i++)    if (user_command_array[i] &&	(strcmp (user_command_array[i]->name, string) == 0))      return (user_command_array[i]);  /* Nope, we never heard of this command. */  return ((COMMAND *) - 1);

⌨️ 快捷键说明

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