示例#1
0
/*
 * selectTag - select a tag from a list of possible tags
 */
static vi_rc selectTag( FILE *f, char *str, char *buff, char *fname )
{
    int         tagcnt;
    char        **taglist;
    int         i;
    int         whichtag;
    char        tag[MAX_STR];

    tagcnt = 0;
    taglist = NULL;

    for( ;; ) {
        RemoveLeadingSpaces( buff );
        taglist = MemReAlloc( taglist, sizeof( char * ) * (tagcnt + 1) );
        AddString( &taglist[tagcnt], buff );
        i = 0;
        while( !isspace( taglist[tagcnt][i] ) ) {
            i++;
        }
        taglist[tagcnt][i] = 0;
        tagcnt++;
        if( fgets( buff, MAX_STR, f ) == NULL )  {
            break;
        }
        if( NextWord1( buff, tag ) <= 0 ) {
            continue;
        }
        if( EditFlags.IgnoreTagCase ) {
            i = stricmp( str, tag );
        } else {
            i = strcmp( str, tag );
        }
        if( i ) {
            break;
        }
    }
    fclose( f );
    if( EditFlags.TagPrompt && EditFlags.WindowsStarted && tagcnt > 1 ) {
        whichtag = PickATag( tagcnt, taglist, str );
        if( whichtag < 0 ) {
            return( DO_NOT_CLEAR_MESSAGE_WINDOW );
        }
    } else {
        whichtag = 0;
    }
    taglist[whichtag][strlen( taglist[whichtag] )] = ' ';
    strcpy( buff, taglist[whichtag] );
    MemFreeList( tagcnt, taglist );

    if( NextWord1( buff, fname ) <= 0 ) {
        return( ERR_INVALID_TAG_FOUND );
    }
    buff[strlen( buff ) - 1] = 0;
    RemoveLeadingSpaces( buff );
    if( buff[0] == 0 ) {
        return( ERR_INVALID_TAG_FOUND );
    }
    return( ERR_NO_ERR );

} /* selectTag */
示例#2
0
bool 
NEWSArticle::StoreHeader(const string &line)
{
    // First we simply store the raw header string
    fHeader = line;

    // Now we try to disassemble the header and store it as such

    // Separate the lines
    vector<string> headerLines = GetTokens(fHeader,'\n');
    
    string fieldName  = "";
    string fieldValue = "";
    
    for(vector<string>::const_iterator
        itemIter  = headerLines.begin();
        itemIter != headerLines.end();
        itemIter ++)
    {
        string thisLine = (*itemIter);
        RemoveTrailingSpaces(thisLine);

        if (thisLine[0] != ' ' && thisLine[0] != '\t')
        {  // This means that this line is a new field
            int position = thisLine.find(":");

            fieldName.assign(thisLine,0,position);
            fieldValue.assign(thisLine.begin()+position+1,thisLine.end());

            RemoveLeadingSpaces(fieldName);
            RemoveTrailingSpaces(fieldName);

            RemoveLeadingSpaces(fieldValue);
            RemoveTrailingSpaces(fieldValue);
        
            // Store the field 
            fParsedHeaderFields.push_back(fieldName);
            fParsedHeaders[fieldName] = fieldValue;
        }
        else
        {  // This means that this line is a continuation of the previous line
            // Just append the extra data with a newline
            fParsedHeaders[fieldName] += "\n" + thisLine;
        }
    }

    string groupsField;
    if (GetHeaderField("Newsgroups",groupsField))
    {
        fNewsGroups = GetTokens(groupsField,',');
        fNrOfNewsGroups = fNewsGroups.size();
    }

    fState = NA_ONLY_HEADER;
    return true;
}
示例#3
0
vi_rc DoHelp( char *data )
{
    // Use the windows help till we get one of our own
    LPSTR vi_chmfile = "editor.chm";
    LPSTR vi_helpfile = "editor.hlp";
#ifdef __NT__
    //LPSTR win_helpfile = "api32wh.hlp";
    LPSTR win_helpfile = "win32sdk.hlp";
#else
    LPSTR win_helpfile = "win31wh.hlp";
#endif

    RemoveLeadingSpaces( data );
    if( !strcmp( data, "OnHelp" ) ) {
        WWinHelp( Root, NULL, HELP_HELPONHELP, (HELP_DATA)0 );
    } else if( !strcmp( data, "Contents" ) ) {
        if( !WHtmlHelp( Root, vi_chmfile, HELP_CONTENTS, (HELP_DATA)0 ) ) {
            WWinHelp( Root, vi_helpfile, HELP_CONTENTS, (HELP_DATA)0 );
        }
    } else if( !strcmp( data, "Search" ) ) {
        if( !WHtmlHelp( Root, vi_chmfile, HELP_PARTIALKEY, (HELP_DATA)"" ) ) {
            WWinHelp( Root, vi_helpfile, HELP_PARTIALKEY, (HELP_DATA)"" );
        }
    } else {
        WWinHelp( Root, win_helpfile, HELP_KEY, (HELP_DATA)data );
    }
    return ( ERR_NO_ERR );
}
示例#4
0
/*
 * GenTestCond - generate test condition for current statement
 */
void GenTestCond( void )
{
    char        v1[MAX_SRC_LINE];

    /*
     * process syntax of test condition
     * IF expr
     */
    strcpy( v1, CurrentSrcData );
    RemoveLeadingSpaces( v1 );
    if( v1[0] == 0 ) {
        AbortGen( ERR_SRC_INVALID_IF );
    }

    /*
     * build the if data structure
     */
#ifndef VICOMP
    if( EditFlags.CompileScript ) {
#endif
        genItem( SRC_T_IF, v1 );
#ifndef VICOMP
    } else {
        genItem( SRC_T_IF, NULL );
        AddString( &tmpTail->arg1, v1 );
    }
#endif

} /* GenTestCond */
示例#5
0
/*
 * EnterHexKey - enter a hexidecimal key stroke and insert it into the text
 */
vi_rc EnterHexKey( void )
{
    int         i;
    char        st[MAX_STR], val;
    vi_rc       rc;

    rc = ModificationTest();
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    if( CurrentLine->len >= EditVars.MaxLine - 1 ) {
        return( ERR_LINE_FULL );
    }

    rc = PromptForString( "Enter the number of char to insert:", st,
                          sizeof( st ) - 1, NULL );
    if( rc != ERR_NO_ERR ) {
        if( rc == NO_VALUE_ENTERED ) {
            return( ERR_NO_ERR );
        }
        return( rc );
    }

    /*
     * get value
     */
    RemoveLeadingSpaces( st );
    val = (char) strtol( st, NULL, 0 );
    if( val == 0 ) {
        return( ERR_INVALID_VALUE );
    }

    /*
     * build undo record
     */
    StartUndoGroup( UndoStack );
    CurrentLineReplaceUndoStart();
    CurrentLineReplaceUndoEnd( true );
    EndUndoGroup( UndoStack );

    /*
     * add the char
     */
    GetCurrentLine();
    for( i = WorkLine->len; i >= CurrentPos.column - 1; i-- ) {
        WorkLine->data[i + 1] = WorkLine->data[i];
    }
    WorkLine->data[CurrentPos.column - 1] = val;
    WorkLine->len++;
    DisplayWorkLine( true );
    if( CurrentPos.column < WorkLine->len ) {
        GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 );
    }
    ReplaceCurrentLine();
    EditFlags.Dotable = true;
    return( ERR_NO_ERR );

} /* EnterHexKey */
示例#6
0
void GetSpawnCommandLine( char *path, const char *cmdl, cmd_struct *cmds )
{
    char        orgcmd[MAX_INPUT_LINE];
    char        cmd[MAX_INPUT_LINE];
    char        full[FILENAME_MAX];
    char        drive[_MAX_DRIVE], directory[_MAX_DIR], name[_MAX_FNAME];
    char        ext[_MAX_EXT];
    int         i;
    bool        is_internal;

    strcpy( cmd, cmdl );
    strcpy( orgcmd, cmd );
    NextWord1( cmd, full );
    is_internal = false;

    strcpy( path, full );
    _splitpath( full, drive, directory, name, ext );
    if( ext[0] != 0 ) {
        if( drive[0] == 0 && directory[0] == 0 ) {
            GetFromEnv( full, path );
        }
    } else {
        if( drive[0] == 0 && directory[0] == 0 ) {
            for( i = 0; i < InternalCommandCount; i++ ) {
                if( !stricmp( full, InternalCommands[i] ) ) {
                    is_internal = true;
                    break;
                }
            }
        }
        if( !is_internal ) {
            for( i = 0; i < ExeExtensionCount; i++ ) {
                _makepath( full, drive, directory, name, ExeExtensions[i] );
                GetFromEnv( full, path );
                if( path[0] != 0 ) {
                    break;
                }
            }
        }
    }
    RemoveLeadingSpaces( cmd );
    _splitpath( full, drive, directory, name, ext );
    if( !stricmp( ext, ExeExtensions[0] ) || is_internal ) {
        strcpy( path, Comspec );
        strcpy( cmds->cmd, "/c " );
        strcat( cmds->cmd, orgcmd );
    } else {
        strcpy( cmds->cmd, cmd );
    }
    cmds->len = strlen( cmds->cmd );
    cmds->cmd[cmds->len] = 0x0d;
}
示例#7
0
vi_rc DoHelp( char *data )
{
    char        *hfile;
    char        *tstr;
    int         token;
    vi_rc       rc;
    char        path[FILENAME_MAX];
    char        tmp[MAX_STR];
    int         i;

    RemoveLeadingSpaces( data );
    token = Tokenize( helpCmds, data, false );
    if( token == TOK_INVALID ) {
        if( data[0] == 0 ) {
            strcpy( tmp, "Topics: " );
            for( i = 0; i < nHelpFiles; i++ ) {
                if( i != 0 ) {
                    strcat( tmp, ", " );
                }
                strcat( tmp, GetTokenString( helpCmds, i ) );
            }
            Message1( "%s", tmp );
        } else {
            Error( "No help on topic %s", data );
        }
        return( DO_NOT_CLEAR_MESSAGE_WINDOW );
    }
    hfile = helpFiles[token];
    GetFromEnv( hfile, path );
    if( path[0] == 0 ) {
        Error( "Help file %s not found", hfile );
        return( DO_NOT_CLEAR_MESSAGE_WINDOW );
    }
    EditFlags.ViewOnly = true;
    rc = EditFile( path, false );
    EditFlags.ViewOnly = false;
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    tstr = GetTokenString( helpCmds, token );
    strcpy( tmp, tstr );
    strlwr( tmp );
    strcat( tmp, " Help" );
    tmp[0] = toupper( tmp[0] );
    CurrentFile->read_only = false;
    AddString2( &(CurrentFile->name), tmp );
    SetFileWindowTitle( CurrentWindow, CurrentInfo, true );
    DisplayFileStatus();
    return( ERR_NO_ERR );

} /* DoHelp */
示例#8
0
/*
 * OpenWindowOnFile - open a window on a file
 */
