From b7676f0712f12a68dcf27715addcfb09e27f5b2b Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 3 Mar 2017 12:05:35 +0100 Subject: Option parsing ++ New syntax: see usage() --- main.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/main.cpp b/main.cpp index 99ba3f7..cfa8502 100644 --- a/main.cpp +++ b/main.cpp @@ -226,6 +226,26 @@ static void signalHandler(int sig){ #endif +struct RobotSpec{ + string fname; + bool random; + int x,y,heading; +}; + +int parseInt(const char *str){ + char *endp; + int v=strtol(str,&endp,10); + if(str[0]=='\0'||*endp!='\0'){ + cerr<<"Invalid number '"<]* [-p ]*"< teams; - bool opt_pos = false; - vector> positions; - - int k = 1; // Increase past options; + vector robotSpecs; - if(argc>k && string(argv[k]) == "-p") { - opt_pos = true; - k++; + if(argc<=1){ + usage(argv); + return 1; } - for(int i=k;iargc - i += 3; + for(int i=1;i=argc-1){ + cerr<<"Expected file name after '-r'"<=argc-4){ + cerr<<"Expected file name, x, y and heading after '-p'"<(positions[i]), get<1>(positions[i]), get<2>(positions[i])) - : world.create(&t,2,t.banks.size(),false); + default: + cerr<<"Unknown switch in '"<