aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/hardcopy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/hardcopy.c')
-rw-r--r--src/nvim/hardcopy.c192
1 files changed, 90 insertions, 102 deletions
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index d7f7b8eb92..602fa8b71d 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -10,19 +10,16 @@
#include <string.h>
#include "nvim/ascii.h"
-#include "nvim/vim.h"
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
-#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/fileio.h"
#include "nvim/garray.h"
+#include "nvim/grid.h"
#include "nvim/hardcopy.h"
#include "nvim/highlight_group.h"
+#include "nvim/indent.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@@ -31,11 +28,13 @@
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/path.h"
-#include "nvim/screen.h"
+#include "nvim/runtime.h"
+#include "nvim/statusline.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/ui.h"
#include "nvim/version.h"
+#include "nvim/vim.h"
/*
* To implement printing on a platform, the following functions must be
@@ -49,20 +48,20 @@
*
* int mch_print_begin(prt_settings_T *settings)
* Called to start the print job.
- * Return FALSE to abort.
+ * Return false to abort.
*
* int mch_print_begin_page(char_u *msg)
* Called at the start of each page.
* "msg" indicates the progress of the print job, can be NULL.
- * Return FALSE to abort.
+ * Return false to abort.
*
* int mch_print_end_page()
* Called at the end of each page.
- * Return FALSE to abort.
+ * Return false to abort.
*
* int mch_print_blank_page()
* Called to generate a blank page for collated, duplex, multiple copy
- * document. Return FALSE to abort.
+ * document. Return false to abort.
*
* void mch_print_end(prt_settings_T *psettings)
* Called at normal end of print job.
@@ -85,36 +84,33 @@
*
* mch_print_start_line(int margin, int page_line)
* Sets the current position at the start of line "page_line".
- * If margin is TRUE start in the left margin (for header and line number).
+ * If margin is true start in the left margin (for header and line number).
*
* int mch_print_text_out(char_u *p, size_t len);
* Output one character of text p[len] at the current position.
- * Return TRUE if there is no room for another character in the same line.
+ * Return true if there is no room for another character in the same line.
*
* Note that the generic code has no idea of margins. The machine code should
* simply make the page look smaller! The header and the line numbers are
* printed in the margin.
*/
-static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS]
- =
- {
- { "top", TRUE, 0, NULL, 0, FALSE },
- { "bottom", TRUE, 0, NULL, 0, FALSE },
- { "left", TRUE, 0, NULL, 0, FALSE },
- { "right", TRUE, 0, NULL, 0, FALSE },
- { "header", TRUE, 0, NULL, 0, FALSE },
- { "syntax", FALSE, 0, NULL, 0, FALSE },
- { "number", FALSE, 0, NULL, 0, FALSE },
- { "wrap", FALSE, 0, NULL, 0, FALSE },
- { "duplex", FALSE, 0, NULL, 0, FALSE },
- { "portrait", FALSE, 0, NULL, 0, FALSE },
- { "paper", FALSE, 0, NULL, 0, FALSE },
- { "collate", FALSE, 0, NULL, 0, FALSE },
- { "jobsplit", FALSE, 0, NULL, 0, FALSE },
- { "formfeed", FALSE, 0, NULL, 0, FALSE },
- }
-;
+static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] = {
+ { "top", true, 0, NULL, 0, false },
+ { "bottom", true, 0, NULL, 0, false },
+ { "left", true, 0, NULL, 0, false },
+ { "right", true, 0, NULL, 0, false },
+ { "header", true, 0, NULL, 0, false },
+ { "syntax", false, 0, NULL, 0, false },
+ { "number", false, 0, NULL, 0, false },
+ { "wrap", false, 0, NULL, 0, false },
+ { "duplex", false, 0, NULL, 0, false },
+ { "portrait", false, 0, NULL, 0, false },
+ { "paper", false, 0, NULL, 0, false },
+ { "collate", false, 0, NULL, 0, false },
+ { "jobsplit", false, 0, NULL, 0, false },
+ { "formfeed", false, 0, NULL, 0, false },
+};
static const uint32_t cterm_color_8[8] = {
0x000000, 0xff0000, 0x00ff00, 0xffff00,
@@ -150,12 +146,12 @@ static int page_count;
static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] =
{
- { "c", FALSE, 0, NULL, 0, FALSE },
- { "a", FALSE, 0, NULL, 0, FALSE },
- { "r", FALSE, 0, NULL, 0, FALSE },
- { "b", FALSE, 0, NULL, 0, FALSE },
- { "i", FALSE, 0, NULL, 0, FALSE },
- { "o", FALSE, 0, NULL, 0, FALSE },
+ { "c", false, 0, NULL, 0, false },
+ { "a", false, 0, NULL, 0, false },
+ { "r", false, 0, NULL, 0, false },
+ { "b", false, 0, NULL, 0, false },
+ { "i", false, 0, NULL, 0, false },
+ { "o", false, 0, NULL, 0, false },
};
/*
@@ -265,7 +261,7 @@ struct prt_resfile_buffer_S {
*/
char *parse_printoptions(void)
{
- return parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
+ return parse_list_options((char_u *)p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
}
/*
@@ -274,7 +270,7 @@ char *parse_printoptions(void)
*/
char *parse_printmbfont(void)
{
- return parse_list_options(p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS);
+ return parse_list_options((char_u *)p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS);
}
/*
@@ -292,8 +288,8 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_
char *ret = NULL;
char_u *stringp;
char_u *colonp;
- char_u *commap;
- char_u *p;
+ char *commap;
+ char *p;
size_t idx = 0; // init for GCC
int len;
@@ -315,14 +311,14 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_
ret = N_("E550: Missing colon");
break;
}
- commap = (char_u *)vim_strchr((char *)stringp, ',');
+ commap = vim_strchr((char *)stringp, ',');
if (commap == NULL) {
- commap = option_str + STRLEN(option_str);
+ commap = (char *)option_str + STRLEN(option_str);
}
len = (int)(colonp - stringp);
- for (idx = 0; idx < table_size; ++idx) {
+ for (idx = 0; idx < table_size; idx++) {
if (STRNICMP(stringp, table[idx].name, len) == 0) {
break;
}
@@ -333,8 +329,8 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_
break;
}
- p = colonp + 1;
- table[idx].present = TRUE;
+ p = (char *)colonp + 1;
+ table[idx].present = true;
if (table[idx].hasnum) {
if (!ascii_isdigit(*p)) {
@@ -342,15 +338,15 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_
break;
}
- table[idx].number = getdigits_int((char **)&p, false, 0);
+ table[idx].number = getdigits_int(&p, false, 0);
}
- table[idx].string = p;
+ table[idx].string = (char_u *)p;
table[idx].strlen = (int)(commap - p);
- stringp = commap;
+ stringp = (char_u *)commap;
if (*stringp == ',') {
- ++stringp;
+ stringp++;
}
}
@@ -504,9 +500,7 @@ int prt_header_height(void)
return 2;
}
-/*
- * Return TRUE if using a line number for printing.
- */
+// Return true if using a line number for printing.
int prt_use_number(void)
{
return printer_opts[OPT_PRINT_NUMBER].present
@@ -524,7 +518,7 @@ int prt_get_unit(int idx)
static char *(units[4]) = PRT_UNIT_NAMES;
if (printer_opts[idx].present) {
- for (i = 0; i < 4; ++i) {
+ for (i = 0; i < 4; i++) {
if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0) {
u = i;
break;
@@ -550,7 +544,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const
if (*p_header != NUL) {
linenr_T tmp_lnum, tmp_topline, tmp_botline;
- int use_sandbox = FALSE;
+ int use_sandbox = false;
/*
* Need to (temporarily) set current line number and first/last line
@@ -619,7 +613,7 @@ static void prt_message(char_u *s)
{
// TODO(bfredl): delete this
grid_fill(&default_grid, Rows - 1, Rows, 0, Columns, ' ', ' ', 0);
- grid_puts(&default_grid, s, Rows - 1, 0, HL_ATTR(HLF_R));
+ grid_puts(&default_grid, (char *)s, Rows - 1, 0, HL_ATTR(HLF_R));
ui_flush();
}
@@ -632,8 +626,8 @@ void ex_hardcopy(exarg_T *eap)
int page_line;
int jobsplit;
- memset(&settings, 0, sizeof(prt_settings_T));
- settings.has_color = TRUE;
+ CLEAR_FIELD(settings);
+ settings.has_color = true;
if (*eap->arg == '>') {
char *errormsg = NULL;
@@ -667,7 +661,7 @@ void ex_hardcopy(exarg_T *eap)
settings.modec = 'c';
if (!syntax_present(curwin)) {
- settings.do_syntax = FALSE;
+ settings.do_syntax = false;
} else if (printer_opts[OPT_PRINT_SYNTAX].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') {
settings.do_syntax =
@@ -734,7 +728,7 @@ void ex_hardcopy(exarg_T *eap)
prt_pos_T page_prtpos; // print position at page start
int side;
- memset(&page_prtpos, 0, sizeof(prt_pos_T));
+ CLEAR_FIELD(page_prtpos);
page_prtpos.file_line = eap->line1;
prtpos = page_prtpos;
@@ -749,11 +743,9 @@ void ex_hardcopy(exarg_T *eap)
/*
* Loop over all pages in the print job: 1 2 3 ...
*/
- for (page_count = 0; prtpos.file_line <= eap->line2; ++page_count) {
- /*
- * Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ...
- * For duplex: 12 12 12 34 34 34, ...
- */
+ for (page_count = 0; prtpos.file_line <= eap->line2; page_count++) {
+ // Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ...
+ // For duplex: 12 12 12 34 34 34, ...
for (uncollated_copies = 0;
uncollated_copies < settings.n_uncollated_copies;
uncollated_copies++) {
@@ -763,10 +755,8 @@ void ex_hardcopy(exarg_T *eap)
/*
* Do front and rear side of a page.
*/
- for (side = 0; side <= settings.duplex; ++side) {
- /*
- * Print one page.
- */
+ for (side = 0; side <= settings.duplex; side++) {
+ // Print one page.
// Check for interrupt character every page.
os_breakcheck();
@@ -837,7 +827,7 @@ void ex_hardcopy(exarg_T *eap)
}
}
if (settings.duplex && prtpos.file_line <= eap->line2) {
- ++page_count;
+ page_count++;
}
// Remember the position where the next page starts.
@@ -868,7 +858,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
{
colnr_T col;
char_u *line;
- int need_break = FALSE;
+ int need_break = false;
int outputlen;
int tab_spaces;
int print_pos;
@@ -881,7 +871,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
if (!ppos->ff && prt_use_number()) {
prt_line_number(psettings, page_line, ppos->file_line);
}
- ppos->ff = FALSE;
+ ppos->ff = false;
} else {
// left over from wrap halfway through a tab
print_pos = ppos->print_pos;
@@ -900,7 +890,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
}
// syntax highlighting stuff.
if (psettings->do_syntax) {
- id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, FALSE);
+ id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, false);
if (id > 0) {
id = syn_get_final_id(id);
} else {
@@ -944,7 +934,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
&& printer_opts[OPT_PRINT_FORMFEED].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0])
== 'y') {
- ppos->ff = TRUE;
+ ppos->ff = true;
need_break = 1;
} else {
need_break = mch_print_text_out(line + col, (size_t)outputlen);
@@ -1718,7 +1708,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource)
semsg(_("E624: Can't open file \"%s\""), resource->filename);
return false;
}
- memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN);
+ CLEAR_FIELD(prt_resfile.buffer);
// Parse first line to ensure valid resource file
prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u),
@@ -1986,7 +1976,7 @@ void mch_print_cleanup(void)
if (prt_do_conv) {
convert_setup(&prt_conv, NULL, NULL);
- prt_do_conv = FALSE;
+ prt_do_conv = false;
}
if (prt_ps_fd != NULL) {
fclose(prt_ps_fd);
@@ -2118,11 +2108,11 @@ static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap,
for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) {
if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0) {
*pp_mbenc = p_mbenc;
- return TRUE;
+ return true;
}
p_mbenc++;
}
- return FALSE;
+ return false;
}
static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap,
@@ -2141,11 +2131,11 @@ static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap,
for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) {
if (STRNICMP(p_mbchar->charset, p_charset, char_len) == 0) {
*pp_mbchar = p_mbchar;
- return TRUE;
+ return true;
}
p_mbchar++;
}
- return FALSE;
+ return false;
}
int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
@@ -2157,17 +2147,14 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
char_u *p;
int props;
int cmap = 0;
- char_u *p_encoding;
struct prt_ps_encoding_S *p_mbenc;
struct prt_ps_encoding_S *p_mbenc_first;
struct prt_ps_charset_S *p_mbchar = NULL;
- /*
- * Set up font and encoding.
- */
- p_encoding = enc_skip(p_penc);
+ // Set up font and encoding.
+ char_u *p_encoding = (char_u *)enc_skip(p_penc);
if (*p_encoding == NUL) {
- p_encoding = enc_skip(p_enc);
+ p_encoding = (char_u *)enc_skip(p_enc);
}
// Look for a multi-byte font that matches the encoding and character set.
@@ -2186,7 +2173,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
p_mbenc_first = p_mbenc;
effective_cmap = cmap;
}
- if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], &p_mbchar)) {
+ if (prt_match_charset(p_pmcs, &prt_ps_mbfonts[cmap], &p_mbchar)) {
break;
}
}
@@ -2279,7 +2266,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_ps_font = &prt_ps_mb_font;
} else {
- prt_use_courier = FALSE;
+ prt_use_courier = false;
prt_ps_font = &prt_ps_courier_font;
}
@@ -2296,7 +2283,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
paper_name = "A4";
paper_strlen = 2;
}
- for (i = 0; i < (int)PRT_MEDIASIZE_LEN; ++i) {
+ for (i = 0; i < (int)PRT_MEDIASIZE_LEN; i++) {
if (STRLEN(prt_mediasize[i].name) == (unsigned)paper_strlen
&& STRNICMP(prt_mediasize[i].name, paper_name,
paper_strlen) == 0) {
@@ -2337,7 +2324,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
* Set up the font size.
*/
fontsize = PRT_PS_DEFAULT_FONTSIZE;
- for (p = p_pfn; (p = (char_u *)vim_strchr((char *)p, ':')) != NULL; p++) {
+ for (p = (char_u *)p_pfn; (p = (char_u *)vim_strchr((char *)p, ':')) != NULL; p++) {
if (p[1] == 'h' && ascii_isdigit(p[2])) {
fontsize = atoi((char *)p + 2);
}
@@ -2381,16 +2368,16 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
* Set up printer duplex and tumble based on Duplex option setting - default
* is long sided duplex printing (i.e. no tumble).
*/
- prt_duplex = TRUE;
- prt_tumble = FALSE;
+ prt_duplex = true;
+ prt_tumble = false;
psettings->duplex = 1;
if (printer_opts[OPT_PRINT_DUPLEX].present) {
if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "off", 3) == 0) {
- prt_duplex = FALSE;
+ prt_duplex = false;
psettings->duplex = 0;
} else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5)
== 0) {
- prt_tumble = TRUE;
+ prt_tumble = true;
}
}
@@ -2601,13 +2588,13 @@ bool mch_print_begin(prt_settings_T *psettings)
// that cannot be found then default to "latin1".
// Note: VIM specific encoding header is always skipped.
if (!prt_out_mbyte) {
- p_encoding = (char *)enc_skip(p_penc);
+ p_encoding = enc_skip(p_penc);
if (*p_encoding == NUL
|| !prt_find_resource(p_encoding, &res_encoding)) {
// 'printencoding' not set or not supported - find alternate
int props;
- p_encoding = (char *)enc_skip(p_enc);
+ p_encoding = enc_skip(p_enc);
props = enc_canon_props((char_u *)p_encoding);
if (!(props & ENC_8BIT)
|| !prt_find_resource(p_encoding, &res_encoding)) {
@@ -2627,9 +2614,9 @@ bool mch_print_begin(prt_settings_T *psettings)
// For the moment there are no checks on encoding resource files to
// perform
} else {
- p_encoding = (char *)enc_skip(p_penc);
+ p_encoding = enc_skip(p_penc);
if (*p_encoding == NUL) {
- p_encoding = (char *)enc_skip(p_enc);
+ p_encoding = enc_skip(p_enc);
}
if (prt_use_courier) {
// Include ASCII range encoding vector
@@ -2647,9 +2634,9 @@ bool mch_print_begin(prt_settings_T *psettings)
}
prt_conv.vc_type = CONV_NONE;
- if (!(enc_canon_props(p_enc) & enc_canon_props((char_u *)p_encoding) & ENC_8BIT)) {
+ if (!(enc_canon_props((char_u *)p_enc) & enc_canon_props((char_u *)p_encoding) & ENC_8BIT)) {
// Set up encoding conversion if required
- if (convert_setup(&prt_conv, p_enc, (char_u *)p_encoding) == FAIL) {
+ if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) {
semsg(_("E620: Unable to convert to print encoding \"%s\""),
p_encoding);
return false;
@@ -2943,7 +2930,7 @@ int mch_print_begin_page(char_u *str)
int mch_print_blank_page(void)
{
- return mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE;
+ return mch_print_begin_page(NULL) ? (mch_print_end_page()) : false;
}
static double prt_pos_x = 0;
@@ -3075,7 +3062,8 @@ int mch_print_text_out(char_u *const textp, size_t len)
if (prt_do_conv) {
// Convert from multi-byte to 8-bit encoding
- tofree = p = string_convert(&prt_conv, p, &len);
+ p = (char_u *)string_convert(&prt_conv, (char *)p, &len);
+ tofree = p;
if (p == NULL) {
p = (char_u *)"";
len = 0;