vi_rc OpenWindowOnFile( char *data )
{
    char        *name;
    vi_rc       rc;
    window_id   wn;

    RemoveLeadingSpaces( data );
    name = data;
    if( data[0] == 0 ) {
        name = NULL;
    }
    wn = CurrentWindow;
    rc = NewFile( name, true );
    if( rc == ERR_NO_ERR ) {
        InactiveWindow( wn );
        DCDisplayAllLines();
    }
    return( rc );

} /* OpenWindowOnFile */
示例#9
0
/*
 * EditFile - read a file into text
 */
vi_rc EditFile( char *name, bool dammit )
{
    char        *fn, **list, *currfn;
    int         i, cnt, ocnt;
    int         j, len;
    window_id   wn = NO_WINDOW;
    char        cdir[FILENAME_MAX];
    info        *ci, *il;
    bool        usedir = false;
    char        mask[FILENAME_MAX];
    bool        reset_dir;
    int         index;
    char        *altname = NULL;
    vi_rc       rc;

    fn = MemAlloc( FILENAME_MAX );

    /*
     * get file name
     */
    strcpy( cdir, CurrentDirectory );
    reset_dir = false;
    RemoveLeadingSpaces( name );
    if( name[0] == '$' ) {
        EliminateFirstN( name, 1 );
        usedir = true;
    }
    fn[0] = 0;
//    if( NextWord1( name, fn ) <= 0 )
    if( GetStringWithPossibleQuote2( name, fn, false ) != ERR_NO_ERR ) {
        usedir = true;
        mask[0] = '*';
        mask[1] = 0;
    }
    if( usedir ) {
        if( EditFlags.ExMode ) {
            MemFree( fn );
            return( ERR_INVALID_IN_EX_MODE );
        }
        len = strlen( fn );
        if( len > 0 ) {
            i = len - 1;
            strcpy( mask, fn );
            cnt = 0;
            while( i >= 0 ) {
                if( fn[i] == FILE_SEP ) {
                    for( j = i + 1; j <= len; j++ ) {
                        mask[j - (i + 1)] = fn[j];
                    }
                    cnt = i;
                    break;
                }
                i--;
            }
            fn[cnt] = 0;
        }
        if( fn[0] != 0 ) {
            rc = SelectFileOpen( fn, &fn, mask, true );
        } else {
#ifdef __WIN__
            if( name[0] == '\0' ) {
                altname = MemAlloc( 1000 );
                rc = SelectFileOpen( CurrentDirectory, &altname, mask, true );
                NextWord1( altname, fn );  // if multiple, kill path
                if( isMultipleFiles( altname ) ) {
                    NextWord1( altname, fn ); // get 1st name
                }
            } else {
                rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
            }
#else
            rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
#endif
        }
        if( altname ) {
            name = altname;
        }

        if( rc != ERR_NO_ERR || fn[0] == 0 ) {
            MemFree( fn );
            SetCWD( cdir );
            return( rc );
        }
    }

    /*
     * loop through all files
     */
    rc = ERR_NO_ERR;
    EditFlags.WatchForBreak = true;
#ifdef __WIN__
    ToggleHourglass( true );
#endif
    do {
        if( IsDirectory( fn ) ) {
            if( EditFlags.ExMode ) {
                rc = ERR_INVALID_IN_EX_MODE;
                reset_dir = true;
                break;
            }
            rc = SelectFileOpen( fn, &fn, "*", false );
            if( rc != ERR_NO_ERR ) {
                reset_dir = true;
                break;
            }
            if( fn[0] == 0 ) {
                reset_dir = true;
                rc = ERR_NO_ERR;
                break;
            }
        }
        currfn = fn;
        ocnt = cnt = ExpandFileNames( currfn, &list );
        if( !cnt ) {
            cnt = 1;
        } else {
            currfn = list[0];
        }

        /*
         * loop through all expanded files
         */
        index = 1;
        while( cnt > 0 ) {
            cnt--;
            /*
             * quit current file if ! specified, else just save current state
             */
            if( dammit ) {
                ci = InfoHead;
                if( CurrentInfo == ci ) {
                    ci = ci->next;
                }
                RemoveFromAutoSaveList();
#ifdef __WIN__
                CloseAChildWindow( CurrentWindow );
#else
                CloseAWindow( CurrentWindow );
#endif
                FreeUndoStacks();
                FreeMarkList();
                FreeEntireFile( CurrentFile );
                MemFree( DeleteLLItem( (ss **)&InfoHead, (ss **)&InfoTail,
                         (ss *)CurrentInfo ) );
                CurrentInfo = NULL;
                CurrentWindow = NO_WINDOW;
            } else {
                ci = CurrentInfo;
                SaveCurrentInfo();
                wn = CurrentWindow;
            }

            /*
             * see if new file is already being edited
             */
            SaveCurrentInfo();
            for( il = InfoHead; il != NULL; il = il->next ) {
                if( SameFile( il->CurrentFile->name, currfn ) ) {
                    break;
                }
                if( strcmp( CurrentDirectory, il->CurrentFile->home ) ) {
                    /* directory has changed -- check with full path
                     * note that this will fail if an absolute path
                     * was specified thus we do the regular check first */
                    char path[FILENAME_MAX];
                    char drive[_MAX_DRIVE];
                    char dir[_MAX_DIR];
                    char fname[_MAX_FNAME];
                    char ext[_MAX_EXT];

                    _splitpath( il->CurrentFile->name, drive, dir, fname, ext );
                    if( !strlen( drive ) ) {
                        _splitpath( il->CurrentFile->home, drive, NULL, NULL, NULL );
                    }
                    if( !strlen( dir ) ) {
                        _splitpath( il->CurrentFile->home, NULL, dir, NULL, NULL );
                    } else if( dir[0] != '\\' ) {
                        char dir2[_MAX_DIR];
                        _splitpath( il->CurrentFile->home, NULL, dir2, NULL, NULL );
                        strcat( dir2, dir );
                        strcpy( dir, dir2 );
                    }
                    _makepath( path, drive, dir, fname, ext );

                    if( SameFile( path, currfn ) ) {
                        break;
                    }
                }
            }

            if( il != NULL ) {
                BringUpFile( il, true );
            } else {
                /*
                 * file not edited, go get it
                */
                rc = NewFile( currfn, false );
                if( rc != ERR_NO_ERR && rc != NEW_FILE ) {
                    RestoreInfo( ci );
                    DCDisplayAllLines();
                    break;
                }
                if( !dammit ) {
                    InactiveWindow( wn );
                }
                if( EditFlags.BreakPressed ) {
                    break;
                }
            }
            if( cnt > 0 ) {
                currfn = list[index];
                index++;
            }
        }

        if( ocnt > 0 ) {
            MemFreeList( ocnt, list );
        }
        if( EditFlags.BreakPressed ) {
            ClearBreak();
            break;
        }

    } while( NextWord1( name, fn ) > 0 );

    if( altname ) {
        MemFree( altname );
    }
    MemFree( fn );

#ifdef __WIN__
    ToggleHourglass( false );
#endif
    EditFlags.WatchForBreak = false;
    if( reset_dir ) {
        SetCWD( cdir );
    }
    return( rc );

} /* EditFile */
示例#10
0
文件: strmix.cpp 项目: alexlav/conemu
string&  WINAPI RemoveExternalSpaces(string &strStr)
{
	return RemoveTrailingSpaces(RemoveLeadingSpaces(strStr));
}
示例#11
0
文件: strmix.cpp 项目: alexlav/conemu
wchar_t* WINAPI RemoveExternalSpaces(wchar_t *Str)
{
	return RemoveTrailingSpaces(RemoveLeadingSpaces(Str));
}
示例#12
0
HeaderMatcher::HeaderMatcher(
        IniFile *settings,
        const string sectionName,
        const string valueName)
    : Printable("HeaderMatcher")
    , ArticleImpactChecker(settings)
{
    fObjectIsValid  = true;

    fRegExpression = NULL;

    // Copy the parameters
    fIniSectionName = sectionName;
    fIniValueName   = valueName;

    // Initialize the Cooked values
    fHeaderName    = "";
    fHeaderValue   = "";
    fLastMatchDate = fNow;
    fMatchCount    = 0;
    fImpactValue   = 100; // Default Impact value
    fSearchCaseINSensitive = false;

    // Quick check of the parameters
    if (fSettings    == NULL ||
        fIniSectionName == ""   ||
        fIniValueName   == "")
    {
        fObjectIsValid = false;
        return;
    }

    // ----------
    // Split the fIniValueName into the required parts
    // There should be two possibilities:
    // Casesensitive matching
    //    fieldname:valuetomatch
    // Case INsensitive matching
    //    ~fieldname:valuetomatch

    // First check if searching case insensitive.
    string parseValueName = fIniValueName;
    if (parseValueName[0] == '~')
    {
        fSearchCaseINSensitive = true;
        // Remove "~"
        parseValueName.erase(parseValueName.begin()); 
    }

    // Now split at the first ':'
    unsigned long colonPosition = parseValueName.find(":");

    if (colonPosition == parseValueName.npos)
    {   // The header doesn't include a ':' --> Not a header !! 
        fObjectIsValid = false;
        Lerror << "Invalid \"" << sectionName 
               << "\" header matching line : \"" 
               << valueName << "\"." << endl << flush;
        return;
    }

    fHeaderName.assign (parseValueName,0,colonPosition);
    fHeaderValue.assign(parseValueName.begin() + colonPosition + 1,parseValueName.end());


    // ----------
    // Try to compile the header value that should be matched
    regbase::flag_type cflags = regbase::normal;
    if (fSearchCaseINSensitive)
        cflags |= regbase::icase;

    try 
    {
        fRegExpression = new regex(fHeaderValue, cflags);
    }

    catch (bad_expression)
    {
        fObjectIsValid = false;
        Lerror << "Invalid regular expression \"" << fHeaderValue 
               << "\". Check the suckmt config file" << endl << flush;
        char inistr[100];
        std::sprintf(inistr,"%s ; %5ld ; %5ld ; INVALID REGULAR EXPRESSION !!",fLastMatchDate.c_str(),fMatchCount,fImpactValue);
        fSettings->SetValue(fIniSectionName, fIniValueName, inistr);
        return;
    }

    // ----------
    // Now get the statistics parameters for the matching process
    if (fSettings->GetValue(fIniSectionName,fIniValueName,fIniValue))
    {
        // ----------
        // Split the value into the required parts
        vector<string> iniValueList = GetTokens(fIniValue,';');

        switch (iniValueList.size())
        {
            case 3: StringToLong(iniValueList[2],fImpactValue);
            case 2: StringToLong(iniValueList[1],fMatchCount);
            case 1: RemoveLeadingSpaces(iniValueList[0]);
                    RemoveTrailingSpaces(iniValueList[0]);
                    fLastMatchDate = iniValueList[0];
        }
    }

    char inistr[100];
    std::sprintf(inistr,"%s ; %5ld ; %5ld",fLastMatchDate.c_str(),fMatchCount,fImpactValue);
    fSettings->SetValue(fIniSectionName, fIniValueName, inistr);
}
示例#13
0
/*
 * SelectLineInFile - select a line in a given file
 */
