Esempio n. 1
0
int Plot_close (void) /*{{{*/
{
   int status;
   SLSig_Fun_Type *sig_func;

   if (pli_undefined())
     return -1;

   if (PLI->close == NULL)
     return -1;

   sig_func = SLsignal (SIGSEGV, sig_segv);
   if (SIG_ERR == sig_func)
     fprintf (stderr, "warning:  failed initializing signal handler for SIGSEGV\n");

   if (-1 == SLexecute_function (PLI->close))
     {
        isis_vmesg (FAIL, I_FAILED, __FILE__, __LINE__, "failed closing plot device");
        return -1;
     }
   if (-1 == SLang_pop_integer (&status))
     {
        isis_vmesg (FAIL, I_ERROR, __FILE__, __LINE__, "function closing plot device did not return status integer");
        return -1;
     }

   if (SLsignal (SIGSEGV, sig_func) == SIG_ERR)
     fprintf (stderr, "warning:  failed to re-set signal handler\n");

   return status;
}
Esempio n. 2
0
File: sig.c Progetto: hankem/jed
void jed_reset_signals (void)
{
   SLsignal (SIGINT, Old_Sigint_Handler);
#ifdef SIGTSTP
   SLsignal (SIGTSTP, Old_Sigtstp_Handler);
#endif
   /* return 0; */
}
Esempio n. 3
0
static void _pgclos (void)
{
   void (*sig_func)(int);

   sig_func = SLsignal (SIGSEGV, sig_segv);
   if (sig_func == SIG_ERR)
     fprintf (stderr, "warning:  failed initializing signal handler for SIGSEGV\n");

   cpgclos ();

   if (SLsignal (SIGSEGV, sig_func) == SIG_ERR)
     fprintf (stderr, "warning:  failed to re-set signal handler\n");
}
Esempio n. 4
0
File: sig.c Progetto: hankem/jed
void init_signals (void) /*{{{*/
{
#if !defined(VMS) || (__VMS_VER >= 70000000)

#ifdef SIGWINCH
   (void) SLsignal_intr(SIGWINCH, sigwinch_handler);
#endif

   Old_Sigint_Handler = SLsignal_intr (SIGINT, my_interrupt);

   SLsignal (SIGHUP, sig_hup_exit_jed);
   SLsignal (SIGQUIT, sig_hup_exit_jed);
   SLsignal (SIGTERM, sig_hup_exit_jed);

   SLsignal (SIGILL, sig_exit_jed);
#if 0 && defined(SIGTRAP)
   SLsignal (SIGTRAP, sig_exit_jed);
#endif
#if 0
   SLsignal (SIGIOT, sig_exit_jed);  /* used by abort */
#endif
#ifdef SIGPIPE
   SLsignal_intr (SIGPIPE, SIG_IGN);
#endif
   /* SIGNAL (SIGFPE, sig_exit_jed); */
#ifdef SIGBUS
   SLsignal (SIGBUS, sig_exit_jed);
#endif
#if 0
   SLsignal (SIGSEGV, sig_exit_jed);
#endif
#ifdef SIGSYS
    SLsignal (SIGSYS, sig_exit_jed);
#endif

#ifdef SIGTSTP
   if (Jed_Handle_SIGTSTP)
     {
	Old_Sigtstp_Handler = SLsignal_intr (SIGTSTP, sig_sys_spawn_cmd);
	if (SIG_DFL != Old_Sigtstp_Handler)
	  Jed_Suspension_Not_Allowed = 1;
     }
#endif

#if CATCH_SIGTTIN
# ifdef SIGTTOU
   SLsignal_intr (SIGTTOU, background_read);
# endif
# ifdef SIGTTIN
   SLsignal_intr (SIGTTIN, background_read);
# endif
#endif

#endif /* VMS */
}
Esempio n. 5
0
/* pipes a single email body to some file.
   In interactive mode, we catch the PIPE signal
   in case the receiving command closed the connection
   prematurely. In that case, we simply stop sending. */
