nfs-ganesha 1.4

test_parse.c

Go to the documentation of this file.
00001 #include "config_parsing.h"
00002 #include "log.h"
00003 #include <errno.h>
00004 
00005 int main(int argc, char **argv)
00006 {
00007   SetDefaultLogging("TEST");
00008   SetNamePgm("test_parse");
00009 
00010   config_file_t config;
00011   char *fichier;
00012   char *errtxt;
00013 
00014   if((argc > 1) && (argv[1]))
00015     {
00016       fichier = argv[1];
00017     }
00018   else
00019     {
00020       LogTest("Usage %s <config_file>", argv[0]);
00021       exit(EINVAL);
00022     }
00023 
00024   /* Exemple de parsing */
00025   config = config_ParseFile(fichier);
00026 
00027   LogTest("config_pointer = %p", config);
00028 
00029   if(config == NULL)
00030     {
00031       errtxt = config_GetErrorMsg();
00032       LogTest("Error in parsing %s : %s", argv[1], errtxt);
00033       exit(EINVAL);
00034     }
00035 
00036   config_Print(stdout, config);
00037 
00038   {
00039     int i;
00040     char *val_a;
00041     config_item_t block, item;
00042 
00043     for(i = 0; i < config_GetNbBlocks(config); i++)
00044       {
00045 
00046         int j;
00047         char *nom;
00048         char *val;
00049 
00050         /* affichage du nom de l'item : */
00051         block = config_GetBlockByIndex(config, i);
00052 
00053         LogTest("bloc %s", config_GetBlockName(block));
00054 
00055         if((val_a = config_GetKeyValueByName(block, "b")))
00056           {
00057             LogTest("%s.b is defined as %s", config_GetBlockName(block), val_a);
00058           }
00059         else
00060           {
00061             LogTest("%s.b not defined", config_GetBlockName(block));
00062           }
00063 
00064         /* parcours des variables du block */
00065         for(j = 0; j < config_GetNbItems(block); j++)
00066           {
00067 
00068             item = config_GetItemByIndex(block, j);
00069 
00070             if(config_ItemType(item) == CONFIG_ITEM_VAR)
00071               {
00072                 config_GetKeyValue(item, &nom, &val);
00073                 LogTest("\t%s = %s", nom, val);
00074               }
00075             else
00076               LogTest("\tsub-block = %s", config_GetBlockName(item));
00077           }
00078         LogTest(" ");
00079 
00080       }
00081 
00082   }
00083 
00084 /* free and reload the file */
00085   config_Free(config);
00086 
00087   config = config_ParseFile(fichier);
00088 
00089   LogTest("config_pointer = %p", config);
00090 
00091   if(config == NULL)
00092     {
00093       errtxt = config_GetErrorMsg();
00094       LogTest("Parsing error for %s : %s", argv[1], errtxt);
00095       exit(EINVAL);
00096     }
00097 
00098   config_Print(stdout, config);
00099 
00100   exit(0);
00101 
00102 }