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

clp.c

Go to the documentation of this file.
00001 /* just some information about this file */
00002 #define CLP_VERSION     "1.0.4"
00003 #define CLP_DATE "29-Jan-2004"
00004 
00005 /* structures and typedefs */
00006 
00007 /** @file
00008 * @anchor CommandLineParameters
00009 * Fault-tolerant structure to store the values of all command line arguments.
00010 *
00011 * This structure provides a fault-tolerant way to store the values of all command line arguments. The
00012 * values are set to their default values during the creation of the structure via @ref CLP_create.
00013 * The memory allocation of the members of the structure is managed automatically.
00014 *
00015 * The structure is created with @ref CLP_create, destroyed with @ref CLP_destroy and displayed with
00016 * @ref CLP_display. With CLP_set<i>nameOfVariable</i> and CLP_get<i>nameOfVariable</i> the values of
00017 * the individual members of the structure @ref CommandLineParameters could be set or gotten.
00018 *
00019 * Whenever a string is set the provided string is @b copied via @c strncpy. Hence, the string provided
00020 * as an argument has to be freed by the caller of the function.
00021 * 
00022 * <B>Description of the members:</B><BR><BR>
00023 * @c outputFile - string containing the name of the output file.<BR>
00024 * @c reactionFile - string storing the name of the reaction file.<BR>
00025 * @c errorLogFile - string storing the name of the SMILES error log file.<BR>
00026 * <P>
00027 * @author Uli Fechner
00028 * @version 05/13/2003 - Uli Fechner - v1.0.0 - initial release
00029 * @version 24/11/2003 - Uli Fechner - v1.0.1 - modified according to the needs of retroflux
00030 * @version 03/12/2003 - Uli Fechner - v1.0.2 - added the member @c errorLogFile
00031 * @version 07/01/2004 - Uli Fechner - v1.0.3 - added the member @c filterFile
00032 * @version 29/01/2004 - Tina Grabowski - v1.0.4 - added the member @c smartsFile and the corresponding
00033 *                       functions @ref CLP_getSmartsFile and @ref CLP_setSmartsFile; consideration of @c
00034 *                       smartsFile in @ref CLP_create, @ref CLP_display and @ref CLP_destroy
00035 * @@code
00036 */
00037 typedef struct
00038 {
00039         char* outputFile;
00040         char* reactionFile;
00041         char* filterFile;
00042         char* smartsFile;
00043         char* errorLogFile;
00044 } CommandLineParameters;
00045 /** @endcode */
00046 
00047 /** A pointer to structure @ref CommandLineParameters is assigned the name @c CLP_Ptr. */
00048 typedef CommandLineParameters* CLP_Ptr;
00049 
00050 /* function prototypes */
00051 
00052 CLP_Ptr CLP_create( void );
00053 
00054 void CLP_destroy( CLP_Ptr clpPtr );
00055 
00056 void CLP_display( const CLP_Ptr clpPtr, FILE* outputStream );
00057 
00058 void CLP_setOutputFile( const CLP_Ptr clpPtr, const char* const name );
00059 
00060 char* CLP_getOutputFile( const CLP_Ptr clpPtr );
00061 
00062 void CLP_setReactionFile( const CLP_Ptr clpPtr, const char* const name );
00063 
00064 char* CLP_getReactionFile( const CLP_Ptr clpPtr );
00065 
00066 void CLP_setErrorLogFile( const CLP_Ptr clpPtr, const char* const name );
00067 
00068 char* CLP_getErrorLogFile( const CLP_Ptr clpPtr );
00069 
00070 void CLP_setFilterFile( const CLP_Ptr clpPtr, const char* const name );
00071 
00072 char* CLP_getFilterFile( const CLP_Ptr clpPtr );
00073 
00074 void CLP_setSmartsFile( const CLP_Ptr clpPtr, const char* const name );
00075 
00076 char* CLP_getSmartsFile( const CLP_Ptr clpPtr );
00077 
00078 /* functions */
00079 
00080 /** Creates a @ref CommandLineParameters structure.
00081 *
00082 * The structure @ref CommandLineParameters is created. The memory of the structure itself and the members
00083 * of the structure is allocated automatically. The values of the individual command line parameters are
00084 * set to default values as written in the help text.
00085 * @retval CLP_Ptr pointer on the newly created structure @ref CommandLineParameters
00086 * @author Uli Fechner
00087 * @version 13/05/2003 - Uli Fechner - initial release
00088 * @version 24/11/2003 - Uli Fechner - adjusted to the needs of flux
00089 * @version 03/12/2003 - Uli Fechner - added support for the member @c errorLogFile
00090 * @version 07/01/2004 - Uli Fechner - added support for the member @c filterFile
00091 * @version 29/01/2004 - Tina Grabowski - added support for the member @c smartsFile
00092 */
00093 CLP_Ptr CLP_create( void )
00094 {
00095         CLP_Ptr clpPtr;
00096         if( !( clpPtr = calloc( 1, sizeof( CommandLineParameters ) ) ) )
00097                 MemoryError( "CLP_create", "clpPtr" );
00098 
00099         CLP_setOutputFile( clpPtr, NULL );
00100         CLP_setReactionFile( clpPtr, NULL );
00101         CLP_setFilterFile( clpPtr, NULL );
00102         CLP_setSmartsFile( clpPtr, NULL );
00103         CLP_setErrorLogFile( clpPtr, NULL );
00104 
00105         return clpPtr;
00106 }
00107 
00108 /** Destroys a structure @ref CommandLineParameters.
00109 *
00110 * The structure @ref CommandLineParameters the pointer @c clpPtr refers to is destroyed. All
00111 * allocated memory of the structure and its members is automatically freed.
00112 *
00113 * @attention
00114 * The two strings (@c outputFile and @c catsTypeExpression) are freed here, too.
00115 *
00116 * @param clpPtr pointer on the structure @ref CommandLineParameters that should be destroyed
00117 * @author Uli Fechner
00118 * @version 13/05/2003 - Uli Fechner - initial release
00119 * @version 24/11/2003 - Uli Fechner - adjusted to the needs of retroflux
00120 * @version 07/01/2004 - Uli Fechner - added support for the member @c filterFile
00121 * @version 29/01/2004 - Tina Grabowski - added support for the member @c smartsFile
00122 */
00123 void CLP_destroy( CLP_Ptr clpPtr )
00124 {
00125         if( clpPtr != NULL )
00126         {
00127                 if( CLP_getOutputFile( clpPtr ) != NULL )
00128                         free( CLP_getOutputFile( clpPtr ) );
00129                 if( CLP_getReactionFile( clpPtr ) != NULL )
00130                         free( CLP_getReactionFile( clpPtr ) );
00131                 if( CLP_getFilterFile( clpPtr ) != NULL )
00132                         free( CLP_getFilterFile( clpPtr ) );
00133                 if( CLP_getSmartsFile( clpPtr ) != NULL )
00134                         free( CLP_getSmartsFile( clpPtr ) );
00135                 free( clpPtr );
00136         }
00137         else
00138         {
00139                 fprintf( stderr, "\n\nERROR: Function 'CLP_destroy' is not able to destroy a structure\n" );
00140                 fprintf( stderr, "'CommandLineParameters' that has not been created before!\n" );
00141                 AbortProgram;
00142         }
00143 }
00144 
00145 /** Displays a structure @ref CommandLineParameters.
00146 *
00147 * The structure @ref CommandLineParameters the pointer @c clpPtr refers to is displayed on the FILE* @c
00148 * outputStream.
00149 *
00150 * @param clpPtr pointer on the structure @ref CommandLineParameters that should be displayed
00151 * @param outputStream FILE* on the stream the output should be sent to
00152 * @author Uli Fechner
00153 * @version 13/05/2003 - Uli Fechner - initial release
00154 * @version 24/11/2003 - Uli Fechner - adjusted to the needs of flux
00155 * @version 03/12/2003 - Uli Fechner - added support for the member @c errorLogFile
00156 * @version 07/01/2004 - Uli Fechner - added support for the member @c filterFile
00157 * @version 29/01/2004 - Tina Grabowski - added support for the member @c smartsFile
00158 */
00159 void CLP_display( CLP_Ptr clpPtr, FILE* outputStream )
00160 {       
00161         fprintf( outputStream, "Output file: %s\n", CLP_getOutputFile( clpPtr ) );
00162         fprintf( outputStream, "Error log file: %s\n", CLP_getErrorLogFile( clpPtr ) );
00163         if( clpPtr->filterFile != NULL )
00164                 fprintf( outputStream, "Filter file: %s\n", CLP_getFilterFile( clpPtr ) );
00165         if( clpPtr->reactionFile != NULL )
00166                 fprintf( outputStream, "Reaction file: %s\n", CLP_getReactionFile( clpPtr ) );
00167         if( clpPtr->smartsFile != NULL )
00168                 fprintf( outputStream, "Smarts file: %s\n", CLP_getSmartsFile( clpPtr ) );
00169         fprintf( outputStream, "\n" );
00170 }
00171 
00172 /** The name of the output file is set.
00173 *
00174 * @attention
00175 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00176 * the caller of this function.
00177 *
00178 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00179 * @param name name of the output file
00180 * @author Uli Fechner
00181 * @version 13/05/2003 - Uli Fechner - initial release
00182 */
00183 void CLP_setOutputFile( const CLP_Ptr clpPtr, const char* const name )
00184 {
00185         if( name != NULL )
00186         {
00187                 if( !( clpPtr->outputFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00188                         MemoryError( "CLP_setOutputFile", "clpPtr->outputFile" );       
00189                 strncpy( clpPtr->outputFile, name, strlen( name ) + 1 );
00190         }
00191         else
00192                 clpPtr->outputFile = NULL;
00193 }
00194 
00195 /** The name of the output file is returned.
00196 *
00197 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00198 * @retval char name of the output data file
00199 * @author Uli Fechner
00200 * @version 13/05/2003 - Uli Fechner - initial release
00201 */
00202 char* CLP_getOutputFile( const CLP_Ptr clpPtr )
00203 {
00204         return clpPtr->outputFile;
00205 }
00206 
00207 /** The name of the reaction file is set.
00208 *
00209 * @attention
00210 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00211 * the caller of this function.
00212 *
00213 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00214 * @param name name of the reaction file
00215 * @author Uli Fechner
00216 * @version 24/11/2003 - Uli Fechner - initial release
00217 */
00218 void CLP_setReactionFile( const CLP_Ptr clpPtr, const char* const name )
00219 {
00220         if( name != NULL )
00221         {
00222                 if( !( clpPtr->reactionFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00223                         MemoryError( "CLP_setReactionFile", "clpPtr->reactionFile" );   
00224                 strncpy( clpPtr->reactionFile, name, strlen( name ) + 1 );
00225         }
00226         else
00227                 clpPtr->reactionFile = NULL;
00228 }
00229 
00230 /** The name of the reaction file is returned.
00231 *
00232 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00233 * @retval char name of the reaction data file
00234 * @author Uli Fechner
00235 * @version 24/11/2003 - Uli Fechner - initial release
00236 */
00237 char* CLP_getReactionFile( const CLP_Ptr clpPtr )
00238 {
00239         return clpPtr->reactionFile;
00240 }
00241 
00242 /** The name of the error log file is set.
00243 *
00244 * @attention
00245 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00246 * the caller of this function.
00247 *
00248 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00249 * @param name name of the error log file
00250 * @author Uli Fechner
00251 * @version 03/12/2003 - Uli Fechner - initial release
00252 */
00253 void CLP_setErrorLogFile( const CLP_Ptr clpPtr, const char* const name )
00254 {
00255         if( name != NULL )
00256         {
00257                 if( !( clpPtr->errorLogFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00258                         MemoryError( "CLP_setErrorLogFile", "clpPtr->errorLogFile" );   
00259                 strncpy( clpPtr->errorLogFile, name, strlen( name ) + 1 );
00260         }
00261         else
00262                 clpPtr->errorLogFile = NULL;
00263 }
00264 
00265 /** The name of the error log file is returned.
00266 *
00267 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00268 * @retval char name of the error log file
00269 * @author Uli Fechner
00270 * @version 03/12/2003 - Uli Fechner - initial release
00271 */
00272 char* CLP_getErrorLogFile( const CLP_Ptr clpPtr )
00273 {
00274         return clpPtr->errorLogFile;
00275 }
00276 
00277 /** The name of the filter file is set.
00278 *
00279 * @attention
00280 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00281 * the caller of this function.
00282 *
00283 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00284 * @param name name of the filter file
00285 * @author Uli Fechner
00286 * @version 07/01/2004 - Uli Fechner - initial release
00287 */
00288 void CLP_setFilterFile( const CLP_Ptr clpPtr, const char* const name )
00289 {
00290         if( name != NULL )
00291         {
00292                 if( !( clpPtr->filterFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00293                         MemoryError( "CLP_setFilterFile", "clpPtr->filterFile" );       
00294                 strncpy( clpPtr->filterFile, name, strlen( name ) + 1 );
00295         }
00296         else
00297                 clpPtr->filterFile = NULL;
00298 }
00299 
00300 /** The name of the filter file is returned.
00301 *
00302 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00303 * @retval char name of the filter file
00304 * @author Uli Fechner
00305 * @version 07/01/2004 - Uli Fechner - initial release
00306 */
00307 char* CLP_getFilterFile( const CLP_Ptr clpPtr )
00308 {
00309         return clpPtr->filterFile;
00310 }
00311 
00312 /** The name of the Smarts file is set.
00313 *
00314 * @attention
00315 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00316 * the caller of this function.
00317 *
00318 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00319 * @param name name of the Smarts file
00320 * @author Tina Grabowski
00321 * @version 29/01/2004 - Tina Grabowski - initial release
00322 */
00323 void CLP_setSmartsFile( const CLP_Ptr clpPtr, const char* const name )
00324 {
00325         if( name != NULL )
00326         {
00327                 if( !( clpPtr->smartsFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00328                         MemoryError( "CLP_setSmartsFile", "clpPtr->SmartsFile" );       
00329                 strncpy( clpPtr->smartsFile, name, strlen( name ) + 1 );
00330         }
00331         else
00332                 clpPtr->smartsFile = NULL;
00333 }
00334 
00335 /** The name of the Smarts file is returned.
00336 *
00337 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00338 * @retval char name of the Smarts file
00339 * @author Tina Grabowski
00340 * @version 29/01/2004 - Tina Grabowski - initial release
00341 */
00342 char* CLP_getSmartsFile( const CLP_Ptr clpPtr )
00343 {
00344         return clpPtr->smartsFile;
00345 }

Generated on Tue Nov 9 16:27:11 2004 for retroflux by doxygen 1.3.6