예제 #1
0
파일: Section.c 프로젝트: kaiaie/bile
/** Creates a empty section */
Section *new_Section(Section *parent, char *dir){
	Section *s = NULL;
	s = (Section *)mu_malloc(sizeof(Section));
	s->type = BILE_SECTION;
	s->parent = parent;
	if(parent == NULL)
		s->variables = new_Vars(NULL);
	else
		s->variables = new_Vars(parent->variables);
	s->dir = astrcpy(dir);
	s->sections  = new_List();
	s->indexes   = new_List();
	s->stories   = new_List();
	return s;
}
예제 #2
0
static int private_link_archive( const void* buildParameters, const void* providerContext, const void* targetIDirectory )
{
    int status = 1;

    const BuildParameters* parameters = (BuildParameters*) buildParameters;
    const ProviderContext* context = (ProviderContext*) providerContext;
    const IDirectory*      target = (IDirectory*) targetIDirectory;

    const char* target_location = Path_getCondensed( Directory_getRealPath( target ) );

    //	Linux: ar rcs <LIBNAME> <OBJECTS>...
    //	Win32: lib /OUT:<LIBNAME> <OBJECTS>...

    char* name = CharString_between( context->package_name, "", "-" );
    if ( !name )
    {
        name = new_CharString( context->package_name );
    }
    {
        char* libname           = CharString_cat2( name, ".a" );
        char* full_lib_location = CharString_cat3( target_location, "/lib/", libname );
        char* obj_dir           = CharString_cat2( target_location, "/obj/" );

        if ( 0 < List_count( context->objectFiles ) )
        {
            Command* command;
            IList* arguments = new_List();
            IList* native_arguments;

            List_copyItem( arguments, context->archiver );
            List_copyItem( arguments, "rcs" );
            List_copyItem( arguments, full_lib_location );
            addFlags( arguments, obj_dir, context->objectFiles );


            native_arguments = Path_ConvertListToNative( arguments );
            command = new_Command( context->archiver, (const char**) native_arguments->items );
            Command_print( command, stderr );

//			if ( !BuildParameters_isNo( parameters ) && Command_run( command ) && Command_waitFor( command ) )
//			{
//				status &= Command_getResult( command );
//			} else {
//				fprintf( stderr, "failed: " );
//				Command_print( command, stderr );
//			}
            free_Command( command );
            free_List( native_arguments );
            free_List( arguments );
        }

        free_CharString( obj_dir );
        free_CharString( full_lib_location );
        free_CharString( libname );
    }
    free_CharString( name );

    return status;
}
예제 #3
0
파일: student_list.c 프로젝트: yrko1/ee209
/* create and initialize a student list */
StudentList* new_StudentList () {
	StudentList *studentlist;
	studentlist = malloc(sizeof(StudentList));
	studentlist -> list = new_List();
	studentlist -> len = 0;
	studentlist -> avg = 0;
	return studentlist;
}
예제 #4
0
파일: path.c 프로젝트: kaiaie/bile
/** Removes "." and ".." from a path */
char *getCanonicalPath(const char *path){
	char   *prefix = NULL;
	char   *rest   = NULL;
	char   *tmp    = NULL;
	size_t offset  = 0;
	char   **src   = NULL;
	List   *dst    = NULL;
	size_t ii = 0;
	Buffer *buf    = NULL;
	char   *result = NULL;
	
	if (path != NULL && strlen(path) > 0) {
		tmp = strxreplace(astrcpy(path), '\\', '/');
		if (isDosPath(tmp) || isUncPath(tmp)) {
			if (isDosPath(tmp)) {
				prefix = getPathPart(tmp, PATH_DRIVE);
				offset = 0;
			}
			else if (isUncPath(tmp)) {
				prefix = getPathPart(tmp, PATH_HOST);
				offset = 2;
			}
			rest = astrcpy(strchr(&tmp[offset], '/'));
		}
		else {
			rest = astrcpy(tmp);
		}
		src = astrtok(rest, "/");
		dst = new_List();
		while (src[ii] != NULL) {
			if (strxequals(src[ii], "..")) {
				List_remove(dst, -1, false);
			}
			else if (!strxequals(src[ii], ".")) {
				List_append(dst, src[ii]);
			}
			ii++;
		}
		buf = new_Buffer(0);
		if (prefix != NULL) {
			Buffer_appendString(buf, prefix);
		}
		for (ii = 0; ii < List_length(dst); ++ii) {
			Buffer_appendString(buf, List_get(dst, ii));
			if (ii != (List_length(dst) - 1)) {
				Buffer_appendChar(buf, '/');
			}
		}
		result = astrcpy(buf->data);
		delete_Buffer(buf);
		delete_List(dst, false);
		astrtokfree(src);
		mu_free(prefix);
		mu_free(rest);
		mu_free(tmp);
	}
	return result;
}
예제 #5
0
파일: hash.c 프로젝트: AnaZugravu/HashTable
Hash new_Hash(int length){
	Hash newHash;
	int i;
	
	newHash = malloc(sizeof(struct hashmap));
	newHash->length = length;
	newHash->lists = calloc(length, sizeof(struct list *));

	for (i = 0; i < length; ++i)
		newHash->lists[i] = new_List();

	return newHash;
}
예제 #6
0
int SuperDirectory_refresh( ISuperDirectory* self )
{
	int status = 1;
	
	if ( self->volumes )
	{
		free_List( self->volumes );
	}
	self->volumes = new_List();
	
	List_copyItem( self->volumes, "/" );
	
	return status;
}
예제 #7
0
/**
   inserisce una nuova coppia (key, payload) nella hash table (se non c'e' gia')

    \param t la tabella cui aggiungere
    \param key la chiave
    \param payload l'informazione

    \retval -1 se si sono verificati errori (errno settato opportunamente)
    \retval 0 se l'inserimento \`e andato a buon fine

    SP ricordarsi di controllare se (in caso di errore) si lascia la
    situazione consistente o si fa casino nella lista ....
*/
int add_hashElement(hashTable_t * t,void * key, void* payload ) {
  int index = 0;

  /* controllo valore dei parametri */
  if (!t || !key || !payload || !(t->table)) {
    errno = EINVAL;
    return -1;
  }

  /* indice della tabella hash per la chiave da inserire */
  index = t->hash(key, t->size);

  /* verifica che sia allocatanella, nella tabella hash, la lista per
   * l'indice hash della chiave da inserire */
  if (NULL == *(t->table+index)) {
    /* crea la lista per l'indice index della tablella */
    if (NULL == (*(t->table+index) = new_List(t->compare, t->copyk, t->copyp)))
      return -1; /* impossibile creare la lista in index di hash table
		  * (memoria non disponibile) */
  } 

  /* aggiungi un nuovo elemento alla lista (key, payload) */
  errno = 0;
  if (-1 == add_ListElement(*(t->table+index), key, payload)) {
    /* dato che NULL != { *(t->table+index), key, payload }
     * allora e' impossibile aggiungere un nuovo elemento 
     * - perche' la memoria non e' disponibile
     * - perche' esiste gia' un elemento con chiave key
     * in entrambi i casi errno viene opportunamente impostato
     * da add_ListElement */

    if (NULL == (*(t->table+index))->head) {/* <================================================== ACCESSO AI CAMPI DELLA STRUTTURA LIST_T */
      /* la lista dell'indice corrispondente alla nuova chiave e'
       * vuota, cio' implica che e' stata allocata da questa
       * insersione e deve essere deallocata, in quanto l'insersione
       * e' fallita.
       *
       * nota: la free_List imposta a NULL il valore del puntatore
       * riferito dal puntatore passato per argomento, quindi
       * *(t->table+index) assumera' NULL, che significa lista non
       * presente per l'indice index della tabella hash. */

      free_List(t->table+index);
    }

    return -1;
  }
  
  return 0;
}
예제 #8
0
파일: String_.c 프로젝트: PiJoules/python2c
Object *new_String(char *base){
    // Intiialize object
    Object *string = new_List();

    // Set default values
    string->name = "string";

    // Set list values
    int i;
    int len = strlen(base);
    for (i = 0; i < len; i++){
        Object *c = new_Char(*(base + i));
        list_append(string, c);
        destroy(c);
    }

    return string;
}
예제 #9
0
파일: room.c 프로젝트: tekktonic/newsdl
Room new_Room( ResourceManager rm, Window win, const char *bg, const char *map)
{
    Room ret = malloc(sizeof(*ret));
    ret->bg = malloc(sizeof(Sprite_s));
    ret->window = win;
    

    ret->bg->tex = ResourceManager_loadImage(rm, win, bg);
    ret->bg->rect.pos.x = ret->bg->rect.pos.y = 0;
    ret->bg->rect.w = 640;
    ret->bg->rect.h = 480;
    ret->offsetX = ret->offsetY = 0;
    ret->cameraFocus = NULL;
    ret->entities = new_List(0);

    if (map)
    {
	json_t *maproot, *entities;
	json_error_t jsonError;

	maproot = ResourceManager_loadMap(rm, map);
	ret->width = json_value(integer, maproot, "width");
	ret->width = json_value(integer, maproot, "height");

	entities = json_object_get(maproot, "entities");
	for(unsigned int i = 0; i < json_array_size(entities); i++)
	{
	    json_t *elm, *args;
	    char *type;
	    elm = json_array_get(entities, i);
	    assert(json_is_object(elm));
	    type = (char*)json_value(string, elm, "type");

	    Entity (*constructor)(json_t*);
	    if (constructor = FHash_get(constructors, type))
		constructor(elm);
	}
    }
    return ret;
}
예제 #10
0
static int private_compile( const void* buildParameters, const void* providerContext, const void* targetIDirectory )
{
    bool status = 1;
    const BuildParameters* parameters = (BuildParameters*) buildParameters;
    const ProviderContext* context = (ProviderContext*) providerContext;
    const IDirectory*      target = (IDirectory*) targetIDirectory;

    //IList* cppflags = translateArguments( context->FULL_CPPFLAGS );

    unsigned int i;
    unsigned int count = List_count( context->sourceFiles );
//	fprintf( stdout, "ISLabs::linux-gnu::gnu::compile( %s )\n", Path_getCondensed( Directory_getRealPath( target ) ) );
    for ( i = 0; (i < count) && status; i++ )
    {
        //	cc $CPPFLAGS $LANGFLAGS $CFLAGS $SRC_FILE -o $OUTPUT

        IPath* p = new_Path( context->sourceFiles->items[i] );
        char* target_file = CharString_cat2( Path_getBasename( p ), ".obj" );
        char* target_path = CharString_cat3( Path_getCondensed( Directory_getRealPath( target ) ), "/obj/", target_file );

        Command* command;
        IList*   arguments = new_List();
        IList*   native_arguments;

        // Compiler
        List_copyItem( arguments, context->compiler );

        // C-preprocessor flags
        addFlags( arguments, "-I", context->includeDirs );
        List_addList( arguments, BuildParameters_getGlobal( parameters )->CPPFLAGS );

        // C flags
        List_copyItem( arguments, "-Wall" );
        List_copyItem( arguments, "-fPIC" );
        List_copyItem( arguments, "-c" );

        if ( BuildParameters_isRelease( parameters ) )
        {
            //List_copyItem( arguments, "-O2" );
        } else {
            List_copyItem( arguments, "-g" );
        }
        List_addList( arguments, BuildParameters_getGlobal( parameters )->CFLAGS );

        // Source files
        List_copyItem( arguments, context->sourceFiles->items[i] );

        // Output files
        List_copyItem( arguments, "-o" );
        List_copyItem( arguments, target_path );

        native_arguments = Path_ConvertListToNative( arguments );
        command = new_Command( context->compiler, (const char**) native_arguments->items );
        Command_print( command, stderr );
//		if ( !BuildParameters_isNo( parameters ) && Command_run( command ) && Command_waitFor( command ) )
//		{
//			status &= Command_getResult( command );
//		} else {
//			fprintf( stderr, "failed: " );
//			Command_print( command, stderr );
//		}
        free_Command( command );
        free_CharString( target_file );
        free_Path( p );
    }
    return status;
}
예제 #11
0
static int private_link_executable( const void* buildParameters, const void* providerContext, const void* targetIDirectory )
{
//	fprintf( stdout, "ISLabs::linux-gnu::gnu::link()\n" );
    bool status = 1;
    const BuildParameters* parameters = (BuildParameters*) buildParameters;
    const ProviderContext* context = (ProviderContext*) providerContext;
    const IDirectory*      target = (IDirectory*) targetIDirectory;

    SoName* so_name = generateSoName( context->package_name, context->isLib );
    char* target_location_obj       = CharString_cat2( Path_getCondensed( Directory_getRealPath( target ) ), "/obj/" );
    char* target_location_bin_short = CharString_cat3( Path_getCondensed( Directory_getRealPath( target ) ), "/bin/", so_name->short_name );

    Command* command;
    IList* arguments = new_List();
    IList* native_arguments;

    //  Linker
    List_copyItem( arguments, context->linker );

    //  Linker flags
    //if ( !BuildParameters_isRelease( parameters ) )
    //{
    //	List_copyItem( arguments, "-Wl,-G" );
    //}
    //List_copyItem( arguments, "-shared" );

    //  Object files: need to be before archive libraries so
    //                symbols can be found.
    addFlags( arguments, target_location_obj, context->objectFiles );

    //  System library directories
    //
    addFlags( arguments, "-L", context->systemLibraryDirs );

    if ( BuildParameters_isMonolithic( parameters ) )
    {
        addFlags( arguments, "", context->unix_archives );
        addFlags( arguments, "-l", context->system_libraries );
    } else {
        addFlags( arguments, "-L", context->libraryDirs );
        addFlags( arguments, "-l", context->libraries );
    }

    List_addList( arguments, BuildParameters_getGlobal( parameters )->LFLAGS );
    List_addList( arguments, BuildParameters_getGlobal( parameters )->LDFLAGS );

    List_copyItem( arguments, "-Wl,-R$ORIGIN" );
    List_copyItem( arguments, "-Wl,-R$ORIGIN/../lib" );

    if ( BuildParameters_isDeep( parameters ) )
    {
        addFlags( arguments, "-Wl,-R$ORIGIN/../", context->runtimeLibraryDirs );
    }


    //List_copyItem( arguments, "-Wl,-soname" );
    //List_addItem( arguments, CharString_cat2( "-Wl,", so_name->long_name ) );

    List_copyItem( arguments, "-o" );
    List_copyItem( arguments, target_location_bin_short );

    native_arguments = Path_ConvertListToNative( arguments );
    command = new_Command( context->linker, (const char**) native_arguments->items );
    Command_print( command, stderr );

//	if ( BuildParameters_getVerbosity( parameters ) )
//	{
//		Command_print( command, stderr );
//	}
//
//	if ( !BuildParameters_isNo( parameters ) && Command_run( command ) && Command_waitFor( command ) )
//	{
//		status &= Command_getResult( command );
//	} else {
//		fprintf( stderr, "failed: " );
//		Command_print( command, stderr );
//	}

    free_Command( command );
    free_List( native_arguments );

    free_List( arguments );
    free_CharString( target_location_obj );
    free_CharString( target_location_bin_short );

    return status;
}
예제 #12
0
파일: LinkedList.c 프로젝트: PiJoules/ooc
Any List_add_impl(Any self, Any other){
    return new_List();
}
예제 #13
0
파일: LinkedList.c 프로젝트: PiJoules/ooc
Any List_copy_impl(Any self){
    return new_List();
}
예제 #14
0
파일: stack.c 프로젝트: kaiaie/bile
List new_Stack(void){
	return (Stack)new_List();
}
예제 #15
0
파일: Dict.c 프로젝트: kaiaie/bile
Dict *new_Dict() {
	return (Dict *)new_List();
}