diff options
Diffstat (limited to 'src/nvim/hardcopy.c')
-rw-r--r-- | src/nvim/hardcopy.c | 201 |
1 files changed, 94 insertions, 107 deletions
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 99e0bff81c..a6cbfa7a72 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -263,7 +263,7 @@ struct prt_resfile_buffer_S { * Parse 'printoptions' and set the flags in "printer_opts". * Returns an error message or NULL; */ -char_u *parse_printoptions(void) +char *parse_printoptions(void) { return parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS); } @@ -272,7 +272,7 @@ char_u *parse_printoptions(void) * Parse 'printoptions' and set the flags in "printer_opts". * Returns an error message or NULL; */ -char_u *parse_printmbfont(void) +char *parse_printmbfont(void) { return parse_list_options(p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS); } @@ -286,10 +286,10 @@ char_u *parse_printmbfont(void) * Returns an error message for an illegal option, NULL otherwise. * Only used for the printer at the moment... */ -static char_u *parse_list_options(char_u *option_str, option_table_T *table, size_t table_size) +static char *parse_list_options(char_u *option_str, option_table_T *table, size_t table_size) { option_table_T *old_opts; - char_u *ret = NULL; + char *ret = NULL; char_u *stringp; char_u *colonp; char_u *commap; @@ -312,7 +312,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, siz while (*stringp) { colonp = vim_strchr(stringp, ':'); if (colonp == NULL) { - ret = (char_u *)N_("E550: Missing colon"); + ret = N_("E550: Missing colon"); break; } commap = vim_strchr(stringp, ','); @@ -329,7 +329,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, siz } if (idx == table_size) { - ret = (char_u *)N_("E551: Illegal component"); + ret = N_("E551: Illegal component"); break; } @@ -338,7 +338,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, siz if (table[idx].hasnum) { if (!ascii_isdigit(*p)) { - ret = (char_u *)N_("E552: digit expected"); + ret = N_("E552: digit expected"); break; } @@ -621,12 +621,12 @@ void ex_hardcopy(exarg_T *eap) settings.has_color = TRUE; if (*eap->arg == '>') { - char_u *errormsg = NULL; + char *errormsg = NULL; // Expand things like "%.ps". if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) { if (errormsg != NULL) { - EMSG(errormsg); + emsg(errormsg); } return; } @@ -684,7 +684,7 @@ void ex_hardcopy(exarg_T *eap) bytes_to_print += STRLEN(skipwhite(ml_get(lnum))); } if (bytes_to_print == 0) { - MSG(_("No text to be printed")); + msg(_("No text to be printed")); goto print_fail_no_begin; } @@ -794,8 +794,8 @@ void ex_hardcopy(exarg_T *eap) break; // reached the end } } else if (prtpos.ff) { - /* Line had a formfeed in it - start new page but - * stay on the current line */ + // Line had a formfeed in it - start new page but + // stay on the current line break; } } @@ -1329,7 +1329,7 @@ static void prt_write_file_raw_len(char_u *buffer, size_t bytes) { if (!prt_file_error && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd) != bytes) { - EMSG(_("E455: Error writing to PostScript output file")); + emsg(_("E455: Error writing to PostScript output file")); prt_file_error = TRUE; } } @@ -1505,9 +1505,8 @@ static void prt_flush_buffer(void) prt_write_real(b / 255.0, 3); prt_write_string("bg\n"); } - /* Draw underlines before the text as it makes it slightly easier to - * find the starting point. - */ + // Draw underlines before the text as it makes it slightly easier to + // find the starting point. if (prt_do_underline) { if (prt_do_moveto) { prt_write_real(prt_pos_x_moveto, 2); @@ -1696,9 +1695,8 @@ static bool prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) 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. - */ +/// 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 bool prt_open_resource(struct prt_ps_resource_S *resource) FUNC_ATTR_NONNULL_ALL { @@ -1706,7 +1704,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) FILE *fd_resource = os_fopen((char *)resource->filename, READBIN); if (fd_resource == NULL) { - EMSG2(_("E624: Can't open file \"%s\""), resource->filename); + semsg(_("E624: Can't open file \"%s\""), resource->filename); return false; } memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); @@ -1715,7 +1713,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) 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\""), + semsg(_("E457: Can't read PostScript resource file \"%s\""), resource->filename); fclose(fd_resource); return false; @@ -1731,7 +1729,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) if (prt_resfile_strncmp(offset, PRT_RESOURCE_HEADER, (int)STRLEN(PRT_RESOURCE_HEADER)) != 0) { - EMSG2(_("E618: file \"%s\" is not a PostScript resource file"), + semsg(_("E618: file \"%s\" is not a PostScript resource file"), resource->filename); return false; } @@ -1748,7 +1746,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) } 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"), + semsg(_("E619: file \"%s\" is not a supported PostScript resource file"), resource->filename); return false; } @@ -1765,7 +1763,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) (int)STRLEN(PRT_RESOURCE_CMAP)) == 0) { resource->type = PRT_RESOURCE_TYPE_CMAP; } else { - EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), + semsg(_("E619: file \"%s\" is not a supported PostScript resource file"), resource->filename); return false; } @@ -1806,7 +1804,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource) } if (!seen_title || !seen_version) { - EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"), + semsg(_("E619: file \"%s\" is not a supported PostScript resource file"), resource->filename); return false; } @@ -1819,7 +1817,7 @@ static bool prt_check_resource(const struct prt_ps_resource_S *resource, const c { // 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"), + semsg(_("E621: \"%s\" resource file has wrong version"), resource->name); return false; } @@ -1906,9 +1904,8 @@ static void prt_dsc_font_resource(char *resource, struct prt_ps_font_S *ps_font) static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, int num_copies) { - /* Only output the comment if we need to. - * Note: tumble is ignored if we are not duplexing - */ + // Only output the comment if we need to. + // Note: tumble is ignored if we are not duplexing if (!(duplex || collate || color || (num_copies > 1))) { return; } @@ -1967,10 +1964,9 @@ void mch_print_cleanup(void) if (prt_out_mbyte) { int i; - /* Free off all CID font names created, but first clear duplicate - * pointers to the same string (when the same font is used for more than - * one style). - */ + // Free off all CID font names created, but first clear duplicate + // pointers to the same string (when the same font is used for more than + // one style). for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) { xfree(prt_ps_mb_font.ps_fontname[i]); @@ -2048,9 +2044,8 @@ static int prt_get_cpl(void) { if (prt_use_number()) { prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; - /* If we are outputting multi-byte characters then line numbers will be - * printed with half width characters - */ + // If we are outputting multi-byte characters then line numbers will be + // printed with half width characters if (prt_out_mbyte) { prt_number_width /= 2; } @@ -2168,10 +2163,10 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) p_encoding = enc_skip(p_enc); } - /* Look for a multi-byte font that matches the encoding and character set. - * Only look if multi-byte character set is defined, or using multi-byte - * encoding other than Unicode. This is because a Unicode encoding does not - * uniquely identify a CJK character set to use. */ + // Look for a multi-byte font that matches the encoding and character set. + // Only look if multi-byte character set is defined, or using multi-byte + // encoding other than Unicode. This is because a Unicode encoding does not + // uniquely identify a CJK character set to use. p_mbenc = NULL; props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) { @@ -2208,7 +2203,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) if (!prt_custom_cmap) { // 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.")); + emsg(_("E673: Incompatible multi-byte encoding and character set.")); return FALSE; } @@ -2220,7 +2215,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) } else { // Add custom CMap character set name if (*p_pmcs == NUL) { - EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); + emsg(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); return FALSE; } STRLCPY(prt_cmap, p_pmcs, sizeof(prt_cmap) - 2); @@ -2236,7 +2231,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) STRCAT(prt_cmap, "H"); if (!mbfont_opts[OPT_MBFONT_REGULAR].present) { - EMSG(_("E675: No default font specified for multi-byte printing.")); + emsg(_("E675: No default font specified for multi-byte printing.")); return FALSE; } @@ -2399,7 +2394,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) if (psettings->outfile == NULL) { prt_ps_file_name = vim_tempname(); if (prt_ps_file_name == NULL) { - EMSG(_(e_notmp)); + emsg(_(e_notmp)); return FAIL; } prt_ps_fd = os_fopen((char *)prt_ps_file_name, WRITEBIN); @@ -2411,7 +2406,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) } } if (prt_ps_fd == NULL) { - EMSG(_("E324: Can't open PostScript output file")); + emsg(_("E324: Can't open PostScript output file")); mch_print_cleanup(); return FAIL; } @@ -2438,13 +2433,13 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) static int prt_add_resource(struct prt_ps_resource_S *resource) { - FILE * fd_resource; + FILE *fd_resource; char_u resource_buffer[512]; size_t bytes_read; fd_resource = os_fopen((char *)resource->filename, READBIN); if (fd_resource == NULL) { - EMSG2(_("E456: Can't open file \"%s\""), resource->filename); + semsg(_("E456: Can't open file \"%s\""), resource->filename); return FALSE; } switch (resource->type) { @@ -2464,7 +2459,7 @@ static int prt_add_resource(struct prt_ps_resource_S *resource) bytes_read = fread((char *)resource_buffer, sizeof(char_u), sizeof(resource_buffer), fd_resource); if (ferror(fd_resource)) { - EMSG2(_("E457: Can't read PostScript resource file \"%s\""), + semsg(_("E457: Can't read PostScript resource file \"%s\""), resource->filename); fclose(fd_resource); return FALSE; @@ -2526,28 +2521,26 @@ int mch_print_begin(prt_settings_T *psettings) prt_dsc_textline("Orientation", "Portrait"); prt_dsc_atend("Pages"); prt_dsc_textline("PageOrder", "Ascend"); - /* The bbox does not change with orientation - it is always in the default - * user coordinate system! We have to recalculate right and bottom - * coordinates based on the font metrics for the bbox to be accurate. */ + // The bbox does not change with orientation - it is always in the default + // user coordinate system! We have to recalculate right and bottom + // coordinates based on the font metrics for the bbox to be accurate. prt_page_margins(prt_mediasize[prt_media].width, prt_mediasize[prt_media].height, &left, &right, &top, &bottom); bbox[0] = (int)left; if (prt_portrait) { - /* In portrait printing the fixed point is the top left corner so we - * derive the bbox from that point. We have the expected cpl chars - * across the media and lpp lines down the media. - */ + // In portrait printing the fixed point is the top left corner so we + // derive the bbox from that point. We have the expected cpl chars + // across the media and lpp lines down the media. bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) * prt_line_height); bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width + 0.5); bbox[3] = (int)(top + 0.5); } else { - /* In landscape printing the fixed point is the bottom left corner so we - * derive the bbox from that point. We have lpp chars across the media - * and cpl lines up the media. - */ + // In landscape printing the fixed point is the bottom left corner so we + // derive the bbox from that point. We have lpp chars across the media + // and cpl lines up the media. bbox[1] = (int)bottom; bbox[2] = (int)(left + ((psettings->lines_per_page + prt_header_height()) * prt_line_height) + 0.5); @@ -2574,7 +2567,7 @@ int mch_print_begin(prt_settings_T *psettings) // Search for external resources VIM supplies if (!prt_find_resource("prolog", &res_prolog)) { - EMSG(_("E456: Can't find PostScript resource file \"prolog.ps\"")); + emsg(_("E456: Can't find PostScript resource file \"prolog.ps\"")); return FALSE; } if (!prt_open_resource(&res_prolog)) { @@ -2586,7 +2579,7 @@ int mch_print_begin(prt_settings_T *psettings) if (prt_out_mbyte) { // 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\"")); + emsg(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); return FALSE; } if (!prt_open_resource(&res_cidfont)) { @@ -2597,11 +2590,10 @@ int mch_print_begin(prt_settings_T *psettings) } } - /* Find an encoding to use for printing. - * Check 'printencoding'. If not set or not found, then use 'encoding'. If - * that cannot be found then default to "latin1". - * Note: VIM specific encoding header is always skipped. - */ + // Find an encoding to use for printing. + // Check 'printencoding'. If not set or not found, then use 'encoding'. If + // that cannot be found then default to "latin1". + // Note: VIM specific encoding header is always skipped. if (!prt_out_mbyte) { p_encoding = enc_skip(p_penc); if (*p_encoding == NUL @@ -2617,7 +2609,7 @@ int mch_print_begin(prt_settings_T *psettings) // 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\""), + semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), p_encoding); return FALSE; } @@ -2626,8 +2618,8 @@ int mch_print_begin(prt_settings_T *psettings) if (!prt_open_resource(&res_encoding)) { return FALSE; } - /* For the moment there are no checks on encoding resource files to - * perform */ + // For the moment there are no checks on encoding resource files to + // perform } else { p_encoding = enc_skip(p_penc); if (*p_encoding == NUL) { @@ -2636,15 +2628,15 @@ int mch_print_begin(prt_settings_T *psettings) if (prt_use_courier) { // Include ASCII range encoding vector if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) { - EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), + semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), prt_ascii_encoding); return FALSE; } if (!prt_open_resource(&res_encoding)) { return FALSE; } - /* For the moment there are no checks on encoding resource files to - * perform */ + // For the moment there are no checks on encoding resource files to + // perform } } @@ -2652,7 +2644,7 @@ int mch_print_begin(prt_settings_T *psettings) if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { // Set up encoding conversion if required if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) { - emsgf(_("E620: Unable to convert to print encoding \"%s\""), + semsg(_("E620: Unable to convert to print encoding \"%s\""), p_encoding); return false; } @@ -2662,7 +2654,7 @@ int mch_print_begin(prt_settings_T *psettings) if (prt_out_mbyte && prt_custom_cmap) { // Find user supplied CMap if (!prt_find_resource(prt_cmap, &res_cmap)) { - EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""), + semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), prt_cmap); return FALSE; } @@ -2696,8 +2688,8 @@ int mch_print_begin(prt_settings_T *psettings) prt_dsc_resources(NULL, "encoding", buffer); } prt_dsc_requirements(prt_duplex, prt_tumble, prt_collate, - psettings->do_syntax - , prt_num_copies); + psettings->do_syntax, + prt_num_copies); prt_dsc_noarg("EndComments"); /* @@ -2742,8 +2734,8 @@ int mch_print_begin(prt_settings_T *psettings) } if (!prt_out_mbyte || prt_use_courier) { - /* There will be only one Roman font encoding to be included in the PS - * file. */ + // There will be only one Roman font encoding to be included in the PS + // file. if (!prt_add_resource(&res_encoding)) { return FALSE; } @@ -2771,8 +2763,8 @@ int mch_print_begin(prt_settings_T *psettings) // 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. */ + // When using Courier for ASCII range when printing multi-byte, need to + // pick up ASCII encoding to use with it. if (prt_use_courier) { p_encoding = (char_u *)prt_ascii_encoding; } @@ -2794,12 +2786,11 @@ int mch_print_begin(prt_settings_T *psettings) prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); } if (prt_out_mbyte) { - /* Define the CID fonts to be used in the job. Typically CJKV fonts do - * not have an italic form being a western style, so where no font is - * defined for these faces VIM falls back to an existing face. - * Note: if using Courier for the ASCII range then the printout will - * have bold/italic/bolditalic regardless of the setting of printmbfont. - */ + // Define the CID fonts to be used in the job. Typically CJKV fonts do + // not have an italic form being a western style, so where no font is + // defined for these faces VIM falls back to an existing face. + // Note: if using Courier for the ASCII range then the printout will + // have bold/italic/bolditalic regardless of the setting of printmbfont. prt_dsc_resources("IncludeResource", "font", prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); if (!prt_custom_cmap) { @@ -2872,8 +2863,8 @@ void mch_print_end(prt_settings_T *psettings) prt_dsc_noarg("EOF"); - /* Write CTRL-D to close serial communication link if used. - * NOTHING MUST BE WRITTEN AFTER THIS! */ + // Write CTRL-D to close serial communication link if used. + // NOTHING MUST BE WRITTEN AFTER THIS! prt_write_file((char_u *)"\004"); if (!prt_file_error && psettings->outfile == NULL @@ -2888,7 +2879,7 @@ void mch_print_end(prt_settings_T *psettings) // Not printing to a file: use 'printexpr' to print the file. if (eval_printexpr((char *)prt_ps_file_name, (char *)psettings->arguments) == FAIL) { - EMSG(_("E365: Failed to print PostScript file")); + emsg(_("E365: Failed to print PostScript file")); } else { prt_message((char_u *)_("Print job sent.")); } @@ -2977,13 +2968,12 @@ int mch_print_text_out(char_u *const textp, size_t len) char_u *tofree = NULL; double char_width = prt_char_width; - /* Ideally VIM would create a rearranged CID font to combine a Roman and - * CJKV font to do what VIM is doing here - use a Roman font for characters - * in the ASCII range, and the original CID font for everything else. - * The problem is that GhostScript still (as of 8.13) does not support - * rearranged fonts even though they have been documented by Adobe for 7 - * years! If they ever do, a lot of this code will disappear. - */ + // Ideally VIM would create a rearranged CID font to combine a Roman and + // CJKV font to do what VIM is doing here - use a Roman font for characters + // in the ASCII range, and the original CID font for everything else. + // The problem is that GhostScript still (as of 8.13) does not support + // rearranged fonts even though they have been documented by Adobe for 7 + // years! If they ever do, a lot of this code will disappear. if (prt_use_courier) { const bool in_ascii = (len == 1 && *p < 0x80); if (prt_in_ascii) { @@ -3020,9 +3010,8 @@ int mch_print_text_out(char_u *const textp, size_t len) } } - /* Output any required changes to the graphics state, after flushing any - * text buffered so far. - */ + // Output any required changes to the graphics state, after flushing any + // text buffered so far. if (prt_attribute_change) { prt_flush_buffer(); // Reset count of number of chars that will be printed @@ -3100,16 +3089,14 @@ int mch_print_text_out(char_u *const textp, size_t len) p++; } } else { - /* Add next character to buffer of characters to output. - * Note: One printed character may require several PS characters to - * represent it, but we only count them as one printed character. - */ + // Add next character to buffer of characters to output. + // Note: One printed character may require several PS characters to + // represent it, but we only count them as one printed character. ch = *p; if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') { - /* Convert non-printing characters to either their escape or octal - * sequence, ensures PS sent over a serial line does not interfere - * with the comms protocol. - */ + // Convert non-printing characters to either their escape or octal + // sequence, ensures PS sent over a serial line does not interfere + // with the comms protocol. ga_append(&prt_ps_buffer, '\\'); switch (ch) { case BS: |