Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

/Users/trevorw/projects/release/covered-0.7.4/src/info.c File Reference


Detailed Description

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
2/12/2003

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "defines.h"
#include "info.h"
#include "link.h"
#include "score.h"
#include "util.h"

Functions

void score_add_args (const char *arg1, const char *arg2)
 Adds the given argument(s) from the command-line to the score array such that no arguments are duplicated.

void info_set_vector_elem_size ()
void info_db_write (FILE *file)
 Writes info line to specified CDD file.

void info_db_read (char **line)
 Reads info line from specified line and stores information.

void args_db_read (char **line)
 Reads score args line from specified line and stores information.

void message_db_read (char **line)
 Reads user-specified message from specified line and stores information.

void merged_cdd_db_read (char **line)
 Reads merged CDD information from specified line and stores information.

void info_dealloc ()
 Deallocates all memory associated with the information section of a database file.


Variables

db ** db_list
unsigned int curr_db
str_linkmerge_in_head
str_linkmerge_in_tail
int merge_in_num
char * merged_file
uint64 num_timesteps
char * cdd_message
char user_msg [USER_MSG_LENGTH]
isuppl info_suppl = {0}
int cdd_version = CDD_VERSION
char score_run_path [4096]
str_linkscore_args_head = NULL
str_linkscore_args_tail = NULL


Function Documentation

void args_db_read char **  line  ) 
 

Reads score args line from specified line and stores information.

Exceptions:
anonymous Throw
Reads score command-line args line from specified string and stores its information.
Parameters:
line  Pointer to string containing information line to parse

00291   { PROFILE(ARGS_DB_READ);
00292 
00293   int  chars_read;  /* Number of characters scanned in from this line */
00294   char tmp1[4096];  /* Temporary string */
00295   char tmp2[4096];  /* Temporary string */
00296   int  arg_num;
00297 
00298   if( sscanf( *line, "%s%n", score_run_path, &chars_read ) == 1 ) {
00299 
00300     *line = *line + chars_read;
00301 
00302     /* Store score command-line arguments */
00303     while( sscanf( *line, "%d%n", &arg_num, &chars_read ) == 1 ) {
00304       *line = *line + chars_read;
00305       if( (arg_num == 1) && (sscanf( *line, "%s%n", tmp1, &chars_read ) == 1) ) {
00306         score_add_args( tmp1, NULL );
00307       } else if( (arg_num == 2) && (sscanf( *line, "%s (%[^)])%n", tmp1, tmp2, &chars_read ) == 2) ) {
00308         score_add_args( tmp1, tmp2 );
00309       }
00310       *line = *line + chars_read;
00311     }
00312 
00313   } else {
00314 
00315     print_output( "CDD file being read is incompatible with this version of Covered", FATAL, __FILE__, __LINE__ );
00316     Throw 0;
00317 
00318   }
00319 
00320   PROFILE_END;
00321 
00322 }

void info_db_read char **  line  ) 
 

Reads info line from specified line and stores information.

Exceptions:
anonymous Throw Throw Throw
Reads information line from specified string and stores its information.
Parameters:
line  Pointer to string containing information line to parse

