Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

read_conf.c

00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "config.h"
00004 
00005 int main (int argc, char *argv[])
00006 {
00007   int     e, res, rc;
00008   char    *value;
00009 
00010   if (argc != 3)
00011   {
00012     fprintf (stdout, "FATAL: Wrong arguments (Usage: read_conf <path to configuration file> <tag>)");
00013     return 1;
00014   }
00015 
00016   rc = parse_configuration_file (argv[1], &e);
00017   if (rc != PARSE_CONFIGURATION_OK)
00018   {
00019 
00020     switch (rc)
00021     {
00022       case PARSE_CONFIGURATION_NO_MEM:
00023            {
00024               fprintf (stderr,
00025                        "FATAL: Could not load the configuration file <%s> - Could not allocate memory!",
00026                        argv[1]);
00027            }; break;
00028       case PARSE_CONFIGURATION_FILE_NOT_FOUND:
00029            {
00030               fprintf (stderr,
00031                        "FATAL :Could not load the configuration file <%s> - %s",
00032                        argv[1], strerror(e));
00033            }; break;
00034       case PARSE_CONFIGURATION_SYNTAX_ERROR:
00035            {
00036               fprintf (stderr,
00037                        "FATAL: Could not load the configuration file <%s> - Found syntax error.",
00038                        argv[1]);
00039            }; break;
00040       case PARSE_CONFIGURATION_DUPLICATED_TAG:
00041            {
00042               fprintf (stderr,
00043                        "FATAL: Could not load the configuration file <%s> - Duplicated tag found.",
00044                        argv[1]);
00045            }; break;
00046       case PARSE_CONFIGURATION_DLL_OPEN_ERROR:
00047            {
00048               fprintf (stderr,
00049                        "FATAL: Could not load the configuration file <%s> - Could not open DLL. %s.",
00050                        argv[1], conf_get_last_error());
00051            }; break;
00052       case PARSE_CONFIGURATION_DLL_INVALID:
00053            {
00054               fprintf (stderr,
00055                        "FATAL: Could not load the configuration file <%s> - DLL is not valid. %s.",
00056                        argv[1], conf_get_last_error());
00057            }; break;
00058       case PARSE_CONFIGURATION_MODEM_CONF_NOT_VALID:
00059            {
00060               fprintf (stderr,
00061                        "FATAL: Could not load the configuration file <%s> - Modem's configuration is not valid.",
00062                        argv[1]);
00063            }; break;
00064     }
00065 
00066     return 1;
00067   }
00068 
00069   res = get_value(argv[2], &value);
00070 
00071   if (res == 0)
00072   {
00073     fprintf (stdout, "FATAL: Tag <%s> not found in configuration file <%s>", argv[2], argv[1]);
00074     return  1;
00075   }
00076 
00077   if (res == -1)
00078   {
00079     fprintf (stdout, "FATAL: Unexpected error while parsing configuration file <%s> for tag <%s>",
00080              argv[1], argv[2]);
00081     return 1;
00082   }
00083   
00084   fprintf (stdout, "%s", value);
00085 
00086   return 0;
00087 }
00088 

Generated on Mon Jun 19 12:31:06 2006 for MyDhcp_V2 by doxygen1.2.15