DEADSOFTWARE

Можно задавать директории для поиска модулей
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 18 Aug 2017 20:06:05 +0000 (23:06 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 18 Aug 2017 20:06:05 +0000 (23:06 +0300)
31 files changed:
obn-compile.sh
obn-run-tests.sh
src/main.c
tests/Test1.obn [moved from Test1.obn with 100% similarity]
tests/Test10.obn [moved from Test10.obn with 100% similarity]
tests/Test11.obn [moved from Test11.obn with 100% similarity]
tests/Test12.obn [moved from Test12.obn with 100% similarity]
tests/Test13.obn [moved from Test13.obn with 100% similarity]
tests/Test14.obn [moved from Test14.obn with 100% similarity]
tests/Test15.obn [moved from Test15.obn with 100% similarity]
tests/Test16.obn [moved from Test16.obn with 100% similarity]
tests/Test17A.obn [moved from Test17A.obn with 100% similarity]
tests/Test17B.obn [moved from Test17B.obn with 100% similarity]
tests/Test17C.obn [moved from Test17C.obn with 100% similarity]
tests/Test17Common.obn [moved from Test17Common.obn with 100% similarity]
tests/Test17D.obn [moved from Test17D.obn with 100% similarity]
tests/Test17E.obn [moved from Test17E.obn with 100% similarity]
tests/Test17F.obn [moved from Test17F.obn with 100% similarity]
tests/Test18A.obn [moved from Test18A.obn with 100% similarity]
tests/Test18B.obn [moved from Test18B.obn with 100% similarity]
tests/Test18C.obn [moved from Test18C.obn with 100% similarity]
tests/Test19.obn [moved from Test19.obn with 91% similarity]
tests/Test2.obn [moved from Test2.obn with 100% similarity]
tests/Test20.obn [moved from Test20.obn with 100% similarity]
tests/Test3.obn [moved from Test3.obn with 100% similarity]
tests/Test4.obn [moved from Test4.obn with 100% similarity]
tests/Test5.obn [moved from Test5.obn with 100% similarity]
tests/Test6.obn [moved from Test6.obn with 100% similarity]
tests/Test7.obn [moved from Test7.obn with 100% similarity]
tests/Test8.obn [moved from Test8.obn with 100% similarity]
tests/Test9.obn [moved from Test9.obn with 100% similarity]

index 85b71c5cd77a31745dd068269b2181989469303d..4ad5c3d6b261bc9f977b75efaf7957c00a217299 100755 (executable)
@@ -5,7 +5,7 @@ set -e
 rm -rf classes tmp
 mkdir -p classes tmp
 
-./a.out -d tmp $1
+./a.out -d tmp $*
 
 jasmin -d classes tmp/*.j
 
index fa1d728f373bbc133344fd14886982b2cdb21fe1..faaf6eacd92a3c1e2a002f7b5f393b321c1253bf 100755 (executable)
@@ -2,12 +2,14 @@
 
 set -e
 
+TEST_DIR=tests
+
 # Тест: компиляция и исполнение
 maketest()
 {
        local OK=1
        local LOG=""
-       if ! LOG="$(./obn-compile.sh $1)"; then
+       if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then
                OK=0;
                echo "=============================="
                echo "Test fail: $1 compile-time $?:"
@@ -18,11 +20,6 @@ maketest()
        if [ $OK = 1 ]; then
                if ! ./obn-run.sh $1; then
                        OK=0
-                       echo "=============================="
-                       echo "Test fail: $1 run-time $?:"
-                       echo "$LOG"
-                       echo "=============================="
-                       echo
                fi
        fi
        if [ $OK = 1 ]; then
@@ -34,7 +31,7 @@ maketest()
 makecomp()
 {
        local LOG=""
-       if ! LOG="$(./obn-compile.sh $1)"; then
+       if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then
                echo "=============================="
                echo "Test fail: $1 compile-time $?:"
                echo "$LOG"
@@ -50,7 +47,7 @@ makecomp()
 makefail()
 {
        local LOG=""
-       if ! LOG="$(./obn-compile.sh $1)"; then
+       if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then
                echo "Test ok: $1"
        else
                echo "=============================="
index 994ae806747dc34788ee8c76e9b247e27dd8202b..754d90aa7f216863d6f6337c0c3d41bd3def2afc 100644 (file)
@@ -5,24 +5,48 @@
 
 #include "../include/oberon.h"
 
+struct string_stack
+{
+       char * string;
+       struct string_stack * next;
+};
+
 static oberon_context_t * ctx;
 static oberon_module_t * mod;
 static const char * module;
 static const char * out_path;
+static struct string_stack * path_list;
+
+static void
+add_to_stack(struct string_stack ** stack, char * string)
+{
+       struct string_stack * p = malloc(sizeof *p);
+       p -> string = string;
+       p -> next = *stack;
+       *stack = p;
+}
+
+static FILE *
+open_file(struct string_stack * path, const char * ext, const char * name, const char * mode)
+{
+       FILE * fp = NULL;
+       while(fp == NULL && path != NULL)
+       {
+               char fname[256];
+               snprintf(fname, 256, "%s/%s.%s", path -> string, name, ext);
+               fp = fopen(fname, mode);
+               path = path -> next;
+       }
+       return fp;
+}
 
 static const char *
 import_module(const char * name)
 {
-       assert(name);
-
        FILE * fp;
-       char fname[256];
-       snprintf(fname, 256, "%s.obn", name);
-       fp = fopen(fname, "r");
+       fp = open_file(path_list, "obn", name, "r");
        if(fp == NULL)
        {
-               printf("can't open file %s\n", fname);
-               exit(1);
                return NULL;
        }
 
@@ -43,13 +67,27 @@ static void
 init(int argc, char ** argv)
 {
        int i = 1;
+       add_to_stack(&path_list, ".");
        out_path = ".";
 
-       if(argc > 2 && strcmp(argv[i], "-d") == 0)
+       while(argc > 2)
        {
-               out_path = argv[i + 1];
-               argc -= 2;
-               i += 2;
+               if(argc > 2 && strcmp(argv[i], "-d") == 0)
+               {
+                       out_path = argv[i + 1];
+                       argc -= 2;
+                       i += 2;
+               }
+               else if(argc > 2 && strcmp(argv[i], "-I") == 0)
+               {
+                       add_to_stack(&path_list, argv[i + 1]);
+                       argc -= 2;
+                       i += 2;
+               }
+               else
+               {
+                       break;
+               }
        }
 
        if(argc != 2 || argv[i][0] == '-')
@@ -69,6 +107,11 @@ main(int argc, char ** argv)
        init(argc, argv);
 
        code = import_module(module);
+       if(code == NULL)
+       {
+               printf("can't open module source %s\n", module);
+               return 0;
+       }
 
        ctx = oberon_create_context(import_module);
        oberon_set_out_directory(ctx, out_path);
similarity index 100%
rename from Test1.obn
rename to tests/Test1.obn
similarity index 100%
rename from Test10.obn
rename to tests/Test10.obn
similarity index 100%
rename from Test11.obn
rename to tests/Test11.obn
similarity index 100%
rename from Test12.obn
rename to tests/Test12.obn
similarity index 100%
rename from Test13.obn
rename to tests/Test13.obn
similarity index 100%
rename from Test14.obn
rename to tests/Test14.obn
similarity index 100%
rename from Test15.obn
rename to tests/Test15.obn
similarity index 100%
rename from Test16.obn
rename to tests/Test16.obn
similarity index 100%
rename from Test17A.obn
rename to tests/Test17A.obn
similarity index 100%
rename from Test17B.obn
rename to tests/Test17B.obn
similarity index 100%
rename from Test17C.obn
rename to tests/Test17C.obn
similarity index 100%
rename from Test17Common.obn
rename to tests/Test17Common.obn
similarity index 100%
rename from Test17D.obn
rename to tests/Test17D.obn
similarity index 100%
rename from Test17E.obn
rename to tests/Test17E.obn
similarity index 100%
rename from Test17F.obn
rename to tests/Test17F.obn
similarity index 100%
rename from Test18A.obn
rename to tests/Test18A.obn
similarity index 100%
rename from Test18B.obn
rename to tests/Test18B.obn
similarity index 100%
rename from Test18C.obn
rename to tests/Test18C.obn
similarity index 91%
rename from Test19.obn
rename to tests/Test19.obn
index 323d52829abcee47f89ae98fcde1b5c447a4e8c4..c5e684db354fe4ff4bcc90c0d81fc1315aca666a 100644 (file)
@@ -9,7 +9,7 @@ VAR
   x : POINTER TO ARRAY OF CHAR;
 
 BEGIN
-  f := Files.Old("Test19.obn");
+  f := Files.Old("tests/Test19.obn");
   ASSERT(f # NIL);
   Files.Set(r, f, 0);
 
similarity index 100%
rename from Test2.obn
rename to tests/Test2.obn
similarity index 100%
rename from Test20.obn
rename to tests/Test20.obn
similarity index 100%
rename from Test3.obn
rename to tests/Test3.obn
similarity index 100%
rename from Test4.obn
rename to tests/Test4.obn
similarity index 100%
rename from Test5.obn
rename to tests/Test5.obn
similarity index 100%
rename from Test6.obn
rename to tests/Test6.obn
similarity index 100%
rename from Test7.obn
rename to tests/Test7.obn
similarity index 100%
rename from Test8.obn
rename to tests/Test8.obn
similarity index 100%
rename from Test9.obn
rename to tests/Test9.obn