Results 1 to 8 of 8

Thread: User interrupt

  1. #1

    User interrupt

    I was trying to convert everything in ANSI C to Pascal but I was stuck with signal functions. I don't know what equivalent to catch a control-C signal before exiting a console-based program. Anyone knows?

    Thanks.
    Geo Massar
    <br />Retired engineer

  2. #2

    User interrupt

    Edit: ..answered the wrong thing.. ops:
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  3. #3

    User interrupt

    Could you post C code doing Ctrl+C catching?
    There are only 10 types of people in this world; those who understand binary and those who don't.

  4. #4

    User interrupt

    The C code is too long to post, 5 or 6 pages long. It is lua.c, Lua interpreter, which you could get from lua.org.

    I have converted the code nearly completely to Pascal code. I had to comment out the 'signal' functions since I don't know what equivalent to replace them. I am planning to put up a project with the lua.c clone at LuaForge.org. I'll make an announcement as soon as the project gets off the grounds.

    Thanks for your interest.
    Geo Massar
    <br />Retired engineer

  5. #5

    User interrupt

    Hmm... It's an ANSI C RTL function: http://msdn.microsoft.com/library/de...crt_signal.asp

    But:
    Note: SIGINT is not supported for any Win32 application, including Windows 98/Me and Windows NT/2000/XP. When a CTRL+C interrupt occurs, Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application such as UNIX, to become multithreaded, resulting in unexpected behavior.
    Have you expereimented that actually happends when you press Ctrl+C in Delphi/FPC console program? Is it exits or returns some string as a Read[Ln]?
    There are only 10 types of people in this world; those who understand binary and those who don't.

  6. #6

    User interrupt

    Thanks for the reply.

    While running the clone (I named it 'LuaTut', short for Lua Tutor), the program merely exits and the command prompts once you press ctrl-C key. No message whatever.

    I used Delphi to develop the console application for Windows XP platform.
    Geo Massar
    <br />Retired engineer

  7. #7

    User interrupt

    Seems you has to assign your own error handling procedure procedure to ErrorProc variable.

    If you include SysUtils in you app - it assigns it to:

    [pascal]{ RTL error handler }

    type
    TExceptRec = record
    EClass: ExceptClass;
    EIdent: string;
    end;

    const
    ExceptMap: array[Ord(reDivByZero)..Ord(High(TRuntimeError))] of TExceptRec = (
    (EClass: EDivByZero; EIdent: SDivByZero),
    (EClass: ERangeError; EIdent: SRangeError),
    (EClass: EIntOverflow; EIdent: SIntOverflow),
    (EClass: EInvalidOp; EIdent: SInvalidOp),
    (EClass: EZeroDivide; EIdent: SZeroDivide),
    (EClass: EOverflow; EIdent: SOverflow),
    (EClass: EUnderflow; EIdent: SUnderflow),
    (EClass: EInvalidCast; EIdent: SInvalidCast),
    (EClass: EAccessViolation; EIdent: SAccessViolationNoArg),
    (EClass: EPrivilege; EIdent: SPrivilege),
    (EClass: EControlC; EIdent: SControlC),
    (EClass: EStackOverflow; EIdent: SStackOverflow),
    (EClass: EVariantError; EIdent: SInvalidVarCast),
    (EClass: EVariantError; EIdent: SInvalidVarOp),
    (EClass: EVariantError; EIdent: SDispatchError),
    (EClass: EVariantError; EIdent: SVarArrayCreate),
    (EClass: EVariantError; EIdent: SVarInvalid),
    (EClass: EVariantError; EIdent: SVarArrayBounds),
    (EClass: EAssertionFailed; EIdent: SAssertionFailed),
    (EClass: EExternalException; EIdent: SExternalException),
    (EClass: EIntfCastError; EIdent: SIntfCastError),
    (EClass: ESafecallException; EIdent: SSafecallException)
    {$IFDEF LINUX}
    ,
    (EClass: EQuit; EIdent: SQuit),
    (EClass: ECodesetConversion; EIdent: SCodesetConversionError)
    {$ENDIF}
    );

    procedure ErrorHandler(ErrorCode: Byte; ErrorAddr: Pointer); export;
    var
    E: Exception;
    begin
    case ErrorCode of
    Ord(reOutOfMemory):
    E := OutOfMemory;
    Ord(reInvalidPtr):
    E := InvalidPointer;
    Ord(reDivByZero)..Ord(High(TRuntimeError)):
    begin
    with ExceptMap[ErrorCode] do
    E := EClass.Create(EIdent);
    end;
    else
    E := CreateInOutError;
    end;
    raise E at ErrorAddr;
    end;
    [/pascal]
    There are only 10 types of people in this world; those who understand binary and those who don't.

  8. #8

    User interrupt

    See the announcement at http://www.pascalgamedevelopment.com...pic.php?t=3370

    You'll see the omissions in DoCall function in mainunit.pas which is part of LuaTut package. That's where ctrl-C was unable to catch. Hope you have a suggestion to replace the ommision.

    Thank you for your time.
    Geo Massar
    <br />Retired engineer

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •