bool legal_move_board (unsigned short pos, unsigned char color, bool allow_suicide) { /* you can always pass */ if (pos == PASS_POS) { return true; } if (!on_board (pos) || (color != BLACK && color != WHITE)) { return false; } if (pos == ko_pos && color == current_player) { return false; } if (get_point_board (pos) != EMPTY) { return false; } /* don't need to save the current state, because it's always empty since we tested for that above */ set_point_board (pos, color); /* if we have liberties, it can't be illegal */ if (get_liberties_board (pos) > 0 || /* if we can capture something, it can't be illegal */ (get_point_board (NORTH (pos)) == OTHER (color) && !get_liberties_board (NORTH (pos))) || (get_point_board (SOUTH (pos)) == OTHER (color) && !get_liberties_board (SOUTH (pos))) || (get_point_board (EAST (pos)) == OTHER (color) && !get_liberties_board (EAST (pos))) || (get_point_board (WEST (pos)) == OTHER (color) && !get_liberties_board (WEST (pos))) || /* if we're allowed to suicide, only multi-stone suicide is legal (no ruleset allows single-stone suicide that I know of) */ (allow_suicide && (get_point_board (NORTH (pos)) == color || get_point_board (SOUTH (pos)) == color || get_point_board (EAST (pos)) == color || get_point_board (WEST (pos)) == color))) { /* undo our previous set */ set_point_board (pos, EMPTY); return true; } else { /* undo our previous set */ set_point_board (pos, EMPTY); return false; } }
void AutoMove(int From, int To, int Num) { if(Num == 1) { MakeMove(From, To); return; } AutoMove(From, OTHER(From, To), Num-1); MakeMove(From, To); AutoMove(OTHER(From, To), To, Num-1); }
static void AutoMove(int From, int To, int Num) { if (Num == 1) { MakeMove(From, To); napms(500); } else { AutoMove(From, OTHER(From, To), Num - 1); MakeMove(From, To); napms(500); AutoMove(OTHER(From, To), To, Num - 1); } }
int ab(int lvl, int mark, int lb, int d) { int di, pos, ans, dir, s; s = score(&hist[hno], mark) - lvl; if (lvl <= 0) return s; if (s <= -WINL || s >= WINL) return s; ans = lb; for (di = 0; di < 4; di++) { dir = dirs[di]; for (pos = 0; pos < bsize; pos++) { domove(dir, pos, mark); s = -ab(lvl-1, OTHER(mark), -d, -ans); if (s > ans) ans = s; undomove(); if (ans >= d) goto end; } } end: return ans; }
static rotate_return rotate(int child, node root) { rotate_return __return__; /// node orphan; node orphan; /// out = root->children_[child]; __return__.out = root->children_[child]; /// orphan = out->children_[OTHER(child)]; orphan = __return__.out->children_[OTHER(child)]; /// out->children_[OTHER(child)] = root; __return__.out->children_[OTHER(child)] = root; /// out->children_[OTHER(child)]->children_[child] = orphan; __return__.out->children_[OTHER(child)]->children_[child] = orphan; /// return out; __return__.value = __return__.out; return __return__; }
void computemove(char *dirp, int *posp, int mark) { int pos, di, high, lvl, s, i, j, bdir = 0, bpos = 0; int dir; struct move *mp, *np, *tmp; mp = moves; for (di = 0; di < 4; di++) { dir = dirs[di]; for (pos = 0; pos < bsize; pos++) { mp->dir = dir; mp->pos = pos; mp++; } } mp = moves; np = nmoves; for (lvl = 3; lvl < MAXLVL; lvl++) { high = -INF; for (i = 0; i < bsize4; i++) { domove(mp[i].dir, mp[i].pos, mark); s = -ab(lvl, OTHER(mark), -INF, -high); if (s > high) { high = s; bdir = mp[i].dir; bpos = mp[i].pos; if (WINNER(high)) { goto done; } } undomove(); /* sort the move into np */ for (j = i; j > 0; j--) { if (np[j-1].score >= s) break; np[j] = np[j-1]; } np[j].dir = mp[i].dir; np[j].pos = mp[i].pos; np[j].score = s; } *dirp = bdir; *posp = bpos; DPRINTF(("lvl=%d nscore=%d, high=%d\n", lvl, nscore, high)); nscore = 0; tmp = mp; mp = np; np = tmp; } done: *dirp = bdir; *posp = bpos; DPRINTF(("high=%d\n", high)); }
static int zoom1( /* called by Input_pointer */ int x, int y) { /* called by Input_pointer */ static int use = 1; static Objects objects[] = { MENU("CANCEL", cancel, &use), INFO(" Define the window ", &use), OTHER(zoom2, &use), {0} }; /* * user has marked first corner * this determines which view is being zoomed */ x1 = x; y1 = y; if (In_view(pick_view = VIEW_MAP1, x1, y1)) { main_view = VIEW_MAP1; zoom_view = VIEW_MAP1_ZOOM; target_flag = 0; } /* else if (In_view (pick_view = VIEW_MAP2, x1, y1)) { if (!pick_view->cell.configured) return 0; *//* ignore the mouse event *//* main_view = VIEW_MAP2; zoom_view = VIEW_MAP2_ZOOM; target_flag = 1; } */ else if (In_view(pick_view = VIEW_MAP1_ZOOM, x1, y1)) { if (!pick_view->cell.configured) return 0; /* ignore the mouse event */ main_view = VIEW_MAP1; zoom_view = VIEW_MAP1_ZOOM; target_flag = 0; } /* else if (In_view (pick_view = VIEW_MAP2_ZOOM, x1, y1)) { if (!pick_view->cell.configured) return 0; *//* ignore the mouse event *//* main_view = VIEW_MAP2; zoom_view = VIEW_MAP2_ZOOM; target_flag = 1; } */ else return 0; /* ignore the mouse event */ if (!pick_view->cell.configured) return 0; /* just to be sure */ return Input_box(objects, x, y); }
static void goodmove (enum EPlayer player, unsigned m) { printplayer (OTHER(player)); wprintw (_wmsg, "have %u %s%s.\n", _hand[OTHER(player)][m], c_CardNames[m], _hand[OTHER(player)][m] == 1 ? "" : "'s"); _hand[player][m] += _hand[OTHER(player)][m]; _hand[OTHER(player)][m] = 0; if (_hand[player][m] == SUITS) { printplayer (player); wprintw (_wmsg, "made a book of %s's!\n", c_CardNames[m]); chkwinner (player); } chkwinner (OTHER(player)); printplayer (player); waddstr (_wmsg, "get another guess!\n"); }
int main (void) { initialize_curses(); initialize_windows(); shuffle_deck_and_deal(); instructions(); enum EPlayer player = nrand(NPLAYERS); printplayer (player); waddstr (_wmsg, "get to start.\n"); for (;;) { unsigned m = makemove (player); if (_hand[OTHER(player)][m]) goodmove (player, m); else if (!gofish (player, m)) player = OTHER(player); } return EXIT_SUCCESS; }
void goodmove(int player, int move, int *hand, int *opphand) { printplayer(OTHER(player)); (void)printf("have %d %s%s.\n", opphand[move], cards[move], opphand[move] == 1 ? "": "'s"); hand[move] += opphand[move]; opphand[move] = 0; if (hand[move] == CARDS) { printplayer(player); (void)printf("made a book of %s's!\n", cards[move]); chkwinner(player, hand); } chkwinner(OTHER(player), opphand); printplayer(player); (void)printf("get another guess!\n"); }
ScriptDiscoverySyntax::ScriptDiscoverySyntax(const char *suffix) { DEFINE("FirstLine", GLUE( STRING("#!"), LAZY_REPEAT(OTHER('\n')), STRING(suffix) ) ); ENTRY("FirstLine"); LINK(); }
static bool gofish (enum EPlayer player, unsigned askedfor) { wattron (_wmsg, A_BOLD); printplayer (OTHER(player)); waddstr (_wmsg, "say \"GO FISH!\"\n"); wattroff (_wmsg, A_BOLD); if (askedfor == drawcard (player)) { printplayer (player); waddstr (_wmsg, "drew the guess and get to ask again.\n"); return true; } return false; }
int zoom_point(void) { static int use = 1; static Objects objects[] = { MENU("CANCEL", cancel, &use), INFO(" Mark center of area to be zoomed ", &use), OTHER(zoom1, &use), {0} }; Input_pointer(objects); return 1; }
int zoom_box(void) { static int use = 1; static Objects objects[] = { MENU("CANCEL", cancel, &use), INFO(" Mark first corner of window ", &use), OTHER(zoom1, &use), {0} }; Input_pointer(objects); return 1; }
int gofish(int askedfor, int player, int *hand) { printplayer(OTHER(player)); (void)printf("say \"GO FISH!\"\n"); if (askedfor == drawcard(player, hand)) { printplayer(player); (void)printf("drew the guess!\n"); printplayer(player); (void)printf("get to ask again!\n"); return(1); } return(0); }
static int get_liberties_helper (unsigned short pos, unsigned char orig_color) { if (on_board (pos) && get_point_board (pos) != OTHER (orig_color) && !is_marked (pos)) { make_mark (pos); if (get_point_board (pos) == EMPTY) { return 1; } else { push_pos_stack (&parse_stack, pos); } } return 0; }
void execute(char *s) { int f, g; f = POS(s[1] - '1', s[0] - 'a'); s += 2; while (*s) { g = POS(s[2] - '1', s[1] - 'a'); fld[f] = EMPTY; if (s[0] == '*') { --cnt[fld[(f + g)/2]]; fld[(f + g)/2] = EMPTY; } last[cur] = MOVE(f,g); f = g; s += 3; } fld[f] = cur; cur = OTHER(cur); }
int main(int argc, char **argv) { int i, mark, pos, delay; char dir; hmax = 50; hist = malloc(hmax * sizeof(struct config)); memset(&hist[0], 0, sizeof (struct config)); for (i = 1; i <= bsize; i++) sumsize += AMP(i); if (argc == 1) delay = 28; else delay = atoi(argv[1]); DPRINTF(("delay=%d\n", delay)); #if 0 scanf("%d\n", &mark); if (mark != bsize) exit(1); #endif for (mark = X; scanf("%c%d\n", &dir, &pos) == 2; mark = OTHER(mark)) { domove(dir, pos-1, mark); } signal(SIGALRM, timeout); alarm(delay); computemove(&bestdir, &bestpos, mark); DPRINTF(("done\n")); timeout(); exit(0); }
int search_capture(int from, int depth, int alpha, int beta) { int *adj, to, v; bool found = false; if (depth == 0) { strcat(move_buf, "*"); strcat(move_buf, field_str[from]); } for (adj = adjacent_capture[from]; *adj >= 0; ++adj) if (fld[*adj] == OTHER(cur) && fld[to = from + 2*(*adj - from)] == EMPTY) { fld[*adj] = EMPTY; --cnt[OTHER(cur)]; v = search_capture(to, depth, alpha, beta); ++cnt[OTHER(cur)]; fld[*adj] = OTHER(cur); if (v >= beta) return v; else if (v > alpha) alpha = v; found = true; } if (!found) { fld[from] = cur; cur = OTHER(cur); alpha = -evaluate(depth + 1, -beta, -alpha); fld[from] = EMPTY; cur = OTHER(cur); } if (depth == 0) { move_buf[strlen(move_buf) - 3] = '\0'; } return alpha; }
int ask_magnification(int *magnification) { static int use = 1; int x, y; int height; int stat; int width; int top, bottom, left, right; static Objects objects[] = { OTHER(incr, &use), {0} }; Menu_msg(""); mag = *magnification; if (mag < 1) mag = 1; height = VIEW_MENU->nrows; R_text_size(height - 4, height - 4); Get_mouse_xy(&x, &y); top = y - height / 2; if (top < SCREEN_TOP) top = SCREEN_TOP; bottom = top + 4 * height; if (bottom >= VIEW_MENU->top) { top -= bottom - (VIEW_MENU->top - 1); bottom = VIEW_MENU->top - 1; } width = Text_width("MAGNIFICATION") + 4; left = x - width / 2; if (left < SCREEN_LEFT) left = SCREEN_LEFT; right = left + width; if (right > SCREEN_RIGHT) { left -= right - SCREEN_RIGHT; right = SCREEN_RIGHT; } R_panel_save(tempfile1, top, bottom, left, right); R_standard_color(WHITE); R_box_abs(left, top, right, bottom); R_standard_color(BLACK); Outline_box(top, bottom, left, right); plus.top = top + height; plus.bottom = plus.top + height; plus.left = left; plus.right = plus.left + Text_width("++") + 4; Outline_box(plus.top, plus.bottom, plus.left, plus.right); minus.top = top + height; minus.bottom = minus.top + height; minus.right = right; minus.left = minus.right - Text_width("--") - 4; Outline_box(minus.top, minus.bottom, minus.left, minus.right); value.top = top + height; value.bottom = value.top + height; value.left = plus.right; value.right = minus.left; Outline_box(value.top, value.bottom, value.left, value.right); accept.top = value.bottom; accept.bottom = accept.top + height; accept.left = left; accept.right = right; Outline_box(accept.top, accept.bottom, accept.left, accept.right); cancel.top = accept.bottom; cancel.bottom = cancel.top + height; cancel.left = left; cancel.right = right; Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right); dotext("MAGNIFICATION", top, top + height, left, right, WHITE); dotext("+", plus.top, plus.bottom, plus.left, plus.right, GREY); dotext("-", minus.top, minus.bottom, minus.left, minus.right, GREY); dotext("ACCEPT", accept.top, accept.bottom, accept.left, accept.right, GREY); dotext("CANCEL", cancel.top, cancel.bottom, cancel.left, cancel.right, GREY); draw_mag(); stat = Input_pointer(objects); /* to respond to user */ R_standard_color(WHITE); R_box_abs(left, top, right, bottom); R_flush(); R_panel_restore(tempfile1); R_panel_delete(tempfile1); *magnification = mag; return stat > 0; }
HaxeMessageSyntax::HaxeMessageSyntax() { DEFINE_VOID("SpaceChar", RANGE(" \n\r\t")); DEFINE_VOID("Whitespace", REPEAT(INLINE("SpaceChar"))); specialChar_ = DEFINE("SpecialChar", GLUE( CHAR('&'), KEYWORD("gt lt"), CHAR(';') ) ); gt_ = keywordByName("gt"); lt_ = keywordByName("lt"); value_ = DEFINE("Value", REPEAT(1, CHOICE( REF("SpecialChar"), GLUE( NOT( GLUE( INLINE("Whitespace"), CHAR('<') ) ), ANY() ) ) ) ); typeTip_ = DEFINE("TypeTip", GLUE( STRING("<type>"), INLINE("Whitespace"), REF("Value"), INLINE("Whitespace"), STRING("</type>") ) ); memberName_ = DEFINE("MemberName", REPEAT(1, OTHER('\"'))); memberType_ = DEFINE("MemberType", REPEAT(0, 1, INLINE("Value"))); memberDescription_ = DEFINE("MemberDescription", REPEAT(0, 1, INLINE("Value"))); member_ = DEFINE("Member", GLUE( STRING("<i n=\""), REF("MemberName"), STRING("\"><t>"), REF("MemberType"), STRING("</t><d>"), REF("MemberDescription"), STRING("</d></i>") ) ); membersTip_ = DEFINE("MembersTip", GLUE( STRING("<list>"), REPEAT(1, GLUE( INLINE("Whitespace"), REF("Member") ) ), INLINE("Whitespace"), STRING("</list>") ) ); haxeTip_ = DEFINE("HaxeTip", FIND( GLUE( INLINE("Whitespace"), CHOICE( REF("TypeTip"), REF("MembersTip") ), INLINE("Whitespace") ) ) ); ENTRY("HaxeTip"); }
RString InputHandler_MacOSX_HID::GetDeviceSpecificInputString( const DeviceInput &di ) { if( di.device == DEVICE_KEYBOARD ) { #define OTHER(n) (KEY_OTHER_0 + (n)) switch( di.button ) { case KEY_DEL: return "del"; case KEY_BACK: return "delete"; case KEY_ENTER: return "return"; case KEY_LALT: return "left option"; case KEY_RALT: return "right option"; case KEY_LMETA: return "left cmd"; case KEY_RMETA: return "right cmd"; case KEY_INSERT: return "help"; case OTHER(0): return "F17"; case OTHER(1): return "F18"; case OTHER(2): return "F19"; case OTHER(3): return "F20"; case OTHER(4): return "F21"; case OTHER(5): return "F22"; case OTHER(6): return "F23"; case OTHER(7): return "F25"; case OTHER(8): return "execute"; case OTHER(9): return "select"; case OTHER(10): return "stop"; case OTHER(11): return "again"; case OTHER(12): return "undo"; case OTHER(13): return "cut"; case OTHER(14): return "copy"; case OTHER(15): return "paste"; case OTHER(16): return "find"; case OTHER(17): return "mute"; case OTHER(18): return "volume up"; case OTHER(19): return "volume down"; case OTHER(20): return "AS/400 equal"; case OTHER(21): return "international 1"; case OTHER(22): return "international 2"; case OTHER(23): return "international 3"; case OTHER(24): return "international 4"; case OTHER(25): return "international 5"; case OTHER(26): return "international 6"; case OTHER(27): return "international 7"; case OTHER(28): return "international 8"; case OTHER(29): return "international 9"; case OTHER(30): return "lang 1"; case OTHER(31): return "lang 2"; case OTHER(32): return "lang 3"; case OTHER(33): return "lang 4"; case OTHER(34): return "lang 5"; case OTHER(35): return "lang 6"; case OTHER(36): return "lang 7"; case OTHER(37): return "lang 8"; case OTHER(38): return "lang 9"; case OTHER(39): return "alt erase"; case OTHER(40): return "sys req"; case OTHER(41): return "cancel"; case OTHER(42): return "separator"; case OTHER(43): return "out"; case OTHER(44): return "oper"; case OTHER(45): return "clear/again"; // XXX huh? case OTHER(46): return "cr sel/props"; // XXX case OTHER(47): return "ex sel"; case OTHER(48): return "non US backslash"; case OTHER(49): return "application"; case OTHER(50): return "prior"; default: break; } #undef OTHER } if( di.device == DEVICE_PUMP1 || di.device == DEVICE_PUMP2 ) { switch( di.button ) { case JOY_BUTTON_1: return "UL"; case JOY_BUTTON_2: return "UR"; case JOY_BUTTON_3: return "MID"; case JOY_BUTTON_4: return "DL"; case JOY_BUTTON_5: return "DR"; case JOY_BUTTON_6: return "Esc"; case JOY_BUTTON_7: return "P2 UL"; case JOY_BUTTON_8: return "P2 UR"; case JOY_BUTTON_9: return "P2 MID"; case JOY_BUTTON_10: return "P2 DL"; case JOY_BUTTON_11: return "P2 DR"; default: break; } } return InputHandler::GetDeviceSpecificInputString( di ); }
static bool UsbKeyToDeviceButton( UInt8 iUsbKey, DeviceButton &buttonOut ) { UInt8 usage = iUsbKey; if( usage < kHIDUsage_KeyboardA ) return false; if( usage <= kHIDUsage_KeyboardZ ) { buttonOut = enum_add2( KEY_Ca, usage - kHIDUsage_KeyboardA ); return true; } // KEY_C0 = KEY_C1 - 1, kHIDUsage_Keyboard0 = kHIDUsage_Keyboard9 + 1 if( usage <= kHIDUsage_Keyboard9 ) { buttonOut = enum_add2( KEY_C1, usage - kHIDUsage_Keyboard1 ); return true; } if( usage >= kHIDUsage_KeyboardF1 && usage <= kHIDUsage_KeyboardF12 ) { buttonOut = enum_add2( KEY_F1, usage - kHIDUsage_KeyboardF1 ); return true; } if( usage >= kHIDUsage_KeyboardF13 && usage <= kHIDUsage_KeyboardF16 ) { buttonOut = enum_add2( KEY_F13, usage - kHIDUsage_KeyboardF13 ); return true; } // keypad 0 is again backward if( usage >= kHIDUsage_Keypad1 && usage <= kHIDUsage_Keypad9 ) { buttonOut = enum_add2( KEY_KP_C1, usage - kHIDUsage_Keypad1 ); return true; } #define OTHER(n) (enum_add2(KEY_OTHER_0, (n))) // [0, 8] if( usage >= kHIDUsage_KeyboardF17 && usage <= kHIDUsage_KeyboardExecute ) { buttonOut = OTHER( 0 + usage - kHIDUsage_KeyboardF17 ); return true; } // [9, 19] if( usage >= kHIDUsage_KeyboardSelect && usage <= kHIDUsage_KeyboardVolumeDown ) { buttonOut = OTHER( 9 + usage - kHIDUsage_KeyboardSelect ); return true; } // [20, 41] if( usage >= kHIDUsage_KeypadEqualSignAS400 && usage <= kHIDUsage_KeyboardCancel ) { buttonOut = OTHER( 20 + usage - kHIDUsage_KeypadEqualSignAS400 ); return true; } // [42, 47] // XXX kHIDUsage_KeyboardClearOrAgain if( usage >= kHIDUsage_KeyboardSeparator && usage <= kHIDUsage_KeyboardExSel ) { buttonOut = OTHER( 32 + usage - kHIDUsage_KeyboardSeparator ); return true; } #define X(x,y) case x: buttonOut = y; return true // Time for the special cases switch( usage ) { X( kHIDUsage_Keyboard0, KEY_C0 ); X( kHIDUsage_Keypad0, KEY_KP_C0 ); X( kHIDUsage_KeyboardReturnOrEnter, KEY_ENTER ); X( kHIDUsage_KeyboardEscape, KEY_ESC ); X( kHIDUsage_KeyboardDeleteOrBackspace, KEY_BACK ); X( kHIDUsage_KeyboardTab, KEY_TAB ); X( kHIDUsage_KeyboardSpacebar, KEY_SPACE ); X( kHIDUsage_KeyboardHyphen, KEY_HYPHEN ); X( kHIDUsage_KeyboardEqualSign, KEY_EQUAL ); X( kHIDUsage_KeyboardOpenBracket, KEY_LBRACKET ); X( kHIDUsage_KeyboardCloseBracket, KEY_RBRACKET ); X( kHIDUsage_KeyboardBackslash, KEY_BACKSLASH ); X( kHIDUsage_KeyboardNonUSPound, KEY_HASH ); X( kHIDUsage_KeyboardSemicolon, KEY_SEMICOLON ); X( kHIDUsage_KeyboardQuote, KEY_SQUOTE ); X( kHIDUsage_KeyboardGraveAccentAndTilde, KEY_ACCENT ); X( kHIDUsage_KeyboardComma, KEY_COMMA ); X( kHIDUsage_KeyboardPeriod, KEY_PERIOD ); X( kHIDUsage_KeyboardSlash, KEY_SLASH ); X( kHIDUsage_KeyboardCapsLock, KEY_CAPSLOCK ); X( kHIDUsage_KeyboardPrintScreen, KEY_PRTSC ); X( kHIDUsage_KeyboardScrollLock, KEY_SCRLLOCK ); X( kHIDUsage_KeyboardPause, KEY_PAUSE ); X( kHIDUsage_KeyboardInsert, KEY_INSERT ); X( kHIDUsage_KeyboardHome, KEY_HOME ); X( kHIDUsage_KeyboardPageUp, KEY_PGUP ); X( kHIDUsage_KeyboardDeleteForward, KEY_DEL ); X( kHIDUsage_KeyboardEnd, KEY_END ); X( kHIDUsage_KeyboardPageDown, KEY_PGDN ); X( kHIDUsage_KeyboardRightArrow, KEY_RIGHT ); X( kHIDUsage_KeyboardLeftArrow, KEY_LEFT ); X( kHIDUsage_KeyboardDownArrow, KEY_DOWN ); X( kHIDUsage_KeyboardUpArrow, KEY_UP ); X( kHIDUsage_KeypadNumLock, KEY_NUMLOCK ); X( kHIDUsage_KeypadSlash, KEY_KP_SLASH ); X( kHIDUsage_KeypadEqualSign, KEY_KP_EQUAL ); X( kHIDUsage_KeypadAsterisk, KEY_KP_ASTERISK ); X( kHIDUsage_KeypadHyphen, KEY_KP_HYPHEN ); X( kHIDUsage_KeypadPlus, KEY_KP_PLUS ); X( kHIDUsage_KeypadEnter, KEY_KP_ENTER ); X( kHIDUsage_KeypadPeriod, KEY_KP_PERIOD ); X( kHIDUsage_KeyboardNonUSBackslash, OTHER(48) ); X( kHIDUsage_KeyboardApplication, OTHER(49) ); X( kHIDUsage_KeyboardClear, KEY_NUMLOCK ); // XXX X( kHIDUsage_KeyboardHelp, KEY_INSERT ); X( kHIDUsage_KeyboardMenu, KEY_MENU ); // XXX kHIDUsage_KeyboardLockingCapsLock // XXX kHIDUsage_KeyboardLockingNumLock // XXX kHIDUsage_KeyboardLockingScrollLock X( kHIDUsage_KeypadComma, KEY_KP_PERIOD ); // XXX X( kHIDUsage_KeyboardReturn, KEY_ENTER ); X( kHIDUsage_KeyboardPrior, OTHER(50) ); X( kHIDUsage_KeyboardLeftControl, KEY_LCTRL ); X( kHIDUsage_KeyboardLeftShift, KEY_LSHIFT ); X( kHIDUsage_KeyboardLeftAlt, KEY_LALT ); X( kHIDUsage_KeyboardLeftGUI, KEY_LMETA ); X( kHIDUsage_KeyboardRightControl, KEY_RCTRL ); X( kHIDUsage_KeyboardRightShift, KEY_RSHIFT ); X( kHIDUsage_KeyboardRightAlt, KEY_RALT ); X( kHIDUsage_KeyboardRightGUI, KEY_RMETA ); } #undef X #undef OTHER return false; }
/* ARGSUSED */ int cbc_decrypt_contiguous_blocks(cbc_ctx_t *ctx, char *data, size_t length, crypto_data_t *out, size_t block_size, int (*decrypt)(const void *, const uint8_t *, uint8_t *), void (*copy_block)(uint8_t *, uint8_t *), void (*xor_block)(uint8_t *, uint8_t *)) { size_t remainder = length; size_t need = 0; uint8_t *datap = (uint8_t *)data; uint8_t *blockp; uint8_t *lastp; void *iov_or_mp; offset_t offset; uint8_t *out_data_1; uint8_t *out_data_2; size_t out_data_1_len; if (length + ctx->cbc_remainder_len < block_size) { /* accumulate bytes here and return */ bcopy(datap, (uint8_t *)ctx->cbc_remainder + ctx->cbc_remainder_len, length); ctx->cbc_remainder_len += length; ctx->cbc_copy_to = datap; return (CRYPTO_SUCCESS); } lastp = ctx->cbc_lastp; if (out != NULL) crypto_init_ptrs(out, &iov_or_mp, &offset); do { /* Unprocessed data from last call. */ if (ctx->cbc_remainder_len > 0) { need = block_size - ctx->cbc_remainder_len; if (need > remainder) return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE); bcopy(datap, &((uint8_t *)ctx->cbc_remainder) [ctx->cbc_remainder_len], need); blockp = (uint8_t *)ctx->cbc_remainder; } else { blockp = datap; } /* LINTED: pointer alignment */ copy_block(blockp, (uint8_t *)OTHER((uint64_t *)lastp, ctx)); if (out != NULL) { decrypt(ctx->cbc_keysched, blockp, (uint8_t *)ctx->cbc_remainder); blockp = (uint8_t *)ctx->cbc_remainder; } else { decrypt(ctx->cbc_keysched, blockp, blockp); } /* * XOR the previous cipher block or IV with the * currently decrypted block. */ xor_block(lastp, blockp); /* LINTED: pointer alignment */ lastp = (uint8_t *)OTHER((uint64_t *)lastp, ctx); if (out != NULL) { crypto_get_ptrs(out, &iov_or_mp, &offset, &out_data_1, &out_data_1_len, &out_data_2, block_size); bcopy(blockp, out_data_1, out_data_1_len); if (out_data_2 != NULL) { bcopy(blockp + out_data_1_len, out_data_2, block_size - out_data_1_len); } /* update offset */ out->cd_offset += block_size; } else if (ctx->cbc_remainder_len > 0) { /* copy temporary block to where it belongs */ bcopy(blockp, ctx->cbc_copy_to, ctx->cbc_remainder_len); bcopy(blockp + ctx->cbc_remainder_len, datap, need); } /* Update pointer to next block of data to be processed. */ if (ctx->cbc_remainder_len != 0) { datap += need; ctx->cbc_remainder_len = 0; } else { datap += block_size; } remainder = (size_t)&data[length] - (size_t)datap; /* Incomplete last block. */ if (remainder > 0 && remainder < block_size) { bcopy(datap, ctx->cbc_remainder, remainder); ctx->cbc_remainder_len = remainder; ctx->cbc_lastp = lastp; ctx->cbc_copy_to = datap; return (CRYPTO_SUCCESS); } ctx->cbc_copy_to = NULL; } while (remainder > 0); ctx->cbc_lastp = lastp; return (CRYPTO_SUCCESS); }
int ask_line_color(char *colors, int len1, char *xname, int position) { static int use = 1; int pick(); static Objects objects[] = { OTHER(pick, &use), {0} }; char msg[100]; int width; int len2 = 0, len; long offset; long *page_offset; int col, nlist; int line; int stat; char buf[100]; int top, bottom, left, right, center; int topx, bottomx, leftx, rightx, widthx; char name[100], mapset[100], cur_mapset[100]; int new_mapset; Menu_msg(""); sprintf(msg, "Double click on color to assign to vector layer"); /* * build a popup window at center of the screen. * 35% the height and wide enough to hold 2 columms of file names * * the window is for choosing file names and will be laid out in 2 columns * * ------------------------------------------ * | CANCEL | (MORE) | (LESS) | * ------------------------------------------ * | mapset | * ------------------------------------------ * | name1 | name2 | * ------------------------------------------ * | name3 | name4 | * ------------------------------------------ * | name5 | name6 | * | . | * | . | * | . | * ------------------------------------------ */ /* height of 1 line, based on NLINES taking up 35% vertical space */ height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1; /* size of text, 80% of line height */ text_size = .8 * height; size = text_size - 1; /* fudge for computing pixels width of text */ /* indent for the text */ edge = .1 * height + 1; /* this is a fudge to determine the length of the largest text */ len1 = 2 * len1; /* name in 2 columns */ len2 += strlen("mapset "); len = (len1 > len2 ? len1 : len2); /* width is for max chars plus sidecar for more/less */ width = len * size + height; widthx = strlen(msg) * size; if (widthx < width) widthx = width; /* define the window */ top = (SCREEN_TOP + SCREEN_BOTTOM - height * NLINES) / 2; bottom = top + height * NLINES; center = (SCREEN_LEFT + SCREEN_RIGHT) / 2; if (position > 0) { right = (center + SCREEN_RIGHT + width) / 2; if (right >= SCREEN_RIGHT) right = SCREEN_RIGHT - 1; left = right - width; } else if (position < 0) { left = (center + SCREEN_LEFT - width) / 2; if (left <= SCREEN_LEFT) left = SCREEN_LEFT + 1; right = left + width; } else { left = center + width / 2; right = left + width; } topx = top - 3 * height; bottomx = topx + 2 * height; leftx = (left + right - widthx) / 2; if (leftx < SCREEN_LEFT) leftx = SCREEN_LEFT; rightx = leftx + widthx; /* save what is under these areas, so they can be restored */ R_panel_save(tempfile1, top, bottom, left, right); R_panel_save(tempfile2, topx, bottomx, leftx, rightx); /* fill it top with GREY, pick area with white */ R_standard_color(WHITE); R_box_abs(left, top, right, bottom); R_standard_color(GREY); R_box_abs(leftx, topx, rightx, bottomx); R_standard_color(BLACK); Outline_box(top, bottom, left, right); right -= height; /* reduce it to exclude sidecar */ Outline_box(top, bottom, left, right); /* print messages above the files */ dotext(msg, topx, topx + height, leftx, rightx, 1); dotext("Double click here to cancel", topx + height, bottomx, leftx, rightx, 1); cancel.top = topx; cancel.bottom = bottomx; cancel.left = leftx; cancel.right = rightx; /* start the mouse in the cancel box */ Set_mouse_xy((leftx + rightx) / 2, (topx + bottomx) / 2); dobox(&less, "", WHITE, top, right, right + height, 0); dobox(&more, "", WHITE, bottom - height, right, right + height, 0); /* as we read the file of names, keep track of pages so we can * page backward */ page = 0; page_offset = (long *)G_calloc(npages = 1, sizeof(long)); *page_offset = ftell(fd); nlist = sizeof(list) / sizeof(list[0]); for (stat = -1; stat < 0;) { line = 0; count = 0; *cur_mapset = 0; col = 0; while (1) { /* offset = ftell (fd); if (fgets (buf, sizeof buf, fd) == NULL || sscanf (buf, "%s %s", name, mapset) != 2) break; if(new_mapset = (strcmp (cur_mapset,mapset) != 0)) { if(line) line++; if (col) line++; col = 0; } if (count >= nlist || line+new_mapset >= NLINES) { if (page+1 == npages) { npages++; page_offset = (long *) G_realloc (page_offset, npages * sizeof (long)); page_offset[npages-1] = offset; } break; } if (new_mapset) { struct box dummy; char label[100]; strcpy (cur_mapset, mapset); sprintf (label, "Mapset %s", mapset); dobox (&dummy, label, WHITE, top+line*height, left, right, 0); line++; } if (col) { dobox (&list[count].box, name, GREY, top+line*height, left+width/2, right, 0); line++; col = 0; } else { dobox (&list[count].box, name, GREY, top+line*height, left, left+width/2, 0); col = 1; } strcpy (list[count].name, name); strcpy (list[count].mapset, mapset); count++; } downarrow (&more, page+1 < npages ? BLACK : WHITE); uparrow (&less, page > 0 ? BLACK : WHITE); which = -1; switch(Input_pointer(objects)) { case -1: /* more or less */ break; case -2: /* cancel */ stat = 0; continue; default: /* file picked */ strcpy(xname, list[which].name); stat = 1; continue; } fseek(fd, page_offset[page], 0); R_standard_color(WHITE); R_box_abs(left + 1, top + 1, right - 1, bottom - 1); } /* all done. restore what was under the window */ right += height; /* move it back over the sidecar */ R_standard_color(WHITE); R_box_abs(left, top, right, bottom); R_panel_restore(tempfile1); R_panel_restore(tempfile2); R_panel_delete(tempfile1); R_panel_delete(tempfile2); R_flush(); G_free(page_offset); return stat; }
int analyze(void) { static int use = 1; static Objects objects[] = { MENU("DONE", done, &use), MENU("PRINT", to_printer, &use), MENU("FILE", to_file, &use), MENU("OVERLAY", do_warp, &use), MENU(delete_msg, delete_mark, &use), INFO("Transform->", &use), MENU(order_msg, get_order, &use), INFO(pick_msg, &use), OTHER(pick, &use), {0} }; int color; int tsize; int cury; int len; int line; int top, bottom, left, right, width, middle, nums; /* to give user a response of some sort */ Menu_msg("Preparing analysis ..."); /* * build a popup window at center of the screen. * 35% the height and wide enough to hold the report * */ /* height of 1 line, based on NLINES taking up 35% vertical space */ height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1; /* size of text, 80% of line height */ tsize = .8 * height; size = tsize - 2; /* fudge for computing pixels width of text */ /* indent for the text */ edge = .1 * height + 1; /* determine the length, in chars, of printed line */ FMT0(buf, 0); nums = strlen(buf) * size; FMT1(buf, 0.0, 0.0, 0.0); len = strlen(buf); middle = len * size; FMT2(buf, 0.0, 0.0, 0.0, 0.0); len += strlen(buf); /* width is for max chars plus sidecar for more/less */ width = len * size + nums + 2 * height; if ((SCREEN_RIGHT - SCREEN_LEFT) < width) width = SCREEN_RIGHT - SCREEN_LEFT; /* define the window */ bottom = VIEW_MENU->top - 1; top = bottom - height * NLINES; left = SCREEN_LEFT; right = left + width; middle += left + nums; nums += left; /* save what is under this area, so it can be restored */ R_panel_save(tempfile1, top, bottom + 1, left, right + 1); /* fill it with white */ R_standard_color(BACKGROUND); R_box_abs(left, top, right, bottom); right -= 2 * height; /* reduce it to exclude sidecar */ /* print messages in message area */ R_text_size(tsize, tsize); /* setup the more/less boxes in the sidecar */ R_standard_color(BLACK); less.top = top; less.bottom = top + 2 * height; less.left = right; less.right = right + 2 * height; Outline_box(less.top, less.bottom, less.left, less.right); more.top = bottom - 2 * height; more.bottom = bottom; more.left = right; more.right = right + 2 * height; Outline_box(more.top, more.bottom, more.left, more.right); /* * top two lines are for column labels * last two line is for overall rms error. */ nlines = NLINES - 3; first_point = 0; /* allocate predicted values */ xres = (double *)G_calloc(group.points.count, sizeof(double)); yres = (double *)G_calloc(group.points.count, sizeof(double)); gnd = (double *)G_calloc(group.points.count, sizeof(double)); /* compute transformation for the first time */ compute_transformation(); /* put head on the report */ cury = top; dotext(LHEAD1, cury, cury + height, left, middle, 0, BLACK); dotext(RHEAD1, cury, cury + height, middle, right - 1, 0, BLACK); cury += height; dotext(LHEAD2, cury, cury + height, left, middle, 0, BLACK); dotext(RHEAD2, cury, cury + height, middle, right - 1, 0, BLACK); cury += height; R_move_abs(left, cury - 1); R_cont_abs(right, cury - 1); /* isolate the sidecar */ R_move_abs(right, top); R_cont_abs(right, bottom); /* define report box */ report.top = cury; report.left = left; report.right = right; /* lets do it */ pager = 1; while (1) { R_text_size(tsize, tsize); line = 0; curp = first_point; cury = top + 2 * height; while (1) { if (line >= nlines || curp >= group.points.count) break; line++; if (!delete_mode) color = BLACK; else color = BLUE; if (group.equation_stat > 0 && group.points.status[curp] > 0) { /* color = BLACK; */ FMT1(buf, xres[curp], yres[curp], gnd[curp]); if (curp == xmax || curp == ymax || curp == gmax) color = RED; dotext(buf, cury, cury + height, nums, middle, 0, color); } else if (group.points.status[curp] > 0) dotext("?", cury, cury + height, nums, middle, 1, color); else dotext("not used", cury, cury + height, nums, middle, 1, color); if (pager) { FMT0(buf, curp + 1); dotext(buf, cury, cury + height, left, nums, 0, color); FMT2(buf, group.points.e1[curp], group.points.n1[curp], group.points.e2[curp], group.points.n2[curp]); dotext(buf, cury, cury + height, middle, right - 1, 0, color); } cury += height; curp++; } report.bottom = cury; downarrow(&more, curp < group.points.count ? color : BACKGROUND); uparrow(&less, first_point > 0 ? color : BACKGROUND); R_standard_color(BACKGROUND); R_box_abs(left, cury, right - 1, bottom); if (group.equation_stat < 0) { if (group.equation_stat == -1) { color = RED; strcpy(buf, "Poorly placed control points"); } else { if (group.equation_stat == -2) G_fatal_error("NOT ENOUGH MEMORY"); else G_fatal_error("PARAMETER ERROR"); } } else if (group.equation_stat == 0) { color = RED; strcpy(buf, "No active control points"); } else { color = BLACK; sprintf(buf, "Overall rms error: %.2f", rms); } dotext(buf, bottom - height, bottom, left, right - 1, 0, color); R_standard_color(BLACK); R_move_abs(left, bottom - height); R_cont_abs(right - 1, bottom - height); pager = 0; which = -1; if (Input_pointer(objects) < 0) break; display_points(1); } /* all done. restore what was under the window */ right += 2 * height; /* move it back over the sidecar */ R_standard_color(BACKGROUND); R_box_abs(left, top, right, bottom); R_panel_restore(tempfile1); R_panel_delete(tempfile1); R_flush(); G_free(xres); G_free(yres); G_free(gnd); I_put_control_points(group.name, &group.points); display_points(1); return 0; /* return but don't QUIT */ }
int material_value() { int diff = cnt[cur] - cnt[OTHER(cur)], sum = cnt[0] + cnt[1];; return 100000*(2*diff + 1)/sum; }
int search(int depth, int alpha, int beta) { bool found = false; int from, to, *adj, v, bak; /* Search for capturing moves */ bak = last[cur]; last[cur] = -1; for (from = 0; from < FIELDS; ++from) if (fld[from] == cur) { for (adj = adjacent_capture[from]; *adj >= 0; ++adj) if (fld[*adj] == OTHER(cur) && fld[to = from + 2*(*adj - from)] == EMPTY) { if (depth == 0) strcpy(move_buf, field_str[from]); fld[from] = fld[*adj] = EMPTY; --cnt[OTHER(cur)]; v = search_capture(to, depth, alpha, beta); ++cnt[OTHER(cur)]; fld[from] = cur; fld[*adj] = OTHER(cur); if (v >= beta) return v; else if (v > alpha) alpha = v; found = true; } } last[cur] = bak; if (found) return alpha; /* Search for non-capturing moves */ /* FIXME: cache fields occupied by `cur' and use them here? */ for (from = 0; from < FIELDS; ++from) if (fld[from] == cur) { for (adj = adjacent[from]; *adj >= 0; ++adj) if (fld[to = *adj] == EMPTY) { if (bak == MOVE(to,from)) continue; if (depth == 0) { strcpy(move_buf, field_str[from]); strcat(move_buf, "-"); strcat(move_buf, field_str[to]); } fld[from] = EMPTY; fld[to] = cur; last[cur] = MOVE(from,to); cur = OTHER(cur); v = -evaluate(depth + 1, -beta, -alpha); cur = OTHER(cur); fld[from] = cur; fld[to] = EMPTY; last[cur] = bak; if (v >= beta) return v; else if (v > alpha) alpha = v; } } return alpha; }