int ReadHelpFile(int index) { FILE* fptr; unsigned long offset; int complen, uncomplen; int c, result, read = 0, numpages; unsigned char *CompData, *UncompData, *pos; /* Free any memory from a previous help file */ FreeHelpSysData(); /* Return if the help file was corrupted. */ if (HelpFile[0] == '\0') return HELPREADERROR; /* Get the number of pages in the help file, and check wether the asked page exists. */ numpages = GetNumberOfHelpPages(); if ((numpages == 0) || (index >= numpages)) { LogPrint("Invalid index"); return HELPREADERROR; } /* Get the positions in the help file where to read the file, the number of bytes to read and the number of bytes to reserve as the output. */ if (!GetIndexInformation(index, &offset, &complen, &uncomplen)) { LogPrint("Invalid index"); return HELPREADERROR; } /* Try allocating the memory required. */ CompData = (unsigned char*) malloc(complen); if (!CompData) return HELPMEMINSUFFICIENT; UncompData = (unsigned char*) malloc(uncomplen); if (!UncompData) { free(CompData); return HELPMEMINSUFFICIENT; } /* Read the file. */ if ((fptr = fopen(HelpFile, "rb")) != NULL) { fseek(fptr, offset, SEEK_SET); pos = CompData; while ((c = fgetc(fptr)) != EOF) { *pos++ = (char) c; read++; if (read == complen) break; } fclose(fptr); } else { free(CompData); free(UncompData); return HELPREADERROR; } if (read != complen) { free(CompData); free(UncompData); return HELPREADERROR; } UncompressBuffer(CompData, UncompData, complen, uncomplen); free(CompData); /* Don't need the compressed data any more. */ result = ParseHelpFile((char*) UncompData, uncomplen); free(UncompData); /* Don't need the raw text data any more. */ return result; }
void TOperandString::Uncompress(TOperandString *op, Buffer *buf) { Buffer read_buf(op->GetData(), op->GetDataLength()); UncompressBuffer(&read_buf, buf); }