summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--examples/add8.qua86
-rw-r--r--examples/add8test.qua2
-rw-r--r--examples/and.qua2
-rw-r--r--examples/andtest.qua8
-rw-r--r--examples/full.qua6
-rw-r--r--examples/fulltest.qua16
-rw-r--r--examples/half.qua4
-rw-r--r--examples/halftest.qua8
-rw-r--r--examples/nottest.qua2
-rw-r--r--examples/or.qua4
-rw-r--r--examples/ortest.qua8
-rw-r--r--examples/xor.qua4
-rw-r--r--examples/xortest.qua8
-rwxr-xr-xqualumsbin34760 -> 35224 bytes
-rw-r--r--src/Color.cpp2
-rw-r--r--src/Color.h2
-rw-r--r--src/main.cpp74
18 files changed, 140 insertions, 98 deletions
diff --git a/Makefile b/Makefile
index e8e99f3..679c102 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
C=g++
-FLAGS=-std=c++11 -Wno-write-strings `pkg-config --libs --cflags sdl2`
+FLAGS=-std=c++11 `pkg-config --libs --cflags sdl2`
default: all
diff --git a/examples/add8.qua b/examples/add8.qua
index f52008b..dfbf80a 100644
--- a/examples/add8.qua
+++ b/examples/add8.qua
@@ -72,14 +72,14 @@ x y speedX speedY color
35 4 0 0 CY
-35 17 0 0 !examples/half.qua # Outputs to 33/34, 43
+35 17 0 0 !half.qua # Outputs to 33/34, 43
# Redirect last digit of answer
34 44 0 0 GA
40 44 0 0 GA
40 -3 0 0 PU
39 -3 0 0 RE
## Delay rest of bits while first pair is adding
-0 0 0 0 !examples/add8rect1.qua
+0 0 0 0 !add8rect1.qua
## Second pair
# Redirect carry in
33 45 0 0 GA
@@ -124,14 +124,14 @@ x y speedX speedY color
62 1 0 0 PU
62 0 0 0 RE
# Add
-60 10 0 0 !examples/full.qua # Outputs to 63/64, 87
+60 10 0 0 !full.qua # Outputs to 63/64, 87
# Redirect sum
64 90 0 0 GA
77 90 0 0 GA
77 -4 0 0 PU
76 -4 0 0 RE
## Delay other bits while second pair is adding
-0 8 0 0 !examples/add8rect2.qua
+0 8 0 0 !add8rect2.qua
## Third pair
# Redirect carry in
63 91 0 0 GA
@@ -173,7 +173,7 @@ x y speedX speedY color
96 3 0 0 CY
95 8 0 0 CY
# Add
-95 10 0 0 !examples/full.qua # Outputs to 98/99, 87
+95 10 0 0 !full.qua # Outputs to 98/99, 87
# Redirect sum
99 90 0 0 GA
112 90 0 0 GA
@@ -188,7 +188,7 @@ x y speedX speedY color
132 1 0 0 PU
132 0 0 0 RE
# Delay while last bits are adding
-0 24 0 0 !examples/add8rect3.qua
+0 24 0 0 !add8rect3.qua
# Redirect bits
-3 94 0 0 GA
-12 95 0 0 GA
@@ -224,7 +224,7 @@ x y speedX speedY color
116 83 0 0 CY
116 82 0 0 CY
# Add
-130 10 0 0 !examples/full.qua # Outputs to 133/134, 87
+130 10 0 0 !full.qua # Outputs to 133/134, 87
# Redirect sum
134 90 0 0 GA
147 90 0 0 GA
@@ -239,7 +239,7 @@ x y speedX speedY color
167 1 0 0 PU
167 0 0 0 RE
# Delay while last bits are adding
-0 44 0 0 !examples/add8rect4.qua
+0 44 0 0 !add8rect4.qua
# Redirect bits
-4 96 0 0 GA
-13 97 0 0 GA
@@ -277,7 +277,7 @@ x y speedX speedY color
151 82 0 0 CY
151 81 0 0 CY
# Add
-165 10 0 0 !examples/full.qua # Outputs to 168/169, 87
+165 10 0 0 !full.qua # Outputs to 168/169, 87
# Redirect sum
169 90 0 0 GA
182 90 0 0 GA
@@ -294,7 +294,7 @@ x y speedX speedY color
202 1 0 0 PU
202 0 0 0 RE
# Delay while last bits are adding
-0 66 0 0 !examples/add8rect5.qua
+0 66 0 0 !add8rect5.qua
# Redirect bits
-5 98 0 0 GA
-14 99 0 0 GA
@@ -334,7 +334,7 @@ x y speedX speedY color
186 81 0 0 CY
186 80 0 0 CY
# Add
-200 10 0 0 !examples/full.qua # Outputs to 203/204, 87
+200 10 0 0 !full.qua # Outputs to 203/204, 87
# Redirect sum
204 90 0 0 GA
217 90 0 0 GA
@@ -351,7 +351,7 @@ x y speedX speedY color
237 1 0 0 PU
237 0 0 0 RE
# Delay while last bits are adding
--5 100 0 0 !examples/add8rect6.qua
+-5 100 0 0 !add8rect6.qua
# Redirect bits
-6 100 0 0 GA
-15 101 0 0 GA
@@ -393,7 +393,7 @@ x y speedX speedY color
221 80 0 0 CY
221 79 0 0 CY
# Add
-235 10 0 0 !examples/full.qua # Outputs to 238/239, 87
+235 10 0 0 !full.qua # Outputs to 238/239, 87
# Redirect sum
239 90 0 0 GA
252 90 0 0 GA
@@ -409,7 +409,7 @@ x y speedX speedY color
272 1 0 0 PU
272 0 0 0 RE
# Delay while last bits are adding
-15 100 0 0 !examples/add8rect7.qua
+15 100 0 0 !add8rect7.qua
# Redirect bits
-7 102 0 0 GA
-16 103 0 0 GA
@@ -453,7 +453,7 @@ x y speedX speedY color
256 79 0 0 CY
256 78 0 0 CY
# Add
-270 10 0 0 !examples/full.qua # Outputs to 273/274, 87
+270 10 0 0 !full.qua # Outputs to 273/274, 87
# Redirect sum & carry
274 90 0 0 GA
@@ -472,13 +472,13 @@ x y speedX speedY color
287 -11 0 0 RE
## Delay outputs
-253 -9 0 0 !examples/20row.qua
-253 -8 0 0 !examples/20row.qua
-253 -7 0 0 !examples/20row.qua
-253 -6 0 0 !examples/20row.qua
-253 -5 0 0 !examples/20row.qua
-253 -4 0 0 !examples/20row.qua
-253 -3 0 0 !examples/20row.qua
+253 -9 0 0 !20row.qua
+253 -8 0 0 !20row.qua
+253 -7 0 0 !20row.qua
+253 -6 0 0 !20row.qua
+253 -5 0 0 !20row.qua
+253 -4 0 0 !20row.qua
+253 -3 0 0 !20row.qua
273 -3 0 0 OR
274 -3 0 0 OR
273 -4 0 0 OR
@@ -562,32 +562,32 @@ x y speedX speedY color
290 -3 0 0 OR
291 -3 0 0 OR
-218 -8 0 0 !examples/20row.qua
-218 -7 0 0 !examples/20row.qua
-218 -6 0 0 !examples/20row.qua
-218 -5 0 0 !examples/20row.qua
-218 -4 0 0 !examples/20row.qua
-218 -3 0 0 !examples/20row.qua
+218 -8 0 0 !20row.qua
+218 -7 0 0 !20row.qua
+218 -6 0 0 !20row.qua
+218 -5 0 0 !20row.qua
+218 -4 0 0 !20row.qua
+218 -3 0 0 !20row.qua
-183 -7 0 0 !examples/20row.qua
-183 -6 0 0 !examples/20row.qua
-183 -5 0 0 !examples/20row.qua
-183 -4 0 0 !examples/20row.qua
-183 -3 0 0 !examples/20row.qua
+183 -7 0 0 !20row.qua
+183 -6 0 0 !20row.qua
+183 -5 0 0 !20row.qua
+183 -4 0 0 !20row.qua
+183 -3 0 0 !20row.qua
-148 -6 0 0 !examples/20row.qua
-148 -5 0 0 !examples/20row.qua
-148 -4 0 0 !examples/20row.qua
-148 -3 0 0 !examples/20row.qua
+148 -6 0 0 !20row.qua
+148 -5 0 0 !20row.qua
+148 -4 0 0 !20row.qua
+148 -3 0 0 !20row.qua
-113 -5 0 0 !examples/20row.qua
-113 -4 0 0 !examples/20row.qua
-113 -3 0 0 !examples/20row.qua
+113 -5 0 0 !20row.qua
+113 -4 0 0 !20row.qua
+113 -3 0 0 !20row.qua
-78 -4 0 0 !examples/20row.qua
-78 -3 0 0 !examples/20row.qua
+78 -4 0 0 !20row.qua
+78 -3 0 0 !20row.qua
-43 -3 0 0 !examples/20row.qua
+43 -3 0 0 !20row.qua
# ADD-8
# Inputs: -17, -16
diff --git a/examples/add8test.qua b/examples/add8test.qua
index c440c3e..4197d53 100644
--- a/examples/add8test.qua
+++ b/examples/add8test.qua
@@ -16,5 +16,5 @@ x y speedX speedY color
50 44 1 0 GE
50 45 1 0 GE
50 46 1 0 BL
-70 47 0 0 !examples/add8.qua
+70 47 0 0 !add8.qua
# 11001101 (205) + 01011110 (94) = 100101011 (299) \ No newline at end of file
diff --git a/examples/and.qua b/examples/and.qua
index 5bc9914..48c783e 100644
--- a/examples/and.qua
+++ b/examples/and.qua
@@ -4,7 +4,7 @@ x y speedX speedY color
2 1 0 0 GA
2 0 0 0 GA
-1 0 0 0 GA
--1 3 0 0 !examples/not.qua
+-1 3 0 0 !not.qua
# AND - Input: 0, 0 speed 0, 1
# 1, 0 speed 0, 1
# Output: 0, 3
diff --git a/examples/andtest.qua b/examples/andtest.qua
index e8e784c..fc7f960 100644
--- a/examples/andtest.qua
+++ b/examples/andtest.qua
@@ -1,14 +1,14 @@
x y speedX speedY color
100 50 0 1 GE
101 50 0 1 GE
-100 100 0 0 !examples/and.qua
+100 100 0 0 !and.qua
120 50 0 1 GE
121 50 0 1 BL
-120 100 0 0 !examples/and.qua
+120 100 0 0 !and.qua
140 50 0 1 BL
141 50 0 1 GE
-140 100 0 0 !examples/and.qua
+140 100 0 0 !and.qua
160 50 0 1 BL
161 50 0 1 BL
-160 100 0 0 !examples/and.qua
+160 100 0 0 !and.qua
diff --git a/examples/full.qua b/examples/full.qua
index fb861f0..c196e1c 100644
--- a/examples/full.qua
+++ b/examples/full.qua
@@ -62,9 +62,9 @@ x y speedX speedY color
9 59 0 0 CY
9 58 0 0 CY
# While the first 2 digits are adding
-0 5 0 0 !examples/half.qua
+0 5 0 0 !half.qua
# Add the third digit with the sum of the first 2
--1 41 0 0 !examples/half.qua # Outputs to -2/-3, 67
+-1 41 0 0 !half.qua # Outputs to -2/-3, 67
# Bring sum of second addition to answer
-2 68 0 0 GA
7 68 0 0 GA
@@ -76,7 +76,7 @@ x y speedX speedY color
7 77 0 0 GA
4 77 0 0 GA
# OR carries
--3 72 0 0 !examples/or.qua
+-3 72 0 0 !or.qua
# FULL-ADDER
# Inputs: 0, 0
diff --git a/examples/fulltest.qua b/examples/fulltest.qua
index 2e5964b..e135e8b 100644
--- a/examples/fulltest.qua
+++ b/examples/fulltest.qua
@@ -2,33 +2,33 @@ x y speedX speedY color
20 1 0 1 GE
21 1 0 1 GE
22 1 0 1 GE
-20 30 0 0 !examples/full.qua
+20 30 0 0 !full.qua
55 1 0 1 GE
56 1 0 1 GE
57 1 0 1 BL
-55 30 0 0 !examples/full.qua
+55 30 0 0 !full.qua
90 1 0 1 GE
91 1 0 1 BL
92 1 0 1 GE
-90 30 0 0 !examples/full.qua
+90 30 0 0 !full.qua
125 1 0 1 GE
126 1 0 1 BL
127 1 0 1 BL
-125 30 0 0 !examples/full.qua
+125 30 0 0 !full.qua
160 1 0 1 BL
161 1 0 1 GE
162 1 0 1 GE
-160 30 0 0 !examples/full.qua
+160 30 0 0 !full.qua
195 1 0 1 BL
196 1 0 1 GE
197 1 0 1 BL
-195 30 0 0 !examples/full.qua
+195 30 0 0 !full.qua
230 1 0 1 BL
231 1 0 1 BL
232 1 0 1 GE
-230 30 0 0 !examples/full.qua
+230 30 0 0 !full.qua
265 1 0 1 BL
266 1 0 1 BL
267 1 0 1 BL
-265 30 0 0 !examples/full.qua
+265 30 0 0 !full.qua
diff --git a/examples/half.qua b/examples/half.qua
index eb23a6b..8c2083c 100644
--- a/examples/half.qua
+++ b/examples/half.qua
@@ -15,7 +15,7 @@ x y speedX speedY color
4 -2 0 0 GA
-3 -1 0 0 GA
-4 -2 0 0 GA
--4 3 0 0 !examples/xor.qua # Outputs to 2, 15
+-4 3 0 0 !xor.qua # Outputs to 2, 15
# What happens to the top copy (AND)
-1 -3 0 0 GA
2 -4 0 0 GA
@@ -23,7 +23,7 @@ x y speedX speedY color
-10 -4 0 0 GA
-9 -2 0 0 CY
-9 -1 0 0 CY
--10 15 0 0 !examples/and.qua # Outputs to -10, 18
+-10 15 0 0 !and.qua # Outputs to -10, 18
-10 22 0 0 GA
-5 22 0 0 PU
-5 21 0 0 RE
diff --git a/examples/halftest.qua b/examples/halftest.qua
index aad797e..3f47e48 100644
--- a/examples/halftest.qua
+++ b/examples/halftest.qua
@@ -1,16 +1,16 @@
x y speedX speedY color
100 50 0 1 GE
101 50 0 1 GE
-100 100 0 0 !examples/half.qua
+100 100 0 0 !half.qua
130 50 0 1 GE
131 50 0 1 BL
-130 100 0 0 !examples/half.qua
+130 100 0 0 !half.qua
160 50 0 1 BL
161 50 0 1 GE
-160 100 0 0 !examples/half.qua
+160 100 0 0 !half.qua
190 50 0 1 BL
191 50 0 1 BL
-190 100 0 0 !examples/half.qua
+190 100 0 0 !half.qua
diff --git a/examples/nottest.qua b/examples/nottest.qua
index c7b8854..40b8669 100644
--- a/examples/nottest.qua
+++ b/examples/nottest.qua
@@ -16,7 +16,7 @@ x y speedX speedY color
120 30 0 0 PU
120 28 0 0 RE
# ---- NOT ----
-120 120 0 0 !examples/not.qua
+120 120 0 0 !not.qua
#120 120 0 0 PU
#118 120 0 0 GA
#123 120 0 0 YE
diff --git a/examples/or.qua b/examples/or.qua
index 162fe04..830f1cd 100644
--- a/examples/or.qua
+++ b/examples/or.qua
@@ -1,10 +1,10 @@
x y speedX speedY color
-0 2 0 0 !examples/not.qua
+0 2 0 0 !not.qua
1 0 0 0 GA
6 0 0 0 GA
6 -1 0 0 GA
5 -1 0 0 GA
-5 2 0 0 !examples/not.qua
+5 2 0 0 !not.qua
1 4 0 0 GA
7 4 0 0 YE
# OR
diff --git a/examples/ortest.qua b/examples/ortest.qua
index be08d4e..dd42cfa 100644
--- a/examples/ortest.qua
+++ b/examples/ortest.qua
@@ -1,15 +1,15 @@
x y speedX speedY color
100 50 0 1 GE
101 50 0 1 GE
-100 100 0 0 !examples/or.qua
+100 100 0 0 !or.qua
120 50 0 1 GE
121 50 0 1 BL
-120 100 0 0 !examples/or.qua
+120 100 0 0 !or.qua
140 50 0 1 BL
141 50 0 1 GE
-140 100 0 0 !examples/or.qua
+140 100 0 0 !or.qua
160 50 0 1 BL
161 50 0 1 BL
-160 100 0 0 !examples/or.qua
+160 100 0 0 !or.qua
diff --git a/examples/xor.qua b/examples/xor.qua
index 50eb731..d9c527d 100644
--- a/examples/xor.qua
+++ b/examples/xor.qua
@@ -21,9 +21,9 @@ x y speedX speedY color
2 -2 0 0 GA
-2 -1 0 0 GA
-3 -2 0 0 GA
--3 5 0 0 !examples/or.qua
+-3 5 0 0 !or.qua
# The combining (AND)
-3 12 0 0 !examples/and.qua
+3 12 0 0 !and.qua
# A XOR B = (A OR B) AND (A NAND B)
# Inputs: 0, 0
# 1, 0
diff --git a/examples/xortest.qua b/examples/xortest.qua
index 449145b..cfe1230 100644
--- a/examples/xortest.qua
+++ b/examples/xortest.qua
@@ -1,16 +1,16 @@
x y speedX speedY color
100 50 0 1 GE
101 50 0 1 GE
-100 100 0 0 !examples/xor.qua
+100 100 0 0 !xor.qua
120 50 0 1 GE
121 50 0 1 BL
-120 100 0 0 !examples/xor.qua
+120 100 0 0 !xor.qua
140 50 0 1 BL
141 50 0 1 GE
-140 100 0 0 !examples/xor.qua
+140 100 0 0 !xor.qua
160 50 0 1 BL
161 50 0 1 BL
-160 100 0 0 !examples/xor.qua
+160 100 0 0 !xor.qua
diff --git a/qualums b/qualums
index 24441ff..0e00315 100755
--- a/qualums
+++ b/qualums
Binary files differ
diff --git a/src/Color.cpp b/src/Color.cpp
index b612315..5ca41dd 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -6,7 +6,7 @@
unsigned Colors::colors[] = {0x888888, 0xFF0000, 0x0000FF, 0x00FF00,
0x660099, 0xFFFF00, 0x00FFFF, 0xFF8800};
-char* Colors::color_names[] = {"GA", "RE", "BL", "GE", "PU", "YE", "CY", "OR", NULL};
+const char* Colors::color_names[] = {"GA", "RE", "BL", "GE", "PU", "YE", "CY", "OR", NULL};
Color Colors::read_color(char* s)
{
diff --git a/src/Color.h b/src/Color.h
index 0f67023..96aa03b 100644
--- a/src/Color.h
+++ b/src/Color.h
@@ -11,7 +11,7 @@ public:
private:
static unsigned get_color(Color c);
static unsigned colors[];
- static char* color_names[];
+ static const char* color_names[];
};
#endif /* COLOR_H */
diff --git a/src/main.cpp b/src/main.cpp
index d96441f..6b217f1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,12 @@
#include "Rendering.h"
#include "Color.h"
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
+const char SLASH = '\\';
+#else
+const char SLASH = '/';
+#endif
+
SDL_Window* window;
float TIME_SCALE = 4.0f;
@@ -16,39 +22,75 @@ void quit()
SDL_Quit();
}
-void read_file(char* filename, int x, int y, int speedx, int speedy)
+char* empty_string()
+{
+ // To avoid write-string warnings
+ char* s = (char*)malloc(1);
+ *s = 0;
+ return s;
+}
+
+char* getdirname(char* filename)
+{
+ // Gets, e.g. a/b/ from a/b/c.txt
+ char* dir = (char*)malloc(strlen(filename)+1);
+ strcpy(dir, filename);
+ char* lastSlash = strrchr(dir, SLASH);
+ if (lastSlash)
+ *(lastSlash+1) = 0;
+ else
+ return empty_string();
+ return dir;
+}
+
+char* getfilename(char* path)
+{
+ char* filename = (char*)malloc(strlen(path)+1);
+ strcpy(filename, path);
+ char* lastSlash = strrchr(path, SLASH);
+ if (lastSlash)
+ return lastSlash + 1;
+ return filename;
+}
+
+void read_file(char* directory, char* filename, int x, int y, int speedx, int speedy)
{
// Create the qualums from the given file
// Increasing their positions by (x,y) and their speeds by (speedx, speedy)
- FILE* input_file = fopen(filename, "r"); // Skip first line
+ char* path = (char*)malloc(4096); // Full path to file
+ sprintf(path, "%s%s", directory, filename);
+
+ FILE* input_file = fopen(path, "r"); // Skip first line
if (!input_file)
{
- fprintf(stderr, "File not found: %s\n", filename);
+ fprintf(stderr, "File not found: %s\n", path);
exit(1);
}
char* buffer = (char*)malloc(4096);
- fgets(buffer, 4096, input_file);
+ fgets(buffer, 4096, input_file); // Skip first line
int xrel, yrel, speedxrel, speedyrel; // Read input file
char* color_str = (char*) malloc(4096);
- char* include_filename = (char*) malloc(4096); // File name for includes
while (fgets(buffer, 4096, input_file))
{
- int i;
- for (i = 0; i < strlen(buffer); i++)
- if (buffer[i] == '#')
- break;
- buffer[i] = 0;
+ buffer += strspn(buffer, " \t"); // Remove whitespace at start
+ if (buffer[0] == '%') // Other data (width, height, etc.)
+ {
+
+ continue;
+ }
+
+ buffer[strcspn(buffer, "#\0")] = 0;
if (sscanf(buffer, "%d %d %d %d %s", &xrel, &yrel, &speedxrel, &speedyrel, color_str) > 0)
{
if (color_str[0] == '!') // Include
{
- int c;
- for (c = 0; color_str[c+1]; c++) // Remove !
- include_filename[c] = color_str[c+1];
- include_filename[c] = 0;
- read_file(include_filename, x + xrel, y + yrel, speedx + speedxrel, speedy + speedyrel);
+ color_str++;
+ char* newdir = (char*) malloc(4096);
+ strcpy(newdir, directory);
+ strcat(newdir, getdirname(color_str));
+ read_file(newdir, getfilename(color_str), x + xrel, y + yrel, speedx + speedxrel, speedy + speedyrel);
}
else // Color
{
@@ -76,7 +118,7 @@ int main(int argc, char** argv)
SDL_Event event;
bool will_quit = false;
- read_file(argv[1], 0, 0, 0, 0);
+ read_file(getdirname(argv[1]), getfilename(argv[1]), 0, 0, 0, 0);
int i = 0, last_printed = -1;
while (!will_quit)