home *** CD-ROM | disk | FTP | other *** search
-
- /******************************************************************************
-
- MODULE
- AUTO.c
-
- DESCRIPTION
- The Purpose of this Module is to add
- __autoinit-abilities to every known
- C-compiler by adding one simple line
- to the top of the main() function.
-
- this Module was created, 'cause we
- often used DICE's __autoinit qualifier
- and we were not able to port XDME to
- any other platform without bigger changes
- without such a construct.
-
- this module exports 1 function:
- void AUTO_Init(void);
- where AUTO_Init() should be called from
- or before main().
- when using DICE or SAS/C that functioncall
- is obsolete, but using GCC it is really
- necessary.
-
-
- USAGE
-
- METHOD 1
-
- that method does (hopefully) not use any compiler
- depencies, to enable auto-initialisation;
- all You need is an ANSI-Compiler, a Make-Utility
- and a Grep-Utility
-
- * call "AUTO_Init();" at the beginning of main()
-
- * when using gcc it is necessary to add
- the following dependencies to Your Makefile:
-
- M>
- M>_AUTO_enex.h : $(SOURCESC)
- M> egrep -h -e "^[ ]*(MK_)?AUTO(IN|EX)IT[ ]*\(.*\)[ ]*([;/]|$)" $(SOURCESC) > $*.h1
- M> sed -e "s/\([;/{].*$\)|\(.*:\)//g" $*.h1 > $*.h
- M># ^--- drop leding file-comments of grep
- M># ^--- drop the res of the current line
- M> rm $*.h1
- M>
- M>AUTO.o : _AUTO_enex.h
- M>
-
- depending on which system the Makefile is executed on,
- the dependencies can look much nicer or more ugly (I had
- to get to know, that on HPUX the "-h"-option in egrep is
- not available; on AMIGA pipes are officially not supported
- by the root-shell (You might have to replace "rm" by "delete"
- here, too))
-
- * each autoentry/exit-function should get a line
- in its Module's Header of the following form:
-
- for autoentry:
- C> AUTOINIT(<function_name>)
- C>
-
- for autoexit:
- C> AUTOEXIT(<function_name>)
- C>
-
- which might be followed by a comment or a semicolon
- (but to be on the safe side You'd better not put anything
- but Your AUTO..IT(...) definition into that line, since we
- have not totally managed deleting other stuff)
-
-
- METHOD 2
-
- that Method is designed to support the Compiler-builtin
- Auto-initialisation features, like used by DICE or SAS/C,
- but if not using one of those compilers,
-
- * call "AUTO_Init();" at the beginning of main()
- this is done for future support of GNU/C, which to my
- knowledge has no autoinit support
-
- * surround the definition of each auto??it-function
- with MK_AUTO??IT(), where MK_AUTO..IT must be the 1st
- word of a line. Wanna say, write
- C> MK_AUTOINIT(my_init) { ...
- where DICE expects
- C> __autoinit void my_init(void) { ...
- or SAS/C expects
- C> void STI_my_init (void) { ...
-
- * since that method is not ready to use with GNU/C
- there is currently no need to do any addes to the Makefile
- but that might be necessary, if a later version of Method#2
- does also support GNU/C
-
-
-
- NOTES
- Please note these two methods are to be used mutally exclusive, i.e.
- using "AUTO??IT(func_x)" and defining "MK_AUTO??IT(func_x){...}"
- causes func_x be called twice, which might lead into undefined
- situations ...
-
- REQUIREMENTS
-
- METHOD 1
-
- * You must use egrep or something like that to extract
- the autoinit-funktions from Your sources;
- the "-h" options seems not to be available for each version
- of egrep over there (#$&%^$& HPUX), so there might be some
- other solution neccessary.
-
- e.g. it should be possible using sedwith something like:
- M> sed -n "s/^ *AUTO..IT( *[A-Za-z0-9_]* *)/p" >
- but I was never forced to use something like that,
- so it is untested.
-
- METHOD 2
-
- * while using SAS/C or DICE there is no other tool necessary
- when using GNU/C a parser like shown below is necessary,
- so lex might be used to create it...
-
- the parser might be a lex-pgm like the following
- L> WS [ \n\t]
- L> DLM [A-Za-z_][A-Za-z_0-9]*
- L> %%
- L> ^{WS}*(MK_)?AUTO(IN|EX)IT{WS}*"("{WS}*{DLM}{WS}*")" printf("%s;",yytext);
- L> . ;
- to create the scanner just type
- %> lex lex.l
- %> gcc lex.yy.c -ll
- to get it work in a Makefile
- M> _AUTO_enex.h : $(OWN_C_SRCS)
- M> cat $(OWN_C_SRCS) | a.out > _AUTO_ENEX.h
-
- BUGS
- none known
-
- TODO
- tell me
-
- EXAMPLES
-
- SEE ALSO
- AUTO.h
- (DICE: DCC:doc/EXTENSIONS.doc DCC:doc/COMPILER.doc)
-
- INDEX
-
- HISTORY
- 05-12-93 b_noll created
- 15-06-94 b_noll added (void) into MK_AUTO??IT
-
- ******************************************************************************/
-
-
- /**************************************
- Includes
- **************************************/
-
-
- #ifndef AUTO_H
- #include "AUTO.h"
- #endif /* AUTO_H */
-
- #ifndef STDLIB_H
- #include <stdlib.h>
- #endif /* STDLIB_H */
-
- /**************************************
- Global Variables
- **************************************/
-
- /* none */
-
- /**************************************
- Internal Defines & Structures
- **************************************/
-
- #undef AUTOINIT
- #undef AUTOEXIT
- #undef MK_AUTOEXIT
- #undef AUTO_Init
-
-
- /* ---- when using SAS/C or DICE we must ignore method # 2 */
- #if SUPPORT_AUTO
- #define CALL2(x)
- #else
- #define CALL2(x) x();
- #endif
-
- /**************************************
- Internal Variables
- **************************************/
-
- /* none */
-
- /**************************************
- Internal Prototypes
- **************************************/
-
-
- extern void AUTO_Init(void);
- extern void AUTO_Exit(void);
-
- /**************************************
- Macros
- **************************************/
-
- /* see everywhere we include "_AUTO_enex.h" */
-
- /**************************************
- Implementation
- **************************************/
-
-
- ; MK_AUTOINIT( AUTO_Init ) /*
- ^--------------------------------- with that semicolon we disable the sanner */
- { /* for that occurancy of MK_AUTOINIT */
-
- /* ---- *AUTOEXIT is ignored in that function */
- #define AUTOEXIT(x)
- #define MK_AUTOEXIT(x)
- #undef MK_AUTOINIT
-
-
- /* ---- declare protos */
- # define AUTOINIT(x) extern void x(void);
- # define MK_AUTOINIT(x) extern void x(void);
- #include "_AUTO_enex.h"
- # undef MK_AUTOINIT
- # undef AUTOINIT
-
-
- /* ---- be sure we call AUTO_Exit */
- atexit (AUTO_Exit);
-
-
- /* ---- call the functions */
- # define MK_AUTOINIT(x) CALL2(x)
- # define AUTOINIT(x) x();
- #include "_AUTO_enex.h"
- # undef AUTOINIT
- # undef MK_AUTOINIT
-
-
- #undef AUTOEXIT
- #undef MK_AUTOEXIT
- } /* AUTO_Init */
-
-
-
-
-
- void AUTO_Exit (void)
- {
-
- /* ---- *AUTOINIT is ignored in that function */
- #define AUTOINIT(x)
- #define MK_AUTOINIT(x)
-
-
- /* ---- declare protos */
- # define AUTOEXIT(x) extern void x(void);
- # define MK_AUTOEXIT(x) extern void x(void);
- #include "_AUTO_enex.h"
- # undef MK_AUTOEXIT
- # undef AUTOEXIT
-
-
- /* ---- call the functions */
- # define MK_AUTOEXIT(x) CALL2(x)
- # define AUTOEXIT(x) x();
- #include "_AUTO_enex.h"
- # undef AUTOEXIT
- # undef MK_AUTOEXIT
-
-
- #undef AUTOINIT
- #undef MK_AUTOINIT
- } /* AUTO_Exit */
-
- /******************************************************************************
- ***** END AUTO.c
- ******************************************************************************/
-
-
-
-
-
-
-
- /* Hier noch einmal das lex-pgm fuer BEIDE Methoden; um */
- /* Methode X ausschliesslich zu parsen, muss bei "SMB" */
- /* fuer #2 das "?" und fuer #1 "(MK_)?" entfernt weden */
-
-
- #ifdef LEX
-
- WS [ \n\t]
- DLM [A-Za-z_][A-Za-z_0-9]*
- SMB (MK_)?AUTO(IN|EX)IT
-
- %%
-
- ^{WS}*{SMB}{WS}*"("{WS}*{DLM}{WS}*")" ECHO;
- . ;
-
- #endif /* LEX */
-
-