document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //----------------------------------------------------------
  2. // Title :  Design suitable data structures and implement
  3. //      pass-II of a two-pass macro-processor.
  4. //----------------------------------------------------------
  5.  
  6. #include<stdio.h>
  7. #include<conio.h>
  8. char i1[20],i2[20],i3[20],macron[30],cname[50][50],dname[50][50];
  9. int size,a;
  10.  
  11. void write(char line[])
  12. {
  13. FILE *fptr1;
  14. if((fptr1=fopen("callr.txt" ,"a+"))==NULL)
  15.         {
  16.         printf("\\n\\t\\t file error ....");
  17.         }
  18.         else
  19.         {
  20.             fputs(line,fptr1);
  21.             fclose(fptr1);
  22.         }
  23. }
  24.  
  25. int cmp(char data[])
  26. {
  27. int i,flag=0;
  28.  
  29. flushall();
  30.    for(i=0;i<=size;i++)
  31.    {
  32.      if(strcmp(dname[i],data)==0)
  33.      {
  34.        write(cname[i]);
  35.        puts(cname[i]);
  36.     flag=1;
  37.     break;
  38.      }
  39.  
  40. }
  41. if(flag!=1)
  42. {
  43.     write(data);
  44.     write(" ");
  45.     puts(data);
  46. }
  47.  
  48. return 0;
  49. }
  50.  
  51. void mdt()
  52. {
  53. FILE *fptr;
  54. char line[100],msg[30],op1[20],data1[20],com[1]={","};
  55. int i,j=0,k=0,l=0,m,n,o,flag;
  56. flushall();
  57. if((fptr=fopen("mdt.txt" ,"r"))==NULL)
  58. {
  59. printf("\\n\\t\\t file error ....");
  60. }
  61. else
  62. {
  63.     while(!feof(fptr))
  64.     {
  65.     j=0;
  66.     line[j]=fgetc(fptr);
  67.        while(line[j]!=\'\\n\'&&line[j]!=EOF)
  68.         {
  69.  
  70.             j++;
  71.             line[j]=fgetc(fptr);
  72.         }
  73.         line[j]=\'\\0\';
  74.         sscanf(line,"%s %s ",op1,msg);
  75.  
  76.         if(atoi(i2)==atoi(op1))
  77.         {
  78.           flag=1;
  79.           continue;
  80.          }
  81.             if(flag==1)
  82.             {
  83.             if(strcmp(msg,"MEND")!=0)
  84.             {
  85.               puts(line);
  86.  
  87.           for(k=strlen(op1)+1,l=0;line[k]!=\'\\0\';k++,l++)
  88.            {
  89.           if(line[k]==\' \')
  90.              {
  91.               data1[l]=\'\\0\';
  92.               cmp(data1);
  93.               l=0;
  94.               k++;
  95.               }
  96.           data1[l]=line[k];
  97.            }
  98.  
  99.           data1[l]=\'\\0\';
  100.           write(com);
  101.           cmp(data1);
  102.           write("\\n");
  103.             }
  104.             else
  105.             {
  106.             flag=0;
  107.             }
  108.            }
  109.     }
  110.     }
  111.  
  112. fclose(fptr);
  113. }
  114.  
  115. void sepc(char arg[])
  116. {
  117. char line[100];
  118. int i,j,k,l;
  119. l=0,i=0,j=0;
  120. while(arg[i]!=\'\\0\')
  121. {
  122.    if(isspace(arg[i]))
  123.    {
  124.     line[l]=\'\\0\';
  125.     strcpy(cname[j],line);
  126.     j++;
  127.     l=0;
  128.     i++;
  129.    }
  130.    line[l]=arg[i];
  131.    l++;
  132.    i++;
  133. }
  134.  line[l]=\'\\0\';
  135.  strcpy(cname[j],line);
  136.  size=j;
  137. }
  138.  
  139. void sepd(char arg[])
  140. {
  141. char line[100];
  142. int i,j,k,l;
  143. l=0,i=0,j=0;
  144. while(arg[i]!=\'\\0\')
  145. {
  146.    if(isspace(arg[i]))
  147.    {
  148.     line[l]=\'\\0\';
  149.     strcpy(dname[j],line);
  150.     j++;
  151.     l=0;
  152.     i++;
  153.    }
  154.    line[l]=arg[i];
  155.    l++;
  156.    i++;
  157. }
  158.  line[l]=\'\\0\';
  159.  strcpy(dname[j],line);
  160.  
  161. }
  162.  
  163.  
  164. int searchn(char op[])
  165. {
  166. FILE *fptr;
  167. char line[100];
  168. int i,j,k;
  169.  
  170. if((fptr=fopen("mnt.txt" ,"r"))==NULL)
  171. {
  172. printf("\\n\\t\\t file error ....");
  173. }
  174. else
  175. {
  176.     while(!feof(fptr))
  177.     {
  178.     j=0;
  179.     line[j]=fgetc(fptr);
  180.        while(line[j]!=\'\\n\'&&line[j]!=EOF)
  181.         {
  182.             j++;
  183.             line[j]=fgetc(fptr);
  184.         }
  185.         line[j]=\'\\0\';
  186.         sscanf(line,"%s %s %s %s ",macron,i1,i2,i3);
  187.         if(strcmp(macron,op)==0)
  188.         {
  189.        return 1;
  190.         }
  191.  
  192.     }
  193. }
  194. fclose(fptr);
  195. return 0;
  196.  
  197. }
  198. int getarg()
  199. {
  200. FILE *fptr;
  201. char line[100],dline[100],op1[10],op2[50];
  202. int i,j,k,l;
  203.  
  204.      if((fptr=fopen("ala.txt" ,"r"))==NULL)
  205. {
  206. printf("\\n\\t\\t file error ....");
  207. }
  208. else
  209. {
  210.     while(!feof(fptr))
  211.     {
  212.     j=0;
  213.     line[j]=fgetc(fptr);
  214.        while(line[j]!=\'\\n\'&&line[j]!=EOF)
  215.         {
  216.  
  217.             j++;
  218.             line[j]=fgetc(fptr);
  219.         }
  220.         line[j]=\'\\0\';
  221.         sscanf(line,"%s %s",op1,op2);
  222.         k=strlen(op1)+1;
  223.         l=strlen(line);
  224.         if(atoi(i3)==atoi(op1))
  225.         {
  226.  
  227.            for(i=strlen(op1)+1,l=0;line[i]!=\'\\0\';i++,l++)
  228.            {
  229.           dline[l]=line[i];
  230.  
  231.            }
  232.           dline[l]=\'\\0\';
  233.           //puts(dline);
  234.           sepd(dline);
  235.            return 1;
  236.         }
  237.         }
  238.         }
  239. fclose(fptr);
  240. return 0;
  241. }
  242. void main()
  243. {
  244. FILE *fptr,*fptr1;
  245. char fname[20],line[50],op[20],str[20],msg[20],arg[20],callline[50];
  246. int j=0,cnt,flag=0,i,l,m,o,k,argf;
  247. clrscr();
  248. if((fptr=fopen("m1.txt" ,"r"))==NULL)
  249. {
  250. printf("\\n\\t\\t file error ....");
  251. }
  252. else
  253. {
  254.     while(!feof(fptr))
  255.     {
  256.     j=0;
  257.     line[j]=fgetc(fptr);
  258.        while(line[j]!=\'\\n\'&&line[j]!=EOF)
  259.         {
  260.             j++;
  261.             line[j]=fgetc(fptr);
  262.         }
  263.         line[j]=\'\\0\';
  264.         sscanf(line," %s ",op);
  265.         flag=searchn(op);
  266.         if(flag!=1)
  267.         {
  268.         write(line);
  269.         write("\\n");
  270.        }
  271.  
  272.        if(flag==1)
  273.         {
  274.            for(i=strlen(macron)+1,l=0;line[i]!=\'\\0\';i++,l++)
  275.         {
  276.            if(line[i]==\',\')
  277.            {
  278.            line[i]=\' \';
  279.            }
  280.             callline[l]=line[i];
  281.         }
  282.         callline[l]=\'\\0\';
  283.         //puts(callline);
  284.         argf=getarg();
  285.         if(argf==1)
  286.         {
  287.           sepc(callline);
  288.           mdt();
  289.           flag=0;
  290.         }
  291.         }
  292.        }
  293. }
  294. fclose(fptr);
  295.         getch();
  296.         }
  297. // end of the program
');