Main Page   Compound List   File List   Compound Members   File Members  

pc_libs/pc_comline.c

Go to the documentation of this file.
00001 /*=====================================================================
00002                 =======   COPYRIGHT NOTICE   =======
00003 Copyright (C) 1996, Carnegie Mellon University, Cambridge University,
00004 Ronald Rosenfeld and Philip Clarkson.
00005 
00006 All rights reserved.
00007 
00008 This software is made available for research purposes only.  It may be
00009 redistributed freely for this purpose, in full or in part, provided
00010 that this entire copyright notice is included on any copies of this
00011 software and applications and derivations thereof.
00012 
00013 This software is provided on an "as is" basis, without warranty of any
00014 kind, either expressed or implied, as to any matter including, but not
00015 limited to warranty of fitness of purpose, or merchantability, or
00016 results obtained from use of this software.
00017 ======================================================================*/
00018 
00019 
00024 #include <string.h>
00025 #include <stdlib.h>
00026 #include "../rr_libs/general.h"
00027 #include "pc_general.h"
00028 #include "../toolkit.h"
00029 
00030 /* update the command line argument sequence */
00031 static void updateArgs( int *pargc, char **argv, int rm_cnt ) 
00032 {
00033   int i ;                      
00034   /* update the argument count */
00035   (*pargc)-- ;
00036  
00037   /* update the command line */
00038   for( i = rm_cnt ; i < *pargc ; i++ ) argv[i] = argv[i+1] ;
00039 }
00040 
00041 int pc_flagarg(int *argc, char **argv, char *flag) {
00042 
00043   int i;
00044   
00045   for(i = 1; i < *argc; i++){
00046     if (!strcmp(argv[i], flag)) {
00047       updateArgs(argc, argv, i);
00048       return(1);
00049     }
00050   }
00051   return(0);
00052 }
00053 
00054 char *pc_stringarg(int *argc, char **argv, char *flag, char *value) {
00055   
00056   int i;
00057   
00058   for(i = 1; i < *argc -1; i++){
00059     if (!strcmp(argv[i], flag)) {
00060       value = argv[i+1];
00061       updateArgs(argc, argv, i+1);
00062       updateArgs(argc, argv, i);
00063       return(value);
00064     }
00065   }
00066   return(value);
00067 }
00068 
00069 int pc_intarg(int *argc, char **argv, char *flag, int value) {
00070 
00071   int i;
00072 
00073   for(i = 1; i < *argc - 1; i++){
00074     if (!strcmp(argv[i], flag)) {
00075       value = atoi(argv[i+1]);
00076       updateArgs(argc, argv, i+1);
00077       updateArgs(argc, argv, i);
00078       return(value);
00079     }
00080   }
00081   return(value);
00082 }
00083 
00084 double pc_doublearg(int *argc, char **argv, char *flag, double value) {
00085 
00086   int i;
00087 
00088   for(i = 1; i < *argc -1; i++){
00089     if (!strcmp(argv[i], flag)) {
00090       value = atof(argv[i+1]);
00091       updateArgs(argc, argv, i+1);
00092       updateArgs(argc, argv, i);
00093       return(value);
00094     }
00095   }
00096   return(value);
00097 }
00098   
00099 short *pc_shortarrayarg(int *argc, char **argv, char *flag, int elements, int size) {
00100  
00101   short *array;
00102   int i,j;
00103 
00104   array = NULL;
00105 
00106   if (size < elements) {
00107     quit(-1,"pc_shortarrayarg Error : Size of array is less than number of elements\nto be read.\n");
00108   }
00109 
00110   for(i = 1; i < *argc-elements; i++){
00111     if (!strcmp(argv[i], flag)) {
00112 
00113       array = (short *) rr_malloc(size * sizeof(int));
00114 
00115       for (j=0;j<=elements-1;j++) {
00116         array[j] = atoi(argv[i+1+j]);
00117       }
00118       for (j=i+elements;j>=i;j--) {
00119         updateArgs(argc, argv, j);
00120       }
00121       return(array);
00122     }
00123   }
00124 
00125   return(array);
00126 }
00127 
00128 int *pc_intarrayarg(int *argc, char **argv, char *flag, int elements, int size) {
00129  
00130   int *array;
00131   int i,j;
00132 
00133   array = NULL;
00134 
00135   if (size < elements) {
00136     quit(-1,"pc_shortarrayarg Error : Size of array is less than number of elements\nto be read.\n");
00137   }
00138 
00139   for(i = 1; i < *argc-elements; i++){
00140     if (!strcmp(argv[i], flag)) {
00141 
00142       array = (int *) rr_malloc(size * sizeof(int));
00143 
00144       for (j=0;j<=elements-1;j++) {
00145         array[j] = atoi(argv[i+1+j]);
00146       }
00147       for (j=i+elements;j>=i;j--) {
00148         updateArgs(argc, argv, j);
00149       }
00150       return(array);
00151     }
00152   }
00153 
00154   return(array);
00155 }
00156 
00157 void pc_report_unk_args(int *argc, char **argv, int verbosity) {
00158  
00159   int i;
00160  
00161   if (*argc > 1) {
00162     fprintf(stderr,"Error : Unknown (or unprocessed) command line options:\n");
00163     for (i = 1; i< *argc; i++) {
00164       fprintf(stderr,"%s ",argv[i]);
00165     }
00166     quit(-1,"\nRerun with the -help option for more information.\n");
00167   }
00168 }
00169 
00170 void report_version(int *argc, char **argv) {
00171 
00172   if (pc_flagarg(argc,argv,"-version")) {
00173     quit(-1,"%s from the CMU-Cambridge SLM Toolkit V%3.2f\n",argv[0],SLM_VERSION);
00174     
00175   }
00176 }
00177 

Generated on Tue Dec 21 13:54:45 2004 by doxygen1.2.18