static gboolean add_action(rra_diff_info *in_info, rra_diff_action *in_action) { if (in_info == NULL) { if (in_action != NULL) { free_action(in_action); } return FALSE; } if (in_action == NULL) { return FALSE; } gchar *msg = rra_di_action_to_string(in_action); rra_info(N_("Adding action: %s"), msg); g_free(msg); g_ptr_array_add(in_info->action_list, in_action); return TRUE; }
void free_players(t_list *players) { t_player *player; t_action *action; while (players) { player = players->data; while ((action = c_buf_get(&(player->actions)))) free_action(action); players = players->next; } close_fds(g_zappy->players); free_list(g_zappy->players); }
static gboolean free_actions(GPtrArray *in_arr) { gboolean ret_val = TRUE; while (in_arr->len > 0) { rra_diff_action *action = (rra_diff_action*)g_ptr_array_remove_index_fast(in_arr, 0); if (!free_action(action)) { ret_val = FALSE; } } return ret_val; }
void writing_command(int fds,char* name_prog){ if(!fork()){ creat("res/tmp.txt",0666); int fdout = open("res/tmp.txt",O_WRONLY); dup2(fdout,1); execlp("strace","strace","-f","-e",TRACE_FORK,"-o","res/lala",name_prog, NULL); } else{ FILE* buffer = fopen("res/lala", "r"); char* buf=NULL; char *line = malloc(MAX_LINE*sizeof(char)); action *action; size_t len=0; int got = 0; creat("res/resultat.txt",0666); creat("res/CLE1.txt",0666); int fd = open("res/resultat.txt",O_WRONLY); int fd1 = open("res/CLE1.txt",O_WRONLY); while((got=getline(&buf, &len, buffer))!=-1){ printf("Nouvelle ecriture niveau 1\n"); write(fd,buf,got); action = parser_command(buf); sprintf(line,"%d/%d/%s/%d/%d/%d/%d/%s\n",action->begin,action->pid_father,action->call,action->wait,action->pid_son,action->end,action->fd,action->message); write(fd1,line,strlen(line)); write(fds,line,strlen(line)); free_action(action); if(global_data->state == RUN) usleep((MAX_SPEED-global_data->speed)*10000); } printf("Fin niveau 1\n"); free(line); free(buf); close(fd); } //wait(NULL); }
/* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */ void free_libblock(ListBase *lb, void *idv) { ID *id= idv; #ifdef WITH_PYTHON BPY_id_release(id); #endif switch( GS(id->name) ) { /* GetShort from util.h */ case ID_SCE: free_scene((Scene *)id); break; case ID_LI: free_library((Library *)id); break; case ID_OB: free_object((Object *)id); break; case ID_ME: free_mesh((Mesh *)id); break; case ID_CU: free_curve((Curve *)id); break; case ID_MB: free_mball((MetaBall *)id); break; case ID_MA: free_material((Material *)id); break; case ID_TE: free_texture((Tex *)id); break; case ID_IM: free_image((Image *)id); break; case ID_LT: free_lattice((Lattice *)id); break; case ID_LA: free_lamp((Lamp *)id); break; case ID_CA: free_camera((Camera*) id); break; case ID_IP: free_ipo((Ipo *)id); break; case ID_KE: free_key((Key *)id); break; case ID_WO: free_world((World *)id); break; case ID_SCR: free_screen((bScreen *)id); break; case ID_VF: free_vfont((VFont *)id); break; case ID_TXT: free_text((Text *)id); break; case ID_SCRIPT: //XXX free_script((Script *)id); break; case ID_SPK: free_speaker((Speaker *)id); break; case ID_SO: sound_free((bSound*)id); break; case ID_GR: free_group_objects((Group *)id); break; case ID_AR: free_armature((bArmature *)id); break; case ID_AC: free_action((bAction *)id); break; case ID_NT: ntreeFreeTree((bNodeTree *)id); break; case ID_BR: free_brush((Brush *)id); break; case ID_PA: psys_free_settings((ParticleSettings *)id); break; case ID_WM: if(free_windowmanager_cb) free_windowmanager_cb(NULL, (wmWindowManager *)id); break; case ID_GD: free_gpencil_data((bGPdata *)id); break; } if (id->properties) { IDP_FreeProperty(id->properties); MEM_freeN(id->properties); } BLI_remlink(lb, id); /* this ID may be a driver target! */ BKE_animdata_main_cb(G.main, animdata_dtar_clear_cb, (void *)id); MEM_freeN(id); }
/* This procedure frees up the strings and/or the structures attatched to a * descriptor, sets all flags back to how they should be. */ void cleanup_olc(struct descriptor_data *d, byte cleanup_type) { /* Clean up WHAT? */ if (d->olc == NULL) return; /* Check for a room. free_room doesn't perform sanity checks, we must be * careful here. */ if (OLC_ROOM(d)) { switch (cleanup_type) { case CLEANUP_ALL: /* free(OLC_SCRIPT(d)) equivalent */ free_proto_script(OLC_ROOM(d), WLD_TRIGGER); free_room(OLC_ROOM(d)); break; case CLEANUP_STRUCTS: free(OLC_ROOM(d)); break; case CLEANUP_CONFIG: free_config(OLC_CONFIG(d)); break; default: /* The caller has screwed up. */ log("SYSERR: cleanup_olc: Unknown type!"); break; } } /* Check for an existing object in the OLC. The strings aren't part of the * prototype any longer. They get added with strdup(). */ if (OLC_OBJ(d)) { free_object_strings(OLC_OBJ(d)); free(OLC_OBJ(d)); } /* Check for a mob. free_mobile() makes sure strings are not in the * prototype. */ if (OLC_MOB(d)) free_mobile(OLC_MOB(d)); /* Check for a zone. cleanup_type is irrelevant here, free() everything. */ if (OLC_ZONE(d)) { if (OLC_ZONE(d)->builders) free(OLC_ZONE(d)->builders); if (OLC_ZONE(d)->name) free(OLC_ZONE(d)->name); if (OLC_ZONE(d)->cmd) free(OLC_ZONE(d)->cmd); free(OLC_ZONE(d)); } /* Check for a shop. free_shop doesn't perform sanity checks, we must be * careful here. OLC_SHOP(d) is a _copy_ - no pointers to the original. Just * go ahead and free it all. */ if (OLC_SHOP(d)) free_shop(OLC_SHOP(d)); /* Check for a quest. */ if (OLC_QUEST(d)) { switch (cleanup_type) { case CLEANUP_ALL: free_quest(OLC_QUEST(d)); break; case CLEANUP_STRUCTS: free(OLC_QUEST(d)); break; default: break; } } /*. Check for aedit stuff -- M. Scott */ if (OLC_ACTION(d)) { switch(cleanup_type) { case CLEANUP_ALL: free_action(OLC_ACTION(d)); break; case CLEANUP_STRUCTS: free(OLC_ACTION(d)); break; default: /* Caller has screwed up */ break; } } /* Used for cleanup of Hedit */ if (OLC_HELP(d)) { switch(cleanup_type) { case CLEANUP_ALL: free_help(OLC_HELP(d)); break; case CLEANUP_STRUCTS: free(OLC_HELP(d)); break; default: break; } } if (OLC_IBT(d)) { free_olc_ibt(OLC_IBT(d)); OLC_IBT(d) = NULL; } if (OLC_MSG_LIST(d)) { free_message_list(OLC_MSG_LIST(d)); OLC_MSG_LIST(d) = NULL; OLC_MSG(d) = NULL; } /* Free storage if allocated (tedit, aedit, and trigedit). This is the command * list - it's been copied to disk already, so just free it -Welcor. */ if (OLC_STORAGE(d)) { free(OLC_STORAGE(d)); OLC_STORAGE(d) = NULL; } /* Free this one regardless. If we've left olc, we've either made a fresh * copy of it in the trig index, or we lost connection. Either way, we need * to get rid of this. */ if (OLC_TRIG(d)) { free_trigger(OLC_TRIG(d)); OLC_TRIG(d) = NULL; } /* Free this one regardless. If we've left olc, we've either copied the * * preferences to the player, or we lost connection. Either way, we need * * to get rid of this. */ if(OLC_PREFS(d)) { /*. There is nothing else really to free, except this... .*/ free(OLC_PREFS(d)); OLC_PREFS(d) = NULL; } /* OLC_SCRIPT is always set as trig_proto of OLC_OBJ/MOB/ROOM. Therefore it * should not be free'd here. */ /* Restore descriptor playing status. */ if (d->character) { REMOVE_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING); act("$n stops using OLC.", TRUE, d->character, NULL, NULL, TO_ROOM); if (cleanup_type == CLEANUP_CONFIG) mudlog(BRF, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing the game configuration", GET_NAME(d->character)); else if (STATE(d) == CON_TEDIT) mudlog(BRF, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing text files.", GET_NAME(d->character)); else if (STATE(d) == CON_HEDIT) mudlog(CMP, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing help files.", GET_NAME(d->character)); else mudlog(CMP, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing zone %d allowed zone %d", GET_NAME(d->character), zone_table[OLC_ZNUM(d)].number, GET_OLC_ZONE(d->character)); STATE(d) = CON_PLAYING; } free(d->olc); d->olc = NULL; }
void read_info(int fdl,int fdw){ char *buf =malloc((MAX_LINE+1)*sizeof(char)); char line[MAX_LINE]; int *listing = malloc(50*sizeof(int)); int *bool_listing = malloc(50*sizeof(int)); int size_listing=0,num_turn=0,pos=-1; creat("res/CLE.txt",0666); int got=0,fd = open("res/CLE.txt", O_WRONLY),first_read=1; action *action; clear_listing(listing,50); clear_listing(bool_listing,50); do{ if ((got = readline(fdl, buf, 500)) < 0){ got=1; } else if(got>0){ printf("Message recu niveau 2\n"); buf[got]='\0'; /*Build action and manage the turns*/ action = build_again_action(buf); if( ((first_read || !strlen(action->message)) && !strncmp(action->call,"read",strlen("read"))) || (!strlen(action->message) && !strncmp(action->call,"write",strlen("write"))) ){ printf("On a un %s useless\n",action->call); first_read=0; free(action); continue; } else if((pos=isInListing(listing,size_listing,action->pid_father))==-1){ listing[size_listing]=action->pid_father; size_listing++; bool_listing[size_listing-1]=1; } else{ if(bool_listing[pos]){ clear_listing(bool_listing,size_listing); bool_listing[pos]=1; num_turn++; char line2[50]; sprintf(line2,"new turn\n"); write(fdw,line2,strlen(line2)); write(fd,line2,strlen(line2)); } else bool_listing[pos]=1; } sprintf(line,"%d/%d/%s/%d/%d/%d/%d/%s\n",action->begin,action->pid_father,action->call,action->wait,action->pid_son,action->end,action->fd,action->message); printf("%s\n", line); if((action->end && (strcmp(action->call,"clone") || action->pid_son!=0))|| !strcmp("wait4",action->call) || !strcmp("waitpid",action->call) || !strcmp("read",action->call) || !strcmp("write",action->call)){ write(fdw,line,strlen(line)); } write(fd,line,strlen(line)); free_action(action); } if(global_data->state == RUN) usleep((MAX_SPEED-global_data->speed)*10000); } while(got>0); wait(NULL); printf("Fin lecture niveau 2\n"); free(bool_listing); free(buf); close(fdw); free(listing); }