int bfs(){ int i,x,y,S; int nx,ny,nS; queue<int>q; q.push(sx);q.push(sy);q.push(0); state[sx][sy][0]=0; map[sx][sy]='.'; while(!q.empty()) { x=q.front();q.pop(); y=q.front();q.pop(); S=q.front();q.pop(); for(i=0;i<4;i++) { nx=x+dir[i][0]; ny=y+dir[i][1]; if(0 == check(nx,ny)) continue; if('.' == map[nx][ny]) push(q,nx,ny,S,state[x][y][S]+1); else if('X' == map[nx][ny]) return state[x][y][S]+1; else if(1 == iskey(map[nx][ny])) push(q,nx,ny,cal(nx,ny,S),state[x][y][S]+1); else{ if(0 == ownkey(map[nx][ny],S)) continue; push(q,nx,ny,S,state[x][y][S]+1); } } } return -1; }
bool readrecord() { if(!skip('#')) return false; // Read data base name if(!readidentifier()) { error(ErrorExpectedIdentifier); return true; } skipws(); const bsreq* fields = 0; auto pd = bsdata::find(buffer); if(pd) fields = pd->fields; else warning(ErrorNotFoundBase1p, buffer); // Read key value parent_object = value_object; if(iskey(p)) readvalue(fields, true); else if(pd) value_object = pd->add(); else value_object = 0; readfields(value_object, fields); parent_type = fields; return true; }
void print(char buffer[100],int i) { int f=0; if(!isdigit(buffer[0])) { if(iskey(buffer)) { printf("%s \t Keyword\n",buffer); } else printf("%s \t Identifier\n",buffer); } else { for(int k=0;k<i;k++) { if(!isdigit(buffer[k])) { f=1; break; } } if(f==1) { printf("%s \t Invalid token\n",buffer); } else { printf("%s \t Number\n",buffer); } } }
/** * Print shell banner and prompt for shell entry * * @ret enter_shell User wants to enter shell */ int shell_banner ( void ) { int enter_shell = 0; int wait_count; int key; if ( BANNER_TIMEOUT <= 0 ) return enter_shell; printf ( "\nPress Ctrl-B for the gPXE command line..." ); /* Wait for key */ for ( wait_count = 0 ; wait_count < BANNER_TIMEOUT ; wait_count++ ) { if ( iskey() ) { key = getchar(); if ( key == CTRL_B ) enter_shell = 1; break; } mdelay(100); } /* Clear the "Press Ctrl-B" line */ printf ( "\r \r" ); return enter_shell; }
static void davicom_more() { printf("\n\n-- more --"); while (!iskey()) /* wait */; getchar(); printf("\n\n"); }
/** * Read character from console if available within timeout period * * @v timeout Timeout period, in ticks * @ret character Character read from console */ static int getchar_timeout ( unsigned long timeout ) { unsigned long expiry = ( currticks() + timeout ); while ( currticks() < expiry ) { step(); if ( iskey() ) return getchar(); } return -1; }
/** * Read character from console if available within timeout period * * @v timeout Timeout period, in ticks (0=indefinite) * @ret character Character read from console */ static int getchar_timeout ( unsigned long timeout ) { unsigned long start = currticks(); while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) { step(); if ( iskey() ) return getchar(); } return -1; }
char awaitkey(int timeout, int tell) { int i; char c = 0; i = timeout * POLL_FREQ; for (;;) { if (tell && (i % POLL_FREQ) == 0) { char numbuf[20]; int len, j; sprintf(numbuf, "%d ", i / POLL_FREQ); len = strlen(numbuf); for (j = 0; j < len; j++) numbuf[len + j] = '\b'; numbuf[len + j] = '\0'; printf(numbuf); } if (iskey(1)) { /* flush input buffer */ while (iskey(0)) c = getchar(); if (c == 0) c = -1; goto out; } if (i--) { delay(1000 / POLL_FREQ); } else { break; } } out: if (tell) printf("0 \n"); return (c); }
int matchcurves(const char* teststr,const char* decollator,char* result[3]) { const char* str = teststr; int i = 0,iok = 1; int j = 0,jok = 1; int k = 0; char* before_curves = calloc(10,sizeof(char*)); char* in_curves = calloc(100,sizeof(char*)); char* after_curves = calloc(100,sizeof(char*)); if(instr(teststr,'(')) { while(*str) { if(*str != decollator[0] && iok) { before_curves[i++] = *str++; } else if(*str != decollator[1] && jok) { iok = 0; in_curves[j++] = *str++; } else { if(jok) { jok = 0; in_curves[j] = *str++; } after_curves[k++] = *str++; } } result[0] = before_curves; result[1] = in_curves; result[2] = after_curves; if(!iskey(result[0]) && !strstr(result[2],";")) { printf("%s\n1:%s\n2:%s\n3:%s\n",teststr,result[0],result[1],result[2]); return 1; } } // printf("no key!\n"); return 0; }
h_conf* h_conf_parse(char* str, int len) { h_conf* conf = malloc(sizeof(h_conf)); int offset_key = -1; int offset_key_end = -1; int offset_val = -1; int i; for (i = 0; i < len; ++i) { char c = str[i]; if (offset_key == -1 && iskey(c)) { offset_key = i; } else if (c == ':' && offset_val == -1) { str[i] = '\0'; offset_key_end = i; } else if (offset_key_end != -1 && !isspace(c)) { offset_val = i; offset_key_end = -1; } else if (offset_val != -1 && c == '\n') { str[i] = '\0'; put_pair(conf, str + offset_key, str + offset_val); offset_key = -1; offset_val = -1; } } return conf; }
/** * Wait for link-up, with status indication * * @v netdev Network device * @v max_wait_ms Maximum time to wait, in ms */ int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) { int key; int rc; if ( netdev_link_ok ( netdev ) ) return 0; printf ( "Waiting for link-up on %s...", netdev->name ); while ( 1 ) { if ( netdev_link_ok ( netdev ) ) { rc = 0; break; } if ( max_wait_ms-- == 0 ) { rc = netdev->link_rc; break; } step(); if ( iskey() ) { key = getchar(); if ( key == CTRL_C ) { rc = -ECANCELED; break; } } mdelay ( 1 ); } if ( rc == 0 ) { printf ( " ok\n" ); } else { printf ( " failed: %s\n", strerror ( rc ) ); } return rc; }
int TWubiIM::processinput(TIMC * std_imc, XKeyEvent * e) { TWubiIMC * imc = (TWubiIMC *) std_imc; static int do_switch_enable = 0; if (iskey(e, &Switch_Enable_Key)){ if (e->type == KeyPress){ do_switch_enable = 1; return FORWARD_KEY; }else if (do_switch_enable){ do_switch_enable = 0; imc->switch_stat(IMC_STAT_DISABLE); return STAT_KEY; } }else do_switch_enable = 0; if (e->type == KeyRelease) return IGNORE_KEY; if (!imc->enabled()) return FORWARD_KEY; if (iskey(e, &Switch_BQ_Key)){ switchBQmode(imc); return STAT_KEY; } if (imc->is_preedit()){ if (iskey(e, &Listforward_Key)) return LISTFORWARD_KEY; if (iskey(e, &Listbackward_Key)) return LISTBACKWARD_KEY; int i; if ((i = iskey(e, Word_Delete_Keys, 9)) > 0){ if (i > imc->display_count()) return IGNORE_KEY; List_Item * li = imc->display_list_item(i-1); //is it a word? if (li->wr.w[1] != 0){ delete_word(li); imc->set_update_stamp(time(NULL)); imc->clear(); return HIDE_KEY; } return IGNORE_KEY; } } if (iskey(e, &New_Word_Key)){ imc->start_new_word(); return NORMAL_KEY; } if (e->state & (ControlMask | Mod1Mask)) // the key with shift only is needed return FORWARD_KEY; if (imc->is_mb_input()) if (convertB2Q(e, cb2q)) return COMMIT_KEY; else return FORWARD_KEY; return processnormal((TWubiIMC *)imc, e); }
/************************************************************************** POLLKBD - Check for Interrupt from keyboard **************************************************************************/ pollkbd() { #ifndef SECURE_BOOT if (iskey() && (getchar() == ESC)) longjmp(jmp_bootmenu,1); #endif }
struct token *gettok(char *s) { struct token *tok, *ret; int i, nestfunc, nestarr; bool quot, func, arr, dict; ret = calloc(1, sizeof(struct token)); for (quot = dict = arr = func = NO, i = nestfunc = nestarr = 0, tok = ret; *s != '\0'; s++) { if (!tok->tok) tok->tok = malloc(1), tok->type = T_VAR; else tok->tok = realloc(tok->tok, (size_t)i+2); if (*s == '(') { func = YES; tok->type = T_FUNC; nestfunc++; } else if (*s == ')') { if (--nestfunc == 0) func = NO, tok->tok[i++] = *s; } else if (*s == '"' && !func) { quot = (quot) ? NO : YES; tok->type = T_LIT; } else if ((*s == '[' || *s == ']') && !func) { tok->type = T_LIT; if (*s == ']') { if (--nestarr == 0) arr = NO, tok->tok[i++] = *s; } else if (*s == '[') { nestarr++; arr = YES; } } else if ((*s == '{' || *s == '}') && !func) { dict = (dict) ? NO : YES; tok->type = T_LIT; } else if (((isdigit(*s) || (*s == '-' && isdigit(*(s+1))))) && i < 1) { tok->type = T_LIT; tok->tok[i++] = *s++; if (!*s) break; } else if (*s == '#') return remwht(ret); if (*s == '.' && tok->type == T_LIT && !quot) { tok->tok[i++] = *s++; if (!*s) break; } if (!isalnum(*s) && !quot && !func && !arr && !dict) { tok->next = calloc(1, sizeof(struct token)); if (*s == '=' && tok->type != T_FUNC) { tok->next->type = T_ASS; tok->next->tok = "="; tok->tok[i] = 0; tok = tok->next; tok->next = calloc(1, sizeof(struct token)); } else tok->tok[i] = 0; i = 0; if (iskey(tok)) tok->type = T_KEY; else if (iswhte(tok)) tok->type = T_WHT; else if (isctrl(tok)) tok->type = T_CTL; tok = tok->next; } else { tok->tok[i++] = *s; } } if (iskey(ret)) ret->type = T_KEY; return remwht(ret); }