home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / toswinsc.zoo / toswin.c < prev    next >
C/C++ Source or Header  |  1992-10-27  |  22KB  |  985 lines

  1. /*
  2.  * Copyright 1992 Eric R. Smith. All rights reserved.
  3.  * Redistribution is permitted only if the distribution
  4.  * is not for profit, and only if all documentation
  5.  * (including, in particular, the file "copying")
  6.  * is included in the distribution in unmodified form.
  7.  * THIS PROGRAM COMES WITH ABSOLUTELY NO WARRANTY, NOT
  8.  * EVEN THE IMPLIED WARRANTIES OF MERCHANTIBILITY OR
  9.  * FITNESS FOR A PARTICULAR PURPOSE. USE AT YOUR OWN
  10.  * RISK.
  11.  */
  12. #include "xgem.h"
  13. #include <osbind.h>
  14. #include <mintbind.h>
  15. #include <fcntl.h>
  16. #include <signal.h>
  17. #include <minimal.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include "toswin.h"
  21. #include "twdefs.h"
  22. #include "twproto.h"
  23. #include <linea.h>
  24.  
  25. extern void free();
  26. void *heapbase = 0;
  27. long heapsize = 96*1024L;
  28. long _stksiz = 6 * 1024L;
  29. long termfunc;
  30.  
  31. WINDOW *focuswin;
  32.  
  33. #ifndef TIOCSWINSZ
  34. #define TIOCGWINSZ    (('T'<< 8) | 11)
  35. #define TIOCSWINSZ    (('T'<< 8) | 12)
  36. #endif
  37.  
  38. /* set if we're running MultiTOS */
  39. int MultiTOS = 0;
  40.  
  41. /* set if we're an accessory under old TOS */
  42. int oldACC = 0;
  43. int global_flag = 0;    /* set to O_GLOBAL if necessary */
  44.  
  45. /* file descriptor of TOSRUN */
  46. int trun_fd;
  47. extern long fd_mask;
  48.  
  49. /* is the "tools" window open? */
  50. int showtools = 1;
  51. int toolx, tooly;    /* location of tools window */
  52.  
  53. /* do we automatically close any windows that have exited? */
  54. int autoclose;
  55.  
  56. /* try to scroll nicely? */
  57. int smoothscroll;
  58.  
  59. /* 1 for "point to type", 0 for "click to type" */
  60. int point_to_type;
  61. WINDOW *toolwindow;
  62.  
  63. MENU *sysbar;        /* the system menu bar */
  64. MENU *globalmenu;
  65. MENU *windowmenu;
  66. MENU *filemenu, *editmenu;
  67. ENTRY *closeentry;
  68. ENTRY *copyentry, *pasteentry;
  69. MENU *gadgmenu;
  70.  
  71. int appl_menus = 1;    /* OK to load/show application menus */
  72. int sys_menu = 1;    /* set if the system menu is being displayed */
  73.  
  74. OBJECT *deskobj;
  75. OBJECT *cutdialog, *fontdial;
  76. OBJECT *menudef_dialog;
  77. OBJECT *winsize_dialog;
  78.  
  79. #define ALLGADGETS 0xfff    /* everything including the INFO line */
  80. #define MINGADGETS 0x01f    /* NAME, CLOSER, FULLER, MOVER, INFO */
  81. #define NOGADGETS  0x000
  82.  
  83. int default_kind = ALLGADGETS;
  84.  
  85. extern char progpath[128];
  86. static char fname[256];
  87. int altrow, altcol;
  88. int stdrow, stdcol;
  89. int altscroll, stdscroll;
  90.  
  91. char stdconfig[128] = "TOSWIN.CNF";
  92. char nullstr[2] = "";
  93.  
  94. int lineAset = 0;
  95. int lineArow, lineAcol;
  96.  
  97. #ifdef OLD_WAY
  98. /*
  99.  * signal handler for dead children
  100.  * all we do is collect (and discard :-( ) the exit code
  101.  * it's up to fd_input() and friends to figure out when no
  102.  * more data exists for a window
  103.  */
  104.  
  105. #define WNOHANG 1
  106.  
  107. void
  108. dead_kid()
  109. {
  110.     long r;
  111.  
  112.     r = Pwait3(WNOHANG, (void *)0);
  113.  
  114. }
  115.  
  116. #endif
  117.  
  118. /*
  119.  * signal handler for SIGINT and SIGQUIT: these get passed along to the
  120.  * process group in the focus window
  121.  */
  122.  
  123. void
  124. send_sig(sig)
  125.     long sig;
  126. {
  127.     TEXTWIN *t;
  128.  
  129.     if (focuswin && focuswin->wtype == TEXT_WIN) {
  130.         t = focuswin->extra;
  131.         if (t->pgrp) {
  132.             (void)Pkill(-t->pgrp, (short)sig);
  133.         }
  134.     }
  135. }
  136.  
  137. void
  138. ignore()
  139. {
  140. }
  141.  
  142. char argstr[128];
  143.  
  144. void
  145. newstdwin()
  146. {
  147.     TEXTWIN *t;
  148.  
  149.     if ((getprogname(fname) == OK) &&
  150.         (getargs(fname, argstr) == OK) ) {
  151.         t = newproc(fname, argstr, progpath, 0, 0, stdcol, stdrow, stdscroll,
  152.             default_kind, default_font, default_height);
  153.         if (t)
  154.             open_window(t->win);
  155.     }
  156. }
  157.  
  158. void
  159. newaltwin()
  160. {
  161.     TEXTWIN *t;
  162.  
  163.     if ((getprogname(fname) == OK) &&
  164.         (getargs(fname, argstr) == OK) ) {
  165.         t = newproc(fname, argstr, progpath, 0, 0, altcol, altrow, altscroll,
  166.             default_kind, default_font, default_height);
  167.         if (t)
  168.             open_window(t->win);
  169.     }
  170. }
  171.  
  172. void
  173. get_winsize(colptr, rowptr, sptr)
  174.     int *colptr, *rowptr, *sptr;
  175. {
  176.     int x, y, w, h, i;
  177.     TEDINFO *ted;
  178.     char *rowstr, *colstr, *scrstr;
  179.     int row, col, scroll;
  180.  
  181.     row = *rowptr;
  182.     col = *colptr;
  183.     scroll = *sptr;
  184.  
  185.     ted = (TEDINFO *)winsize_dialog[ROWBOX].ob_spec;
  186.     rowstr = (char *)ted->te_ptext;
  187.     strcpy(rowstr, valdec(row));
  188.     ted = (TEDINFO *)winsize_dialog[COLBOX].ob_spec;
  189.     colstr = (char *)ted->te_ptext;
  190.     strcpy(colstr, valdec(col));
  191.     ted = (TEDINFO *)winsize_dialog[SCRBOX].ob_spec;
  192.     scrstr = (char *)ted->te_ptext;
  193.     strcpy(scrstr, valdec(scroll));
  194.  
  195.     form_center(winsize_dialog, &x, &y, &w, &h);
  196.  
  197.     wind_update(1);
  198.     form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  199.     if (win_flourishes)
  200.         form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  201.  
  202.     objc_draw(winsize_dialog, 0, 2, x, y, w, h);
  203.  
  204.     i = form_do(winsize_dialog, COLBOX);
  205.  
  206.     if (win_flourishes)
  207.         form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  208.  
  209.     form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  210.     objc_change(winsize_dialog, i, 0, x, y, w, h, NORMAL, 0);
  211.     wind_update(0);
  212.     if (i != WINSIZOK) return;
  213.  
  214.     col = decval(colstr);
  215.     if (col < MINCOLS) col = MINCOLS; else if (col > MAXCOLS) col = MAXCOLS;
  216.     row = decval(rowstr);
  217.     if (row < MINROWS) row = MINROWS; else if (row > MAXROWS) row = MAXROWS;
  218.     scroll = decval(scrstr);
  219.     if (scroll < 0) scroll = 0;
  220.  
  221.     *colptr = col;
  222.     *rowptr = row;
  223.     *sptr = scroll;
  224. }
  225.  
  226. void
  227. set_altsiz()
  228. {
  229.     get_winsize(&altcol, &altrow, &altscroll);
  230. }
  231.  
  232. /*
  233.  * set the line A variables and stdcol and
  234.  * stdrow.
  235.  */
  236. void
  237. set_linea(ncol, nrow)
  238.     int ncol, nrow;
  239. {
  240.     lineAset = 1;
  241.     stdrow = nrow;
  242.     stdcol = ncol;
  243.     V_CEL_MX = stdcol - 1;
  244.     V_CEL_MY = stdrow - 1;
  245. }
  246.  
  247. void
  248. set_stdsiz()
  249. {
  250.     int ncol, nrow;
  251.  
  252.     ncol = stdcol;
  253.     nrow = stdrow;
  254.     get_winsize(&ncol, &nrow, &stdscroll);
  255.     set_linea(ncol, nrow);
  256. }
  257.  
  258. void
  259. set_winsiz()
  260. {
  261.     TEXTWIN *t;
  262.     int row, col, scroll;
  263.     struct winsize tw;
  264.  
  265.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  266.         t = gl_topwin->extra;
  267.         row = NROWS(t);
  268.         col = NCOLS(t);
  269.         scroll = SCROLLBACK(t);
  270.         get_winsize(&col, &row, &scroll);
  271.         if (col != NCOLS(t) || row != NROWS(t) ||
  272.             scroll != SCROLLBACK(t)) {
  273.             curs_off(t);
  274.             resize_textwin(t, col, row, scroll);
  275.             curs_on(t);
  276.             tw.ws_row = row;
  277.             tw.ws_col = col;
  278.             tw.ws_xpixel = tw.ws_ypixel = 0;
  279.             (void)Fcntl(t->fd, &tw, TIOCSWINSZ);
  280.             (void)Pkill(-t->pgrp, SIGWINCH);
  281.         }
  282.     }
  283. }
  284.  
  285. void
  286. set_wintitle()
  287. {
  288.     WINDOW *v;
  289.     OBJECT *titledial;
  290.     TEDINFO *ted;
  291.     char *titlestr;
  292.     int x, y, w, h, ret;
  293.  
  294.     v = gl_topwin;
  295.     if (v && v->wtype == TEXT_WIN) {
  296.         rsrc_gaddr(0, TITLDIAL, &titledial);
  297.         ted = (TEDINFO *)titledial[TITLSTR].ob_spec;
  298.         titlestr = (char *)ted->te_ptext;
  299.         strncpy(titlestr, v->wi_title, 32);
  300.  
  301.         form_center(titledial, &x, &y, &w, &h);
  302.         wind_update(1);
  303.         form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  304.         if (win_flourishes)
  305.             form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  306.         objc_draw(titledial, 0, 2, x, y, w, h);
  307.         ret = form_do(titledial, TITLSTR);
  308.         if (win_flourishes)
  309.             form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  310.         form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  311.  
  312.         objc_change(titledial, ret, 0, x, y, w, h, NORMAL, 0);
  313.         wind_update(0);
  314.         if (ret != TITLOK) return;
  315.         title_window(v, titlestr);
  316.     }
  317. }
  318.  
  319. /* shut down all windows */
  320. void
  321. shutdown()
  322. {
  323.     WINDOW *w;
  324.  
  325.     for (w = gl_winlist; w; w = w->next)
  326.         (*w->closed)(w);
  327. }
  328.  
  329. void
  330. quit()
  331. {
  332.     if (_app) {
  333.         gl_done = 1;
  334.         shutdown();
  335.     }
  336. }
  337.  
  338. void
  339. do_cut()
  340. {
  341.     extern void cut(), paste_to_desk();
  342.     extern char *cliptext;
  343.     int x, y;
  344.  
  345.     if (gl_topwin) {
  346.         cut(gl_topwin);
  347.         objc_offset(deskobj, CLIPICN, &x, &y);
  348.         if (cliptext)
  349.             paste_to_desk(x+1, y+1);
  350.     }
  351. }
  352.  
  353. void
  354. do_paste()
  355. {
  356.     extern char *read_scrap();
  357.     extern void paste();
  358.     extern char *cliptext;
  359.  
  360.     if (!gl_topwin) return;
  361.  
  362.     if (cliptext)
  363.         free(cliptext);
  364.  
  365.     cliptext = read_scrap("SCRAP.TXT");
  366.     if (!cliptext) {
  367.         form_alert(1, AlertStrng(SCRAPDAT));
  368.         return;
  369.     }
  370.     paste(gl_topwin);
  371. }
  372.  
  373. void
  374. set_wfont()
  375. {
  376.     int font, point;
  377.     int i;
  378.     TEXTWIN *t;
  379.  
  380.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  381.         t = gl_topwin->extra;
  382.         font = t->cfont;
  383.         point = t->cpoints;
  384.         i = get_font(&font, &point);
  385.         if (i == OK)
  386.             textwin_setfont(t, font, point);
  387.     }
  388. }
  389.  
  390. void
  391. set_dfont()
  392. {
  393.     int font, point;
  394.  
  395.     font = default_font;
  396.     point = default_height;
  397.  
  398.     if (get_font(&font, &point) == OK) {
  399.         default_font = font;
  400.         default_height = point;
  401.     }
  402. }
  403.  
  404. /*
  405.  * functions for setting window gadgets
  406.  * if "info_ok" is nonzero, we allow the
  407.  * user to select the INFO line, otherwise
  408.  * not. "kindptr" points to the current
  409.  * settings on input, and is set to the
  410.  * new settings on output.
  411.  */
  412.  
  413. void
  414. get_gadgets(kindptr, info_ok)
  415.     int *kindptr;
  416.     int info_ok;
  417. {
  418.     OBJECT *gadgdial;
  419.     int kind = *kindptr;
  420.     int ret;
  421.     int x, y, w, h;
  422.     int doubleclick = 0;
  423.  
  424.     rsrc_gaddr(0, GADGDIAL, &gadgdial);
  425.     form_center(gadgdial, &x, &y, &w, &h);
  426.  
  427. /* make info_ok a mask */
  428.     if (info_ok)
  429.         info_ok = ~0;
  430.     else
  431.         info_ok = ~INFO;
  432.  
  433.     wind_update(1);
  434.  
  435.     form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  436.     if (win_flourishes)
  437.         form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  438.  
  439. redisplay:
  440.     gadgdial[GCLOSER].ob_state = (kind & CLOSER) ? SELECTED : NORMAL;
  441.     gadgdial[GTITLE].ob_state = (kind & MOVER) ? SELECTED : NORMAL;
  442.     if (info_ok & INFO) {
  443.         gadgdial[GMENU].ob_state = (kind & INFO) ? SELECTED : NORMAL;
  444.     } else {
  445.         gadgdial[GMENU].ob_state = DISABLED;
  446.     }
  447.     gadgdial[GFULLER].ob_state = (kind & FULLER) ? SELECTED : NORMAL;
  448.     gadgdial[GVSLIDE].ob_state = (kind & VSLIDE) ? SELECTED : NORMAL;
  449.     gadgdial[GHSLIDE].ob_state = (kind & HSLIDE) ? SELECTED : NORMAL;
  450.     gadgdial[GSIZER].ob_state = (kind & SIZER) ? SELECTED : NORMAL;
  451.     objc_draw(gadgdial, 0, 2, x, y, w, h);
  452.     ret = form_do(gadgdial, 0);
  453.     if (ret & 0x8000) {
  454.         doubleclick = 1;
  455.         ret &= 0x7fff;
  456.     }
  457.     if (ret == GALLGAD) {
  458.         kind = ALLGADGETS & info_ok; if (!doubleclick) goto redisplay;
  459.     } else if (ret == GTOPGAD) {
  460.         kind = MINGADGETS & info_ok; if (!doubleclick) goto redisplay;
  461.     } else if (ret == GNOGAD) {
  462.         kind = NOGADGETS; if (!doubleclick) goto redisplay;
  463.     } else if (ret == GADGOK) {
  464.         kind = 0;
  465.         if (gadgdial[GCLOSER].ob_state == SELECTED)
  466.             kind |= CLOSER;
  467.         if (gadgdial[GFULLER].ob_state == SELECTED)
  468.             kind |= FULLER;
  469.         if (gadgdial[GSIZER].ob_state == SELECTED)
  470.             kind |= SIZER;
  471.         if (gadgdial[GTITLE].ob_state == SELECTED)
  472.             kind |= (NAME|MOVER);
  473.         if (gadgdial[GMENU].ob_state == SELECTED)
  474.             kind |= INFO;
  475.         if (gadgdial[GVSLIDE].ob_state == SELECTED)
  476.             kind |= (UPARROW|DNARROW|VSLIDE);
  477.         if (gadgdial[GHSLIDE].ob_state == SELECTED)
  478.             kind |= (LFARROW|RTARROW|HSLIDE);
  479.     } else if (ret == GADGCAN) {
  480.         kind = *kindptr;
  481.     }
  482.  
  483.     if (win_flourishes)
  484.         form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  485.     form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  486.     wind_update(0);
  487.  
  488.     gadgdial[ret].ob_state = NORMAL;
  489.  
  490.     *kindptr = kind;
  491. }
  492.  
  493. void
  494. set_wkind()
  495. {
  496.     int kind;
  497.  
  498.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  499.         kind = gl_topwin->wi_kind;
  500.         get_gadgets(&kind, gl_topwin->menu ? 1 : 0);
  501.         change_window_gadgets(gl_topwin, kind);
  502.     }
  503. }
  504.  
  505. void
  506. set_dkind()
  507. {
  508.     get_gadgets(&default_kind, 1);
  509. }
  510.  
  511. /*
  512.  * function that toggles an (integer) on/off switch in the global menu
  513.  */
  514.  
  515. void
  516. toggle(var)
  517.     int *var;
  518. {
  519.     ENTRY *e;
  520.     MENU *m = globalmenu;
  521.     WINDOW *v;
  522.     int x, y, w, h;
  523.  
  524.     *var = !*var;
  525.     for (e = m->contents; e; e = e->next) {
  526.         if (e->arg == var)
  527.             break;
  528.     }
  529.  
  530.     if (e) {
  531.         if (*var) {
  532.             check_entry(m, e);
  533.         } else {
  534.             uncheck_entry(m, e);
  535.         }
  536.     }
  537.  
  538.     if (var == &align_windows && *var) {
  539.         for(v = gl_winlist; v; v = v->next) {
  540.             if (v->wtype == TEXT_WIN && v->wi_handle >= 0) {
  541.                 wind_get(v->wi_handle, WF_CURRXYWH, &x,
  542.                     &y, &w, &h);
  543.                 (*v->moved)(v, x, y, w, h);
  544.             }
  545.         }
  546.     }
  547. }
  548.  
  549. /* bury the topmost window */
  550.  
  551. void
  552. bury()
  553. {
  554.     new_topwin(0);
  555. }
  556.  
  557. /* redraw the whole screen */
  558.  
  559. void
  560. doredraw()
  561. {
  562.     sys_menu = 1;
  563. #ifdef GLOBAL_APPL_MENUS
  564.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  565.         if (gl_topwin->menu && appl_menus) {
  566.             sys_menu = 0;
  567.             show_menu(gl_topwin->menu);
  568.         }
  569.     }
  570. #endif
  571.     if (sys_menu)
  572.         show_menu(sysbar);
  573.  
  574.     redraw_screen(xdesk, ydesk, wdesk, hdesk);
  575. }
  576.  
  577. void
  578. dieloop()
  579. {
  580.     int msgbuff[8];
  581.  
  582.     for(;;) {
  583.         (void)evnt_mesag(msgbuff);
  584.     }
  585. }
  586.  
  587. static void (*oldttop)();
  588.  
  589. static void
  590. tooltop(v)
  591.     WINDOW *v;
  592. {
  593.     extern void top_menu();
  594.  
  595.     top_menu(v, oldttop);
  596. }
  597.  
  598. void
  599. toolclose(v)
  600.     WINDOW *v;
  601. {
  602.     if (!_app)
  603.         ac_close();
  604.     else {
  605.         showtools = 0;
  606.         close_window(v);
  607.     }
  608. }
  609.  
  610. void
  611. toolopen()
  612. {
  613.     if (showtools) {
  614.         (*toolwindow->topped)(toolwindow);
  615.     } else {
  616.         showtools = 1;
  617.         open_window(toolwindow);
  618.     }
  619. }
  620.  
  621. char *Strng(index)
  622.     int index;
  623. {
  624.     char *addr;
  625.  
  626.     addr = 0;
  627.     rsrc_gaddr(5, index, &addr);
  628.     return addr;
  629. }
  630.  
  631. int __mint;
  632.  
  633. /*
  634.  * get MiNT version number
  635.  */
  636.  
  637. static void
  638. getMiNT()
  639. {
  640.     long *cookie;
  641.  
  642. /* get the system time in 200HZ ticks from the BIOS _hz_200 variable */
  643.  
  644.     cookie = *((long **) 0x5a0L);
  645.     if (!cookie)
  646.         __mint = 0;
  647.     else {
  648.         while (*cookie) {
  649.             if (*cookie == 0x4d694e54L) {    /* MiNT */
  650.                 __mint = (int) cookie[1];
  651.                 return;
  652.             }
  653.             cookie += 2;
  654.         }
  655.     }
  656.     __mint = 0;
  657. }
  658.  
  659. int
  660. main()
  661. {
  662.     extern short _global[];        /* AES global array */
  663.     int i;
  664.  
  665.     (void)Supexec(getMiNT);
  666.     init_gem();
  667.     if (_global[1] == -1) {        /* multitasking AES? */
  668.         MultiTOS = 1;
  669.     } else {
  670.         if (_app)
  671.             (void)Cursconf(0, 0);    /* hide cursor */
  672.         else {
  673.             oldACC = 1;
  674.             global_flag = 0x1000;
  675.             termfunc = (long)Setexc(0x102, -1L);
  676.             heapbase = (void *)Malloc(heapsize);
  677.             if (__mint == 0 ||
  678.                (heapbase = (void *)Malloc(heapsize)) == 0)
  679.             {
  680.                 close_vwork();
  681.                 while(1) evnt_loop();
  682.             }
  683.         }
  684.     }
  685.  
  686.     linea0();
  687.     toolx = xdesk;
  688.     tooly = ydesk;
  689.     graf_mouse(BEE, 0L);
  690.     i = rsrc_load("TOSWIN.RSC");
  691.     if (i == 0) {
  692.         form_alert(1, "[3][TOSWIN.RSC not found][Cancel]");
  693.         if (oldACC)
  694.             dieloop();
  695.         else {
  696.             exit_gem(1);
  697.         }
  698.     }
  699.     graf_mouse(ARROW, 0L);
  700.  
  701.     if (
  702.         rsrc_gaddr(0, DESKTOP, &deskobj) == 0 ||
  703.         rsrc_gaddr(0, MENUDEF, &menudef_dialog) == 0 ||
  704.         rsrc_gaddr(0, WINSIZE, &winsize_dialog) == 0 ||
  705.         rsrc_gaddr(0, FNTDIAL, &fontdial) == 0 ||
  706.         rsrc_gaddr(0, CUTOPTS, &cutdialog) == 0) {
  707.         form_alert(1, "[3][TOSWIN.RSC corrupted??][Cancel]");
  708.         if (oldACC)
  709.             dieloop();
  710.         else
  711.             exit_gem(1);
  712.     }
  713.  
  714.     if (MultiTOS || oldACC) {
  715.         menu_register(gl_apid, Strng(TOSPROGS));
  716.     }
  717.     init_fontdesc();
  718.     gl_timer = MultiTOS ? LONGWAIT : NOMULTIWAIT;
  719.     fn_timeout = oldACC ? acc_input : fd_input;
  720.     fn_message = iconify_message;
  721.     fn_mouse = desk_mouse;
  722.  
  723.     about_string = Strng(ABOUTTW);
  724.     about_func = toolopen;
  725.  
  726.     sysbar = filemenu = create_menu(Strng(SFILE));
  727.     (void)add_entry(filemenu, Strng(SOPNSTD), newstdwin, NULL, 0, NORMAL);
  728.     (void)add_entry(filemenu, Strng(SOPNALT), newaltwin, NULL, 0, NORMAL);
  729.     closeentry = add_entry(filemenu, Strng(SCLOSE), g_close, NULL,
  730.              0, DISABLED);
  731.     (void)add_entry(filemenu, "---", about_func, NULL, 0, DISABLED);
  732.     (void)add_entry(filemenu, Strng(SLOADCFG), load_config, NULL, 0, NORMAL);
  733.     (void)add_entry(filemenu, Strng(SSAVECFG), save_config, NULL, 0, NORMAL);
  734.     (void)add_entry(filemenu, "---", about_func, NULL, 0, DISABLED);
  735.     (void)add_entry(filemenu, Strng(SSETMENU), config_menu, sysbar,
  736.              0, NORMAL);
  737.     (void)add_entry(filemenu, "---", quit, NULL, 0, DISABLED);
  738.     (void)add_entry(filemenu, Strng(SQUIT), quit, NULL, 0, oldACC ? DISABLED : NORMAL);
  739.  
  740.     editmenu = create_menu(Strng(SEDIT));
  741.     copyentry = add_entry(editmenu, Strng(SCOPY), do_cut, NULL, 0, NORMAL);
  742.     pasteentry = add_entry(editmenu, Strng(SPASTE), do_paste, NULL, 0, NORMAL);
  743.     (void)add_entry(editmenu, "---", about_func, NULL, 0, DISABLED);
  744.     (void)add_entry(editmenu, Strng(SPASTEOP), setcutoptions, NULL, 0, NORMAL);
  745.     filemenu->next = editmenu;
  746.  
  747.     globalmenu = create_menu(Strng(SGLOBAL));
  748.     (void)add_entry(globalmenu, Strng(SALIGNW), toggle, &align_windows,
  749.              0, NORMAL);
  750. #ifdef GLOBAL_APPL_MENUS
  751.     (void)add_entry(globalmenu, Strng(SAPPMENU), togglemenu, &appl_menus,
  752.              0, CHECKED);
  753. #else
  754.     (void)add_entry(globalmenu, Strng(SAPPMENU), toggle, &appl_menus,
  755.              0, CHECKED);
  756. #endif
  757.     (void)add_entry(globalmenu, Strng(SAUTOCL), toggle, &autoclose, 0, NORMAL);
  758.     (void)add_entry(globalmenu, Strng(SFLOURIS), toggle, &win_flourishes,
  759.              0, CHECKED);
  760.     (void)add_entry(globalmenu, Strng(SPTTYPE), toggle, &point_to_type,
  761.              0, NORMAL);
  762.     (void)add_entry(globalmenu, Strng(SSMOOTH), toggle, &smoothscroll,
  763.              0, NORMAL);
  764.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  765.     (void)add_entry(globalmenu, Strng(SSETSTD), set_stdsiz, NULL,
  766.              0, NORMAL);
  767.     (void)add_entry(globalmenu, Strng(SSETALT), set_altsiz, NULL,
  768.              0, NORMAL);
  769.     (void)add_entry(globalmenu, Strng(SSETDFNT), set_dfont, NULL,
  770.              0, NORMAL);
  771.     (void)add_entry(globalmenu, Strng(SSETDGAD), set_dkind, NULL,
  772.              0, NORMAL);
  773.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  774.     (void)add_entry(globalmenu, Strng(SENVIRON), setenvoptions, NULL,
  775.              0, NORMAL);
  776.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  777.     (void)add_entry(globalmenu, Strng(SREDRAW), doredraw, NULL,
  778.              0, NORMAL);
  779.     editmenu->next = globalmenu;
  780.  
  781.     windowmenu = create_menu(Strng(SWINDOW));
  782.     (void)add_entry(windowmenu, Strng(SBURY), bury, NULL, 0, DISABLED);
  783.     (void)add_entry(windowmenu, Strng(SICONIFY), iconify_topwin,
  784.              NULL, 0, DISABLED);
  785.     (void)add_entry(windowmenu, "---", about_func, NULL, 0, DISABLED);
  786.     (void)add_entry(windowmenu, Strng(SLITERAL), send_char,
  787.             NULL, 0, DISABLED);
  788.     (void)add_entry(windowmenu, "---", about_func, NULL, 0, DISABLED);
  789.     (void)add_entry(windowmenu, Strng(SSETWSIZ), set_winsiz, NULL,
  790.              0, DISABLED);
  791.     (void)add_entry(windowmenu, Strng(SSETWFNT), set_wfont, NULL,
  792.              0, DISABLED);
  793.     (void)add_entry(windowmenu, Strng(SSETWGAD), set_wkind, NULL,
  794.              0, DISABLED);
  795.     (void)add_entry(windowmenu, Strng(SSETWTIT), set_wintitle, NULL,
  796.              0, DISABLED);
  797.     globalmenu->next = windowmenu;
  798.  
  799.     gadgmenu = create_menu(Strng(SGADGETS));
  800.     (void)add_entry(gadgmenu, Strng(STOGFULL), g_full, NULL, 0, DISABLED);
  801.     (void)add_entry(gadgmenu, Strng(SMOVE), g_move, NULL, 0, DISABLED);
  802.     (void)add_entry(gadgmenu, Strng(SSCRUP), g_scroll, (void *)(long)WA_UPLINE,
  803.             0, DISABLED);
  804.     (void)add_entry(gadgmenu, Strng(SSCRDOWN), g_scroll, (void *)(long)WA_DNLINE,
  805.             0, DISABLED);
  806.     (void)add_entry(gadgmenu, Strng(SSCRLEFT), g_scroll, (void *)(long)WA_LFLINE,
  807.             0, DISABLED);
  808.     (void)add_entry(gadgmenu, Strng(SSCRRIGH), g_scroll, (void *)(long)WA_RTLINE,
  809.             0, DISABLED);
  810.     windowmenu->next = gadgmenu;
  811.  
  812.     if (!oldACC) {
  813. #ifdef OLD_WAY
  814.         (void)Psignal(SIGCHLD, dead_kid);
  815. #endif
  816.         (void)Psignal(SIGINT, send_sig);
  817.         (void)Psignal(SIGQUIT, send_sig);
  818.         (void)Psignal(SIGHUP, send_sig);
  819.         (void)Psignal(SIGTSTP, send_sig);
  820.         (void)Psignal(SIGTTIN, ignore);
  821.         (void)Psignal(SIGTTOU, ignore);
  822.     }
  823.  
  824. /* open up the TOSRUN pipe, so that the desktop can tell us to run stuff */
  825.     trun_fd = Fcreate("U:\\PIPE\\TOSRUN", global_flag);
  826.     if (trun_fd <= 0)
  827.         trun_fd = 0;
  828.     else {
  829.         if (!oldACC)
  830.             fd_mask |= (1L << trun_fd);
  831.         (void)Fcntl(trun_fd, (long)O_NDELAY, F_SETFL);
  832.     }
  833.  
  834. /* set up window sizes */
  835. /* the standard size always matches the line A size; the alt size is
  836.  * settable by the user
  837.  */
  838.  
  839.     stdrow = lineArow = V_CEL_MY+1; stdcol = lineAcol = V_CEL_MX+1;
  840.     altrow = (stdrow == 50) ? 25 : 50; altcol = 80;
  841.  
  842.     vsf_perimeter(vdi_handle, 0);    /* no bars around perimeter */
  843.  
  844.     show_menu(sysbar);    /* show_menu checks _app */
  845.  
  846. /* try to load a standard config file */
  847.     i = shel_find(stdconfig);
  848.     if (i != 0) {
  849.         load_config(stdconfig);
  850.     }
  851.  
  852.     if (!_app)
  853.         showtools = 1;
  854.  
  855.     i = CLOSER|MOVER|NAME;
  856.     if (!_app) i |= INFO;
  857.  
  858.     toolwindow = create_objwin(deskobj, "TOSWIN", i,
  859.              toolx, tooly, deskobj[0].ob_width, deskobj[0].ob_height);
  860.     if (!_app) {
  861.         toolwindow->menu = filemenu;
  862.         toolwindow->infostr = strdup(menustr(filemenu));
  863.     }
  864.     oldttop = toolwindow->topped;
  865.     toolwindow->topped = tooltop;
  866.     toolwindow->closed = toolclose;
  867.  
  868.     if (_app && showtools)
  869.         open_window(toolwindow);
  870.  
  871.     if (oldACC)
  872.         close_vwork();
  873.  
  874.     evnt_loop();
  875.  
  876.     if (lineAset) {
  877.         V_CEL_MX = lineAcol - 1;
  878.         V_CEL_MY = lineArow - 1;
  879.     }
  880.     exit_gem(0);
  881.     return 0;
  882. }
  883.  
  884. /*
  885.  * functions for when we are accessories
  886.  */
  887.  
  888. int opened = 0;
  889.  
  890. void
  891. ac_open()
  892. {
  893.     WINDOW *w;
  894.  
  895.     if (!opened) {
  896.         open_vwork();
  897.         vsf_perimeter(vdi_handle, 0);
  898.         for (w = gl_winlist; w; w = w->next) {
  899.             if (open_window(w))
  900.                 opened = 1;
  901.         }
  902.         if (opened) return;
  903.         if (gl_winlist) {    /* bad error */
  904.             form_alert(1, AlertStrng(NOOPEN));
  905.             close_vwork();
  906.             return;
  907.         }
  908.     }
  909.     toolopen();
  910.     if (!gl_winlist) {
  911.         close_vwork();
  912.         opened = 0;
  913.     }
  914.     if (lineAset) {
  915.         set_linea(stdcol, stdrow);
  916.     }
  917. }
  918.  
  919. void
  920. ac_close()
  921. {
  922.     WINDOW *w;
  923.  
  924.     if (!opened) return;
  925.  
  926.     for (w = gl_winlist; w; w = w->next)
  927.         close_window(w);
  928.     close_vwork();
  929.     opened = 0;
  930.     if (lineAset) {
  931.         V_CEL_MX = lineAcol - 1;
  932.         V_CEL_MY = lineArow - 1;
  933.     }
  934. }
  935.  
  936. /* called when we get an AC_CLOSE message; this tells us that our
  937.  * windows have been forcibly deleted on us
  938.  */
  939.  
  940. void
  941. force_ac_close()
  942. {
  943.     WINDOW *w;
  944.  
  945.     if (opened) {
  946.         for (w = gl_winlist; w; w = w->next) {
  947.             w->wi_handle = -1;
  948.         }
  949.         close_vwork();
  950.         opened = 0;
  951.     }
  952. }
  953.  
  954.  
  955. /*
  956.  * special sbrk() stuff; note that this requires the MiNT
  957.  * library
  958.  */
  959.  
  960. void *
  961. _sbrk(sz)
  962.     long sz;
  963. {
  964.     void *foo;
  965.  
  966.     sz = (sz + 7) & ~((unsigned long)7L);
  967.  
  968.     if (heapbase) {
  969.         if (sz >= heapsize) return 0;
  970.         foo = heapbase;
  971.         heapbase = (void *)((char *)heapbase + sz);
  972.         heapsize -= sz;
  973.     } else {
  974.         foo = (void *)Malloc(sz);
  975.     }
  976.     return foo;
  977. }
  978.  
  979. void *
  980. sbrk(sz)
  981.     size_t sz;
  982. {
  983.     return _sbrk((long)sz);
  984. }
  985.