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

📄 makeinfo.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
  {"w", cm_w, true},  {"xref", cm_xref, true},  {"{", insert_self, false},  {"}", insert_self, false},  /* Now @include does what this was supposed to. */  {"infoinclude", cm_infoinclude, false},  {"footnote", cm_footnote, false}, /* self-arg eater */  {(char *) NULL, (FUNCTION *) NULL}, false};/* Non-zero means we are running inside of Emacs. */int in_emacs = 0;#ifndef MAKEINFO_MAJOR#define MAKEINFO_MAJOR 1#endif#ifndef MAKEINFO_MINOR#define MAKEINFO_MINOR 0#endifint major_version = MAKEINFO_MAJOR;int minor_version = MAKEINFO_MINOR;struct option long_options[] ={  { "no-validate", 0, &validating, false },	/* formerly -nv */  { "no-warn", 0, &print_warnings, false },	/* formerly -nw */  { "no-split", 0, &splitting, false },		/* formerly -ns */  { "verbose", 0, &verbose_mode, 1 },		/* formerly -verbose */  { "fill-column", 1, 0, 'f' },			/* formerly -fc */  { "paragraph-indent", 1, 0, 'p' },		/* formerly -pi */  { "error-limit", 1, 0, 'e' },			/* formerly -el */  { "reference-limit", 1, 0, 'r' },		/* formerly -rl */  { "footnote-style", 1, 0, 's' },		/* formerly -ft */  { "version", 0, 0, 'V' },  {NULL, 0, NULL, 0}};  /* **************************************************************** *//*								    *//*			Main ()  Start of code  		    *//*					        		    *//* **************************************************************** *//* For each file mentioned in the command line, process it, turning   texinfo commands into wonderfully formatted output text. */main (argc, argv)     int argc;     char **argv;{  char *t = (char *) getenv ("EMACS");  int c;  int ind;  progname = argv[0];  if (t && strcmp (t, "t") == 0)    in_emacs++;  /* Parse argument flags from the input line. */  while ((c = getopt_long (argc, argv, "", long_options, &ind)) != EOF)    {      if (c == 0 && long_options[ind].flag == 0)	c = long_options[ind].val;      switch (c)	{	case 'f':	  /* user specified fill_column? */	  if (sscanf (optarg, "%d", &fill_column) != 1)	    usage ();	  break;	case 'p':	  /* User specified paragraph indent (paragraph_start_index)? */	  if (sscanf (optarg, "%d", &paragraph_start_indent) != 1)	    usage ();	  break;	case 'e':	  /* User specified error level? */	  if (sscanf (optarg, "%d", &max_error_level) != 1)	    usage ();	  break;	case 'r':	  /* User specified reference warning limit? */	  if (sscanf (optarg, "%d", &reference_warning_limit) != 1)	    usage ();	  break;	case 's':	  /* User specified footnote style? */	  set_footnote_style (optarg);	  break;	case 'V':		/* Use requested version info? */	  fprintf (stderr, "Makeinfo verison %d.%d.\n",		   major_version, minor_version);	  exit (NO_ERROR);	  break;	case '?':	  usage ();	}    }  if (optind == argc)    usage ();  /* Remaining arguments are file names of texinfo files.     Convert them, one by one. */  while (optind != argc)    convert (argv[optind++]);  exit (NO_ERROR);}/* **************************************************************** *//*								    *//*			Generic Utilities			    *//*								    *//* **************************************************************** *//* Just like malloc, but kills the program in case of fatal error. */char *xmalloc (nbytes)     int nbytes;{  char *temp = (char *) malloc (nbytes);  if (temp == (char *) NULL)    {      error ("Virtual memory exhausted! Needed %d bytes.", nbytes);      exit (FATAL);    }  return (temp);}/* Like realloc (), but barfs if there isn't enough memory. */char *xrealloc (pointer, nbytes)     char *pointer;     int nbytes;{  pointer = (char *) realloc (pointer, nbytes);  if (!pointer)    {      error ("Virtual memory exhausted in realloc ().");      abort ();    }  return (pointer);}/* Tell the user how to use this program. */usage (){  fprintf (stderr, "Usage: %s [options] texinfo-file...\n\\n\This program accepts as input files of texinfo commands and text\n\and outputs a file suitable for reading with GNU Info.\n\\n\The options are:\n\`+no-validate' to suppress node cross reference validation.\n\`+no-warn' to suppress warning messages (errors are still output).\n\`+no-split' to suppress the splitting of large files.\n\`+verbose' to print information about what is being done.\n\`+version' to print the version number of Makeinfo.\n\`+paragraph-indent NUM' to set the paragraph indent to NUM (default %d).\n\`+fill-column NUM' to set the filling column to NUM (default %d).\n\`+error-limit NUM' to set the error limit to NUM (default %d).\n\`+reference-limit NUM' to set the reference warning limit to NUM (default %d).\n\`+footnote-style STYLE' to set the footnote style to STYLE.  STYLE should\n\  either be `MN' for `make node', or `BN' for `bottom node'.\n\n",	   progname, paragraph_start_indent,	   fill_column, max_error_level, reference_warning_limit);  exit (FATAL);}/* **************************************************************** *//*								    *//*			Manipulating Lists      		    *//*					        		    *//* **************************************************************** */typedef struct generic_list{  struct generic_list *next;}            GENERIC_LIST;/* Reverse the chain of structures in LIST.  Output the new head   of the chain.  You should always assign the output value of this   function to something, or you will lose the chain. */GENERIC_LIST *reverse_list (list)     register GENERIC_LIST *list;{  register GENERIC_LIST *next;  register GENERIC_LIST *prev = (GENERIC_LIST *) NULL;  while (list)    {      next = list->next;      list->next = prev;      prev = list;      list = next;    }  return (prev);}/* **************************************************************** *//*								    *//*			Pushing and Popping Files       	    *//*								    *//* **************************************************************** *//* Find and load the file named FILENAME.  Return a pointer to   the loaded file, or NULL if it can't be loaded. */char *find_and_load (filename)     char *filename;{  struct stat fileinfo;  int file, n, i, count = 0;  char *result = (char *) NULL;  if (stat (filename, &fileinfo) != 0)    goto error_exit;  file = open (filename, O_RDONLY);  if (file < 0)    goto error_exit;  /* Load the file. */  result = xmalloc (fileinfo.st_size);  /* VMS stat lies about the st_size value.  The actual number of     readable bytes is always less than this value.  The arcane     mysteries of VMS/RMS are too much to probe, so this hack    suffices to make things work. */#if defined (VMS)  while ((n = read (file, result+count, fileinfo.st_size)) > 0)    count += n;  if (n == -1)#else    count = fileinfo.st_size;    if (read (file, result, fileinfo.st_size) != fileinfo.st_size)#endif  error_exit:    {      if (result)	free (result);      if (file != -1)	close (file);      return ((char *) NULL);    }  close (file);  /* Set the globals to the new file. */  input_text = result;  size_of_input_text = fileinfo.st_size;  input_filename = savestring (filename);  node_filename = savestring (filename);  input_text_offset = 0;  line_number = 1;  return (result);}/* Save the state of the current input file. */pushfile (){  FSTACK *newstack = (FSTACK *) xmalloc (sizeof (FSTACK));  newstack->filename = input_filename;  newstack->text = input_text;  newstack->size = size_of_input_text;  newstack->offset = input_text_offset;  newstack->line_number = line_number;  newstack->next = filestack;  filestack = newstack;  push_node_filename ();}/* Make the current file globals be what is on top of the file stack. */popfile (){  extern int executing_string;  FSTACK *temp = filestack;  if (!filestack)    abort ();			/* My fault.  I wonder what I did? */  /* Make sure that commands with braces have been satisfied. */  if (!executing_string)    discard_braces ();  /* Get the top of the stack into the globals. */  input_filename = filestack->filename;  input_text = filestack->text;  size_of_input_text = filestack->size;  input_text_offset = filestack->offset;  line_number = filestack->line_number;  /* Pop the stack. */  filestack = filestack->next;  free (temp);  pop_node_filename ();}/* Flush all open files on the file stack. */flush_file_stack (){  while (filestack)    {      free (input_filename);      free (input_text);      popfile ();    }}int node_filename_stack_index = 0;int node_filename_stack_size = 0;char **node_filename_stack = (char **)NULL;push_node_filename (){  if (node_filename_stack_index + 1 > node_filename_stack_size)    {      if (!node_filename_stack)	node_filename_stack =	  (char **)xmalloc ((node_filename_stack_size += 10)			    * sizeof (char *));      else	node_filename_stack =	  (char **)xrealloc (node_filename_stack,			     (node_filename_stack_size + 10)			     * sizeof (char *));    }  node_filename_stack[node_filename_stack_index] = node_filename;  node_filename_stack_index++;}pop_node_filename (){  node_filename = node_filename_stack[--node_filename_stack_index];}/* Return just the simple part of the filename; i.e. the   filename without the path information, or extensions.   This conses up a new string. */char *filename_part (filename)     char *filename;{  register int i = strlen (filename) - 1;  while (i && filename[i] != '/')    i--;  if (filename[i] == '/')    i++;#ifdef REMOVE_OUTPUT_EXTENSIONS  result = savestring (&filename[i]);  /* See if there is an extension to remove.  If so, remove it. */  if (rindex (result, '.'))    *(rindex (result, '.')) = '\0';  return (result);#else  return (savestring (&filename[i]));#endif /* REMOVE_OUTPUT_EXTENSIONS */}/* Return the pathname part of filename.  This can be NULL. */char *pathname_part (filename)     char *filename;{  char *expand_filename ();  char *result = (char *) NULL;  register int i;  filename = expand_filename (filename, "");  i = strlen (filename) - 1;  while (i && filename[i] != '/')    i--;  if (filename[i] == '/')    i++;  if (i)    {      result = xmalloc (1 + i);      strncpy (result, filename, i);      result[i] = '\0';    }  free (filename);  return (result);}/* Return the expansion of FILENAME. */char *expand_filename (filename, input_name)     char *filename, *input_name;{  char *full_pathname ();  filename = full_pathname (filename);  if (filename[0] == '.')    return (filename);  if (filename[0] != '/' && input_name[0] == '/')    {      /* Make it so that relative names work. */      char *result = xmalloc (1 + strlen (input_name)			      + strlen (filename));      int i = strlen (input_name) - 1;      strcpy (result, input_name);      while (result[i] != '/' && i)	i--;      if (result[i] == '/')	i++;      strcpy (&result[i], filename);      free (filename);      return (result);    }  return (filename);}/* Return the full path to FILENAME. */char *full_pathname (filename)     char *filename;{  int initial_character;  if (filename && (initial_character = *filename))    {      if (initial_character == '/')	return (savestring (filename));      if (initial_character != '~')	{	  return (savestring (filename));	}      else	{	  if (filename[1] == '/')	    {	      /* Return the concatenation of HOME and the rest of the string. */	      char *temp_home = (char *) getenv ("HOME");	      char *temp_name = xmalloc (strlen (&filename[2])					 + 1					 + temp_home ? strlen (temp_home)					 : 0);	      if (temp_home)		strcpy (temp_name, temp_home);	      strcat (temp_name, &filename[2]);	      return (temp_name);	    }	  else	    {	      struct passwd *user_entry;	      int i, c;	      char *username = xmalloc (257);	      char *temp_name;	      for (i = 1; c = filename[i]; i++)		{		  if (c == '/')		    break;		  else		    username[i - 1] = c;		}	      if (c)		username[i - 1] = '\0';	      user_entry = getpwnam (username);	      if (!user_entry)		return (savestring (filename));	      temp_name = xmalloc (1 + strlen (user_entry->pw_dir)				   + strlen (&filename[i]));	      strcpy (temp_name, user_entry->pw_dir);	      strcat (temp_name, &filename[i]);	      return (temp_name);	    }	}    }  else    {      return (savestring (filename));    }}/* **************************************************************** *//*								    *//*			Error Handling				    *//*								    *//* **************************************************************** *//* Number of errors encountered. */int errors_printed = 0;/* Print the last error gotten from the file system. */fs_error (filename)     char *filename;{  perror (filename);  return ((int) false);}/* Print an error message, and return false. */error (format, arg1, arg2, arg3, arg4, arg5)     char *format;{  remember_error ();  fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);  fprintf (stderr, "\n");

⌨️ 快捷键说明

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