summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/doc9
-rw-r--r--src/file.c36
-rw-r--r--src/main.c12
3 files changed, 41 insertions, 16 deletions
diff --git a/src/doc b/src/doc
index f70eab5..9a4867e 100755
--- a/src/doc
+++ b/src/doc
@@ -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:
diff --git a/src/file.c b/src/file.c
index f9f5f06..c042450 100644
--- a/src/file.c
+++ b/src/file.c
@@ -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);
diff --git a/src/main.c b/src/main.c
index 0352c0c..2b926e3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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(&current_tv, NULL);