refactor: reformat with uncrustify #15736

* fix function parameter comments
* remove space after star in function names
This commit is contained in:
dundargoc 2021-09-20 18:35:41 +02:00 committed by GitHub
parent 1f8c91bf72
commit f4ca3a29dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 1412 additions and 1262 deletions

View File

@ -208,7 +208,7 @@ sp_after_ptr_star_qualifier = ignore # ignore/add/remove/force/not_defined
# prototype or function definition. # prototype or function definition.
# #
# Overrides sp_after_ptr_star and sp_type_func. # Overrides sp_after_ptr_star and sp_type_func.
sp_after_ptr_star_func = ignore # ignore/add/remove/force/not_defined sp_after_ptr_star_func = remove # ignore/add/remove/force/not_defined
# Add or remove space after a pointer star '*' in the trailing return of a # Add or remove space after a pointer star '*' in the trailing return of a
# function prototype or function definition. # function prototype or function definition.
@ -3279,5 +3279,5 @@ set PREPROC REAL_FATTR_CONST
set PREPROC REAL_FATTR_NONNULL_ALL set PREPROC REAL_FATTR_NONNULL_ALL
set PREPROC REAL_FATTR_PURE set PREPROC REAL_FATTR_PURE
set PREPROC REAL_FATTR_WARN_UNUSED_RESULT set PREPROC REAL_FATTR_WARN_UNUSED_RESULT
# option(s) with 'not default' value: 61 # option(s) with 'not default' value: 62
# #

View File

@ -5218,8 +5218,8 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int
/// Call "user_expand_func()" to invoke a user defined Vim script function and /// Call "user_expand_func()" to invoke a user defined Vim script function and
/// return the result (either a string, a List or NULL). /// return the result (either a string, a List or NULL).
static void * call_user_expand_func(user_expand_func_T user_expand_func, expand_T *xp, static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T *xp, int *num_file,
int *num_file, char_u ***file) char_u ***file)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
char_u keep = 0; char_u keep = 0;

File diff suppressed because it is too large Load Diff

View File

