parseArgs.cpp
00001
00002
00003
00004
00005
00006
00007 #include "parseArgs.h"
00008 #include <stdio.h>
00009 #include <string>
00010
00011
00012 #ifndef LogFile
00013 #define LogFile "logfile.xml"
00014 #endif
00015 #ifndef EnvFile
00016 #define EnvFile "envfile.env"
00017 #endif
00018
00019 static bool isHelpPrinted = false;
00020
00021
00022 static void printHelp(void) {
00023 printf("\n"
00024 "----- Monitor Library -----\n"
00025 "Common Options:\n"
00026 "-h,--help Display this information\n"
00027 "-p,--playback Run playback mode using logfile.xml\n"
00028 "--nolog No output monitor log\n"
00029 "-l [logfile], --log [logfile]\n"
00030 " Run playback mode using [logfile]\n"
00031 "-s,--simulator Connect to each device's simulator\n"
00032 "-fs Full screen mode\n"
00033 "\n");
00034 }
00035
00036
00037 int Monitor::parseArgs(char*& logfile, char*& envfile,
00038 int argc, char *argv[]) {
00039 logfile = LogFile;
00040 envfile = EnvFile;
00041 bool simulator = false;
00042 bool playback = false;
00043 bool help = false;
00044 bool nolog = false;
00045
00046 for (int i = 0; i < argc; ++i) {
00047 if (!strcmp("-s", argv[i]) || !strcmp("--simulator", argv[i])) {
00048 simulator = true;
00049
00050 } else if (!strcmp("-p", argv[i]) || !strcmp("--playback", argv[i])) {
00051 playback = true;
00052
00053 } else if (!strcmp("-l", argv[i]) || !strcmp("--log", argv[i])) {
00054 playback = true;
00055 if (i+1 < argc) {
00056 logfile = argv[++i];
00057 }
00058 } else if (!strcmp("-h", argv[i]) || !strcmp("--help", argv[i])) {
00059 help = true;
00060
00061 } else if (!strcmp("--nolog", argv[i])) {
00062 nolog = true;
00063
00064 } else {
00065 envfile = argv[i];
00066 }
00067 }
00068 if (help && !isHelpPrinted) {
00069 printHelp();
00070 isHelpPrinted = true;
00071 }
00072 if (nolog) {
00073 logfile = NULL;
00074 }
00075
00076 if (playback) {
00077 return Playback;
00078 }
00079 return (simulator) ? Simulator : RealDevice;
00080 }
00081