summaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2017-11-13 03:24:32 -0800
committerapache <apache@e5-web1.enlightenment.org>2017-11-13 03:24:32 -0800
commit8a806a09167db7248b7973479a727c629354c922 (patch)
treef22b4d51ea75f343b7b6fd4b8c632c83293e8cb6 /pages
parent02758817990751b07fb6f8fe8f0be9aeba98a410 (diff)
Wiki page hello-world.md changed with summary [Added command line parameters] by Xavi Artigas
Diffstat (limited to 'pages')
-rw-r--r--pages/develop/tutorial/c/hello-world.md.txt51
1 files changed, 44 insertions, 7 deletions
diff --git a/pages/develop/tutorial/c/hello-world.md.txt b/pages/develop/tutorial/c/hello-world.md.txt
index aa7df2bb2..31987f433 100644
--- a/pages/develop/tutorial/c/hello-world.md.txt
+++ b/pages/develop/tutorial/c/hello-world.md.txt
@@ -79,8 +79,7 @@ This defines the real ``main()`` method required by C programs, which deals with
79 79
80This is not mandatory but it simplifies the setup and shutdown processes considerably, so it is going to be used a lot in this series of tutorials. 80This is not mandatory but it simplifies the setup and shutdown processes considerably, so it is going to be used a lot in this series of tutorials.
81 81
82## The Complete Program ## 82Your program should now look something like this:
83
84```c 83```c
85#include <Eina.h> 84#include <Eina.h>
86#include <Efl.h> 85#include <Efl.h>
@@ -96,8 +95,6 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
96EFL_MAIN() 95EFL_MAIN()
97``` 96```
98 97
99## Running the Program ##
100
101Save the program then build it as outlined in [Setting up the Development Environment](/develop/setup/c/#Building). As a reminder, if you are using the ``gcc`` compiler, run: 98Save the program then build it as outlined in [Setting up the Development Environment](/develop/setup/c/#Building). As a reminder, if you are using the ``gcc`` compiler, run:
102 99
103```bash 100```bash
@@ -110,7 +107,48 @@ If the systems displays no errors, your program should be ready. Test it by typi
110./hello-world 107./hello-world
111``` 108```
112 109
113The words ``Hello World!`` will now appear on the screen. 110The words ``Hello World!`` should now appear on your terminal.
111
112## Step Six: Retrieve the Command Line Parameters ##
113
114Sometimes you might be interested in retrieving the command line parameters passed to your program. They are passed to ``efl_main()`` but in a slightly different way than they are usually passed to ``main()``.
115
116Replace your current ``efl_main()`` with this slightly modified version:
117
118```c
119EAPI_MAIN void
120efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
121{
122 Efl_Loop_Arguments *args = ev->info;
123
124 if (eina_array_count(args->argv) == 0)
125 {
126 printf("Hello World!\n");
127 }
128 else
129 {
130 printf("Hello %s!\n", (char *) eina_array_data_get(args->argv, 0));
131 }
132
133 efl_exit(0);
134}
135```
136
137As you can see, the ``Efl_Event *ev`` parameters is no longer marked with ``EINA_UNUSED``, because now you are going to use it:
138
139The ``Efl_Event`` structure contains an array with all the command line parameters. You retrieve it like this:
140
141```c
142 Efl_Loop_Arguments *args = ev->info;
143```
144
145Finally, the array can be found in ``args->argv``. Arrays in EFL are handled with the ``Eina_Array`` type, so you can use ``eina_array_count()`` to retrieve the number of elements in an array and ``eina_array_data_get()`` to access the contents of the array.
146
147In the above example, if no parameters are passed to your program (``eina_array_count(args->argv) == 0``), it just prints "Hello World!". Otherwise, the first parameter is retrieved and printed. Try compiling again your program and running it with your name as the first parameter:
148
149```bash
150./hello-world Mike
151```
114 152
115## Summary ## 153## Summary ##
116 154
@@ -120,5 +158,4 @@ At the end of this tutorial you have learned:
120* Your **main method** should be ``efl_main()``. 158* Your **main method** should be ``efl_main()``.
121* Your EFL programs should **always call ``efl_exit()``** at some stage. 159* Your EFL programs should **always call ``efl_exit()``** at some stage.
122* Your EFL programs should **include the ``EFL_MAIN()`` macro** at the end so EFL can insert its own start-up and shutdown code. 160* Your EFL programs should **include the ``EFL_MAIN()`` macro** at the end so EFL can insert its own start-up and shutdown code.
123 161* **Command line parameters** are available through the ``Efl_Event *`` parameter in ``efl_main()``, and can be accessed with ``eina_array_count()`` and ``eina_array_data_get()``.
124The next tutorial keeps introducing more basic concepts, and shows how to retrieve the command line parameters passed to your program. \ No newline at end of file