home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / atarist / astgem.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  9KB  |  369 lines

  1. /*
  2.  * "astgem.c" ATARI ST GEM Window & Screen Management
  3.  */
  4.  
  5. #include <osbind.h>   /* TOS binding */
  6. #include <stdio.h>    /* common I/O defs */
  7. #include <obdefs.h>   /* common Object definitions */
  8. #include <gemdefs.h>  /* common GEM definitions */
  9. #include "astinc.h"   /* common KERMIT definitions */
  10. #include "astobj.h"   /* KERMIT object definitions */
  11.  
  12. extern FILE *fopen(),*fopenb();
  13.  
  14. /* communication variables for AES & VDI */
  15. int contrl[12];
  16. int intin[128];
  17. int ptsin[128];
  18. int intout[128];
  19. int ptsout[128];
  20. int workin[12];
  21. int workout[57];
  22.  
  23. /* global variables */
  24. int vdi_handle;               /* handle for workstation */
  25. int wi_handle;                /* handle for one (fake) window */
  26. int ap_id;
  27. OBJECT                        /* addrs of objects */
  28.   *menu_addr,
  29.   *obj_addr;
  30. int mbuf[8];                  /* message buffer */
  31. int gl_wchar, gl_hchar, gl_wbox, gl_hbox; /* parameters of virt. works. */
  32. int xdesk, ydesk, hdesk, wdesk; /* desktop parameters */
  33.  
  34.  
  35. /* initialize screen */
  36. w_init_screen()
  37. {int i,dummy;
  38.  ap_id = appl_init();
  39.  vdi_handle = graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  40.  wind_get(0,WF_WORKXYWH,&xdesk,&ydesk,&wdesk,&hdesk);
  41.  for (i = 0; i < 10; i++) workin[i] = 1;
  42.  workin[10] = 2; /* use RC coordinates */
  43.  v_opnvwk(workin, &vdi_handle, workout);
  44.  if (!rsrc_load(KER_RSC))
  45.   {form_error(2);
  46.    return FALSE;
  47.   };
  48.  if (rsrc_gaddr(0,0,&menu_addr) == 0)
  49.   {form_alert(1,"[3][Resource File Format?][ABORT]");
  50.    return FALSE;
  51.   };
  52.  rsrc_gaddr(R_TREE,KERMENU,&menu_addr);
  53.  menu_bar(menu_addr,1);
  54.  return TRUE;
  55. }
  56.  
  57. /* terminate code for screen management */
  58. w_exit_screen()
  59. {
  60.  v_clsvwk(vdi_handle);
  61.  appl_exit();
  62. }
  63.  
  64. /* the main dispatcher */
  65. w_multi()
  66. {char *objstr;
  67.  check_options();
  68.  fgetpath(kpathname);
  69.  fgetpath(gpathname);
  70.  graf_mouse(ARROW,0x0L);
  71.  while (TRUE)
  72.   {evnt_mesag(mbuf);
  73.    wind_update(1);   /* deselect menu */
  74.    if (mbuf[0] == MN_SELECTED)
  75.     {switch (mbuf[3])
  76.       {case MDESK: /* Desk */
  77.             if (mbuf[4] == ABOUTKER)
  78.              {
  79.               rsrc_gaddr(R_TREE,KRABOUT,&obj_addr);
  80.               objstr = (obj_addr[KRAVMM].ob_spec)->te_ptext;
  81.               sprintf(objstr,"%2d%02d",VERSION,RELEASE);
  82.               objstr = (obj_addr[KRAVDAT].ob_spec)->te_ptext;
  83.               sprintf(objstr,VERDATE);
  84.               displ_object(KRABOUT,-1,-1,MDESK,&obj_addr);
  85.               form_do(obj_addr,-1);
  86.               destroy_object(KRABOUT,-1,-1,MDESK);
  87.               change_state(obj_addr,KRABOUOK,NORMAL);
  88.              };
  89.             break;
  90.        case MFILE: /* File Menu */
  91.             switch (mbuf[4])
  92.              {case FQUIT:
  93.                    fsetpath(kpathname);
  94.                    if (debug) fclose(deb);
  95.                    if (translog) fclose(log);
  96.                    wind_update(0);
  97.                    return; /* return and quit */
  98.               case FDELETE:
  99.                    mdelfile(); break;
  100.               case FTYPE:
  101.                    mtypefile(); break;
  102.               case FRENAME:
  103.                    mrenfile(); break;
  104.               case FDFREE:
  105.                    mdfree(); break;
  106.              }; /* switch on mbuf[4] in case MFILE */
  107.              break;
  108.        case MTRANS: /* Transfer Menu */
  109.             do_transfer(mbuf[4]);
  110.             break;
  111.        case MOPTION:
  112.             do_options(mbuf[4]);
  113.             break;
  114.       }; /* switch on mbuf[3] */
  115.      menu_tnormal(menu_addr,mbuf[3],1);
  116.     }; /* if message for us */
  117.    wind_update(0);
  118.   }; /* while */
  119. } /* w_multi */
  120.  
  121. /*
  122.  * display an alert message
  123.  */
  124. displ_alert(cnt,obix)
  125. int cnt,obix;
  126. {long aaddr;
  127.  rsrc_gaddr(R_STRING,obix,&aaddr);
  128.  cnt = form_alert(cnt,aaddr);
  129.  return cnt;
  130. }
  131.  
  132. /*
  133.  * change state of an object but don't display
  134.  */
  135. change_state(tree,ix,state)
  136. long tree;
  137. int state,ix;
  138. {
  139.  objc_change(tree,ix,0,xdesk,ydesk,wdesk,hdesk,state,0);
  140. }
  141.  
  142. /*
  143.  * draw an object
  144.  */
  145. displ_object(ix, x, y, menuix, ad)
  146. int ix, x, y, menuix;
  147. long int *ad;
  148. /* if x or y < 0 then the centered position is used */
  149. /* if y == 0 then y will be half a box below the menu bar */
  150. /* otherwise the new x,y positions are used
  151. /* menuix is the subindex of a menu title which is used for */
  152. /* dial form. if -1 no growing box is displayed */
  153. /* if -2 no dial form */
  154. { int obj_x, obj_y, obj_w, obj_h;
  155.  rsrc_gaddr(R_TREE,ix,ad);
  156.  form_center(*ad,&obj_x,&obj_y,&obj_w,&obj_h);
  157.  obj_x = ((x >= 0) ? x : obj_x);
  158.  y = ((y == 0) ? (ydesk+(gl_hbox/3)) : y);
  159.  obj_y = ((y >= 0) ? y : obj_y);
  160.  (*ad)->ob_x = obj_x + 3;
  161.  (*ad)->ob_y = obj_y + 3;
  162.     if (menuix == -1)
  163.        form_dial(0,0,0,0,0,obj_x,obj_y,obj_w,obj_h);
  164.     else if (menuix >= 0)
  165.        {
  166.         form_dial(0,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
  167.                     obj_x,obj_y,obj_w,obj_h);
  168.         form_dial(1,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
  169.                     obj_x,obj_y,obj_w,obj_h);
  170.        };
  171.  objc_draw(*ad,ROOT,MAX_DEPTH,obj_x,obj_y,obj_w,obj_h);
  172. }
  173.  
  174. /*
  175.  * destroy an object
  176.  */
  177. destroy_object(ix, x, y, menuix)
  178. int ix, x, y, menuix;
  179. /* same parameter conventions as above */
  180. {long ad;
  181.  int obj_x, obj_y, obj_w, obj_h;
  182.  rsrc_gaddr(R_TREE,ix,&ad);
  183.  form_center(ad,&obj_x,&obj_y,&obj_w,&obj_h);
  184.  obj_x = ((x >= 0) ? x : obj_x);
  185.  y = ((y == 0) ? (ydesk+(gl_hbox/3)) : y);
  186.  obj_y = ((y >= 0) ? y : obj_y);
  187.  (ad)->ob_x = obj_x + 3;
  188.  (ad)->ob_y = obj_y + 3;
  189.     if (menuix == -1)
  190.        form_dial(3,0,0,0,0,obj_x,obj_y,obj_w,obj_h);
  191.     else if (menuix >= 0)
  192.        {
  193.         form_dial(2,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
  194.                     obj_x,obj_y,obj_w,obj_h);
  195.         form_dial(3,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
  196.                     obj_x,obj_y,obj_w,obj_h);
  197.        };
  198. }
  199.  
  200.  
  201.  
  202. /*
  203.  * some terminal functions
  204.  */
  205.  
  206. /*
  207.  * type out a file in terminal mode
  208.  */
  209. mtypefile()
  210. {
  211.  int lcnt;
  212.  char c, resp;
  213.  char *cp;
  214.  displ_object(KRMDOTYP,-1,0,MFILE,&obj_addr);
  215.  if (!fsetfilename(gpathname,filnam))
  216.      {destroy_object(KRMDOTYP,-1,0,MFILE);
  217.       return;
  218.      };
  219.  fp = fopen(filnam,"r");
  220.  if (fp == NIL)
  221.     {displ_alert(1,KRFILNEX);
  222.      destroy_object(KRMDOTYP,-1,0,MFILE);
  223.      return;};
  224.  destroy_object(KRMDOTYP,-1,0,MFILE);
  225.  menu_tnormal(menu_addr,MFILE,1);
  226.  init_terminal();
  227.  rsrc_gaddr(R_TREE,KRMESSS,&obj_addr);
  228.  while (Cconis()) Cnecin();
  229.  lcnt = 0;
  230.  while (TRUE)
  231.   {c = getc(fp);
  232.    if (feof(fp) || ferror(fp)) break;
  233.    Crawio(c);
  234.    if (c == '\n')
  235.       {Crawio(CR);
  236.        if (++lcnt > 22)
  237.           {lcnt = 0;
  238.            for (cp = obj_addr[MSMORE].ob_spec; *cp; cp++)
  239.                Crawio(*cp);
  240.            resp = Crawcin();
  241.            if (resp == ETX) break;
  242.            Crawio(CR);
  243.            v_eeol(vdi_handle);
  244.           };
  245.       };
  246.   };
  247.  if (resp != ETX)
  248.     {Crawio(CR);
  249.      Crawio(LF);
  250.      for (cp = obj_addr[MSEOF].ob_spec; *cp; cp++)
  251.          Crawio(*cp);
  252.      Crawcin();
  253.     };
  254.  fclose(fp);
  255.  exit_terminal();
  256. }
  257.  
  258. /*
  259.  * init workstation as a terminal
  260.  */
  261. int init_terminal()
  262. {
  263.  graf_mouse(M_OFF,NIL);
  264.  wi_handle = wind_create(0,xdesk,ydesk,wdesk,hdesk);
  265.  graf_growbox(menu_addr[MFILE].ob_x,0,4*gl_wbox,gl_hbox,
  266.               xdesk,ydesk,wdesk,hdesk);
  267.  wind_open(wi_handle,xdesk,ydesk,wdesk,hdesk);
  268.  v_enter_cur(vdi_handle);
  269.  v_curhome(vdi_handle);
  270.  v_eeos(vdi_handle);
  271. }
  272.  
  273. /*
  274.  * exit terminal mode
  275.  */
  276.  
  277. exit_terminal()
  278. {
  279.  v_curhome(vdi_handle);
  280.  v_eeos(vdi_handle);
  281.  v_exit_cur(vdi_handle);
  282.  menu_bar(menu_addr,1);
  283.  wind_close(wi_handle);
  284.  wind_delete(wi_handle);
  285.  graf_shrinkbox(menu_addr[MFILE].ob_x,0,gl_wbox,gl_hbox,
  286.                 xdesk,ydesk,wdesk,hdesk);
  287.  graf_mouse(M_ON,NIL);
  288. }
  289.  
  290.  
  291. /*
  292.  * ask for file and delete
  293.  */
  294. mdelfile()
  295. {long addr;
  296.  displ_object(KRMDODEL,-1,0,MFILE,&addr);
  297.  if (fsetfilename(gpathname,filnam))
  298.     if (access(filnam,4) != 0)
  299.        displ_alert(1,KRFILNEX);
  300.     else
  301.        {
  302.         if (unlink(filnam) != 0)
  303.             displ_alert(1,KRDELERR);
  304.         else
  305.             displ_alert(1,KRDELDON);
  306.        };
  307.  destroy_object(KRMDODEL,-1,0,MFILE);
  308. };
  309.  
  310. /*
  311.  * rename a file
  312.  */
  313. mrenfile()
  314. {char oname[FILNAMLEN],
  315.       nname[FILNAMLEN];
  316.  OBJECT *objp;
  317.  int objx;
  318.  displ_object(KRMDOREN,-1,0,MFILE,&objp);
  319.  objx = KRMDOREN;
  320.  if (fsetfilename(gpathname,filnam))
  321.     if (access(filnam,4) != 0)
  322.        displ_alert(1,KRFILNEX);
  323.     else
  324.        {strcpy(oname,gpathname);
  325.         strcat(oname,filnam);
  326.         destroy_object(KRMDOREN,-1,0,MFILE);
  327.         displ_object(KRMDORE2,-1,0,MFILE,&objx);
  328.         objx = KRMDORE2;
  329.         if (fsetfilename(gpathname,filnam))
  330.            if (access(filnam,2) == 0)
  331.               displ_alert(1,KRFILEX);
  332.            else
  333.               {strcpy(nname,gpathname);
  334.                strcat(nname,filnam);
  335.                destroy_object(KRMDORE2,-1,0,MFILE);
  336.                objx = -1;
  337.                if (Frename(0,oname,nname) != 0)
  338.                   displ_alert(1,KRRENERR);
  339.                else
  340.                   displ_alert(1,KRRENDON);
  341.               };
  342.          };
  343.  if (objx >= 0)
  344.     destroy_object(objx,-1,0,MFILE);
  345. }
  346.  
  347. /* display free disk space */
  348. mdfree()
  349. {OBJECT *objp;
  350.  char *bytp, *idp;
  351.  long int infbuf[4];
  352.  rsrc_gaddr(R_TREE,KRDFREE,&objp);
  353.  bytp = objp[KRDFBY].ob_spec->te_ptext;
  354.  idp  = objp[KRDFID].ob_spec->te_ptext;
  355.  *bytp = '\0';
  356.  *idp  = Dgetdrv() + 'A';
  357.  displ_object(KRDFREE,-1,-1,MFILE,&objp);
  358.  form_do(objp,KRDFID);
  359.  change_state(objp,KRDFOK,NORMAL);
  360.  if (Dfree(infbuf,*idp - 'A' + 1) != 0)
  361.     strcpy(bytp,"????????");
  362.  else
  363.     sprintf(bytp,"%ld",(infbuf[0] * infbuf[2] * infbuf[3]));
  364.  displ_object(KRDFREE,-1,-1,-2,&objp);
  365.  form_do(objp,-1);
  366.  change_state(objp,KRDFOK,NORMAL);
  367.  destroy_object(KRDFREE,-1,-1,MFILE);
  368. }
  369.