Ejemplo n.º 1
0
int SLang_set_error (int error)
{
   set_error (error);

   if (error == 0)
     return 0;

   if (error == SL_UserBreak_Error)
     {
	/* This function may be called from a SIGINT handler, in which case the 
	 * error code will be SL_UserBreak_Error.
	 */
	/* print_error (_SLERR_MSG_ERROR, SLerr_strerror (_pSLang_Error)); */
	Static_Error_Message = SLerr_strerror (error);
	return 0;
     }	
   
   /* If a string is not in the message queue, then add one. */
   if (Active_Error_Queue != NULL)
     {
	Error_Message_Type *m = Active_Error_Queue->head;
	while (m != NULL)
	  {
	     if (m->msg_type == _SLERR_MSG_ERROR)
	       return 0;
	     m = m->next;
	  }
     }
   
   _pSLang_verror (_pSLang_Error, "%s", SLerr_strerror (_pSLang_Error));
   return 0;
}
Ejemplo n.º 2
0
static int example_3 (void)
{
   SLrline_Type *rl;
   unsigned int width = 80;

   if ((-1 == SLang_init_all ())
       || (-1 == SLang_init_array_extra ())
       || (-1 == SLang_init_import ()))
     return -1;

   (void) SLpath_set_load_path ("../slsh/lib");

   if (-1 == SLrline_init ("demo/rline", NULL, NULL))
     return -1;

   issue_instructions ();

   SLang_init_tty (-1, 0, 1);
   SLang_set_abort_signal (NULL);

   rl = SLrline_open2 ("rline", width, SL_RLINE_BLINK_MATCH);
   if (rl == NULL)
     return -1;

   while (1)
     {
	char *line;
	unsigned int len;

	line = SLrline_read_line (rl, "prompt>", &len);
	if (line == NULL)
	  {
	     int err = SLang_get_error ();
	     if (err == SL_UserBreak_Error)
	       {
		  (void) fprintf (stderr, "*Interrupted*\n");
		  SLang_set_error (0);
		  SLKeyBoard_Quit = 0;
		  continue;
	       }
	     if (err == 0)
	       break;		       /* EOF */
	     fprintf (stderr, "Error Occurred: %s\n", SLerr_strerror (err));
	     break;
	  }
	if (0 == strcmp (line, "quit"))
	  {
	     SLfree (line);
	     break;
	  }
	(void) fprintf (stdout, "\nRead %d bytes: %s\n", strlen(line), line);
	if (-1 == SLrline_save_line (rl))
	  break;

	SLfree (line);
     }
   SLrline_close (rl);
   SLang_reset_tty ();
   return 0;
}
Ejemplo n.º 3
0
static void do_file_line_funct_error (SLCONST char *file, int linenum, SLCONST char *function)
{
   if ((file == NULL) || (_pSLang_Error == 0))
     return;

   if (Last_Function_With_Error == function)	       /* either slstring or "<top-level>" */
     return;
   Last_Function_With_Error = function;
   if (SLang_Traceback && *function)
     _pSLerr_traceback_msg ("%s:%d:%s:%s\n", file, linenum, function, SLerr_strerror (_pSLang_Error));
}
Ejemplo n.º 4
0
Archivo: screen.c Proyecto: hankem/jed
/* This routine is a mess and it, do_dialog, and the Mini_Ghost flag needs
 * to be totally redesigned.
 */
