loadversion.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* INRIA 2006 */
00003 /* Allan CORNET */
00004 /*-----------------------------------------------------------------------------------*/ 
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include "loadversion.h"
00009 #include "with_module.h"
00010 #include "setgetSCIpath.h"
00011 #include "MALLOC.h"
00012 /*-----------------------------------------------------------------------------------*/ 
00013 #define FORMATFILENAMEVERSION  "%s/modules/%s/VERSION" 
00014 #define SCI_VERSION_MAJOR_keyword "SCI_VERSION_MAJOR"
00015 #define SCI_VERSION_MINOR_keyword "SCI_VERSION_MINOR"
00016 #define SCI_VERSION_MAINTENANCE_keyword "SCI_VERSION_MAINTENANCE"
00017 #define SCI_VERSION_STRING_keyword "SCI_VERSION_STRING"
00018 #define SCI_VERSION_REVISION_keyword "SCI_VERSION_REVISION"
00019 /*-----------------------------------------------------------------------------------*/ 
00020 extern BOOL FileExist(char *filename);
00021 /*-----------------------------------------------------------------------------------*/ 
00022 BOOL getversionmodule(char *modulename,
00023                                          int *sci_version_major,
00024                                          int *sci_version_minor,
00025                                          int *sci_version_maintenance,
00026                                          char *sci_version_string,
00027                                          int *sci_version_revision)
00028 {
00029         BOOL bOK=FALSE;
00030 
00031 
00032         if (with_module(modulename))
00033         {
00034                 char *filename_VERSION_module=NULL;
00035                 char *SciPath=NULL;
00036                 int len=0;
00037 
00038                 SciPath=getSCIpath();
00039                 len=strlen(FORMATFILENAMEVERSION)+strlen(SciPath)+strlen(modulename)+1;
00040                 filename_VERSION_module=(char*)MALLOC(sizeof(char)*len);
00041                 sprintf(filename_VERSION_module,FORMATFILENAMEVERSION,SciPath,modulename);
00042 
00043                 if (FileExist(filename_VERSION_module))
00044                 {
00045                         #define LineMaxSize 1024
00046                         char Line[LineMaxSize];
00047                         FILE *pFile;
00048 
00049                         pFile=fopen(filename_VERSION_module,"rt");
00050                         while (fgets(Line, LineMaxSize,pFile))
00051                         {
00052                                 int retval=0;
00053                                 char SCI_VERSION_TYPE[32];
00054 
00055                                 retval=sscanf(Line,"%s",SCI_VERSION_TYPE);
00056 
00057                                 if ( strcmp(SCI_VERSION_TYPE,SCI_VERSION_MAJOR_keyword) == 0 )
00058                                 {
00059                                         retval=sscanf(Line,"%s %d",SCI_VERSION_TYPE,sci_version_major);
00060                                 }
00061                                 else if ( strcmp(SCI_VERSION_TYPE,SCI_VERSION_MINOR_keyword) == 0 )
00062                                 {
00063                                         retval=sscanf(Line,"%s %d",SCI_VERSION_TYPE,sci_version_minor);
00064                                 }
00065                                 else if ( strcmp(SCI_VERSION_TYPE,SCI_VERSION_MAINTENANCE_keyword) == 0 )
00066                                 {
00067                                         retval=sscanf(Line,"%s %d",SCI_VERSION_TYPE,sci_version_maintenance);
00068                                 }
00069                                 else if ( strcmp(SCI_VERSION_TYPE,SCI_VERSION_STRING_keyword) == 0 )
00070                                 {
00071                                         int j=0;
00072                                         strncpy(sci_version_string,&Line[strlen(SCI_VERSION_STRING_keyword)],LineMaxSize);
00073                                         for (j=strlen(sci_version_string);j>0;j--)
00074                                         {
00075                                                 if (sci_version_string[j] == '\n')
00076                                                 {
00077                                                         sci_version_string[j]='\0';
00078                                                         break;
00079                                                 }
00080                                         }
00081                                 }
00082                                 else if ( strcmp(SCI_VERSION_TYPE,SCI_VERSION_REVISION_keyword) == 0 )
00083                                 {
00084                                         retval=sscanf(Line,"%s %d",SCI_VERSION_TYPE,sci_version_revision);
00085                                 }
00086                         }
00087                         fclose(pFile);
00088                         bOK=TRUE;
00089                 }
00090                 if (SciPath){FREE(SciPath);SciPath=NULL;}
00091                 if (filename_VERSION_module) {FREE(filename_VERSION_module);filename_VERSION_module=NULL;}
00092         }
00093         return bOK;
00094 }
00095 /*-----------------------------------------------------------------------------------*/ 

Generated on Sun Mar 4 15:03:46 2007 for Scilab [trunk] by  doxygen 1.5.1