static Hotkey* hotkeySetFull( char* action, char* keydefinition, int append, int isUserDefined ) { Hotkey* hk = calloc(1,sizeof(Hotkey)); if ( hk==NULL ) return 0; strncpy( hk->action, action, HOTKEY_ACTION_MAX_SIZE ); HotkeyParse( hk, keydefinition ); // If we didn't get a hotkey (No Shortcut) // then we move along if( !hk->state && !hk->keysym ) { free(hk); return 0; } // If we already have a binding for that hotkey combination // for this window, forget the old one. One combo = One action. if( !append ) { Hotkey* oldkey = hotkeyFindByStateAndKeysym( hotkeyGetWindowTypeString(hk), hk->state, hk->keysym ); if( oldkey ) { dlist_erase( &hotkeys, (struct dlistnode *)oldkey ); free(oldkey); } } hk->isUserDefined = isUserDefined; dlist_pushfront( &hotkeys, (struct dlistnode *)hk ); return hk; }
void SFUndoRemoveAndFree( SplineFont *sf, struct sfundoes *undo ) { SFUndoFreeAssociated( undo ); dlist_erase( (struct dlistnode **)&sf->undoes, (struct dlistnode *)undo ); free(undo); }
int main(int argc, char* argv[]) { dstring* input; int input_done; int code; ENetEvent event; if (argc > 1) { fprintf(stderr, "svcc doesn't accept any command line arguments, use stdin instead.\n"); return 1; } /* initialize enet */ if (enet_initialize()) { fprintf(stderr, "Failed to initialize ENet\n"); return 1; } /* initialize client state */ init_client_state(); /* init SVC */ svc_init(send_callback); /* main loop */ input = dnew(); client.main_done = 0; signal(SIGINT, sigint); while(!client.main_done) { /* enet event handler */ if (client.state == SVCECLIENT_STATE_CONNECTED) { /* handle connection state */ while (1) { mutex_lock(&client.network_lock); code = enet_host_service(client.host, &event, 0); mutex_unlock(&client.network_lock); if (code <= 0) break; /* handle event */ switch(event.type) { case ENET_EVENT_TYPE_DISCONNECT: /* we got disconnected */ mutex_lock(&client.network_lock); client.state = SVCECLIENT_STATE_DISCONNECTED; free_server_info(); mutex_unlock(&client.network_lock); msg_state(); break; case ENET_EVENT_TYPE_RECEIVE: /* some data just arrived */ if (event.channelID == 0) { handle_server_msg(event.packet); } else if (event.channelID == 1) { handle_server_audio(event.packet); } else { fprintf(stderr, "Received message from server on invalid channel %i.\n", event.channelID); } mutex_lock(&client.network_lock); enet_packet_destroy(event.packet); mutex_unlock(&client.network_lock); break; case ENET_EVENT_TYPE_CONNECT: /* no one will connect, ignore the bastard */ default: break; } } } else if (client.state == SVCECLIENT_STATE_CONNECTING) { /* handle connecting state */ mutex_lock(&client.network_lock); code = enet_host_service(client.host, &event, 0); mutex_unlock(&client.network_lock); if (code > 0) { if (event.type == ENET_EVENT_TYPE_CONNECT) { client.state = SVCECLIENT_STATE_CONNECTED; client.server_info = dsdict_new(); msg_state(); } else { mutex_lock(&client.network_lock); client.state = SVCECLIENT_STATE_DISCONNECTED; enet_peer_disconnect(client.client, 0); client.client = NULL; enet_host_destroy(client.host); client.host = NULL; msg_state(); mutex_unlock(&client.network_lock); } } } else { /* sleep for 8ms */ usleep(8000); } /* play with the input queue */ if (!client.main_done) { input_done = 0; while (!input_done) { /* get next input command */ mutex_lock(&client.input_lock); if (client.input_queue->size) { dcpy(input, client.input_queue->front->string); dlist_erase(client.input_queue, client.input_queue->front); } else { input_done = 1; } mutex_unlock(&client.input_lock); /* quit input loop if queue is empty */ if (input_done) { break; } /* handle commands */ input_done = client.main_done = handle_input_command(input); } } /* check if input died for some reasons */ mutex_lock(&client.input_lock); if (client.input_error) { /* if so, leave main loop */ client.main_done = 1; } mutex_unlock(&client.input_lock); fflush(stdout); fflush(stderr); /* sleep for 8ms */ usleep(8000); } fprintf(stdout, ":STATE exiting\n"); dfree(input); svc_close(); quit_client_state(); enet_deinitialize(); return 0; }
struct dlistnode* dlist_popback( struct dlistnode** list ) { struct dlistnode* node = dlist_last(*list); if( node ) dlist_erase( list, node ); return node; }