examples/test_parser/test_parser.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*------------------------------------------------------------*/
00021 /** @file test_parser.c Test program for Parsers              */
00022 /*------------------------------------------------------------*/
00023 
00024 #include <stdio.h>
00025 #include <stdarg.h>
00026 
00027 #include <it/vec.h>
00028 #include <it/mat.h>
00029 #include <it/parser.h>
00030 #include <it/io.h>
00031 
00032 int main (int argc, char **argv)
00033 {
00034   int  i, def;
00035   double dbl;
00036   char *s;
00037   vec  v;
00038   ivec iv;
00039   cvec cv;
00040   mat  m;
00041   cmat cm;
00042   parser_t *parser;
00043 
00044   /* Initialization of the parser with the command line. 
00045      This source has the highest priority                     */
00046   printf ("______________________________\n");
00047   parser = parser_init (argc, argv, "test_parser.param",
00048       "a=-35\ndef=9\nv=[-1,-2,-3]\ncv=[i 1 -i 1+i]");
00049   parser_print (parser);
00050 
00051 
00052   printf ("______________________________\n");
00053   printf ("[ Display variables ]\n");
00054   i = parser_get_int (parser, "a");
00055   def = parser_get_int (parser, "def");
00056   dbl = parser_get_double (parser, "dbl");
00057   s = parser_get_string (parser, "S");
00058   v = parser_get_vec (parser, "V2");
00059   iv = parser_get_ivec (parser, "V");
00060   cv = parser_get_cvec (parser, "cv");
00061   m = parser_get_mat (parser, "m");
00062   cm = parser_get_cmat (parser, "cm");
00063 
00064   printf ("______________________________\n");
00065   printf ("a   = %d\n", i);
00066   printf ("def = %d\n", def);
00067   printf ("dbl = %g\n", dbl);
00068   printf ("S   = %s\n", s);
00069   it_printf ("v   = $v\n", v);
00070   it_printf ("iv  = $d\n", iv);
00071   it_printf ("cv  = $.3z\n", cv);
00072   it_printf ("m  = #m\n", m);
00073   it_printf ("cm  = #.3z\n", cm);
00074   parser_delete (parser);
00075   return 0;
00076 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau