Пример #1
0
/**
 * Compresses the input text and writes the compressed data to a file.
 * @param[in] filename name and path of the file to compress.
 * @param[in] compressed name and path of the compressed output file.
 * @param[in] algorithm the algorithm that will be used to build the suffix tree (Ukkonnen or Kurtz).
 * @param[in] see if see will be used.
 */
static void zip(char *filename, char *compressed, BOOL algorithm, int parts, BOOL see) {
  Uchar *origText, *prevText = NULL;
  Uint origTextLen, partTextLen, currentTextLen;
  FILE *compressed_file;
  int i, part;
  fsmTree_t stree = NULL, prevTree = NULL;
  BOOL alloc = False;

#ifdef WIN32
  HANDLE hndl;
  origText = (Uchar *) file2String(filename, &origTextLen, &hndl);
#else
  origText = (Uchar *) file2String(filename, &origTextLen);
#endif

  if(origText == NULL) {
    fprintf(stderr,"Cannot open file %s\n", filename);
    exit(EXIT_FAILURE);
  }
  /*if(textLen > MAXTEXTLEN)
    {
    fprintf(stderr,"Sorry, textlen = %lu is larger than maximal textlen = %lu\n",
    (Showuint) textLen,(Showuint) MAXTEXTLEN);
    exit(EXIT_FAILURE);
    }*/

  if (!compressed) {
    CALLOC(compressed, Uchar, strlen(filename) + 5);
    strcpy(compressed, filename);
    strcat(compressed, ".ctx");
    alloc = True;
  }

  compressed_file = fopen(compressed, "wb");
  if (!compressed_file) {
    printf( "Could not open output file");
    exit(1);
  }
  if (alloc) FREE(compressed);

  buildAlpha(origText, origTextLen);
  printf ("Alphasize: %ld\n", alphasize);
  printf("Algorithm %d\n", algorithm);

  setMaxCount();

  /* write magic number */
  putc(MAGIC >> 8, compressed_file);
  putc(MAGIC, compressed_file);
  /* write # of parts */
  putc(parts, compressed_file);

  initialize_output_bitstream();
  initialize_arithmetic_encoder();

  writeAlphabet(compressed_file);

  currentTextLen = 0;
  for (part = 1; part <= parts; part++) {
    printf("---------- part %d ---------------\n", part);
    if (part != parts) {
      partTextLen = floor(origTextLen / parts);
    }
    else {
      partTextLen = origTextLen - (floor(origTextLen / parts) * (parts - 1));
    }
 
    if (part > 1) {
      prevText = text;
      prevTree = stree;
    }

    textlen = partTextLen;
    CALLOC(text, Uchar, textlen);
    reversestring(origText + currentTextLen, textlen, text);
    
    if (algorithm == UKKONEN) {
      suffixTree_t tree = initSuffixTree();
      buildSuffixTree(tree);
      printf("Tree built\n");
      pruneSuffixTree(tree);
      stree = fsmSuffixTree(tree);   
    }
    else {
      stree = buildSTree();
      printf("Tree built\n");
    }

    /*if (part > 1) {
      copyStatistics(prevTree, stree, prevText);
      FREE(prevText);
      freeFsmTree(prevTree);
    }*/

    DEBUGCODE(printf("gamma hits: %d gamma Misses: %d\n", getHits(), getMisses()));
    printf("height: %ld\n", getHeight(stree));

    /* write textlen */
    for (i=3; i>=0; i--) {
      writeByte(textlen >> (8 * i), compressed_file);
    }
    printf ("Textlen: %ld\n", textlen);
    writeFsmTree(stree, compressed_file);
    printf("FSM...\n");
    makeFsm(stree);
    DEBUGCODE(printFsmTree(stree));
    printf("Encoding...\n");

    encode(stree, compressed_file, origText + currentTextLen, partTextLen, see);
    
    currentTextLen += partTextLen;
  }

  FREE(text);
  freeFsmTree(stree);

  flush_arithmetic_encoder(compressed_file);
  flush_output_bitstream(compressed_file);

#ifdef WIN32
  freetextspace(origText, hndl);
#else
  freetextspace(origText, origTextLen);
#endif

  fclose(compressed_file);
}
int QComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 24)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 24;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = isEditable(); break;
        case 1: *reinterpret_cast< int*>(_v) = count(); break;
        case 2: *reinterpret_cast< QString*>(_v) = currentText(); break;
        case 3: *reinterpret_cast< int*>(_v) = currentIndex(); break;
        case 4: *reinterpret_cast< int*>(_v) = maxVisibleItems(); break;
        case 5: *reinterpret_cast< int*>(_v) = maxCount(); break;
        case 6: *reinterpret_cast< InsertPolicy*>(_v) = insertPolicy(); break;
        case 7: *reinterpret_cast< SizeAdjustPolicy*>(_v) = sizeAdjustPolicy(); break;
        case 8: *reinterpret_cast< int*>(_v) = minimumContentsLength(); break;
        case 9: *reinterpret_cast< QSize*>(_v) = iconSize(); break;
        case 10: *reinterpret_cast< bool*>(_v) = autoCompletion(); break;
        case 11: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = autoCompletionCaseSensitivity(); break;
        case 12: *reinterpret_cast< bool*>(_v) = duplicatesEnabled(); break;
        case 13: *reinterpret_cast< bool*>(_v) = hasFrame(); break;
        case 14: *reinterpret_cast< int*>(_v) = modelColumn(); break;
        }
        _id -= 15;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setEditable(*reinterpret_cast< bool*>(_v)); break;
        case 3: setCurrentIndex(*reinterpret_cast< int*>(_v)); break;
        case 4: setMaxVisibleItems(*reinterpret_cast< int*>(_v)); break;
        case 5: setMaxCount(*reinterpret_cast< int*>(_v)); break;
        case 6: setInsertPolicy(*reinterpret_cast< InsertPolicy*>(_v)); break;
        case 7: setSizeAdjustPolicy(*reinterpret_cast< SizeAdjustPolicy*>(_v)); break;
        case 8: setMinimumContentsLength(*reinterpret_cast< int*>(_v)); break;
        case 9: setIconSize(*reinterpret_cast< QSize*>(_v)); break;
        case 10: setAutoCompletion(*reinterpret_cast< bool*>(_v)); break;
        case 11: setAutoCompletionCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break;
        case 12: setDuplicatesEnabled(*reinterpret_cast< bool*>(_v)); break;
        case 13: setFrame(*reinterpret_cast< bool*>(_v)); break;
        case 14: setModelColumn(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 15;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 15;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 15;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 15;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 15;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 15;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 15;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
void DisplayFilterCombo::updateMaxCount()
{
    setMaxCount(prefs.gui_recent_df_entries_max);
}
Пример #4
0
HistoryComboBox::HistoryComboBox(QWidget *parent):
    QComboBox(parent)
{
    setInsertPolicy(QComboBox::InsertAtTop);
    setMaxCount(10);
}