summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFábio Mello <mello@profusion.mobi>2012-11-30 13:31:00 +0000
committerFábio Mello <mello@profusion.mobi>2012-11-30 13:31:00 +0000
commit206c1aaa18cfeb1f9c7934f7ea25223a778de906 (patch)
treeb5558dd9f021d1b25954eb558b3160cb6a70a294
parent48907c329e38bc337acae0b906ac0ebdb7da4701 (diff)
elev8: Use Ecore to parse command line arguments.
Summary: Parse command line arguments using Ecore instead of hardcode it. Author: Joao Paulo Fernandes Ventura <ventura@profusion.mobi> SVN revision: 79902
-rw-r--r--src/bin/Makefile.am3
-rw-r--r--src/bin/args.c48
-rw-r--r--src/bin/args.h22
-rw-r--r--src/bin/main.cc8
4 files changed, 79 insertions, 2 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 6547cc2..0688f5f 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -27,7 +27,8 @@ elev8_SOURCES = \
27 environment.cc \ 27 environment.cc \
28 utils.cc \ 28 utils.cc \
29 utils_js.cc \ 29 utils_js.cc \
30 server.cc 30 server.cc \
31 args.c
31 32
32elev8_LDADD = @EINA_LIBS@ @ECORE_LIBS@ @V8_LIBS@ @EET_LIBS@ @ECORECON_LIBS@ 33elev8_LDADD = @EINA_LIBS@ @ECORE_LIBS@ @V8_LIBS@ @EET_LIBS@ @ECORECON_LIBS@
33 34
diff --git a/src/bin/args.c b/src/bin/args.c
new file mode 100644
index 0000000..fa44f1d
--- /dev/null
+++ b/src/bin/args.c
@@ -0,0 +1,48 @@
1#include <Ecore.h>
2#include <Ecore_Getopt.h>
3#include "args.h"
4
5int log_domain;
6
7#define ARGS_ERR(...) EINA_LOG_DOM_ERR(log_domain, __VA_ARGS__)
8
9static const Ecore_Getopt optdesc = {
10 "",
11 "\n\telev8 input_file.js\n\te.g. elev8 ../../data/javascript/button.js\n",
12 "0.0",
13 "(C) 2012 Enlightenment",
14 "GPLv3",
15 "EFL Elev8 JavaScript interpreter.",
16 0,
17 {
18 ECORE_GETOPT_STORE_DEF_BOOL(0, "debug", "enable debuggind mode", EINA_TRUE),
19 ECORE_GETOPT_STORE_DEF_BOOL(0, "server", "enable server mode", EINA_TRUE),
20 ECORE_GETOPT_STORE_DEF_BOOL(0, "shutdown", "shutdown elev8 server.", EINA_TRUE),
21 ECORE_GETOPT_HELP('h', "help"),
22 ECORE_GETOPT_LICENSE('l', "license"),
23 ECORE_GETOPT_VERSION('v', "version"),
24 ECORE_GETOPT_SENTINEL
25 }
26};
27
28int elev8_parse_argv(elev8_args *args, int argc, char **argv)
29{
30 int status;
31
32 Ecore_Getopt_Value values[] = {
33 ECORE_GETOPT_VALUE_BOOL(args->debug),
34 ECORE_GETOPT_VALUE_BOOL(args->server),
35 ECORE_GETOPT_VALUE_BOOL(args->shutdown),
36 ECORE_GETOPT_VALUE_BOOL(args->quit),
37 ECORE_GETOPT_VALUE_BOOL(args->quit),
38 ECORE_GETOPT_VALUE_BOOL(args->quit),
39 ECORE_GETOPT_VALUE_NONE
40 };
41
42 status = ecore_getopt_parse(&optdesc, values, argc, argv);
43
44 if (status < 0)
45 ARGS_ERR("Elev8 argument parsing failed\n");
46
47 return status;
48}
diff --git a/src/bin/args.h b/src/bin/args.h
new file mode 100644
index 0000000..dd6e98b
--- /dev/null
+++ b/src/bin/args.h
@@ -0,0 +1,22 @@
1#ifndef ARGS_H
2#define ARGS_H
3#include <stdio.h>
4#include <Eina.h>
5#endif
6
7#ifdef __cplusplus
8
9extern "C" {
10#endif
11 typedef struct {
12 Eina_Bool debug;
13 Eina_Bool server;
14 Eina_Bool shutdown;
15 Eina_Bool quit;
16 } elev8_args;
17
18 extern int elev8_parse_argv(elev8_args *args, int argc, char **argv);
19#ifdef __cplusplus
20};
21#endif
22
diff --git a/src/bin/main.cc b/src/bin/main.cc
index 8168e50..74ae257 100644
--- a/src/bin/main.cc
+++ b/src/bin/main.cc
@@ -11,6 +11,7 @@
11#include <elev8_common.h> 11#include <elev8_common.h>
12#include <unistd.h> 12#include <unistd.h>
13#include <v8-debug.h> 13#include <v8-debug.h>
14#include "args.h"
14#include "environment.h" 15#include "environment.h"
15#include "storage.h" 16#include "storage.h"
16#include "timer.h" 17#include "timer.h"
@@ -449,6 +450,7 @@ int
449main(int argc, char *argv[]) 450main(int argc, char *argv[])
450{ 451{
451 int script_arg = 1; 452 int script_arg = 1;
453 elev8_args args = { };
452 454
453 eina_init(); 455 eina_init();
454 ecore_con_init(); 456 ecore_con_init();
@@ -465,6 +467,8 @@ main(int argc, char *argv[])
465 V8::AddMessageListener(message, Undefined()); 467 V8::AddMessageListener(message, Undefined());
466 V8::SetCaptureStackTraceForUncaughtExceptions(true, 10, StackTrace::kDetailed); 468 V8::SetCaptureStackTraceForUncaughtExceptions(true, 10, StackTrace::kDetailed);
467 469
470 elev8_parse_argv(&args, argc, argv);
471
468 if (argc < 2) 472 if (argc < 2)
469 { 473 {
470 ERR("%s: Error: no input file specified.", argv[0]); 474 ERR("%s: Error: no input file specified.", argv[0]);
@@ -474,7 +478,7 @@ main(int argc, char *argv[])
474 argv[0], argv[0]); 478 argv[0], argv[0]);
475 exit(-1); 479 exit(-1);
476 } 480 }
477 else if (argc >= 3 && !strcmp(argv[1], "--debug")) 481 else if (args.debug)
478 { 482 {
479 printf("Awaiting connection from debugger on port 5858."); 483 printf("Awaiting connection from debugger on port 5858.");
480 fflush(stdout); 484 fflush(stdout);
@@ -482,6 +486,8 @@ main(int argc, char *argv[])
482 Debug::SetDebugMessageDispatchHandler(debug_message_handler); 486 Debug::SetDebugMessageDispatchHandler(debug_message_handler);
483 script_arg = 2; 487 script_arg = 2;
484 } 488 }
489 else if (args.quit)
490 exit(0);
485 491
486 HandleScope handle_scope; 492 HandleScope handle_scope;
487 493