home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / lsetup6.c < prev    next >
Text File  |  1998-08-01  |  56KB  |  1,597 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <ctype.h>
  22. #include <string.h>
  23. #include <io.h>
  24. #include <fcntl.h>
  25. #include <alloc.h>
  26. #include <sys\stat.h>
  27.  
  28. #include "lsetup.h"
  29. #include "lprot.h"
  30.  
  31. extern struct _configuration config;
  32.  
  33. #include <cxl\cxlvid.h>
  34. #include <cxl\cxlwin.h>
  35. #include <cxl\cxlstr.h>
  36. #include <cxl\cxlkey.h>
  37.  
  38. void VioUpdate (void);
  39.  
  40. int sh_open (char *file, int shmode, int omode, int fmode);
  41. char *get_priv_text (int);
  42. void update_message (void);
  43. long get_menu_crc (int n_elem);
  44.  
  45. static void display_menu (int n_elem);
  46. static int list_menu_items (int beg, int n_elem);
  47.  
  48. #define MAX_ITEMS   100
  49.  
  50. struct _menu_header {
  51.    char  name[14];
  52.    short n_elem;
  53. };
  54.  
  55. static struct _cmd *cmd = NULL;
  56.  
  57. static char *menu_types[] = {
  58.    " 0 - Display only",
  59.    " 1 - Gosub message area",
  60.    " 2 - Gosub file area",
  61.    " 3 - Logoff",
  62.    " 4 - N/A",
  63.    " 5 - Display file (anywhere)",
  64.    " 6 - Yell at Sysop",
  65.    " 7 - User status",
  66.    " 8 - User list",
  67.    " 9 - Version information",
  68.    " 10 - Run external program",
  69.    " 11 - Bulletin menu",
  70.    " 12 - N/A",
  71.    " 13 - Show quotes",
  72.    " 14 - Clear goto menu",
  73.    " 15 - Clear gosub menu",
  74.    " 16 - Return to MAIN menu",
  75.    " 17 - Change area",
  76.    " 18 - N/A",
  77.    " 19 - Kill message",
  78.    " 20 - N/A",
  79.    " 21 - Goto menu",
  80.    " 22 - File list",
  81.    " 23 - Download file",
  82.    " 24 - File display",
  83.    " 25 - Raw directory",
  84.    " 26 - Kill file",
  85.    " 27 - Set password",
  86.    " 28 - Change language",
  87.    " 29 - Set nulls",
  88.    " 30 - Set screen length",
  89.    " 31 - N/A",
  90.    " 32 - Set 'more?' question",
  91.    " 33 - Set screen clear",
  92.    " 34 - Set editor",
  93.    " 35 - Set location",
  94.    " 36 - Set mail check at logon",
  95.    " 37 - Set Avatar/0+",
  96.    " 38 - Set ANSI",
  97.    " 39 - Set color",
  98.    " 40 - Edit new message",
  99.    " 41 - Reply to message",
  100.    " 42 - Save message",
  101.    " 43 - Abort editing",
  102.    " 44 - List message text",
  103.    " 45 - Edit line",
  104.    " 46 - Insert line",
  105.    " 47 - Delete line",
  106.    " 48 - Continue editing",
  107.    " 49 - Change 'To' field",
  108.    " 50 - Change subject",
  109.    " 51 - Press enter to continue",
  110.    " 52 - N/A",
  111.    " 53 - Short message list",
  112.    " 54 - Read next message",
  113.    " 55 - Read previous message",
  114.    " 56 - Read message non-stop",
  115.    " 57 - Read parent message",
  116.    " 58 - Read child message",
  117.    " 59 - Check mail-box",
  118.    " 60 - Inquire message",
  119.    " 61 - Gosub menu",
  120.    " 62 - Hurl file",
  121.    " 63 - Forward message",
  122.    " 64 - Read individual message",
  123.    " 65 - Tag files for download",
  124.    " 66 - Return to previous",
  125.    " 67 - Clear menu stack",
  126.    " 68 - Locate files",
  127.    " 69 - Upload file",
  128.    " 70 - Set signature",
  129.    " 71 - Write log entry",
  130.    " 72 - Override path",
  131.    " 73 - New files list",
  132.    " 74 - Read next mail",
  133.    " 75 - Read previous mail",
  134.    " 76 - Read mail non-stop",
  135.    " 77 - Set full screen reader",
  136.    " 78 - Send online message",
  137.    " 79 - N/A",
  138.    " 80 - N/A",
  139.    " 81 - Users online",
  140.    " 82 - List mail",
  141.    " 83 - Comment to next caller",
  142.    " 84 - Download from any area",
  143.    " 85 - Read individual mail",
  144.    " 86 - Tag areas",
  145.    " 87 - ASCII download",
  146.    " 88 - Resume download",
  147.    " 89 - Verbose message list",
  148.    " 90 - Time statistics",
  149.    " 91 - Show account",
  150.    " 92 - Deposit time",
  151.    " 93 - Withdraw time",
  152.    " 94 - N/A",
  153.    " 95 - Who is where",
  154.    " 96 - CB-chat system",
  155.    " 97 - Display file (system)",
  156.    " 98 - Display last callers",
  157.    " 99 - Set alias",
  158.    " 100 - Set voice phone",
  159.    " 101 - Set data phone",
  160.    " 102 - Archive contents",
  161.    " 103 - N/A",
  162.    " 104 - Set counter",
  163.    " 105 - Usage graphic",
  164.    " 106 - Set ho-keyed menu",
  165.    " 107 - Add to BBS-list",
  166.    " 108 - Short BBS list",
  167.    " 109 - Long BBS list",
  168.    " 110 - Change BBS-list",
  169.    " 111 - Remove BBS from list",
  170.    " 112 - QWK download",
  171.    " 113 - Upload replies",
  172.    " 114 - Deposit Kbytes",
  173.    " 115 - Withdraw Kbytes",
  174.    " 116 - Vote user",
  175.    " 117 - Set IBM characters",
  176.    " 118 - List areas w/new messages",
  177.    " 119 - Write message to disk",
  178.    " 120 - Download BBS-list",
  179.    " 121 - Set user group",
  180.    " 122 - Upload to filebox",
  181.    " 123 - Download from filebox",
  182.    " 124 - Set birthdate",
  183.    " 125 - Set default protocol",
  184.    " 126 - Set default archiver",
  185.    " 127 - Kill from filebox",
  186.    " 128 - List file in filebox",
  187.    " 129 - List/Remove tagged files",
  188.    " 130 - Set view kludge lines",
  189.    " 131 - BlueWave download",
  190.    NULL
  191. };
  192.  
  193. static int last_sel;
  194.  
  195. int winputs (int wy, int wx, char *stri, char *fmt, int mode, char pad, int fieldattr, int textattr)
  196. {
  197.    int linelimit, pos;
  198.    unsigned int c;
  199.    char *result, *tmp, str[2], first;
  200.  
  201.    linelimit = strlen (fmt);
  202.  
  203.    if ((result = (char *)malloc (linelimit + 1)) == NULL)
  204.       return (-1);
  205.  
  206.    if ((tmp = (char *)malloc (linelimit + 1)) == NULL) {
  207.       free (result);
  208.       return (-1);
  209.    }
  210.  
  211.    memset (tmp, pad, linelimit);
  212.    tmp[linelimit] = '\0';
  213.    wprints (wy, wx, fieldattr, tmp);
  214.  
  215.    if (mode == 0)
  216.       strcpy (result, "");
  217.    else
  218.       strcpy (result, stri);
  219.  
  220.    if (mode == 2)
  221.       first = 1;
  222.    else
  223.       first = 0;
  224.  
  225.    pos = strlen (result);
  226.    wprints (wy, wx, textattr, result);
  227.    wgotoxy (wy, wx + pos);
  228.  
  229.    showcur ();
  230.  
  231.    for (;;) {
  232.       VioUpdate ();
  233.       c = getxch ();
  234.  
  235.       if ((c & 0xFF) != 0) {
  236.          c &= 0xFF;
  237.  
  238.          if (c >= 32 && c <= 255) {
  239.             if (first) {
  240.                memset (tmp, pad, linelimit);
  241.                tmp[linelimit] = '\0';
  242.                wprints (wy, wx, fieldattr, tmp);
  243.  
  244.                strcpy (result, "");
  245.                first = 0;
  246.  
  247.                pos = strlen (result);
  248.                wprints (wy, wx, textattr, result);
  249.                wgotoxy (wy, wx + pos);
  250.             }
  251.  
  252.             if (strlen (result) < linelimit) {
  253.                str[0] = c;
  254.                str[1] = '\0';
  255.  
  256.                strcpy (tmp, &result[pos]);
  257.                strcpy (&result[pos], str);
  258.                strcat (&result[pos], tmp);
  259.                result[linelimit] = '\0';
  260.  
  261.                if (pos < linelimit - 1)
  262.                   pos++;
  263.  
  264.                wprints (wy, wx, textattr, result);
  265.                wgotoxy (wy, wx + pos);
  266.             }
  267.          }
  268.  
  269.          else if (c == 0x08) {
  270.             first = 0;
  271.  
  272.             if (pos) {
  273.                strcpy (&result[pos - 1], &result[pos]);
  274.                pos--;
  275.  
  276.                wprints (wy, wx, textattr, result);
  277.                wgotoxy (wy, wx + pos);
  278.  
  279.                memset (tmp, pad, linelimit);
  280.                tmp[linelimit] = '\0';
  281.                wprints (wy, wx + strlen (result), fieldattr, &tmp[strlen (result)]);
  282.             }
  283.          }
  284.  
  285.          else if (c == 0x0D || c == 0x1B)
  286.             break;
  287.  
  288.          else {
  289.             if (first) {
  290.                memset (tmp, pad, linelimit);
  291.                tmp[linelimit] = '\0';
  292.                wprints (wy, wx, fieldattr, tmp);
  293.  
  294.                strcpy (result, "");
  295.                first = 0;
  296.  
  297.                pos = strlen (result);
  298.                wprints (wy, wx, textattr, result);
  299.                wgotoxy (wy, wx + pos);
  300.             }
  301.  
  302.             if (strlen (result) < linelimit) {
  303.                str[0] = c;
  304.                str[1] = '\0';
  305.  
  306.                strcpy (tmp, &result[pos]);
  307.                strcpy (&result[pos], str);
  308.                strcat (&result[pos], tmp);
  309.                result[linelimit] = '\0';
  310.  
  311.                if (pos < linelimit - 1)
  312.                   pos++;
  313.  
  314.                wprints (wy, wx, textattr, result);
  315.                wgotoxy (wy, wx + pos);
  316.             }
  317.          }
  318.       }
  319.  
  320.       // DEL
  321.       else if (c == 0x5300) {
  322.          first = 0;
  323.  
  324.          if (result[pos]) {
  325.             strcpy (&result[pos], &result[pos + 1]);
  326.  
  327.             wprints (wy, wx, textattr, result);
  328.             wgotoxy (wy, wx + pos);
  329.  
  330.             memset (tmp, pad, linelimit);
  331.             tmp[linelimit] = '\0';
  332.             wprints (wy, wx + strlen (result), fieldattr, &tmp[strlen (result)]);
  333.          }
  334.       }
  335.  
  336.       else if (c == 0x4B00) {
  337.          first = 0;
  338.  
  339.          if (pos) {
  340.             pos--;
  341.             wgotoxy (wy, wx + pos);
  342.          }
  343.       }
  344.  
  345.       else if (c == 0x4D00) {
  346.          first = 0;
  347.  
  348.          if (result[pos]) {
  349.             pos++;
  350.             wgotoxy (wy, wx + pos);
  351.          }
  352.       }
  353.  
  354.       else if (c == 0x4700) {
  355.          first = 0;
  356.  
  357.          pos = 0;
  358.          wgotoxy (wy, wx + pos);
  359.       }
  360.  
  361.       else if (c == 0x4F00) {
  362.          first = 0;
  363.  
  364.          pos = strlen (result);
  365.          if (pos >= linelimit - 1)
  366.             pos--;
  367.          wgotoxy (wy, wx + pos);
  368.       }
  369.  
  370.       else if (c == 0x7400) {
  371.          first = 0;
  372.  
  373.          while (result[pos] != ' ' && result[pos] != '\0')
  374.             pos++;
  375.          while (result[pos] == ' ')
  376.             pos++;
  377.          if (!result[pos])
  378.             pos--;
  379.          wgotoxy (wy, wx + pos);
  380.       }
  381.  
  382.       else if (c == 0x7300) {
  383.          first = 0;
  384.  
  385.          if (pos) {
  386.             if (result[pos] == ' ' || result[pos - 1] == ' ') {
  387.                pos--;
  388.                while (pos && result[pos] == ' ')
  389.                   pos--;
  390.             }
  391.             while (result[pos] != ' ' && pos)
  392.                pos--;
  393.             if (result[pos] == ' ')
  394.                pos++;
  395.             wgotoxy (wy, wx + pos);
  396.          }
  397.       }
  398.    }
  399.  
  400.    if (c == 0x0D)
  401.       strcpy (stri, result);
  402.  
  403.    free (result);
  404.    free (tmp);
  405.  
  406.    return (c == 0x0D ? 0 : W_ESCPRESS);
  407. }
  408.  
  409. static void set_selection (void)
  410. {
  411.    struct _item_t *item;
  412.  
  413.    item = wmenuicurr ();
  414.    last_sel = item->tagid;
  415. }
  416.  
  417. static int select_menu_type (int start)
  418. {
  419.    int i, wh;
  420.  
  421.    wh = wopen (5, 28, 18, 51, 3, LCYAN|_BLACK, LCYAN|_BLACK);
  422.    wactiv (wh);
  423.    wshadow (DGREY|_BLACK);
  424.    wtitle (" Menu types ", TRIGHT, YELLOW|_BLUE);
  425.  
  426.    wmenubegc ();
  427.    wmenuitem (0, 0, " Moving between menus ", 'M', 1000, 0, NULL, 0, 0);
  428.       wmenubeg (9, 40, 19, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  429.       wmenuitem (0, 0, menu_types[14], 0, 14, M_CLALL, set_selection, 0, 0);
  430.       wmenuitem (1, 0, menu_types[15], 0, 15, M_CLALL, set_selection, 0, 0);
  431.       wmenuitem (2, 0, menu_types[16], 0, 16, M_CLALL, set_selection, 0, 0);
  432.       wmenuitem (3, 0, menu_types[21], 0, 21, M_CLALL, set_selection, 0, 0);
  433.       wmenuitem (4, 0, menu_types[61], 0, 61, M_CLALL, set_selection, 0, 0);
  434.       wmenuitem (5, 0, menu_types[66], 0, 66, M_CLALL, set_selection, 0, 0);
  435.       wmenuitem (6, 0, menu_types[67], 0, 67, M_CLALL, set_selection, 0, 0);
  436.       wmenuitem (7, 0, menu_types[1], 0, 1, M_CLALL, set_selection, 0, 0);
  437.       wmenuitem (8, 0, menu_types[2], 0, 2, M_CLALL, set_selection, 0, 0);
  438.       wmenuend (14, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  439.    wmenuitem (1, 0, " Message areas ", 'F', 2000, 0, NULL, 0, 0);
  440.       wmenubeg (4, 38, 21, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  441.       wmenuitem (0, 0, menu_types[19], 0, 19, M_CLALL, set_selection, 0, 0);
  442.       wmenuitem (1, 0, menu_types[40], 0, 40, M_CLALL, set_selection, 0, 0);
  443.       wmenuitem (2, 0, menu_types[41], 0, 41, M_CLALL, set_selection, 0, 0);
  444.       wmenuitem (3, 0, menu_types[53], 0, 53, M_CLALL, set_selection, 0, 0);
  445.       wmenuitem (4, 0, menu_types[54], 0, 54, M_CLALL, set_selection, 0, 0);
  446.       wmenuitem (5, 0, menu_types[55], 0, 55, M_CLALL, set_selection, 0, 0);
  447.       wmenuitem (6, 0, menu_types[56], 0, 56, M_CLALL, set_selection, 0, 0);
  448.       wmenuitem (7, 0, menu_types[57], 0, 57, M_CLALL, set_selection, 0, 0);
  449.       wmenuitem (8, 0, menu_types[58], 0, 58, M_CLALL, set_selection, 0, 0);
  450.       wmenuitem (9, 0, menu_types[59], 0, 59, M_CLALL, set_selection, 0, 0);
  451.       wmenuitem (10, 0, menu_types[60], 0, 60, M_CLALL, set_selection, 0, 0);
  452.       wmenuitem (11, 0, menu_types[63], 0, 63, M_CLALL, set_selection, 0, 0);
  453.       wmenuitem (12, 0, menu_types[64], 0, 64, M_CLALL, set_selection, 0, 0);
  454.       wmenuitem (13, 0, menu_types[89], 0, 89, M_CLALL, set_selection, 0, 0);
  455.       wmenuitem (14, 0, menu_types[118], 0, 118, M_CLALL, set_selection, 0, 0);
  456.       wmenuitem (15, 0, menu_types[119], 0, 119, M_CLALL, set_selection, 0, 0);
  457.       wmenuend (19, M_OMNI|M_PD|M_SAVE, 35, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  458.    wmenuitem (2, 0, " File areas ", 'F', 3000, 0, NULL, 0, 0);
  459.       wmenubeg (4, 40, 21, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  460.       wmenuitem (0, 0, menu_types[22], 0, 22, M_CLALL, set_selection, 0, 0);
  461.       wmenuitem (1, 0, menu_types[23], 0, 23, M_CLALL, set_selection, 0, 0);
  462.       wmenuitem (2, 0, menu_types[24], 0, 24, M_CLALL, set_selection, 0, 0);
  463.       wmenuitem (3, 0, menu_types[25], 0, 25, M_CLALL, set_selection, 0, 0);
  464.       wmenuitem (4, 0, menu_types[65], 0, 65, M_CLALL, set_selection, 0, 0);
  465.       wmenuitem (5, 0, menu_types[68], 0, 68, M_CLALL, set_selection, 0, 0);
  466.       wmenuitem (6, 0, menu_types[69], 0, 69, M_CLALL, set_selection, 0, 0);
  467.       wmenuitem (7, 0, menu_types[72], 0, 72, M_CLALL, set_selection, 0, 0);
  468.       wmenuitem (8, 0, menu_types[73], 0, 73, M_CLALL, set_selection, 0, 0);
  469.       wmenuitem (9, 0, menu_types[84], 0, 84, M_CLALL, set_selection, 0, 0);
  470.       wmenuitem (10, 0, menu_types[102], 0, 102, M_CLALL, set_selection, 0, 0);
  471.       wmenuitem (11, 0, menu_types[122], 0, 122, M_CLALL, set_selection, 0, 0);
  472.       wmenuitem (12, 0, menu_types[123], 0, 123, M_CLALL, set_selection, 0, 0);
  473.       wmenuitem (13, 0, menu_types[127], 0, 127, M_CLALL, set_selection, 0, 0);
  474.       wmenuitem (14, 0, menu_types[128], 0, 128, M_CLALL, set_selection, 0, 0);
  475.       wmenuitem (15, 0, menu_types[129], 0, 129, M_CLALL, set_selection, 0, 0);
  476.       wmenuend (22, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  477.    wmenuitem (3, 0, " User configuration 1", 'F', 4000, 0, NULL, 0, 0);
  478.       wmenubeg (4, 40, 18, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  479.       wmenuitem (0, 0, menu_types[27], 0, 27, M_CLALL, set_selection, 0, 0);
  480.       wmenuitem (1, 0, menu_types[28], 0, 28, M_CLALL, set_selection, 0, 0);
  481.       wmenuitem (2, 0, menu_types[29], 0, 29, M_CLALL, set_selection, 0, 0);
  482.       wmenuitem (3, 0, menu_types[30], 0, 30, M_CLALL, set_selection, 0, 0);
  483.       wmenuitem (4, 0, menu_types[32], 0, 32, M_CLALL, set_selection, 0, 0);
  484.       wmenuitem (5, 0, menu_types[33], 0, 33, M_CLALL, set_selection, 0, 0);
  485.       wmenuitem (6, 0, menu_types[34], 0, 34, M_CLALL, set_selection, 0, 0);
  486.       wmenuitem (7, 0, menu_types[35], 0, 35, M_CLALL, set_selection, 0, 0);
  487.       wmenuitem (8, 0, menu_types[36], 0, 36, M_CLALL, set_selection, 0, 0);
  488.       wmenuitem (9, 0, menu_types[37], 0, 37, M_CLALL, set_selection, 0, 0);
  489.       wmenuitem (10, 0, menu_types[38], 0, 38, M_CLALL, set_selection, 0, 0);
  490.       wmenuitem (11, 0, menu_types[39], 0, 39, M_CLALL, set_selection, 0, 0);
  491.       wmenuitem (12, 0, menu_types[70], 0, 70, M_CLALL, set_selection, 0, 0);
  492.       wmenuend (27, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  493.    wmenuitem (4, 0, " User configuration 2", 'F', 4500, 0, NULL, 0, 0);
  494.       wmenubeg (7, 40, 19, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  495.       wmenuitem (0, 0, menu_types[77], 0, 77, M_CLALL, set_selection, 0, 0);
  496.       wmenuitem (1, 0, menu_types[99], 0, 99, M_CLALL, set_selection, 0, 0);
  497.       wmenuitem (2, 0, menu_types[100], 0, 100, M_CLALL, set_selection, 0, 0);
  498.       wmenuitem (3, 0, menu_types[101], 0, 101, M_CLALL, set_selection, 0, 0);
  499.       wmenuitem (4, 0, menu_types[106], 0, 106, M_CLALL, set_selection, 0, 0);
  500.       wmenuitem (5, 0, menu_types[117], 0, 117, M_CLALL, set_selection, 0, 0);
  501.       wmenuitem (6, 0, menu_types[121], 0, 121, M_CLALL, set_selection, 0, 0);
  502.       wmenuitem (7, 0, menu_types[124], 0, 124, M_CLALL, set_selection, 0, 0);
  503.       wmenuitem (8, 0, menu_types[125], 0, 125, M_CLALL, set_selection, 0, 0);
  504.       wmenuitem (9, 0, menu_types[126], 0, 126, M_CLALL, set_selection, 0, 0);
  505.       wmenuitem (10, 0, menu_types[130], 0, 130, M_CLALL, set_selection, 0, 0);
  506.       wmenuend (77, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  507.    wmenuitem (5, 0, " Line editor ", 'F', 5000, 0, NULL, 0, 0);
  508.       wmenubeg (9, 40, 19, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  509.       wmenuitem (0, 0, menu_types[42], 0, 42, M_CLALL, set_selection, 0, 0);
  510.       wmenuitem (1, 0, menu_types[43], 0, 43, M_CLALL, set_selection, 0, 0);
  511.       wmenuitem (2, 0, menu_types[44], 0, 44, M_CLALL, set_selection, 0, 0);
  512.       wmenuitem (3, 0, menu_types[45], 0, 45, M_CLALL, set_selection, 0, 0);
  513.       wmenuitem (4, 0, menu_types[46], 0, 46, M_CLALL, set_selection, 0, 0);
  514.       wmenuitem (5, 0, menu_types[47], 0, 47, M_CLALL, set_selection, 0, 0);
  515.       wmenuitem (6, 0, menu_types[48], 0, 48, M_CLALL, set_selection, 0, 0);
  516.       wmenuitem (7, 0, menu_types[49], 0, 49, M_CLALL, set_selection, 0, 0);
  517.       wmenuitem (8, 0, menu_types[50], 0, 50, M_CLALL, set_selection, 0, 0);
  518.       wmenuend (42, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  519.    wmenuitem (6, 0, " Personal mail ", 'F', 6000, 0, NULL, 0, 0);
  520.       wmenubeg (9, 40, 15, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  521.       wmenuitem (0, 0, menu_types[74], 0, 74, M_CLALL, set_selection, 0, 0);
  522.       wmenuitem (1, 0, menu_types[75], 0, 75, M_CLALL, set_selection, 0, 0);
  523.       wmenuitem (2, 0, menu_types[76], 0, 76, M_CLALL, set_selection, 0, 0);
  524.       wmenuitem (3, 0, menu_types[82], 0, 82, M_CLALL, set_selection, 0, 0);
  525.       wmenuitem (4, 0, menu_types[85], 0, 85, M_CLALL, set_selection, 0, 0);
  526.       wmenuend (74, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  527.    wmenuitem (7, 0, " Multiline chat ", 'F', 7000, 0, NULL, 0, 0);
  528.       wmenubeg (9, 40, 14, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  529.       wmenuitem (0, 0, menu_types[78], 0, 78, M_CLALL, set_selection, 0, 0);
  530.       wmenuitem (1, 0, menu_types[81], 0, 81, M_CLALL, set_selection, 0, 0);
  531.       wmenuitem (2, 0, menu_types[95], 0, 95, M_CLALL, set_selection, 0, 0);
  532.       wmenuitem (3, 0, menu_types[96], 0, 96, M_CLALL, set_selection, 0, 0);
  533.       wmenuend (78, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  534.    wmenuitem (8, 0, " Offline reader ", 'F', 8000, 0, NULL, 0, 0);
  535.       wmenubeg (9, 40, 16, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  536.       wmenuitem (0, 0, menu_types[86], 0, 86, M_CLALL, set_selection, 0, 0);
  537.       wmenuitem (1, 0, menu_types[87], 0, 87, M_CLALL, set_selection, 0, 0);
  538.       wmenuitem (2, 0, menu_types[88], 0, 88, M_CLALL, set_selection, 0, 0);
  539.       wmenuitem (3, 0, menu_types[112], 0, 112, M_CLALL, set_selection, 0, 0);
  540.       wmenuitem (4, 0, menu_types[113], 0, 113, M_CLALL, set_selection, 0, 0);
  541.       wmenuitem (5, 0, menu_types[131], 0, 131, M_CLALL, set_selection, 0, 0);
  542.       wmenuend (86, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  543.    wmenuitem (9, 0, " Built-in doors ", 'F', 8500, 0, NULL, 0, 0);
  544.       wmenubeg (6, 40, 18, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  545.       wmenuitem (0, 0, menu_types[91], 0, 91, M_CLALL, set_selection, 0, 0);
  546.       wmenuitem (1, 0, menu_types[92], 0, 92, M_CLALL, set_selection, 0, 0);
  547.       wmenuitem (2, 0, menu_types[93], 0, 93, M_CLALL, set_selection, 0, 0);
  548.       wmenuitem (3, 0, menu_types[114], 0, 114, M_CLALL, set_selection, 0, 0);
  549.       wmenuitem (4, 0, menu_types[115], 0, 115, M_CLALL, set_selection, 0, 0);
  550.       wmenuitem (5, 0, menu_types[107], 0, 107, M_CLALL, set_selection, 0, 0);
  551.       wmenuitem (6, 0, menu_types[108], 0, 108, M_CLALL, set_selection, 0, 0);
  552.       wmenuitem (7, 0, menu_types[109], 0, 109, M_CLALL, set_selection, 0, 0);
  553.       wmenuitem (8, 0, menu_types[110], 0, 110, M_CLALL, set_selection, 0, 0);
  554.       wmenuitem (9, 0, menu_types[111], 0, 111, M_CLALL, set_selection, 0, 0);
  555.       wmenuitem (10, 0, menu_types[120], 0, 120, M_CLALL, set_selection, 0, 0);
  556.       wmenuend (91, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  557.    wmenuitem (10, 0, " Miscellaneous 1", 'F', 9000, 0, NULL, 0, 0);
  558.       wmenubeg (6, 40, 18, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  559.       wmenuitem (0, 0, menu_types[0], 0, 999, M_CLALL, set_selection, 0, 0);
  560.       wmenuitem (1, 0, menu_types[3], 0, 3, M_CLALL, set_selection, 0, 0);
  561.       wmenuitem (2, 0, menu_types[5], 0, 5, M_CLALL, set_selection, 0, 0);
  562.       wmenuitem (3, 0, menu_types[6], 0, 6, M_CLALL, set_selection, 0, 0);
  563.       wmenuitem (4, 0, menu_types[7], 0, 7, M_CLALL, set_selection, 0, 0);
  564.       wmenuitem (5, 0, menu_types[8], 0, 8, M_CLALL, set_selection, 0, 0);
  565.       wmenuitem (6, 0, menu_types[9], 0, 9, M_CLALL, set_selection, 0, 0);
  566.       wmenuitem (7, 0, menu_types[10], 0, 10, M_CLALL, set_selection, 0, 0);
  567.       wmenuitem (8, 0, menu_types[11], 0, 11, M_CLALL, set_selection, 0, 0);
  568.       wmenuitem (9, 0, menu_types[13], 0, 13, M_CLALL, set_selection, 0, 0);
  569.       wmenuitem (10, 0, menu_types[17], 0, 17, M_CLALL, set_selection, 0, 0);
  570.       wmenuend (999, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  571.    wmenuitem (11, 0, " Miscellaneous 2", 'F', 9500, 0, NULL, 0, 0);
  572.       wmenubeg (6, 40, 15, 73, 3, LCYAN|_BLACK, LCYAN|_BLACK, NULL);
  573.       wmenuitem (0, 0, menu_types[51], 0, 51, M_CLALL, set_selection, 0, 0);
  574.       wmenuitem (1, 0, menu_types[71], 0, 71, M_CLALL, set_selection, 0, 0);
  575.       wmenuitem (2, 0, menu_types[83], 0, 83, M_CLALL, set_selection, 0, 0);
  576.       wmenuitem (3, 0, menu_types[90], 0, 90, M_CLALL, set_selection, 0, 0);
  577.       wmenuitem (4, 0, menu_types[97], 0, 97, M_CLALL, set_selection, 0, 0);
  578.       wmenuitem (5, 0, menu_types[98], 0, 98, M_CLALL, set_selection, 0, 0);
  579.       wmenuitem (6, 0, menu_types[104], 0, 104, M_CLALL, set_selection, 0, 0);
  580.       wmenuitem (7, 0, menu_types[105], 0, 105, M_CLALL, set_selection, 0, 0);
  581.       wmenuend (51, M_OMNI|M_PD|M_SAVE, 33, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  582.  
  583.    wmenuend (1000, M_OMNI, 22, 0, LGREY|_BLACK, LGREY|_BLACK, DGREY|_BLACK, BLUE|_LGREY);
  584.  
  585.    last_sel = -1;
  586.    i = wmenuget ();
  587.    if (last_sel == 999)
  588.       last_sel = 0;
  589.    wclose ();
  590.  
  591.    return (i == -1 ? start : last_sel);
  592. }
  593.  
  594. int select_color (int color)
  595. {
  596.    int x, y, i, wh;
  597.  
  598.    wh = wopen (7, 30, 16, 47, 1, LCYAN|_BLACK, CYAN|_BLACK);
  599.    wactiv (wh);
  600.    wshadow (DGREY|_BLACK);
  601.    wtitle (" Colors ", TRIGHT, YELLOW|_BLUE);
  602.  
  603.    for (y = 0; y < 8; y++) {
  604.       for (x = 0; x < 16; x++)
  605.          wprints (y, x, x | (y << 4), "");
  606.    }
  607.  
  608.    x = color & 0x0F;
  609.    y = (color & 0xF0) >> 4;
  610.  
  611.    wprints (y, x, LGREY|_BLACK, "");
  612.  
  613.    for (;;) {
  614.       i = getxch ();
  615.       if ( (i & 0xFF) != 0 )
  616.          i &= 0xFF;
  617.  
  618.       switch (i) {
  619.          case 0x4800:
  620.             if (y > 0) {
  621.                wprints (y, x, x | (y << 4), "");
  622.                y--;
  623.                wprints (y, x, LGREY|_BLACK, "");
  624.             }
  625.             break;
  626.  
  627.          case 0x5000:
  628.             if (y < 7) {
  629.                wprints (y, x, x | (y << 4), "");
  630.                y++;
  631.                wprints (y, x, LGREY|_BLACK, "");
  632.             }
  633.             break;
  634.  
  635.          case 0x4B00:
  636.             if (x > 0) {
  637.                wprints (y, x, x | (y << 4), "");
  638.                x--;
  639.                wprints (y, x, LGREY|_BLACK, "");
  640.             }
  641.             break;
  642.  
  643.          case 0x4D00:
  644.             if (x < 15) {
  645.                wprints (y, x, x | (y << 4), "");
  646.                x++;
  647.                wprints (y, x, LGREY|_BLACK, "");
  648.             }
  649.             break;
  650.       }
  651.  
  652.       if (i == 0x1B) {
  653.          color = -1;
  654.          break;
  655.       }
  656.       else if (i == 0x0D) {
  657.          color = x | (y << 4);
  658.          break;
  659.       }
  660.    }
  661.  
  662.    wclose ();
  663.    return (color);
  664. }
  665.  
  666. static int edit_single_item (struct _cmd *cmd)
  667. {
  668.    int i = 1, wh1;
  669.    char string[80];
  670.    struct _cmd mi;
  671.  
  672.    memcpy (&mi, cmd, sizeof (struct _cmd));
  673.  
  674.    gotoxy_ (24, 1);
  675.    clreol_ ();
  676.    prints (24, 1, LGREY|_BLACK, "ESC-Exit/Save  ENTER-Edit");
  677.    prints (24, 1, YELLOW|_BLACK, "ESC");
  678.    prints (24, 16, YELLOW|_BLACK, "ENTER");
  679.  
  680. continue_editing:
  681.    do {
  682.       stop_update ();
  683.       wclear ();
  684.  
  685.       wmenubegc ();
  686.       wprints (0, 16, LGREY|_BLACK, "0....5...10...15...20...25...30...35...40...45...50...55.");
  687.  
  688.       wmenuitem ( 1, 1, " Display      ", 0,  1, 0, NULL, 0, 0);
  689.       wmenuitem ( 2, 1, " Type         ", 0,  2, 0, NULL, 0, 0);
  690.       wmenuitem ( 3, 1, " Data         ", 0,  3, 0, NULL, 0, 0);
  691.       wmenuitem ( 4, 1, " Hot-key      ", 0,  4, 0, NULL, 0, 0);
  692.       wmenuitem ( 5, 1, " Automatic    ", 0,  5, 0, NULL, 0, 0);
  693.       wmenuitem ( 6, 1, " First time   ", 0,  6, 0, NULL, 0, 0);
  694.       wmenuitem ( 7, 1, " Hide display ", 0,  7, 0, NULL, 0, 0);
  695.       wmenuitem ( 8, 1, " Color        ", 0,  8, 0, NULL, 0, 0);
  696.       wmenuitem ( 9, 1, " Hilight      ", 0,  9, 0, NULL, 0, 0);
  697.       wmenuitem (10, 1, " Security     ", 0, 10, 0, NULL, 0, 0);
  698.       wmenuitem (11, 1, " Flags-A      ", 0, 11, 0, NULL, 0, 0);
  699.       wmenuitem (12, 1, " Flags-B      ", 0, 12, 0, NULL, 0, 0);
  700.       wmenuitem (13, 1, " Flags-C      ", 0, 13, 0, NULL, 0, 0);
  701.       wmenuitem (14, 1, " Flags-D      ", 0, 14, 0, NULL, 0, 0);
  702.       wmenuend (i, M_VERT|M_SAVE, 0, 0, LGREY|_BLACK, LGREY|_BLACK, LGREY|_BLACK, BLUE|_LGREY);
  703.  
  704.       wprints (1, 16, CYAN|_BLACK, mi.name);
  705.       wprints (2, 15, CYAN|_BLACK, menu_types[mi.flag_type]);
  706.       wprints (3, 16, CYAN|_BLACK, mi.argument);
  707.       sprintf (string, "%c", mi.hotkey);
  708.       wprints (4, 16, CYAN|_BLACK, string);
  709.       if (mi.automatic)
  710.          wprints (5, 16, CYAN|_BLACK, "Yes");
  711.       else
  712.          wprints (5, 16, CYAN|_BLACK, "No");
  713.       if (mi.first_time)
  714.          wprints (6, 16, CYAN|_BLACK, "Yes");
  715.       else
  716.          wprints (6, 16, CYAN|_BLACK, "No");
  717.       if (mi.no_display)
  718.          wprints (7, 16, CYAN|_BLACK, "Yes");
  719.       else
  720.          wprints (7, 16, CYAN|_BLACK, "No");
  721.       wprints (8, 16, mi.color, "Sample color text");
  722.       wprints (9, 16, mi.first_color, "Sample color text");
  723.       wprints (10, 15, CYAN|_BLACK, get_priv_text (mi.priv));
  724.       wprints (11, 16, CYAN|_BLACK, get_flagA_text ((mi.flags >> 24) & 0xFF));
  725.       wprints (12, 16, CYAN|_BLACK, get_flagB_text ((mi.flags >> 16) & 0xFF));
  726.       wprints (13, 16, CYAN|_BLACK, get_flagC_text ((mi.flags >> 8) & 0xFF));
  727.       wprints (14, 16, CYAN|_BLACK, get_flagD_text (mi.flags & 0xFF));
  728.  
  729.       start_update ();
  730.       i = wmenuget ();
  731.  
  732.       switch (i) {
  733.          case 1:
  734.             strcpy (string, mi.name);
  735.             if (winputs (1, 16, string, "?????????????????????????????????????????????????????????", 1, '▒', BLUE|_GREEN, BLUE|_GREEN) != W_ESCPRESS)
  736.                strcpy (mi.name, string);
  737. //            winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  738. //            winpdef (1, 16, string, "?????????????????????????????????????????????????", 0, 1, NULL, 0);
  739. //            if (winpread () != W_ESCPRESS)
  740. //               strcpy (mi.name, strrtrim (string));
  741.             break;
  742.  
  743.          case 2:
  744.             mi.flag_type = select_menu_type (mi.flag_type);
  745.             break;
  746.  
  747.          case 3:
  748.             strcpy (string, mi.argument);
  749.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  750.             winpdef (3, 16, string, "?????????????????????????????????????????????????", 0, 1, NULL, 0);
  751.             if (winpread () != W_ESCPRESS)
  752.                strcpy (mi.argument, strbtrim (string));
  753.             break;
  754.  
  755.          case 4:
  756.             sprintf (string, "%c", mi.hotkey);
  757.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  758.             winpdef (4, 16, string, "?", 0, 1, NULL, 0);
  759.             if (winpread () != W_ESCPRESS)
  760.                mi.hotkey = toupper (string[0]);
  761.             break;
  762.  
  763.          case 5:
  764.             mi.automatic ^= 1;
  765.             break;
  766.  
  767.          case 6:
  768.             mi.first_time ^= 1;
  769.             break;
  770.  
  771.          case 7:
  772.             mi.no_display ^= 1;
  773.             break;
  774.  
  775.          case 8:
  776.             i = select_color (mi.color);
  777.             if (i != -1)
  778.                mi.color = i;
  779.             i = 8;
  780.             break;
  781.  
  782.          case 9:
  783.             i = select_color (mi.first_color);
  784.             if (i != -1)
  785.                mi.first_color = i;
  786.             i = 9;
  787.             break;
  788.  
  789.          case 10:
  790.             mi.priv = select_level (mi.priv, 47, 4);
  791.             break;
  792.  
  793.          case 11:
  794.             strcpy (string, get_flag_text ((mi.flags >> 24) & 0xFF));
  795.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  796.             winpdef (11, 16, string, "????????", 0, 1, NULL, 0);
  797.             if (winpread () != W_ESCPRESS) {
  798.                mi.flags &= 0x00FFFFFFL;
  799.                mi.flags |= recover_flags (string) << 24;
  800.             }
  801.             break;
  802.  
  803.          case 12:
  804.             strcpy (string, get_flag_text ((mi.flags >> 16) & 0xFF));
  805.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  806.             winpdef (12, 16, string, "????????", 0, 1, NULL, 0);
  807.             if (winpread () != W_ESCPRESS) {
  808.                mi.flags &= 0xFF00FFFFL;
  809.                mi.flags |= recover_flags (string) << 16;
  810.             }
  811.             break;
  812.  
  813.          case 13:
  814.             strcpy (string, get_flag_text ((mi.flags >> 8) & 0xFF));
  815.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  816.             winpdef (13, 16, string, "????????", 0, 1, NULL, 0);
  817.             if (winpread () != W_ESCPRESS) {
  818.                mi.flags &= 0xFFFF00FFL;
  819.                mi.flags |= recover_flags (string) << 8;
  820.             }
  821.             break;
  822.  
  823.          case 14:
  824.             strcpy (string, get_flag_text (mi.flags & 0xFF));
  825.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  826.             winpdef (14, 16, string, "????????", 0, 1, NULL, 0);
  827.             if (winpread () != W_ESCPRESS) {
  828.                mi.flags &= 0xFFFFFF00L;
  829.                mi.flags |= recover_flags (string);
  830.             }
  831.             break;
  832.       }
  833.  
  834.       hidecur ();
  835.    } while (i != -1);
  836.  
  837.    if (memcmp ((char *)&mi, (char *)cmd, sizeof (struct _cmd))) {
  838.       wh1 = wopen (10, 25, 14, 54, 0, BLACK|_LGREY, BLACK|_LGREY);
  839.       wactiv (wh1);
  840.       wshadow (DGREY|_BLACK);
  841.  
  842.       wcenters (1, BLACK|_LGREY, "Save changes (Y/n) ?  ");
  843.  
  844.       strcpy (string, "Y");
  845.       winpbeg (BLACK|_LGREY, BLACK|_LGREY);
  846.       winpdef (1, 24, string, "?", 0, 2, NULL, 0);
  847.  
  848.       i = winpread ();
  849.       wclose ();
  850.       hidecur ();
  851.  
  852.       if (i == W_ESCPRESS)
  853.          goto continue_editing;
  854.  
  855.       if (toupper (string[0]) == 'Y') {
  856.          memcpy ((char *)cmd, (char *)&mi, sizeof (struct _cmd));
  857.          i = 1;
  858.       }
  859.       else
  860.          i = 0;
  861.    }
  862.    else
  863.       i = 0;
  864.  
  865.    gotoxy_ (24, 1);
  866.    clreol_ ();
  867.    prints (24, 1, LGREY|_BLACK, "PgUp/PgDn-Next/Previous  E-Edit  A-Add  C-Copy  L-List  D-Delete  S-Show");
  868.    prints (24, 1, YELLOW|_BLACK, "PgUp/PgDn");
  869.    prints (24, 26, YELLOW|_BLACK, "E");
  870.    prints (24, 34, YELLOW|_BLACK, "A");
  871.    prints (24, 41, YELLOW|_BLACK, "C");
  872.    prints (24, 49, YELLOW|_BLACK, "L");
  873.    prints (24, 57, YELLOW|_BLACK, "D");
  874.    prints (24, 67, YELLOW|_BLACK, "S");
  875.  
  876.  
  877.    return (i);
  878. }
  879.  
  880. static void edit_menu_items (char *file, char *name)
  881. {
  882.    FILE *fp, *fpd;
  883.    int fd, i, beg = 0, wh, elements, wh1;
  884.    char filename[80], string[80], newname[30];
  885.    long crc;
  886.    struct _menu_header mh;
  887.    struct _cmd mi;
  888.  
  889.    memset (&mi, 0, sizeof (struct _cmd));
  890.  
  891.    sprintf (filename, "%s%s.MNU", config.menu_path, file);
  892.    fd = sh_open (filename, SH_DENYWR, O_RDONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  893.    if (fd == -1)
  894.       return;
  895.  
  896.    i = 0;
  897.    while (read (fd, &mh, sizeof (struct _menu_header)) == sizeof (struct _menu_header)) {
  898.       if (!stricmp (mh.name, name))
  899.          break;
  900.       lseek (fd, (long)sizeof(struct _cmd) * mh.n_elem, SEEK_CUR);
  901.    }
  902.  
  903.    cmd = (struct _cmd *)malloc (MAX_ITEMS * sizeof (struct _cmd));
  904.    if (cmd == NULL)
  905.       return;
  906.  
  907.    i = mh.n_elem;
  908.    if (i > MAX_ITEMS)
  909.       i = MAX_ITEMS;
  910.  
  911.    read (fd, (char *)cmd, sizeof (struct _cmd) * i);
  912.    close (fd);
  913.  
  914.    crc = get_menu_crc (i);
  915.    elements = mh.n_elem;
  916.  
  917.    gotoxy_ (24, 1);
  918.    clreol_ ();
  919.    prints (24, 1, LGREY|_BLACK, "PgUp/PgDn-Next/Previous  E-Edit  A-Add  C-Copy  L-List  D-Delete  S-Show");
  920.    prints (24, 1, YELLOW|_BLACK, "PgUp/PgDn");
  921.    prints (24, 26, YELLOW|_BLACK, "E");
  922.    prints (24, 34, YELLOW|_BLACK, "A");
  923.    prints (24, 41, YELLOW|_BLACK, "C");
  924.    prints (24, 49, YELLOW|_BLACK, "L");
  925.    prints (24, 57, YELLOW|_BLACK, "D");
  926.    prints (24, 67, YELLOW|_BLACK, "S");
  927.  
  928.    wh = wopen (3, 1, 20, 76, 1, LCYAN|_BLACK, CYAN|_BLACK);
  929.    wactiv (wh);
  930.    wshadow (DGREY|_BLACK);
  931.    wtitle (" Menu ", TRIGHT, YELLOW|_BLUE);
  932.  
  933.    do {
  934.       stop_update ();
  935.       wclear ();
  936.       wprints (0, 16, LGREY|_BLACK, "0....5...10...15...20...25...30...35...40...45...50...55.");
  937.  
  938.       wprints ( 1, 1, LGREY|_BLACK, " Display      ");
  939.       wprints ( 2, 1, LGREY|_BLACK, " Type         ");
  940.       wprints ( 3, 1, LGREY|_BLACK, " Data         ");
  941.       wprints ( 4, 1, LGREY|_BLACK, " Hot-key      ");
  942.       wprints ( 5, 1, LGREY|_BLACK, " Automatic    ");
  943.       wprints ( 6, 1, LGREY|_BLACK, " First time   ");
  944.       wprints ( 7, 1, LGREY|_BLACK, " Hide display ");
  945.       wprints ( 8, 1, LGREY|_BLACK, " Color        ");
  946.       wprints ( 9, 1, LGREY|_BLACK, " Hilight      ");
  947.       wprints (10, 1, LGREY|_BLACK, " Security     ");
  948.       wprints (11, 1, LGREY|_BLACK, " Flags-A      ");
  949.       wprints (12, 1, LGREY|_BLACK, " Flags-B      ");
  950.       wprints (13, 1, LGREY|_BLACK, " Flags-C      ");
  951.       wprints (14, 1, LGREY|_BLACK, " Flags-D      ");
  952.  
  953.       if (mh.n_elem) {
  954.          wprints (1, 16, CYAN|_BLACK, cmd[beg].name);
  955.          wprints (2, 15, CYAN|_BLACK, menu_types[cmd[beg].flag_type]);
  956.          wprints (3, 16, CYAN|_BLACK, cmd[beg].argument);
  957.          sprintf (string, "%c", cmd[beg].hotkey);
  958.          wprints (4, 16, CYAN|_BLACK, string);
  959.          if (cmd[beg].automatic)
  960.             wprints (5, 16, CYAN|_BLACK, "Yes");
  961.          else
  962.             wprints (5, 16, CYAN|_BLACK, "No");
  963.          if (cmd[beg].first_time)
  964.             wprints (6, 16, CYAN|_BLACK, "Yes");
  965.          else
  966.             wprints (6, 16, CYAN|_BLACK, "No");
  967.          if (cmd[beg].no_display)
  968.             wprints (7, 16, CYAN|_BLACK, "Yes");
  969.          else
  970.             wprints (7, 16, CYAN|_BLACK, "No");
  971.          wprints (8, 16, cmd[beg].color, "Sample color text");
  972.          wprints (9, 16, cmd[beg].first_color, "Sample color text");
  973.          wprints (10, 15, CYAN|_BLACK, get_priv_text (cmd[beg].priv));
  974.          wprints (11, 16, CYAN|_BLACK, get_flagA_text ((cmd[beg].flags >> 24) & 0xFF));
  975.          wprints (12, 16, CYAN|_BLACK, get_flagB_text ((cmd[beg].flags >> 16) & 0xFF));
  976.          wprints (13, 16, CYAN|_BLACK, get_flagC_text ((cmd[beg].flags >> 8) & 0xFF));
  977.          wprints (14, 16, CYAN|_BLACK, get_flagD_text (cmd[beg].flags & 0xFF));
  978.       }
  979.  
  980.       start_update ();
  981.       i = getxch ();
  982.       if ( (i & 0xFF) != 0 )
  983.          i &= 0xFF;
  984.  
  985.       switch (i) {
  986.          // PgDn
  987.          case 0x5100:
  988.             if (beg < mh.n_elem - 1)
  989.                beg++;
  990.             break;
  991.  
  992.          // PgUp
  993.          case 0x4900:
  994.             if (beg > 0)
  995.                beg--;
  996.             break;
  997.  
  998.          // E Edit
  999.          case 'E':
  1000.          case 'e':
  1001.             if (mh.n_elem) {
  1002.                memcpy (&mi, &cmd[beg], sizeof (struct _cmd));
  1003.                edit_single_item (&mi);
  1004.                memcpy (&cmd[beg], &mi, sizeof (struct _cmd));
  1005.                break;
  1006.             }
  1007.             // Se si tratta del primo elemento, passa direttamente alla
  1008.             // funzione di add.
  1009.  
  1010.          // A Add
  1011.          case 'A':
  1012.          case 'a':
  1013.             if (elements + 1 >= MAX_ITEMS)
  1014.                break;
  1015.  
  1016.             memset (&mi, 0, sizeof (struct _cmd));
  1017.             if (mh.n_elem) {
  1018.                mi.color = cmd[beg].color;
  1019.                mi.first_color = cmd[beg].first_color;
  1020.                mi.priv = cmd[beg].priv;
  1021.             }
  1022.             else {
  1023.                mi.color = 15;
  1024.                mi.first_color = 14;
  1025.                mi.priv = TWIT;
  1026.             }
  1027.  
  1028.             if (edit_single_item (&mi)) {
  1029.                if (mh.n_elem) {
  1030.                   for (i = mh.n_elem - 1; i > beg; i--)
  1031.                      memcpy (&cmd[i + 1], &cmd[i], sizeof (struct _cmd));
  1032.  
  1033.                   beg++;
  1034.                   mh.n_elem++;
  1035.                   elements++;
  1036.                   memcpy (&cmd[beg], &mi, sizeof (struct _cmd));
  1037.                }
  1038.                else {
  1039.                   memcpy (&cmd[beg], &mi, sizeof (struct _cmd));
  1040.                   mh.n_elem++;
  1041.                   elements++;
  1042.                }
  1043.             }
  1044.  
  1045.             i = 'A';
  1046.             break;
  1047.  
  1048.          // Show
  1049.          case 'S':
  1050.          case 's':
  1051.             display_menu (elements);
  1052.             break;
  1053.  
  1054.          // L List
  1055.          case 'L':
  1056.          case 'l':
  1057.             beg = list_menu_items (beg, elements);
  1058.             break;
  1059.  
  1060.          // C Copy
  1061.          case 'C':
  1062.          case 'c':
  1063.             if (elements + 1 >= MAX_ITEMS)
  1064.                break;
  1065.  
  1066.             if (mh.n_elem) {
  1067.                for (i = mh.n_elem - 1; i > beg; i--)
  1068.                   memcpy (&cmd[i + 1], &cmd[i], sizeof (struct _cmd));
  1069.  
  1070.                beg++;
  1071.                mh.n_elem++;
  1072.                elements++;
  1073.                memcpy (&cmd[beg], &cmd[beg - 1], sizeof (struct _cmd));
  1074.             }
  1075.             i = 'C';
  1076.             break;
  1077.  
  1078.          // D Delete
  1079.          case 'D':
  1080.          case 'd':
  1081.             if (!elements)
  1082.                break;
  1083.  
  1084.             wh1 = wopen (10, 25, 14, 54, 0, BLACK|_LGREY, BLACK|_LGREY);
  1085.             wactiv (wh1);
  1086.             wshadow (DGREY|_BLACK);
  1087.  
  1088.             wcenters (1, BLACK|_LGREY, "Are you sure (Y/n) ?  ");
  1089.  
  1090.             strcpy (string, "Y");
  1091.             winpbeg (BLACK|_LGREY, BLACK|_LGREY);
  1092.             winpdef (1, 24, string, "?", 0, 2, NULL, 0);
  1093.  
  1094.             i = winpread ();
  1095.             wclose ();
  1096.             hidecur ();
  1097.  
  1098.             if (i == W_ESCPRESS)
  1099.                break;
  1100.  
  1101.             if (toupper (string[0]) == 'Y') {
  1102.                memset (&cmd[beg], 0, sizeof (struct _cmd));
  1103.                for (i = beg + 1; i < mh.n_elem; i++)
  1104.                   memcpy (&cmd[i - 1], &cmd[i], sizeof (struct _cmd));
  1105.                mh.n_elem--;
  1106.                elements--;
  1107.             }
  1108.  
  1109.             i = 'D';
  1110.             break;
  1111.  
  1112.          // ESC Exit
  1113.          case 0x1B:
  1114.             i = -1;
  1115.             break;
  1116.       }
  1117.  
  1118.    } while (i != -1);
  1119.  
  1120.    if (crc != get_menu_crc (elements)) {
  1121.       strcpy (newname, name);
  1122.  
  1123.       wh1 = wopen (14, 14, 16, 41, 1, LCYAN|_BLACK, CYAN|_BLACK);
  1124.       wactiv (wh1);
  1125.       wshadow (DGREY|_BLACK);
  1126.       wtitle (" Save ", TRIGHT, YELLOW|_BLUE);
  1127.       wprints (0, 1, LGREY|_BLACK, "Menu name: ");
  1128.       strcpy (filename, "");
  1129.       winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  1130.       winpdef (0, 12, filename, "?????????????", 0, 1, NULL, 0);
  1131.       wclose ();
  1132.  
  1133.       if (winpread () != W_ESCPRESS) {
  1134.          strcpy (newname, strupr (strbtrim (filename)));
  1135.          if (!newname[0])
  1136.             strcpy (newname, name);
  1137.       }
  1138.  
  1139.       update_message ();
  1140.  
  1141.       sprintf (filename, "%s%s.MNU", config.menu_path, file);
  1142.       fd = sh_open (filename, SH_DENYRW, O_RDONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  1143.       if (fd == -1)
  1144.          return;
  1145.       fp = fdopen (fd, "rb");
  1146.  
  1147.       sprintf (filename, "%s%s.NEW", config.menu_path, file);
  1148.       fd = sh_open (filename, SH_DENYRW, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  1149.       if (fd == -1)
  1150.          return;
  1151.       fpd = fdopen (fd, "wb");
  1152.  
  1153.       while (fread (&mh, 1, sizeof (struct _menu_header), fp) == sizeof (struct _menu_header)) {
  1154.          if (!stricmp (mh.name, name)) {
  1155.             fseek (fp, (long)sizeof(struct _cmd) * mh.n_elem, SEEK_CUR);
  1156.             mh.n_elem = elements;
  1157.             strcpy (mh.name, newname);
  1158.             if (mh.n_elem) {
  1159.                fwrite (&mh, sizeof (struct _menu_header), 1, fpd);
  1160.                fwrite ((char *)cmd, sizeof (struct _cmd) * mh.n_elem, 1, fpd);
  1161.             }
  1162.          }
  1163.          else {
  1164.             if (mh.n_elem) {
  1165.                fwrite (&mh, sizeof (struct _menu_header), 1, fpd);
  1166.                for (i = 0; i < mh.n_elem; i++) {
  1167.                   fread (&mi, sizeof (struct _cmd), 1, fp);
  1168.                   fwrite (&mi, sizeof (struct _cmd), 1, fpd);
  1169.                }
  1170.             }
  1171.          }
  1172.       }
  1173.  
  1174.       fclose (fp);
  1175.       fclose (fpd);
  1176.  
  1177.       sprintf (filename, "%s%s.MNU", config.menu_path, file);
  1178.       unlink (filename);
  1179.       sprintf (string, "%s%s.NEW", config.menu_path, file);
  1180.       rename (string, filename);
  1181.  
  1182.       wclose ();
  1183.    }
  1184.  
  1185.    wclose ();
  1186.    gotoxy_ (24, 1);
  1187.    clreol_ ();
  1188.  
  1189.    free (cmd);
  1190. }
  1191.  
  1192. static void setup_menu (char *file)
  1193. {
  1194.    int fd, i, m, beg, wh;
  1195.    char filename[80], items[MAX_ITEMS][20], *array[MAX_ITEMS];
  1196.    struct _menu_header mh;
  1197.  
  1198.    sprintf (filename, "%s%s.MNU", config.menu_path, file);
  1199.    fd = sh_open (filename, SH_DENYWR, O_RDONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  1200.    if (fd == -1)
  1201.       return;
  1202.  
  1203.    i = 0;
  1204.    while (read (fd, &mh, sizeof (struct _menu_header)) == sizeof (struct _menu_header)) {
  1205.       sprintf (items[i], "%-14.14s", strupr (mh.name));
  1206.       i++;
  1207.       lseek (fd, (long)sizeof(struct _cmd) * mh.n_elem, SEEK_CUR);
  1208.    }
  1209.  
  1210.    strcpy (items[i++], "< New menu >  ");
  1211.  
  1212.    close (fd);
  1213.  
  1214.    for (m = 0; m < i; m++)
  1215.       array[m] = items[m];
  1216.    array[m] = NULL;
  1217.  
  1218.    beg = 0;
  1219.  
  1220.    do {
  1221.       i = wpickstr (5, 10, 17, 27, 1, LCYAN|_BLACK, CYAN|_BLACK, BLUE|_LGREY, array, beg, NULL);
  1222.       if (i != -1) {
  1223.          if (array[i + 1] == NULL) {
  1224.             wh = wopen (14, 14, 16, 41, 1, LCYAN|_BLACK, CYAN|_BLACK);
  1225.             wactiv (wh);
  1226.             wshadow (DGREY|_BLACK);
  1227.             wtitle (" New menu ", TRIGHT, YELLOW|_BLUE);
  1228.             wprints (0, 1, LGREY|_BLACK, "Menu name: ");
  1229.             strcpy (filename, "");
  1230.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  1231.             winpdef (0, 12, filename, "?????????????", 0, 1, NULL, 0);
  1232.             if (winpread () != W_ESCPRESS) {
  1233.                wclose ();
  1234.                hidecur ();
  1235.  
  1236.                memset (&mh, 0, sizeof (struct _menu_header));
  1237.                strcpy (mh.name, strupr (strbtrim (filename)));
  1238.                if (!mh.name[0])
  1239.                   continue;
  1240.  
  1241.                sprintf (filename, "%s%s.MNU", config.menu_path, file);
  1242.                fd = sh_open (filename, SH_DENYWR, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  1243.                lseek (fd, 0L, SEEK_END);
  1244.                if (fd == -1)
  1245.                   return;
  1246.                write (fd, &mh, sizeof (struct _menu_header));
  1247.                close (fd);
  1248.  
  1249.                strcpy (filename, mh.name);
  1250.  
  1251.                edit_menu_items (file, filename);
  1252.  
  1253.                strcpy (items[i], filename);
  1254.                beg = i++;
  1255.                strcpy (items[i++], "< New menu >  ");
  1256.                for (m = 0; m < i; m++)
  1257.                   array[m] = items[m];
  1258.                array[m] = NULL;
  1259.             }
  1260.             else
  1261.                wclose ();
  1262.          }
  1263.          else {
  1264.             strcpy (filename, items[i]);
  1265.             edit_menu_items (file, strbtrim (filename));
  1266.             beg = i;
  1267.          }
  1268.       }
  1269.    } while (i != -1);
  1270. }
  1271.  
  1272. void manager_menu ()
  1273. {
  1274.    int wh, i = 1, beg = 1;
  1275.    char string[80], mnu[16][20];
  1276.  
  1277.    wh = wopen (7, 20, 15, 67, 1, LCYAN|_BLACK, CYAN|_BLACK);
  1278.    wactiv (wh);
  1279.    wshadow (DGREY|_BLACK);
  1280.    wtitle (" Select menu ", TRIGHT, YELLOW|_BLUE);
  1281.  
  1282.    do {
  1283.       stop_update ();
  1284.       wclear ();
  1285.  
  1286.       wmenubegc ();
  1287.  
  1288.       for (i = 0; i < 15; i++) {
  1289.          if (!config.language[i].basename[0])
  1290.             break;
  1291.          sprintf (string, "%s.MNU", strupr (config.language[i].basename));
  1292.          sprintf (mnu[i], " %-12.12s ", string);
  1293.          wmenuitem ( (i / 3) + 1, (i % 3) * 15 + 1, mnu[i], 0, i + 1, 0, NULL, 0, 0);
  1294.       }
  1295.  
  1296.       wmenuend (beg, M_OMNI, 0, 0, LGREY|_BLACK, LGREY|_BLACK, LGREY|_BLACK, BLUE|_LGREY);
  1297.  
  1298.       if (i == 0) {
  1299.          wcenters (3, YELLOW|_BLACK, "No menu defined");
  1300.          getxch ();
  1301.          wclose ();
  1302.          return;
  1303.       }
  1304.  
  1305.       start_update ();
  1306.       i = wmenuget ();
  1307.       if (i != -1) {
  1308.          setup_menu (config.language[i - 1].basename);
  1309.          beg = i;
  1310.       }
  1311.  
  1312.       hidecur ();
  1313.    } while (i != -1);
  1314.  
  1315.    wclose ();
  1316. }
  1317.  
  1318. static unsigned long cr3tab[] = {
  1319.     0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
  1320.     0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
  1321.     0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
  1322.     0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
  1323.     0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
  1324.     0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
  1325.     0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
  1326.     0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
  1327.     0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
  1328.     0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
  1329.     0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
  1330.     0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
  1331.     0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
  1332.     0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
  1333.     0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
  1334.     0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
  1335.     0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
  1336.     0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
  1337.     0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
  1338.     0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
  1339.     0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
  1340.     0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
  1341.     0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
  1342.     0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
  1343.     0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
  1344.     0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
  1345.     0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
  1346.     0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
  1347.     0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
  1348.     0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
  1349.     0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
  1350.     0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
  1351. };
  1352.  
  1353. #define UpdateCRC(c,crc) (cr3tab[((int) crc ^ c) & 0xff] ^ ((crc >> 8) & 0x00FFFFFFL))
  1354.  
  1355. long get_config_crc (void)
  1356. {
  1357.    int i;
  1358.    char *p;
  1359.    long crc = 0xFFFFFFFFL;
  1360.  
  1361.    p = (char *)&config;
  1362.  
  1363.    for (i = 0; i < sizeof (struct _configuration); i++)
  1364.       crc = UpdateCRC (p[i], crc);
  1365.  
  1366.    return (crc);
  1367. }
  1368.  
  1369. long get_menu_crc (int n_elem)
  1370. {
  1371.    int i, max;
  1372.    char *p;
  1373.    long crc = 0xFFFFFFFFL;
  1374.  
  1375.    p = (char *)cmd;
  1376.    max = n_elem * sizeof (struct _cmd);
  1377.  
  1378.    for (i = 0; i < max; i++)
  1379.       crc = UpdateCRC (p[i], crc);
  1380.  
  1381.    return (crc);
  1382. }
  1383.  
  1384. static void display_menu (int n_elem)
  1385. {
  1386.    int m, first, c, noret;
  1387.    char *p;
  1388.  
  1389.    wopen (0, 0, 24, 79, 5, LGREY|_BLACK, LGREY|_BLACK);
  1390.  
  1391.    for (m = 0; m < n_elem; m++) {
  1392.       if (cmd[m].priv == HIDDEN)
  1393.          continue;
  1394.  
  1395.       first = 1;
  1396.       noret = 1;
  1397.       wtextattr (cmd[m].color);
  1398.  
  1399.       for (p = cmd[m].name; *p; p++) {
  1400.          if (*p == ';' && *(p + 1) == '\0')
  1401.             noret = 0;
  1402.  
  1403.          else if (*p == '^') {
  1404.             if (first)
  1405.                wtextattr (cmd[m].first_color);
  1406.             else
  1407.                wtextattr (cmd[m].color);
  1408.             first = first ? 0 : 1;
  1409.          }
  1410.  
  1411.          else if (*p == 0x16) {
  1412.             p++;
  1413.             if (*p == 0x01) {
  1414.                p++;
  1415.                if(*p == 0x10) {
  1416.                   p++;
  1417.                   c = *p & 0x7F;
  1418.                }
  1419.                else
  1420.                   c = *p;
  1421.  
  1422.                if (!c)
  1423.                   wtextattr (13);
  1424.                else
  1425.                   wtextattr (c);
  1426.             }
  1427.  
  1428.             else if (*p == 0x07)
  1429.                wclreol ();
  1430.  
  1431.             else if (*p == 0x07)
  1432.                wclreol ();
  1433.          }
  1434.  
  1435.          else if (*p == 0x0C)
  1436.             wclear ();
  1437.  
  1438.          else if (*p < 0x20 && *p > 0x00) {
  1439.             wputc ('^');
  1440.             wputc (*p + 0x40);
  1441.          }
  1442.  
  1443.          else
  1444.             wputc (*p);
  1445.       }
  1446.  
  1447.       if (!noret)
  1448.          wputs ("\n");
  1449.    }
  1450.  
  1451.    wtextattr (BLACK|_LGREY);
  1452.    wgotoxy (23, 0);
  1453.    wclreol ();
  1454.    wgotoxy (24, 0);
  1455.    wclreol ();
  1456.    wprints (23, 1, BLACK|_LGREY, "Press any key to continue");
  1457.  
  1458.    getxch ();
  1459.  
  1460.    wclose ();
  1461. }
  1462.  
  1463. int list_menu_items (int beg, int n_elem)
  1464. {
  1465.    int wh, i;
  1466.    char string[80], *array[60];
  1467.  
  1468.    wh = wopen (3, 1, 20, 76, 1, LCYAN|_BLACK, CYAN|_BLACK);
  1469.    wactiv (wh);
  1470.    wshadow (DGREY|_BLACK);
  1471.    wtitle (" Select item ", TRIGHT, YELLOW|_BLUE);
  1472.  
  1473.    wprints (0, 1, LGREY|_BLACK, "User display             Key  Menu type            Data");
  1474.    whline (1, 0, 76, 0, BLUE|_BLACK);
  1475.  
  1476.    gotoxy_ (24, 1);
  1477.    clreol_ ();
  1478.    prints (24, 1, LGREY|_BLACK, "-Move bar  ENTER-Select");
  1479.    prints (24, 1, YELLOW|_BLACK, "");
  1480.    prints (24, 14, YELLOW|_BLACK, "ENTER");
  1481.  
  1482.    for (i = 0; i < n_elem; i++) {
  1483.       sprintf (string, " %-22.22s │'%c'│%-19.19s │ %-20.20s ", cmd[i].name, cmd[i].hotkey ? cmd[i].hotkey : ' ', menu_types[cmd[i].flag_type], cmd[i].argument);
  1484.       array[i] = (char *)malloc (strlen (string) + 1);
  1485.       if (array[i] == NULL)
  1486.          break;
  1487.       strcpy (array[i], string);
  1488.    }
  1489.    array[i] = NULL;
  1490.  
  1491.    i = wpickstr (6, 2, 19, 75, 5, LGREY|_BLACK, CYAN|_BLACK, BLUE|_LGREY, array, beg, NULL);
  1492.  
  1493.    wclose ();
  1494.  
  1495.    gotoxy_ (24, 1);
  1496.    clreol_ ();
  1497.    prints (24, 1, LGREY|_BLACK, "PgUp/PgDn-Next/Previous  E-Edit  A-Add  C-Copy  L-List  D-Delete  S-Show");
  1498.    prints (24, 1, YELLOW|_BLACK, "PgUp/PgDn");
  1499.    prints (24, 26, YELLOW|_BLACK, "E");
  1500.    prints (24, 34, YELLOW|_BLACK, "A");
  1501.    prints (24, 41, YELLOW|_BLACK, "C");
  1502.    prints (24, 49, YELLOW|_BLACK, "L");
  1503.    prints (24, 57, YELLOW|_BLACK, "D");
  1504.    prints (24, 67, YELLOW|_BLACK, "S");
  1505.  
  1506.    return (i == -1 ? beg : i);
  1507. }
  1508.  
  1509. void bbs_paging_hours (void)
  1510. {
  1511.    int m, x, i = 1;
  1512.    char string[128], *p;
  1513.  
  1514.    wopen (6, 22, 16, 49, 3, LCYAN|_BLACK, CYAN|_BLACK);
  1515.    wshadow (DGREY|_BLACK);
  1516.    wtitle (" Paging hours ", TRIGHT, YELLOW|_BLUE);
  1517.  
  1518.    do {
  1519.       stop_update ();
  1520.       wclear ();
  1521.  
  1522.       wmenubegc ();
  1523.       wmenuitem ( 1,  1, " Sunday    ", 0,  1, 0, NULL, 0, 0);
  1524.       wmenuitem ( 2,  1, " Monday    ", 0,  2, 0, NULL, 0, 0);
  1525.       wmenuitem ( 3,  1, " Tuesday   ", 0,  3, 0, NULL, 0, 0);
  1526.       wmenuitem ( 4,  1, " Wednesday ", 0,  4, 0, NULL, 0, 0);
  1527.       wmenuitem ( 5,  1, " Thursday  ", 0,  5, 0, NULL, 0, 0);
  1528.       wmenuitem ( 6,  1, " Friday    ", 0,  6, 0, NULL, 0, 0);
  1529.       wmenuitem ( 7,  1, " Saturday  ", 0,  7, 0, NULL, 0, 0);
  1530.       wmenuend (i, M_OMNI|M_SAVE, 0, 0, LGREY|_BLACK, LGREY|_BLACK, LGREY|_BLACK, BLUE|_LGREY);
  1531.  
  1532.       for (i = 0; i < 7; i++) {
  1533.          m = config.page_start[i];
  1534.          x = config.page_end[i];
  1535.          sprintf (string, "%02d:%02d %02d:%02d", m / 60, m % 60, x / 60, x % 60);
  1536.          wprints (i + 1, 13, CYAN|_BLACK, string);
  1537.       }
  1538.  
  1539.       hidecur ();
  1540.  
  1541.       start_update ();
  1542.       i = wmenuget ();
  1543.  
  1544.       switch (i) {
  1545.          case 1:
  1546.          case 2:
  1547.          case 3:
  1548.          case 4:
  1549.          case 5:
  1550.          case 6:
  1551.          case 7:
  1552.             m = config.page_start[i - 1];
  1553.  
  1554.             sprintf (string, "%02d:%02d", m / 60, m % 60);
  1555.             winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  1556.             winpdef (i, 13, string, "?????", 0, 2, NULL, 0);
  1557.             if (winpread () != W_ESCPRESS) {
  1558.                p = strtok (string, ":");
  1559.                if (p == NULL)
  1560.                   config.page_start[i - 1] = atoi (string) % 1440;
  1561.                else {
  1562.                   config.page_start[i - 1] = atoi (p) * 60;
  1563.                   if ((p = strtok (NULL, "")) != NULL)
  1564.                      config.page_start[i - 1] += atoi (p);
  1565.                }
  1566.  
  1567.                     m = config.page_start[i -1];
  1568.                sprintf (string, "%02d:%02d", m / 60, m % 60);
  1569.                wprints (i, 13, CYAN|_BLACK, string);
  1570.  
  1571.                m = config.page_end[i - 1];
  1572.  
  1573.                sprintf (string, "%02d:%02d", m / 60, m % 60);
  1574.                winpbeg (BLUE|_GREEN, BLUE|_GREEN);
  1575.                winpdef (i, 19, string, "?????", 0, 2, NULL, 0);
  1576.                if (winpread () != W_ESCPRESS) {
  1577.                   p = strtok (string, ":");
  1578.                   if (p == NULL)
  1579.                      config.page_end[i - 1] = atoi (string) % 1440;
  1580.                   else {
  1581.                      config.page_end[i - 1] = atoi (p) * 60;
  1582.                      p = strtok (NULL, "");
  1583.                      config.page_end[i - 1] += atoi (p);
  1584.                   }
  1585.                }
  1586.             }
  1587.             break;
  1588.       }
  1589.  
  1590.       hidecur ();
  1591.    } while (i != -1);
  1592.  
  1593.    wclose ();
  1594. }
  1595.  
  1596.  
  1597.