void output_with_escape(const char *str) { unsigned i; a_putchar('"'); if (str != NULL) { if (strchr(str, '"') || strchr(str, '\\')) { for (i = 0; i < strlen(str); i ++) { if (str[i] == '"') a_printf("\\\""); else if (str[i] == '\\') a_printf("\\\\"); else a_putchar(str[i]); } } else { a_printf("%s", str); } } a_putchar('"'); }
static int cmd_getenc(const char *im) { const char *encoding = get_im_encoding(im); if (encoding) a_printf(" ( E \"%s\" ) ", encoding); else a_printf(" ( E \"\" ) "); return 1; }
int show_preedit_force(preedit *pe) { if (! show_preedit(pe)) a_printf("( p (t \"\") ) "); return 1; }
int show_preedit(preedit *pe) { preedit_buffer *p; p = pe->head; if (p == NULL || pe->length == 0) { a_printf(" ( e ) "); return 0; } a_printf("( p "); while (p) { a_printf(" ( "); if (p->attr & UPreeditAttr_Reverse) a_putchar('r'); if (p->attr & UPreeditAttr_UnderLine) a_putchar('u'); if (p->attr & UPreeditAttr_Cursor) a_putchar('c'); if (p->attr & UPreeditAttr_Separator) a_putchar('s'); a_putchar('t'); a_putchar(' '); output_with_escape(p->str); a_printf(" ) "); p = p->next; } a_printf(" ) "); return 1; }
int show_candidate(candidate_info *cand) { int i; int page; int index; if (cand->num == 0) { a_printf("( e )"); return 0; } index = cand->index; if (cand->disp_limit) page = index / cand->disp_limit; else page = 0; a_printf("( c "); a_printf(" ( %d . %d ) ", cand->index + 1, cand->num); for (i = cand->disp_limit * page; i < (cand->disp_limit ? cand->disp_limit * (page + 1) : cand->num); i ++) { if (i >= cand->num) break; if (i == index) a_printf("( t "); else a_printf("( nil "); output_with_escape(cand->cand_array[i].label); a_putchar(' '); output_with_escape(cand->cand_array[i].str); a_printf(" ) "); } a_printf(") "); return 1; }
int main(int argc, char *argv[]) { int opt; setlocale(LC_CTYPE, ""); while ((opt = getopt(argc, argv, "d")) != -1) { switch (opt) { case 'd': debug_level ++; break; } } if (debug_level == 0) fclose(stderr); if (uim_init() < 0) { debug_printf(DEBUG_ERROR, "uim_init failed\n"); return -1; } atexit(cleanup); a_printf("OK\n"); while (1) { int cid, serial; char *p1, *p2, *c; char buf[2048], keyname[32]; uim_key ukey; fflush(stdout); if (fgets(buf, sizeof (buf), stdin) == NULL) { if (feof(stdin)) debug_printf(DEBUG_NOTE, "unexpected EOF\n"); else debug_printf(DEBUG_ERROR, "failed to read command: %s\n", strerror (errno)); goto QUIT; } p1 = buf; serial = -1; /* command format serial CID COMMAND OPTION key format serial CID [keyvector] */ if ((p2 = strchr(p1, ' ')) == NULL) { debug_printf(DEBUG_WARNING, "input error: space after 1st string\n"); goto ERROR; } /* 1st string must be digit */ *p2 = '\0'; serial = strtol(p1, &c, 10); if (c != p2) { debug_printf(DEBUG_WARNING, "input error: invalid serial %d\n", serial); goto ERROR; } p1 = p2 + 1; if ((p2 = strchr(p1, ' ')) == NULL) { debug_printf(DEBUG_WARNING, "input error: no space after 2nd string\n"); goto ERROR; } /* 2nd string must be digit */ *p2 = '\0'; cid = strtol(p1, &c, 10); if (c != p2) { debug_printf(DEBUG_WARNING, "invalid cid %d\n", cid); goto ERROR; } /* 3rd string */ p1 = p2 + 1; if (*p1 == '[') { /* keyvector if 3rd string starts with [ */ if ((p2 = strchr(p1, ']')) == NULL) { /* no corresponding ] */ debug_printf(DEBUG_WARNING, "']' not found\n"); goto ERROR; } p2 ++; if (*p2 == ']') p2 ++; /* for [X-]] */ *p2 = '\0'; /* replace character after ] with \0 */ ukey.mod = 0; ukey.key = -1; keyname[0] = '\0'; if (analyze_keyvector(p1, &ukey, keyname, sizeof(keyname)) > 0) { a_printf("( %d %d ", serial, cid); if (process_keyvector(serial, cid, ukey, keyname) < 0) a_printf(" ( f ) "); else a_printf(" ( a ) "); a_printf(" )\n"); fflush(stdout); continue; } goto ERROR; } else if (*p1 >= 'A' && *p1 <= 'Z') { /* command */ if (strncmp(p1, "QUIT", 4) == 0) goto QUIT; a_printf("( %d %d ", serial, cid); if (process_command(serial, cid, p1) < 0) { debug_printf(DEBUG_WARNING, "command error\n"); a_printf(" ( f ) "); /* command error */ } else { a_printf(" ( a ) "); /* command ok */ } a_printf(" )\n"); fflush(stdout); continue; } debug_printf(DEBUG_WARNING, "invalid input\n"); ERROR: a_printf("( %d 0 ( x ) )\n", serial); fflush(stdout); } QUIT: uim_quit(); return 0; }
static int process_keyvector(int serial, int cid, uim_key ukey, const char *keyname) { int ret, ret2; if (! focused || current == NULL || (current != NULL && current->context_id != cid)) { if (set_current_uim_agent_context(get_uim_agent_context(cid)) < 0) { debug_printf(DEBUG_WARNING, "context %d not found\n", cid); return -1; } } focused = 1; if (ukey.key >= 0) { /* key input is received by requested context */ debug_printf(DEBUG_NOTE, "uim_press_key\n"); ret = uim_press_key(current->context, ukey.key, ukey.mod); debug_printf(DEBUG_NOTE, "uim_release_key\n"); ret2 = uim_release_key(current->context, ukey.key, ukey.mod); debug_printf(DEBUG_NOTE, "ret = %d, ret2 = %d\n", ret, ret2); show_commit_string_uim_agent_context(current); if (ret > 0) { /* uim did not process the key */ if (ukey.mod & UMod_Shift && ukey.key >= 0x41 && ukey.key <= 0x5a) ukey.mod &= ~UMod_Shift; if (ukey.mod != 0 || ukey.key > 255) { a_printf(" ( n [("); if (ukey.mod & UMod_Control) a_printf("control "); if (ukey.mod & UMod_Alt) a_printf("meta "); /* if (ukey->mod & UMod_Shift) a_printf("shift "); */ if (ukey.mod & UMod_Hyper) a_printf("hyper "); if (ukey.mod & UMod_Super) a_printf("super "); if (ukey.key > 255) a_printf("%s", keyname); else a_printf("%d", ukey.key); a_printf(")] ) "); } else { a_printf(" ( n [%d] ) ", ukey.key); } } show_preedit_uim_agent_context(current); show_candidate_uim_agent_context(current); } else { /* ukey.key < 0 */ show_commit_string_uim_agent_context(current); show_preedit_uim_agent_context(current); show_candidate_uim_agent_context(current); a_printf(" ( n ) "); /* dummy */ } /*show_prop_uim_agent_context(current);*/ check_prop_list_update(current); check_default_engine(); return 1; }
extern "C" int Alynx_Init(char* rom, char* bios) { StartTicks(); mpLynx = new CSystem(rom, bios); if( !Video_Setup(LynxScale) ) return 0; if(gAudioEnabled) { if(Audio_Init()) { gAudioEnabled = TRUE; } } Video_Init(); start_time = GetTicks(); KeyMask = mpLynx->GetButtonData(); a_printf("Starting Lynx Emulation...\n"); emulation=0; pause=0; while(!emulation) { mpLynx->SetButtonData(KeyMask); // Update TimerCount gTimerCount++; while( Alynx_Update() ) { if(!gSystemHalt) { for(ULONG loop=1024;loop;loop--) mpLynx->Update(); } else gTimerCount++; } if(gAudioEnabled) Audio_CallBack(); this_time = GetTicks(); fps_counter = (((float)gTimerCount/(this_time-start_time))*1000.0); if( (Throttle) && (fps_counter > 59.99) ) Delay( (Uint32)fps_counter ); native_fps = static_cast<int>(fps_counter); while(pause==1) { Delay(20); } } free(mpLynxBuffer); free(HandyBuffer); free(mainSurface); start_render=0; delete mpLynx; a_printf("Stoping...\n"); return 0; }
int main(int argc, char *argv[]) { int opt; while ((opt = getopt(argc, argv, "d")) != -1) { switch (opt) { case 'd': debug_level ++; break; } } if (debug_level == 0) fclose(stderr); if (uim_init() < 0) { debug_printf(DEBUG_ERROR, "uim_init failed\n"); return -1; } atexit(cleanup); a_printf("OK\n"); cmdbuf_len = DEFAULT_MESSAGE_SIZE; cmdbuf = uim_malloc(cmdbuf_len); cmdbuf[0] = '\0'; while (1) { char *msg; fd_set rfds; check_helper_connection(); wait_data_arrival(&rfds); debug_printf(DEBUG_NOTE, "data arrive\n"); if (FD_ISSET(STDIN_FILENO, &rfds)) { if (!read_command()) goto QUIT; } if (FD_ISSET(helper_fd, &rfds)) { /* read message from helper */ uim_helper_read_proc(helper_fd); } while (command_exists_in_cmdbuf()) process_command(); while ((msg = uim_helper_get_message())) { process_message(msg); } fflush(NULL); } QUIT: uim_quit(); return 0; }
int CErrorHandler::Warning(const char *message) { a_printf(message); exit(-1); }
int CErrorHandler::Fatal(const char *message) { a_printf(message); exit(-1); }
int show_prop(property *prop) { char *buf; char *head, *tail; char *p[6] = {0}; char *indication_id = NULL, *iconic_label =NULL, *label_string = NULL; int check_leaf = 0; /* output new prop_list for Emacs */ if (prop->list == NULL) { debug_printf(DEBUG_ERROR, "no prop_list\n"); a_printf(" ( e ) "); return 0; } a_printf(" ( l "); head = buf = uim_strdup(prop->list); #define PART_BRANCH "branch" #define PART_LEAF "leaf" #define ACTION_ID_IMSW "action_imsw_" while (head && *head) { /* * head: beginning of each line * tail: end of each line * p[n]: token */ tail = strchr(head, '\n'); if (tail) *tail = '\0'; else break; /* head always not equal NULL */ if (strlen(head) >= strlen(PART_BRANCH) && strncmp(head, PART_BRANCH, strlen(PART_BRANCH)) == 0) { if ((p[0] = strchr(head, '\t')) && (p[1] = strchr(p[0] + 1, '\t')) && (p[2] = strchr(p[1] + 1, '\t'))) { *p[0] = *p[1] = *p[2] = '\0'; indication_id = p[0] + 1; iconic_label = p[1] + 1; label_string = p[2] + 1; check_leaf = 1; /* check next leaf */ /*a_printf(" ( \"%s\" \"%s\" \"%s\" ) ", p[0] + 1, p[1] + 1, p[2] + 1);*/ } } else if (strlen(head) >= strlen(PART_LEAF) && strncmp(head, PART_LEAF, strlen(PART_LEAF)) == 0) { if (check_leaf && indication_id && iconic_label && label_string) { check_leaf = 0; /* im_switcher detection */ if ((p[0] = strchr(head, '\t')) && (p[1] = strchr(p[0] + 1, '\t')) && (p[2] = strchr(p[1] + 1, '\t')) && (p[3] = strchr(p[2] + 1, '\t')) && (p[4] = strchr(p[3] + 1, '\t')) && (p[5] = strchr(p[4] + 1, '\t'))) *p[0] = *p[1] = *p[2] = *p[3] = *p[4] = *p[5] = '\0'; if (strlen(p[4] + 1) >= strlen(ACTION_ID_IMSW) && strncmp(p[4] + 1, ACTION_ID_IMSW, strlen(ACTION_ID_IMSW)) == 0) a_printf(" ( \"im-name\" \"%s\" \"%s\" \"%s\" ) ", indication_id, iconic_label, label_string); else a_printf(" ( \"im-mode\" \"%s\" \"%s\" \"%s\" ) ", indication_id, iconic_label, label_string); } } head = tail + 1; } free(buf); a_printf(" ) "); return 1; #undef PART_BRANCH #undef PART_LEAF #undef ACTION_ID_IMSW }