2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
19 #define _read(stream,buff,count) fread(buff,1,count,stream)
21 int main ( int argc
, char **argv
)
24 int i
, filecount
, startarg
;
27 /* Starting sequence of a C comment: '\slash','\asterisk' */
28 char c_comment
[3] = { 0x2f, 0x2a, 0x00 };
29 /* Starting sequence of a C++ comment: '\slash','\slash' */
30 char cpp_comment
[3] = { 0x2f, 0x2f, 0x00 };
33 struct inclist first
= { NULL
, ft
}, *current
, *search
;
42 fprintf( stderr
, "No input files given!\n" );
46 if ( strcmp(argv
[1],"-d") == 0 )
57 sprintf(filename
, "%s/functions.c", outputdir
);
58 fdo
= fopen ( filename
, "w" );
61 fprintf ( stderr
, "Could not open functions.c out-file!\n" );
64 fprintf ( fdo
, "#include \"functions.h\"\n" );
66 printf ( "Collecting functions..." );
67 for ( filecount
= startarg
; filecount
< argc
; filecount
++ )
69 /* printf ( "Opening %s\n", argv[filecount] ); */
70 strcpy ( filename
, argv
[filecount
] );
71 strcat ( filename
, ".c" );
72 fd
= fopen ( filename
, "rb" );
75 fprintf ( stderr
, "\n%s - No such file !\n", argv
[filecount
] );
79 fprintf ( fdo
, "#line 1 \"%s\"\n", filename
);
80 count
= _read ( fd
, fbuf
, 1 );
86 count
= _read( fd
, &fbuf
[1], 1 );
87 if ( fbuf
[count
] == '*' )
89 /* This is a C comment, copy everything until
90 the end of the comment */
91 fprintf ( fdo
, c_comment
);
96 count
= _read ( fd
, fbuf
, 1 );
97 putc ( fbuf
[0], fdo
);
98 } while ( count
== 1 && fbuf
[0] != '*' );
99 count
= _read( fd
, fbuf
, 1 );
100 putc ( fbuf
[0], fdo
);
101 } while ( count
== 1 && fbuf
[0] != '/' );
103 else if ( fbuf
[count
] == '/' )
105 /* This is a C++ comment, copy everything until
106 the end of the current line */
107 fprintf ( fdo
, cpp_comment
);
110 count
= _read( fd
, fbuf
, 1 );
111 putc ( fbuf
[0], fdo
);
112 } while ( count
== 1 && fbuf
[0] != '\n' );
116 if ( fseek ( fd
, -count
, SEEK_CUR
) != 0 )
121 putc ( fbuf
[0], fdo
);
125 count
= _read ( fd
, &fbuf
[1], 8 );
127 if ( strcmp ( fbuf
, "#include " ) == 0 )
129 _read ( fd
, incname
, 1 );
130 if ( incname
[0] == '<' || incname
[0] == 0x22 )
134 if ( incname
[0] == '<' )
146 _read ( fd
, &incname
[i
], 1 );
147 } while ( incname
[i
] != bracket
);
152 found
= 0, search
= &first
;
153 search
->next
!= NULL
;
154 search
= search
->next
157 /* don't put <> includes after "" ones */
158 if ( bracket
== '>' && search
->next
->text
[0] != '<')
161 if ( strcmp ( search
->next
->text
, incname
) == 0 )
169 current
= malloc ( sizeof ( struct inclist
) );
170 current
->next
= search
->next
;
171 current
->text
= strdup ( incname
);
172 search
->next
= current
;
177 fprintf ( fdo
, "#include %c", incname
[0] );
182 if ( fseek ( fd
, -count
, SEEK_CUR
) != 0 )
187 putc ( fbuf
[0], fdo
);
193 putc ( fbuf
[0], fdo
);
196 count
= _read ( fd
, fbuf
, 1 );
198 /* If the last character of the file is not a newline '\n'
199 then append a newline character to avoid faulty concatenation
201 if ( fbuf
[0] != '\n' )
209 sprintf(filename
, "%s/functions.h", outputdir
);
210 fdo
= fopen ( filename
, "w" );
213 fprintf ( stderr
, "Could not open functions.h out-file!\n" );
218 while ( search
!= NULL
)
221 fprintf ( fdo
, "#include %s\n", current
->text
);
222 search
= current
->next
;
223 free ( current
->text
);
228 printf ( "Done!\n" );