Skip to content

Commit

Permalink
Merge pull request #519 from npitre/conf
Browse files Browse the repository at this point in the history
many improvements to the config facility and usage
  • Loading branch information
andmarti1424 authored Mar 21, 2021
2 parents 804d6c0 + b89bc21 commit 4175e52
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 294 deletions.
4 changes: 2 additions & 2 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ int save_plain(FILE * fout, int r0, int c0, int rn, int cn) {
if(emptyfield){
fwprintf(fout, L"\t");
}
if (! atoi(get_conf_value("copy_to_clipboard_delimited_tab"))) {
if (! get_conf_int("copy_to_clipboard_delimited_tab")) {
pad_and_align(text, num, fwidth[col], align, 0, out);
fwprintf(fout, L"%ls", out);
} else if ( (*pp)->flags & is_valid) {
fwprintf(fout, L"%s\t", num);
} else if ( (*pp)->label) {
fwprintf(fout, L"%s\t", text);
}
} else if (! atoi(get_conf_value("copy_to_clipboard_delimited_tab"))) {
} else if (! get_conf_int("copy_to_clipboard_delimited_tab")) {
fwprintf(fout, L"%*s", fwidth[col], " ");
} else {
fwprintf(fout, L"\t");
Expand Down
14 changes: 7 additions & 7 deletions src/cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ void doformat(int c1, int c2, int w, int p, int r) {
w = 1;
}

if (! atoi(get_conf_value("nocurses")) && w > COLS - rescol - 2) {
if (! get_conf_int("nocurses") && w > COLS - rescol - 2) {
sc_info("Width too large - Maximum = %d", COLS - rescol - 2);
w = COLS - rescol - 2;
}
Expand Down Expand Up @@ -950,7 +950,7 @@ void int_deleterow(int row, int mult) {
}
rebuild_graph(); //FIXME CHECK HERE WHY REBUILD IS NEEDED. See NOTE1 in shift.c
sync_refs();
//if (atoi(get_conf_value("autocalc")) && ! loading) EvalAll();
//if (get_conf_int("autocalc") && ! loading) EvalAll();
EvalAll();
maxrow--;
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ void enter_cell_content(int r, int c, char * submode, wchar_t * content) {
*/

void send_to_interp(wchar_t * oper) {
if (atoi(get_conf_value("nocurses"))) {
if (get_conf_int("nocurses")) {
int pos = -1;
if ((pos = wstr_in_wstr(oper, L"\n")) != -1)
oper[pos] = L'\0';
Expand All @@ -1231,7 +1231,7 @@ void send_to_interp(wchar_t * oper) {
yyparse();
linelim = -1;
line[0]='\0';
if (atoi(get_conf_value("autocalc")) && ! loading) EvalAll();
if (get_conf_int("autocalc") && ! loading) EvalAll();
return;
}

Expand Down Expand Up @@ -2532,7 +2532,7 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a
}

// If content exceedes column width, outputs n number of '*' needed to fill column width
if (str_len + num_len + padding > col_width && !atoi(get_conf_value("truncate")) && ( (! atoi(get_conf_value("overlap")))) ) {
if (str_len + num_len + padding > col_width && !get_conf_int("truncate") && ( (! get_conf_int("overlap"))) ) {
if (padding) wmemset(str_out + wcslen(str_out), L'#', padding);
wmemset(str_out + wcslen(str_out), L'*', col_width - padding);
return;
Expand Down Expand Up @@ -2573,7 +2573,7 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a
}

// Similar condition to max width '*' condition above, but just trims instead
if (str_len + num_len + padding > col_width && atoi(get_conf_value("truncate"))) {
if (str_len + num_len + padding > col_width && get_conf_int("truncate")) {
str_out[col_width] = '\0';
}

Expand Down Expand Up @@ -2679,7 +2679,7 @@ int is_single_command (struct block * buf, long timeout) {
else if (buf->value == L'-') result = EDITION_CMD;
else if (buf->value == L'+') result = EDITION_CMD;

else if (isdigit(buf->value) && atoi(get_conf_value("numeric")) )
else if (isdigit(buf->value) && get_conf_int("numeric") )
result = MOVEMENT_CMD; // repeat last command

else if (buf->value == L'.') result = MOVEMENT_CMD; // repeat last command
Expand Down
4 changes: 2 additions & 2 deletions src/cmds_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void do_commandmode(struct block * sb) {
create_structures();
readfile(name, 0);

if (! atoi(get_conf_value("nocurses"))) {
if (! get_conf_int("nocurses")) {
ui_show_header();
}
}
Expand Down Expand Up @@ -845,7 +845,7 @@ void do_commandmode(struct block * sb) {
plotedit(aux);

} else if ( ! wcscmp(inputline, L"set") ) {
char valores[ (get_maxkey_length(user_conf_d) + get_maxvalue_length(user_conf_d) + 1) * user_conf_d->len ];
char valores[get_dict_buffer_size(user_conf_d) + 1];
get_conf_values(valores);
ui_show_text(valores);

Expand Down
24 changes: 12 additions & 12 deletions src/cmds_normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void do_normalmode(struct block * buf) {
break;

case L'0':
if (atoi(get_conf_value("numeric_zero")) == 1 && atoi(get_conf_value("numeric")) == 1) goto numeric;
if (get_conf_int("numeric_zero") == 1 && get_conf_int("numeric") == 1) goto numeric;
case OKEY_HOME:
;
int freeze = freeze_ranges && (freeze_ranges->type == 'c' || freeze_ranges->type == 'a') ? 1 : 0;
Expand Down Expand Up @@ -262,7 +262,7 @@ void do_normalmode(struct block * buf) {
case OKEY_PGDOWN:
{
int n = LINES - RESROW - 1;
if (atoi(get_conf_value("half_page_scroll"))) n = n / 2;
if (get_conf_int("half_page_scroll")) n = n / 2;
lastcol = curcol;
lastrow = currow;
currow = forw_row(n)->row;
Expand All @@ -277,7 +277,7 @@ void do_normalmode(struct block * buf) {
case OKEY_PGUP:
{
int n = LINES - RESROW - 1;
if (atoi(get_conf_value("half_page_scroll"))) n = n / 2;
if (get_conf_int("half_page_scroll")) n = n / 2;
lastcol = curcol;
lastrow = currow;
currow = back_row(n)->row;
Expand Down Expand Up @@ -435,7 +435,7 @@ void do_normalmode(struct block * buf) {

// repeat last command
case L'.':
if (atoi(get_conf_value("numeric_decimal")) == 1 && atoi(get_conf_value("numeric")) == 1) goto numeric;
if (get_conf_int("numeric_decimal") == 1 && get_conf_int("numeric") == 1) goto numeric;
copybuffer(lastcmd_buffer, buf); // nose graba en lastcmd_buffer!!
cmd_multiplier = 1;
exec_mult(buf, COMPLETECMDTIMEOUT);
Expand Down Expand Up @@ -640,7 +640,7 @@ void do_normalmode(struct block * buf) {
#endif
}

//if (atoi(get_conf_value("autocalc"))) EvalAll();
//if (get_conf_int("autocalc")) EvalAll();
ui_update(TRUE);
break;
}
Expand Down Expand Up @@ -737,7 +737,7 @@ void do_normalmode(struct block * buf) {

} else if (buf->pnext->value == L'd') {
del_selected_cells();
if (atoi(get_conf_value("autocalc")) && ! loading) EvalAll();
if (get_conf_int("autocalc") && ! loading) EvalAll();
}

ui_update(TRUE);
Expand Down Expand Up @@ -920,13 +920,13 @@ void do_normalmode(struct block * buf) {

case L'H':
scroll = calc_offscr_sc_cols() - center_hidden_cols;
if (atoi(get_conf_value("half_page_scroll"))) scroll /= 2;
if (get_conf_int("half_page_scroll")) scroll /= 2;
scroll_left(scroll);
break;

case L'L':
scroll = calc_offscr_sc_cols() - center_hidden_cols;
if (atoi(get_conf_value("half_page_scroll"))) scroll /= 2;
if (get_conf_int("half_page_scroll")) scroll /= 2;
scroll_right(scroll);
break;

Expand Down Expand Up @@ -1106,7 +1106,7 @@ void do_normalmode(struct block * buf) {
sc_error("Locked cells encountered. Nothing changed");
return;
}
if (atoi(get_conf_value("numeric")) == 1) goto numeric;
if (get_conf_int("numeric") == 1) goto numeric;
struct ent * p;
#ifdef UNDO
create_undo_action();
Expand Down Expand Up @@ -1136,7 +1136,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
end_undo_action();
#endif
if (atoi(get_conf_value("autocalc"))) EvalAll();
if (get_conf_int("autocalc")) EvalAll();
cmd_multiplier = 0;
ui_update(TRUE);
}
Expand All @@ -1146,8 +1146,8 @@ void do_normalmode(struct block * buf) {
default:
numeric:
if ( (isdigit(buf->value) || buf->value == L'-' || buf->value == L'+' ||
( buf->value == L'.' && atoi(get_conf_value("numeric_decimal")) )) &&
atoi(get_conf_value("numeric")) ) {
( buf->value == L'.' && get_conf_int("numeric_decimal") )) &&
get_conf_int("numeric") ) {
if (locked_cell(currow, curcol)) return;
insert_edit_submode='=';
chg_mode(insert_edit_submode);
Expand Down
44 changes: 22 additions & 22 deletions src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void free_colors_param_dict() {
*/

void chg_color(char * str) {
if (atoi((char *) get_conf_value("nocurses"))) return;
if (get_conf_int("nocurses")) return;

// Create key-value dictionary for the content of the string
struct dictionary * d = create_dictionary();
Expand Down Expand Up @@ -310,27 +310,27 @@ void chg_color(char * str) {
}

// Change the color
int type = atoi(get(d_colors_param, get(d, "type")));
int type = get_int(d_colors_param, get(d, "type"));
struct custom_color * cc;
if ((cc = get_custom_color(get(d, "bg"))) != NULL) { // bg is custom color
ucolors[ type ].bg = 7 + cc->number;
} else { // bg is stock ncurses color
ucolors[ type ].bg = atoi(get(d_colors_param, get(d, "bg")));
ucolors[ type ].bg = get_int(d_colors_param, get(d, "bg"));
}

if ((cc = get_custom_color(get(d, "fg"))) != NULL) { // fg is custom color
ucolors[ type ].fg = 7 + cc->number;
} else { // fg is stock ncurses color
ucolors[ type ].fg = atoi(get(d_colors_param, get(d, "fg")));
ucolors[ type ].fg = get_int(d_colors_param, get(d, "fg"));
}

if (((cl = get(d, "bold")) != NULL) && cl[0] != '\0') ucolors[ type ].bold = atoi(get(d, "bold"));
if (((cl = get(d, "italic")) != NULL) && cl[0] != '\0') ucolors[ type ].italic = atoi(get(d, "italic"));
if (((cl = get(d, "dim")) != NULL) && cl[0] != '\0') ucolors[ type ].dim = atoi(get(d, "dim"));
if (((cl = get(d, "reverse")) != NULL) && cl[0] != '\0') ucolors[ type ].reverse = atoi(get(d, "reverse"));
if (((cl = get(d, "standout")) != NULL) && cl[0] != '\0') ucolors[ type ].standout = atoi(get(d, "standout"));
if (((cl = get(d, "blink")) != NULL) && cl[0] != '\0') ucolors[ type ].blink = atoi(get(d, "blink"));
if (((cl = get(d, "underline")) != NULL) && cl[0] != '\0') ucolors[ type ].underline = atoi(get(d, "underline"));
if (((cl = get(d, "bold")) != NULL) && cl[0] != '\0') ucolors[ type ].bold = get_int(d, "bold");
if (((cl = get(d, "italic")) != NULL) && cl[0] != '\0') ucolors[ type ].italic = get_int(d, "italic");
if (((cl = get(d, "dim")) != NULL) && cl[0] != '\0') ucolors[ type ].dim = get_int(d, "dim");
if (((cl = get(d, "reverse")) != NULL) && cl[0] != '\0') ucolors[ type ].reverse = get_int(d, "reverse");
if (((cl = get(d, "standout")) != NULL) && cl[0] != '\0') ucolors[ type ].standout = get_int(d, "standout");
if (((cl = get(d, "blink")) != NULL) && cl[0] != '\0') ucolors[ type ].blink = get_int(d, "blink");
if (((cl = get(d, "underline")) != NULL) && cl[0] != '\0') ucolors[ type ].underline = get_int(d, "underline");

// clean temp variable
destroy_dictionary(d);
Expand Down Expand Up @@ -419,7 +419,7 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
struct custom_color * cc;
if ((cl = get(d, "bg")) != NULL && cl[0] != '\0') {
if (get(d_colors_param, get(d, "bg")) != NULL) {
n->ucolor->bg = atoi(get(d_colors_param, get(d, "bg")));
n->ucolor->bg = get_int(d_colors_param, get(d, "bg"));
} else if ((cc = get_custom_color(get(d, "bg"))) != NULL) {
n->ucolor->bg = 7 + cc->number;
} else {
Expand All @@ -429,7 +429,7 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
}
if ((cl = get(d, "fg")) != NULL && cl[0] != '\0') {
if (get(d_colors_param, get(d, "fg")) != NULL) {
n->ucolor->fg = atoi(get(d_colors_param, get(d, "fg")));
n->ucolor->fg = get_int(d_colors_param, get(d, "fg"));
} else if ((cc = get_custom_color(get(d, "fg"))) != NULL) {
n->ucolor->fg = 7 + cc->number;
} else {
Expand All @@ -438,13 +438,13 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
}
}

if ((cl = get(d, "bold")) != NULL && cl[0] != '\0') n->ucolor->bold = atoi(get(d, "bold"));
if ((cl = get(d, "italic")) != NULL && cl[0] != '\0') n->ucolor->italic = atoi(get(d, "italic"));
if ((cl = get(d, "dim") ) != NULL && cl[0] != '\0') n->ucolor->dim = atoi(get(d, "dim"));
if ((cl = get(d, "reverse")) != NULL && cl[0] != '\0') n->ucolor->reverse = atoi(get(d, "reverse"));
if ((cl = get(d, "standout")) != NULL && cl[0] != '\0') n->ucolor->standout = atoi(get(d, "standout"));
if ((cl = get(d, "blink")) != NULL && cl[0] != '\0') n->ucolor->blink = atoi(get(d, "blink"));
if ((cl = get(d, "underline")) != NULL && cl[0] != '\0') n->ucolor->underline = atoi(get(d, "underline"));
if ((cl = get(d, "bold")) != NULL && cl[0] != '\0') n->ucolor->bold = get_int(d, "bold");
if ((cl = get(d, "italic")) != NULL && cl[0] != '\0') n->ucolor->italic = get_int(d, "italic");
if ((cl = get(d, "dim") ) != NULL && cl[0] != '\0') n->ucolor->dim = get_int(d, "dim");
if ((cl = get(d, "reverse")) != NULL && cl[0] != '\0') n->ucolor->reverse = get_int(d, "reverse");
if ((cl = get(d, "standout")) != NULL && cl[0] != '\0') n->ucolor->standout = get_int(d, "standout");
if ((cl = get(d, "blink")) != NULL && cl[0] != '\0') n->ucolor->blink = get_int(d, "blink");
if ((cl = get(d, "underline")) != NULL && cl[0] != '\0') n->ucolor->underline = get_int(d, "underline");

if (! loading) {
#ifdef UNDO
Expand Down Expand Up @@ -567,7 +567,7 @@ int redefine_color(char * color, int r, int g, int b) {
#if defined(NCURSES) && defined(USECOLORS)
extern void sig_winchg();
if (
! atoi(get_conf_value("nocurses"))
! get_conf_int("nocurses")
&& has_colors() && can_change_color()
) {
char * s = get(d_colors_param, color);
Expand Down Expand Up @@ -604,7 +604,7 @@ int redefine_color(char * color, int r, int g, int b) {
int define_color(char * color, int r, int g, int b) {

#if defined(NCURSES) && defined(USECOLORS)
if (atoi(get_conf_value("nocurses"))) {
if (get_conf_int("nocurses")) {
// this should not be alerted.
//sc_error("Could not define color %s. Not using NCURSES.", color);
return -1;
Expand Down
Loading

0 comments on commit 4175e52

Please sign in to comment.