예제 #1
0
static void
handler(int signo)
{
	SigTable *sig_tbl;
	AWKNUM ret;
	static INSTRUCTION *code;
	extern int exiting;

	sig_tbl = sig2ptr(signo);

	/* make function call instructions */
	code = bcalloc(Op_func_call, 2, 0);
	code->func_name = NULL;		/* not needed, func_body will assign */
	code->nexti = bcalloc(Op_stop, 1, 0);

	code->func_body = sig_tbl->user_handler;
	(code + 1)->expr_count = 1;	/* function takes one argument */

	PUSH(make_number((AWKNUM) signo));

	interpret(code);
	if (exiting)	/* do not assume anything about the user-defined function! */
		gawk_exit(exit_val);

	POP_NUMBER(ret);

	bcfree(code->nexti);            /* Op_stop */
	bcfree(code);                   /* Op_func_call */

	return;
}
예제 #2
0
파일: msg.c 프로젝트: Distrotech/gawk
/* VARARGS2 */
void
err(bool isfatal, const char *s, const char *emsg, va_list argp)
{
	char *file;
	const char *me;

	static bool first = true;
	static bool add_src_info = false;

	if (first) {
		first = false;
		add_src_info = (getenv("GAWK_MSG_SRC") != NULL);
	}

	(void) fflush(output_fp);
	me = myname;
	(void) fprintf(stderr, "%s: ", me);

	if (srcfile != NULL && add_src_info) {
		fprintf(stderr, "%s:%d:", srcfile, srcline);
		srcfile = NULL;
	}

	if (sourceline > 0) {
		if (source != NULL)
			(void) fprintf(stderr, "%s:", source);
		else
			(void) fprintf(stderr, _("cmd. line:"));

		(void) fprintf(stderr, "%d: ", sourceline);
	}

#ifdef HAVE_MPFR
	if (FNR_node && is_mpg_number(FNR_node->var_value)) {
		NODE *val;
		val = mpg_update_var(FNR_node);
		assert((val->flags & MPZN) != 0);
		if (mpz_sgn(val->mpg_i) > 0) {
			file = FILENAME_node->var_value->stptr;
			(void) putc('(', stderr);
			if (file)
				(void) fprintf(stderr, "FILENAME=%s ", file);
			(void) mpfr_fprintf(stderr, "FNR=%Zd) ", val->mpg_i);
		}
	} else
#endif
	if (FNR > 0) {
		file = FILENAME_node->var_value->stptr;
		(void) putc('(', stderr);
		if (file)
			(void) fprintf(stderr, "FILENAME=%s ", file);
		(void) fprintf(stderr, "FNR=%ld) ", FNR);
	}

	(void) fprintf(stderr, "%s", s);
	vfprintf(stderr, emsg, argp);
	(void) fprintf(stderr, "\n");
	(void) fflush(stderr);

	if (isfatal) {
#ifdef GAWKDEBUG
		abort();
#endif
		gawk_exit(EXIT_FATAL);
	}
}