1
0
mirror of https://frontier.innolan.net/rainlance/amiga-ntimed.git synced 2025-11-21 07:00:37 +00:00

Initial commit

This commit is contained in:
llsth
2015-03-07 23:29:12 +01:00
parent db0abbb4c8
commit a56b6e0b0f
20 changed files with 1565 additions and 374 deletions

View File

@ -72,29 +72,31 @@ static FILE *tracefile;
static FILE *
getdst(enum ocx_chan chan)
{
if (chan == OCX_DIAG)
return (stderr);
if (chan == OCX_TRACE)
return (tracefile);
if (chan == OCX_DEBUG)
return (stdout);
WRONG("Wrong ocx_chan");
NEEDLESS_RETURN(NULL);
if (chan == OCX_DIAG)
return (stderr);
if (chan == OCX_TRACE)
return (tracefile);
if (chan == OCX_DEBUG)
return (stdout);
WRONG("Wrong ocx_chan");
NEEDLESS_RETURN(NULL);
}
static void __match_proto__()
static void
putv(struct ocx *ocx, enum ocx_chan chan, const char *fmt, va_list ap)
{
FILE *dst = getdst(chan);
va_list ap2;
FILE *dst = getdst(chan);
va_list ap2;
va_copy(ap2, ap);
AZ(ocx);
if (dst != NULL)
(void)vfprintf(dst, fmt, ap);
if (chan == OCX_DIAG)
vsyslog(LOG_ERR, fmt, ap2);
va_end(ap2);
va_copy(ap2, ap);
AZ(ocx);
if (dst != NULL) {
(void)vfprintf(dst, fmt, ap);
fflush(dst);
}
// if (chan == OCX_DIAG)
// vsyslog(LOG_ERR, fmt, ap2);
va_end(ap2);
}
/**********************************************************************
@ -105,23 +107,23 @@ void
ArgTracefile(const char *fn)
{
if (tracefile != NULL && tracefile != stdout) {
AZ(fclose(tracefile));
tracefile = NULL;
}
if (tracefile != NULL && tracefile != stdout) {
AZ(fclose(tracefile));
tracefile = NULL;
}
if (fn == NULL)
return;
if (fn == NULL)
return;
if (!strcmp(fn, "-")) {
tracefile = stdout;
return;
}
if (!strcmp(fn, "-")) {
tracefile = stdout;
return;
}
tracefile = fopen(fn, "w");
if (tracefile == NULL)
Fail(NULL, 1, "Could not open '%s' for writing", fn);
setbuf(tracefile, NULL);
tracefile = fopen(fn, "w");
if (tracefile == NULL)
Fail(NULL, 1, "Could not open '%s' for writing", fn);
setbuf(tracefile, NULL);
}
/**********************************************************************
@ -132,42 +134,43 @@ ArgTracefile(const char *fn)
void
Put(struct ocx *ocx, enum ocx_chan chan, const char *fmt, ...)
{
va_list ap;
va_list ap;
AZ(ocx);
va_start(ap, fmt);
putv(ocx, chan, fmt, ap);
va_end(ap);
AZ(ocx);
va_start(ap, fmt);
putv(ocx, chan, fmt, ap);
va_end(ap);
}
void
PutHex(struct ocx *ocx, enum ocx_chan chan, const void *ptr, ssize_t len)
{
const uint8_t *p = ptr;
const char *s = "";
const uint8_t *p = ptr;
const char *s = "";
AN(ptr);
assert(len >= 0);
AN(ptr);
assert(len >= 0);
while(len--) {
Put(ocx, chan, "%s%02x", s, *p++);
s = " ";
}
while(len--) {
// Put(ocx, chan, "%s%02x", s, *p++);
Put(ocx, chan, "%s%x", s, *p++);
s = " ";
}
}
void
Fail(struct ocx *ocx, int err, const char *fmt, ...)
{
va_list ap;
va_list ap;
if (err)
err = errno;
Put(ocx, OCX_DIAG, "Failure: ");
va_start(ap, fmt);
putv(ocx, OCX_DIAG, fmt, ap);
va_end(ap);
Put(ocx, OCX_DIAG, "\n");
if (err)
Put(ocx, OCX_DIAG, "errno = %d (%s)\n", err, strerror(err));
exit(1);
if (err)
err = errno;
Put(ocx, OCX_DIAG, "Failure: ");
va_start(ap, fmt);
putv(ocx, OCX_DIAG, fmt, ap);
va_end(ap);
Put(ocx, OCX_DIAG, "\n");
if (err)
Put(ocx, OCX_DIAG, "errno = %d (%s)\n", err, strerror(err));
exit(1);
}