// Zmod10.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <tchar.h>
#include <time.h>

#include "Zmodlib.h"
#include "zmcore.h"



/************************************************************/

int _tmain(int argc, _TCHAR* argv[])
{
    static ZMCORE zmcore;
	char filename[80];
	
	printf("\nZmodem program...");

	// No arguments?
	if((argc == 1 || argc > 3))
	{
		printf("\nUsage: zmodem /r /s [filename]");
		exit(1);
	}

	InitCom();
 
	// Get the filename
	if(argv[1][0] == '/')
	{
		switch(argv[1][1])
		{
		case 'r':	// Receive
		    zmcoreDefaults(&zmcore);
		    zmcoreInit(&zmcore);
			zmcoreReceive(&zmcore);
			zmcoreTerm(&zmcore);
			break;

		case 's':	// Send
			if(argc == 3) 
			{
				strcpy((char *)zmcore.filename, argv[2]);
			}
			else 
			{
				printf("\nError: send requires filename");
				exit(1);
			}
		    zmcoreDefaults(&zmcore);
		    zmcoreInit(&zmcore);
			zmcoreSend(&zmcore);
			zmcoreTerm(&zmcore);
			break;
		default:
			printf("\nUnrecognized argument");
		}
	}
	else printf("\nUnrecognized argument");
	CloseCom();    
    return (0);
}

/***********************************************************************/

