args.h

Go to the documentation of this file.
00001 #include <libplayerc++/playerc++.h>
00002 #include <iostream>
00003 #include <unistd.h>
00004 
00005 std::string  gHostname(PlayerCc::PLAYER_HOSTNAME);
00006 uint         gPort(PlayerCc::PLAYER_PORTNUM);
00007 uint         gIndex(0);
00008 uint         gDebug(0);
00009 
00010 void print_usage(int argc, char** argv);
00011 
00012 int parse_args(int argc, char** argv)
00013 {
00014   // set the flags
00015   const char* optflags = "h:p:i:d:";
00016   int ch;
00017 
00018   // use getopt to parse the flags
00019   while(-1 != (ch = getopt(argc, argv, optflags)))
00020   {
00021     switch(ch)
00022     {
00023       // case values must match long_options
00024       case 'h': // hostname
00025           gHostname = optarg;
00026           break;
00027       case 'p': // port
00028           gPort = atoi(optarg);
00029           break;
00030       case 'i': // index
00031           gIndex = atoi(optarg);
00032           break;
00033       case 'd': // debug
00034           gDebug = atoi(optarg);
00035           break;
00036 //      case '?': // help
00037 //      case ':':
00038       case '?': 
00039           print_usage(argc, argv);
00040           exit (-1);
00041       default:  // unknown
00042      if (isprint (optopt))
00043         fprintf (stderr, "Unknown option `-%c'.\n", optopt);
00044      else
00045              fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
00046           print_usage(argc, argv);
00047           exit (-1);
00048     }
00049   }
00050   return (0);
00051 } // end parse_args
00052 
00053 
00054 
00055 void print_usage(int argc, char** argv)
00056 {
00057   using namespace std;
00058   cerr << "USAGE:  " << *argv << " [options]" << endl << endl;
00059   cerr << "Where [options] can be:" << endl;
00060   cerr << "  -h <hostname>  : hostname to connect to (default: "
00061        << PlayerCc::PLAYER_HOSTNAME << ")" << endl;
00062   cerr << "  -p <port>      : port where Player will listen (default: "
00063        << PlayerCc::PLAYER_PORTNUM << ")" << endl;
00064   cerr << "  -i <index>     : device index (default: 0)"
00065        << endl;
00066   cerr << "  -d <level>     : debug message level (0 = none -- 9 = all)"
00067        << endl;
00068 } // end print_usage

Generated on Sat Jan 13 03:11:09 2007 for ERSP Player driver by  doxygen 1.5.1