diff options
author | mongo <andmarti@gmail.com> | 2017-04-07 10:30:56 -0300 |
---|---|---|
committer | mongo <andmarti@gmail.com> | 2017-04-07 10:30:56 -0300 |
commit | 9ac9aa8fcacc09bc197b283ce309b45bbd9489be (patch) | |
tree | 95566d7616611da8b76a9cdaaf6921678f7174ac /src/file.c | |
parent | bc759e2971d4e1216e698d04cf7410f99f3266dd (diff) |
fix in savefile and import_csv
Diffstat (limited to 'src/file.c')
-rw-r--r-- | src/file.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -138,15 +138,29 @@ int savefile() { } // add sc extension if not present - if (wcslen(inputline) > 2 && str_in_str(curfile, ".") == -1) + if (wcslen(inputline) > 2 && str_in_str(curfile, ".") == -1) { sprintf(curfile + strlen(curfile), ".sc"); + // treat csv + } else if (strlen(curfile) > 4 && (! strcasecmp( & curfile[strlen(curfile)-4], ".csv"))) { + export_delim(curfile, ',', 0, 0, maxrow, maxcol); + modflg = 0; + wordfree(&p); + return 0; + // treat tab + } else if (strlen(curfile) > 4 && (! strcasecmp( & curfile[strlen(curfile)-4], ".tsv") || + ! strcasecmp( & curfile[strlen(curfile)-4], ".tab"))){ + export_delim(curfile, '\t', 0, 0, maxrow, maxcol); + modflg = 0; + wordfree(&p); + return 0; + } + // save in sc format if (writefile(curfile, 0, 0, maxrow, maxcol) < 0) { sc_error("File could not be saved"); wordfree(&p); return -1; } - wordfree(&p); return 0; } @@ -726,7 +740,7 @@ void print_options(FILE *f) { int import_csv(char * fname, char d) { register FILE * f; - int r = 0, c = 0; + int r = 0, c = 0, cf = 0; wchar_t line_interp[FBUFLEN] = L""; char * token; @@ -784,19 +798,16 @@ int import_csv(char * fname, char d) { ) { //wide char swprintf(line_interp, BUFFERSIZE, L"let %s%d=%s", coltoa(c), r, st); - //sprintf(line_in, "let %s%d=%s", coltoa(c), r, st); // text import } else if (strlen(st)){ //wide char swprintf(line_interp, BUFFERSIZE, L"label %s%d=\"%s\"", coltoa(c), r, st); - //sprintf(line_in, "label %s%d=\"%s\"", coltoa(c), r, st); } //wide char if (strlen(st)) send_to_interp(line_interp); - //if (strlen(st)) send_to_interpp(line_in); - c++; + if (++c > cf) cf = c; quote = 0; token = xstrtok(NULL, delim); free(st); @@ -806,7 +817,7 @@ int import_csv(char * fname, char d) { if (r > MAXROWS - GROWAMT - 1 || c > ABSMAXCOLS - 1) break; } maxrow = r-1; - maxcol = c-1; + maxcol = cf-1; auto_justify(0, maxcols, DEFWIDTH); |