Main Page | Data Structures | File List | Data Fields | Globals

command_line_parser.c

Go to the documentation of this file.
00001 /* command_line_parser.c --- 
00002  * 
00003  * Filename: command_line_parser.c
00004  * Description: 
00005  * Author: Bryce Himebaugh
00006  * Maintainer: 
00007  * Created: Thu Sep  7 12:40:16 2006
00008  * Version: 
00009  * Last-Updated: 
00010  *           By: 
00011  *     Update #: 0
00012  * Keywords: 
00013  * Compatibility: 
00014  * 
00015  */
00016 
00017 /* Commentary: 
00018  * 
00019  * 
00020  * 
00021  */
00022 
00023 /* Change log:
00024  * 
00025  * 
00026  */
00027 
00028 /* This program is free software; you can redistribute it and/or modify
00029  * it under the terms of the GNU General Public License as published by
00030  * the Free Software Foundation; either version 2, or (at your option)
00031  * any later version.
00032  * 
00033  * This program is distributed in the hope that it will be useful,
00034  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00036  * GNU General Public License for more details.
00037  * 
00038  * You should have received a copy of the GNU General Public License
00039  * along with this program; see the file COPYING.  If not, write to the
00040  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00041  * Boston, MA 02111-1307, USA.
00042  */
00043 
00044 /* Code: */
00045 
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include <stdlib.h>
00049 #include <errno.h>
00050 #include "command_line_parser.h"
00051 
00052 void print_help (void);
00053 
00054 int command_line_parser (int argc, char *argv[], command_options_t *options) {
00055   int i;
00056   const char port_str[]="-p";
00057   const char help_str[]="-h";
00058   long portnum=5555;
00059   
00060   for (i=1;i<argc;i++) {
00061     if (!strcmp(argv[i],port_str)) {
00062         if ((i+1)<argc) {
00063           if (!((portnum=strtol(argv[i+1],NULL,10))<1024)) {
00064             options->port=portnum;
00065           }
00066           i++;
00067         }
00068     }
00069     else if (!strcmp(argv[i],help_str)) {
00070       print_help();
00071       exit(0);
00072     }
00073     else { 
00074       printf("Error: bad option %s\n",argv[i]);
00075       printf("\"cart_comm -h\" for list of options\n");
00076       exit(0);
00077     } 
00078   }
00079   return 0;
00080 }
00081 
00082 void print_help (void) {
00083   printf("\nUSAGE: arm-elf-console-proxy [-h] [-r] [-a] [-p portnum]\n");
00084   printf("-h: Print this help message and exit\n");
00085   printf("-p portnum: Specify the port number for the comm server. Default value is 5555\n\n");
00086 } 
00087 
00088 void init_command_line_options(command_options_t *options) {
00089   options->port=5555;
00090 }
00091 
00092   
00093 
00094 
00095 /* command_line_parser.c ends here */

Generated on Fri Nov 3 15:24:51 2006 for ERT1 Communication Server by  doxygen 1.3.9.1