home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c-kermit / ckisig.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  3KB  |  144 lines

  1. /* C K I S I G  --  Kermit signal handling for Amiga systems */
  2.  
  3. /*
  4.   Modified from CKUSIG.C by Stephen Walton
  5.   (stephen.walton@csun.edu), California State University Northridge
  6.  
  7.   Original Author: Jeffrey Altman (jaltman@columbia.edu),
  8.   Columbia University Academic Information Systems, New York City
  9.  
  10.   Copyright (C) 1985, 1995, Trustees of Columbia University in the City of New
  11.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  12.   sold for profit as a software product itself, nor may it be included in or
  13.   distributed with commercial products or otherwise distributed by commercial
  14.   concerns to their clients or customers without written permission of the
  15.   Office of Kermit Development and Distribution, Columbia University.  This
  16.   copyright notice must not be removed, altered, or obscured.
  17. */
  18. #include "ckcsym.h"
  19. #include "ckcasc.h"            /* ASCII character symbols */
  20. #include "ckcdeb.h"            /* Debug & other symbols */
  21. #include "ckcker.h"            /* Kermit symbols */
  22. #include "ckcnet.h"            /* Network symbols */
  23. #ifndef NOSPL
  24. #include "ckuusr.h"
  25. #endif /* NOSPL */
  26.  
  27. #include <signal.h>
  28. #include <setjmp.h>
  29. #include "ckcsig.h"
  30.  
  31. #ifdef NOCCTRAP
  32. extern ckjmpbuf cmjbuf;
  33. #endif /* NOCCTRAP */
  34.  
  35. #ifndef NOCCTRAP
  36. int
  37. #ifdef CK_ANSIC
  38. cc_execute( ckjptr(sj_buf), ck_sigfunc dofunc, ck_sigfunc failfunc ) 
  39. #else
  40. cc_execute( sj_buf, dofunc, failfunc)
  41.     ckjptr(sj_buf);
  42.     ck_sigfunc dofunc;
  43.     ck_sigfunc failfunc;
  44. #endif /* CK_ANSIC */
  45. /* cc_execute */ {
  46.     int rc = 0 ;
  47.     if (cksetjmp(ckjdref(sj_buf))) {    /* Control-C trap returns to here. */
  48.     (*failfunc)(NULL) ;
  49.     rc = -1 ;
  50.     } else {            
  51.     (*dofunc)(NULL) ;
  52.     }
  53.     return rc ;
  54. }
  55. #endif /* NOCCTRAP */
  56.  
  57. int
  58. #ifdef CK_ANSIC                /* ANSIC C declaration... */
  59. alrm_execute(ckjptr(sj_buf),
  60.          int timo,
  61.          ck_sighand handler,
  62.          ck_sigfunc dofunc,
  63.          ck_sigfunc failfunc
  64.          ) 
  65.  
  66. #else /* Not ANSIC C ... */
  67.  
  68. alrm_execute(sj_buf,
  69.          timo,
  70.          handler,
  71.          dofunc,
  72.          failfunc
  73.          )
  74.     ckjptr(sj_buf);
  75.     int timo;
  76.     ck_sighand handler;
  77.     ck_sigfunc dofunc;
  78.     ck_sigfunc failfunc;
  79. #endif /* CK_ANSIC */
  80.  
  81. /* alrm_execute */ {
  82.  
  83.     int rc = 0;
  84.     int savalrm = 0;
  85. _PROTOTYP( SIGTYP (*savhandler), (int) );
  86.  
  87.     savalrm = alarm(timo);
  88.     savhandler = signal( SIGALRM, handler );
  89.     if (cksetjmp(ckjdref(sj_buf))) {    /* Alarm trap returns to here. */
  90.     (*failfunc)(NULL) ;
  91.     rc = -1 ;
  92.     } else {            
  93.     (*dofunc)(NULL) ;
  94.     }
  95.     alarm(savalrm) ;
  96.     if ( savhandler )
  97.         signal( SIGALRM, savhandler ) ;
  98.     return rc ;
  99. }
  100.  
  101. int
  102. #ifdef CK_ANSIC                /* ANSIC C declaration... */
  103. cc_alrm_execute(ckjptr(sj_buf),
  104.         int timo,
  105.         ck_sighand handler,
  106.         ck_sigfunc dofunc,
  107.         ck_sigfunc failfunc
  108.         ) 
  109.  
  110. #else /* Not ANSIC C ... */
  111.  
  112. cc_alrm_execute(sj_buf,
  113.          timo,
  114.          handler,
  115.          dofunc,
  116.          failfunc
  117.          )
  118.     ckjptr(sj_buf);
  119.     int timo;
  120.     ck_sighand handler;
  121.     ck_sigfunc dofunc;
  122.     ck_sigfunc failfunc;
  123. #endif /* CK_ANSIC */
  124.  
  125. /* cc_alrm_execute */ {
  126.  
  127.     int rc = 0;
  128.     int savalrm = 0;
  129. _PROTOTYP( SIGTYP (*savhandler), (int) );
  130.  
  131.     savalrm = alarm(timo);
  132.     savhandler = signal( SIGALRM, handler );
  133.     if (cksetjmp(ckjdref(sj_buf))) {    /* ^C or alarm trap returns here. */
  134.     (*failfunc)(NULL) ;
  135.     rc = -1 ;
  136.     } else {            
  137.     (*dofunc)(NULL) ;
  138.     }
  139.     alarm(savalrm) ;
  140.     if ( savhandler )
  141.       signal( SIGALRM, savhandler ) ;
  142.     return rc ;
  143. }
  144.