home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVSOR / XFER.C < prev    next >
Text File  |  1995-05-12  |  27KB  |  1,256 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include <dir.h>
  22.  
  23.  
  24.  
  25. #define SETREC(f,i)  sh_lseek(f,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
  26.  
  27. /* number of dots for searching */
  28. #define DOTS 5
  29.  
  30. /* color for frame */
  31. #define FRAME 7
  32.  
  33. /* How far to indent extended descriptions */
  34. #define INDENTION 24
  35.  
  36. /* the archive type to use */
  37. #define ARC_NUMBER 0
  38.  
  39. int foundany;
  40.  
  41. typedef struct {
  42.   char name[13];
  43.   long offset; /* of ext_desc_type */
  44. } ext_desc_rec;
  45.  
  46. static int ed_num, ed_got;
  47. static ext_desc_rec *ed_info;
  48.  
  49. void zap_ed_info(void)
  50. {
  51.   if (ed_info) {
  52.     bbsfree(ed_info);
  53.     ed_info = NULL;
  54.   }
  55.   ed_num=0;
  56.   ed_got=0;
  57. }
  58.  
  59. void get_ed_info(void)
  60. {
  61.   int f;
  62.   long l,l1;
  63.   ext_desc_type ed;
  64.  
  65.   if (ed_got)
  66.     return;
  67.  
  68.   zap_ed_info();
  69.   ed_got=1;
  70.  
  71.   if (!numf)
  72.     return;
  73.  
  74.   l=0;
  75.   f=sh_open1(edlfn,O_RDONLY | O_BINARY);
  76.   if (f>0) {
  77.     l1=filelength(f);
  78.     if (l1>0) {
  79.       ed_info=malloca((long)numf*sizeof(ext_desc_rec));
  80.       if (ed_info==NULL) {
  81.         sh_close(f);
  82.         return;
  83.       }
  84.       ed_num=0;
  85.       while ((l<l1) && (ed_num<numf)) {
  86.         sh_lseek(f,l,SEEK_SET);
  87.         if (sh_read(f,&ed,sizeof(ext_desc_type)) == sizeof(ext_desc_type)) {
  88.           strcpy(ed_info[ed_num].name,ed.name);
  89.           ed_info[ed_num].offset=l;
  90.           l += (long) ed.len + sizeof(ext_desc_type);
  91.           ed_num++;
  92.         }
  93.       }
  94.       if (l<l1)
  95.         ed_got=2;
  96.     }
  97.     f=sh_close(f);
  98.   }
  99. }
  100.  
  101. unsigned long bytes_to_k(unsigned long b)
  102. {
  103.   return((unsigned long)((b+1023)/1024));
  104. }
  105.  
  106.  
  107. int check_batch_queue(char *fn)
  108. {
  109.   int i;
  110.  
  111.   for (i=0; i<numbatch; i++) {
  112.     if (strcmp(fn,batch[i].filename)==0)
  113.       if (batch[i].sending)
  114.         return(1);
  115.       else
  116.         return(-1);
  117.   }
  118.  
  119.   return(0);
  120. }
  121.  
  122.  
  123. int check_ul_event(int dn, uploadsrec *u)
  124. {
  125.   char s[161],s1[10];
  126.  
  127.   if (syscfg.upload_c[0]) {
  128.     sprintf(s1,"%d",syscfgovr.primaryport);
  129.     stuff_in(s,syscfg.upload_c,create_chain_file(),
  130.              directories[dn].path,stripfn(u->filename),s1,"");
  131.     extern_prog(s, sysinfo.spawn_opts[4]);
  132.     sprintf(s,"%s%s",directories[dn].path, stripfn(u->filename));
  133.     if (!exist(s)) {
  134.       sprintf(s,get_stringx(1,40),
  135.               u->filename, directories[dn].name);
  136.       sysoplog(s);
  137.       outstr(u->filename);
  138.       pl(get_string(727));
  139.       return(1);
  140.     }
  141.   }
  142.  
  143.   return(0);
  144. }
  145.  
  146. char (*devices)[9];
  147. int num_devices;
  148.  
  149. #ifdef __OS2__
  150. #define NUM_OS2_DEVICES 17
  151. static char *OS2DeviceNames[] =
  152.   {
  153.     "KBD$", "PRN", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6",
  154.     "COM7", "COM8", "LPT1", "LPT2", "LPT3", "CLOCK$", "SCREEN$",
  155.     "POINTER$", "MOUSE$"
  156.   };
  157. #endif
  158.  
  159. void finddevs(char (*devs)[9], int *count)
  160. {
  161. #ifdef __OS2__
  162.   int x;
  163.  
  164.   *count = NUM_OS2_DEVICES;
  165.   if (devs)
  166.     for (x = 0; x < NUM_OS2_DEVICES; x++)
  167.       strcpy(devs[x], OS2DeviceNames[x]);
  168. #else
  169.   char s[9];
  170.   int i;
  171.   char far *ss;
  172.   long far *l;
  173.   union REGS regs;
  174.   struct SREGS sregs;
  175.  
  176.   *count=0;
  177.   regs.x.ax=0x5200;
  178.   int86x(INT_REAL_DOS, ®s, ®s, &sregs);
  179.   ss=MK_FP(sregs.es, regs.x.bx);
  180.   ss += 34;
  181.   l=(long far *) ss;
  182.  
  183.   while (((unsigned short) l) != 0xffff) {
  184.     ss=(char far *) l;
  185.     ss += 10;
  186.     if (*ss>32) {
  187.       strncpy(s,ss,8);
  188.       s[8]=0;
  189.       for (i=7; i; i--)
  190.         if (s[i]==' ')
  191.           s[i]=0;
  192.         else
  193.           break;
  194.       if (devs) {
  195.         strcpy(devs[*count],s);
  196.       }
  197.       ++(*count);
  198.     }
  199.     l=(long far *) *l;
  200.   }
  201. #endif
  202. }
  203.  
  204. void find_devices(void)
  205. {
  206.   finddevs(NULL, &num_devices);
  207.   devices=malloca((num_devices+2)*9);
  208.   finddevs(devices,&num_devices);
  209. }
  210.  
  211. int okfn(char *s)
  212. {
  213.   int i,l;
  214.   unsigned char ch;
  215.  
  216.   l=strlen(s);
  217.   if ((s[0]=='-') || (s[0]==' ') || (s[0]=='.') || (s[0]=='@'))
  218.     return(0);
  219.   for (i=0; i<l; i++) {
  220.     ch=s[i];
  221.     if ((ch==' ') || (ch=='/') || (ch=='\\') || (ch==':') ||
  222.         (ch=='>') || (ch=='<') || (ch=='|')  || (ch=='+') ||
  223.         (ch==',') || (ch==';') || (ch=='^')  || (ch=='\"') ||
  224.         (ch=='\'') || (ch>126))
  225.       return(0);
  226.   }
  227.  
  228.   for (i=0; i<num_devices; i++) {
  229.     l=strlen(devices[i]);
  230.     if (strncmp(devices[i],s,l)==0) {
  231.       if ((s[l]==0) || (s[l]=='.') || (l==8))
  232.         return(0);
  233.     }
  234.   }
  235.   return(1);
  236. }
  237.  
  238. void print_devices(void)
  239. {
  240.   int i;
  241.   for (i=0; i<num_devices; i++)
  242.     pl(devices[i]);
  243. }
  244.  
  245. char *exts[] = {"", ".COM", ".EXE", ".BAT", 0};
  246.  
  247. char *make_abs_cmd(char *out)
  248. {
  249.   char s[161],s1[161],s2[161],*ss,*ss1;
  250.   int i;
  251.  
  252.   strcpy(s1,out);
  253.  
  254.   if (s1[1]==':') {
  255.     if (s1[2]!='\\') {
  256.       getcurdir(upcase(s1[0])-'A'+1, s);
  257.       if (s[0])
  258.         sprintf(s1,"%c:\\%s\\%s", s1[0], s, out+2);
  259.       else
  260.         sprintf(s1,"%c:\\%s",s1[0], out+2);
  261.     }
  262.   } else if (s1[0]=='\\') {
  263.     sprintf(s1,"%c:%s", cdir[0], out);
  264.   } else {
  265.     strcpy(s2,s1);
  266.     strtok(s2," \t");
  267.     if (strchr(s2,'\\')) {
  268.       sprintf(s1,"%s\\%s", cdir, out);
  269.     }
  270.   }
  271.  
  272.   ss=strchr(s1,' ');
  273.   if (ss) {
  274.     *ss=0;
  275.     sprintf(s2," %s",ss+1);
  276.   } else {
  277.     s2[0]=0;
  278.   }
  279.   for (i=0; exts[i]; i++) {
  280.     if (i==0) {
  281.       ss1=strrchr(s1,'\\');
  282.       if (!ss1)
  283.         ss1=s1;
  284.       if (strchr(ss1,'.')==0)
  285.         continue;
  286.     }
  287.     sprintf(s,"%s%s",s1,exts[i]);
  288.     if (s1[1]==':') {
  289.       if (exist(s)) {
  290.         sprintf(out,"%s%s",s,s2);
  291.         goto got_cmd;
  292.       }
  293.     } else {
  294.       if (exist(s)) {
  295.         sprintf(out,"%s\\%s%s", cdir, s, s2);
  296.         goto got_cmd;
  297.       } else {
  298.         ss1=searchpath(s);
  299.         if (ss1) {
  300.           sprintf(out, "%s%s", ss1, s2);
  301.           goto got_cmd;
  302.         }
  303.       }
  304.     }
  305.   }
  306.  
  307.   sprintf(out, "%s\\%s%s", cdir, s1, s2);
  308.  
  309. got_cmd:
  310.   return(out);
  311. }
  312.  
  313. void get_arc_cmd(char *out, char *arcfn, int cmd, char *ofn)
  314. {
  315.   char *ss,s[161];
  316.   int i;
  317.  
  318.   out[0]=0;
  319.   ss=strchr(arcfn,'.');
  320.   if (ss==NULL)
  321.     return;
  322.   ++ss;
  323.   for (i=0; i<4; i++)
  324.     if (stricmp(ss,syscfg.arcs[i].extension)==0) {
  325.       switch(cmd) {
  326.         case 0: strcpy(s,syscfg.arcs[i].arcl); break;
  327.         case 1: strcpy(s,syscfg.arcs[i].arce); break;
  328.         case 2: strcpy(s,syscfg.arcs[i].arca); break;
  329.       }
  330.       if (s[0]==0)
  331.         return;
  332.       stuff_in(out,s,arcfn,ofn,"","","");
  333.       make_abs_cmd(out);
  334.       return;
  335.     }
  336.  
  337. }
  338.  
  339.  
  340. int list_arc_out(char *fn, char *dir)
  341. {
  342.   char s[161],s1[81],s2[81], rmfn[81];
  343.   int i=0;
  344.  
  345.   rmfn[0]=0;
  346.  
  347.   sprintf(s1,"%s%s",dir,fn);
  348.   if (directories[udir[curdir].subnum].mask & mask_cdrom) {
  349.     sprintf(s1,"%s%s",syscfgovr.tempdir,fn);
  350.     if (!exist(s1)) {
  351.       sprintf(s2,"%s%s",dir,fn);
  352.       copy_file(s2,s1);
  353.       strcpy(rmfn, s1);
  354.     }
  355.   }
  356.   get_arc_cmd(s,s1,0,"");
  357.   if (!okfn(fn))
  358.     s[0]=0;
  359.   if (exist(s1) && (s[0]!=0)) {
  360.     nln(2);
  361.     outstr(get_string(728));
  362.     pl(fn);
  363.     nl();
  364.     i=extern_prog(s, sysinfo.spawn_opts[10]);
  365.     nl();
  366.   } else {
  367.     nl();
  368.     outs(get_string(729));
  369.     pl(fn);
  370.     nl();
  371.     i=0;
  372.   }
  373.  
  374.   if (rmfn[0])
  375.     unlink(rmfn);
  376.  
  377.   return(i);
  378. }
  379.  
  380.  
  381. int ratio_ok(void)
  382. {
  383.   int ok=1;
  384.   char s[250];
  385.  
  386.   if (!(thisuser.exempt & exempt_ratio))
  387.     if ((syscfg.req_ratio>0.0001) && (ratio()<syscfg.req_ratio)) {
  388.       ok=0;
  389.       nln(2);
  390.       sprintf(s,"%s %-5.3f.  %s %-5.3f %s.",
  391.               get_string(730), ratio(),
  392.               get_string(731), syscfg.req_ratio,
  393.               get_string(732));
  394.       pl(s);
  395.       nl();
  396.     }
  397.  
  398.   if (!(thisuser.exempt & exempt_post))
  399.     if ((syscfg.post_call_ratio>0.0001) && (post_ratio()<syscfg.post_call_ratio)) {
  400.       ok=0;
  401.       nln(2);
  402.       sprintf(s,"%s %-5.3f.  %s %-5.3f %s.",
  403.               get_string(733), post_ratio(),
  404.               get_string(731), syscfg.post_call_ratio,
  405.               get_string(732));
  406.       pl(s);
  407.       nl();
  408.     }
  409.  
  410.  
  411.   return(ok);
  412. }
  413.  
  414.  
  415. int dcs(void)
  416. {
  417.   if (cs())
  418.     return(1);
  419.   if (thisuser.dsl>=100)
  420.     return(1);
  421.   else
  422.     return(0);
  423. }
  424.  
  425.  
  426. void dliscan1(int dn)
  427. {
  428.   int i,f;
  429.   uploadsrec u;
  430.   long l;
  431.  
  432.   sprintf(dlfn,"%s%s.DIR",syscfg.datadir,directories[dn].filename);
  433.   f=sh_open(dlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  434.   i=filelength(f)/sizeof(uploadsrec);
  435.   if (i==0) {
  436.     memset(&u, 0, sizeof(uploadsrec));
  437.     strcpy(u.filename,"|MARKER|");
  438.     time(&l);
  439.     u.daten=l;
  440.     SETREC(f,0);
  441.     sh_write(f,(void *)&u,sizeof(uploadsrec));
  442.   } else {
  443.     SETREC(f,0);
  444.     sh_read(f,(void *)&u,sizeof(uploadsrec));
  445.     if (strcmp(u.filename,"|MARKER|")) {
  446.       numf=u.numbytes;
  447.       memset(&u, 0, sizeof(uploadsrec));
  448.       strcpy(u.filename,"|MARKER|");
  449.       time(&l);
  450.       u.daten=l;
  451.       u.numbytes = numf;
  452.       SETREC(f,0);
  453.       sh_write(f, &u, sizeof(uploadsrec));
  454.     }
  455.   }
  456.   f=sh_close(f);
  457.   numf=u.numbytes;
  458.   this_date = u.daten;
  459.   dir_dates[dn]=this_date;
  460.  
  461.   sprintf(edlfn,"%s%s.EXT",syscfg.datadir,directories[dn].filename);
  462.   zap_ed_info();
  463. }
  464.  
  465. void dliscan_hash(int dn)
  466. {
  467.   char s[81];
  468.   int i,f;
  469.   uploadsrec u;
  470.  
  471.   if ((dn>=num_dirs) || (dir_dates[dn]))
  472.     return;
  473.  
  474.   sprintf(s,"%s%s.DIR",syscfg.datadir,directories[dn].filename);
  475.   f=sh_open1(s,O_RDONLY | O_BINARY);
  476.   if (f<0) {
  477.     time((long *)&(dir_dates[dn]));
  478.     return;
  479.   }
  480.   i=filelength(f)/sizeof(uploadsrec);
  481.   if (i<1) {
  482.     time((long *)&(dir_dates[dn]));
  483.   } else {
  484.     SETREC(f,0);
  485.     sh_read(f,(void *)&u,sizeof(uploadsrec));
  486.     if (strcmp(u.filename,"|MARKER|")==0) {
  487.       dir_dates[dn]=u.daten;
  488.     } else {
  489.       time((long *)&(dir_dates[dn]));
  490.     }
  491.   }
  492.   sh_close(f);
  493. }
  494.  
  495.  
  496. void dliscan(void)
  497. {
  498.   dliscan1(udir[curdir].subnum);
  499. }
  500.  
  501.  
  502. void add_extended_description(char *fn, char *desc)
  503. {
  504.   ext_desc_type ed;
  505.   int f;
  506.  
  507.   strcpy(ed.name,fn);
  508.   ed.len=strlen(desc);
  509.   f=sh_open(edlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  510.   sh_lseek(f,0L,SEEK_END);
  511.   sh_write(f,&ed,sizeof(ext_desc_type));
  512.   sh_write(f,desc,ed.len);
  513.   f=sh_close(f);
  514.   zap_ed_info();
  515. }
  516.  
  517.  
  518. void delete_extended_description(char *fn)
  519. {
  520.   ext_desc_type ed;
  521.   long r,w,l1,f;
  522.   char *ss=NULL;
  523.  
  524.   r=w=0;
  525.   if ((ss=malloca(10240L))==NULL)
  526.     return;
  527.   f=sh_open(edlfn,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  528.   l1=filelength(f);
  529.   while (r<l1) {
  530.     sh_lseek(f,r,SEEK_SET);
  531.     sh_read(f,&ed,sizeof(ext_desc_type));
  532.     if (ed.len<10000) {
  533.       sh_read(f,ss,ed.len);
  534.       if (strcmp(fn,ed.name)) {
  535.         if (r!=w) {
  536.           sh_lseek(f,w,SEEK_SET);
  537.           sh_write(f,&ed,sizeof(ext_desc_type));
  538.           sh_write(f,ss,ed.len);
  539.         }
  540.         w +=(sizeof(ext_desc_type) + ed.len);
  541.       }
  542.     }
  543.     r += (sizeof(ext_desc_type) + ed.len);
  544.   }
  545.   chsize(f,w);
  546.   f=sh_close(f);
  547.   bbsfree(ss);
  548.   zap_ed_info();
  549. }
  550.  
  551.  
  552. char *read_extended_description(char *fn)
  553. {
  554.   ext_desc_type ed;
  555.   long l,l1;
  556.   char *ss=NULL;
  557.   int f,i;
  558.  
  559.   get_ed_info();
  560.  
  561.   if (ed_got && ed_info) {
  562.     for (i=0; i<ed_num; i++) {
  563.       if (strcmp(fn, ed_info[i].name)==0) {
  564.         f=sh_open1(edlfn, O_RDONLY|O_BINARY);
  565.         if (f<0) {
  566.           return(NULL);
  567.         }
  568.         sh_lseek(f, ed_info[i].offset, SEEK_SET);
  569.         l=sh_read(f, &ed, sizeof(ext_desc_type));
  570.         if ((l==sizeof(ext_desc_type)) && (strcmp(fn, ed.name)==0)) {
  571.           ss=malloca((long) ed.len+10);
  572.           if (ss) {
  573.             sh_read(f,ss,ed.len);
  574.             ss[ed.len]=0;
  575.           }
  576.           f=sh_close(f);
  577.           return(ss);
  578.         } else {
  579.           zap_ed_info();
  580.           f=sh_close(f);
  581.           break;
  582.         }
  583.       }
  584.     }
  585.   }
  586.  
  587.   if (ed_got!=1) {
  588.     l=0;
  589.     f=sh_open1(edlfn,O_RDONLY | O_BINARY);
  590.     if (f>0) {
  591.       l1=filelength(f);
  592.       while (l<l1) {
  593.         sh_lseek(f,l,SEEK_SET);
  594.         l += (long) sh_read(f,&ed,sizeof(ext_desc_type));
  595.         if (strcmp(fn,ed.name)==0) {
  596.           ss=malloca((long) ed.len+10);
  597.           if (ss) {
  598.             sh_read(f,ss,ed.len);
  599.             ss[ed.len]=0;
  600.           }
  601.           f=sh_close(f);
  602.           return(ss);
  603.         } else
  604.           l += (long) ed.len;
  605.       }
  606.       f=sh_close(f);
  607.     }
  608.   }
  609.   return(NULL);
  610. }
  611.  
  612.  
  613.  
  614. void print_extended(char *fn, int *abort, unsigned char numlist, int indent)
  615. {
  616.   char *ss;
  617.   int next=0;
  618.   unsigned char numl=0;
  619.   int cpos=0;
  620.   char ch,s[81];
  621.   int i;
  622.  
  623.   ss=read_extended_description(fn);
  624.   if (ss) {
  625.     if (indent!=2)
  626.       ch=10;
  627.     while ((ss[cpos]) && (!(*abort)) && (numl<numlist)) {
  628.       if (ch==10) {
  629.         if (indent==1) {
  630.           for (i=0; i<INDENTION; i++) {
  631.             if ((i==12) || (i==18))
  632.               s[i]=(okansi() ? '║' : '|');
  633.             else
  634.               s[i]=32;
  635.           }
  636.           s[INDENTION]=0;
  637.           ansic((thisuser.sysstatus & sysstatus_extra_color)
  638.             && (!(*abort)) ? FRAME : 0);
  639.           osan(s,abort,&next);
  640.           if ((thisuser.sysstatus & sysstatus_extra_color) && (!(*abort)))
  641.             ansic(1);
  642.         } else {
  643.           if (indent==2) {
  644.             for (i=0; i<13; i++)
  645.               s[i]=32;
  646.             s[13]=0;
  647.             osan(s,abort,&next);
  648.             if ((thisuser.sysstatus & sysstatus_extra_color) && (!(*abort)))
  649.               ansic(2);
  650.           }
  651.         }
  652.       }
  653.       outchr(ch=ss[cpos++]);
  654.       checka(abort,&next);
  655.       if (ch==10)
  656.         ++numl;
  657.       else
  658.         if ((ch!=13) && (WhereX()>=78)) {
  659.           osan("\r\n",abort,&next);
  660.           ch=10;
  661.         }
  662.     }
  663.     if (WhereX())
  664.       nl();
  665.     bbsfree(ss);
  666.   } else {
  667.     if (WhereX())
  668.       nl();
  669.   }
  670. }
  671.  
  672.  
  673.  
  674. void align(char *s)
  675. {
  676.   char f[40],e[40],s1[20],*s2;
  677.   int i,i1,i2;
  678.  
  679.   i1=0;
  680.   if (s[0]=='.')
  681.     i1=1;
  682.   for (i=0; i<strlen(s); i++)
  683.     if ((s[i]=='\\') || (s[i]=='/') || (s[i]==':') || (s[i]=='<') ||
  684.       (s[i]=='>') || (s[i]=='|'))
  685.       i1=1;
  686.   if (i1) {
  687.     strcpy(s,"        .   ");
  688.     return;
  689.   }
  690.   s2=strchr(s,'.');
  691.   if (s2==NULL) {
  692.     e[0]=0;
  693.   } else {
  694.     strcpy(e,&(s2[1]));
  695.     e[3]=0;
  696.     s2[0]=0;
  697.   }
  698.   strcpy(f,s);
  699.  
  700.   for (i=strlen(f); i<8; i++)
  701.     f[i]=32;
  702.   f[8]=0;
  703.   i1=0;
  704.   i2=0;
  705.   for (i=0; i<8; i++) {
  706.     if (f[i]=='*')
  707.       i1=1;
  708.     if (f[i]==' ')
  709.       i2=1;
  710.     if (i2)
  711.       f[i]=' ';
  712.     if (i1)
  713.       f[i]='?';
  714.   }
  715.  
  716.   for (i=strlen(e); i<3; i++)
  717.     e[i]=32;
  718.   e[3]=0;
  719.   i1=0;
  720.   for (i=0; i<3; i++) {
  721.     if (e[i]=='*')
  722.       i1=1;
  723.     if (i1)
  724.       e[i]='?';
  725.   }
  726.  
  727.   for (i=0; i<12; i++)
  728.     s1[i]=32;
  729.   strcpy(s1,f);
  730.   s1[8]='.';
  731.   strcpy(&(s1[9]),e);
  732.   strcpy(s,s1);
  733.   for (i=0; i<12; i++)
  734.     s[i]=upcase(s[i]);
  735. }
  736.  
  737.  
  738. int compare(char *s1, char *s2)
  739. {
  740.   int ok,i;
  741.  
  742.   ok=1;
  743.   for (i=0; i<12; i++)
  744.     if ((s1[i]!=s2[i]) && (s1[i]!='?') && (s2[i]!='?'))
  745.       ok=0;
  746.   return(ok);
  747. }
  748.  
  749.  
  750. void printinfo(uploadsrec *u, int *abort)
  751. {
  752.   char s[85],s1[40],s2[81];
  753.   int i,next,fc;
  754.  
  755.   fc=thisuser.sysstatus & sysstatus_extra_color;
  756.   if (titled!=0)
  757.     printtitle(abort);
  758.   if ((tagging==0) && (!x_only))
  759.     return;
  760.   if ((tagging == 1) && !(thisuser.sysstatus & sysstatus_no_tag)
  761.     && (!x_only)) {
  762.     if (!filelist) {
  763.       filelist=(tagrec *)malloca(50 * sizeof(tagrec));
  764.       tagptr=0;
  765.     }
  766.     if (filelist) {
  767.       filelist[tagptr].u=*u;
  768.       filelist[tagptr].directory= udir[curdir].subnum;
  769.       filelist[tagptr].dir_mask=  directories[udir[curdir].subnum].mask;
  770.       tagptr++;
  771.       sprintf(s,"\r%d%2d%d%c",
  772.         (check_batch_queue(filelist[tagptr-1].u.filename)) ? 6 : 0,
  773.         tagptr,fc ? FRAME : 0, okansi() ? '║' : '|' );
  774.       osan(s,abort,&next);
  775.     }
  776.   } else
  777.     if (!x_only)
  778.       outstr("\r");
  779.   if (fc)
  780.     ansic(1);
  781.   strncpy(s,u->filename,8);
  782.   s[8]=0;
  783.   osan(s,abort,&next);
  784.   strncpy(s,&((u->filename)[8]),4);
  785.   s[4]=0;
  786.   if (fc)
  787.     ansic(1);
  788.   osan(s,abort,&next);
  789.   ansic(fc ? FRAME : 0);
  790.   osan((okansi() ? "║" : "|"),abort,&next);
  791.  
  792.   ltoa(bytes_to_k(u->numbytes),s1,10);
  793.   strcat(s1,"k");
  794.  
  795.   if (!(directories[udir[curdir].subnum].mask & mask_cdrom)) {
  796.     strcpy(s2,directories[udir[curdir].subnum].path);
  797.     strcat(s2,u->filename);
  798.     if (!exist(s2))
  799.       strcpy(s1,get_string(741));
  800.   }
  801.  
  802.   for (i=0; i<5-(int)strlen(s1); i++)
  803.     s[i]=32;
  804.   s[i]=0;
  805.   strcat(s,s1);
  806.   if (fc)
  807.     ansic(2);
  808.   osan(s,abort,&next);
  809.  
  810.   if ((tagging == 1) && !(thisuser.sysstatus & sysstatus_no_tag)
  811.     && (!x_only)) {
  812.     ansic(fc ? FRAME : 0);
  813.     osan((okansi() ? "║" : "|"),abort,&next);
  814.     sprintf(s1,"%d",u->numdloads);
  815.  
  816.     for (i=0; i<4-(int)strlen(s1); i++)
  817.       s[i]=32;
  818.     s[i]=0;
  819.     strcat(s,s1);
  820.     if (fc)
  821.       ansic(2);
  822.     osan(s,abort,&next);
  823.   }
  824.  
  825.   ansic(fc ? FRAME : 0);
  826.   osan((okansi() ? "║" : "|"),abort,&next);
  827.   sprintf(s,"%d%s",
  828.     (u->mask & mask_extended) ? 1 : 2, u->description);
  829.   if ((tagging) && !(thisuser.sysstatus & sysstatus_no_tag)
  830.     && (!x_only)) {
  831.     plal(s,thisuser.screenchars-28,abort);
  832.   } else {
  833.     plal(s,strlen(s),abort);
  834.     if ((!*abort) && (thisuser.num_extended) && (u->mask & mask_extended))
  835.       print_extended(u->filename,abort,thisuser.num_extended,1);
  836.   }
  837.   if (!(*abort)) {
  838.     ++num_listed;
  839.   } else {
  840.     tagptr=0;
  841.     tagging=0;
  842.   }
  843. }
  844.  
  845.  
  846. void printtitle(int *abort)
  847. {
  848.   char s[81], *ss;
  849.  
  850.   if (x_only) {
  851.     nl();
  852.     ss="";
  853.   } else
  854.     ss="\r";
  855.   if ((lines_listed >= screenlinest - 7) && (!x_only)
  856.     && !(thisuser.sysstatus & sysstatus_no_tag) && filelist && num_listed) {
  857.     tag_files();
  858.     if (tagging==0)
  859.       return;
  860.   }
  861.   sprintf(s,"%s%s - #%s, %d %s.",ss,directories[udir[curdir].subnum].name,
  862.                                 udir[curdir].keys,numf, get_string(742));
  863.   ansic(thisuser.sysstatus & sysstatus_extra_color ? FRAME : 0);
  864.   if (((num_listed==0) && (tagptr==0)) || (tagging==0)
  865.     || ((thisuser.sysstatus & sysstatus_no_tag) && (num_listed==0))) {
  866.     if (okansi())
  867.       npr("%s%s\r\n",ss,get_string(1311));
  868.     else
  869.       npr("%s%s\r\n",ss,get_string(1312));
  870.   } else {
  871.     if ((titled!=2) && (tagging == 1)
  872.       && !(thisuser.sysstatus & sysstatus_no_tag)) {
  873.       if (okansi())
  874.         npr("%s%s\r\n",ss,get_string(1313));
  875.       else
  876.         npr("%s%s\r\n",ss,get_string(1314));
  877.     } else {
  878.       if (((thisuser.sysstatus & sysstatus_no_tag) || (tagging==2))
  879.         && (num_listed!=0)) {
  880.         ansic(thisuser.sysstatus & sysstatus_extra_color ? FRAME : 0);
  881.         if (okansi())
  882.           npr("%s%s\r\n",ss,get_string(1315));
  883.         else
  884.           npr("%s%s\r\n",ss,get_string(1316));
  885.       }
  886.     }
  887.   }
  888.   if (thisuser.sysstatus & sysstatus_extra_color)
  889.     ansic(2);
  890.   pla(s,abort);
  891.   if ((tagging == 1) && !(thisuser.sysstatus & sysstatus_no_tag)
  892.     && (!x_only)) {
  893.     ansic(thisuser.sysstatus & sysstatus_extra_color ? FRAME : 0);
  894.     if (okansi())
  895.       npr("\r%s\r\n",get_string(1317));
  896.     else
  897.       npr("\r%s\r\n",get_string(1318));
  898.   } else {
  899.     ansic(thisuser.sysstatus & sysstatus_extra_color ? FRAME : 0);
  900.     if (okansi())
  901.       npr("\r%s\r\n",get_string(1319));
  902.     else
  903.       if (x_only)
  904.         npr("%s\r\n",get_string(1320));
  905.       else
  906.         npr("\r%s\r\n",get_string(1321));
  907.   }
  908.   titled=0;
  909. }
  910.  
  911.  
  912. void file_mask(char *s)
  913. {
  914.   nl();
  915.   helpl=9;
  916.   prt(2,get_string(743));
  917.   input(s,12);
  918.   if (s[0]==0)
  919.     strcpy(s,"*.*");
  920.   if (strchr(s,'.')==NULL)
  921.     strcat(s,".*");
  922.   align(s);
  923.   nl();
  924. }
  925.  
  926.  
  927. void listfiles(void)
  928. {
  929.   char s[81];
  930.   int i,abort,next=0,f;
  931.   uploadsrec u;
  932.  
  933.   dliscan();
  934.   file_mask(s);
  935.   abort=0;
  936.   num_listed=0;
  937.   titled=1;
  938.   lines_listed=0;
  939.   f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  940.   for (i=1; (i<=numf) && (!abort) && (!hangup) && (tagging!=0); i++) {
  941.     SETREC(f,i);
  942.     sh_read(f,(void *)&u,sizeof(uploadsrec));
  943.     if (compare(s,u.filename)) {
  944.       f=sh_close(f);
  945.       printinfo(&u, &abort);
  946.       f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  947.     } else if (!empty())
  948.       checka(&abort,&next);
  949.   }
  950.   f=sh_close(f);
  951.   endlist(1);
  952. }
  953.  
  954.  
  955. void nscandir(int d, int *abort)
  956. {
  957.   int i,od,next=0,f;
  958.   uploadsrec u;
  959.  
  960.   if ((dir_dates[udir[d].subnum]) && (dir_dates[udir[d].subnum]<nscandate))
  961.     return;
  962.  
  963.   od=curdir;
  964.   curdir=d;
  965.   dliscan();
  966.   if (this_date>=nscandate) {
  967.     f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  968.     for (i=1; (i<=numf) && (!(*abort)) && (!hangup) && (tagging!=0); i++) {
  969.       checkhangup();
  970.       SETREC(f,i);
  971.       sh_read(f,(void *)&u,sizeof(uploadsrec));
  972.       if (u.daten>=nscandate) {
  973.         f=sh_close(f);
  974.         printinfo(&u, abort);
  975.         f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  976.       } else if (!empty())
  977.         checka(abort,&next);
  978.  
  979.     }
  980.     f=sh_close(f);
  981.   }
  982.   curdir=od;
  983. }
  984.  
  985.  
  986. void nscanall(void)
  987. {
  988.   int abort,i,i1,count,color,ac=0;
  989.  
  990.   if ((uconfdir[1].confnum!=-1) && (okconf(&thisuser))) {
  991.     if (!x_only) {
  992.       nl();
  993.       prt(5,get_string(1379));
  994.       ac=yn();
  995.       nl();
  996.     } else
  997.       ac=1;
  998.     if (ac)
  999.       tmp_disable_conf(1);
  1000.   }
  1001.   abort=0;
  1002.   num_listed=0;
  1003.   count=0;
  1004.   color=3;
  1005.   if (!x_only) {
  1006.     outstr("\r");
  1007.     outstr(get_string(1184));
  1008.   }
  1009.   for (i=0; (i<num_dirs) && (!abort) && (udir[i].subnum!=-1) &&
  1010.        (tagging!=0); i++) {
  1011.     count++;
  1012.     if (!x_only) {
  1013.       npr("%d.",color);
  1014.       if (count>=DOTS) {
  1015.         outstr("\r");
  1016.         outstr(get_string(1184));
  1017.         color++;
  1018.         count=0;
  1019.         if (color==4)
  1020.           color++;
  1021.         if (color==10)
  1022.           color=0;
  1023.       }
  1024.     }
  1025.     i1=udir[i].subnum;
  1026.     if (qsc_n[i1/32]&(1L<<(i1%32))) {
  1027.       titled=1;
  1028.       nscandir(i,&abort);
  1029.     }
  1030.   }
  1031.   endlist(2);
  1032.   if (ac)
  1033.     tmp_disable_conf(0);
  1034. }
  1035.  
  1036.  
  1037. void searchall(void)
  1038. {
  1039.   int i,i1,pts,abort,ocd,next=0,f,count,color,ac=0;
  1040.   char s[81];
  1041.   uploadsrec u;
  1042.  
  1043.   if ((uconfdir[1].confnum!=-1) && (okconf(&thisuser))) {
  1044.     if (!x_only) {
  1045.       nl();
  1046.       prt(5,get_string(1379));
  1047.       ac=yn();
  1048.       nl();
  1049.     } else
  1050.       ac=1;
  1051.     if (ac)
  1052.       tmp_disable_conf(1);
  1053.   }
  1054.  
  1055.   abort=0;
  1056.   ocd=curdir;
  1057.   if (x_only) {
  1058.     strcpy(s,"*.*");
  1059.     align(s);
  1060.   } else {
  1061.     nln(2);
  1062.     pl(get_string(745));
  1063.     file_mask(s);
  1064.     if (!x_only) {
  1065.       nl();
  1066.       outstr(get_string(1184));
  1067.     }
  1068.   }
  1069.   num_listed=0;
  1070.   lines_listed=0;
  1071.   count=0;
  1072.   color=3;
  1073.   for (i=0; (i<num_dirs) && (!abort) && (!hangup) && (tagging || x_only)
  1074.     && (udir[i].subnum!=-1); i++) {
  1075.     i1=udir[i].subnum;
  1076.     pts=0;
  1077.     if (qsc_n[i1/32]&(1L<<(i1%32)))
  1078.       pts=1;
  1079.     pts=1;
  1080.     /* remove pts=1 to search only marked directories */
  1081.     if (pts) {
  1082.       if (!x_only) {
  1083.         count++;
  1084.         npr("%d.",color);
  1085.         if (count>=DOTS) {
  1086.           outstr("\r");
  1087.           outstr(get_string(1184));
  1088.           color++;
  1089.           count=0;
  1090.           if (color==4)
  1091.             color++;
  1092.           if (color==10)
  1093.             color=0;
  1094.         }
  1095.       }
  1096.       curdir=i;
  1097.       dliscan();
  1098.       titled=1;
  1099.       f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  1100.       for (i1=1; (i1<=numf) && (!abort) && (!hangup) && (tagging || x_only); i1++) {
  1101.         SETREC(f,i1);
  1102.         sh_read(f,(void *)&u,sizeof(uploadsrec));
  1103.         if (compare(s,u.filename)) {
  1104.           f=sh_close(f);
  1105.           printinfo(&u, &abort);
  1106.           f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  1107.         } else if (!empty())
  1108.           checka(&abort,&next);
  1109.       }
  1110.       f=sh_close(f);
  1111.     }
  1112.   }
  1113.   curdir=ocd;
  1114.   endlist(1);
  1115.   if (ac)
  1116.     tmp_disable_conf(0);
  1117. }
  1118.  
  1119.  
  1120. int recno(char *s)
  1121. {
  1122.   int i,f;
  1123.   uploadsrec u;
  1124.  
  1125.   i=1;
  1126.   if (numf<1)
  1127.     return(-1);
  1128.   f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  1129.   SETREC(f,i);
  1130.   sh_read(f,(void *)&u,sizeof(uploadsrec));
  1131.   while ((i<numf) && (compare(s,u.filename)==0)) {
  1132.     ++i;
  1133.     SETREC(f,i);
  1134.     sh_read(f,(void *)&u,sizeof(uploadsrec));
  1135.   }
  1136.   f=sh_close(f);
  1137.   if (compare(s,u.filename))
  1138.     return(i);
  1139.   else
  1140.     return(-1);
  1141. }
  1142.  
  1143.  
  1144. int nrecno(char *s,int i1)
  1145. {
  1146.   int i,f;
  1147.   uploadsrec u;
  1148.  
  1149.   i=i1+1;
  1150.   if ((numf<1) || (i1>=numf))
  1151.     return(-1);
  1152.  
  1153.   f=sh_open1(dlfn,O_RDONLY | O_BINARY);
  1154.   SETREC(f,i);
  1155.   sh_read(f,(void *)&u,sizeof(uploadsrec));
  1156.   while ((i<numf) && (compare(s,u.filename)==0)) {
  1157.     ++i;
  1158.     SETREC(f,i);
  1159.     sh_read(f,(void *)&u,sizeof(uploadsrec));
  1160.   }
  1161.   f=sh_close(f);
  1162.   if (compare(s,u.filename))
  1163.     return(i);
  1164.   else
  1165.     return(-1);
  1166. }
  1167.  
  1168.  
  1169. int printfileinfo(uploadsrec *u, int dn)
  1170. {
  1171.   char s[81];
  1172.   double d;
  1173.   int abort;
  1174.  
  1175.   d=XFER_TIME(u->numbytes);
  1176.   outstr(get_string(746)); pl(stripfn(u->filename));
  1177.   outstr(get_string(747)); pl(u->description);
  1178.   outstr(get_string(748)); npr("%dk\r\n", bytes_to_k(u->numbytes));
  1179.   outstr(get_string(749)); pl(ctim(d));
  1180.   outstr(get_string(750)); pl(u->date);
  1181.   outstr(get_string(751)); pl(u->upby);
  1182.   outstr(get_string(752)); pln(u->numdloads);
  1183.   nl();
  1184.   abort=0;
  1185.   if (u->mask & mask_extended) {
  1186.     pl(get_string(753));
  1187.     print_extended(u->filename,&abort,255,0);
  1188.   }
  1189.  
  1190.   sprintf(s,"%s%s",directories[dn].path,u->filename);
  1191.   if (!exist(s)) {
  1192.     nl();
  1193.     pl(get_string(754));
  1194.     nl();
  1195.     return(-1);
  1196.   }
  1197.  
  1198.   if (nsl()>=d)
  1199.     return(1);
  1200.   else
  1201.     return(0);
  1202. }
  1203.  
  1204.  
  1205. /****************************************************************************/
  1206. /* This kludge will get us through 2019 and should not interfere anywhere   */
  1207. /* else.                                                                    */
  1208. /****************************************************************************/
  1209.  
  1210. long date_to_daten(char *datet)
  1211. {
  1212.   struct time t;
  1213.   struct date d;
  1214.  
  1215.   if (strlen(datet)!=8)
  1216.     return(0);
  1217.  
  1218.   memset(&d, 0, sizeof(struct date));
  1219.   memset(&t, 0, sizeof(struct time));
  1220.   d.da_mon=atoi(datet);
  1221.   d.da_day=atoi(datet+3);
  1222.   d.da_year=1900+atoi(datet+6);                  /* fixed for 1920-2019 */
  1223.   if (datet[6]<'2')
  1224.     d.da_year+=100;
  1225.   return(dostounix(&d, &t));
  1226. }
  1227.  
  1228.  
  1229. /****************************************************************************/
  1230.  
  1231.  
  1232.  
  1233. void remlist(char *fn)
  1234. {
  1235.   int i,i2;
  1236.   char s[81],s1[81];
  1237.  
  1238.   sprintf(s,"%s",fn);
  1239.   align(s);
  1240.  
  1241.   if (filelist) {
  1242.     for (i=0;i<tagptr;i++) {
  1243.       strcpy(s1,filelist[i].u.filename);
  1244.       align(s1);
  1245.       if (strcmp(s,s1)==0) {
  1246.         for (i2=i;i2<tagptr-1;i2++)
  1247.           filelist[i2]=filelist[i2+1];
  1248.         tagptr--;
  1249.         num_listed--;
  1250.       }
  1251.     }
  1252.   }
  1253. }
  1254.  
  1255.  
  1256.