]> uap-core.de Git - uwplayer.git/commitdiff
add support for multiple file arguments when starting the application
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 15 Jul 2025 18:46:26 +0000 (20:46 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 15 Jul 2025 18:46:26 +0000 (20:46 +0200)
application/main.c
application/main.h
application/window.c

index 422b6ee2aed8ca431aa198f1e85510b0eb62a978..f6f1c8d6f6d457e37e6af7911efe152aeaee8b48 100644 (file)
 
 #include <cx/buffer.h>
 #include <cx/utils.h>
+#include <cx/array_list.h>
 
 static XtAppContext app;
 static Display *display;
 static Widget toplevel_window;
 
-static char *open_file_arg;
+static CxList *open_file_arg;
 
 static int event_pipe[2];
 
@@ -105,13 +106,16 @@ int main(int argc, char** argv) {
     display =  XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv);
     
     if(argc > 1) {
-        struct stat s;
-        if(stat(argv[1], &s)) {
-            fprintf(stderr, "Cannot open file: %s\n", argv[1]);
-            perror("");
-            return 1;
+        open_file_arg = cxArrayListCreateSimple(CX_STORE_POINTERS, argc-1);
+        for(int i=1;i<argc;i++) {
+            struct stat s;
+            if(stat(argv[1], &s)) {
+                fprintf(stderr, "Cannot open file: %s\n", argv[1]);
+                perror("");
+                return 1;
+            }
+            cxListAdd(open_file_arg, argv[i]);
         }
-        open_file_arg = argv[1];
     }
     
     // load settings
@@ -126,9 +130,12 @@ int main(int argc, char** argv) {
         free(instance_path);
         
         if(instance_fd >= 0) {
-            write(instance_fd, "open ", 5);
-            write(instance_fd, open_file_arg, strlen(open_file_arg));
-            write(instance_fd, "\n", 1);
+            CxIterator i = cxListIterator(open_file_arg);
+            cx_foreach(char *, file, i) {
+                write(instance_fd, "open ", 5);
+                write(instance_fd, file, strlen(file));
+                write(instance_fd, "\n", 1);
+            }
             close(instance_fd);
             return 0;
         }
@@ -168,11 +175,12 @@ void AppExecProc(XtWorkProc proc, XtPointer data) {
     write(event_pipe[1], &cb, sizeof(cb));
 }
 
-char* GetOpenFileArg(void) {
+CxList* GetOpenFileArgs(void) {
     return open_file_arg;
 }
 
-void CleanOpenFileArg(void) {
+void CleanOpenFileArgs(void) {
+    cxListDestroy(open_file_arg);
     open_file_arg = NULL;
 }
 
index e39b82794f1072a83e982a8fd1335ab59b325a27..de79d8aa07637a5e21dca02dd74f38b468021b45 100644 (file)
@@ -24,6 +24,7 @@
 #define UWP_MAIN_H
 
 #include <Xm/XmAll.h>
+#include <cx/list.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,8 +39,8 @@ void ApplicationExit(void);
 
 void AppExecProc(XtWorkProc proc, XtPointer data);
 
-char* GetOpenFileArg(void);
-void CleanOpenFileArg(void);
+CxList* GetOpenFileArgs(void);
+void CleanOpenFileArgs(void);
 
 void SetPlayerWindow(Window w);
 
index 8d8a285ebbe1f65933478cc3db2eba9ac243fedc..7caf301362007de48590b42b0ef70de9239a1146 100644 (file)
@@ -96,11 +96,14 @@ static void resizeEH(Widget widget, XtPointer data, XEvent *event, Boolean *disp
 }
 
 static void WindowRealized(MainWindow *win) {
-    char *open_file = GetOpenFileArg();
+    CxList *open_file = GetOpenFileArgs();
     if(open_file) {
-        PlayListAddFile(win, open_file);
+        CxIterator i = cxListIterator(open_file);
+        cx_foreach(char *, file, i) {
+            PlayListAddFile(win, file);
+        }
         PlayListPlayNext(win, true);
-        CleanOpenFileArg();
+        CleanOpenFileArgs();
     }
     
     if(!blank_cursor_init) {