22 #include "table/strings.h" 
   24 #if defined(WITH_ZLIB) 
   28 #if defined(WITH_LZMA) 
   60   _nested_textfile_widgets, 
lengthof(_nested_textfile_widgets)
 
   65   this->CreateNestedTree();
 
   68   this->FinishInitNested();
 
   69   this->GetWidget<NWidgetCore>(
WID_TF_CAPTION)->
SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
 
   71   this->hscroll->SetStepSize(10); 
 
   75  TextfileWindow::~TextfileWindow()
 
  103       size->width = 
max(200u, size->width); 
 
  160       y_offset += line_height; 
 
  204 #if defined(WITH_ZLIB) 
  220 static void Gunzip(byte **bufp, 
size_t *sizep)
 
  222   static const int BLOCKSIZE  = 8192;
 
  224   size_t           alloc_size = 0;
 
  228   memset(&z, 0, 
sizeof(z));
 
  230   z.avail_in = (uInt)*sizep;
 
  233   res = inflateInit2(&z, 15 + 32);
 
  235   while (res == Z_OK || (res == Z_BUF_ERROR && z.avail_out == 0)) {
 
  238     alloc_size += BLOCKSIZE;
 
  239     z.avail_out += BLOCKSIZE;
 
  241     z.next_out = buf + alloc_size - z.avail_out;
 
  242     res = inflate(&z, Z_FINISH);
 
  248   if (res == Z_STREAM_END) {
 
  250     *sizep = alloc_size - z.avail_out;
 
  260 #if defined(WITH_LZMA) 
  276 static void Xunzip(byte **bufp, 
size_t *sizep)
 
  278   static const int BLOCKSIZE  = 8192;
 
  280   size_t           alloc_size = 0;
 
  281   lzma_stream      z = LZMA_STREAM_INIT;
 
  287   res = lzma_auto_decoder(&z, UINT64_MAX, LZMA_CONCATENATED);
 
  289   while (res == LZMA_OK || (res == LZMA_BUF_ERROR && z.avail_out == 0)) {
 
  292     alloc_size += BLOCKSIZE;
 
  293     z.avail_out += BLOCKSIZE;
 
  295     z.next_out = buf + alloc_size - z.avail_out;
 
  296     res = lzma_code(&z, LZMA_FINISH);
 
  302   if (res == LZMA_STREAM_END) {
 
  304     *sizep = alloc_size - z.avail_out;
 
  320   if (textfile == NULL) 
return;
 
  326   FILE *handle = 
FioFOpenFile(textfile, 
"rb", dir, &filesize);
 
  327   if (handle == NULL) 
return;
 
  330   size_t read = fread(this->
text, 1, filesize, handle);
 
  333   if (read != filesize) 
return;
 
  335 #if defined(WITH_ZLIB) || defined(WITH_LZMA) 
  336   const char *suffix = strrchr(textfile, 
'.');
 
  337   if (suffix == NULL) 
return;
 
  340 #if defined(WITH_ZLIB) 
  342   if (strcmp(suffix, 
".gz") == 0) 
Gunzip((byte**)&this->
text, &filesize);
 
  345 #if defined(WITH_LZMA) 
  347   if (strcmp(suffix, 
".xz") == 0) 
Xunzip((byte**)&this->
text, &filesize);
 
  350   if (!this->
text) 
return;
 
  354   this->
text[filesize] = 
'\0';
 
  357   for (
char *p = this->
text; *p != 
'\0'; p++) {
 
  358     if (*p == 
'\t' || *p == 
'\r') *p = 
' ';
 
  362   char *p = this->
text + (strncmp(
"\xEF\xBB\xBF", this->
text, 3) == 0 ? 3 : 0);
 
  369   for (; *p != 
'\0'; p++) {
 
  388   static const char * 
const prefixes[] = {
 
  393   assert_compile(
lengthof(prefixes) == TFT_END);
 
  395   const char *prefix = prefixes[type];
 
  397   if (filename == NULL) 
return NULL;
 
  399   static char file_path[MAX_PATH];
 
  402   char *slash = strrchr(file_path, PATHSEPCHAR);
 
  403   if (slash == NULL) 
return NULL;
 
  405   static const char * 
const exts[] = {
 
  407 #if defined(WITH_ZLIB) 
  410 #if defined(WITH_LZMA) 
  415   for (
size_t i = 0; i < 
lengthof(exts); i++) {