misc.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 839 行 · 第 1/2 页

C
839
字号
    int         rc, i;
    int num = 0;
    for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next )num ++;

    BringUpFile( InfoHead, TRUE );
    for( i = 0; i<num; i++ ){
        if( NextFile() > 0 ) {
            // file modified ask
            rc = FileExitOptionSaveChanges( CurrentFile );
            if( rc == TRUE ) {
                /* user hit cancel - always allow this! */
                return( FALSE );
            }
        }
    }
    if( do_quit ) {
        QuitEditor( 0 );
    }
    return( TRUE );

} /* ExitWithPrompt */

/*
 * ExitWithVerify - try to exit, verifying first
 */
void ExitWithVerify( void )
{
    int         i,num=0;
    static bool entered=FALSE;
    info        *cinfo;
    bool        modified;
    #ifndef __WIN__
        char    st[MAX_STR];
    #endif

    if( entered ) {
        return;
    }
    entered = TRUE;
    cinfo = InfoHead;
    modified = FALSE;
    while( cinfo != NULL ) {
        modified |= cinfo->CurrentFile->modified;
        cinfo = cinfo->next;
        num++;
    }
    if( modified ) {
        #ifdef __WIN__
            i = MessageBox( Root, "Files are modified, really exit?",
                                EditorName, MB_YESNO | MB_TASKMODAL );
            if( i == IDYES ) {
                BringUpFile( InfoHead, TRUE );
                EditFlags.QuitAtLastFileExit = TRUE;
                for( ;; ){
                    NextFileDammit();
                }
            }
        #else
            i = GetResponse( "Files are modified, really exit?", st );
            if( i == GOT_RESPONSE && st[0] == 'y' ) {
                BringUpFile( InfoHead, TRUE );
                EditFlags.QuitAtLastFileExit = TRUE;
                for( ;; ){
                    NextFileDammit();
                }
            }
        #endif
    } else {
        BringUpFile( InfoHead, TRUE );
        EditFlags.QuitAtLastFileExit = TRUE;
        for( ;; ){
            NextFileDammit();
        }
    }
    entered = FALSE;

} /* ExitWithVerify */

#if 0
// the old way (super lossy)

bool ExitWithPrompt( bool do_quit )
{
    info        *cinfo, *next;
    int         rc;

    for( cinfo = InfoHead; cinfo != NULL; cinfo = next ) {
        next = cinfo->next;
        if( cinfo->CurrentFile->modified == TRUE ) {
            /* have to bring up the file first */
            BringUpFile( cinfo, TRUE );
            rc = FileExitOptionSaveChanges( cinfo->CurrentFile );
            if( rc == TRUE ) {
                /* user hit cancel - always allow this!
                */
                return( FALSE );
            }
        }
    }
    if( do_quit ) {
        QuitEditor( 0 );
    }
    return( TRUE );

} /* ExitWithPrompt */

/*
 * ExitWithVerify - try to exit, verifying first
 */
void ExitWithVerify( void )
{
    int         i;
    static bool entered=FALSE;
    info        *cinfo;
    bool        modified;
    #ifndef __WIN__
        char    st[MAX_STR];
    #endif

    if( entered ) {
        return;
    }
    entered = TRUE;
    cinfo = InfoHead;
    modified = FALSE;
    while( cinfo != NULL ) {
        modified |= cinfo->CurrentFile->modified;
        cinfo = cinfo->next;
    }
    if( modified ) {
        #ifdef __WIN__
            i = MessageBox( Root, "Files are modified, really exit?",
                                EditorName, MB_YESNO | MB_TASKMODAL );
            if( i == IDYES ) {
                QuitEditor( 0 );
            }
        #else
            i = GetResponse( "Files are modified, really exit?", st );
            if( i == GOT_RESPONSE && st[0] == 'y' ) {
                QuitEditor( 0 );
            }
        #endif
    } else {
        QuitEditor( 0 );
    }
    entered = FALSE;

} /* ExitWithVerify */
#endif

/*
 * PrintHexValue - print hex value of char under cursor
 */
