
/* ////////////////////////////////////////////////////////////////////////////
                                      x.c
///////////////////////////////////////////////////////////////////////////////
DESCRIPTION:    This program reads a list of symbols from SYMBOLS.TXT and
                automatically generates a corresponding set of #defines in
                SYMBOLS.H and a corresponding set of EQUs in SYMBOLS.INC.
                Adjust to suit if you don't like the hard coded filenames.

REVISIONS:       9 Jun 07 - RAC - Genesis
//////////////////////////////////////////////////////////////////////////// */

#include <stdio.h>

/* ////////////////////////////////////////////////////////////////////////////
                               Names for Numbers
//////////////////////////////////////////////////////////////////////////// */

#define BUF_SIZE        200

void main() {

    FILE        *pIn;                           // Pointer to input file
    FILE        *pH;                            // Pointer to .H output file
    FILE        *pI;                            // Pointer to .INC output file
    char        symbol[BUF_SIZE];               // A gigantic input buffer
    int         symbolCount;                    // Count symbols here

/*  Open all the input files, or die trying */

    if (((pIn = fopen("SYMBOLS.TXT", "rt")) == NULL) ||
        ((pH  = fopen("SYMBOLS.H",   "wt")) == NULL) ||
        ((pI  = fopen("SYMBOLS.INC", "wt")) == NULL)) {
        printf("File open error\n");
        return;
        }

/*  Write a line to each output file for every line in the input file  */

    symbolCount = 0;                            // No symbols yet
    while (fgets(symbol, BUF_SIZE, pIn)) {      // For each input line
        symbol[strlen(symbol) - 1] = '\0';      // Zap the newline character
        fprintf(pI, "%s\tEQU\t%d\n",            // Make ASM include file entry
            symbol, symbolCount);
        fprintf(pH, "#define\t%s\t%d\n",        // Make C header file entry
            symbol, symbolCount);
        symbolCount++;                          // Count symbol just processed
        }                                       // End 'for each input line'

/*  Close all the files  */

    fclose(pIn);  fclose(pI);  fclose(pH);
    }                                           // End main()
