source: head/obuild/cpp/obuild_windef.c@ 3

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