00226   { PROFILE(INFO_DB_READ);
00227 
00228   int          chars_read;  /* Number of characters scanned in from this line */
00229   uint32       scored;      /* Indicates if this file contains scored data */
00230   unsigned int version;     /* Contains CDD version from file */
00231   char         tmp[4096];   /* Temporary string */
00232 
00233   /* Save off original scored value */
00234   scored = info_suppl.part.scored;
00235 
00236   if( sscanf( *line, "%x%n", &version, &chars_read ) == 1 ) {
00237 
00238     *line = *line + chars_read;
00239 
00240     if( version != CDD_VERSION ) {
00241       print_output( "CDD file being read is incompatible with this version of Covered", FATAL, __FILE__, __LINE__ );
00242       Throw 0;
00243     }
00244 
00245     /*@-formattype -duplicatequals@*/
00246     if( sscanf( *line, "%x %llu %s%n", &(info_suppl.all), &num_timesteps, tmp, &chars_read ) == 3 ) {
00247     /*@=formattype =duplicatequals@*/
00248 
00249       *line = *line + chars_read;
00250 
00251       /* Set leading_hiers_differ to TRUE if this is not the first hierarchy and it differs from the first */
00252       if( (db_list[curr_db]->leading_hier_num > 0) && (strcmp( db_list[curr_db]->leading_hierarchies[0], tmp ) != 0) ) {
00253         db_list[curr_db]->leading_hiers_differ = TRUE;
00254       }
00255 
00256       /* Assign this hierarchy to the leading hierarchies array */
00257       db_list[curr_db]->leading_hierarchies = (char**)realloc_safe( db_list[curr_db]->leading_hierarchies, (sizeof( char* ) * db_list[curr_db]->leading_hier_num), (sizeof( char* ) * (db_list[curr_db]->leading_hier_num + 1)) );
00258       db_list[curr_db]->leading_hierarchies[db_list[curr_db]->leading_hier_num] = strdup_safe( tmp );
00259       db_list[curr_db]->leading_hier_num++;
00260 
00261       /* Set scored flag to correct value */
00262       if( info_suppl.part.scored == 0 ) {
00263         info_suppl.part.scored = scored;
00264       }
00265 
00266     } else {
00267 
00268       print_output( "CDD file being read is incompatible with this version of Covered", FATAL, __FILE__, __LINE__ );
00269       Throw 0;
00270 
00271     }
00272 
00273   } else {
00274 
00275     print_output( "CDD file being read is incompatible with this version of Covered", FATAL, __FILE__, __LINE__ );
00276     Throw 0;
00277 
00278   }
00279 
00280   PROFILE_END;
00281 
00282 }

void info_db_write FILE *  file  ) 
 

Writes info line to specified CDD file.

Writes information line to specified file.

Parameters:
file  Pointer to file to write information to

00151   { PROFILE(INFO_DB_WRITE);
00152 
00153   str_link* arg;
00154 
00155   assert( db_list[curr_db]->leading_hier_num > 0 );
00156 
00157   /* Calculate vector element size */
00158   info_set_vector_elem_size();
00159 
00160   /*@-formattype -duplicatequals@*/
00161   fprintf( file, "%d %x %x %llu %s\n",
00162            DB_TYPE_INFO,
00163            CDD_VERSION,
00164            info_suppl.all,
00165            num_timesteps,
00166            db_list[curr_db]->leading_hierarchies[0] );
00167   /*@=formattype =duplicatequals@*/
00168 
00169   /* Display score arguments */
00170   fprintf( file, "%d %s", DB_TYPE_SCORE_ARGS, score_run_path );
00171 
00172   arg = score_args_head;
00173   while( arg != NULL ) {
00174     if( arg->str2 != NULL ) {
00175       fprintf( file, " 2 %s (%s)", arg->str, arg->str2 );
00176     } else {
00177       fprintf( file, " 1 %s", arg->str );
00178     }
00179     arg = arg->next;
00180   }
00181 
00182   fprintf( file, "\n" );
00183 
00184   /* Display the CDD message, if there is one */
00185   if( cdd_message != NULL ) {
00186     fprintf( file, "%d %s\n", DB_TYPE_MESSAGE, cdd_message );
00187   }
00188 
00189   /* Display the merged CDD information, if there are any */
00190   if( db_list[curr_db]->leading_hier_num == merge_in_num ) {
00191     str_link*    strl = merge_in_head;
00192     unsigned int i    = 0;
00193     while( strl != NULL ) {
00194       if( (strcmp( strl->str, merged_file ) != 0) && (strl->suppl == 1) ) {
00195         fprintf( file, "%d %s %s\n", DB_TYPE_MERGED_CDD, strl->str, db_list[curr_db]->leading_hierarchies[i++] );
00196       } else {
00197         i++;
00198       }
00199       strl = strl->next; 
00200     }
00201   } else { 
00202     str_link*    strl = merge_in_head;
00203     unsigned int i    = 1; 
00204     assert( (db_list[curr_db]->leading_hier_num - 1) == merge_in_num );
00205     while( strl != NULL ) {
00206       if( (strcmp( strl->str, merged_file ) != 0) && (strl->suppl == 1) ) {
00207         fprintf( file, "%d %s %s\n", DB_TYPE_MERGED_CDD, strl->str, db_list[curr_db]->leading_hierarchies[i++] );
00208       } else {
00209         i++;
00210       }
00211       strl = strl->next;
00212     }
00213   }
00214 
00215   PROFILE_END;
00216 
00217 }

