/*
 * $Id: small2big.c,v 1.2 2006/02/14 09:13:55 horti Exp $
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int
main (int argc, char **argv)
{
    char *infilename = "", *outfilename = "";
    FILE *infile, *outfile;
    unsigned int value, byte_swapped, status;
    int bytes = 0;

    if (argc > 2) {
        if (argc > 3) {
            if (!strcmp(argv[3], "-b")) {
                bytes = 1;
            } else {
                fprintf (stderr, "%s: bad arg %s\n", argv[0], argv[3]);
                exit (1);
            }
        }
        infilename = argv[1];
        printf ("%s\n", infilename);
        if ((infile = fopen (infilename, "r")) == NULL) {
            perror ("open");
            exit (1);
        }
        outfilename = argv[2];
        printf ("%s\n", outfilename);
        if ((outfile = fopen (outfilename, "w")) == NULL) {
            perror ("open");
            exit (1);
        }
    } else {
        exit (1);
    }
    
    do {
        status = fread (&value, sizeof (value), 1, infile);
        if (status != 1) break;
        byte_swapped = ((value & 0xff) << 24) 
            | ((value & 0xff00) << 8) 
            | ((value & 0xff0000) >> 8) 
            | ((value & 0xff000000) >> 24);
//        printf ("%08x %08x\n", value, byte_swapped);
        fwrite (&byte_swapped, sizeof (byte_swapped), 1, outfile);
    } while (status == 1);

    exit (0);
}
