/** * Output a comment to the column using indent_with_tabs and * indent_cmt_with_tabs as the rules. * base_col is the indent of the first line of the comment. * On the first line, column == base_col. * On subsequnet lines, column >= base_col. * * @param brace_col the brace-level indent of the comment * @param base_col the indent of the start of the comment (multiline) * @param column the column that we should end up in */ static void cmt_output_indent(int brace_col, int base_col, int column) { int iwt; int tab_col; iwt = cpd.settings[UO_indent_cmt_with_tabs].b ? 2 : (cpd.settings[UO_indent_with_tabs].n ? 1 : 0); tab_col = (iwt == 0) ? 0 : ((iwt == 1) ? brace_col : base_col); //LOG_FMT(LSYS, "%s(brace=%d base=%d col=%d iwt=%d) tab=%d cur=%d\n", // __func__, brace_col, base_col, column, iwt, tab_col, cpd.column); cpd.did_newline = 0; if ((iwt == 2) || ((cpd.column == 1) && (iwt == 1))) { /* tab out as far as possible and then use spaces */ while (next_tab_column(cpd.column) <= tab_col) { add_text("\t"); } } /* space out the rest */ while (cpd.column < column) { add_text(" "); } }
/** * Advance to a specific column * cpd.column is the current column * * @param column The column to advance to */ void output_to_column(int column, bool allow_tabs) { int nc; cpd.did_newline = 0; if (allow_tabs) { /* tab out as far as possible and then use spaces */ while ((nc = next_tab_column(cpd.column)) <= column) { add_text("\t"); } } /* space out the final bit */ while (cpd.column < column) { add_text(" "); } }
void add_char(char ch) { /* convert a newline into the LF/CRLF/CR sequence */ if (ch == '\n') { fputs(cpd.newline, cpd.fout); cpd.column = 1; cpd.did_newline = 1; } else { fputc(ch, cpd.fout); if (ch == '\t') { cpd.column = next_tab_column(cpd.column); } else { cpd.column++; } } }
void output_indent(int column, int brace_col) { if ((cpd.column == 1) && (cpd.settings[UO_indent_with_tabs].n != 0)) { if (cpd.settings[UO_indent_with_tabs].n == 2) { brace_col = column; } /* tab out as far as possible and then use spaces */ int nc; while ((nc = next_tab_column(cpd.column)) <= brace_col) { add_text("\t"); } } /* space out the rest */ while (cpd.column < column) { add_text(" "); } }
/** * All output text is sent here, one char at a time. */ static void add_char(UINT32 ch) { static int last_char = 0; /* If we did a '\r' and it isn't followed by a '\n', then output a newline */ if ((last_char == '\r') && (ch != '\n')) { write_string(cpd.fout, cpd.newline.get(), cpd.enc); cpd.column = 1; cpd.did_newline = 1; cpd.spaces = 0; } /* convert a newline into the LF/CRLF/CR sequence */ if (ch == '\n') { write_string(cpd.fout, cpd.newline.get(), cpd.enc); cpd.column = 1; cpd.did_newline = 1; cpd.spaces = 0; } else if (ch == '\r') { /* do not output '\r' */ cpd.column = 1; cpd.did_newline = 1; cpd.spaces = 0; } else { /* Explicitly disallow a tab after a space */ if ((ch == '\t') && (last_char == ' ')) { int endcol = next_tab_column(cpd.column); while (cpd.column < endcol) { add_char(' '); } return; } else if (ch == ' ') { cpd.spaces++; cpd.column++; } else { while (cpd.spaces > 0) { write_char(cpd.fout, ' ', cpd.enc); cpd.spaces--; } write_char(cpd.fout, ch, cpd.enc); if (ch == '\t') { cpd.column = next_tab_column(cpd.column); } else { cpd.column++; } } } last_char = ch; }