[LibExArg]: (Explore Arguments Library) Manual

Introduction

LibExArg library is a small, easy to use with a consistent API which allows you to parse command line argument for your program.

It is build on top of glib which make it really portable and at this point is running on GNU/Linux platforms and Microsoft Windows platforms.

For details on how to starting to use LibExarg, you can find the module documentation for LibExArg here.

Library License

The library is released under the terms of the GNU LGPL (The GNU Lesser General Public License) licence. You can get a copy of the license http://www.gnu.org/licenses/licenses.html#LGPL.

This license allows you to write applications using LibExArg which are using some GPL compatible license or commercial applications.

A simple example on using LibExarg

You may find interesting the following example which makes use of LibExArg. This example install 3 arguments to be accepted as valid command line options and the write down to the terminal the result of those command used by the user.

Once the arguments are installed, the user can execute

00001 //  LibExploreArguments: a library to parse command line options
00002 //  Copyright (C) 2005 Advanced Software Production Line, S.L.
00003 // 
00004 //  This program is free software; you can redistribute it and/or
00005 //  modify it under the terms of the GNU Lesser General Public License
00006 //  as published by the Free Software Foundation; either version 2.1 of
00007 //  the License, or (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
00012 //  GNU Lesser General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU Lesser General Public
00015 //  License along with this program; if not, write to the Free
00016 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017 //  02111-1307 USA
00018 //  
00019 //  You may find a copy of the license under this software is released
00020 //  at COPYING file. This is LGPL software: you are wellcome to
00021 //  develop propietary applications using this library withtout any
00022 //  royalty or fee but returning back any change, improvement or
00023 //  addition in the form of source code, project image, documentation
00024 //  patches, etc. 
00025 //
00026 //  You can also contact us to negociate other license term you may be
00027 //  interested different from LGPL. Contact us at:
00028 //          
00029 //      Postal address:
00030 //         Advanced Software Production Line, S.L.
00031 //         C/ Dr. Michavila NÂș 14
00032 //         Coslada 28820 Madrid
00033 //         Spain
00034 //
00035 //      Email address:
00036 //         info@aspl.es - http://fact.aspl.es
00037 //
00038 //
00039 
00040 #include <exarg.h>
00041 
00042 #define HELP_HEADER "test-exarg: a simple program to test libexarg library\n\
00043 Copyright (C) 2005 Advanced Software Production Line\n\n"
00044 
00045 #define USAGE_HEADER "Brief: You can use any of the following option from the usage.\n\
00046 Once the option is used, the program will parse it and will notify that options was\n\
00047 read. For those arguments which receives values, that will also showed.\n\n"
00048 
00049 #define POST_MESSAGE "\nIf you have any question, path to report or problems about using\n\
00050 this library feel free to contact us at aspl-fact-devel@lists.aspl.es\n"
00051 
00052 gint main (gint argc, gchar ** argv)
00053 {
00054         GList * list_aux;
00055 
00056         exarg_install_arg ("version", "v",      EXARG_NONE,   "Show the program version.");
00057         exarg_install_arg ("load-library", "l", EXARG_STRING, "Load a library.");
00058         exarg_install_arg ("how-many-foo", "f", EXARG_INT,    "How many foos to frobnicate.");
00059 
00060         exarg_add_usage_header  (USAGE_HEADER);
00061         exarg_add_help_header   (HELP_HEADER);
00062         exarg_post_usage_header (POST_MESSAGE);
00063         exarg_post_help_header  (POST_MESSAGE);
00064         
00065 
00066         exarg_parse (argc, argv);
00067         
00068         // check argument status
00069         if (exarg_is_defined ("version")) 
00070                 g_print ("argument --version have been invoked.\n");
00071 
00072         if (exarg_is_defined ("load-library")) {
00073                 g_print ("argument --load-library have been invoked:\n");
00074                 g_print ("     value is: %s\n", exarg_get_string ("load-library"));
00075         }
00076         if (exarg_is_defined ("how-many-foo")) {
00077                 g_print ("argument --how-many-foo have been invoked: \n");
00078                 g_print ("     value is %d\n", exarg_get_int ("how-many-foo"));
00079         }
00080 
00081         // check param list status
00082         for (list_aux = g_list_first (exarg_get_params ()); 
00083              list_aux; list_aux = g_list_next (list_aux)) {
00084                 g_print ("param received: %s\n", (gchar *) list_aux->data);
00085         }
00086 
00087         // end libexarg (once called you must not call exarg anymore until
00088         // current program ends)
00089         exarg_end ();
00090                 
00091         return 0;
00092 }