vi_rc SelectLineInFile( selflinedata *sfd )
{
    int         i, winflag;
    int         leftcol = 0, key2;
    bool        done = FALSE, redraw = TRUE;
    bool        hiflag = FALSE, drawbord = FALSE;
    int         farx, text_lines;
    linenum     pagetop = 1, lln = 1;
    char        tmp[MAX_STR];
    hilst       *ptr;
    linenum     cln;
    linenum     endline;
    vi_rc       rc;
    vi_key      key;

    /*
     * create the window
     */
    cln = sfd->cln;
    endline = sfd->f->fcbs.tail->end_line;
    farx = sfd->wi->x2;
    if( sfd->show_lineno ) {
        farx++;
    }
    if( sfd->hilite != NULL ) {
        hiflag = TRUE;
    }
    rc = NewWindow2( &cWin, sfd->wi );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    if( !sfd->is_menu ) {
        WindowAuxUpdate( cWin, WIND_INFO_HAS_SCROLL_GADGETS, TRUE );
        DrawBorder( cWin );
    }
    oWin = sfd->eiw;
    isMenu = sfd->is_menu;
    PushMouseEventHandler( SelectLineMouseHandler );
    KillCursor();
    text_lines = WindowAuxInfo( cWin, WIND_INFO_TEXT_LINES );
    sfd->sl = -1;
    if( sfd->title != NULL ) {
        WindowTitle( cWin, sfd->title );
    }
    pagetop = text_lines * (cln / text_lines);
    if( cln % text_lines != 0 ) {
        pagetop++;
    }
    key = 0;
    if( LastEvent == VI_KEY( MOUSEEVENT ) ) {
        DisplayMouse( TRUE );
    }

    /*
     * now, allow free scrolling and selection
     */
    while( !done ) {

        if( redraw ) {
            if( sfd->show_lineno ) {
                MySprintf(tmp, "%l/%l", cln, endline );
                i = sfd->wi->x2 - sfd->wi->x1;
                WindowBorderData( cWin, tmp, i - strlen( tmp ) );
                drawbord = TRUE;
            }
            if( hiflag ) {
                ptr = sfd->hilite;
                ptr += cln - 1;
                if( ptr->_char == (char)-1 ) {
                    if( cln > lln ) {
                        cln++;
                    } else if( cln < lln ) {
                        cln--;
                    }
                }
            }
            if( drawbord ) {
                DrawBorder( cWin );
            }
            displayGenericLines( sfd->f, pagetop, leftcol, cln, &(sfd->wi->hilight), sfd->hilite, sfd->vals, sfd->valoff );
        }
        lln = cln;
        redraw = TRUE;
        drawbord = FALSE;
        mouseLine = -1;
        rlMenu = FALSE;
        if( key == VI_KEY( MOUSEEVENT ) ) {
            DisplayMouse( TRUE );
        }
        key = GetNextEvent( TRUE );
        if( hiflag && ((key >= VI_KEY( ALT_A ) && key <= VI_KEY( ALT_Z )) ||
                       (key >='a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
                       (key >= '1' && key <= '9')) ) {
            i = 0;
            if( key >= VI_KEY( ALT_A ) && key <= VI_KEY( ALT_Z ) ) {
                key2 = key - VI_KEY( ALT_A ) + 'A';
            } else if( key >= 'a' && key <= 'z' ) {
                key2 = key - 'a' + 'A';
            } else {
                key2 = key;
            }
            ptr = sfd->hilite;
            while( ptr->_char != '\0' ) {
                if( toupper( ptr->_char ) == key2 ) {
                    cln = i + 1;
                    key = VI_KEY( ENTER );
                    break;
                }
                ++i;
                ++ptr;
            }
        }

        /*
         * check if a return-event has been selected
         */
        if( sfd->retevents != NULL ) {
            i = 0;
            if( key == VI_KEY( MOUSEEVENT ) ) {
                if( mouseWin == oWin && LastMouseEvent == MOUSE_PRESS ) {
                    DisplayMouse( FALSE );
                    sfd->event = sfd->retevents[mouseLine];
                    key = VI_KEY( ENTER );
                }
            } else {
                while( sfd->retevents[i] != 0 ) {
                    if( key == sfd->retevents[i] ) {
                        sfd->event = key;
                        key = VI_KEY( ENTER );
                        break;
                    }
                    i++;
                }
            }
        }

        /*
         * process key stroke
         */
        switch( key ) {
        case VI_KEY( MOUSEEVENT ):
            DisplayMouse( FALSE );
            if( hiflag ) {
                ptr = sfd->hilite;
                ptr += mouseLine;
                if( ptr->_char == (char) -1 ) {
                    break;
                }
            }
            if( rlMenu && sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = rlMenuNum;
                done = TRUE;
                break;
            }
            if( mouseScroll != MS_NONE ) {
                switch( mouseScroll ) {
                case MS_UP: goto evil_up;
                case MS_DOWN: goto evil_down;
                case MS_PAGEUP: goto evil_pageup;
                case MS_PAGEDOWN: goto evil_pagedown;
                case MS_EXPOSEDOWN:
                    adjustCLN( &cln, &pagetop, pagetop + text_lines - cln - 1, endline, text_lines );
                    adjustCLN( &cln, &pagetop, 1, endline, text_lines );
                    drawbord = TRUE;
                    break;
                case MS_EXPOSEUP:
                    adjustCLN( &cln, &pagetop, pagetop - cln, endline, text_lines );
                    adjustCLN( &cln, &pagetop, -1, endline, text_lines );
                    drawbord = TRUE;
                    break;

                }
                break;
            }
            switch( LastMouseEvent ) {
            case MOUSE_DRAG:
                if( mouseWin != cWin ) {
                    break;
                }
                cln = mouseLine + pagetop;
                break;
            case MOUSE_RELEASE:
                if( !sfd->is_menu ) {
                    break;
                }
                if( mouseWin == cWin ) {
                    cln = mouseLine + pagetop;
                    if( cln <= endline ) {
                        goto evil_enter;
                    }
                }
                break;
            case MOUSE_DCLICK:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                } else {
                    cln = mouseLine + pagetop;
                    if( cln <= endline ) {
                        goto evil_enter;
                    }
                }
                break;
            case MOUSE_PRESS_R:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                }
                break;
            case MOUSE_PRESS:
                if( mouseWin != cWin ) {
                    AddCurrentMouseEvent();
                    done = TRUE;
                } else {
                    cln = mouseLine + pagetop;
                }
                break;
            }
            break;

        case VI_KEY( ESC ):
            done = TRUE;
            break;

        evil_enter:
        case VI_KEY( ENTER ):
        case ' ':
            /*
             * see if we need to do a callback for this
             */
            if( sfd->checkres != NULL ) {
                line    *cline;
                fcb     *cfcb;
                char    data[64];

                i = cln - 1;
                GimmeLinePtr( cln, sfd->f, &cfcb, &cline );
                strcpy( data, cline->data );
                RemoveLeadingSpaces( data );
                winflag = FALSE;
                strcpy( tmp, sfd->vals[i] );
                rc = sfd->checkres( data, tmp, &winflag );
                if( winflag ) {
                    if( winflag == 2 ) {
                        winflag = TRUE;
                    } else {
                        winflag = FALSE;
                    }
                }
                if( winflag ) {
                    MoveWindowToFront( cWin );
                }
                if( rc == ERR_NO_ERR ) {
                    AddString2( &(sfd->vals[i]), tmp );
                    redraw = TRUE;
                }
                break;

            /*
             * no value window, so just return line selected
             */
            } else {
                if( isMenu && InvokeMenuHook( CurrentMenuNumber, cln ) == -1 ) {
                    break;
                }
                sfd->sl = cln;
                done = TRUE;
            }
            break;

        case VI_KEY( LEFT ):
        case 'h':
            if( sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = -1;
                done = TRUE;
            }
            break;

        case VI_KEY( RIGHT ):
        case 'l':
            if( sfd->allow_rl != NULL ) {
                *(sfd->allow_rl) = 1;
                done = TRUE;
            }
            break;

        evil_up:
        case VI_KEY( UP ):
        case 'k':
            drawbord = adjustCLN( &cln, &pagetop, -1, endline, text_lines );
            break;

        evil_down:
        case VI_KEY( DOWN ):
        case 'j':
            drawbord = adjustCLN( &cln, &pagetop, 1, endline, text_lines );
            break;

        case VI_KEY( CTRL_PAGEUP ):
            drawbord = adjustCLN( &cln, &pagetop, -cln + 1, endline, text_lines );
            break;

        case VI_KEY( CTRL_PAGEDOWN ):
            drawbord = adjustCLN( &cln, &pagetop, endline - cln, endline, text_lines );
            break;

        evil_pageup:
        case VI_KEY( PAGEUP ):
        case VI_KEY( CTRL_B ):
            drawbord = adjustCLN( &cln, &pagetop, -text_lines, endline, text_lines );
            break;

        evil_pagedown:
        case VI_KEY( PAGEDOWN ):
        case VI_KEY( CTRL_F ):
            drawbord = adjustCLN( &cln, &pagetop, text_lines, endline, text_lines );
            break;

        case VI_KEY( HOME ):
            drawbord = TRUE;
            cln = 1;
            pagetop = 1;
            break;

        case VI_KEY( END ):
            drawbord = TRUE;
            cln = endline;
            pagetop = endline - text_lines + 1;
            if( pagetop < 1 ) {
                pagetop = 1;
            }
            break;

        default:
            redraw = FALSE;
            break;

        }

    }
    PopMouseEventHandler();
    CloseAWindow( cWin );
    RestoreCursor();
    SetWindowCursor();
    return( rc );

} /* SelectLineInFile */
示例#14
0
void MenuFileToList(DList<UserMenuItem> *Menu, File& MenuFile, GetFileString& GetStr, uintptr_t MenuCP = CP_UNICODE)
{
	INT64 Pos = MenuFile.GetPointer();
	if (!Pos)
	{
		if (!GetFileFormat(MenuFile,MenuCP))
			MenuCP = CP_OEMCP;
	}

	LPWSTR MenuStr = nullptr;
	int MenuStrLength = 0;
	UserMenuItem *MenuItem = nullptr;

	while (GetStr.GetString(&MenuStr, MenuCP, MenuStrLength))
	{
		RemoveTrailingSpaces(MenuStr);

		if (!*MenuStr)
			continue;

		if (*MenuStr==L'{' && MenuItem && MenuItem->Menu)
		{
			MenuFileToList(MenuItem->Menu, MenuFile, GetStr, MenuCP);
			MenuItem = nullptr;
			continue;
		}

		if (*MenuStr==L'}')
			break;

		if (!IsSpace(*MenuStr))
		{
			wchar_t *ChPtr = nullptr;

			if (!(ChPtr=wcschr(MenuStr,L':')))
				continue;

			MenuItem = Menu->Push();

			*ChPtr = 0;
			MenuItem->strHotKey = MenuStr;
			MenuItem->strLabel = ChPtr+1;
			RemoveLeadingSpaces(MenuItem->strLabel);
			MenuItem->Submenu = (GetStr.PeekString(&MenuStr, MenuCP, MenuStrLength) && *MenuStr==L'{');

			if (MenuItem->Submenu)
				MenuItem->Menu = new DList<UserMenuItem>();

			// Support for old 1.x separator format
			if (MenuCP==CP_OEMCP && MenuItem->strHotKey==L"-" && MenuItem->strLabel.IsEmpty())
			{
				MenuItem->strHotKey += L"-";
			}
		}
		else if (MenuItem)
		{
			RemoveLeadingSpaces(MenuStr);
			string *str = MenuItem->Commands.Push();
			*str = MenuStr;
		}
	}
}
示例#15
0
/*
 * MapKey - set up a key mapping
 */