void pipe_single_email(mbox_item *what, FILE *output) {
  FILE *input;
  char buf[PIPE_BUFLEN];

  if( emails.filename ) {
    input = fopen(emails.filename, "rb");
    if( input ) {
#if defined COMPILE_INTERACTIVE_MODE
      if( u_options & (1<<U_OPTION_INTERACTIVE) ) {
	SLsignal(SIGPIPE, sigpipe_handler);
      }
#endif
      fseek(input, what->seekpos, SEEK_SET);
      pipe_done = 0;
      fputs(what->description[0], output);
      while( !pipe_done ) {
	fgets(buf, PIPE_BUFLEN, input);
	if( feof(input) || (strncmp(buf, "From ", 5) == 0) ) {
	  pipe_done = 1;
	} else {
	  fputs(buf, output);
	}
      }
    }
    fclose(input);
  }

}
Esempio n. 6
0
static void
sigwinch_handler (int dummy)
{
    (void) dummy;

    mc_global.tty.winch_flag = 1;
    (void) SLsignal (SIGWINCH, sigwinch_handler);
}
Esempio n. 7
0
static void sig_sigtstp (int sig)
{
    sig = errno;
#  if USE_SIGTSTP_INTERRUPT
    Want_Suspension = 1;
#  else
    suspend_slsh ();
#  endif
    (void) SLsignal (sig, sig_sigtstp);
    errno = sig;
}
Esempio n. 8
0
static void sig_segv (int signo) /*{{{*/
{
   static char msg[] =
"\n**** Segmentation Fault occurred while closing plot device\n";
   (void) signo;
   if (Signal_In_Progress)
     return;
   Signal_In_Progress = 1;
   write (STDERR_FILENO, msg, sizeof(msg));
   /* so more SEGVs won't interfere with _exit() */
   SLsignal (SIGSEGV, SIG_DFL);
   _exit (EXIT_FAILURE);
}
Esempio n. 9
0
static void sig_segv (int signo)
{
   static char msg[] =
     "\n**** PGPLOT is buggy:  Segmentation Fault occurred while in PGCLOSE\n";
   (void) signo;
   if (Signal_In_Progress)
     return;
   Signal_In_Progress = 1;
   write (STDERR_FILENO, msg, sizeof(msg));
   /* so more SEGVs won't interfere with exit() */
   SLsignal (SIGSEGV, SIG_DFL);
   SLang_exit_error ("Fatal error in PGPLOT--- exiting");
}
Esempio n. 10
0
static void init_tty (void) /*{{{*/
{
#ifdef HAVE_GNU_READLINE
   if (Use_SLang_Readline == 0)
     {
        SLsig_block_signals ();
        last_sig_sigint = SLsignal (SIGINT, gnu_rl_sigint_handler);
        last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp);
        SLsig_unblock_signals ();
        return;
     }
#endif

   if (TTY_Inited)
     return;
   TTY_Inited++;

   SLsig_block_signals ();
   SLang_TT_Read_FD = fileno (stdin);
   last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp);

   if (-1 == SLang_init_tty (-1, 1, 0))
     {
        SLsignal (SIGTSTP, last_sig_sigtstp);
        SLsig_unblock_signals ();
        fprintf (stderr, "Error initializing terminal.");
        exit (EXIT_FAILURE);
     }

   SLang_getkey_intr_hook = getkey_intr_hook;

   (void) add_sigwinch_handlers ();
   SLtt_get_screen_size ();

   SLtty_set_suspend_state (1);
   SLsig_unblock_signals ();
}
Esempio n. 11
0
static void reset_tty (void) /*{{{*/
{
#ifdef HAVE_GNU_READLINE
   if (Use_SLang_Readline == 0)
     {
        SLsig_block_signals ();
        SLsignal (SIGINT, last_sig_sigint);
        SLsignal (SIGTSTP, last_sig_sigtstp);
        SLsig_unblock_signals ();
        return;
     }
#endif

   if (TTY_Inited == 0)
     return;
   TTY_Inited = 0;

   SLsig_block_signals ();
   SLsignal (SIGTSTP, last_sig_sigtstp);
   SLang_reset_tty ();
   SLsig_unblock_signals ();
   fputs ("\r\n", stdout);   /* need this with buggy Linux rlogin? */
   fflush (stdout);
}
Esempio n. 12
0
static void init_tty (void)
{
   int abort_char = 3;
   if (TTY_Inited)
     return;
   TTY_Inited++;
# if SYSTEM_SUPPORTS_SIGNALS
   SLsig_block_signals ();
   SLang_TT_Read_FD = fileno (stdin);
   last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp);
# endif
# ifdef REAL_UNIX_SYSTEM
   abort_char = -1;		       /* determine from tty */
# endif

   if (-1 == SLang_init_tty (abort_char, 1, 1))   /* opost was 0 */
     {
# if SYSTEM_SUPPORTS_SIGNALS
	SLsignal (SIGTSTP, last_sig_sigtstp);
	SLsig_unblock_signals ();
# endif
	SLang_exit_error ("Error initializing terminal.");
     }

# ifdef REAL_UNIX_SYSTEM
   SLang_getkey_intr_hook = getkey_intr_hook;
# endif
   (void) add_sigwinch_handlers ();

   SLtt_get_screen_size ();

# if SYSTEM_SUPPORTS_SIGNALS
   SLtty_set_suspend_state (1);
   SLsig_unblock_signals ();
