TInt CVBookmarkConverter::ReadAssignment( const TDesC8& aBuffer,
    TInt& aPosition, TPtrC8& aTag, TPtrC8& aValue )
    {
    LOGGER_ENTERFN( "CVBookmarkConverter::ReadAssignment" );    
        
    TPtrC8 start = aBuffer.Mid( aPosition );
    TInt assignment = start.Find( KVBMKAssignment );
    TInt linefeed = start.Find( KVBMKLinefeed );
    
    // Did we find the delimeter and the linefeed
    if ( ( assignment == KErrNotFound) || ( linefeed == KErrNotFound ) )
        {
        return KErrNotFound;
        }
    // Linefeed must reside behind the delimeter
    if ( linefeed <= assignment )
        {
        return KErrNotFound;
        }
    // Extract tag
    aTag.Set( start.Left( assignment ) );
    IgnoreSpaces( aTag );

    // Extract value
    aValue.Set( start.Mid( assignment + 1, ( linefeed - 1 ) - assignment ) );
    IgnoreSpaces( aValue );
    
    // update position
    aPosition += ( linefeed + KVBMKLinefeed().Length() );

    LOGGER_LEAVEFN( "CVBookmarkConverter::ReadAssignment" );        
    return KErrNone;
    }
Beispiel #2
0
CC_STRING CMaExpander::TryExpand()
{
	CToken token;
	CC_STRING outs;
	static int debug_level;
	CC_STRING saved_inStr = inStr;

	debug_level++;


	while(1) {
		const char *const last_pos  = pos;

		IgnoreSpaces();
		if( ! get_token(tc, &pos, &token, for_include) )
			break;
		if( token.attr == CToken::TA_IDENT ) {
			CMacro *ma;
			CC_STRING tmp;
			ma = GetMacro(token.id);
			if( IS_MACRO(ma) && ! in_defined_context() ) {
				if( IS_FLM(ma) ) {
					skip_blanks(pos);
					if( *pos == '(' ) {
						tmp = Expand_FLM(ma);
					}
					else
						goto do_cat;
				} else {
					tmp = Expand_OLM(ma);
				}

				const ssize_t offset = last_pos - inStr.c_str();
				CC_STRING newStr;
				
				newStr.strcat(inStr.c_str(), last_pos);
				newStr += tmp;
				newStr += pos;
				
				inStr = newStr;
				pos   = inStr.c_str() + offset;
			} else
				goto do_cat;
		} else {
		do_cat:
			outs.strcat(last_pos, pos);
		}
		last_ids[0] = last_ids[1];
		last_ids[1] = token.id;
	}

//	printf("Leave [%u] %s\n", debug_level, outs.c_str());
	--debug_level;
//	fprintf(stderr, "*** %u: %s => %s\n", debug_level, saved_inStr.c_str(), outs.c_str());

	return outs;
}
int main(int argc, char** argv)
{
    bool32 FlagActivated = 0;
    
    for(int i=0;
        i < argc;
        i++)
    {
        char Flag[MAX_FLAG_CHAR];  

        // NOTE: '-' Indicate that a flag name is what comes next
        if(argv[i][0] == '-')
        {
            int IndexArray = 0;
            for(argv[i][1];
                *argv[i];
                argv[i]++)
            {
                if (IndexArray < (MAX_FLAG_CHAR - 1))
                {
                    Flag[IndexArray] = *argv[i];
                    IndexArray++;
                }
            }

            if (CompareStrings(Flag, "-h", 2) == 0)
            {
                FlagActivated = FlagActivated|HELP_FLAG; //0x00      
                ShowHelpPage();
            }

            else if (CompareStrings(Flag, "-cc", 3) == 0)
            {
                FlagActivated = FlagActivated|CHANGE_TARGET_DIRECTORY_FLAG; // 0x01
            }

            else if (CompareStrings(Flag, "-s", 2) == 0)
            {
                FlagActivated = FlagActivated|SOURCE_FILE_FLAG; // 0x02
            }

            else
            {
                // logging
            }
        }

        // NOTE: '@' represents char that indicates that what comes next is an diretory
        else if(argv[i][0] == '@')
        {
                                    
        }
        
        else
        {
            // logging
        }
        
    }

    bool Running = true;
    bool ProjectAssigned = false;
    tree_directory *TreeRootDirectory;
    tree_directory *TreeActualDirectory;
    char PathToPrepend[MAX_PATH_SIZE]; 
    
    WelcomeMessage();

    while(Running)
    {

        char CommandLine[MAX_LINE_SIZE];
        char CLineLowerCase[MAX_LINE_SIZE];
        char CommandName[MAX_LINE_SIZE];
        char CommandAction[MAX_LINE_SIZE];
        
        printf("\nC-environment Shell> ");

        // TODO: Make space before first world do not count for the string comparisons
        gets_s(CommandLine, MAX_LINE_SIZE); 

        IgnoreSpaces(CommandLine, CharArrayCount(CommandLine));
        printf("CommandLine without spaces before: '%s'", CommandLine);

        
        BreakString(CommandLine, CharArrayCount(CLineLowerCase), CommandName,
                    CommandAction, SPACE_CHAR);
        ToLowerCase(CommandName, CLineLowerCase, MAX_LINE_SIZE);

#if 0
        // NOTE: Debug Lines
        printf("CommandLine: %s\tCLineLowerCase: %s\nCommandAction: %s",CommandLine,
               CLineLowerCase, CommandAction);
#endif


        // TODO: Program still have some problems with parsing the input with spaces before command 
        if(CompareStrings(CLineLowerCase, "setprojectname", sizeof("setprojectname")) == 0)
        {
            if (IS_EMPTY_STRING(CommandAction))
            {
                printf("\nAction for command '%s' not found\n Usage:\t'%s [Project Name]'\n",
                       CLineLowerCase, CLineLowerCase);
            }
            TreeRootDirectory = TreeDirectoryCreate(CommandAction);
            TreeActualDirectory = TreeRootDirectory;
            StringCopy(PathToPrepend, CommandAction, CharArrayCount(CommandAction));
            AppendString(PathToPrepend, "/");
            ProjectAssigned = true;
        }
        
        else if(CompareStrings(CLineLowerCase, "createdir", sizeof("createdir")) == 0)
        {
            char ActualPath[MAX_PATH_SIZE];
            StringCopy(ActualPath, PathToPrepend, CharArrayCount(PathToPrepend));
            
            if (ProjectAssigned && !IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Parse if the directory name is valid
                
                // TODO: Prevent PathToPrepend to grow 
                AppendString(PathToPrepend, CommandAction);
                AppendString(PathToPrepend, "/");
                
                // TODO: Virtual file system structured in a tree   
                tree_directory *TreeDirectory = TreeDirectoryCreate(ActualPath);

                // NOTE: More debug lines
                printf("Path: %s", ActualPath);
                printf("Path2: %s", TreeDirectory->PathName);
                
                TreeDirectoryAddNode(TreeActualDirectory, TreeDirectory);
            }

            else if (!ProjectAssigned)
            {
                // TODO: logging system
            }

            else if (IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Logging system
            }
            StringCopy(PathToPrepend, ActualPath, CharArrayCount(ActualPath));
        }

        // TODO: Not sure how to do pathfinder right now!
        else if(CompareStrings(CLineLowerCase, "setdir", sizeof("setdir")) == 0)
        {
            char *DirName = CommandAction;
            if (!IS_EMPTY_STRING(CommandAction))
            {
                if (TreeDirSearchBrother(TreeActualDirectory, DirName))
                {
                    AppendString(PathToPrepend, CommandAction);
                    AppendString(PathToPrepend, "/");

                    TreeDirGoToDirectory(TreeActualDirectory, DirName);
                }
            }
        }

        else if(CompareStrings(CLineLowerCase, "saveconfig", sizeof("saveconfig")) == 0)
        {
            // TODO: Save settings to a file, that can be evoked lately, or in any other
            // instance of the program
        }
        
        else if(CompareStrings(CLineLowerCase, "exit", sizeof("exit")) == 0)
        {
            Running = false;
        }

        else
        {
            printf("\nCommand not found. Type '-h' for help. Command 'exit' is self explanatory.\n");
        }
    }
    return 0;
}
TInt CVBookmarkConverter::ReadTagAndValue( const TDesC8& aBuffer, TInt& aPosition, 
    TPtrC8& aTag, TPtrC8& aValue, TPtrC8& aProperties )
    {
    LOGGER_ENTERFN( "CVBookmarkConverter::ReadTagAndValue" );   
    
    TPtrC8 start = aBuffer.Mid( aPosition );
    TInt delimeter = start.Find( KVBMKColon );
    TInt linefeed = start.Find( KVBMKLinefeed );
    TInt semicolon = start.Find( KVBMKSemicolon );
    
    
    // Did we find a linefeed?
    if ( linefeed == KErrNotFound )
        {
        // Check whether file ends without newline
        if( aBuffer.Length() <= ( aPosition + start.Length() ) )
            {
            // Set linefeed at the end of the file
            linefeed = start.Length();
            }
        else
            { 
            return KErrNotFound;
            }
        }

    // Did we find a semicolon?
    if ( semicolon != KErrNotFound )
        {
        // It must be before the delimeter (property identifiers reside in this block)
        if ( semicolon >= delimeter || semicolon < 0 )
            {
            semicolon = KErrNotFound;
            }
        }
    
    // Did we find the delimeter
    if( delimeter == KErrNotFound )
        {
        return KErrNotFound;
        }

    // Linefeed must reside behind the delimeter
    if ( linefeed <= delimeter )
        {
        return KErrNotFound;
        }
    
    aTag.Set( start.Left( semicolon != KErrNotFound ? semicolon : delimeter ) );
    IgnoreSpaces( aTag );

    // Extract value
    aValue.Set( start.Mid( delimeter + 1, (linefeed - 1) - delimeter ) );
    IgnoreSpaces( aValue );
    
    // Extract properties if found
    if ( semicolon != KErrNotFound )
        {
        aProperties.Set( start.Mid( semicolon, delimeter - semicolon ) );
        IgnoreSpaces( aProperties );
        }
    else
        {
        aProperties.Set( KVBMKNone() );
        }     
    
    // update position
    aPosition += ( linefeed + KVBMKLinefeed().Length() );
    
    LOGGER_LEAVEFN( "CVBookmarkConverter::ReadTagAndValue" );       
    return KErrNone;
    }