home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #2 / RBBS_vol1_no2.iso / add2 / jmd4tlx.zip / JXFER.SLT < prev   
Text File  |  1989-03-20  |  9KB  |  276 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // This TELIX 3.11 script completely parses the file list, expands any
  3. // wildcards, and calls the Jmodem program once for each resulting fully
  4. // quaified filename.  Each file transfer attempt is noted in the file
  5. // "Jmodem.log" in the directory specified by the TELIX environment
  6. // variable.  If no directory is specified, the log is written in the
  7. // current directory.
  8. //
  9. // Written by: Michael K. Bozovich
  10. // Date: 3-19-89
  11. ///////////////////////////////////////////////////////////////////////////////
  12.  
  13. /////// Integer Variable Declarations.
  14.  
  15. int pointer = 0;               // String pointer.
  16. int done = 0;                  // Break flag.
  17. int handle;                    // Log file handle.
  18.  
  19. /////// String Variable Declarations.
  20.  
  21. str port[1];                   // COM port number.
  22. str fname[64];                 // Scratch buffer.
  23. str path[64];                  // Path name of file(s) to xfer.
  24.  
  25. str logfile[75];               // Log file name.
  26. str scratch[64];               // Scratch buffer.
  27. str xferdir[64];               // Transfer directory.
  28.  
  29. str crlf[2] = "^m^j";          // Carriage Return/Line Feed.
  30. str eofchar[1] = "^z";         // End of file character.
  31.  
  32. main(str mode)
  33.  
  34. {
  35.  
  36.   /////// Determine whether uploading or downloading.
  37.  
  38.   if(mode == "S")
  39.     xferdir = _up_dir;
  40.   else
  41.     xferdir = _down_dir;
  42.  
  43.   /////// Get current port number as a string.
  44.  
  45.   itos(get_port(), port);
  46.  
  47.   /////// Build log file name.
  48.  
  49.   logfile = _telix_dir;             // Try to use TELIX directory.
  50.   strcat(logfile, "jmodem.log");    // If user didn't specify it, put file
  51.                                     // in the current directory.
  52.  
  53.   /////// Write the header if we had to create the file.
  54.  
  55.   if (! filefind(logfile, 0, path))
  56.     {
  57.     handle = fopen(logfile, "a+");
  58.     fwrite("                     TELIX JMODEM File Transfer Log", 51, handle);
  59.     fwrite("^m^j", 2, handle);
  60.     fwrite("^m^j", 2, handle);
  61.     fwrite("^z", 1, handle);
  62.     fclose(handle);
  63.     }
  64.  
  65.   /////// Loop until the file list is exhausted.
  66.  
  67.   while(1)
  68.  
  69.   {
  70.     /////// Strip any leading spaces from file list.
  71.  
  72.     _ext_filespec = ltrim(_ext_filespec);
  73.  
  74.     /////// Find the first space in the file list.
  75.  
  76.     pointer = strpos(_ext_filespec, " ", pointer);
  77.  
  78.     if (pointer == -1)                      // No spaces, only one file left.
  79.     {
  80.       scratch = _ext_filespec;
  81.       done = 1;                             // Set break flag.
  82.     }
  83.     else                                    // Strip the first file from list.
  84.     {
  85.       substr(_ext_filespec, 0, pointer, scratch);
  86.       substr(_ext_filespec, pointer + 1, 64, _ext_filespec);
  87.       pointer = 0;                          // Reset pointer.
  88.     }
  89.  
  90.     /////// Fully qualify the resultant file name.
  91.  
  92.     if(strpos(scratch, "\", 0) == -1)         // User didn't specify a path.
  93.       if(strpos(scratch, ":", 0) == -1)       // Or a drive.
  94.                                               // Let TELIX specify it, then!!
  95.         inschrs(xferdir, scratch, 0, strlen(xferdir));
  96.  
  97.     /////// Strip the resulting drive/pathname because
  98.     /////// the filefind() function does not retain it!
  99.  
  100.     fnstrip(scratch, 12, path);
  101.  
  102.     if(mode == "S")            // User is uploading.
  103.  
  104.       /////// Expand any wild cards while making sure the file exists.
  105.  
  106.       while (filefind(scratch, 0, fname) != 0)
  107.       {
  108.         jmodem(mode, port, fname, path);
  109.         scratch = "";          // Prepare to find next matching file.
  110.       }
  111.  
  112.     else                       // User is downloading.
  113.  
  114.       /////// Make sure that file DOES NOT exist.
  115.  
  116.       if(filefind(scratch, 0, fname) == 0)
  117.         jmodem(mode, port, scratch, path);
  118.       else
  119.         {
  120.         printsc("The file ");
  121.         printsc(scratch);
  122.         prints(" already exists!  It's download was ABORTED.");
  123.         }
  124.  
  125.     if(done)
  126.       break;
  127.   }
  128.  
  129.   /////// Erase the temporary file used for size determination.
  130.  
  131.   dos("erase jsize.$$$", 0);
  132.  
  133.   /////// Return to terminal.
  134.  
  135.   return();
  136.  
  137. }
  138.  
  139. ///////////////////////////////////////////////////////////////////////////////
  140. ///////////////////////////////////////////////////////////////////////////////
  141.  
  142. jmodem(str mode, str port, str fname, str path)
  143.  
  144. {
  145.  
  146.   /////// Integer Variable Declarations.
  147.  
  148.   int size;                      // Numeric count of bytes transferred.
  149.   int handle;                    // Log file handle.
  150.   int abort;                     // Jmodem return code.
  151.   int start;                     // Used to time transfer.
  152.  
  153.   /////// String Variable Declarations.
  154.  
  155.   str cps[5];                    // Transfer speed.
  156.   str comline[70];               // Jmodem command line buffer.
  157.   str buff[110];                 // Scratch buffer used to build log entry.
  158.   str bytes[7];                  // String cast of "size".
  159.   str baud[6];                   // Port speed.
  160.   str elapse[5];                 // String cast of transfer time.
  161.   str xfer_date[8];              // Today's date.
  162.   str status[] = "COMPLETED";    // String to hold status of transfer.
  163.   str crlf[2] = "^m^j";          // Carriage Return/Line Feed.
  164.   str eofchar[1] = "^z";         // End of file character.
  165.  
  166.   /////// Build the Jmodem command string.
  167.  
  168.   comline = mode;
  169.   strcat(comline, port);
  170.   strcat(comline, " ");
  171.   if(mode == "S")
  172.     inschrs(path, fname, 0, strlen(path));  // Restore path information.
  173.   strcat(comline, fname);
  174.  
  175.   /////// Run the Jmodem program with the command line just built.
  176.  
  177.   start = curtime();                      // Start timing.
  178.   abort = run("jmodem", comline, 0);
  179.   start = curtime() - start;              // Finished.
  180.  
  181.   /////// Calculate the file size.
  182.  
  183.   run("jsize", fname);               // Run the kludge.
  184.  
  185.   handle = fopen("jsize.$$$", "r+"); // Open temporary file.
  186.   fread(bytes, 7, handle);           // Read the number of bytes.
  187.   fclose(handle);                    // Close the file.
  188.  
  189.   /////// Determine status of the transfer.
  190.  
  191.   if(abort)
  192.   {
  193.     status = "*ABORTED*";
  194.     size = 0;
  195.   }
  196.   else
  197.     size = stoi(ltrim(bytes));
  198.  
  199.   /////// Open log for appending.
  200.  
  201.   handle = fopen(logfile, "a+");
  202.  
  203.   /////// Move the file pointer to the end of file marker.
  204.  
  205.   fseek(handle, -1, 2);
  206.  
  207.   /////// Build the log entry in a scratch buffer.
  208.  
  209.   buff = mode;                   // Get the transfer mode.
  210.   pad(buff, bytes, 7);           // Insert spaces.
  211.   strcat(buff, bytes);           // Append size to buff.
  212.   itos(get_baud(), baud);        // Get baud rate - cast into string.
  213.   pad(buff, baud, 7);            // Insert spaces.
  214.   strcat(buff, baud);            // Append baud rate.
  215.   strcat(buff, " bps ");         // Append units.
  216.   itos(start, elapse);           // Get elapsed time - cast into string.
  217.   itos(size / start, cps);       // Calculate speed - cast into string.
  218.   pad(buff, cps, 6);             // Insert spaces.
  219.   strcat(buff, cps);             // Append speed.
  220.   strcat(buff, " cps ");         // Append units.
  221.   pad(buff, elapse, 6);          // Insert spaces.
  222.   strcat(buff, elapse);          // Append elapsed time.
  223.   strcat(buff, "s ");            // Append units.
  224.   date(curtime(), xfer_date);    // Get today's date.
  225.   strcat(buff, xfer_date);       // Append it to the buffer.
  226.   strcat(buff, " ");             // Insert a space.
  227.   strcat(buff, status);          // Append status string.
  228.   strcat(buff, " ");             // Insert a space.
  229.   strcat(buff, fname);           // Append the file name.
  230.   strcat(buff, "^m^j");          // Append a newline.
  231.   strcat(buff, "^z");            // Append eof.            -- DONE --
  232.  
  233.   /////// Write the entry to the log.
  234.  
  235.   fwrite(buff, strlen(buff), handle);
  236.  
  237.   /////// Close the file.
  238.  
  239.   fclose(handle);
  240.  
  241. }
  242.  
  243. ///////////////////////////////////////////////////////////////////////////////
  244. ///////////////////////////////////////////////////////////////////////////////
  245.  
  246. ltrim(str str_2_trim)
  247.  
  248. {
  249.   int j;
  250.   while(1)
  251.   {
  252.     if(j = strpos(str_2_trim, " ", 0) != 0)
  253.       break;
  254.  
  255.     substr(str_2_trim, 1, strlen(str_2_trim), str_2_trim);
  256.   }
  257.   return(str_2_trim);
  258. }
  259.  
  260. ///////////////////////////////////////////////////////////////////////////////
  261. ///////////////////////////////////////////////////////////////////////////////
  262.  
  263. pad(str buffer, str junk, int spaces)
  264.  
  265. {
  266.   int n;
  267.  
  268.   for (n = 0; n != (spaces - strlen(junk)); n = n + 1)
  269.     strcat(buffer, " ");
  270. }
  271.  
  272. ///////////////////////////////////////////////////////////////////////////////
  273. ///////////////////////////////////////////////////////////////////////////////
  274.  
  275. // eof jxfer.slt
  276.