00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #include <stdio.h>
00067 #include <stdlib.h>
00068 #include <string.h>
00069 #include <lal/LALConfig.h>
00070
00071 #ifdef HAVE_UNISTD_H
00072 #include <unistd.h>
00073 #endif
00074
00075 #ifdef HAVE_GETOPT_H
00076 #include <getopt.h>
00077 #endif
00078
00079 #include <lal/LALStdlib.h>
00080 #include <lal/LALHello.h>
00081
00082 #define CODES_(x) #x
00083 #define CODES(x) CODES_(x)
00084
00085 NRCSID( MAIN, "$Id: LALHelloTest.c,v 1.12 2007/06/08 14:41:46 bema Exp $" );
00086
00087 extern char *optarg;
00088 extern int optind;
00089
00090 int lalDebugLevel = 0;
00091 int verbose = 0;
00092
00093 static void
00094 Usage( const char *program, int exitflag );
00095
00096 static void
00097 ParseOptions( int argc, char *argv[] );
00098
00099 static void
00100 TestStatus( LALStatus *status, const char *expectedCodes, int exitCode );
00101
00102 static void
00103 ClearStatus( LALStatus *status );
00104
00105 int
00106 main( int argc, char *argv[] )
00107 {
00108 static LALStatus status;
00109 LALStatus keep;
00110
00111 ParseOptions( argc, argv );
00112
00113 LALHello( &status, NULL );
00114 TestStatus( &status, CODES(0), 1 );
00115
00116 LALHello( &status, "\0" );
00117 TestStatus( &status, CODES(-1), 1 );
00118
00119 keep = status;
00120
00121 LALHello( &status, NULL );
00122 TestStatus( &status, CODES(-2), 1 );
00123
00124
00125 ClearStatus( &keep );
00126
00127 LALCheckMemoryLeaks();
00128 return 0;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 static void
00141 TestStatus( LALStatus *status, const char *ignored, int exitcode )
00142 {
00143 char str[64];
00144 char *tok;
00145
00146 if ( verbose )
00147 {
00148 REPORTSTATUS( status );
00149 }
00150
00151 if ( strncpy( str, ignored, sizeof( str ) ) )
00152 {
00153 if ( ( tok = strtok( str, " " ) ) )
00154 {
00155 do
00156 {
00157 if ( status->statusCode == atoi( tok ) )
00158 {
00159 return;
00160 }
00161 }
00162 while ( ( tok = strtok( NULL, " " ) ) );
00163 }
00164 else
00165 {
00166 if ( status->statusCode == atoi( tok ) )
00167 {
00168 return;
00169 }
00170 }
00171 }
00172
00173 fprintf( stderr, "\nExiting to system with code %d\n", exitcode );
00174 exit( exitcode );
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 void
00187 ClearStatus( LALStatus *status )
00188 {
00189 if ( status->statusPtr )
00190 {
00191 ClearStatus( status->statusPtr );
00192 DETATCHSTATUSPTR( status );
00193 }
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203 static void
00204 Usage( const char *program, int exitcode )
00205 {
00206 fprintf( stderr, "Usage: %s [options]\n", program );
00207 fprintf( stderr, "Options:\n" );
00208 fprintf( stderr, " -h print this message\n" );
00209 fprintf( stderr, " -q quiet: run silently\n" );
00210 fprintf( stderr, " -v verbose: print extra information\n" );
00211 fprintf( stderr, " -d level set lalDebugLevel to level\n" );
00212 exit( exitcode );
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222 static void
00223 ParseOptions( int argc, char *argv[] )
00224 {
00225 while ( 1 )
00226 {
00227 int c = -1;
00228
00229 c = getopt( argc, argv, "hqvd:" );
00230 if ( c == -1 )
00231 {
00232 break;
00233 }
00234
00235 switch ( c )
00236 {
00237 case 'd':
00238 lalDebugLevel = atoi( optarg );
00239 break;
00240
00241 case 'v':
00242 ++verbose;
00243 break;
00244
00245 case 'q':
00246 freopen( "/dev/null", "w", stderr );
00247 freopen( "/dev/null", "w", stdout );
00248 break;
00249
00250 case 'h':
00251 Usage( argv[0], 0 );
00252 break;
00253
00254 default:
00255 Usage( argv[0], 1 );
00256 }
00257
00258 }
00259
00260 if ( optind < argc )
00261 {
00262 Usage( argv[0], 1 );
00263 }
00264
00265 return;
00266 }