home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / imain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  7.8 KB  |  344 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <ctype.h>
  13. #include <string.h>
  14. #include "config.h"
  15. #include "ivars.h"
  16. #include "slot.h"
  17. #include "ifile.h"
  18. #include "intaprots.h"
  19. #include "loadprots.h"
  20. #include "miscprots.h"
  21. #include "libfprots.h"
  22. #ifdef vms
  23. #include descrip
  24. #endif
  25.  
  26. #ifdef DEBUG
  27. #ifdef DEBUG_STORES
  28. int heap_store_offset = 0;
  29. #endif
  30. #endif
  31.  
  32. static void fold_upper(char *);
  33.  
  34. /* global variable needed for imain.c, derived from generator */
  35. FILE *MALFILE;
  36. FILE *efopen();
  37.  
  38. main(int argc, char **argv)                                            /*;main*/
  39. {
  40.     int         c, i, n, status;
  41.     int         errflg = 0, nobuffer = 0;
  42.     char        *FILENAME;
  43.     IFILE       *ifile;
  44.     extern int  optind;
  45.     extern char *optarg;
  46.     char        *library_name;
  47.     char    *t_name;
  48.     Axq        axq;
  49.     char    *main_unit = (char *)0;
  50.     char     *tname;
  51.     int        malloc_trace = 0;
  52. #ifdef vms
  53.     char        buffer[50];
  54.     short       rlength;
  55.     struct      dsc$descriptor_s entity_desc;
  56.     struct      dsc$descriptor_s value_desc;
  57. #endif
  58.  
  59.     max_mem = MAX_MEM;
  60. #ifdef IBM_PC
  61.     new_task_size = 2048;
  62.     main_task_size = 4096;
  63. #else
  64.     main_task_size = 10000;
  65.     new_task_size = 10000;
  66. #endif
  67. #ifdef vms
  68.     entity_desc.dsc$b_dtype = DSC$K_DTYPE_T;
  69.     entity_desc.dsc$b_class = DSC$K_CLASS_S;
  70.     entity_desc.dsc$a_pointer = "TRACE";
  71.     entity_desc.dsc$w_length = 5;
  72.     value_desc.dsc$b_dtype = DSC$K_DTYPE_T;
  73.     value_desc.dsc$b_class = DSC$K_CLASS_S;
  74.     value_desc.dsc$a_pointer = buffer;
  75.     value_desc.dsc$w_length = 50;
  76.     status = CLI$PRESENT(&entity_desc);
  77. #ifdef DEBUG
  78.     printf("TRACE status %d\n",status);
  79. #endif
  80.     while (status & 1) {
  81.         status = CLI$GET_VALUE(&entity_desc, &value_desc, &rlength);
  82. #ifdef DEBUG
  83.         value_desc.dsc$a_pointer[rlength] = '\0';
  84.         printf("TRACE %s\n", value_desc.dsc$a_pointer);
  85. #endif
  86.         switch (value_desc.dsc$a_pointer[0]) {
  87.         case 'A': /* ADALINE    */
  88.             line_trace++;  
  89.             break;
  90.         case 'C': /* CALL       */
  91.             call_trace++;  
  92.             break;
  93.         case 'D': /* DEBUG      */
  94.             debug_trace++;  
  95.             break;
  96.         case 'E': /* EXCEPTION  */
  97.             exception_trace++;  
  98.             break;
  99.         case 'R': /* RENDEZVOUS */
  100.             rendezvous_trace++;  
  101.             break;
  102.         case 'S': /* SIGNAL     */
  103.             signal_trace++;  
  104.             break;
  105.         case 'T': /* TASKING    */
  106.             tasking_trace++;  
  107.             break;
  108.         }
  109.         if (status == 1) break;
  110.     }
  111.     entity_desc.dsc$a_pointer = "HEAP_SIZE";
  112.     entity_desc.dsc$w_length = 9;
  113.     status = CLI$PRESENT(&entity_desc);
  114. #ifdef DEBUG
  115.     printf("HEAP_SIZE status %d\n",status);
  116. #endif
  117.     if (status & 1) {
  118.         status = CLI$GET_VALUE(&entity_desc, &value_desc, &rlength);
  119.         value_desc.dsc$a_pointer[rlength] = '\0';
  120.         max_mem = atoi(value_desc.dsc$a_pointer);
  121. #ifdef DEBUG
  122.         printf("HEAP_SIZE %d\n", max_mem);
  123. #endif
  124.         max_mem = 1000 * max_mem;
  125.     }
  126.     entity_desc.dsc$a_pointer = "MAIN_UNIT";
  127.     entity_desc.dsc$w_length = 9;
  128.     status = CLI$PRESENT(&entity_desc);
  129. #ifdef DEBUG
  130.     printf("MAIN_UNIT status %d\n",status);
  131. #endif
  132.     if (status & 1) {
  133.         status = CLI$GET_VALUE(&entity_desc, &value_desc, &rlength);
  134.         value_desc.dsc$a_pointer[rlength] = '\0';
  135.         main_unit = strjoin(value_desc.dsc$a_pointer,"");
  136.         fold_upper(main_unit);
  137. #ifdef DEBUG
  138.         printf("MAIN_UNIT %s\n", main_unit);
  139. #endif
  140.     }
  141.     entity_desc.dsc$a_pointer = "LIBRARY";
  142.     entity_desc.dsc$w_length = 7;
  143.     status = CLI$PRESENT(&entity_desc);
  144. #ifdef DEBUG
  145.     printf("LIBRARY status %d\n",status);
  146. #endif
  147.     if (status & 1) {
  148.         status = CLI$GET_VALUE(&entity_desc, &value_desc, &rlength);
  149.         value_desc.dsc$a_pointer[rlength] = '\0';
  150.         library_name = strjoin(value_desc.dsc$a_pointer,"");
  151. #ifdef DEBUG
  152.         printf("LIBRARY %s\n", library_name);
  153. #endif
  154.     }
  155. #else
  156. #ifndef DEBUG_STORES
  157.     while((c = getopt(argc, argv, "bf:h:m:p:s:t:")) != EOF) {
  158. #else
  159.     while((c = getopt(argc, argv, "bf:h:m:p:s:t:w:")) != EOF) {
  160. #endif
  161.         /*    user:
  162.          *      h       heap size in kilobytes
  163.          *    m    main unit name
  164.          *    p    main program task stack size
  165.          *    s    task stack size
  166.          *    t    tracing, followed by list of options:
  167.          *                a    Ada lines
  168.          *                c    calls 
  169.          *                e    exceptions
  170.          *                r    rendezvous
  171.          *                t    tasks
  172.          *    debug (only):
  173.          *                d    debug
  174.          *          i     instruction
  175.          *          m    malloc
  176.          *                s    signals
  177.          *    b    do not buffer standard output
  178.          *    f    file i/o trace, followed by list of options
  179.          *        a    trace axq files
  180.          *        d    do not include descriptors in trace
  181.          *        n    do not include file numbers in trace
  182.          *        l    trace lib files
  183.          *    w    off    trace stores at specified offset in heap
  184.          */
  185.         switch(c) {
  186. #ifdef DEBUG
  187.         case 'b':    /* do not buffer standard output (for debugging) */
  188.             nobuffer++;
  189.             break;
  190.         case 'f':    /* process ifile trace options */
  191.             n = strlen(optarg);
  192.             for (i = 0;i < n; i++) {
  193.                 switch (optarg[i]) {
  194.  
  195.                 case 'a':
  196.                     iot_ais_r = 2; 
  197.                     break;
  198.                 case 'l':
  199.                     iot_lib_r = 2; 
  200.                     break;
  201.                 case 'n': 
  202.                     iot_set_opt_number(0);
  203.                     break;
  204.                 case 'd': 
  205.                     iot_set_opt_desc(0); 
  206.                     break;
  207.                 }
  208.             }
  209.             break;
  210. #ifdef DEBUG_STORES
  211.         case 'w':    /* storage write trace */
  212.             heap_store_offset = atoi(optarg);
  213.             break;
  214. #endif
  215. #endif
  216.         case 'h': /* heap size in kilo bytes */
  217. #ifndef IBM_PC
  218.             max_mem = 1000*atoi(optarg);
  219. #else
  220.             {
  221.                 int optval; /* avoid too large value */
  222.                 optval = atoi(optarg);
  223.                 if (optval > 0 && optval < MAX_MEM/1000) 
  224.                     max_mem = 1000*optval;
  225.             }
  226. #endif
  227.             break;
  228.         case 'm': /* specify main unit name */
  229.             main_unit = strjoin(optarg,"");
  230.             fold_upper(main_unit);
  231.             break;
  232.         case 'p': /* main task stack size */
  233.             i = atoi(optarg);
  234.             if (i > 0 && i < 31)     /* small value gives kilowords */
  235.                 main_task_size = i * 1024;
  236.             else if (i > 31)
  237.                 main_task_size = i;
  238.             break;
  239.         case 's': /* task stack size */
  240.             i = atoi(optarg);
  241.             if (i > 0 && i < 31)    /* small value gives kilowords */
  242.                 new_task_size = i * 1024;
  243.             else if (i > 31)
  244.                 new_task_size = i;
  245.             break;
  246.         case 't': /* interpreter trace arguments */
  247.             n = strlen(optarg);
  248.             for (i = 0; i < n; i++) {
  249.                 switch(optarg[i]) {
  250.                 case 'c': /* calls */
  251.                     call_trace++;
  252.                     break;
  253.                 case 'e': /* exceptions */
  254.                     exception_trace++;
  255.                     break;
  256.                 case 'a': /* Ada lines */
  257.                     line_trace++;
  258.                     break;
  259.                 case 'r': /* rendezvous */
  260.                     rendezvous_trace++;
  261.                     break;
  262.                 case 't': /* tasks */
  263.                     tasking_trace++;
  264.                     break;
  265. #ifdef DEBUG
  266.                 case 'd': /* debug */
  267.                     debug_trace++;
  268.                     break;
  269.                 case 'i': /* instructions */
  270.                     instruction_trace++;
  271.                     break;
  272.                 case 'm': /* malloc */
  273.                     malloc_trace++;
  274.                     break;
  275.                 case 's': /* signals */
  276.                     signal_trace++;
  277.                     break;
  278. #endif
  279.                 default:
  280.                     errflg++;
  281.                     break;
  282.                 }
  283.             }
  284.             break;
  285.         case '?':
  286.             errflg++;
  287.         }
  288.     }
  289. #ifdef DEBUG
  290.     if (debug_trace)
  291.         printf("program, new task stack sizes %d %d\n",
  292.           main_task_size, new_task_size);
  293. #endif
  294.     if (optind < argc)
  295.         library_name = argv[optind];
  296.     else {
  297.         library_name = getenv("ADALIB");
  298.     }
  299.     if (library_name == (char *)0)
  300.         errflg++;
  301.     if (errflg) {
  302.         fprintf(stderr,
  303.           "Usage: adaexec -m main_unit -h size -t[acert] library\n");
  304.         exit(RC_ABORT);
  305.     }
  306. #endif
  307. #ifdef DEBUG
  308.     if (nobuffer)
  309.         setbuf(stdout,(char *) 0);/* do not buffer output(for debug) */
  310.     if (malloc_trace) {
  311.         trace_malloc();
  312.         tname = emalloc((unsigned)strlen(library_name) + 5);
  313.         MALFILE = efopen(strcat(strcpy(tname,library_name),".mai"),"w","t");
  314.         efreet(tname,"temp-file-name");
  315.     }
  316. #endif
  317.     FILENAME = library_name;
  318.     t_name = libset(library_name);
  319.  
  320.     /* AXQFILE is opened by load_axq or library read (TBSL);*/
  321.     axq = (Axq) emalloc((unsigned) sizeof(Axq_s));
  322.     load_slots(FILENAME, &ifile, axq);
  323.     /* second arg to load_lib and load_axq is non-null if file open */
  324.     load_lib(FILENAME, ifile, axq, main_unit, argv);
  325.  
  326.     status = int_main();
  327. #ifdef vms
  328.     exit();
  329. #else
  330.     exit(status);
  331. #endif
  332. }
  333.  
  334. static void fold_upper(char *s)                    /*;fold_upper*/
  335. {
  336.     char c;
  337.  
  338.     while (*s) {
  339.         c = *s;
  340.         if (islower(c)) *s = toupper(c);
  341.         s++;
  342.     }
  343. }
  344.