@ -5,16 +5,16 @@
/// ///
/// Functions for handling growing arrays. /// Functions for handling growing arrays.
#include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/garray.h"
#include "nvim/log.h" #include "nvim/log.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/garray.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/vim.h"
// #include "nvim/globals.h" // #include "nvim/globals.h"
#include "nvim/memline.h" #include "nvim/memline.h"
@ -206,8 +206,7 @@ void ga_concat(garray_T *gap, const char_u *restrict s)
/// @param[out] gap Growarray to modify. /// @param[out] gap Growarray to modify.
/// @param[in] s String to concatenate. /// @param[in] s String to concatenate.
/// @param[in] len String length. /// @param[in] len String length.
void ga_concat_len(garray_T *const gap, const char *restrict s, void ga_concat_len(garray_T *const gap, const char *restrict s, const size_t len)
const size_t len)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (len) { if (len) {

File diff suppressed because it is too large Load Diff

View File

@ -6,35 +6,35 @@
*/ */
#include <assert.h> #include <assert.h>
#include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/vim.h"
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
# include <locale.h> # include <locale.h>
#endif #endif
#include "nvim/hardcopy.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/ex_cmds2.h" #include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/garray.h"
#include "nvim/hardcopy.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/garray.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/ui.h" #include "nvim/ui.h"
#include "nvim/version.h" #include "nvim/version.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
/* /*
* To implement printing on a platform, the following functions must be * To implement printing on a platform, the following functions must be
@ -286,8 +286,7 @@ char_u *parse_printmbfont(void)
* Returns an error message for an illegal option, NULL otherwise. * Returns an error message for an illegal option, NULL otherwise.
* Only used for the printer at the moment... * Only used for the printer at the moment...
*/ */
static char_u *parse_list_options(char_u *option_str, option_table_T *table, static char_u *parse_list_options(char_u *option_str, option_table_T *table, size_t table_size)
size_t table_size)
{ {
option_table_T *old_opts; option_table_T *old_opts;
char_u *ret = NULL; char_u *ret = NULL;
@ -317,14 +316,17 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table,
break; break;
} }
commap = vim_strchr(stringp, ','); commap = vim_strchr(stringp, ',');
if (commap == NULL) if (commap == NULL) {
commap = option_str + STRLEN(option_str); commap = option_str + STRLEN(option_str);
}
len = (int)(colonp - stringp); 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) if (STRNICMP(stringp, table[idx].name, len) == 0) {
break; break;
}
}
if (idx == table_size) { if (idx == table_size) {
ret = (char_u *)N_("E551: Illegal component"); ret = (char_u *)N_("E551: Illegal component");
@ -347,9 +349,10 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table,
table[idx].strlen = (int)(commap - p); table[idx].strlen = (int)(commap - p);
stringp = commap; stringp = commap;
if (*stringp == ',') if (*stringp == ',') {
++stringp; ++stringp;
} }
}
if (ret != NULL) { if (ret != NULL) {
// Restore old options in case of error // Restore old options in case of error
@ -401,16 +404,18 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec)
colorindex = atoi(color); colorindex = atoi(color);
} }
if (colorindex >= 0 && colorindex < t_colors) if (colorindex >= 0 && colorindex < t_colors) {
fg_color = prt_get_term_color(colorindex); fg_color = prt_get_term_color(colorindex);
else } else {
fg_color = PRCOLOR_BLACK; fg_color = PRCOLOR_BLACK;
} }
}
if (fg_color == PRCOLOR_WHITE) if (fg_color == PRCOLOR_WHITE) {
fg_color = PRCOLOR_BLACK; fg_color = PRCOLOR_BLACK;
else if (*p_bg == 'd') } else if (*p_bg == 'd') {
fg_color = darken_rgb(fg_color); fg_color = darken_rgb(fg_color);
}
pattr->fg_color = fg_color; pattr->fg_color = fg_color;
pattr->bg_color = PRCOLOR_WHITE; pattr->bg_color = PRCOLOR_WHITE;
@ -432,8 +437,7 @@ static void prt_set_bg(uint32_t bg)
} }
} }
static void prt_set_font(const TriState bold, const TriState italic, static void prt_set_font(const TriState bold, const TriState italic, const TriState underline)
const TriState underline)
{ {
if (curr_bold != bold if (curr_bold != bold
|| curr_italic != italic || curr_italic != italic
@ -446,8 +450,8 @@ static void prt_set_font(const TriState bold, const TriState italic,
} }
// Print the line number in the left margin. // Print the line number in the left margin.
static void prt_line_number(prt_settings_T *const psettings, static void prt_line_number(prt_settings_T *const psettings, const int page_line,
const int page_line, const linenr_T lnum) const linenr_T lnum)
{ {
prt_set_fg(psettings->number.fg_color); prt_set_fg(psettings->number.fg_color);
prt_set_bg(psettings->number.bg_color); prt_set_bg(psettings->number.bg_color);
@ -504,18 +508,19 @@ int prt_get_unit(int idx)
int i; int i;
static char *(units[4]) = PRT_UNIT_NAMES; static char *(units[4]) = PRT_UNIT_NAMES;
if (printer_opts[idx].present) 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) { if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0) {
u = i; u = i;
break; break;
} }
}
}
return u; return u;
} }
// Print the page header. // Print the page header.
static void prt_header(prt_settings_T *const psettings, const int pagenum, static void prt_header(prt_settings_T *const psettings, const int pagenum, const linenr_T lnum)
const linenr_T lnum)
{ {
int width = psettings->chars_per_line; int width = psettings->chars_per_line;
@ -620,13 +625,15 @@ void ex_hardcopy(exarg_T *eap)
// Expand things like "%.ps". // Expand things like "%.ps".
if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) { if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) {
if (errormsg != NULL) if (errormsg != NULL) {
EMSG(errormsg); EMSG(errormsg);
}
return; return;
} }
settings.outfile = skipwhite(eap->arg + 1); settings.outfile = skipwhite(eap->arg + 1);
} else if (*eap->arg != NUL) } else if (*eap->arg != NUL) {
settings.arguments = eap->arg; settings.arguments = eap->arg;
}
/* /*
* Initialise for printing. Ask the user for settings, unless forceit is * Initialise for printing. Ask the user for settings, unless forceit is
@ -641,19 +648,21 @@ void ex_hardcopy(exarg_T *eap)
: curbuf->b_sfname == NULL : curbuf->b_sfname == NULL
? curbuf->b_fname ? curbuf->b_fname
: curbuf->b_sfname, : curbuf->b_sfname,
eap->forceit) == FAIL) eap->forceit) == FAIL) {
return; return;
}
settings.modec = 'c'; settings.modec = 'c';
if (!syntax_present(curwin)) if (!syntax_present(curwin)) {
settings.do_syntax = FALSE; settings.do_syntax = FALSE;
else if (printer_opts[OPT_PRINT_SYNTAX].present } else if (printer_opts[OPT_PRINT_SYNTAX].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') && TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') {
settings.do_syntax = settings.do_syntax =
(TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y'); (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y');
else } else {
settings.do_syntax = settings.has_color; settings.do_syntax = settings.has_color;
}
// Set up printing attributes for line numbers // Set up printing attributes for line numbers
settings.number.fg_color = PRCOLOR_BLACK; settings.number.fg_color = PRCOLOR_BLACK;
@ -675,8 +684,9 @@ void ex_hardcopy(exarg_T *eap)
/* /*
* Estimate the total lines to be printed * Estimate the total lines to be printed
*/ */
for (lnum = eap->line1; lnum <= eap->line2; lnum++) for (lnum = eap->line1; lnum <= eap->line2; lnum++) {
bytes_to_print += STRLEN(skipwhite(ml_get(lnum))); bytes_to_print += STRLEN(skipwhite(ml_get(lnum)));
}
if (bytes_to_print == 0) { if (bytes_to_print == 0) {
MSG(_("No text to be printed")); MSG(_("No text to be printed"));
goto print_fail_no_begin; goto print_fail_no_begin;
@ -697,8 +707,9 @@ void ex_hardcopy(exarg_T *eap)
jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_JOBSPLIT].string[0]) == 'y'); && TOLOWER_ASC(printer_opts[OPT_PRINT_JOBSPLIT].string[0]) == 'y');
if (!mch_print_begin(&settings)) if (!mch_print_begin(&settings)) {
goto print_fail_no_begin; goto print_fail_no_begin;
}
/* /*
* Loop over collated copies: 1 2 3, 1 2 3, ... * Loop over collated copies: 1 2 3, 1 2 3, ...
@ -718,9 +729,10 @@ void ex_hardcopy(exarg_T *eap)
if (jobsplit && collated_copies > 0) { 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); mch_print_end(&settings);
if (!mch_print_begin(&settings)) if (!mch_print_begin(&settings)) {
goto print_fail_no_begin; goto print_fail_no_begin;
} }
}
/* /*
* Loop over all pages in the print job: 1 2 3 ... * Loop over all pages in the print job: 1 2 3 ...
@ -746,29 +758,33 @@ void ex_hardcopy(exarg_T *eap)
// Check for interrupt character every page. // Check for interrupt character every page.
os_breakcheck(); os_breakcheck();
if (got_int || settings.user_abort) if (got_int || settings.user_abort) {
goto print_fail; goto print_fail;
}
assert(prtpos.bytes_printed <= SIZE_MAX / 100); assert(prtpos.bytes_printed <= SIZE_MAX / 100);
sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), sprintf((char *)IObuff, _("Printing page %d (%zu%%)"),
page_count + 1 + side, page_count + 1 + side,
prtpos.bytes_printed * 100 / bytes_to_print); prtpos.bytes_printed * 100 / bytes_to_print);
if (!mch_print_begin_page(IObuff)) if (!mch_print_begin_page(IObuff)) {
goto print_fail; goto print_fail;
}
if (settings.n_collated_copies > 1) if (settings.n_collated_copies > 1) {
sprintf((char *)IObuff + STRLEN(IObuff), sprintf((char *)IObuff + STRLEN(IObuff),
_(" Copy %d of %d"), _(" Copy %d of %d"),
collated_copies + 1, collated_copies + 1,
settings.n_collated_copies); settings.n_collated_copies);
}
prt_message(IObuff); prt_message(IObuff);
/* /*
* Output header if required * Output header if required
*/ */
if (prt_header_height() > 0) if (prt_header_height() > 0) {
prt_header(&settings, page_count + 1 + side, prt_header(&settings, page_count + 1 + side,
prtpos.file_line); prtpos.file_line);
}
for (page_line = 0; page_line < settings.lines_per_page; for (page_line = 0; page_line < settings.lines_per_page;
++page_line) { ++page_line) {
@ -803,12 +819,14 @@ void ex_hardcopy(exarg_T *eap)
if (prtpos.file_line > eap->line2 && settings.duplex if (prtpos.file_line > eap->line2 && settings.duplex
&& side == 0 && side == 0
&& uncollated_copies + 1 < settings.n_uncollated_copies) { && uncollated_copies + 1 < settings.n_uncollated_copies) {
if (!mch_print_blank_page()) if (!mch_print_blank_page()) {
goto print_fail; goto print_fail;
} }
} }
if (settings.duplex && prtpos.file_line <= eap->line2) }
if (settings.duplex && prtpos.file_line <= eap->line2) {
++page_count; ++page_count;
}
// Remember the position where the next page starts. // Remember the position where the next page starts.
page_prtpos = prtpos; page_prtpos = prtpos;
@ -848,8 +866,9 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
if (ppos->column == 0 || ppos->ff) { if (ppos->column == 0 || ppos->ff) {
print_pos = 0; print_pos = 0;
tab_spaces = 0; tab_spaces = 0;
if (!ppos->ff && prt_use_number()) if (!ppos->ff && prt_use_number()) {
prt_line_number(psettings, page_line, ppos->file_line); prt_line_number(psettings, page_line, ppos->file_line);
}
ppos->ff = FALSE; ppos->ff = FALSE;
} else { } else {
// left over from wrap halfway through a tab // left over from wrap halfway through a tab
@ -870,10 +889,11 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
// syntax highlighting stuff. // syntax highlighting stuff.
if (psettings->do_syntax) { 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) if (id > 0) {
id = syn_get_final_id(id); id = syn_get_final_id(id);
else } else {
id = 0; 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); line = ml_get(ppos->file_line);
@ -900,9 +920,10 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
need_break = mch_print_text_out((char_u *)" ", 1); need_break = mch_print_text_out((char_u *)" ", 1);
print_pos++; print_pos++;
tab_spaces--; tab_spaces--;
if (need_break) if (need_break) {
break; break;
} }
}
// Keep the TAB if we didn't finish it. // Keep the TAB if we didn't finish it.
if (need_break && tab_spaces > 0) { if (need_break && tab_spaces > 0) {
break; break;
@ -930,8 +951,9 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
&& (line[col] == NUL && (line[col] == NUL
|| (printer_opts[OPT_PRINT_WRAP].present || (printer_opts[OPT_PRINT_WRAP].present
&& TOLOWER_ASC(printer_opts[OPT_PRINT_WRAP].string[0]) && TOLOWER_ASC(printer_opts[OPT_PRINT_WRAP].string[0])
== 'n'))) == 'n'))) {
return 0; return 0;
}
return col; return col;
} }
@ -1361,12 +1383,13 @@ static void prt_def_font(char *new_name, char *encoding, int height, char *font)
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"/_%s /VIM-%s /%s ref\n", new_name, encoding, font); "/_%s /VIM-%s /%s ref\n", new_name, encoding, font);
prt_write_file(prt_line_buffer); prt_write_file(prt_line_buffer);
if (prt_out_mbyte) if (prt_out_mbyte) {
sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n", sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n",
new_name, height, 500./prt_ps_courier_font.wx, new_name); new_name, height, 500./prt_ps_courier_font.wx, new_name);
else } else {
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"/%s %d /_%s ffs\n", new_name, height, new_name); "/%s %d /_%s ffs\n", new_name, height, new_name);
}
prt_write_file(prt_line_buffer); prt_write_file(prt_line_buffer);
} }
@ -1402,10 +1425,12 @@ static void prt_real_bits(double real, int precision, int *pinteger, int *pfract
{ {
int integer = (int)real; int integer = (int)real;
double fraction = real - integer; double fraction = real - integer;
if (real < integer) if (real < integer) {
fraction = -fraction; fraction = -fraction;
for (int i = 0; i < precision; i++) }
for (int i = 0; i < precision; i++) {
fraction *= 10.0; fraction *= 10.0;
}
*pinteger = integer; *pinteger = integer;
*pfraction = (int)(fraction + 0.5); *pfraction = (int)(fraction + 0.5);
@ -1500,16 +1525,18 @@ static void prt_flush_buffer(void)
prt_write_string("ul\n"); prt_write_string("ul\n");
} }
// Draw the text // Draw the text
if (prt_out_mbyte) if (prt_out_mbyte) {
prt_write_string("<"); prt_write_string("<");
else } else {
prt_write_string("("); prt_write_string("(");
}
assert(prt_ps_buffer.ga_len >= 0); assert(prt_ps_buffer.ga_len >= 0);
prt_write_file_raw_len(prt_ps_buffer.ga_data, (size_t)prt_ps_buffer.ga_len); prt_write_file_raw_len(prt_ps_buffer.ga_data, (size_t)prt_ps_buffer.ga_len);
if (prt_out_mbyte) if (prt_out_mbyte) {
prt_write_string(">"); prt_write_string(">");
else } else {
prt_write_string(")"); 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) { if (prt_do_moveto) {
prt_write_real(prt_pos_x_moveto, 2); prt_write_real(prt_pos_x_moveto, 2);
@ -1529,11 +1556,12 @@ static void prt_resource_name(char_u *filename, void *cookie)
{ {
char_u *resource_filename = cookie; char_u *resource_filename = cookie;
if (STRLEN(filename) >= MAXPATHL) if (STRLEN(filename) >= MAXPATHL) {
*resource_filename = NUL; *resource_filename = NUL;
else } else {
STRCPY(resource_filename, filename); STRCPY(resource_filename, filename);
} }
}
static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
{ {
@ -1568,15 +1596,17 @@ static int prt_resfile_next_line(void)
// 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; idx = prt_resfile.line_end + 1;
while (idx < prt_resfile.len) { while (idx < prt_resfile.len) {
if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR) if (prt_resfile.buffer[idx] != PSLF && prt_resfile.buffer[idx] != PSCR) {
break; break;
}
idx++; idx++;
} }
prt_resfile.line_start = idx; prt_resfile.line_start = idx;
while (idx < prt_resfile.len) { while (idx < prt_resfile.len) {
if (prt_resfile.buffer[idx] == PSLF || prt_resfile.buffer[idx] == PSCR) if (prt_resfile.buffer[idx] == PSLF || prt_resfile.buffer[idx] == PSCR) {
break; break;
}
idx++; idx++;
} }
prt_resfile.line_end = idx; prt_resfile.line_end = idx;
@ -1601,8 +1631,9 @@ static int prt_resfile_skip_nonws(int offset)
idx = prt_resfile.line_start + offset; idx = prt_resfile.line_start + offset;
while (idx < prt_resfile.line_end) { while (idx < prt_resfile.line_end) {
if (isspace(prt_resfile.buffer[idx])) if (isspace(prt_resfile.buffer[idx])) {
return idx - prt_resfile.line_start; return idx - prt_resfile.line_start;
}
idx++; idx++;
} }
return -1; return -1;
@ -1614,8 +1645,9 @@ static int prt_resfile_skip_ws(int offset)
idx = prt_resfile.line_start + offset; idx = prt_resfile.line_start + offset;
while (idx < prt_resfile.line_end) { while (idx < prt_resfile.line_end) {
if (!isspace(prt_resfile.buffer[idx])) if (!isspace(prt_resfile.buffer[idx])) {
return idx - prt_resfile.line_start; return idx - prt_resfile.line_start;
}
idx++; idx++;
} }
return -1; return -1;
@ -1786,8 +1818,7 @@ static bool prt_open_resource(struct prt_ps_resource_S *resource)
return true; return true;
} }
static bool prt_check_resource(const struct prt_ps_resource_S *resource, static bool prt_check_resource(const struct prt_ps_resource_S *resource, const char_u *version)
const char_u *version)
FUNC_ATTR_NONNULL_ALL 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
@ -1846,19 +1877,17 @@ static void prt_dsc_ints(char *comment, int count, int *ints)
prt_write_string("\n"); prt_write_string("\n");
} }
static void prt_dsc_resources( /// @param comment if NULL add to previous
const char *comment, // if NULL add to previous static void prt_dsc_resources(const char *comment, const char *type, const char *string)
const char *type,
const char *string
)
FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_NONNULL_ARG(2, 3)
{ {
if (comment != NULL) if (comment != NULL) {
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"%%%%%s: %s", comment, type); "%%%%%s: %s", comment, type);
else } else {
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"%%%%+ %s", type); "%%%%+ %s", type);
}
prt_write_file(prt_line_buffer); prt_write_file(prt_line_buffer);
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
@ -1872,31 +1901,37 @@ static void prt_dsc_font_resource(char *resource, struct prt_ps_font_S *ps_font)
prt_dsc_resources(resource, "font", prt_dsc_resources(resource, "font",
ps_font->ps_fontname[PRT_PS_FONT_ROMAN]); ps_font->ps_fontname[PRT_PS_FONT_ROMAN]);
for (i = PRT_PS_FONT_BOLD; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) for (i = PRT_PS_FONT_BOLD; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) {
if (ps_font->ps_fontname[i] != NULL) if (ps_font->ps_fontname[i] != NULL) {
prt_dsc_resources(NULL, "font", ps_font->ps_fontname[i]); prt_dsc_resources(NULL, "font", ps_font->ps_fontname[i]);
} }
}
}
static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, int num_copies) static void prt_dsc_requirements(int duplex, int tumble, int collate, int color, int num_copies)
{ {
/* Only output the comment if we need to. /* Only output the comment if we need to.
* Note: tumble is ignored if we are not duplexing * Note: tumble is ignored if we are not duplexing
*/ */
if (!(duplex || collate || color || (num_copies > 1))) if (!(duplex || collate || color || (num_copies > 1))) {
return; return;
}
sprintf((char *)prt_line_buffer, "%%%%Requirements:"); sprintf((char *)prt_line_buffer, "%%%%Requirements:");
prt_write_file(prt_line_buffer); prt_write_file(prt_line_buffer);
if (duplex) { if (duplex) {
prt_write_string(" duplex"); prt_write_string(" duplex");
if (tumble) if (tumble) {
prt_write_string("(tumble)"); prt_write_string("(tumble)");
} }
if (collate) }
if (collate) {
prt_write_string(" collate"); prt_write_string(" collate");
if (color) }
if (color) {
prt_write_string(" color"); prt_write_string(" color");
}
if (num_copies > 1) { if (num_copies > 1) {
prt_write_string(" numcopies("); prt_write_string(" numcopies(");
// Note: no space wanted so don't use prt_write_int() // Note: no space wanted so don't use prt_write_int()
@ -1908,7 +1943,8 @@ static void prt_dsc_requirements(int duplex, int tumble, int collate, int color,
prt_write_string("\n"); prt_write_string("\n");
} }
static void prt_dsc_docmedia(char *paper_name, double width, double height, double weight, char *colour, char *type) static void prt_dsc_docmedia(char *paper_name, double width, double height, double weight,
char *colour, char *type)
{ {
vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer),
"%%%%DocumentMedia: %s ", paper_name); "%%%%DocumentMedia: %s ", paper_name);
@ -1916,15 +1952,17 @@ static void prt_dsc_docmedia(char *paper_name, double width, double height, doub
prt_write_real(width, 2); prt_write_real(width, 2);
prt_write_real(height, 2); prt_write_real(height, 2);
prt_write_real(weight, 2); prt_write_real(weight, 2);
if (colour == NULL) if (colour == NULL) {
prt_write_string("()"); prt_write_string("()");
else } else {
prt_write_string(colour); prt_write_string(colour);
}
prt_write_string(" "); prt_write_string(" ");
if (type == NULL) if (type == NULL) {
prt_write_string("()"); prt_write_string("()");
else } else {
prt_write_string(type); prt_write_string(type);
}
prt_write_string("\n"); prt_write_string("\n");
} }
@ -1938,8 +1976,9 @@ void mch_print_cleanup(void)
* one style). * one style).
*/ */
for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) {
if (prt_ps_mb_font.ps_fontname[i] != NULL) if (prt_ps_mb_font.ps_fontname[i] != NULL) {
xfree(prt_ps_mb_font.ps_fontname[i]); xfree(prt_ps_mb_font.ps_fontname[i]);
}
prt_ps_mb_font.ps_fontname[i] = NULL; prt_ps_mb_font.ps_fontname[i] = NULL;
} }
} }
@ -1993,7 +2032,8 @@ static double to_device_units(int idx, double physsize, int def_number)
/* /*
* Calculate margins for given width and height from printoptions settings. * Calculate margins for given width and height from printoptions settings.
*/ */
static void prt_page_margins(double width, double height, double *left, double *right, double *top, double *bottom) static void prt_page_margins(double width, double height, double *left, double *right, double *top,
double *bottom)
{ {
*left = to_device_units(OPT_PRINT_LEFT, width, 10); *left = to_device_units(OPT_PRINT_LEFT, width, 10);
*right = width - to_device_units(OPT_PRINT_RIGHT, width, 5); *right = width - to_device_units(OPT_PRINT_RIGHT, width, 5);
@ -2015,11 +2055,13 @@ static int prt_get_cpl(void)
/* If we are outputting multi-byte characters then line numbers will be /* If we are outputting multi-byte characters then line numbers will be
* printed with half width characters * printed with half width characters
*/ */
if (prt_out_mbyte) if (prt_out_mbyte) {
prt_number_width /= 2; prt_number_width /= 2;
}
prt_left_margin += prt_number_width; prt_left_margin += prt_number_width;
} else } else {
prt_number_width = 0.0; prt_number_width = 0.0;
}
return (int)((prt_right_margin - prt_left_margin) / prt_char_width); return (int)((prt_right_margin - prt_left_margin) / prt_char_width);
} }
@ -2063,7 +2105,8 @@ static int prt_get_lpp(void)
return lpp - prt_header_height(); return lpp - prt_header_height();
} }
static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_encoding_S **pp_mbenc) static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap,
struct prt_ps_encoding_S **pp_mbenc)
{ {
int mbenc; int mbenc;
int enc_len; int enc_len;
@ -2083,7 +2126,8 @@ static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap,
return FALSE; return FALSE;
} }
static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_charset_S **pp_mbchar) static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap,
struct prt_ps_charset_S **pp_mbchar)
{ {
int mbchar; int mbchar;
int char_len; int char_len;
@ -2124,8 +2168,9 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
* Set up font and encoding. * Set up font and encoding.
*/ */
p_encoding = enc_skip(p_penc); p_encoding = enc_skip(p_penc);
if (*p_encoding == NUL) if (*p_encoding == NUL) {
p_encoding = enc_skip(p_enc); p_encoding = enc_skip(p_enc);
}
/* Look for a multi-byte font that matches the encoding and character set. /* 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 * Only look if multi-byte character set is defined, or using multi-byte
@ -2136,16 +2181,18 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) { if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) {
p_mbenc_first = NULL; p_mbenc_first = NULL;
int effective_cmap = 0; int effective_cmap = 0;
for (cmap = 0; cmap < (int)ARRAY_SIZE(prt_ps_mbfonts); cmap++) for (cmap = 0; cmap < (int)ARRAY_SIZE(prt_ps_mbfonts); cmap++) {
if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap], if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap],
&p_mbenc)) { &p_mbenc)) {
if (p_mbenc_first == NULL) { if (p_mbenc_first == NULL) {
p_mbenc_first = p_mbenc; p_mbenc_first = p_mbenc;
effective_cmap = cmap; effective_cmap = cmap;
} }
if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], &p_mbchar)) if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap], &p_mbchar)) {
break; 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) { if (p_mbenc_first != NULL && p_mbchar == NULL) {
@ -2205,7 +2252,6 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_build_cid_fontname(PRT_PS_FONT_BOLD, prt_build_cid_fontname(PRT_PS_FONT_BOLD,
mbfont_opts[OPT_MBFONT_BOLD].string, mbfont_opts[OPT_MBFONT_BOLD].string,
mbfont_opts[OPT_MBFONT_BOLD].strlen); mbfont_opts[OPT_MBFONT_BOLD].strlen);
} }
if (mbfont_opts[OPT_MBFONT_OBLIQUE].present) { if (mbfont_opts[OPT_MBFONT_OBLIQUE].present) {
prt_build_cid_fontname(PRT_PS_FONT_OBLIQUE, prt_build_cid_fontname(PRT_PS_FONT_OBLIQUE,
@ -2252,13 +2298,16 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
paper_name = "A4"; paper_name = "A4";
paper_strlen = 2; 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 if (STRLEN(prt_mediasize[i].name) == (unsigned)paper_strlen
&& STRNICMP(prt_mediasize[i].name, paper_name, && STRNICMP(prt_mediasize[i].name, paper_name,
paper_strlen) == 0) paper_strlen) == 0) {
break; break;
if (i == PRT_MEDIASIZE_LEN) }
}
if (i == PRT_MEDIASIZE_LEN) {
i = 0; i = 0;
}
prt_media = i; prt_media = i;
/* /*
@ -2290,9 +2339,11 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
* Set up the font size. * Set up the font size.
*/ */
fontsize = PRT_PS_DEFAULT_FONTSIZE; fontsize = PRT_PS_DEFAULT_FONTSIZE;
for (p = p_pfn; (p = vim_strchr(p, ':')) != NULL; ++p) for (p = p_pfn; (p = vim_strchr(p, ':')) != NULL; ++p) {
if (p[1] == 'h' && ascii_isdigit(p[2])) if (p[1] == 'h' && ascii_isdigit(p[2])) {
fontsize = atoi((char *)p + 2); fontsize = atoi((char *)p + 2);
}
}
prt_font_metrics(fontsize); prt_font_metrics(fontsize);
/* /*
@ -2340,9 +2391,10 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
prt_duplex = FALSE; prt_duplex = FALSE;
psettings->duplex = 0; psettings->duplex = 0;
} else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5) } else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5)
== 0) == 0) {
prt_tumble = TRUE; prt_tumble = TRUE;
} }
}
// For now user abort not supported // For now user abort not supported
psettings->user_abort = 0; psettings->user_abort = 0;
@ -2369,8 +2421,9 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
} }
prt_bufsiz = psettings->chars_per_line; prt_bufsiz = psettings->chars_per_line;
if (prt_out_mbyte) if (prt_out_mbyte) {
prt_bufsiz *= 2; prt_bufsiz *= 2;
}
ga_init(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz); ga_init(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz);
prt_page_num = 0; prt_page_num = 0;
@ -2420,8 +2473,9 @@ static int prt_add_resource(struct prt_ps_resource_S *resource)
fclose(fd_resource); fclose(fd_resource);
return FALSE; return FALSE;
} }
if (bytes_read == 0) if (bytes_read == 0) {
break; break;
}
prt_write_file_raw_len(resource_buffer, bytes_read); prt_write_file_raw_len(resource_buffer, bytes_read);
if (prt_file_error) { if (prt_file_error) {
fclose(fd_resource); fclose(fd_resource);
@ -2468,8 +2522,9 @@ int mch_print_begin(prt_settings_T *psettings)
char *p_time = os_ctime(ctime_buf, sizeof(ctime_buf)); char *p_time = os_ctime(ctime_buf, sizeof(ctime_buf));
// Note: os_ctime() adds a \n so we have to remove it :-( // Note: os_ctime() adds a \n so we have to remove it :-(
p = vim_strchr((char_u *)p_time, '\n'); p = vim_strchr((char_u *)p_time, '\n');
if (p != NULL) if (p != NULL) {
*p = NUL; *p = NUL;
}
prt_dsc_textline("CreationDate", p_time); prt_dsc_textline("CreationDate", p_time);
prt_dsc_textline("DocumentData", "Clean8Bit"); prt_dsc_textline("DocumentData", "Clean8Bit");
prt_dsc_textline("Orientation", "Portrait"); prt_dsc_textline("Orientation", "Portrait");
@ -2516,30 +2571,35 @@ int mch_print_begin(prt_settings_T *psettings)
if (prt_out_mbyte) { if (prt_out_mbyte) {
prt_dsc_font_resource((prt_use_courier ? NULL prt_dsc_font_resource((prt_use_courier ? NULL
: "DocumentNeededResources"), &prt_ps_mb_font); : "DocumentNeededResources"), &prt_ps_mb_font);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources(NULL, "cmap", prt_cmap); 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)) { 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; return FALSE;
} }
if (!prt_open_resource(&res_prolog)) if (!prt_open_resource(&res_prolog)) {
return FALSE; return FALSE;
if (!prt_check_resource(&res_prolog, PRT_PROLOG_VERSION)) }
if (!prt_check_resource(&res_prolog, PRT_PROLOG_VERSION)) {
return FALSE; return FALSE;
}
if (prt_out_mbyte) { 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)) { 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; return FALSE;
} }
if (!prt_open_resource(&res_cidfont)) if (!prt_open_resource(&res_cidfont)) {
return FALSE; return FALSE;
if (!prt_check_resource(&res_cidfont, PRT_CID_PROLOG_VERSION)) }
if (!prt_check_resource(&res_cidfont, PRT_CID_PROLOG_VERSION)) {
return FALSE; return FALSE;
} }
}
/* Find an encoding to use for printing. /* Find an encoding to use for printing.
* Check 'printencoding'. If not set or not found, then use 'encoding'. If * Check 'printencoding'. If not set or not found, then use 'encoding'. If
@ -2567,14 +2627,16 @@ int mch_print_begin(prt_settings_T *psettings)
} }
} }
} }
if (!prt_open_resource(&res_encoding)) if (!prt_open_resource(&res_encoding)) {
return FALSE; return FALSE;
}
/* For the moment there are no checks on encoding resource files to /* For the moment there are no checks on encoding resource files to
* perform */ * perform */
} else { } else {
p_encoding = enc_skip(p_penc); p_encoding = enc_skip(p_penc);
if (*p_encoding == NUL) if (*p_encoding == NUL) {
p_encoding = enc_skip(p_enc); p_encoding = enc_skip(p_enc);
}
if (prt_use_courier) { if (prt_use_courier) {
// Include ASCII range encoding vector // Include ASCII range encoding vector
if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) { if (!prt_find_resource(prt_ascii_encoding, &res_encoding)) {
@ -2582,8 +2644,9 @@ int mch_print_begin(prt_settings_T *psettings)
prt_ascii_encoding); prt_ascii_encoding);
return FALSE; return FALSE;
} }
if (!prt_open_resource(&res_encoding)) if (!prt_open_resource(&res_encoding)) {
return FALSE; return FALSE;
}
/* For the moment there are no checks on encoding resource files to /* For the moment there are no checks on encoding resource files to
* perform */ * perform */
} }
@ -2607,9 +2670,10 @@ int mch_print_begin(prt_settings_T *psettings)
prt_cmap); prt_cmap);
return FALSE; return FALSE;
} }
if (!prt_open_resource(&res_cmap)) if (!prt_open_resource(&res_cmap)) {
return FALSE; return FALSE;
} }
}
// List resources supplied // List resources supplied
STRCPY(buffer, res_prolog.title); STRCPY(buffer, res_prolog.title);
@ -2652,9 +2716,10 @@ int mch_print_begin(prt_settings_T *psettings)
if (prt_out_mbyte) { if (prt_out_mbyte) {
prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"), prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"),
&prt_ps_mb_font); &prt_ps_mb_font);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources(NULL, "cmap", prt_cmap); 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_textline("PageMedia", prt_mediasize[prt_media].name);
@ -2680,11 +2745,13 @@ int mch_print_begin(prt_settings_T *psettings)
} }
} }
if (!prt_out_mbyte || prt_use_courier) if (!prt_out_mbyte || prt_use_courier) {
/* There will be only one Roman font encoding to be included in the PS /* There will be only one Roman font encoding to be included in the PS
* file. */ * file. */
if (!prt_add_resource(&res_encoding)) if (!prt_add_resource(&res_encoding)) {
return FALSE; return FALSE;
}
}
prt_dsc_noarg("EndProlog"); prt_dsc_noarg("EndProlog");
@ -2710,8 +2777,9 @@ int mch_print_begin(prt_settings_T *psettings)
if (!prt_out_mbyte || prt_use_courier) { if (!prt_out_mbyte || prt_use_courier) {
/* When using Courier for ASCII range when printing multi-byte, need to /* When using Courier for ASCII range when printing multi-byte, need to
* pick up ASCII encoding to use with it. */ * pick up ASCII encoding to use with it. */
if (prt_use_courier) if (prt_use_courier) {
p_encoding = (char_u *)prt_ascii_encoding; p_encoding = (char_u *)prt_ascii_encoding;
}
prt_dsc_resources("IncludeResource", "font", prt_dsc_resources("IncludeResource", "font",
prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]); prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]);
prt_def_font("F0", (char *)p_encoding, (int)prt_line_height, prt_def_font("F0", (char *)p_encoding, (int)prt_line_height,
@ -2738,16 +2806,18 @@ int mch_print_begin(prt_settings_T *psettings)
*/ */
prt_dsc_resources("IncludeResource", "font", prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources("IncludeResource", "cmap", prt_cmap); prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
}
prt_def_cidfont("CF0", (int)prt_line_height, prt_def_cidfont("CF0", (int)prt_line_height,
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]);
if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD] != NULL) { if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD] != NULL) {
prt_dsc_resources("IncludeResource", "font", prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources("IncludeResource", "cmap", prt_cmap); prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
}
prt_def_cidfont("CF1", (int)prt_line_height, prt_def_cidfont("CF1", (int)prt_line_height,
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
} else { } else {
@ -2757,8 +2827,9 @@ int mch_print_begin(prt_settings_T *psettings)
if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) { if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) {
prt_dsc_resources("IncludeResource", "font", prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources("IncludeResource", "cmap", prt_cmap); prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
}
prt_def_cidfont("CF2", (int)prt_line_height, prt_def_cidfont("CF2", (int)prt_line_height,
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
} else { } else {
@ -2768,8 +2839,9 @@ int mch_print_begin(prt_settings_T *psettings)
if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) { if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) {
prt_dsc_resources("IncludeResource", "font", prt_dsc_resources("IncludeResource", "font",
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
if (!prt_custom_cmap) if (!prt_custom_cmap) {
prt_dsc_resources("IncludeResource", "cmap", prt_cmap); prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
}
prt_def_cidfont("CF3", (int)prt_line_height, prt_def_cidfont("CF3", (int)prt_line_height,
prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
} else { } else {
@ -2853,10 +2925,11 @@ int mch_print_begin_page(char_u *str)
prt_write_string("sv\n0 g\n"); prt_write_string("sv\n0 g\n");
prt_in_ascii = !prt_out_mbyte; prt_in_ascii = !prt_out_mbyte;
if (prt_out_mbyte) if (prt_out_mbyte) {
prt_write_string("CF0 sf\n"); prt_write_string("CF0 sf\n");
else } else {
prt_write_string("F0 sf\n"); prt_write_string("F0 sf\n");
}
prt_fgcol = PRCOLOR_BLACK; prt_fgcol = PRCOLOR_BLACK;
prt_bgcol = PRCOLOR_WHITE; prt_bgcol = PRCOLOR_WHITE;
prt_font = PRT_PS_FONT_ROMAN; prt_font = PRT_PS_FONT_ROMAN;
@ -2983,9 +3056,9 @@ int mch_print_text_out(char_u *const textp, size_t len)
b = prt_fgcol & 0xff; b = prt_fgcol & 0xff;
prt_write_real(r / 255.0, 3); prt_write_real(r / 255.0, 3);
if (r == g && g == b) if (r == g && g == b) {
prt_write_string("g\n"); prt_write_string("g\n");
else { } else {
prt_write_real(g / 255.0, 3); prt_write_real(g / 255.0, 3);
prt_write_real(b / 255.0, 3); prt_write_real(b / 255.0, 3);
prt_write_string("r\n"); prt_write_string("r\n");
@ -3003,8 +3076,9 @@ int mch_print_text_out(char_u *const textp, size_t len)
} }
prt_need_bgcol = false; prt_need_bgcol = false;
if (prt_need_underline) if (prt_need_underline) {
prt_do_underline = prt_underline; prt_do_underline = prt_underline;
}
prt_need_underline = false; prt_need_underline = false;
prt_attribute_change = false; prt_attribute_change = false;
@ -3042,14 +3116,22 @@ int mch_print_text_out(char_u *const textp, size_t len)
*/ */
ga_append(&prt_ps_buffer, '\\'); ga_append(&prt_ps_buffer, '\\');
switch (ch) { switch (ch) {
case BS: ga_append(&prt_ps_buffer, 'b'); break; case BS:
case TAB: ga_append(&prt_ps_buffer, 't'); break; ga_append(&prt_ps_buffer, 'b'); break;
case NL: ga_append(&prt_ps_buffer, 'n'); break; case TAB:
case FF: ga_append(&prt_ps_buffer, 'f'); break; ga_append(&prt_ps_buffer, 't'); break;
case CAR: ga_append(&prt_ps_buffer, 'r'); break; case NL:
case '(': ga_append(&prt_ps_buffer, '('); break; ga_append(&prt_ps_buffer, 'n'); break;
case ')': ga_append(&prt_ps_buffer, ')'); break; case FF:
case '\\': ga_append(&prt_ps_buffer, '\\'); break; ga_append(&prt_ps_buffer, 'f'); break;
case CAR:
ga_append(&prt_ps_buffer, 'r'); break;
case '(':
ga_append(&prt_ps_buffer, '('); break;
case ')':
ga_append(&prt_ps_buffer, ')'); break;
case '\\':
ga_append(&prt_ps_buffer, '\\'); break;
default: default:
sprintf((char *)ch_buff, "%03o", (unsigned int)ch); sprintf((char *)ch_buff, "%03o", (unsigned int)ch);
@ -3058,9 +3140,10 @@ int mch_print_text_out(char_u *const textp, size_t len)
ga_append(&prt_ps_buffer, (char)ch_buff[2]); ga_append(&prt_ps_buffer, (char)ch_buff[2]);
break; break;
} }
} else } else {
ga_append(&prt_ps_buffer, (char)ch); ga_append(&prt_ps_buffer, (char)ch);
} }
}
// Need to free any translated characters // Need to free any translated characters
xfree(tofree); xfree(tofree);
@ -3080,15 +3163,16 @@ int mch_print_text_out(char_u *const textp, size_t len)
return need_break; return need_break;
} }
void mch_print_set_font(const TriState iBold, const TriState iItalic, void mch_print_set_font(const TriState iBold, const TriState iItalic, const TriState iUnderline)
const TriState iUnderline)
{ {
int font = 0; int font = 0;
if (iBold) if (iBold) {
font |= 0x01; font |= 0x01;
if (iItalic) }
if (iItalic) {
font |= 0x02; font |= 0x02;
}
if (font != prt_font) { if (font != prt_font) {
prt_font = font; prt_font = font;

View File

@ -22,15 +22,15 @@
/// memory). /// memory).
#include <assert.h> #include <assert.h>
#include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/hashtab.h" #include "nvim/hashtab.h"
#include "nvim/message.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/vim.h"
// Magic value for algorithm that walks through the array. // Magic value for algorithm that walks through the array.
#define PERTURB_SHIFT 5 #define PERTURB_SHIFT 5
@ -102,8 +102,7 @@ hashitem_T *hash_find(const hashtab_T *const ht, const char_u *const key)
/// ///
/// @warning Returned pointer becomes invalid as soon as the hash table /// @warning Returned pointer becomes invalid as soon as the hash table
/// is changed in any way. /// is changed in any way.
hashitem_T *hash_find_len(const hashtab_T *const ht, const char *const key, hashitem_T *hash_find_len(const hashtab_T *const ht, const char *const key, const size_t len)
const size_t len)
{ {
return hash_lookup(ht, key, len, hash_hash_len(key, len)); return hash_lookup(ht, key, len, hash_hash_len(key, len));
} }
@ -119,8 +118,7 @@ hashitem_T *hash_find_len(const hashtab_T *const ht, const char *const key,
/// used for that key. /// used for that key.
/// WARNING: Returned pointer becomes invalid as soon as the hash table /// WARNING: Returned pointer becomes invalid as soon as the hash table
/// is changed in any way. /// is changed in any way.
hashitem_T *hash_lookup(const hashtab_T *const ht, hashitem_T *hash_lookup(const hashtab_T *const ht, const char *const key, const size_t key_len,
const char *const key, const size_t key_len,
const hash_T hash) const hash_T hash)
{ {
#ifdef HT_DEBUG #ifdef HT_DEBUG

View File

@ -3,9 +3,11 @@
// highlight.c: low level code for UI and syntax highlighting // highlight.c: low level code for UI and syntax highlighting
#include "nvim/vim.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/highlight.h" #include "nvim/highlight.h"
#include "nvim/highlight_defs.h" #include "nvim/highlight_defs.h"
#include "nvim/lua/executor.h"
#include "nvim/map.h" #include "nvim/map.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/option.h" #include "nvim/option.h"
@ -13,9 +15,7 @@
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/ui.h" #include "nvim/ui.h"
#include "nvim/api/private/defs.h" #include "nvim/vim.h"
#include "nvim/api/private/helpers.h"
#include "nvim/lua/executor.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "highlight.c.generated.h" # include "highlight.c.generated.h"

View File

@ -7,13 +7,14 @@
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/assert.h" #include "nvim/assert.h"
#include "nvim/buffer.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/indent.h"
#include "nvim/eval.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/mark.h" #include "nvim/eval.h"
#include "nvim/extmark.h" #include "nvim/extmark.h"
#include "nvim/indent.h"
#include "nvim/mark.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
@ -25,7 +26,6 @@
#include "nvim/search.h" #include "nvim/search.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@ -533,8 +533,7 @@ int get_expr_indent(void)
colnr_T save_curswant; colnr_T save_curswant;
int save_set_curswant; int save_set_curswant;
int save_State; int save_State;
int use_sandbox = was_set_insecurely( int use_sandbox = was_set_insecurely(curwin, (char_u *)"indentexpr", OPT_LOCAL);
curwin, (char_u *)"indentexpr", OPT_LOCAL);
// Save and restore cursor position and curswant, in case it was changed // Save and restore cursor position and curswant, in case it was changed
// * via :normal commands. // * via :normal commands.

View File

@ -5,16 +5,16 @@
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/keymap.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/memory.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/keymap.h"
#include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/strings.h"
#include "nvim/mouse.h" #include "nvim/mouse.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "keymap.c.generated.h" # include "keymap.c.generated.h"
@ -51,48 +51,48 @@ static const struct modmasktable {
static char_u modifier_keys_table[] = static char_u modifier_keys_table[] =
{ {
/* mod mask with modifier without modifier */ // mod mask with modifier without modifier
MOD_MASK_SHIFT, '&', '9', '@', '1', /* begin */ MOD_MASK_SHIFT, '&', '9', '@', '1', // begin
MOD_MASK_SHIFT, '&', '0', '@', '2', /* cancel */ MOD_MASK_SHIFT, '&', '0', '@', '2', // cancel
MOD_MASK_SHIFT, '*', '1', '@', '4', /* command */ MOD_MASK_SHIFT, '*', '1', '@', '4', // command
MOD_MASK_SHIFT, '*', '2', '@', '5', /* copy */ MOD_MASK_SHIFT, '*', '2', '@', '5', // copy
MOD_MASK_SHIFT, '*', '3', '@', '6', /* create */ MOD_MASK_SHIFT, '*', '3', '@', '6', // create
MOD_MASK_SHIFT, '*', '4', 'k', 'D', /* delete char */ MOD_MASK_SHIFT, '*', '4', 'k', 'D', // delete char
MOD_MASK_SHIFT, '*', '5', 'k', 'L', /* delete line */ MOD_MASK_SHIFT, '*', '5', 'k', 'L', // delete line
MOD_MASK_SHIFT, '*', '7', '@', '7', /* end */ MOD_MASK_SHIFT, '*', '7', '@', '7', // end
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', /* end */ MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', // end
MOD_MASK_SHIFT, '*', '9', '@', '9', /* exit */ MOD_MASK_SHIFT, '*', '9', '@', '9', // exit
MOD_MASK_SHIFT, '*', '0', '@', '0', /* find */ MOD_MASK_SHIFT, '*', '0', '@', '0', // find
MOD_MASK_SHIFT, '#', '1', '%', '1', /* help */ MOD_MASK_SHIFT, '#', '1', '%', '1', // help
MOD_MASK_SHIFT, '#', '2', 'k', 'h', /* home */ MOD_MASK_SHIFT, '#', '2', 'k', 'h', // home
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', /* home */ MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', // home
MOD_MASK_SHIFT, '#', '3', 'k', 'I', /* insert */ MOD_MASK_SHIFT, '#', '3', 'k', 'I', // insert
MOD_MASK_SHIFT, '#', '4', 'k', 'l', /* left arrow */ MOD_MASK_SHIFT, '#', '4', 'k', 'l', // left arrow
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', /* left arrow */ MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', // left arrow
MOD_MASK_SHIFT, '%', 'a', '%', '3', /* message */ MOD_MASK_SHIFT, '%', 'a', '%', '3', // message
MOD_MASK_SHIFT, '%', 'b', '%', '4', /* move */ MOD_MASK_SHIFT, '%', 'b', '%', '4', // move
MOD_MASK_SHIFT, '%', 'c', '%', '5', /* next */ MOD_MASK_SHIFT, '%', 'c', '%', '5', // next
MOD_MASK_SHIFT, '%', 'd', '%', '7', /* options */ MOD_MASK_SHIFT, '%', 'd', '%', '7', // options
MOD_MASK_SHIFT, '%', 'e', '%', '8', /* previous */ MOD_MASK_SHIFT, '%', 'e', '%', '8', // previous
MOD_MASK_SHIFT, '%', 'f', '%', '9', /* print */ MOD_MASK_SHIFT, '%', 'f', '%', '9', // print
MOD_MASK_SHIFT, '%', 'g', '%', '0', /* redo */ MOD_MASK_SHIFT, '%', 'g', '%', '0', // redo
MOD_MASK_SHIFT, '%', 'h', '&', '3', /* replace */ MOD_MASK_SHIFT, '%', 'h', '&', '3', // replace
MOD_MASK_SHIFT, '%', 'i', 'k', 'r', /* right arr. */ MOD_MASK_SHIFT, '%', 'i', 'k', 'r', // right arr.
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', /* right arr. */ MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', // right arr.
MOD_MASK_SHIFT, '%', 'j', '&', '5', /* resume */ MOD_MASK_SHIFT, '%', 'j', '&', '5', // resume
MOD_MASK_SHIFT, '!', '1', '&', '6', /* save */ MOD_MASK_SHIFT, '!', '1', '&', '6', // save
MOD_MASK_SHIFT, '!', '2', '&', '7', /* suspend */ MOD_MASK_SHIFT, '!', '2', '&', '7', // suspend
MOD_MASK_SHIFT, '!', '3', '&', '8', /* undo */ MOD_MASK_SHIFT, '!', '3', '&', '8', // undo
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', /* up arrow */ MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', // up arrow
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', /* down arrow */ MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', // down arrow
/* vt100 F1 */ // vt100 F1
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1, MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2, MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3, MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4, MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', /* F1 */ MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', // F1
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4',
@ -101,7 +101,7 @@ static char_u modifier_keys_table[] =
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', /* F10 */ MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', // F10
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2',
@ -133,7 +133,7 @@ static char_u modifier_keys_table[] =
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R', MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R',
/* TAB pseudo code*/ // TAB pseudo code
MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB, MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB,
NUL NUL
@ -397,22 +397,38 @@ int handle_x_keys(const int key)
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
{ {
switch (key) { switch (key) {
case K_XUP: return K_UP; case K_XUP:
case K_XDOWN: return K_DOWN; return K_UP;
case K_XLEFT: return K_LEFT; case K_XDOWN:
case K_XRIGHT: return K_RIGHT; return K_DOWN;
case K_XHOME: return K_HOME; case K_XLEFT:
case K_ZHOME: return K_HOME; return K_LEFT;
case K_XEND: return K_END; case K_XRIGHT:
case K_ZEND: return K_END; return K_RIGHT;
case K_XF1: return K_F1; case K_XHOME:
case K_XF2: return K_F2; return K_HOME;
case K_XF3: return K_F3; case K_ZHOME:
case K_XF4: return K_F4; return K_HOME;
case K_S_XF1: return K_S_F1; case K_XEND:
case K_S_XF2: return K_S_F2; return K_END;
case K_S_XF3: return K_S_F3; case K_ZEND:
case K_S_XF4: return K_S_F4; return K_END;
case K_XF1:
return K_F1;
case K_XF2:
return K_F2;
case K_XF3:
return K_F3;
case K_XF4:
return K_F4;
case K_S_XF1:
return K_S_F1;
case K_S_XF2:
return K_S_F2;
case K_S_XF3:
return K_S_F3;
case K_S_XF4:
return K_S_F4;
} }
return key; return key;
} }
@ -432,16 +448,17 @@ char_u *get_special_key_name(int c, int modifiers)
string[0] = '<'; string[0] = '<';
idx = 1; idx = 1;
/* Key that stands for a normal character. */ // Key that stands for a normal character.
if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) {
c = KEY2TERMCAP1(c); c = KEY2TERMCAP1(c);
}
/* /*
* Translate shifted special keys into unshifted keys and set modifier. * Translate shifted special keys into unshifted keys and set modifier.
* Same for CTRL and ALT modifiers. * Same for CTRL and ALT modifiers.
*/ */
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
for (i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE) for (i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE) {
if (KEY2TERMCAP0(c) == (int)modifier_keys_table[i + 1] if (KEY2TERMCAP0(c) == (int)modifier_keys_table[i + 1]
&& (int)KEY2TERMCAP1(c) == (int)modifier_keys_table[i + 2]) { && (int)KEY2TERMCAP1(c) == (int)modifier_keys_table[i + 2]) {
modifiers |= modifier_keys_table[i]; modifiers |= modifier_keys_table[i];
@ -450,8 +467,9 @@ char_u *get_special_key_name(int c, int modifiers)
break; break;
} }
} }
}
/* try to find the key in the special key table */ // try to find the key in the special key table
table_idx = find_special_key_in_table(c); table_idx = find_special_key_in_table(c);
/* /*
@ -459,14 +477,13 @@ char_u *get_special_key_name(int c, int modifiers)
* extract modifiers. * extract modifiers.
*/ */
if (c > 0 if (c > 0
&& (*mb_char2len)(c) == 1 && (*mb_char2len)(c) == 1) {
) {
if (table_idx < 0 if (table_idx < 0
&& (!vim_isprintc(c) || (c & 0x7f) == ' ') && (!vim_isprintc(c) || (c & 0x7f) == ' ')
&& (c & 0x80)) { && (c & 0x80)) {
c &= 0x7f; c &= 0x7f;
modifiers |= MOD_MASK_ALT; modifiers |= MOD_MASK_ALT;
/* try again, to find the un-alted key in the special key table */ // try again, to find the un-alted key in the special key table
table_idx = find_special_key_in_table(c); table_idx = find_special_key_in_table(c);
} }
if (table_idx < 0 && !vim_isprintc(c) && c < ' ') { if (table_idx < 0 && !vim_isprintc(c) && c < ' ') {
@ -475,15 +492,16 @@ char_u *get_special_key_name(int c, int modifiers)
} }
} }
/* translate the modifier into a string */ // translate the modifier into a string
for (i = 0; mod_mask_table[i].name != 'A'; i++) for (i = 0; mod_mask_table[i].name != 'A'; i++) {
if ((modifiers & mod_mask_table[i].mod_mask) if ((modifiers & mod_mask_table[i].mod_mask)
== mod_mask_table[i].mod_flag) { == mod_mask_table[i].mod_flag) {
string[idx++] = mod_mask_table[i].name; string[idx++] = mod_mask_table[i].name;
string[idx++] = (char_u)'-'; string[idx++] = (char_u)'-';
} }
}
if (table_idx < 0) { /* unknown special key, may output t_xx */ if (table_idx < 0) { // unknown special key, may output t_xx
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
string[idx++] = 't'; string[idx++] = 't';
string[idx++] = '_'; string[idx++] = '_';
@ -497,10 +515,11 @@ char_u *get_special_key_name(int c, int modifiers)
string[idx++] = (char_u)c; string[idx++] = (char_u)c;
} else { } else {
s = transchar(c); s = transchar(c);
while (*s) while (*s) {
string[idx++] = *s++; string[idx++] = *s++;
} }
} }
}
} else { // use name of special key } else { // use name of special key
size_t len = STRLEN(key_names_table[table_idx].name); size_t len = STRLEN(key_names_table[table_idx].name);
@ -525,9 +544,8 @@ char_u *get_special_key_name(int c, int modifiers)
/// @param[in] in_string Inside a double quoted string /// @param[in] in_string Inside a double quoted string
/// ///
/// @return Number of characters added to dst, zero for no match. /// @return Number of characters added to dst, zero for no match.
unsigned int trans_special(const char_u **srcp, const size_t src_len, unsigned int trans_special(const char_u **srcp, const size_t src_len, char_u *const dst,
char_u *const dst, const bool keycode, const bool keycode, const bool in_string)
const bool in_string)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{ {
int modifiers = 0; int modifiers = 0;
@ -582,9 +600,8 @@ unsigned int special_to_buf(int key, int modifiers, bool keycode, char_u *dst)
/// @param[in] in_string In string, double quote is escaped /// @param[in] in_string In string, double quote is escaped
/// ///
/// @return Key and modifiers or 0 if there is no match. /// @return Key and modifiers or 0 if there is no match.
int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, const bool keycode,
const bool keycode, const bool keep_x_key, const bool keep_x_key, const bool in_string)
const bool in_string)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
const char_u *last_dash; const char_u *last_dash;
@ -641,7 +658,7 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp,
if (bp <= end && *bp == '>') { // found matching '>' if (bp <= end && *bp == '>') { // found matching '>'
end_of_name = bp + 1; end_of_name = bp + 1;
/* Which modifiers are given? */ // Which modifiers are given?
modifiers = 0x0; modifiers = 0x0;
for (bp = src + 1; bp < last_dash; bp++) { for (bp = src + 1; bp < last_dash; bp++) {
if (*bp != '-') { if (*bp != '-') {
@ -795,13 +812,14 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag)
{ {
int i; int i;
for (i = 0; mouse_table[i].pseudo_code; i++) for (i = 0; mouse_table[i].pseudo_code; i++) {
if (code == mouse_table[i].pseudo_code) { if (code == mouse_table[i].pseudo_code) {
*is_click = mouse_table[i].is_click; *is_click = mouse_table[i].is_click;
*is_drag = mouse_table[i].is_drag; *is_drag = mouse_table[i].is_drag;
return mouse_table[i].button; return mouse_table[i].button;
} }
return 0; /* Shouldn't get here */ }
return 0; // Shouldn't get here
} }
/// Replace any terminal code strings with the equivalent internal /// Replace any terminal code strings with the equivalent internal
@ -829,9 +847,8 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag)
/// @return Pointer to an allocated memory in case of success, "from" in case of /// @return Pointer to an allocated memory in case of success, "from" in case of
/// failure. In case of success returned pointer is also saved to /// failure. In case of success returned pointer is also saved to
/// "bufp". /// "bufp".
char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bufp,
char_u **bufp, const bool from_part, const bool do_lt, const bool from_part, const bool do_lt, const bool special, int cpo_flags)
const bool special, int cpo_flags)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
ssize_t i; ssize_t i;

View File

@ -17,9 +17,9 @@
#include "auto/config.h" #include "auto/config.h"
#include "nvim/log.h" #include "nvim/log.h"
#include "nvim/types.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/os/time.h" #include "nvim/os/time.h"
#include "nvim/types.h"
#define LOG_FILE_ENV "NVIM_LOG_FILE" #define LOG_FILE_ENV "NVIM_LOG_FILE"
@ -124,8 +124,8 @@ void log_unlock(void)
/// @param line_num Source line number, or -1 /// @param line_num Source line number, or -1
/// @param eol Append linefeed "\n" /// @param eol Append linefeed "\n"
/// @param fmt printf-style format string /// @param fmt printf-style format string
bool logmsg(int log_level, const char *context, const char *func_name, bool logmsg(int log_level, const char *context, const char *func_name, int line_num, bool eol,
int line_num, bool eol, const char *fmt, ...) const char *fmt, ...)
FUNC_ATTR_UNUSED FUNC_ATTR_PRINTF(6, 7) FUNC_ATTR_UNUSED FUNC_ATTR_PRINTF(6, 7)
{ {
if (log_level < MIN_LOG_LEVEL) { if (log_level < MIN_LOG_LEVEL) {
@ -215,8 +215,7 @@ FILE *open_log_file(void)
} }
#ifdef HAVE_EXECINFO_BACKTRACE #ifdef HAVE_EXECINFO_BACKTRACE
void log_callstack_to_file(FILE *log_file, const char *const func_name, void log_callstack_to_file(FILE *log_file, const char *const func_name, const int line_num)
const int line_num)
{ {
void *trace[100]; void *trace[100];
int trace_size = backtrace(trace, ARRAY_SIZE(trace)); int trace_size = backtrace(trace, ARRAY_SIZE(trace));
@ -268,8 +267,7 @@ end:
#endif #endif
static bool do_log_to_file(FILE *log_file, int log_level, const char *context, static bool do_log_to_file(FILE *log_file, int log_level, const char *context,
const char *func_name, int line_num, bool eol, const char *func_name, int line_num, bool eol, const char *fmt, ...)
const char *fmt, ...)
FUNC_ATTR_PRINTF(7, 8) FUNC_ATTR_PRINTF(7, 8)
{ {
va_list args; va_list args;
@ -281,9 +279,8 @@ static bool do_log_to_file(FILE *log_file, int log_level, const char *context,
return ret; return ret;
} }
static bool v_do_log_to_file(FILE *log_file, int log_level, static bool v_do_log_to_file(FILE *log_file, int log_level, const char *context,
const char *context, const char *func_name, const char *func_name, int line_num, bool eol, const char *fmt,
int line_num, bool eol, const char *fmt,
va_list args) va_list args)
{ {
static const char *log_levels[] = { static const char *log_levels[] = {