/*-----------------------------------------------------------------------------
Author: Eric Aksomitis ( http://www.dlcwest.com/~jed/re_answer.shtml )
Date  : 2000-05-24
Name  : TMSCRIPT.C  (Time-Script)
Purpose:
			This is a basic (and not overly well written, yet functional)
			way to script time elements for batch files.
			Basically, it just writes its arguments to a string, replacing key
			arguments with current time, then executes the string with the system ()
			call.
Example:
pkzip temp.zip *.mdb
tmscript move -s temp.zip -s archive_ yyyy -- mm -- dd -- -- hh _ mi .zip


		 I know this is not really a _great_ solution, but it is universal and
		 requires no setup or installation of any other software, just basic
		 windows DOS (although it can be used even better on LINUX/UNIX).
		 Perl would be better to do this in, but this works.

*----------------------------------------------------------------------------*/
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

void main (int no,char *arg[])
{
	int    i;
	char   hh[3],ss[3],mi[3],dd[3],mm[3],yy[3],yyyy[5],command[20000];
	time_t now;

	command[0] = '\0';

	now=time(NULL); /* Get today's date */
	strftime(hh  ,3, "%H", localtime(&now));
	strftime(ss  ,3, "%S", localtime(&now));
	strftime(mi  ,3, "%M", localtime(&now));
	strftime(dd  ,3, "%d", localtime(&now));
	strftime(mm  ,3, "%m", localtime(&now));
	strftime(yy  ,3, "%y", localtime(&now));
	strftime(yyyy,5, "%Y", localtime(&now));

		for (i=1;i<no;i++)
		{
			if (strcmp(arg[i],"-s") == 0) strcat(command," ");
			else
				if (strcmp(arg[i],"-n") == 0) strcat (command,"\n");
				else
					if (strcmp(arg[i],"-sq") == 0) strcat (command,"\'");
					else
						if (strcmp(arg[i],"-dq") == 0) strcat (command,"\"");
						else
							if (strcmp(arg[i],"--") == 0) strcat (command,"-");
							else
								if (strcmp(arg[i],"hh") == 0) strcat (command,hh);
								else
								if (strcmp(arg[i],"ss") == 0) strcat (command,ss);
								else
								if (strcmp(arg[i],"mi") == 0) strcat (command,mi);
								else
								if (strcmp(arg[i],"dd") == 0) strcat (command,dd);
								else
								if (strcmp(arg[i],"mm") == 0) strcat (command,mm);
								else
								if (strcmp(arg[i],"yyyy") == 0) strcat (command,yyyy);
								else
								if (strcmp(arg[i],"yy") == 0) strcat (command,yy);
								else
								strcat (command,arg[i]);
		}
		printf ("%s\n",command);
		system (command);
}
