#include <stdio.h>#include <stdlib.h>#include <string.h>#include "inifile.h"Include dependency graph for inivar.c:

Go to the source code of this file.
Functions | |
| int | main (int argc, char *argv[]) |
|
||||||||||||
|
Definition at line 24 of file inivar.c. 00025 {
00026 int t;
00027 char _variable[INIFILE_MAX_LINELEN] = "";
00028 char *variable = 0;
00029 char _section[INIFILE_MAX_LINELEN] = "";
00030 char *section = 0;
00031 char INIFILE[256] = "emc.ini";
00032 FILE *fp;
00033 const char *inistring;
00034
00035 /* process command line args, indexing argv[] from [1] */
00036 for (t = 1; t < argc; t++) {
00037 if (!strcmp(argv[t], "-ini")) {
00038 if (t == argc - 1) {
00039 /* no arg following -ini, so abort */
00040 fprintf(stderr,
00041 "%s: ini file not specified after -ini\n",
00042 argv[0]);
00043 exit(1);
00044 }
00045 else {
00046 strcpy(INIFILE, argv[t+1]);
00047 t++; /* step over following arg */
00048 }
00049 }
00050 else if (!strcmp(argv[t], "-var")) {
00051 if (t == argc - 1) {
00052 /* no arg following -var, so abort */
00053 fprintf(stderr,
00054 "%s: variable name not specified after -var\n",
00055 argv[0]);
00056 exit(1);
00057 }
00058 else {
00059 strcpy(_variable, argv[t+1]);
00060 variable = _variable;
00061 t++; /* step over following arg */
00062 }
00063 }
00064 else if (!strcmp(argv[t], "-sec")) {
00065 if (t == argc - 1) {
00066 /* no arg following -sec, so abort */
00067 fprintf(stderr,
00068 "%s: section name not specified after -sec\n",
00069 argv[0]);
00070 exit(1);
00071 }
00072 else {
00073 strcpy(_section, argv[t+1]);
00074 section = _section;
00075 t++; /* step over following arg */
00076 }
00077 }
00078 else {
00079 /* invalid argument */
00080 fprintf(stderr,
00081 "%s: -var <variable> {-sec <section>} {<-ini inifile>}\n",
00082 argv[0]);
00083 exit(1);
00084 }
00085 }
00086
00087 /* check that variable was supplied */
00088 if (0 == variable) {
00089 fprintf(stderr,
00090 "%s: no variable supplied\n",
00091 argv[0]);
00092 exit(1);
00093 }
00094
00095 /* open the inifile */
00096 if (NULL == (fp = fopen(INIFILE, "r"))) {
00097 fprintf(stderr,
00098 "%s: can't open %s\n",
00099 argv[0], INIFILE);
00100 exit(1);
00101 }
00102
00103 inistring = iniFind(fp, variable, section);
00104 if (NULL != inistring) {
00105 printf("%s\n", inistring);
00106 }
00107
00108 fclose(fp);
00109
00110 exit(0);
00111 }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001