ARA ROOT v3.10 Software

AraWebPlotter/configLib/configStore.cxx

00001 /* configStore.c - <short description of this file/module> */
00002 
00003 /* G.J.Crone, University College London */
00004 
00005 /*
00006  * Current CVS Tag:
00007  * $Header: /work1/anitaCVS/flightSoft/common/configLib/configStore.c,v 1.4 2005/06/15 16:22:00 rjn Exp $
00008  */
00009  
00010 /* 
00011  * Modification History : DO NOT EDIT - MAINTAINED BY CVS 
00012  * $Log: configStore.c,v $
00013  * Revision 1.4  2005/06/15 16:22:00  rjn
00014  * Fixed a lot of silly warnings
00015  *
00016  * Revision 1.3  2004/10/13 20:27:37  rjn
00017  * Added Mike's GPS code to the repository. And fixed a couple of minor bugs.
00018  *
00019  * Revision 1.2  2004/08/31 17:51:21  rjn
00020  * Stuck a load of syslog messages into the configLib stuff. Previosuly it used some strange wrapper around syslog, due to implementation issues on the operating system used by some parts of the MINOS daq.
00021  *
00022  * Revision 1.1  2004/08/31 15:48:09  rjn
00023  * Um... lots of additions. The biggest ones are switching from shared to static libraries, and the additon of configLib and kvpLib to read formatted config files. These two libraries were created by Gordon Crone (gjc@hep.ucl.ac.uk) and are in spirit released under the GPL license.
00024  * Also the first of the actually programs (Eventd) has been started. At the moment it just opens a socket to fakeAcqd. Other sockets and better handling of multiple sockets in socketLib are the next things on my to do list.
00025  *
00026  * Revision 1.1  2001/07/24 13:36:44  gjc
00027  * First check in of new package
00028  *
00029  *
00030  */ 
00031 
00032 /*
00033 DESCRIPTION
00034 <Insert a description of the file/module here>
00035 INCLUDE FILES: <place list of any relevant header files here>
00036 */
00037 
00038 /* includes */
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <syslog.h>
00042 #include <pwd.h>
00043 #include <string.h>
00044 #include <sys/stat.h>
00045 #include <unistd.h>
00046 #include <fcntl.h>
00047 #include <errno.h>
00048 #include <time.h>
00049 
00050 #include "configLib/configLib.h"
00051 #include "kvpLib/keyValuePair.h"
00052 
00053 /* defines */
00054 
00055 /* typedefs */
00056 
00057 /* globals */   
00058 
00059 /* locals */
00060 
00061 /* forward declarations */
00062 
00063 
00064  int copyFile2(const char *theFile, const char *newFile) 
00065  { 
00066      //Only works on relative small files (will write a better version) 
00067      static int errorCounter=0;
00068      char *buffer;
00069      //Open the input file
00070      FILE *fin = fopen(theFile,"r");
00071      unsigned long numBytes;
00072      if(!fin) {
00073          if(errorCounter<100) {
00074              syslog(LOG_ERR,"Error reading file %s -- Error %s\n",
00075                    theFile,strerror(errno));
00076              fprintf(stderr,"Error reading file %s-- Error %s\n",
00077                      theFile,strerror(errno));
00078              errorCounter++;
00079          }
00080          return -1;
00081      }
00082      
00083      fseek(fin,0,SEEK_END);
00084      (numBytes)=ftell(fin);
00085      fseek(fin,SEEK_SET,0);
00086      buffer=(char*)malloc((numBytes));
00087      fread(buffer,1,(numBytes),fin);
00088      fclose(fin);
00089      
00090      //Open the output file 
00091      FILE *fout = fopen(newFile,"w"); 
00092      if(!fout) { 
00093         if(errorCounter<100) { 
00094             syslog(LOG_ERR,"Couldn't open %s for copy of %s -- Error %s\n", 
00095                    newFile,theFile,strerror(errno)); 
00096             fprintf(stderr,"Couldn't open %s for copy of %s -- Error %s\n", 
00097                     newFile,theFile,strerror(errno)); 
00098             errorCounter++; 
00099         } 
00100         return -1; 
00101      } 
00102      fwrite(buffer,1,numBytes,fout); 
00103      fclose(fout); 
00104      free(buffer); 
00105      return 0; 
00106  } 
00107 
00108 
00109 
00110 ConfigErrorCode configSwitchToLast(char *configFile, time_t *rawTimePtr) {    
00111     
00112 //    int retVal=0;
00113     //   char* errMessage ;
00114     char configPath[FILENAME_MAX] ;
00115     struct passwd *myPwent ;
00116     int myUid ;
00117     struct stat fileStat ;
00118     char oldFileSpec[FILENAME_MAX] ;
00119     char lastFileSpec[FILENAME_MAX];
00120     char archiveFileSpec[FILENAME_MAX] ;
00121     char newFileSpec[FILENAME_MAX] ;
00122 
00123     char *tempPath =getenv ("ARA_WEBPLOTTER_CONFIG_DIR") ;
00124     if (tempPath == NULL) {
00125         /* Environment variable not set so use current dir if there's
00126            already a config file here */
00127       if (stat (configFile, &fileStat) == 0) {
00128         strcpy(configPath,"./");
00129       }
00130       else {
00131         /* Finally default to home directory */
00132         myUid = getuid () ;
00133         myPwent = getpwuid (myUid) ;
00134         strcpy(configPath,myPwent->pw_dir) ;
00135       }
00136     }
00137     else {
00138       strcpy(configPath,tempPath);
00139     }
00140 
00141 
00142      time ( rawTimePtr );
00143 
00144      strcpy (oldFileSpec, configPath) ;
00145      strcat (oldFileSpec, "/") ;
00146      strcat (oldFileSpec, configFile) ;
00147 
00148      strcpy (lastFileSpec, configPath) ;
00149      strcat (lastFileSpec, "/previous/") ;
00150      strcat (lastFileSpec, configFile) ;
00151 
00152      sprintf(archiveFileSpec,"%s/archive/%s.%ld",configPath,configFile,*rawTimePtr);
00153      sprintf(newFileSpec,"%s/%s.temp",configPath,configFile);
00154 
00155 
00156     if(stat (lastFileSpec, &fileStat) != 0) {
00157         syslog(LOG_ERR,"configSwitch couldn't find: %s",lastFileSpec);
00158         return CONFIG_E_NOFILE;
00159     }
00160     if(stat (oldFileSpec, &fileStat) != 0) {
00161         syslog(LOG_ERR,"configSwitch couldn't find: %s",oldFileSpec);
00162         return CONFIG_E_NOFILE;
00163     }
00164 
00165     // mv lastFileSpec newFileSpec
00166     // cp oldFileSpec lastFileSpec
00167     // mv oldFileSpec archiveFileSpec
00168     // mv newFileSpec oldFileSpec
00169     copyFile2(lastFileSpec,newFileSpec);
00170     copyFile2(oldFileSpec,lastFileSpec);
00171     copyFile2(oldFileSpec,archiveFileSpec);
00172     copyFile2(newFileSpec,oldFileSpec);
00173     unlink(newFileSpec);
00174 
00175     syslog(LOG_INFO,"configSwitch arcvhived: %s", archiveFileSpec);   
00176     return CONFIG_E_OK;
00177 
00178  }
00179 
00180 
00181 
00182  ConfigErrorCode configSwitch(char *configFile, char whichConfig, time_t *rawTimePtr) {    
00183 
00184  //    int retVal=0;
00185      //   char* errMessage ;
00186 
00187     char configPath[FILENAME_MAX] ;
00188     struct passwd *myPwent ;
00189     int myUid ;
00190     struct stat fileStat ;
00191     char oldFileSpec[FILENAME_MAX] ;
00192     char lastFileSpec[FILENAME_MAX];
00193     char archiveFileSpec[FILENAME_MAX] ;
00194     char newFileSpec[FILENAME_MAX] ;
00195 
00196     char *tempPath =getenv ("ARA_WEBPLOTTER_CONFIG_DIR") ;
00197     if (tempPath == NULL) {
00198         /* Environment variable not set so use current dir if there's
00199            already a config file here */
00200       if (stat (configFile, &fileStat) == 0) {
00201         strcpy(configPath,"./");
00202       }
00203       else {
00204         /* Finally default to home directory */
00205         myUid = getuid () ;
00206         myPwent = getpwuid (myUid) ;
00207         strcpy(configPath,myPwent->pw_dir) ;
00208       }
00209     }
00210     else {
00211       strcpy(configPath,tempPath);
00212     }
00213 
00214 
00215 
00216     time ( rawTimePtr );
00217 
00218     strcpy (oldFileSpec, configPath) ;
00219     strcat (oldFileSpec, "/") ;
00220     strcat (oldFileSpec, configFile) ;
00221 
00222     strcpy (lastFileSpec, configPath) ;
00223     strcat (lastFileSpec, "/previous/") ;
00224     strcat (lastFileSpec, configFile) ;
00225 
00226     sprintf(archiveFileSpec,"%s/archive/%s.%ld",configPath,configFile,*rawTimePtr);
00227     if(whichConfig>0) 
00228         sprintf(newFileSpec,"%s/defaults/%s.%d",configPath,configFile,whichConfig);
00229     else
00230         sprintf(newFileSpec,"%s/defaults/%s",configPath,configFile);
00231 
00232 
00233     if(stat (newFileSpec, &fileStat) != 0) {
00234         syslog(LOG_ERR,"configSwitch couldn't find: %s",newFileSpec);
00235         return CONFIG_E_NOFILE;
00236     }
00237     if(stat (oldFileSpec, &fileStat) != 0) {
00238         syslog(LOG_ERR,"configSwitch couldn't find: %s",oldFileSpec);
00239         return CONFIG_E_NOFILE;
00240     }
00241 
00242     // cp oldFileSpec lastFileSpec
00243     // mv oldFileSpec archiveFileSpec
00244     // cp newFileSpec oldFileSpec
00245     copyFile2(oldFileSpec,lastFileSpec);
00246     rename(oldFileSpec,archiveFileSpec);
00247     copyFile2(newFileSpec,oldFileSpec);
00248 
00249     syslog(LOG_INFO,"configSwitch arcvhived: %s", archiveFileSpec);   
00250     return CONFIG_E_OK;
00251 
00252  }
00253 
00254 
00255 
00256  /********************************************************************
00257  *
00258  * configReplace - Copies one file to another and archives replaced file
00259  *
00260  * <Insert longer description here>
00261  *
00262  * RETURNS: 0 => success,  -1 => failure
00263  *
00264  */
00265  ConfigErrorCode configReplace(char *oldFileName, char *newFileName, time_t *rawTimePtr)
00266  {
00267  /*     printf("configReplace %s %s\n",oldFileName,newFileName); */
00268  //    int retVal=0;
00269     //   char* errMessage ;
00270 
00271 
00272     char configPath[FILENAME_MAX] ;
00273     struct passwd *myPwent ;
00274     int myUid ;
00275     struct stat fileStat ;
00276     char oldFileSpec[FILENAME_MAX] ;
00277     char lastFileSpec[FILENAME_MAX];
00278     char archiveFileSpec[FILENAME_MAX] ;
00279     char newFileSpec[FILENAME_MAX] ;
00280 
00281     char *tempPath =getenv ("ARA_WEBPLOTTER_CONFIG_DIR") ;
00282     if (tempPath == NULL) {
00283         /* Environment variable not set so use current dir if there's
00284            already a config file here */
00285       if (stat (oldFileName, &fileStat) == 0) {
00286         strcpy(configPath,"./");
00287       }
00288       else {
00289         /* Finally default to home directory */
00290         myUid = getuid () ;
00291         myPwent = getpwuid (myUid) ;
00292         strcpy(configPath,myPwent->pw_dir) ;
00293       }
00294     }
00295     else {
00296       strcpy(configPath,tempPath);
00297     }
00298 
00299 
00300     time ( rawTimePtr );
00301 
00302     strcpy (oldFileSpec, configPath) ;
00303     strcat (oldFileSpec, "/") ;
00304     strcat (oldFileSpec, oldFileName) ;
00305 
00306     strcpy (lastFileSpec, configPath) ;
00307     strcat (lastFileSpec, "/previous/") ;
00308     strcat (lastFileSpec, oldFileName) ;
00309 
00310 
00311     if(rawTimePtr!=NULL)
00312        sprintf(archiveFileSpec,"%s/archive/%s.%ld",configPath,oldFileName,*rawTimePtr);
00313 
00314 
00315     strcpy (newFileSpec, configPath) ;
00316     strcat (newFileSpec, "/") ;
00317     strcat (newFileSpec, newFileName) ;
00318 
00319 
00320 
00321     if(stat (newFileSpec, &fileStat) != 0) {
00322         syslog(LOG_ERR,"configReplace couldn't find: %s",newFileSpec);
00323         return CONFIG_E_NOFILE;
00324     }
00325     if(stat (oldFileSpec, &fileStat) != 0) {
00326         syslog(LOG_ERR,"configReplace couldn't find: %s",oldFileSpec);
00327         return CONFIG_E_NOFILE;
00328     }
00329 
00330     // cp oldFileSpec lastFileSpec
00331     // mv oldFileSpec archiveFileSpec
00332     // mv newFileSpec oldFileSpec
00333     if(rawTimePtr) {
00334         copyFile2(oldFileSpec,lastFileSpec);
00335         rename(oldFileSpec,archiveFileSpec);
00336         rename(newFileSpec,oldFileSpec);
00337     }
00338     else {
00339         copyFile2(newFileSpec,oldFileSpec);
00340         unlink(newFileSpec);
00341     }
00342 
00343  //   unlink(newFileSpec);
00344 
00345 
00346  /*    sprintf(mvCommand,"cp %s %s\n",oldFileSpec,lastFileSpec); */
00347  /*    retVal=system(mvCommand); */
00348  /*    if(retVal<0) { */
00349  /*        syslog(LOG_ERR,"Problem storing config: %s %s ",archiveFileSpec,strerror(errno)); */
00350  /*        return CONFIG_E_SYSTEM; */
00351  /*    } */
00352  /*    sprintf(mvCommand,"mv %s %s\n",oldFileSpec,archiveFileSpec); */
00353  /*    retVal=system(mvCommand); */
00354  /*    if(retVal<0) { */
00355  /*        syslog(LOG_ERR,"Problem archiving config: %s %s ",archiveFileSpec,strerror(errno)); */
00356  /*        return CONFIG_E_SYSTEM; */
00357  /*    } */
00358  /*    sprintf(mvCommand,"mv %s %s\n",newFileSpec,oldFileSpec); */
00359  /*    retVal=system(mvCommand); */
00360  /*    if(retVal<0) { */
00361  /*        syslog(LOG_ERR,"Problem replacing config: %s %s ",archiveFileSpec,strerror(errno)); */
00362  /*        return CONFIG_E_SYSTEM; */
00363  /*    } */
00364     syslog(LOG_INFO,"configReplace arcvhived: %s", archiveFileSpec);   
00365     return CONFIG_E_OK;
00366  }
00367 
00368  /********************************************************************
00369  *
00370  * storeConfig - Write current contents of kvp buffer to file
00371  *
00372  * <Insert longer description here>
00373  *
00374  * RETURNS: 0 => success,  -1 => failure
00375  *
00376  */
00377  ConfigErrorCode configStore (
00378                               char* fileName,
00379                               char* blockName
00380                               )
00381  {
00382     int config ;
00383     //   char* errMessage ;
00384     char configPath[FILENAME_MAX]; ;
00385     struct passwd *myPwent ;
00386     int myUid ;
00387     struct stat fileStat ;
00388     char fileSpec[FILENAME_MAX] ;
00389     int status ;
00390     char tag[BLOCKNAME_MAX+3] ;
00391 
00392     char *tempPath = getenv ("ARA_WEBPLOTTER_CONFIG_DIR") ;
00393     if (tempPath == NULL) {
00394        /* Environment variable not set so use current dir if there's
00395           already a config file here */
00396        if (stat (fileName, &fileStat) == 0) {
00397          strcpy(configPath,"./") ;
00398        }
00399        else {
00400           /* Finally default to home directory */
00401           myUid = getuid () ;
00402           myPwent = getpwuid (myUid) ;
00403           strcpy(configPath,myPwent->pw_dir);
00404        }
00405     }
00406     else {
00407       strcpy(configPath,tempPath);
00408     }
00409 
00410     strcpy (fileSpec, configPath) ;
00411     strcat (fileSpec, "/") ;
00412     strcat (fileSpec, fileName) ;
00413     syslog(LOG_INFO,"storeConfig writing params to: %s", fileSpec) ;
00414 
00415     config = creat (fileSpec, 0664) ;
00416     if (config == -1) {
00417        syslog (LOG_ERR,"storeConfig: error %d creating %s", errno, fileSpec) ;
00418        return (CONFIG_E_SYSTEM) ;
00419     }
00420     else {
00421        snprintf (tag, BLOCKNAME_MAX+2, "<%s>\n", blockName) ;
00422        write (config, tag, strlen (tag)) ;
00423        status = kvpWrite (config) ;
00424        if (status == -1) {
00425            /*errMessage = kvpErrorString (kvpError()) ;*/
00426           syslog (LOG_ERR,"storeConfig: kvpWrite failed %s",kvpErrorString (kvpError()) ) ;
00427           close(config);
00428           return (CONFIG_E_KVP) ;
00429        }
00430        snprintf (tag, BLOCKNAME_MAX+3, "\n</%s>\n", blockName) ;
00431        write (config, tag, strlen (tag)) ;
00432        close(config);
00433        return (CONFIG_E_OK) ;
00434     }
00435  }
00436 
00437  ConfigErrorCode configAppend (
00438                               char* fileName,
00439                               char* blockName
00440                               )
00441  {
00442     int config ;
00443     //   char* errMessage ;
00444     char configPath[FILENAME_MAX] ;
00445     struct passwd *myPwent ;
00446     int myUid ;
00447     struct stat fileStat ;
00448     char fileSpec[FILENAME_MAX] ;
00449     int status ;
00450     char tag[BLOCKNAME_MAX+3] ;
00451 
00452     char *tempPath = getenv ("ARA_WEBPLOTTER_CONFIG_DIR") ;
00453     if (tempPath == NULL) {
00454        /* Environment variable not set so use current dir if there's
00455           already a config file here */
00456        if (stat (fileName, &fileStat) == 0) {
00457          strcpy(configPath,"./" );
00458        }
00459        else {
00460           /* Finally default to home directory */
00461           myUid = getuid () ;
00462           myPwent = getpwuid (myUid) ;
00463           strcpy(configPath,myPwent->pw_dir );
00464        }
00465     }
00466     else {
00467       strcpy(configPath,tempPath);
00468     }
00469 
00470     strcpy (fileSpec, configPath) ;
00471     strcat (fileSpec, "/") ;
00472     strcat (fileSpec, fileName) ;
00473     syslog(LOG_INFO,"configAppend writing params to: %s", fileSpec) ;
00474 
00475     config = open (fileSpec,O_CREAT|O_WRONLY|O_APPEND,0664) ;
00476     if (config == -1) {
00477        syslog (LOG_ERR,"configAppend: error %d creating %s", errno, fileSpec) ;
00478        return (CONFIG_E_SYSTEM) ;
00479     }
00480     else {
00481        snprintf (tag, BLOCKNAME_MAX+2, "\n\n<%s>\n", blockName) ;
00482        write (config, tag, strlen (tag)) ;
00483        status = kvpWrite (config) ;
00484        if (status == -1) {
00485            /*errMessage = kvpErrorString (kvpError()) ;*/
00486           syslog (LOG_ERR,"configAppend: kvpWrite failed %s",kvpErrorString (kvpError()) ) ;
00487           close(config);
00488           return (CONFIG_E_KVP) ;
00489        }
00490        snprintf (tag, BLOCKNAME_MAX+3, "\n</%s>\n", blockName) ;
00491        write (config, tag, strlen (tag)) ;
00492        close(config);
00493        return (CONFIG_E_OK) ;
00494     }
00495  }
00496 
00497 
00498 
00499  ConfigErrorCode configModifyInt(char *fileName,char *blockName,char *key,int value, time_t *rawTimePtr)
00500  /* Will tidy it up so that 
00501  Does exactly what it says on the tin */
00502  {
00503      /* Config file thingies */
00504      int status=0;
00505      KvpErrorCode kvpStatus=KVP_E_OK;
00506  //    char* eString;
00507      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00508      int numBlocks=0,blockNum;
00509      char tempFile[FILENAME_MAX];
00510      sprintf(tempFile,"%s.new",fileName);
00511      /* Load Config */
00512      kvpReset () ;
00513      readBlocks(fileName,blockList,&numBlocks);
00514      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00515          kvpReset () ;
00516          status = configLoad (fileName,blockList[blockNum]) ;
00517          if(status == CONFIG_E_OK) {    
00518              if (strcmp (blockName, blockList[blockNum]) == 0) {
00519  //             printf("Here\n");
00520                  kvpStatus=kvpUpdateInt(key,value);
00521                  if(kvpStatus!=KVP_E_OK) {
00522                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00523                  }
00524              }
00525  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00526              if(blockNum==0)
00527                  status = configStore(tempFile,blockList[blockNum]);
00528              else
00529                  status = configAppend(tempFile,blockList[blockNum]);
00530              if(status != CONFIG_E_OK) {
00531                  printf("Bugger\n");
00532              }
00533          }
00534      }
00535      return configReplace(fileName,tempFile,rawTimePtr);
00536  }
00537 
00538 
00539  ConfigErrorCode configModifyIntArray(char *fileName,char *blockName,char *key,int *values, int length, time_t *rawTimePtr)
00540  /* Will tidy it up so that 
00541  Does exactly what it says on the tin */
00542  {
00543      /* Config file thingies */
00544      int status=0;
00545      KvpErrorCode kvpStatus=KVP_E_OK;
00546  //    char* eString;
00547      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00548      int numBlocks=0,blockNum;
00549      char tempFile[FILENAME_MAX];
00550      sprintf(tempFile,"%s.new",fileName);
00551      /* Load Config */
00552      kvpReset () ;
00553      readBlocks(fileName,blockList,&numBlocks);
00554      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00555          kvpReset () ;
00556          status = configLoad (fileName,blockList[blockNum]) ;
00557          if(status == CONFIG_E_OK) {    
00558              if (strcmp (blockName, blockList[blockNum]) == 0) {
00559  //             printf("Here\n");
00560                  kvpStatus=kvpUpdateIntArray(key,values,length);
00561                  if(kvpStatus!=KVP_E_OK) {
00562                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00563                  }
00564              }
00565  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00566              if(blockNum==0)
00567                  status = configStore(tempFile,blockList[blockNum]);
00568              else
00569                  status = configAppend(tempFile,blockList[blockNum]);
00570              if(status != CONFIG_E_OK) {
00571                  printf("Bugger\n");
00572              }
00573          }
00574      }
00575      return configReplace(fileName,tempFile,rawTimePtr);
00576  }
00577 
00578  ConfigErrorCode configModifyUnsignedIntArray(char *fileName,char *blockName,char *key,unsigned int *values, int length, time_t *rawTimePtr)
00579  {
00580      /* Config file thingies */
00581      int status=0;
00582      KvpErrorCode kvpStatus=KVP_E_OK;
00583  //    char* eString;
00584      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00585      int numBlocks=0,blockNum;
00586      char tempFile[FILENAME_MAX];
00587      sprintf(tempFile,"%s.new",fileName);
00588      /* Load Config */
00589      kvpReset () ;
00590      readBlocks(fileName,blockList,&numBlocks);
00591      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00592          kvpReset () ;
00593          status = configLoad (fileName,blockList[blockNum]) ;
00594          if(status == CONFIG_E_OK) {    
00595              if (strcmp (blockName, blockList[blockNum]) == 0) {
00596  //             printf("Here\n");
00597                  kvpStatus=kvpUpdateUnsignedIntArray(key,values,length);
00598                  if(kvpStatus!=KVP_E_OK) {
00599                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00600                  }
00601              }
00602  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00603              if(blockNum==0)
00604                  status = configStore(tempFile,blockList[blockNum]);
00605              else
00606                  status = configAppend(tempFile,blockList[blockNum]);
00607              if(status != CONFIG_E_OK) {
00608                  printf("Bugger\n");
00609              }
00610          }
00611      }
00612      return configReplace(fileName,tempFile,rawTimePtr);
00613  }
00614 
00615  ConfigErrorCode configModifyFloatArray(char *fileName,char *blockName,char *key,float *values, int length, time_t *rawTimePtr) 
00616  {
00617     /* Config file thingies */
00618      int status=0;
00619      KvpErrorCode kvpStatus=KVP_E_OK;
00620  //    char* eString;
00621      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00622      int numBlocks=0,blockNum;
00623      char tempFile[FILENAME_MAX];
00624      sprintf(tempFile,"%s.new",fileName);
00625      /* Load Config */
00626      kvpReset () ;
00627      readBlocks(fileName,blockList,&numBlocks);
00628      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00629          kvpReset () ;
00630          status = configLoad (fileName,blockList[blockNum]) ;
00631          if(status == CONFIG_E_OK) {    
00632              if (strcmp (blockName, blockList[blockNum]) == 0) {
00633  //             printf("Here\n");
00634                  kvpStatus=kvpUpdateFloatArray(key,values,length);
00635                  if(kvpStatus!=KVP_E_OK) {
00636                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00637                  }
00638              }
00639  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00640              if(blockNum==0)
00641                  status = configStore(tempFile,blockList[blockNum]);
00642              else
00643                  status = configAppend(tempFile,blockList[blockNum]);
00644              if(status != CONFIG_E_OK) {
00645                  printf("Bugger\n");
00646              }
00647          }
00648      }
00649      return configReplace(fileName,tempFile,rawTimePtr);
00650 
00651  }
00652 
00653 
00654 
00655  ConfigErrorCode configModifyUnsignedInt(char *fileName,char *blockName,char *key,unsigned long value, time_t *rawTimePtr)
00656  /* Will tidy it up so that 
00657  Does exactly what it says on the tin */
00658  {
00659      /* Config file thingies */
00660      int status=0;
00661      KvpErrorCode kvpStatus=KVP_E_OK;
00662  //    char* eString;
00663      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00664      int numBlocks=0,blockNum;
00665      char tempFile[FILENAME_MAX];
00666      sprintf(tempFile,"%s.new",fileName);
00667      /* Load Config */
00668      kvpReset () ;
00669      readBlocks(fileName,blockList,&numBlocks);
00670      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00671          kvpReset () ;
00672          status = configLoad (fileName,blockList[blockNum]) ;
00673          if(status == CONFIG_E_OK) {    
00674              if (strcmp (blockName, blockList[blockNum]) == 0) {
00675  //             printf("Here\n");
00676                  kvpStatus=kvpUpdateUnsignedInt(key,value);
00677                  if(kvpStatus!=KVP_E_OK) {
00678                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00679                  }
00680              }
00681  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00682              if(blockNum==0)
00683                  status = configStore(tempFile,blockList[blockNum]);
00684              else
00685                  status = configAppend(tempFile,blockList[blockNum]);
00686              if(status != CONFIG_E_OK) {
00687                  printf("Bugger\n");
00688              }
00689          }
00690      }
00691      return configReplace(fileName,tempFile,rawTimePtr);
00692  }
00693 
00694 
00695 
00696  ConfigErrorCode configModifyFloat(char *fileName,char *blockName,char *key,float value, time_t *rawTimePtr)
00697  /* Will tidy it up so that 
00698  Does exactly what it says on the tin */
00699  {
00700      /* Config file thingies */
00701      int status=0;
00702      KvpErrorCode kvpStatus=KVP_E_OK;
00703  //    char* eString;
00704      char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00705      int numBlocks=0,blockNum;
00706      char tempFile[FILENAME_MAX];
00707      sprintf(tempFile,"%s.new",fileName);
00708      /* Load Config */
00709      kvpReset () ;
00710      readBlocks(fileName,blockList,&numBlocks);
00711      for(blockNum=0;blockNum<numBlocks;blockNum++) {
00712          kvpReset () ;
00713          status = configLoad (fileName,blockList[blockNum]) ;
00714          if(status == CONFIG_E_OK) {    
00715              if (strcmp (blockName, blockList[blockNum]) == 0) {
00716  //             printf("Here\n");
00717                  kvpStatus=kvpUpdateFloat(key,value);
00718                  if(kvpStatus!=KVP_E_OK) {
00719                      printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00720                  }
00721              }
00722  //         printf("%s\t%s\n",blockName,blockList[blockNum]);
00723              if(blockNum==0)
00724                  status = configStore(tempFile,blockList[blockNum]);
00725              else
00726                  status = configAppend(tempFile,blockList[blockNum]);
00727              if(status != CONFIG_E_OK) {
00728                  printf("Bugger\n");
00729              }
00730          }
00731      }
00732      return configReplace(fileName,tempFile,rawTimePtr);
00733  }
00734 
00735  ConfigErrorCode configModifyString(char *fileName,char *blockName,char *key,char *value, time_t *rawTimePtr)
00736  /* Will tidy it up so that 
00737  Does exactly what it says on the tin */
00738  {
00739      /* Config file thingies */
00740      int status=0;
00741      KvpErrorCode kvpStatus=KVP_E_OK;
00742 //    char* eString;
00743     char blockList[MAX_BLOCKS][BLOCKNAME_MAX];
00744     int numBlocks=0,blockNum;
00745     char tempFile[FILENAME_MAX];
00746     sprintf(tempFile,"%s.new",fileName);
00747     /* Load Config */
00748     kvpReset () ;
00749     readBlocks(fileName,blockList,&numBlocks);
00750     for(blockNum=0;blockNum<numBlocks;blockNum++) {
00751         kvpReset () ;
00752         status = configLoad (fileName,blockList[blockNum]) ;
00753         if(status == CONFIG_E_OK) {     
00754             if (strcmp (blockName, blockList[blockNum]) == 0) {
00755 //              printf("Here\n");
00756                 kvpStatus=kvpUpdateString(key,value);
00757                 if(kvpStatus!=KVP_E_OK) {
00758                     printf("%d\t%s\n",kvpStatus,kvpErrorString(kvpStatus));
00759                 }
00760             }
00761 //          printf("%s\t%s\n",blockName,blockList[blockNum]);
00762             if(blockNum==0)
00763                 status = configStore(tempFile,blockList[blockNum]);
00764             else
00765                 status = configAppend(tempFile,blockList[blockNum]);
00766             if(status != CONFIG_E_OK) {
00767                 printf("Bugger\n");
00768             }
00769         }
00770     }
00771     return configReplace(fileName,tempFile,rawTimePtr);
00772 
00773 }

Generated on Tue Jul 16 16:58:01 2013 for ARA ROOT v3.10 Software by doxygen 1.4.7