void compress() { init(); // A byte is in [0, 255[ int byte; (*update)(); // First update // Read byte byte = read_byte(); // Compress each byte while (byte != EOF) { if (already_added(byte) == 1) { // Write path to leaf Tree* leaf = ascii[byte]; path_from(leaf); write_path_inverse(); // Update tree increment_from(leaf); } else { // New character // Write path to '?' path_from(unknow); write_path_inverse(); // Write char write_byte(byte); // Add char to tree add_char(byte); // Update tree // New parent's weight of unknow is already set // Increase from grand parent increment_from(unknow->parent->parent); } (*update)(); // Update // Read next byte byte = read_byte(); } // EOF reached path_from(my_eof); write_path_inverse(); // Compression is done destroy(); }
/* * NAME: path->include() * DESCRIPTION: resolve an include path */ char *path_include(char *buf, char *from, char *file, string ***strs, int *nstr) { frame *f; int i; value *v; string **str; *strs = NULL; *nstr = 0; if (c_autodriver()) { return path_from(buf, from, file); } f = cframe; PUSH_STRVAL(f, str_new(from, strlen(from))); PUSH_STRVAL(f, str_new(file, (long) strlen(file))); if (!call_driver_object(f, "include_file", 2)) { f->sp++; return path_from(buf, from, file); } if (f->sp->type == T_STRING) { /* simple path */ path_resolve(buf, f->sp->u.string->text); str_del((f->sp++)->u.string); return buf; } else if (f->sp->type == T_ARRAY) { /* * Array of strings. Check that the array does indeed contain only * strings, then return it. */ i = f->sp->u.array->size; if (i != 0) { v = d_get_elts(f->sp->u.array); while ((v++)->type == T_STRING) { if (--i == 0) { *nstr = i = f->sp->u.array->size; str = ALLOC(string*, i); do { str_ref(*str++ = (--v)->u.string); } while (--i != 0); *strs = str; arr_del((f->sp++)->u.array); /* return the untranslated path, as well */ return path_from(buf, from, file); } }