home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff330.lzh / Vt100 / Src.lzh / Src / init.c < prev    next >
C/C++ Source or Header  |  1990-03-01  |  26KB  |  877 lines

  1. static char rcsid[] = "$RCSfile: init.c,v $ $Revision: 1.4 $";
  2.  
  3. /***************************************************************
  4.  * vt100 - terminal emulator - initialization
  5.  *                :ts=8
  6.  *
  7.  * $Log:    init.c,v $
  8.  * Revision 1.4  89/12/12  22:13:56  acs
  9.  * 1) Strip excess blanks from the rest of the menu items.
  10.  * 2) No checkmark on "---" parity item (ParItem[5]).
  11.  * 
  12.  * Revision 1.3  89/12/11  20:48:16  acs
  13.  * 1) Remove extraneous spaces at end of menu items.
  14.  * 2) Increase width of checked menu items by CHECKWIDTH instead of by
  15.  *    the width of 2 characters.
  16.  * 3) Don't highlight the "---" separating the new Strip item from the
  17.  *    other items in the Parity menu.
  18.  * 4) A little better initialization of the Utility items.
  19.  * 
  20.  * Revision 1.2  89/11/06  21:25:22  acs
  21.  * 1) Add new Parity menu item: Strip to remove parity from data destined
  22.  *    for the display.
  23.  * 2) Add RCS id and change log.
  24.  * 
  25.  *    v2.9 ACS - Support new cmds EXT.  Use S and R for Send and Receive menu
  26.  *           items instead of ^ and V.  AREXX support.
  27.  *    v2.8a 880331 ACS - Allow lines 0 in init file to *really* mean
  28.  *              "use all available lines".
  29.  *    v2.7 870825 ACS - Allow execution of all script files specified on
  30.  *              command line (companion to changes in script.c).
  31.  *              Rolled menu init into one routine (do_menu_init()).
  32.  *    v2.6 870227 DBW - bug fixes for all the stuff in v2.5
  33.  *    v2.5 870214 DBW - more additions (see readme file)
  34.  *    v2.4 861214 DBW - lots of fixes/additions (see readme file)
  35.  *    v2.3 861101 DBW - minor bug fixes
  36.  *    v2.2 861012 DBW - more of the same
  37.  *    v2.1 860915 DBW - new features (see README)
  38.  *         860901 ACS - Added Parity and Word Length and support code
  39.  *         860823 DBW - Integrated and rewrote lots of code
  40.  *    v2.0 860809 DBW - Major rewrite
  41.  *    v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
  42.  *    v1.0 860712 DBW - First version released
  43.  *
  44.  ***************************************************************/
  45.  
  46. #include "vt100.h"
  47.  
  48. struct Device *ConsoleDevice = NULL;
  49. struct IOStdReq ConReq;
  50. extern APTR OrigWindowPtr;
  51. extern int capture;        /* in vt100.c */
  52.  
  53. /*   Used by script.c for script file chaining. */
  54. int script_files_todo = 0;
  55. char **script_files = NULL;
  56.  
  57. char line[256];
  58.  
  59. /* Command key equivalences per menu.  Manipulated by script.c */
  60.  
  61. /*   Equivalences for the File menu... */
  62. struct filecmd {
  63.     char mo;    /* Mode            */
  64.     char se;    /* Send            */
  65.     char re;    /* Receive        */
  66.     char kg;    /* Kermit Get        */
  67.     char kb;    /* Kermit Bye        */
  68.     char ca;    /* Capture or Capturing */
  69.     char nl;
  70. } filecmd_chars = { ' ', 'S', 'R', 'G', 'B', ' ', '\0' };
  71.  
  72. /*   Equivalences for Mode sub-menu... */
  73. struct mode_cmd {
  74.     char as;    /* ascii mode        */
  75.     char xm;    /* xmodem mode        */
  76.     char xmc;    /* xmodemcrc mode    */
  77.     char ke;    /* kermit mode        */
  78.     char nl;
  79. } modecmd_chars = { ' ', 'X', ' ', 'K', '\0' };
  80.  
  81. /*   Equivalences for the Comm menu... */
  82. struct commcmd {
  83.     char nl0;    /* Baud Sub-Item    */
  84.     char nl1;    /* Parity Sub-Item    */
  85.     char nl2;    /* Xfer mode Sub-Item    */
  86.     char sh;    /* Shared item        */
  87.     char nl;
  88. } commcmd_chars = { ' ', ' ', ' ', ' ', '\0' };
  89.  
  90. /*   Equivalences for the Baud Rate sub-menu... */
  91. struct baudcmd {
  92.     char b03;    /* 0300            */
  93.     char b12;    /* 1200            */
  94.     char b24;    /* 2400            */
  95.     char b48;    /* 4800            */
  96.     char b96;    /* 9600            */
  97.     char bnl;
  98. } baudcmd_chars = { ' ', 'L', 'H', ' ', ' ', '\0' };
  99.  
  100. /*   Equivalences for the Parity sub-menu... */
  101. struct parcmd {
  102.     char no;    /* NOne            */
  103.     char ma;    /* MArk            */
  104.     char sp;    /* SPace        */
  105.     char ev;    /* EVen            */
  106.     char od;    /* ODd            */
  107.     char n0;    /* ---                  */
  108.     char st;    /* STrip        */
  109.     char n1;
  110. } parcmd_chars = { 'N', ' ', ' ', 'E', 'O', ' ', ' ', '\0' };
  111.  
  112. /*   Equivalences for the Xfer Mode sub-menu... */
  113. struct modcmd {
  114.     char im;    /* IMage        */
  115.     char tx;    /* TeXt            */
  116.     char cn;    /* CoNvert        */
  117.     char ac;    /* AutoChop        */
  118.     char nl;
  119. } modcmd_chars = { 'I', 'T', ' ', ' ', '\0' };
  120.  
  121. /*   Equivalences for the Script menu... */
  122. struct scrcmd {
  123.     char em;    /* Execute Macro    */
  124.     char ab;    /* Abort Macro        */
  125.     char rc;    /* AREXX Macro        */
  126.     char nl;
  127. } scrcmd_chars = { 'M', 'A', ' ', '\0' };
  128.  
  129. /*   Equivalences for the Utility menu... */
  130. struct utilcmd {
  131.     char sb;    /* Send Break    */
  132.     char hu;    /* Hang Up    */
  133.     char cd;    /* Change Dir    */
  134.     char cs;    /* Clear Screen    */
  135.     char ec;    /* ECho        */
  136.     char wr;    /* WRap        */
  137.     char nk;    /* Num Key    */
  138.     char ac;    /* App Cur    */
  139.     char bs;    /* BS<->DEL    */
  140.     char xb;    /* Xfer beep    */
  141.     char mu;    /* Mouse up events    */
  142.     char md;    /* Mouse down events    */
  143.     char nl;
  144. } utilcmd_chars = { '.', ' ', 'D', ' ', ' ', 'W', 'K', 'C', ' ', ' ', ' ', ' ', '\0' };
  145.  
  146. static char *filetext[] = {
  147.     "Protocol",
  148.     "Send",
  149.     "Receive",
  150.     "Kermit Get",
  151.     "Kermit BYE",
  152.     "Capture"
  153. };
  154.  
  155. static char *modetext[] = {
  156.     "Ascii",
  157.     "Xmodem",
  158.     "XmodemCRC",
  159.     "Kermit"
  160. };
  161.  
  162. static char *commtext[] = {
  163.     "Baud Rate",
  164.     "Parity",
  165.     "Xfer Mode",
  166.     "Shared",
  167. };
  168.  
  169. static char *baudtext[] = {
  170.     " 300",
  171.     "1200",
  172.     "2400",
  173.     "4800",
  174.     "9600"
  175. };
  176.  
  177. static char *partext[] = {
  178.     "None",
  179.     "Mark",
  180.     "Space",
  181.     "Even",
  182.     "Odd",
  183.     "-------",
  184.     "Strip"
  185. };
  186.  
  187. static char *modtext[] = {
  188.     "Image",
  189.     "Text",
  190.     "Convert",
  191.     "AutoChop"
  192. };
  193.  
  194. static char *scrtext[] = {
  195.     "Execute Macro",
  196.     "Abort Execution",
  197.     "AREXX Macro"
  198. };
  199.  
  200. static char *utiltext[] = {
  201.     "Send Break",
  202.     "Hang Up",
  203.     "Change Dir",
  204.     "Clear Scrn",
  205.     "Echo",
  206.     "Wrap",
  207.     "Num Key",
  208.     "App Cur",
  209.     "BS<->DEL",
  210.     "Xfer Beep ",
  211.     "Mouse Up",
  212.     "Mouse Dn",
  213. };
  214.  
  215. struct HowToInit {
  216.     int LeftEdge;    /* in characters, NOT pixels    */
  217.     int Width;        /*     ditto            */
  218.     ULONG Flags;
  219.     char **text;
  220.     char *cmdkeys;
  221. };
  222.  
  223. static struct HowToInit menu_init[] = {
  224.     { 0, 20, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  225.          filetext, (char *)(&filecmd_chars) },
  226.     {10, 17, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | MENUTOGGLE,
  227.          modetext, (char *)(&modecmd_chars) },
  228.     { 0, 11, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  229.          commtext, (char *)(&commcmd_chars) },
  230.     { 10, 12, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | MENUTOGGLE,
  231.            baudtext, (char *)(&baudcmd_chars) },
  232.     { 10, 12, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | MENUTOGGLE,
  233.           partext, (char *)(&parcmd_chars) },
  234.     { 10, 15, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | MENUTOGGLE,
  235.           modtext, (char *)(&modcmd_chars) },
  236.     { 0, 20, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  237.          scrtext, (char *)(&scrcmd_chars) },
  238.     { 0, 16, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT | MENUTOGGLE,
  239.          utiltext, (char *)(&utilcmd_chars) }
  240. };
  241.  
  242. #define FILE_INIT_ENTRY    (&(menu_init[0]))
  243. #define MODE_INIT_ENTRY (&(menu_init[1]))
  244. #define COMM_INIT_ENTRY    (&(menu_init[2]))
  245. #define RS_INIT_ENTRY    (&(menu_init[3]))
  246. #define PAR_INIT_ENTRY    (&(menu_init[4]))
  247. #define XF_INIT_ENTRY    (&(menu_init[5]))
  248. #define SCRIPT_INIT_ENTRY    (&(menu_init[6]))
  249. #define UTIL_INIT_ENTRY    (&(menu_init[7]))
  250.  
  251. void do_menu_init();
  252.  
  253. #if AREXX
  254. char *rexxerrmsgs[] = {
  255.     "",
  256.     "No AREXX library - AREXX unavailable.",
  257.     "Can't contact AREXX server - AREXX unavailable.",
  258.     "Can't create an AREXX msg - AREXX unavailable.",
  259.     "Can't get memory for hostname.",
  260.     "VT100 AREXX port already present - another VT100 up?",
  261.     "Can't get memory for AREXX port."
  262. };
  263. #endif /* AREXX */
  264.  
  265. char *InitDefaults(argc,argv)
  266. int    argc;
  267. char    **argv;
  268.     {
  269.     FILE    *fd = NULL;
  270.     char    *p = NULL, *ifile, temp[80];
  271.     int     i, l, dont_init = 0, customfudge, maxrows, maxlines;
  272.  
  273.     for(l = 0; l < EXTMAX; l++)
  274.     ExtXfer[l] = NULL;
  275.  
  276.     doing_init = 1;    /* make sure we only allow INIT script commands */
  277.     if (argc > 1) {
  278.     int start_of_script_files = 1;
  279.  
  280.     if(strcmp(argv[1], "-i") == 0) {    /* No init file */
  281.         dont_init = 1;
  282.         start_of_script_files = 2;
  283.     }
  284.     else if(strcmp(argv[1], "+i") == 0) {    /* Use specified init file */
  285.         start_of_script_files = 3;
  286.             if((fd=fopen(argv[2],"r")) == NULL) {
  287.         ifile = AllocMem((LONG)(strlen(argv[2])+3), MEMF_PUBLIC|MEMF_CLEAR);
  288.         strcpy(ifile, "S:");
  289.         strcat(ifile, argv[2]);
  290.         fd = fopen(ifile, "r");
  291.         FreeMem(ifile, (LONG)(strlen(argv[2])+3));
  292.         ifile = NULL;
  293.         }
  294.     }
  295.     if(start_of_script_files > argc)
  296.         script_files_todo = 0;
  297.     else
  298.         script_files_todo = argc - start_of_script_files; /* # of cmdline script files left */
  299.     script_files = &(argv[start_of_script_files]);      /* Ptr to first of 'em */
  300.     }
  301.  
  302.     if((p_font == NULL) || (p_font[0] == '\0'))
  303.     strcpy(myfontname, "topaz");
  304.     else
  305.     strcpy(myfontname, p_font);    /* Init font name */
  306.     strcat(myfontname, ".font");
  307.  
  308.     if((p_device == NULL) || (p_device[0] == '\0'))
  309.     strcpy(mysername, SERIALNAME);
  310.     else
  311.     strcpy(mysername, p_device);
  312.  
  313. #if AREXX
  314.     /*   Setup the AREXX interface now so user can use it during init. */
  315.     if( (RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME, 0L))
  316.        == NULL)
  317.     puts("Can't open rexxsyslib.library - AREXX unavailable.");
  318.     else if( (i = makerexxport()) != 0)
  319.     cleanup(rexxerrmsgs[i], 256);
  320. #endif /* AREXX */
  321.  
  322.     if(!dont_init)
  323.     if((fd == NULL) && ((fd=fopen("vt100.init","r")) == NULL))
  324.         fd=fopen("s:vt100.init","r");
  325.  
  326.     if(fd != NULL) {
  327.     while (fgets(line,256,fd) != 0) {
  328.         if(line[strlen(line)-1] == '\n')
  329.         line[strlen(line)-1] = '\000';
  330.         p = next_wrd(&line[0],&l);
  331.         if (*p) {
  332.         *p |= ' ';
  333.         if (p[1]) p[1] |= ' ';
  334.         if (*p == '#') continue;
  335.         if (strncmp(p, "exi", 3) == 0) break;
  336.         exe_cmd(p,l);
  337.         }
  338.     }
  339.     fclose(fd);
  340.     }
  341.     doing_init = 0;
  342.  
  343.     IntuitionBase = (struct IntuitionBase *)
  344.     OpenLibrary("intuition.library", INTUITION_REV);
  345.     if( IntuitionBase == NULL )
  346.     cleanup("can't open intuition",1);
  347.  
  348.     GfxBase = (struct GfxBase *)
  349.     OpenLibrary("graphics.library",GRAPHICS_REV);
  350.     if( GfxBase == NULL )
  351.     cleanup("can't open graphics library",2);
  352.  
  353.     DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", 0L);
  354.     if(DiskfontBase == NULL)
  355.     cleanup("can't open diskfont library", 2);
  356.  
  357.     if ( (myfont = (struct TextFont *)OpenFont(&myattr)) == NULL
  358.       && (myfont = (struct TextFont *)OpenDiskFont(&myattr)) == NULL) {
  359.     sprintf(temp, "Can't open font %s", myfontname);
  360.     cleanup(temp, 4);
  361.     }
  362.  
  363.     Xsize = myfont->tf_XSize;
  364.     Ysize = myfont->tf_YSize;
  365.     BaseLine = myfont->tf_Baseline;
  366.  
  367.     /* Now set up all the screen info as necessary */
  368.  
  369.     maxrows = GfxBase->NormalDisplayRows;
  370.  
  371.     /*   If user wants to use the current interlace setting then set p_interlace
  372.     ** according to what the ViewLord says it is. */
  373.     if(p_interlace == 2)
  374.     p_interlace = ((IntuitionBase->ViewLord.Modes & LACE) == LACE) ? 1 : 0;
  375.     else if((p_screen == 0) && ((IntuitionBase->ViewLord.Modes & LACE) == 0))
  376.     p_interlace = 0;
  377.  
  378.     if(p_interlace)
  379.     maxrows *= 2;
  380.  
  381.     customfudge = (p_screen == 1) ? 4 : 0;
  382.  
  383.     /*   See if user wants to use everything available (specified LINES 0).If
  384.     ** so then set p_lines so we'll leave room for the window title.
  385.     ** (Ysize + 1) is the size of the window title bar.
  386.     ** (Ysize + 1 + customfudge) is used to allow us to account for the the 4
  387.     ** scan-lines we'll allow in CUSTOM screen mode so that the user can pull
  388.     ** the window down to expose the screen's depth arrangement gadgets.  Note
  389.     ** that it's OK to overwrite the last 2 lines or so of the window-title bar
  390.     ** (that's why we take the remainder first).
  391.     **/
  392.     if( ((maxrows - (Ysize + 1 - customfudge)) % Ysize) > (Ysize - 2) )
  393.     maxlines = (maxrows - Ysize + customfudge) / Ysize;
  394.     else
  395.     maxlines = (maxrows - (Ysize + 1 + customfudge)) / Ysize;
  396.     if(p_lines == 0)
  397.     p_lines = maxlines;
  398.     else if (p_lines > maxlines)
  399.     p_lines = maxlines;
  400.  
  401.     /*   Set MINY.  MINY will be adjusted so we'll overwrite part of the
  402.     ** window title bar if necessary to get the last line to end at the bottom
  403.     ** of the window.
  404.     ** Remember that MINY is the location of the BASELINE of the character. */
  405.     {
  406.     int end = (Ysize + 2) + (p_lines * Ysize);
  407.  
  408.     MINY = Ysize + 2;
  409.     if(end > maxrows)
  410.         MINY -= (end - maxrows);
  411.     MINY += BaseLine;
  412.     }
  413.     if(p_screen == 1 && p_interlace == 1)
  414.     NewScreen.ViewModes |= LACE;
  415.  
  416.     MAXY = MINY + ((p_lines - 1) * Ysize);
  417.     top  = MINY; bot  = MAXY;
  418.     savx = MINX; savy = MINY;
  419.  
  420.     NewWindow.Height = MAXY + customfudge + (Ysize - BaseLine);
  421.     NewWindow.MinHeight = NewWindow.Height;
  422.     NewWindow.MaxHeight = NewWindow.Height;
  423.     NewReqWindow.MaxHeight = NewWindow.Height;
  424.     NewWindow.TopEdge    = 0L;
  425.  
  426.     if (p_screen == 1) {
  427.     if (p_depth > 2)
  428.         p_depth = 2;
  429.     else if (p_depth < 1)
  430.         p_depth = 1;
  431.     NewScreen.Depth = (long)p_depth;
  432.     NewScreen.Height = NewWindow.Height + customfudge;
  433.     NewScreen.TopEdge = 0;
  434.     } else {
  435.     p_depth    = 2L;
  436.     NewWindow.Screen = NULL;
  437.     NewReqWindow.Screen = NULL;
  438.     NewWindow.Type = WBENCHSCREEN;
  439.     NewReqWindow.Type = WBENCHSCREEN;
  440.     }
  441.  
  442.     /* see if we exit with a startup script */
  443.     if (strncmp(p, "exi", 3) == 0) {
  444.     p = next_wrd(p+l+1,&l);
  445.     if (*p) return(p);
  446.     }
  447.     if (script_files_todo > 0) {
  448.         script_files_todo--;
  449.         return(*(script_files++));
  450.     }
  451.     return(NULL);
  452.     }
  453.  
  454. void InitDevs()
  455. {
  456. USHORT    colors[4];
  457. int    i;
  458. BYTE    *b,*c;
  459. struct Process *mproc;
  460.  
  461.     if (p_screen == 1) {
  462.     if ((myscreen = (struct Screen *)OpenScreen(&NewScreen)) == NULL)
  463.         cleanup("can't open screen",3);
  464.     NewWindow.Screen = myscreen;
  465.     NewReqWindow.Screen = myscreen;
  466.     }
  467.  
  468.     if ((mywindow = (struct Window *)OpenWindow(&NewWindow)) == NULL)
  469.     cleanup("can't open window",4);
  470.  
  471.     if(OpenDevice("console.device", -1L, &ConReq, 0L))
  472.     cleanup("can't open console", 4);
  473.     ConsoleDevice = ConReq.io_Device;
  474.  
  475.     if(p_screen == 1) {    /* Cause system reqs to come to this screen */
  476.     mproc = (struct Process *)FindTask(0L);
  477.     OrigWindowPtr = mproc->pr_WindowPtr;
  478.     mproc->pr_WindowPtr = (APTR)mywindow;
  479.     }
  480.  
  481.     myviewport   = (struct ViewPort *)ViewPortAddress(mywindow);
  482.     myrastport   = (struct RastPort *)mywindow->RPort;
  483.  
  484.     SetFont(myrastport,myfont);
  485.  
  486.     if (p_depth > 1) myrequest.BackFill = 2;
  487.     if (p_screen != 0 && p_wbcolors == 0) {
  488.     colors[0] = p_background;
  489.     colors[1] = p_foreground;
  490.     colors[2] = p_bold;
  491.     colors[3] = p_cursor;
  492.     if (p_depth == 1)
  493.         LoadRGB4(myviewport, colors, 2L);
  494.     else
  495.         LoadRGB4(myviewport, colors, 4L);
  496.     }
  497.  
  498.     Read_Request = (struct IOExtSer *)
  499.     AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR);
  500.     Read_Request->io_SerFlags = (p_shared ? SERF_SHARED : 0);
  501.     Read_Request->IOSer.io_Message.mn_ReplyPort = CreatePort(0L,0L);
  502.     if(OpenDevice(mysername, (LONG)p_unit, (struct IORequest *)Read_Request, NULL))
  503.     cleanup("Can't open Read device",5);
  504.     rs_in = malloc(p_buffer+1);
  505.     Read_Request->io_SerFlags = 0L;
  506.     Read_Request->io_Baud      = p_baud;
  507.     Read_Request->io_ReadLen  = 8L;
  508.     Read_Request->io_WriteLen = 8L;
  509.     Read_Request->io_CtlChar  = 0x11130000L;
  510.     Read_Request->io_RBufLen  = p_buffer;
  511.     Read_Request->io_BrkTime  = p_break;
  512.     Read_Request->IOSer.io_Command = SDCMD_SETPARAMS;
  513.     DoIO((struct IORequest *)Read_Request);
  514.     Read_Request->IOSer.io_Command = CMD_READ;
  515.     Read_Request->IOSer.io_Length  = 1;
  516.     Read_Request->IOSer.io_Data    = (APTR) &rs_in[0];
  517.  
  518.     Write_Request = (struct IOExtSer *)
  519.     AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR);
  520.     b = (BYTE *)Read_Request;
  521.     c = (BYTE *)Write_Request;
  522.     for (i=0;i<sizeof(struct IOExtSer);i++)
  523.     *c++ = *b++;
  524.     Write_Request->IOSer.io_Message.mn_ReplyPort = CreatePort(0L,0L);
  525.     Write_Request->IOSer.io_Command = CMD_WRITE;
  526.     Write_Request->IOSer.io_Length = 1;
  527.     Write_Request->IOSer.io_Data = (APTR) &rs_out[0];
  528.  
  529.     Timer_Port = CreatePort("Timer Port",0L);
  530.     Script_Timer_Port = CreatePort("Timer Port",0L);
  531.  
  532.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)&Timer, NULL) ||
  533.     OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)&Script_Timer, NULL))
  534.     cleanup("can't open timer device",7);
  535.  
  536.     Timer.tr_node.io_Message.mn_ReplyPort = Timer_Port;
  537.     Timer.tr_node.io_Command = TR_ADDREQUEST;
  538.     Timer.tr_node.io_Flags = 0;
  539.     Timer.tr_node.io_Error = 0;
  540.  
  541.     Script_Timer.tr_node.io_Message.mn_ReplyPort = Script_Timer_Port;
  542.     Script_Timer.tr_node.io_Command = TR_ADDREQUEST;
  543.     Script_Timer.tr_node.io_Flags = 0;
  544.     Script_Timer.tr_node.io_Error = 0;
  545.  
  546.     BeepWave = (UBYTE *)AllocMem(BEEPSIZE,(long)(MEMF_CHIP|MEMF_CLEAR));
  547.     if (BeepWave != 0)
  548.     BeepWave[0] = 100;
  549.  
  550.     Audio_Port = CreatePort("Audio Port",0L);
  551.  
  552.     Audio_Request.ioa_Request.io_Message.mn_ReplyPort = Audio_Port;
  553.     Audio_Request.ioa_Request.io_Message.mn_Node.ln_Pri = 85;
  554.     Audio_Request.ioa_Data = Audio_AllocMap;
  555.     Audio_Request.ioa_Length = (ULONG) sizeof(Audio_AllocMap);
  556.  
  557.     if (OpenDevice(AUDIONAME, NULL, (struct IORequest *)&Audio_Request, NULL))
  558.     cleanup("can't open audio device",8);
  559.  
  560.     Audio_Request.ioa_Request.io_Command = CMD_WRITE;
  561.     Audio_Request.ioa_Request.io_Flags = ADIOF_PERVOL;
  562.     Audio_Request.ioa_Data = BeepWave;
  563.     Audio_Request.ioa_Length = BEEPSIZE;
  564.     Audio_Request.ioa_Period = COLORCLOCK / (BEEPSIZE * BEEPFREQ);
  565.     Audio_Request.ioa_Volume = p_volume;
  566.     Audio_Request.ioa_Cycles = 100;
  567. }
  568.  
  569. /*****************************************************************/
  570. /*    The following function initializes the structure arrays     */
  571. /*   needed to provide the File menu topic.             */
  572. /*****************************************************************/
  573. void InitFileItems()
  574. {
  575.     int n, nxfer;
  576.     struct HowToInit Externs;    /* for the external xfer pgms */
  577.     char *p, *p1;
  578.  
  579.     if(capture == TRUE)
  580.     filetext[FILEMAX-1] = "Capturing";
  581.     else
  582.     filetext[FILEMAX-1] = "Capture";
  583.     do_menu_init(FileItem, FileText, FILE_INIT_ENTRY, FILEMAX);
  584.     FileItem[0].SubItem = ModeItem;
  585.     do_menu_init(ModeItem, ModeText, MODE_INIT_ENTRY, MODEMAX);
  586.  
  587.     p = (char *)&Externs; p1 = (char *)MODE_INIT_ENTRY;
  588.     for(n = 0; n < sizeof(struct HowToInit); n++)
  589.     *(p++) = *(p1++);
  590.  
  591.     nxfer = MODEMAX;
  592.     for(n = 0; n < NumExts; n++) {
  593.     struct ExternalXfer *exp = ExtXfer[n];
  594.  
  595.     nxfer = n + MODEMAX;
  596.     ModeItem[nxfer-1].NextItem = &ModeItem[nxfer];
  597.     Externs.text = &exp->dispname;
  598.     *Externs.cmdkeys = exp->cmdkey;
  599.     do_menu_init(&ModeItem[nxfer], &ModeText[nxfer], &Externs, 1);
  600.     ModeItem[nxfer].TopEdge = 10 * nxfer;
  601.     }
  602.  
  603.     for(n = 0; n <= nxfer; n++ ) {
  604.     ModeItem[n].MutualExclude = (~(1 << n));
  605.     }
  606.     if(p_xproto > nxfer) {
  607.     p_xproto = MODEMAX - 1;
  608.     }
  609.     ModeItem[p_xproto].Flags |= CHECKED;
  610. }
  611.  
  612. /******************************************************************
  613. **            Main Comm menu
  614. **        set up for Baud & Parity submenus
  615. *******************************************************************/
  616. void InitCommItems()
  617. {
  618.     struct IntuiText *itext;
  619.     int n;
  620.  
  621.     do_menu_init(CommItem, CommText, COMM_INIT_ENTRY, COMMAX);
  622.     CommItem[0].SubItem = RSItem;
  623.     CommItem[1].SubItem = ParItem;
  624.     CommItem[2].SubItem = XFItem;
  625.     CommItem[3].Flags |= CHECKIT | MENUTOGGLE;
  626.     CommItem[3].Width += CHECKWIDTH;
  627.     itext = (struct IntuiText *)CommItem[3].ItemFill;
  628.     itext->LeftEdge = CHECKWIDTH;
  629.     if(p_shared)
  630.     CommItem[3].Flags |= CHECKED;
  631.     else
  632.     CommItem[3].Flags &= (-1L ^ CHECKED);
  633.  
  634. /*****************************************************************/
  635. /*    The following initializes the structure arrays         */
  636. /*   needed to provide the BaudRate Submenu topic.         */
  637. /*****************************************************************/
  638.  
  639.     do_menu_init(RSItem, RSText, RS_INIT_ENTRY, RSMAX);
  640.     for( n=0; n<RSMAX; n++ ) {
  641.     RSItem[n].MutualExclude = (~(1 << n));
  642.     }
  643.  
  644.     /* select baud item chekced */
  645.     switch (p_baud) {
  646.     case 300:    n = 0; break;
  647.     case 1200:    n = 1; break;
  648.     case 2400:    n = 2; break;
  649.     case 4800:    n = 3; break;
  650.     case 9600:    n = 4; break;
  651.     default:    n = 2; p_baud = 2400;
  652.     }
  653.     RSItem[n].Flags |= CHECKED;
  654.  
  655. /* initialize text for specific menu items */
  656.  
  657. /*****************************************************************/
  658. /*    The following initializes the structure arrays         */
  659. /*   needed to provide the Parity   Submenu topic.         */
  660. /*****************************************************************/
  661.  
  662.     do_menu_init(ParItem, ParText, PAR_INIT_ENTRY, PARMAX);
  663.     for( n=0; n<PARMAX-2; n++ ) {
  664.     ParItem[n].MutualExclude = (~(1 << n));
  665.     }
  666.  
  667.     /* select parity item chekced */
  668.     ParItem[p_parity].Flags |= CHECKED;
  669.  
  670.     if(p_strip)
  671.     ParItem[PARMAX-1].Flags |= CHECKED;
  672.     else
  673.     ParItem[PARMAX-1].Flags &= (-1L ^ CHECKED);
  674.  
  675.     ParItem[5].Flags |= HIGHNONE;        /* Don't highlight "----" */
  676.     ParItem[5].Flags &= (-1L ^ (CHECKIT | MENUTOGGLE));    /* No checkmarks  */
  677.  
  678. /*****************************************************************/
  679. /*    The following initializes the structure arrays         */
  680. /* initialize text for specific menu items */
  681. /*    needed to provide the Transfer Mode menu topic.         */
  682. /*****************************************************************/
  683.  
  684.     do_menu_init(XFItem, XFText, XF_INIT_ENTRY, XFMAX);
  685.     
  686.     /* initialize each menu item and IntuiText with loop */
  687.     for(n = 0; n < 2; n++)
  688.     XFItem[n].MutualExclude = 2 - n;
  689.  
  690.     /* mode checked */
  691.     XFItem[p_mode].Flags |= CHECKED;
  692.     if (p_convert)
  693.     XFItem[2].Flags |= CHECKED;
  694.  
  695.     if (p_autochop)
  696.     XFItem[3].Flags |= CHECKED;
  697.     
  698. } /* end of InitCommItems() */
  699.  
  700.  
  701. /*****************************************************************/
  702. /*    The following function initializes the structure arrays     */
  703. /*   needed to provide the Script menu topic.             */
  704. /*****************************************************************/
  705. void InitScriptItems()
  706. {
  707.     do_menu_init(ScriptItem, ScriptText, SCRIPT_INIT_ENTRY, SCRIPTMAX);
  708. }
  709.  
  710. /*****************************************************************/
  711. /*    The following function initializes the structure arrays     */
  712. /*   needed to provide the Util menu topic.               */
  713. /*****************************************************************/
  714. void InitUtilItems()
  715. {
  716.     struct IntuiText *itext;
  717.     int    n;
  718.  
  719.     do_menu_init(UtilItem, UtilText, UTIL_INIT_ENTRY, UTILMAX);
  720.     /* initialize each menu item and IntuiText with loop */
  721.     for(n = 0; n < 4; n++) {
  722.     UtilItem[n].Flags &= (-1L ^ (CHECKIT | MENUTOGGLE));
  723.     }
  724.  
  725.     if (p_echo)
  726.     UtilItem[4].Flags |= CHECKED;
  727.     if (p_wrap)
  728.     UtilItem[5].Flags |= CHECKED;
  729.     if (p_keyapp == 0)
  730.     UtilItem[6].Flags |= CHECKED;
  731.     if (p_curapp)
  732.     UtilItem[7].Flags |= CHECKED;
  733.     if (p_bs_del)
  734.     UtilItem[8].Flags |= CHECKED;
  735.     if (p_xbeep)
  736.     UtilItem[9].Flags |= CHECKED;
  737.     if(p_mouse_up)
  738.     UtilItem[10].Flags |= CHECKED;
  739.     if(p_mouse_down)
  740.     UtilItem[11].Flags |= CHECKED;
  741.  
  742.     swap_bs_del();    /* Setup keys[] properly... */
  743.     swap_bs_del();    /* ...for mode            */
  744. }
  745.  
  746. /****************************************************************/
  747. /*   The following function inits the Menu structure array with */
  748. /*  appropriate values for our simple menu.  Review the manual    */
  749. /*  if you need to know what each value means.            */
  750. /****************************************************************/
  751. void InitMenu()
  752. {
  753.     menu[0].NextMenu = &menu[1];
  754.     menu[0].LeftEdge = 5;
  755.     menu[0].TopEdge = 0;
  756.     menu[0].Width = 40;
  757.     menu[0].Height = 10;
  758.     menu[0].Flags = MENUENABLED;
  759.     menu[0].MenuName = "File";      /* text for menu-bar display */
  760.     menu[0].FirstItem = &FileItem[0]; /* pointer to first item in list */
  761.  
  762.     menu[1].NextMenu = &menu[2];
  763.     menu[1].LeftEdge = 55;
  764.     menu[1].TopEdge = 0;
  765.     menu[1].Width = 88;
  766.     menu[1].Height = 10;
  767.     menu[1].Flags = MENUENABLED;
  768.     menu[1].MenuName = "Comm Setup";    /* text for menu-bar display */
  769.     menu[1].FirstItem = &CommItem[0];    /* pointer to first item in list */
  770.  
  771.     menu[2].NextMenu = &menu[3];
  772.     menu[2].LeftEdge = 153;
  773.     menu[2].TopEdge = 0;
  774.     menu[2].Width = 56;
  775.     menu[2].Height = 10;
  776.     menu[2].Flags = MENUENABLED;
  777.     menu[2].MenuName = "Script";    /* text for menu-bar display */
  778.     menu[2].FirstItem = &ScriptItem[0];    /* pointer to first item in list*/
  779.  
  780.     menu[3].NextMenu = NULL;
  781.     menu[3].LeftEdge = 225;
  782.     menu[3].TopEdge = 0;
  783.     menu[3].Width = 64;
  784.     menu[3].Height = 10;
  785.     menu[3].Flags = MENUENABLED;
  786.     menu[3].MenuName = "Utility";       /* text for menu-bar display */
  787.     menu[3].FirstItem = &UtilItem[0];  /* pointer to first item in list*/
  788. }
  789.  
  790. void do_menu_init(menuitem, menutext, initentry, max)
  791. struct MenuItem menuitem[];
  792. struct IntuiText menutext[];
  793. struct HowToInit *initentry;
  794. int max;
  795. {
  796.     int n, nplus1;
  797.     char **temp;
  798.  
  799.     /* initialize each menu item and IntuiText with loop */
  800.     for( n=0; n < max; n++ ) {
  801.     nplus1 = n + 1;
  802.     temp = initentry->text;
  803.     menutext[n].IText = (UBYTE *)temp[n];
  804.     menuitem[n].NextItem = &menuitem[nplus1];
  805.     menuitem[n].LeftEdge = initentry->LeftEdge * Ysize;
  806.     menuitem[n].TopEdge = 10 * n;
  807.     menuitem[n].Width = initentry->Width * Ysize;
  808.     if(initentry->Flags & CHECKIT)
  809.         menuitem[n].Width += CHECKWIDTH;
  810.     menuitem[n].Height = 10;
  811.     menuitem[n].Flags = initentry->Flags;
  812.     menuitem[n].MutualExclude = 0;
  813.     menuitem[n].ItemFill = (APTR)&menutext[n];
  814.     menuitem[n].SelectFill = NULL;
  815.     if((initentry->cmdkeys != NULL)
  816.     && (initentry->cmdkeys[n])
  817.     && (initentry->cmdkeys[n] != ' ')) {
  818.         menuitem[n].Command  = initentry->cmdkeys[n];
  819.         menuitem[n].Flags   |= COMMSEQ;
  820.     }
  821.     else menuitem[n].Command = 0;
  822.     menuitem[n].SubItem = NULL;
  823.     menuitem[n].NextSelect = 0;
  824.     
  825.     menutext[n].FrontPen = 0;
  826.     menutext[n].BackPen = 1;
  827.     menutext[n].DrawMode = JAM2;/* render in fore and background */
  828.     if(menuitem[n].Flags & CHECKIT)
  829.         menutext[n].LeftEdge = CHECKWIDTH;
  830.     else
  831.         menutext[n].LeftEdge = 0;
  832.     menutext[n].TopEdge = 1;
  833.     menutext[n].ITextFont = NULL;
  834.     menutext[n].NextText = NULL;
  835.     }
  836.     menuitem[max-1].NextItem = NULL;
  837. }
  838.  
  839. #if AREXX
  840. makerexxport()
  841. {
  842.     int i,
  843.     ret = 0;
  844.     long hostlen = strlen(HOSTNAMEROOT) + strlen(mysername) + 1 + 2 + 1;
  845.             /* "VT100-"            name          "-" "xx" \0 */
  846.  
  847.     if(HostName) {
  848.     FreeMem(HostName, (ULONG)(strlen(HostName)+1));
  849.     HostName = NULL;
  850.     }
  851.  
  852.     if( (HostName = AllocMem(hostlen, MEMF_PUBLIC | MEMF_CLEAR)) == NULL)
  853.     return NOHOSTMEM;
  854.  
  855.     sprintf(HostName, "%s%s-%02d", HOSTNAMEROOT, mysername, p_unit);
  856.  
  857.     Forbid();
  858.     
  859.     if(FindPort(HostName) != NULL)
  860.     ret = HAVEVT100PORT;
  861.     else if( (FromRexxPort = (struct MsgPort *)AllocMem((LONG)sizeof(struct MsgPort),
  862.                  MEMF_PUBLIC | MEMF_CLEAR)) == NULL)
  863.     ret = NOPORTMEM;
  864.     else {
  865.     InitPort(FromRexxPort, HostName);
  866.     AddPort(FromRexxPort);
  867.     }
  868.  
  869.     Permit();
  870.     if(ret && RexxSysBase) {
  871.     CloseLibrary((struct Library *)RexxSysBase);
  872.     RexxSysBase = NULL;
  873.     }
  874.     return ret;
  875. }
  876. #endif /* AREXX */
  877.