aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-01-28 09:44:11 +0100
committerCamil Staps2016-01-28 09:45:19 +0100
commit93598fef1ea487d76af29eb0f0e6bd8e82dc2be8 (patch)
treef3864935bfc9eb5a69b2c6d24e8851b1b3b1c616
parentMerge pull request #1 from dopefishh/master (diff)
Removed duplicate code; improved Makefile
-rw-r--r--Makefile17
-rw-r--r--compile.c44
2 files changed, 33 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 392730f..eb29c9a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,8 @@
+CFLAGS=-std=c99 -Wall -O0 -c
+CLM=clm
+CLMFLAGS=-I CleanReadLine -l -lreadline -l compile.o
+RUNFLAGS=-nr -nt
+
all: iclean
clean:
@@ -5,14 +10,18 @@ clean:
make -C CleanReadLine clean
compile.o: compile.c
- cc -O0 -c compile.c
+ $(CC) $(CFLAGS) compile.c
iclean: compile.o iclean.icl readline
- clm -I CleanReadLine -l -lreadline -l compile.o iclean -o iclean
+ $(CLM) $(CLMFLAGS) iclean -o iclean
-readline:
+readline: FORCE
make -C CleanReadLine
run: iclean
- ./iclean -nr -nt
+ ./iclean $(RUNFLAGS)
+
+FORCE:
+
+.PHONY: FORCE clean run
diff --git a/compile.c b/compile.c
index d0a3ee0..0240698 100644
--- a/compile.c
+++ b/compile.c
@@ -31,6 +31,19 @@
#include <string.h>
#include "Clean.h"
+char* cleanstoc(CleanString s) {
+ char* cs = calloc(sizeof(char), CleanStringLength(s) + 1);
+ if (cs == NULL)
+ return NULL;
+
+ int i;
+ for (i = 0; i < CleanStringLength(s); i++)
+ cs[i] = CleanStringCharacters(s)[i];
+ cs[i] = '\0';
+
+ return cs;
+}
+
/**
* Compile a Clean module in a path
*
@@ -44,39 +57,22 @@
*/
int64_t compile(CleanString path, CleanString module) {
char* pathchars, * modulechars;
- int pathlength, modulelength;
- // Copy from CleanString to normal char[]
- pathlength = CleanStringLength(path);
- modulelength = CleanStringLength(module);
-
- pathchars = calloc(sizeof(char), pathlength + 1);
- modulechars = calloc(sizeof(char), pathlength + 1);
+ pathchars = cleanstoc(path);
+ modulechars = cleanstoc(module);
+
if (modulechars == NULL || pathchars == NULL) {
printf("Couldn't allocate memory\n");
exit(-1);
}
- int i;
- for (i=0;i<modulelength;i++)
- modulechars[i] = CleanStringCharacters(module)[i];
- modulechars[i] = 0x00;
-
- for (i=0;i<pathlength;i++)
- pathchars[i] = CleanStringCharacters(path)[i];
- pathchars[i] = 0x00;
-
// Build command:
// cd "<path>" && clm -ms <module> -o <module>
char cmd[64] = "cd \"";
- strcat(cmd, pathchars);
- strcat(cmd, "\" && clm -ms -nw ");
- strcat(cmd, modulechars);
- strcat(cmd, " -o ");
- strcat(cmd, modulechars);
+ snprintf(cmd, 64, "cd \"%s\" && clm -ms -nw %s -o %s", pathchars, modulechars, modulechars);
- free(pathchars);
- free(modulechars);
+ free(pathchars);
+ free(modulechars);
// Call clm
return system(cmd);
@@ -114,6 +110,6 @@ void run(CleanString executable) {
// <module> -nt
strcat(execchars, " -nt");
system(execchars);
- free(execchars);
+ free(execchars);
}