rem: fprintf(outfile, "==libname %s.%s\n", BaseNamL, type);
add: fprintf(outfile, "==libname %s.%s\n", strcmp(BaseNamL, "cardres") == 0 ? "card" : BaseNamL, type);
context: main(int argc, char** argv){   fdDef *tmpdef,	/* a dummy to contain the name to look for */	 *founddef;	/* the fdDef for which we found a prototype */   fdFile *myfile;   char *tmpstr;   FILE *clib;   FILE *outfile;   int   closeoutfile=0;   int   rc = EXIT_FAILURE;   char *fdfilename=0, *clibfilename=0, *outfilename=0;   const char* type = "library";   int count;   Error lerror;   for (count=1; count<argc; count++)   {      char *option=argv[count];      if (*option=='-')      {	 option++;	 if (strcmp(option, "o")==0)	 {	    if (count==argc-1 || outfilename)	    {	       printusage(argv[0]);	       return EXIT_FAILURE;	    }	    if (strcmp(argv[++count], "-"))	       outfilename=argv[count];	 }	 else	 {	    if (*option=='-') /* Accept GNU-style '--' options */	       option++;	    if (strcmp(option, "quiet") == 0)	       Quiet = 1;	    else if (strcmp(option, "version")==0)	    {	       fprintf(stderr, "fd2sfd version " VERSION "\n");	       return EXIT_SUCCESS;	    }	    /* Unknown option */	    else	    {	       printusage(argv[0]);	       return EXIT_FAILURE;	    }	 }      }      else      {	 /* One of the filenames */	 if (!fdfilename)	    fdfilename=option;	 else if (!clibfilename)	    clibfilename=option;	 else if (!outfilename)	    outfilename=option;	 else	 {	    printusage(argv[0]);	    return EXIT_FAILURE;	 }      }   }   if (!fdfilename || !clibfilename)   {      printusage(argv[0]);      return EXIT_FAILURE;   }   if (!(arrdefs=malloc(FDS*sizeof(fdDef*))))   {      fprintf(stderr, "No mem for FDs\n");      rc = EXIT_FAILURE;      goto quit;   }   if (!(arrcmts=malloc(FDS*sizeof(char*))))   {      fprintf(stderr, "No mem for FD comments\n");      rc = EXIT_FAILURE;      goto quit;   }   for (count=0; count<FDS; count++)   {      arrdefs[count]=NULL;      arrcmts[count]=NULL;   }   if (!(myfile=fF_ctor(fdfilename)))   {      fprintf(stderr, "Couldn't open file '%s'.\n", fdfilename);      rc = EXIT_FAILURE;      goto quit;   }   lerror=false;   for (count=0; count<FDS && lerror==false; count++)   {      if (!(arrdefs[count]=fD_ctor()))      {	 fprintf(stderr, "No mem for FDs\n" );	 rc = EXIT_FAILURE;	 goto quit;      }      do      {	 if ((lerror=fF_readln(myfile))==false)	 {	    fF_SetError(myfile, false);	    lerror=fD_parsefd(arrdefs[count], &arrcmts[count], myfile);	 }      }      while (lerror==nodef);   }   if (count<FDS)   {      count--;      fD_dtor(arrdefs[count]);      arrdefs[count]=NULL;      arrcmts[count]=NULL;   }   fds=count;   /* Make a copy before we sort, since we need to process the      definitions in bias order, not lexical order */   if (!(defs=malloc(fds*sizeof(fdDef*))))   {      fprintf(stderr, "No mem for FDs\n");      rc = EXIT_FAILURE;      goto quit;   }   bcopy(arrdefs,defs,fds*sizeof(fdDef*));      qsort(arrdefs, count, sizeof arrdefs[0], fD_cmpName);   if (BaseName[0])   {      unsigned int count2;      StdLib="Library";      for (count2=0; count2<sizeof LibExcTable/sizeof LibExcTable[0]; count2+=2)	 if (strcmp(BaseName, LibExcTable[count2])==0)	 {	    StdLib=LibExcTable[count2+1];	    break;	 }   }   fF_dtor(myfile);   if (!(myfile=fF_ctor(clibfilename)))   {     fprintf(stderr, "Couldn't open file '%s'.\n", clibfilename);     rc = EXIT_FAILURE;     goto quit;   }   if (!(tmpdef=fD_ctor()))   {     fprintf(stderr, "No mem for FDs\n");     rc = EXIT_FAILURE;     goto quit;   }   for (lerror=false; lerror==false || lerror==nodef;)     if ((lerror=fF_readln(myfile))==false)     {       fF_SetError(myfile, false); /* continue even on errors */       tmpstr=fF_FuncName(myfile);       if (tmpstr)       {	 fdDef **res;	 fD_NewName(tmpdef, tmpstr);	 res=(fdDef**)bsearch(&tmpdef, arrdefs, fds, sizeof arrdefs[0],			      fD_cmpName);	 if (res)	 {	   founddef=*res;	   DBP(fprintf(stderr, "found (%s).\n", fD_GetName(founddef)));	   fF_SetError(myfile, false);	   lerror=fD_parsepr(founddef, myfile);	 }	 else	   if (!ishandleddifferently(myfile->line, tmpstr))	     if (!Quiet)	       fprintf(stderr, "Don't know what to do with <%s> in line %lu.\n",		       tmpstr, myfile->lineno);	 free(tmpstr);       }     }   fD_dtor(tmpdef);   fF_dtor(myfile);   if (strlen(fdfilename)>7 &&   !strcmp(fdfilename+strlen(fdfilename)-7, "_lib.fd"))   {      char *str=fdfilename+strlen(fdfilename)-8;      while (str!=fdfilename && str[-1]!='/' && str[-1]!=':')	 str--;//lcs      strncpy(BaseNamL, str, strlen(str)-7);      strncpy(BaseNamU, str, strlen(str)-7);      BaseNamU[strlen(str)-7]='\0';      strcpy(BaseNamL, BaseNamU);      strcpy(BaseNamC, BaseNamU);   }   else   {      strcpy(BaseNamU, BaseName);      if (strlen(BaseNamU)>4 && strcmp(BaseNamU+strlen(BaseNamU)-4, "Base")==0)	 BaseNamU[strlen(BaseNamU)-4]='\0';      strcpy(BaseNamL, BaseNamU);      strcpy(BaseNamC, BaseNamU);   }   StrUpr(BaseNamU);   BaseNamC[0]=toupper(BaseNamC[0]);   if (BaseName[0])   {      unsigned int count2;      if (strlen(fdfilename)>6 &&	  !strcmp(fdfilename+strlen(fdfilename)-6, "_gc.fd"))	 type = GADGET;      else if (strlen(fdfilename)>6 &&	       !strcmp(fdfilename+strlen(fdfilename)-6, "_ic.fd"))	 type = IMAGE;      else if (strlen(fdfilename)>6 &&	       !strcmp(fdfilename+strlen(fdfilename)-6, "_cl.fd"))	 type = CLASS;      else      {	 for (count2=0; count2<sizeof TypeTable/sizeof TypeTable[0]; count2+=2)	 {	    if (strcmp(BaseName, TypeTable[count2])==0)	    {	       type=TypeTable[count2+1];	       break;	    }	 }      }   }   if (outfilename)   {      if (!(outfile=fopen(outfilename, "w")))      {	 fprintf(stderr, "Couldn't open output file.\n");	 rc = EXIT_FAILURE;	 goto quit;      }      else      {	 closeoutfile=1;      }   }   else      outfile=stdout;   if (BaseName[0])   {      fprintf(outfile, "==base _%s\n", BaseName);      fprintf(outfile, "==basetype struct %s *\n", StdLib);   }   if (BaseName[0])   {      fprintf(outfile, "==libname %s.%s\n", BaseNamL, type);   }   // We always need this   fprintf(outfile, "==include <exec/types.h>\n");	       clib = fopen( clibfilename, "r" );   if (clib == NULL)   {      fprintf(stderr, "Couldn't open file '%s'.\n", clibfilename);   }   else   {      char* buffer = malloc(1024);      if (buffer == NULL)      {	 fprintf(stderr, "No memory for line buffer.\n " );      }      else      {	 while (fgets(buffer, 1023, clib) != NULL)	 {	    int i = 0;	    while (buffer[i] == ' ' || buffer[i] == '\t') ++i;	    if( buffer[ i ] == '#') /* Pre-processor instruction */ 	    {	       ++i;	       while (buffer[i] == ' ' || buffer[i] == '\t') ++i;	       if (strncmp(buffer+i, "include",7) == 0)	       {		  char  start = 0;		  char  end   = 0;		  char* inc;		  i += 7;		  while (buffer[i] == ' ' || buffer[i] == '\t') ++i;		  start = buffer[i];		  		  if (start== '"' )		     end = '"';		  else if (start == '<')		     end = '>';		  else		  {		     fprintf(stderr, "Bad #include line\n");		  }		  ++i;		  inc = buffer+i;		  while (buffer[i] != end && buffer[i] != 0) ++i;		  buffer[i] = 0;		     		  fprintf(outfile, "==include %c%s%c\n", start, inc, end );	       }	    }	 }			 free(buffer);      }            fclose(clib);   }   for (count=0; count<fds && defs[count]; count++)   {      DBP(fprintf(stderr, "outputting %ld...\n", count));      if (arrcmts[count])      {	fprintf(outfile, "%s", arrcmts[count]);      }      fD_write(outfile, defs[count], 0);   }   fprintf(outfile, "==end\n");   rc = EXIT_SUCCESS;  quit:   for (count=0; count<FDS && arrdefs[count]; count++)      fD_dtor(arrdefs[count]);   for (count=0; count<FDS && arrcmts[count]; count++)      free(arrcmts[count]);   free(defs);   free(arrdefs);   free(arrcmts);   if (closeoutfile)   {      fclose(outfile);   }   return rc;}