/***************************************************************************\
*                                                                           *
* This program contains a few short routines to replace the standard        *
* output-routines of C and an example of how to detect the ^C signal.       *
* The advantage of these routines is the size of the compiled code.         *
* If you uses the routines myputs(),to write strings to the screen, and     *
* myputchar(), to write one character to the screen, then the size is       *
* about 5K smaller as when you uses printf(), puts() or putchar()-routines. *
*                                                                           *
* To print numbers you can use the function printn(number, base).           *
* Number is the integer that you want to print and base is an integer       *
* that containts the base of the number you want to print.                  *
* (Printn() is a very short, recursive function thats very interesting      *
* to look at.)                                                              *
*                                                                           *
* In the Aztec version of printf() is a routine that checks if the user     *
* hits ^C. If the program then quits then immediately with the exit()       *
* function and doesn't free memory or lock on files.                        *
* In this program is also a methode to detect a ^C so you can free memory   *
* and unlocks files (etc.)                                                  *
*                                                                           *
*                            Pieter van Leuven                              *
*                                                                           *
\***************************************************************************/

#include <libraries/dos.h>
#include <functions.h>     /* This isn't necessary with Lattice */

main(argc, argv)
int argc;
char *argv[];
{
    SetSignal (0L, SIGBREAKF_CTRL_C); /* Clear Signals */
    if (argc != 3)
        myputs ("Usage: convert <number> <Base>\n");
    else
    {
        printn (atoi(argv[1]), atoi(argv[2]));
        myputchar ('\n');
    }
    myputs ("Press ^C to quit this program.\n");
    while (1) /* ForEver */
    {
        if ((long)SetSignal (0L, 0L) & SIGBREAKF_CTRL_C)
        {
            myputs ("Break ^C\n");
            break;
        }
    } 
}

printn (n, b)     /* n = number to print, b = base */
unsigned n, b;
{
    unsigned a;

    if (a=n/b)
        printn (a, b);
    myputchar ("0123456789ABCDEF"[(int)(n%b)]);
}

myputchar(a)
char a;
{
    Write (Output(), &a, 1L);
}

myputs (str)
char *str;
{
    Write(Output(), str, (long) strlen(str));
}

