Commit 20cb122c authored by Richard Buckley's avatar Richard Buckley
Browse files

Removing need for SupportLib

parent fa1664d6
......@@ -36,7 +36,7 @@
#include "callback.h"
#include "m.h"
#include "riscos.h"
#include "trace.h"
#include "jc_trace.h"
#ifdef TRACE
/*#define XTRACE*/
......
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*trace.c - simple trace to tube*/
#undef TRACE
#define TRACE 0
/*From CLib*/
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*From OSLib*/
#include "econet.h"
#include "macros.h"
#include "os.h"
#include "osargs.h"
#include "osfile.h"
#include "osfind.h"
#include "osgbpb.h"
/*From Support*/
#include "hostfs.h"
#include "jc_trace.h"
#define TRACE_BUFFER_SIZE 512
#if TRACE
static os_f F;
static enum {To_Stdout, To_File, To_Tube, To_Nowhere, To_Econet, To_VDU}
Trace = To_Nowhere;
static os_error *Error = NULL;
static int S, N;
/*------------------------------------------------------------------------*/
static os_error *Send (char *s, int n)
{ int status;
os_error *error;
do
if ((error = xeconet_do_transmit (0x81, 0xF0, S, N, (byte *) s,
n, 1, 0, &status, NULL)) != NULL)
goto finish;
while (status != econet_STATUS_TRANSMITTED);
finish:
return error;
}
/*------------------------------------------------------------------------*/
os_error *trace_initialise (char *var)
{ os_error *error = NULL;
char to [80 + 1], *val;
if ((val = getenv (var)) == NULL)
strcpy (to, "v");
else
strcpy (to, val);
switch (to [0])
{ case 'f': case 'F':
if ((error = xosfind_openout (osfind_NO_PATH |
osfind_ERROR_IF_ABSENT | osfind_ERROR_IF_DIR, to + 1, NULL,
&F)) != NULL)
goto finish;
if ((error = xosfile_set_type (to + 1, osfile_TYPE_TEXT)) != NULL)
goto finish;
Trace = To_File;
break;
case 'n': case 'N':
Trace = To_Nowhere;
break;
case 's': case 'S':
Trace = To_Stdout;
break;
case 't': case 'T':
Trace = To_Tube;
break;
case 'e': case 'E':
if ((error = xeconet_read_station_number (to + 1, NULL, &S, &N)) !=
NULL)
goto finish;
Trace = To_Econet;
break;
case 'v': case 'V':
Trace = To_VDU;
break;
}
finish:
return Error = error;
}
/*------------------------------------------------------------------------*/
os_error *trace_terminate (void)
{ os_error *error = NULL;
switch (Trace)
{ case To_File:
if ((error = xosfind_close (F)) != NULL)
goto finish;
break;
}
finish:
return Error;
}
/*------------------------------------------------------------------------*/
void trace_f (char *file, int line, char *format, ...)
{ va_list list;
char s [TRACE_BUFFER_SIZE + 1], *cc;
bool has_format = format != NULL && strlen (format) > 0;
os_error *error = NULL;
/*Do not do anything once Error is set.*/
if (Error == NULL)
{ s [TRACE_BUFFER_SIZE] = '\0';
if (file != NULL)
{ sprintf (s, has_format? "%s,%d: ": "%s,%d\n\r", file, line);
assert (s [TRACE_BUFFER_SIZE] == '\0');
switch (Trace)
{ case To_File:
if ((error = xosgbpb_write (F, (byte *) s, strlen (s), NULL))
!= NULL)
goto finish;
if ((error = xosargs_ensure (F)) != NULL)
goto finish;
break;
case To_Stdout:
printf ("%s", s);
break;
case To_Tube:
for (cc = s; *cc != '\0'; cc++)
if ((error = xhostfs_writec (*cc)) != NULL)
goto finish;
break;
case To_Econet:
if ((error = Send (s, strlen (s))) != NULL)
goto finish;
break;
case To_VDU:
if ((error = xos_write0 (s)) != NULL)
goto finish;
break;
} }
if (has_format)
{ s [TRACE_BUFFER_SIZE] = '\0';
va_start (list, format);
vsprintf (s, format, list);
va_end (list);
assert (s [TRACE_BUFFER_SIZE] == '\0');
switch (Trace)
{ case To_File:
if ((error = xosgbpb_write (F, (byte *) s, strlen (s), NULL))
!= NULL)
goto finish;
if ((error = xosargs_ensure (F)) != NULL)
goto finish;
break;
case To_Stdout:
printf ("%s", s);
break;
case To_Tube:
for (cc = s; *cc != '\0'; cc++)
if (*cc >= 32)
{ if ((error = xhostfs_writec (*cc)) != NULL)
goto finish;
if (*cc == '\\')
if ((error = xhostfs_writec (*cc)) != NULL)
goto finish;
}
else if (*cc == '\n')
{ if ((error = xhostfs_writec ('\n')) != NULL)
goto finish;
if ((error = xhostfs_writec ('\r')) != NULL)
goto finish;
}
else
{ if ((error = xhostfs_writec ('\\')) != NULL)
goto finish;
if ((error = xhostfs_writec ('x')) != NULL)
goto finish;
if ((error = xhostfs_writec (UCHAR (*cc/16))) != NULL)
goto finish;
if ((error = xhostfs_writec (UCHAR (*cc%16))) != NULL)
goto finish;
}
break;
case To_Econet:
if ((error = Send (s, strlen (s))) != NULL)
goto finish;
break;
case To_VDU:
for (cc = s; *cc != '\0'; cc++)
{ char c = *cc;
if (c >= 128)
{ if ((error = xos_writen ("|!", 2)) != NULL)
goto finish;
c -= 128;
}
if (c < 32)
{ if (c == '\n')
{ if ((error = xos_new_line ()) != NULL)
goto finish;
break;
}
else
{ if ((error = xos_writec ('|')) != NULL)
goto finish;
c += 64;
}
}
if ((error = xos_writec (c)) != NULL)
goto finish;
if (c == '|')
if ((error = xos_writec (c)) != NULL)
goto finish;
}
break;
} } }
finish:
if (error != NULL)
Error = error;
}
/*------------------------------------------------------------------------*/
void trace_vdu (char *s, int n)
{ os_error *error = NULL;
int i;
/*Do not do anything once Error is set.*/
if (Error == NULL)
switch (Trace)
{ case To_Tube:
for (i = 0; i < n; i++)
if ((error = xhostfs_writec (s [i])) != NULL)
goto finish;
break;
case To_Econet:
if ((error = Send (s, n)) != NULL)
goto finish;
break;
case To_VDU:
if ((error = xos_writen (s, n)) != NULL)
goto finish;
break;
}
finish:
if (error != NULL)
Error = error;
}
/*------------------------------------------------------------------------*/
void trace_wait (char *file, int line, int t)
{ clock_t end;
int left;
os_error *error;
end = clock () + t*CLOCKS_PER_SEC;
while ((left = (int) end - (int) clock ()) > 0)
switch (Trace)
{ case To_Tube:
trace_f (file, line, "%-*d", DEC_WIDTH, left/CLOCKS_PER_SEC);
if ((error = xhostfs_writec ('\r')) != NULL)
goto finish;
break;
}
finish:;
}
#endif /* TRACE */
......@@ -29,7 +29,7 @@
/*From Support*/
#include "m.h"
#include "riscos.h"
#include "trace.h"
#include "jc_trace.h"
#ifndef BOOTCMDS
static char *Decimal_Point = ".";
......
......@@ -20,7 +20,7 @@
#include "os.h"
#include "muldiv.h"
#include "trace.h"
#include "jc_trace.h"
#include "trfm.h"
void trfm_mul (os_trfm *r, os_trfm *m1, os_trfm *m2)
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment