home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / Main / c / window < prev   
Text File  |  1995-02-22  |  12KB  |  592 lines

  1. #define EXPRO 0
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdarg.h>
  7. #include <signal.h>
  8.  
  9. #include "akbd.h"
  10. #if EXPRO
  11. #include "exprofle.h"
  12. #endif
  13. /*
  14. #include "usProfiler.h"
  15. */
  16. #include "wimpt.h"
  17. #include "res.h"
  18. #include "resspr.h"
  19. #include "template.h"
  20. void template_update_fonts(void);
  21. #include "dbox.h"
  22. #include "flex.h"
  23. #include "heap.h"
  24. #include "kernel.h"
  25. #include "event.h"
  26. #include "visdelay.h"
  27. #include "baricon.h"
  28. #include "menu.h"
  29. #include "saveas.h"
  30. #include "werr.h"
  31. #include "wimp.h"
  32. #include "win.h"
  33. #include "alarm.h"
  34. #include "global.h"
  35. #include "config.h"
  36. #include "cmdparse.h"
  37. #include "misc.h"
  38. #include "driver.h"
  39. #include "Terminal.h"
  40. #include "vterm.h"
  41. #include "import.h"
  42. #include "session.h"
  43. #include "files.h"
  44.  
  45. extern void cmdparse_init(void);
  46.  
  47. extern void vterm_setmenudir(char *dir);
  48.  
  49. #define Icon_Menu_Info     1
  50. #define Icon_Menu_Keypad   2
  51. #define Icon_Menu_Colours  3
  52. #define Icon_Menu_Quit     4
  53.  
  54. Terminal *MWin = NULL;
  55. Terminal *TWin = NULL;
  56.  
  57. static BOOL Trace_Window_Open = FALSE;
  58.  
  59. static menu Icon_Menu;
  60.  
  61. static int  doscale(int, char **);
  62. static int  dostatus(int, char **);
  63. static int  doterminal(int, char **);
  64. static void Icon_MenuProc(void *, char *);
  65. static void Icon_Click(wimp_i);
  66. static void Alarm_Handler(int, void *);
  67. static void Signal_Proc(int);
  68. static void event_handler(wimp_eventstr *e, void *handle);
  69.  
  70. int term_type = -1;
  71.  
  72. int32 wimp_ver;
  73. static char term_name[12];
  74.  
  75. static int (*terminal_driver)(int,...);
  76. extern int (*pipe_load(char *))(int,...);
  77.  
  78. extern char version[];
  79. extern char arc_vs[];
  80. extern char compile_date[];
  81.  
  82. extern char startup[];
  83. extern char menus[];
  84.  
  85. /* extern BOOL scale; */
  86.  
  87. static struct cmds wincmds[] = {
  88.   "scale",        doscale,        0, NULLCHAR, NULLCHAR,
  89.   "status",       dostatus,       0, NULLCHAR, NULLCHAR,
  90.   "terminal",     doterminal,     0, NULLCHAR, NULLCHAR,
  91.   NULLCHAR,
  92. };
  93.  
  94. int dowin(int argc, char **argv)
  95. {
  96.   return subcmd(wincmds, argc, argv);
  97. }
  98.  
  99. int docredits(int argc, char **argv)
  100. {
  101.   vterm_printf(MWin->vt, ATTRIB_BOLD | ATTRIB_REVERSE, " KA9Q Internet Protocol Package, v%s \r\n", version);
  102.   vterm_printf(MWin->vt, 0, " Original program copyright 1988 by Phil Karn, KA9Q\r\n");
  103.   vterm_printf(MWin->vt, 0, " NET/ROM support copyright 1989 by Dan Frank, W9NK\r\n") ;
  104.   vterm_printf(MWin->vt, 0, " Original Acorn Archimedes port by Jonathan Naylor, G4KLX\r\n");
  105.   vterm_printf(MWin->vt, 0, " VTLib VTxxx Terminals (c) 1994 Adam Goodfellow\r\n\r\n");
  106.   vterm_printf(MWin->vt, 0, " Currently maintained by Anthony Frost G8UDV, vulch@kernow.demon.co.uk\r\n");
  107.   vterm_printf(MWin->vt, 0, " and Adam Goodfellow, adam@comptech.demon.co.uk\r\n");
  108.   vterm_printf(MWin->vt, 0, " Further work by Thomas Aeby, Andrew Draper, Peter Burwood, Gav Maxell\r\n");
  109.   vterm_printf(MWin->vt, 0, " Tom Hughes, Geoff Riley, Paul Allen, and others!\r\n");
  110.   vterm_printf(MWin->vt, ATTRIB_BOLD, "\r\n This is Arc version %s, compiled %s\r\n\r\n", arc_vs, compile_date);
  111.   vterm_printf(MWin->vt, ATTRIB_ULINE, "    Bug reports and comments to tcpip2@comptech.demon.co.uk please. \r\n\r\n");
  112.  
  113.   return(FALSE);
  114. }
  115.  
  116. int doterminal(int argc, char **argv)
  117. {
  118.   int ports, loop;
  119.  
  120.   if (argc == 1)
  121.   {
  122.     cwprintf(NULL, "Using %s terminal", term_type < 0 ? "internal" : "external");
  123.     if (term_type != -1)
  124.       cwprintf(NULL, " with %s driver\r\n", term_name);
  125.     else
  126.       cwprintf(NULL, "\r\n");
  127.   }
  128.   else
  129.   {
  130.     if (argc > 1 && strnlcmp(argv[1], "external", MIN(strlen(argv[1]), 8)) == 0)
  131.     {
  132.       terminal_driver = pipe_load(argv[2]);
  133.       ports = ((int *) terminal_driver)[49];
  134.       for (loop = 0; loop < ports / 0x1000000; loop++)
  135.         (terminal_driver)(DRIVER_INITIALISE, loop);
  136.       term_type = 0;
  137.       strcpy(term_name, argv[2]);
  138.       vterm_close(TWin->vt);
  139.       vterm_close(MWin->vt);
  140. /*      Window_Close(MWin);
  141.       Window_Close(TWin); */
  142.     }
  143.     if (strnlcmp(argv[1], "internal", MIN(strlen(argv[1]), 8)) == 0)
  144.     {
  145. /*      wimp_wstate state;
  146.       wimp_get_wind_state(MWin->Window_Handle, &state);
  147.       wimp_open_wind(&state.o); */
  148.       vterm_open(MWin->vt);
  149.       term_type = -1;
  150.     }
  151.   }
  152.   docredits(0, NULL);
  153.   return(FALSE);
  154. }
  155.  
  156. static int doscale(int argc, char **argv)
  157. {
  158. /* Removed by adam - new terminals don't allow this
  159.   if (argc == 1)
  160.   {
  161.     cwprintf(NULL, "scaling is %s\r\n", (scale) ? "on" : "off");
  162.   }
  163.   else
  164.   {
  165.     if (stricmp(argv[1], "on") == 0)
  166.     {
  167.       scale = TRUE;
  168.     }
  169.     else
  170.     {
  171.       scale = FALSE;
  172.     }
  173.   }
  174. */
  175.   cwprintf(NULL, "Sorry - terminal scaling no longer supported\r\n.");
  176.   return 0;
  177. }
  178.  
  179. static int dostatus(int argc, char **argv)
  180. {
  181.   argc = argc;
  182.   argv = argv;
  183.  
  184.   cwprintf(NULL, "trace window: status:%s\r\n", (Trace_Window_Open) ? "open" : "closed");
  185.  
  186.   return(0);
  187. }
  188.  
  189. static BOOL remote_message(wimp_eventstr *event, void *handle)
  190. {
  191.   extern struct cmds cmds[];
  192.  
  193.   if (event->e == wimp_ESEND)
  194.   {
  195.     if (event->data.msg.hdr.action == 0x823F0)
  196.     {
  197. /*      cwprintf(MWin, "%s\r\n", event->data.msg.data.chars); */
  198.       cmdparse(cmds, event->data.msg.data.chars, MWin);
  199.       return(TRUE);
  200.     }
  201.   }
  202.   return(FALSE);
  203. }
  204.  
  205. static BOOL change_fonts(wimp_eventstr *event, void *handle)
  206. {
  207.   switch (event->e)
  208.   {
  209.     case wimp_ESEND:
  210.     case wimp_ESENDWANTACK:
  211.       switch (event->data.msg.hdr.action) {
  212.         case wimp_MMODECHANGE:
  213.           template_update_fonts();
  214.           break;
  215.       }
  216.   }
  217.   return(FALSE);
  218. }
  219.  
  220. int main(int argc, char *argv[])
  221. {
  222. #if EXPRO
  223.   exprofle_init("<TCPIP$Dir>.profile");
  224. #endif
  225. /*
  226. #if FALSE
  227.   profiler__initialise("<TCPIP$Dir>.profile");
  228. #endif
  229. */
  230.   wimp_ver = wimpt_init("TCP/IP");
  231.   res_init(APPNAME);
  232.   flex_init();
  233.   _kernel_register_slotextend(flex_budge);
  234.   resspr_init();
  235.   template_use_fancyfonts();
  236.   template_init();
  237.   dbox_init();
  238.   visdelay_init();
  239.   alarm_init();
  240.   cmdparse_init();
  241.   vterm_setmenudir(menus);
  242.   if (!vterm_initialise())
  243.     werr(1, "Terminal initialisation failed");
  244.  
  245.  
  246.   argc = argc;
  247.   argv = argv;
  248. /*
  249.   signal(SIGABRT, Signal_Proc);
  250.   signal(SIGFPE,  Signal_Proc);
  251.   signal(SIGILL,  Signal_Proc);
  252.   signal(SIGINT,  Signal_Proc);
  253.   signal(SIGSEGV, Signal_Proc);
  254.   signal(SIGTERM, Signal_Proc);
  255.   signal(SIGSTAK, Signal_Proc);
  256.   signal(8, Signal_Proc);
  257.   signal(9, Signal_Proc);
  258. */
  259.   visdelay_begin();
  260.  
  261.   if ((Icon_Menu = menu_new("TCP/IP", ">Info,Keypad\x8c,>Colours,Quit")) == NULL)
  262.   {
  263.     visdelay_end();
  264.     return(1);
  265.   }
  266.  
  267.   baricon("!tcpip", (int)wimp_baseofsprites(), Icon_Click);
  268.  
  269.   if (!event_attachmenu(win_ICONBAR, Icon_Menu, Icon_MenuProc, 0))
  270.   {
  271.     visdelay_end();
  272.     return(1);
  273.   }
  274.   win_register_event_handler(win_ICONBARLOAD, event_handler, 0);
  275.  
  276.   wimp_save_fp_state_on_poll();
  277.  
  278.   if (TWin = Window_Open(NULL, "Trace Window", term_DONT_OPEN | term_DONT_DESTROY | term_NO_INPUT), TWin == NULL)
  279.   {
  280.     visdelay_end();
  281.     return(1);
  282.   }
  283.  
  284.   if (MWin = Window_Open(NULL, "TCPIP Command Window", term_CARET | term_DONT_DESTROY), MWin == NULL)
  285.   {
  286.     visdelay_end();
  287.     return(1);
  288.   }
  289.   win_add_unknown_event_processor(remote_message, NULL);
  290.   win_add_unknown_event_processor(change_fonts, NULL);
  291. /*
  292.   win_add_unknown_event_processor(wimptcp_message_handler, NULL);
  293. */
  294.   net_init(argc-1, argv+1);
  295.  
  296.   visdelay_end();
  297.  
  298.   alarm_set(alarm_timenow() + 1, Alarm_Handler, 0);
  299.  
  300.   while (TRUE)
  301.     event_process();
  302.  
  303.   return(0);
  304. }
  305.  
  306. static void Icon_MenuProc(void *Handle, char *Hit)
  307. {
  308.   char buffer[50];
  309.   dbox d;
  310.  
  311.   Handle = Handle;
  312.  
  313.   switch (Hit[0])
  314.   {
  315.   case Icon_Menu_Info:
  316.     if ((d = dbox_new("progInfo")) == NULL)
  317.       return;
  318.     sprintf(buffer, "%s (%s)", arc_vs, compile_date);
  319.     dbox_setfield(d, 4, buffer);
  320.     dbox_show(d);
  321.     dbox_fillin(d);
  322.     dbox_dispose(&d);
  323.     break;
  324.  
  325.   case Icon_Menu_Keypad:
  326.     vterm_keypad();
  327.     break;
  328.  
  329.   case Icon_Menu_Colours:
  330.     vterm_coloursdbox();
  331.     break;
  332.  
  333.   case Icon_Menu_Quit:
  334.     if (akbd_pollctl() && akbd_pollsh())
  335.       exit(0); /* Put this in so I can quit and restart on-line (Adam) */
  336.     else
  337.       net_exit();
  338.     break;
  339.   default:
  340.     break;
  341.   }
  342. }
  343.  
  344. static void Icon_Click(wimp_i Icon)
  345. {
  346.   wimp_wstate state;
  347.  
  348.   Icon = Icon;
  349.  
  350.   if (term_type == -1)
  351.   {
  352.     vterm_open(MWin->vt);
  353. /*    wimp_get_wind_state(MWin->Window_Handle, &state);
  354.     wimp_open_wind(&state.o); */
  355.