vi_rc MapKey( int flag, char *data )
{
    char        keystr[MAX_STR];
    key_map     *maps;
    int         j;
    vi_key      key;
    vi_rc       rc;

#ifndef VICOMP
    if( !EditFlags.ScriptIsCompiled || (flag & MAPFLAG_UNMAP) ) {
#endif
        rc = readKeyData();
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
#ifndef VICOMP
    }
#endif

    /*
     * get if it is an input/regular key mapping
     */
    if( flag & MAPFLAG_DAMMIT ) {
        maps = InputKeyMaps;
    } else {
        maps = KeyMaps;
    }

    if( NextWord1( data, keystr ) <= 0 ) {
        return( ERR_INVALID_MAP );
    }
    RemoveLeadingSpaces( data );

    /*
     * get key we are using
     */
#ifndef VICOMP
    if( !EditFlags.ScriptIsCompiled || (flag & MAPFLAG_UNMAP) ) {
#endif
        j = Tokenize( charTokens, keystr, TRUE );
        if( j == TOK_INVALID ) {
            key = (unsigned char)keystr[0];
        } else {
            key = keyVals[j];
        }
        if( key >= MAX_EVENTS ) {
            return( ERR_INVALID_KEY );
        }
#ifndef VICOMP
    } else {
        long    keyl;

        keyl = atol( keystr );
        if( keyl < 0 || keyl >= MAX_EVENTS ) {
            return( ERR_INVALID_KEY );
        }
        key = (vi_key)keyl;
    }
#endif

#ifndef VICOMP
    if( EditFlags.CompileScript ) {
#endif
        if( !(flag & MAPFLAG_UNMAP) ) {
            key_map     scr;

            rc = AddKeyMap( &scr, data );
            if( rc == ERR_NO_ERR ) {
                if( scr.no_input_window ) {
                    MySprintf( WorkLine->data, "%d \\x%s", key, scr.data );
                } else {
                    MySprintf( WorkLine->data, "%d %s", key, scr.data );
                }
            }
            MemFree( scr.data );
            return( rc );

        } else {
            MySprintf( WorkLine->data, "%d %s", key, data );
            return( ERR_NO_ERR );
        }
#ifndef VICOMP
    }

    maps[key].inuse = FALSE;
    maps[key].is_base = FALSE;
    MemFree( maps[key].data );
    maps[key].data = NULL;
    if( !(flag & MAPFLAG_UNMAP ) ) {
        if( flag & MAPFLAG_BASE ) {
            maps[key].is_base = TRUE;
        }
        return( AddKeyMap( &maps[key], data ) );
    }
    return( ERR_NO_ERR );
#endif

} /* MapKey */
示例#16
0
/*
 * AutoSaveInit - initialize for auto-save
 */
void AutoSaveInit( void )
{
    char        path[FILENAME_MAX];
    char        path2[FILENAME_MAX];
    char        as_path[FILENAME_MAX];
    char        asl_path[FILENAME_MAX];
    int         len;
    int         cnt;
    FILE        *f;
    int         pid;
    int         ch;
    int         handle;
    int         off;
//    int         old_len;
    int         i;

    /*
     * initialize tmpname
     */
#ifdef __UNIX__
    strcpy( currTmpName,"aaaaaaaaaaaa.tmp" );
#else
    strcpy( currTmpName,"aaaaaaaa.tmp" );
#endif
    pid = getpid();
    itoa( pid, path, 36 );
    len = strlen( path );
    memcpy( &currTmpName[TMP_FNAME_LEN - len], path, len );
#ifdef __QNX__
    {
        int     len2, len3;
        int     nid, uid;

        nid = getnid();
        itoa( nid, path, 36 );
        len2 = strlen( path );
        memcpy( &currTmpName[TMP_FNAME_LEN - len - len2], path, len2 );

        uid = getuid();
        itoa( uid, path, 36 );
        len3 = strlen( path );
        memcpy( &currTmpName[TMP_FNAME_LEN - len - len2 - len3], path, len3 );
        memcpy( &checkFileName[EXTRA_EXT_OFF], path, len3 );
        memcpy( &checkFileTmpName[EXTRA_EXT_OFF], path, len3 );
        memcpy( &lockFileName[EXTRA_EXT_OFF], path, len3 );
    }
#endif

    /*
     * check if we need to recover lost files
     */
    if( EditFlags.RecoverLostFiles ) {
        cnt = 0;
        MakeTmpPath( as_path, checkFileName );
        MakeTmpPath( asl_path, lockFileName );
        off = strlen( as_path ) - 5;
        for( ch = START_CHAR; ch <= END_CHAR; ch++ ) {
            as_path[off] = ch;
            asl_path[off] = ch;
            handle = sopen3( as_path, O_RDONLY | O_TEXT, SH_DENYRW );
            if( handle < 0 ) {
                continue;
            }
            f = fdopen( handle, "r" );
            if( f != NULL ) {
                while( fgets( path2, FILENAME_MAX, f ) != NULL ) {
                    for( i = strlen( path2 ); i && isWSorCtrlZ( path2[i - 1] ); --i ) {
                        path2[i - 1] = '\0';
                    }
                    NextWord1( path2, path );
                    RemoveLeadingSpaces( path2 );
                    NewFile( path, FALSE );
                    AddString2( &(CurrentFile->name), path2 );
                    SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE );
                    FileSPVAR();
                    CurrentFile->modified = TRUE;
                    CurrentFile->check_readonly = TRUE;
                    FTSRunCmds( path2 );
                    cnt++;
                }
                fclose( f );
                remove( as_path );
            } else {
                close( handle );
            }
            remove( asl_path );
        }
        if( cnt == 0 ) {
            MyPrintf( "No files recovered!\n" );
            ExitEditor( -1 );
        }
        Message1( "%d files recovered", cnt );

    }
    if( EditVars.AutoSaveInterval == 0 ) {
        return;
    }

//    old_len = strlen( lockFileName );
    MakeTmpPath( path, lockFileName );
    len = strlen( path ) - strlen( lockFileName );
    off = len + CHAR_OFF;
    for( ch = START_CHAR; ch <= END_CHAR; ch++ ) {
        path[off] = ch;
        lockFileHandle = sopen4( path, O_CREAT | O_TRUNC | O_RDWR | O_TEXT, SH_DENYRW, PMODE_RW );
        if( lockFileHandle > 0 ) {
            break;
        }
    }
    if( lockFileHandle < 0 ) {
        // MyPrintf( "Too many editors running!\n" );
        MyPrintf( "Error opening temp file - '%s'\n", strerror( errno ) );
        ExitEditor( -1 );
    }
    lockFileName[CHAR_OFF] = ch;
    checkFileName[CHAR_OFF] = ch;
    checkFileTmpName[CHAR_OFF] = ch;

} /* AutoSaveInit */
示例#17
0
/*
 * processSetToken - set value for set token
 */
