/*
    Specific.c
*/

/// Includes
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include "conio.h"
#include "mytypes.h"
#include "tmiga.h"
#include "protos.h"
///
/// Prototypes
///
/// Global variables
struct RDArgs *rdargs = NULL;
struct Window *ReqWindow = NULL;
char *argarray[NumArgs];
///

/// GetArgs
/* ---------------------------------- GetArgs ----------------------------------

 Comment: Read command line arguments

*/

//void GetArgs(int argc, char **argv)
int main(int argc, char **argv)
{
        BOOL badArgs = FALSE, gotFile = FALSE, gotConfig = FALSE, gotArg = FALSE;
        int p;
        static char argbuf[512] = "";
        char *defcfg;

        defcfg = ConfigFilename ();
        arg_CONFIG = defcfg;

	conio_init();

        // arg_CONFIG = "~/.tagomigarc";

        if (argc < 1) {
                fail (20, "Tag-o-Miga: Bad arguments (try --help)");
        }
        
        for (p = 1; p < argc; p++) {
                if (strncmp (argv[p], "--help", 6) == 0 || strncmp (argv[p], "-?", 2) == 0) {
                        printf ("Tag-o-Miga [-c configfile] editfile editorargs\n");
                } else if (strncmp (argv[p], "-c", 2) == 0) {
                        if (strlen (argv[p]) > 2) {
                                arg_CONFIG = &argv[p][2];
                        } else {
                                if (gotConfig == TRUE) fail (20, "Option -c can only be specified once");
                                gotConfig = TRUE;
                                if (argc == p+1) {
                                        fail (20, "Option -c requires a filename");
                                }
                                arg_CONFIG = argv[p+1];
                                p++;
                        }
                } else if (gotFile == FALSE) {
                        arg_EDITFILE = argv[p];
                        gotFile = TRUE;
                } else {
                        if (gotArg == TRUE) strcat (argbuf, " ");
                        strcat (argbuf, argv[p]);
                        gotArg = TRUE;
                }
        }
        arg_ARGS = argbuf;

        if (gotFile == FALSE) fail (20, "Bad arguments - try --help");

	realMain();

	return 0;
}
///
