/***====================================================================***/
void
-uFatalError(const char *s, ...)
-{
- va_list args;
-
- if (!errorFile)
- errorFile = stderr;
-
- if ((outCount == 0) && (preMsg != NULL))
- fprintf(errorFile, "%s\n", preMsg);
- if (prefix != NULL)
- fprintf(errorFile, "%s", prefix);
- fprintf(errorFile, "Fatal Error: ");
- va_start(args, s);
- vfprintf(errorFile, s, args);
- va_end(args);
- fprintf(errorFile, " Exiting\n");
- fflush(errorFile);
- outCount++;
- exit(1);
- /* NOTREACHED */
-}
-
-/***====================================================================***/
-
-void
uInternalError(const char *s, ...)
{
va_list args;
#include "parseutils.h"
#include "path.h"
+ATTR_MALLOC static void *
+malloc_or_die(size_t size)
+{
+ void *p = malloc(size);
+ if (!p) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
+ return p;
+}
+
ParseCommon *
AppendStmt(ParseCommon * to, ParseCommon * append)
{
{
ExprDef *expr;
- expr = malloc(sizeof(*expr));
- if (!expr)
- FATAL("Couldn't allocate expression in parser\n");
+ expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr;
expr->common.next = NULL;
ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
{
ExprDef *expr;
- expr = malloc(sizeof(*expr));
- if (!expr)
- FATAL("Couldn't allocate expression in parser\n");
+ expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr;
expr->common.next = NULL;
{
ExprDef *expr;
- expr = malloc(sizeof(*expr));
- if (!expr)
- FATAL("Couldn't allocate expression in parser\n");
+ expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr;
expr->common.next = NULL;
{
KeycodeDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate key name definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeycodeDef;
def->common.next = NULL;
{
KeyAliasDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate key alias definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeyAliasDef;
def->common.next = NULL;
{
VModDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate variable definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtVModDef;
def->common.next = NULL;
VarCreate(ExprDef * name, ExprDef * value)
{
VarDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate variable definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtVarDef;
def->common.next = NULL;
{
InterpDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate interp definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtInterpDef;
def->common.next = NULL;
{
KeyTypeDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate key type definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeyTypeDef;
def->common.next = NULL;
{
SymbolsDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate symbols definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtSymbolsDef;
def->common.next = NULL;
{
GroupCompatDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate group compat definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtGroupCompatDef;
def->common.next = NULL;
{
ModMapDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate mod mask definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtModMapDef;
def->common.next = NULL;
{
IndicatorMapDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate indicator map definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtIndicatorMapDef;
def->common.next = NULL;
{
IndicatorNameDef *def;
- def = malloc(sizeof(*def));
- if (!def)
- FATAL("Couldn't allocate indicator index definition in parser\n");
+ def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtIndicatorNameDef;
def->common.next = NULL;
{
ExprDef *act;
- act = malloc(sizeof(*act));
- if (!act)
- FATAL("Couldn't allocate ActionDef in parser\n");
+ act = malloc_or_die(sizeof(*act));
act->common.stmtType = StmtExpr;
act->common.next = NULL;
ExprDef *def;
def = ExprCreate(ExprKeysymList, TypeSymbols);
- if (!def) {
- FATAL("Couldn't allocate expression for keysym list in parser\n");
- return NULL;
- }
darray_init(def->value.list.syms);
darray_init(def->value.list.symsMapIndex);