getoptdata.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "getoptdata.h"
00014
00022 int GetOptData::GetOpt()
00023 {
00024 const OptionData *odata;
00025
00026 char *s = this->cont;
00027 if (s == NULL) {
00028 if (this->numleft == 0) return -1;
00029
00030 s = this->argv[0];
00031 if (*s != '-') return -1;
00032
00033 this->argv++;
00034 this->numleft--;
00035
00036
00037 for (odata = this->options; odata->flags != ODF_END; odata++) {
00038 if (odata->longname != NULL && !strcmp(odata->longname, s)) {
00039 this->cont = NULL;
00040 goto set_optval;
00041 }
00042 }
00043
00044 s++;
00045 }
00046
00047
00048 for (odata = this->options; odata->flags != ODF_END; odata++) {
00049 if (odata->shortname != '\0' && *s == odata->shortname) {
00050 this->cont = (s[1] != '\0') ? s + 1 : NULL;
00051
00052 set_optval:
00053 this->opt = NULL;
00054 switch (odata->flags) {
00055 case ODF_NO_VALUE:
00056 return odata->id;
00057
00058 case ODF_HAS_VALUE:
00059 case ODF_OPTIONAL_VALUE:
00060 if (this->cont != NULL) {
00061 this->opt = this->cont;
00062 this->cont = NULL;
00063 return odata->id;
00064 }
00065
00066 if (this->numleft == 0) return (odata->flags == ODF_HAS_VALUE) ? -2 : odata->id;
00067
00068
00069 if (odata->flags == ODF_OPTIONAL_VALUE && this->argv[0][0] == '-') return odata->id;
00070
00071 this->opt = this->argv[0];
00072 this->argv++;
00073 this->numleft--;
00074 return odata->id;
00075
00076 default: NOT_REACHED();
00077 }
00078 }
00079 }
00080
00081 return -2;
00082 }
00083