diff options
-rwxr-xr-x | src/doc | 9 | ||||
-rw-r--r-- | src/file.c | 36 | ||||
-rw-r--r-- | src/main.c | 12 |
3 files changed, 41 insertions, 16 deletions
@@ -1452,6 +1452,11 @@ Commands for handling cell content: You can set the --output parameter to save the results to a file. + Export to csv, tab or plain text formats without interaction: + ./sc-im --quit_afterload --nocurses --export_csv + ./sc-im --quit_afterload --nocurses --export_tab + ./sc-im --quit_afterload --nocurses --export_txt # (or just --export) + If you set the --quit_afterload flag, SC-IM will quit after loading all files, but before becoming interactive. @@ -1715,6 +1720,4 @@ Commands for handling cell content: NEWLINE_ACTION = {NUMBER} TM_GMTOFF TM_GMTOFF = {num} - - -vim:tw=78:ts=8:ft=help:norl: + vim:tw=78:ts=8:ft=help:norl: @@ -1283,12 +1283,16 @@ void export_plain(char * fname, int r0, int c0, int rn, int cn) { int pid; wchar_t out[FBUFLEN] = L""; - sc_info("Writing file \"%s\"...", fname); - - if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) { - sc_error ("Can't create file \"%s\"", fname); - return; + if (fname == NULL) + f = stdout; + else { + sc_info("Writing file \"%s\"...", fname); + if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) { + sc_error ("Can't create file \"%s\"", fname); + return; + } } + struct ent * ent = go_end(); if (rn > ent->row) rn = ent->row; @@ -1349,10 +1353,11 @@ void export_plain(char * fname, int r0, int c0, int rn, int cn) { } (void) fprintf(f,"\n"); } - closefile(f, pid, 0); - - if (! pid) { - sc_info("File \"%s\" written", fname); + if (fname != NULL) { + closefile(f, pid, 0); + if (! pid) { + sc_info("File \"%s\" written", fname); + } } } @@ -1381,9 +1386,13 @@ void export_delim(char * fname, char coldelim, int r0, int c0, int rn, int cn, i if (verbose) sc_info("Writing file \"%s\"...", fname); - if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) { - if (verbose) sc_error ("Can't create file \"%s\"", fname); - return; + if (fname == NULL) + f = stdout; + else { + if ((f = openfile(fname, &pid, NULL)) == (FILE *)0) { + if (verbose) sc_error ("Can't create file \"%s\"", fname); + return; + } } struct ent * ent = go_end(); @@ -1423,7 +1432,8 @@ void export_delim(char * fname, char coldelim, int r0, int c0, int rn, int cn, i } (void) fprintf(f,"\n"); } - closefile(f, pid, 0); + if (fname != NULL) + closefile(f, pid, 0); if (! pid && verbose) { sc_info("File \"%s\" written", fname); @@ -321,6 +321,18 @@ int main (int argc, char ** argv) { lastbackup_tv = (struct timeval) {0}; #endif + if (get_conf_value("export_csv")) { + export_delim(NULL, ',', 0, 0, maxrow, maxcol, 0); + } + + if (get_conf_value("export_tab")) { + export_delim(NULL, '\t', 0, 0, maxrow, maxcol, 0); + } + + if (get_conf_value("export") || get_conf_value("export_txt")) { + export_plain(NULL, 0, 0, maxrow, maxcol); + } + while ( ! shall_quit && ! atoi((char *) get_conf_value("quit_afterload"))) { // save current time for runtime timer gettimeofday(¤t_tv, NULL); |