7月2-6号LNI文件解析

来源:互联网 发布:淘宝卖家分析 编辑:程序博客网 时间:2024/04/29 13:24

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<malloc.h>

typedef struct Node
{
 int  libraryfilecount;
 char libraryfile[10][50];
 char linkerotheroption[100];
 char cruntimefile[50];
 char dllentry[50];
}Node;
typedef Node *NSNode;

void main()
{
 char ch[50]="";
 char dh[50]="";
 char d[50]="";
 char a[50]="";
 int i=0,j=0,k=0,n=0,flag=0,flag1=0,flag2=0,flag3=0,m=0;

 fstream rfile,rrfile, wfile;
    rrfile.open("d:\\1\\c.txt",ios::in);
     while(!rrfile.eof())
  {
   rrfile.getline(dh,30);
   if(strstr(dh,"LibraryFileCount"))
   {
           while(dh[i]!='=')i++;
     i++;
            m=dh[i]-48;
   cout<<"m="<<m<<endl;
   }
  }
    rrfile.close();


 rfile.open("e:\\Sample\\SAMPLE33.LNI",ios::in);

   
 wfile.open("d:\\1\\c.txt",ios::app);
     NSNode ns;
  ns=(NSNode)malloc(sizeof(Node));
  ns->libraryfilecount=m;

   
 if(!wfile)
 {
  cout<<"cant open"<<endl;
 }
              wfile.put('\n');
              //wfile.put('0');
     //wfile.put('\n');
              //wfile.write("hello!\n",10);
 
 if(!rfile)
 {
       cout<<"mei you da kai cheng gong! "<<endl;
 }
       
   rfile.getline(ch,50);

     for(n=0;n<5;n++)
  {
      i=0;k=0;
   rfile.getline(ch,50);

         while(ch[i]!='=')
    {
                  a[k++]=ch[i++];
    }
    a[k]='\0';
    cout<<a<<endl;
    i=0;
    

   while(ch[i]!='\0')
   {
   
              if(ch[i]=='='&&ch[i+1]!='\0')
     {
      if(flag==0)
      {
       wfile.put('\n');
       wfile.write("[LinkerOptions]",20);
       flag=1;
      }
      i++;j=0;
      while(ch[i]!='\0')
      {
       d[j]=ch[i];
       i++;
       j++;
      }
      i--;
      d[j++]='\0';
      cout<<d<<endl;

      if(!strcmp(a,"Option32"))
      {
       ns->libraryfilecount++;
       strncpy(ns->libraryfile[0],d,j);
       //ns->libraryfile[0][j++]='\0';

      }
      else if(!strcmp(a,"DebugType"))
      {

                      flag1=1;

       strncpy(ns->linkerotheroption,"LinkerOtherOptions=/DebugType:",strlen("LinkerOtherOptions=/DebugType:"));
       ns->linkerotheroption[strlen("LinkerOtherOptions=/DebugType:")]='\0';
            strncat(ns->linkerotheroption,d,j);
          //cout<<d<<endl;
      }
      else if(!strcmp(a,"C Linkage File"))
      {
     
           flag2=1;
          strncpy(ns->cruntimefile,"CRuntimeFile=",strlen("CRuntimeFile="));
       ns->cruntimefile[strlen("CRuntimeFile=")]='\0';
                 strncat(ns->cruntimefile,d,j); 
              //cout<<d<<endl;
      
      }
      else if(!strcmp(a,"DllEntryObjecy"))
      {
           flag3=1;
           strncpy(ns->dllentry,"DLLEntry=",strlen("DLLEntry="));
        ns->dllentry[strlen("DLLEntry=")]='\0';
                  strncat(ns->dllentry,d,j);
      }
       else if(!strcmp(a,"Map"))
      {
        j=0;n=0;
        if(strcmp(d,"No"))
        {
                           while(d[j]!=',')j++;
         j++;
         while(d[j]!='\0')
         d[n++]=d[j++];
         d[n]='\0';
          
           if(flag1==0)
        {
        
         strncpy(ns->linkerotheroption,"LinkerOtherOption=/MAP",strlen("LinkerOtherOption=/MAP"));
         ns->linkerotheroption[strlen("LinkerOtherOption=/MAP")]='\0';
         strncat(ns->linkerotheroption,d,j);
        }
           else
                          {
                strncat(ns->linkerotheroption,";/MAP",strlen(";/MAP"));
                      strncat(ns->linkerotheroption,d,j);
        }
        }
       
      }
      else
       {

       }
       
     } 
   
      // cout<<d<<endl;
               i++;

   }
   

  }
            wfile<<endl;
   wfile<<"LibraryFileCount="<<ns->libraryfilecount<<endl;
      wfile<<"libraryfile"<<ns->libraryfilecount<<"="<<ns->libraryfile[0]<<endl;
            wfile<<ns->linkerotheroption<<endl;
            wfile<<ns->cruntimefile<<endl;
   wfile<<ns->dllentry<<endl;

  wfile.close();
  
}