static void *_elim_request_authorise ( PurpleAccount *account , const char *remote_user , const char *id , const char *alias , const char *message , gboolean on_list , PARA_CB authorize_cb , PARA_CB deny_cb , void *user_data ) { CB_HANDLER *cbh = g_new0( CB_HANDLER, 1 ); AUI_RESP *resp = g_new0( AUI_RESP , 1 ); xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); fprintf( stderr, "(_elim_request_authorise)\n" ); AL_STR ( alist, "user" , remote_user ); AL_STR ( alist, "id" , id ); AL_STR ( alist, "alias" , alias ); AL_BOOL( alist, "on-list" , on_list ); AL_STR ( alist, "message" , message ); AL_PTR ( alist, "account-uid" , account ); AL_STR ( alist, "account-name", purple_account_get_username ( account ) ); AL_STR ( alist, "im-protocol" , purple_account_get_protocol_id( account ) ); resp->ok = authorize_cb; resp->nok = deny_cb; resp->id = ID; resp->data = user_data; cbh ->func = _elim_request_authorise_cb; cbh ->data = resp; store_cb_data( ID, cbh ); xmlnode *mcall = func_call( "elim-account-request-auth", ID, alist ); add_outbound_sexp( mcall ); return cbh; }
static void _elim_write_conv ( PurpleConversation *conv , const char *name , const char *alias , const char *message , PurpleMessageFlags flags , time_t mtime ) { char *msg = NULL; char *ID = new_elim_id(); xmlnode *args = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-conv-write-sys", ID, args ); g_free( ID ); fprintf( stderr, "(_elim_write_conv)\n" ); if( _elim_strippable( conv, flags ) ) msg = purple_markup_strip_html( message ); _elim_conv_args( args, conv ); AL_STR ( args, "who" , (name ? name : (alias ? alias : "")) ); AL_STR ( args, "alias", (alias ? alias : (name ? name : "")) ); AL_STR ( args, "text" , msg ? msg : message ); AL_ENUM( args, "flags", flags , ":message-flags" ); AL_INT ( args, "time" , mtime ); if( msg ) g_free( msg ); fprintf( stderr, "(elim-debug _elim_write_conv:DONE)\n" ); add_outbound_sexp( mcall ); }
int main(){ int x = func_call(); //float x = func_call(); printf("Success returning int \n"); //printf("Failure returning float \n"); return 0; }
static void _elim_connect_progress ( PurpleConnection *gc , const char *text , size_t step , size_t step_count ) { PurpleAccount *acct = purple_connection_get_account( gc ); fprintf( stderr, "(_elim_connect_progress)\n" ); if( acct ) { char *ID = new_elim_id(); xmlnode *alist = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-connection-progress", ID, alist ); const char *aname = purple_account_get_username ( acct ); const char *proto = purple_account_get_protocol_id( acct ); int state = purple_connection_get_state ( gc ); g_free( ID ); AL_PTR ( alist, "account-uid" , acct ); AL_STR ( alist, "account-name", aname ); AL_STR ( alist, "im-protocol" , proto ); AL_INT ( alist, "step" , step ); AL_INT ( alist, "step-count" , step_count ); AL_STR ( alist, "message" , text ); AL_ENUM( alist, "state" , state , ":connection-state" ); add_outbound_sexp( mcall ); } }
static void _elim_report_disconnect_reason( PurpleConnection *conn , PurpleConnectionError reason , const char *text ) { PurpleAccount *acct = purple_connection_get_account( conn ); if( acct ) { char *ID = new_elim_id(); xmlnode *alist = xnode_new( "alist" ); fprintf( stderr, "(_elim_report_disconnect_reason)\n" ); xmlnode *mcall = func_call( "elim-disconnect-reason", ID, alist ); const char *aname = purple_account_get_username ( acct ); const char *proto = purple_account_get_protocol_id( acct ); int state = purple_connection_get_state ( conn ); g_free( ID ); AL_PTR ( alist, "account-uid" , acct ); AL_STR ( alist, "account-name", aname ); AL_STR ( alist, "im-protocol" , proto ); AL_STR ( alist, "message" , text ); AL_ENUM( alist, "reason-code" , reason, ":connection-error" ); AL_ENUM( alist, "state" , state , ":connection-state" ); add_outbound_sexp( mcall ); } }
static void _elim_chat_add_users ( PurpleConversation *conv , GList *cbuddies , gboolean new_arrivals ) { char *ID = new_elim_id(); xmlnode *args = xnode_new( "alist" ); xmlnode *list = xnode_new( "list" ); xmlnode *mcall = func_call( "elim-chat-add-users", ID, args ); g_free( ID ); fprintf( stderr, "(_elim_chat_add_users)\n" ); _elim_conv_args( args, conv ); AL_BOOL( args, "new-arrivals" , new_arrivals ); AL_NODE( args, "participants" , list ); fprintf( stderr, "(_elim_chat_add_users)\n" ); for( ; cbuddies; cbuddies = cbuddies->next ) { xmlnode *cbuddy = xnode_new( "alist" ); PurpleConvChatBuddy *pccb = cbuddies->data; AL_STR ( cbuddy, "name" , pccb->name ? pccb->name : "" ); AL_STR ( cbuddy, "alias" , pccb->alias ? pccb->alias : "" ); AL_STR ( cbuddy, "alias-key", pccb->alias_key ? pccb->alias_key : "" ); AL_ENUM( cbuddy, "flags" , pccb->flags , ":conv-chat-buddy-flags" ); AL_BOOL( cbuddy, "on-blist" , pccb->buddy ); xnode_insert_child( list, cbuddy ); } add_outbound_sexp( mcall ); fprintf( stderr, "(_elim_chat_add_users:DONE)\n" ); }
static void _elim_network ( const char *call ) { char *ID = new_elim_id(); xmlnode *mcall = func_call( call , ID, NULL ); fprintf( stderr, "(_elim_network)\n" ); g_free( ID ); add_outbound_sexp( mcall ); }
static void method(struct context *context, struct byte_array *program, bool really) { struct variable *indexable=NULL, *index; if (context->runtime) { indexable = variable_pop(context); index = variable_pop(context); lookup(context, indexable, index, really); } func_call(context, VM_MET, program, indexable); }
static void _elim_destroy_conversation ( PurpleConversation *conv ) { char *ID = new_elim_id(); xmlnode *args = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-conv-destroy", ID, args ); g_free( ID ); fprintf( stderr, "(_elim_destroy_conversation)\n" ); _elim_conv_args( args, conv ); add_outbound_sexp( mcall ); }
static void _elim_roomlist_add ( PurpleRoomlist *list , PurpleRoomlistRoom *room ) { g_return_if_fail( list && room ); xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); __roomlist_insert_account( list->account, alist ); AL_PTR ( alist , "roomlist-id" , list ); AL_STR ( alist , "room-name" , room->name ); AL_ENUM( alist , "room-type" , room->type , ":roomlist-room-type" ); AL_PTR ( alist , "room-parent" , room->parent ); AL_BOOL( alist , "room-expanded-once", room->expanded_once ); xmlnode *fields = xnode_new_child( alist, "alist" ); xnode_set_attrib( fields, "name", "fields" ); GList *listf = g_list_first( list->fields ); GList *roomf = g_list_first( room->fields ); #define NNEXTT( a, b ) a = g_list_next( a ), b = g_list_next( b ) #define PTR_TO_BOOL(_p) (_p != NULL) for( ; listf && roomf ; NNEXTT( listf, roomf ) ) { PurpleRoomlistField *f = (PurpleRoomlistField*) listf->data; switch( f->type ) { case PURPLE_ROOMLIST_FIELD_BOOL: AL_BOOL( fields, f->name, PTR_TO_BOOL( roomf->data ) ); break; case PURPLE_ROOMLIST_FIELD_INT: AL_INT ( fields, f->name, roomf->data ); break; case PURPLE_ROOMLIST_FIELD_STRING: AL_STR ( fields, f->name, roomf->data ); break; default: fprintf( stderr, "unsupported room list field type.\n" ); break; } } xmlnode *mcall = func_call( "elim-roomlist-add", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_roomlist_destroy ( PurpleRoomlist *list ) { g_return_if_fail( list ); xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); __roomlist_insert_account( list->account, alist ); AL_PTR ( alist , "roomlist-id", list ); xmlnode *mcall = func_call( "elim-roomlist-destroy", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_roomlist_in_progress ( PurpleRoomlist *list , gboolean flag ) { g_return_if_fail( list ); xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); __roomlist_insert_account( list->account, alist ); AL_PTR ( alist , "roomlist-id", list ); AL_BOOL( alist , "in-progress", flag ); xmlnode *mcall = func_call( "elim-roomlist-in-progress", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_roomlist_create ( PurpleRoomlist *list ) { g_return_if_fail( list ); xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); __roomlist_insert_account( list->account, alist ); AL_PTR ( alist, "roomlist-id", list ); xmlnode *flist = xnode_new_child( alist, "alist" ); xnode_set_attrib( flist, "name", "fields" ); g_list_foreach( list->fields, __roomlist_add_list_field, flist ); xmlnode *mcall = func_call( "elim-roomlist-create", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_chat_rename_user ( PurpleConversation *conv , const char *old_name , const char *new_name , const char *new_alias ) { char *ID = new_elim_id(); xmlnode *args = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-chat-rename-user", ID, args ); g_free( ID ); fprintf( stderr, "(_elim_chat_rename_user)\n" ); _elim_conv_args( args, conv ); AL_STR( args, "old-name" , old_name ); AL_STR( args, "new-name" , new_name ); AL_STR( args, "new-alias", new_alias ); add_outbound_sexp( mcall ); }
static void _elim_notify_added ( PurpleAccount *account , const char *remote_user, const char *id , const char *alias , const char *message ) { xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); fprintf( stderr, "(_elim_notify_added)\n" ); AL_STR( alist, "user" , remote_user ); AL_STR( alist, "alias" , alias ); AL_STR( alist, "message" , message ); AL_PTR( alist, "account-uid" , account ); AL_STR( alist, "account-name" , purple_account_get_username ( account ) ); AL_STR( alist, "im-protocol" , purple_account_get_protocol_id( account ) ); xmlnode *mcall = func_call( "elim-account-notify-added", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_notice ( PurpleConnection *conn, const char *msg ) { PurpleAccount *acct = purple_connection_get_account( conn ); if( acct ) { char *ID = new_elim_id(); xmlnode *alist = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-connection-state", ID, alist ); const char *aname = purple_account_get_username ( acct ); const char *proto = purple_account_get_protocol_id( acct ); int state = purple_connection_get_state ( conn ); g_free( ID ); AL_PTR ( alist, "account-uid" , acct ); AL_STR ( alist, "account-name", aname ); AL_STR ( alist, "im-protocol" , proto ); AL_STR ( alist, "message" , msg ); AL_ENUM( alist, "state" , state , ":connection-state" ); add_outbound_sexp( mcall ); } }
static void _elim_status_changed ( PurpleAccount *account , PurpleStatus *status ) { xmlnode *alist = xnode_new( "alist" ); char *ID = new_elim_id(); fprintf( stderr, "(_elim_status_changed)\n" ); PurpleStatusType *type = purple_status_get_type( status ); PurpleStatusPrimitive statp = purple_status_type_get_primitive( type ); AL_PTR ( alist, "account-uid" , account ); AL_STR ( alist, "account-name", purple_account_get_username ( account ) ); AL_STR ( alist, "im-protocol" , purple_account_get_protocol_id( account ) ); AL_STR ( alist, "status-name" , purple_status_get_name ( status ) ); AL_ENUM( alist, "status-type" , statp, ":status-primitive" ); AL_BOOL( alist, "connected" , purple_account_is_connected ( account ) ); xmlnode *mcall = func_call( "elim-account-status-changed", ID, alist ); g_free( ID ); add_outbound_sexp( mcall ); }
static void _elim_chat_remove_users ( PurpleConversation *conv , GList *users ) { char *ID = new_elim_id(); xmlnode *args = xnode_new( "alist" ); xmlnode *mcall = func_call( "elim-chat-remove-users", ID, args ); xmlnode *list = xnode_new( "list" ); g_free( ID ); fprintf( stderr, "(_elim_chat_remove_users)\n" ); _elim_conv_args( args, conv ); for( ; users; users = users->next ) { xmlnode *user = xnode_new_child( list, "string" ); xnode_insert_data( user, users->data ? users->data : "", -1 ); } AL_NODE( args, "participants", list ); fprintf( stderr, "(_elim_chat_remove_users:DONE)\n" ); add_outbound_sexp( mcall ); }
int main(int argc, char** argv){ // Get time of mininmal function call in C clock_gettime(CLOCK_ID,&func_start); func_call(); clock_gettime(CLOCK_ID,&func_end); func_time = get_time(func_start, func_end); // Get time of minimal system call in C clock_gettime(CLOCK_ID,&sys_start); sys_call(); clock_gettime(CLOCK_ID,&sys_end); sys_time = get_time(sys_start,sys_end); // Calculate the time difference between the two calls time_diff = sys_time - func_time; // Print the time difference printf("The time it takes to do a minimum function call in C: %llu(ns)\n", (long long unsigned int) func_time); printf("The time it takes to do a minimum system call in C: %llu(ns)\n", (long long unsigned int) sys_time); printf("The time difference between a system call and a function call in C: %llu(ns)\n", (long long unsigned int) time_diff); exit(EXIT_SUCCESS); }
int main () { int x = 17; int *xP, **xPP; char buf[200]; char *s; int *ai; float *af; func_intptr(&x); func_intptr_ret(&x); func_string("zero\0xxxxxxxxxxxxxx"); func_strlen(buf); extern int func_arg0(char *); func_arg0(buf); printf("%s\n", buf); func_strfixed(buf); printf("%s\n", buf); x = 80; xP = &x; xPP = &xP; func_ppp(&xPP); s = (char*) malloc(100); strcpy(s, "Dude"); func_stringp(&s); func_enum(BLUE); func_short(-8, -9); func_ushort(33, 34); float f = func_float(3.4, -3.4); double d = func_double(3.4, -3.4); func_typedef(BLUE); ai = (int*) calloc(sizeof(int), 8); for (x = 0; x < 8; x++) ai[x] = 10 + x; func_arrayi(ai, 8); func_arrayi(ai, 2); af = (float*) calloc(sizeof(float), 8); for (x = 0; x < 8; x++) af[x] = 10.1 + x; func_arrayf(af, 8); func_arrayf(af, 2); { struct { int simple; int alen; int slen; struct { int a; int b; }* array; struct { int a; int b; } seq[3]; char* str; } x; x.simple = 89; x.alen = 2; x.array = malloc(800); x.array[0].a = 1; x.array[0].b = 10; x.array[1].a = 3; x.array[1].b = 30; x.seq[0].a = 4; x.seq[0].b = 40; x.seq[1].a = 5; x.seq[1].b = 50; x.seq[2].a = 6; x.seq[2].b = 60; x.slen = 3; x.str = "123junk"; func_struct(&x); } { char x[10] = {}; char y[10] = {}; func_call(x, y, call_func_work); } struct S2 { float f; char a; char b; }; struct S3 { char a[6]; float f; }; struct S2 func_struct_2(int, struct S3 s3, double d); func_struct_2(17, (struct S3){ "ABCDE", 0.25 }, 0.5);
gint snoop() { switch(in_state) { case STATE_CMD: if((cmd_in_cnt < 3 && cmd_in_cnt > 0 && cmd_in_need) || cmd_in_cnt == 0) { /* modifiers set here */ cmd_in_buf[cmd_in_cnt].keyval = key_event->keyval; cmd_in_buf[cmd_in_cnt].keyval_type = KT_SINGLE; int found; found = shortcut_find(cmd_in_buf); cmd_in_cnt++; if(found >= 0) { /* this is not parameter */ if(!cmd_current) { /* function does not have any parameters */ if(commands[found]->param_type==PT_NONE) { func_call(commands[found],cmd_repeat_cnt,NULL); } /* this cmd is parameter for function */ else { in_state = commands[found]->param_type; cmd_current = commands[found]; } } /* this is a parameter */ else { cmd_param_data = malloc(sizeof(emacs_keybinding)); *cmd_param_data = commands[found]; func_call(commands[found],cmd_repeat_cnt,cmd_param_data); } input_reset(); return TRUE; } else if(found == -2) //maybe found { cmd_in_need = TRUE; return TRUE; } else if(found == -1) //not found { input_reset(); return FALSE; } }//if(cmd_in_cmd < 3 && ... break; case STATE_KEY: emacs_hotkey cur_key; cur_key.keyval = event->keyval; //k.alt = ... /* modifiers set here */ cmd_param_data = malloc(sizeof(emacs_hotkey)); *cmd_param_data = cur_key; func_call(cmd_current,cmd_repeat_cnt,cmd_param_data); input_reset(); break; case STATE_INT: if(!cmd_param_data) { cmd_param_data = malloc(sizeof(int)); *cmd_param_data = 0; } param_in_cnt++; gint data = *cmd_param_data; data = keyval2int(event->keyval)*pow(param_in_cnt,10) + data; *cmd_param_data = data; break; case STATE_STR: if(!cmd_param_data) { cmd_param_data = malloc(sizeof(gchar)*PARAM_STR_MAX); } param_in_cnt++; gchar data = cmd_param_data[param_in_cnt]; data = keyval2char(event->keyval); cmd_param_data[param_in_cnt]; break; } }
bool run(struct context *context, struct byte_array *program, struct map *env, bool in_context) { null_check(context); null_check(program); program = byte_array_copy(program); program->current = program->data; struct program_state *state = NULL; enum Opcode inst = VM_NIL; if (context->runtime) { if (in_context) { if (!state) state = (struct program_state*)stack_peek(context->program_stack, 0); env = state->named_variables; // use the caller's variable set in the new state } else state = program_state_new(context, env); } while (program->current < program->data + program->length) { inst = (enum Opcode)*program->current; bool really = inst & VM_RLY; inst &= ~VM_RLY; #ifdef DEBUG display_program_counter(context, program); #endif program->current++; // increment past the instruction int32_t pc_offset = 0; switch (inst) { case VM_COM: case VM_ITR: if (iterate(context, inst, state, program)) goto done; break; case VM_RET: if (ret(context, program)) goto done; break; case VM_TRO: if (tro(context)) goto done; break; case VM_TRY: if (vm_trycatch(context, program)) goto done; break; case VM_EQU: case VM_MUL: case VM_DIV: case VM_ADD: case VM_SUB: case VM_NEQ: case VM_GTN: case VM_LTN: case VM_GRQ: case VM_LEQ: case VM_BND: case VM_BOR: case VM_MOD: case VM_XOR: case VM_INV: case VM_RSF: case VM_LSF: binary_op(context, inst); break; case VM_ORR: case VM_AND: pc_offset = boolean_op(context, program, inst); break; case VM_NEG: case VM_NOT: unary_op(context, inst); break; case VM_SRC: src(context, inst, program); break; case VM_DST: dst(context, really); break; case VM_STX: case VM_SET: set(context, inst, state, program); break; case VM_JMP: pc_offset = jump(context, program); break; case VM_IFF: pc_offset = iff(context, program); break; case VM_CAL: func_call(context, inst, program, NULL); break; case VM_LST: push_list(context, program); break; case VM_MAP: push_map(context, program); break; case VM_NIL: push_nil(context); break; case VM_INT: push_int(context, program); break; case VM_FLT: push_float(context, program); break; case VM_BUL: push_bool(context, program); break; case VM_STR: push_str(context, program); break; case VM_VAR: push_var(context, program); break; case VM_FNC: push_fnc(context, program); break; case VM_GET: list_get(context, really); break; case VM_PTX: case VM_PUT: list_put(context, inst, really); break; case VM_MET: method(context, program, really); break; default: vm_exit_message(context, ERROR_OPCODE); return false; } program->current += pc_offset; } if (!context->runtime) return false; done: if (!in_context) stack_pop(context->program_stack); return inst == VM_RET; }