void info_dealloc  ) 
 

Deallocates all memory associated with the information section of a database file.

Deallocates all memory associated with the database information section. Needs to be called when the database is closed.

00400                     { PROFILE(INFO_DEALLOC);
00401 
00402   str_link_delete_list( score_args_head );
00403   score_args_head = NULL;
00404   score_args_tail = NULL;
00405 
00406   /* Free merged arguments */
00407   str_link_delete_list( merge_in_head );
00408   merge_in_head = NULL;
00409   merge_in_tail = NULL;
00410   merge_in_num  = 0;
00411 
00412   /* Free user message */
00413   free_safe( cdd_message, (strlen( cdd_message ) + 1) );
00414   cdd_message = NULL;
00415 
00416   PROFILE_END;
00417 
00418 }

void info_set_vector_elem_size  ) 
 

Sets the vector element size in the global info_suppl structure based on the current machine unsigned long byte size.

00127                                  { PROFILE(INFO_SET_VECTOR_ELEM_SIZE);
00128 
00129   switch( sizeof( ulong ) ) {
00130     case 1 :  info_suppl.part.vec_ul_size = 0;  break;
00131     case 2 :  info_suppl.part.vec_ul_size = 1;  break;
00132     case 4 :  info_suppl.part.vec_ul_size = 2;  break;
00133     case 8 :  info_suppl.part.vec_ul_size = 3;  break;
00134     default:
00135       print_output( "Unsupported unsigned long size", FATAL, __FILE__, __LINE__ );
00136       Throw 0;
00137       /*@-unreachable@*/
00138       break;
00139       /*@=unreachable@*/
00140   }
00141 
00142   PROFILE_END;
00143 
00144 }

void merged_cdd_db_read char **  line  ) 
 

Reads merged CDD information from specified line and stores information.

Parses given line for merged CDD information and stores this information in the appropriate global variables.

Parameters:
line  Pointer to string containing merged CDD line to parse

00345   { PROFILE(MERGED_CDD_DB_READ);
00346 
00347   char tmp1[4096];  /* Temporary string */
00348   char tmp2[4096];  /* Temporary string */
00349   int  chars_read;  /* Number of characters read */
00350 
00351   if( sscanf( *line, "%s %s%n", tmp1, tmp2, &chars_read ) == 2 ) {
00352 
00353     str_link* strl;
00354 
00355     *line = *line + chars_read;
00356 
00357     /* Add merged file */
00358     if( (strl = str_link_find( tmp1, merge_in_head)) == NULL ) {
00359 
00360       strl = str_link_add( strdup_safe( tmp1 ), &merge_in_head, &merge_in_tail );
00361       strl->suppl = 1;
00362       merge_in_num++;
00363 
00364       /* Set leading_hiers_differ to TRUE if this is not the first hierarchy and it differs from the first */
00365       if( strcmp( db_list[curr_db]->leading_hierarchies[0], tmp2 ) != 0 ) {
00366         db_list[curr_db]->leading_hiers_differ = TRUE;
00367       }
00368 
00369       /* Add its hierarchy */
00370       db_list[curr_db]->leading_hierarchies = (char**)realloc_safe( db_list[curr_db]->leading_hierarchies, (sizeof( char* ) * db_list[curr_db]->leading_hier_num), (sizeof( char* ) * (db_list[curr_db]->leading_hier_num + 1)) );
00371       db_list[curr_db]->leading_hierarchies[db_list[curr_db]->leading_hier_num] = strdup_safe( tmp2 );
00372       db_list[curr_db]->leading_hier_num++;
00373 
00374     } else if( merge_in_num > 0 ) {
00375 
00376       char* file = get_relative_path( tmp1 );
00377       unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "File %s in CDD file has been specified on the command-line", file );
00378       assert( rv < USER_MSG_LENGTH );
00379       free_safe( file, (strlen( file ) + 1) );
00380       print_output( user_msg, FATAL, __FILE__, __LINE__ );
00381       Throw 0;
00382 
00383     }
00384 
00385   } else {
00386 
00387     print_output( "CDD file being read is incompatible with this version of Covered", FATAL, __FILE__, __LINE__ );
00388     Throw 0;
00389 
00390   }
00391 
00392   PROFILE_END;
00393 
00394 }

