Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5482)
+++ ChangeLog	(revision 5484)
@@ -18,4 +18,5 @@
 	* Added support for quotes strings to kv split and
 	  roardl para argument splitting (pr0).
+	* Added support for an application mode in roarpluginrunner (pr0).
 
 v. 1.0beta0 - Fri Mar 16 2012 19:39 CET
Index: roarclients/Makefile
===================================================================
--- roarclients/Makefile	(revision 5413)
+++ roarclients/Makefile	(revision 5484)
@@ -7,5 +7,5 @@
 TARGETS_M=roardtmf
 TARGETS_VIO=roarvio
-TARGETS_PLUGINS=roarpluginrunner
+TARGETS_PLUGINS=roarpluginrunner roarpluginapplication
 
 #TARGETS_TESTS=zcattest pgptest pipetest polytest
Index: roarclients/roarpluginapplication.sht
===================================================================
--- roarclients/roarpluginapplication.sht	(revision 5484)
+++ roarclients/roarpluginapplication.sht	(revision 5484)
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+_plugin=`basename "$0"`
+
+if [ "$_plugin" = 'roarpluginapplication' ]
+then
+ echo "$0: This script should not be run like this, see $_plugin(1) for details."
+ exit 1
+fi
+
+exec roarpluginrunner --run-as-application "$_plugin" "$@"
+
+#ll
Index: roarclients/roarpluginrunner.c
===================================================================
--- roarclients/roarpluginrunner.c	(revision 5442)
+++ roarclients/roarpluginrunner.c	(revision 5484)
@@ -31,4 +31,5 @@
 enum action {
  RUN,
+ RUN_AS_APPLICATION,
  EXPLAIN
 };
@@ -41,12 +42,14 @@
  fprintf(stderr, "\nOptions:\n\n");
 
- fprintf(stderr, " -h --help            - This help.\n"
-                 " -v --verbose         - Be verbose. Can be used multiple times.\n"
-                 "    --server SERVER   - Set default server to SERVER.\n"
-                 "    --run             - Run plugin.\n"
-                 "    --explain         - Explain plugin.\n"
-                 "    --appname NAME    - Sets the appname.\n"
-                 "    --abiversion ABI  - Set the ABI version.\n"
-                 "    --args ARGS       - Set plugin arguments.\n"
+ fprintf(stderr, " -h --help               - This help.\n"
+                 " -v --verbose            - Be verbose. Can be used multiple times.\n"
+                 "    --server SERVER      - Set default server to SERVER.\n"
+                 "    --run                - Run plugin.\n"
+                 "    --run-as-application - Same as --run except all tailing arguments are\n"
+                 "                           passed to the plugin.\n"
+                 "    --explain            - Explain plugin.\n"
+                 "    --appname NAME       - Sets the appname.\n"
+                 "    --abiversion ABI     - Set the ABI version.\n"
+                 "    --args ARGS          - Set plugin arguments.\n"
         );
 }
@@ -285,4 +288,5 @@
    break;
   case RUN:
+  case RUN_AS_APPLICATION:
     return do_run(name);
    break;
@@ -300,4 +304,112 @@
  roar_dl_para_unref(g_para);
  g_para = NULL;
