Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
win32def.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define MAX_STRING   2048
 
#define STRDUP(str)   ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
 
#define STRDEL(str)   {if((str)!=NULL) {free(str);str=NULL;}}
 

Functions

char ** GetWords (char *, char *, int *)
 
int main (int aArgn, char **aArgs)
 

Macro Definition Documentation

#define MAX_STRING   2048

Referenced by main().

#define STRDEL (   str)    {if((str)!=NULL) {free(str);str=NULL;}}

Referenced by GetWords().

#define STRDUP (   str)    ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)

Referenced by GetWords().

Function Documentation

char ** GetWords ( char *  a_string,
char *  a_limiter,
int a_number 
)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Definition at line 104 of file win32def.c.

References free(), malloc(), realloc(), STRDEL, and STRDUP.

Referenced by main().

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 STRDUP(str)
#define STRDEL(str)
void * realloc(void *__ptr, size_t __size)
Definition: hjmalloc.cc:103
void * malloc(size_t __size)
Definition: hjmalloc.cc:30
int main ( int  aArgn,
char **  aArgs 
)

Definition at line 31 of file win32def.c.

References buffer, free(), GetWords(), and MAX_STRING.

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 }
void free(void *__ptr)
Definition: hjmalloc.cc:140
#define buffer
Definition: xmlparse.cc:611
char ** GetWords(char *, char *, int *)
Definition: win32def.c:104
#define MAX_STRING