renamed most source files
This commit is contained in:
95
tecs/err_handling.c
Normal file
95
tecs/err_handling.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "err_handling.h"
|
||||
|
||||
#define SLEN 64
|
||||
#define MLEN 64
|
||||
|
||||
static char *txt[SLEN];
|
||||
static int sp=0;
|
||||
|
||||
int ErrCode;
|
||||
char *ErrMessage=NULL;
|
||||
void (*outrtn)()=NULL;
|
||||
void *outarg;
|
||||
|
||||
void ErrTxt(char *text, int systemError)
|
||||
{
|
||||
if (systemError) { sp=0; ErrCode=errno; ErrMessage=strerror(errno); }
|
||||
if (sp<SLEN) {
|
||||
txt[sp++]=text;
|
||||
}
|
||||
}
|
||||
|
||||
void ErrMsg(char *msg)
|
||||
{
|
||||
ErrCode=-1;
|
||||
ErrMessage=msg; sp=0;
|
||||
}
|
||||
|
||||
void ErrCod(int code)
|
||||
{
|
||||
ErrCode=code;
|
||||
ErrMessage=strerror(code); sp=0;
|
||||
}
|
||||
|
||||
void ErrOutFil(void *arg, char *text) {
|
||||
fprintf((FILE *)arg, "%s\n", text);
|
||||
}
|
||||
|
||||
void ErrWrite(char *text)
|
||||
{
|
||||
int i, l;
|
||||
char buf[256];
|
||||
|
||||
if (outrtn==NULL) {
|
||||
outrtn=ErrOutFil;
|
||||
outarg=stdout;
|
||||
}
|
||||
l=strlen(text)+strlen(ErrMessage)+6;
|
||||
assert(l<256);
|
||||
sprintf(buf, "--- %s: %s", text, ErrMessage);
|
||||
for (i=0;i<sp;i++) {
|
||||
if (txt[i][0]==':') {
|
||||
l+=strlen(txt[i]);
|
||||
assert(l<256);
|
||||
strcat(buf, &(txt[i][1]));
|
||||
} else {
|
||||
outrtn(outarg, buf);
|
||||
l=strlen(txt[i]);
|
||||
assert(l<256);
|
||||
strcpy(buf, txt[i]);
|
||||
}
|
||||
}
|
||||
outrtn(outarg, buf);
|
||||
outrtn(outarg, "");
|
||||
}
|
||||
|
||||
void ErrSetOutRtn(void (*rtn)(), void *arg) {
|
||||
outrtn=rtn;
|
||||
outarg=arg;
|
||||
}
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
typedef struct { short size, dummy; char *text; } Desc;
|
||||
|
||||
void ErrShowVms(Desc *desc, void (*outrtn)(), void *arg) {
|
||||
char buf[256];
|
||||
int l;
|
||||
|
||||
l=desc->size;
|
||||
if (l>=256) l=255;
|
||||
strncpy(buf, desc->text, l);
|
||||
buf[l]='\0';
|
||||
ErrWrite(buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ERR_EXIT(char *text) {
|
||||
ErrWrite(text); exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user