📄 makeinfo.c
字号:
{ 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. */voidfix_whitespace (string) char *string;{ char *temp = (char *)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. */voiddiscard_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 offset where the string starts. */intget_until (match, string) char *match, **string;{ int len, current_point, x, new_point, tem; current_point = x = input_text_offset; 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. */ tem = new_point + (strlen (match) - 1); while (x != tem) if (input_text[x++] == '\n') line_number++; *string = (char *)xmalloc (len + 1); memcpy (*string, &input_text[current_point], len); (*string)[len] = 0; /* Now leave input_text_offset in a consistent state. */ input_text_offset = tem; if (input_text_offset > size_of_input_text) input_text_offset = size_of_input_text; return (new_point);}/* Read characters from the file until we are at MATCH or end of line. Place the characters read into STRING. */voidget_until_in_line (expand, match, string) int expand; char *match, **string;{ int real_bottom = size_of_input_text; int limit = search_forward ("\n", input_text_offset); if (limit < 0) limit = size_of_input_text; /* Replace input_text[input_text_offset .. limit-1] with its macro expansion (actually, we expand all commands). This allows the node names themselves to be constructed via a macro, as in: @macro foo{p, q} Together: \p\ & \q\. @end macro @node @foo{A,B}, next, prev, top Otherwise, the `,' separating the macro args A and B is taken as the node argument separator, so the node name is `@foo{A'. This expansion is only necessary on the first call, since we expand the whole line then. Furthermore, if we're executing a string, don't do it -- we'll end up shrinking the execution string which is currently aliased to `input_text', so it might get moved, and not updated in the `execution_strings' array. This happens when processing the (synthetic) Overview-Footnotes node in the Texinfo manual. */ if (expand && !executing_string && !me_executing_string) { char *xp; unsigned xp_len, new_len; /* Get original string from input. */ unsigned raw_len = limit - input_text_offset; char *str = xmalloc (raw_len + 1); strncpy (str, input_text + input_text_offset, raw_len); str[raw_len] = 0; /* Expand it. */ xp = expansion (str, 0); xp_len = strlen (xp); free (str); /* Plunk the expansion into the middle of `input_text' -- which is terminated by a newline, not a null. */ str = xmalloc (real_bottom - limit + 1); strncpy (str, input_text + limit, real_bottom - limit + 1); new_len = input_text_offset + xp_len + real_bottom - limit + 1; input_text = xrealloc (input_text, new_len); strcpy (input_text + input_text_offset, xp); strncpy (input_text + input_text_offset + xp_len, str, real_bottom - limit + 1); free (str); free (xp); limit += xp_len - raw_len; real_bottom += xp_len - raw_len; } size_of_input_text = limit; get_until (match, string); size_of_input_text = real_bottom;}voidget_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++; }}/* Backup the input pointer to the previous character, keeping track of the current line number. */voidbackup_input_pointer (){ if (input_text_offset) { input_text_offset--; if (curchar () == '\n') line_number--; }}/* Read characters from the file until we are at MATCH or closing brace. Place the characters read into STRING. */voidget_until_in_braces (match, string) char *match, **string;{ char *temp; int i, brace = 0; int match_len = strlen (match); for (i = input_text_offset; i < size_of_input_text; i++) { if (input_text[i] == '{') brace++; else if (input_text[i] == '}') brace--; else 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 = (char *)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. */static char *suffixes[] = { ".texinfo", ".texi", ".txinfo", "", (char *)NULL};voidinitialize_conversion (){ init_tag_table (); init_indices (); init_internals (); init_paragraph (); /* This is used for splitting the output file and for doing section headings. It was previously initialized in `init_paragraph', but its use there loses with the `init_paragraph' calls done by the multitable code; the tag indices get reset to zero. */ output_position = 0;}/* We read in multiples of 4k, simply because it is a typical pipe size on unix systems. */#define READ_BUFFER_GROWTH (4 * 4096)/* Convert the Texinfo file coming from the open stream STREAM. Assume the source of the stream is named NAME. */voidconvert_from_stream (stream, name) FILE *stream; char *name;{ char *buffer = (char *)NULL; int buffer_offset = 0, buffer_size = 0; initialize_conversion (); /* Read until the end of the stream. This isn't strictly correct, since the texinfo input may end before the stream ends, but it is a quick working hueristic. */ while (!feof (stream)) { int count; if (buffer_offset + (READ_BUFFER_GROWTH + 1) >= buffer_size) buffer = (char *) xrealloc (buffer, (buffer_size += READ_BUFFER_GROWTH)); count = fread (buffer + buffer_offset, 1, READ_BUFFER_GROWTH, stream); if (count < 0) { perror (name); exit (FATAL); } buffer_offset += count; if (count == 0) break; } /* Set the globals to the new file. */ input_text = buffer; size_of_input_text = buffer_offset; input_filename = xstrdup (name); node_filename = xstrdup (name); input_text_offset = 0; line_number = 1; /* Not strictly necessary. This magic prevents read_token () from doing extra unnecessary work each time it is called (that is a lot of times). The SIZE_OF_INPUT_TEXT is one past the actual end of the text. */ input_text[size_of_input_text] = '\n'; convert_from_loaded_file (name);}voidconvert_from_file (name) char *name;{ register int i; char *filename = (char *)xmalloc (strlen (name) + 50); initialize_conversion (); /* Try to load the file specified by NAME, concatenated with our various suffixes. Prefer files like `makeinfo.texi' to `makeinfo'. */ for (i = 0; suffixes[i]; i++) { strcpy (filename, name); strcat (filename, suffixes[i]); if (find_and_load (filename)) break; if (!suffixes[i][0] && strrchr (filename, '.')) { fs_error (filename); free (filename); return; } } if (!suffixes[i]) { fs_error (name); free (filename); return; } input_filename = filename; convert_from_loaded_file (name);} voidconvert_from_loaded_file (name) char *name;{ char *expand_filename (), *filename_part (); char *real_output_filename = (char *)NULL;#if defined (HAVE_MACROS) remember_itext (input_text, 0);#endif /* HAVE_MACROS */ /* Search this file looking for the special string which starts conversion. Once found, we may truly begin. */ input_text_offset = 0; while (input_text_offset >= 0) { input_text_offset = search_forward (setfilename_search, input_text_offset); if ((input_text_offset == 0) || ((input_text_offset > 0) && (input_text[input_text_offset -1] == '\n'))) break; else if (input_text_offset > 0) input_text_offset++; } if (input_text_offset < 0) { if (!command_output_filename) {#if defined (REQUIRE_SETFILENAME) error (_("No `%s' found in `%s'"), setfilename_search, name); goto finished;#else register int i, end_of_first_line; /* Find the end of the first line in the file. */ for (i = 0; i < size_of_input_text - 1; i++) if (input_text[i] == '\n') break; end_of_first_line = i + 1; input_text_offset = 0; for (i = 0; i < end_of_first_line; i++) { if ((input_text[i] == '\\') && (strncmp (input_text + i + 1, "include", 7) == 0)) { input_text_offset = end_of_first_line;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -