SOFTWARE LABORATORY
First of all we will require ala.txt , mnt.txt , mdt.txt , output.txt generated by macro pass I . Put all this file in same folder where MII.c will beTo see more about mnt.txt , mdt.txt,ala.txt and output.txt visit this link
code for MII.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct mdtab
{
char def[40];
}mdt[20];
struct mntab
{
char name[8];
int address,argcnt;
}mnt[5];
struct ALA
{
char formal[10];
char actual[10];
}ala[20];
int imnt=0,imdt=0,iala=0;
int main()
{
FILE * fp;
char buffer[40],s1[10],s2[10],s3[16],s4[16];
char ap1[8],ap2[8],ap3[8];
int i,j,k,cnt;
fp=fopen("mdt.txt","r");
while(fgets(buffer,40,fp)!=0)
{
strcpy(mdt[imdt++].def,buffer);
}
fclose(fp);
fp=fopen("mnt.txt","r");
while(fgets(buffer,40,fp)!=0)
{
sscanf(buffer,"%s%s%s",s1,s2,s3);
strcpy(mnt[imnt].name,s1);
mnt[imnt].address=atoi(s2);
mnt[imnt++].argcnt=atoi(s3);
}
fclose(fp);
fp=fopen("ala.txt","r");
while(fgets(buffer,40,fp)!=0)
{
sscanf(buffer,"%s%s",s1,s2);
strcpy(ala[iala].formal,s1);
strcpy(ala[iala++].actual,s2);
}
fclose(fp);
fp=fopen("output.txt","r");
while(fgets(buffer,40,fp)!=0)
{
for(j=0;j<strlen(buffer);j++)
if(buffer[j]==',')
buffer[j]=' ';
sscanf(buffer,"%s%s%s%s",s1,s2,s3,s4);
i=(s1[1]-65)%5;
if(strcmp(mnt[i].name,s1)==0)
{
//printf("\nMacro call..... %s",buffer);
i=mnt[i].address;
sscanf(mdt[i++].def,"%s%s%s%s",s1,s2,s3,s4);
//printf("\n\t\t %s %d %d %d",s1,atoi(s2),atoi(s3),atoi(s4));
printf("\n\t %s ",buffer);
cnt=sscanf(buffer,"%s%s%s%s",s1,ap1,ap2,ap3);
//printf("\nAfter scan %s %s %s %s",s1,ap1,ap2,ap3);
if(cnt>1)
strcpy(ala[atoi(s2)].actual,ap1);
if(cnt>2)
strcpy(ala[atoi(s3)].actual,ap2);
if(cnt>3)
strcpy(ala[atoi(s4)].actual,ap3);
while(1)
{
sscanf(mdt[i++].def,"%s%s%s",s1,s2,s3);
if(strcmp(s1,"MEND")==0)
break;
printf("\n\t+%s",s1);
printf("\t%s\t%s",ala[atoi(s2)].actual,ala[atoi(s3)].actual);
}
}
else
printf("\n\t %s ",buffer);
}
fclose(fp);
return(0);
}
No comments:
Post a Comment