void update(Line *line, int force, int flag, int run_update_hook)
{
   int pc_flag = 1;
   int col;
   static unsigned long last_time;
   Line *hscroll_line_save;

   if (0 == Jed_Display_Initialized)
     return;

#if JED_HAS_SUBPROCESSES
   if (Child_Status_Changed_Flag)
     {
	jed_get_child_status ();
	force = 1;
     }
#endif

   if (Batch) return;

   if (!force && !SLang_get_error () && !SLKeyBoard_Quit && (!*Error_Buffer))
     {
	if (screen_input_pending (0))
	  {
	     JWindow->trashed = 1;
	     return;
	  }
     }

   if (last_time + 30 < Status_This_Time)
     {
	if (last_time == 0) last_time = Status_This_Time;
	else
	  {
	     last_time = Status_This_Time;
	     if (SLang_run_hooks ("update_timer_hook", 0))
	       flag = 0;
	  }
     }

   if (run_update_hook
       && (CBuf->buffer_hooks != NULL)
       && (CBuf->buffer_hooks->update_hook != NULL)
       && (SLang_get_error () == 0))
     {
	Suspend_Screen_Update = 1;
	SLexecute_function (CBuf->buffer_hooks->update_hook);
	if (SLang_get_error ()) CBuf->buffer_hooks->update_hook = NULL;
     }

   if (Suspend_Screen_Update != 0)
     {
	Suspend_Screen_Update = 0;
	touch_screen ();
     }

   if (X_Update_Open_Hook != NULL) (*X_Update_Open_Hook) ();
#ifdef FIX_CHAR_WIDTH
   FIX_CHAR_WIDTH;
#endif
   col = calculate_column ();
   HScroll_Line = NULL;
   if (Wants_HScroll) set_hscroll(col); else HScroll = 0;
   hscroll_line_save = HScroll_Line;

   if (SLang_get_error ()) flag = 0;	       /* update hook invalidates flag */

   if (SLang_get_error () && !(*Error_Buffer || SLKeyBoard_Quit))
     {
	SLang_verror (0, "%s", SLerr_strerror (0));
     }

   if (!flag && (*Error_Buffer || SLKeyBoard_Quit))
     {
	do_dialog(Error_Buffer);
#if 0
	SLKeyBoard_Quit = 0;
	SLang_restart(0);
	SLang_set_error (0);
#endif
	Mini_Ghost = 1;
	(void) update_1(line, 1);
	update_minibuffer();
     }
   else if ((flag == 0) && *Message_Buffer)
     {
	if (!update_1(line, force))
	  goto done;

	do_dialog(Message_Buffer);
	Mini_Ghost = 1;
	update_minibuffer();
     }
   else
     {
	pc_flag = JWindow->trashed || (JWindow != JWindow->next) || Cursor_Motion;
	if (!flag) update_minibuffer();
	if (!update_1(line, force)) goto done;
     }
   if (!flag) *Error_Buffer = *Message_Buffer = 0;

#if JED_HAS_MENUS
   update_top_screen_line ();
#else
   if ((Top_Window_SY > 0) && JScreen[0].is_modified)
     {
	update_top_screen_line ();
     }
#endif
   done:

   HScroll_Line = hscroll_line_save;

   if (MiniBuf_Get_Response_String != NULL)
     {
	do_dialog (MiniBuf_Get_Response_String);
	Mini_Ghost = 1;
     }
   else if (Point_Cursor_Flag || pc_flag)
     point_cursor(col);

   if (X_Update_Close_Hook != NULL) (*X_Update_Close_Hook) ();

   SLsmg_refresh ();
}
Ejemplo n.º 5
0
static void get_exception_info_intrinsic (void)
{
#define NUM_EXCEPT_FIELDS 8
   static SLFUTURE_CONST char *field_names[NUM_EXCEPT_FIELDS] =
     {
	"error", "descr", "file", "line", "function", "object", "message", "traceback"
     };
   SLtype field_types[NUM_EXCEPT_FIELDS];
   VOID_STAR field_values[NUM_EXCEPT_FIELDS];
   int err;
   SLCONST char *desc;
   SLCONST char *file;
   SLCONST char *function;
   SLCONST char *errmsg;
   SLCONST char *tbmsg;
   int linenum;

   err = _pSLerr_get_last_error ();
   if (err == 0)
     {
	(void) SLang_push_null ();
	return;
     }

   desc = SLerr_strerror (err);
   (void) _pSLerr_get_last_error_line_info (&file, &linenum, &function);

   field_types[0] = SLANG_INT_TYPE;
   field_values[0] = (VOID_STAR) &err;

   field_types[1] = SLANG_STRING_TYPE;
   field_values[1] = (VOID_STAR) &desc;

   field_types[2] = SLANG_STRING_TYPE;
   field_values[2] = (VOID_STAR) &file;

   field_types[3] = SLANG_INT_TYPE;
   field_values[3] = (VOID_STAR) &linenum;

   field_types[4] = SLANG_STRING_TYPE;
   field_values[4] = (VOID_STAR) &function;

   if ((Error_Context == NULL)
       || (Error_Context->object_was_thrown == 0))
     {
	char *null = NULL;
	field_types[5] = SLANG_NULL_TYPE;
	field_values[5] = (VOID_STAR) &null;
     }
   else
     {
	SLtype data_type = Error_Context->object_thrown.o_data_type;
	field_types[5] = data_type;
	field_values[5] = _pSLclass_get_ptr_to_value (_pSLclass_get_class (data_type),
						      &Error_Context->object_thrown);
     }
   errmsg = get_error_msg_from_queue  (_SLERR_MSG_ERROR);
   if ((errmsg == NULL) || (*errmsg == 0))
     errmsg = desc;
   field_types[6] = SLANG_STRING_TYPE;
   field_values[6] = (VOID_STAR) &errmsg;

   tbmsg = get_error_msg_from_queue  (_SLERR_MSG_TRACEBACK);
   field_types[7] = (tbmsg == NULL) ? SLANG_NULL_TYPE : SLANG_STRING_TYPE;
   field_values[7] = (VOID_STAR) &tbmsg;

   (void) SLstruct_create_struct (NUM_EXCEPT_FIELDS, field_names, field_types, field_values);
   if (errmsg != desc)
     SLang_free_slstring ((char *) errmsg);
   SLang_free_slstring ((char *)tbmsg);
}