## modules/ca/ca_configFns.c

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. stringPack
2. ca_populateDictionary
3. opSplitsen
4. ca_readConfig
5. ca_getDictionary
6. ca_get_int
7. ca_get_dirlist
8. ca_get_string
9. ca_get_boolean
10. ca_set_int
11. ca_change_int_value
12. testFunction
13. ca_getDatabase
14. ca_getSource
15. ca_getAllSources
16. ca_getAsource
17. ca_set_boolean
18. ca_set_dirlist
19. ca_set_string
20. ca_writeNewValue
21. ca_getStorageLocation
22. ca_getConfig
23. ca_getType

       1 #include <stdio.h>
       2 #include <stdlib.h>
       3 #include <glib.h>
       4 #include "ca_defs.h"
       5 #define DEBUG
       6
       7 /**********************************************
       8  * This file contains the definitions of all    *
       9  * the functions.                                                                               *
      10         **********************************************/
      11
      12
      13 void stringPack(char *dest, const char *source)
         /* [<][>][^][v][top][bottom][index][help] */
      14 {
      15 #ifdef DEBUG
      16 printf("\nInside stringPack function\n");
      17 #endif  /* DEBUG */
      18
      19 /*----------------------------------------------------------------------*\
      20
      21 *  Function to rewrite a line of text with only one blankspace between  *
      22 *  each word.
      23 *
      24
      25 \*----------------------------------------------------------------------*/
      26
      27
      28 /*
      29  * This while loop continues until the NULL character is copied into
      30  * the destination string.  If a tab character is copied into the
      31  * destination string, it is replaced with a blank-space character.
      32  *
      33  * Multiple blank-space and/or tab characters are skipped in the source
      34  * string until any other character is found.
      35  */
      36
      37         while (1)
      38                 {
      39                 *dest = *source;
      40
      41                 if (*dest == '\t')
      42                         (*dest = ' ');
      43
      44                 /* Exit if have copied the end of the string. */
      45                 if (*dest == '\0')
      46                         return;
      47
      48 /*
      49  * If the source character was a blank-space or a tab, move to the next
      50  * source character.  While the source character is a blank-space or a
      51  * tab, move to the next character (i.e. ignore these characters).  When
      52  * any other character is found in the source string, move to the next
      53  * element of the destination string.
      54  *
      55  * Otherwise, simultaneously, move to the next elements of the destination
      56  * and the source strings.
      57  */
      58
      59
      60
      61                 if ( (*source == ' ') || (*source == '\t') )
      62                         {
      63                         ++source;
      64                         while ( (*source == ' ') || (*source == '\t') )
      65                                 {
      66                                 ++source;
      67                                 }
      68
      69                         ++dest;
      70                         }
      71                 else
      72                         {
      73                         ++dest;
      74                         ++source;
      75                         }
      76                 }
      77 }
      78
      79
      80 void ca_populateDictionary(dict_t woordenboek[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
      81
      82 /*******************************************************************
      83  * ca_populateDictionary -- Parses dictionary file, initializes    *
      84  *                                                                      the dictionary structure and writes    *
      85  *                                                                      the file of dictionary symbols,                         *
      86         *                                                                       ca_dictSyms.h                                                                   *
      87         *                                                                                                                                                                               *
      88         * Parameters                                                                                                                                            *
      89         *               woordenboek -- the dictionary to be populated                                   *
      90         *               size -- the total number of variables i.e. the size of the  *
      91  *                                array of dict_t structures.  See D. & D., p.276               *
      92  *                                                                                                                                                                              *
      93  * Returns                                                                                                                                                      *
      94         *               Nothing ?  (may change this later)                                                                      *
      95  *                                                                                                                                                                              *
      96  *******************************************************************/
      97
      98 {
      99 const char *blankLine = "\n";
     100 const char *comment = "#";
     101 char line[120];
     102 char input[120];
     103 char test[120];
     104 int lineNo = 0;
     105 int i;
     106 int entry = 0;
     107 FILE *dictPtr, *defnPtr;
     108
     109 gchar **tokens;                         /* Pointer to an array of strings. */
     110
     111 /*
     112         * Try to open the dictionary file for reading.  If it cannot be
     113  * opened, exit with an error.
     114  */
     115 if ( (dictPtr = fopen("dictionary.txt", "r")) == NULL)
     116                 {
     117                 fprintf(stderr, "Error: Unable to open 'dictionary.txt'\n");
     118                 exit (51);
     119                 }
     120
     121
     122         /*
     123          *Try to open the definitions file for writing.  If it cannot be
     124   * opened,exit with an error
     125   */
     126 if ( (defnPtr = fopen("defs.txt", "w")) == NULL)
     127                 {
     128                 fprintf(stderr, "Error: Unable to open 'defs.txt'\n");
     129                 exit (51);
     130                 }
     131
     132                 /*
     133                  * Read the file one line at a time;
     134                  * if the line begins with a comment, ignore it;
     135                  * otherwise, split each line into tokens;
     136                  * print each token.
     137                  * Assign each token to the appropriate member of
     138                  * the appropriate element of the dictionary array.
     139                  */
     140
     141                 fgets(input, sizeof(input), dictPtr);
     142
     143                 if ( (strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0) )
     144
     145                         {
     146                         /*
     147                          * First remove the newline character.
     148                          * Then replace multiple tab and space
     149                          * characters with single space characters.
     150                          */
     151
     152                         /* Remove the newline character, if present.
     153                          * Replace the last character of the string
     154                          * array with with '\0'.
     155                          */
     156
     157                         input[strlen(input) - 1] = '\0';
     158
     159                         /* Now, remove the multiple space and tab
     160                          * characters.
     161                          */
     162
     163                         stringPack(line, input);
     164
     165                         g_strchomp(line); /* Remove trailing w-space. */
     166 #ifdef DEBUG
     167 puts(line);
     168 #endif  /*DEBUG */
     169
     170                         tokens = g_strsplit(line, " ", 0);
     171
     172 #ifdef DEBUG
     173                         for (i = 0; tokens[i] != NULL; i++)
     174                                 printf("tokens[%d] = %s\n", i, tokens[i]);
     175 #endif  /* DEBUG */
     176
     177                         /* We no longer need a variable for scope
     178                          * woordenboek[entry].varScope = atoi(tokens[1]);
     179                          */
     180
     181                         strcpy(woordenboek[entry].varName, tokens[0]);
     182                         strcpy(woordenboek[entry].varSym, tokens[1]);
     183                         strcpy(woordenboek[entry].varType, tokens[2]);
     184                         woordenboek[entry].varNum = entry;
     185
     186        /*
     187                          * Write the dictionary symbol and the entry number
     188                          * to the definitions file.
     189         */
     190                         fprintf(defnPtr, "%s\t%d\n", tokens[1], entry);
     191
     192                         ++entry;
     193                         }
     194         /*
     195          * Get the 2nd and subsequent line of the file.
     196          */
     197
     198         fgets(input, sizeof(input), dictPtr);
     199
     200         while(!feof(dictPtr) )
     201         {
     202                 /*
     203                  * Process the line if it is not a comment.
     204                  */
     205
     206                 if ( (strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0 ) )
     207                 {
     208                         /*
     209                          * First remove the newline character.
     210                          * Then replace multiple tab and space
     211                          * characters with single space characters.
     212                          */
     213
     214                         /* Remove the newline character, if present.
     215                          * Replace the last character of the string
     216                          * array with with '\0'.
     217                          */
     218
     219                         input[strlen(input) - 1] = '\0';
     220
     221                         /* Now, remove the multiple space and tab
     222                          * characters.
     223                          */
     224
     225                         stringPack(line, input);
     226
     227                         g_strchomp(line); /* Remove trailing w/space. */
     228 #ifdef  DEBUG
     229 puts(line);
     230 #endif  /* DEBUG */
     231                         tokens = g_strsplit(line, " ", 0);
     232
     233 #ifdef DEBUG
     234                         for (i = 0; tokens[i] != NULL; i++)
     235                                 printf("tokens[%d] = %s\n", i, tokens[i]);
     236 #endif  /* DEBUG */
     237
     238                         /*
     239                          * We no longer need to know the scope of a variable
     240                          * woordenboek[entry].varScope = atoi(tokens[1]);
     241         */
     242
     243                         strcpy(woordenboek[entry].varName, tokens[0]);
     244                         strcpy(woordenboek[entry].varSym, tokens[1]);
     245                         strcpy(woordenboek[entry].varType, tokens[2]);
     246                         woordenboek[entry].varNum = entry;
     247                         fprintf(defnPtr, "%s\t%d\n", tokens[1], entry);
     248                         ++entry;
     249                 }
     250                 fgets(input, sizeof(input), dictPtr);
     251         }
     252
     253 fclose(dictPtr);
     254 fclose(defnPtr);
     255
     256 }       /* End of ca_populateDictionary() function. */
     257
     258
     259 void opSplitsen (FILE *filePtr, gchar **tokenArray)
         /* [<][>][^][v][top][bottom][index][help] */
     260 {
     261 /*
     262  * Declaring character constants is safer than using #define.
     263  * See Oualline's book, p.145.
     264  *
     265  */
     266
     267 const char *blankLine = "\n";           /* Declared as a string, not a character. */
     268 const char *comment = "#";                      /* Declared as a string. */
     269 char line[99];
     270 char input[99];
     271 int lineNo = 0;
     272 int j;
     273
     274
     275         fgets(input, sizeof(input), filePtr); /* Get the (first) line from the */
     276                                          /* file to which filePtr points. */
     277
     278 #ifdef DEBUG
     279         printf("\nFIRST INPUT >>> %s\n", input);
     280 #endif  /* DEBUG */
     281
     282         /* Compare the first character of the input */
     283         /* to the comment and the newline strings. */
     284
     285         if ( (strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0) )
     286
     287
     288
     289                 {
     290                 /* Remove the newline character, if present. */
     291                 /* Replace the last character */
     292                 /* of the string array with '\0'. */
     293
     294                 input[strlen(input) - 1] = '\0';
     295 #ifdef DEBUG
     296 printf("First Input >>> %s\n", input);
     297 #endif /* DEBUG */
     298
     299                 strcpy(line, input);
     300 #ifdef DEBUG
     301 printf("First Line after copy >>> %s\n", line);
     302 #endif  /* DEBUG */
     303
     304                 stringPack(line, input);
     305 #ifdef DEBUG
     306 printf("Line: %s\n", line);
     307 #endif  /* DEBUG */
     308
     309                 g_strchomp(line);
     310 /*              g_strdelimit(line, " ", ':');
     311  *              g_strdelimit(line, "\t", '*');
     312 */
     313
     314                 printf("%3d> %s\n", ++lineNo, line);
     315
     316                 /*
     317                  * g_strsplit() is a GLib function;
     318                  * it returns an array of strings.
     319                  *
     320                  * Here, we split on two spaces, "  ".
     321                  * We set max_tokenArray to be 0.  We want the
     322                  * first token to be the name of the variable
     323                  * and the other tokens to be the value of the variable,
     324                  * qualifiers, etc.
     325                  */
     326
     327                 tokenArray = g_strsplit(line, " ", 0);
     328
     329                 for (j = 0; tokenArray[j] != NULL; j++)
     330                         printf("token[%d] = %s\n", j, tokenArray[j]);
     331                 } /* End of processing the first line, if not commented. */
     332
     333                 /* End of getting the first line. */
     334
     335
     336         /*Get the 2nd line of the file. */
     337         fgets(input, sizeof(input), filePtr);
     338
     339         while(!feof(filePtr) )
     340                 {
     341
     342                         /* Process the line if it is not commented. */
     343                         if ( (strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1) != 0 ) )
     344                         {
     345                 /* Remove the newline character, if present. */
     346                         input[strlen(input) -1] = '\0';
     347 #ifdef DEBUG
     348 printf("Subsequent Input >>> %s\n", input);
     349 #endif  /* DEBUG */
     350
     351                         strcpy(line, input);
     352 #ifdef DEBUG
     353 printf("Subsequent Line after copy >>> %s\n", line);
     354 #endif  /* DEBUG */
     355
     356                         stringPack(line, input);
     357 #ifdef DEBUG
     358 printf("Line: %s\n", line);
     359 #endif  /* DEBUG */
     360
     361                         g_strchomp(line);
     362 /*                      g_strdelimit(line, " ", ':');
     363  *                      g_strdelimit(line, "\t", '*');
     364  */
     365                         printf("%3d> %s\n", ++lineNo, line);
     366
     367                         /*
     368                          * See the comment above about the maximum
     369                          * number of tokens being set to 0.
     370                          */
     371
     372                         tokenArray = g_strsplit(line, " ", 0);
     373                         for (j = 0; tokenArray[j] != NULL; j++)
     374                                 {
     375                                 printf("token[%d] = %s\n", j, tokenArray[j]);
     376                                 /* Can also use puts(tokenArray[j]) here. */
     377                                 }
     378                         } /* Processed uncommented lines. */
     379
     380                 fgets(input, sizeof(input), filePtr);
     381                 } /* Processed the 2nd & subsequent lines of the file. */
     382
     383 } /* End of processing the opened file. */
     384
     385
     386 void ca_readConfig(const char *configFile, values_t confVars[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
     387 /*******************************************************************
     388  *                                                                                                                                                                              *
     389  * ca_readConfig -- parses the config file and writes the values   *
     390  *                                               into memory.                                                                                           *
     391  *                                                                                                                                                                              *
     392  * Parameters                                                                                                                                           *
     393  *              configFile -- the configuration file
     394         *               confVars[] -- the array of values structures                                            *
     395         *               size -- the number of configuration variables                                   *
     396  *                                                                                                                                                                              *
     397  * Returns                                                                                                                                                      *
     398  *              Nothing -- perhaps make this return 0 on successful exit ?      *
     399  *                                                                                                                                                                              *
     400  * Note:        Should we make the name of the config file a global             *
     401         *                       variable ?                                                                                                                              *
     402  *******************************************************************/
     403 {
     404 FILE *confPtr;                  /* Pointer to config file. */
     405 char name[STRLENGTH];           /* The name of the config variable */
     406 char value[STRLENGTH];                  /* The value of the variable */
     407 int location;                   /* Storage Location of the variable's value. */
     408 int type;        /* Data type of the variable, represented by an integer. */
     409
     410
     411 const char *blankLine = "\n";  /* Declared as a string, not a character. */
     412 const char *comment = "#";              /* Declared as a string. */
     413
     414 char source[16];                                                                        /* The name of a source. */
     415 char database[STRLENGTH];               /* The elements of a database. */
     416
     417 gchar **dbcomps;        /* Pointer to an array of strings that represents */
     418                                                         /* the components of a db. */
     419
     420 int i;                                  /* A counting variable. */
     421
     422 ca_database_t *newDbPtr;        /* A pointer to a new instance of */
     423                                                                                 /* ca_database_t.                                                */
     424
     425 ca_database_list_t *newSrc;     /* A pointer to a new instance of */
     426                                                                                 /* ca_database_list_t.                           */
     427
     428 /*
     429  * Function Prototype for ca_getStorageLocation()
     430  * We put it here; thus it can only be called from
     431  * within ca_readConfig()
     432  *
     433  * This function finds the location in the values_t array
     434  * where we store pointers to the string value and the actual
     435  * value of the variable.  It returns this location as an
     436  * integer.
     437  *
     438  */
     439 int ca_getStorageLocation(char [], dict_t [], int);
     440
     441 /*
     442         * Function Prototype for ca_getType()
     443         * We put it here so that it can only be called from
     444         * within ca_readConfig()
     445  *
     446  * This function returns the type of the configuration
     447  * variable.  It returns it as a string.
     448  *
     449  */
     450 int ca_getType(char [], dict_t [], int);
     451
     452
     453 #ifdef  DEBUG
     454 printf("\nInside readConfig() function.\n");
     455 printf("Configuration file is: %s\n", configFile);
     456 #endif  /* DEBUG */
     457
     458 /*
     459         * Open the configuration file for reading .....
     460  */
     461 if ( (confPtr = fopen(configFile, "r")) == NULL)
     462                 {
     463                 printf("Error: file %s could not be opened.\n", configFile);
     464                 exit (51);
     465                 }
     466
     467 /*
     468         * Read the first record in the configuration file .....
     469  * We read the _name_ of the variable using fscanf into a
     470  * string array.  We read the _value_ of the variable
     471  * using fgets into an array; thus, we can handle values of
     472  * variables with qualifiers (e.g. SPLIT after DBLIST) and
     473  * values with blank characters (e.g. REPLYBANNER).
     474  */
     475 fscanf(confPtr, "%s", name);
     476 fgets(value, sizeof(value), confPtr);
     477
     478
     479 /*
     480         *               While there are records to be read in the config file.
     481         *               write the current record into memory,
     482  *     read the next record in the config file
     483  */
     484
     485
     486 while (!feof(confPtr) )
     487         {
     488
     489 /*
     490         * From the variable name, find the dictionary number.
     491  * The dictionary number is defined as the place in the
     492  * values array in which to store the value of the variable.
     493  *
     494  */
     495
     496                 /*
     497                  * Process the line only when/if it is not a comment or
     498                  * a blankline.
     499      */
     500                 if ( (strncmp(name, comment, 1) != 0) && (strncmp(name, blankLine, 1) != 0) )
     501                         {
     502                         /*
     503                  * If the last character of "value" is '\n',
     504         * replace it with '\0'.
     505         */
     506                         if ( value[strlen(value) - 1] == '\n')
     507                                 {
     508                                 value[strlen(value) - 1] = '\0';
     509                                 }
     510
     511                         /*
     512                          * From the variable name, find the element of the values
     513                          * array in which to store the value of the variable.
     514         *
     515                          */
     516                         location = ca_getStorageLocation(name, dictionary, VARS);
     517                         printf("The location is: %d\n", location);
     518
     519                         /*
     520                          * See if the string value has already been stored;
     521                          * if it has, then concatenate the new value to it;
     522                          * if not, then allocate some memory and copy the
     523                          * string into it.
     524                          */
     525
     526                         /*
     527                          * If this variable already exists, it has a non-zero
     528         * value and this 'if' statement returns a "true" value.
     529                          * Otherwise, it returns a "zero" or "false" value.
     530                          */
     531                         if (confVars[location].strPtr)
     532                                 {
     533                                 strcat(confVars[location].strPtr, value);
     534                                 }
     535                         else
     536                                 {
     537                         /*
     538                          * Store a pointer to the string that contains the value
     539                          * This is not necessarily the actual value itself.
     540                          * First, we must allocate some memory.
     541                          */
     542                         confVars[location].strPtr = (char *)malloc(STRLENGTH_L);
     543                         /*
     544                          * We check the return value of the malloc function .....
     545         */
     546                         if (confVars[location].strPtr == NULL)
     547                                 {
     548                                 fprintf(stderr, "Cannot allocate memory for confVars[location].strPtr\n");
     549                                 exit (8);
     550                                 }
     551
     552                         strcpy(confVars[location].strPtr, value);
     553                                 }
     554
     555                         /*
     556                          * Now, store a pointer to the _value_ of the variable.
     557                          * Do this as follows:
     558                          * (a) get the _type_ of the variable
     559                          * (b) store a pointer to the value of the variable in
     560                          *     a way that depends on the _type_ of the variable.
     561         */
     562 #ifdef DEBUG
     563 printf("Variable \"%s\" is data-type \"%d\"\n", name, ca_getType(name, dictionary, VARS) );
     564 #endif /* DEBUG */
     565
     566
     567 type = ca_getType(name, dictionary, VARS);
     568
     569                         /*
     570                          * Given the _type_ of the variable, store the value of the
     571                  * variable in the appropriate way.
     572                          */
     573                         switch(type)
     574                                 {
     575                                 case 11:
     576                                 puts("Data type is Integer");
     577                                 confVars[location].valPtr = malloc(sizeof(int) );
     578                                 if (confVars[location].valPtr == NULL)
     579                                         {
     580                                         fprintf(stderr, "Cannot allocate memory !!!\n");
     581                                         exit (8);
     582                                         }
     583                                 sscanf(value, "%d", (int *) confVars[location].valPtr);
     584                                 break;
     585
     586                                 case 12:
     587                                 puts("Data type is String");
     588
     589                                 /*
     590                                  * Test if this variable has already been created.
     591                                  * Look for a non-zero i.e. true value.
     592                                  */
     593                                 if (confVars[location].valPtr)
     594                                         {
     595                                         printf("\n%s variable already exists\n", name);
     596                                         strcat(confVars[location].valPtr, value);
     597                                         }
     598                                 else
     599                                         {
     600                                         /*
     601                                          * If the variable has not already been created,
     602                                          * then create it.
     603                                          */
     604                                         printf("\n%s variable does not exist\n", name);
     605
     606                                         confVars[location].valPtr = (char *)malloc(STRLENGTH_XL);
     607                                         if (confVars[location].valPtr == NULL)
     608                                                 {
     609                                                 fprintf(stderr, "Cannot allocate memory !!!\n");
     610                                                 exit (8);
     611                                                 }
     612                                          strcpy(confVars[location].valPtr, value);
     613                                         }
     614
     615                                 break;
     616
     617                                 case 13:
     618                                 puts("Data type is Dirlist");
     619                                 confVars[location].valPtr = (char *)malloc(STRLENGTH);
     620                                 if (confVars[location].valPtr == NULL)
     621                                         {
     622                                         fprintf(stderr, "Cannot allocate memory !!!\n");
     623                                         exit (8);
     624                                         }
     625                                  strcpy(confVars[location].valPtr, value);
     626                                 break;
     627
     628                                 case 15:
     629                                 puts("Data type is Source !!!");
     630                                 /*
     631                                  * Split the value into "source" and "database"
     632            * Use blankspace as the delimiter between the
     633                                  * "source" and "database".
     634                                  */
     635                                 sscanf(value, "%s %s", source, database);
     636 #ifdef DEBUG
     637 puts(source);
     638 puts(database);
     639 #endif  /* DEBUG */
     640
     641                                 /*
     642                                  * Using the values in "database".
     643                                  * populate a ca_database_t structure.
     644                                  * Give this variable a name.
     645                                  *
     646                                  */
     647
     648                         /* First, separate the values in "database", using "," as
     649                                          * as a delimiting  character.
     650                                          */
     651                                 dbcomps = g_strsplit(database, ",", 0);
     652
     653 #ifdef DEBUG
     654 for (i = 0; dbcomps[i] != NULL; i++)
     655                 printf("dbcomps[%d] = %s\n", i, dbcomps[i]);
     656 #endif  /* DEBUG */
     657
     658
     659                                         /*
     660                                          * Create a structure for this database.
     661                                          */
     662                                 newDbPtr = malloc(sizeof(ca_database_t));
     663                                 if (newDbPtr == NULL)
     664                                         {
     665                                         fprintf(stderr, "Cannot allocate memory to new db structure\n");
     666                                         exit (8);
     667                                         }
     668
     669                                 strcpy(newDbPtr->host, dbcomps[0]);
     670                                 strcpy(newDbPtr->port, dbcomps[1]);
     671                                 strcpy(newDbPtr->user, dbcomps[2]);
     672                                 strcpy(newDbPtr->password, dbcomps[3]);
     673                                 strcpy(newDbPtr->dbName, dbcomps[4]);
     674 #ifdef DEBUG
     675 puts("Testing the population of the db structure:");
     676 printf("\n%s::%s::%s::%s::%s\n", newDbPtr->host, newDbPtr->port, newDbPtr->user, newDbPtr->password, newDbPtr->dbName);
     677 #endif /* DEBUG */
     678
     679                                 /*
     680                                  * Using the above ca_database_t structure
     681                                  * and the "source" value,
     682                                  * populate the ca_src_t structure.
     683                                  */
     684
     685                                         /*
     686                                          * Create a new structure for this source.
     687                                          */
     688                                 newSrc = malloc(sizeof(ca_database_list_t));
     689
     690                                 if (newSrc == NULL)
     691                                         {
     692                                         fprintf(stderr, "Cannot allocate memory to new source structure\n");
     693                                         exit (8);
     694                                         }
     695
     696                                 strcpy(newSrc->name, source);
     697                                 newSrc->db = *newDbPtr;
     698
     699 #ifdef DEBUG
     700 puts("Testing the population of the ca_database_list_t structure:");
     701 printf("\n%s::%s::%s::%s::%s::%s\n", newSrc->name, (newSrc->db).host, (newSrc->db).port, (newSrc->db).user, (newSrc->db).password, (newSrc->db).dbName);
     702 #endif /* DEBUG */
     703
     704                                 /*
     705                                  * Append this ca_src_t structure to the sourceList,
     706                                  * which is a singly-linked list if type GSList.
     707                                  */
     708
     709 sourceList = g_slist_append(sourceList, newSrc);
     710
     711 /*
     712  * 20000609
     713         * Experiment:
     714         * Add the newSrc to the other variable describing the list of sources,
     715  * mySrcList
     716  *
     717  * mySrcList = g_slist_append(mySrcList, newSrc);
     718  */
     719
     720                                 break;
     721
     722                                 default:
     723                                 printf("Data type not found for variable \"%s\".\n", name);
     724                                 break;
     725                                 }
     726                         }
     727
     728 fscanf(confPtr, "%s", name);
     729 fgets(value, sizeof(value), confPtr);
     730
     731         }       /* End of processing the config file. */
     732
     733 }       /* End of readConfig() function */
     734
     735
     736 /*
     737  * void ca_populateDictionary(dictionary_t woordenboek[], int size, FILE *fiPtr)
     738  * {
     739  * int j;
     740  * char input[99];
     741  *
     742  * for (j=0; (j < size) && !feof(fiPtr); j++)
     743  *      j = 0;
     744  *      while ((j < size) && !feof(fiPtr) )
     745  *      {
     746  *      printf("\n%d\n", j);
     747  *
     748  *      fgets(input, sizeof(input), filePtr);
     749  *
     750  *      if ( (strncmp(input, comment, 1) != 0) && (strncmp(input, blankLine, 1)
     751  * != 0) )
     752  *      {
     753  *      fscanf(fiPtr, "%s %s %s %s", woordenboek[j].varName, woordenboek[j].varScope, woordenboek[j].varSym, woordenboek[j].varType);
     754  *      }
     755  *
     756  *      fgets(input, sizeof(input), filePtr);
     757  *      printf("%s\n", woordenboek[j].varName);
     758  *      }
     759  * }
     760  *
     761  */
     762
     763
     764 void ca_getDictionary(dict_t woordenboek[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
     765 {
     766 int k;
     767
     768 for (k = 0; k <= size; k++)
     769         {
     770         printf("\nj = %d\n", k);
     771  /*
     772          * printf("%s\t%d\t%s\n", woordenboek[k].varName, woordenboek[k].varScope, woordenboek[k].varType);
     773          */
     774          printf("%s\t%s\t%s\t%d\n", woordenboek[k].varName, woordenboek[k].varSym, woordenboek[k].varType, woordenboek[k].varNum);
     775
     776         }
     777 }
     778
     779
     780 int ca_get_int(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
     781 {
     782 int *xPtr;
     783
     784                 /*
     785                  * First print a message saying that the ca_get_int()
     786                  * function is being called.
     787                  */
     788 #ifdef DEBUG
     789         printf("\nDEBUG: ca_get_int() function is called .....\n");
     790 printf("DEBUG: New value of StringPtr: %s\n", globals[symbol].strPtr);
     791 #endif  /* DEBUG */
     792
     793                 /*
     794                  * Look at the appropriate place in the dictionary;
     795                  * e.g. C_BINDPORT => the first element, index = 0.
     796                  *
     797                  * if the varType is not an integer, exit with an error;
     798                  *
     799                  * otherwise,
     800                  *              if the varScope is global, look for the value in the
     801                  *              appropriate place in memory in the global values array;
     802                  *    otherwise, look for the value in the appropriate place in
     803                  *      memory in the local values array;
     804                  *
     805                  *
     806                  */
     807
     808                 /* Look at the appropriate place in the dictionary. */
     809
     810 #ifdef DEBUG
     811                 printf("\nDEBUG: Variable type: %s\n", dictionary[symbol].varType);
     812 #endif  /* DEBUG */
     813
     814                 /* If the variable type is not an integer, exit with an error. */
     815                 if ( strcmp(dictionary[symbol].varType, "CA_INT") != 0)
     816                         {
     817                         fprintf(stderr, "Error: unexpected variable type.\n");
     818                         exit (51);
     819                         }
     820                 else
     821                         {
     822                         /*
     823                          * If the variable has global scope, look for it in
     824                          * the globals array.  Otherwise, look for it in the
     825                          * locals array.
     826                          *
     827                          */
     828
     829                         /*
     830                          * Lock the value of the variable before reading it.
     831                          */
     832
     833                         mutex_lock(&Lock);
     834
     835                                 switch(dictionary[symbol].varScope)
     836                                         {
     837                                         case 1:
     838 #ifdef  DEBUG
     839                                         printf("\nThis variable has global scope.\n");
     840                                         printf("The string is: %s\n", globals[symbol].strPtr);
     841                                         printf("String2Value: %d\n", atoi(globals[symbol].strPtr));
     842 #endif  /* DEBUG */
     843
     844                                         xPtr = globals[symbol].valPtr;
     845                                         printf("Value: %d\n", *xPtr);
     846                                         return(*xPtr);
     847                                         break;
     848
     849                                         case 99:
     850 #ifdef  DEBUG
     851                                         printf("\nThis variable has local scope.\n");
     852                                         printf("The string is %s\n", locals[symbol].strPtr);
     853                                         printf("String2Value: %d\n", atoi(locals[symbol].strPtr));
     854 #endif  /* DEBUG */
     855                                         xPtr = locals[symbol].valPtr;
     856                                         printf("Value: %d\n", *xPtr);
     857                                         return(*xPtr);
     858                                         break;
     859
     860                                         default:
     861                                         printf("\nAaaargh !!!  This variable has unwelcome scope.\n");
     862                                         break;
     863                                         }
     864                         /*
     865                          * Unlock the value of the variable after reading it.
     866                          */
     867                         mutex_unlock(&Lock);
     868
     869                         }
     870
     871 }
     872
     873 char *ca_get_dirlist(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
     874 {
     875 /*
     876  * This function returns a pointer to a character array.  Thus,
     877  * we need to declare such a pointer.
     878  *
     879  */
     880
     881 char *xPtr;
     882 #ifdef  DEBUG
     883         printf("\nca_get_dirlist() function is called .....\n");
     884 #endif  /* DEBUG */
     885
     886
     887                 /*
     888                  * Look at the appropriate place in the dictionary;
     889                  * e.g. CA_HELP => the second element, index = 1.
     890                  *
     891                  * if the varType is not CA_DIRLIST, exit with an error;
     892                  *
     893                  * otherwise,
     894                  *              if the varScope is global, look for the value in the
     895                  *              appropriate place in memory in the global values array;
     896                  *    otherwise, look for the value in the appropriate place in
     897                  *      memory in the local values array;
     898                  *
     899                  *
     900                  */
     901
     902                 /* Look at the appropriate place in the dictionary. */
     903
     904                 printf("\nVariable type: %s\n", dictionary[symbol].varType);
     905
     906                 /* If the variable type is not CA_DIRLIST, exit with an error. */
     907                 if ( strcmp(dictionary[symbol].varType, "CA_DIRLIST") != 0)
     908                         {
     909                         fprintf(stderr, "Error: unexpected variable type.\n");
     910                         exit (51);
     911                         }
     912                 else
     913                         {
     914                         /*
     915                          * If the variable has global scope, look for it in
     916                          * the globals array.  Otherwise, look for it in the
     917                          * locals array.
     918                          *
     919                          */
     920
     921                                 switch(dictionary[symbol].varScope)
     922                                         {
     923                                         case 1:
     924                                         printf("\nThis variable has global scope.\n");
     925                                         printf("The string is: %s\n", globals[symbol].strPtr);
     926                                         xPtr = globals[symbol].valPtr;
     927                                         printf("Value: %s\n", xPtr);
     928                                         return(xPtr);
     929                                         break;
     930
     931                                         case 99:
     932                                         printf("\nThis variable has local scope.\n");
     933                                         printf("The string is %s\n", locals[symbol].strPtr);
     934                                         xPtr = locals[symbol].valPtr;
     935                                         printf("Value: %s\n", xPtr);
     936                                         return(xPtr);
     937                                         break;
     938
     939                                         default:
     940                                         printf("\nAaaargh !!!  This variable has unwelcome scope.\n");
     941                                         break;
     942                                         }
     943
     944                         }
     945
     946 }
     947
     948
     949 char *ca_get_string(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
     950 {
     951 /*
     952  * This function returns a pointer to a character array.  Thus,
     953  * we need to declare such a pointer.
     954  *
     955  */
     956
     957 char *xPtr;
     958 #ifdef  DEBUG
     959         printf("\nca_get_text() function is called .....\n");
     960 #endif  /* DEBUG */
     961
     962
     963                 /*
     964                  * Look at the appropriate place in the dictionary;
     965                  * e.g. CA_REPLYBANNER => the third element, index = 2.
     966                  *
     967                  * if the varType is not CA_STRING, exit with an error;
     968                  *
     969                  * otherwise,
     970                  *              if the varScope is global, look for the value in the
     971                  *              appropriate place in memory in the global values array;
     972                  *    otherwise, look for the value in the appropriate place in
     973                  *      memory in the local values array;
     974                  *
     975                  *
     976                  */
     977
     978                 /* Look at the appropriate place in the dictionary. */
     979
     980                 printf("\nVariable type: %s\n", dictionary[symbol].varType);
     981
     982                 /* If the variable type is not CA_STRING, exit with an error. */
     983                 if ( strcmp(dictionary[symbol].varType, "CA_STRING") != 0)
     984                         {
     985                         fprintf(stderr, "Error: unexpected variable type.\n");
     986                         exit (51);
     987                         }
     988                 else
     989                         {
     990                         /*
     991                          * If the variable has global scope, look for it in
     992                          * the globals array.  Otherwise, look for it in the
     993                          * locals array.
     994                          *
     995                          */
     996
     997                                 switch(dictionary[symbol].varScope)
     998                                         {
     999                                         case 1:
    1000                                         printf("\nThis variable has global scope.\n");
    1001                                         printf("The string is: %s\n", globals[symbol].strPtr);
    1002                                         xPtr = globals[symbol].valPtr;
    1003                                         printf("Value: %s\n", xPtr);
    1004                                         return(xPtr);
    1005                                         break;
    1006
    1007                                         case 99:
    1008                                         printf("\nThis variable has local scope.\n");
    1009                                         printf("The string is %s\n", locals[symbol].strPtr);
    1010                                         xPtr = locals[symbol].valPtr;
    1011                                         printf("Value: %s\n", xPtr);
    1012                                         return(xPtr);
    1013                                         break;
    1014
    1015                                         default:
    1016                                         printf("\nAaaargh !!!  This variable has unwelcome scope.\n");
    1017                                         break;
    1018                                         }
    1019
    1020                         }
    1021 }
    1022
    1023
    1024 int ca_get_boolean(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
    1025 {
    1026 /**********************************************
    1027  * ca_get_boolean()                                                                     *
    1028         *                                                                                                                       *
    1029         *                                                                                                                       *
    1030         * Parameters                                                                                    *
    1031         *                                                                                                                       *
    1032         *       symbol -- the symbol for the variable           *
    1033  *                                                                                                                      *
    1034         *                                                                                                                       *
    1035         * Returns                                                                                               *
    1036         *                                                                                                                       *
    1037         *       1 if true, 0 if false.                                                  *
    1038  *                                                                                                                      *
    1039  * Remarks                                                                                              *
    1040         *                                                                                                                       *
    1041  *   Is there a better way to implement                 *
    1042         *   Boolean values in C ?                                                       *
    1043  *                                                                                                                      *
    1044         *********************************************/
    1045
    1046 int *xPtr;
    1047
    1048 /*
    1049  * Print this message if in debug mode.
    1050  *
    1051  */
    1052 #ifdef DEBUG
    1053         printf("\nca_get_boolean() function is called .....\n");
    1054 printf("DEBUG 5: New value of StringPtr: %s\n", globals[symbol].strPtr);
    1055 #endif  /* DEBUG        */
    1056
    1057 /**********************************************\
    1058  *                                                                                                                      *
    1059         * Here is how this works:                                                       *
    1060  *                                                                                                                      *
    1061  * (a) Check that the type of variable whose    *
    1062  *     value is being read is CA_BOOLEAN.               *
    1063  *                                                                                                                      *
    1064  * (b) Lock the value of the variable before    *
    1065  *              reading it.                                                                             *
    1066  *                                                                                                                      *
    1067  * (c) Depending on the scope of the variable   *
    1068  *     look for it in the appropriate array.    *
    1069  *                                                                                                                      *
    1070         * (d) Read the value of the variable.                   *
    1071  *                                                                                                                      *
    1072         * (e) Unlock the value of the variable after *
    1073  *              reading it.                                                                             *
    1074         *                                                                                                                       *
    1075  *                                                                                                                      *
    1076  * Returns                                                                                              *
    1077         *
    1078         *       an integer value as follows:                                    *
    1079         *               1 if the db is in testmode (true),                                                      *
    1080         *               0 if the db is not in testmode (false).                                 *
    1081 \*********************************************/
    1082
    1083
    1084 /*
    1085         * Look at the appropriate place in the dictionary;
    1086         * e.g. CA_BOOLEAN = the fifth element of the dict_t array,
    1087  * => index = 4.
    1088  *
    1089  * If the varType is not Boolean, exit with an error
    1090         *
    1091  * Otherwise,
    1092         *       if the varScope is global, look for the value in the
    1093         *       appropriate place in the global values array;
    1094         *
    1095         *       otherwise, look for the value in the appropriate place in the
    1096         *       locals array.
    1097         *
    1098  */
    1099
    1100 #ifdef DEBUG
    1101 /* Look in the appropriate place in the dictionary. */
    1102 printf("\nVariable type: %s\n", dictionary[symbol].varType);
    1103 #endif  /* DEBUG */
    1104
    1105 /* If the variable type is not Boolean, exit with an error. */
    1106
    1107         if ( strcmp(dictionary[symbol].varType, "CA_BOOLEAN") != 0)
    1108                 {
    1109                 fprintf(stderr, "Error: Boolean type expected.\n");
    1110                 exit (51);
    1111                 }
    1112
    1113         else
    1114                 {
    1115                 /*
    1116                  * Lock the value of the variable before reading it.
    1117                  *
    1118                  */
    1119
    1120                 mutex_lock(&Lock);
    1121
    1122                 /*
    1123                  * If the variable has global scope, look for it in the globals
    1124                  * array.  Otherwise, look for it in the locals array.
    1125                  *
    1126      */
    1127
    1128                 switch(dictionary[symbol].varScope)
    1129                         {
    1130                         case 1:
    1131                         printf("\nThis variable has global scope.\n");
    1132                         printf("The string is: %s\n", globals[symbol].strPtr);
    1133                         printf("String2Value: %d\n", atoi(globals[symbol].strPtr) );
    1134                         xPtr = globals[symbol].valPtr;
    1135                         printf("Value: %d\n", *xPtr);
    1136                         return (*xPtr);
    1137                         break;
    1138
    1139                         case 99:
    1140                         printf("\nThis variable has local scope.\n");
    1141                         printf("The string is %s\n", locals[symbol].strPtr);
    1142                         printf("String2Value: %d\n", atoi(locals[symbol].strPtr) );
    1143                         xPtr = locals[symbol].valPtr;
    1144                         printf("Value: %d\n", *xPtr);
    1145                         return(*xPtr);
    1146                         break;
    1147
    1148                         default:
    1149                         printf("\nError: This variable has unknown scope.\n");
    1150                         break;
    1151                         }
    1152
    1153                 /*
    1154                  * Unlock the value of the variable after reading it.
    1155                  */
    1156                 mutex_unlock(&Lock);
    1157
    1158                 }
    1159
    1160 }
    1161
    1162
    1163
    1164 void ca_set_int(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
    1165 {
    1166         /*********************************************
    1167          * ca_set_int()                                                                         *
    1168   *                                                                                                             *
    1169          * Parameters                                                                                   *
    1170          *              symbol -- the symbol for the variable.  *
    1171          *                                                                                                                      *
    1172          * Returns                                                                                              *
    1173          *              1 if successful 0 if not ?                                      *
    1174          *                                                                                                                      *
    1175          * Remarks                                                                                              *
    1176          *      Needs a better way to check for valid  *
    1177   *    values from the keyboard.                                        *
    1178          *                                                                                                                      *
    1179          *********************************************/
    1180
    1181         void *tempPtr;          /* Temp pointer to point to the value pointer
    1182                                                                 in the appropriate values array. */
    1183  char newPort[16];
    1184  int invalid;
    1185  int portNr;
    1186
    1187  /* Function to change the value in a given values array.
    1188   * This function can only be called from within ca_set_int().
    1189          */
    1190  int *ca_change_int_value(char []);
    1191  void testFunction(values_t values[]);
    1192
    1193         /*
    1194   * Using the symbol, look at the appropriate place in the
    1195          * dictionary.
    1196          */
    1197 #ifdef DEBUG
    1198  printf("\nca_set_int() function called .....\n");
    1199         printf("Variable type: %s\n", dictionary[symbol].varType);
    1200 #endif  /* DEBUG */
    1201
    1202
    1203 /*
    1204  * Make sure that a reasonable, sensible value of bind-port has
    1205  * been read from the keyboard.
    1206  */
    1207
    1208 do      {
    1209
    1210                 /*
    1211                  * First, flush input stream.
    1212      */
    1213                 fflush(stdin);
    1214
    1215                 /*
    1216                  * Prompt for the new value of the bind-port.
    1217                  */
    1218
    1219                 printf("\nNew value of bind-port (non-zero positive integer) >>> ");
    1220                 scanf("%s", newPort);
    1221                 /*
    1222                  * gets(newPort);
    1223                  */
    1224 #ifdef DEBUG
    1225                 printf("\nDEBUG: Value of newPort variable: %s\n", newPort);
    1226 #endif  /* DEBUG */
    1227
    1228                 sscanf(newPort, "%d", &portNr);
    1229
    1230 #ifdef DEBUG
    1231                 printf("\nDEBUG: Value of integer variable, portNr: %d\n", portNr);
    1232 #endif  /* DEBUG */
    1233
    1234                         if (portNr < 0)
    1235                                 {
    1236                                 invalid = 1;
    1237                                 puts("Only non-zero positive integer values accepted for bind-port");
    1238                                 }
    1239                         else
    1240                                 {
    1241                                 invalid = 0;
    1242                                 }
    1243
    1244                 } while(invalid);
    1245
    1246  /*
    1247          * Check that the function is attempting to set the correct type
    1248          * of value.  If not, do not set the value and exit.
    1249          */
    1250
    1251         if (strcmp(dictionary[symbol].varType, "CA_INT") != 0)
    1252                 {
    1253                 fprintf(stderr, "Error: unexpected variable type.\n");
    1254                 exit (51);
    1255                 }
    1256
    1257         /*
    1258          * Choose the appropriate values array.
    1259          */
    1260         switch(dictionary[symbol].varScope)
    1261                 {
    1262                 /* If the variable has global scope,
    1263                  * write it into the globals array.
    1264                  * If it has local scope,
    1265                  * write it into the local array.
    1266                  * If the scope cannot be found, then report an error.
    1267                  */
    1268                 case 1:
    1269                 globals[symbol].valPtr = ca_change_int_value(newPort);
    1270                 globals[symbol].strPtr = newPort;
    1271
    1272                 globals[symbol].strPtr = (char *)malloc(sizeof(newPort) );
    1273
    1274                 /* Check the return value of malloc() to make sure that we
    1275                  * actually got the memory.
    1276                  */
    1277                 if (globals[symbol].strPtr == NULL)
    1278                         {
    1279                         fprintf(stderr, "Cannot allocate memory for globals[symbol].strPtr.\n");
    1280                         exit (8);
    1281                         }
    1282 #ifdef DEBUG
    1283                 printf("DEBUG: New value of StringPtr: %s\n", globals[symbol].strPtr);
    1284 #endif  /* DEBUG */
    1285
    1286                 strcpy(globals[symbol].strPtr, newPort);
    1287
    1288 #ifdef DEBUG
    1289                 printf("DEBUG 2: New value of StringPtr: %s\n", globals[symbol].strPtr);
    1290 #endif  /* DEBUG */
    1291                 break;
    1292
    1293                 case 99:
    1294                 locals[symbol].valPtr = ca_change_int_value(newPort);
    1295                 /*
    1296                  * First allocate some memory and then copy the value of the new
    1297                  * Port into it.
    1298      */
    1299                 locals[symbol].strPtr = (char *)malloc(sizeof(newPort) );
    1300                 /*
    1301                  * Now, check that the memory was actually allocated.
    1302                  */
    1303                 if (locals[symbol].strPtr == NULL)
    1304                         {
    1305                         fprintf(stderr, "Cannot allocate memory for locals[symbol].strPtr\n");
    1306                         exit(8);
    1307                         }
    1308
    1309                 strcpy(locals[symbol].strPtr, newPort);
    1310                 /*
    1311                  * locals[symbol].strPtr = newPort;
    1312                  */
    1313                 break;
    1314
    1315                 default:
    1316                 fprintf(stderr, "Error; unknown scope: %d\n", dictionary[symbol].varScope);
    1317                 break;
    1318                 }
    1319
    1320  /*
    1321   * Write the new value of the variable to the correct place in
    1322   * this array.  (First, set a mutex lock ???).
    1323          */
    1324
    1325  /*
    1326          * Write the new value of this variable back to the config. file
    1327          */
    1328
    1329 ca_writeNewValue(symbol, newPort);
    1330
    1331                 printf("DEBUG 3: New value of StringPtr: %s\n", globals[symbol].strPtr);
    1332
    1333 }
    1334
    1335 int *ca_change_int_value(char value[])
         /* [<][>][^][v][top][bottom][index][help] */
    1336 {
    1337 void *tempPtr;
    1338
    1339 /*
    1340  * Check the return value of malloc() in case we did not actually get
    1341  * the memory.
    1342  */
    1343 tempPtr = malloc(sizeof(int) );
    1344 if (tempPtr == NULL)
    1345                 {
    1346                 fprintf(stderr, "Cannot allocate memory for tempPtr\n");
    1347                 exit (8);
    1348                 }
    1349
    1350 sscanf(value, "%d", (int *) tempPtr);
    1351 return(tempPtr);
    1352 }
    1353
    1354
    1355
    1356 void testFunction(values_t array[])
         /* [<][>][^][v][top][bottom][index][help] */
    1357 {
    1358         printf("\nInside the Test function.\n");
    1359         }
    1360
    1361
    1362 void ca_getDatabase(ca_database_t db)
         /* [<][>][^][v][top][bottom][index][help] */
    1363 {
    1364 printf("\n%s\t%s\t%s\t%s\t%s\n", db.host, db.port, db.user, db.password, db.dbName);
    1365 }
    1366
    1367 void ca_getSource(ca_database_list_t src)
         /* [<][>][^][v][top][bottom][index][help] */
    1368 {
    1369 printf("\n%s\t%s\t%s\t%s\t%s\t%s\n", src.name, (src.db).host, (src.db).port, (src.db).user, (src.db).password, (src.db).dbName);
    1370 }
    1371
    1372
    1373 void ca_getAllSources(GSList *sources)
         /* [<][>][^][v][top][bottom][index][help] */
    1374 {
    1375 /*
    1376  * Function Prototype of getSource().
    1377  * getSource can only be called from within getAllSources().
    1378  */
    1379 void ca_getAsource(ca_database_list_t *);
    1380
    1381 GSList *currentPtr;     /* Pointer to the structure at which we look. */
    1382
    1383 /*
    1384  * Look at the first member of the linked-list of sources.
    1385  */
    1386 currentPtr = sources;
    1387
    1388 /*
    1389  * Look at each data component of the source list,
    1390  * untill we reach the end of the list.
    1391  */
    1392 while(currentPtr != NULL)
    1393         {
    1394  ca_database_list_t *srcPtr = currentPtr->data;
    1395 printf("\n%s\t%s\t%s\t%s\t%s\t%s\n", srcPtr->name, (srcPtr->db).host, (srcPtr->db).port, (srcPtr->db).user, (srcPtr->db).password, (srcPtr->db).dbName);
    1396  currentPtr = currentPtr->next;
    1397         }
    1398 }
    1399
    1400 void ca_getAsource(ca_database_list_t *srcPtr)
         /* [<][>][^][v][top][bottom][index][help] */
    1401 {
    1402 printf("\n%s\t%s\t%s\t%s\t%s\t%s\n", srcPtr->name, (srcPtr->db).host, (srcPtr->db).port, (srcPtr->db).user, (srcPtr->db).password, (srcPtr->db).dbName);
    1403 }
    1404
    1405
    1406 void ca_set_boolean(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
    1407 {
    1408 /*************************************************************
    1409  *                                                                                                                                                              *
    1410  * ca_set_boolean()                                                                                                             *
    1411  *                                                                                                                                                              *
    1412         *                                                                                                                                                               *
    1413  * Parameters                                                                                                                           *
    1414  *                                                                                                                                                              *
    1415         *       symbol -- the symbol for the variable.                                                  *
    1416  *                                                                                                                                                              *
    1417         *                                                                                                                                                               *
    1418         * Returns                                                                                                                                       *
    1419         *                                                                                                                                                               *
    1420         *               nothing                                                                                                                         *
    1421  *                                                                                                                                                              *
    1422         *                                                                                                                                                               *
    1423  * Remarks                                                                                                                                      *
    1424         *                                                                                                                                                               *
    1425         *       Must check that a sensible value is given as input.             *
    1426         *                                                                                                                                                               *
    1427         *                                                                                                                                                               *
    1428         *************************************************************/
    1429
    1430
    1431 char newTestmodeStr[2];
    1432 int newTestmodeVal;     /* The new value of the testmode variable. */
    1433 int invalid;                            /* Flag to indicate an invalid new value.  */
    1434
    1435 FILE *testPtr, *tempPtr;                        /* The pointer to the files. */
    1436 char name[STRLENGTH];                           /* The name of the variable. */
    1437 char value[STRLENGTH];                  /* The value of the variable. */
    1438
    1439 /*
    1440  * Function to change the value in a given values array.
    1441  * This function can only be called from within ca_set_boolean().
    1442  */
    1443 int *ca_change_int_value(char []);
    1444
    1445
    1446 /*
    1447         * Using the symbol, look at the appropriate place in the
    1448  * dictionary.
    1449         */
    1450 #ifdef DEBUG
    1451 printf("\nca_set_int() function called .....\n");
    1452 printf("Variable type: %s\n", dictionary[symbol].varType);
    1453 #endif          /* DEBUG */
    1454
    1455 /*
    1456  * Check that the function is attempting to set the correct type of
    1457  * value.  If not, do not set the value, but exit instead.
    1458  */
    1459
    1460 if (strcmp(dictionary[symbol].varType, "CA_BOOLEAN") != 0)
    1461                 {
    1462                 fprintf(stderr, "Error: CA_BOOLEAN data type expected.\n");
    1463                 exit (51);
    1464                 }
    1465
    1466 /*
    1467  * First, flush the input stream.
    1468  */
    1469 fflush(stdin);
    1470
    1471
    1472 /*
    1473  * Make sure that a reasonable, sensible value of bind-port has
    1474  * been read from the keyboard.
    1475  */
    1476
    1477 do      {
    1478                         /*
    1479                          * Prompt for the new value of the testmode.
    1480                          */
    1481
    1482                         printf("\nNew value of testmode (0 or 1) >>> ");
    1483                         scanf("%s", newTestmodeStr);
    1484
    1485                         /*
    1486                          * We scanf() the value as a string, but we want it to be an
    1487                          * integer.  Thus, we use sscanf() to scanf the value from the
    1488          * string-variable and store it as an integer in an integer
    1489                          * variable.
    1490                          */
    1491                         sscanf(newTestmodeStr, "%d", &newTestmodeVal);
    1492
    1493                         /*
    1494         * We only change the testmode when the user is absolutely sure
    1495                          * that they want to change.  Thus, we only accept two possible
    1496                          * values for testmode.
    1497                          */
    1498
    1499                         if ( (newTestmodeVal < 0) || (newTestmodeVal > 1) )
    1500                                 {
    1501                                 invalid = 1;
    1502                                 puts("Only '0' or '1' accepted as value for testmode.");
    1503                                 }
    1504                         else
    1505                                 {
    1506                                 invalid = 0;
    1507                                 }
    1508                 } while(invalid);
    1509
    1510
    1511 /*
    1512         * Lock the value of the variable before changing it.
    1513  */
    1514
    1515 mutex_lock(&Lock);
    1516
    1517
    1518 /*
    1519  * Choose the appropriate values array.
    1520  */
    1521
    1522 switch(dictionary[symbol].varScope)
    1523                 {
    1524                 /*
    1525                  * If the variable has global scope,
    1526                  * write it into the globals array.
    1527                  * If it has local scope,
    1528                  * write it into the local array.
    1529                  * If the scope cannot be found, then report an error.
    1530      */
    1531                 case 1:
    1532                 globals[symbol].valPtr = ca_change_int_value(newTestmodeStr);
    1533                 globals[symbol].strPtr = newTestmodeStr;
    1534                 break;
    1535
    1536                 case 99:
    1537                 locals[symbol].valPtr = ca_change_int_value(newTestmodeStr);
    1538                 locals[symbol].strPtr = newTestmodeStr;
    1539                 break;
    1540
    1541                 default:
    1542                 fprintf(stderr, "Error: unknown scope: %d\n", dictionary[symbol].varScope);
    1543                 break;
    1544                 }
    1545
    1546 /*
    1547         * Write the new value of this variable back to the config file.
    1548  *
    1549  * To be implemented.
    1550  */
    1551
    1552 /*
    1553  * Find the actual name of the variable from the dictionary
    1554  * structure (use the variable symbol as an index into the
    1555  * array of dictionary structures.
    1556  */
    1557
    1558         printf("Name of variable to be changed: %s\n", dictionary[symbol].varName);
    1559         printf("Type of variable to be changed: %s\n", dictionary[symbol].varType);
    1560
    1561 /*
    1562         * Open the test config file for reading .....
    1563  */
    1564 if ( (testPtr = fopen(testFile, "r")) == NULL)
    1565         {
    1566         printf("File \"%s\" could not be opened.\n", testFile);
    1567         exit (51);
    1568         }
    1569
    1570 /*
    1571         * Open the temporary file for writing .....
    1572  */
    1573 if ((tempPtr = fopen(tempFile, "w")) == NULL)
    1574         {
    1575         printf("File \"%s\" could not be opened.\n", tempFile);
    1576  exit (51);
    1577  }
    1578
    1579 /*
    1580  * Read the first record in the test config file.
    1581  */
    1582
    1583  fscanf(testPtr, "%s", name);
    1584  fgets(value, sizeof(value), testPtr);
    1585
    1586  /*
    1587   * If the last character of "value" is '\n',
    1588   * replace it with '\0'.
    1589   */
    1590         if (value[strlen(value) - 1] == '\n')
    1591                 {
    1592                 printf("The value string is %s", value);
    1593                 printf("Replacing last character of \"%s\" with the NULL character\n", name);
    1594                 value[strlen(value) - 1] = '\0';
    1595                 printf("The new value string is %s", value);
    1596                 }
    1597
    1598
    1599 /*
    1600         * While there are records to be read in the test config file:
    1601         *               Write the current record into the temporary file.
    1602  *              Read the next record in the config file.
    1603  * Repeat untill the EOF has been reached.
    1604  */
    1605
    1606 while(!feof(testPtr) )
    1607         {
    1608  fprintf(tempPtr, "%s %s\n", name, value);
    1609  fscanf(testPtr, "%s", name);
    1610         fgets(value, sizeof(value), testPtr);
    1611
    1612  /*
    1613   * If the last character of "value" is '\n',
    1614   * replace it with '\0'.
    1615   */
    1616         if (value[strlen(value) - 1] == '\n')
    1617                 {
    1618                 printf("The last character of the value string is %c", value[strlen(value) - 1]);
    1619                 printf("The value string is %s", value);
    1620                 printf("Replacing last character of \"%s\" with the NULL character\n",name);
    1621                 value[strlen(value) - 1] = '\0';
    1622                 printf("The new value string is %s", value);
    1623                 }
    1624
    1625
    1626  /*
    1627   * if we read the variable that we want to change,
    1628   * stop reading this file and print only the name
    1629   * of this variable to the temporary file.
    1630   */
    1631
    1632         /*
    1633          * If we read the variable that we want to change,
    1634   * replace the value of this variable in the config
    1635   * file with the value supplied from the keyboard.
    1636   *
    1637   */
    1638         if ( strcmp(name, dictionary[symbol].varName) == 0)
    1639                 {
    1640                 strcpy(value, newTestmodeStr);
    1641                 printf("The replacement string is %s", value);
    1642                 }
    1643         /*
    1644          * Flush the pointer to the test config file.
    1645          */
    1646         fflush(testPtr);
    1647
    1648         }
    1649  /*
    1650          * Here ends the loop that writes the config file, with the
    1651   * new variable, to the temporary file.
    1652          */
    1653
    1654 /*
    1655  *
    1656  * While !(the record to be updated)
    1657         *       BEGIN
    1658         *  Write the record to the temporary file
    1659  *  Read the next record in the config file
    1660  *      END
    1661  *
    1662  * Write the new value to the temporary file
    1663  * Read the next record in the config file
    1664  * COMMENT: this is the record to be updated.
    1665  * COMMENT: discard this record.
    1666  *
    1667  * Read the next record in the config file
    1668         *
    1669  * While !(EOF)
    1670         *       BEGIN
    1671         *  write the record to the temporary file
    1672  *  read the next record in the config file
    1673  *  END
    1674  *
    1675  * Close Config file
    1676  * Close Temporary file
    1677  *
    1678  * Open Temporary file for reading
    1679  * Open Config file for writing
    1680  *
    1681  * Read the next record of the Temporary file
    1682  *
    1683  * While (!EOF of Temporary file)
    1684         *       BEGIN
    1685         *  write the record into the Config file
    1686         *  read the next record of the Temporary file
    1687  *  END
    1688  *
    1689         *       Close Temporary file
    1690  *  Close Config file
    1691  *
    1692  */
    1693
    1694 fclose(testPtr);
    1695 fclose(tempPtr);
    1696
    1697 /*
    1698         * Now, flush the file pointers
    1699  */
    1700         fflush(testPtr);
    1701         fflush(tempPtr);
    1702
    1703 /*
    1704  * Open the temporary file for reading.
    1705         * Open the config file for writing.
    1706  * Write the contents of the temporary file
    1707  * into the config file.
    1708  */
    1709
    1710 /*
    1711         * Open the temporary file for reading .....
    1712  */
    1713 if ((tempPtr = fopen(tempFile, "r")) == NULL)
    1714         {
    1715         printf("File \"%s\" could not be opened for reading.\n", tempFile);
    1716  exit (51);
    1717  }
    1718
    1719 /*
    1720         * Open the config file for writing .....
    1721  */
    1722 if ((testPtr = fopen(testFile, "w")) == NULL)
    1723         {
    1724         printf("File \"%s\" could not be opened for writing.\n", testFile);
    1725  exit (51);
    1726  }
    1727
    1728 /*
    1729  * Read the first record in the temporary file.
    1730  */
    1731
    1732  fscanf(tempPtr, "%s", name);
    1733  fgets(value, sizeof(value), tempPtr);
    1734         printf("\nFIRST LINE: %s %s", name, value);
    1735
    1736
    1737 /*
    1738         * While there are records to be read in the temporary file:
    1739         *               Write the current record into the test config file.
    1740  *              Read the next record in the temporary file.
    1741  * Repeat untill the EOF has been reached.
    1742  */
    1743
    1744 while(!feof(tempPtr) )
    1745         {
    1746  fprintf(testPtr, "%s %s", name, value);
    1747  fscanf(tempPtr, "%s", name);
    1748         fgets(value, sizeof(value), tempPtr);
    1749  }
    1750
    1751 fclose(testPtr);
    1752 fclose(tempPtr);
    1753
    1754 /*
    1755         * Unlock the value of the variable after setting it and writing the
    1756  * new value back to the configuration (and the dictionary) file.
    1757         *
    1758  */
    1759         mutex_unlock(&Lock);
    1760
    1761 }
    1762
    1763
    1764 void ca_set_dirlist(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
    1765 {
    1766 /****************************************************************
    1767         * ca_set_dirlist()                                                                                                                      *
    1768  *                                                                                                                                                                      *
    1769  * Parameters                                                                                                                                   *
    1770         *               symbol -- the symbol of the variable.                                                   *
    1771  *                                                                                                                                                                      *
    1772  * Returns                                                                                                                                              *
    1773         *               1 if successful, 0 if not successful.                                                   *
    1774         *                                                                                                                                                                       *
    1775         * Remarks                                                                                                                                               *
    1776  *              Writing the new value back to the config file has yet to *
    1777         *               be implemented.                                                                                                         *
    1778  *                                                                                                                                                                      *
    1779         ****************************************************************/
    1780
    1781  char newDir[80];
    1782  /*
    1783   * Declare a pointer to a values_t variable.
    1784          * Later, we shall assign this pointer to the first element
    1785   * of either the globals or the locals array, as appropriate.
    1786   */
    1787  values_t *hereValues;
    1788
    1789         /*
    1790          * Using the symbol, look in the appropriate place in the dictionary.
    1791          */
    1792 #ifdef DEBUG
    1793         printf("\nca_set_dirlist() function called ..... \n");
    1794  printf("Variable type: %s\n", dictionary[symbol].varType);
    1795 #endif
    1796
    1797         /*
    1798          * First, flush the input stream.
    1799          */
    1800         fflush(stdin);
    1801
    1802         /*
    1803          * Prompt for the new value of the directory.
    1804          */
    1805         printf("\nNew value of %s [80 characters, maximum] >>> ", dictionary[symbol].varName);
    1806  scanf("%s", newDir);
    1807
    1808 /*
    1809  * Make sure that a reasonable, sensible value of the directory
    1810  * value has been read from the keyboard.
    1811  *
    1812  * How do we implement this ???
    1813  *
    1814  */
    1815
    1816
    1817  /*
    1818   * Make sure that the function is attempting to set the correct type
    1819   * of value.  If not, do not set the value - and exit.
    1820   */
    1821
    1822 if (strcmp(dictionary[symbol].varType, "CA_DIRLIST") != 0)
    1823                 {
    1824                 fprintf(stderr, "Error: unexpected variable type.\n");
    1825                 exit(51);
    1826                 }
    1827
    1828         /*
    1829   * Choose the appropriate values array.
    1830          * Assign a temporary pointer to this array.
    1831          */
    1832
    1833         switch(dictionary[symbol].varScope)
    1834                 {
    1835                 /* If the variable has global scope,
    1836                  * write it into the globals array.
    1837                  * If it has local scope,
    1838                  * write it into the locals array.
    1839          * If the scope cannot be found, report an error.
    1840                  */
    1841                 case 1:
    1842                 hereValues = globals;
    1843                 break;
    1844
    1845                 case 99:
    1846                 hereValues = locals;
    1847                 break;
    1848
    1849                 default:
    1850                 fprintf(stderr, "Error: Unknown scope: %d\n", dictionary[symbol].varScope);
    1851                 break;
    1852                 }
    1853
    1854
    1855         /*
    1856   * Check for the presence of the mutex lock:
    1857          *              if present,
    1858          *              wait until it is available;
    1859          *              else
    1860   *                     get the lock and proceed with the change of value.
    1861          */
    1862
    1863         /*
    1864   * Write the new value of the variable to the correct place
    1865          * in the [appropriate] values array.
    1866          *
    1867   * Note that there is a check to see if malloc() actually worked .....
    1868          */
    1869
    1870                 hereValues[symbol].valPtr = (char *)malloc(80);
    1871                 if (hereValues[symbol].valPtr == NULL)
    1872                         {
    1873                         fprintf(stderr, "Cannot alllocate memory for hereValuesvlPtr\n");
    1874                         exit (8);
    1875                         }
    1876                 strcpy(hereValues[symbol].valPtr,newDir);
    1877
    1878
    1879                 hereValues[symbol].strPtr = (char *)malloc(sizeof(newDir) );
    1880                 if (hereValues[symbol].strPtr == NULL)
    1881                         {
    1882                         fprintf(stderr, "Cannot alllocate memory for hereValuestPtr\n");
    1883                         exit (8);
    1884                         }
    1885                 strcpy(hereValues[symbol].strPtr, newDir);
    1886
    1887         /*
    1888          * Free the temporary pointer, hereValues.
    1889   *
    1890   */
    1891         free(hereValues);
    1892         hereValues = NULL;
    1893
    1894         /*
    1895          * Release the mutex lock.
    1896          */
    1897
    1898         /*
    1899          * Write the new value of this variable back to the config file.
    1900          */
    1901
    1902 }
    1903
    1904
    1905 void ca_set_string(int symbol)
         /* [<][>][^][v][top][bottom][index][help] */
    1906 {
    1907
    1908 /****************************************************************
    1909         * ca_set_string()                                                                                                                       *
    1910  *                                                                                                                                                                      *
    1911  * Parameters                                                                                                                                   *
    1912         *               symbol -- the symbol of the variable.                                                   *
    1913  *                                                                                                                                                                      *
    1914  * Returns                                                                                                                                              *
    1915         *               1 if successful, 0 if not successful ?                                                  *
    1916         *                                                                                                                                                                       *
    1917         * Remarks                                                                                                                                               *
    1918  *              Writing the new value back to the config file has yet to *
    1919         *               be implemented.                                                                                                         *
    1920  *                                                                                                                                                                      *
    1921         ****************************************************************/
    1922
    1923  char newString[80];    /* May need to make this bigger. */
    1924
    1925  /*
    1926   * Declare a pointer to a values_t variable.
    1927          * Later, we shall assign this pointer to the first element
    1928   * of either the globals or the locals array, as appropriate.
    1929   */
    1930  values_t *hereValues;
    1931
    1932         /*
    1933          * Using the symbol, look in the appropriate place in the dictionary.
    1934          */
    1935 #ifdef DEBUG
    1936         printf("\nca_set_string() function called ..... \n");
    1937  printf("Variable type: %s\n", dictionary[symbol].varType);
    1938 #endif
    1939
    1940         /*
    1941          * First, flush the input stream.
    1942          */
    1943         fflush(stdin);
    1944
    1945         /*
    1946          * Prompt for the new value of the string.
    1947          */
    1948         printf("\nNew value of %s [80 characters, maximum] >>> ", dictionary[symbol].varName);
    1949 gets(newString);
    1950
    1951 /*
    1952  * Make sure that a reasonable, sensible value of the string
    1953  * value has been read from the keyboard.
    1954  *
    1955  * How do we implement this ???
    1956  *
    1957  */
    1958
    1959
    1960  /*
    1961   * Make sure that the function is attempting to set the correct type
    1962   * of value.  If not, do not set the value - and exit.
    1963   */
    1964
    1965 if (strcmp(dictionary[symbol].varType, "CA_STRING") != 0)
    1966                 {
    1967                 fprintf(stderr, "Error: unexpected variable type.\n");
    1968                 exit(51);
    1969                 }
    1970
    1971         /*
    1972   * Choose the appropriate values array.
    1973          * Assign a temporary pointer to this array.
    1974          */
    1975
    1976         switch(dictionary[symbol].varScope)
    1977                 {
    1978                 /* If the variable has global scope,
    1979                  * write it into the globals array.
    1980                  * If it has local scope,
    1981                  * write it into the locals array.
    1982          * If the scope cannot be found, report an error.
    1983                  */
    1984                 case 1:
    1985                 hereValues = globals;
    1986                 break;
    1987
    1988                 case 99:
    1989                 hereValues = locals;
    1990                 break;
    1991
    1992                 default:
    1993                 fprintf(stderr, "Error: Unknown scope: %d\n", dictionary[symbol].varScope);
    1994                 break;
    1995                 }
    1996
    1997
    1998         /*
    1999   * Check for the presence of the mutex lock:
    2000          *              if present,
    2001          *              wait until it is available;
    2002          *              else
    2003   *                     get the lock and proceed with the change of value.
    2004          */
    2005         mutex_lock(&Lock);
    2006
    2007         /*
    2008   * Write the new value of the variable to the correct place
    2009          * in the [appropriate] values array.
    2010   * Note the check to the return value of malloc() to see if the
    2011          * memory was actually obtained.
    2012          */
    2013
    2014                 hereValues[symbol].valPtr = (char *)malloc(80);
    2015                 if (hereValues[symbol].valPtr == NULL)
    2016                         {
    2017                         fprintf(stderr, "Cannot allocate memory for hereValues[symbol].valPtr\n");
    2018                         exit (8);
    2019                         }
    2020                 strcpy(hereValues[symbol].valPtr, newString);
    2021
    2022
    2023                 hereValues[symbol].strPtr = (char *)malloc(sizeof(newString) );
    2024                 if (hereValues[symbol].strPtr == NULL)
    2025                         {
    2026                         fprintf(stderr, "Cannot allocate memory for hereValues[symbol].strPtr\n");
    2027                         exit (8);
    2028                         }
    2029                 strcpy(hereValues[symbol].strPtr, newString);
    2030
    2031         /*
    2032          * Free the temporary pointer, hereValues.
    2033          *
    2034   */
    2035         free(hereValues);
    2036  hereValues = NULL;
    2037
    2038         /*
    2039          * Release the mutex lock.
    2040          */
    2041         mutex_unlock(&Lock);
    2042
    2043         /*
    2044          * Write the new value of this variable back to the config file.
    2045          * Implement this later ?
    2046          */
    2047
    2048 }
    2049
    2050
    2051 int ca_writeNewValue(int dictSymbol, char *newValue)
         /* [<][>][^][v][top][bottom][index][help] */
    2052 {
    2053
    2054 FILE *confPtr;                                          /* Pointer to config file */
    2055 FILE *tempPtr;                                          /* The pointer to temp file. */
    2056 char name[STRLENGTH];                           /* The name of the variable. */
    2057 char value[STRLENGTH];                  /* The value of the variable. */
    2058
    2059
    2060 /*
    2061  * Find the actual name of the variable from the dictionary
    2062  * structure (use the variable symbol as an index into the
    2063  * array of dictionary structures.
    2064  */
    2065 #ifdef DEBUG
    2066         printf("Name of variable to be changed: %s\n", dictionary[dictSymbol].varName);
    2067         printf("Type of variable to be changed: %s\n", dictionary[dictSymbol].varType);
    2068 #endif  /* DEBUG */
    2069
    2070 /*
    2071         * Open the test config file for reading .....
    2072  */
    2073 if ( (confPtr = fopen(testFile, "r")) == NULL)
    2074         {
    2075         printf("File \"%s\" could not be opened.\n", testFile);
    2076         exit (51);
    2077         }
    2078
    2079 /*
    2080         * Open the temporary file for writing .....
    2081  */
    2082 if ((tempPtr = fopen(tempFile, "w")) == NULL)
    2083         {
    2084         printf("File \"%s\" could not be opened.\n", tempFile);
    2085  exit (51);
    2086  }
    2087
    2088 /*
    2089  * Read the first record in the test config file.
    2090  */
    2091
    2092  fscanf(confPtr, "%s", name);
    2093  fgets(value, sizeof(value), confPtr);
    2094
    2095  /*
    2096   * If the last character of "value" is '\n',
    2097   * replace it with '\0'.
    2098   */
    2099         if (value[strlen(value) - 1] == '\n')
    2100                 {
    2101 #ifdef DEBUG
    2102                 printf("The value string is %s", value);
    2103                 printf("Replacing last character of \"%s\" with the NULL character\n", name);
    2104 #endif  /* DEBUG */
    2105
    2106                 value[strlen(value) - 1] = '\0';
    2107
    2108 #ifdef DEBUG
    2109                 printf("The new value string is %s", value);
    2110 #endif  /* DEBUG */
    2111                 }
    2112
    2113         /*
    2114          * If we read the variable that we want to change,
    2115   * replace the value of this variable in the config
    2116   * file with the value supplied from the keyboard.
    2117   *
    2118   */
    2119         if ( strcmp(name, dictionary[dictSymbol].varName) == 0)
    2120                 {
    2121                 strcpy(value, newValue);
    2122
    2123 #ifdef DEBUG
    2124                 printf("The replacement string is %s", value);
    2125 #endif  /* DEBUG */
    2126 }
    2127
    2128 /*
    2129         * While there are records to be read in the test config file:
    2130         *               Write the current record into the temporary file.
    2131  *              Read the next record in the config file.
    2132  * Repeat untill the EOF has been reached.
    2133  */
    2134
    2135 while(!feof(confPtr) )
    2136         {
    2137  fprintf(tempPtr, "%s %s\n", name, value);
    2138  fscanf(confPtr, "%s", name);
    2139         fgets(value, sizeof(value), confPtr);
    2140
    2141  /*
    2142   * If the last character of "value" is '\n',
    2143   * replace it with '\0'.
    2144   */
    2145         if (value[strlen(value) - 1] == '\n')
    2146                 {
    2147 #ifdef DEBUG
    2148                 printf("The last character of the value string is %c", value[strlen(value) - 1]);
    2149                 printf("The value string is %s", value);
    2150                 printf("Replacing last character of \"%s\" with the NULL character\n",name);
    2151 #endif  /* DEBUG */
    2152
    2153                 value[strlen(value) - 1] = '\0';
    2154 #ifdef DEBUG
    2155                 printf("The new value string is %s", value);
    2156 #endif  /* DEBUG */
    2157                 }
    2158
    2159
    2160         /*
    2161          * If we read the variable that we want to change,
    2162   * replace the value of this variable in the config
    2163   * file with the value supplied from the keyboard.
    2164   *
    2165   */
    2166         if ( strcmp(name, dictionary[dictSymbol].varName) == 0)
    2167                 {
    2168                 strcpy(value, newValue);
    2169
    2170 #ifdef DEBUG
    2171                 printf("The replacement string is %s", value);
    2172 #endif  /* DEBUG */
    2173                 }
    2174
    2175         /*
    2176          * Flush the pointer to the test config file.
    2177          */
    2178         fflush(confPtr);
    2179
    2180         }
    2181  /*
    2182          * Here ends the loop that writes the config file, with the
    2183   * new variable, to the temporary file.
    2184          */
    2185
    2186 /*
    2187  *
    2188  * While !(the record to be updated)
    2189         *       BEGIN
    2190         *  Write the record to the temporary file
    2191  *  Read the next record in the config file
    2192  *      END
    2193  *
    2194  * Write the new value to the temporary file
    2195  * Read the next record in the config file
    2196  * COMMENT: this is the record to be updated.
    2197  * COMMENT: discard this record.
    2198  *
    2199  * Read the next record in the config file
    2200         *
    2201  * While !(EOF)
    2202         *       BEGIN
    2203         *  write the record to the temporary file
    2204  *  read the next record in the config file
    2205  *  END
    2206  *
    2207  * Close Config file
    2208  * Close Temporary file
    2209  *
    2210  * Open Temporary file for reading
    2211  * Open Config file for writing
    2212  *
    2213  * Read the next record of the Temporary file
    2214  *
    2215  * While (!EOF of Temporary file)
    2216         *       BEGIN
    2217         *  write the record into the Config file
    2218         *  read the next record of the Temporary file
    2219  *  END
    2220  *
    2221         *       Close Temporary file
    2222  *  Close Config file
    2223  *
    2224  */
    2225
    2226 fclose(confPtr);
    2227 fclose(tempPtr);
    2228
    2229 /*
    2230         * Now, flush the file pointers
    2231  */
    2232         fflush(confPtr);
    2233         fflush(tempPtr);
    2234
    2235 /*
    2236  * Open the temporary file for reading.
    2237         * Open the config file for writing.
    2238  * Write the contents of the temporary file
    2239  * into the config file.
    2240  */
    2241
    2242 /*
    2243         * Open the temporary file for reading .....
    2244  */
    2245 if ((tempPtr = fopen(tempFile, "r")) == NULL)
    2246         {
    2247         printf("File \"%s\" could not be opened for reading.\n", tempFile);
    2248  exit (51);
    2249  }
    2250
    2251 /*
    2252         * Open the config file for writing .....
    2253  */
    2254 if ((confPtr = fopen(testFile, "w")) == NULL)
    2255         {
    2256         printf("File \"%s\" could not be opened for writing.\n", testFile);
    2257  exit (51);
    2258  }
    2259
    2260 /*
    2261  * Read the first record in the temporary file.
    2262  */
    2263
    2264  fscanf(tempPtr, "%s", name);
    2265  fgets(value, sizeof(value), tempPtr);
    2266 #ifdef DEBUG
    2267         printf("\nFIRST LINE: %s %s", name, value);
    2268 #endif /* DEBUG */
    2269
    2270 /*
    2271         * While there are records to be read in the temporary file:
    2272         *               Write the current record into the test config file.
    2273  *              Read the next record in the temporary file.
    2274  * Repeat untill the EOF has been reached.
    2275  */
    2276
    2277 while(!feof(tempPtr) )
    2278         {
    2279  fprintf(confPtr, "%s %s", name, value);
    2280  fscanf(tempPtr, "%s", name);
    2281         fgets(value, sizeof(value), tempPtr);
    2282  }
    2283
    2284 fclose(confPtr);
    2285 fclose(tempPtr);
    2286 unlink(tempFile);
    2287
    2288 return(0);
    2289 }
    2290
    2291
    2292 int ca_getStorageLocation(char *confVar, dict_t woordenboek[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
    2293 /*************************************************************
    2294  * ca_getStorageLocation()                                                                                              *
    2295         *       - takes the name of a config variable and searches the          *
    2296  *    dictionary structure for the storage location for this *
    2297  *        variable.                                                                                                                             *
    2298  *                                                                                                                                                              *
    2299  * Parameters                                                                                                                           *
    2300         *       confVar -- the string variable that contains the name    *
    2301  *                of the variable.                                                                              *
    2302  *  woordenboek -- the dictionary structure to be searched      *
    2303         *       size                    -- the size of the dictionary structure to      *
    2304  *                 searched.                                                                                    *
    2305  *                                                                                                                                                              *
    2306  * Returns                                                                                                                                      *
    2307         *       the location (integer) in the values array.                                     *
    2308  *                                                                                                                                                              *
    2309         *************************************************************/
    2310 {
    2311 int i,
    2312 where,
    2313 found = 0       ;               /* Whether or not the symbol has been found. */
    2314
    2315
    2316 #ifdef DEBUG
    2317 printf("The variable name in ca_getStorageLocation is: %s\n", confVar);
    2318 #endif /* DEBUG */
    2319
    2320 /*
    2321  * Compares each name in the dictionary with the one for which
    2322  * we are looking.
    2323  */
    2324 i = 0;
    2325 while (!found && i <= size)
    2326         {
    2327         if (strcmp(woordenboek[i].varName, confVar) == 0)
    2328                 {
    2329                 found = 1;
    2330                 }
    2331         else
    2332                 {
    2333                 ++i;
    2334                 }
    2335         }
    2336
    2337 /*
    2338         * Returns the storage location for the given variable name
    2339  * or else returns NOT_FOUND
    2340  */
    2341 if (found)
    2342                 {
    2343                 /*      mySymbol = atoi(woordenboek[i].varSym); */
    2344     printf("Symbol is %s\n", woordenboek[i].varSym);
    2345                 printf("Storage Location is: %d\n", woordenboek[i].varNum);
    2346            where = woordenboek[i].varNum;
    2347                 }
    2348 else
    2349                 {
    2350                 fprintf(stderr, "Error: cannot find storage location for variable %s\n", confVar);
    2351                 where = NOT_FOUND;
    2352                 }
    2353         return (where);
    2354
    2355 }
    2356
    2357
    2358 void ca_getConfig(values_t confVars[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
    2359 /*************************************************************
    2360  * ca_getConfig -- prints the strings representing the          *
    2361  *                                         values of the configuration variables                *
    2362  *                                                                                                                                                              *
    2363  * Parameters                                                                                                                           *
    2364         *               confVars -- the values_t array which stores the                 *
    2365         *                                               values of the configuration variables.     *
    2366         *               size -- the number of configuration variables,                  *
    2367         *                       the number of elements in the confVars array  *
    2368  *                                                                                                                                                              *
    2369  *                                                                                                                                                              *
    2370  *************************************************************/
    2371 {
    2372 int i = 0;      /* A counting variable. */
    2373
    2374 puts("A dump of the strings of the values of the Config Vars:");
    2375 puts("Number\t\tString");
    2376 puts("----------");
    2377
    2378 while (i < size)
    2379         {
    2380         printf("%d\t\t%s\n", i, confVars[i].strPtr);
    2381  ++i;
    2382         }
    2383
    2384 }
    2385
    2386
    2387 int ca_getType(char *confVar, dict_t woordenboek[], int size)
         /* [<][>][^][v][top][bottom][index][help] */
    2388 /****************************************************************
    2389         * ca_getType -- returns the data type of the variable.                  *
    2390  *                                                                                                                                                                      *
    2391  * Parameters                                                                                                                                   *
    2392  *              confVar -- the name of the configuration variable.                      *
    2393         *               woordenboek -- the array of dict_t structures.                          *
    2394         *               size -- the number of configuration variables.                          *
    2395  *                                                                                                                                                                      *
    2396  * Returns                                                                                                                                              *
    2397  *              an integer representing the data type of the variable           *
    2398  *                                                                                                                                                                      *
    2399  ****************************************************************/
    2400 {
    2401 int i = 0,              /* Counter variable. */
    2402                 found = 0;      /* Set this == 1 when we find the variable.  */
    2403 int myType;     /* Integer representing the type of the config variable. */
    2404
    2405 /*
    2406  * Compare each name in the dictionary with the one for which we
    2407  * are looking.
    2408  */
    2409
    2410 myType = 0;
    2411
    2412 #ifdef DEBUG
    2413 printf("ca_getType function called for variable: %s\n", confVar);
    2414 #endif  /* DEBUG */
    2415
    2416 while (!found && i <= size)
    2417                 {
    2418                 if (strcmp(woordenboek[i].varName, confVar) == 0)
    2419                         {
    2420                         found = 1;
    2421 #ifdef DEBUG
    2422 printf("ca_getType function: %s, %s matched.\n", woordenboek[i].varName, confVar);
    2423 #endif  /* DEBUG */
    2424                         }
    2425                 else
    2426                         {
    2427                         ++i;
    2428                         }
    2429                 }
    2430
    2431 /*
    2432         * Return the type of the config variable or
    2433         * else return "NOT FOUND".
    2434  */
    2435 if (found)
    2436                 {
    2437                         if(strcmp(woordenboek[i].varType, "CA_INT") == 0)
    2438                                 {
    2439 #ifdef DEBUG
    2440 printf("ca_getType function: %s variable of type %s is Integer type\n", woordenboek[i].varName, woordenboek[i].varType);
    2441
    2442 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
    2443 #endif /* DEBUG */
    2444                                 myType = 11;
    2445                                 printf("For type CA_INT, myType is %d\n", myType);
    2446 #ifdef DEBUG
    2447 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
    2448 #endif /* DEBUG */
    2449                                 }
    2450                         else
    2451                                 {
    2452                                         if(strcmp(woordenboek[i].varType, "CA_STRING") == 0)
    2453                                                 {
    2454 #ifdef DEBUG
    2455 printf("ca_getType function: %s variable of type %s is String type\n", woordenboek[i].varName, woordenboek[i].varType);
    2456 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
    2457 #endif /* DEBUG */
    2458                                                 myType = 12;
    2459 #ifdef DEBUG
    2460 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
    2461 #endif /* DEBUG */
    2462                                                 }
    2463                                         else
    2464                                                 {
    2465                                                 if (strcmp(woordenboek[i].varType, "CA_DIRLIST") == 0 )
    2466                                                         {
    2467 #ifdef DEBUG
    2468 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
    2469 #endif /* DEBUG */
    2470                                                         myType = 13;
    2471 #ifdef DEBUG
    2472 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
    2473 #endif /* DEBUG */
    2474                                                         }
    2475                                                 else
    2476                                                         {
    2477                                                         if (strcmp(woordenboek[i].varType, "CA_BOOLEAN") == 0)
    2478                                                                 {
    2479 #ifdef DEBUG
    2480 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
    2481 #endif /* DEBUG */
    2482                                                                 myType = 14;
    2483 #ifdef DEBUG
    2484 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
    2485 #endif /* DEBUG */
    2486                                                                 }
    2487                                                         else
    2488                                                                 {
    2489                                                                 if (strcmp(woordenboek[i].varType, "CA_SOURCETYPE") == 0)
    2490                                                                         {
    2491 #ifdef DEBUG
    2492 printf("ca_getType function: %s, %s\n", woordenboek[i].varName, woordenboek[i].varType);
    2493 #endif /* DEBUG */
    2494                                                                         myType = 15;
    2495 #ifdef DEBUG
    2496 printf("ca_getType function: %s, %s, %d\n", woordenboek[i].varName, woordenboek[i].varType, myType);
    2497 #endif /* DEBUG */
    2498                                                                         }
    2499                                                                 }
    2500                                                         }
    2501                                                 }
    2502                                 }
    2503                 }
    2504         else
    2505                 {
    2506                 myType = NOT_FOUND;
    2507                 }
    2508         return(myType);
    2509  }

/* [<][>][^][v][top][bottom][index][help] */