1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

GetLine and break handlers

Discussion in 'Plugins' started by p.f.moore, Jul 22, 2008.

  1. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    1
    If I leave the break handling unchanged, and call GetLine to read a
    line from the console in my plugin, then when I hit Ctrl-C while the
    plugin is waiting for input, the whole TCC instance exits. If I
    disable Ctrl-C handling, I can't quit the input without entering
    something (and the TCC instance exits when signals are re-enabled).

    So presumably I need to install my own break handler around GetLine?
    And I guess I need to do something like longjmp to regain control
    after Ctrl-C is pressed? That's doable, but pretty messy. Have I
    missed a simpler approach?

    Thanks,
    Paul.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,129
    Likes Received:
    33
    On Tue, 22 Jul 2008 09:13:02 -0500, "p.f.moore" <> wrote:


    My guess is that that shouldn't happen. Perhaps Rex will have a look at it.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,129
    Likes Received:
    33
    On Tue, 22 Jul 2008 15:08:29 -0500, vefatica <> wrote:


    The SDK's egets() behaves the same way, causing TCC to disappear when called by
    a plugin and interrupted with <Ctrl-C>.

    egets() seems a nice alternative to GetLine() for console input since it allows
    the user to edit the line.
     
  4. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    1
    On 22/07/2008, vefatica <> wrote:



    Both GetLine and egets seem to have the following properties:

    - Ctrl-C causes TCC to terminate
    - If you use a user-defined break handler, you cannot get
    GetLine/egets to return (they are probably looping until they get a
    return character)

    Between them, these 2 properties leave only the option of completely
    disabling signals, which is safe but hardly friendly :-(

    Paul.
     
  5. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    1
    On 23/07/2008, Paul Moore <p.f.moore@gmail.com> wrote:

    Actually, it's worse than that in one way, but better in another.
    Break handling in plugins seems utterly broken. Any break signal while
    a plugin is active seems to terminate TCC. See the attached trivial
    plugin, which just runs Cmd_Delay. If you hit Ctrl-C while the delay
    is ongoing, TCC exits.

    This looks like a bug in TCC (I'm using 9.02.151) as it works fine in 4NT 8.

    Paul.

    // PlugIn.cpp - demonstration plugin for 4NT / TC 7.0

    #define UNICODE 1
    #define _UNICODE 1

    #include <windows.h>

    #include "PlugIn.h"
    #include "TakeCmd.h"


    BOOL APIENTRY DllMain( HANDLE hModule, DWORD dwReason, LPVOID lpReserved )
    {
    switch( dwReason ) {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
    break;
    }
    return TRUE;
    }


    DLLExports LPPLUGININFO WINAPI GetPluginInfo( void )
    {
    static PLUGININFO piInfo;

    piInfo.pszDll = (LPTSTR)L"TestBreak";
    piInfo.pszAuthor = (LPTSTR)L"Paul Moore";
    piInfo.pszEmail = (LPTSTR)L"example@example.com";
    piInfo.pszWWW = (LPTSTR)L"example.com";
    piInfo.pszDescription = (LPTSTR)L"Test plugin";
    piInfo.pszFunctions = (LPTSTR)L"test";
    piInfo.nMajor = 1;
    piInfo.nMinor = 0;
    piInfo.nBuild = 1;

    return &piInfo;
    }


    DLLExports BOOL WINAPI InitializePlugin( void )
    {
    return 0;
    }


    DLLExports BOOL WINAPI ShutdownPlugin( BOOL bEndProcess )
    {
    return 0;
    }

    DLLExports INT WINAPI test (LPTSTR lpszString)
    {
    Delay_Cmd(L"12");
    return 0;
    }
     
  6. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    1
    On 23/07/2008, Paul Moore <p.f.moore@gmail.com> wrote:

    Actually, it's worse than that in one way, but better in another.
    Break handling in plugins seems utterly broken. Any break signal while
    a plugin is active seems to terminate TCC. See the attached trivial
    plugin, which just runs Cmd_Delay. If you hit Ctrl-C while the delay
    is ongoing, TCC exits.

    This looks like a bug in TCC (I'm using 9.02.151) as it works fine in 4NT 8.

    Paul.

    // PlugIn.cpp - demonstration plugin for 4NT / TC 7.0

    #define UNICODE 1
    #define _UNICODE 1

    #include <windows.h>

    #include "PlugIn.h"
    #include "TakeCmd.h"


    BOOL APIENTRY DllMain( HANDLE hModule, DWORD dwReason, LPVOID lpReserved )
    {
    switch( dwReason ) {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
    break;
    }
    return TRUE;
    }


    DLLExports LPPLUGININFO WINAPI GetPluginInfo( void )
    {
    static PLUGININFO piInfo;

    piInfo.pszDll = (LPTSTR)L"TestBreak";
    piInfo.pszAuthor = (LPTSTR)L"Paul Moore";
    piInfo.pszEmail = (LPTSTR)L"example@example.com";
    piInfo.pszWWW = (LPTSTR)L"example.com";
    piInfo.pszDescription = (LPTSTR)L"Test plugin";
    piInfo.pszFunctions = (LPTSTR)L"test";
    piInfo.nMajor = 1;
    piInfo.nMinor = 0;
    piInfo.nBuild = 1;

    return &piInfo;
    }


    DLLExports BOOL WINAPI InitializePlugin( void )
    {
    return 0;
    }


    DLLExports BOOL WINAPI ShutdownPlugin( BOOL bEndProcess )
    {
    return 0;
    }

    DLLExports INT WINAPI test (LPTSTR lpszString)
    {
    Delay_Cmd(L"12");
    return 0;
    }
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,129
    Likes Received:
    33
    On Wed, 23 Jul 2008 08:06:40 -0500, "p.f.moore" <> wrote:


    All that seems to be true. Things work well in v8 and semingly poorly in v9.

    It should be noted that a console control handler set by a plugin works fine if
    it returns TRUE. I use one to be able to interrupt my KEYTIMES or GREPP. But
    returning TRUE, they won't let the user interrupt anything at a higher level (a
    batch file for example).
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,129
    Likes Received:
    33
    p.f.moore:

    Both GetLine and egets seem to have the following properties:

    - Ctrl-C causes TCC to terminate
    - If you use a user-defined break handler, you cannot get
    GetLine/egets to return (they are probably looping until they get a
    return character)

    This doesn't help with interrupting GetLine() or egets() in v9, but I learned an interestin technique (kludge). In my KEYTIMES, which can go on for quite a while, I installed a control handler which sets the global bInterrupt to TRUE and returns TRUE (not invoking further ctrl handlers). Upon finding bInterrupt to be TRUE, my recursive registry-delving function halts and cleans up its mess (closes handles, et c.). Then just before KEYTIMES returns, if it had been interrupted, I recreate the signal with GenerateConsoleCtrlEvent(). This seems to work around the problem with passing the event on to TCC earlier (which causes v9 to go away).

    Rex, is there a more elegant way to let a plugin function clean up on getting a signal and then pass the signal to a higher authority? Do you have any try/catch handlers that I can throw to? And is there a way a plugin can interrupt GetLine() or egets()? Can I put them in a "try" block and use a ctrl handler to throw an exception?
     

Share This Page