home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / icon / Source / Iconx / C / Istart < prev    next >
Encoding:
Text File  |  1990-07-19  |  2.2 KB  |  95 lines

  1. /*
  2.  *  Main program if Icon is called as a subprogram.
  3.  */
  4.  
  5. #include "../h/config.h"
  6. #include "../h/rt.h"
  7. #include "rproto.h"
  8.  
  9. #ifdef IconCalling
  10.  
  11. novalue main(argc,argv)
  12.  
  13. int argc;
  14. char *argv[];
  15.    {
  16.    int clargc;
  17.    char **clargv;
  18.    int i;
  19.    struct descrip darg;
  20.  
  21.    /*
  22.     * Set up standard Icon interface.  This is only necessary so that
  23.     *  Icon can behave normally as if it were the main program.
  24.     *  It is not necessary if Icon is called by a C program for another
  25.     *  purpose.
  26.     */
  27.  
  28. #if VMS
  29.    redirect(&argc, argv, 0);
  30. #endif                    /* VMS */
  31.  
  32. #ifdef CRAY
  33.    argv[0] = "iconx";
  34. #endif                    /* CRAY */
  35.  
  36. #if SASC
  37.    quite(1);            /* suppress C library diagnostics */
  38. #endif                    /* SASC */
  39.  
  40.    icon_setup(argc, argv, &i);
  41.    while (i--) {            /* skip option arguments */
  42.       argc--;
  43.       argv++;
  44.       }
  45.  
  46.    if (!argc) 
  47.       error("no icode file specified");
  48.  
  49.    /*
  50.     * Read in the icode file argv[1] and initialize the Icon system.
  51.     *  This must be done for any C program calling Icon.
  52.     */
  53.    icon_init(argv[1]);
  54.  
  55.    /*
  56.     * Skip the names of the executable and the file it processes.  This
  57.     *  is necessary only to get the right arguments from the command line
  58.     *  to call Icon as if it were the main program and hence provide
  59.     *  the correct values in the list that is the argument of Icon's main
  60.     *  procedure. This is not necessary if Icon is called from C for
  61.     *  another purpose.
  62.     */
  63.    clargv = argv + 2;
  64.    clargc = argc - 2;
  65.  
  66.    /*
  67.     * Set up a temporary stack and build the necessary list
  68.     *  to call main.
  69.     */
  70.    sp = stack + Wsizeof(struct b_coexpr);
  71.  
  72.    PushNull;
  73.    argp = (dptr)(sp - 1);
  74.    for (i = 0; i < clargc; i++) {
  75.       PushAVal(strlen(clargv[i]));
  76.       PushVal(clargv[i]);
  77.       }
  78.    Ollist(clargc, argp);
  79.  
  80.    /*
  81.     * Now that the list is computed, copy its descriptor off the
  82.     *  stack (which is about to be destroyed), reset the argument
  83.     *  pointer, and make the call to the Icon main procedure.
  84.     */
  85.  
  86.    darg = *argp;
  87.    argp = 0;
  88.    icon_call("main", 1, &darg);    /* return signal and value ignored */
  89.    c_exit(NormalExit);
  90.  
  91.    }
  92. #else                    /* IconCalling */
  93. static char x;                /* avoid empty module */
  94. #endif                    /* IconCalling */
  95.