Esempio n. 1
0
bool IC_CmdLineParser::handleChar( wchar_t wc, WideString& cmdName, array<WideString>& args )
{
    static const wchar_t spaceChar = ( wchar_t )' ';
    static const wchar_t escapeChar = ( wchar_t )'\\';
    static const wchar_t quoteChar = ( wchar_t )'\"';
    if ( wc == spaceChar )
    {
      if ( !isQuoted() )
      {
        shoveTmpString( cmdName, args );
      }
      else
      {
        tmpString += ( spaceChar );
        bShouldAddLast = true;
      }
    }
    else if ( wc == quoteChar )
    {
      if ( isEscaped() )
      {
        tmpString += quoteChar;
        bShouldAddLast = true;
        setEscaped( false );
      }
      else if ( isQuoted() )
      {
        shoveTmpString( cmdName, args );
        setQuoted( false );
      }
      else
      {
        setQuoted( true );
      }
    }
    else if ( wc == escapeChar )
    {
      if ( isEscaped() )
      {
        tmpString += escapeChar;
        bShouldAddLast = true;
        setEscaped( false );
      }
      else
      {
        setEscaped( true );
      }
    }
    else
    {
      if ( isEscaped() )
      {
        return false;
      }
      tmpString += wc;
      bShouldAddLast = true;
    }
    return true;
}
Esempio n. 2
0
bool IC_CmdLineParser::parse( WideString& cmdName, array<WideString>& args )
{
    //  cout << "Parsing : [" << cmdLine << "]" << endl;
    static const wchar_t spaceChar = ( wchar_t )' ';
    args.clear();
    cmdName = L"";

    if ( cmdLine.findFirst( spaceChar ) == -1 )
    {
      cmdName = cmdLine;
      return true;
    }

    setQuoted( false );
    setEscaped( false );
    setNameDone( false );
    bShouldAddLast = true;
    resetTmpString();

    for ( s32 x = 0; x < cmdLine.size(); x++ )
    {
      if ( !handleChar( cmdLine[x], cmdName, args ) )
      {
        return false;
      }
    }
    if ( bShouldAddLast )
    {
      shoveTmpString( cmdLine, args );
    }
    return true;
}
Esempio n. 3
0
void getEncodeFlags (int argc, char *argv[]) {
    int maxBits = 12;
    int shouldPrune = 0;
    for (int i = 0; i < argc; i ++) {
        if (!strcmp(argv[i],"-e")){
            Escaped = 1;
            setEscaped();
        }
        else if (!strcmp(argv[i],"-p")){
            shouldPrune = 1;
            setShouldPrune();
        }
        else if (!strcmp(argv[i],"-m")){
            if (i + 1 < argc){
                char *endBuf = NULL;
                int newValue = strtol(argv[i + 1], &endBuf, 10);
                if (newValue <= 20 && newValue > 8) {
                    maxBits = newValue;
                    setMaxBits(maxBits);
                }
            }
        }
    }
    putBits(8, maxBits);
    if (Escaped == 1){
        putBits(1, 1);
    }
    else {
        putBits(1,0);
    }
    if (shouldPrune == 1){
        putBits(1, 1);
    }
    else {
        putBits(1,0);
    }
}
Esempio n. 4
0
void decode () {
    int possition = 0;
    int code = 9;
    Tree codeTrie;
    createT(&codeTrie);
    int codeCount = 1;
    int *outputString = malloc(sizeof(int));
    int *lastString = NULL;
    outputString[0] = -1;
    int * nextString = NULL;
    int bitsCount = 8;
    int getMaxBits = getBits(bitsCount);
    setMaxBits(getMaxBits);
    int Escaped = getBits(1);
    if (Escaped) {
        setEscaped();
    }
    else {
        initializeTrie(&codeTrie);
    }
    int shouldPrune = getBits(1);
    if (shouldPrune) {
        setShouldPrune();
    }
    while ((code = getBits(bitsCount)) != EOF) {
        if (code == 0 && Escaped) {
            int singleLetter = getBits(8);
            nextString = malloc(2 * sizeof(int));
            nextString[0] = singleLetter;
            nextString[1] = -1;
        }
        else {
            nextString = checkForNextCode(&codeTrie, code);
        }
        if (!nextString) {
            nextString = addLetterToStringNoFree(lastString, lastString[0]);
            
        }
        printArray(nextString);
        int *output = combine(outputString, nextString, possition);
        free(outputString);
        outputString = output;
        possition = addStringToTrie(&codeTrie, outputString, 0, &codeCount);
        int stringLength = arrayLen(nextString);
        if (lastString) {
            free(lastString);
            lastString = NULL;
        }
        lastString = malloc((arrayLen(nextString) + 1) * sizeof(int));
        for (int i = 0; nextString[i] != -1; i++) {
            lastString[i] = nextString[i];
        }
        lastString[stringLength] = -1;
        bitsCount = getBitsCount();
        free(nextString);
        nextString = NULL;
    }
    if (lastString) {
        free(lastString);
    }
    freeTrie(&codeTrie);
    free(outputString);
}