fa_pair_t fa_pair_dassoc(fa_pair_t pair) { fa_pair_t pair2 = fa_pair_assoc(pair); fa_destroy(pair->values[1]); fa_destroy(pair); return pair2; }
fa_pair_t fa_pair_dunassoc(fa_pair_t pair) { fa_pair_t pair2 = fa_pair_unassoc(pair); fa_destroy(pair->values[0]); fa_destroy(pair); return pair2; }
void fa_error_destroy_simple(simple_fa_error_t simple) { fa_destroy(simple->message); if (simple->origin) fa_destroy(simple->origin); fa_delete(simple); }
void helper_function() { fa_signal_custom_processor_t proc; proc.before = before_; proc.after = after_; proc.render = render_; proc.receive = receive_; proc.send = NULL; proc.data = NULL; proc.destroy = NULL; // printf("Sending custom proc %p!\n", &proc); fa_signal_t a = fa_multiply(fa_signal_sin(fa_signal_line(440)), fa_signal_input(32)); fa_signal_t b = fa_signal_custom(&proc, a); fa_mark_used(a); fa_mark_used(b); fa_signal_t r = b; if (RT) { fa_audio_session_t s = fa_audio_begin_session(); fa_audio_device_t i = fa_audio_default_input(s); fa_audio_device_t o = fa_audio_default_output(s); fa_list_t out = list(r, a); fa_audio_stream_t st = fa_audio_open_stream(i, o, just, out); if (fa_check(st)) { fa_error_log(st, NULL); } fa_audio_schedule( fa_hms(0, 0, 0), fa_action_send(fa_string("DLS"), fa_string("hello!")), st ); while (1) { fa_audio_schedule( fa_hms(0, 0, 0), fa_action_send(fa_string("DLS"), fa_string("hello!")), st ); fa_thread_sleep(1000 * 1); } fa_destroy(st); fa_destroy(s); } else { fa_signal_run_file(44100 * 10, list( fa_pair_create(fa_hms(0, 0, 0), fa_action_send(fa_string("DLS"), fa_string("hello!"))) ), r, fa_string("test.wav")); } }
fa_buffer_t fa_buffer_dresize(size_t size, fa_buffer_t buffer) { // TODO could use realloc and be much more efficient buffer_t buffer2 = fa_buffer_resize(size, buffer); fa_destroy(buffer); return buffer2; }
int main() { printf("TP4\n"); struct fa tomate; struct fa tomate2; struct fa tomateprod; size_t states,alphas; int loop=1,loop2,example,choice; bool fa_created1=false; bool fa_created2=false; bool fa_createdprod=false; printf("################################################################\n"); printf("# #\n"); printf("# TL fa-manager(0.6.2) #\n"); printf("# #\n"); printf("# !!! Warning there is no input check, follow instructions !!! #\n"); printf("# !!! Do not put any letter when not prompt to !!! #\n"); printf("# #\n"); printf("################################################################\n"); while(loop == 1) { printf("################################################################\n"); printf("# #\n"); printf("# 1 : Create Automate #\n"); printf("# 2 : Create Second Automate (For Product) #\n"); printf("# 3 : Display Automate #\n"); printf("# 4 : Display Production Automate #\n"); printf("# 5 : Modify Automate #\n"); printf("# 6 : Delete Automate #\n"); printf("# 7 : Quit (and delete Automate) #\n"); printf("# #\n"); printf("################################################################\n"); printf("Your Choice :"); scanf("%d", &choice); switch(choice) { case 1: if(fa_created1==true) { printf("Automate already created, destroy it before creating a other one\n"); } else { printf("Do you want a example automate (from the TP subject) ?(1/0)"); scanf("%d", &example); if (example==1) { fa_create(&tomate,2,5); fa_set_state_initial(&tomate, 0); fa_set_state_initial(&tomate, 1); fa_set_state_final(&tomate, 4); fa_add_transition(&tomate, 0, 'a', 1); fa_add_transition(&tomate, 0, 'a', 2); fa_add_transition(&tomate, 0, 'a', 3); fa_add_transition(&tomate, 1, 'b', 3); fa_add_transition(&tomate, 2, 'a', 3); fa_add_transition(&tomate, 2, 'b', 4); fa_add_transition(&tomate, 3, 'a', 3); fa_add_transition(&tomate, 3, 'b', 4); fa_add_transition(&tomate, 4, 'a', 4); } else { printf("How many states do you want ?"); scanf("%zu", &states); printf("How many alpha's do you want ?"); scanf("%zu", &alphas); fa_create(&tomate, alphas, states); } fa_created1 = true; } break; case 2: if(fa_created2==true) { printf("Automate already created, destroy it before creating a other one\n"); } else { printf("Do you want a example automate (from the TP subject) ?(1/0)"); scanf("%d", &example); if (example==1) { fa_create(&tomate2,2,5); fa_set_state_initial(&tomate2, 0); fa_set_state_initial(&tomate2, 1); fa_set_state_final(&tomate2, 4); fa_add_transition(&tomate2, 0, 'a', 1); fa_add_transition(&tomate2, 0, 'a', 2); fa_add_transition(&tomate2, 0, 'a', 3); fa_add_transition(&tomate2, 1, 'b', 3); fa_add_transition(&tomate2, 2, 'a', 3); fa_add_transition(&tomate2, 2, 'b', 4); fa_add_transition(&tomate2, 3, 'a', 3); fa_add_transition(&tomate2, 3, 'b', 4); fa_add_transition(&tomate2, 4, 'a', 4); } else { printf("How many states do you want ?"); scanf("%zu", &states); printf("How many alpha's do you want ?"); scanf("%zu", &alphas); fa_create(&tomate2, alphas, states); } fa_created2 = true; } break; case 3: if(fa_created1==false) { printf("No Production has been done, do one before displaying it\n"); } else { printf("The Automate has %zu transition(s)\n",fa_count_transitions(&tomate)); if(fa_is_deterministic(&tomate)) { printf("The Automate is deterministic\n"); } else { printf("The Automate isn't deterministic\n"); } if(fa_is_complete(&tomate)) { printf("The Automate is complete\n"); } else { printf("The Automate isn't complete\n"); } if(fa_is_language_empty(&tomate)) { printf("The Automate has an empty language\n"); } else { printf("The Automate doesn't have an empty language\n"); } fa_pretty_print(&tomate,stdout); } break; case 4: if(fa_createdprod==false) { printf("No Automate has been created, create it before displaying it\n"); } else { printf("The Automate has %zu transition(s)\n",fa_count_transitions(&tomateprod)); if(fa_is_deterministic(&tomateprod)) { printf("The Automate is deterministic\n"); } else { printf("The Automate isn't deterministic\n"); } if(fa_is_complete(&tomateprod)) { printf("The Automate is complete\n"); } else { printf("The Automate isn't complete\n"); } if(fa_is_language_empty(&tomateprod)) { printf("The Automate has an empty language\n"); } else { printf("The Automate doesn't have an empty language\n"); } if(fa_has_empty_intersection(&tomate,&tomate2)) { printf("The Automates have an empty intersection\n"); } else { printf("The Automates doesn't have an empty intersection\n"); } fa_pretty_print(&tomateprod,stdout); } break; case 5: loop2=1; int choice2; size_t s1,s2; char alpha; if(fa_created1==false) { printf("No Automate has been created, create it before modifying it\n"); } else { while(loop2==1) { printf("#################################################################\n"); printf("# #\n"); printf("# 0 : Add Transition #\n"); printf("# 1 : Remove Transition #\n"); printf("# 2 : Add Initial State #\n"); printf("# 3 : Add Final State #\n"); printf("# 4 : Make Complete #\n"); printf("# 5 : Merge States #\n"); printf("# 6 : Remove State #\n"); printf("# 7 : Remove non accessible states #\n"); printf("# 8 : Remove non co-accessible states(not working) #\n"); printf("# 9 : Product of two automates #\n"); printf("# 10 : Go Back #\n"); printf("# #\n"); printf("#################################################################\n"); choice2 = 0; printf("Your Choice :"); scanf("%d", &choice2); switch (choice2) { case 0: printf("State from ?(0,1,...)"); scanf("%zu", &s1); printf("With which letter ?(a,b,...)"); scanf("%s", &alpha); printf("State to ?(0,1,...)"); scanf("%zu", &s2); fa_add_transition(&tomate,s1,alpha,s2); break; case 1: printf("State from ?(0,1,...)"); scanf("%zu", &s1); printf("With which letter ?(a,b,...)"); scanf("%s", &alpha); printf("State to ?(0,1,...)"); scanf("%zu", &s2); fa_remove_transition(&tomate,s1,alpha,s2); break; case 2: printf("Initial state ?(0,1,...)"); scanf("%zu", &s1); fa_set_state_initial(&tomate,s1); break; case 3: printf("Final state ?(0,1,...)"); scanf("%zu", &s1); fa_set_state_final(&tomate,s1); break; case 4: printf("Completing ...\n"); fa_make_complete(&tomate); break; case 5: printf("First State to merge ?(0,1,...)"); scanf("%zu", &s1); printf("Second State to merge ?(0,1,...)"); scanf("%zu", &s2); fa_merge_states(&tomate,s1,s2); break; case 6: printf("State to remove ?(0,1,...)"); scanf("%zu", &s1); fa_remove_state(&tomate,s1); break; case 7: fa_remove_non_accessible_states(&tomate); break; case 8: fa_remove_non_co_accessible_states(&tomate); loop2 = 0; break; case 9: fa_create_product(&tomateprod,&tomate,&tomate2); fa_createdprod=true; loop2 = 0; break; case 10: loop2 = 0; break; default: printf("Restart menu and choose a number between 1 and 8\n"); loop2=0; break; } } } break; case 6: if(fa_created1==false) { printf("No Automate has been created, create it before deleting it\n"); } else { printf("Deleting ...\n"); fa_created1 = false; fa_destroy(&tomate); } break; case 7: printf("Exiting ...\n"); if(fa_created1==true) { fa_destroy(&tomate); } loop=0; break; default: printf("Restart menu and choose a number between 1 and 5\n"); loop=0; break; } } return 0; /*struct fa tomateleft; fa_create(&tomateleft,2,2); fa_set_state_initial(&tomateleft, 0); fa_set_state_final(&tomateleft, 1); fa_add_transition(&tomateleft, 0, 'a', 1); fa_add_transition(&tomateleft, 1, 'a', 1); fa_add_transition(&tomateleft, 1, 'b', 1); struct fa tomateright; fa_create(&tomateright,2,2); fa_set_state_initial(&tomateright, 0); fa_set_state_final(&tomateright, 1); fa_add_transition(&tomateright, 0, 'a', 0); fa_add_transition(&tomateright, 0, 'b', 1); fa_add_transition(&tomateright, 1, 'b', 1); fa_add_transition(&tomateright, 1, 'a', 0); struct fa tomatefinal; fa_create_product(&tomatefinal, &tomateleft, &tomateright); //fa_has_empty_intersection(&tomateleft, &tomateright); fa_pretty_print(&tomatefinal, stdout);*/ }
fa_pair_t fa_pair_dswap(fa_pair_t pair) { fa_pair_t pair2 = new_pair(pair->values[1], pair->values[0]); fa_destroy(pair); return pair2; }
fa_ptr_t fa_pair_dsecond(fa_pair_t pair) { fa_ptr_t value = pair->values[1]; fa_destroy(pair); return value; }
fa_ptr_t fa_pair_dfirst(fa_pair_t pair) { fa_ptr_t value = pair->values[0]; fa_destroy(pair); return value; }
inline static void delete_device(device_t device) { fa_destroy(device->name); fa_destroy(device->host_name); fa_delete(device); }