summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--examples/xlsx/t3_b.xlsxbin0 -> 6227 bytes
-rw-r--r--src/clipboard.c43
-rw-r--r--src/cmds/cmds.c22
-rw-r--r--src/cmds/cmds_command.c20
-rw-r--r--src/conf.c82
-rw-r--r--src/conf.h2
-rw-r--r--src/help.c2
8 files changed, 141 insertions, 35 deletions
diff --git a/CHANGES b/CHANGES
index a240d25..b6946db 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,7 +27,6 @@ Changes:
+ marks now considers sheet. We could have mark A in Sheet 1, and mark B on Sheet 2..
modified tick() and fix_marks()
Renamed auto_justify to auto_fit
-UI optimizations
`gt` command of NORMAL_MODE renamed to `go`
Removed --sheet and --filename_with_mode configuration variables
UNDO now saves reference to the sheet where the action took place.
@@ -39,6 +38,9 @@ Modified yanklist to be struct ent_ptr list, rather thant struct ent list.
Ents_that_depends_on_list now takes ent_ptr rather than struct ent * as parameter
Backslash double quotes in cpaste. Issue 574.
Do not free ents of sheets when deleting a sheet manually (only at exit). just mark them as deleted.
+Inform old value and new value when changing configuration variable
+UI optimizations
+Simplify clipboard code
Fixes
-----
@@ -55,6 +57,7 @@ Avoid reading passed maxcols maxrows when shifting left or up over last sheet co
fix in Pv when pasting over same place where data was yanked.
fix in paste_yanked_ents: calloc didnt count that yanked cells could share dependencies.
fix a bug when refreshing grid when autowrap operates. Issue 578.
+Avoid segfault in autobackup when no current file is set.
Pending to make v0.8.3 release
diff --git a/examples/xlsx/t3_b.xlsx b/examples/xlsx/t3_b.xlsx
new file mode 100644
index 0000000..f037c6d
--- /dev/null
+++ b/examples/xlsx/t3_b.xlsx
Binary files differ
diff --git a/src/clipboard.c b/src/clipboard.c
index c121f01..889d454 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -66,7 +66,8 @@ extern struct session * session;
*/
int paste_from_clipboard() {
struct roman * roman = session->cur_doc;
- if (! strlen(get_conf_value("default_paste_from_clipboard_cmd"))) return -1;
+ char *clipboard_cmd = get_conf_value("default_paste_from_clipboard_cmd");
+ if (!clipboard_cmd || !*clipboard_cmd) return -1;
// create tmp file
char template[] = "/tmp/sc-im-clipboardXXXXXX";
@@ -80,9 +81,14 @@ int paste_from_clipboard() {
//FILE * fpori = fdopen(fd, "w");
// copy content from clipboard to temp file
- char syscmd[PATHLEN + strlen(get_conf_value("default_paste_from_clipboard_cmd")) + 1];
- sprintf(syscmd, "%s", get_conf_value("default_paste_from_clipboard_cmd"));
- sprintf(syscmd + strlen(syscmd), " >> %s", template);
+ char syscmd[PATHLEN];
+ int ret = snprintf(syscmd, PATHLEN, "%s >> %s", clipboard_cmd, template);
+ if (ret < 0 || ret >= PATHLEN) {
+ sc_error("Error while pasting from clipboard");
+ ret = -1;
+ goto out;
+ }
+ ret = 0;
system(syscmd);
// traverse the temp file
@@ -126,12 +132,13 @@ int paste_from_clipboard() {
}
sc_info("Content pasted from clipboard");
+out:
// close file descriptor
close(fd);
// remove temp file
unlink(template);
- return 0;
+ return ret;
}
@@ -140,7 +147,8 @@ int paste_from_clipboard() {
* \return 0 on success; -1 on error
*/
int copy_to_clipboard(int r0, int c0, int rn, int cn) {
- if (! strlen(get_conf_value("default_copy_to_clipboard_cmd"))) return -1;
+ char *clipboard_cmd = get_conf_value("default_copy_to_clipboard_cmd");
+ if (!clipboard_cmd || !*clipboard_cmd) return -1;
// create tmp file
char template[] = "/tmp/sc-im-clipboardXXXXXX";
@@ -158,12 +166,16 @@ int copy_to_clipboard(int r0, int c0, int rn, int cn) {
fclose(fp);
// copy to clipboard
- char syscmd[PATHLEN + strlen(get_conf_value("default_copy_to_clipboard_cmd")) + 1];
- sprintf(syscmd, "%s", get_conf_value("default_copy_to_clipboard_cmd"));
- sprintf(syscmd + strlen(syscmd), " %s", template);
- system(syscmd);
-
- sc_info("Content copied to clipboard");
+ char syscmd[PATHLEN];
+ int ret = snprintf(syscmd, PATHLEN, "%s %s", clipboard_cmd, template);
+ if (ret < 0 || ret >= PATHLEN) {
+ sc_error("Error while copying to clipboard");
+ ret = -1;
+ } else {
+ system(syscmd);
+ sc_info("Content copied to clipboard");
+ ret = 0;
+ }
// close file descriptor
close(fd);
@@ -171,7 +183,7 @@ int copy_to_clipboard(int r0, int c0, int rn, int cn) {
// remove temp file
unlink(template);
- return 0;
+ return ret;
}
@@ -190,6 +202,7 @@ int copy_to_clipboard(int r0, int c0, int rn, int cn) {
int save_plain(FILE * fout, int r0, int c0, int rn, int cn) {
if (fout == NULL) return -1;
struct roman * roman = session->cur_doc;
+ int conf_clipboard_delimited_tab = get_conf_int("copy_to_clipboard_delimited_tab");
int row, col;
register struct ent ** pp;
wchar_t out[FBUFLEN] = L"";
@@ -250,7 +263,7 @@ int save_plain(FILE * fout, int r0, int c0, int rn, int cn) {
if(emptyfield){
fwprintf(fout, L"\t");
}
- if (! get_conf_int("copy_to_clipboard_delimited_tab")) {
+ if (! conf_clipboard_delimited_tab) {
pad_and_align(text, num, roman->cur_sh->fwidth[col], align, 0, out, roman->cur_sh->row_format[row]);
fwprintf(fout, L"%ls", out);
} else if ( (*pp)->flags & is_valid) {
@@ -258,7 +271,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 (! get_conf_int("copy_to_clipboard_delimited_tab")) {
+ } else if (! conf_clipboard_delimited_tab) {
fwprintf(fout, L"%*s", roman->cur_sh->fwidth[col], " ");
} else {
fwprintf(fout, L"\t");
diff --git a/src/cmds/cmds.c b/src/cmds/cmds.c
index cc24180..a1430e8 100644
--- a/src/cmds/cmds.c
+++ b/src/cmds/cmds.c
@@ -2529,6 +2529,7 @@ int calc_mobile_rows(struct sheet * sh, int *last_p) {
mobile_rows = 0;
last = sh->offscr_sc_rows;
for (i = sh->offscr_sc_rows; i < sh->maxrows; i++) {
+ count_rows_downward:
if (sh->row_hidden[i])
continue;
if (sh->row_frozen[i])
@@ -2560,6 +2561,16 @@ int calc_mobile_rows(struct sheet * sh, int *last_p) {
last = i;
}
sh->offscr_sc_rows = last;
+ last = sh->currow;
+
+ /*
+ * Yet if the rows to follow have a smaller height than those we just
+ * counted then maybe they could fill the remaining space at the
+ * bottom edge of the screen.
+ */
+ i = last + 1;
+ if (row_space > 0 && i < sh->maxrows)
+ goto count_rows_downward;
}
if (last_p)
@@ -2618,6 +2629,7 @@ int calc_mobile_cols(struct sheet * sh, int *last_p) {
mobile_cols = 0;
last = sh->offscr_sc_cols;
for (i = sh->offscr_sc_cols; i < sh->maxcols; i++) {
+ count_cols_rightward:
if (sh->col_hidden[i])
continue;
if (sh->col_frozen[i])
@@ -2649,6 +2661,16 @@ int calc_mobile_cols(struct sheet * sh, int *last_p) {
last = i;
}
sh->offscr_sc_cols = last;
+ last = sh->curcol;
+
+ /*
+ * Yet if the columns to follow have a smaller width than those we
+ * just counted then maybe they could fill the remaining space at the
+ * right edge of the screen.
+ */
+ i = last + 1;
+ if (col_space > 0 && i < sh->maxcols)
+ goto count_cols_rightward;
}
if (last_p)
diff --git a/src/cmds/cmds_command.c b/src/cmds/cmds_command.c
index 7c29f1c..c20837f 100644
--- a/src/cmds/cmds_command.c
+++ b/src/cmds/cmds_command.c
@@ -914,25 +914,9 @@ void do_commandmode(struct block * sb) {
wcscpy(interp_line, inputline);
send_to_interp(interp_line);
+ // Change a config value
} else if ( ! wcsncmp(inputline, L"set ", 4) ) {
- wchar_t line [BUFFERSIZE];
- wcscpy(line, inputline);
- del_range_wchars(line, 0, 3);
-
- wchar_t * l;
- char oper[BUFFERSIZE];
- if ((l = wcschr(line, L' ')) != NULL) l[0] = L'\0';
- if ((l = wcschr(line, L'=')) != NULL) l[0] = L'\0';
-
- wcscpy(interp_line, inputline);
- send_to_interp(interp_line);
-
- wcstombs(oper, line, BUFFERSIZE);
- if (get_conf_value(oper)) {
- sc_info("Config value changed: %s", oper);
- } else if (strlen(oper) > 2 && ! wcsncmp(inputline, L"set no", 6)) {
- sc_info("Config value changed: %s", &oper[2]);
- }
+ change_config_parameter(inputline);
} else if ( ! wcsncmp(inputline, L"pad ", 4) ) {
int c = sh->curcol, cf = sh->curcol;
diff --git a/src/conf.c b/src/conf.c
index 615128d..5fa321b 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -50,6 +50,7 @@
#include <string.h>
#include <time.h>
#include "conf.h"
+#include "sc.h"
#include "utils/dictionary.h"
@@ -195,3 +196,84 @@ char * get_conf_value(const char * key) {
int get_conf_int(const char * key) {
return get_int(user_conf_d, key);
}
+
+
+/* \brief change_config_parameter
+ * parameter[in] char * cmd
+ * return int:
+ * 0 if config parameter changed
+ * 1 if config parameter was valid but previous and new values are the same
+ * -1 on error
+ */
+#include <wchar.h>
+#include <string.h>
+#include "macros.h"
+#include "cmds/cmds.h"
+#include "utils/string.h"
+#include "tui.h"
+int change_config_parameter(wchar_t * inputline) {
+ extern wchar_t interp_line[BUFFERSIZE];
+
+ // remove "set "
+ wchar_t line [BUFFERSIZE];
+ wcscpy(line, inputline);
+ del_range_wchars(line, 0, 3);
+
+ // parse value
+ wchar_t * l;
+ if ((l = wcschr(line, L' ')) != NULL) l[0] = L'\0';
+ if ((l = wcschr(line, L'=')) != NULL) l[0] = L'\0';
+
+ // check a proper config parameter exists
+ char oper[BUFFERSIZE];
+ wcstombs(oper, line, BUFFERSIZE);
+ // sent garbage after "set "..
+ if (! strlen(oper)) {
+ sc_error("Invalid command: \'%ls\'", inputline);
+ return -1;
+ }
+ char * value_bef = malloc(sizeof(char)*90);
+ value_bef[0] = '\0';
+ char * key = malloc(sizeof(char)*90);
+ key[0] = '\0';
+ char * value_aft = malloc(sizeof(char)*90);
+ value_aft[0] = '\0';
+
+ strcpy(key, oper);
+ char * s_aux = get_conf_value(key);
+ if (s_aux != NULL) strcpy(value_bef, get_conf_value(key));
+ if ((! value_bef || ! strlen(value_bef)) && strlen(oper) > 2 && ! wcsncmp(inputline, L"set no", 6)) {
+ s_aux = get_conf_value(&oper[2]);
+ if (s_aux != NULL) {
+ strcpy(value_bef, s_aux);
+ strcpy(key, &oper[2]);
+ }
+ }
+
+ if (! value_bef || ! strlen(value_bef)) {
+ sc_error("Invalid config variable: \'%s\'", oper);
+ free(value_aft);
+ free(value_bef);
+ free(key);
+ return -1;
+ }
+
+ // we try to change config value
+ wcscpy(interp_line, inputline);
+ send_to_interp(interp_line);
+ s_aux = get_conf_value(key);
+ if (s_aux != NULL) strcpy(value_aft, s_aux);
+ // check it was changed
+ if (! strcmp(value_bef, value_aft)) { sc_info("Config variable \'%s\' unchanged. Current value is \'%s\'", key, value_aft);
+ free(value_aft);
+ free(value_bef);
+ free(key);
+ return 1;
+ }
+ // inform so
+ sc_info("Config variable \'%s\' changed. Value \'%s\' to \'%s\'", key, value_bef, value_aft);
+ free(value_aft);
+ free(value_bef);
+ free(key);
+ return 0;
+}
diff --git a/src/conf.h b/src/conf.h
index d81343b..4f656f6 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -42,9 +42,11 @@
* @brief Header file for conf.c
*/
+#include <wchar.h>
extern struct dictionary * user_conf_d;
void store_default_config_values();
char * get_conf_value(const char * key);
int get_conf_int(const char * key);
+int change_config_parameter(wchar_t * inputline);
char * get_conf_values(char * salida);
diff --git a/src/help.c b/src/help.c
index 1967299..9eb3df9 100644
--- a/src/help.c
+++ b/src/help.c
@@ -594,4 +594,4 @@ void show_usage_and_quit(){
put(user_conf_d, "quit_afterload", "1");
}
-char * rev = "version 0.8.3-main";
+char * rev = "version 0.8.3-dev";