Eclipse Applications: Top-Level main() Example


/*********************************************************************
  main() for Eclipse Common Lisp top-level Lisp listener.

    Handles command line argument parsing and initialization of Lisp 
    system.  Then calls clLispTopLevel() as the principle operation.  
    Non-zero status is returned if clLispTopLevel() returns an error 
    status.

    To rebuild a new Eclipse top-level Lisp listener using this file,
    compile this file and link the result with the Eclipse libraries,
    the usual C and math libraries, and any platform specific
    libraries noted in the Release Notes.
    For example, on most Unix systems, if this file is named eclipse.c:
       cc eclipse.o -o eclipse -leclipse -leclipsed -lm -ldl


  (c) Copyright 1997, 1998 by Elwood Corp.  All rights reserved.
 *********************************************************************/
#include <stdio.h>
#include <eclipse.h>

extern void clInit __P((unsigned)), clInitD __P((void));
extern clObject clLispTopLevel(clProto),
  clCharpSimpleBaseString __P((const char *));

extern char *optarg;
extern int optind;

int main __P((int, char **));

int 
main(argc, argv)
     int argc;
     char **argv;
{
  int silentp = 0, initp = 1;
  char *init_file = NULL;

  /* ARGUMENT PARSING.						*
   * This part is application-specific, and none of it has any	*
   * interaction with the internal workings of Eclipse.   	*/
  {
    int flag, error_flag = 0, versionp = 0;

    while ((flag = getopt(argc, argv, "vsni:")) != -1)
      switch (flag) {
      case 's':
	silentp = 1;
	break;
      case 'n':
	initp = 0;
	break;
      case 'i':
	init_file = optarg;
	break;
      case 'v':
	versionp = 1;
	break;
      default:
	error_flag++;
      }
    if (error_flag || (optind < argc)) {
      (void) fprintf(stderr, "usage: %s [-vsn [-i initfile]\n", argv[0]);
      (void) fprintf(stderr, "  -v print version and exit.\n");
      (void) fprintf(stderr, "  -s silent mode.\n");
      (void) fprintf(stderr, "  -n do not load init file.\n");
      (void) fprintf(stderr, "  -i use specified init file instead of searching.\n");
      return(error_flag);
    }
    if (versionp) {
      (void) puts("Eclipse Common Lisp " clEclipseVersion());
      (void) puts("Copyright (c) 1997 Elwood Corporation, Inc.");
      return(0);
    }
  }

  /* INITIALIZATION.						*
   * For the Eclipse top-level, we need only call clInit(0).	*
   * Other applications might call other initializations, too. 	*/

  clInit(0);
  clInitD();
  /* Init-functions for Eclipse-generated C files go here. 	*/


  /* PRINCIPLE OPERATIONS					*
   * For the Eclipse top-level, we need only call the 		*
   * lisp-top-level function. 					*
   * A non-nil return value indicates that the EXIT restart was	*
   * used with a non-nil status (i.e. someone decided there was	*
   * an error). 						*/

  /* N.B.: In some operating systems, a true (i.e. non-zero) 	*
   * return value from main() indicates an error status.	*/
  return(clTrue(clLispTopLevel(clTest(!silentp),
			       (!initp ? clNIL :
				(!init_file ? clT :
				 clCharpSimpleBaseString(init_file))),
			       clEOA))); 
}


[Previous] [Next] [Up] [Documentation Contents] [Eclipse Home Page]