#include <stdio.h>
#include <errno.h>

char buf[127*512];

main(argc, argv)
int argc;
char **argv;
    {
    FILE *in, *out;
    char outname[L_tmpnam], *c;
    int bytes_read, size;

/*    getredirection(&argc, &argv); */
    if (argc == 1)
        {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "\tmktftpboot filename.sys [filename.sys . . .]\n");
        exit();
        }
    while (--argc)
        {
        ++argv;
        if (NULL == (in = fopen(*argv, "r"
#ifdef VMS
                                        , "mbf=2", "mbc=127"
#endif
                                )))
            {
            fprintf(stderr, "Can't open file '%s' for read: %s\n",
                            *argv, strerror(errno, vaxc$errno));
            continue;
            }
        fgetname(in, outname);
        if (NULL != (c = strrchr(outname, '.')))
            *c = '\0';
        if (NULL == (out = fopen(outname, "w"
#ifdef VMS
                                        , "rfm=fix", "mrs=512",
                                          "mbf=2", "mbc=127"
#endif
                                )))
            {
            fprintf(stderr, "Can't open file '%s' for read: %s\n",
                            outname, strerror(errno, vaxc$errno));
            continue;
            }
        bytes_read = 0;
        while (bytes_read < 512)
            {
            size = fread(buf, 1, 512-bytes_read, in);
            bytes_read += size;
            }
        while (0 != (size = fread(buf, 1, sizeof(buf), in)))
            fwrite(buf, 512, (size+511)/512, out);
        fclose(in);
        fclose(out);
        fprintf(stderr, "Generated: %s\n", outname);
        }
    }
