aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/hardcopy.c572
-rw-r--r--src/nvim/if_cscope.c372
2 files changed, 490 insertions, 454 deletions
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 6835e01b29..f1f84e63be 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -162,21 +162,21 @@ static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] =
* These values determine the print position on a page.
*/
typedef struct {
- int lead_spaces; /* remaining spaces for a TAB */
- int print_pos; /* virtual column for computing TABs */
- colnr_T column; /* byte column */
- linenr_T file_line; /* line nr in the buffer */
- size_t bytes_printed; /* bytes printed so far */
- int ff; /* seen form feed character */
+ int lead_spaces; // remaining spaces for a TAB
+ int print_pos; // virtual column for computing TABs
+ colnr_T column; // byte column
+ linenr_T file_line; // line nr in the buffer
+ size_t bytes_printed; // bytes printed so far
+ int ff; // seen form feed character
} prt_pos_T;
struct prt_mediasize_S {
char *name;
- double width; /* width and height in points for portrait */
+ double width; // width and height in points for portrait
double height;
};
-/* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */
+// PS font names, must be in Roman, Bold, Italic, Bold-Italic order
struct prt_ps_font_S {
int wx;
int uline_offset;
@@ -200,7 +200,7 @@ struct prt_ps_charset_S {
int has_charset;
};
-/* Collections of encodings and charsets for multi-byte printing */
+// Collections of encodings and charsets for multi-byte printing
struct prt_ps_mbfont_S {
int num_encodings;
struct prt_ps_encoding_S *encodings;
@@ -361,9 +361,10 @@ static uint32_t darken_rgb(uint32_t rgb)
static uint32_t prt_get_term_color(int colorindex)
{
- /* TODO: Should check for xterm with 88 or 256 colors. */
- if (t_colors > 8)
+ // TODO(vim): Should check for xterm with 88 or 256 colors.
+ if (t_colors > 8) {
return cterm_color_16[colorindex % 16];
+ }
return cterm_color_8[colorindex % 8];
}
@@ -535,7 +536,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum,
p_header, use_sandbox,
' ', width, NULL, NULL);
- /* Reset line numbers */
+ // Reset line numbers
curwin->w_cursor.lnum = tmp_lnum;
curwin->w_topline = tmp_topline;
curwin->w_botline = tmp_botline;
@@ -602,7 +603,7 @@ void ex_hardcopy(exarg_T *eap)
if (*eap->arg == '>') {
char_u *errormsg = NULL;
- /* Expand things like "%.ps". */
+ // Expand things like "%.ps".
if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) {
if (errormsg != NULL)
EMSG(errormsg);
@@ -666,7 +667,7 @@ void ex_hardcopy(exarg_T *eap)
goto print_fail_no_begin;
}
- /* Set colors and font to normal. */
+ // Set colors and font to normal.
curr_bg = 0xffffffff;
curr_fg = 0xffffffff;
curr_italic = kNone;
@@ -691,8 +692,8 @@ void ex_hardcopy(exarg_T *eap)
for (collated_copies = 0;
collated_copies < settings.n_collated_copies;
collated_copies++) {
- prt_pos_T prtpos; /* current print position */
- prt_pos_T page_prtpos; /* print position at page start */
+ prt_pos_T prtpos; // current print position
+ prt_pos_T page_prtpos; // print position at page start
int side;
memset(&page_prtpos, 0, sizeof(prt_pos_T));
@@ -700,7 +701,7 @@ void ex_hardcopy(exarg_T *eap)
prtpos = page_prtpos;
if (jobsplit && collated_copies > 0) {
- /* Splitting jobs: Stop a previous job and start a new one. */
+ // Splitting jobs: Stop a previous job and start a new one.
mch_print_end(&settings);
if (!mch_print_begin(&settings))
goto print_fail_no_begin;
@@ -717,7 +718,7 @@ void ex_hardcopy(exarg_T *eap)
for (uncollated_copies = 0;
uncollated_copies < settings.n_uncollated_copies;
uncollated_copies++) {
- /* Set the print position to the start of this page. */
+ // Set the print position to the start of this page.
prtpos = page_prtpos;
/*
@@ -728,7 +729,7 @@ void ex_hardcopy(exarg_T *eap)
* Print one page.
*/
- /* Check for interrupt character every page. */
+ // Check for interrupt character every page.
os_breakcheck();
if (got_int || settings.user_abort)
goto print_fail;
@@ -759,11 +760,12 @@ void ex_hardcopy(exarg_T *eap)
prtpos.column = hardcopy_line(&settings,
page_line, &prtpos);
if (prtpos.column == 0) {
- /* finished a file line */
+ // finished a file line
prtpos.bytes_printed +=
STRLEN(skipwhite(ml_get(prtpos.file_line)));
- if (++prtpos.file_line > eap->line2)
- break; /* reached the end */
+ if (++prtpos.file_line > eap->line2) {
+ break; // reached the end
+ }
} else if (prtpos.ff) {
/* Line had a formfeed in it - start new page but
* stay on the current line */
@@ -771,10 +773,12 @@ void ex_hardcopy(exarg_T *eap)
}
}
- if (!mch_print_end_page())
+ if (!mch_print_end_page()) {
goto print_fail;
- if (prtpos.file_line > eap->line2)
- break; /* reached the end */
+ }
+ if (prtpos.file_line > eap->line2) {
+ break; // reached the end
+ }
}
/*
@@ -791,7 +795,7 @@ void ex_hardcopy(exarg_T *eap)
if (settings.duplex && prtpos.file_line <= eap->line2)
++page_count;
- /* Remember the position where the next page starts. */
+ // Remember the position where the next page starts.
page_prtpos = prtpos;
}
@@ -855,7 +859,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
id = syn_get_final_id(id);
else
id = 0;
- /* Get the line again, a multi-line regexp may invalidate it. */
+ // Get the line again, a multi-line regexp may invalidate it.
line = ml_get(ppos->file_line);
if (id != current_syn_id) {
@@ -881,9 +885,10 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
if (need_break)
break;
}
- /* Keep the TAB if we didn't finish it. */
- if (need_break && tab_spaces > 0)
+ // Keep the TAB if we didn't finish it.
+ if (need_break && tab_spaces > 0) {
break;
+ }
} else if (line[col] == FF
&& printer_opts[OPT_PRINT_FORMFEED].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0])
@@ -942,7 +947,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
* http://www.adobe.com
*/
-#define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */
+#define PRT_PS_DEFAULT_DPI (72) // Default user space resolution
#define PRT_PS_DEFAULT_FONTSIZE (10)
#define PRT_PS_DEFAULT_BUFFER_SIZE (80)
@@ -951,20 +956,20 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
static struct prt_mediasize_S prt_mediasize[] =
{
- {"A4", 595.0, 842.0},
- {"letter", 612.0, 792.0},
- {"10x14", 720.0, 1008.0},
- {"A3", 842.0, 1191.0},
- {"A5", 420.0, 595.0},
- {"B4", 729.0, 1032.0},
- {"B5", 516.0, 729.0},
- {"executive", 522.0, 756.0},
- {"folio", 595.0, 935.0},
- {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */
- {"legal", 612.0, 1008.0},
- {"quarto", 610.0, 780.0},
- {"statement", 396.0, 612.0},
- {"tabloid", 792.0, 1224.0}
+ { "A4", 595.0, 842.0 },
+ { "letter", 612.0, 792.0 },
+ { "10x14", 720.0, 1008.0 },
+ { "A3", 842.0, 1191.0 },
+ { "A5", 420.0, 595.0 },
+ { "B4", 729.0, 1032.0 },
+ { "B5", 516.0, 729.0 },
+ { "executive", 522.0, 756.0 },
+ { "folio", 595.0, 935.0 },
+ { "ledger", 1224.0, 792.0 }, // Yes, it is wider than taller!
+ { "legal", 612.0, 1008.0 },
+ { "quarto", 610.0, 780.0 },
+ { "statement", 396.0, 612.0 },
+ { "tabloid", 792.0, 1224.0 }
};
#define PRT_PS_FONT_ROMAN (0)
@@ -972,7 +977,7 @@ static struct prt_mediasize_S prt_mediasize[] =
#define PRT_PS_FONT_OBLIQUE (2)
#define PRT_PS_FONT_BOLDOBLIQUE (3)
-/* Standard font metrics for Courier family */
+// Standard font metrics for Courier family
static struct prt_ps_font_S prt_ps_courier_font =
{
600,
@@ -981,7 +986,7 @@ static struct prt_ps_font_S prt_ps_courier_font =
{"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"}
};
-/* Generic font metrics for multi-byte fonts */
+// Generic font metrics for multi-byte fonts
static struct prt_ps_font_S prt_ps_mb_font =
{
1000,
@@ -1002,7 +1007,7 @@ static struct prt_ps_font_S *prt_ps_font;
#define CS_KANJITALK6 (0x40)
#define CS_KANJITALK7 (0x80)
-/* Japanese encodings and charsets */
+// Japanese encodings and charsets
static struct prt_ps_encoding_S j_encodings[] =
{
{"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990|
@@ -1034,7 +1039,7 @@ static struct prt_ps_charset_S j_charsets[] =
#define CS_GBK (0x20)
#define CS_SC_ISO10646 (0x40)
-/* Simplified Chinese encodings and charsets */
+// Simplified Chinese encodings and charsets
static struct prt_ps_encoding_S sc_encodings[] =
{
{"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)},
@@ -1070,7 +1075,7 @@ static struct prt_ps_charset_S sc_charsets[] =
#define CS_DLHKS (0x800)
#define CS_TC_ISO10646 (0x1000)
-/* Traditional Chinese encodings and charsets */
+// Traditional Chinese encodings and charsets
static struct prt_ps_encoding_S tc_encodings[] =
{
{"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)},
@@ -1107,7 +1112,7 @@ static struct prt_ps_charset_S tc_charsets[] =
#define CS_KR_X_1992_MS (0x04)
#define CS_KR_ISO10646 (0x08)
-/* Korean encodings and charsets */
+// Korean encodings and charsets
static struct prt_ps_encoding_S k_encodings[] =
{
{"iso-2022-kr", NULL, CS_KR_X_1992},
@@ -1166,7 +1171,7 @@ static struct prt_ps_mbfont_S prt_ps_mbfonts[] =
}
};
-/* Types of PS resource file currently used */
+// Types of PS resource file currently used
#define PRT_RESOURCE_TYPE_PROCSET (0)
#define PRT_RESOURCE_TYPE_ENCODING (1)
#define PRT_RESOURCE_TYPE_CMAP (2)
@@ -1194,7 +1199,7 @@ static char *prt_resource_types[] =
"cmap"
};
-/* Strings to look for in a PS resource file */
+// Strings to look for in a PS resource file
#define PRT_RESOURCE_HEADER "%!PS-Adobe-"
#define PRT_RESOURCE_RESOURCE "Resource-"
#define PRT_RESOURCE_PROCSET "ProcSet"
@@ -1254,20 +1259,20 @@ static double prt_pos_y_moveto = 0.0;
* Various control variables used to decide when and how to change the
* PostScript graphics state.
*/
-static int prt_need_moveto;
-static int prt_do_moveto;
-static int prt_need_font;
+static bool prt_need_moveto;
+static bool prt_do_moveto;
+static bool prt_need_font;
static int prt_font;
-static int prt_need_underline;
+static bool prt_need_underline;
static TriState prt_underline;
static TriState prt_do_underline;
-static int prt_need_fgcol;
+static bool prt_need_fgcol;
static uint32_t prt_fgcol;
-static int prt_need_bgcol;
-static int prt_do_bgcol;
+static bool prt_need_bgcol;
+static bool prt_do_bgcol;
static uint32_t prt_bgcol;
static uint32_t prt_new_bgcol;
-static int prt_attribute_change;
+static bool prt_attribute_change;
static double prt_text_run;
static int prt_page_num;
static int prt_bufsiz;
@@ -1295,8 +1300,8 @@ static int prt_out_mbyte;
static int prt_custom_cmap;
static char prt_cmap[80];
static int prt_use_courier;
-static int prt_in_ascii;
-static int prt_half_width;
+static bool prt_in_ascii;
+static bool prt_half_width;
static char *prt_ascii_encoding;
static char_u prt_hexchar[] = "0123456789abcdef";
@@ -1415,18 +1420,19 @@ static void prt_write_real(double val, int prec)
int fraction;
prt_real_bits(val, prec, &integer, &fraction);
- /* Emit integer part */
- sprintf((char *)prt_line_buffer, "%d", integer);
+ // Emit integer part
+ snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%d", integer);
prt_write_file(prt_line_buffer);
- /* Only emit fraction if necessary */
+ // Only emit fraction if necessary
if (fraction != 0) {
- /* Remove any trailing zeros */
+ // Remove any trailing zeros
while ((fraction % 10) == 0) {
prec--;
fraction /= 10;
}
- /* Emit fraction left padded with zeros */
- sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction);
+ // Emit fraction left padded with zeros
+ snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), ".%0*d",
+ prec, fraction);
prt_write_file(prt_line_buffer);
}
sprintf((char *)prt_line_buffer, " ");
@@ -1446,13 +1452,13 @@ static void prt_def_var(char *name, double value, int prec)
prt_write_file(prt_line_buffer);
}
-/* Convert size from font space to user space at current font scale */
+// Convert size from font space to user space at current font scale
#define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0))
static void prt_flush_buffer(void)
{
if (!GA_EMPTY(&prt_ps_buffer)) {
- /* Any background color must be drawn first */
+ // Any background color must be drawn first
if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) {
unsigned int r, g, b;
@@ -1460,14 +1466,14 @@ static void prt_flush_buffer(void)
prt_write_real(prt_pos_x_moveto, 2);
prt_write_real(prt_pos_y_moveto, 2);
prt_write_string("m\n");
- prt_do_moveto = FALSE;
+ prt_do_moveto = false;
}
- /* Size of rect of background color on which text is printed */
+ // Size of rect of background color on which text is printed
prt_write_real(prt_text_run, 2);
prt_write_real(prt_line_height, 2);
- /* Lastly add the color of the background */
+ // Lastly add the color of the background
r = (prt_new_bgcol & 0xff0000) >> 16;
g = (prt_new_bgcol & 0xff00) >> 8;
b = prt_new_bgcol & 0xff;
@@ -1484,10 +1490,10 @@ static void prt_flush_buffer(void)
prt_write_real(prt_pos_x_moveto, 2);
prt_write_real(prt_pos_y_moveto, 2);
prt_write_string("m\n");
- prt_do_moveto = FALSE;
+ prt_do_moveto = false;
}
- /* Underline length of text run */
+ // Underline length of text run
prt_write_real(prt_text_run, 2);
prt_write_string("ul\n");
}
@@ -1502,16 +1508,16 @@ static void prt_flush_buffer(void)
prt_write_string(">");
else
prt_write_string(")");
- /* Add a moveto if need be and use the appropriate show procedure */
+ // Add a moveto if need be and use the appropriate show procedure
if (prt_do_moveto) {
prt_write_real(prt_pos_x_moveto, 2);
prt_write_real(prt_pos_y_moveto, 2);
- /* moveto and a show */
+ // moveto and a show
prt_write_string("ms\n");
- prt_do_moveto = FALSE;
- } else /* Simple show */
+ prt_do_moveto = false;
+ } else { // Simple show
prt_write_string("s\n");
-
+ }
ga_clear(&prt_ps_buffer);
ga_init(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz);
}
@@ -1535,7 +1541,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
buffer = xmallocz(MAXPATHL);
STRLCPY(resource->name, name, 64);
- /* Look for named resource file in runtimepath */
+ // Look for named resource file in runtimepath
STRCPY(buffer, "print");
add_pathsep((char *)buffer);
xstrlcat((char *)buffer, name, MAXPATHL);
@@ -1547,7 +1553,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
return retval;
}
-/* PS CR and LF characters have platform independent values */
+// PS CR and LF characters have platform independent values
#define PSLF (0x0a)
#define PSCR (0x0d)
@@ -1557,7 +1563,7 @@ static int prt_resfile_next_line(void)
{
int idx;
- /* Move to start of next line and then find end of line */
+ // Move to start of next line and then find end of line
idx = prt_resfile.line_end + 1;
while (idx < prt_resfile.len) {
if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR)
@@ -1576,12 +1582,13 @@ static int prt_resfile_next_line(void)
return idx < prt_resfile.len;
}
-static int prt_resfile_strncmp(int offset, char *string, int len)
+static int prt_resfile_strncmp(int offset, const char *string, int len)
+ FUNC_ATTR_NONNULL_ALL
{
- /* Force not equal if string is longer than remainder of line */
- if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset)))
+ // Force not equal if string is longer than remainder of line
+ if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) {
return 1;
-
+ }
return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset],
string, len);
}
@@ -1614,178 +1621,182 @@ static int prt_resfile_skip_ws(int offset)
/* prt_next_dsc() - returns detail on next DSC comment line found. Returns true
* if a DSC comment is found, else false */
-static int prt_next_dsc(struct prt_dsc_line_S *p_dsc_line)
+static bool prt_next_dsc(struct prt_dsc_line_S *p_dsc_line)
+ FUNC_ATTR_NONNULL_ALL
{
int comment;
int offset;
- /* Move to start of next line */
- if (!prt_resfile_next_line())
- return FALSE;
-
- /* DSC comments always start %% */
- if (prt_resfile_strncmp(0, "%%", 2) != 0)
- return FALSE;
-
- /* Find type of DSC comment */
- for (comment = 0; comment < (int)ARRAY_SIZE(prt_dsc_table); comment++)
+ // Move to start of next line
+ if (!prt_resfile_next_line()) {
+ return false;
+ }
+ // DSC comments always start %%
+ if (prt_resfile_strncmp(0, "%%", 2) != 0) {
+ return false;
+ }
+ // Find type of DSC comment
+ for (comment = 0; comment < (int)ARRAY_SIZE(prt_dsc_table); comment++) {
if (prt_resfile_strncmp(0, prt_dsc_table[comment].string,
- prt_dsc_table[comment].len) == 0)
+ prt_dsc_table[comment].len) == 0) {
break;
-
+ }
+ }
if (comment != ARRAY_SIZE(prt_dsc_table)) {
- /* Return type of comment */
+ // Return type of comment
p_dsc_line->type = prt_dsc_table[comment].type;
offset = prt_dsc_table[comment].len;
} else {
- /* Unrecognised DSC comment, skip to ws after comment leader */
+ // Unrecognised DSC comment, skip to ws after comment leader
p_dsc_line->type = PRT_DSC_MISC_TYPE;
offset = prt_resfile_skip_nonws(0);
- if (offset == -1)
- return FALSE;
+ if (offset == -1) {
+ return false;
+ }
}
- /* Skip ws to comment value */
+ // Skip ws to comment value
offset = prt_resfile_skip_ws(offset);
- if (offset == -1)
- return FALSE;
-
+ if (offset == -1) {
+ return false;
+ }
p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset];
p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset);
- return TRUE;
+ return true;
}
/* Improved hand crafted parser to get the type, title, and version number of a
* PS resource file so the file details can be added to the DSC header comments.
*/
-static int prt_open_resource(struct prt_ps_resource_S *resource)
+static bool prt_open_resource(struct prt_ps_resource_S *resource)
+ FUNC_ATTR_NONNULL_ALL
{
- int offset;
- int seen_all;
- int seen_title;
- int seen_version;
- FILE *fd_resource;
struct prt_dsc_line_S dsc_line;
- fd_resource = os_fopen((char *)resource->filename, READBIN);
+ FILE *fd_resource = os_fopen((char *)resource->filename, READBIN);
if (fd_resource == NULL) {
EMSG2(_("E624: Can't open file \"%s\""), resource->filename);
- return FALSE;
+ return false;
}
memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN);
- /* Parse first line to ensure valid resource file */
+ // Parse first line to ensure valid resource file
prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u),
PRT_FILE_BUFFER_LEN, fd_resource);
if (ferror(fd_resource)) {
EMSG2(_("E457: Can't read PostScript resource file \"%s\""),
resource->filename);
fclose(fd_resource);
- return FALSE;
+ return false;
}
fclose(fd_resource);
prt_resfile.line_end = -1;
prt_resfile.line_start = 0;
- if (!prt_resfile_next_line())
- return FALSE;
-
- offset = 0;
+ if (!prt_resfile_next_line()) {
+ return false;
+ }
+ int offset = 0;
if (prt_resfile_strncmp(offset, PRT_RESOURCE_HEADER,
(int)STRLEN(PRT_RESOURCE_HEADER)) != 0) {
EMSG2(_("E618: file \"%s\" is not a PostScript resource file"),
- resource->filename);
- return FALSE;
+ resource->filename);
+ return false;
}
- /* Skip over any version numbers and following ws */
+ // Skip over any version numbers and following ws
offset += (int)STRLEN(PRT_RESOURCE_HEADER);
offset = prt_resfile_skip_nonws(offset);
- if (offset == -1)
- return FALSE;
+ if (offset == -1) {
+ return false;
+ }
offset = prt_resfile_skip_ws(offset);
- if (offset == -1)
- return FALSE;
-
+ if (offset == -1) {
+ return false;
+ }
if (prt_resfile_strncmp(offset, PRT_RESOURCE_RESOURCE,
(int)STRLEN(PRT_RESOURCE_RESOURCE)) != 0) {
EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
- resource->filename);
- return FALSE;
+ resource->filename);
+ return false;
}
offset += (int)STRLEN(PRT_RESOURCE_RESOURCE);
- /* Decide type of resource in the file */
+ // Decide type of resource in the file
if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET,
- (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0)
+ (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0) {
resource->type = PRT_RESOURCE_TYPE_PROCSET;
- else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING,
- (int)STRLEN(PRT_RESOURCE_ENCODING)) == 0)
+ } else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING,
+ (int)STRLEN(PRT_RESOURCE_ENCODING)) == 0) {
resource->type = PRT_RESOURCE_TYPE_ENCODING;
- else if (prt_resfile_strncmp(offset, PRT_RESOURCE_CMAP,
- (int)STRLEN(PRT_RESOURCE_CMAP)) == 0)
+ } else if (prt_resfile_strncmp(offset, PRT_RESOURCE_CMAP,
+ (int)STRLEN(PRT_RESOURCE_CMAP)) == 0) {
resource->type = PRT_RESOURCE_TYPE_CMAP;
- else {
+ } else {
EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
- resource->filename);
- return FALSE;
+ resource->filename);
+ return false;
}
- /* Look for title and version of resource */
+ // Look for title and version of resource
resource->title[0] = '\0';
resource->version[0] = '\0';
- seen_title = FALSE;
- seen_version = FALSE;
- seen_all = FALSE;
+ bool seen_title = false;
+ bool seen_version = false;
+ bool seen_all = false;
while (!seen_all && prt_next_dsc(&dsc_line)) {
switch (dsc_line.type) {
case PRT_DSC_TITLE_TYPE:
STRLCPY(resource->title, dsc_line.string, dsc_line.len + 1);
- seen_title = TRUE;
- if (seen_version)
- seen_all = TRUE;
+ seen_title = true;
+ if (seen_version) {
+ seen_all = true;
+ }
break;
case PRT_DSC_VERSION_TYPE:
STRLCPY(resource->version, dsc_line.string, dsc_line.len + 1);
- seen_version = TRUE;
- if (seen_title)
- seen_all = TRUE;
+ seen_version = true;
+ if (seen_title) {
+ seen_all = true;
+ }
break;
case PRT_DSC_ENDCOMMENTS_TYPE:
- /* Wont find title or resource after this comment, stop searching */
- seen_all = TRUE;
+ // Wont find title or resource after this comment, stop searching
+ seen_all = true;
break;
case PRT_DSC_MISC_TYPE:
- /* Not interested in whatever comment this line had */
+ // Not interested in whatever comment this line had
break;
}
}
if (!seen_title || !seen_version) {
EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
- resource->filename);
- return FALSE;
+ resource->filename);
+ return false;
}
- return TRUE;
+ return true;
}
-static int prt_check_resource(struct prt_ps_resource_S *resource, char_u *version)
+static bool prt_check_resource(const struct prt_ps_resource_S *resource,
+ const char_u *version)
+ FUNC_ATTR_NONNULL_ALL
{
- /* Version number m.n should match, the revision number does not matter */
+ // Version number m.n should match, the revision number does not matter
if (STRNCMP(resource->version, version, STRLEN(version))) {
EMSG2(_("E621: \"%s\" resource file has wrong version"),
- resource->name);
- return FALSE;
+ resource->name);
+ return false;
}
- /* Other checks to be added as needed */
- return TRUE;
+ // Other checks to be added as needed
+ return true;
}
static void prt_dsc_start(void)
@@ -1809,7 +1820,7 @@ static void prt_dsc_textline(char *comment, char *text)
static void prt_dsc_text(char *comment, char *text)
{
- /* TODO - should scan 'text' for any chars needing escaping! */
+ // TODO(vim): - should scan 'text' for any chars needing escaping!
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"%%%%%s: (%s)\n", comment, text);
prt_write_file(prt_line_buffer);
@@ -1833,9 +1844,8 @@ static void prt_dsc_ints(char *comment, int count, int *ints)
prt_write_string("\n");
}
-static void
-prt_dsc_resources (
- char *comment, /* if NULL add to previous */
+static void prt_dsc_resources(
+ char *comment, // if NULL add to previous
char *type,
char *string
)
@@ -1886,8 +1896,9 @@ static void prt_dsc_requirements(int duplex, int tumble, int collate, int color,
prt_write_string(" color");
if (num_copies > 1) {
prt_write_string(" numcopies(");
- /* Note: no space wanted so don't use prt_write_int() */
- sprintf((char *)prt_line_buffer, "%d", num_copies);
+ // Note: no space wanted so don't use prt_write_int()
+ snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%d",
+ num_copies);
prt_write_file(prt_line_buffer);
prt_write_string(")");
}
@@ -2037,13 +2048,13 @@ static int prt_get_lpp(void)
prt_ps_font->bbox_min_y)) / 2);
}
- /* Get height for topmost line based on background rect offset. */
+ // Get height for topmost line based on background rect offset.
prt_first_line_height = prt_line_height + prt_bgcol_offset;
- /* Calculate lpp */
+ // Calculate lpp
lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height);
- /* Adjust top margin if there is a header */
+ // Adjust top margin if there is a header
prt_top_margin -= prt_line_height * prt_header_height();
return lpp - prt_header_height();
@@ -2056,7 +2067,7 @@ static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap,
struct prt_ps_encoding_S *p_mbenc;
*pp_mbenc = NULL;
- /* Look for recognised encoding */
+ // Look for recognised encoding
enc_len = (int)STRLEN(p_encoding);
p_mbenc = p_cmap->encodings;
for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) {
@@ -2075,9 +2086,10 @@ static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap, st
int char_len;
struct prt_ps_charset_S *p_mbchar;
- /* Look for recognised character set, using default if one is not given */
- if (*p_charset == NUL)
+ // Look for recognised character set, using default if one is not given
+ if (*p_charset == NUL) {
p_charset = p_cmap->defcs;
+ }
char_len = (int)STRLEN(p_charset);
p_mbchar = p_cmap->charsets;
for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) {
@@ -2132,7 +2144,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
break;
}
- /* Use first encoding matched if no charset matched */
+ // Use first encoding matched if no charset matched
if (p_mbenc_first != NULL && p_mbchar == NULL) {
p_mbenc = p_mbenc_first;
cmap = effective_cmap;
@@ -2143,24 +2155,24 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_out_mbyte = (p_mbenc != NULL);
if (prt_out_mbyte) {
- /* Build CMap name - will be same for all multi-byte fonts used */
+ // Build CMap name - will be same for all multi-byte fonts used
prt_cmap[0] = NUL;
prt_custom_cmap = (p_mbchar == NULL);
if (!prt_custom_cmap) {
- /* Check encoding and character set are compatible */
+ // Check encoding and character set are compatible
if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0) {
EMSG(_("E673: Incompatible multi-byte encoding and character set."));
return FALSE;
}
- /* Add charset name if not empty */
+ // Add charset name if not empty
if (p_mbchar->cmap_charset != NULL) {
STRLCPY(prt_cmap, p_mbchar->cmap_charset, sizeof(prt_cmap) - 2);
STRCAT(prt_cmap, "-");
}
} else {
- /* Add custom CMap character set name */
+ // Add custom CMap character set name
if (*p_pmcs == NUL) {
EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding."));
return FALSE;
@@ -2169,7 +2181,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
STRCAT(prt_cmap, "-");
}
- /* CMap name ends with (optional) encoding name and -H for horizontal */
+ // CMap name ends with (optional) encoding name and -H for horizontal
if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap)
+ STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) {
STRCAT(prt_cmap, p_mbenc->cmap_encoding);
@@ -2182,7 +2194,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
return FALSE;
}
- /* Derive CID font names with fallbacks if not defined */
+ // Derive CID font names with fallbacks if not defined
prt_build_cid_fontname(PRT_PS_FONT_ROMAN,
mbfont_opts[OPT_MBFONT_REGULAR].string,
mbfont_opts[OPT_MBFONT_REGULAR].strlen);
@@ -2287,9 +2299,10 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
psettings->chars_per_line = prt_get_cpl();
psettings->lines_per_page = prt_get_lpp();
- /* Catch margin settings that leave no space for output! */
- if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0)
+ // Catch margin settings that leave no space for output!
+ if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) {
return FAIL;
+ }
/*
* Sort out the number of copies to be printed. PS by default will do
@@ -2328,10 +2341,10 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_tumble = TRUE;
}
- /* For now user abort not supported */
+ // For now user abort not supported
psettings->user_abort = 0;
- /* If the user didn't specify a file name, use a temp file. */
+ // If the user didn't specify a file name, use a temp file.
if (psettings->outfile == NULL) {
prt_ps_file_name = vim_tempname();
if (prt_ps_file_name == NULL) {
@@ -2359,12 +2372,12 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_page_num = 0;
- prt_attribute_change = FALSE;
- prt_need_moveto = FALSE;
- prt_need_font = FALSE;
- prt_need_fgcol = FALSE;
- prt_need_bgcol = FALSE;
- prt_need_underline = FALSE;
+ prt_attribute_change = false;
+ prt_need_moveto = false;
+ prt_need_font = false;
+ prt_need_fgcol = false;
+ prt_need_bgcol = false;
+ prt_need_underline = false;
prt_file_error = FALSE;
@@ -2480,14 +2493,15 @@ int mch_print_begin(prt_settings_T *psettings)
+ 0.5);
}
prt_dsc_ints("BoundingBox", 4, bbox);
- /* The media width and height does not change with landscape printing! */
+ // The media width and height does not change with landscape printing!
prt_dsc_docmedia(prt_mediasize[prt_media].name,
- prt_mediasize[prt_media].width,
- prt_mediasize[prt_media].height,
- (double)0, NULL, NULL);
- /* Define fonts needed */
- if (!prt_out_mbyte || prt_use_courier)
+ prt_mediasize[prt_media].width,
+ prt_mediasize[prt_media].height,
+ (double)0, NULL, NULL);
+ // Define fonts needed
+ if (!prt_out_mbyte || prt_use_courier) {
prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font);
+ }
if (prt_out_mbyte) {
prt_dsc_font_resource((prt_use_courier ? NULL
: "DocumentNeededResources"), &prt_ps_mb_font);
@@ -2495,7 +2509,7 @@ int mch_print_begin(prt_settings_T *psettings)
prt_dsc_resources(NULL, "cmap", prt_cmap);
}
- /* Search for external resources VIM supplies */
+ // Search for external resources VIM supplies
if (!prt_find_resource("prolog", &res_prolog)) {
EMSG(_("E456: Can't find PostScript resource file \"prolog.ps\""));
return FALSE;
@@ -2505,7 +2519,7 @@ int mch_print_begin(prt_settings_T *psettings)
if (!prt_check_resource(&res_prolog, PRT_PROLOG_VERSION))
return FALSE;
if (prt_out_mbyte) {
- /* Look for required version of multi-byte printing procset */
+ // Look for required version of multi-byte printing procset
if (!prt_find_resource("cidfont", &res_cidfont)) {
EMSG(_("E456: Can't find PostScript resource file \"cidfont.ps\""));
return FALSE;
@@ -2525,15 +2539,15 @@ int mch_print_begin(prt_settings_T *psettings)
p_encoding = enc_skip(p_penc);
if (*p_encoding == NUL
|| !prt_find_resource((char *)p_encoding, &res_encoding)) {
- /* 'printencoding' not set or not supported - find alternate */
+ // 'printencoding' not set or not supported - find alternate
int props;
p_encoding = enc_skip(p_enc);
props = enc_canon_props(p_encoding);
if (!(props & ENC_8BIT)
|| !prt_find_resource((char *)p_encoding, &res_encoding)) {
- /* 8-bit 'encoding' is not supported */
- /* Use latin1 as default printing encoding */
+ // 8-bit 'encoding' is not supported
+ // Use latin1 as default printing encoding
p_encoding = (char_u *)"latin1";
if (!prt_find_resource((char *)p_encoding, &res_encoding)) {
EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
@@ -2551,7 +2565,7 @@ int mch_print_begin(prt_settings_T *psettings)
if (*p_encoding == NUL)
p_encoding = enc_skip(p_enc);
if (prt_use_courier) {
- /* Include ASCII range encoding vector */
+ // Include ASCII range encoding vector
if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) {
EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
prt_ascii_encoding);
@@ -2576,7 +2590,7 @@ int mch_print_begin(prt_settings_T *psettings)
prt_do_conv = prt_conv.vc_type != CONV_NONE;
if (prt_out_mbyte && prt_custom_cmap) {
- /* Find user supplied CMap */
+ // Find user supplied CMap
if (!prt_find_resource(prt_cmap, &res_cmap)) {
EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
prt_cmap);
@@ -2586,7 +2600,7 @@ int mch_print_begin(prt_settings_T *psettings)
return FALSE;
}
- /* List resources supplied */
+ // List resources supplied
STRCPY(buffer, res_prolog.title);
STRCAT(buffer, " ");
STRCAT(buffer, res_prolog.version);
@@ -2620,9 +2634,10 @@ int mch_print_begin(prt_settings_T *psettings)
*/
prt_dsc_noarg("BeginDefaults");
- /* List font resources most likely common to all pages */
- if (!prt_out_mbyte || prt_use_courier)
+ // List font resources most likely common to all pages
+ if (!prt_out_mbyte || prt_use_courier) {
prt_dsc_font_resource("PageResources", &prt_ps_courier_font);
+ }
if (prt_out_mbyte) {
prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"),
&prt_ps_mb_font);
@@ -2630,7 +2645,7 @@ int mch_print_begin(prt_settings_T *psettings)
prt_dsc_resources(NULL, "cmap", prt_cmap);
}
- /* Paper will be used for all pages */
+ // Paper will be used for all pages
prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name);
prt_dsc_noarg("EndDefaults");
@@ -2640,15 +2655,18 @@ int mch_print_begin(prt_settings_T *psettings)
*/
prt_dsc_noarg("BeginProlog");
- /* Add required procsets - NOTE: order is important! */
- if (!prt_add_resource(&res_prolog))
- return FALSE;
+ // Add required procsets - NOTE: order is important!
+ if (!prt_add_resource(&res_prolog)) {
+ return false;
+ }
if (prt_out_mbyte) {
- /* Add CID font procset, and any user supplied CMap */
- if (!prt_add_resource(&res_cidfont))
- return FALSE;
- if (prt_custom_cmap && !prt_add_resource(&res_cmap))
- return FALSE;
+ // Add CID font procset, and any user supplied CMap
+ if (!prt_add_resource(&res_cidfont)) {
+ return false;
+ }
+ if (prt_custom_cmap && !prt_add_resource(&res_cmap)) {
+ return false;
+ }
}
if (!prt_out_mbyte || prt_use_courier)
@@ -2664,7 +2682,7 @@ int mch_print_begin(prt_settings_T *psettings)
*/
prt_dsc_noarg("BeginSetup");
- /* Device setup - page size and number of uncollated copies */
+ // Device setup - page size and number of uncollated copies
prt_write_int((int)prt_mediasize[prt_media].width);
prt_write_int((int)prt_mediasize[prt_media].height);
prt_write_int(0);
@@ -2677,7 +2695,7 @@ int mch_print_begin(prt_settings_T *psettings)
prt_write_boolean(prt_collate);
prt_write_string("c\n");
- /* Font resource inclusion and definition */
+ // Font resource inclusion and definition
if (!prt_out_mbyte || prt_use_courier) {
/* When using Courier for ASCII range when printing multi-byte, need to
* pick up ASCII encoding to use with it. */
@@ -2720,35 +2738,36 @@ int mch_print_begin(prt_settings_T *psettings)
if (!prt_custom_cmap)
prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
prt_def_cidfont("CF1", (int)prt_line_height,
- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
- } else
- /* Use ROMAN for BOLD */
+ prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
+ } else {
+ // Use ROMAN for BOLD
prt_dup_cidfont("CF0", "CF1");
-
+ }
if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) {
prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
if (!prt_custom_cmap)
prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
prt_def_cidfont("CF2", (int)prt_line_height,
- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
- } else
- /* Use ROMAN for OBLIQUE */
+ prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
+ } else {
+ // Use ROMAN for OBLIQUE
prt_dup_cidfont("CF0", "CF2");
-
+ }
if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) {
prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
if (!prt_custom_cmap)
prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
prt_def_cidfont("CF3", (int)prt_line_height,
- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
- } else
- /* Use BOLD for BOLDOBLIQUE */
+ prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
+ } else {
+ // Use BOLD for BOLDOBLIQUE
prt_dup_cidfont("CF1", "CF3");
+ }
}
- /* Misc constant vars used for underlining and background rects */
+ // Misc constant vars used for underlining and background rects
prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height,
prt_ps_font->uline_offset), 2);
prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height,
@@ -2757,7 +2776,7 @@ int mch_print_begin(prt_settings_T *psettings)
prt_dsc_noarg("EndSetup");
- /* Fail if any problems writing out to the PS file */
+ // Fail if any problems writing out to the PS file
retval = !prt_file_error;
return retval;
@@ -2780,7 +2799,7 @@ void mch_print_end(prt_settings_T *psettings)
if (!prt_file_error && psettings->outfile == NULL
&& !got_int && !psettings->user_abort) {
- /* Close the file first. */
+ // Close the file first.
if (prt_ps_fd != NULL) {
fclose(prt_ps_fd);
prt_ps_fd = NULL;
@@ -2831,7 +2850,7 @@ int mch_print_begin_page(char_u *str)
prt_bgcol = PRCOLOR_WHITE;
prt_font = PRT_PS_FONT_ROMAN;
- /* Set up page transformation for landscape printing. */
+ // Set up page transformation for landscape printing.
if (!prt_portrait) {
prt_write_int(-((int)prt_mediasize[prt_media].width));
prt_write_string("sl\n");
@@ -2839,7 +2858,7 @@ int mch_print_begin_page(char_u *str)
prt_dsc_noarg("EndPageSetup");
- /* We have reset the font attributes, force setting them again. */
+ // We have reset the font attributes, force setting them again.
curr_bg = 0xffffffff;
curr_fg = 0xffffffff;
curr_bold = kNone;
@@ -2865,9 +2884,9 @@ void mch_print_start_line(const bool margin, const int page_line)
prt_pos_y = prt_top_margin - prt_first_line_height -
page_line * prt_line_height;
- prt_attribute_change = TRUE;
- prt_need_moveto = TRUE;
- prt_half_width = FALSE;
+ prt_attribute_change = true;
+ prt_need_moveto = true;
+ prt_half_width = false;
}
int mch_print_text_out(char_u *const textp, size_t len)
@@ -2889,16 +2908,16 @@ int mch_print_text_out(char_u *const textp, size_t len)
const bool in_ascii = (len == 1 && *p < 0x80);
if (prt_in_ascii) {
if (!in_ascii) {
- /* No longer in ASCII range - need to switch font */
- prt_in_ascii = FALSE;
- prt_need_font = TRUE;
- prt_attribute_change = TRUE;
+ // No longer in ASCII range - need to switch font
+ prt_in_ascii = false;
+ prt_need_font = true;
+ prt_attribute_change = true;
}
} else if (in_ascii) {
- /* Now in ASCII range - need to switch font */
- prt_in_ascii = TRUE;
- prt_need_font = TRUE;
- prt_attribute_change = TRUE;
+ // Now in ASCII range - need to switch font
+ prt_in_ascii = true;
+ prt_need_font = true;
+ prt_attribute_change = true;
}
}
if (prt_out_mbyte) {
@@ -2908,16 +2927,16 @@ int mch_print_text_out(char_u *const textp, size_t len)
}
if (prt_half_width) {
if (!half_width) {
- prt_half_width = FALSE;
+ prt_half_width = false;
prt_pos_x += prt_char_width/4;
- prt_need_moveto = TRUE;
- prt_attribute_change = TRUE;
+ prt_need_moveto = true;
+ prt_attribute_change = true;
}
} else if (half_width) {
- prt_half_width = TRUE;
+ prt_half_width = true;
prt_pos_x += prt_char_width/4;
- prt_need_moveto = TRUE;
- prt_attribute_change = TRUE;
+ prt_need_moveto = true;
+ prt_attribute_change = true;
}
}
@@ -2926,24 +2945,25 @@ int mch_print_text_out(char_u *const textp, size_t len)
*/
if (prt_attribute_change) {
prt_flush_buffer();
- /* Reset count of number of chars that will be printed */
+ // Reset count of number of chars that will be printed
prt_text_run = 0;
if (prt_need_moveto) {
prt_pos_x_moveto = prt_pos_x;
prt_pos_y_moveto = prt_pos_y;
- prt_do_moveto = TRUE;
+ prt_do_moveto = true;
- prt_need_moveto = FALSE;
+ prt_need_moveto = false;
}
if (prt_need_font) {
- if (!prt_in_ascii)
+ if (!prt_in_ascii) {
prt_write_string("CF");
- else
+ } else {
prt_write_string("F");
+ }
prt_write_int(prt_font);
prt_write_string("sf\n");
- prt_need_font = FALSE;
+ prt_need_font = false;
}
if (prt_need_fgcol) {
unsigned int r, g, b;
@@ -2959,22 +2979,24 @@ int mch_print_text_out(char_u *const textp, size_t len)
prt_write_real(b / 255.0, 3);
prt_write_string("r\n");
}
- prt_need_fgcol = FALSE;
+ prt_need_fgcol = false;
}
if (prt_bgcol != PRCOLOR_WHITE) {
prt_new_bgcol = prt_bgcol;
- if (prt_need_bgcol)
- prt_do_bgcol = TRUE;
- } else
- prt_do_bgcol = FALSE;
- prt_need_bgcol = FALSE;
+ if (prt_need_bgcol) {
+ prt_do_bgcol = true;
+ }
+ } else {
+ prt_do_bgcol = false;
+ }
+ prt_need_bgcol = false;
if (prt_need_underline)
prt_do_underline = prt_underline;
- prt_need_underline = FALSE;
+ prt_need_underline = false;
- prt_attribute_change = FALSE;
+ prt_attribute_change = false;
}
if (prt_do_conv) {
@@ -3059,29 +3081,29 @@ void mch_print_set_font(const TriState iBold, const TriState iItalic,
if (font != prt_font) {
prt_font = font;
- prt_attribute_change = TRUE;
- prt_need_font = TRUE;
+ prt_attribute_change = true;
+ prt_need_font = true;
}
if (prt_underline != iUnderline) {
prt_underline = iUnderline;
- prt_attribute_change = TRUE;
- prt_need_underline = TRUE;
+ prt_attribute_change = true;
+ prt_need_underline = true;
}
}
void mch_print_set_bg(uint32_t bgcol)
{
prt_bgcol = bgcol;
- prt_attribute_change = TRUE;
- prt_need_bgcol = TRUE;
+ prt_attribute_change = true;
+ prt_need_bgcol = true;
}
void mch_print_set_fg(uint32_t fgcol)
{
if (fgcol != prt_fgcol) {
prt_fgcol = fgcol;
- prt_attribute_change = TRUE;
- prt_need_fgcol = TRUE;
+ prt_attribute_change = true;
+ prt_need_fgcol = true;
}
}
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 0f9984ec38..2af09f10cb 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -71,10 +71,10 @@ static void cs_usage_msg(csid_e x)
static enum {
- EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */
- EXP_SCSCOPE_SUBCMD, /* expand ":scscope" sub-commands */
- EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */
- EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */
+ EXP_CSCOPE_SUBCMD, // expand ":cscope" sub-commands
+ EXP_SCSCOPE_SUBCMD, // expand ":scscope" sub-commands
+ EXP_CSCOPE_FIND, // expand ":cscope find" arguments
+ EXP_CSCOPE_KILL // expand ":cscope kill" arguments
} expand_what;
/*
@@ -87,13 +87,13 @@ char_u *get_cscope_name(expand_T *xp, int idx)
switch (expand_what) {
case EXP_CSCOPE_SUBCMD:
- /* Complete with sub-commands of ":cscope":
- * add, find, help, kill, reset, show */
+ // Complete with sub-commands of ":cscope":
+ // add, find, help, kill, reset, show
return (char_u *)cs_cmds[idx].name;
case EXP_SCSCOPE_SUBCMD:
{
- /* Complete with sub-commands of ":scscope": same sub-commands as
- * ":cscope" but skip commands which don't support split windows */
+ // Complete with sub-commands of ":scscope": same sub-commands as
+ // ":cscope" but skip commands which don't support split windows
int i;
for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++)
if (cs_cmds[i].cansplit)
@@ -118,10 +118,10 @@ char_u *get_cscope_name(expand_T *xp, int idx)
{
static char connection[5];
- /* ":cscope kill" accepts connection numbers or partial names of
- * the pathname of the cscope database as argument. Only complete
- * with connection numbers. -1 can also be used to kill all
- * connections. */
+ // ":cscope kill" accepts connection numbers or partial names of
+ // the pathname of the cscope database as argument. Only complete
+ // with connection numbers. -1 can also be used to kill all
+ // connections.
size_t i;
for (i = 0, current_idx = 0; i < csinfo_size; i++) {
if (csinfo[i].fname == NULL)
@@ -149,7 +149,7 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
expand_what = ((cmdidx == CMD_scscope)
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD);
- /* (part of) subcommand already typed */
+ // (part of) subcommand already typed
if (*arg != NUL) {
const char *p = (const char *)skiptowhite((const char_u *)arg);
if (*p != NUL) { // Past first word.
@@ -175,7 +175,7 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
static void
do_cscope_general(
exarg_T *eap,
- int make_split /* whether to split window */
+ int make_split // whether to split window
)
{
cscmd_T *cmdp;
@@ -276,17 +276,19 @@ void ex_cstag(exarg_T *eap)
/// This simulates a vim_fgets(), but for cscope, returns the next line
/// from the cscope output. should only be called from find_tags()
///
-/// @return TRUE if eof, FALSE otherwise
-int cs_fgets(char_u *buf, int size)
+/// @return true if eof, FALSE otherwise
+bool cs_fgets(char_u *buf, int size)
+ FUNC_ATTR_NONNULL_ALL
{
char *p;
- if ((p = cs_manage_matches(NULL, NULL, 0, Get)) == NULL)
+ if ((p = cs_manage_matches(NULL, NULL, 0, Get)) == NULL) {
return true;
+ }
STRLCPY(buf, p, size);
- return FALSE;
-} /* cs_fgets */
+ return false;
+}
/// Called only from do_tag(), when popping the tag stack.
@@ -328,48 +330,53 @@ void cs_print_tags(void)
*
* Note: All string comparisons are case sensitive!
*/
-int cs_connection(int num, char_u *dbpath, char_u *ppath)
+bool cs_connection(int num, char_u *dbpath, char_u *ppath)
{
- if (num < 0 || num > 4 || (num > 0 && !dbpath))
+ if (num < 0 || num > 4 || (num > 0 && !dbpath)) {
return false;
+ }
for (size_t i = 0; i < csinfo_size; i++) {
- if (!csinfo[i].fname)
+ if (!csinfo[i].fname) {
continue;
-
- if (num == 0)
- return TRUE;
-
+ }
+ if (num == 0) {
+ return true;
+ }
switch (num) {
case 1:
- if (strstr(csinfo[i].fname, (char *)dbpath))
- return TRUE;
+ if (strstr(csinfo[i].fname, (char *)dbpath)) {
+ return true;
+ }
break;
case 2:
- if (strcmp(csinfo[i].fname, (char *)dbpath) == 0)
- return TRUE;
+ if (strcmp(csinfo[i].fname, (char *)dbpath) == 0) {
+ return true;
+ }
break;
case 3:
if (strstr(csinfo[i].fname, (char *)dbpath)
&& ((!ppath && !csinfo[i].ppath)
|| (ppath
&& csinfo[i].ppath
- && strstr(csinfo[i].ppath, (char *)ppath))))
- return TRUE;
+ && strstr(csinfo[i].ppath, (char *)ppath)))) {
+ return true;
+ }
break;
case 4:
if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0)
&& ((!ppath && !csinfo[i].ppath)
|| (ppath
&& csinfo[i].ppath
- && (strcmp(csinfo[i].ppath, (char *)ppath) == 0))))
- return TRUE;
+ && (strcmp(csinfo[i].ppath, (char *)ppath) == 0)))) {
+ return true;
+ }
break;
}
}
- return FALSE;
-} /* cs_connection */
+ return false;
+} // cs_connection
/*
@@ -419,7 +426,7 @@ cs_add_common(
size_t usedlen = 0;
char_u *fbuf = NULL;
- /* get the filename (arg1), expand it, and try to stat it */
+ // get the filename (arg1), expand it, and try to stat it
fname = xmalloc(MAXPATHL + 1);
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
@@ -451,7 +458,7 @@ staterr:
}
int i;
- /* if filename is a directory, append the cscope database name to it */
+ // if filename is a directory, append the cscope database name to it
if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) {
fname2 = (char *)xmalloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2);
@@ -512,18 +519,18 @@ add_err:
xfree(fname);
xfree(ppath);
return CSCOPE_FAILURE;
-} /* cs_add_common */
+}
static int cs_check_for_connections(void)
{
return cs_cnt_connections() > 0;
-} /* cs_check_for_connections */
+}
static int cs_check_for_tags(void)
{
return p_tags[0] != NUL && curbuf->b_p_tags != NULL;
-} /* cs_check_for_tags */
+}
/// Count the number of cscope connections.
static size_t cs_cnt_connections(void)
@@ -535,10 +542,10 @@ static size_t cs_cnt_connections(void)
cnt++;
}
return cnt;
-} /* cs_cnt_connections */
+}
static void cs_reading_emsg(
- size_t idx /* connection index */
+ size_t idx // connection index
)
{
EMSGU(_("E262: error reading cscope connection %" PRIu64), idx);
@@ -602,7 +609,7 @@ static int cs_cnt_matches(size_t idx)
xfree(buf);
return nlines;
-} /* cs_cnt_matches */
+}
/// Creates the actual cscope command query from what the user entered.
@@ -646,8 +653,8 @@ static char *cs_create_cmd(char *csoption, char *pattern)
return NULL;
}
- /* Skip white space before the patter, except for text and pattern search,
- * they may want to use the leading white space. */
+ // Skip white space before the patter, except for text and pattern search,
+ // they may want to use the leading white space.
pat = pattern;
if (search != 4 && search != 6)
while (ascii_iswhite(*pat))
@@ -658,7 +665,7 @@ static char *cs_create_cmd(char *csoption, char *pattern)
(void)sprintf(cmd, "%d%s", search, pat);
return cmd;
-} /* cs_create_cmd */
+}
/// This piece of code was taken/adapted from nvi. do we need to add
@@ -694,15 +701,18 @@ err_closing:
case -1:
(void)EMSG(_("E622: Could not fork for cscope"));
goto err_closing;
- case 0: /* child: run cscope. */
- if (dup2(to_cs[0], STDIN_FILENO) == -1)
+ case 0: // child: run cscope.
+ if (dup2(to_cs[0], STDIN_FILENO) == -1) {
PERROR("cs_create_connection 1");
- if (dup2(from_cs[1], STDOUT_FILENO) == -1)
+ }
+ if (dup2(from_cs[1], STDOUT_FILENO) == -1) {
PERROR("cs_create_connection 2");
- if (dup2(from_cs[1], STDERR_FILENO) == -1)
+ }
+ if (dup2(from_cs[1], STDERR_FILENO) == -1) {
PERROR("cs_create_connection 3");
+ }
- /* close unused */
+ // close unused
(void)close(to_cs[1]);
(void)close(from_cs[0]);
#else
@@ -735,14 +745,14 @@ err_closing:
return CSCOPE_FAILURE;
}
#endif
- /* expand the cscope exec for env var's */
+ // expand the cscope exec for env var's
prog = xmalloc(MAXPATHL + 1);
expand_env(p_csprg, (char_u *)prog, MAXPATHL);
- /* alloc space to hold the cscope command */
+ // alloc space to hold the cscope command
size_t len = strlen(prog) + strlen(csinfo[i].fname) + 32;
if (csinfo[i].ppath) {
- /* expand the prepend path for env var's */
+ // expand the prepend path for env var's
ppath = xmalloc(MAXPATHL + 1);
expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
@@ -754,12 +764,12 @@ err_closing:
cmd = xmalloc(len);
- /* run the cscope command; is there execl for non-unix systems? */
+ // run the cscope command; is there execl for non-unix systems?
#if defined(UNIX)
- (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
+ (void)snprintf(cmd, len, "exec %s -dl -f %s", prog, csinfo[i].fname);
#else
- /* WIN32 */
- (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
+ // WIN32
+ (void)snprintf(cmd, len, "%s -dl -f %s", prog, csinfo[i].fname);
#endif
if (csinfo[i].ppath != NULL) {
(void)strcat(cmd, " -P");
@@ -770,14 +780,14 @@ err_closing:
(void)strcat(cmd, csinfo[i].flags);
}
# ifdef UNIX
- /* on Win32 we still need prog */
+ // on Win32 we still need prog
xfree(prog);
# endif
xfree(ppath);
#if defined(UNIX)
# if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
- /* Change our process group to avoid cscope receiving SIGWINCH. */
+ // Change our process group to avoid cscope receiving SIGWINCH.
# if defined(HAVE_SETSID)
(void)setsid();
# else
@@ -789,18 +799,18 @@ err_closing:
PERROR(_("cs_create_connection exec failed"));
exit(127);
- /* NOTREACHED */
- default: /* parent. */
- /*
- * Save the file descriptors for later duplication, and
- * reopen as streams.
- */
- if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
+ // NOTREACHED
+ default: // parent.
+ // Save the file descriptors for later duplication, and
+ // reopen as streams.
+ if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL) {
PERROR(_("cs_create_connection: fdopen for to_fp failed"));
- if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL)
+ }
+ if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) {
PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
+ }
- /* close unused */
+ // close unused
(void)close(to_cs[0]);
(void)close(from_cs[1]);
@@ -808,11 +818,11 @@ err_closing:
}
#else
- /* WIN32 */
- /* Create a new process to run cscope and use pipes to talk with it */
+ // WIN32
+ // Create a new process to run cscope and use pipes to talk with it
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE; /* Hide child application window */
+ si.wShowWindow = SW_HIDE; // Hide child application window
si.hStdOutput = stdout_wr;
si.hStdError = stdout_wr;
si.hStdInput = stdin_rd;
@@ -826,7 +836,7 @@ err_closing:
(void)EMSG(_("E623: Could not spawn cscope process"));
goto err_closing;
}
- /* else */
+ // else
csinfo[i].pid = pi.dwProcessId;
csinfo[i].hProc = pi.hProcess;
CloseHandle(pi.hThread);
@@ -844,10 +854,10 @@ err_closing:
CloseHandle(stdin_rd);
CloseHandle(stdout_wr);
-#endif /* !UNIX */
+#endif // !UNIX
return CSCOPE_SUCCESS;
-} /* cs_create_connection */
+}
/// Query cscope using command line interface. Parse the output and use tselect
@@ -882,9 +892,9 @@ static int cs_find(exarg_T *eap)
if (NUL == eap->arg[i])
eap->arg[i] = ' ';
- return cs_find_common(opt, pat, eap->forceit, TRUE,
- eap->cmdidx == CMD_lcscope, *eap->cmdlinep);
-} /* cs_find */
+ return cs_find_common(opt, pat, eap->forceit, true,
+ eap->cmdidx == CMD_lcscope, *eap->cmdlinep);
+}
/// Common code for cscope find, shared by cs_find() and ex_cstag().
@@ -897,7 +907,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
char cmdletter;
char *qfpos;
- /* get cmd letter */
+ // get cmd letter
switch (opt[0]) {
case '0':
cmdletter = 's';
@@ -933,10 +943,10 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
qfpos = (char *)vim_strchr(p_csqf, cmdletter);
if (qfpos != NULL) {
qfpos++;
- /* next symbol must be + or - */
+ // next symbol must be + or -
if (strchr(CSQF_FLAGS, *qfpos) == NULL) {
char *nf = _("E469: invalid cscopequickfix flag %c for %c");
- /* strlen will be enough because we use chars */
+ // strlen will be enough because we use chars
char *buf = xmalloc(strlen(nf));
sprintf(buf, nf, *qfpos, *(qfpos-1));
@@ -954,23 +964,24 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
}
}
- /* create the actual command to send to cscope */
+ // create the actual command to send to cscope
cmd = cs_create_cmd(opt, pat);
if (cmd == NULL)
return FALSE;
nummatches = xmalloc(sizeof(int) * csinfo_size);
- /* Send query to all open connections, then count the total number
- * of matches so we can alloc all in one swell foop. */
- for (size_t i = 0; i < csinfo_size; i++)
+ // Send query to all open connections, then count the total number
+ // of matches so we can alloc all in one swell foop.
+ for (size_t i = 0; i < csinfo_size; i++) {
nummatches[i] = 0;
+ }
totmatches = 0;
for (size_t i = 0; i < csinfo_size; i++) {
if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL)
continue;
- /* send cmd to cscope */
+ // send cmd to cscope
(void)fprintf(csinfo[i].to_fp, "%s\n", cmd);
(void)fflush(csinfo[i].to_fp);
@@ -1014,8 +1025,9 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
} else {
cs_file_results(f, nummatches);
fclose(f);
- if (use_ll) /* Use location list */
+ if (use_ll) { // Use location list
wp = curwin;
+ }
// '-' starts a new error list
if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m",
*qfpos == '-', cmdline, NULL) > 0) {
@@ -1046,7 +1058,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
char **matches = NULL, **contexts = NULL;
size_t matched = 0;
- /* read output */
+ // read output
cs_fill_results((char *)pat, totmatches, nummatches, &matches,
&contexts, &matched);
xfree(nummatches);
@@ -1057,8 +1069,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
}
-
-} /* cs_find_common */
+}
/// Print help.
static int cs_help(exarg_T *eap)
@@ -1070,9 +1081,10 @@ static int cs_help(exarg_T *eap)
char *help = _(cmdp->help);
int space_cnt = 30 - vim_strsize((char_u *)help);
- /* Use %*s rather than %30s to ensure proper alignment in utf-8 */
- if (space_cnt < 0)
+ // Use %*s rather than %30s to ensure proper alignment in utf-8
+ if (space_cnt < 0) {
space_cnt = 0;
+ }
(void)smsg(_("%-5s: %s%*s (Usage: %s)"),
cmdp->name,
help, space_cnt, " ",
@@ -1094,7 +1106,7 @@ static int cs_help(exarg_T *eap)
wait_return(TRUE);
return CSCOPE_SUCCESS;
-} /* cs_help */
+}
static void clear_csinfo(size_t i)
@@ -1124,7 +1136,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
}
if (csinfo[j].fname == NULL && !empty_found) {
- i = j; /* remember first empty entry */
+ i = j; // remember first empty entry
empty_found = true;
}
}
@@ -1132,13 +1144,13 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
if (!empty_found) {
i = csinfo_size;
if (csinfo_size == 0) {
- /* First time allocation: allocate only 1 connection. It should
- * be enough for most users. If more is needed, csinfo will be
- * reallocated. */
+ // First time allocation: allocate only 1 connection. It should
+ // be enough for most users. If more is needed, csinfo will be
+ // reallocated.
csinfo_size = 1;
csinfo = xcalloc(1, sizeof(csinfo_T));
} else {
- /* Reallocate space for more connections. */
+ // Reallocate space for more connections.
csinfo_size *= 2;
csinfo = xrealloc(csinfo, sizeof(csinfo_T)*csinfo_size);
}
@@ -1165,7 +1177,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
os_fileinfo_id(file_info, &(csinfo[i].file_id));
assert(i <= INT_MAX);
return (int)i;
-} /* cs_insert_filelist */
+}
/// Find cscope command in command table.
@@ -1178,7 +1190,7 @@ static cscmd_T * cs_lookup_cmd(exarg_T *eap)
if (eap->arg == NULL)
return NULL;
- /* Store length of eap->arg before it gets modified by strtok(). */
+ // Store length of eap->arg before it gets modified by strtok().
eap_arg_len = (int)STRLEN(eap->arg);
if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
@@ -1190,7 +1202,7 @@ static cscmd_T * cs_lookup_cmd(exarg_T *eap)
return cmdp;
}
return NULL;
-} /* cs_lookup_cmd */
+}
/// Nuke em.
@@ -1247,13 +1259,13 @@ static int cs_kill(exarg_T *eap)
}
return CSCOPE_SUCCESS;
-} /* cs_kill */
+}
/// Actually kills a specific cscope connection.
static void cs_kill_execute(
- size_t i, /* cscope table index */
- char *cname /* cscope database name */
+ size_t i, // cscope table index
+ char *cname // cscope database name
)
{
if (p_csverbose) {
@@ -1284,17 +1296,16 @@ static void cs_kill_execute(
static char *cs_make_vim_style_matches(char *fname, char *slno, char *search,
char *tagstr)
{
- /* vim style is ctags:
- *
- * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
- *
- * but as mentioned above, we'll always use the line number and
- * put the search pattern (if one exists) as "extra"
- *
- * buf is used as part of vim's method of handling tags, and
- * (i think) vim frees it when you pop your tags and get replaced
- * by new ones on the tag stack.
- */
+ // vim style is ctags:
+ //
+ // <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
+ //
+ // but as mentioned above, we'll always use the line number and
+ // put the search pattern (if one exists) as "extra"
+ //
+ // buf is used as part of vim's method of handling tags, and
+ // (i think) vim frees it when you pop your tags and get replaced
+ // by new ones on the tag stack.
char *buf;
size_t amt;
@@ -1311,7 +1322,7 @@ static char *cs_make_vim_style_matches(char *fname, char *slno, char *search,
}
return buf;
-} /* cs_make_vim_style_matches */
+}
/// This is kind of hokey, but i don't see an easy way round this.
@@ -1381,7 +1392,7 @@ static char *cs_manage_matches(char **matches, char **contexts,
}
return p;
-} /* cs_manage_matches */
+}
/// Parse cscope output.
@@ -1408,7 +1419,7 @@ retry:
return NULL;
}
- /* If the line's too long for the buffer, discard it. */
+ // If the line's too long for the buffer, discard it.
if ((p = strchr(buf, '\n')) == NULL) {
while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n')
;
@@ -1427,15 +1438,15 @@ retry:
return NULL;
if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL)
return NULL;
- *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */
+ *search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0
- /* --- nvi ---
- * If the file is older than the cscope database, that is,
- * the database was built since the file was last modified,
- * or there wasn't a search string, use the line number.
- */
- if (strcmp(*search, "<unknown>") == 0)
+ // --- nvi ---
+ // If the file is older than the cscope database, that is,
+ // the database was built since the file was last modified,
+ // or there wasn't a search string, use the line number.
+ if (strcmp(*search, "<unknown>") == 0) {
*search = NULL;
+ }
name = cs_resolve_file(cnumber, name);
return name;
@@ -1474,11 +1485,10 @@ static void cs_file_results(FILE *f, int *nummatches_a)
xfree(context);
xfree(fullname);
- } /* for all matches */
+ } // for all matches
(void)cs_read_prompt(i);
-
- } /* for all cscope connections */
+ } // for all cscope connections
xfree(buf);
}
@@ -1539,10 +1549,10 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
*cntxts_p = cntxts;
xfree(buf);
-} // cs_fill_results
+}
-/* get the requested path components */
+// get the requested path components
static char *cs_pathcomponents(char *path)
{
if (p_cspc == 0) {
@@ -1688,7 +1698,7 @@ static int cs_read_prompt(size_t i)
static char *eprompt = "Press the RETURN key to continue:";
size_t epromptlen = strlen(eprompt);
- /* compute maximum allowed len for Cscope error message */
+ // compute maximum allowed len for Cscope error message
assert(IOSIZE >= cs_emsg_len);
size_t maxlen = IOSIZE - cs_emsg_len;
@@ -1738,11 +1748,12 @@ static int cs_read_prompt(size_t i)
}
if (ch == EOF) {
PERROR("cs_read_prompt EOF");
- if (buf != NULL && buf[0] != NUL)
+ if (buf != NULL && buf[0] != NUL) {
(void)EMSG2(cs_emsg, buf);
- else if (p_csverbose)
- cs_reading_emsg(i); /* don't have additional information */
- cs_release_csp(i, TRUE);
+ } else if (p_csverbose) {
+ cs_reading_emsg(i); // don't have additional information
+ }
+ cs_release_csp(i, true);
xfree(buf);
return CSCOPE_FAILURE;
}
@@ -1753,9 +1764,10 @@ static int cs_read_prompt(size_t i)
}
}
- if (ch == EOF)
- continue; /* didn't find the prompt */
- break; /* did find the prompt */
+ if (ch == EOF) {
+ continue; // didn't find the prompt
+ }
+ break; // did find the prompt
}
xfree(buf);
@@ -1766,8 +1778,9 @@ static int cs_read_prompt(size_t i)
/*
* Used to catch and ignore SIGALRM below.
*/
-static void sig_handler(int s) {
- /* do nothing */
+static void sig_handler(int s)
+{
+ // do nothing
return;
}
@@ -1775,7 +1788,7 @@ static void sig_handler(int s) {
/// Does the actual free'ing for the cs ptr with an optional flag of whether
/// or not to free the filename. Called by cs_kill and cs_reset.
-static void cs_release_csp(size_t i, int freefnpp)
+static void cs_release_csp(size_t i, bool freefnpp)
{
// Trying to exit normally (not sure whether it is fit to Unix cscope)
if (csinfo[i].to_fp != NULL) {
@@ -1791,7 +1804,7 @@ static void cs_release_csp(size_t i, int freefnpp)
# if defined(HAVE_SIGACTION)
struct sigaction sa, old;
- /* Use sigaction() to limit the waiting time to two seconds. */
+ // Use sigaction() to limit the waiting time to two seconds.
sigemptyset(&sa.sa_mask);
sa.sa_handler = sig_handler;
# ifdef SA_NODEFER
@@ -1800,27 +1813,28 @@ static void cs_release_csp(size_t i, int freefnpp)
sa.sa_flags = 0;
# endif
sigaction(SIGALRM, &sa, &old);
- alarm(2); /* 2 sec timeout */
+ alarm(2); // 2 sec timeout
- /* Block until cscope exits or until timer expires */
+ // Block until cscope exits or until timer expires
pid = waitpid(csinfo[i].pid, &pstat, 0);
waitpid_errno = errno;
- /* cancel pending alarm if still there and restore signal */
+ // cancel pending alarm if still there and restore signal
alarm(0);
sigaction(SIGALRM, &old, NULL);
# else
int waited;
- /* Can't use sigaction(), loop for two seconds. First yield the CPU
- * to give cscope a chance to exit quickly. */
+ // Can't use sigaction(), loop for two seconds. First yield the CPU
+ // to give cscope a chance to exit quickly.
sleep(0);
for (waited = 0; waited < 40; ++waited) {
pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
waitpid_errno = errno;
- if (pid != 0)
- break; /* break unless the process is still running */
- os_delay(50L, false); /* sleep 50 ms */
+ if (pid != 0) {
+ break; // break unless the process is still running
+ }
+ os_delay(50L, false); // sleep 50 ms
}
# endif
/*
@@ -1830,7 +1844,7 @@ static void cs_release_csp(size_t i, int freefnpp)
*/
if (pid < 0 && csinfo[i].pid > 1) {
# ifdef ECHILD
- int alive = TRUE;
+ bool alive = true;
if (waitpid_errno == ECHILD) {
/*
@@ -1845,13 +1859,13 @@ static void cs_release_csp(size_t i, int freefnpp)
int waited;
sleep(0);
- for (waited = 0; waited < 40; ++waited) {
- /* Check whether cscope process is still alive */
+ for (waited = 0; waited < 40; waited++) {
+ // Check whether cscope process is still alive
if (kill(csinfo[i].pid, 0) != 0) {
- alive = FALSE; /* cscope process no longer exists */
+ alive = false; // cscope process no longer exists
break;
}
- os_delay(50L, false); /* sleep 50ms */
+ os_delay(50L, false); // sleep 50ms
}
}
if (alive)
@@ -1862,11 +1876,12 @@ static void cs_release_csp(size_t i, int freefnpp)
}
}
}
-#else /* !UNIX */
+#else // !UNIX
if (csinfo[i].hProc != NULL) {
- /* Give cscope a chance to exit normally */
- if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT)
+ // Give cscope a chance to exit normally
+ if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) {
TerminateProcess(csinfo[i].hProc, 0);
+ }
CloseHandle(csinfo[i].hProc);
}
#endif
@@ -1883,7 +1898,7 @@ static void cs_release_csp(size_t i, int freefnpp)
}
clear_csinfo(i);
-} /* cs_release_csp */
+}
/// Calls cs_kill on all cscope connections then reinits.
@@ -1895,7 +1910,7 @@ static int cs_reset(exarg_T *eap)
if (csinfo_size == 0)
return CSCOPE_SUCCESS;
- /* malloc our db and ppath list */
+ // malloc our db and ppath list
dblist = xmalloc(csinfo_size * sizeof(char *));
pplist = xmalloc(csinfo_size * sizeof(char *));
fllist = xmalloc(csinfo_size * sizeof(char *));
@@ -1908,15 +1923,14 @@ static int cs_reset(exarg_T *eap)
cs_release_csp(i, FALSE);
}
- /* rebuild the cscope connection list */
+ // rebuild the cscope connection list
for (size_t i = 0; i < csinfo_size; i++) {
if (dblist[i] != NULL) {
cs_add_common(dblist[i], pplist[i], fllist[i]);
if (p_csverbose) {
- /* don't use smsg_attr() because we want to display the
- * connection number in the same line as
- * "Added cscope database..."
- */
+ // don't use smsg_attr() because we want to display the
+ // connection number in the same line as
+ // "Added cscope database..."
snprintf(buf, ARRAY_SIZE(buf), " (#%zu)", i);
MSG_PUTS_ATTR(buf, HL_ATTR(HLF_R));
}
@@ -1933,7 +1947,7 @@ static int cs_reset(exarg_T *eap)
msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST);
}
return CSCOPE_SUCCESS;
-} /* cs_reset */
+}
/// Construct the full pathname to a file found in the cscope database.
@@ -1954,11 +1968,11 @@ static char *cs_resolve_file(size_t i, char *name)
* copied into the tag buffer used by Vim.
*/
size_t len = strlen(name) + 2;
- if (csinfo[i].ppath != NULL)
+ if (csinfo[i].ppath != NULL) {
len += strlen(csinfo[i].ppath);
- else if (p_csre && csinfo[i].fname != NULL) {
- /* If 'cscoperelative' is set and ppath is not set, use cscope.out
- * path in path resolution. */
+ } else if (p_csre && csinfo[i].fname != NULL) {
+ // If 'cscoperelative' is set and ppath is not set, use cscope.out
+ // path in path resolution.
csdir = xmalloc(MAXPATHL);
STRLCPY(csdir, csinfo[i].fname,
path_tail((char_u *)csinfo[i].fname)
@@ -1966,9 +1980,9 @@ static char *cs_resolve_file(size_t i, char *name)
len += STRLEN(csdir);
}
- /* Note/example: this won't work if the cscope output already starts
- * "../.." and the prefix path is also "../..". if something like this
- * happens, you are screwed up and need to fix how you're using cscope. */
+ // Note/example: this won't work if the cscope output already starts
+ // "../.." and the prefix path is also "../..". if something like this
+ // happens, you are screwed up and need to fix how you're using cscope.
if (csinfo[i].ppath != NULL
&& (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0)
&& (name[0] != '/')
@@ -1976,9 +1990,9 @@ static char *cs_resolve_file(size_t i, char *name)
fullname = xmalloc(len);
(void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
} else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) {
- /* Check for csdir to be non empty to avoid empty path concatenated to
- * cscope output. */
- fullname = concat_fnames((char *)csdir, name, TRUE);
+ // Check for csdir to be non empty to avoid empty path concatenated to
+ // cscope output.
+ fullname = concat_fnames((char *)csdir, name, true);
} else {
fullname = xstrdup(name);
}
@@ -2013,7 +2027,7 @@ static int cs_show(exarg_T *eap)
wait_return(TRUE);
return CSCOPE_SUCCESS;
-} /* cs_show */
+}
/// Only called when VIM exits to quit any cscope sessions.
@@ -2025,4 +2039,4 @@ void cs_end(void)
csinfo_size = 0;
}
-/* the end */
+// the end