static vi_rc processSetToken( int j, char *value, int *winflag, bool isnonbool )
{
    char        fn[MAX_STR], str[MAX_STR];
#ifndef VICOMP
    char        tmp[3];
    char        settokstr[TOK_MAX_LEN + 1];
    char        save[MAX_STR];
    vi_rc       rc = ERR_NO_ERR;
    int         i, clr, k;
    bool        newset;
    bool        set1, toggle, *ptr;
    jmp_buf     jmpaddr;
    cursor_type ct;
    char        *name;
    command_rtn fptr;
    event_bits  eb;
    bool        redisplay = FALSE;
#endif
    bool        bvalue;

#ifdef VICOMP
    winflag = winflag;
    isnonbool = isnonbool;
#endif
    /*
     * set up value for boolean set commands
     */
    if( j < 0 ) {
        j *= -1;
        bvalue = FALSE;
    } else {
        bvalue = TRUE;
    }
#ifndef VICOMP
    if( !(*winflag) ) {
        toggle = TRUE;
        set1 = isnonbool;
    } else {
        toggle = FALSE;
#endif
        if( j >= SET1_T_ ) {
#ifndef VICOMP
            if( EditFlags.CompileScript ) {
#endif
                if( !bvalue ) {
                    j *= -1;
                }
                itoa( j, str, 10 );
                StrMerge( 2, WorkLine->data, str, SingleBlank );
                return( ERR_NO_ERR );
#ifndef VICOMP
            }
            set1 = FALSE;
            j -= SET1_T_;
        } else {
            set1 = TRUE;
#endif
        }
#ifndef VICOMP
    }
    *winflag = FALSE;

    /*
     * process boolean settings
     */
    if( !set1 ) {
        if( j >= SET2_T_ ) {
            return( ERR_INVALID_SET_COMMAND );
        }
        ptr = &(((bool *)&EditFlags)[j]);
        newset = bvalue;
        if( toggle ) {
            newset = !(*ptr);
        }
        switch( j ) {
        case SET2_T_MODELESS:
            if( (newset && !EditFlags.Modeless) ||
                (!newset && EditFlags.Modeless) ) {
                for( k = 0; k < MAX_EVENTS; k++ ) {
                    fptr = EventList[k].rtn;
                    eb = EventList[k].b;
                    EventList[k].rtn = EventList[k].alt_rtn;
                    EventList[k].alt_rtn = fptr;
                    EventList[k].b = EventList[k].alt_b;
                    EventList[k].alt_b = eb;
                }
                if( !EditFlags.Modeless ) {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_INSERT );
                    }
                    EditFlags.WasOverstrike = FALSE;
                    NewCursor( CurrentWindow, EditVars.InsertCursorType );
                } else {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_COMMAND );
                    }
                    NewCursor( CurrentWindow, EditVars.NormalCursorType );
                    // nomodeless must be line based or it dies!
                    EditFlags.LineBased = TRUE;
                }
                /* re-position cursor in window
                */
                SetWindowCursor();
            }
            EditFlags.Modeless = newset;
            break;
        case SET2_T_UNDO:
            if( EditFlags.Undo && !newset ) {
                FreeAllUndos();
            }
            EditFlags.Undo = newset;
            break;
        case SET2_T_STATUSINFO:
            EditFlags.StatusInfo = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            rc = NewStatusWindow();
            break;
        case SET2_T_WINDOWGADGETS:
            EditFlags.WindowGadgets = newset;
            ResetAllWindows();
            *winflag = TRUE;
            redisplay = TRUE;
            break;
        case SET2_T_REALTABS:
            EditFlags.RealTabs = newset;
            redisplay = TRUE;
            break;
        case SET2_T_CLOCK:
            EditFlags.Clock = newset;
            redisplay = TRUE;
            break;
        case SET2_T_TOOLBAR:
            EditFlags.Toolbar = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            break;
        case SET2_T_COLORBAR:
            EditFlags.Colorbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Colorbar = FALSE;
            } else {
                RefreshColorbar();
            }
#endif
            break;
        case SET2_T_SSBAR:
            EditFlags.SSbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.SSbar = FALSE;
            } else {
                RefreshSSbar();
            }
#endif
            break;
        case SET2_T_FONTBAR:
            EditFlags.Fontbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Fontbar = FALSE;
            } else {
                RefreshFontbar();
            }
#endif
            break;
        case SET2_T_MARKLONGLINES:
            EditFlags.MarkLongLines = newset;
            break;
        case SET2_T_MENUS:
            EditFlags.Menus = newset;
            InitMenu();
            break;
        case SET2_T_LINENUMBERS:
            if( toggle ) {
                newset = !EditFlags.LineNumbers;
            }
            if( newset != EditFlags.LineNumbers ) {
                EditFlags.LineNumbers = newset;
                rc = LineNumbersSetup();
                *winflag = TRUE;
            }
            break;
        case SET2_T_CURRENTSTATUS:
            EditFlags.CurrentStatus = newset;
            InitMenu();
            break;
        case SET2_T_DISPLAYSECONDS:
            EditFlags.DisplaySeconds = newset;
            redisplay = TRUE;
            break;
        case SET2_T_PPKEYWORDONLY:
            EditFlags.PPKeywordOnly = newset;
            redisplay = TRUE;
            break;
        case SET2_T_LASTEOL:
#ifndef __WIN__
            *ptr = TRUE;
            toggle = FALSE;
            break;