+}
+
+static inline int _add_para(struct roar_dl_librarypara * para, const char * pluginargs, size_t argc, char * argv[]) {
+ struct roar_keyval * kv;
+ ssize_t argslen, argvlen;
+ ssize_t arglen;
+ ssize_t pluginargc;
+ size_t argv_phys = argc;
+ size_t i;
+ int error;
+ char * sp, * c;
+ int after_parser_end;
+
+ if ( pluginargs == NULL )
+  pluginargs = "";
+
+ argslen = roar_mm_strlen(pluginargs) + 1 /* tailing '\0' */;
+
+ after_parser_end = 0;
+ argvlen = 0;
+ for (i = 0; i < argv_phys; i++) {
+  arglen   = roar_mm_strlen(argv[i]);
+  argvlen += arglen;
+  if ( !after_parser_end ) {
+   if ( !strcmp(argv[i], "--") ) {
+    after_parser_end = 1;
+    argc--;
+   } else if ( arglen > 1 && argv[i][0] == '-' && !(arglen > 2 && argv[i][1] == '-') ) {
+    argc += arglen - 2;
+   }
+  }
+ }
+ argvlen += argc; // the '\0's.
+
+ para->args_store = roar_mm_malloc(argslen+argvlen);
+ if ( para == NULL )
+  return -1;
+
+ memcpy(para->args_store, pluginargs, argslen);
+
+ pluginargc = roar_keyval_split(&kv, para->args_store, NULL, NULL, 1);
+ if ( pluginargc == -1 ) {
+  error = roar_error;
+  roar_mm_free(para->args_store);
+  para->args_store = NULL;
+  roar_error = error;
+  return -1;
+ }
+
+ para->argv = roar_mm_malloc((pluginargc+argc)*sizeof(struct roar_keyval));
+ if ( para->argv == NULL ) {
+  error = roar_error;
+  roar_mm_free(kv);
+  roar_mm_free(para->args_store);
+  para->args_store = NULL;
+  roar_error = error;
+  return -1;
+ }
+
+ para->argc = pluginargc + argc;
+
+ memcpy(para->argv, kv, pluginargc*sizeof(struct roar_keyval));
+ roar_mm_free(kv);
+
+ sp = para->args_store + argslen;
+ kv = para->argv + pluginargc;
+
+ after_parser_end = 0;
+ for (i = 0; i < argv_phys; i++) {
+  arglen = roar_mm_strlen(argv[i]) + 1;
+  if ( after_parser_end || !(arglen > 2 && argv[i][0] == '-' && !(arglen > 3 && argv[i][1] == '-')) )
+   memcpy(sp, argv[i], arglen);
+
+  if ( !after_parser_end && !strcmp(argv[i], "--") ) {
+   after_parser_end = 1;
+   continue;
+  } else if ( !after_parser_end && arglen > 3 && sp[0] == '-' && sp[1] == '-' ) {
+   kv->key = sp + 2;
+   kv->value = NULL;
+   for (c = sp + 2; *c; c++) {
+    if (*c == '=') {
+     *c = 0;
+     c++;
+     kv->value = c;
+     break;
+    }
+   }
+  } else if ( !after_parser_end && arglen > 2 && argv[i][0] == '-' ) {
+   for (c = argv[i] + 1; *c; c++) {
+    printf("*c=%c\n", *c);
+    sp[0] = *c;
+    sp[1] = 0;
+    kv->key = sp;
+    kv->value = NULL;
+    sp += 2;
+    kv++;
+   }
+   continue;
+  } else {
+   kv->key = NULL;
+   kv->value = sp;
+  }
+
+  sp += arglen;
+  kv++;
+ }
+
+ return 0;
 }
 
@@ -319,4 +431,6 @@
   } else if ( !strcmp(k, "--run") ) {
    action = RUN;
+  } else if ( !strcmp(k, "--run-as-application") ) {
+   action = RUN_AS_APPLICATION;
   } else if ( !strcmp(k, "--explain") ) {
    action = EXPLAIN;
@@ -336,11 +450,17 @@
   } else {
    if ( g_para == NULL )
-    g_para = roar_dl_para_new(pluginargs, NULL, appname, abiversion);
-   roar_err_set(ROAR_ERROR_NONE);
-   if ( do_plugin(action, k) == -1 ) {
-    fprintf(stderr, "Error loading plugin: %s\n",
-                    roar_error != ROAR_ERROR_NONE ? roar_error2str(roar_error) : roar_dl_errstr(NULL));
-    ret = 1;
-   }
+    g_para = roar_dl_para_new(action == RUN_AS_APPLICATION ? NULL : pluginargs, NULL, appname, abiversion);
+   if ( action == RUN_AS_APPLICATION && _add_para(g_para, pluginargs, argc - i - 1, &(argv[i+1])) == -1 ) {
+    fprintf(stderr, "Error parsing plugin arguments: %s\n", roar_error2str(roar_error));
+   } else {
+    roar_err_set(ROAR_ERROR_NONE);
+    if ( do_plugin(action, k) == -1 ) {
+     fprintf(stderr, "Error loading plugin: %s\n",
+                     roar_error != ROAR_ERROR_NONE ? roar_error2str(roar_error) : roar_dl_errstr(NULL));
+     ret = 1;
+    }
+   }
+   if ( action == RUN_AS_APPLICATION )
+    break; // end looping over arguments
   }
  }
