home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff369.lzh / VaxTerm / src / setup.c < prev    next >
C/C++ Source or Header  |  1990-08-15  |  12KB  |  382 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <exec/io.h>
  6. #include <libraries/dos.h>
  7. #include <intuition/intuition.h>
  8. #include <hardware/blit.h>
  9. #include <devices/keymap.h>
  10. #include <proto/intuition.h>
  11. #include <proto/dos.h>
  12. #include <proto/exec.h>
  13. #include <proto/graphics.h>
  14.  
  15. #include "main.h"
  16. #include "keymap.h"
  17.  
  18. #define FKEY3           0x0052
  19. #define RET_KEY         0x0044
  20. #define ENTER_KEY       0x0043
  21.  
  22. #define NORMAL_HEIGHT   200
  23. #define SETUP_LINES     17
  24. #define HEAD_ADJUST     2
  25. #define SET_LINES       (SETUP_LINES + HEAD_ADJUST)
  26. #define FONT_WIDTH      10
  27. #define FONT_HEIGHT     9
  28. #define BASE_LINE       2
  29.  
  30. #define SET_COLS        3
  31. #define SET_ADJUST      2
  32. #define SET_COL_WIDTH   ((WIDTH / FONT_WIDTH) / SET_COLS)
  33. #define WIN_WIDTH       ((SET_COL_WIDTH * FONT_WIDTH) * SET_COLS)
  34. #define WIN_LEFT        ((WIDTH - WIN_WIDTH) / 2)
  35. #define WIN_HEIGHT      ((SET_LINES * FONT_HEIGHT) + (2 * BASE_LINE))
  36. #define WIN_TOP         ((NORMAL_HEIGHT - WIN_HEIGHT) / 2)
  37.  
  38. #define NA  7
  39. #define CU  8
  40. #define KI  9
  41.  
  42. struct so save = { NULL,"SAVE SETTINGS",NULL,SO_SAVE,0,1,0,0 };
  43.  
  44. struct so appl = { &save,"APPLICATION KEYPAD",(APTR)"\x1b=",SO_SETUP,0,3,0,1 };
  45. struct so num = { &appl,"NUMERIC KEYPAD",(APTR)"\x1b>",SO_SETUP,0,4,0,1 };
  46.  
  47. struct so ins = { &num,"INSERT",(APTR)"\x9b""4h",SO_SETUP,0,6,0,2 };
  48. struct so over = { &ins,"OVERWRITE",(APTR)"\x9b""4l",SO_SETUP,0,7,0,2 };
  49.  
  50. struct so cret = { &over,"LINEFEED",(APTR)"\x9b""20l",SO_SETUP,0,9,0,3 };
  51. struct so newl = { &cret,"NEWLINE",(APTR)"\x9b""20h",SO_SETUP,0,10,0,3 };
  52.  
  53. struct so wrap = { &newl,"WRAP",(APTR)"\x9b?7h",SO_SETUP,0,12,0,4 };
  54. struct so trunc = { &wrap,"TRUNCATE",(APTR)"\x9b?7l",SO_SETUP,0,13,0,4 };
  55.  
  56. struct so bit_7 = { &trunc,"7-BIT",(APTR)"\x1b F",SO_SETUP,0,15,0,5 };
  57. struct so bit_8 = { &bit_7,"8-BIT",(APTR)"\x1b G",SO_SETUP,0,16,0,5 };
  58.  
  59. struct so mult = { &bit_8,"MULTINATIONAL",(APTR)"\x9b?42l",SO_SETUP,1,0,0,6 };
  60. struct so nat = { &mult,"NATIONAL",(APTR)"\x9b?42h",SO_SETUP,1,1,0,6 };
  61.  
  62. struct so br_set = { &nat,"BRITISH",(APTR)"\x1b(A",SO_SETUP,1,3,0,NA };
  63. struct so du_set = { &br_set,"DUTCH",(APTR)"\x1b(4",SO_SETUP,1,4,0,NA };
  64. struct so fi_set = { &du_set,"FINNISH",(APTR)"\x1b(C",SO_SETUP,1,5,0,NA };
  65. struct so fr_set = { &fi_set,"FRENCH",(APTR)"\x1b(R",SO_SETUP,1,6,0,NA };
  66. struct so fc_set = { &fr_set,"FRENCH/CANADIAN",(APTR)"\x1b(Q",SO_SETUP,1,7,0,NA };
  67. struct so ger_set = { &fc_set,"GERMAN",(APTR)"\x1b(K",SO_SETUP,1,8,0,NA };
  68. struct so ita_set = { &ger_set,"ITALIAN",(APTR)"\x1b(Y",SO_SETUP,1,9,0,NA };
  69. struct so nor_set = { &ita_set,"NORWEGIAN",(APTR)"\x1b(E",SO_SETUP,1,10,0,NA };
  70. struct so spa_set = { &nor_set,"SPANISH",(APTR)"\x1b(Z",SO_SETUP,1,11,0,NA };
  71. struct so swe_set = { &spa_set,"SWEDISH",(APTR)"\x1b(H",SO_SETUP,1,12,0,NA };
  72. struct so swi_set = { &swe_set,"SWISS",(APTR)"\x1b(=",SO_SETUP,1,13,0,NA };
  73.  
  74. struct so curson = { &swi_set,"CURSOR ON",(APTR)"\x9b?25h",SO_SETUP,1,15,0,CU };
  75. struct so cursoff = { &curson,"CURSOR OFF",(APTR)"\x9b?25l",SO_SETUP,1,16,0,CU };
  76.  
  77. struct so us_km = { &cursoff,"NORTH AMERICAN",(APTR)us_map,SO_KEYMAP,2,0,0,KI };
  78. struct so dn_km = { &us_km,"DANISH",(APTR)dn_map,SO_KEYMAP,2,1,0,KI };
  79. struct so fl_km = { &dn_km,"FLEMISH",(APTR)fl_map,SO_KEYMAP,2,2,0,KI };
  80. struct so br_km = { &fl_km,"BRITISH",(APTR)br_map,SO_KEYMAP,2,3,0,KI };
  81. struct so du_km = { &br_km,"DUTCH",(APTR)du_map,SO_KEYMAP,2,4,0,KI };
  82. struct so fi_km = { &du_km,"FINNISH",(APTR)fi_map,SO_KEYMAP,2,5,0,KI };
  83. struct so bf_km = { &fi_km,"BELGIAN/FRENCH",(APTR)bf_map,SO_KEYMAP,2,6,0,KI };
  84. struct so cf_km = { &bf_km,"CANADIAN (FRENCH)",(APTR)cf_map,SO_KEYMAP,2,7,0,KI };
  85. struct so ag_km = { &cf_km,"AUSTRIAN/GERMAN",(APTR)ag_map,SO_KEYMAP,2,8,0,KI };
  86. struct so it_km = { &ag_km,"ITALIAN",(APTR)it_map,SO_KEYMAP,2,9,0,KI };
  87. struct so no_km = { &it_km,"NORWEGIAN",(APTR)no_map,SO_KEYMAP,2,10,0,KI };
  88. struct so sp_km = { &no_km,"SPANISH",(APTR)sp_map,SO_KEYMAP,2,11,0,KI };
  89. struct so sw_km = { &sp_km,"SWEDISH",(APTR)sw_map,SO_KEYMAP,2,12,0,KI };
  90. struct so sf_km = { &sw_km,"SWISS (FRENCH)",(APTR)sf_map,SO_KEYMAP,2,13,0,KI };
  91. struct so sg_km = { &sf_km,"SWISS (GERMAN)",(APTR)sg_map,SO_KEYMAP,2,14,0,KI };
  92. struct so ic_km = { &sg_km,"ICELANDIC",(APTR)ic_map,SO_KEYMAP,2,15,0,KI };
  93. struct so po_km = { &ic_km,"PORTUGUESE",(APTR)po_map,SO_KEYMAP,2,16,0,KI };
  94.  
  95. struct so res = { &po_km,"RESET TERMINAL",(APTR)"\x9b""!p",SO_LOAD,0,0,0,0 };
  96.  
  97. char itxt[SET_COL_WIDTH + 1];
  98. struct TextAttr txf =
  99.     { (STRPTR)"topaz.font",FONT_HEIGHT,FS_NORMAL,FPF_ROMFONT };
  100. struct IntuiText btx =
  101.     { BACKGROUND_PEN,FOREGROUND_PEN,JAM2,0,0,&txf,(UBYTE *)itxt,NULL };
  102.  
  103. struct NewWindow setup_win = {
  104.     WIN_LEFT,WIN_TOP,WIN_WIDTH,WIN_HEIGHT,BACKGROUND_PEN,BACKGROUND_PEN,
  105.     RAWKEY,SMART_REFRESH|BORDERLESS|ACTIVATE|NOCAREREFRESH|RMBTRAP,
  106.     NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN };
  107.  
  108. setup(struct console *con)
  109. {
  110. struct Window       *win;
  111. struct so           *sop,*osop,*nsop;
  112. struct IntuiMessage *msg;
  113. char                **cpp;
  114. SHORT               cnt;
  115. USHORT              code;
  116. static char         *head[] = { "Miscellaneous","Character set","Keymap" };
  117.  
  118. SetRast(&con->srp,0);
  119. setup_win.Screen = con->scr;
  120. if ((win = OpenWindow(&setup_win)) == NULL) return(0);
  121. SetRast(win->RPort,FOREGROUND_PEN);
  122. cpp = head;
  123. for (cnt = 0; cnt < SET_COLS; cnt++) {
  124.     strcpy(itxt,*cpp);
  125.     PrintIText(win->RPort,&btx,
  126.                 (cnt * SET_COL_WIDTH + SET_ADJUST) * FONT_WIDTH,BASE_LINE);
  127.     cpp++;
  128.     }
  129. sop = &res;
  130. showtext(win,sop,TRUE);
  131. sop = sop->next;
  132. while (sop != NULL) {
  133.     showtext(win,sop,FALSE);
  134.     sop = sop->next;
  135.     }
  136. code = 0;
  137. osop = nsop = &res;
  138. while (code != FKEY3) {
  139.     if (nsop != osop) {
  140.         showtext(win,osop,FALSE);
  141.         showtext(win,nsop,TRUE);
  142.         osop = nsop;
  143.         }
  144.     WaitPort(win->UserPort);
  145.     msg = (struct IntuiMessage *)GetMsg(win->UserPort);
  146.     if (msg->Class == RAWKEY) code = msg->Code;
  147.     else code = 0;
  148.     ReplyMsg((struct Message *)msg);
  149.     switch (code) {
  150.         case RET_KEY:
  151.         case ENTER_KEY:
  152.             switch (nsop->type) {
  153.                 case SO_SAVE:
  154.                     writesetup(con);
  155.                     break;
  156.                 case SO_LOAD:
  157.                     reset(con);
  158.                     readsetup(con);
  159.                     sop = &res;
  160.                     showtext(win,sop,TRUE);
  161.                     sop = sop->next;
  162.                     while (sop != NULL) {
  163.                         showtext(win,sop,FALSE);
  164.                         sop = sop->next;
  165.                         }
  166.                     break;
  167.                 case SO_KEYMAP:
  168.                     replace((ULONG **)nsop->setup);
  169.                     activate(nsop);
  170.                     sop = &res;
  171.                     while (sop != NULL) {
  172.                         if (sop->id == nsop->id) {
  173.                             if (sop == nsop) showtext(win,sop,TRUE);
  174.                             else showtext(win,sop,FALSE);
  175.                             }
  176.                         sop = sop->next;
  177.                         }
  178.                     break;
  179.                 case SO_SETUP:
  180.                     strcpy(con->buf,(char *)nsop->setup);
  181.                     interpret(con,strlen(con->buf));
  182.                     sop = &res;
  183.                     while (sop != NULL) {
  184.                         if (sop->id == nsop->id) {
  185.                             if (sop == nsop) showtext(win,sop,TRUE);
  186.                             else showtext(win,sop,FALSE);
  187.                             }
  188.                         sop = sop->next;
  189.                         }
  190.                     break;
  191.                 default: ;
  192.                 }
  193.             break;
  194.         case CURSORUP:
  195.             cnt = osop->row - 1;
  196.             if (cnt == -1) cnt = SETUP_LINES - 1;
  197.             nsop = NULL;
  198.             while (nsop == NULL) {
  199.                 sop = &res;
  200.                 while (sop != NULL) {
  201.                     if ((sop->col == osop->col) &&
  202.                         (sop->row == cnt)) {
  203.                         nsop = sop;
  204.                         break;
  205.                         }
  206.                     sop = sop->next;
  207.                     }
  208.                 cnt--;
  209.                 if (cnt == -1) cnt = SETUP_LINES - 1;
  210.                 }
  211.             break;
  212.         case CURSORLEFT:
  213.             cnt = osop->col - 1;
  214.             if (cnt == -1) cnt = SET_COLS - 1;
  215.             nsop = NULL;
  216.             while (nsop == NULL) {
  217.                 sop = &res;
  218.                 while (sop != NULL) {
  219.                     if ((sop->col == cnt) &&
  220.                         (sop->row == osop->row)) {
  221.                         nsop = sop;
  222.                         break;
  223.                         }
  224.                     sop = sop->next;
  225.                     }
  226.                 cnt--;
  227.                 if (cnt == -1) cnt = SET_COLS - 1;
  228.                 }
  229.             break;
  230.         case CURSORRIGHT:
  231.             cnt = osop->col + 1;
  232.             if (cnt == SET_COLS) cnt = 0;
  233.             nsop = NULL;
  234.             while (nsop == NULL) {
  235.                 sop = &res;
  236.                 while (sop != NULL) {
  237.                     if ((sop->col == cnt) &&
  238.                         (sop->row == osop->row)) {
  239.                         nsop = sop;
  240.                         break;
  241.                         }
  242.                     sop = sop->next;
  243.                     }
  244.                 cnt++;
  245.                 if (cnt == SET_COLS) cnt = 0;
  246.                 }
  247.             break;
  248.         case CURSORDOWN:
  249.             cnt = osop->row + 1;
  250.             if (cnt == SETUP_LINES) cnt = 0;
  251.             nsop = NULL;
  252.             while (nsop == NULL) {
  253.                 sop = &res;
  254.                 while (sop != NULL) {
  255.                     if ((sop->col == osop->col) &&
  256.                         (sop->row == cnt)) {
  257.                         nsop = sop;
  258.                         break;
  259.                         }
  260.                     sop = sop->next;
  261.                     }
  262.                 cnt++;
  263.                 if (cnt == SETUP_LINES) cnt = 0;
  264.                 }
  265.             break;
  266.         default: ;
  267.         }
  268.     }
  269. CloseWindow(win);
  270. initcursor(con);
  271. DRAWCURSOR(con->rp,&con->srp,con->row,con->col);
  272. return(0);
  273. }
  274.  
  275. showtext(struct Window *win,struct so *sop,BOOL negative)
  276. {
  277. register char   *cp;
  278. USHORT          len;
  279.  
  280. if (sop->active) strcpy(itxt," \xbb");
  281. else strcpy(itxt,"  ");
  282. strcat(itxt,sop->name);
  283. len = strlen(itxt);
  284. cp = itxt + len;
  285. while (len < SET_COL_WIDTH) {
  286.     *cp++ = ' ';
  287.     len++;
  288.     }
  289. *cp = '\0';
  290. if (negative) {
  291.     btx.FrontPen = FOREGROUND_PEN;
  292.     btx.BackPen = BACKGROUND_PEN;
  293.     }
  294. PrintIText(win->RPort,&btx,
  295.             (sop->col * SET_COL_WIDTH) * FONT_WIDTH,
  296.             (sop->row + HEAD_ADJUST) * FONT_HEIGHT + BASE_LINE);
  297. if (negative) {
  298.     btx.FrontPen = BACKGROUND_PEN;
  299.     btx.BackPen = FOREGROUND_PEN;
  300.     }
  301. return(0);
  302. }
  303.  
  304. activate(struct so *asop)
  305. {
  306. register struct so *sop;
  307.  
  308. sop = &res;
  309. while (sop != NULL) {
  310.     if (sop == asop) sop->active = TRUE;
  311.     else if (sop->id == asop->id) sop->active = FALSE;
  312.     sop = sop->next;
  313.     }
  314. return(0);
  315. }
  316.  
  317. readsetup(struct console *con)
  318. {
  319. register struct so  *sop;
  320. FILEHANDLE          fp;
  321. USHORT              len;
  322. UBYTE               c;
  323.  
  324. if (fp = OPEN_FOR_READING(TERMINALSETUP)) {
  325.     if (READ(fp,(char *)&c,1)) {
  326.         sop = &res;
  327.         while (sop != NULL) {
  328.             if (sop->id == KI) {
  329.                 if (sop->row == c) {
  330.                     replace((ULONG **)sop->setup);
  331.                     sop->active = TRUE;
  332.                     }
  333.                 else sop->active = FALSE;
  334.                 }
  335.             sop = sop->next;
  336.             }
  337.         do {
  338.             len = READ(fp,con->buf,BUFSIZE);
  339.             if (len) interpret(con,len);
  340.             } while (len == BUFSIZE);
  341.         }
  342.     CLOSEFILE(fp);
  343.     }
  344. else {
  345.     replace((ULONG **)us_km.setup);
  346.     activate(&us_km);
  347.     }
  348. return(0);
  349. }
  350.  
  351. writesetup(struct console *con)
  352. {
  353. register struct so  *sop;
  354. FILEHANDLE          fp;
  355. USHORT              cnt;
  356.  
  357. if (fp = OPEN_FOR_WRITING(TERMINALSETUP)) {
  358.     sop = &res;
  359.     while (sop != NULL) {
  360.         if ((sop->id == KI)&&(sop->active)) {
  361.             WRITE(fp,(char *)&sop->row,1);
  362.             break;
  363.             }
  364.         sop = sop->next;
  365.         }
  366.     cnt = NA;
  367.     while (cnt > 0) {
  368.         sop = &res;
  369.         while (sop != NULL) {
  370.             if ((sop->id == cnt)&&(sop->active)) {
  371.                 WRITE(fp,(char *)sop->setup,strlen((char *)sop->setup));
  372.                 break;
  373.                 }
  374.             sop = sop->next;
  375.             }
  376.         cnt--;
  377.         }
  378.     CLOSEFILE(fp);
  379.     }
  380. return(0);
  381. }
  382.