#endif
        default:
            *ptr = newset;
            break;
        }
        if( msgFlag ) {
            if( !newset ) {
                tmp[0] = 'n';
                tmp[1] = 'o';
                tmp[2] = 0;
            } else {
                tmp[0] = 0;
            }
            MySprintf( fn, "%s%s set", tmp, GetTokenStringCVT( SetTokens2, j, settokstr, TRUE ) );
        }
        if( toggle ) {
            strcpy( save, BoolStr[(int) newset] );
            (*winflag) += 1;
        }

    /*
     * process value settings
     */
    } else {
        if( toggle ) {
            rc = GetNewValueDialog( value );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            strcpy( save, value );
        }
#endif /* VICOMP */
        RemoveLeadingSpaces( value );
        if( value[0] == '"' ) {
            NextWord( value, fn, "\"" );
            EliminateFirstN( value, 1 );
        } else {
            NextWord1( value, fn );
        }
#ifndef VICOMP
        if( EditFlags.CompileScript ) {
#endif
            itoa( j, str, 10 );
            strcat( WorkLine->data, str );
            if( fn[0] == '\0' )
                return( ERR_NO_ERR );
            switch( j ) {
            case SET1_T_STATUSSTRING:
            case SET1_T_FILEENDSTRING:
            case SET1_T_HISTORYFILE:
            case SET1_T_TMPDIR:
            case SET1_T_TAGFILENAME:
                StrMerge( 4, WorkLine->data, SingleBlank, SingleQuote, fn, SingleQuote );
                break;
            case SET1_T_COMMANDCURSORTYPE:
            case SET1_T_OVERSTRIKECURSORTYPE:
            case SET1_T_INSERTCURSORTYPE:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            case SET1_T_TILECOLOR:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( NextWord1( value, str ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StrMerge( 4, WorkLine->data, fn, SingleBlank, str, SingleBlank );
                break;
            case SET1_T_STATUSSECTIONS:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                while( NextWord1( value, fn ) > 0 ) {
#ifdef VICOMP
                    int k;
#endif
                    k = atoi( fn );
                    if( k <= 0 ) {
                        break;
                    }
                    StrMerge( 2, WorkLine->data, SingleBlank, fn );
                }
                break;
            default:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            }
            return( ERR_NO_ERR );
#ifndef VICOMP
        }
        switch( j ) {
        case SET1_T_STATUSSECTIONS:
            if( EditVars.StatusSections != NULL ) {
                MemFree( EditVars.StatusSections );
                EditVars.StatusSections = NULL;
                EditVars.NumStatusSections = 0;
            }
            for( ;; ) {
                k = atoi( fn );
                if( k <= 0 ) {
                    break;
                }
                EditVars.StatusSections = MemReAlloc( EditVars.StatusSections,
                                    sizeof( short ) * (EditVars.NumStatusSections + 1) );
                EditVars.StatusSections[EditVars.NumStatusSections] = k;
                EditVars.NumStatusSections++;
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
            }
            if( EditVars.StatusSections == NULL ) {
                MySprintf( fn, "statussections turned off" );
            } else {
                MySprintf( fn, "statussections set" );
            }
            break;
        case SET1_T_FILEENDSTRING:
            AddString2( &EditVars.FileEndString, fn );
            ResetAllWindows();
            redisplay = TRUE;
            break;
        case SET1_T_STATUSSTRING:
            AddString2( &EditVars.StatusString, fn );
            if( StatusWindow != NO_WINDOW ) {
                ClearWindow( StatusWindow );
                UpdateStatusWindow();
            }
            if( msgFlag ) {
                MySprintf( fn, "statusstring set to %s", EditVars.StatusString );
            }
            break;
        case SET1_T_GREPDEFAULT:
            AddString2( &EditVars.GrepDefault, fn );
            break;
        case SET1_T_TILECOLOR:
            if( EditVars.TileColors == NULL ) {
                EditVars.TileColors = (type_style *) MemAlloc( sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( i = 0; i <= EditVars.MaxTileColors; ++i ) {
                    EditVars.TileColors[i].foreground = -1;
                    EditVars.TileColors[i].background = -1;
                    EditVars.TileColors[i].font = -1;
                }
            }
            clr = atoi( fn );
            if( clr > EditVars.MaxTileColors ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].foreground = atoi( fn );
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].background = atoi( fn );
            EditVars.TileColors[clr].font = FONT_DEFAULT;
            if( msgFlag ) {
                MySprintf( fn, "tilecolor %d set", clr );
            }
            break;
        case SET1_T_GADGETSTRING:
            SetGadgetString( fn );
            if( msgFlag ) {
                MySprintf( fn, "gadget string set to %s", EditVars.GadgetString );
            }
            ResetAllWindows();
            break;
        case SET1_T_SHELLPROMPT:
            AddString2( &EditVars.SpawnPrompt, fn );
            if( msgFlag ) {
                MySprintf( fn, "prompt string set to %s", EditVars.SpawnPrompt );
            }
            break;
        case SET1_T_FIGNORE:
            if( fn[0] == 0 ) {
                MemFreePtr( (void **)&EditVars.FIgnore );
                EditVars.CurrFIgnore = 0;
                if( msgFlag ) {
                    MySprintf( fn, "fignore reset" );
                }
            } else {
                EditVars.FIgnore = MemReAlloc( EditVars.FIgnore, EXTENSION_LENGTH * (EditVars.CurrFIgnore + 1) );
                str[0] = '.';
                str[1] = 0;
                strcat( str, fn );
                str[EXTENSION_LENGTH - 1] = 0;
                strcpy( &EditVars.FIgnore[EXTENSION_LENGTH * EditVars.CurrFIgnore], str );
                EditVars.CurrFIgnore++;
                if( msgFlag ) {
                    MySprintf( fn, "%s added to fignore", str );
                }
            }
            break;
        case SET1_T_HISTORYFILE:
            AddString2( &EditVars.HistoryFile, fn );
            if( msgFlag ) {
                MySprintf( fn, "history file set to %s", EditVars.HistoryFile );
            }
            break;

        case SET1_T_TAGFILENAME:
            AddString2( &EditVars.TagFileName, fn );
            if( msgFlag ) {
                MySprintf( fn, "tag file name set to %s", EditVars.TagFileName );
            }
            break;

        case SET1_T_FILENAME:
            if( CurrentFile != NULL ) {
                AddString2( &(CurrentFile->name), fn );
                SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE );
                if( msgFlag ) {
                    MySprintf( fn, "filename set to %s", CurrentFile->name );
                }
                FileSPVAR();
            }
            break;
        case SET1_T_TMPDIR:
            AddString2( &EditVars.TmpDir, fn );
            VerifyTmpDir();
            if( msgFlag ) {
                MySprintf( fn, "tmpdir set to %s", EditVars.TmpDir );
            }
            break;
        case SET1_T_WORD:
            AddString2( &EditVars.WordDefn, fn );
            InitWordSearch( EditVars.WordDefn );
            if( msgFlag ) {
                MySprintf( fn, "word set to %s", EditVars.WordDefn );
            }
            break;
        case SET1_T_WORDALT:
            AddString2( &EditVars.WordAltDefn, fn );
            if( msgFlag ) {
                MySprintf( fn, "wordalt set to %s", EditVars.WordAltDefn );
            }
            break;
        case SET1_T_MAGICSTRING:
            AddString2( &EditVars.Majick, fn );
            if( msgFlag ) {
                MySprintf( fn, "magicstring set to %s", EditVars.Majick );
            }
            break;
        case SET1_T_COMMANDCURSORTYPE:
        case SET1_T_OVERSTRIKECURSORTYPE:
        case SET1_T_INSERTCURSORTYPE:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            ct.height = GetConstExpr();
            if( NextWord1( value, fn ) <= 0 ) {
                ct.width = 100;
            } else {
                i = setjmp( jmpaddr );
                if( i != 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StartExprParse( fn, jmpaddr );
                ct.width = GetConstExpr();
            }
            if( j == SET1_T_COMMANDCURSORTYPE ) {
                EditVars.NormalCursorType = ct;
                name = "command";
            } else if( j == SET1_T_OVERSTRIKECURSORTYPE ) {
                EditVars.OverstrikeCursorType = ct;
                name = "overstrike";
            } else {
                EditVars.InsertCursorType = ct;
                name = "insert";
            }
            if( msgFlag ) {
                MySprintf( fn, "%s cursor type set to %d,%d", name,
                                ct.height, ct.width );
            }
            break;
        default:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            i = GetConstExpr();
            if( i < 0 ) {
                i = 0;
            }
            switch( j ) {
            case SET1_T_WRAPMARGIN:
                EditVars.WrapMargin = i;
                break;
            case SET1_T_CURSORBLINKRATE:
                SetCursorBlinkRate( i );
                break;
            case SET1_T_MAXPUSH:
                EditVars.MaxPush = i;
                if( EditVars.MaxPush < 1 ) {
                    EditVars.MaxPush = 1;
                }
                InitFileStack();
                break;
            case SET1_T_RADIX:
                EditVars.Radix = i;
                break;
            case SET1_T_AUTOSAVEINTERVAL:
                EditVars.AutoSaveInterval = i;
                SetNextAutoSaveTime();
                break;
            case SET1_T_LANGUAGE:
                if( i < LANG_NONE || i >= LANG_MAX ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( CurrentInfo != NULL ) {
                    LangFini( CurrentInfo->fsi.Language );
                    LangInit( i );
                    redisplay = TRUE;
                }
                break;
            case SET1_T_MOVECOLOR:
                EditVars.MoveColor = i;
                break;
            case SET1_T_RESIZECOLOR:
                EditVars.ResizeColor = i;
                break;
            case SET1_T_MOUSEDCLICKSPEED:
                EditVars.MouseDoubleClickSpeed = i;
                break;
            case SET1_T_MOUSESPEED:
                SetMouseSpeed( i );
                break;
            case SET1_T_MOUSEREPEATDELAY:
                EditVars.MouseRepeatDelay = i;
                break;
            case SET1_T_CURRENTSTATUSCOLUMN:
                EditVars.CurrentStatusColumn = i;
                InitMenu();
                break;
            case SET1_T_ENDOFLINECHAR:
                EditVars.EndOfLineChar = i;
                break;
            case SET1_T_EXITATTR:
                EditVars.ExitAttr = (char) i;
                break;
            case SET1_T_INACTIVEWINDOWCOLOR:
                EditVars.InactiveWindowColor = i;
                break;
            case SET1_T_TABAMOUNT:
                EditVars.TabAmount = i;
                break;
            case SET1_T_SHIFTWIDTH:
                EditVars.ShiftWidth = i;
                break;
            case SET1_T_PAGELINESEXPOSED:
                EditVars.PageLinesExposed = i;
                break;
            case SET1_T_HARDTAB:
                EditVars.HardTab = i;
                redisplay = TRUE;
                break;
            case SET1_T_STACKK:
                if( EditFlags.Starting ) {
                    EditVars.StackK = i;
                }
                break;
            case SET1_T_LINENUMWINWIDTH:
                EditVars.LineNumWinWidth = i;
                break;
            case SET1_T_MAXWINDOWTILEX:
                EditVars.MaxWindowTileX = i;
                break;
            case SET1_T_MAXWINDOWTILEY:
                EditVars.MaxWindowTileY = i;
                break;
            case SET1_T_MAXSWAPK:
                SwapBlockInit( i );
                break;
            case SET1_T_MAXEMSK:
#ifndef NOEMS
                EMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXXMSK:
#ifndef NOXMS
                XMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXFILTERHISTORY:
                FilterHistInit( i );
                break;
            case SET1_T_MAXCLHISTORY:
                CLHistInit( i );
                break;
            case SET1_T_MAXFINDHISTORY:
                FindHistInit( i );
                break;
            case SET1_T_MAXLASTFILESHISTORY:
                LastFilesHistInit( i );
                break;
            case SET1_T_MAXTILECOLORS:
                k = (EditVars.TileColors == NULL) ? 0 : EditVars.MaxTileColors + 1;
                EditVars.MaxTileColors = i;
                EditVars.TileColors = MemReAlloc( EditVars.TileColors, sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( ; k <= EditVars.MaxTileColors; ++k ) {
                    EditVars.TileColors[k].foreground = -1;
                    EditVars.TileColors[k].background = -1;
                    EditVars.TileColors[k].font = -1;
                }
                break;
            case SET1_T_CLOCKX:
                EditVars.ClockX = i;
                GetClockStart();
                break;
            case SET1_T_CLOCKY:
                EditVars.ClockY = i;
                GetClockStart();
                break;
            case SET1_T_SPINX:
                EditVars.SpinX = i;
                GetSpinStart();
                break;
            case SET1_T_SPINY:
                EditVars.SpinY = i;
                GetSpinStart();
                break;
            case SET1_T_MAXLINELEN:
                /* file save fails if 1 line is > MAX_IO_BUFFER */
                i = __min( i, MAX_IO_BUFFER );
                EditVars.MaxLine = i;
                StaticStart();
                WorkLine = MemReAlloc( WorkLine, sizeof( line ) + EditVars.MaxLine + 2 );
                break;
            case SET1_T_TOOLBARBUTTONHEIGHT:
                EditVars.ToolBarButtonHeight = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARBUTTONWIDTH:
                EditVars.ToolBarButtonWidth = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARCOLOR:
                EditVars.ToolBarColor = i;
#ifdef __WIN__
                if( GetToolbarWindow() != NULL ) {
                    InvalidateRect( GetToolbarWindow(), NULL, TRUE );
                    UpdateWindow( GetToolbarWindow() );
                }
#endif
                break;
            default:
                return( ERR_INVALID_SET_COMMAND );
            }

            if( msgFlag ) {
                MySprintf( fn, "%s set to %d", GetTokenStringCVT( SetTokens1, j, settokstr, TRUE ), i );
            }
            break;
        }
    }

    if( msgFlag && rc == ERR_NO_ERR && !EditFlags.Quiet ) {
        setMessage( fn, redisplay );
        rc = DO_NOT_CLEAR_MESSAGE_WINDOW;
    }
    if( rc == ERR_NO_ERR && toggle ) {
        strcpy( value, save );
    }
    return( rc );
#endif /* VICOMP */

} /* processSetToken */
示例#18
0
/*
 * Set - set editor control variable
 */
vi_rc Set( char *name )
{
    char        fn[MAX_STR];
    vi_rc       rc = ERR_NO_ERR;
    int         j, i;
#ifndef VICOMP
#ifndef __WIN__
    int         tmp, tc;
    char        **vals = NULL;
    char        **list;
    int         longest;
#endif
#endif

    /*
     * get item to set
     */
#ifndef VICOMP
    msgFlag = FALSE;
    if( !EditFlags.ScriptIsCompiled ) {
#endif
        RemoveLeadingSpaces( name );
        j = strlen( name );
        for( i = 0; i < j; i++ ) {
            if( name[i] == '=' || name[i] == ',' ) {
                name[i] = ' ';
            }
        }
#ifndef VICOMP
    }
#endif

    if( NextWord1( name, fn ) <=0 ) {
#ifndef VICOMP
        if( !EditFlags.WindowsStarted ) {
            return( ERR_NO_ERR );
        }
#ifndef __WIN__
        tc = getSetInfo( &vals, &list, &longest );
        tmp = setw_info.y2;
        i = setw_info.y2 - setw_info.y1 + 1;
        if( setw_info.has_border ) {
            i -= 2;
        }
        if( tc < i ) {
            setw_info.y2 -= (i - tc);
        }
        rc = SelectItemAndValue( &setw_info, "Settings", list,
                          tc, SettingSelected, 1, vals, longest + 3 );
        setw_info.y2 = tmp;
        MemFreeList( tc, vals );
        MemFreeList( tc, list );
        ReDisplayScreen();
#endif
#endif /* VICOMP */
        return( rc );
    } else {
#ifndef VICOMP
        if( !EditFlags.Starting) {
            msgFlag = TRUE;
        }
#endif
        do {
#ifndef VICOMP
            if( !EditFlags.ScriptIsCompiled ) {
#endif
                if( tolower( fn[0] ) == 'n' && tolower( fn[1] ) == 'o' ) {
                    EliminateFirstN( fn, 2 );
                    i = -1;
                } else {
                    i = 1;
                }
                j = Tokenize( SetTokens1, fn, FALSE );
                if( j == TOK_INVALID ) {
                    j = Tokenize( SetTokens2a, fn, FALSE );
                    if( j == TOK_INVALID ) {
                        j = Tokenize( SetTokens2, fn, FALSE );
                        if( j == TOK_INVALID ) {
                            return( ERR_INVALID_SET_COMMAND );
                        }
                    }
                    j += SET1_T_;
                }
                j *= i;
#ifndef VICOMP
            } else {
                j = atoi( fn );
            }
#endif
            i = TRUE;
            rc = processSetToken( j, name, &i, FALSE );
            if( rc > ERR_NO_ERR ) {
                break;
            }
            RemoveLeadingSpaces( name );
        } while( NextWord1( name, fn ) > 0 );
#ifndef VICOMP
        if( msgFlag ) {
            putMessage();
        }
#endif
        return( rc );
    }

} /* Set */
示例#19
0
/*
 * PreProcess - pre-process source file
 */
vi_rc PreProcess( const char *fn, sfile **sf, labels *lab )
{
    GENERIC_FILE        gf;
    int                 i, token, k, len;
    sfile               *tsf;
    char                tmp[MAX_SRC_LINE], tmp2[MAX_SRC_LINE];
    char                tmp3[MAX_SRC_LINE];
    bool                ret;
#ifdef VICOMP
    bool                AppendingFlag = FALSE;
#else
    #define             AppendingFlag   EditFlags.Appending
#endif

    /*
     * get source file
     */
#ifdef VICOMP
    ret = SpecialOpen( fn, &gf );
#else
    if( EditFlags.CompileScript ) {
        EditFlags.OpeningFileToCompile = TRUE;
        ret = SpecialOpen( fn, &gf, FALSE );
        EditFlags.OpeningFileToCompile = FALSE;
    } else {
        ret = SpecialOpen( fn, &gf, EditFlags.BoundData );
    }
#endif
    if( !ret ) {
        return( ERR_FILE_NOT_FOUND );
    }

    /*
     * init control
     */
    CSInit();
    CurrentSrcLine = 0L;

    tsf = MemAlloc( sizeof( sfile ) );
    tsf->next = NULL;
    tsf->prev = NULL;
    tsf->arg1 = NULL;
    tsf->arg2 = NULL;
    tsf->data = NULL;
    tsf->token = SRC_T_NULL;
    *sf = tmpTail = tsf;
    cLab = lab;

    /*
     * set up error handler
     */
    i = setjmp( genExit );
    if( i != 0 ) {
        SpecialFclose( &gf );
        return( (vi_rc)i );
    }

    /*
     * process each line
     */
    while( SpecialFgets( tmp, MAX_SRC_LINE - 1, &gf ) >= 0 ) {

        /*
         * prepare this line
         */
        CurrentSrcLine++;
#ifndef VICOMP
        if( !EditFlags.ScriptIsCompiled ) {
#endif
            RemoveLeadingSpaces( tmp );
            k = strlen( tmp );
            memcpy( tmp3, tmp, k + 1 );
            if( (len = NextWord1( tmp, tmp2 )) <= 0 ) {
                continue;
            }
            if( tmp2[0] == '#' ) {
                continue;
            }
            hasVar = FALSE;
            for( i = 0; i < k; i++ ){
                if( tmp3[i] == '%' ) {
                    hasVar = TRUE;
                    break;
                }
            }

            /*
             * if we are appending (ie, an append token was encounterd
             * before, stop tokenizing
             */
            if( !AppendingFlag ) {
                token = Tokenize( SourceTokens, tmp2, TRUE );
#ifndef VICOMP
                if( token == SRC_T_VBJ__ ) {
                    EditFlags.ScriptIsCompiled = TRUE;
                    continue;
                }
#endif
            } else {
                token = TOK_INVALID;
            }
#ifndef VICOMP
        } else {
            len = NextWord1( tmp, tmp2 );
            hasVar = (bool) tmp2[0] - '0';
            token = atoi( &tmp2[1] );
        }
#endif
        /*
         * process recognized tokens
         */
        if( token != TOK_INVALID ) {

            RemoveLeadingSpaces( tmp );
            if( token > SRC_T_NULL ) {
                genItem( token, tmp );
                continue;
            }

            /*
             * get parm
             */
            AddString( &CurrentSrcData, tmp );
            freeSrcData = TRUE;

            /*
             * process token
             */
            switch( token ) {
            case SRC_T_EXPR:
                genExpr();
                break;
            case SRC_T_LABEL:
                GenLabel( tmp );
                break;
            case SRC_T_IF:
                CSIf();
                break;
            case SRC_T_QUIF:
                CSQuif();
                break;
            case SRC_T_ELSEIF:
                CSElseIf();
                break;
            case SRC_T_ELSE:
                CSElse();
                break;
            case SRC_T_ENDIF:
                CSEndif();
                break;
            case SRC_T_LOOP:
                CSLoop();
                break;
            case SRC_T_ENDLOOP:
            case SRC_T_ENDWHILE:
                CSEndLoop();
                break;
            case SRC_T_WHILE:
                CSWhile();
                break;
            case SRC_T_UNTIL:
                CSUntil();
                break;
            case SRC_T_BREAK:
                CSBreak();
                break;
            case SRC_T_CONTINUE:
                CSContinue();
                break;
            default:
                genItem( token, NULL );
                if( token == SRC_T_GOTO ) {
#ifndef VICOMP
                    if( EditFlags.ScriptIsCompiled ) {
                        NextWord1( CurrentSrcData, tmp );
                        tmpTail->branchcond = atoi( CurrentSrcData );
                        strcpy( CurrentSrcData, tmp );
                    } else {
#endif
                        tmpTail->branchcond = COND_JMP;
#ifndef VICOMP
                    }
#endif
                }
                tmpTail->data = CurrentSrcData;
                freeSrcData = FALSE;
                break;
            }
            if( freeSrcData ) {
                MemFree( CurrentSrcData );
            }
        /*
         * set all other tokens to be processed at run time
         */
        } else {
#ifndef VICOMP
            if( EditFlags.ScriptIsCompiled ) {
                RemoveLeadingSpaces( tmp );
                genItem( token, tmp );
                continue;
            }
#endif
            if( !AppendingFlag ) {
                token = Tokenize( TokensCmdLine, tmp2, TRUE );
            } else {
                token = TOK_INVALID;
            }
            switch( token ) {
            case PCL_T_COMMANDWINDOW:
            case PCL_T_STATUSWINDOW:
            case PCL_T_COUNTWINDOW:
            case PCL_T_EDITWINDOW:
            case PCL_T_EXTRAINFOWINDOW:
            case PCL_T_FILECWINDOW:
            case PCL_T_LINENUMBERWINDOW:
            case PCL_T_DIRWINDOW:
            case PCL_T_FILEWINDOW:
            case PCL_T_SETWINDOW:
            case PCL_T_SETVALWINDOW:
            case PCL_T_MESSAGEWINDOW:
            case PCL_T_MENUWINDOW:
            case PCL_T_MENUBARWINDOW:
            case PCL_T_ENDWINDOW:
            case PCL_T_SETCOLOR:
            case PCL_T_MATCH:
            case PCL_T_DIMENSION:
            case PCL_T_BORDER:
            case PCL_T_HILIGHT:
            case PCL_T_TEXT:
            case PCL_T_ALIAS:
            case PCL_T_ABBREV:
            case PCL_T_MENU:
            case PCL_T_MENUITEM:
            case PCL_T_ENDMENU:
            case PCL_T_WHITESPACE:
            case PCL_T_SELECTION:
            case PCL_T_EOFTEXT:
            case PCL_T_KEYWORD:
            case PCL_T_OCTAL:
            case PCL_T_HEX:
            case PCL_T_INTEGER:
            case PCL_T_CHAR:
            case PCL_T_PREPROCESSOR:
            case PCL_T_SYMBOL:
            case PCL_T_INVALIDTEXT:
            case PCL_T_IDENTIFIER:
            case PCL_T_JUMPLABEL:
            case PCL_T_COMMENT:
            case PCL_T_FLOAT:
            case PCL_T_STRING:
            case PCL_T_VARIABLE:
            case PCL_T_FILETYPESOURCE:
            case PCL_T_ENDFILETYPESOURCE:
            case PCL_T_LOCATE:
            case PCL_T_MAP:
            case PCL_T_MAP_DMT:

            case PCL_T_MENUFILELIST:
            case PCL_T_MENULASTFILES:

            case PCL_T_DEFAULTWINDOW:
            case PCL_T_ACTIVEMENUWINDOW:
            case PCL_T_GREYEDMENUWINDOW:
            case PCL_T_ACTIVEGREYEDMENUWINDOW:
                RemoveLeadingSpaces( tmp );
                token += SRC_T_NULL + 1;
                genItem( token, tmp );
                break;

            case PCL_T_SET:
                token += SRC_T_NULL + 1;
#ifdef VICOMP
                WorkLine->data[0] = 0;
                Set( tmp );
                genItem( token, WorkLine->data );
#else
                if( EditFlags.CompileScript ) {
                    vi_rc   rc;

                    WorkLine->data[0] = 0;
                    rc = Set( tmp );
                    if( rc != ERR_NO_ERR ) {
                        Error( GetErrorMsg( rc ) );
                    }
                    genItem( token, WorkLine->data );
                } else {
                    genItem( token, tmp );
                }
#endif
                break;

            default:
                if( AppendingFlag ) {
                    if( tmp3[0] == '.' && tmp3[1] == 0 ) {
                        AppendingFlag = FALSE;
                    }
                } else if( token == TOK_INVALID ) {
                    /*
                     * see if the current token is a Ex token.  If
                     * it isn't, then see if the next one is
                     * (i.e., look for <n> append)
                     */
                    token = Tokenize( TokensEx, tmp2, FALSE );
                    if( token == TOK_INVALID ) {
                        if( NextWord1( tmp, tmp2 ) >= 0 ) {
                            token = Tokenize( TokensEx, tmp2, FALSE );
                            if( token == EX_T_APPEND ) {
                                AppendingFlag = TRUE;
                            }
                        }
                    }
                }
                if( tmp3[0] == '>' ) {
                    tmp3[0] = ' ';
                }
                genItem( TOK_INVALID, tmp3 );
                break;
            }
        }

    }

    SpecialFclose( &gf );
    AppendingFlag = FALSE;
    return( CSFini() );

} /* PreProcess */
示例#20
0
/*
 * genExpr - gen an expression assignment
 */
static void genExpr( void )
{
    char        v1[MAX_SRC_LINE], v2[MAX_SRC_LINE], tmp[MAX_SRC_LINE];
#ifndef VICOMP
    expr_oper   oper = EXPR_EQ;
#endif

    /*
     * get expression syntax :
     * EXPR %v = v1
     */
    if( NextWord1( CurrentSrcData, v1 ) <= 0 ) {
        AbortGen( ERR_SRC_INVALID_EXPR );
    }
    if( NextWord1( CurrentSrcData, tmp ) <= 0 ) {
        AbortGen( ERR_SRC_INVALID_EXPR );
    }
    if( tmp[1] == '=' && tmp[2] == 0 ) {
        switch( tmp[0] ) {
#ifndef VICOMP
        case '+': oper = EXPR_PLUSEQ; break;
        case '-': oper = EXPR_MINUSEQ; break;
        case '*': oper = EXPR_TIMESEQ; break;
        case '/': oper = EXPR_DIVIDEEQ; break;
#else
        case '+': break;
        case '-': break;
        case '*': break;
        case '/': break;
#endif
        default:
            AbortGen( ERR_SRC_INVALID_EXPR );
            break;
        }
    } else {
        if( tmp[0] != '=' || tmp[1] != 0 ) {
            AbortGen( ERR_SRC_INVALID_EXPR );
        }
    }
    strcpy( v2, CurrentSrcData );
    RemoveLeadingSpaces( v2 );
    if( v2[0] == 0 ) {
        AbortGen( ERR_SRC_INVALID_EXPR );
    }
#ifndef VICOMP
    if( EditFlags.CompileScript ) {
#endif
        genItem( SRC_T_EXPR, StrMerge( 4, v1, SingleBlank, tmp, SingleBlank, v2 ) );
#ifndef VICOMP
    } else {
        /*
         * build the expr data structure
         */
        genItem( SRC_T_EXPR, NULL );
        tmpTail->u.oper = oper;
        AddString( &tmpTail->arg1, v1 );
        AddString( &tmpTail->arg2, v2 );
    }
#endif

} /* genExpr */
示例#21
0
/*
 * RemoveFromAutoSaveList - take a file that we are quitting out of the list
 */
void RemoveFromAutoSaveList( void )
{
    FILE        *f, *f2;
    char        as_path[FILENAME_MAX];
    char        as2_path[FILENAME_MAX];
    char        path[FILENAME_MAX];
    char        path2[FILENAME_MAX];
    char        data[FILENAME_MAX];
//    bool        found;
    int         i;

    if( EditVars.AutoSaveInterval == 0 ) {
        return;
    }
    if( CurrentFile == NULL ) {
        return;
    }
    if( !CurrentFile->been_autosaved ) {
        return;
    }

    MakeTmpPath( as_path, checkFileName );
    MakeTmpPath( as2_path, checkFileTmpName );

    GetCurrentFilePath( path );

//    found = FALSE;
    f = fopen( as_path, "r" );
    if( f == NULL ) {
        return;
    }
    f2 = fopen( as2_path, "w" );
    if( f2 == NULL ) {
        fclose( f );
        return;
    }
    while( fgets( path2, FILENAME_MAX, f ) != NULL ) {
        for( i = strlen( path2 ); i && isWSorCtrlZ( path2[i - 1] ); --i ) {
            path2[i - 1] = '\0';
        }
        NextWord1( path2, data );
        RemoveLeadingSpaces( path2 );
        if( !strcmp( path, path2 ) ) {
            MakeTmpPath( path2, CurrentFile->as_name );
            if( !strcmp( data, path2 ) ) {
//                found = TRUE;
                remove( path2 );
                while( fgets( data, FILENAME_MAX, f ) != NULL ) {
                    for( i = strlen( data ); i && isWSorCtrlZ( data[i - 1] ); --i ) {
                        data[i - 1] = '\0';
                    }
                    MyFprintf( f2, "%s\n", data );
                }
                break;
            }
        }
        MyFprintf( f2, "%s %s\n", data, path2 );
    }
    fclose( f );
    fclose( f2 );
    remove( as_path );
    rename( as2_path, as_path );

} /* RemoveFromAutoSaveList */
示例#22
0
int main( int argc, char *argv[] )
{
    char                *buff = NULL;
    char                *buff2, *buff3;
    char                *buffn, *buffs;
    int                 i, bytes, j, k, sl;
    FILE                *f;
    struct stat         fs;
    char                drive[_MAX_DRIVE], dir[_MAX_DIR];
    char                fname[_MAX_FNAME], ext[_MAX_EXT];
    char                path[_MAX_PATH];
    char                tmppath[_MAX_PATH];
    char                tmpfname[_MAX_FNAME], tmpext[_MAX_EXT];
    unsigned            cnt;
    unsigned            lines;
    bind_size           *index;
    bind_size           *entries;

    j = argc - 1;
    while( j > 0 ) {
        if( argv[j][0] == '/' || argv[j][0] == '-' ) {
            sl = strlen( argv[j] );
            for( i = 1; i < sl; i++ ) {
                switch( argv[j][i] ) {
                case 's': sflag = TRUE; break;
                case 'q': qflag = TRUE; break;
                case 'd':
                    bindfile = &argv[j][i + 1];
                    i = sl;
                    break;
                case '?':
                    Banner();
                    Usage( NULL );
                default:
                    Banner();
                    Usage( "Invalid option" );
                }
            }
            for( i = j; i < argc; i++ ) {
                argv[i]= argv[i + 1];
            }
            argc--;
        }
        j--;
    }
    Banner();

    /*
     * now, check for null file name
     */
    if( argc < 2 ) {
        Usage( "No executable to bind" );
    }
    _splitpath( argv[1], drive, dir, fname, ext );
    if( ext[0] == 0 ) {
        _makepath( path, drive, dir, fname, ".exe" );
    } else {
        strcpy( path, argv[1] );
    }
    if( stat( path, &fs ) == -1 ) {
        Abort( "Could not find executable \"%s\"", path );
    }

    cnt = 0;
    if( !sflag ) {

        buff = MyAlloc( 65000 );
        buff2 = MyAlloc( 32000 );
        buff3 = MyAlloc( MAX_LINE_LEN );

        /*
         * read in all data files
         */
        MyPrintf( "Getting data files from" );
        f = GetFromEnvAndOpen( bindfile );
        MyPrintf( "\n" );
        if( f == NULL ) {
            Abort( "Could not open %s", bindfile );
        }
        while( fgets( buff3, MAX_LINE_LEN, f ) != NULL ) {
            for( i = strlen( buff3 ); i && isWSorCtrlZ( buff3[i - 1] ); --i ) {
                buff3[i - 1] = '\0';
            }
            if( buff3[0] == '\0' ) {
                continue;
            }
            RemoveLeadingSpaces( buff3 );
            if( buff3[0] == '#' ) {
                continue;
            }
            dats[FileCount] = MyAlloc( strlen( buff3 ) + 1 );
            strcpy( dats[FileCount], buff3 );
            FileCount++;
            if( FileCount >= MAX_DATA_FILES ) {
                Abort( "Too many files to bind!" );
            }
        }
        fclose( f );
        index = MyAlloc( FileCount * sizeof( bind_size ) );
        entries = MyAlloc( FileCount * sizeof( bind_size ) );

        buffn = buff;

        *(bind_size *)buffn = FileCount;
        buffn += sizeof( bind_size );
        cnt += sizeof( bind_size );
        buffs = buffn;
        buffn += sizeof( bind_size );
        cnt += sizeof( bind_size );
        k = 0;
        for( i = 0; i < FileCount; i++ ) {
//          j = strlen( dats[i] ) + 1;
//          memcpy( buffn, dats[i], j );
            _splitpath( dats[i], NULL, NULL, tmpfname, tmpext );
            _makepath( tmppath, NULL, NULL, tmpfname, tmpext );
            j = strlen( tmppath ) + 1;
            memcpy( buffn, tmppath, j );
            buffn += j;
            cnt += j;
            k += j;
        }
        *(bind_size *)buffs = k + 1;  /* size of token list */
        *buffn = 0;                             /* trailing zero */
        buffn++;
        cnt++;
        buffs = buffn;
        buffn += FileCount * ( sizeof( bind_size ) + sizeof( bind_size ) );
        cnt += FileCount * ( sizeof( bind_size ) + sizeof( bind_size ) );

        for( j = 0; j < FileCount; j++ ) {
            MyPrintf( "Loading" );
            f = GetFromEnvAndOpen( dats[j] );
            if( f == NULL ) {
                Abort( "\nLoad of %s failed!", dats[j] );
            }
            setvbuf( f, buff2, _IOFBF, 32000 );
            bytes = lines = 0;
            index[j] = cnt;
            while( fgets( buff3, MAX_LINE_LEN, f ) != NULL ) {
                unsigned    len;

                for( len = strlen( buff3 ); len && isWSorCtrlZ( buff3[len - 1] ); --len )
                    buff3[len - 1] = '\0';
                if( buff3[0] == '\0' ) {
                    continue;
                }
                RemoveLeadingSpaces( buff3 );
                if( buff3[0] == '#' ) {
                    continue;
                }
                len = strlen( buff3 );
                *buffn = (char)len;
                buffn++;
                memcpy( buffn, buff3, len );
                buffn += len;
                cnt += len + 1;
                lines++;
                bytes += len;
            }
            fclose( f );
            entries[j] = lines;
            MyPrintf( "Added %d lines (%d bytes)\n", lines, bytes );
        }
        memcpy( buffs, index, FileCount * sizeof( bind_size ) );
        buffs += FileCount * sizeof( bind_size );
        memcpy( buffs, entries, FileCount * sizeof( bind_size ) );
    }

    AddDataToEXE( path, buff, cnt, fs.st_size );
    if( !sflag ) {
        MyPrintf( "Added %d bytes to \"%s\"\n", cnt, path );
    } else {
        MyPrintf( "\"%s\" has been stripped of configuration information\n", path );
    }
    return( 0 );

} /* main */