www.digitalmars.com         C & C++   DMDScript  

c++.command-line - Managed to write first tool from two

Yeah, I managed to write my first tool of two:

obj2def will produce all needed imports by an .obj file:
    obj2def myprog.obj > myprog.def
It will compile well with dmcpp.

My next tool will use this .def file, searching for the exports given there
in all .dll files in the current directory, and if it is found in a new dll
it will create a new def file containing everything for this dll.
This will take several day.

HERE IS THE SOURCE:

// Obj2Def

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char IsChar(char);

int main(int argc, char *argv[])
{
  FILE *ObjFile;
  char Buffer;
  char FileName[255];
  char AtLeastOne=0;

  if (argc==1) {
    printf("Usage: Obj2Def [file.obj]\n");
  } else {
    strncpy(FileName, argv[1], 255);
    ObjFile=fopen(FileName, "rb");

    if (ObjFile==NULL) {
      printf("Error! File: %s not found!\n", FileName);
      printf("Please enter a valid filename!\n");
    } else {
      while (!feof(ObjFile)) {
        if (fgetc(ObjFile)=='_')
          if (fgetc(ObjFile)=='_')
            if (fgetc(ObjFile)=='i')
              if (fgetc(ObjFile)=='m')
                if (fgetc(ObjFile)=='p')
                  if (fgetc(ObjFile)=='_')
                    if (fgetc(ObjFile)=='_') {
                      if (!AtLeastOne) {
                        AtLeastOne=1;
                        printf("EXPORTS\n");
                      }
                      printf("_");
                      Buffer=fgetc(ObjFile);
                      while (IsChar(Buffer)) {
                        printf("%c", Buffer);
                        Buffer=fgetc(ObjFile);
                      }
                    printf("\n");
                    }
      }
    }
    if (!AtLeastOne) printf("No exports found!\n");
  }
  return 1;
}

char IsChar(char WhatChar) {
  if ((WhatChar>='a' && WhatChar<='z') ||
      (WhatChar>='A' && WhatChar<='Z') ||
      (WhatChar>='0' && WhatChar<='9') ||
      (WhatChar==' '))
    return 1;
  else
    return 0;
}
Jul 24 2001