# HG changeset patch # User Me@portablequad # Date 1329167242 28800 # Node ID 594c0ee5a2b9d3f1915336fe16f032b902fa1555 # Parent bddabc0956b9ee01f593b5e2862d95a683367aec deprecated default brch diff -r bddabc0956b9 -r 594c0ee5a2b9 Param.h --- a/Param.h Mon Feb 13 13:04:40 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * - * Author: SeanHalle@yahoo.com - * - * Created on November 19, 2009, 6:30 PM - */ - -#ifndef _PARAM_H -#define _PARAM_H - -typedef -struct - { int type; - int intValue; - char * strValue; - float floatValue; - } -ParamStruc; - -#define INT_PARAM_TYPE 0 -#define STRING_PARAM_TYPE 1 -#define FLOAT_PARAM_TYPE 2 - -#define PARAM_BAG_HASHSIZE 1024 - -typedef struct _ParamBagHashEntry ParamBagHashEntry; - -struct _ParamBagHashEntry - { - char *key; - ParamStruc *param; - struct _ParamBagHashEntry *next; - } -/*ParamBagHashEntry*/; - - -typedef -struct - { int bagSz; - ParamBagHashEntry* *entries; - } -ParamBag; - - -ParamBag *makeParamBag(); -void readParamFileIntoBag( char *paramFileName, ParamBag * bag ); -ParamStruc *getParamFromBag( char *key, ParamBag * bag ); -int addParamToBag( char* key, ParamStruc *param, ParamBag *bag ); -void freeParamBag( ParamBag *bag ); -//char *paramBagToString( ParamBag * bag ); -ParamStruc *makeParamStruc(); -ParamStruc *makeParamFromStrs( char * type, char *value ); -ssize_t getline( char **lineptr, size_t *n, FILE *stream ); - -#endif /* _PARAM_H */ - diff -r bddabc0956b9 -r 594c0ee5a2b9 ParamBag.c --- a/ParamBag.c Mon Feb 13 13:04:40 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Based on code posted to a discussion group on the web. (Forgot to mark - * down where got it from) - * - * Author: seanhalle@yahoo.com - * - * Created on November 14, 2009, 9:00 PM - */ -#include -#include -#include - -#include "Param.h" - -void freeParamStruc( ParamStruc * param ); -void freeParamBagHashEntry( ParamBagHashEntry *entry ); -ParamBagHashEntry * lookupKeyInHash( char *key, ParamBag * bag ); -unsigned int hashThisKey( char *s, int hashSz ); -void nullOutParamBagHashEntries( ParamBag *bag ); - - ParamBag * -makeParamBag() - { ParamBag * retBag; - retBag = malloc( sizeof( ParamBag ) ); - retBag->entries = malloc( PARAM_BAG_HASHSIZE * sizeof( ParamBagHashEntry *) ); - retBag->bagSz = PARAM_BAG_HASHSIZE; - nullOutParamBagHashEntries( retBag ); - - return retBag; - } - - void -nullOutParamBagHashEntries( ParamBag *bag ) - { int i, bagSz; - bagSz = bag->bagSz; - ParamBagHashEntry ** entries = bag->entries; - for( i = 0; i < bagSz; i++ ) - entries[ i ] = NULL; - } - - unsigned int -hashKey( char *s, int hashSz ) - { unsigned int h = 0; - - for( ; *s != 0; s++ ) - h = *s + h*31; - return h % hashSz; - } - -/*Need this to be separated out, for use in both getParam and putParam - */ - ParamBagHashEntry * -lookupKeyInHash( char *key, ParamBag * bag ) - { unsigned int - hashIndex = hashKey( key, bag->bagSz ); - ParamBagHashEntry* - hashEntry = bag->entries[ hashIndex ]; - for( ; hashEntry != NULL; hashEntry = hashEntry->next ) - { if( strcmp( hashEntry->key, key ) == 0 ) return hashEntry; - } - return NULL; - } - - ParamStruc * -getParamFromBag( char *key, ParamBag * bag ) - { ParamBagHashEntry *entry; - entry = lookupKeyInHash( key, bag ); - if( entry == NULL ) return NULL; - - return entry->param; - } - - int -addParamToBag( char* key, ParamStruc *param, ParamBag *bag ) - { unsigned int hashIdx; - ParamBagHashEntry* hashEntry; - hashEntry = lookupKeyInHash( key, bag ); - if( hashEntry == NULL ) - { hashIdx = hashKey( key, bag->bagSz ); - hashEntry = (ParamBagHashEntry*) malloc( sizeof( ParamBagHashEntry ) ); - if( hashEntry == NULL ) return 0; - hashEntry->key = strdup( key ); - if( hashEntry->key == NULL ) return 0; - hashEntry->next = (bag->entries)[hashIdx]; - (bag->entries)[hashIdx] = hashEntry; - } - else - { freeParamStruc( hashEntry->param ); - } - hashEntry->param = param; - return 1; - } - - - void -freeParamBag( ParamBag *bag ) - { int i; - ParamBagHashEntry *hashEntry, *temp, **entries; - - entries = bag->entries; - for( i=0; i < bag->bagSz; i++ ) - { if( entries[i] != NULL ) - { hashEntry = entries[i]; - while( hashEntry != NULL ) - { - temp = hashEntry->next; - freeParamBagHashEntry( hashEntry ); - hashEntry = temp; - } - } - } - } - - void -freeParamBagHashEntry( ParamBagHashEntry *entry ) - { - freeParamStruc( entry->param ); - free( entry->key ); //was malloc'd above, so free it - free( entry ); - } - - void -freeParamStruc( ParamStruc * param ) - { if( param->type == STRING_PARAM_TYPE ) free( param->strValue ); - free( param ); - } - - ParamStruc * -makeParamStruc() - { ParamStruc *retStruc; - retStruc = malloc( sizeof( ParamStruc ) ); - retStruc->floatValue = 0.0; - retStruc->intValue = 0; - retStruc->strValue = NULL; - - return retStruc; - } - -void -removeEndWhtSpaceFromStr( char *str ) - { int n; - - n = strlen ( str ); - while( --n >= 0 ) - { - if(str[n] != ' ' && str[n] != '\t' && str[n] != '\n' && str[n] != '\r') - break; - } - str[n + 1] = '\0'; - } - - -ParamStruc * -makeParamFromStrs( char * type, char *value ) - { ParamStruc *retParam; - retParam = makeParamStruc(); - switch(*type) - { case 'i': - { retParam->type = INT_PARAM_TYPE; - retParam->intValue = atoi( value ); - } break; - case 's': - { retParam->type = STRING_PARAM_TYPE; - retParam->strValue = malloc( strlen(value) + 1); - strcpy( retParam->strValue, value ); - removeEndWhtSpaceFromStr( retParam->strValue ); - } break; - case 'f': - { retParam->type = FLOAT_PARAM_TYPE; - retParam->floatValue = atof( value ); - } break; - } - return retParam; - } - - -/* A pretty useless but good debugging function, - which simply displays the hashtable in (key.value) pairs -*/ -/*void paramBagToString( ParamBag * bag ) - { int i; - ParamBagHashEntry *t; - for( i = 0; i < bag->bagSz; i++ ) - { t = entries[i]; - if( t == NULL ) - strcat_m( retStr, &"()" ); - else - { strcat_m( retStr, &"(" ); - for( ; t != NULL; t = t->next ) - { strcat_m( retStr, &" " ); - strcat_m( retStr, t->key ); - strcat_m( retStr, &"." ); - strcat_m( retStr, paramToString( t->param ) ); - strcat_m( retStr, &" " ); - } - strcat_m( retStr, &")" ); - } - } - } -*/ diff -r bddabc0956b9 -r 594c0ee5a2b9 ReadParamsFromFile.c --- a/ReadParamsFromFile.c Mon Feb 13 13:04:40 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/* - * Author: SeanHalle@yahoo.com - * - * Created on June 15, 2009, 10:12 AM - */ - -#include -#include -#include - -#include "Param.h" - -ParamStruc * makeParamFromStrs( char * type, char *value ); - -#define _GNU_SOURCE - -/*Copied from gnu's win32 lib - */ - ssize_t -getline( char **lineptr, size_t *n, FILE *stream ) - { - if ( lineptr == NULL || n == NULL) return -1; - if (*lineptr == NULL || *n == 0) - { *n = 500; //max length of line in a config file - *lineptr = (char *) malloc( *n ); - if (*lineptr == NULL) return -1; - } - if( fgets( *lineptr, *n, stream ) ) - return *n; - else - return -1; - } - - void -readParamFileIntoBag( char *paramFileName, ParamBag * bag ) - { - size_t lineSz = 0; - FILE* paramFile; - char* line = NULL; - - char* paramType;// = malloc( 12 ); //"double" is the longest type - char* paramName;// = malloc( 500 ); //max of 500 chars in name - char* paramValue;// = malloc( 500 ); //max of 500 chars in value - - lineSz = 500; //max length of line in a config file - line = (char *) malloc( lineSz ); - if( line == NULL ) - { printf( "\nIn readParamFileIntoBag: no mem for line\n" ); - return; - } - - - paramFile = fopen( paramFileName, "r" ); - if( paramFile == NULL ) - { printf("\ncouldn't open param file: %s\n", paramFileName); exit(0); } - fseek( paramFile, 0, SEEK_SET ); - while( !feof( paramFile ) ) - { while( getline( &line, &lineSz, paramFile ) != -1 ) - { - char *lineEnd = line + strlen(line) +1; - char *searchPos = line; - - if( *line == '\n') continue; //blank line - if( *line == '/' ) continue; //comment line - - //read the param type - paramType = line; //start of string - int foundIt = 0; - for( ; searchPos < lineEnd && !foundIt; searchPos++) - { if( *searchPos == ',' ) - { foundIt = 1; - *searchPos = 0; //mark end of string - } - } - //get rid of leading spaces - for( ; searchPos < lineEnd; searchPos++) - { if( *searchPos != ' ' ) break; - } - //read the param name - paramName = searchPos; - foundIt = 0; - for( ; searchPos < lineEnd && !foundIt; searchPos++) - { if( *searchPos == ',' ) - { foundIt = 1; - *searchPos = 0; //mark end - } - } - //get rid of leading spaces - for( ; searchPos < lineEnd; searchPos++) - { if( *searchPos != ' ' ) break; - } - //read the param value - paramValue = searchPos; - foundIt = 0; - for( ; searchPos < lineEnd && !foundIt; searchPos++) - { if( *searchPos == '\n' ) - { foundIt = 1; - *searchPos = 0; //mark end - } - } - if( foundIt ) - { printf("Found: %s, %s, %s\n", paramType, paramName, paramValue ); - ParamStruc * - paramStruc = makeParamFromStrs( paramType, paramValue ); - addParamToBag( paramName, paramStruc, bag ); - } - } - } - free( line ); - } - diff -r bddabc0956b9 -r 594c0ee5a2b9 __brch__DEPRECATED_README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/__brch__DEPRECATED_README Mon Feb 13 13:07:22 2012 -0800 @@ -0,0 +1,8 @@ + +There are two versions of the library -- one for pure C use, the other for use inside VMS or within applications written in a VMS-based language (IE, inside a top-level function or a call descendant of a top-level function) -- but only when the VMS is the "MC_shared" version. + +The reason is that VMS that uses shared memory on multicores moves the SlaveVPs around among cores. But, the libC and glibC malloc stores info at the top of the stack (a "clever" hack), for a speed improvement. So, when VMS manipulates the stack pointer, and/or moves Slaves to different cores, the "free" seg faults (that was FUN to figure out ; ) So, this version of VMS implements its own malloc. + +It is anticipated that the MC_split version, where each core has separate data, and messages are sent between cores, can handle malloc and free to use the glibC version. + +For now, update to the version of the library you wish to use.. diff -r bddabc0956b9 -r 594c0ee5a2b9 __brch__pure_C --- a/__brch__pure_C Mon Feb 13 13:04:40 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ - -This branch is for use in pure C code (*not* inside VMS-based language application code) - -There are two versions of the library -- one for pure C use, the other for use inside VMS or within applications written in a VMS-based language (IE, inside a top-level function or a call descendant of a top-level function) -- but only when the VMS is the "MC_shared" version. - -The reason is that VMS that uses shared memory on multicores moves the SlaveVPs around among cores. But, the libC and glibC malloc stores info at the top of the stack (a "clever" hack), for a speed improvement. So, when VMS manipulates the stack pointer, and/or moves Slaves to different cores, the "free" seg faults (that was FUN to figure out ; ) So, this version of VMS implements its own malloc. \ No newline at end of file