int rcz_file_size( int in_fd ) { unsigned int version, length; alloc_buf(in_fd); b_lseek(in_fd, 0, 0); version = get_byte(in_fd); version = (version<<8) | (get_byte(in_fd)); version = (version<<8) | (get_byte(in_fd)); version = (version<<8) | (get_byte(in_fd)); if(version != METHOD_17_JUL_95) { return (-1); // fprintf(stderr, "Incompatible version.\n"); // return(0); } length = get_byte(in_fd); length = (length<<8) | (get_byte(in_fd)); length = (length<<8) | (get_byte(in_fd)); length = (length<<8) | (get_byte(in_fd)); free_buf(); return length; }
static uint32_t load_keyboard_layout_file(const char *filename) { int fd; char magic[KEYBOARD_LAYOUTS_MAGIC_SIZE]; uint32_t version; if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { goto fail; // fail } if (read(fd, magic, sizeof(magic)) != sizeof(magic)) { printf("Can't find magic in keyboard layout file: %s\n", filename); goto fail; } if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) { printf("Invalid magic code in keyboard layout file: %s\n", filename); goto fail; } if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) { printf("Can't get version of keyboard layout file: %s\n", filename); goto fail; } if (version != KEYBOARD_LAYOUTS_VERSION) { verbose("Bad version for keyboard layout file %s expected v%d found v%d\n", filename, KEYBOARD_LAYOUTS_VERSION, version); goto fail; } if (current_layout) free(current_layout); current_layout = malloc(sizeof(*current_layout)); if (!current_layout) goto fail; b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0); if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) { printf("Wrong keyboard layout file %s size\n", filename); goto fail; } close(fd); return 1; fail: if (current_layout) { free(current_layout); current_layout = NULL; } return 0; }
int rcz_decompress_file( int in_fd, unsigned char *out ) /* Returns actual number of bytes emitted as decompressed stream 'out.' Note that the 'in' stream contains this byte count already. Returns -1 if the input stream was not in compressed format. */ { unsigned int c, j, k, jmatch, jabove; int length; unsigned int even_length, word, token; unsigned char *outorigin = out; length = rcz_file_size(in_fd); if (length < 0) return length; alloc_buf(in_fd); b_lseek(in_fd, 8, 0); for(c=0; c < QLEN; c++) que[c] = c; even_length = 2*(length/2); while((int)(out-outorigin) < even_length) { token = get_byte(in_fd); token = (token<<8) | (get_byte(in_fd)); token = (token<<8) | (get_byte(in_fd)); token = (token<<8) | (get_byte(in_fd)); c = 1<<31; for(k = 0; k<32; k++) { if(c & token) { jmatch = get_byte(in_fd); word = que[jmatch]; /* Next, dynamically process the queue for match. */ jabove = (F1*jmatch) >> 4; for(j = jmatch; j > jabove; j--) { que[j] = que[j-1]; } que[jabove] = word; } else { /* Next, dynamically process the queue for unmatch. */ word = get_byte(in_fd); word = (word << 8) | (get_byte(in_fd)); for(j=QLEN-1; j > ABOVE; j--) { que[j] = que[j-1]; } que[ABOVE] = word; } *out++ = (word >> 8) & 0xff; *out++ = (word) & 0xff; if((int)(out-outorigin) >= even_length) break; c >>= 1; }