Geant4_10
win32def.c
Go to the documentation of this file.
1 /* $Id: win32def.c 66368 2012-12-18 09:20:17Z gcosmo $ */
2 /* +---------------------- Copyright notice -------------------------------+ */
3 /* | Copyright (C) 1995, Guy Barrand, LAL Orsay, (barrand@lal.in2p3.fr) | */
4 /* | Permission to use, copy, modify, and distribute this software | */
5 /* | and its documentation for any purpose and without fee is hereby | */
6 /* | granted, provided that the above copyright notice appear in all | */
7 /* | copies and that both that copyright notice and this permission | */
8 /* | notice appear in supporting documentation. This software is | */
9 /* | provided "as is" without express or implied warranty. | */
10 /* +---------------------- Copyright notice -------------------------------+ */
11 
12 /*
13  This program is a tool to build .def file
14  used by lib.exe to build the DLL on Windows.
15  It takes the output of a "dumpbin" over an
16  archive library and produces the .def file for
17  this library. For example :
18  DOS> dumpbin /out:tmp /symbols MyLib.arc
19  DOS> win32def.exe MyLib < tmp > MyLib.def
20  Note that win32def is a standalone program that
21  can be easily reconstructed with :
22  DOS> cl /Fowin32def.exe win32def.c
23 */
24 
25 #include <string.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 
29 char** GetWords (char*,char*,int*);
30 /*****************************************************************************/
31 int main (
32  int aArgn
33 ,char** aArgs
34 )
35 /*****************************************************************************/
36 {
37 #define MAX_STRING 2048
38  char buffer[MAX_STRING+1];
39  int length;
40 
41 
42  /*EXETYPE WINDOWS\n\ */
43  printf("\
44 LIBRARY %s\n\
45 EXPORTS\n",aArgs[1]);
46 
47  while(1){
48  if(fgets(buffer,MAX_STRING,stdin)==NULL) return EXIT_FAILURE;
49  /*
50  On some system (NT) editors when saving binary files
51  put \r\n at place of \n ; we then look for \r\n.
52  */
53  length = strlen(buffer);
54  if( (length>=2) && (buffer[length-2]=='\r') && (buffer[length-1]=='\n') ) {
55  buffer[length-2] = '\0';
56  length--;
57  length--;
58  } else if((length>=1) && (buffer[length-1]=='\n')) {
59  buffer[length-1] = '\0';
60  length--;
61  }
62  if(strstr(buffer,"SECT")==NULL) continue;
63  if(strstr(buffer,"External")==NULL) continue;
64  if(strstr(buffer,"??_")!=NULL) {
65  if(strstr(buffer,"operator/=")==NULL) continue;
66  /* Keep operator /= */
67  }
68 
69  {
70  char** words;
71  int wordn;
72  words = GetWords (buffer," ",&wordn);
73  if(wordn>=8) {
74  int iword = 7;
75  int offset = 0;
76  if(strcmp(words[4],"()")==0) {
77  iword = 7;
78  } else if(strcmp(words[4],"External")==0) {
79  iword = 6;
80  }
81  if(words[iword][0]=='_') offset = 1;
82 
83  if( (iword==6) && (strstr(buffer,"static class")!=NULL) ){
84  /* static class objects are not DATA */
85  printf(" %s\n",words[iword]+offset);
86  } else if(iword==6) {
87  /* DATA */
88  printf(" %s\tDATA\n",words[iword]+offset);
89  } else {
90  /* code */
91  printf(" %s\n",words[iword]+offset);
92  }
93 
94  }
95  {int count;
96  for(count=0;count<wordn;count++) if(words[count]) free(words[count]);
97  if(words) free(words);}
98  }
99  /*printf("%s\n",buffer);*/
100  }
101  return EXIT_SUCCESS;
102 }
103 /*****************************************************************************/
104 char** GetWords (
105  char* a_string
106 ,char* a_limiter
107 ,int* a_number
108 )
109 /***************************************************************************/
111 {
112 #define STRDUP(str) ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
113 #define STRDEL(str) {if((str)!=NULL) {free(str);str=NULL;}}
114  int count;
115  char* string;
116  char* token;
117  int iline;
118  char** list = NULL;
119  int nline = 0;
120 /*.........................................................................*/
121  if(a_number!=NULL) *a_number = 0;
122  if( (a_string==NULL) || (*a_string=='\0') ) return NULL;
123  if(a_limiter==NULL) return NULL;
124 
125  string = STRDUP(a_string);
126  if(string==NULL) return NULL;
127 
128  nline = 16;
129  list = (char**)malloc(nline*sizeof(char*));
130  if(list==NULL) return NULL;
131  iline = 0;
132 
133  token = string;
134  while(1) {
135  char* pos;
136  pos = strstr (token,a_limiter);
137  if(pos!=NULL) {
138  *pos = '\0';
139  if(*token!='\0') {
140  if(iline>=nline) {
141  nline +=16;
142  list = (char**)realloc(list,nline*sizeof(char*));
143  if(list==NULL) return NULL;
144  }
145  list[iline] = token;
146  iline++;
147  }
148  token = pos + strlen(a_limiter);
149  } else { /*last word*/
150  if(*token!='\0') {
151  if(iline>=nline) {
152  nline += 16;
153  list = (char**)realloc(list,nline*sizeof(char*));
154  if(list==NULL) return NULL;
155  }
156  list[iline] = token;
157  iline++;
158  }
159  break;
160  }
161  }
162 
163  for(count=0;count<iline;count++) list[count] = STRDUP(list[count]);
164  STRDEL(string);
165 
166  if(iline==0) {
167  if(list) free(list);
168  if(a_number!=NULL) *a_number = 0;
169  return NULL;
170  } else {
171  if(a_number!=NULL) *a_number = iline;
172  return list;
173  }
174 }
void free(void *__ptr)
Definition: hjmalloc.cc:140
#define buffer
Definition: xmlparse.cc:611
int main(int argc, char **argv)
Definition: genwindef.cpp:30
char ** GetWords(char *, char *, int *)
Definition: win32def.c:104
#define MAX_STRING
#define STRDUP(str)
#define STRDEL(str)
printf("%d Experimental points found\n", nlines)
void * realloc(void *__ptr, size_t __size)
Definition: hjmalloc.cc:103
void * malloc(size_t __size)
Definition: hjmalloc.cc:30