summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2016-09-08 21:08:14 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2016-09-08 21:08:14 +0200
commit662f22a41f659055f7d28ad191f957caef316ee6 (patch)
tree469b24a5ec16c231e57d887caf2b46b2195bd5ea
parent4ed7eae68357dca42a6cf866e5ac160d1c9a03c4 (diff)
Expand filenames using wordexp
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
-rw-r--r--src/cmds_command.c13
-rw-r--r--src/main.c8
2 files changed, 15 insertions, 6 deletions
diff --git a/src/cmds_command.c b/src/cmds_command.c
index 09574c7..77c4d04 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -4,6 +4,7 @@
#include <wchar.h>
#include <stdlib.h>
#include <ctype.h> // for isprint()
+#include <wordexp.h>
#include "sc.h" // for rescol
#include "color.h" // for set_ucolor
#include "conf.h"
@@ -337,28 +338,32 @@ void do_commandmode(struct block * sb) {
} else if ( ! wcsncmp(inputline, L"load", 4) ) {
char cline [BUFFERSIZE];
int force_rewrite = 0;
+ wordexp_t p;
wcstombs(cline, inputline, BUFFERSIZE);
-
if ( ! wcsncmp(inputline, L"load! ", 6) ) {
force_rewrite = 1;
del_range_chars(cline, 4, 4);
}
del_range_chars(cline, 0, 4);
+ wordexp(cline, &p, 0);
if ( ! strlen(cline) ) {
sc_error("Path to file to load is missing !");
+ } else if ( p.we_wordc < 1 ) {
+ sc_error("Failed expanding filepath");
} else if ( modflg && ! force_rewrite ) {
sc_error("Changes were made since last save. Use '!' to force the load");
- } else if ( ! file_exists(cline)) {
- sc_error("File %s does not exists!", cline);
+ } else if ( ! file_exists(p.we_wordv[0])) {
+ sc_error("File %s does not exists!", p.we_wordv[0]);
} else {
delete_structures();
create_structures();
- readfile(cline, 0);
+ readfile(p.we_wordv[0], 0);
//EvalAll(); // is it necessary?
modflg = 0;
update(TRUE);
}
+ wordfree(&p);
} else if ( ! wcsncmp(inputline, L"hiderow ", 8) ||
! wcsncmp(inputline, L"showrow ", 8) ||
diff --git a/src/main.c b/src/main.c
index 9efe202..3c7bd25 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,6 +8,7 @@
#include <fcntl.h> // for F_GETFL O_NONBLOCK F_SETFL
#include <locale.h>
#include <wchar.h>
+#include <wordexp.h>
#include "main.h"
#include "shift.h"
@@ -356,9 +357,12 @@ void load_sc() {
if (! curfile[0]) { // there was no file passed to scim executable
erasedb();
} else {
- if (! readfile(curfile, 1) && ! atoi(get_conf_value("nocurses"))) {
- sc_info("New file: \"%s\"", curfile); // file passed to scim executable does not exists
+ wordexp_t p;
+ wordexp(curfile, &p, 0);
+ if (! readfile(p.we_wordv[0], 1) && ! atoi(get_conf_value("nocurses"))) {
+ sc_info("New file: \"%s\"", p.we_wordv[0]); // file passed to scim executable does not exists
}
+ wordfree(&p);
EvalAll(); // we eval formulas
}
return;