home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / comm / zedzap05.lha / dosstuff.c < prev    next >
C/C++ Source or Header  |  1992-11-27  |  8KB  |  241 lines

  1.  
  2. #include <proto/all.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <exec/execbase.h>
  6. /* added */
  7. #include <libraries/dos.h>
  8. #include <libraries/dosextens.h>
  9. /* end */
  10. #include <ctype.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "xproto.h"
  15. #include "zmodem.h"
  16. #include "xprzmodem.h"
  17.  
  18. char WinName[256];
  19. struct DosLibrary *DOSBase = NULL;
  20.  
  21. void ClearStats(struct Vars *v){
  22.    if(!DOSBase) return;
  23.    if(!v->use_dos_lib) return;
  24.    if(!v->TransferWindow) return;
  25.    WinPuts(v,"\x1B[1;1H\x1B[J\x1B[1m"); /* erase display */
  26.    WinPuts(v,"\x1B[1;1HProtocol:\n");
  27.    WinPuts(v,"\x1B[2;1H\n");
  28.    WinPuts(v,"\x1B[3;1H     Filename:\x1B[3;40H         Size:\n");
  29.    WinPuts(v,"\x1B[4;1HExpected Time:\x1B[4;40H Elapsed Time:\n");
  30.    WinPuts(v,"\x1B[5;1H          CPS:\x1B[5;40H   Bytes Sent:\n");
  31.    WinPuts(v,"\x1B[6;1H   Block Size:\x1B[6;40H  Blocks Sent:\n");
  32.    WinPuts(v,"\x1B[7;1H  Block Check:\x1B[7;40H   Char Delay:\n");
  33.    WinPuts(v,"\x1B[8;1H  Packet Type:\x1B[8;40H Packet Delay:\n");
  34.    WinPuts(v,"\x1B[9;1H       Errors:\x1B[9;40H     TimeOuts:\n");
  35.    WinPuts(v,"\x1B[10;1H\n");
  36.    WinPuts(v,"\x1B[11;1H Last Message:\n");
  37.    WinPuts(v,"\x1B[12;1H   Last Error:\n");
  38.    WinPuts(v,"\x1B[13;1H\n");
  39.    WinPuts(v,"\x1B[14;1H       Status:\x1B[0m\n");
  40. }
  41.  
  42. void UpdateStats(struct Vars *v){
  43.    struct XPR_UPDATE *xpru = &v->xpru;
  44.    char Buffer[100],buffer[20];
  45.    unsigned long val = 0, va = 0, vb = 0;
  46.    if(!DOSBase) return;
  47.    if(!v->use_dos_lib) return; /* dos.library may be open */
  48.    if(!v->TransferWindow) return;
  49.    /* do we even have to update something ? */
  50.    if(xpru->xpru_updatemask){
  51.       if(xpru->xpru_updatemask & XPRU_PROTOCOL){
  52.          sprintf(Buffer,"\x1B[1;10H%-20.20s\n",xpru->xpru_protocol);
  53.          WinPuts(v,Buffer);
  54.       }
  55.       if(xpru->xpru_updatemask & XPRU_FILENAME){
  56.          sprintf(Buffer,"\x1B[3;15H%-20.20s\n",xpru->xpru_filename);
  57.          WinPuts(v,Buffer);
  58.       }
  59.       if(xpru->xpru_updatemask & XPRU_FILESIZE){
  60.          sprintf(Buffer,"\x1B[3;54H%-20.20ld\n",xpru->xpru_filesize);
  61.          WinPuts(v,Buffer);
  62.       }
  63.       if(xpru->xpru_updatemask & XPRU_EXPECTTIME){
  64.          sprintf(Buffer,"\x1B[4;15H%-20.20s\n",xpru->xpru_expecttime);
  65.          WinPuts(v,Buffer);
  66.       }
  67.       if(xpru->xpru_updatemask & XPRU_ELAPSEDTIME){
  68.          sprintf(Buffer,"\x1B[4;54H%-20.20s\n",xpru->xpru_elapsedtime);
  69.          WinPuts(v,Buffer);
  70.       }
  71.       if(xpru->xpru_updatemask & XPRU_DATARATE){
  72.          val = 0;
  73.          if(v->NEWBAUD){
  74.             val = (xpru->xpru_datarate * 1000) / v->NEWBAUD;
  75.          }
  76.          else{
  77.             val = (xpru->xpru_datarate * 1000) / v->Baud;
  78.          }
  79.          sprintf(buffer,"%ld (%ld%%)",xpru->xpru_datarate,val);
  80.          sprintf(Buffer,"\x1B[5;15H%-20.20s\n",buffer);
  81.          WinPuts(v,Buffer);
  82.       }
  83.       if(xpru->xpru_updatemask & XPRU_BYTES){
  84.          val = 0;
  85.          va = v->Fsize;
  86.          vb = xpru->xpru_bytes;
  87.          while(va > 1000){ /* don't really need to be all that precise */
  88.             va = va / 10;
  89.             vb = vb / 10;
  90.          }
  91.          if(va) val = (vb * 100) / va;
  92.          sprintf(buffer,"%ld (%ld%%)",xpru->xpru_bytes,val);
  93.          sprintf(Buffer,"\x1B[5;54H%-20.20s\n",buffer);
  94.          WinPuts(v,Buffer);
  95.       }
  96.       if(xpru->xpru_updatemask & XPRU_BLOCKSIZE){
  97.          sprintf(Buffer,"\x1B[6;15H%-20.20ld\n",xpru->xpru_blocksize);
  98.          WinPuts(v,Buffer);
  99.       }
  100.       if(xpru->xpru_updatemask & XPRU_BLOCKS){
  101.          sprintf(Buffer,"\x1B[6;54H%-20.20ld\n",xpru->xpru_blocks);
  102.          WinPuts(v,Buffer);
  103.       }
  104.       if(xpru->xpru_updatemask & XPRU_BLOCKCHECK){
  105.          sprintf(Buffer,"\x1B[7;15H%-20.20s\n",xpru->xpru_blockcheck);
  106.          WinPuts(v,Buffer);
  107.       }
  108.       if(xpru->xpru_updatemask & XPRU_CHARDELAY){
  109.          sprintf(Buffer,"\x1B[7;54H%-20.20ld\n",xpru->xpru_chardelay);
  110.          WinPuts(v,Buffer);
  111.       }
  112.       if(xpru->xpru_updatemask & XPRU_PACKETTYPE){
  113.          sprintf(Buffer,"\x1B[8;15H%-20.20ld\n",xpru->xpru_packettype);
  114.          WinPuts(v,Buffer);
  115.       }
  116.       if(xpru->xpru_updatemask & XPRU_PACKETDELAY){
  117.          sprintf(Buffer,"\x1B[8;54H%-20.20ld\n",xpru->xpru_packetdelay);
  118.          WinPuts(v,Buffer);
  119.       }
  120.       if(xpru->xpru_updatemask & XPRU_ERRORS){
  121.          sprintf(Buffer,"\x1B[9;15H%-20.20ld\n",xpru->xpru_errors);
  122.          WinPuts(v,Buffer);
  123.       }
  124.       if(xpru->xpru_updatemask & XPRU_TIMEOUTS){
  125.          sprintf(Buffer,"\x1B[9;54H%-20.20ld\n",xpru->xpru_timeouts);
  126.          WinPuts(v,Buffer);
  127.       }
  128.       if(xpru->xpru_updatemask & XPRU_MSG){
  129.          sprintf(Buffer,"\x1B[11;15H%-60.60s\n",xpru->xpru_msg);
  130.          WinPuts(v,Buffer);
  131.       }
  132.       if(xpru->xpru_updatemask & XPRU_ERRORMSG){
  133.          sprintf(Buffer,"\x1B[12;15H%-60.60s\n",xpru->xpru_errormsg);
  134.          WinPuts(v,Buffer);
  135.       }
  136.       if(xpru->xpru_updatemask & XPRU_STATUS){
  137.          sprintf(Buffer,"\x1B[14;15H%-20.20ld\n",xpru->xpru_status);
  138.          WinPuts(v,Buffer);
  139.       }
  140.    }
  141. }
  142.  
  143. void OpenDisplay(struct Vars *v){
  144.    /* open up the dos.library so we can do our own IO */
  145.    char *bufptr = WinName;
  146.    BPTR MyEnvVal = NULL;
  147.    char EnvVal[50];
  148.  
  149.    *bufptr = 0;
  150.  
  151.    CloseDisplay(v); /* maybe we are opening up in a different way */
  152.  
  153.    OpenDosLibrary();
  154.    if(!DOSBase) return; /* don't even bother opening up the window! */
  155.    if(!v->use_dos_lib) return; /* dos.library is still open, but we will not */
  156.                                /* touch it since another program may also be */
  157.                                /* accessing this library                     */
  158.    /* prevent any other program from doing things with DOSBase */
  159.    Forbid();
  160.    if(DOSBase){
  161.       if(!v->TransferWindow){
  162.          /* get the env: variable */
  163.          sprintf(EnvVal,"%sZedZapWindow",v->env_starter);
  164.          MyEnvVal = Open(EnvVal,MODE_OLDFILE);
  165.          if(MyEnvVal){
  166.             while(Read(MyEnvVal,bufptr,1)){
  167.                bufptr++;
  168.                *bufptr = 0;
  169.             }
  170.             Close(MyEnvVal);
  171.             MyEnvVal = NULL;
  172.          }
  173.          if(WinName[0]){
  174.             v->TransferWindow = Open(WinName,MODE_NEWFILE);
  175.             if(v->TransferWindow){
  176.                WinPuts(v,"\x9B\x3E\x31\x6C"); /* disable scroll */
  177.                WinPuts(v,"\x9B\x3F\x37\x6C"); /* disable autowrap */
  178.                WinPuts(v,"\x9B\x30\x20\x70"); /* disable cursor */
  179.             }
  180.          }
  181.       }
  182.    }
  183.    Permit();
  184.    ClearStats(v);
  185. }
  186.  
  187. void CloseDisplay(struct Vars *v){
  188.    /* prevent any other program from doing things with DOSBase */
  189.    Forbid();
  190.    if(DOSBase){ /* check if the dos.library is open... */
  191.       if(v->TransferWindow){ /* close the window... */
  192.          Close(v->TransferWindow);
  193.          v->TransferWindow = NULL;
  194.       }
  195.    }
  196.    Permit();
  197. }
  198.  
  199. void WinPuts(struct Vars *v,char *out_string){
  200.    if(!v->use_dos_lib) return; /* although dos.library may be open */
  201.    /* prevent any other program from doing things with DOSBase */
  202.    Forbid();
  203.    if(DOSBase){           /* check if can do dos functions */
  204.       if(v->TransferWindow){ /* check if the window is open */
  205.          Write(v->TransferWindow,out_string,strlen(out_string));
  206.       }
  207.    }
  208.    Permit();
  209. }
  210.  
  211. void OpenDosLibrary(){
  212.    Forbid();
  213.    if(!DOSBase){
  214.       DOSBase = (struct DosLibrary*)OpenLibrary("dos.library",0);
  215.    }
  216.    /* tada... the dos.library was secretly opened... */
  217.    Permit();
  218.    /* REMEBER: since multiple programs may use the same library, it is */
  219.    /* important to remeber that the dos.library is opened only ONCE!   */
  220.    /* Therefore one must be VERY SURE when calling XProtocolCleanup()  */
  221.    /* since that closes the dos.library */
  222.    /* Since XProtocolSetup can be called on many occasions without the */
  223.    /* need of XProtocolCleanup, I suggest setting up the protocol once */
  224.    /* for each slave (when using Welmat) and then cleaning up only if  */
  225.    /* all slaves have been shut down.                                  */
  226.    /* If the dos.library is opened, then one must be very sure that no */
  227.    /* other program will call XProtocolCleanup() while another program */
  228.    /* is still accessing the library!                                  */
  229.    /* A few Forbid() statements have been added to prevent some of the */
  230.    /* problems that may occur...                                       */
  231. }
  232.  
  233. void CloseDosLibrary(){
  234.    Forbid();
  235.    if(DOSBase){
  236.       CloseLibrary(DOSBase);
  237.       DOSBase = NULL;
  238.    }
  239.    Permit();
  240. }
  241.