home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / MISC / WMAPCWD.C < prev    next >
C/C++ Source or Header  |  1999-01-25  |  3KB  |  128 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.     char *HeaderString="Address                 Publics by name\n";
  42.  
  43.     fpin=fopen(InputFile,"ra");
  44.     if(fpin==NULL){
  45.         printf("\nError opening file: %s \007",InputFile);
  46.         exit(1);
  47.     }
  48.     fpout=fopen(OutputFile,"wa");
  49.     if(fpout==NULL){
  50.         printf("\nError opening file: %s \007",OutputFile);
  51.         exit(1);
  52.     }
  53.     while(fpin!=NULL && fgets(IOBuffer,255,fpin)!=NULL){    // read until file end
  54.         if(ParseFlag==2){    // processing symbols
  55.             pos=0;
  56.             len=strlen(IOBuffer);
  57.             while(len && IOBuffer[pos]==' ' || IOBuffer[pos]==9){
  58.                 pos++;
  59.                 len--;
  60.             }
  61.             if(len && isdigit(IOBuffer[pos])){    // valid symbol entry
  62. //                if(IOBuffer[pos+13]!='+'){    // kill special symbol sign, ignore locals
  63.                     IOBuffer[pos+13]=' ';
  64.                     fputs(IOBuffer,fpout);
  65. //                }
  66.             }
  67.             if(!len){    // done processing symbol entry list
  68.                 break;
  69.             }
  70.         }
  71.         else if(ParseFlag==1){    // found header, need to process symbols
  72.             pos=0;
  73.             len=strlen(IOBuffer);
  74.             while(len && IOBuffer[pos]==' ' || IOBuffer[pos]==9){
  75.                 pos++;
  76.                 len--;
  77.             }
  78.             if(!len){    // blank line
  79.                 if(!BlankLineFlag){
  80.                     BlankLineFlag=1;    // flag blank line occurred
  81.                 }
  82.                 else{    // only one blank line allowed
  83.                     break;
  84.                 }
  85.             }
  86.             else if(isdigit(IOBuffer[pos])){    // we're at symbols now
  87.                 fputs(HeaderString,fpout);
  88. //                if(IOBuffer[pos+13]!='+'){    // kill special symbol sign, ignore locals
  89.                     IOBuffer[pos+13]=' ';
  90.                     fputs(IOBuffer,fpout);
  91. //                }
  92.                 ParseFlag=2;
  93.             }
  94.         }
  95.         else{    // not found symbol header
  96.             len=strlen(TargetString1);
  97.             pos=0;
  98.             len2=strlen(IOBuffer);
  99.             Target1MatchFlag=0;
  100.             for(i=0;i<=len2-len;i++){
  101.                 if(!strnicmp(&IOBuffer[pos],TargetString1,len)){
  102.                     Target1MatchFlag=1;
  103.                     pos+=len;
  104.                     break;
  105.                 }
  106.                 if(IOBuffer[pos]!=' ' && IOBuffer[pos]!=0){
  107.                     break;    // text in front of first target string
  108.                 }
  109.                 pos++;
  110.             }
  111.             if(Target1MatchFlag){
  112.                 len=strlen(TargetString2);
  113.                 len2=strlen(&IOBuffer[pos]);
  114.                 for(i=0;i<=len2-len;i++){
  115.                     if(!strnicmp(&IOBuffer[pos],TargetString2,len)){
  116.                         ParseFlag=1;
  117.                         break;
  118.                     }
  119.                     if(IOBuffer[pos]!=' ' && IOBuffer[pos]!=0){
  120.                         break;    // text in front of second target string
  121.                     }
  122.                     pos++;
  123.                 }
  124.             }
  125.         }
  126.     }
  127. }
  128.