throwback 1.97 KB
Newer Older
Kevin Bracey's avatar
Kevin Bracey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright 1998 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.
 */
#include <stdlib.h>
16
#include <stdio.h>
Kevin Bracey's avatar
Kevin Bracey committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

#define Throwback_Start       0x42587
#define Throwback_Send        0x42588
#define Throwback_End         0x42589

#include "swis.h"

#include "throwback.h"

#define Throwback_ReasonProcessing   0
#define Throwback_ReasonErrorDetails 1

static int throwback_id;
static int sent_procfile_msg;

static void throwback_exit(void)
{
    if (throwback_id >= 0)
        _swix(Throwback_End, _IN(0), throwback_id);
}

static void throwback_start(void)
{
    atexit(throwback_exit);
    if (!_swix(Throwback_Start, 0))
        throwback_id = 1;
}

void throwback_send(int severity, int line, const char *msg, const char *sourcefile, const char *current)
{
    if (!sent_procfile_msg) {
        throwback_start();
        sent_procfile_msg = 1;
        if (throwback_id >= 0) {
            _swix(Throwback_Send, _INR(0,2),
                  Throwback_ReasonProcessing, throwback_id, sourcefile);
        }
    }
    if (throwback_id >= 0) {
        _swix(Throwback_Send, _INR(0,5),
              Throwback_ReasonErrorDetails, throwback_id, current,
              line, severity, msg);
    }
}
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

const char *dependfilename;

void add_dependency(const char *target, const char *filename)
{
    static FILE *dependfile;

    if (!dependfile)
    {
        dependfile = fopen(dependfilename, "w");
        if (!dependfile) return;
    }


    fprintf(dependfile, "%s: %s\n", target, filename);
}