int PrintHexValue( void )
{
    int i;

    if( CurrentFile != NULL ) {
        i = CurrentLine->data[ CurrentColumn-1 ];
        if( i == '\0' ) {
            // of not on data, pretend are 'on' newline
            i = '\n';
        }
        Message1( "Char '%c': 0x%Z (%d)",(char) i,i,i );
    }

    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* PrintHexValue */

/*
 * EnterHexKey - enter a hexidecimal key stroke and insert it into the text
 */
int EnterHexKey( void )
{
    int         rc,i;
    char        st[MAX_STR],val;

    if( rc = ModificationTest() ) {
        return( rc );
    }
    if( CurrentLine->len >= MaxLinem1 ) {
        return( ERR_LINE_FULL );
    }

    rc = PromptForString( "Enter the number of char to insert:", st,
                                sizeof( st )-1, NULL );
    if( rc ) {
        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>=CurrentColumn-1;i-- ) {
        WorkLine->data[i+1] = WorkLine->data[i];
    }
    WorkLine->data[CurrentColumn-1] = val;
    WorkLine->len++;
    DisplayWorkLine( TRUE );
    if( CurrentColumn < WorkLine->len ) {
        GoToColumn( CurrentColumn +1, WorkLine->len+1 );
    }
    ReplaceCurrentLine();
    EditFlags.Dotable = TRUE;
    return( ERR_NO_ERR );

} /* EnterHexKey */

/*
 * DoVersion - display version info
 */
int DoVersion( void )
{
    Message1( "\"%s\" v%s  %s %s", TITLE,VERSIONT, DATESTAMP_T, DATESTAMP_D );
    Message2( "%s", AUTHOR );
    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* DoVersion */

/*
 * StrMerge - merge a number of strings together
 */
char *StrMerge( int cnt, char *str, ... )
{
    va_list     arg;
    char        *n;

    va_start( arg, str );
    while( cnt > 0 ) {
        n = va_arg( arg, char * );
        if( n != NULL ) {
            strcat( str, n );
        }
        cnt--;
    }
    va_end( arg );
    return( str );

} /* StrMerge */

/*
 * ModificationTest - test a file as it is about to be modified
 */
int ModificationTest( void )
{
    int         rc;
    bool        olddm;
    int         olddotdigits;

    if( CurrentFile == NULL ) {
        return( ERR_NO_FILE );
    }

    if( CurrentFile->viewonly ) {
        return( ERR_FILE_VIEW_ONLY );
    }
    if( !CurrentFile->modified ) {
        olddm = EditFlags.DotMode;
        EditFlags.DotMode = FALSE;
        EditFlags.NoAddToDotBuffer = TRUE;
        olddotdigits = DotDigits;
        rc = SourceHook( SRC_HOOK_MODIFIED, ERR_NO_ERR );
        DotDigits = olddotdigits;
        EditFlags.NoAddToDotBuffer = FALSE;
        EditFlags.DotMode = olddm;
        return( rc );
    }
    return( ERR_NO_ERR );

} /* ModificationTest */

/*
 * CurFileExitOptionSaveChanges - exit current file, opt save if modified
 */
int CurFileExitOptionSaveChanges( void )
{
    if( NextFile() > 0 ) {
        FileExitOptionSaveChanges( CurrentFile );
    }
    return( ERR_NO_ERR );
}

/*
 * UpdateCurrentDirectory - update the current directory variable
 */
void UpdateCurrentDirectory( void )
{

    MemFree2( &CurrentDirectory );
    GetCWD1( &CurrentDirectory );

} /* UpdateCurrentDirectory */

#ifndef __WIN__
/*
 * DoAboutBox - do an about box
 */
int DoAboutBox( void )
{
    return( ERR_NO_ERR );

} /* DoAboutBox */
#endif

/*
 * NextBiggestPrime - the 'lowest common denominator' version (ie simple)
 */
int NextBiggestPrime( int start )
{
    int n = start;
    int i;

    while( 1 ) {
        for( i = 2; i < ( int )( n / 2 ); i++ ) {
            if( i * ( n / i ) == n ) {
                break;
            }
        }
        if( i == ( int )( n / 2 ) ) {
            break;
        }
        n++;
    }
    return n;
}

int FancySetFS( void )
{
#ifdef __WIN__
    GetSetFSDialog();
#endif
    return( ERR_NO_ERR );
}

int FancySetScr( void )
{
#ifdef __WIN__
    GetSetScrDialog();
#endif
    return( ERR_NO_ERR );
}

int FancySetGen( void )
{
#ifdef __WIN__
    GetSetGenDialog();
#endif
    return( ERR_NO_ERR );
}

int ToggleToolbar( void )
{
    char    cmd[ 14 ];
    sprintf( cmd, "set%stoolbar", EditFlags.Toolbar ? " no" : " " );
    return( RunCommandLine( cmd ) );
}

int ToggleStatusbar( void )
{
    char    cmd[ 17 ];
    sprintf( cmd, "set%sstatusinfo", EditFlags.StatusInfo? " no" : " " );
    return( RunCommandLine( cmd ) );
}

int ToggleColorbar( void )
{
    char    cmd[ 15 ];
    sprintf( cmd, "set%scolorbar", EditFlags.Colorbar ? " no" : " " );
    return( RunCommandLine( cmd ) );
}

int ToggleSSbar( void )
{
    char    cmd[ 15 ];
    sprintf( cmd, "set%sssbar", EditFlags.SSbar ? " no" : " " );
    return( RunCommandLine( cmd ) );
}

int ToggleFontbar( void )
{
    char    cmd[ 14 ];
    sprintf( cmd, "set%sfontbar", EditFlags.Fontbar ? " no" : " " );
    return( RunCommandLine( cmd ) );
}

int GenericQueryBool( char *str )
{
    #ifdef __WIN__
        return( MessageBox( Root, str, EditorName, MB_OKCANCEL ) == IDOK );
    #else
        #define BUFLEN 10
        char buffer[BUFLEN];
        PromptForString( str, buffer, BUFLEN, NULL );
        return( tolower( buffer[0] ) == 'y' );
    #endif
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?