// (c) 1993-2007 Electronic Arts Inc.

const char *SPIT_history[] =
{
"------------------------------------------------------------------",
"                                                                  ",
"                             Fmj v1.00                            ",
"                                                                  ",
"                        by FrANK G. Barchard                      ",
"                                                                  ",
"                     Main program - Apr 05, 2007                  ",
"                                                                  ",
"------------------------------------------------------------------",
"                                                                  ",
" Version Date   SE History:                                       ",
" ------- ----   -- --------                                       ",
"    1.00 070405 FB Initial version                                ",
"                                                                  ",
"------------------------------------------------------------------",
"\0"
};

/****************************************************************/
/*  Spit Setup                                                  */
/****************************************************************/

#include    "spit.h"

const char FmjVersion[]="1.00 (Salvation) 2007.4.07";
#define TOOL_VERSION 100
#define TOOL_NAME "fmj"


/*
;
; ABSTRACT
;
; fmj - patch motion jpeg files
;
; SUMMARY
;
; fmj mymjpeg.avi
;     @file     response file, containing a list of options and files
;     =file     specify a output file ie fmj source=dest
;
; DESCRIPTION
;
; FMJ patches the fourcc in a motion jpeg AVI to MJPG.
;
; RETURNS
;
; no return code
;
; SEE ALSO
;
; gx, Spit
;
; END ABSTRACT
;
*/

/****************************************************************/
/*  SPIT Routines                                               */
/****************************************************************/

void SPIT_reset(void)
{
}

void SPIT_usage(const char *prgname,const char *envname,const char *urlname, int utype)
{
    printf("Fmj v%s by FrANK Barchard, EAC\n",FmjVersion);
    if (utype)
        printf("USAGE: %s -options [files]\n", prgname);

    switch (utype)
    {
        case 2:
            puts("     @ response file              = output file");
          printf("type '%s -h' for more help\n", prgname);
          printf("type '%s -help' for web page (%s)\n", prgname,urlname);
            break;

        case 3:
            puts("");
          printf("VERSION: %s v%s, Spit v%.2f\n",SPIT_MACHINE,FmjVersion,(float)SPIT_VERSION/100.0f);
            puts("SUMMARY: Fmj convert fmj file cr/lf styles for PC,MAC & SGI");
          printf("         SPIT environment variable is %s\n",envname);
            puts("");
            puts("    @file     response file, containing a list of options and files");
          printf("    =file     specify a output file ie %s source=dest\n", prgname);

        default:
            break;
    }
}

char *SPIT_opt(const char *)
{
    return NULL;
}

int main(int argc,char **argv)
{
    int more;

    SPIT_init(SPIT_reset, SPIT_usage, SPIT_opt, SPIT_history);
    do
    {
        more = SPIT_parse(argc, argv, TOOL_NAME, TOOL_VERSION);

        for (int i=0; i<SPITargnum; ++i)
        {
            GSTREAM *g = grwopen(SPITdargv[i]);
            gseek(g,0x70);
            gwrite(g,"mjpg",4);
            gseek(g,0xbc);
            gwrite(g,"MJPG",4);
            gclose(g);
        }
    } while (more);

    SPIT_restore();

    return 0;
    
}

