#include "tcp"

main (argc,argv,envp)

	int	argc;
	char	*argv[],*envp[];

{

	char    m1[140],hd[2048];
	char	head[20][41];
	short 	ph[20][5];
	int	i,flag,j,m,c,fi,nh,nr,nc,df,rgh,rgh1;
	FILE	*fh,*fopen();
	FILE	*fp,*fopen();

	long	lh;
	tcp(0);
	if ((fp=fopen(argv[1],"r")) == (FILE *)0)
	{
			fprintf(stderr,"can't open %s\n",argv[1]);
			exit(0);
	}
	fscanf(fp,"%2d%2d%2d%2d",&nh,&nr,&nc,&df);
	for (i=0;i<nh;i++)
	{
		for (j=0;j<4;j++)
		{
			fscanf(fp,"%2d",&m);
			ph[i][j]=m;
		}
		j=0;
		while((head[i][j]=getc(fp))!='\n') j++;
		head[i][j]=0;
		if (head[i][0] && head[i][0]!='|') ph[i][4]=1;
	}
	fclose(fp);
	sprintf(m1,"%s.0",argv[1]);
	fp=fopen(m1,"r");
	j=0;
	while((c=getc(fp))!=EOF) hd[j++]=c;
	fclose(fp);
	printf ("%s%s",tc[4],hd);
	for (i=0;i<nh;i++)
	{
		pos(ph[i][0],ph[i][1]);
		printf ("%s",head[i]);
	}
	i=0;
	j=0;
	c='e';
	while (c=='E' || c=='e')
	{
		coment("DIGITE LOS DATOS Y PRESIONE ENTER   [ESC : COMANDOS ]");
		do
		{
			strcpy(m1,head[j]);
			c=input(ph[j][0],ph[j][1],ph[j][2],ph[j][3],m1);
			strcpy(head[j],m1);
			if(ph[j][3])
			{
				sprintf(m1,"%%%ds",ph[j][2]);
				pos(ph[j][0],ph[j][1]);
				printf(m1,head[j]);
			}
			if (c==13 || c==10) j++;
			if (c==26) j--;
			if (j==nh) j=0;
			if (j<0) j=nh-1;
		}
		while (c!=27);
		coment("COMAND : [ ENTER : PROCESA ] [ E : EDICION ] [ ESC : ANULA ]  (^X)");
		while((c=getin1())!=13 && c!=27 && c!=24 && c!='e' && c!='E');
		c=toupper(c);
		if (c==24|| c==27)
		{
			coment("RETORNO A MENU");
			exit(0);
		}
		if (c==13)
		{
			coment("COMAND : [ ENTER  : EJECUTA] [ ESC : ANULA ]");
			while ((c=getin1())!=13 && c!=27);
		}
		if (c==13 )
		{
			sprintf (m1,"exec %s.sh ",argv[1]);
			for (i=0;i<nh;i++)
			{
				strcat (m1,head[i]);
				strcat(m1," ");
			}
			system(m1);
/*
			if ((fp=fopen(argv[1],"w")) != (FILE *)0)
			{
				fprintf(fp,"%.2d%.2d%.2d%.2d",nh,nr,nc,df);
				for (i=0;i<nh;i++)
				{
					for (j=0;j<4;j++) fprintf(fp,"%.2d",ph[i][j]);
					if (ph[i][4]) fprintf (fp,"%s\n",head[i]);
					else fprintf (fp,"\n");
				}
				fclose(fp);
			}
*/
		}
	}
}
