home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / WMAPCWD.C < prev    next >
C/C++ Source or Header  |  1996-06-17  |  3KB  |  127 lines

  1. /*
  2.     Convert Watcom MAP files to format digestable by CWD
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. char InputFile[82],OutputFile[82];
  8. char IOBuffer[255];
  9. FILE *fpin,*fpout;
  10.  
  11. void main(int argc, char **argv)
  12. {
  13.     if(argc<2){
  14.         printf("\nInput MAP file?\n");
  15.         fgets(InputFile,80,stdin);
  16.     }
  17.     else{
  18.         strcpy(InputFile,argv[1]);
  19.     }
  20.     if(argc<3){
  21.         printf("\nOutput MAP file?\n");
  22.         fgets(OutputFile,80,stdin);
  23.     }
  24.     else{
  25.         strcpy(OutputFile,argv[2]);
  26.     }
  27.     if(!strcmp(InputFile,OutputFile)){
  28.         printf("\nInput file name and output file name must be different!\007");
  29.         exit(1);
  30.     }
  31.     ParseMapFile();
  32. }
  33.  
  34. void ParseMapFile()
  35. {
  36.     int pos,len,len2,i;
  37.     int ParseFlag=0,BlankLineFlag=0,Target1MatchFlag=0;
  38.     char *TargetString1="Address";
  39.     char *TargetString2="Symbol";
  40.     char *HeaderString="Address        Publics by Name\n";
  41.  
  42.     fpin=fopen(InputFile,"ra");
  43.     if(fpin==NULL){
  44.         printf("\nError opening file: %s \007",InputFile);
  45.         exit(1);
  46.     }
  47.     fpout=fopen(OutputFile,"wa");
  48.     if(fpout==NULL){
  49.         printf("\nError opening file: %s \007",OutputFile);
  50.         exit(1);
  51.     }
  52.     while(fpin!=NULL && fgets(IOBuffer,255,fpin)!=NULL){    // read until file end
  53.         if(ParseFlag==2){    // processing symbols
  54.             pos=0;
  55.             len=strlen(IOBuffer);
  56.             while(len && IOBuffer[pos]==' ' || IOBuffer[pos]==9){
  57.                 pos++;
  58.                 len--;
  59.             }
  60.             if(len && isdigit(IOBuffer[pos])){    // valid symbol entry
  61.                 if(IOBuffer[pos+13]!='+'){    // kill special symbol sign, ignore locals
  62.                     IOBuffer[pos+13]=' ';
  63.                     fputs(IOBuffer,fpout);
  64.                 }
  65.             }
  66.             if(!len){    // done processing symbol entry list
  67.                 break;
  68.             }
  69.         }
  70.         else if(ParseFlag==1){    // found header, need to process symbols
  71.             pos=0;
  72.             len=strlen(IOBuffer);
  73.             while(len && IOBuffer[pos]==' ' || IOBuffer[pos]==9){
  74.                 pos++;
  75.                 len--;
  76.             }
  77.             if(!len){    // blank line
  78.                 if(!BlankLineFlag){
  79.                     BlankLineFlag=1;    // flag blank line occurred
  80.                 }
  81.                 else{    // only one blank line allowed
  82.                     break;
  83.                 }
  84.             }
  85.             else if(isdigit(IOBuffer[pos])){    // we're at symbols now
  86.                 fputs(HeaderString,fpout);
  87.                 if(IOBuffer[pos+13]!='+'){    // kill special symbol sign, ignore locals
  88.                     IOBuffer[pos+13]=' ';
  89.                     fputs(IOBuffer,fpout);
  90.                 }
  91.                 ParseFlag=2;
  92.             }
  93.         }
  94.         else{    // not found symbol header
  95.             len=strlen(TargetString1);
  96.             pos=0;
  97.             len2=strlen(IOBuffer);
  98.             Target1MatchFlag=0;
  99.             for(i=0;i<=len2-len;i++){
  100.                 if(!strnicmp(&IOBuffer[pos],TargetString1,len)){
  101.                     Target1MatchFlag=1;
  102.                     pos+=len;
  103.                     break;
  104.                 }
  105.                 if(IOBuffer[pos]!=' ' && IOBuffer[pos]!=0){
  106.                     break;    // text in front of first target string
  107.                 }
  108.                 pos++;
  109.             }
  110.             if(Target1MatchFlag){
  111.                 len=strlen(TargetString2);
  112.                 len2=strlen(&IOBuffer[pos]);
  113.                 for(i=0;i<=len2-len;i++){
  114.                     if(!strnicmp(&IOBuffer[pos],TargetString2,len)){
  115.                         ParseFlag=1;
  116.                         break;
  117.                     }
  118.                     if(IOBuffer[pos]!=' ' && IOBuffer[pos]!=0){
  119.                         break;    // text in front of second target string
  120.                     }
  121.                     pos++;
  122.                 }
  123.             }
  124.         }
  125.     }
  126. }
  127.