void philosopher_fn(void* no){ int i = (int)no; int right,count; right = (i+1)%NUM_CHOPSTICKS; for(count=0;count<NUM_ROUNDS;count++){ printf("Philosopher %d going to think [%d]\n",i,count); think(); sem_wait(&four_chairs); printf("Philosopher %d occupied a chair [%d]\n",i,count); pthread_mutex_lock(&mutex_arr[i]); pthread_mutex_lock(&mutex_arr[right]); printf("Philosopher %d locked chopsticks [%d]\n",i,count); printf("Philosopher %d going to eat [%d]\n",i,count); eat(); printf("Philosopher %d going to unlock chopsticks [%d]\n",i,count); pthread_mutex_unlock(&mutex_arr[right]); pthread_mutex_unlock(&mutex_arr[i]); sem_post(&four_chairs); printf("Philosopher %d gave up a chair [%d]\n",i,count); } }
static Obj *readName( istream& is ) { string s = readID( is ); if( s == "true" ) { return new BooleanObj( true ); } else if( s == "false" ) { return new BooleanObj( false ); } else { if( !eat( is ) ) { return new IdObj( s ); } int ch = is.peek(); if( strchr( "}),;", ch ) != NULL ) { return new IdObj( s ); } else { return new NamedObj( s, readObject( is ) ); } } }
Type* compileType(void) { Type* type; Type* elementType; int arraySize; Object* obj; switch (lookAhead->tokenType) { case KW_INTEGER: eat(KW_INTEGER); type = makeIntType(); break; case KW_CHAR: eat(KW_CHAR); type = makeCharType(); break; case KW_ARRAY: eat(KW_ARRAY); eat(SB_LSEL); eat(TK_NUMBER); arraySize = currentToken->value; eat(SB_RSEL); eat(KW_OF); elementType = compileType(); type = makeArrayType(arraySize, elementType); break; case TK_IDENT: eat(TK_IDENT); obj = checkDeclaredType(currentToken->string); type = duplicateType(obj->typeAttrs->actualType); break; default: error(ERR_INVALID_TYPE, lookAhead->lineNo, lookAhead->colNo); break; } return type; }
IMPLEMENT int Pic::irq_pending() { unsigned int i; for (i = 0; i < highest_irq; i++) pfd[i].revents = 0; if (poll(pfd, highest_irq, 0) > 0) for (i = 0; i < highest_irq; i++) if (pfd[i].revents & POLLIN) { if (!Emulation::idt_vector_present(0x20 + i)) eat(i); else return i; } return -1; }
int main() { hOut = GetStdHandle(STD_OUTPUT_HANDLE); //标准输出句柄获得 SetConsoleCursorInfo(hOut, &cur_info); //隐藏光标 while(1) { system("cls");/*清屏*/ Snake* head = (Snake*)malloc(sizeof(Snake)); initialization(head); background(); while(1) { Sleep(500); refresh(); getkeys(); run(head); eat(head); if(door(head)) break; food(head); } release_list(head); SetConsoleCursorPosition(hOut, pos); SetConsoleTextAttribute(hOut, 0x07); system("cls");/*清屏*/ printf("得分:%d\n空格重新开始\n",scoring); while(1) { int w = getch(); if(w == ' ') { break; } else { continue; } } } return 0; }
void FACTOR(void){ /*factor ::= <CONST_INT> | <CONST_FLOAT> | <CONST_BOOLEAN> | id restof_functioncall_or_epsilon | "(" assignment ")"*/ switch(l){ case CONST_INT: eat(CONST_INT); return; case CONST_FLOAT: eat(CONST_FLOAT); return; case CONST_BOOLEAN: eat(CONST_BOOLEAN); return; case ID: eat(ID); RESTOF_FUNCTIONCALL_OR_EPSILON(); return; case '(': eat('('); ASSIGNMENT(); eat(')'); return; default: StdError(__func__); } }
Type* compileType(void) { Type* type; Type* elementType; int arraySize; Object* obj; switch (lookAhead->tokenType) { case KW_INTEGER: eat(KW_INTEGER); type = makeIntType(); break; case KW_CHAR: eat(KW_CHAR); type = makeCharType(); break; case KW_ARRAY: eat(KW_ARRAY); eat(SB_LSEL); eat(TK_NUMBER); arraySize = currentToken->value; eat(SB_RSEL); eat(KW_OF); elementType = compileType(); type = makeArrayType(arraySize, elementType); break; case TK_IDENT: eat(TK_IDENT); // TODO: check if the type idntifier is declared and get its actual type break; default: error(ERR_INVALID_TYPE, lookAhead->lineNo, lookAhead->colNo); break; } return type; }
void Snake::init() { con->clear(); for (int i = 0; i < WIDTH; ++i) for (int j = 0; j < HEIGHT; ++j) { B[i][j] = 0; } for (int i = intLeft; i <= intRight; ++i) { con->putChar('*',i,intTop - 1); con->putChar('*',i,intBottom + 1); B[i][intTop - 1] = B[i][intBottom + 1] = -1; } for (int i = intTop; i <= intBottom; ++i) { con->putChar('*',intLeft - 1,i); con->putChar('*',intRight + 1,i); B[intLeft - 1][i] = B[intRight + 1][i] = -1; } while (!snakeBody.empty()) snakeBody.pop(); curDirect = D_EAST; int midX = (intRight - intLeft) / 2 + intLeft; int midY = (intBottom - intTop) / 2 + intTop; snakeHead.X = midX; snakeHead.Y = midY; B[midX][midY] = -1; con->putChar(SNAKE_CHAR, snakeHead.X, snakeHead.Y); snakeBody.push(snakeHead); eat(D_EAST); }
void compileExpression(void) { assert("Parsing an expression"); // TODO switch (lookAhead->tokenType) { case SB_PLUS: case SB_MINUS: eat(lookAhead->tokenType); compileExpression2(); break; case TK_IDENT: case TK_CHAR: case TK_NUMBER: case SB_LPAR: case TK_STRING: compileExpression2(); break; default: error(ERR_INVALIDEXPRESSION, lookAhead->lineNo, lookAhead->colNo); break; } assert("Expression parsed"); }
void compileType(void) { switch(lookAhead->tokenType){ case KW_INTEGER: eat(KW_INTEGER); break; case KW_CHAR: eat(KW_CHAR); break; case KW_ARRAY: eat(KW_ARRAY); eat(SB_LSEL); eat(TK_NUMBER); eat(SB_RSEL); eat(KW_OF); compileType(); break; case TK_IDENT://type ident eat(TK_IDENT); break; default : error(ERR_INVALIDTYPE, lookAhead->lineNo, lookAhead->colNo); break; } }
/* Implementation of cimport */ static struct PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; static void __pyx_init_filenames(void); /*proto*/ PyMODINIT_FUNC initcimport(void); /*proto*/ PyMODINIT_FUNC initcimport(void) { PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; __pyx_init_filenames(); __pyx_m = Py_InitModule4("cimport", __pyx_methods, 0, 0, PYTHON_API_VERSION); if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}; Py_INCREF(__pyx_m); __pyx_b = PyImport_AddModule("__builtin__"); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}; if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}; if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}; __pyx_v_7cimport_fried = ((struct __pyx_obj_3pkg_4eggs_Eggs *)Py_None); Py_INCREF(Py_None); __pyx_ptype_3pkg_4eggs_Eggs = __Pyx_ImportType("pkg.eggs", "Eggs", sizeof(struct __pyx_obj_3pkg_4eggs_Eggs)); if (!__pyx_ptype_3pkg_4eggs_Eggs) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 1; goto __pyx_L1;} /* "/Local/Projects/D/Pyrex/Source/Tests/8/cimport.pyx":7 */ eat(__pyx_v_7cimport_yummy); /* "/Local/Projects/D/Pyrex/Source/Tests/8/cimport.pyx":8 */ tons = 3.14; /* "/Local/Projects/D/Pyrex/Source/Tests/8/cimport.pyx":9 */ __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_pkg); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;} __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_eggs); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_ova, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; /* "/Local/Projects/D/Pyrex/Source/Tests/8/cimport.pyx":10 */ __pyx_1 = PyObject_CallObject(((PyObject *)__pyx_ptype_3pkg_4eggs_Eggs), 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;} Py_DECREF(((PyObject *)__pyx_v_7cimport_fried)); __pyx_v_7cimport_fried = ((struct __pyx_obj_3pkg_4eggs_Eggs *)__pyx_1); __pyx_1 = 0; return; __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); __Pyx_AddTraceback("cimport"); }
void game(HGame *game)//전체게임함수 { int current_player = 0; while(true) { //인터페이스 : e(exit), b(잔고), h(키설명),save(저장).load //eat함수 eat(); //상태갱신 //점수산출score함수 score(); //났나? - 났을 때 고 혹은 스톱 //스톱시 stop함수 //턴 넘기기 ++current_player; } }
void ImageEaterThread::run() { QImage* image; m_alive = true; while(m_alive) { m_mutexSleep.lock(); m_condition.wait(&m_mutexSleep, m_rate); m_mutexSleep.unlock(); image = eat(); if (image != NULL && m_alive) { // TODO : when main window dies, m_renderTarget is deallocated // shared mutex ? (testing only for m_alive is not guaranteed) m_renderTarget->setPixmap(QPixmap::fromImage(*image)); //allows for dynamic buffersize change and more robust when heavy lag if(m_numberImage < m_bufferSize) { m_condition.wakeAll(); } delete image; emit imageEaten(); } } }
QString GaduEmoticonParser::parseQuoted() { QChar c = peek(); if (c == '"') { eat(); int quoteIndex = EmoticonLine.indexOf('"', Index); if (quoteIndex < 0) return getToIndex(EmoticonLine.length()); else return getToIndex(quoteIndex); } int bracketIndex = EmoticonLine.indexOf(')', Index); int comaIndex = EmoticonLine.indexOf(',', Index); int endIndex = bracketIndex < 0 ? comaIndex : comaIndex < 0 ? bracketIndex : qMin(bracketIndex, comaIndex); return getToIndex(endIndex); }
bool _eat_item_on_floor() { // Don't steal stuff by eating them auto tile = get_tile_at(current_dungeon, player.pos.x, player.pos.y); if (tile->properties & TILE_PROP_SHOP) { return false; } std::vector<item_t*> food_on_ground; for (item_t* item : current_dungeon->items) { if (item->pos.x == player.pos.x && item->pos.y == player.pos.y && item->type == ITEM_TYPE_FOOD) { food_on_ground.push_back(item); } } for (item_t* food : food_on_ground) { if (yesno(format("There is a %s here. Eat it?", food->get_item_name().c_str()), true)) { eat(&player, food); food->stacksize--; if (food->stacksize == 0) { remove_item(current_dungeon, food, true); } return true; } } return false; }
void do_dining(int dining_time, int eat_min, int eat_max, int think_min, int think_max) { int think_time, eat_time, think_range, eat_range; if(signal(SIGUSR1,&start_dinner)==SIG_ERR) { printf("Cannot set signal handler! Aborting!\n"); exit(1); } /** start random number generator */ srand(time(0x0)); think_range = think_max-think_min; think_time = (rand()%think_range)+think_min; eat_range = eat_max-eat_min; eat_time = (rand()%eat_range)+eat_min; /* wait for start signal! */ while(start==0); printf("[GENIUS%d] Starting dinner...\n",which); /** dining philosopher here!!!! */ while(dining_time>0) { /** start to think */ think(think_time); /** try to get dining tools a.k.a. forks */ if(starving()&&think_time>think_min) think_time--; else if(think_time<think_max) think_time++; /** start to eat */ eat(eat_time,&dining_time); /** release dining tools a.k.a. forks - shouldn't we wash first? */ burping(); } fprintf(stderr,"[GENIUS%d] Finishing dinner...",which); fprintf(stderr," (Think=%d)(Starve=%d)(Attempt=%d)\n", total_think,total_starve,total_attempt); exit(0); }
/** ==================== Stmt ============================================= Grammar: stmt : loc '=' bool ';' | 'if' '(' bool ')' stmt | 'if' '(' bool ')' stmt 'else' stmt | 'while' '(' bool ')' stmt | 'do' stmt 'while' '(' bool ')' ';' | 'break' ';' | block | 'read' loc ';' | 'write' bool ';' */ static TreeStmt p_stmt(void) { TreeStmt stmt = 0; // set null by default TokenCode code = curr()->code; // cases switch (code) { case TOK_id: { //===== REDUCED TOK_loc TreeLoc l0loc = p_loc(); eat('='); TreeBool l2bool = p_bool(); eat(';'); stmt = t_stmt_loc(l0loc, l2bool); break; } case TOK_if: { eat(TOK_if); eat('('); TreeBool l2bool = p_bool(); eat(')'); TreeStmt l4stmt = p_stmt(); stmt = t_stmt_if(l2bool, l4stmt); break; } case TOK_if: { eat(TOK_if); eat('('); TreeBool l2bool = p_bool(); eat(')'); TreeStmt l4stmt = p_stmt(); eat(TOK_else); TreeStmt l6stmt = p_stmt(); stmt = t_stmt_if(l2bool, l4stmt, l6stmt); break; } case TOK_while: { eat(TOK_while); eat('('); TreeBool l2bool = p_bool(); eat(')'); TreeStmt l4stmt = p_stmt(); stmt = t_stmt_while(l2bool, l4stmt); break; } case TOK_do: { eat(TOK_do); TreeStmt l1stmt = p_stmt(); eat(TOK_while); eat('('); TreeBool l4bool = p_bool(); eat(')'); eat(';'); stmt = t_stmt_do(l1stmt, l4bool); break; } case TOK_break: { eat(TOK_break); eat(';'); stmt = t_stmt_break(); break; } case '{': { //===== REDUCED TOK_block TreeBlock l0block = p_block(); stmt = t_stmt_block(l0block); break; } case TOK_read: { eat(TOK_read); TreeLoc l1loc = p_loc(); eat(';'); stmt = t_stmt_read(l1loc); break; } case TOK_write: { eat(TOK_write); TreeBool l1bool = p_bool(); eat(';'); stmt = t_stmt_write(l1bool); break; } default: error_parse("stmt"); break; } return stmt; }
int main(int argc, char* argv[]) { FILE *input = nullptr; if (argc > 1) { input = fopen(argv[1], "r"); if (input == nullptr) return -1; } else return -1; std::cout.sync_with_stdio(false); // allocate the buffer char buffer[BUFFER_SIZE+1]; char* line1 = nullptr; char* line2 = nullptr; char* brkt; size_t num_read = 0; num_read = fread(buffer, 1, BUFFER_SIZE, input); buffer[num_read] = '\0'; auto book = new trading::booking<unsigned long>(); auto process_line = [&book](char* line) { //std::cout << line << std::endl; auto message = book->parse_message(line); if (unlikely(message == nullptr)) return; book->eat(message, std::cerr); book->print_mid(std::cerr); if ((++count) % 10 == 0) book->display(std::cerr); return; }; while(true) { line1 = strtok_r(buffer, "\r\n", &brkt); int line1_size; while ((line2 = strtok_r(nullptr, "\r\n", &brkt))) { process_line(line1); line1 = line2; } if (likely(num_read == BUFFER_SIZE)) { if (likely(buffer[BUFFER_SIZE-1] != 0)) { line1_size= buffer + BUFFER_SIZE - line1; memmove(buffer, line1, line1_size); num_read = line1_size + fread(buffer + line1_size, 1, BUFFER_SIZE - line1_size, input); } else { process_line(line1); num_read = fread(buffer, 1, BUFFER_SIZE, input); } buffer[num_read] = '\0'; } else { // process last line process_line(line1); break; } } // finish work book->display(std::cout); delete book; fclose(input); //std::cout<< "Finish" << std::endl; }
void compileConstDecl(void) { eat(TK_IDENT); eat(SB_EQ); compileConstant(); eat(SB_SEMICOLON); }
void compileVarDecl(void) { eat(TK_IDENT); eat(SB_COLON); compileType(); eat(SB_SEMICOLON); }
void compileElseSt(void) { eat(KW_ELSE); compileStatement(); }
void compileBlock5(void) { eat(KW_BEGIN); compileStatements(); eat(KW_END); }
/* * virtual string must be : * {vhost,vnet}:[%method]* * * vhost = accept only a host (/32) * vnet = accept any network * * %no = no virtual IP (accept public IP) * %priv = accept system-wide private net list * %v4:x = accept ipv4 in list 'x' * %v6:x = accept ipv6 in list 'x' * %all = accept all ips [only for testing] * * ex: vhost:%no,%priv,%v4:192.168.1.0/24 * * @param c Connection Struct * @param string (virtual_private= from ipsec.conf) * @return virtual_t */ struct virtual_t *create_virtual(const struct connection *c, const char *string) { unsigned short flags = 0, n_net = 0; const char *str = string, *first_net = NULL; struct virtual_t *v; if (string == NULL || string[0] == '\0') return NULL; if (eat(str, "vhost:")) { flags |= F_VIRTUAL_HOST; } else if (eat(str, "vnet:")) { /* ??? do nothing? */ } else { libreswan_log("virtual string \"%s\" missing prefix - virtual selection disabled for connection '%s'", string, c->name); return NULL; } /* * Parse string : fill flags & count subnets */ while (str != NULL && *str != '\0') { ip_subnet sub; /* sink -- value never used */ ptrdiff_t len; const char *next = strchr(str, ','); if (next == NULL) next = str + strlen(str); len = next - str; if (eat(str, "%no")) { flags |= F_VIRTUAL_NO; } else if (eat(str, "%priv")) { flags |= F_VIRTUAL_PRIVATE; } else if (eat(str, "%all")) { flags |= F_VIRTUAL_ALL; } else if (read_subnet(str, len, &sub, NULL, NULL)) { n_net++; if (first_net == NULL) first_net = str; str += len; } else { /* nothing matched: force failure */ str = NULL; } if (str != next) { libreswan_log("invalid virtual string \"%s\" - virtual selection disabled for connection '%s'", string, c->name); return NULL; } /* clang 3.5 thinks that next might be NULL; wrong */ str = *next != '\0' ? next + 1 : NULL; } v = (struct virtual_t *)alloc_bytes( sizeof(struct virtual_t) + (n_net * sizeof(ip_subnet)), "virtual description"); v->flags = flags; v->n_net = n_net; if (n_net != 0 && first_net != NULL) { /* * Save subnets in newly allocated struct */ int i = 0; for (str = first_net; str != NULL && *str != '\0'; ) { const char *next = strchr(str, ','); if (next == NULL) next = str + strlen(str); if (read_subnet(str, next - str, &(v->net[i]), NULL, NULL)) i++; str = *next ? next + 1 : NULL; } } return v; }
Type* compileFactor(void) { Type* type; Object* obj; switch (lookAhead->tokenType) { case TK_NUMBER: eat(TK_NUMBER); type = intType; genLC(currentToken->value); break; case TK_CHAR: eat(TK_CHAR); type = charType; genLC(currentToken->value); break; case TK_IDENT: eat(TK_IDENT); obj = checkDeclaredIdent(currentToken->string); switch (obj->kind) { case OBJ_CONSTANT: switch (obj->constAttrs->value->type) { case TP_INT: type = intType; genLC(obj->constAttrs->value->intValue); break; case TP_CHAR: type = charType; genLC(obj->constAttrs->value->charValue); break; default: break; } break; case OBJ_VARIABLE: if (obj->varAttrs->type->typeClass == TP_ARRAY) { genVariableAddress(obj); type = compileIndexes(obj->varAttrs->type); genLI(); } else { type = obj->varAttrs->type; genVariableValue(obj); } break; case OBJ_PARAMETER: // TODO: push parameter's value onto the stack type = obj->paramAttrs->type; break; case OBJ_FUNCTION: // TODO: generate function call if (isPredefinedFunction(obj)) { compileArguments(obj->funcAttrs->paramList); genPredefinedFunctionCall(obj); } else { compileArguments(obj->funcAttrs->paramList); } type = obj->funcAttrs->returnType; break; default: error(ERR_INVALID_FACTOR,currentToken->lineNo, currentToken->colNo); break; } break; case SB_LPAR: eat(SB_LPAR); type = compileExpression(); eat(SB_RPAR); break; default: error(ERR_INVALID_FACTOR, lookAhead->lineNo, lookAhead->colNo); } return type; }
int cypher(void) { int n; int junk; int lflag; char buffer[10]; lflag = -1; while (wordtype[wordnumber] == ADJS) wordnumber++; while (wordnumber <= wordcount) { switch (wordvalue[wordnumber]) { case UP: if (location[position].access || wiz || tempwiz) { if (!location[position].access) puts("Zap! A gust of wind lifts you up."); if (!battlestar_move(location[position].up, AHEAD)) return (-1); } else { puts("There is no way up"); return (-1); } lflag = 0; break; case DOWN: if (!battlestar_move(location[position].down, AHEAD)) return (-1); lflag = 0; break; case LEFT: if (!battlestar_move(left, LEFT)) return (-1); lflag = 0; break; case RIGHT: if (!battlestar_move(right, RIGHT)) return (-1); lflag = 0; break; case AHEAD: if (!battlestar_move(ahead, AHEAD)) return (-1); lflag = 0; break; case BACK: if (!battlestar_move(back, BACK)) return (-1); lflag = 0; break; case SHOOT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = shoot(); } wordnumber++; wordnumber++; } else shoot(); break; case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = take(location[position].objects); } wordnumber++; wordnumber++; } else take(location[position].objects); break; case DROP: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = drop("Dropped"); } wordnumber++; wordnumber++; } else drop("Dropped"); break; case KICK: case THROW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) { if ((testbit(inven, n) || testbit(location[position].objects, n)) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } } wordnumber += 2; } else throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); break; case TAKEOFF: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = takeoff(); } wordnumber += 2; } else takeoff(); break; case DRAW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = draw(); } wordnumber += 2; } else draw(); break; case PUTON: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = puton(); } wordnumber += 2; } else puton(); break; case WEARIT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = wearit(); } wordnumber += 2; } else wearit(); break; case EAT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = eat(); } wordnumber += 2; } else eat(); break; case PUT: put(); break; case INVEN: if (ucard(inven)) { puts("You are holding:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1)); printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER); } else puts("You aren't carrying anything."); if (ucard(wear)) { puts("\nYou are wearing:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); if (card(injuries, NUMOFINJURIES)) { puts("\nYou have suffered:\n"); for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n]) printf("\t%s\n", ouch[n]); printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s.")); } else puts("\nYou are in perfect health."); break; case USE: lflag = use(); break; case LOOK: if (!notes[CANTSEE] || testbit(inven, LAMPON) || testbit(location[position].objects, LAMPON) || matchlight) { beenthere[position] = 2; writedes(); printobjs(); if (matchlight) { puts("\nYour match splutters out."); matchlight = 0; } } else puts("I can't see anything."); return (-1); break; case SU: if (wiz || tempwiz) { printf("\nRoom (was %d) = ", position); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &position); printf("Time (was %d) = ", gtime); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", >ime); printf("Fuel (was %d) = ", fuel); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &fuel); printf("Torps (was %d) = ", torps); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &torps); printf("CUMBER (was %d) = ", CUMBER); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &CUMBER); printf("WEIGHT (was %d) = ", WEIGHT); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &WEIGHT); printf("Clock (was %d) = ", gclock); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &gclock); printf("Wizard (was %d, %d) = ", wiz, tempwiz); fgets(buffer, 10, stdin); if (*buffer != '\n') { sscanf(buffer, "%d", &junk); if (!junk) tempwiz = wiz = 0; } printf("\nDONE.\n"); return (0); } else puts("You aren't a wizard."); break; case SCORE: printf("\tPLEASURE\tPOWER\t\tEGO\n"); printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego); printf("This gives you the rating of %s in %d turns.\n", rate(), gtime); printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS); break; case KNIFE: case KILL: murder(); break; case UNDRESS: case RAVAGE: ravage(); break; case SAVE: save(); break; case FOLLOW: lflag = follow(); break; case GIVE: give(); break; case KISS: kiss(); break; case LOVE: love(); break; case RIDE: lflag = ride(); break; case DRIVE: lflag = drive(); break; case LIGHT: light(); break; case LAUNCH: if (!launch()) return (-1); else lflag = 0; break; case LANDIT: if (!land()) return (-1); else lflag = 0; break; case TIME: chime(); break; case SLEEP: zzz(); break; case DIG: dig(); break; case JUMP: lflag = jump(); break; case BURY: bury(); break; case SWIM: puts("Surf's up!"); break; case DRINK: drink(); break; case QUIT: die(0); default: puts("How's that?"); return (-1); break; } if (wordnumber < wordcount && *words[wordnumber++] == ',') continue; else return (lflag); } return (lflag); }
void compileLValue(void) { eat(TK_IDENT); compileIndexes(); }
void compileGroupSt(void) { eat(KW_BEGIN); compileStatements(); eat(KW_END); }
void compileAssignSt(void) { compileLValue(); eat(SB_ASSIGN); compileExpression(); }
void compileWhileSt(void) { eat(KW_WHILE); compileCondition(); eat(KW_DO); compileStatement(); }
void compileCallSt(void) { eat(KW_CALL); eat(TK_IDENT); compileArguments(); }