#include "common.h"
#include "h_script.h"
#include "haserl.h"
#include "h_error.h"
char *g_err_msg[] = {
"",
"Memory Allocation Failure",
"Unable to open file %s",
"%c> before <%c",
"Missing %c>",
"Unknown operation",
"Unable to start subshell",
"Unspecified Error",
};
/*
* abort the program
*/
void
die_with_error (char *msg)
{
fprintf (stderr, "Error: %s\n", msg);
exit (-1);
}
/* print an error message and die. If sp or where are non-null pointers, then
a line is added saying where in the script buffer the error occured. If
there's a request method, then http headers are added.
*/
void
die_with_message (void *sp, char *where, const char *s, ...)
{
#ifndef JUST_LUACSHELL
script_t *script = sp;
#endif
va_list p;
FILE *fo = stderr;
if (global.silent == FALSE)
{
if (getenv ("REQUEST_METHOD"))
{
fo = stdout;
fprintf (fo, "HTTP/1.0 500 Server Error\n"
"Content-Type: text/html\n\n"
"" PACKAGE_NAME
" CGI Error
\n");
}
va_start (p, s);
vfprintf (fo, s, p);
va_end (p);
#ifndef JUST_LUACSHELL
if (where && sp)
{
fprintf (fo, " near line %d of %s\n",
count_lines (script->buf, script->size, where),
script->name);
}
#endif
printf ("\n");
if (getenv ("REQUEST_METHOD"))
fprintf (fo, "
\n");
}
exit (-1);
}