void configParserStruct::pythonParser::recreateDictionary()
{
  clearDictionary();
  
  Dictionary = (void*)( PyDict_New() );
  PyDict_SetItemString( castToPyObject(Dictionary), "__builtins__", PyEval_GetBuiltins() );
}
configParserStruct::pythonParser::~pythonParser()
{
  clearDictionary();

  NumberOfPythonParsers--;
  if ( NumberOfPythonParsers <= 0 )
    Py_Finalize();
}
Пример #3
0
int
_clearDictArray( dictionary_t *dictArray, int len ) {
    int i;

    if ( dictArray == NULL ) {
        return 0;
    }

    for ( i = 0; i < len; i++ ) {
        clearDictionary( &dictArray[i] );
    }
    return 0;
}
Пример #4
0
int
clearDictionary( dictionary_t *dictionary ) {
    int i;

    if ( dictionary == NULL || dictionary->len <= 0 ) {
        return ( 0 );
    }

    for ( i = 0; i < dictionary->len; i++ ) {
        free( dictionary->key[i] );
        if ( strcmp( dictionary->value[i].type_PI, Dictionary_MS_T ) == 0 ) {
            clearDictionary( ( dictionary_t * ) dictionary->value[i].ptr );
        }
        free( dictionary->value[i].ptr );
    }

    free( dictionary->key );
    free( dictionary->value );
    bzero( dictionary, sizeof( dictionary_t ) );
    return( 0 );
}
Пример #5
0
int
clearGenArray( genArray_t *genArray ) {
    int i;

    if ( genArray == NULL || genArray->len <= 0 ) {
        return ( 0 );
    }

    for ( i = 0; i < genArray->len; i++ ) {
        if ( strcmp( genArray->value[i].type_PI, Dictionary_MS_T ) == 0 ) {
            clearDictionary( ( dictionary_t * ) genArray->value[i].ptr );
        }
        else if ( strcmp( genArray->value[i].type_PI, GenArray_MS_T ) == 0 ) {
            clearGenArray( ( genArray_t * ) genArray->value[i].ptr );
        }

        free( genArray->value[i].ptr );
    }

    free( genArray->value );
    bzero( genArray, sizeof( genArray_t ) );
    return( 0 );
}
void QRelation::clear()
{
    delete model;
    model = 0;
    clearDictionary();
}
Пример #7
0
int main(int argc, char* argv[]){

    if ( argc != 3 ) // argc should be 3 for correct execution
    {
        printf( "usage: %s input_filename output_filename\n", argv[0] );
    }

	//read text file into input array
	OriginalData* orig = readOriginalData(argv[1]);

	//allocate the same amount of compressed data (lets hope it is enough)
	CompressedData* compressed = newCompressedData(orig->dataLength, 8);

	//initializez the dictionary and the symbols in the dictionary
	Dictionary* dict = newDictionary(8);
	initDictionary(dict);

    printf("Compressing...\n");
	writeToCompressedData(compressed, dict->clearCode);

	MyString* S = newString();
	int codeword;
	int dictReturn;
	while(hasNextSymbol(orig)){
		appendString(S, (uint8_t) nextSymbol(orig));

		if(getCodeword(dict, S) != -1){
			;
		} else {
			//output S minus the last char 
			S->length--;
			codeword = getCodeword(dict, S);
			writeToCompressedData(compressed, codeword);
			S->length++;

			//great for debugging :
			// printf("wrote a %d bit codeword: %d\n", compressed->bitWidth, codeword);         
			// printf("Saved new word: %d    \t", dict->wordCount);
			// printString(S);
			// printf("\n");

			//add S to the dictionary
			dictReturn = addToDictionary(dict, S);

			if(dictReturn == -2){
				//for debugging :
            	// printf("--------------------------Increased Bit Width\n");

				//increase the bit width by one
				compressed->bitWidth++;
				dict->bitWidth *= 2;
			}
			if(dictReturn == -1){
				//dictionary is full, clear it and write a clearCode
				clearDictionary(dict);
				writeToCompressedData(compressed, dict->clearCode);
            	compressed->bitWidth = compressed->rootBitWidth+1;
				//step one symbol back in original data
				orig->nextSymbol--;
				orig->dataLeft++;
				//make S empty
				S->length = 0;
			}else{
				//"delete" the last character (it will still be in the data)
				S->length--;
				S->data[0] = S->data[S->length];//make S start with the "deleted" character
				S->length = 1;	//make the length of S 1, now S is the earlier last character
			}
		}
	}
	//write the last codeword
	codeword = getCodeword(dict, S);
	writeToCompressedData(compressed, codeword);

	//write EOI
	writeToCompressedData(compressed, dict->endOfInformation);

	writeCompressedDataToFile(compressed, argv[2]);  
    printf("File %s compressed succesfully to %s\n", argv[1], argv[2]);
    return 0;
}
Пример #8
0
int
jsonUnpackDict( json_t *dictObj, dictionary_t *outDict ) {
    void *iter;
    void *tmpOut;
    dictionary_t *tmpDict;
    genArray_t *tmpGenArray;
    int *tmpInt;
    float *tmpFloat;
    const char *key;
    json_t *value;
    int status = 0;

    if ( dictObj == NULL || outDict == NULL ) {
        rodsLog( LOG_ERROR,
                 "jsonUnpackDict: NULL input" );
        return USER__NULL_INPUT_ERR;
    }
    bzero( outDict, sizeof( dictionary_t ) );
    iter = json_object_iter( dictObj );
    while ( iter ) {
        json_type myType;

        key = json_object_iter_key( iter );
        value = json_object_iter_value( iter );
        myType = json_typeof( value );
        switch ( myType ) {
        case JSON_OBJECT:
            tmpDict = ( dictionary_t * ) calloc( 1, sizeof( dictionary_t ) );
            status = jsonUnpackDict( value, tmpDict );
            if ( status < 0 ) {
                free( tmpDict );
            }
            else {
                status = dictSetAttr( outDict, ( char * ) key, Dictionary_MS_T,
                                      tmpDict );
            }
            break;
        case JSON_ARRAY:
            tmpGenArray = ( genArray_t * ) calloc( 1, sizeof( genArray_t ) );
            status = jsonUnpackArray( value, tmpGenArray );
            if ( status < 0 ) {
                free( tmpGenArray );
            }
            else {
                status = dictSetAttr( outDict, ( char * ) key, GenArray_MS_T,
                                      tmpGenArray );
            }
            break;
        case JSON_STRING:
            tmpOut = strdup( json_string_value( value ) );
            status = dictSetAttr( outDict, ( char * ) key, STR_MS_T, tmpOut );
            break;
        case JSON_INTEGER:
            tmpInt = ( int * ) calloc( 1, sizeof( int ) );
            *tmpInt = ( int ) json_integer_value( value );
            status = dictSetAttr( outDict, ( char * ) key, INT_MS_T,
                                  ( void * ) tmpInt );
            break;
        case JSON_REAL:
            tmpFloat = ( float * ) calloc( 1, sizeof( float ) );
            *tmpFloat = ( float ) json_real_value( value );
            status = dictSetAttr( outDict, ( char * ) key, FLOAT_MS_T,
                                  ( void * ) tmpFloat );
            break;
        case JSON_TRUE:
            tmpInt = ( int * ) calloc( 1, sizeof( int ) );
            *tmpInt = 1;
            status = dictSetAttr( outDict, ( char * ) key, BOOL_MS_T,
                                  ( void * ) tmpInt );
            break;
        case JSON_FALSE:
            tmpInt = ( int * ) calloc( 1, sizeof( int ) );
            *tmpInt = 0;
            status = dictSetAttr( outDict, ( char * ) key, BOOL_MS_T,
                                  ( void * ) tmpInt );
            break;
        default:
            rodsLog( LOG_ERROR,
                     "ooiGenServReqFunc: myType %d not supported", myType );
            status = OOI_JSON_TYPE_ERR;
        }
        iter = json_object_iter_next( dictObj, iter );
    }
    if ( status < 0 ) {
        clearDictionary( outDict );
    }

    return status;
}