You are on page 1of 4

# include <ctype.

h>
# include <stdio.h>
# include <conio.h>
# include <dos.h>

void view(void);
void compiled(void);
void initialize(void);

char row = 0, column = 0;


FILE *fcom, *fpr;
char let[2], entered[100], line[100], start[10], string[80], extra[10];
int indi, level, sf, bef,eef, br, pr, comp, index, counter = 0;

struct{
char s_string[80];
int spacing;
}disp;

main(void)
{ int character;
clrscr();
for(;;)
{ disp_char();
}
}

disp_char()
{ char inchar, inchar1;
printf(" \n\nStarts Here: \n");
fcom = fopen("text", "w+");
for(;;)
{ fcom = fopen("text", "a");
inchar1 = getch();
if(inchar1 == 0 )
{inchar = getch();
switch(inchar)
{ case 112 : fclose(fcom); /* ALT - F9: for COMPILE */
compiled();
getch();
fcom = fopen("text", "w+");
fcom = fopen("text", "a");
clrscr();
printf(" \n\nStarts Here: \n");
break;
case 45 : fclose(fcom); /* CTRL - F9: for EXECUTE */
printf("Exit the program");
exit();
case 102: fclose(fcom); /* ALT - X : for EXIT */
view();
getch();
clrscr();
printf("\n\nStarts Here: \n");
fcom = fopen("text", "w+");
fcom = fopen("text", "a");
break;
}
}
else{gets(entered);
fwrite(entered, sizeof(entered), 1, fcom);
fclose(fcom);}
}
}

void view(void)
{
clrscr();
if( sf == 1 && pr == 1 && bef == eef)
{ fcom = fopen("com","r");
fread(&disp, sizeof(disp), 1, fcom);
do
{ if(disp.spacing == 2)
{printf ("\n");}
if(disp.spacing == 3)
{printf ("\t");}
if(disp.s_string != NULL)
{printf ("%s", disp.s_string);}
fread(&disp, sizeof(disp), 1, fcom);
}while(!feof(fcom));
fclose(fcom);
getch();
}
else { gotoxy(12,40);
printf(" Please compile your program ");
}
}

void compiled(void)
{ level = 0; sf = 0; br = 1; bef = 0;
clrscr();
fcom = fopen("text", "r");
fpr = fopen("com", "w+");
fread(line, 100, 1, fcom);
do{
if(level == 0)
{ for(index = 6; line[index] != 0; index++)
{ start[0] = line[index-6]; start[4] = line[index-2];
start[1] = line[index-5]; start[5] = line[index-1];
start[2] = line[index-4]; start[6] = line[index];
start[3] = line[index-3];
if(!strcmp(start,"sugod()"))
{ sf = 1; level = 1; break;
} } }
if(level == 1)
{ for(index = 0; line[index] != 0; index++)
{ if(line[index] == '{')
{ br++; level = 2; pr = 1; break;
} } }
if(level == 2)
{ for(index = 0; line[index] != 0; index++)
{ if(pr == 1)
{ start[0] = line[index-7]; start[4] = line[index-3];
start[1] = line[index-6]; start[5] = line[index-2];
start[2] = line[index-5]; start[6] = line[index-1];
start[3] = line[index-4]; start[7] = line[index];
if(!strcmp(start,"isuwat(\""))
{ pr = 2; bef++ ; index++;
} }
if(pr == 2)
{ do {
if(line[index] == '\\' && line[index+1] == 'n')
{index+=1;
disp.spacing = 2;
fpr = fopen("com", "a");
fwrite(&disp,sizeof(disp),1,fpr);
fclose(fpr);
disp.spacing = 0;
}
else if(line[index] == '\\' && line[index+1] == 't')
{index+=1;
disp.spacing = 3;
fpr = fopen("com", "a");
fwrite(&disp,sizeof(disp),1,fpr);
fclose(fpr);
disp.spacing = 0;
}
else if(line[index] == '"' && line[index+1] == ')' && line[index+2]
== ';')
{ eef++;
strcpy(disp.s_string, string);
fpr = fopen("com", "a");
fwrite(&disp,sizeof(disp),1,fpr);
fclose(fpr);
initialize();
strcpy(disp.s_string,string);
break;
}
else { string[counter] = line[index];
counter++;

}
index++;
}while(line[index]!= 0);
pr = 1;
}
}
}
if(pr == 1)
{ for(index = 0; line[index] != 0; index++)
{ if(line[index] == '}')
{br--;}
}
}
fread(line, 100, 1, fcom);
counter = 0;
}while(!feof(fcom));
fclose(fcom);
fclose(fpr);
if( sf!= 1 || br != 1 || bef != eef)
{ printf("\n\n\t\tSorry .......");
printf("\n\n\n\t\There's something wrong in your program");
printf("\n\n\n\t\tPlease check. ");
}
else{ printf("\n\n\t\t Compile...Success!!!");}

}
void initialize(void)
{ int t,l;
l = strlen(string);
for(t = 0; t<= l; t++)
{ string[t] = NULL;
}
}

You might also like