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.1"
00003 #define CLP_DATE "09-JUN-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 09/06/2003 - Uli Fechner - v1.0.1 - modified according to the needs of countSmarts
00030 * @@code
00031 */
00032 typedef struct
00033 {
00034         char* outputFile;
00035         char* smartsFile;
00036         char* errorLogFile;
00037         int matchingType;
00038         int uniqueSmiles;
00039 } CommandLineParameters;
00040 /** @endcode */
00041 
00042 /** A pointer to structure @ref CommandLineParameters is assigned the name @c CLP_Ptr. */
00043 typedef CommandLineParameters* CLP_Ptr;
00044 
00045 /* function prototypes */
00046 
00047 CLP_Ptr CLP_create( void );
00048 
00049 void CLP_destroy( CLP_Ptr clpPtr );
00050 
00051 void CLP_display( const CLP_Ptr clpPtr, FILE* outputStream );
00052 
00053 void CLP_setOutputFile( const CLP_Ptr clpPtr, const char* const name );
00054 
00055 char* CLP_getOutputFile( const CLP_Ptr clpPtr );
00056 
00057 void CLP_setSmartsFile( const CLP_Ptr clpPtr, const char* const name );
00058 
00059 char* CLP_getSmartsFile( const CLP_Ptr clpPtr );
00060 
00061 void CLP_setErrorLogFile( const CLP_Ptr clpPtr, const char* const name );
00062 
00063 char* CLP_getErrorLogFile( const CLP_Ptr clpPtr );
00064 
00065 void CLP_setMatchingType( const CLP_Ptr clpPtr, const int matchingType );
00066 
00067 int CLP_getMatchingType( const CLP_Ptr clpPtr );
00068 
00069 void CLP_setUniqueSmiles( const CLP_Ptr clpPtr, const int boolean );
00070 
00071 int CLP_getUniqueSmiles( const CLP_Ptr clpPtr );
00072 
00073 /* functions */
00074 
00075 /** Creates a @ref CommandLineParameters structure.
00076 *
00077 * The structure @ref CommandLineParameters is created. The memory of the structure itself and the members
00078 * of the structure is allocated automatically. The values of the individual command line parameters are
00079 * set to default values as written in the help text.
00080 * @retval CLP_Ptr pointer on the newly created structure @ref CommandLineParameters
00081 * @author Uli Fechner
00082 * @version 13/05/2003 - Uli Fechner - initial release
00083 * @version 09/06/2004 - Uli Fechner - adjusted to the needs of countSmarts
00084 */
00085 CLP_Ptr CLP_create( void )
00086 {
00087         CLP_Ptr clpPtr;
00088         if( !( clpPtr = calloc( 1, sizeof( CommandLineParameters ) ) ) )
00089                 MemoryError( "CLP_create", "clpPtr" );
00090 
00091         CLP_setOutputFile( clpPtr, NULL );
00092         CLP_setSmartsFile( clpPtr, NULL );
00093         CLP_setErrorLogFile( clpPtr, NULL );
00094         CLP_setMatchingType( clpPtr, 2 );
00095         CLP_setUniqueSmiles( clpPtr, BOOLEAN_FALSE );
00096 
00097         return clpPtr;
00098 }
00099 
00100 /** Destroys a structure @ref CommandLineParameters.
00101 *
00102 * The structure @ref CommandLineParameters the pointer @c clpPtr refers to is destroyed. All
00103 * allocated memory of the structure and its members is automatically freed.
00104 *
00105 * @attention
00106 * The two strings (@c outputFile and @c catsTypeExpression) are freed here, too.
00107 *
00108 * @param clpPtr pointer on the structure @ref CommandLineParameters that should be destroyed
00109 * @author Uli Fechner
00110 * @version 13/05/2003 - Uli Fechner - initial release
00111 * @version 09/06/2004 - Uli Fechner - adjusted to the needs of countSmarts
00112 */
00113 void CLP_destroy( CLP_Ptr clpPtr )
00114 {
00115         if( clpPtr != NULL )
00116         {
00117                 if( CLP_getOutputFile( clpPtr ) != NULL )
00118                         free( CLP_getOutputFile( clpPtr ) );
00119                 if( CLP_getSmartsFile( clpPtr ) != NULL )
00120                         free( CLP_getSmartsFile( clpPtr ) );
00121                 if( CLP_getErrorLogFile( clpPtr ) != NULL )
00122                         free( CLP_getErrorLogFile( clpPtr ) );
00123                 free( clpPtr );
00124         }
00125         else
00126         {
00127                 fprintf( stderr, "\n\nERROR: Function 'CLP_destroy' is not able to destroy a structure\n" );
00128                 fprintf( stderr, "'CommandLineParameters' that has not been created before!\n" );
00129                 AbortProgram;
00130         }
00131 }
00132 
00133 /** Displays a structure @ref CommandLineParameters.
00134 *
00135 * The structure @ref CommandLineParameters the pointer @c clpPtr refers to is displayed on the FILE* @c
00136 * outputStream.
00137 *
00138 * @param clpPtr pointer on the structure @ref CommandLineParameters that should be displayed
00139 * @param outputStream FILE* on the stream the output should be sent to
00140 * @author Uli Fechner
00141 * @version 13/05/2003 - Uli Fechner - initial release
00142 * @version 09/06/2003 - Uli Fechner - adjusted to the needs of countSmarts
00143 */
00144 void CLP_display( CLP_Ptr clpPtr, FILE* outputStream )
00145 {       
00146         fprintf( outputStream, "Output file: %s\n", CLP_getOutputFile( clpPtr ) );
00147         fprintf( outputStream, "Error log file: %s\n", CLP_getErrorLogFile( clpPtr ) );
00148         fprintf( outputStream, "Smarts file: %s\n", CLP_getSmartsFile( clpPtr ) );
00149         fprintf( outputStream, "MatchingType: " );
00150         if( CLP_getMatchingType( clpPtr ) == 1 )
00151                 fprintf( outputStream, "1 - exhaustive search [dt_match,0]\n" );
00152         if( CLP_getMatchingType( clpPtr ) == 2 )
00153                 fprintf( outputStream, "2 - unique set-of-atoms in results [dt_umatch,0]\n" );
00154         if( CLP_getMatchingType( clpPtr ) == 3 )
00155                 fprintf( outputStream, "3 - each atom appears in exactly one result [dt_xmatch,0]\n" );
00156         fprintf( outputStream, "UniqueSmiles: " );
00157         if( CLP_getUniqueSmiles( clpPtr ) == BOOLEAN_FALSE )
00158                 fprintf( outputStream, "Nope\n" );
00159         else
00160                 fprintf( outputStream, "Yesh\n" );
00161         fprintf( outputStream, "\n" );
00162 }
00163 
00164 /** The name of the output file is set.
00165 *
00166 * @attention
00167 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00168 * the caller of this function.
00169 *
00170 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00171 * @param name name of the output file
00172 * @author Uli Fechner
00173 * @version 13/05/2003 - Uli Fechner - initial release
00174 */
00175 void CLP_setOutputFile( const CLP_Ptr clpPtr, const char* const name )
00176 {
00177         if( name != NULL )
00178         {
00179                 if( !( clpPtr->outputFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00180                         MemoryError( "CLP_setOutputFile", "clpPtr->outputFile" );       
00181                 strncpy( clpPtr->outputFile, name, strlen( name ) + 1 );
00182         }
00183         else
00184                 clpPtr->outputFile = NULL;
00185 }
00186 
00187 /** The name of the output file is returned.
00188 *
00189 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00190 * @retval char name of the output data file
00191 * @author Uli Fechner
00192 * @version 13/05/2003 - Uli Fechner - initial release
00193 */
00194 char* CLP_getOutputFile( const CLP_Ptr clpPtr )
00195 {
00196         return clpPtr->outputFile;
00197 }
00198 
00199 /** The name of the error log file is set.
00200 *
00201 * @attention
00202 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00203 * the caller of this function.
00204 *
00205 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00206 * @param name name of the error log file
00207 * @author Uli Fechner
00208 * @version 03/12/2003 - Uli Fechner - initial release
00209 */
00210 void CLP_setErrorLogFile( const CLP_Ptr clpPtr, const char* const name )
00211 {
00212         if( name != NULL )
00213         {
00214                 if( !( clpPtr->errorLogFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00215                         MemoryError( "CLP_setErrorLogFile", "clpPtr->errorLogFile" );   
00216                 strncpy( clpPtr->errorLogFile, name, strlen( name ) + 1 );
00217         }
00218         else
00219                 clpPtr->errorLogFile = NULL;
00220 }
00221 
00222 /** The name of the error log file is returned.
00223 *
00224 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00225 * @retval char name of the error log file
00226 * @author Uli Fechner
00227 * @version 03/12/2003 - Uli Fechner - initial release
00228 */
00229 char* CLP_getErrorLogFile( const CLP_Ptr clpPtr )
00230 {
00231         return clpPtr->errorLogFile;
00232 }
00233 
00234 /** The name of the Smarts file is set.
00235 *
00236 * @attention
00237 * The provided parameter @c name is copied. @c name is NOT freed afterwards. This has to be done by
00238 * the caller of this function.
00239 *
00240 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00241 * @param name name of the Smarts file
00242 * @author Tina Grabowski
00243 * @version 29/01/2004 - Tina Grabowski - initial release
00244 */
00245 void CLP_setSmartsFile( const CLP_Ptr clpPtr, const char* const name )
00246 {
00247         if( name != NULL )
00248         {
00249                 if( !( clpPtr->smartsFile = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00250                         MemoryError( "CLP_setSmartsFile", "clpPtr->SmartsFile" );       
00251                 strncpy( clpPtr->smartsFile, name, strlen( name ) + 1 );
00252         }
00253         else
00254                 clpPtr->smartsFile = NULL;
00255 }
00256 
00257 /** The name of the Smarts file is returned.
00258 *
00259 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00260 * @retval char name of the Smarts file
00261 * @author Tina Grabowski
00262 * @version 29/01/2004 - Tina Grabowski - initial release
00263 */
00264 char* CLP_getSmartsFile( const CLP_Ptr clpPtr )
00265 {
00266         return clpPtr->smartsFile;
00267 }
00268 
00269 /** Sets the number of the matching type.
00270 *
00271 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00272 * @param matchingType the number of the matching type
00273 * @author UF
00274 * @version 09/06/2004 - UF - initial release
00275 */
00276 void CLP_setMatchingType( const CLP_Ptr clpPtr, const int matchingType )
00277 {
00278         /* checking the allowed range of matchingType */
00279         if( matchingType > 0 && matchingType < 4 )      
00280                 clpPtr->matchingType = matchingType;
00281         else
00282         {
00283                 fprintf( stderr, "\nERROR: The value of option '-m' has to be in [1,3]!\n" );
00284                 fprintf( stderr, "Type 'countSmarts -h' for a detailed help text.\n" );
00285                 AbortProgram;
00286         }
00287 }
00288 
00289 /** The number of the matching type is returned.
00290 *
00291 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00292 * @retval int the number of the matching type
00293 * @author UF
00294 * @version 09/06/2004 - UF - initial release
00295 */
00296 int CLP_getMatchingType( const CLP_Ptr clpPtr )
00297 {
00298         return clpPtr->matchingType;
00299 }
00300 
00301 /** Sets whether or not the input file is filtered to yield unique SMILES.
00302 *
00303 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00304 * @param boolean boolean value (@ref BOOLEAN_FALSE or @ref BOOLEAN_TRUE)
00305 * @author UF
00306 * @version 09/06/2004 - UF - initial release
00307 */
00308 void CLP_setUniqueSmiles( const CLP_Ptr clpPtr, const int boolean )
00309 {
00310         clpPtr->uniqueSmiles = boolean;
00311 }
00312 
00313 /** Returns whether or not the input file is filtered to yield unique SMILES.
00314 *
00315 * @param clpPtr pointer on the structure @ref CommandLineParameters that contains the value
00316 * @retval int boolean value (@ref BOOLEAN_FALSE or @ref BOOLEAN_TRUE)
00317 * @author UF
00318 * @version 09/06/2004 - UF - initial release
00319 */
00320 int CLP_getUniqueSmiles( const CLP_Ptr clpPtr )
00321 {
00322         return clpPtr->uniqueSmiles;
00323 }

Generated on Mon Nov 8 16:04:06 2004 for countSmarts by doxygen 1.3.6