summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés M <andmarti1424@users.noreply.github.com>2021-03-21 11:02:58 -0300
committerGitHub <noreply@github.com>2021-03-21 11:02:58 -0300
commit4175e52f9c02c6279babb76fa52c1dc5b8fbbf9d (patch)
treecaa0a62dd4265b061e1f35da8b6fb33777e2fb06
parent804d6c096b1722bb6b6f7a00a6a26e68be1d0836 (diff)
parentb89bc2172d767ef75b3393ee9b5e06ae1ed4c829 (diff)
Merge pull request #519 from npitre/conf
many improvements to the config facility and usage
-rw-r--r--src/clipboard.c4
-rw-r--r--src/cmds.c14
-rw-r--r--src/cmds_command.c4
-rw-r--r--src/cmds_normal.c24
-rw-r--r--src/color.c44
-rw-r--r--src/conf.c127
-rw-r--r--src/conf.h2
-rw-r--r--src/file.c14
-rwxr-xr-xsrc/gram.y8
-rw-r--r--src/input.c2
-rw-r--r--src/interp.c4
-rw-r--r--src/main.c35
-rw-r--r--src/shift.c4
-rw-r--r--src/tui.c30
-rwxr-xr-xsrc/utils/dictionary.c213
-rwxr-xr-xsrc/utils/dictionary.h6
-rw-r--r--src/xlsx.c10
17 files changed, 251 insertions, 294 deletions
diff --git a/src/clipboard.c b/src/clipboard.c
index 5861fba..c5c64d7 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -272,7 +272,7 @@ 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) {
@@ -280,7 +280,7 @@ int save_plain(FILE * fout, int r0, int c0, int rn, int cn) {
} 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");
diff --git a/src/cmds.c b/src/cmds.c
index f7a732a..7d099dd 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -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;
}
@@ -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--;
}
@@ -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';
@@ -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;
}
@@ -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;
@@ -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';
}
@@ -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
diff --git a/src/cmds_command.c b/src/cmds_command.c
index 55f1ce9..08ad76b 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -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();
}
}
@@ -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);
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index 8462c63..f9007e8 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -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;
}
@@ -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);
@@ -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;
@@ -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();
@@ -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);
}
@@ -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);
diff --git a/src/color.c b/src/color.c
index 5509018..95f0da6 100644
--- a/src/color.c
+++ b/src/color.c
@@ -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();
@@ -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);
@@ -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 {
@@ -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 {
@@ -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
@@ -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);
@@ -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;
diff --git a/src/conf.c b/src/conf.c
index 67d54bf..3142bd8 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -42,7 +42,7 @@
* \brief Configuration functions
*
* \details This file contains functions that operate on the user's configuration
- * dictionary (user_conf_d) and the predefined dictionary (predefined_conf_d).
+ * dictionary (user_conf_d).
*/
#include <stdlib.h>
@@ -52,57 +52,68 @@
#include "conf.h"
#include "utils/dictionary.h"
-/**
- * \brief Populates user_conf_d with default values
- *
- * \details Populates the user's configuration dictionary (user_conf_d) with
- * default values.
- *
- * \return none
- */
-// TODO Make this function take a pointer to a dictionary as an
-// argument rather than using user_conf_d directly.
-void store_default_config_values() {
- put(user_conf_d, "half_page_scroll", "1");
- put(user_conf_d, "autocalc", "1");
- put(user_conf_d, "numeric", "0");
- put(user_conf_d, "nocurses", "0");
- put(user_conf_d, "newline_action", "j");
- put(user_conf_d, "external_functions", "0");
- put(user_conf_d, "xlsx_readformulas", "0");
- put(user_conf_d, "import_delimited_as_text", "0");
- put(user_conf_d, "quit_afterload", "0");
- put(user_conf_d, "numeric_zero", "1");
- put(user_conf_d, "numeric_decimal", "1");
- put(user_conf_d, "filename_with_mode", "0");
- put(user_conf_d, "overlap", "0");
- put(user_conf_d, "truncate", "0");
- put(user_conf_d, "debug", "0");
- put(user_conf_d, "ignorecase", "0");
- put(user_conf_d, "trigger", "1");
- put(user_conf_d, "version", "0");
- put(user_conf_d, "help", "0");
- put(user_conf_d, "input_bar_bottom", "0");
- put(user_conf_d, "underline_grid", "0");
+const char default_config[] =
+ "half_page_scroll=1\n"
+ "autocalc=1\n"
+ "numeric=0\n"
+ "nocurses=0\n"
+ "newline_action=j\n"
+ "external_functions=0\n"
+ "xlsx_readformulas=0\n"
+ "import_delimited_as_text=0\n"
+ "quit_afterload=0\n"
+ "numeric_zero=1\n"
+ "numeric_decimal=1\n"
+ "filename_with_mode=0\n"
+ "overlap=0\n"
+ "truncate=0\n"
+ "debug=0\n"
+ "ignorecase=0\n"
+ "trigger=1\n"
+ "version=0\n"
+ "help=0\n"
+ "input_bar_bottom=0\n"
+ "underline_grid=0\n"
#ifdef AUTOBACKUP
- put(user_conf_d, "autobackup", "0"); // 0:noautobackup, n>0: backup every n in seconds
+ "autobackup=0\n" // 0:noautobackup, n>0: backup every n in seconds
#endif
#ifdef DEFAULT_COPY_TO_CLIPBOARD_CMD
- put(user_conf_d, "default_copy_to_clipboard_cmd", DEFAULT_COPY_TO_CLIPBOARD_CMD);
+ "default_copy_to_clipboard_cmd=" DEFAULT_COPY_TO_CLIPBOARD_CMD "\n"
#else
- put(user_conf_d, "default_copy_to_clipboard_cmd", "");
+ "default_copy_to_clipboard_cmd=\n"
#endif
- put(user_conf_d, "copy_to_clipboard_delimited_tab", "0");
+ "copy_to_clipboard_delimited_tab=0\n"
#ifdef DEFAULT_PASTE_FROM_CLIPBOARD_CMD
- put(user_conf_d, "default_paste_from_clipboard_cmd", DEFAULT_PASTE_FROM_CLIPBOARD_CMD);
+ "default_paste_from_clipboard_cmd=" DEFAULT_PASTE_FROM_CLIPBOARD_CMD "\n"
#else
- put(user_conf_d, "default_paste_from_clipboard_cmd", "");
+ "default_paste_from_clipboard_cmd=\n"
#endif
+ "tm_gmtoff=0\n";
+
+/**
+ * \brief Populates user_conf_d with default values
+ *
+ * \details Populates the user's configuration dictionary (user_conf_d) with
+ * default values.
+ *
+ * \return none
+ */
+// TODO Make this function take a pointer to a dictionary as an
+// argument rather than using user_conf_d directly.
+
+void store_default_config_values() {
+ char *line = default_config;
+
+ do {
+ parse_str(user_conf_d, line, 0);
+ line = strchr(line, '\n');
+ } while(line && *++line != 0);
+
// Calculate GMT offset (not on Solaris, doesn't have tm_gmtoff)
#if defined(USELOCALE) && !defined(__sun)
time_t t = time(NULL);
@@ -110,10 +121,7 @@ void store_default_config_values() {
char strgmtoff[7];
sprintf(strgmtoff, "%ld", lt->tm_gmtoff);
put(user_conf_d, "tm_gmtoff", strgmtoff);
- #else
- put(user_conf_d, "tm_gmtoff", "0");
#endif
-
}
/**
@@ -132,20 +140,20 @@ char * get_conf_values(char * salida) {
if (user_conf_d == NULL) return NULL;
struct nlist * nl;
- nl = user_conf_d->list;
salida[0]='\0';
- while (nl != NULL) {
+
+ char *buf = salida;
+ for (nl = user_conf_d->list; nl != NULL; nl = nl->next) {
// ignore version conf variable here so that its not shown in :set command
- if (! strcmp(nl->key, "version")) { nl = nl->next; continue; }
+ if (! strcmp(nl->key, "version")) continue;
- sprintf(salida + strlen(salida), "%s=%s\n", nl->key, nl->val);
- nl = nl->next;
+ buf += sprintf(buf, "%s=%s\n", nl->key, nl->val);
}
return salida;
}
/**
- * \brief Retreive the value of a given key in user_conf_d
+ * \brief Retreive the string value of a given key in user_conf_d
*
* \details This function will look for a given key in the user_conf_d
* dictionary. If the key is found it will return the value of that
@@ -159,10 +167,23 @@ char * get_conf_values(char * salida) {
// argument rather than using user_conf_d directly.
char * get_conf_value(char * key) {
- char * val = get(user_conf_d, key);
+ return get(user_conf_d, key);
+}
+
+/**
+ * \brief Retreive the integer value of a given key in user_conf_d
+ *
+ * \details This function will look for a given key in the user_conf_d
+ * dictionary. If the key is found it will return the value of that
+ * dictionary entry, or 0 otherwise.
+ *
+ * \param[in] key The key to search for in user_conf_d
+ *
+ * \return key value
+ */
+// TODO Make this function take a pointer to a dictionary as an
+// argument rather than using user_conf_d directly.
- if ( val == NULL || *(&val[0]) == '\0')
- return get(predefined_conf_d, key);
- else
- return val;
+int get_conf_int(char * key) {
+ return get_int(user_conf_d, key);
}
diff --git a/src/conf.h b/src/conf.h
index 057914d..57329ba 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -43,8 +43,8 @@
*/
extern struct dictionary * user_conf_d;
-extern struct dictionary * predefined_conf_d;
void store_default_config_values();
char * get_conf_value(char * key);
+int get_conf_int(char * key);
char * get_conf_values(char * salida);
diff --git a/src/file.c b/src/file.c
index 7ef633e..1578020 100644
--- a/src/file.c
+++ b/src/file.c
@@ -181,7 +181,7 @@ int file_exists(const char * fname) {
*/
int modcheck() {
- if (modflg && ! atoi(get_conf_value("nocurses"))) {
+ if (modflg && ! get_conf_int("nocurses")) {
sc_error("File not saved since last change. Add '!' to force");
return(1);
}
@@ -947,7 +947,7 @@ void closefile(FILE *f, int pid, int rfd) {
} else {
close(rfd);
#ifdef NCURSES
- if (! atoi(get_conf_value("nocurses"))) {
+ if (! get_conf_int("nocurses")) {
cbreak();
nonl();
noecho ();
@@ -975,7 +975,7 @@ void print_options(FILE *f) {
! rndtoeven &&
calc_order == BYROWS &&
prescale == 1.0 &&
- ! atoi(get_conf_value("external_functions")) &&
+ ! get_conf_int("external_functions") &&
tbl_style == 0
)
return; // No reason to do this
@@ -985,7 +985,7 @@ void print_options(FILE *f) {
if (rndtoeven) (void) fprintf(f, " rndtoeven");
if (calc_order != BYROWS ) (void) fprintf(f, " bycols");
if (prescale != 1.0) (void) fprintf(f, " prescale");
- if ( atoi(get_conf_value("external_functions")) ) (void) fprintf(f, " external_functions");
+ if ( get_conf_int("external_functions") ) (void) fprintf(f, " external_functions");
if (tbl_style) (void) fprintf(f, " tblstyle = %s", tbl_style == TBL ? "tbl" : tbl_style == LATEX ? "latex" : tbl_style == SLATEX ? "slatex" : tbl_style == TEX ? "tex" : tbl_style == FRAME ? "frame" : "0" );
(void) fprintf(f, "\n");
}
@@ -1069,7 +1069,7 @@ int import_csv(char * fname, char d) {
char * st = str_replace (token, "\"", "''"); //replace double quotes inside string
// number import
- if (strlen(st) && isnumeric(st) && ! atoi(get_conf_value("import_delimited_as_text"))
+ if (strlen(st) && isnumeric(st) && ! get_conf_int("import_delimited_as_text")
) {
//wide char
swprintf(line_interp, BUFFERSIZE, L"let %s%d=%s", coltoa(c), r, st);
@@ -1645,7 +1645,7 @@ void * do_autobackup() {
add_char(name, '.', pos+1);
sprintf(name + strlen(name), ".bak");
sprintf(namenew, "%.*s.new", PATHLEN-5, name);
- //if (atoi(get_conf_value("debug"))) sc_info("doing autobackup of file:%s", name);
+ //if (get_conf_int("debug")) sc_info("doing autobackup of file:%s", name);
// create new version
if (! strcmp(&name[strlen(name)-7], ".sc.bak")) {
@@ -1684,7 +1684,7 @@ void handle_backup() {
extern struct timeval lastbackup_tv; // last backup timer
extern struct timeval current_tv; //runtime timer
- int autobackup = atoi(get_conf_value ("autobackup"));
+ int autobackup = get_conf_int("autobackup");
if (autobackup && autobackup > 0 && (current_tv.tv_sec - lastbackup_tv.tv_sec > autobackup || (lastbackup_tv.tv_sec == 0 && lastbackup_tv.tv_usec == 0))) {
#ifdef HAVE_PTHREAD
if (pthread_exists) pthread_join (fthread, NULL);
diff --git a/src/gram.y b/src/gram.y
index 08e87bc..4299388 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -635,7 +635,7 @@ command:
| S_CELLCOLOR var_or_range STRING
{
#ifdef USECOLORS
- if ( ! atoi(get_conf_value("nocurses")))
+ if ( ! get_conf_int("nocurses"))
color_cell($2.left.vp->row, $2.left.vp->col, $2.right.vp->row, $2.right.vp->col, $3);
#endif
scxfree($3);
@@ -652,7 +652,7 @@ command:
| S_CELLCOLOR STRING {
#ifdef USECOLORS
- if ( ! atoi(get_conf_value("nocurses")))
+ if ( ! get_conf_int("nocurses"))
color_cell(currow, curcol, currow, curcol, $2);
#endif
scxfree($2);
@@ -660,13 +660,13 @@ command:
| S_UNFORMAT var_or_range {
#ifdef USECOLORS
- if ( ! atoi(get_conf_value("nocurses"))) unformat($2.left.vp->row, $2.left.vp->col, $2.right.vp->row, $2.right.vp->col);
+ if ( ! get_conf_int("nocurses")) unformat($2.left.vp->row, $2.left.vp->col, $2.right.vp->row, $2.right.vp->col);
#endif
}
| S_UNFORMAT {
#ifdef USECOLORS
- if ( ! atoi(get_conf_value("nocurses"))) unformat(currow, curcol, currow, curcol);
+ if ( ! get_conf_int("nocurses")) unformat(currow, curcol, currow, curcol);
#endif
}
diff --git a/src/input.c b/src/input.c
index d0a30c1..338500c 100644
--- a/src/input.c
+++ b/src/input.c
@@ -121,7 +121,7 @@ void handle_input(struct block * buffer) {
&& ( buffer->value == L'\0' || iswdigit((wchar_t) buffer->value))
&& ( curmode == NORMAL_MODE || curmode == VISUAL_MODE || curmode == EDIT_MODE )
&& ( cmd_multiplier || d != L'0' )
- && ( ! atoi(get_conf_value("numeric")))
+ && ( ! get_conf_int("numeric"))
) {
cmd_multiplier *= 10;
cmd_multiplier += (int) (d - '0');
diff --git a/src/interp.c b/src/interp.c
index 526ff75..4c9f6a5 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -1507,7 +1507,7 @@ char * doext(struct enode *se) {
command = seval(NULL, se->e.o.left);
value = eval(NULL, se->e.o.right);
- if ( ! atoi(get_conf_value("external_functions")) ) {
+ if ( ! get_conf_int("external_functions") ) {
sc_error("Warning: external functions disabled; using %s value",
(se->e.o.s && *se->e.o.s) ? "previous" : "null");
@@ -2182,7 +2182,7 @@ void str_search(char *s, int firstrow, int firstcol, int lastrow_, int lastcol_,
regex_t preg;
int errcode;
- if ( atoi(get_conf_value("ignorecase")))
+ if ( get_conf_int("ignorecase"))
errcode = regcomp(&preg, s, REG_EXTENDED | REG_ICASE);
else
errcode = regcomp(&preg, s, REG_EXTENDED);
diff --git a/src/main.c b/src/main.c
index e205b6e..47dca45 100644
--- a/src/main.c
+++ b/src/main.c
@@ -142,7 +142,6 @@ int rescol = RESCOL; /**< Columns reserved for row numbers */
struct block * buffer;
struct block * lastcmd_buffer;
struct dictionary * user_conf_d; /**< User's configuration dictionary */
-struct dictionary * predefined_conf_d; /**< Predefined configuration dictionary */
struct history * commandline_history;
struct history * insert_history;
char stderr_buffer[1024] = "";
@@ -197,23 +196,22 @@ int main (int argc, char ** argv) {
#endif
// start configuration dictionaries
- user_conf_d = (struct dictionary *) create_dictionary();
- predefined_conf_d = (struct dictionary *) create_dictionary();
+ user_conf_d = create_dictionary();
store_default_config_values(); // Stores default values in user_conf_d
// Read the main() parameters and replace values in user_conf_d as necessary
read_argv(argc, argv);
// check if help is in argv. if so, show usage and quit
- if (atoi((char *) get_conf_value("help"))) // atoi converts string to an int
+ if (get_conf_int("help"))
show_usage_and_quit();
// check if version is in argv. if so, show version and quit
- if (atoi((char *) get_conf_value("version"))) // atoi converts string to an int
+ if (get_conf_int("version"))
show_version_and_quit();
// create command line history structure
- if (! atoi((char *) get_conf_value("nocurses"))) {
+ if (! get_conf_int("nocurses")) {
#ifdef HISTORY_FILE
commandline_history = (struct history *) create_history(':');
load_history(commandline_history, ':'); // load the command history file
@@ -231,7 +229,7 @@ int main (int argc, char ** argv) {
if (! growtbl(GROWNEW, 0, 0)) return exit_app(1);
// initiate NCURSES if that is what is wanted
- if (! atoi((char *) get_conf_value("nocurses"))) {
+ if (! get_conf_int("nocurses")) {
ui_start_screen();
#ifdef USECOLORS
@@ -260,7 +258,7 @@ int main (int argc, char ** argv) {
return exit_app(-1);
}
- if (! atoi((char *) get_conf_value("nocurses"))) { // WE MUST STOP SCREEN!
+ if (! get_conf_int("nocurses")) { // WE MUST STOP SCREEN!
ui_stop_screen();
// if output is set, nocurses should always be 1 !
@@ -294,7 +292,7 @@ int main (int argc, char ** argv) {
// initiate ui
FILE * f;
- if ( ! atoi((char *) get_conf_value("nocurses"))) {
+ if ( ! get_conf_int("nocurses")) {
// we show welcome screen if no spreadsheet was passed to SC-IM
// and no input was sent throw pipeline
if ( ! curfile[0] && ! wcslen(stdin_buffer)) {
@@ -312,7 +310,7 @@ int main (int argc, char ** argv) {
}
// handle input from keyboard
- if (! atoi((char *) get_conf_value("nocurses")))
+ if (! get_conf_int("nocurses"))
buffer = (struct block *) create_buf(); // this should only take place if curses ui
wchar_t nocurses_buffer[BUFFERSIZE];
@@ -342,7 +340,7 @@ int main (int argc, char ** argv) {
}
- while ( ! shall_quit && ! atoi((char *) get_conf_value("quit_afterload"))) {
+ while ( ! shall_quit && ! get_conf_int("quit_afterload")) {
// save current time for runtime timer
gettimeofday(&current_tv, NULL);
@@ -350,7 +348,7 @@ int main (int argc, char ** argv) {
handle_backup();
// if we are in ncurses
- if (! atoi((char *) get_conf_value("nocurses"))) {
+ if (! get_conf_int("nocurses")) {
handle_input(buffer);
// if we are not in ncurses
@@ -363,7 +361,7 @@ int main (int argc, char ** argv) {
shall_quit=2 means :q! */
if (shall_quit == 1 && modcheck()) shall_quit = 0;
}
- if (atoi((char *) get_conf_value("nocurses")) && f != NULL) fclose(f);
+ if (get_conf_int("nocurses") && f != NULL) fclose(f);
return shall_quit == -1 ? exit_app(-1) : exit_app(0);
}
@@ -487,7 +485,7 @@ void delete_structures() {
int exit_app(int status) {
// free history
- if (! atoi((char *) (get_conf_value("nocurses")))) {
+ if (! get_conf_int("nocurses")) {
#ifdef HISTORY_FILE
if (! save_history(commandline_history, "w")) sc_error("Could not save commandline history");
@@ -520,7 +518,7 @@ int exit_app(int status) {
erase_buf(buffer);
// stop CURSES screen
- if (! atoi((char *) (get_conf_value("nocurses"))))
+ if (! get_conf_int("nocurses"))
ui_stop_screen();
// close fdoutput
@@ -528,8 +526,7 @@ int exit_app(int status) {
fclose(fdoutput);
}
- // delete user and predefined config dictionaries</