void message_db_read char **  line  ) 
 

Reads user-specified message from specified line and stores information.

Read user-specified message from specified string and stores its information.

Parameters:
line  Pointer to string containing information line to parse

00329   { PROFILE(MESSAGE_DB_READ);
00330 
00331   /* All we need to do is copy the message */
00332   if( (cdd_message == NULL) && (strlen( *line + 1 ) > 0) ) {
00333     cdd_message = strdup_safe( *line + 1 );
00334   }
00335 
00336   PROFILE_END;
00337 
00338 }

void score_add_args const char *  arg1,
const char *  arg2
 

Adds the given argument(s) from the command-line to the score array such that no arguments are duplicated.

Adds the specified argument to the list of score arguments that will be written to the CDD file.

Parameters:
arg1  First argument from score command
arg2  Second argument from score command

00084   { PROFILE(SCORE_ADD_ARGS);
00085 
00086   str_link* arg    = score_args_head;
00087   bool      done   = FALSE;
00088   bool      nondup = ((strncmp( arg1, "-vpi", 4 ) == 0) ||
00089                       (strncmp( arg1, "-lxt", 4 ) == 0) ||
00090                       (strncmp( arg1, "-vcd", 4 ) == 0) ||
00091                       (strncmp( arg1, "-t",   2 ) == 0) ||
00092                       (strncmp( arg1, "-i",   2 ) == 0) ||
00093                       (strncmp( arg1, "-o",   2 ) == 0));
00094 
00095   while( !done ) {
00096 
00097     /* Check to see if the specified arguments already exist */
00098     while( (arg != NULL) && (strcmp( arg->str, arg1 ) != 0) ) {
00099       arg = arg->next;
00100     }
00101 
00102     /* If the argument doesn't exist, just add it and be done */
00103     if( arg == NULL ) {
00104       arg = str_link_add( strdup_safe( arg1 ), &score_args_head, &score_args_tail );
00105       if( arg2 != NULL ) {
00106         arg->str2 = strdup_safe( arg2 );
00107       }
00108       done = TRUE;
00109 
00110     /* If the first option exists and its either a non-duplicatible option or it already exists, be done */
00111     } else if( nondup || ((arg2 != NULL) && (strcmp( arg2, arg->str2 ) == 0)) ) {
00112       done = TRUE;
00113 
00114     /* Otherwise, advance the arg pointer */
00115     } else {
00116       arg = arg->next;
00117     }
00118 
00119   }
00120 
00121 }


Variable Documentation

char* cdd_message
 

User-supplied message to include in the CDD database

int cdd_version = CDD_VERSION
 

Contains the CDD version number of all CDD files that this version of Covered can write and read.

unsigned int curr_db
 

Index of current database in db_list array that is being handled.

db** db_list
 

Array of database pointers storing all currently loaded databases.

isuppl info_suppl = {0}
 

Informational line for the CDD file.

str_link* merge_in_head
 

Pointer to head of list containing names of the input CDD files.

int merge_in_num
 

Specifies the number of merged CDD files.

str_link* merge_in_tail
 

Pointer to tail of list containing names of the input CDD files.

char* merged_file
 

Specifies the output filename of the CDD file that contains the merged data.

uint64 num_timesteps
 

Specifies the number of timesteps that have transpired during this simulation.

str_link* score_args_head = NULL
 

Pointer to the head of the score arguments list.

str_link* score_args_tail = NULL
 

Pointer to the tail of the score arguments list.

char score_run_path[4096]
 

Specifes the pathname where the score command was originally run from.

char user_msg[USER_MSG_LENGTH]
 

Holds some output that will be displayed via the print_output command. This is created globally so that memory does not need to be reallocated for each function that wishes to use it.


Generated on Wed Jun 17 22:19:22 2009 for Covered by doxygen 1.3.4