char* stgParseListAllCmdLineArg( int* argc, char** argv[] ) { Index arg_I; /* Loop over all the arguments from command line and reads all arguments of form "--help topic" */ for( arg_I = 1 ; arg_I < *argc; arg_I++ ) { char* valueString = 0; char* argumentString = (*argv)[arg_I]; const char* preceedingString = "--list-all"; unsigned int preceedingStringLength = strlen( preceedingString ); /* Check is string has preceeding string is "--list" if not then continue in loop */ if( strncmp( preceedingString, argumentString , preceedingStringLength ) != 0 ) { continue; } if( strlen( argumentString ) != strlen( preceedingString ) ) { continue; } if( arg_I >= (*argc - 1) ) { /* "--list" is the last commandline argument */ valueString = StG_Strdup( "" ); stgRemoveCmdLineArg( argc, argv, arg_I ); /* first argument: --list */ return valueString; } valueString = StG_Strdup( (*argv)[arg_I+1] ); stgRemoveCmdLineArg( argc, argv, arg_I ); /* first argument: --list */ stgRemoveCmdLineArg( argc, argv, arg_I ); /* second argument: topic */ return valueString; } return 0; }
void _lucAxis_Init( lucAxis* self, Coord origin, float length, char* axes, char* labelX, char* labelY, char* labelZ, lucColour colourX, lucColour colourY, lucColour colourZ) { int i; for (i=0; i<3; i++) self->axes[i] = False; if (strchr(axes, 'x')) self->axes[I_AXIS] = True; if (strchr(axes, 'y')) self->axes[J_AXIS] = True; if (strchr(axes, 'z')) self->axes[K_AXIS] = True; if (strchr(axes, 'X')) self->axes[I_AXIS] = True; if (strchr(axes, 'Y')) self->axes[J_AXIS] = True; if (strchr(axes, 'Z')) self->axes[K_AXIS] = True; self->length = length; self->labels[0] = StG_Strdup(labelX); self->labels[1] = StG_Strdup(labelY); self->labels[2] = StG_Strdup(labelZ); memcpy( self->origin, origin, sizeof(Coord) ); memcpy( &(self->colours[0]), &colourX, sizeof(lucColour) ); memcpy( &(self->colours[1]), &colourY, sizeof(lucColour) ); memcpy( &(self->colours[2]), &colourZ, sizeof(lucColour) ); }
Stg_ObjectList* stgParseInputPathCmdLineArg( int* argc, char** argv[] ) { Index arg_I; Stg_ObjectList* allInputPaths = Stg_ObjectList_New(); /* Loop over all the arguments from command line and reads all arguments of form "--help topic" */ for( arg_I = 1 ; arg_I < *argc; arg_I++ ) { char* valueString = 0; char* argumentString = (*argv)[arg_I]; const char* preceedingString = "--inputPath"; unsigned int preceedingStringLength = strlen( preceedingString ); /* Check is string has preceeding string is "--inputPath" if not then continue in loop */ if( strncmp( preceedingString, argumentString , preceedingStringLength ) != 0 ) { continue; } if( strlen( argumentString ) <= (strlen( preceedingString ) + 1) ) { /* i.e. it has = sign (maybe) but not an input path itself */ continue; } if( strncmp( "=", &argumentString[preceedingStringLength], 1 ) != 0 ) { /* i.e. no = sign */ continue; } valueString = StG_Strdup( &(*argv)[arg_I][preceedingStringLength+1] ); stgRemoveCmdLineArg( argc, argv, arg_I ); /* name=value: --inputPath=??? */ Stg_ObjectList_Append( allInputPaths, Stg_ObjectAdaptor_NewOfPointer( valueString, 0, True, False, deleteInputPathItem, 0, 0 ) ); } return allInputPaths; }
/** add a path to the search paths */ void File_AddPath( char* directory ) { Bool found; Index dir_i; /* Check if it is a valid path */ if( !directory ) { return; } /* Check if dictionary already exists */ if( _stgFilePaths == NULL ) { _stgFilePaths = Stg_ObjectList_New(); } /* Add path to global list */ found = False; for( dir_i = 0; dir_i < _stgFilePaths->count; dir_i++ ){ if( strcmp( directory, (char*)Stg_ObjectList_ObjectAt( _stgFilePaths, dir_i ) ) == 0 ) { found = True; } } if( !found ) { Stg_ObjectList_PointerAppend( _stgFilePaths, StG_Strdup( directory ), directory, deleteInputPathItem, 0, 0 ); } }
void _FileParticleLayout_Init( void* particleLayout, Name filename ) { FileParticleLayout* self = (FileParticleLayout*) particleLayout; self->filename = StG_Strdup( filename ); self->file = NULL; self->errorStream = Journal_MyStream( Error_Type, self ); _GlobalParticleLayout_Init( self, GlobalCoordSystem, False, 0, 0.0 ); }
void FieldVariable_SetUnits( void* fieldVariable, char* o_units ) { FieldVariable* self = (FieldVariable*)fieldVariable; /* Override any previously defined o_units */ if(self->o_units) { Memory_Free( self->o_units ); self->o_units = NULL; } self->o_units = StG_Strdup( o_units ); }
Stg_Component* _Stg_ComponentFactory_PluginConstructByKey( void* cf, void* codelet, Dictionary_Entry_Key componentKey, Type type, Bool isEssential, void* data ) { Stg_ComponentFactory* self = (Stg_ComponentFactory*)cf; Stg_Component* plugin = (Stg_Component*)codelet; Dictionary* thisPluginDict = NULL; Dictionary* pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" ); Name componentName, redirect, pluginType; Dictionary_Entry_Value* componentEntryVal; Index pluginIndex; Stream* errorStream = Journal_Register( Error_Type, self->type ); Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_Component is NULL.\n", __func__ ); /* Get this plugins Dictionary */ for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( (Dictionary_Entry_Value*)pluginDict ); pluginIndex++ ) { thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( (Dictionary_Entry_Value*)pluginDict, pluginIndex ) ); pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) ); if( !strcmp( plugin->type, pluginType ) ){ Memory_Free( pluginType ); break; } Memory_Free( pluginType ); } /* Get Dependency's Name */ componentEntryVal = Dictionary_Get( thisPluginDict, componentKey ); if ( componentEntryVal == NULL ) { Journal_Firewall( !isEssential, errorStream, "plugin '%s' cannot find essential component with key '%s'.\n", plugin->type, componentKey ); Journal_PrintfL( self->infoStream, 2, "plugin '%s' cannot find non-essential component with key '%s'.\n", plugin->type, componentKey ); return NULL; } componentName = Dictionary_Entry_Value_AsString( componentEntryVal ); /* If we can find the component's name in the root dictionary, use that value instead. */ if( self->rootDict ) { redirect = Dictionary_GetString_WithDefault( self->rootDict, componentName, "" ); if( strcmp( redirect, "" ) ) componentName = redirect; } return self->constructByName( self, componentName, type, isEssential, data ); }
int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; Stream* stream; Stg_ObjectList* directories; PluginLoader* plugin; /* Initialise MPI, get world info */ MPI_Init( &argc, &argv ); MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld ); MPI_Comm_size( CommWorld, &numProcessors ); MPI_Comm_rank( CommWorld, &rank ); BaseFoundation_Init( &argc, &argv ); BaseIO_Init( &argc, &argv ); BaseContainer_Init( &argc, &argv ); BaseAutomation_Init( &argc, &argv ); BaseExtensibility_Init( &argc, &argv ); /* creating a stream */ stream = Journal_Register( Info_Type, __FILE__ ); directories = Stg_ObjectList_New(); Stg_ObjectList_PointerAppend( directories, StG_Strdup(LIB_DIR), "default dir", 0, 0, 0 ); plugin = PluginLoader_NewLocal( "LocalPlugin", directories ); Journal_Firewall( plugin != NULL, stream, "Failed!\n" ); Journal_Printf( stream, "PluginLoader_GetName(): %s\n", PluginLoader_GetName( plugin ) ); Print( plugin, stream ); Stg_Class_Delete( plugin ); Stg_Class_Delete( directories ); BaseExtensibility_Finalise(); BaseAutomation_Finalise(); BaseContainer_Finalise(); BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return 0; }
void* _ForceVector_Copy( void* forceVector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) { ForceVector* self = (ForceVector*)forceVector; ForceVector* newForceVector; PtrMap* map = ptrMap; Bool ownMap = False; if( !map ) { map = PtrMap_New( 10 ); ownMap = True; } newForceVector = _SolutionVector_Copy( self, dest, deep, nameExt, map ); /* TODO: copy vector? */ newForceVector->entryPoint_Register = self->entryPoint_Register; newForceVector->localSize = self->localSize; if( deep ) { newForceVector->assembleForceVector = (FeEntryPoint*)Stg_Class_Copy( self->assembleForceVector, NULL, deep, nameExt, map ); if( self->_assembleForceVectorEPName ) { if( nameExt ) { unsigned nameLen = strlen( self->_assembleForceVectorEPName ); newForceVector->_assembleForceVectorEPName = Memory_Alloc_Bytes_Unnamed( nameLen + strlen( nameExt ) + 1, "FV->vecEPName" ); memcpy( newForceVector->_assembleForceVectorEPName, self->_assembleForceVectorEPName, nameLen ); strcpy( newForceVector->_assembleForceVectorEPName + nameLen, nameExt ); } else { newForceVector->_assembleForceVectorEPName = StG_Strdup( self->_assembleForceVectorEPName ); } } else { newForceVector->_assembleForceVectorEPName = NULL; } } else { newForceVector->debug = self->debug; newForceVector->_assembleForceVectorEPName = self->_assembleForceVectorEPName; newForceVector->assembleForceVector = self->assembleForceVector; } if( ownMap ) { Stg_Class_Delete( map ); } return (void*)newForceVector; }
Dictionary_Entry_Value* _DictionaryUtils_GetRecursive( Dictionary* dict, char* str ){ char* strPoint = strchr( str, '.' ); if(strPoint){ Dictionary_Entry_Value* entryVal=NULL; /* Create the struct and member strings from the source. */ char* structString = StG_Strdup( str ); char* strPointNew = strchr( structString, '.' ); *strPointNew = 0; char* memberString = strPointNew + 1; Dictionary_Entry_Value* subDict = Dictionary_Get( dict, structString ); if( subDict ) entryVal = _DictionaryUtils_GetRecursive( Dictionary_Entry_Value_AsDictionary(subDict), memberString ); Memory_Free( structString ); return entryVal; } else { return Dictionary_Get( dict, str ); } }
void _lucViewport_Init( lucViewport* self, lucCamera* camera, lucDrawingObject** drawingObjectList, DrawingObject_Index drawingObjectCount, char* title, Bool axis, double axisLength, Bool antialias, Bool rulers, Bool timestep, int border, Name borderColourName, Bool disabled, Pixel_Index margin, double nearClipPlane, double farClipPlane, double scaleX, double scaleY, double scaleZ) { DrawingObject_Index object_I; self->camera = camera; self->title = StG_Strdup( title ); self->axis = axis; self->axisLength = axisLength; self->antialias = antialias; self->rulers = rulers; self->timestep = timestep; self->border = border; self->margin = margin; self->nearClipPlane = nearClipPlane; self->farClipPlane = farClipPlane; self->scaleX = scaleX; self->scaleY = scaleY; self->scaleZ = scaleZ; self->disabled = disabled || !self->context->vis; lucColour_FromString( &self->borderColour, borderColourName ); self->drawingObject_Register = lucDrawingObject_Register_New(); for ( object_I = 0 ; object_I < drawingObjectCount ; object_I++ ) lucDrawingObject_Register_Add( self->drawingObject_Register, drawingObjectList[ object_I ] ); }
void* _LineFormatter_Copy( void* lineFormatter, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) { LineFormatter* self = (LineFormatter*)lineFormatter; LineFormatter* newLineFormatter; /* Create new instance. Copy virtual info */ newLineFormatter = (LineFormatter*)_StreamFormatter_Copy( self, dest, deep, nameExt, ptrMap ); /* Copy member info. */ newLineFormatter->_newLine = self->_newLine; if ( self->_tag != NULL ) { newLineFormatter->_tag = StG_Strdup( self->_tag ); } else { newLineFormatter->_tag = NULL; } return newLineFormatter; }
void _FieldVariable_Init( FieldVariable* self, DomainContext* context, Index fieldComponentCount, Dimension_Index dim, Bool isCheckpointedAndReloaded, char* o_units, MPI_Comm communicator, FieldVariable_Register* fV_Register, Bool useCacheMaxMin ) { /* Add ourselves to the register for later retrieval by clients */ self->context = context; self->fieldComponentCount = fieldComponentCount; self->dim = dim; self->communicator = communicator; self->fieldVariable_Register = fV_Register; self->isCheckpointedAndReloaded = isCheckpointedAndReloaded; self->useCacheMaxMin = useCacheMaxMin; if( o_units ) { /* test if units string is valid */ Scaling_Parse( o_units ); /* copy units string */ self->o_units = StG_Strdup( o_units ); } if( self != NULL && fV_Register != NULL ) { /* Prevent the same field from being added more than once */ if( NamedObject_Register_GetIndex( fV_Register, self->name ) == -1 ) FieldVariable_Register_Add( fV_Register, self ); } self->extensionMgr = ExtensionManager_New_OfExistingObject( self->name, self ); self->cachedTimestep = -1; }
static void Dictionary_Entry_Value_SetValueString( Dictionary_Entry_Value* self, const char* const value ) { self->as.typeString = StG_Strdup( value ); self->type = Dictionary_Entry_Value_Type_String; }
Dictionary_Entry_Value* _Stg_ComponentFactory_PluginGetDictionaryValue( void* cf, void *codelet, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) { Stg_ComponentFactory* self = (Stg_ComponentFactory*) cf; Stg_Component* plugin = (Stg_Component*)codelet; Dictionary* thisPluginDict = NULL; Dictionary* pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" ); Name pluginType; Index pluginIndex; Dictionary_Entry_Value* returnVal; Bool usedDefault = False; Stream* errorStream = Journal_Register( Error_Type, Stg_Component_Type ); Stream* stream = self->infoStream; Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_ComponentFactory is NULL.\n", __func__ ); Journal_PrintfL( stream, 2, "Getting parameter '%s': ", key ); Journal_Firewall( pluginDict != NULL, errorStream, "In func %s: Stg_Component Factory's dictionary is NULL.\n", __func__ ); /* Get this plugins Dictionary */ for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( (Dictionary_Entry_Value*)pluginDict ); pluginIndex++ ) { thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( (Dictionary_Entry_Value*)pluginDict, pluginIndex ) ); pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) ); if( !strcmp( plugin->type, pluginType ) ){ Memory_Free( pluginType ); break; } Memory_Free( pluginType ); } /* Get this Stg_Component's Dictionary */ Journal_Firewall( thisPluginDict != NULL, errorStream, "In func %s: Can't find sub-dictionary for component '%s'.\n", __func__, plugin->name ); /* Get Value from dictionary */ returnVal = Dictionary_Get( thisPluginDict, key ); if ( !returnVal && defaultVal ) { returnVal = Dictionary_GetDefault( thisPluginDict, key, defaultVal ); usedDefault = True; } /* Print Stuff */ if ( usedDefault ) { Journal_PrintfL( stream, 2, "Using default value = " ); if ( Stream_IsPrintableLevel( stream, 2 ) ) Dictionary_Entry_Value_Print( returnVal, stream ); Journal_PrintfL( stream, 2, "\n" ); return returnVal; } else if ( returnVal ) { Journal_PrintfL( stream, 2, "Found - Value = " ); if ( Stream_IsPrintableLevel( stream, 2 ) ) Dictionary_Entry_Value_Print( returnVal, stream ); Journal_PrintfL( stream, 2, "\n" ); } else Journal_PrintfL( stream, 2, "Not found.\n" ); return returnVal; }
char* Stg_ComponentFactory_GetString( void* cf, Name componentName, Dictionary_Entry_Key key, const char* const defaultVal ) { Stg_ComponentFactory* self = (Stg_ComponentFactory*)cf; /* return a copy to this string. this is safer, but will create potential memory leaks at times, but should only be minor */ return StG_Strdup( self->getString( cf, componentName, key, defaultVal ) ); }
void stgGenerateFlattenedXML( Dictionary* dictionary, Dictionary* sources, char* timeStamp ) { XML_IO_Handler* ioHandler; char* outputPath; char* flatFilename; char* flatFilenameStamped; char* slimFilename; Stream* s; Bool isEnabled; Bool ret; Bool outputSlim; s = Journal_Register( Info_Type, (Name)XML_IO_Handler_Type ); /* Avoid confusing messages from XML_IO_Handler. Turn it off temporarily. */ isEnabled = Stream_IsEnable( s ); Stream_EnableSelfOnly( s, False ); ioHandler = XML_IO_Handler_New(); if( sources == NULL ) ioHandler->writeSources = False; outputPath = StG_Strdup( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString( "./" ) ) ) ); outputSlim = Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputSlimmedXML", Dictionary_Entry_Value_FromBool( True ) ) ); if( ! Stg_DirectoryExists( outputPath ) ) { if( Stg_FileExists( outputPath ) ) Journal_Firewall( 0, s, "outputPath '%s' is a file an not a directory! Exiting...\n", outputPath ); Journal_Printf( s, "outputPath '%s' does not exist, attempting to create...\n", outputPath ); ret = Stg_CreateDirectory( outputPath ); Journal_Firewall( ret, s, "Unable to create non-existing outputPath to '%s'\n", outputPath ); Journal_Printf( s, "outputPath '%s' successfully created!\n", outputPath ); } /* Set file names. */ Stg_asprintf( &flatFilename, "%s/%s", outputPath, "input.xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilename, dictionary, sources ); /* Format; path/input-YYYY.MM.DD-HH.MM.SS.xml. */ if (timeStamp) { Stg_asprintf( &flatFilenameStamped, "%s/%s-%s.%s", outputPath, "input", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilenameStamped, dictionary, sources ); Memory_Free( flatFilenameStamped ); } if( outputSlim && timeStamp ) { ioHandler->writeSources = False; Stg_asprintf( &slimFilename, "%s/%s-%s.%s", outputPath, "input-basic", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, slimFilename, dictionary, NULL); } Stream_EnableSelfOnly( s, isEnabled ); Stg_Class_Delete( ioHandler ); Memory_Free( flatFilename ); }