/* genks.c */

/* Generate a pxeboot config file from template */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char buffer[64 * 1024];

unsigned int addr = 0xC0A84600;

int  main(
int  argc,
char **argv)
{
    int size;
    char id[2];
    char *loc;
    int  offset;
    char filename[40];
    FILE *out;

    strcpy(id, argv[1]);

    size = fread(buffer, 1, sizeof(buffer), stdin);
    loc = buffer;
    while (loc = strstr(loc, "$$"))
    {
       memcpy(loc, id, 2);
       loc = loc + 2;
    }

    offset = atoi(id);
    addr += offset;
    sprintf(filename, "%X", addr);
    out = fopen(filename, "w");
    fwrite(buffer, 1, size, out);
}