# endif
}
Esempio n. 13
0
static void sigwinch_handler (int sig) {

  SLsig_block_signals();

  SLtt_get_screen_size();
  SLsmg_reinit_smg();

  if( !disp.delay_sigwinch ) {
    redraw_current_state();
  }

  SLsig_unblock_signals();

  SLsignal(SIGWINCH, sigwinch_handler);

}
Esempio n. 14
0
static void reset_tty (void)
{
   if (TTY_Inited == 0)
     return;
   TTY_Inited = 0;
# if SYSTEM_SUPPORTS_SIGNALS
   SLsig_block_signals ();
   SLsignal (SIGTSTP, last_sig_sigtstp);
# endif
   SLang_reset_tty ();
# if SYSTEM_SUPPORTS_SIGNALS
   SLsig_unblock_signals ();
# endif
   /* Add a \r here to work around what I believe is a solaris kernel bug.
    * The terminal is being reset by SLang_reset_tty which uses TCSADRAIN
    * option.  However, that is not supposed to affect output after that
    * call is made (like the output below), but it does.
    */
   fputs ("\r\n", stdout);
   fflush (stdout);
}
Esempio n. 15
0
int SLang_init_slmath (void)
{
   SLtype *int_types;

#if SLANG_HAS_COMPLEX
   if (-1 == _pSLinit_slcomplex ())
     return -1;
#endif
   int_types = _pSLarith_Arith_Types;

   while (*int_types != SLANG_FLOAT_TYPE)
     {
	if (-1 == SLclass_add_math_op (*int_types, generic_math_op, double_math_op_result))
	  return -1;
	int_types++;
     }

   if ((-1 == SLclass_add_math_op (SLANG_FLOAT_TYPE, float_math_op, double_math_op_result))
       || (-1 == SLclass_add_math_op (SLANG_DOUBLE_TYPE, double_math_op, double_math_op_result))
#if SLANG_HAS_COMPLEX
       || (-1 == SLclass_add_math_op (SLANG_COMPLEX_TYPE, complex_math_op, complex_math_op_result))
#endif
       )
     return -1;

   if ((-1 == SLadd_math_unary_table (SLmath_Table, "__SLMATH__"))
       || (-1 == SLadd_intrin_fun_table (SLang_Math_Table, NULL))
       || (-1 == SLadd_dconstant_table (DConst_Table, NULL))
       || (-1 == SLadd_iconstant_table (IConsts, NULL))
       || (-1 == add_nan_and_inf ()))
     return -1;

#if defined(__unix__)
   (void) SLsignal (SIGFPE, math_floating_point_exception);
#endif

   return 0;
}
Esempio n. 16
0
static void init_sigtstp (void)
{
    (void) SLang_add_interrupt_hook (sigtstp_interrupt_hook, NULL);
    last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp);
}
Esempio n. 17
0
static int sl_output(int port, char *buf, int len)
{
    int x,y,z,v,w;
    char *str, *t1, *t2, *t3;
    int ret;
    char ch;


    /* check for signals */

    if (signal_cought != 0) {  /* async out signal */
	char xxx[5];

	xxx[0] = 0;
	put_int32(signal_cought, xxx+1);
	driver_output(port, xxx, 5);
	signal_cought = 0;
    }

    switch (*buf++) {
    case INIT_TTY: {
	int abort_char, flow_ctl, opost;
	abort_char = get_int32(buf); buf+=4;
	flow_ctl = get_int32(buf); buf+= 4;
	opost = get_int32(buf); buf+= 4;
	ret = SLang_init_tty (abort_char,flow_ctl, opost);
	return ret_int(port, ret);
    }
    
    case SET_ABORT_FUNCTION: {
	SLang_set_abort_signal (NULL);
	return ret_int(port, 0);
    }
    case GETKEY: {
	unsigned int key;
	if (SLang_input_pending (0) == 0) {
	    wait_for = GETKEY;
	    driver_select(port, 0, DO_READ, 1);
	    return 0;
	}
	x = SLang_getkey ();
	return ret_int(port, x);
    }
    /* read a symbol */
    case KP_GETKEY: {
	if (SLang_input_pending (0) == 0) {
	    wait_for = KP_GETKEY;
	    driver_select(port, 0, DO_READ, 1);
	    return 0;
	}
	x = SLkp_getkey ();
	return ret_int(port, x);
    }
    case UNGETKEY: {
	unsigned char  key =  (unsigned char) *buf;
	SLang_ungetkey (key); 
	return 0;
    }
    case RESET_TTY: {
	SLang_reset_tty();
	return 0;
    }
    case KP_INIT: {
	return ret_int(port, SLkp_init ());
    }
    case SETVAR: {
	x = get_int32(buf);buf+= 4;
	y = get_int32(buf);
	switch (x) {
	case  esl_baud_rate:
	    SLang_TT_Baud_Rate = y; return 0;
	case esl_read_fd:
	    return 0;
	case esl_abort_char:
	    SLang_Abort_Char = y; return 0;
	case esl_ignore_user_abort:
	    SLang_Ignore_User_Abort=y; return 0;
	case esl_input_buffer_len :
	    SLang_Input_Buffer_Len=y; return 0;
	case  esl_keyboard_quit:
	    SLKeyBoard_Quit=y; return 0;
	case esl_last_key_char:
	    SLang_Last_Key_Char=y; return 0;
	case esl_rl_eof_char:
	    SLang_RL_EOF_Char=y; return 0;
	case esl_rline_quit:
	    SLang_Rline_Quit=y; return 0;
	case esl_screen_rows:
	case  esl_screen_cols :
	    return 0;
	case esl_tab_width:
	    SLsmg_Tab_Width=y; return 0;
	case  esl_newline_behaviour:
	    SLsmg_Newline_Behavior=y; return 0;
	case esl_error:
	    SLang_Error=y; return 0;
	case esl_version:
	    return 0;
	case  esl_backspace_moves :
	    SLsmg_Backspace_Moves=y; return 0;
	case esl_display_eight_bit:
	    SLsmg_Display_Eight_Bit=y; return 0;
	default:
	    return 0;
	}
    }

    case GETVAR: {
	x = get_int32(buf);
	switch (x) {
	case  esl_baud_rate:
	    return ret_int(port, SLang_TT_Baud_Rate);
	case esl_read_fd:
	    return ret_int(port,  SLang_TT_Read_FD);
	case esl_abort_char:
	    return (ret_int(port, SLang_Abort_Char));
	case esl_ignore_user_abort:
	    return ret_int(port, SLang_Ignore_User_Abort);
	case esl_input_buffer_len :
	    return ret_int(port, SLang_Input_Buffer_Len);
	case  esl_keyboard_quit:
	    return ret_int(port, SLKeyBoard_Quit);
	case esl_last_key_char:
	    return ret_int(port, SLang_Last_Key_Char);
	case esl_rl_eof_char:
	    return ret_int(port, SLang_RL_EOF_Char);
	case esl_rline_quit:
	    return ret_int(port, SLang_Rline_Quit);
	case esl_screen_rows:
	    return ret_int(port, SLtt_Screen_Rows);
	case  esl_screen_cols :
	    return ret_int(port, SLtt_Screen_Cols);
	case esl_tab_width:
	    return ret_int(port, SLsmg_Tab_Width);
	case  esl_newline_behaviour:
	    return ret_int(port, SLsmg_Newline_Behavior);
	case esl_error:
	    return ret_int(port, SLang_Error);
	case esl_version:
	    return ret_int(port, SLang_Version); 
	case  esl_backspace_moves :
	    return ret_int(port, SLsmg_Backspace_Moves);
	case esl_display_eight_bit:
	    return  ret_int(port, SLsmg_Display_Eight_Bit);
	default:
	    return ret_int(port, -1);
	}
    }
	    


    /*{{{ SLsmg Screen Management Functions */


    
    case SMG_FILL_REGION: {
	x = get_int32(buf); buf+= 4;
	y =  get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	ch = *buf;
	SLsmg_fill_region(x, y,z,v,ch);
	return 0;
    }			  
    case SMG_SET_CHAR_SET: {
	x = get_int32(buf); buf+= 4;
	SLsmg_set_char_set(x);
	return 0;
    }			
    case SMG_SUSPEND_SMG: {
	return ret_int(port, SLsmg_suspend_smg());
    }				  
    case SMG_RESUME_SMG: {
	ret_int(port, SLsmg_resume_smg());
    }				     
    case SMG_ERASE_EOL: {
	SLsmg_erase_eol();
	return 0;
    }					
    case SMG_GOTORC: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	SLsmg_gotorc(x,  y);
	return 0;
    }					 
    case SMG_ERASE_EOS: {
	SLsmg_erase_eos();
	return 0;
    }						
    case SMG_REVERSE_VIDEO: {
	SLsmg_reverse_video();
	return 0;
    }							
    case SMG_SET_COLOR: {
	x = get_int32(buf); buf+= 4;
	SLsmg_set_color(x);
	return 0;
    }							
    case SMG_NORMAL_VIDEO: {
	SLsmg_normal_video();
	return 0;
    }							
    case SMG_WRITE_STRING: {
	SLsmg_write_string(buf);
	return 0;
    }									   
    case SMG_WRITE_CHAR: {
	ch = *buf;
	SLsmg_write_char(ch);
	return 0;
    }
    case SMG_WRITE_WRAPPED_STRING: {
	t1 = buf;
	buf += strlen(t1) + 1;
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	w = get_int32(buf); buf+= 4;
	SLsmg_write_wrapped_string(t1, x,y,z,v,w);
	return 0;
    }												   
    case SMG_CLS: {
	SLsmg_cls();
	return 0;
    }									
    case SMG_REFRESH: {
	SLsmg_refresh();
	return 0;
    }										
    case SMG_TOUCH_LINES: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	SLsmg_touch_lines(x, y);
	return 0;
    }											
    case SMG_TOUCH_SCREEN: {
#if (SLANG_VERSION < 10400 )
	return ret_int(port, -1);
#else
	SLsmg_touch_screen();
#endif
	return 0;
    }													   
    case SMG_INIT_SMG: {
	return ret_int(port,  SLsmg_init_smg());
    }													   
    case SMG_REINIT_SMG: {
#if (SLANG_VERSION < 10400 )
	return ret_int(port, -1);
#else
	return ret_int(port, SLsmg_reinit_smg());
#endif
    }														 
    case SMG_RESET_SMG: {
	SLsmg_reset_smg();
	return 0;
    }														    
    case SMG_CHAR_AT: {
	return ret_int(port, SLsmg_char_at());
    }														     
    case SMG_SET_SCREEN_START: {
	int *ip1, *ip2;
	*ip1 = get_int32(buf); buf+= 4;
	*ip2 = get_int32(buf); buf+= 4;

	SLsmg_set_screen_start(ip1, ip2);
	return ret_int_int(port, *ip1, *ip2);
    }
    case SMG_DRAW_HLINE: {
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_hline(x);
	return 0;
    }																 
    case SMG_DRAW_VLINE: {
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_vline(x);
	return 0;
    }																     
    case SMG_DRAW_OBJECT: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_object(x, y,z);
	return 0;
    }																	  
    case SMG_DRAW_BOX: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	SLsmg_draw_box(x, y,z,v);
	return 0;
    }																	   
    case SMG_GET_COLUMN: {
	return ret_int(port, SLsmg_get_column());
    }																		
    case SMG_GET_ROW: {
	return ret_int(port, SLsmg_get_row());
    }		

    case SMG_FORWARD: {
	x = get_int32(buf); buf+= 4;
	SLsmg_forward(x);
	return 0;
    }							
    case SMG_WRITE_COLOR_CHARS: {
	SLsmg_Char_Type * sl;
	sl = decode_smg_char_type(&buf);
	x = get_int32(buf); buf+= 4;
	SLsmg_write_color_chars(sl, x);
	return 0;
    }		
    case SMG_READ_RAW: {
	x = get_int32(buf); buf+= 4;
	t1 = malloc((2*x) + 2 + 1);
	y = SLsmg_read_raw((unsigned short*)t1 +1, x);
	t1[1] = 1;
	driver_output(port, t1, y+1);
	free(t1);
	return 0;
    }
    case SMG_WRITE_RAW: {
	SLsmg_Char_Type * sl;
	sl = decode_smg_char_type(&buf);
	x = get_int32(buf); 
	y = SLsmg_write_raw(sl, x);
	return ret_int(port, y);
    }																				
    case SMG_SET_COLOR_IN_REGION: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	w = get_int32(buf); buf+= 4;
	SLsmg_set_color_in_region(x, y,z,v,w);
	return 0;
    }																				
    
    




    /* all the tt_functions  */

    case TT_FLUSH_OUTPUT: {
	ret = SLtt_flush_output();
	return ret_int(port, ret);
    }
    case TT_SET_SCROLL_REGION: {

	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_set_scroll_region(x, y);
	return 0;
    }
    case TT_RESET_SCROLL_REGION: {
	SLtt_reset_scroll_region();
	return 0;
    }
    case TT_REVERSE_VIDEO: {
	SLtt_reverse_video (get_int32(buf));
	return 0;
    }
    case TT_BOLD_VIDEO: {
	SLtt_begin_insert();
	return 0;
    }
    case TT_BEGIN_INSERT: {
	SLtt_begin_insert();
	return 0;
    }
    case TT_END_INSERT: {
	SLtt_end_insert();
	return 0;
    }
    case TT_DEL_EOL: {
	SLtt_del_eol();
	return 0;
    }
    case TT_GOTO_RC: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_goto_rc (x, y);
	return 0;
    }
    case TT_DELETE_NLINES: {
	SLtt_delete_nlines(get_int32(buf));
	return 0;
    }
    case TT_DELETE_CHAR: {
	SLtt_delete_char();
	return 0;
    }
    case TT_ERASE_LINE: {
	SLtt_erase_line();
	return 0;
    }
    case TT_NORMAL_VIDEO: {
	SLtt_normal_video();
	return 0;
    }
    case TT_CLS: {
	SLtt_cls();
	return 0;
    }
    case TT_BEEP: {
	SLtt_beep();
	return 0;
    }
    case TT_REVERSE_INDEX: {
	SLtt_reverse_index(get_int32(buf));
	return 0;
    }
    case TT_SMART_PUTS: {
	SLsmg_Char_Type *t1 ;
	SLsmg_Char_Type *t2;

	t1 = decode_smg_char_type(&buf);
	t2 = decode_smg_char_type(&buf);
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_smart_puts(t1, t2,x,y);
	return 0;
    }
    case TT_WRITE_STRING: {
	SLtt_write_string (buf);
	return 0;
    }
    case TT_PUTCHAR: {
	SLtt_putchar((char) get_int32(buf));
	return 0;
    }
    case TT_INIT_VIDEO: {
	ret = SLtt_init_video ();
	return ret_int(port, ret);	
    }
    case TT_RESET_VIDEO: {
	SLtt_reset_video ();
	return 0;
    }
    case TT_GET_TERMINFO: {
	SLtt_get_terminfo();
	return 0;
    }
    case TT_GET_SCREEN_SIZE: {
	SLtt_get_screen_size ();
	return 0;
    }
    case TT_SET_CURSOR_VISIBILITY: {
	ret = SLtt_set_cursor_visibility (get_int32(buf));
	return ret_int(port, ret);	
    }
    case TT_SET_MOUSE_MODE: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	ret = SLtt_set_mouse_mode (x,y);
	return ret_int(port, ret);	
    }

    case TT_INITIALIZE: {
	ret =SLtt_initialize (buf);
	return ret_int(port, ret);	
    }
    case TT_ENABLE_CURSOR_KEYS: {
	SLtt_enable_cursor_keys();
	return 0;
    }
    case TT_SET_TERM_VTXXX: {
	
	return 0;
    }
    case TT_SET_COLOR_ESC: {
	x = get_int32(buf); buf+=4;
	SLtt_set_color_esc (x, buf);
	return 0;
    }
    case TT_WIDE_WIDTH: {
	SLtt_narrow_width();
	return 0;
    }
    case TT_NARROW_WIDTH: {
	SLtt_narrow_width();
	return 0;
    }
    case TT_SET_ALT_CHAR_SET: {
	SLtt_set_alt_char_set (get_int32(buf));
	return 0;
    }
    case TT_WRITE_TO_STATUS_LINE: {
	x = get_int32(buf); buf+=4;
	SLtt_write_to_status_line (buf, x);
	return 0;
    }
    case TT_DISABLE_STATUS_LINE: {
	SLtt_disable_status_line ();
	return 0;
    }


    case TT_TGETSTR: {
	str = SLtt_tgetstr (buf);
	return ret_string(port, str);
    }
    case TT_TGETNUM: {
	x = SLtt_tgetnum (buf);
	return ret_int(port, x);
    }
    case TT_TGETFLAG: {
	x = SLtt_tgetflag (buf);
	return  ret_int(port, x);
    }
    case TT_TIGETENT: {
	str = SLtt_tigetent (buf);
	return ret_string(port, str);
    }
    case TT_TIGETSTR: {
	
	return 0;
    }
    case TT_TIGETNUM: {

	return 0;
    }

    case SLTT_GET_COLOR_OBJECT: {
	x = get_int32(buf); buf+=4;
	y = SLtt_get_color_object (x);
	return  ret_int(port, y);
	return 0;
    }
    case TT_SET_COLOR_OBJECT: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_set_color_object (x, y);
	return 0;
    }
    case TT_SET_COLOR: {
	x = get_int32(buf); buf+=4;
	t1 = buf;
	t2 = buf + (strlen(t1) + 1);
	t3 = buf + (strlen(t1) + strlen(t2) + 2);
	SLtt_set_color (x, t1, t2, t3);
	return 0;
    }
    case TT_SET_MONO: {
	x = get_int32(buf); buf+=4;
	t1 = buf;
	buf += strlen(t1) + 1;
	y = get_int32(buf);
	SLtt_set_mono (x, t1, y);
	return 0;
    }
    case TT_ADD_COLOR_ATTRIBUTE: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_add_color_attribute (x, y);
	return 0;
    }
    case TT_SET_COLOR_FGBG: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	z = get_int32(buf); buf+=4;
	SLtt_set_color_fgbg (x, y, z);
	return 0;
    }
    case ISATTY: {
	x = get_int32(buf); buf+=4;
	return ret_int(port, isatty(x));
    }
    case EFORMAT: {
	fprintf(stderr, "%s", buf);
	fflush(stderr);
	return 0;
    }
    case SIGNAL: {
	x = get_int32(buf); buf+=4;
	SLsignal(x_to_sig(x), sig_handler);
	return 0;
    }
    case SIGNAL_CHECK: {
	/* polled */
	if (signal_cought != 0)
	    signal_cought = 0;
	return ret_int(port, signal_cought);
    }

    default:
	return 0;
    }
}
Esempio n. 18
0
bool SLangConsole::init() {

  setenv("TERM","xterm-color",0); 
  SLtt_get_terminfo();

  if( -1 == SLkp_init() ) { // keyboard interface
	error("failure in SLkp_init()");
  	return false;
  }

  SLang_init_tty(-1, 0, 0);

  SLsmg_init_smg(); // screen manager

  //  SLutf8_enable(1); // enable UTF8 character set
//  this is a mess ...
  screen_size_changed = false;

  // register signals
  SLsignal (SIGWINCH, sigwinch_handler);
  SLang_set_abort_signal(sigint_handler);

  SLkp_set_getkey_function(getkey_handler);
  

  // SLsmg_Tab_Width = 8;
  // SLsmg_Display_Eight_Bit = 1;
  // SLtt_Use_Ansi_Colors = 0;
  // SLtt_Term_Cannot_Scroll = 0;

  // set sizes of the whole console
  w = SLtt_Screen_Cols;
  h = SLtt_Screen_Rows;

  /* setup colors with the palette scheme:
     n = normal;
     n+10 = highlight;
     n+20 = reverse normal;
     n+30 = reverse highlight; */

  // crazy casting for crazy slang
  SLtt_set_color(1,NULL,(char *)"lightgray",(char *)"black");
  SLtt_set_color(11,NULL,(char *)"white",(char *)"black");
  SLtt_set_color(21,NULL,(char *)"black",(char *)"lightgray");
  SLtt_set_color(31,NULL,(char *)"black",(char *)"white");
  
  SLtt_set_color(2,NULL,(char *)"red",(char *)"black");
  SLtt_set_color(12,NULL,(char *)"brightred",(char *)"black");
  SLtt_set_color(22,NULL,(char *)"black",(char *)"red");
  SLtt_set_color(32,NULL,(char *)"black",(char *)"brightred");
  
  SLtt_set_color(3,NULL,(char *)"green",(char *)"black");
  SLtt_set_color(13,NULL,(char *)"brightgreen",(char *)"black");
  SLtt_set_color(23,NULL,(char *)"black",(char *)"green");
  SLtt_set_color(33,NULL,(char *)"black",(char *)"brightgreen");
  
  SLtt_set_color(4,NULL,(char *)"brown",(char *)"black");
  SLtt_set_color(14,NULL,(char *)"yellow",(char *)"black");
  SLtt_set_color(24,NULL,(char *)"black",(char *)"brown");
  SLtt_set_color(34,NULL,(char *)"black",(char *)"yellow");
  
  SLtt_set_color(5,NULL,(char *)"blue",(char *)"black");
  SLtt_set_color(15,NULL,(char *)"brightblue",(char *)"black");
  SLtt_set_color(25,NULL,(char *)"black",(char *)"blue");
  SLtt_set_color(35,NULL,(char *)"black",(char *)"brightblue");
  
  SLtt_set_color(6,NULL,(char *)"magenta",(char *)"black");
  SLtt_set_color(16,NULL,(char *)"brightmagenta",(char *)"black");
  SLtt_set_color(26,NULL,(char *)"black",(char *)"magenta");
  SLtt_set_color(36,NULL,(char *)"black",(char *)"brightmagenta");
  
  SLtt_set_color(7,NULL,(char *)"cyan",(char *)"black");
  SLtt_set_color(17,NULL,(char *)"brightcyan",(char *)"black");
  SLtt_set_color(27,NULL,(char *)"black",(char *)"cyan");
  SLtt_set_color(37,NULL,(char *)"black",(char *)"brightcyan");
  

  
  refresh();

  return true;
}
Esempio n. 19
0
static void sigwinch_handler (int sig) {
  screen_size_changed = true;
  SLsignal (SIGWINCH, sigwinch_handler);
}
Esempio n. 20
0
/* this is the main key processing loop for interactive mode */
void display_results_interactively() {

  bool_t done = 0;
  int c, c1;

  /* set up the terminal etc. */
  SLang_init_tty(-1, 0, 0);
  SLtt_get_terminfo();
  if(-1 == SLsmg_init_smg() ) {
    fprintf (stderr, "Unable to initialize terminal.");
    return;
  }
  SLkp_init(); /* for cursor keys */

  SLsignal(SIGWINCH, sigwinch_handler);

  init_disp_state();

  while(!done) {

    redraw_current_state();

    c = SLang_getkey();

    /* if it's a meta combination, translate */
    if( c == '' ) {
      c1 = SLang_getkey();
      switch(c1) {

      case '<':
	c = SL_KEY_HOME;
	break;

      case '>':
	c = SL_KEY_END;
	break;

      case 'v':
      case 'V':
	c = SL_KEY_PPAGE;
	break;

      case 'r':
      case 'R':
	c = '?';
	break;

      case 's':
      case 'S':
	c = '/';
	break;

      default:
	/* could be special cursor keys */
	SLang_ungetkey(c1);
	SLang_ungetkey(c);
	c = SLkp_getkey();
      }
    }

    /* handle key press */
    switch(c) {

    case 'q':
    case 'Q':
      done = 1;
      break;

    case 'c':
      interactive_categorize();
      disp.highlighted = disp.first_visible = 0;
      break;

    case '\r':
    case 'v':
      if( emails.num_limited > 0 ) {
	view_current_email();
      }
      break;

    case SL_KEY_F(1):
      if( emails.num_limited > 0 && disp.fkey_cmd[0] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[0]);
      }
      break;

    case SL_KEY_F(2):
      if( emails.num_limited > 0 && disp.fkey_cmd[1] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[1]);
      }
      break;

    case SL_KEY_F(3):
      if( emails.num_limited > 0 && disp.fkey_cmd[2] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[2]);
      }
      break;

    case SL_KEY_F(4):
      if( emails.num_limited > 0 && disp.fkey_cmd[3] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[3]);
      }
      break;

    case SL_KEY_F(5):
      if( emails.num_limited > 0 && disp.fkey_cmd[4] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[4]);
      }
      break;

    case SL_KEY_F(6):
      if( emails.num_limited > 0 && disp.fkey_cmd[5] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[5]);
      }
      break;

    case SL_KEY_F(7):
      if( emails.num_limited > 0 && disp.fkey_cmd[6] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[6]);
      }
      break;

    case SL_KEY_F(8):
      if( emails.num_limited > 0 && disp.fkey_cmd[7] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[7]);
      }
      break;

    case SL_KEY_F(9):
      if( emails.num_limited > 0 && disp.fkey_cmd[8] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[8]);
      }
      break;

    case SL_KEY_F(10):
      if( emails.num_limited > 0 && disp.fkey_cmd[9] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[9]);
      }
      break;

    case 's':
      if( emails.num_limited > 0 ) {
	interactive_pipe_current("");
      }
      break;

    case 'S':
      if( emails.num_limited > 0 ) {
	interactive_pipe_all_tagged("");
      }
      break;

    case 'o':
      if( ++emails.score_type >= MAX_SCORES ) {
	emails.score_type = 0;
      }
      qsort(emails.list, emails.num_emails, sizeof(mbox_item), compare_scores);
      recalculate_limited();
      break;

    case 'p':
      if( ++emails.index_format >= MAX_FORMATS ) {
	emails.index_format = 0;
      }
      break;

    case 't':
      if( emails.num_limited > 0 ) {
	tag_current(1);
      }
      break;

    case 'T':
      if( emails.num_limited > 0 ) {
	tag_all_limited(1);
      }
      break;

    case 'u':
      if( emails.num_limited > 0 ) {
	tag_current(0);
      }
      break;

    case 'U':
      if( emails.num_limited > 0 ) {
	tag_all_limited(0);
      }
      break;

    case 'z':
      reverse_sort();
      recalculate_limited();
      break;

    case 'G':
    case SL_KEY_END:
      if( emails.num_limited > 0 ) {
	disp.first_visible = emails.num_limited - 1;
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '1':
    case SL_KEY_HOME:
      disp.first_visible = 0;
      break;

    case '':
    case SL_KEY_PPAGE:
      if( disp.first_visible > disp.num_rows )
	{ disp.first_visible -= disp.num_rows; }
      else
	{ disp.first_visible = 0; disp.highlighted = 0; }

      /* assert emails.num_limited >= disp.first_visible */
      if( disp.highlighted > (emails.num_limited - disp.first_visible) ) {
	disp.highlighted = (emails.num_limited - disp.first_visible);
      }
      break;

    case 'k':
    case '':
    case SL_KEY_UP:
      if( disp.highlighted > 0 ) {
	disp.highlighted--;
      } else {
	if( disp.first_visible > 1 ) 
	  { disp.first_visible -= 1; }
	else
	  { disp.first_visible = 0; }
      }
      break;

    case 'j':
    case '':
    case SL_KEY_DOWN:
      if( emails.num_limited > 0 ) {
	if( disp.highlighted < (emails.num_limited - disp.first_visible - 1) ) {
	  if( disp.highlighted < (disp.num_rows - 3) ) {
	    disp.highlighted++;
	  } else {
	    if( (disp.first_visible += 1) >= emails.num_limited ) 
	      { disp.first_visible = emails.num_limited - 1; }
	  }
	}
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '':
    case '':
    case ' ':
    case SL_KEY_NPAGE:
      if( emails.num_limited > 0 ) {
	if( (disp.first_visible += disp.num_rows) >= emails.num_limited ) 
	  { disp.first_visible = emails.num_limited - 1; }

	if( disp.highlighted > (emails.num_limited - disp.first_visible) ) {
	  disp.highlighted = (emails.num_limited - disp.first_visible) - 1;
	}
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '?':
      interactive_search(0, "");
      disp.highlighted = disp.first_visible = 0;
      break;
    case '/':
      interactive_search(1, "");
      disp.highlighted = disp.first_visible = 0;
      break;

    default:
      break;
    }

  }

  /* we're done */
  SLsmg_reset_smg();
  SLang_reset_tty();
}
Esempio n. 21
0
int SLsystem (char *cmd)
{
#ifdef SLANG_POSIX_SIGNALS
   pid_t pid;
   int status;
   struct sigaction ignore;
# ifdef SIGINT
   struct sigaction save_intr;
# endif
# ifdef SIGQUIT
   struct sigaction save_quit;
# endif
# ifdef SIGCHLD
   sigset_t child_mask, save_mask;
# endif

   if (cmd == NULL) return 1;

   ignore.sa_handler = SIG_IGN;
   sigemptyset (&ignore.sa_mask);
   ignore.sa_flags = 0;

# ifdef SIGINT
   if (-1 == sigaction (SIGINT, &ignore, &save_intr))
     return -1;
# endif

# ifdef SIGQUIT
   if (-1 == sigaction (SIGQUIT, &ignore, &save_quit))
     {
	(void) sigaction (SIGINT, &save_intr, NULL);
	return -1;
     }
# endif

# ifdef SIGCHLD
   sigemptyset (&child_mask);
   sigaddset (&child_mask, SIGCHLD);
   if (-1 == sigprocmask (SIG_BLOCK, &child_mask, &save_mask))
     {
#  ifdef SIGINT
	(void) sigaction (SIGINT, &save_intr, NULL);
#  endif
#  ifdef SIGQUIT
	(void) sigaction (SIGQUIT, &save_quit, NULL);
#  endif
	return -1;
     }
# endif

   pid = fork();

   if (pid == -1)
     status = -1;
   else if (pid == 0)
     {
	/* Child */
# ifdef SIGINT
	(void) sigaction (SIGINT, &save_intr, NULL);
# endif
# ifdef SIGQUIT
	(void) sigaction (SIGQUIT, &save_quit, NULL);
# endif
# ifdef SIGCHLD
	(void) sigprocmask (SIG_SETMASK, &save_mask, NULL);
# endif

	execl ("/bin/sh", "sh", "-c", cmd, NULL);
	_exit (127);
     }
   else
     {
	/* parent */
	while (-1 == waitpid (pid, &status, 0))
	  {
# ifdef EINTR
	     if (errno == EINTR)
	       continue;
# endif
# ifdef ERESTARTSYS
	     if (errno == ERESTARTSYS)
	       continue;
# endif
	     status = -1;
	     break;
	  }
     }
# ifdef SIGINT
   if (-1 == sigaction (SIGINT, &save_intr, NULL))
     status = -1;
# endif
# ifdef SIGQUIT
   if (-1 == sigaction (SIGQUIT, &save_quit, NULL))
     status = -1;
# endif
# ifdef SIGCHLD
   if (-1 == sigprocmask (SIG_SETMASK, &save_mask, NULL))
     status = -1;
# endif

   return status;

#else				       /* No POSIX Signals */
# ifdef SIGINT
   void (*sint)(int);
# endif
# ifdef SIGQUIT
   void (*squit)(int);
# endif
   int status;

# ifdef SIGQUIT
   squit = SLsignal (SIGQUIT, SIG_IGN);
# endif
# ifdef SIGINT
   sint = SLsignal (SIGINT, SIG_IGN);
# endif
   status = system (cmd);
# ifdef SIGINT
   SLsignal (SIGINT, sint);
# endif
# ifdef SIGQUIT
   SLsignal (SIGQUIT, squit);
# endif
   return status;
#endif				       /* POSIX_SIGNALS */
}
Esempio n. 22
0
static void
tty_setup_sigwinch (void (*handler) (int))
{
    (void) SLsignal (SIGWINCH, handler);
}
Esempio n. 23
0
static void reset_tty (void)
{
    SLsignal (SIGINT, last_sig_sigint);
}
Esempio n. 24
0
static void init_tty (void)
{
    last_sig_sigint = SLsignal (SIGINT, gnu_rl_sigint_handler);
}
Esempio n. 25
0
static void deinit_sigtstp (void)
{
    SLsignal (SIGTSTP, last_sig_sigtstp);
    (void) SLang_remove_interrupt_hook (sigtstp_interrupt_hook, NULL);
}
Esempio n. 26
0
static void math_floating_point_exception (int sig)
{
   sig = errno;
   (void) SLsignal (SIGFPE, math_floating_point_exception);
   errno = sig;
}