home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVSOR / BATCH.C next >
Text File  |  1996-11-30  |  22KB  |  949 lines

  1.  
  2. #include "vars.h"
  3.  
  4. #pragma hdrstop
  5.  
  6. #include <dir.h>
  7.  
  8. #define SETREC(f,i)  sh_lseek(f,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
  9.  
  10. /****************************************************************************/
  11.  
  12. /*
  13.  * Shows listing of files currently in batch queue(s), both upload and
  14.  * download. Shows estimated time, by item, for files in the d/l queue.
  15.  */
  16.  
  17. void listbatch(void)
  18. {
  19.   char s[81];
  20.   int abort,i;
  21.  
  22.   abort=0;
  23.   nl();
  24.   outstr(get_string(864));
  25.   npr("%d  ",numbatch);
  26.   if (numbatchdl) {
  27.     outstr(get_string(865));
  28.     pl(ctim(batchtime));
  29.   } else
  30.     nl();
  31.   nl();
  32.   for (i=0; (i<numbatch) && (!abort) && (!hangup); i++) {
  33.     if (batch[i].sending)
  34.       sprintf(s,"%d. %s %s   %s  %s",
  35.       i+1,
  36.       get_string(1621),
  37.       batch[i].filename,
  38.       ctim(batch[i].time),
  39.       directories[batch[i].dir].name);
  40.     else
  41.       sprintf(s,"%d. %s %s             %s",
  42.       i+1,
  43.       get_string(1622),
  44.       batch[i].filename,
  45.       directories[batch[i].dir].name);
  46.  
  47.     pla(s,&abort);
  48.   }
  49. }
  50.  
  51. /****************************************************************************/
  52.  
  53. /*
  54.  * Deletes one item (index i) from the d/l batch queue.
  55.  */
  56.  
  57. void delbatch(int i)
  58. {
  59.   int i1;
  60.  
  61.   if (i<numbatch) {
  62.     if (batch[i].sending) {
  63.       batchtime -= batch[i].time;
  64.       --numbatchdl;
  65.     }
  66.     --numbatch;
  67.     for (i1=i; i1<=numbatch; i1++) {
  68.       batch[i1]=batch[i1+1];
  69.     }
  70.   }
  71. }
  72.  
  73. /****************************************************************************/
  74.  
  75. void downloaded(char *fn, long cps)
  76. {
  77.   int i,i1,f;
  78.   uploadsrec u;
  79.   char s[161];
  80.   userrec ur;
  81.  
  82.   for (i1=0; i1<numbatch; i1++) {
  83.     if ((strcmp(fn,batch[i1].filename)==0) && (batch[i1].sending)) {
  84.       dliscan1(batch[i1].dir);
  85.       i=recno((batch[i1].filename));
  86.       if (i>0) {
  87.         f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  88.         SETREC(f,i);
  89.         sh_read(f,(void *)&u,sizeof(uploadsrec));
  90.         ++thisuser.downloaded;
  91.         thisuser.dk += (int) (bytes_to_k(u.numbytes));
  92.         ++u.numdloads;
  93.         SETREC(f,i);
  94.         sh_write(f,(void *)&u,sizeof(uploadsrec));
  95.         f=sh_close(f);
  96.         if (cps)
  97.           sprintf(s,get_stringx(1,50),u.filename, cps);
  98.         else
  99.           sprintf(s,get_stringx(1,43),u.filename);
  100.         sysoplog(s);
  101.         if (syscfg.sysconfig & sysconfig_log_dl) {
  102.           read_user(u.ownerusr, &ur);
  103.           if (!(ur.inact & inact_deleted)) {
  104.             if (date_to_daten(ur.firston) < u.daten) {
  105.               sprintf(s,get_stringx(1,51),
  106.                 nam(&thisuser,usernum), u.filename, date());
  107.               ssm(u.ownerusr,0,s);
  108.             }
  109.           }
  110.         }
  111.       }
  112.       delbatch(i1);
  113.  
  114.       return;
  115.     }
  116.   }
  117.   sprintf(s,get_stringx(1,52),fn);
  118.   sysoplog(s);
  119. }
  120.  
  121. /****************************************************************************/
  122.  
  123. void didnt_upload(int ind)
  124. {
  125.   int i,i1,f;
  126.   char s[161];
  127.   uploadsrec u;
  128.  
  129.   if (batch[ind].sending)
  130.     return;
  131.  
  132.   dliscan1(batch[ind].dir);
  133.   i=recno(batch[ind].filename);
  134.   if (i>0) {
  135.     f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  136.     do {
  137.       SETREC(f,i);
  138.       sh_read(f, &u, sizeof(uploadsrec));
  139.       if (u.numbytes!=0) {
  140.         f=sh_close(f);
  141.         i=nrecno(batch[ind].filename, i);
  142.         f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  143.       }
  144.     } while ((i!=-1) && (u.numbytes!=0));
  145.     if ((i!=-1) && (u.numbytes==0)) {
  146.       if (u.mask & mask_extended)
  147.         delete_extended_description(u.filename);
  148.       for (i1=i; i1<numf; i1++) {
  149.         SETREC(f,i1+1);
  150.         sh_read(f,(void *)&u,sizeof(uploadsrec));
  151.         SETREC(f,i1);
  152.         sh_write(f,(void *)&u,sizeof(uploadsrec));
  153.       }
  154.       --i;
  155.       --numf;
  156.       SETREC(f,0);
  157.       sh_read(f, &u, sizeof(uploadsrec));
  158.       u.numbytes=numf;
  159.       SETREC(f,0);
  160.       sh_write(f,(void *)&u,sizeof(uploadsrec));
  161.       f=sh_close(f);
  162.       return;
  163.     }
  164.     f=sh_close(f);
  165.   }
  166.   sprintf(s,get_stringx(1,53),batch[ind].filename);
  167.   sysoplog(s);
  168. }
  169.  
  170. /****************************************************************************/
  171.  
  172. int try_to_ul(char *fn)
  173. {
  174.  
  175.   if (hangup)
  176.     return(1);
  177.  
  178.   if (!okfn(fn))
  179.     return(1);
  180.  
  181.   /* future expansion here */
  182.  
  183.   /* yes, this should be return(1) until there is code above to prompt the */
  184.   /* user for the file's info, and to handle uploading it */
  185.   return(1);
  186. }
  187.  
  188. /****************************************************************************/
  189.  
  190. void uploaded(char *fn, long cps)
  191. {
  192.   int i1, rn, f, f1;
  193.   uploadsrec u;
  194.   char s[161], s1[81], s2[81];
  195.  
  196.   for (i1=0; i1<numbatch; i1++) {
  197.     if ((strcmp(fn,batch[i1].filename)==0) && (!batch[i1].sending)) {
  198.       dliscan1(batch[i1].dir);
  199.       rn=recno((batch[i1].filename));
  200.       if (rn>0) {
  201.         f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  202.         do {
  203.           SETREC(f,rn);
  204.           sh_read(f, &u, sizeof(uploadsrec));
  205.           if (u.numbytes!=0)
  206.             rn=nrecno(batch[i1].filename, rn);
  207.         } while ((rn!=-1) && (u.numbytes!=0));
  208.         f=sh_close(f);
  209.         if ((rn!=-1) && (u.numbytes==0)) {
  210.  
  211.           sprintf(s1,"%s%s",syscfgovr.batchdir, fn);
  212.           sprintf(s2,"%s%s", directories[batch[i1].dir].path, fn);
  213.  
  214.           if ((strcmp(s1,s2)!=0) && (exist(s1))) {
  215.             f1=0;
  216.             if ((s1[1]!=':') && (s2[1]!=':'))
  217.               f1=1;
  218.             if ((s1[1]==':') && (s2[1]==':') && (s1[0]==s2[0]))
  219.               f1=1;
  220.             if (f1) {
  221.               rename(s1,s2);
  222.               unlink(s1);
  223.             } else {
  224.               copy_file(s1,s2);
  225.               unlink(s1);
  226.             }
  227.           }
  228.  
  229.           f1=sh_open1(s2,O_RDONLY | O_BINARY);
  230.           if (f1>0) {
  231.             if (syscfg.upload_c[0]) {
  232.               sh_close(f1);
  233.               if (check_ul_event(batch[i1].dir, &u)) {
  234.                 didnt_upload(i1);
  235.                 f1=-1;
  236.               } else {
  237.                 f1=sh_open1(s2,O_RDONLY | O_BINARY);
  238.               }
  239.             }
  240.             if (f1>=0) {
  241.               u.numbytes = filelength(f1);
  242.               sh_close(f1);
  243.               get_file_idz(&u,batch[i1].dir);
  244.               ++thisuser.uploaded;
  245.               modify_database(u.filename,1);
  246.               thisuser.uk += (int) (bytes_to_k(u.numbytes));
  247.               lock_status();
  248.               ++status.uptoday;
  249.               ++status.filechange[filechange_upload];
  250.               save_status();
  251.               f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  252.               SETREC(f,rn);
  253.               sh_write(f,(void *)&u,sizeof(uploadsrec));
  254.               f=sh_close(f);
  255.               sprintf(s,get_stringx(1,54),
  256.                 u.filename,
  257.                 directories[batch[i1].dir].name, cps);
  258.               sysoplog(s);
  259.               outstr(get_string(866));
  260.               outstr(u.filename);
  261.               outstr(get_string(867));
  262.               pl(directories[batch[i1].dir].name);
  263.             }
  264.           }
  265.           delbatch(i1);
  266.           return;
  267.         }
  268.       }
  269.       delbatch(i1);
  270.       if (try_to_ul(fn)) {
  271.         sprintf(s,get_stringx(1,55), fn);
  272.         sysoplog(s);
  273.         outstr(get_string(868));
  274.         pl(fn);
  275.       }
  276.  
  277.       return;
  278.     }
  279.   }
  280.   if (try_to_ul(fn)) {
  281.     sprintf(s,get_stringx(1,56),fn);
  282.     sysoplog(s);
  283.     outstr(get_string(869));
  284.     pl(fn);
  285.     sprintf(s,"%s%s",syscfgovr.batchdir, fn);
  286.     unlink(s);
  287.   }
  288. }
  289.  
  290. /****************************************************************************/
  291.  
  292. void ymbatchdl(int had)
  293. {
  294.   int rr,i,ok,cur=0,f;
  295.   char s[161],s1[81];
  296.   uploadsrec u;
  297.   double percent;
  298.  
  299.   if (!incom)
  300.     return;
  301.   sprintf(s,get_stringx(1,57),numbatchdl, ctim(batchtime));
  302.   if (had)
  303.     strcat(s,get_stringx(1,58));
  304.   sysoplog(s);
  305.   nl();
  306.   pl(s);
  307.   nl();
  308.  
  309.   rr=0;
  310.   do {
  311.     tleft(1);
  312.     if ((syscfg.req_ratio>0.0001) && (ratio()<syscfg.req_ratio))
  313.       rr=1;
  314.     if (thisuser.exempt & exempt_ratio)
  315.       rr=0;
  316.     if (!batch[cur].sending) {
  317.       rr=0;
  318.       ++cur;
  319.     }
  320.     if ((nsl()>=batch[cur].time) && (!rr)) {
  321.       dliscan1(batch[cur].dir);
  322.       i=recno(batch[cur].filename);
  323.       if (i<=0) {
  324.         delbatch(cur);
  325.       } else {
  326.         sprintf(s,get_stringx(1,59),numbatchdl,ctim(batchtime));
  327.         outs(s);
  328.         f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  329.         SETREC(f,i);
  330.         sh_read(f,(void *)&u,sizeof(uploadsrec));
  331.         f=sh_close(f);
  332.         sprintf(s,"%s%s",directories[batch[cur].dir].path,u.filename);
  333.         if(directories[batch[cur].dir].mask & mask_cdrom) {
  334.           sprintf(s1,"%s%s",
  335.             directories[batch[cur].dir].path,u.filename);
  336.           sprintf(s,"%s%s",
  337.             syscfgovr.tempdir,u.filename);
  338.           if (!exist(s))
  339.             copy_file(s1,s);
  340.         }
  341.         write_inst(INST_LOC_DOWNLOAD,udir[curdir].subnum,INST_FLAGS_NONE);
  342.         xymodem_send(s,&ok,&percent,u.filetype,1,1,1);
  343.         if (ok) {
  344.           downloaded(u.filename, 0);
  345.         } else {
  346.         }
  347.       }
  348.     } else
  349.       delbatch(cur);
  350.   } while ((ok) && (!hangup) && (numbatch>cur) && (!rr));
  351.   if ((ok) && (!hangup))
  352.     endbatch();
  353.   if (rr) {
  354.     nl();
  355.     pl(get_string(870));
  356.     nl();
  357.   }
  358.   if (had) {
  359.     bihangup(0);
  360.   }
  361. }
  362.  
  363. /****************************************************************************/
  364.  
  365. void handle_dszline(char *l)
  366. {
  367.   char *ss;
  368.   int i;
  369.   long cps;
  370.   char s[161];
  371.  
  372.   /* find the filename */
  373.   ss=strtok(l," \t");
  374.   for (i=0; (i<10) && (ss); i++) {
  375.     switch(i) {
  376.       case 4: cps=atol(ss); break;
  377.     }
  378.     ss=strtok(NULL," \t");
  379.   }
  380.  
  381.   if (ss) {
  382.     strcpy(s,stripfn(ss));
  383.     align(s);
  384.  
  385.     switch(*l) {
  386.       case 'Z':
  387.       case 'r':
  388.       case 'R':
  389.       case 'B':
  390.       case 'H':
  391.         /* received a file */
  392.         uploaded(s,cps);
  393.         break;
  394.  
  395.       case 'z':
  396.       case 's':
  397.       case 'S':
  398.       case 'b':
  399.       case 'h':
  400.       case 'Q':
  401.         /* sent a file */
  402.         downloaded(s,cps);
  403.         break;
  404.  
  405.       case 'E':
  406.       case 'e':
  407.       case 'L':
  408.       case 'l':
  409.       case 'U':
  410.         /* error */
  411.         sprintf(s,get_stringx(1,60),ss);
  412.         sysoplog(s);
  413.         break;
  414.     }
  415.   }
  416. }
  417.  
  418. /****************************************************************************/
  419.  
  420. double ratio1(long a)
  421. {
  422.   double r;
  423.  
  424.   if ((thisuser.dk==0) && (a==0))
  425.     return(99.999);
  426.   r=((float) thisuser.uk) / ((float) (thisuser.dk + a));
  427.   if (r>99.998)
  428.     r=99.998;
  429.   return(r);
  430. }
  431.  
  432. /****************************************************************************/
  433.  
  434. void make_ul_batch_list(char *listfn)
  435. {
  436.   int f,i;
  437.   char s[255],s1[81];
  438.  
  439.   if(instance > 1)
  440.     sprintf(listfn,"%s\\FILESUL.%3.3d",cdir,instance);
  441.   else
  442.     sprintf(listfn,"%s\\FILES.UL",cdir);
  443.  
  444.   _chmod(listfn,1,0);
  445.   unlink(listfn);
  446.  
  447.   f=sh_open(listfn,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  448.   if (f<0) {
  449.     listfn[0]=0;
  450.     return;
  451.   }
  452.  
  453.   for (i=0; i<numbatch; i++) {
  454.     if (!batch[i].sending) {
  455.       cd_to(directories[batch[i].dir].path);
  456.       get_dir(s1,1);
  457.       cd_to(cdir);
  458.       sprintf(s,"%s%s\r\n",s1,stripfn(batch[i].filename));
  459.       sh_write(f,s,strlen(s));
  460.     }
  461.   }
  462.   sh_close(f);
  463. }
  464.  
  465. /****************************************************************************/
  466.  
  467. void make_dl_batch_list(char *listfn)
  468. {
  469.   char s[255],s1[81],s2[81];
  470.   int i, f, ok;
  471.   double at=0.0;
  472.   long addk=0,thisk;
  473.  
  474.   if(instance > 1)
  475.     sprintf(listfn,"%s\\FILESDL.%3.3d",cdir,instance);
  476.   else
  477.     sprintf(listfn,"%s\\FILES.DL",cdir);
  478.  
  479.   _chmod(listfn,1,0);
  480.   unlink(listfn);
  481.  
  482.   f=sh_open(listfn,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  483.   if (f<0) {
  484.     listfn[0]=0;
  485.     return;
  486.   }
  487.  
  488.   for (i=0; i<numbatch; i++) {
  489.     if (batch[i].sending) {
  490.       if(directories[batch[i].dir].mask & mask_cdrom) {
  491.         cd_to(syscfgovr.tempdir);
  492.         get_dir(s1,1);
  493.         sprintf(s,"%s%s",s1,stripfn(batch[i].filename));
  494.         if(!exist(s)) {
  495.           cd_to(directories[batch[i].dir].path);
  496.           get_dir(s2,1);
  497.           strcat(s2,stripfn(batch[i].filename));
  498.           copy_file(s2,s);
  499.         }
  500.         strcat(s,"\r\n");
  501.       } else {
  502.         cd_to(directories[batch[i].dir].path);
  503.         get_dir(s1,1);
  504.         sprintf(s,"%s%s\r\n",s1,stripfn(batch[i].filename));
  505.       }
  506.       ok=1;
  507.       cd_to(cdir);
  508.       if (nsl() < (batch[i].time + at)) {
  509.         ok=0;
  510.         npr("%s%s%s\r\n",
  511.             get_string(1478),
  512.             batch[i].filename,
  513.             get_string(1479));
  514.       }
  515.       thisk=bytes_to_k(batch[i].len);
  516.       if ((syscfg.req_ratio>0.0001) && (ratio1(addk+thisk)<syscfg.req_ratio) &&
  517.           (!(thisuser.exempt & exempt_ratio))) {
  518.         ok=0;
  519.         npr("%s%s%s\r\n",
  520.             get_string(1478),
  521.             batch[i].filename,
  522.             get_string(1480));
  523.       }
  524.       if (ok) {
  525.         sh_write(f,s,strlen(s));
  526.         at += batch[i].time;
  527.         addk += thisk;
  528.       }
  529.     }
  530.   }
  531.   sh_close(f);
  532. }
  533.  
  534. /****************************************************************************/
  535.  
  536. void run_cmd(char *cmdln, char *downlist, char *uplist, char *dl, int had)
  537. {
  538.   char sx1[21], sx2[21], sx3[21], s[161];
  539.  
  540.   ultoa(com_speed,sx1,10);
  541.   if ((com_speed==1) || (com_speed==49664))
  542.     strcpy(sx1,"115200");
  543.   ultoa(modem_speed,sx3,10);
  544.   sx2[0]='0'+syscfgovr.primaryport;
  545.   sx2[1]=0;
  546.   stuff_in(s,cmdln,sx1,sx2,downlist,sx3,uplist);
  547.   if (s[0]) {
  548.     make_abs_cmd(s);
  549.     clrscrb();
  550.     outs(dl);
  551.     outs("\r\n");
  552.     outs(s);
  553.     outs("\r\n");
  554.     if (incom) {
  555.       _chmod(dszlog,1,0);
  556.       unlink(dszlog);
  557.  
  558.       create_chain_file();
  559.  
  560.       cd_to(syscfgovr.batchdir);
  561.  
  562.       extern_prog(s, sysinfo.spawn_opts[7]);
  563.  
  564.       cd_to(cdir);
  565.  
  566.       if (had) {
  567.         bihangup(1);
  568.         if (!cdet()) {
  569.           dtr(1);
  570.           wait1(5);
  571.           holdphone(1);
  572.         }
  573.       } else {
  574.         nl();
  575.         pl(get_string(26));
  576.         nl();
  577.       }
  578.  
  579.       process_dszlog();
  580.  
  581.       topscreen();
  582.     }
  583.   }
  584.  
  585.   if (downlist[0]) {
  586.     _chmod(downlist,1,0);
  587.     unlink(downlist);
  588.   }
  589.   if (uplist[0]) {
  590.     _chmod(uplist,1,0);
  591.     unlink(uplist);
  592.   }
  593. }
  594.  
  595. /****************************************************************************/
  596.  
  597. void process_dszlog(void)
  598. {
  599.   int f,i,i1;
  600.   char *ss;
  601.   char **lines;
  602.  
  603.   lines = (char **)malloca(sysinfo.max_batch * sizeof(char *) * 2);
  604.  
  605.   if (!lines)
  606.     return;
  607.  
  608.   f=sh_open1(dszlog,O_RDONLY | O_BINARY);
  609.   if (f>0) {
  610.     i1=(int)filelength(f);
  611.     ss=malloca(i1);
  612.     if (ss) {
  613.       i=sh_read(f,ss,i1);
  614.       if (i>0) {
  615.         ss[i]=0;
  616.         lines[0]=strtok(ss,"\r\n");
  617.         for (i=1; (i<sysinfo.max_batch*2-2) && (lines[i-1]); i++)
  618.           lines[i]=strtok(NULL,"\n");
  619.  
  620.         lines[sysinfo.max_batch*2-2]=NULL;
  621.  
  622.         for (i1=0; lines[i1]; i1++) {
  623.           handle_dszline(lines[i1]);
  624.         }
  625.  
  626.       }
  627.       bbsfree(ss);
  628.     }
  629.     sh_close(f);
  630.   }
  631.  
  632.   bbsfree(lines);
  633. }
  634.  
  635. /****************************************************************************/
  636.  
  637. void dszbatchdl(int had, char *cmdln, char *desc)
  638. {
  639.   char listfn[81],dl[161];
  640.  
  641.   sprintf(dl,get_stringx(1,61),
  642.           desc, numbatchdl, ctim(batchtime));
  643.   if (had)
  644.     strcat(dl,get_stringx(1,58));
  645.   sysoplog(dl);
  646.   nl();
  647.   pl(dl);
  648.   nl();
  649.  
  650.   write_inst(INST_LOC_DOWNLOAD,udir[curdir].subnum,INST_FLAGS_NONE);
  651.   make_dl_batch_list(listfn);
  652.   run_cmd(cmdln, listfn, "", dl, had);
  653. }
  654.  
  655. /****************************************************************************/
  656.  
  657. void dszbatchul(int had, char *cmdln, char *desc)
  658. {
  659.   char listfn[81],dl[161];
  660.   double ti;
  661.  
  662.   sprintf(dl,get_stringx(1,62), desc, numbatch-numbatchdl);
  663.   if (had)
  664.     strcat(dl,get_stringx(1,58));
  665.   sysoplog(dl);
  666.   nl();
  667.   pl(dl);
  668.   nl();
  669.  
  670.   write_inst(INST_LOC_UPLOAD,udir[curdir].subnum,INST_FLAGS_NONE);
  671.   make_ul_batch_list(listfn);
  672.  
  673.   ti=timer();
  674.   run_cmd(cmdln, "", listfn, dl, had);
  675.   ti=timer()-ti;
  676.   if (ti<0)
  677.     ti += 24.0*3600.0;
  678.   thisuser.extratime += ti;
  679. }
  680.  
  681. /****************************************************************************/
  682.  
  683. void bibatch(int had, char *cmdln, char *desc)
  684. {
  685.   char listfn[81], listfn1[81], dl[161];
  686.   double ti;
  687.  
  688.   sprintf(dl,get_stringx(1,63),
  689.     desc, numbatchdl, numbatch-numbatchdl);
  690.   if (had)
  691.     strcat(dl,get_stringx(1,58));
  692.   sysoplog(dl);
  693.   nl();
  694.   pl(dl);
  695.   nl();
  696.  
  697.   write_inst(INST_LOC_BIXFER,udir[curdir].subnum,INST_FLAGS_NONE);
  698.   make_ul_batch_list(listfn);
  699.   make_dl_batch_list(listfn1);
  700.  
  701.   ti=timer();
  702.   run_cmd(cmdln, listfn1, listfn, dl, had);
  703.   ti=timer()-ti;
  704.   if (ti<0)
  705.     ti += 24.0*3600.0;
  706.   /* Hmm... */
  707.   /* thisuser.extratime += ti; */
  708. }
  709.  
  710. /****************************************************************************/
  711.  
  712. void batchdl(int mode)
  713. {
  714.   int i,done,had,otag;
  715.   char s[81],ch;
  716.  
  717.   done=0;
  718.   if (numbatch==0) {
  719.     nl();
  720.     pl(get_string(871));
  721.     nl();
  722.     return;
  723.   }
  724.   otag=tagging;
  725.   tagging=0;
  726.   do {
  727.     switch(mode) {
  728.       case 0:
  729.         nl();
  730.         if (menu_on()) {
  731.           rip_saveall();
  732.           printmenu(9);
  733.         } else
  734.           prt(2,get_string(872));
  735.         ch=onek("Q?CLRDUB");
  736.         if (menu_on())
  737.           rip_restoreall();
  738.       break;
  739.       case 1:
  740.         listbatch();
  741.         ch='D';
  742.       break;
  743.       case 2:
  744.         listbatch();
  745.         ch='U';
  746.       break;
  747.     }
  748.     switch(ch) {
  749.       case '?':
  750.         printmenu(9);
  751.         break;
  752.       case 'Q':
  753.         done=1;
  754.         break;
  755.       case 'L':
  756.         listbatch();
  757.         break;
  758.       case 'R':
  759.         nl();
  760.         prt(2,get_string(724));
  761.         input(s,4);
  762.         i=atoi(s);
  763.         if ((i>0) && (i<=numbatch)) {
  764.           didnt_upload(i-1);
  765.           delbatch(i-1);
  766.         }
  767.         if (numbatch==0) {
  768.           nl();
  769.           pl(get_string(873));
  770.           nl();
  771.           done=1;
  772.         }
  773.         break;
  774.       case 'C':
  775.         prt(5,get_string(874));
  776.         if (yn()) {
  777.           for (i=0; i<numbatch; i++)
  778.             didnt_upload(i);
  779.           numbatch=0;
  780.           numbatchdl=0;
  781.           batchtime=0.0;
  782.           done=1;
  783.           pl(get_string(875));
  784.         }
  785.         done=1;
  786.         break;
  787.       case 'U':
  788.         if (numbatchdl==numbatch) {
  789.           nl();
  790.           pl(get_string(876));
  791.           nl();
  792.           break;
  793.         }
  794.         nl();
  795.         prt(5,get_string(877));
  796.         had=yn();
  797.         nl();
  798.  
  799.         i=get_protocol(xf_up_batch);
  800.         if (i>0) {
  801.  
  802.           dszbatchul(had, externs[i-6].receivebatchfn, externs[i-6].description);
  803.  
  804.           if (!had) {
  805.             nl();
  806.             outstr(get_string(782));
  807.             npr("%-6.3f\r\n",ratio());
  808.           }
  809.         }
  810.         done=1;
  811.         break;
  812.       case 'B':
  813.         if (modem_flag & flag_as) {
  814.           nl();
  815.           pl(get_string(878));
  816.           pl(get_string(879));
  817.           pl(get_string(880));
  818.           nl();
  819.           prt(5,get_string(881));
  820.           if (!yn()) {
  821.             done=1;
  822.             break;
  823.           }
  824.         }
  825.         nl();
  826.         prt(5,get_string(877));
  827.         had=yn();
  828.         nl();
  829.  
  830.         i=get_protocol(xf_bi);
  831.         if (i>0) {
  832.  
  833.           bibatch(had, externs[i-6].bibatchfn, externs[i-6].description);
  834.  
  835.           if (!had) {
  836.             nl();
  837.             outstr(get_string(782));
  838.             npr("%-6.3f\r\n",ratio());
  839.           }
  840.         }
  841.         done=1;
  842.         break;
  843.       case 'D':
  844.         if (numbatchdl==0) {
  845.           nl();
  846.           pl(get_string(882));
  847.           nl();
  848.           done=1;
  849.           break;
  850.         }
  851.  
  852.         nl();
  853.         if (!ratio_ok()) {
  854.           nl();
  855.           pl(get_string(883));
  856.           nl();
  857.           done=1;
  858.           break;
  859.         }
  860.         nl();
  861.         prt(5,get_string(877));
  862.         had=yn();
  863.         nl();
  864.  
  865.         i=get_protocol(xf_down_batch);
  866.         if (i>0) {
  867.  
  868.           if (i==4) {
  869.             if (over_intern && (over_intern[2].othr & othr_override_internal) &&
  870.                 (over_intern[2].sendbatchfn[0]))
  871.               dszbatchdl(had, over_intern[2].sendbatchfn, prot_name(4));
  872.             else
  873.               ymbatchdl(had);
  874.           } else
  875.             dszbatchdl(had,externs[i-6].sendbatchfn, externs[i-6].description);
  876.  
  877.           if (!had) {
  878.             nl();
  879.             outstr(get_string(782));
  880.             npr("%-6.3f\r\n",ratio());
  881.           }
  882.         }
  883.         done=1;
  884.         break;
  885.     }
  886.   } while ((!done) && (!hangup));
  887.   tagging=otag;
  888. }
  889.  
  890. /****************************************************************************/
  891.  
  892.  
  893. void bihangup(int up)
  894. /* This function returns one character from either the local keyboard or
  895.  * remote com port (if applicable).  Every second of inactivity, a
  896.  * beep is sounded.  After 10 seconds of inactivity, the user is hung up.
  897.  */
  898. {
  899.   unsigned char ch;
  900.   long nextbeep;
  901.   long dd;
  902.   int color=5;
  903.  
  904.   timelastchar1=timer1();
  905.   nextbeep=18L;
  906.   nl();
  907.   outstr(get_string(1481));
  908.   nl();
  909.   outstr(get_string(1482));
  910.   npr("%d%d  %c",color,(int)(182L/nextbeep),7);
  911.   do {
  912.     while (empty() && !hangup) {
  913.       dd = timer1();
  914.       if (labs(dd - timelastchar1) > 65536L) {
  915.         nextbeep -= 1572480L;
  916.         timelastchar1 -= 1572480L;
  917.       }
  918.       if ((dd - timelastchar1) > nextbeep) {
  919.         npr("\r%d%d  %c",color,(182L-nextbeep)/18L,7);
  920.         nextbeep += 18L;
  921.         if ((182L-nextbeep)/18L <= 6)
  922.           color=2;
  923.         if ((182L-nextbeep)/18L <= 3)
  924.           color=6;
  925.       }
  926.       if (labs(dd - timelastchar1) > 182L) {
  927.     nl();
  928.     outstr(get_string(1483));
  929.     nl();
  930.         dtr(0);
  931.     hangup = 1;
  932.         if(up) {
  933.           wait1(2);
  934.           if (!cdet()) {
  935.             dtr(1);
  936.             wait1(2);
  937.             holdphone(1);
  938.           }
  939.         }
  940.       }
  941.       giveup_timeslice();
  942.       checkhangup();
  943.     }
  944.     ch = inkey();
  945.     if ((ch=='h') || (ch=='H'))
  946.       hangup=1;
  947.   } while (!ch && !hangup);
  948. }
  949.