/* Store a bitmap in the cache */ void cache_put_bitmap(rdcConnection conn, uint8 id, uint16 idx, HBITMAP bitmap) { HBITMAP old; if ((id < NUM_ELEMENTS(conn->bmpcache)) && (idx < NUM_ELEMENTS(conn->bmpcache[0]))) { old = conn->bmpcache[id][idx].bitmap; if (old != NULL) ui_destroy_bitmap(old); conn->bmpcache[id][idx].bitmap = bitmap; if (IS_PERSISTENT(id)) { if (old == NULL) conn->bmpcache[id][idx].previous = conn->bmpcache[id][idx].next = NOT_SET; cache_bump_bitmap(conn, id, idx, TO_TOP); if (conn->bmpcacheCount[id] > BMPCACHE2_C2_CELLS) cache_evict_bitmap(conn, id); } } else if ((id < NUM_ELEMENTS(conn->volatileBc)) && (idx == 0x7fff)) { old = conn->volatileBc[id]; if (old != NULL) ui_destroy_bitmap(old); conn->volatileBc[id] = bitmap; } else { error("put bitmap %d:%d\n", id, idx); } }
/* Store a bitmap in the cache */ void cache_put_bitmap(uint8 id, uint16 idx, RD_HBITMAP bitmap) { RD_HBITMAP old; if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0]))) { old = g_bmpcache[id][idx].bitmap; if (old != NULL) ui_destroy_bitmap(old); g_bmpcache[id][idx].bitmap = bitmap; if (IS_PERSISTENT(id)) { if (old == NULL) g_bmpcache[id][idx].previous = g_bmpcache[id][idx].next = NOT_SET; cache_bump_bitmap(id, idx, TO_TOP); if (g_bmpcache_count[id] > BMPCACHE2_C2_CELLS) cache_evict_bitmap(id); } } else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff)) { old = g_volatile_bc[id]; if (old != NULL) ui_destroy_bitmap(old); g_volatile_bc[id] = bitmap; } else { error("put bitmap %d:%d\n", id, idx); } }
char * LapSkillToAscii( uchar skill_level /* In Skill level */ ) { if (skill_level >= NUM_ELEMENTS(skill)) { skill_level = NUM_ELEMENTS(skill) - 1; } return skill[skill_level]; }
char * LapCircuitText( int circuit_number /* In Cicruit number */ ) { if (circuit_number >= NUM_ELEMENTS(circuits)) { circuit_number = NUM_ELEMENTS(circuits) - 1; } return circuits[circuit_number]; }
/* Retrieve a glyph from the font cache */ FONTGLYPH * cache_get_font(uint8 font, uint16 character) { FONTGLYPH *glyph; if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0]))) { glyph = &g_fontcache[font][character]; if (glyph->pixmap != NULL) return glyph; } error("get font %d:%d\n", font, character); return NULL; }
/* Retrieve a bitmap from the cache */ HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx) { HBITMAP bitmap; if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0]))) { bitmap = bmpcache[cache_id][cache_idx]; if (bitmap != NULL) return bitmap; } error("get bitmap %d:%d\n", cache_id, cache_idx); return NULL; }
TeamsWindow::TeamsWindow( HINSTANCE hInst, HWND hWndParent, unsigned short usWidth, unsigned short usHeight ) : ChildWindow(hInst, TEAMS_CLASS_NAME, GetAppName(), WS_CHILD, CHILD_ID_TEAMS, hWndParent) { unsigned short i; fInBitmap = FALSE; usSelectedTeam = 0; usClientWidth = usWidth; usClientHeight = usHeight; usMiniCarWidth = usClientWidth / TEAMS_NUM_X; usMiniCarHeight = usClientHeight / TEAMS_NUM_Y; pClientBitmap = new Bitmap(pF1CarBitmap, usClientWidth, usClientHeight); ASSERT(pClientBitmap != NULL); pCursorTeamCar = new Cursor(Instance(), APP_CURSOR_TEAMCAR); ASSERT(pCursorTeamCar != NULL); CAR_REGIONS *pCR = car_regions; for (i = 0; i < NUM_ELEMENTS(car_regions); i++, pCR++) { pCR->hRgn = CreatePolygonRgn(pCR->points, pCR->usPoints, ALTERNATE); ASSERT(pCR->hRgn != NULL); } UpdateMemoryImage(); DragAcceptFiles(Handle(), TRUE); }
const struct log_minor_info *dal_logger_enum_log_minor_info( struct dal_logger *logger, enum log_major major, unsigned int enum_index) { const struct log_minor_info *minor_info = NULL; uint32_t i; for (i = 0; i < NUM_ELEMENTS(log_major_mask_info_tbl); i++) { const struct log_major_mask_info *maj_mask_info = &log_major_mask_info_tbl[i]; if (maj_mask_info->major_info.major == major) { if (maj_mask_info->minor_tbl != NULL) { uint32_t j; for (j = 0; j < maj_mask_info->tbl_element_cnt; j++) { minor_info = &maj_mask_info->minor_tbl[j]; if (minor_info->minor == enum_index) return minor_info; } } break; } } return NULL; }
void mpt_req_state(mpt_req_state_t state) { mpt_decode_value(req_state_parse_table, NUM_ELEMENTS(req_state_parse_table), "REQ_STATE", state, NULL, 80); }
SAEventFlags::SAEventFlags(QObject *parent) : super(512, // Total number of bit flags. "SADataEvents", // Translation context. &sa_event_flags_desc[0], // Bit flags with names. NUM_ELEMENTS(sa_event_flags_desc)-1, // Number of named flags. parent) { }
static void print_help (void) { int i, j; usage(); printf("\n"); for (i=0;i<sizeof(help_string)/sizeof(help_string[0]);i++) { printf("%s\n", help_string[i]); /* Check if the string contains "oid" string. */ if (strstr(help_string[i], "oid")) { printf("\n\toid index\tOID info\n"); printf("\t------------------------------------\n"); for (j = 0; j < NUM_ELEMENTS(ilo_old_table); j++) printf("\t%4d\t\t%s\n", j + 1, ilo_old_table[j].oid_pool[HLTH_GROUP_OID].oid_name); printf("\t------------------------------------\n"); } } return ; }
static void log_major_minor(struct log_entry *entry) { uint32_t i; enum log_major major = entry->major; enum log_minor minor = entry->minor; for (i = 0; i < NUM_ELEMENTS(log_major_mask_info_tbl); i++) { const struct log_major_mask_info *maj_mask_info = &log_major_mask_info_tbl[i]; if (maj_mask_info->major_info.major == major) { dal_logger_append(entry, "[%s_", maj_mask_info->major_info.major_name); if (maj_mask_info->minor_tbl != NULL) { uint32_t j; for (j = 0; j < maj_mask_info->tbl_element_cnt; j++) { const struct log_minor_info *min_info = &maj_mask_info->minor_tbl[j]; if (min_info->minor == minor) dal_logger_append(entry, "%s]\t", min_info->minor_name); } } break; } } }
unsigned char LapCircuitLaps( int circuit_number /* In Cicruit number */ ) { if (circuit_number >= NUM_ELEMENTS(circuits_laps)) { circuit_number = 0; } return circuits_laps[circuit_number]; }
/* Store a bitmap in the cache */ void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap) { HBITMAP old; if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0]))) { old = bmpcache[cache_id][cache_idx]; if (old != NULL) ui_destroy_bitmap(old); bmpcache[cache_id][cache_idx] = bitmap; } else { error("put bitmap %d:%d\n", cache_id, cache_idx); } }
/* ----------- Object init and destruction ----------- */ static bool construct(struct dc_context *ctx, struct dal_logger *logger) { uint32_t i; /* malloc buffer and init offsets */ logger->log_buffer_size = DAL_LOGGER_BUFFER_MAX_SIZE; logger->log_buffer = (char *)dm_alloc(logger->log_buffer_size * sizeof(char)); if (!logger->log_buffer) return false; /* todo: Fill buffer with \0 if not done by dal_alloc */ /* Initialize both offsets to start of buffer (empty) */ logger->buffer_read_offset = 0; logger->buffer_write_offset = 0; logger->write_wrap_count = 0; logger->read_wrap_count = 0; logger->open_count = 0; logger->flags.bits.ENABLE_CONSOLE = 1; logger->flags.bits.ENABLE_BUFFER = 0; logger->ctx = ctx; /* malloc and init minor mask array */ logger->log_enable_mask_minors = (uint32_t *)dm_alloc(NUM_ELEMENTS(log_major_mask_info_tbl) * sizeof(uint32_t)); if (!logger->log_enable_mask_minors) return false; /* Set default values for mask */ for (i = 0; i < NUM_ELEMENTS(log_major_mask_info_tbl); i++) { uint32_t dflt_mask = log_major_mask_info_tbl[i].default_mask; logger->log_enable_mask_minors[i] = dflt_mask; } return true; }
int main(int /* argc */, char ** /*argv*/) { /* Conversion using encode() and decode(), with encoding flags. */ try { /* Flags that will control the conversions. */ unsigned encodingFlags = b64::B64_F_LINE_LEN_USE_PARAM; /* encode() will use the lineLen parameter to determine line length. */ unsigned decodingFlags = b64::B64_F_STOP_ON_UNKNOWN_CHAR; /* decode() will fail if any non-b64-character / non-white-space character is in the encoded string. */ int encodingLineLen = 4; /* Encoding line length will be 4 characters. */ /* Declare an array of bytes to use as the 'binary' blob to encode. */ unsigned char bytes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::cout << "Converting " << NUM_ELEMENTS(bytes) << " bytes:\n"; std::copy( bytes, bytes + NUM_ELEMENTS(bytes) , stlsoft::FILE_iterator<unsigned char>(stdout, " %d")); std::cout << std::endl; /* Perform the encoding, whose results are returned in an instance of * b64::cpp::string_t. */ b64::cpp::string_t enc = b64::cpp::encode(&bytes[0], sizeof(bytes), encodingFlags, encodingLineLen); std::cout << "Encoded form: [" << enc << "]" << std::endl; /* Perform the decoding, whose results are returned in an instance of * b64::cpp::blob_t. */ b64::cpp::blob_t dec = b64::cpp::decode(enc, decodingFlags); /* Verify that the decoding is exactly the same size and contents as * the encoding. */ assert(0 == ::memcmp(&bytes[0], &dec[0], sizeof(bytes))); } catch(b64::cpp::coding_exception &x) { std::cerr << "Exception: " << x.what() << std::endl; } return EXIT_SUCCESS; }
const struct log_major_info *dal_logger_enum_log_major_info( struct dal_logger *logger, unsigned int enum_index) { const struct log_major_info *major_info; if (enum_index >= NUM_ELEMENTS(log_major_mask_info_tbl)) return NULL; major_info = &log_major_mask_info_tbl[enum_index].major_info; return major_info; }
/** * Convert a UTF-16 string (WCHAR) to UTF-8. * Uses tmpchar and tmpwchar buffers. (NOT REENTRANT OR THREAD-SAFE!) * @param wcs WCHAR string. * @return UTF-8 string. (STATIC BUFFER; use immediately, DO NOT FREE!) */ const char *wchar_to_char(const WCHAR *wcs) { static char tmpchar[512]; size_t i; wchar_t *wcptr = tmpwchar.u32; // Convert the WCHAR string to wchar_t. // NOTE: Characters >U+FFFF are not supported. for (i = 0; i < NUM_ELEMENTS(tmpwchar.u32); i++) { if (*wcs == 0) break; *wcptr++ = *wcs++; } // NULL-terminate the string. *wcptr = 0; /// Convert from UTF-32 to UTF-8. wcstombs(tmpchar, tmpwchar.u32, NUM_ELEMENTS(tmpchar)); return tmpchar; }
/* Retrieve a bitmap from the cache */ RD_HBITMAP cache_get_bitmap(uint8 id, uint16 idx) { if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0]))) { if (g_bmpcache[id][idx].bitmap || pstcache_load_bitmap(id, idx)) { if (IS_PERSISTENT(id)) cache_bump_bitmap(id, idx, BUMP_COUNT); return g_bmpcache[id][idx].bitmap; } } else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff)) { return g_volatile_bc[id]; } error("get bitmap %d:%d\n", id, idx); return NULL; }
/* Retrieve a bitmap from the cache */ HBITMAP cache_get_bitmap(rdcConnection conn, uint8 id, uint16 idx) { if ((id < NUM_ELEMENTS(conn->bmpcache)) && (idx < NUM_ELEMENTS(conn->bmpcache[0]))) { if (conn->bmpcache[id][idx].bitmap || pstcache_load_bitmap(conn, id, idx)) { if (IS_PERSISTENT(id)) cache_bump_bitmap(conn, id, idx, BUMP_COUNT); return conn->bmpcache[id][idx].bitmap; } } else if ((id < NUM_ELEMENTS(conn->volatileBc)) && (idx == 0x7fff)) { return conn->volatileBc[id]; } error("get bitmap %d:%d\n", id, idx); return NULL; }
/** * Convert a UTF-8 string to WCHAR (UTF-16). * Uses tmpwchar buffer. (NOT REENTRANT OR THREAD-SAFE!) * @param str UTF-8 string. * @return True if converted; false if string is empty or invalid. */ static inline bool char_to_wchar(const char *str) { size_t len, i; if (!str || *str == 0) return false; len = mbstowcs(tmpwchar.u32, str, NUM_ELEMENTS(tmpwchar.u32)); if (len == 0) return false; if (len >= NUM_ELEMENTS(tmpwchar.u32)) len = NUM_ELEMENTS(tmpwchar.u32)-1; // Convert from UTF-32 to UTF-16. // NOTE: Characters >U+FFFF are not supported. for (i = 0; i < len; ++i) { tmpwchar.u16[i] = (WCHAR)(tmpwchar.u32[i] & 0xFFFF); } // NULL-terminate the string. tmpwchar.u16[len] = 0; return true; }
int main(int /* argc */, char ** /*argv*/) { /* Simple conversion using encode() and decode(). */ try { /* Declare an array of bytes to use as the 'binary' blob to encode. */ unsigned char bytes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::cout << "Converting " << NUM_ELEMENTS(bytes) << " bytes:\n"; std::copy( bytes, bytes + NUM_ELEMENTS(bytes) , stlsoft::FILE_iterator<unsigned char, char>(stdout, " %d")); std::cout << std::endl; /* Perform the encoding, whose results are returned in an instance of * b64::cpp::string_t. */ b64::cpp::string_t enc = b64::cpp::encode(&bytes[0], sizeof(bytes)); std::cout << "Encoded form: [" << enc << "]" << std::endl; /* Perform the decoding, whose results are returned in an instance of * b64::cpp::blob_t. */ b64::cpp::blob_t dec = b64::cpp::decode(enc); /* Verify that the decoding is exactly the same size and contents as * the encoding. */ assert(0 == ::memcmp(&bytes[0], &dec[0], sizeof(bytes))); } catch(b64::cpp::coding_exception &x) { std::cerr << "Exception: " << x.what() << std::endl; } return EXIT_SUCCESS; }
/* Store a glyph in the font cache */ void cache_put_font(uint8 font, uint16 character, uint16 offset, uint16 baseline, uint16 width, uint16 height, RD_HGLYPH pixmap) { FONTGLYPH *glyph; if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0]))) { glyph = &g_fontcache[font][character]; if (glyph->pixmap != NULL) ui_destroy_glyph(glyph->pixmap); glyph->offset = offset; glyph->baseline = baseline; glyph->width = width; glyph->height = height; glyph->pixmap = pixmap; } else { error("put font %d:%d\n", font, character); } }
/* Retrieve cursor from cache */ HCURSOR cache_get_cursor(RDPCLIENT * This, uint16 cache_idx) { HCURSOR cursor; if (cache_idx < NUM_ELEMENTS(This->cache.cursorcache)) { cursor = This->cache.cursorcache[cache_idx]; if (cursor != NULL) return cursor; } error("get cursor %d\n", cache_idx); return NULL; }
/* Retrieve cursor from cache */ HCURSOR cache_get_cursor(rdcConnection conn, uint16 cache_idx) { HCURSOR cursor; if (cache_idx < NUM_ELEMENTS(conn->cursorCache)) { cursor = conn->cursorCache[cache_idx]; if (cursor != NULL) return cursor; } error("get cursor %d\n", cache_idx); return NULL; }
static bool IsGameExeColoursPresent( void ) { bool ok = TRUE; unsigned short i; for (i = 0; ok && i < NUM_ELEMENTS(GP_EXE_car_colours); i++) { if (GP_EXE_car_colours[i].pling != '!') { ok = FALSE; } } return ok; }
/* Retrieve cursor from cache */ RD_HCURSOR cache_get_cursor(uint16 cache_idx) { RD_HCURSOR cursor; if (cache_idx < NUM_ELEMENTS(g_cursorcache)) { cursor = g_cursorcache[cache_idx]; if (cursor != NULL) return cursor; } error("get cursor %d\n", cache_idx); return NULL; }
/* Retrieve a text item from the cache */ DATABLOB * cache_get_text(uint8 cache_id) { DATABLOB *text; if (cache_id < NUM_ELEMENTS(textcache)) { text = &textcache[cache_id]; if (text->data != NULL) return text; } error("get text %d\n", cache_id); return NULL; }
void transition(U8 data) { int i; for (i = 0; i < NUM_ELEMENTS(state_machine); i++) { if (state_machine[i].current_state == current_state && (data & state_machine[i].mask) == state_machine[i].match) { if (state_machine[i].transition) { state_machine[i].transition(i, data); } current_state = state_machine[i].new_state; break; } } }
static struct req_info *lookup(int argc, const char **argv) { if (argc < 1) { set_last_error("Not enough parameters"); return 0; } size_t i; for (i = 0; i < NUM_ELEMENTS(req_table); i++) { if (strcmp(argv[0], req_table[i].name) == 0) { return &req_table[i]; } } set_last_error("Unknown function"); return 0; }