#!/usr/bin/env perl
########################################################################
# cc8-to-os8 - Filter C code meant for the CC8 cross-compiler so that it
#   will work with the OS/8 version of CC8.
#
#   This is not meant to fix up 100% of the differences in the C
#   compilers, just the ones which prevent src/cc8/examples/*.c
#   from building under OS/8 CC8 as-is.
#
#   You can run it like a filter: 
#
#       $ cc8-to-os8 < foo.c | txt2ptp > foo.pt
#
#   Or you can just give it one or more file name(s), with output going
#   to stdout, which gives this way to hack around the lack of #include:
#
#       $ cc8-to-os8 myheader.h foo.c > OS8FOO.C
#
# Copyright © 2017-2018 Warren Young
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the names of the authors above
# shall not be used in advertising or otherwise to promote the sale,
# use or other dealings in this Software without prior written
# authorization from those authors.
########################################################################

use strict;
use warnings;

my $nblines = 0;        # number of non-blank lines written out

while (<>) {
    if (!m{^\#include }) {
        # Pass it through unchanged.
        print;
    }
    else {
        # Unlike the CC8 cross-compiler, the OS/8 version of CC8 doesn't
        # process #includes, or in fact any C preprocessor directives,
        # not even #asm.  Strip just the #includes in the hope that it's
        # init.h or libc.h, the contents of which are hard-coded into
        # the OS/8 CC8 compiler.
    }
}
