home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part03 / tooltool.c
Encoding:
C/C++ Source or Header  |  1989-06-06  |  6.3 KB  |  191 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /*                                    */
  16. /*    The sale of any product based wholely or in part upon the     */
  17. /*    technology provided by tooltool is strictly forbidden without    */
  18. /*    specific, prior written permission from Harris Corporation.    */
  19. /*    Tooltool technology includes, but is not limited to, the source    */
  20. /*    code, executable binary files, specification language, and    */
  21. /*    sample specification files.                    */
  22. /************************************************************************/
  23.  
  24.  
  25. #include    <stdio.h>
  26. #include    <ctype.h>
  27.  
  28. #include    <sys/file.h>
  29.  
  30. #include    "tooltool.h"
  31.  
  32. EXPORT    a_ptr    tt_initial_action = NULL,
  33.         tt_timer_action = NULL,
  34.         tt_func_keys[MAX_KEY_SETS][MAX_FUNC_KEYS][MAX_SHIFT_SETS];
  35.  
  36. EXPORT    char    *tt_application = NULL,
  37.         *tt_curr_file = "stdin",
  38.         *tt_icon = NULL,
  39.         *tt_program;
  40.  
  41. EXPORT    d_ptr    tt_base_window = NULL;
  42.  
  43. EXPORT    int    tt_mouse_base = 0,
  44.         tt_mouse_chars = TRUE,
  45.         tt_errors_occured = 0,
  46.         tt_normal_off = FALSE,
  47.         tt_function_off = FALSE,
  48.         tt_action_depth = 0,
  49.         tt_timer_pending = FALSE;
  50.  
  51. EXPORT    l_ptr    tt_default_mark,
  52.         tt_default_nomark,
  53.         tt_default_cycle;
  54.  
  55. EXPORT    m_data    tt_mouse[MAX_MOUSE_BUTTONS][MAX_SHIFT_SETS];
  56.  
  57. EXPORT    Menu    tt_ttymenu = NULL;
  58.  
  59. EXPORT    struct    pixfont    *tt_default_font = NULL,
  60.             *tt_a_font = NULL;
  61.  
  62. EXPORT    s_ptr    tt_mouse_x,
  63.         tt_mouse_y,
  64.         tt_delimiters;
  65.  
  66. PRIVATE    short    mark_bits[] = {0x07C0,0x1830,0x2008,0x4384,0x4FE4,0x8FE2,0x9FF2,0x9FF2,
  67.                    0x9FF2,0x8FE2,0x4FE4,0x4384,0x2008,0x1830,0x07C0,0x0000};
  68. mpr_static(tt_mark_image, 15, 15, 1, mark_bits);
  69.  
  70. PRIVATE    short    nomark_bits[] = {0x07C0,0x1830,0x2008,0x4004,0x4004,0x8002,0x8002,0x8002,
  71.                  0x8002,0x8002,0x4004,0x4004,0x2008,0x1830,0x07C0,0x0000};
  72. mpr_static(tt_nomark_image, 15, 15, 1, nomark_bits);
  73.  
  74. PRIVATE    short    cycle_bits[] = {0x07C0,0x0FE0,0x1834,0x301C,0x601C,0x203C,0x0000,0x0000,
  75.                 0x7808,0x700C,0x7018,0x5830,0x0FE0,0x07C0,0x0000,0x0000};
  76. mpr_static(tt_cycle_image, 16, 16, 1, cycle_bits);
  77.  
  78. /************************************************************************/
  79. /* The main driver parses the specification file, builds the window,    */
  80. /* and starts up suntools to execute the user application.        */
  81. /************************************************************************/
  82.  
  83. /************************************************************************/
  84. PRIVATE    check_args(argc, argv, n1, n2, v1, v2)
  85.  
  86. int    *argc;
  87. char    **argv;
  88. char    *n1;
  89. char    *n2;
  90. int    *v1;
  91. int    *v2;
  92.  
  93. {    int    i, j;
  94.  
  95.     for (i = 1; i < *argc; i++)
  96.        if (strcmp(argv[i], n1) == 0 || strcmp(argv[i], n2) == 0) {
  97.           if (i + 1 < *argc)
  98.              *v1 = atoi(argv[i + 1]);
  99.           else
  100.              abend("missing argument after %s", argv[i]);
  101.           if (v2)
  102.              if (i + 2 < *argc)
  103.                 *v2 = atoi(argv[i + 2]);
  104.              else
  105.                 abend("missing argument after %s", argv[i]);
  106.           for (j = i + (v2? 3 : 2); j < *argc; j++, i++)
  107.              argv[i] = argv[j];
  108.           *argc -= (v2? 3 : 2);
  109.           argv[*argc] = NULL;
  110.           break;
  111.           }
  112. }
  113.  
  114. /************************************************************************/
  115. main(argc, argv)
  116.  
  117. int    argc;
  118. char    **argv;
  119.  
  120. {    int    i, j, k;
  121.     int    force_height = -1, force_width = -1, force_rows = -1, force_cols = -1;
  122.  
  123.     tt_program = strsave(argv[0]);
  124.  
  125.     if (argc > 1 && strcmp(argv[1], POLLING_MAGIC_NUMBER) == 0) { /* is this a gross hack, or what? */
  126.        wait_for_window_size(atoi(argv[2]), atoi(argv[3]), POLLING_TIME_OUT);
  127.        execv(tt_full_path_of(argv[4], X_OK), &(argv[4]));
  128.        fprintf(stderr, "could not exec %s\n", argv[4]);
  129.        sleep(20);
  130.        exit(1);
  131.        }
  132.  
  133.     for (i = LEFT_KEY_SET; i < MAX_KEY_SETS; i++)
  134.        for (j = 0; j < MAX_FUNC_KEYS; j++)
  135.           for (k = 0; k < MAX_SHIFT_SETS; k++)
  136.              tt_func_keys[i][j][k] = NULL;
  137.     for (i = MOUSE_LEFT; i < MAX_MOUSE_BUTTONS; i++)
  138.        for (j = 0; j < MAX_SHIFT_SETS; j++)
  139.           tt_mouse[i][j].defined = MOUSE_UNDEFINED;
  140.  
  141.     if (argc >= 3 && strcmp(argv[1], "-f") == 0) {
  142.        if (freopen(tt_full_path_of(argv[2], R_OK), "r", stdin) == NULL)
  143.           abend("could not read %s", argv[2]);
  144.        else {
  145.           tt_curr_file = argv[2];
  146.           for (i = 3; i < argc; i++)
  147.              argv[i - 2] = argv[i];
  148.           argc -= 2;
  149.           }
  150.        }
  151.     check_args(&argc, argv, "-Ww", "-width", &force_cols, NULL);
  152.     check_args(&argc, argv, "-Wh", "-height", &force_rows, NULL);
  153.     check_args(&argc, argv, "-Ws", "-size", &force_width, &force_height);
  154.  
  155.     tt_default_font = pf_default();
  156.     tt_default_mark = tt_make_label(FALSE, NULL, NULL, &tt_mark_image);
  157.     tt_default_nomark = tt_make_label(FALSE, NULL, NULL, &tt_nomark_image);
  158.     tt_default_cycle = tt_make_label(FALSE, NULL, NULL, &tt_cycle_image);
  159.     tt_a_font = tt_default_font;
  160.     tt_base_window = tt_make_base_window();
  161.     tt_make_intrinsic_symbols();
  162.     yyparse();
  163.     if (tt_errors_occured)
  164.        abend("%d errors.", tt_errors_occured);
  165.     if (force_height != -1)
  166.        if (force_rows != -1 || force_cols != -1)
  167.           abend("conflict between window size command line options");
  168.        else {
  169.           tt_base_window->is_chars = FALSE;
  170.           tt_base_window->rows = force_height;
  171.           tt_base_window->columns = force_width;
  172.           }
  173.     else {
  174.        if (force_rows != -1)
  175.           if (tt_base_window->is_chars)
  176.              tt_base_window->rows = force_rows;
  177.           else
  178.              tt_base_window->rows = force_rows * charheight_of(tt_a_font);
  179.        if (force_cols != -1)
  180.           if (tt_base_window->is_chars)
  181.              tt_base_window->columns = force_cols;
  182.           else
  183.              tt_base_window->columns = force_cols * charwidth_of(tt_a_font);
  184.        }
  185.     if (tt_base_window->g_align == NO_ALIGN)
  186.        tt_base_window->g_align = ALIGN_TOP;
  187.     build_window(argc, argv);
  188.     window_main_loop(tt_base_window->frame);
  189.     exit(0);
  190. }
  191.