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

  1. /*
  2.  * astgmt.c ATARI ST Kermit: GEM interface to Transfer functions
  3.  */
  4.  
  5. #include <osbind.h>  /* TOS bindings */
  6. #include <stdio.h>   /* common I/O defintions */
  7. #include <obdefs.h>  /* common object defintions */
  8. #include <gemdefs.h> /* GEM defintions */
  9. #include "astinc.h"  /* common KERMIT defintions */
  10. #include "astobj.h"  /* KERMIT object definitions */
  11.  
  12. OBJECT
  13.     *optr,           /* pointer to an object */
  14.     *displo;         /* pointer to the Transfer Display Object */
  15.  
  16. int old_n,           /* old packet number */
  17.     old_n_total,     /* old total count */
  18.     old_bps,         /* old bps */
  19.     old_timcnt,      /* old timeout count */
  20.     old_nakcnt;      /* old nak counter */
  21.  
  22. long int
  23.    old_bytecnt;      /* old byte count */
  24.  
  25.  
  26. /*
  27.  * handle transfer commands
  28.  */
  29. do_transfer(menuix)
  30. int menuix;
  31. {
  32.  int ready, doit;
  33.  char savfnam[13];
  34.  rsrc_gaddr(R_TREE,KERDISPL,&displo);
  35.  tvar_init();
  36.  switch (menuix)
  37.   {
  38.    case TPUT:
  39.         displo[KDSENDS].ob_flags &= ~HIDETREE;
  40.         displ_object(KRTDOPUT,-1,0,MTRANS,&optr);
  41.         doit = fsetfilename(gpathname,filnam);
  42.         strcpy(savfnam,filnam);
  43.         destroy_object(KRTDOPUT,-1,0,MTRANS);
  44.         goto do_send;
  45.    case TSEND:
  46.         displo[KDSEND].ob_flags &= ~HIDETREE;
  47.         displ_object(KRTDOSND,-1,0,MTRANS,&optr);
  48.         doit = fsetfilename(gpathname,filnam);
  49.         strcpy(savfnam,filnam);
  50.         destroy_object(KRTDOSND,-1,0,MTRANS);
  51.    do_send:
  52.         if (!doit) return;
  53.         dt_files(FALSE);
  54.         displ_object(KERDISPL,-1,-1,MTRANS,&displo);
  55.         msgall(-1,MSGSNDBG,gpathname,filnam);
  56.         if (!f1stfil(filnam))
  57.            msgall(KRFILNEX,MSGFILNX);
  58.         else
  59.            {
  60.             fp = NIL;
  61.             if (ready = sendsw())
  62.                msgall(-1,MSGSNDRD);
  63.             else
  64.                msgall(-1,MSGSNDFD);
  65.            };
  66.         break;
  67.    case TGET:
  68.         rsrc_gaddr(R_TREE,KRTASKG,&optr);
  69.         change_state(optr,KRTASKAB,NORMAL);
  70.         change_state(optr,KRTASKOK,NORMAL);
  71.         displ_object(KRTASKG,-1,-1,MTRANS,&optr);
  72.         doit = form_do(optr,KRTGFILN);
  73.         destroy_object(KRTASKG,-1,-1,MTRANS);
  74.         if (doit == KRTASKAB) return;
  75.         strcpy(filnam1,optr[KRTGFILN].ob_spec->te_ptext);
  76.         if (strlen(filnam1) == 0) return;
  77.         displo[KDRECEIV].ob_flags &= ~HIDETREE;
  78.         displ_object(KRTDOGET,-1,0,MTRANS,&optr);
  79.         doit = fsetfilename(gpathname,filnam);
  80.         strcpy(savfnam,filnam);
  81.         destroy_object(KRTDOGET,-1,0,MTRANS);
  82.         dt_files(FALSE);
  83.         displ_object(KERDISPL,-1,-1,MTRANS,&displo);
  84.         msgall(-1,MSGGETBG,filnam1,gpathname,filnam);
  85.         fp = NULL;
  86.         if (ready = getsw())
  87.            msgall(-1,MSGGETRD);
  88.         else
  89.            msgall(-1,MSGGETFD);
  90.         break;
  91.    case TRECEIVE:
  92.         displo[KDRECEIV].ob_flags &= ~HIDETREE;
  93.         displ_object(KRTDOREC,-1,0,MTRANS,&optr);
  94.         doit = fsetfilename(gpathname,filnam);
  95.         strcpy(savfnam,filnam);
  96.         destroy_object(KRTDOREC,-1,0,MTRANS);
  97.         if (!doit) return;
  98.         dt_files(FALSE);
  99.         displ_object(KERDISPL,-1,-1,MTRANS,&displo);
  100.         msgall(-1,MSGRECBG,gpathname,filnam);
  101.         fp = NULL;
  102.         if (ready = recsw())
  103.                msgall(-1,MSGRECRD);
  104.             else
  105.                msgall(-1,MSGRECFD);
  106.         break;
  107.    case TFINISH:
  108.         displo[KDFINISH].ob_flags &= ~HIDETREE;
  109.         displ_object(KERDISPL,-1,-1,MTRANS,&displo);
  110.         msgall(-1,MSGSRVFI);
  111.         if (ready = gencmdsw('F'))
  112.            msgall(-1,MSGFINRD);
  113.         else
  114.            msgall(KSVFERR,MSGFINFD);
  115.         break;
  116.    case TBYE:
  117.         displo[KDBYE].ob_flags &= ~HIDETREE;
  118.         displ_object(KERDISPL,-1,-1,MTRANS,&displo);
  119.         msgall(-1,MSGSRVBY);
  120.         if (ready = gencmdsw('L'))
  121.            msgall(-1,MSGBYERD);
  122.         else
  123.            msgall(KSVBERR,MSGBYEFD);
  124.         break;
  125.   };
  126.   if (ready)
  127.      change_state(displo,KRDABORT,DISABLED);
  128.   else
  129.      change_state(displo,KRDABORT,DISABLED | SELECTED);
  130.   redisp_fld(KRDABORT,NIL,NIL);
  131.   change_state(displo,KRDRFCTI,DISABLED);
  132.   redisp_fld(KRDRFCTI,NIL,NIL);
  133.   change_state(displo,KRDRDYOK,NORMAL);
  134.   redisp_fld(KRDRDYOK,NIL,NIL);
  135.   Cconout(0x07);
  136.   form_do(displo,-1);
  137.   destroy_object(KERDISPL,-1,-1,MTRANS);
  138.   if (fp != NULL) fclose(fp);
  139.   strcpy(filnam,savfnam);
  140. }
  141.  
  142.  
  143.  
  144. /* some display utilities for the transfer function */
  145.  
  146. /*
  147.  * access of message strings
  148.  * will be used mostly by prtdeb & prtlog
  149.  */
  150. char *msg_string(ix)
  151. int ix;
  152. {
  153.  OBJECT *oprt;
  154.  rsrc_gaddr(R_TREE,KRMESSS,&oprt);
  155.  return (oprt[ix].ob_spec);
  156. }
  157.  
  158. /*
  159.  * initialize transfer variables
  160.  * and transfer display object
  161.  */
  162. tvar_init()
  163. {
  164.  /* init vars */
  165.  numtry = getfile = n = n_total = filecnt = bps = nakcnt = timcnt = 0;
  166.  old_n = old_n_total = old_bps = old_nakcnt = old_timcnt = 0;
  167.  bytecnt = old_bytecnt = 0L;
  168.  fp = NULL;
  169.  strcpy(filnam1,"\0");
  170.  /* init display object */
  171.  change_state(displo,KRDABORT,NORMAL);
  172.  change_state(displo,KRDRFCTI,NORMAL);
  173.  change_state(displo,KRDRDYOK,DISABLED);
  174.  displo[KDSEND].ob_flags |= HIDETREE;
  175.  displo[KDSENDS].ob_flags |= HIDETREE;
  176.  displo[KDRECEIV].ob_flags |= HIDETREE;
  177.  displo[KDRECEIS].ob_flags |= HIDETREE;
  178.  displo[KDFINISH].ob_flags |= HIDETREE;
  179.  displo[KDBYE].ob_flags |= HIDETREE;
  180.  dt_files(FALSE);
  181.  dt_packets(FALSE);
  182. }
  183.  
  184. /*
  185.  * update file fields and redisplay
  186.  */
  187. dt_files(dp_change)
  188. int dp_change;
  189. {
  190.  char *dest;
  191.  char tname[21];
  192.  dest = displo[KDFILNAM].ob_spec->te_ptext;
  193.  strncpy(tname,filnam,21);
  194.  tname[21] = '\0';
  195.  sprintf(dest,"%s",tname);
  196.  dest = displo[KDCNVFIL].ob_spec->te_ptext;
  197.  strncpy(tname,filnam1,21);
  198.  tname[21] = '\0';
  199.  sprintf(dest,"%s",tname);
  200.  sprintf(displo[KDFCNT].ob_spec->te_ptext,"%d",filecnt);
  201.  if (dp_change)
  202.     {
  203.      redisp_fld(KDFILNAM,NIL,NIL);
  204.      redisp_fld(KDCNVFIL,NIL,NIL);
  205.      redisp_fld(KDFCNT,NIL,NIL);
  206.     };
  207. }
  208.  
  209. /*
  210.  * update packet fields and redisplay
  211.  */
  212. dt_packets(dp_change)
  213. int dp_change;
  214. {
  215.  sprintf(displo[KDPCNT].ob_spec->te_ptext,"%d",n_total);
  216.  sprintf(displo[KDBCNT].ob_spec->te_ptext,"%ld",bytecnt);
  217.  sprintf(displo[KDPNUM].ob_spec->te_ptext,"%02x",n);
  218.  sprintf(displo[KDBPS].ob_spec->te_ptext,"%d",bps);
  219.  sprintf(displo[KDNAKCNT].ob_spec->te_ptext,"%d",nakcnt);
  220.  sprintf(displo[KDTIMCNT].ob_spec->te_ptext,"%d",timcnt);
  221.  if (dp_change)
  222.     {
  223.      redisp_fld(KDPCNT,&n_total,&old_n_total);
  224.      if (bytecnt != old_bytecnt) redisp_fld(KDBCNT,NIL,NIL);
  225.      old_bytecnt = bytecnt;
  226.      redisp_fld(KDPNUM,&n,&old_n);
  227.      redisp_fld(KDBPS,&bps,&old_bps);
  228.      redisp_fld(KDNAKCNT,&nakcnt,&old_nakcnt);
  229.      redisp_fld(KDTIMCNT,&timcnt,&old_timcnt);
  230.     };
  231. }
  232.  
  233.  
  234. /*
  235.  * redisplay a field in the transfer display object
  236.  */
  237. redisp_fld(ix,new,old)
  238. int ix;
  239. int *new, *old;
  240. {
  241.  int absx, absy;
  242.  OBJECT *cobj;
  243.  if ((new != NIL) && (old != NIL))
  244.     {
  245.      if (*new == *old)
  246.         return;
  247.      else
  248.         *old = *new;
  249.     };
  250.  cobj = &(displo[ix]);
  251.  objc_offset(displo,ix,&absx,&absy);
  252.  objc_draw(displo,ROOT,MAX_DEPTH,absx,absy,cobj->ob_width,cobj->ob_height);
  253. }
  254.  
  255. /*
  256.  * display an error packet message
  257.  */
  258. displ_pckerr(msg)
  259. char *msg;
  260. {
  261.  OBJECT *addr,*krabort;
  262.  int maxslen;
  263.  char *dest;
  264.  rsrc_gaddr(R_TREE,KRABORT,&krabort);
  265.  dest = krabort[KRABMESS].ob_spec->te_ptext;
  266.  maxslen = strlen(krabort[KRABMESS].ob_spec->te_pvalid) - 1;
  267.  strncpy(dest,msg,maxslen);
  268.  dest[maxslen] = '\0';
  269.  displ_object(KRABORT,-1,-1,-1,&addr);
  270.  form_do(addr,-1);
  271.  change_state(addr,KRABOK,NORMAL);
  272.  destroy_object(KRABORT,-1,-1,-1);
  273.  displ_object(KERDISPL,-1,-1,-2,&addr);
  274. }
  275.  
  276.  
  277. /*
  278.  * wait the specified milli seconds
  279.  * and additionally for a click on the ABORT box
  280.  * in the display object
  281.  */
  282. sleepwait(msecs)
  283. int msecs;
  284. {
  285.  int event, dummy, dummy1, dummy2, mx, my;
  286.  event = evnt_multi((MU_TIMER | MU_BUTTON), 1, 1, 1,
  287.                                             0, 0, 0, 0, 0,
  288.                                             0, 0, 0, 0, 0,
  289.                                             &dummy,
  290.                                             msecs, 0,
  291.                                             &mx, &my,
  292.                                             &dummy, &dummy, &dummy1, &dummy2);
  293.  if (MU_BUTTON & event)
  294.     if (objc_find(displo, KRDABORT, 1, mx, my) == KRDABORT)
  295.        {
  296.         change_state(displo,KRDABORT,SELECTED);
  297.         redisp_fld(KRDABORT,NIL,NIL);
  298.         if (displ_alert(1,KRCONFAB) != 1)
  299.            return ('A');
  300.         change_state(displo,KRDABORT,NORMAL);
  301.         redisp_fld(KRDABORT,NIL,NIL);
  302.         return(FALSE);
  303.        }
  304.     else
  305.      if (objc_find(displo, KRDRFCTI, 1, mx, my) == KRDRFCTI)
  306.         {
  307.          change_state(displo,KRDRFCTI,SELECTED);
  308.          redisp_fld(KRDRFCTI,NIL,NIL);
  309.          evnt_timer(200,0);
  310.          change_state(displo,KRDRFCTI,NORMAL);
  311.          redisp_fld(KRDRFCTI,NIL,NIL);
  312.          return('T');
  313.         }
  314.       else
  315.         Cconout(0x07);
  316.  return(FALSE);
  317. }
  318.