/*

  (c) 1990 S.Hawtin.
  Permission is granted to copy this file provided
   1) It is not used for commercial gain
   2) This notice is included in all copies

  No liability is accepted for the contents of the file.

*/

/* An example 'C' program to read small.lib and convert it to
  an assembler include file */

/* Find the FILE structures */
#include <stdio.h>

FILE *in;		/* Input file */
FILE *out;		/* Output file */
char name[128];	        /* Name being defined */
unsigned long val;	/* Value to assign */

read_num()
   {int i;
    char ch;

    val = 0;
    for(i=0;i<4;i++)
       {ch = fgetc(in);
        val = 256*val + (0xff & ch);
        }
    }

read_name(num)
    int num;
   {int i;

    for(i=0;i<4*num;i++)
        name[i] = fgetc(in);

    name[i]='\0';
    }

main()
   {/* No command line arguments */

    /* First define the local arguments to use */
    int  i;		/* Temp count value */

    /* Open small.lib for reading */
    in = fopen("small.lib","r");
    if(in == NULL)
       {printf("Failed to open small.lib\n");
        exit(10);
        }

    out = fopen("dos.i","w");
    if(in == NULL)
       {printf("Failed to open dos.i\n");
        exit(10);
        }

    /* Read past the header, and then the first number */
    for(i=0;i<6;i++)
       {read_num();
        }

    while(!feof(in) && val!=0)
       {/* Loop round reading characters */
        read_name((int)(val & 0xffff));
        read_num();
        fprintf(out,"%-24s\tEQU\t$%lx\n",&name[0],val);
        read_num();
        }

    fclose(in);
    fclose(out);
    }
