home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff114.lzh / Vt100 / init.c < prev    next >
C/C++ Source or Header  |  1987-11-22  |  20KB  |  675 lines

  1. /***************************************************************
  2.  * vt100 - terminal emulator - initialization
  3.  *
  4.  *    v2.7 870825 ACS - Allow execution of all script files specified on
  5.  *              command line (companion to changes in script.c).
  6.  *              Rolled menu init into one routine (do_menu_init()).
  7.  *    v2.6 870227 DBW - bug fixes for all the stuff in v2.5
  8.  *    v2.5 870214 DBW - more additions (see readme file)
  9.  *    v2.4 861214 DBW - lots of fixes/additions (see readme file)
  10.  *    v2.3 861101 DBW - minor bug fixes
  11.  *    v2.2 861012 DBW - more of the same
  12.  *    v2.1 860915 DBW - new features (see README)
  13.  *         860901 ACS - Added Parity and Word Length and support code
  14.  *         860823 DBW - Integrated and rewrote lots of code
  15.  *    v2.0 860809 DBW - Major rewrite
  16.  *    v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
  17.  *    v1.0 860712 DBW - First version released
  18.  *
  19.  ***************************************************************/
  20.  
  21. #include "vt100.h"
  22. #define FONTNAMESIZE    40
  23. #define FONTSUFFIX    ".font"
  24. #define MAXFONTVARLEN    34    /* 40 minus sizeof(".font") */
  25.  
  26. /*   Used by script.c for script file chaining. */
  27. int script_files_todo = 0;
  28. char **script_files = NULL;
  29.  
  30. char line[256];
  31.  
  32. /* Command key equivalences per menu.  Manipulated by script.c */
  33.  
  34. /*   Equivalences for the File menu... */
  35. struct filecmd {
  36.     char ac;    /* ASCII Capture    */
  37.     char as;    /* ASCII Send        */
  38.     char xs;    /* Xmodem Send        */
  39.     char xr;    /* Xmodem Receive    */
  40.     char kg;    /* Kermit Get        */
  41.     char kr;    /* Kermit Receive    */
  42.     char ks;    /* Kermit Send        */
  43.     char kb;    /* Kermit Bye        */
  44.     char nl;
  45. } filecmd_chars = { ' ', ' ', 'V', '^', 'G', 'R', 'S', 'B', '\0' };
  46.  
  47. /*   Equivalences for the Baud Rate sub-menu... */
  48. struct baducmd {
  49.     char b03;    /* 0300            */
  50.     char b12;    /* 1200            */
  51.     char b24;    /* 2400            */
  52.     char b48;    /* 4800            */
  53.     char b96;    /* 9600            */
  54.     char bnl;
  55. } baudcmd_chars = { ' ', 'L', 'H', ' ', ' ', '\0' };
  56.  
  57. /*   Equivalences for the Parity sub-menu... */
  58. struct parcmd {
  59.     char no;    /* NOne            */
  60.     char ma;    /* MArk            */
  61.     char sp;    /* SPace        */
  62.     char ev;    /* EVen            */
  63.     char od;    /* ODd            */
  64.     char nl;
  65. } parcmd_chars = { 'X', ' ', ' ', 'E', 'O', '\0' };
  66.  
  67. /*   Equivalences for the Xfer Mode sub-menu... */
  68. struct modcmd {
  69.     char im;    /* IMage        */
  70.     char tx;    /* TeXt            */
  71.     char cn;    /* CoNvert        */
  72.     char nl;
  73. } modcmd_chars = { 'I', 'T', ' ', '\0' };
  74.  
  75. /*   Equivalences for the Script menu... */
  76. struct scrcmd {
  77.     char em;    /* Execute Macro    */
  78.     char ab;    /* Abort Macro        */
  79.     char nl;
  80. } scrcmd_chars = { 'M', 'A', '\0' };
  81.  
  82. /*   Equivalences for the Utility menu... */
  83. struct utilcmd {
  84.     char sb;    /* Send Break    */
  85.     char hu;    /* Hang Up    */
  86.     char cd;    /* Change Dir    */
  87.     char cs;    /* Clear Screen    */
  88.     char ec;    /* ECho        */
  89.     char wr;    /* WRap        */
  90.     char nk;    /* Num Key    */
  91.     char ac;    /* App Cur    */
  92.     char bs;    /* BS<->DEL    */
  93.     char nl;
  94. } utilcmd_chars = { '.', ' ', 'D', ' ', ' ', 'W', 'K', 'C', 'Z', '\0' };
  95.  
  96. static char myfontname[FONTNAMESIZE];
  97. extern char *getenv();
  98.  
  99. static char *filetext[] = {
  100.     "Ascii  Capture",
  101.     "Ascii  Send",
  102.     "Xmodem Receive",
  103.     "Xmodem Send",
  104.     "Kermit Get",
  105.     "Kermit Receive",
  106.     "Kermit Send",
  107.     "Kermit BYE"
  108. };
  109.  
  110. static char *commtext[] = {
  111.     "Baud Rate",
  112.     "Parity   ",
  113.     "Xfer Mode"
  114. };
  115.  
  116. static char *baudtext[] = {
  117.     "   300",
  118.     "  1200",
  119.     "  2400",
  120.     "  4800",
  121.     "  9600"
  122. };
  123.  
  124. static char *partext[] = {
  125.     "  None ",
  126.     "  Mark ",
  127.     "  Space",
  128.     "  Even ",
  129.     "  Odd  "
  130. };
  131.  
  132. static char *modtext[] = {
  133.     "  Image  ",
  134.     "  Text   ",
  135.     "  Convert"
  136. };
  137.  
  138. static char *scrtext[] = {
  139.     "Execute Macro",
  140.     "Abort Execution"
  141. };
  142.  
  143. static char *utiltext[] = {
  144.     "Send Break",
  145.     "Hang Up",
  146.     "Change Dir",
  147.     "Clear Scrn",
  148.     "  Echo",
  149.     "  Wrap",
  150.     "  Num Key",
  151.     "  App Cur",
  152.     "  BS<->DEL"
  153. };
  154.  
  155. struct HowToInit {
  156.     int LeftEdge;
  157.     int Width;
  158.     ULONG Flags;
  159.     char **text;
  160.     char *cmdkeys;
  161. };
  162.  
  163. static struct HowToInit menu_init[] = {
  164.     { 0, 120+40, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  165.          filetext, (char *)(&filecmd_chars) },
  166.     { 0, 88, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  167.          commtext, NULL },
  168.     { 75, 56+40, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  169.            baudtext, (char *)(&baudcmd_chars) },
  170.     { 75, 56+40, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  171.           partext, (char *)(&parcmd_chars) },
  172.     { 75, 80+40, ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKIT,
  173.           modtext, (char *)(&modcmd_chars) },
  174.     { 0, 160, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  175.          scrtext, (char *)(&scrcmd_chars) },
  176.     { 0, 88+40, ITEMTEXT | ITEMENABLED | HIGHCOMP,
  177.          utiltext, (char *)(&utilcmd_chars) }
  178. };
  179.  
  180. #define FILE_INIT_ENTRY    (&(menu_init[0]))
  181. #define COMM_INIT_ENTRY    (&(menu_init[1]))
  182. #define RS_INIT_ENTRY    (&(menu_init[2]))
  183. #define PAR_INIT_ENTRY    (&(menu_init[3]))
  184. #define XF_INIT_ENTRY    (&(menu_init[4]))
  185. #define SCRIPT_INIT_ENTRY    (&(menu_init[5]))
  186. #define UTIL_INIT_ENTRY    (&(menu_init[6]))
  187.  
  188. void do_menu_init();
  189.  
  190. char *InitDefaults(argc,argv)
  191. int    argc;
  192. char    **argv;
  193.     {
  194.     FILE    *fd = NULL;
  195.     char    *p, *t, *ifile;
  196.     int     l, dont_init = 0;
  197. #ifdef BUGFIXES
  198.     int        screen_height, max_screen_lines, border_size;
  199.     int        wb_lace;
  200.     register struct Screen *s;
  201. #endif
  202.  
  203.     doing_init = 1;    /* make sure we only allow INIT script commands */
  204.     if (argc > 1) {
  205.     int start_of_script_files = 1;
  206.  
  207.     if(strcmp(argv[1], "-i") == 0) {    /* No init file */
  208.         dont_init = 1;
  209.         start_of_script_files = 2;
  210.     }
  211.     else if(strcmp(argv[1], "+i") == 0) {    /* Use specified init file */
  212.         start_of_script_files = 3;
  213.             if((fd=fopen(argv[2],"r")) == NULL) {
  214.         ifile = AllocMem((LONG)(strlen(argv[2])+3), MEMF_PUBLIC|MEMF_CLEAR);
  215.         strcpy(ifile, "S:");
  216.         strcat(ifile, argv[2]);
  217.         fd = fopen(ifile, "r");
  218.         FreeMem(ifile, (LONG)(strlen(argv[2])+3));
  219.         ifile = NULL;
  220.         }
  221.     }
  222.     if(start_of_script_files > argc)
  223.         script_files_todo = 0;
  224.     else
  225.         script_files_todo = argc - start_of_script_files; /* # of cmdline script files left */
  226.     script_files = &(argv[start_of_script_files]);      /* Ptr to first of 'em */
  227.     }
  228.  
  229.     if(!dont_init)
  230.     if((fd == NULL) && ((fd=fopen("vt100.init","r")) == NULL))
  231.         fd=fopen("s:vt100.init","r");
  232.  
  233.     if(fd != NULL) {
  234.     while (fgets(line,256,fd) != 0) {
  235.         line[strlen(line)-1] = '\000';
  236.         p = next_wrd(&line[0],&l);
  237.         if (*p) {
  238.         *p |= ' ';
  239.         if (p[1]) p[1] |= ' ';
  240.         if (*p == '#') continue;
  241.         if (*p == 'e' && p[1] == 'x') break;
  242.         exe_cmd(p,l);
  243.         }
  244.     }
  245.     fclose(fd);
  246.     }
  247.     doing_init = 0;
  248.  
  249.     /* Now set up all the screen info as necessary */
  250. #ifdef BUGFIXES
  251.     IntuitionBase = (struct IntuitionBase *)
  252.     OpenLibrary("intuition.library", INTUITION_REV);
  253.     if( IntuitionBase == NULL )
  254.     cleanup("can't open intuition",1);
  255.  
  256.     Forbid();    /* user might be moving screen */
  257.     for (s = IntuitionBase->FirstScreen; s ; s = s->NextScreen)
  258.     if ((s->Flags & SCREENTYPE) == WBENCHSCREEN)
  259.         break;
  260.     screen_height = s->Height;
  261.     wb_lace = s->ViewPort.Modes & LACE;
  262.     Permit();
  263.     if(wb_lace)
  264.     screen_height = screen_height/2;
  265.     if (p_interlace) {
  266.         max_screen_lines = (screen_height*2)/8 - 1;
  267.     border_size = screen_height*2 - max_screen_lines*8;
  268.     NewScreen.ViewModes |= LACE;
  269.     } else {
  270.         max_screen_lines = screen_height/8 - 1;
  271.     border_size = screen_height - max_screen_lines*8;
  272.     }
  273.     if (p_lines > max_screen_lines) p_lines = max_screen_lines;
  274.     if(border_size > 10)
  275.     border_size = 10;
  276.     MINY = 14 + border_size - 8;
  277.     NewWindow.Height    = (long)((p_lines*8) + border_size);
  278. #else
  279.     if (p_interlace == 0) {
  280.     if (p_lines > 24) p_lines = 24;
  281.     MINY = 14;
  282.     NewWindow.Height    = (long)((p_lines*8)+8);
  283.     }
  284.     else {
  285.     if (p_lines > 48) p_lines = 48;
  286.     MINY = 16;
  287.     NewScreen.ViewModes |= LACE;
  288.     NewWindow.Height    = (long)((p_lines*8)+10);
  289.     }
  290. #endif
  291.     NewWindow.MinHeight = NewWindow.Height;
  292.     NewWindow.MaxHeight = NewWindow.Height;
  293.     NewWindow.TopEdge    = 0L;
  294.     MAXY = ((p_lines-1)*8) + MINY;
  295.     top  = MINY;
  296.     bot  = MAXY;
  297.     savx = MINX;
  298.     savy = MINY;
  299.     if (p_screen == 1) {
  300.     if (p_depth > 2) p_depth = 2;
  301.     if (p_depth < 1) p_depth = 1;
  302.     NewScreen.Depth     = (long)p_depth;
  303. #ifdef BUGFIXES
  304.     NewScreen.Height    = (long)NewWindow.Height;
  305.     if (p_interlace == 1)
  306.         NewScreen.TopEdge    = (long)(screen_height*2 - NewScreen.Height);
  307.     else
  308.         NewScreen.TopEdge    = (long)(screen_height - NewScreen.Height);
  309.     }
  310. #else
  311.     NewScreen.Height    = (long)((p_lines*8)+16);
  312.     if (p_interlace == 1)
  313.         NewScreen.TopEdge    = (long)(400 - NewScreen.Height);
  314.     else
  315.         NewScreen.TopEdge    = (long)(208 - NewScreen.Height);
  316.     }
  317. #endif
  318.     else {
  319.     p_depth            = 2L;
  320.     NewWindow.TopEdge    = 0L;
  321.     NewWindow.Screen    = NULL;
  322.     NewReqWindow.Screen    = NULL;
  323.     NewWindow.Type        = WBENCHSCREEN;
  324.     NewReqWindow.Type    = WBENCHSCREEN;
  325.     }
  326.  
  327.     /* check for environment variable specifying font name */
  328.     if((t = getenv("font"))) {
  329.         if(strlen(t) <= MAXFONTVARLEN) {
  330.             strcpy(myfontname,t);
  331.             strcat(myfontname,FONTSUFFIX);
  332.             myattr.ta_Name = (STRPTR)myfontname;
  333.         } else
  334.             fprintf(stderr,"font environment variable is too long.\n");
  335.     }
  336.  
  337.     /* see if we exit with a startup script */
  338.     if (*p == 'e') {
  339.     p = next_wrd(p+l+1,&l);
  340.     if (*p) return(p);
  341.     }
  342.     if (script_files_todo > 0) {
  343.         script_files_todo--;
  344.         return(*(script_files++));
  345.     }
  346.     return(NULL);
  347.     }
  348.  
  349. void InitDevs()
  350. {
  351. USHORT    colors[4];
  352. int    i;
  353. BYTE    *b,*c;
  354.  
  355. #ifndef BUGFIXES
  356. IntuitionBase = (struct IntuitionBase *)
  357.     OpenLibrary("intuition.library", INTUITION_REV);
  358. if( IntuitionBase == NULL )
  359.     cleanup("can't open intuition",1);
  360. #endif
  361.  
  362. GfxBase = (struct GfxBase *)
  363.     OpenLibrary("graphics.library",GRAPHICS_REV);
  364. if( GfxBase == NULL )
  365.     cleanup("can't open graphics library",2);
  366.  
  367. if (p_screen == 1) {
  368.     if ((myscreen = (struct Screen *)OpenScreen(&NewScreen)) == NULL)
  369.     cleanup("can't open screen",3);
  370.     NewWindow.Screen = myscreen;
  371.     NewReqWindow.Screen = myscreen;
  372.     }
  373.  
  374. if ((mywindow = (struct Window *)OpenWindow(&NewWindow)) == NULL)
  375.     cleanup("can't open window",4);
  376. if ((myfont = (struct TextFont *)OpenFont(&myattr)) == NULL)
  377.     cleanup("can't open font",4);
  378.  
  379. myviewport   = (struct ViewPort *)ViewPortAddress(mywindow);
  380. myrastport   = (struct RastPort *)mywindow->RPort;
  381.  
  382. SetFont(myrastport,myfont);
  383.  
  384. if (p_depth > 1) myrequest.BackFill = 2;
  385. if (p_screen != 0 && p_wbcolors == 0) {
  386.     colors[0] = p_background;
  387.     colors[1] = p_foreground;
  388.     colors[2] = p_bold;
  389.     colors[3] = p_cursor;
  390.     if (p_depth == 1)
  391.     LoadRGB4(myviewport,(struct ColorMap *)colors,2L);
  392.     else
  393.     LoadRGB4(myviewport,(struct ColorMap *)colors,4L);
  394.     }
  395.  
  396. Read_Request = (struct IOExtSer *)
  397.     AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR);
  398. Read_Request->io_SerFlags = 0L;
  399. Read_Request->IOSer.io_Message.mn_ReplyPort = CreatePort(0L,0L);
  400. if(OpenDevice(SERIALNAME,NULL,Read_Request,NULL))
  401.     cleanup("Cant open Read device",5);
  402. rs_in = malloc(p_buffer+1);
  403. Read_Request->io_SerFlags = 0L;
  404. Read_Request->io_Baud      = p_baud;
  405. Read_Request->io_ReadLen  = 8L;
  406. Read_Request->io_WriteLen = 8L;
  407. Read_Request->io_CtlChar  = 0x11130000L;
  408. Read_Request->io_RBufLen  = p_buffer;
  409. Read_Request->io_BrkTime  = p_break;
  410. Read_Request->IOSer.io_Command = SDCMD_SETPARAMS;
  411. DoIO(Read_Request);
  412. Read_Request->IOSer.io_Command = CMD_READ;
  413. Read_Request->IOSer.io_Length  = 1;
  414. Read_Request->IOSer.io_Data    = (APTR) &rs_in[0];
  415.  
  416. Write_Request = (struct IOExtSer *)
  417.     AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR);
  418. b = (BYTE *)Read_Request;
  419. c = (BYTE *)Write_Request;
  420. for (i=0;i<sizeof(struct IOExtSer);i++) *c++ = *b++;
  421. Write_Request->IOSer.io_Message.mn_ReplyPort = CreatePort(0L,0L);
  422. Write_Request->IOSer.io_Command = CMD_WRITE;
  423. Write_Request->IOSer.io_Length    = 1;
  424. Write_Request->IOSer.io_Data    = (APTR) &rs_out[0];
  425.  
  426. Timer_Port = CreatePort("Timer Port",0L);
  427. Script_Timer_Port = CreatePort("Timer Port",0L);
  428.  
  429. if (OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Timer, 0) ||
  430.     OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Script_Timer, 0))
  431.     cleanup("can't open timer device",7);
  432.  
  433. Timer.tr_node.io_Message.mn_ReplyPort = Timer_Port;
  434. Timer.tr_node.io_Command = TR_ADDREQUEST;
  435. Timer.tr_node.io_Flags = 0;
  436. Timer.tr_node.io_Error = 0;
  437.  
  438. Script_Timer.tr_node.io_Message.mn_ReplyPort = Script_Timer_Port;
  439. Script_Timer.tr_node.io_Command = TR_ADDREQUEST;
  440. Script_Timer.tr_node.io_Flags = 0;
  441. Script_Timer.tr_node.io_Error = 0;
  442.  
  443. BeepWave   = (UBYTE *)AllocMem(BEEPSIZE,(long)(MEMF_CHIP|MEMF_CLEAR));
  444. if (BeepWave != 0) BeepWave[0] = 100;
  445.  
  446. Audio_Port = CreatePort("Audio Port",0L);
  447.  
  448. Audio_Request.ioa_Request.io_Message.mn_ReplyPort   = Audio_Port;
  449. Audio_Request.ioa_Request.io_Message.mn_Node.ln_Pri = 85;
  450. Audio_Request.ioa_Data            = Audio_AllocMap;
  451. Audio_Request.ioa_Length        = (ULONG) sizeof(Audio_AllocMap);
  452.  
  453. if (OpenDevice(AUDIONAME, NULL, (char *) &Audio_Request, NULL))
  454.     cleanup("can't open audio device",8);
  455.  
  456. Audio_Request.ioa_Request.io_Command    = CMD_WRITE;
  457. Audio_Request.ioa_Request.io_Flags    = ADIOF_PERVOL;
  458. Audio_Request.ioa_Data        = BeepWave;
  459. Audio_Request.ioa_Length    = BEEPSIZE;
  460. Audio_Request.ioa_Period    = COLORCLOCK / (BEEPSIZE * BEEPFREQ);
  461. Audio_Request.ioa_Volume    = p_volume;
  462. Audio_Request.ioa_Cycles    = 100;
  463. }
  464.  
  465. /*****************************************************************/
  466. /*    The following function initializes the structure arrays     */
  467. /*   needed to provide the File menu topic.             */
  468. /*****************************************************************/
  469. void InitFileItems()
  470. {
  471.     do_menu_init(FileItem, FileText, FILE_INIT_ENTRY, FILEMAX);
  472. }
  473.  
  474. /******************************************************************
  475. /*            Main Comm menu
  476. /*        set up for Baud & Parity submenus
  477. /******************************************************************/
  478. void InitCommItems()
  479. {
  480.     int n;
  481.  
  482.     do_menu_init(CommItem, CommText, COMM_INIT_ENTRY, COMMAX);
  483.     CommItem[0].SubItem = RSItem;
  484.     CommItem[1].SubItem = ParItem;
  485.     CommItem[2].SubItem = XFItem;
  486.  
  487. /*****************************************************************/
  488. /*    The following initializes the structure arrays         */
  489. /*   needed to provide the BaudRate Submenu topic.         */
  490. /*****************************************************************/
  491.  
  492.     do_menu_init(RSItem, RSText, RS_INIT_ENTRY, RSMAX);
  493.     for( n=0; n<RSMAX; n++ ) {
  494.     RSItem[n].MutualExclude = (~(1 << n));
  495.     }
  496.  
  497.     /* select baud item chekced */
  498.     switch (p_baud) {
  499.     case 300:    n = 0; break;
  500.     case 1200:    n = 1; break;
  501.     case 2400:    n = 2; break;
  502.     case 4800:    n = 3; break;
  503.     case 9600:    n = 4; break;
  504.     default:    n = 2; p_baud = 2400;
  505.     }
  506.     RSItem[n].Flags |= CHECKED;
  507.  
  508. /* initialize text for specific menu items */
  509.  
  510. /*****************************************************************/
  511. /*    The following initializes the structure arrays         */
  512. /*   needed to provide the Parity   Submenu topic.         */
  513. /*****************************************************************/
  514.  
  515.     do_menu_init(ParItem, ParText, PAR_INIT_ENTRY, PARMAX);
  516.     for( n=0; n<PARMAX; n++ ) {
  517.     ParItem[n].MutualExclude = (~(1 << n));
  518.     }
  519.  
  520.     /* select parity item chekced */
  521.     ParItem[p_parity].Flags |= CHECKED;
  522.  
  523. /*****************************************************************/
  524. /*    The following initializes the structure arrays         */
  525. /* initialize text for specific menu items */
  526. /*    needed to provide the Transfer Mode menu topic.         */
  527. /*****************************************************************/
  528.  
  529.     do_menu_init(XFItem, XFText, XF_INIT_ENTRY, XFMAX);
  530.     
  531.     /* initialize each menu item and IntuiText with loop */
  532.     for( n=0; n<XFMAX; n++ ) {
  533.     if (n < 2)    XFItem[n].MutualExclude = 2 - n;
  534.     }
  535.     /* mode checked */
  536.     XFItem[p_mode].Flags |= CHECKED;
  537.     if (p_convert)    XFItem[2].Flags |= CHECKED;
  538.  
  539. /* initialize text for specific menu items */
  540.  
  541. } /* end of InitCommItems() */
  542.  
  543.  
  544. /*****************************************************************/
  545. /*    The following function initializes the structure arrays     */
  546. /*   needed to provide the Script menu topic.             */
  547. /*****************************************************************/
  548. void InitScriptItems()
  549. {
  550.     do_menu_init(ScriptItem, ScriptText, SCRIPT_INIT_ENTRY, SCRIPTMAX);
  551. }
  552.  
  553. /*****************************************************************/
  554. /*    The following function initializes the structure arrays     */
  555. /*   needed to provide the Util menu topic.               */
  556. /*****************************************************************/
  557. void InitUtilItems()
  558.     {
  559.     int    n;
  560.  
  561.     do_menu_init(UtilItem, UtilText, UTIL_INIT_ENTRY, UTILMAX);
  562. /* initialize each menu item and IntuiText with loop */
  563.     for( n=0; n<UTILMAX; n++ ) {
  564.     if (n > 3) UtilItem[n].Flags |= CHECKIT;
  565.     }
  566.  
  567.     if (p_echo)        UtilItem[4].Flags |= CHECKED;
  568.     if (p_wrap)        UtilItem[5].Flags |= CHECKED;
  569.     if (p_keyapp == 0)    UtilItem[6].Flags |= CHECKED;
  570.     if (p_curapp)    UtilItem[7].Flags |= CHECKED;
  571.     if (p_bs_del)    UtilItem[8].Flags |= CHECKED;
  572. }
  573.  
  574. /****************************************************************/
  575. /*   The following function inits the Menu structure array with */
  576. /*  appropriate values for our simple menu.  Review the manual    */
  577. /*  if you need to know what each value means.            */
  578. /****************************************************************/
  579. void InitMenu()
  580. {
  581. menu[0].NextMenu = &menu[1];
  582. menu[0].LeftEdge = 5;
  583. menu[0].TopEdge = 0;
  584. menu[0].Width = 40;
  585. menu[0].Height = 10;
  586. menu[0].Flags = MENUENABLED;
  587. menu[0].MenuName = "File";      /* text for menu-bar display */
  588. menu[0].FirstItem = &FileItem[0]; /* pointer to first item in list */
  589.  
  590. menu[1].NextMenu = &menu[2];
  591. menu[1].LeftEdge = 55;
  592. menu[1].TopEdge = 0;
  593. menu[1].Width = 88;
  594. menu[1].Height = 10;
  595. menu[1].Flags = MENUENABLED;
  596. menu[1].MenuName = "Comm Setup";   /* text for menu-bar display */
  597. menu[1].FirstItem = &CommItem[0];  /* pointer to first item in list */
  598.  
  599. menu[2].NextMenu = &menu[3];
  600. menu[2].LeftEdge = 153;
  601. menu[2].TopEdge = 0;
  602. menu[2].Width = 56;
  603. menu[2].Height = 10;
  604. menu[2].Flags = MENUENABLED;
  605. menu[2].MenuName = "Script";        /* text for menu-bar display */
  606. menu[2].FirstItem = &ScriptItem[0]; /* pointer to first item in list*/
  607.  
  608. menu[3].NextMenu = NULL;
  609. menu[3].LeftEdge = 225;
  610. menu[3].TopEdge = 0;
  611. menu[3].Width = 64;
  612. menu[3].Height = 10;
  613. menu[3].Flags = MENUENABLED;
  614. menu[3].MenuName = "Utility";       /* text for menu-bar display */
  615. menu[3].FirstItem = &UtilItem[0];  /* pointer to first item in list*/
  616. }
  617.  
  618. #ifdef BUGFIXES
  619. void do_menu_init(menuitem, menutext, initentry, maxValue)
  620. #else
  621. void do_menu_init(menuitem, menutext, initentry, max)
  622. #endif
  623. struct MenuItem menuitem[];
  624. struct IntuiText menutext[];
  625. struct HowToInit *initentry;
  626. #ifdef BUGFIXES
  627. int maxValue;
  628. #else
  629. int max;
  630. #endif
  631. {
  632.     int n, nplus1;
  633.     char **temp;
  634.  
  635.     /* initialize each menu item and IntuiText with loop */
  636. #ifdef BUGFIXES
  637.     for( n=0; n < maxValue; n++ ) {
  638. #else
  639.     for( n=0; n < max; n++ ) {
  640. #endif
  641.     nplus1 = n + 1;
  642.     temp = initentry->text;
  643.     menutext[n].IText = (UBYTE *)temp[n];
  644.     menuitem[n].NextItem = &menuitem[nplus1];
  645.     menuitem[n].LeftEdge = initentry->LeftEdge;
  646.     menuitem[n].TopEdge = 10 * n;
  647.     menuitem[n].Width = initentry->Width;
  648.     menuitem[n].Height = 10;
  649.     menuitem[n].Flags = initentry->Flags;
  650.     menuitem[n].MutualExclude = 0;
  651.     menuitem[n].ItemFill = (APTR)&menutext[n];
  652.     menuitem[n].SelectFill = NULL;
  653.     if((initentry->cmdkeys != NULL) && (initentry->cmdkeys[n] != ' ')) {
  654.         menuitem[n].Command  = initentry->cmdkeys[n];
  655.         menuitem[n].Flags   |= COMMSEQ;
  656.         }
  657.     else menuitem[n].Command = 0;
  658.     menuitem[n].SubItem = NULL;
  659.     menuitem[n].NextSelect = 0;
  660.     
  661.     menutext[n].FrontPen = 0;
  662.     menutext[n].BackPen = 1;
  663.     menutext[n].DrawMode = JAM2;/* render in fore and background */
  664.     menutext[n].LeftEdge = 0;
  665.     menutext[n].TopEdge = 1;
  666.     menutext[n].ITextFont = NULL;
  667.     menutext[n].NextText = NULL;
  668.     }
  669. #ifdef BUGFIXES
  670.     menuitem[maxValue-1].NextItem = NULL;
  671. #else
  672.     menuitem[max-1].NextItem = NULL;
  673. #endif
  674. }
  675.