📄 makeinfo.c
字号:
}/* input_text_offset is right at the command prefix character. Read the next token to determine what to do. */read_command (){ COMMAND *entry; input_text_offset++; free_and_clear (&command); command = read_token (); entry = get_command_entry (command); if ((int) entry < 0) { line_error ("Unknown info command `%s'", command); return; } if (entry->argument_in_braces) remember_brace (entry->proc); (*(entry->proc)) (START);}/* Return the string which invokes PROC; a pointer to a function. */char *find_proc_name (proc) FUNCTION *proc;{ register int i; for (i = 0; CommandTable[i].name; i++) if (proc == CommandTable[i].proc) return (CommandTable[i].name); return ("NO_NAME!");}init_brace_stack (){ brace_stack = (BRACE_ELEMENT *) NULL;}remember_brace (proc) FUNCTION *proc;{ if (curchar () != '{') line_error ("@%s expected `{..}'", command); else input_text_offset++; remember_brace_1 (proc, output_paragraph_offset);}/* Remember the current output position here. Save PROC along with it so you can call it later. */remember_brace_1 (proc, position) FUNCTION *proc; int position;{ BRACE_ELEMENT *new = (BRACE_ELEMENT *) xmalloc (sizeof (BRACE_ELEMENT)); new->next = brace_stack; new->proc = proc; new->pos = position; new->line = line_number; brace_stack = new;}/* Pop the top of the brace stack, and call the associated function with the args END and POS. */pop_and_call_brace (){ BRACE_ELEMENT *temp; FUNCTION *proc; int pos; if (brace_stack == (BRACE_ELEMENT *) NULL) return (line_error ("Unmatched close bracket")); pos = brace_stack->pos; proc = brace_stack->proc; temp = brace_stack->next; free (brace_stack); brace_stack = temp; return ((*proc) (END, pos, output_paragraph_offset));}/* You call discard_braces () when you shouldn't have any braces on the stack. I used to think that this happens for commands that don't take arguments in braces, but that was wrong because of things like @code{foo @@}. So now I only detect it at the beginning of nodes. */discard_braces (){ int temp_line_number = line_number; char *proc_name; if (!brace_stack) return; while (brace_stack) { line_number = brace_stack->line; proc_name = find_proc_name (brace_stack->proc); line_error ("@%s missing close brace", proc_name); line_number = temp_line_number; pop_and_call_brace (); }}get_char_len (character) int character;{ /* Return the printed length of the character. */ int len; switch (character) { case '\t': len = (output_column + 8) & 0xf7; if (len > fill_column) len = fill_column - output_column; else len = len - output_column; break; case '\n': len = fill_column - output_column; break; default: if (character < ' ') len = 2; else len = 1; } return (len);}add_word_args (format, arg1, arg2, arg3, arg4, arg5) char *format;{ char buffer[1000]; sprintf (buffer, format, arg1, arg2, arg3, arg4, arg5); add_word (buffer);}/* Add STRING to output_paragraph. */add_word (string) char *string;{ while (*string) add_char (*string++);}boolean last_char_was_newline = true;int last_inserted_character = 0;/* Add the character to the current paragraph. If filling_enabled is true, then do filling as well. */add_char (character) int character;{ extern int must_start_paragraph; /* If we are adding a character now, then we don't have to ignore close_paragraph () calls any more. */ if (must_start_paragraph) { must_start_paragraph = 0; if (current_indent > output_column) { indent (current_indent - output_column); output_column = current_indent; } } if (non_splitting_words && member (character, " \t\n")) character = ' ' | 0x80; switch (character) { case '\n': if (!filling_enabled) { insert ('\n'); /* Should I be flushing output here? * / flush_output (); */ output_column = 0; if (!no_indent) indent (output_column = current_indent); break; } else { if (sentence_ender (last_inserted_character)) { insert (' '); output_column++; last_inserted_character = character; } } if (last_char_was_newline) { close_paragraph (); pending_indent = 0; } else { last_char_was_newline = true; insert (' '); output_column++; } break; default: { int len = get_char_len (character); if ((character == ' ') && (last_char_was_newline)) { if (!paragraph_is_open) { pending_indent++; return; } } if (!paragraph_is_open) { start_paragraph (); /* If the paragraph is supposed to be indented a certain way, then discard all of the pending whitespace. Otherwise, we let the whitespace stay. */ if (!paragraph_start_indent) indent (pending_indent); pending_indent = 0; } if ((output_column += len) >= fill_column) { if (filling_enabled) { int temp = output_paragraph_offset - 1; while (temp > 0 && output_paragraph[--temp] != '\n') { if (output_paragraph[temp] == ' ') { output_paragraph[temp++] = '\n'; /* We have correctly broken the line where we want to. What we don't want is spaces following where we have decided to break the line. We get rid of them. */ { int t1 = temp; while (t1 < output_paragraph_offset && whitespace (output_paragraph[t1])) t1++; if (t1 != temp) { strncpy (&output_paragraph[temp], &output_paragraph[t1], (output_paragraph_offset - t1)); output_paragraph_offset -= (t1 - temp); } } /* Filled, but now indent if that is right. */ if (indented_fill && current_indent) { int buffer_len = ((output_paragraph_offset - temp) + current_indent); char *temp_buffer = xmalloc (buffer_len); int indentation = 0; /* We have to shift any markers that are in front of the wrap point. */ { register BRACE_ELEMENT *stack = brace_stack; while (stack) { if (stack->pos > temp) stack->pos += current_indent; stack = stack->next; } } while (indentation != current_indent) temp_buffer[indentation++] = ' '; strncpy (&temp_buffer[current_indent], &output_paragraph[temp], buffer_len - current_indent); if (output_paragraph_offset + buffer_len >= paragraph_buffer_len) { char *tt = (char *) xrealloc (output_paragraph, (paragraph_buffer_len += buffer_len)); output_paragraph = tt; } strncpy (&output_paragraph[temp], temp_buffer, buffer_len); output_paragraph_offset += current_indent; free (temp_buffer); } output_column = 0; while (temp != output_paragraph_offset) output_column += get_char_len (output_paragraph[temp++]); output_column += len; break; } } } } insert (character); last_char_was_newline = false; last_inserted_character = character; } }}/* Insert CHARACTER into OUTPUT_PARAGRAPH. */insert (character) int character;{ output_paragraph[output_paragraph_offset++] = character; if (output_paragraph_offset == paragraph_buffer_len) { output_paragraph = (char *) xrealloc (output_paragraph, (paragraph_buffer_len += 100)); }}/* Remove upto COUNT characters of whitespace from the the current output line. If COUNT is less than zero, then remove until none left. */kill_self_indent (count) int count;{ /* Handle infinite case first. */ if (count < 0) { output_column = 0; while (output_paragraph_offset) { if (whitespace (output_paragraph[output_paragraph_offset - 1])) output_paragraph_offset--; else break; } } else { while (output_paragraph_offset && count--) if (whitespace (output_paragraph[output_paragraph_offset - 1])) output_paragraph_offset--; else break; }}flush_output (){ register int i; if (!output_paragraph_offset) return; for (i = 0; i < output_paragraph_offset; i++) output_paragraph[i] &= 0x7f; fwrite (output_paragraph, 1, output_paragraph_offset, output_stream); output_position += output_paragraph_offset; output_paragraph_offset = 0;}/* How to close a paragraph controlling the number of lines between this one and the last one. *//* Paragraph spacing is controlled by this variable. It is the number of blank lines that you wish to appear between paragraphs. A value of 1 creates a single blank line between paragraphs. */int paragraph_spacing = 1;/* Close the current paragraph, leaving no blank lines between them. */close_single_paragraph (){ close_paragraph_with_lines (0);}close_paragraph_with_lines (lines) int lines;{ int old_spacing = paragraph_spacing; paragraph_spacing = lines; close_paragraph (); paragraph_spacing = old_spacing;}/* Non-zero means that start_paragraph () MUST be called before we pay any attention to close_paragraph () calls. */int must_start_paragraph = 0;/* Close the currently open paragraph. */close_paragraph (){ if (paragraph_is_open && !must_start_paragraph) { /* Gobble up blank lines that are extra... */ register int tindex = output_paragraph_offset; register int c; while (tindex && ((c = output_paragraph[tindex - 1]) == ' ' || c == '\n')) output_paragraph[--tindex] = '\n'; output_paragraph_offset = tindex; insert ('\n'); { register int i; for (i = 0; i < paragraph_spacing; i++) insert ('\n'); } flush_output (); paragraph_is_open = false; no_indent = false; } last_char_was_newline = true;}/* Begin a new paragraph. */start_paragraph (){ close_paragraph (); /* First close existing one. */ paragraph_is_open = true; if (!must_start_paragraph) { output_column = 0; /* If doing indentation, then insert the appropriate amount. */ if (!no_indent) { if (inhibit_paragraph_indentation || paragraph_start_indent < 0) output_column = current_indent; else output_column = current_indent + paragraph_start_indent; indent (output_column); } } else must_start_paragraph = 0;}/* Insert the indentation specified by AMOUNT. */indent (amount) int amount;{ while (--amount >= 0) insert (' ');}/* Search forward for STRING in input_text. FROM says where where to start. */search_forward (string, from) char *string; int from;{ int len = strlen (string); while (from < size_of_input_text) { if (strnicmp (input_text + from, string, len) == 0) return (from); from++; } return (-1);}/* Whoops, Unix doesn't have stricmp, or strnicmp. *//* Case independent string compare. */stricmp (string1, string2) char *string1, *string2;{ char ch1, ch2; for (;;) { ch1 = *string1++; ch2 = *string2++; if (!(ch1 | ch2)) return (0); ch1 = coerce_to_upper (ch1); ch2 = coerce_to_upper (ch2); if (ch1 != ch2) return (1); }}/* Compare at most COUNT characters from string1 to string2. Case doesn't matter. */strnicmp (string1, string2, count) char *string1, *string2;{ char ch1, ch2; while (count) { ch1 = *string1++; ch2 = *string2++; if (coerce_to_upper (ch1) == coerce_to_upper (ch2)) count--; else break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -