Fix for fetching current directory when loading sequence
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 5 Jun 2016 04:28:11 +0000 (06:28 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 5 Jun 2016 04:28:11 +0000 (06:28 +0200)
gui/timeline.c
src/colorize.c

index ba06625..8fbd0c9 100644 (file)
@@ -14,6 +14,9 @@
 #include "../src/opticalflow.h"
 #endif
 
+// Uncomment this to test some filename processing
+//#define DEBUG_FILENAME
+
 /* functions to load directory */
 
 typedef struct dir_entry {
@@ -40,9 +43,16 @@ static dir_t *fetch_dir(const char *path) /* NOTE: if path is not empty, it must
        int i;
 
        /* read linked list */
-       dir = opendir(path);
-       if (!dir)
+       if (path == NULL || path[0] == '\0')
+               dir = opendir(".");
+       else
+               dir = opendir(path);
+       if (!dir) {
+#ifdef DEBUG_FILENAME
+               printf("Failed to open directory: path='%s'\n", path);
+#endif
                return NULL;
+       }
        while (1) {
                rc = readdir_r(dir, &dirent, &result);
                if (rc < 0)
@@ -58,6 +68,9 @@ static dir_t *fetch_dir(const char *path) /* NOTE: if path is not empty, it must
                }
                *entryp = entry;
                entryp = &entry->next;
+#ifdef DEBUG_FILENAME
+               printf("Fetching entry: path='%s' filename='%s'\n", path, result->d_name);
+#endif
                strcpy(entry->name, path);
                strcat(entry->name, result->d_name);
                count++;
@@ -80,6 +93,9 @@ static dir_t *fetch_dir(const char *path) /* NOTE: if path is not empty, it must
        for (i = 0; i < count; i++) {
                /* relink */
                entry = list[i];
+#ifdef DEBUG_FILENAME
+               printf("Sorted full name: '%s'\n", entry->name);
+#endif
                entry->next = NULL;
                *entryp = entry;
                entryp = &entry->next;
@@ -172,7 +188,7 @@ static void draw_timeline_frame(int frame)
 }
 
 /* get path of given file name */
-static char *get_path(const char *filename)
+static const char *get_path(const char *filename)
 {
        static char path[256];
 
@@ -230,7 +246,6 @@ void create_timeline(const char *filename)
                }
                if (*p < '0' || *p > '9') {
 single_file:
-//                     printf("single file\n");
                        frame_list = malloc(sizeof(struct frame_list));
                        memset(frame_list, 0, sizeof(struct frame_list));
                        strcpy(frame_list[0].filename, filename);
index 4ea8616..6516d08 100644 (file)
@@ -648,9 +648,9 @@ next_sequence:
                rc = colorize(I, mI, flow, flow_i, in_itr_num, out_itr_num, target_residual_change, quick, scalexyz, feat_names, NULL);
                if (rc < 0) {
                        if (k > 1)
-                               printf("No memory! Use smaller frames or less frames between key frames or add more memory.");
+                               printf("No memory! Use smaller frames or less frames between key frames or add more memory.\n");
                        else
-                               printf("No memory! Use smaller image or add more memory.");
+                               printf("No memory! Use smaller image or add more memory.\n");
                        exit(-1);
                }
        }