summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2020-04-15 20:52:23 +0100
committerFreeArtMan <dos21h@gmail.com>2020-04-15 20:52:23 +0100
commitef29d288ed57250b399d6a95cf26a40d4e33794e (patch)
tree10b124d73cc6bef42fba56abdf8f65fc277bcc8e
parent6c44c2e89000444b1bdf790452fd1b92d121ed06 (diff)
downloadihe-master.tar.gz
ihe-master.zip
Open file with space in filenameHEADmaster
-rw-r--r--Makefile4
-rw-r--r--cmd/cmd_open.c15
-rw-r--r--util.c33
-rw-r--r--util.h13
4 files changed, 61 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 5f6e0f0..8020f78 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
PROJECT=ihe
CC=gcc
CPP=g++
-CFLAGS=-I./ -I./libbuf -Wwrite-strings -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables
-SOURCES=core.c
+CFLAGS=-g3 -I./ -I./libbuf -Wwrite-strings -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables -std=c11
+SOURCES=core.c util.c
SOURCES+=$(wildcard cmd/*.c)
OBJECTS=$(SOURCES:.c=.o)
LIB_OBJECTS=libcmd/libcmd.o libterm/libterm.o h64e/core.o libbuf/libbuf.o
diff --git a/cmd/cmd_open.c b/cmd/cmd_open.c
index d758598..ebec8c1 100644
--- a/cmd/cmd_open.c
+++ b/cmd/cmd_open.c
@@ -1,5 +1,6 @@
#include "buf.h"
#include "core.h"
+#include "util.h"
#include "libcmd/cmd.h"
#include "libcmd/cmd_parse.h"
@@ -16,6 +17,7 @@ int c_open( cmd_arg_t *arg )
int argc = arg->argc;
char **argv = arg->argv;
+ int *type = arg->type;
char *fname = NULL;
int fret = 0;
@@ -25,11 +27,20 @@ int c_open( cmd_arg_t *arg )
return -1;
}
- fname = argv[0];
- printf("%s\n",fname);
+ //fname = argv[0];
+ if (type[0] == CMDT_QSTR)
+ {
+ fname = alloc_new_str(argv[0]+1);
+ fname[strlen(argv[0])-2] = 0x0;
+ } else {
+ fname = alloc_new_str(argv[0]);
+ }
+
+ printf("fname %s\n",fname);
fret = file_open_fn( g_file, fname, g_flags ); //!if failure fields could be non empty inside struct
+ free(fname);fname=NULL;
if ( fret < 0 )
{
printf("Cannot open file %s\n",fname);
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..ebd264c
--- /dev/null
+++ b/util.c
@@ -0,0 +1,33 @@
+#include "util.h"
+
+char *alloc_new_str_s(char *str, size_t size)
+{
+ char *ret = NULL;
+
+ if (str == NULL)
+ {
+ return NULL;
+ }
+
+ //1MB is enought
+ if (size > (1024*1024))
+ {
+ return NULL;
+ }
+
+ ret = malloc(size+1); //extra for 1 zero at then end
+ if (ret == NULL)
+ {
+ return NULL;
+ }
+
+ memcpy(ret, str, size);
+ ret[size] = 0; //add zero at the end
+
+ return ret;
+}
+
+char *alloc_new_str(char *str)
+{
+ return alloc_new_str_s(str, strlen(str));
+}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..1af317f
--- /dev/null
+++ b/util.h
@@ -0,0 +1,13 @@
+#ifndef __UTIL_H
+#define __UTIL_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+char *alloc_new_str_s(char *str, size_t size);
+char *alloc_new_str(char *str);
+
+#endif \ No newline at end of file