void textSource::copyEOLsequence() /* Record the way lines are separated in the input. With this recording, the same pattern can be applied to the output. */ { wint_t ch; while((ch = Getc(sourceFile)) != '\n' && ch != '\r' && ch != WEOF && ch != 26) { } if(ch == '\n') { flgs.firstEOLchar = '\n'; if(Getc(sourceFile) == '\r') flgs.secondEOLchar = '\r'; } else if(ch == '\r') { flgs.firstEOLchar = '\r'; if(Getc(sourceFile) == '\n') flgs.secondEOLchar = '\n'; } else // Assume DOS-format { flgs.firstEOLchar = '\r'; flgs.secondEOLchar = '\n'; } Frewind(sourceFile); }
void compress(File *in, File *out) { uint8_t ch; Queue_Node *buf[256]; Queue *queueHead; Encoder_Node *en, *root; Encoder_Table **table; Queue_Node *qn; uint16_t nodeCount; memset(buf, 0, sizeof(buf)); queueHead = queue_new(); ch = Fgetc(in); while (!Feof(in)) { if (buf[ch] == NULL) { en = encoder_newNode(ch, 0, NULL, NULL); qn = queue_newNode(1, en, NULL, NULL); queue_append(queueHead, qn); buf[ch] = qn; } else buf[ch]->count++; ch = Fgetc(in); } Frewind(in); root = encoder_newEncoder(queueHead); table = encoder_newEncoderTable(buf); nodeCount = encoder_getEncoderNodeCount(table); encoder_writeHeader(root, out, in->size, nodeCount); encoder_writeData(table, in, out); encoder_freeEncoder(root); encoder_freeEncoderTable(table); queue_freeQueue(queueHead); }
Room *load_RoomData(char *filename, unsigned int number, int flags) { Room *r; File *f; int (*load_func)(File *, Room *, int) = NULL; int version; if (filename == NULL || !*filename || (r = new_Room()) == NULL) return NULL; if ((f = Fopen(filename)) == NULL) { destroy_Room(r); return NULL; } r->number = number; version = fileformat_version(f); switch(version) { case -1: log_err("load_RoomData(): error trying to determine file format version of %s", filename); load_func = NULL; break; case 0: Frewind(f); load_func = load_RoomData_version0; break; case 1: load_func = load_RoomData_version1; break; default: log_err("load_RoomData(): don't know how to load version %d of %s", version, filename); } if (load_func != NULL && !load_func(f, r, flags)) { Fclose(f); r->flags &= ROOM_ALL; /* force the room name for Mail> and Home> so that find_abbrevRoom() won't act strangely when these names are different in the files for some strange reason */ if (r->number == MAIL_ROOM) { Free(r->name); r->name = cstrdup("Mail"); } if (r->number == HOME_ROOM) { Free(r->name); r->name = cstrdup("Home"); } if (r->number == MAIL_ROOM) r->max_msgs = PARAM_MAX_MAIL_MSGS; else if (r->max_msgs < 1) r->max_msgs = PARAM_MAX_MESSAGES; if (PARAM_HAVE_CHATROOMS && (r->flags & ROOM_CHATROOM) && r->chat_history == NULL) r->chat_history = new_StringQueue(); if (!PARAM_HAVE_CHATROOMS && (r->flags & ROOM_CHATROOM) && r->number != HOME_ROOM) { r->flags &= ~ROOM_CHATROOM; r->flags |= ROOM_DIRTY; } (void)sort_StringList(&r->room_aides, alphasort_StringList); (void)sort_StringList(&r->invited, alphasort_StringList); (void)sort_StringList(&r->kicked, alphasort_StringList); return r; } destroy_Room(r); Fclose(f); return NULL; }