9.3.4 sic.c amp

back: sic_builtin.c
forward: introducing gnu libtool
up: a sample shell application
fastforward: introducing gnu libtool
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

9.3.4 `sic.c' & `sic.h'

Since the application binary has no installed header files, there is little point in maintaining a corresponding header file for every source, all of the structures shared by these files, and non-static functions in these files are declared in `sic.h' :

 #ifndef SIC_H #define SIC_H 1 #include <sic/common.h> #include <sic/sic.h> #include <sic/builtin.h> BEGIN_C_DECLS extern Syntax syntax_table[]; extern Builtin builtin_table[]; extern Syntax syntax_table[]; extern int evalstream    (Sic *sic, FILE *stream); extern int evalline      (Sic *sic, char **pline); extern int source        (Sic *sic, const char *path); extern int syntax_init   (Sic *sic); extern int syntax_finish (Sic *sic, BufferIn *in, BufferOut *out); END_C_DECLS #endif /* !SIC_H */ 

To hold together everything you have seen so far, the main function creates a Sic parser and initialises it by adding syntax handler functions and builtin functions from the two tables defined earlier, before handing control to evalstream which will eventually exit when the input stream is exhausted.

 int main (int argc, char * const argv[]) {   int result = EXIT_SUCCESS;   Sic *sic = sic_new ();      /* initialise the system */   if (sic_init (sic) != SIC_OKAY)       sic_fatal ("sic initialisation failed");   signal (SIGINT, SIG_IGN);   setbuf (stdout, NULL);   /* initial symbols */   sicstate_set (sic, "PS1", "] ", NULL);   sicstate_set (sic, "PS2", "- ", NULL);      /* evaluate the input stream */   evalstream (sic, stdin);   exit (result); } 

Now, the shell can be built and used:

 $ bootstrap ... $ ./configure --with-readline ... $ make ... make[2]: Entering directory `/tmp/sic/src' gcc -DHAVE_CONFIG_H -I. -I.. -I../sic -I.. -I../sic -g -c sic.c gcc -DHAVE_CONFIG_H -I. -I.. -I../sic -I.. -I../sic -g -c sic_builtin.c gcc -DHAVE_CONFIG_H -I. -I.. -I../sic -I.. -I../sic -g -c sic_repl.c gcc -DHAVE_CONFIG_H -I. -I.. -I../sic -I.. -I../sic -g -c sic_syntax.c gcc  -g -O2  -o sic  sic.o sic_builtin.o sic_repl.o sic_syntax.o \ ../sic/libsic.a ../replace/libreplace.a -lreadline make[2]: Leaving directory `/tmp/sic/src' ... $ ./src/sic ] pwd /tmp/sic ] ls -F Makefile     aclocal.m4   config.cache    configure*    sic/ Makefile.am  bootstrap*   config.log      configure.in  src/ Makefile.in  config/      config.status*  replace/ ] exit $ 

This chapter has developed a solid foundation of code, which I will return to in 12. A Large GNU Autotools Project, when Libtool will join the fray. The chapters leading up to that explain what Libtool is for, how to use it and integrate it into your own projects, and the advantages it offers over building shared libraries with Automake (or even just Make) alone.

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html

GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net