home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B84.ZIP / UUMAIN.CPP < prev    next >
C/C++ Source or Header  |  1997-12-31  |  34KB  |  1,393 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <dir.h>
  6. #include <dos.h>
  7. #include <share.h>
  8. #include <sys\stat.h>
  9. #include <alloc.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include <time.h>
  13. #include <errno.h>
  14. #include <process.h>
  15. #include "uu.h"
  16. #include "net.h"
  17. #include "vardec.h"
  18. #include "version.h"
  19. #include "retcode.h"
  20.  
  21. #define MAX_BUF 1024
  22. #define MAX_DIZ_LINES 10
  23.  
  24. #define SHARE_LEVEL 10
  25. #define WAIT_TIME 10
  26. #define TRIES 100
  27. #define MT_DESQVIEW 0x01
  28. #define MT_WINDOWS  0x02
  29. #define MT_OS2      0x04
  30. #define MT_NB       0x40
  31.  
  32. #define SETREC(f,i)  sh_lseek(f,((long) (i)) * ((long)sizeof(uploadsrec)), SEEK_SET);
  33.  
  34. #define LAST(s) s[strlen(s)-1]
  35.  
  36. extern unsigned _stklen = (15*1024);
  37.  
  38. char net_name[21], net_data[MAXPATH], fdldesc[81], fdlfn[40], fdlupby[40], edlfn[MAXPATH];
  39. char temp_dir[MAXPATH], maindir[MAXPATH], dlfn[MAXPATH];
  40. char *xenviron[40];
  41. unsigned short fdltype;
  42. int numf, multitasker = 0;
  43. char *version = "Freeware PPP Project UU Encode/Decode " VERSION;
  44.  
  45. directoryrec huge *dirs;
  46. configrec syscfg;
  47.  
  48. void dv_pause(void)
  49. {
  50.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  51.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  52.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  53. }
  54.  
  55. void win_pause(void)
  56. {
  57.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  58. }
  59.  
  60. int get_dos_version(void)
  61. {
  62.   _AX = 0x3000;
  63.   geninterrupt(0x21);
  64.   if (_AX % 256 >= 10) {
  65.     multitasker |= MT_OS2;
  66.   }
  67.   return (_AX);
  68. }
  69.  
  70. int get_dv_version(void)
  71. {
  72.   int v;
  73.  
  74.   if (multitasker & MT_OS2)
  75.     return 0;
  76.   _AX = 0x2b01;
  77.   _CX = 0x4445;
  78.   _DX = 0x5351;
  79.   geninterrupt(0x21);
  80.   if (_AL == 0xff) {
  81.     return 0;
  82.   } else {
  83.     v = _BX;
  84.     multitasker |= MT_DESQVIEW;
  85.     return v;
  86.   }
  87. }
  88.  
  89. int get_win_version(void)
  90. {
  91.   int v = 0;
  92.  
  93.   __emit__(0x55, 0x06, 0x53);
  94.   _AX = 0x352f;
  95.   geninterrupt(0x21);
  96.   _AX = _ES;
  97.   if (_AX | _BX) {
  98.     _AX = 0x1600;
  99.     geninterrupt(0x2f);
  100.     v = _AX;
  101.     if (v % 256 <= 1)
  102.       v = 0;
  103.   }
  104.   __emit__(0x5b, 0x07, 0x5d);
  105.   if (v != 0)
  106.     multitasker |= MT_WINDOWS;
  107.   return (v);
  108. }
  109.  
  110. int get_nb_version(void)
  111. {
  112.   _AX = 0;
  113.   geninterrupt(0x2A);
  114.   return (_AH);
  115. }
  116.  
  117. void detect_multitask(void)
  118. {
  119.   get_dos_version();
  120.   get_win_version();
  121.   get_dv_version();
  122.   if (multitasker < 2)
  123.     if (get_nb_version())
  124.       multitasker = MT_NB;
  125. }
  126.  
  127. void giveup_timeslice(void)
  128. {
  129.   if (multitasker) {
  130.     switch (multitasker) {
  131.  case 1:
  132.  case 3:
  133.         dv_pause();
  134.         break;
  135.       case 2:
  136.       case 4:
  137.       case 5:
  138.       case 6:
  139.       case 7:
  140.         win_pause();
  141.         break;
  142.       default:
  143.         break;
  144.     }
  145.   }
  146. }
  147.  
  148. int sh_read(int handle, void *buf, unsigned len)
  149. {
  150.   if (handle == -1) {
  151.     return (-1);
  152.   }
  153.   return (read(handle, buf, len));
  154. }
  155.  
  156. long sh_lseek(int handle, long offset, int fromwhere)
  157. {
  158.   if (handle == -1) {
  159.     return (-1L);
  160.   }
  161.   return (lseek(handle, offset, fromwhere));
  162. }
  163.  
  164. int sh_write(int handle, void *buffer, unsigned long len)
  165. {
  166.   if (handle == -1) {
  167.     return (-1);
  168.   }
  169.   return (write(handle, buffer, (unsigned) len));
  170. }
  171.  
  172. int sh_close(int f)
  173. {
  174.   if (f != -1)
  175.     close(f);
  176.   return (-1);
  177. }
  178.  
  179. int sh_open(char *path, int file_access, unsigned fmode)
  180. {
  181.   int handle, count, share;
  182.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  183.  
  184.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  185.     share = SH_DENYRW;
  186.   } else {
  187.     share = SH_DENYWR;
  188.   }
  189.   handle = open(path, file_access | share, fmode);
  190.   if (handle < 0) {
  191.     count = 1;
  192.     fnsplit(path, drive, dir, file, ext);
  193.     if (access(path, 0) != -1) {
  194.       delay(WAIT_TIME);
  195.       handle = open(path, file_access | share, fmode);
  196.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  197.         if (count % 2)
  198.           delay(WAIT_TIME);
  199.         else
  200.           giveup_timeslice();
  201.         count++;
  202.         handle = open(path, file_access | share, fmode);
  203.       }
  204.     }
  205.   }
  206.   return (handle);
  207. }
  208.  
  209. int sh_open1(char *path, int access)
  210. {
  211.   unsigned fmode;
  212.  
  213.   fmode = 0;
  214.   if ((access & O_RDWR) || (access & O_WRONLY))
  215.     fmode |= S_IWRITE;
  216.   if ((access & O_RDWR) || (access & O_RDONLY))
  217.     fmode |= S_IREAD;
  218.   return (sh_open(path, access, fmode));
  219. }
  220.  
  221. FILE *fsh_open(char *path, char *fmode)
  222. {
  223.   FILE *f;
  224.   int count, share, md, fd;
  225.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  226.  
  227.   share = SH_DENYWR;
  228.   md = 0;
  229.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  230.     share = SH_DENYRD;
  231.     md = O_RDWR | O_CREAT | O_TRUNC;
  232.   } else
  233.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  234.     share = SH_DENYRD;
  235.     md = O_RDWR | O_CREAT;
  236.   } else {
  237.     md = O_RDONLY;
  238.   }
  239.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  240.     md |= O_BINARY;
  241.   }
  242.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  243.     md &= ~O_RDONLY;
  244.     md |= O_RDWR;
  245.     share = SH_DENYRD;
  246.   }
  247.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  248.   if (fd < 0) {
  249.     count = 1;
  250.     fnsplit(path, drive, dir, file, ext);
  251.     if ((access(path, 0)) != -1) {
  252.       delay(WAIT_TIME);
  253.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  254.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  255.         delay(WAIT_TIME);
  256.         count++;
  257.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  258.       }
  259.     }
  260.   }
  261.   if (fd > 0) {
  262.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  263.       sh_lseek(fd, 0L, SEEK_END);
  264.     f = fdopen(fd, fmode);
  265.     if (!f) {
  266.       close(fd);
  267.     }
  268.   } else
  269.     f = NULL;
  270.   return (f);
  271. }
  272.  
  273. int log_it(int display, char *fmt,...)
  274. {
  275.   va_list v;
  276.   char s[255], fn[MAXPATH];
  277.   FILE *fp;
  278.  
  279.   sprintf(fn, "%sNEWS.LOG", net_data);
  280.   if ((fp = fsh_open(fn, "at")) == NULL)
  281.     return 1;
  282.   va_start(v, fmt);
  283.   vsprintf(s, fmt, v);
  284.   va_end(v);
  285.   fputs(s, fp);
  286.   fclose(fp);
  287.   if (display)
  288.     fputs(s, stderr);
  289.   return 0;
  290. }
  291.  
  292.  
  293. #define MAX_XFER 61440L
  294.  
  295. long huge_xfer(int fd, void huge * buf, unsigned sz, unsigned nel, int wr)
  296. {
  297.   long nxfr = 0, len = ((long) sz) * ((long) nel);
  298.   char huge *xbuf = (char huge *) buf;
  299.   unsigned cur, cur1;
  300.  
  301.   while (len > 0) {
  302.  
  303.     if (len > MAX_XFER)
  304.       cur = (unsigned int) MAX_XFER;
  305.     else
  306.       cur = (unsigned int) len;
  307.  
  308.     if (wr)
  309.       cur1 = sh_write(fd, (char *) xbuf, cur);
  310.     else
  311.       cur1 = sh_read(fd, (char *) xbuf, cur);
  312.  
  313.     if (cur1 != 65535L) {
  314.       len -= cur1;
  315.       nxfr += cur1;
  316.       xbuf = ((char huge *) buf) + nxfr;
  317.     }
  318.     if (cur1 != cur)
  319.       break;
  320.   }
  321.  
  322.   return (nxfr);
  323. }
  324.  
  325. void output(char *fmt,...)
  326. {
  327.   va_list v;
  328.   char s[255];
  329.  
  330.   va_start(v, fmt);
  331.   vsprintf(s, fmt, v);
  332.   va_end(v);
  333.   fputs(s, stderr);
  334. }
  335.  
  336.  
  337.  
  338. void far *mallocx(unsigned long l)
  339. {
  340.   void *x;
  341.   char huge *xx;
  342.  
  343.   if (!l)
  344.     l = 1;
  345.   x = farmalloc(l);
  346.   if (!x) {
  347.     log_it(1, "\n ! Insufficient memory (%ld bytes) to read all directories.", l);
  348.     return NULL;
  349.   }
  350.   xx = (char huge *) x;
  351.   while (l >= 1) {
  352.     if (l > 32768L) {
  353.       memset((void *) xx, 0, (size_t)32768L);
  354.       l -= 32768L;
  355.       xx += 32768L;
  356.     } else {
  357.       memset((void *) xx, 0, (size_t)l);
  358.       break;
  359.     }
  360.   }
  361.   return (x);
  362. }
  363.  
  364. int scanfor(char *token, FILE * in)
  365. {
  366.   char buf[MAX_BUF];
  367.   long pos;
  368.  
  369.   pos = ftell(in);
  370.   while (fgets(buf, MAX_BUF, in) && strncmpi(buf, token, strlen(token))) {
  371.     pos = ftell(in);
  372.   }
  373.   rewind(in);
  374.   fseek(in, pos, 0);
  375.   pos = ftell(in);
  376.   return (!strncmpi(buf, "begin 6", 7));
  377. }
  378.  
  379. unsigned char *trimstr1(unsigned char *s)
  380. {
  381.   int i;
  382.   static char *whitespace = " \r\n\t";
  383.  
  384.   i = strlen(s);
  385.   while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
  386.     --i;
  387.   while ((i > 0) && (_fstrchr(whitespace, *s))) {
  388.     memmove(s, s + 1, --i);
  389.   }
  390.   s[i] = 0;
  391.   return (s);
  392. }
  393.  
  394.  
  395. void scanfdl(FILE * in)
  396. {
  397.   char *ss, buf[MAX_BUF];
  398.   int done = 0;
  399.  
  400.   while ((fgets(buf, MAX_BUF, in)) && !done) {
  401.     ss = NULL;
  402.     if (strncmpi(buf, "subject:", 8) == 0) {
  403.       if (_fstrstr(buf, "FILE TRANSFER")) {
  404.         ss = strtok(buf, "@");
  405.         if (ss) {
  406.           ss = strtok(NULL, " ");
  407.           strcpy(net_name, ss);
  408.           ss = strtok(NULL, ":");
  409.           if (ss) {
  410.             ss = strtok(NULL, "\r\n");
  411.             if (ss) {
  412.               strcpy(fdlfn, ss);
  413.               trimstr1(fdlfn);
  414.             }
  415.           }
  416.         }
  417.       }
  418.     } else
  419.       if (strncmpi(buf, "Description:", 12) == 0) {
  420.       ss = strtok(buf, " ");
  421.       if (ss) {
  422.         ss = strtok(NULL, "\r\n");
  423.         strcpy(fdldesc, ss);
  424.       }
  425.     } else
  426.       if (strncmpi(buf, "FDL Type:", 9) == 0) {
  427.       ss = strtok(buf, ":");
  428.       if (ss) {
  429.         ss = strtok(NULL, "\r\n");
  430.         trimstr1(ss);
  431.         fdltype = atoi(ss);
  432.       }
  433.     } else
  434.       if (strncmpi(buf, "Originating System:", 19) == 0) {
  435.       ss = strtok(buf, ":");
  436.       if (ss) {
  437.         ss = strtok(NULL, "\r\n");
  438.         trimstr1(ss);
  439.         strcpy(fdlupby, ss);
  440.       }
  441.     } else
  442.       if (strncmpi(buf, "begin 600", 9) == 0)
  443.       done = 1;
  444.   }
  445.   return;
  446. }
  447.  
  448. void cd_to(char *s)
  449. {
  450.   char s1[81];
  451.   int i, db;
  452.  
  453.   strcpy(s1, s);
  454.   i = strlen(s1) - 1;
  455.   db = (s1[i] == '\\');
  456.   if (i == 0)
  457.     db = 0;
  458.   if ((i == 2) && (s1[1] == ':'))
  459.     db = 0;
  460.   if (db)
  461.     s1[i] = 0;
  462.   chdir(s1);
  463.   if (s[1] == ':') {
  464.     setdisk(s[0] - 'A');
  465.     if (s[2] == 0)
  466.       chdir("\\");
  467.   }
  468. }
  469.  
  470. void get_dir(char *s, int be)
  471. {
  472.   strcpy(s, "X:\\");
  473.   s[0] = 'A' + getdisk();
  474.   getcurdir(0, &(s[3]));
  475.   if (be) {
  476.     if (s[strlen(s) - 1] != '\\')
  477.       strcat(s, "\\");
  478.   }
  479. }
  480.  
  481. int exist(char *s)
  482. {
  483.   int i;
  484.   struct ffblk ff;
  485.  
  486.   i = findfirst(s, &ff, FA_HIDDEN);
  487.   if (i)
  488.     return (0);
  489.   else
  490.     return (1);
  491. }
  492.  
  493. int copyfile(int display, char *infile, char *outfile)
  494. {
  495.   int f1, f2, i;
  496.   char *b, s[181], s1[21], s2[81], s3[81];
  497.   struct ftime ft;
  498.  
  499.   if ((strcmp(infile, outfile) != 0) && (exist(infile))) {
  500.     if (exist(outfile)) {
  501.       fnsplit(outfile, s3, s2, s1, NULL);
  502.       i = 0;
  503.       sprintf(s, "%s%s%s.%03d", s3, s2, s1, i);
  504.       while (exist(s))
  505.         sprintf(s, "%s%s%s.%03d", s3, s2, s1, ++i);
  506.       strcpy(outfile, s);
  507.     }
  508.     fnsplit(outfile, NULL, NULL, s3, s2);
  509.     if (display)
  510.       output(" as %s%s", s3, s2);
  511.     if ((b = (char *) farmalloc(16400)) == NULL)
  512.       return 1;
  513.     f1 = open(infile, O_RDONLY | O_BINARY, S_IREAD | S_IWRITE);
  514.     if (!f1) {
  515.       farfree(b);
  516.       return 1;
  517.     }
  518.     getftime(f1, &ft);
  519.     f2 = open(outfile, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  520.     if (!f2) {
  521.       farfree(b);
  522.       close(f1);
  523.       return 1;
  524.     }
  525.     i = read(f1, (void *) b, 16384);
  526.     while (i > 0) {
  527.       write(f2, (void *) b, i);
  528.       i = read(f1, (void *) b, 16384);
  529.     }
  530.     f1 = close(f1);
  531.     setftime(f2, &ft);
  532.     f2 = close(f2);
  533.     farfree(b);
  534.   }
  535.   return 0;
  536. }
  537.  
  538. char *stripfn(char *fn)
  539. {
  540.   static char ofn[15];
  541.   int i, i1;
  542.   char s[81];
  543.  
  544.   i1 = -1;
  545.   for (i = 0; i < strlen(fn); i++)
  546.     if ((fn[i] == '\\') || (fn[i] == ':') || (fn[i] == '/'))
  547.       i1 = i;
  548.   if (i1 != -1)
  549.     strcpy(s, &(fn[i1 + 1]));
  550.   else
  551.     strcpy(s, fn);
  552.   for (i = 0; i < strlen(s); i++)
  553.     if ((s[i] >= 'A') && (s[i] <= 'Z'))
  554.       s[i] = s[i] - 'A' + 'a';
  555.   i = 0;
  556.   while (s[i] != 0) {
  557.     if (s[i] == 32)
  558.       strcpy(&s[i], &s[i + 1]);
  559.     else
  560.       ++i;
  561.   }
  562.   strcpy(ofn, s);
  563.  
  564.   return (ofn);
  565. }
  566.  
  567. void ssm(char *s)
  568. {
  569.   int f, i, i1;
  570.   char s1[161];
  571.   shortmsgrec sm;
  572.  
  573.   sprintf(s1, "%sSMW.DAT", syscfg.datadir);
  574.   f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  575.   if (f < 0)
  576.     return;
  577.   i = (int) (filelength(f) / sizeof(shortmsgrec));
  578.   i1 = i - 1;
  579.   if (i1 >= 0) {
  580.     sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  581.     sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  582.     while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
  583.       --i1;
  584.       sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  585.       sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  586.     }
  587.     if ((sm.tosys) || (sm.touser))
  588.       ++i1;
  589.   } else
  590.     i1 = 0;
  591.   sm.tosys = 0;
  592.   sm.touser = 1;
  593.   strncpy(sm.message, s, 80);
  594.   sm.message[80] = 0;
  595.   sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  596.   sh_write(f, (void *) &sm, sizeof(shortmsgrec));
  597.   sh_close(f);
  598. }
  599.  
  600. int do_it(char *cl)
  601. {
  602.   int i, i1, l, result;
  603.   char s[101], *ss[20];
  604.  
  605.   strcpy(s, cl);
  606.   ss[0] = s;
  607.   i = 1;
  608.   l = strlen(s);
  609.   for (i1 = 1; i1 < l; i1++)
  610.     if (s[i1] == 32) {
  611.       s[i1] = 0;
  612.       ss[i++] = &(s[i1 + 1]);
  613.     }
  614.   ss[i] = NULL;
  615.   result = spawnvpe(P_WAIT, ss[0], ss, xenviron);
  616.   return result;
  617. }
  618.  
  619. void align(char *s)
  620. {
  621.   char f[40], e[40], s1[20], *s2;
  622.   int i, i1, i2;
  623.  
  624.   i1 = 0;
  625.   if (s[0] == '.')
  626.     i1 = 1;
  627.   for (i = 0; i < strlen(s); i++)
  628.     if ((s[i] == '\\') || (s[i] == '/') || (s[i] == ':') || (s[i] == '<') ||
  629.         (s[i] == '>') || (s[i] == '|'))
  630.       i1 = 1;
  631.   if (i1) {
  632.     strcpy(s, "!");
  633.     return;
  634.   }
  635.   s2 = _fstrchr(s, '.');
  636.   if (s2 == NULL) {
  637.     e[0] = 0;
  638.   } else {
  639.     strcpy(e, &(s2[1]));
  640.     e[3] = 0;
  641.     s2[0] = 0;
  642.   }
  643.   strcpy(f, s);
  644.  
  645.   for (i = strlen(f); i < 8; i++)
  646.     f[i] = 32;
  647.   f[8] = 0;
  648.   i1 = 0;
  649.   i2 = 0;
  650.   for (i = 0; i < 8; i++) {
  651.     if (f[i] == '*')
  652.       i1 = 1;
  653.     if (f[i] == ' ')
  654.       i2 = 1;
  655.     if (i2)
  656.       f[i] = ' ';
  657.     if (i1)
  658.       f[i] = '?';
  659.   }
  660.  
  661.   for (i = strlen(e); i < 3; i++)
  662.     e[i] = 32;
  663.   e[3] = 0;
  664.   i1 = 0;
  665.   for (i = 0; i < 3; i++) {
  666.     if (e[i] == '*')
  667.       i1 = 1;
  668.     if (i1)
  669.       e[i] = '?';
  670.   }
  671.  
  672.   for (i = 0; i < 12; i++)
  673.     s1[i] = 32;
  674.   strcpy(s1, f);
  675.   s1[8] = '.';
  676.   strcpy(&(s1[9]), e);
  677.   strcpy(s, s1);
  678.   strupr(s);
  679. }
  680.  
  681.  
  682. void stuff_in(char *s, char *s1, char *f1, char *f2, char *f3, char *f4, char *f5)
  683. {
  684.   int r = 0, w = 0;
  685.  
  686.   while (s1[r] != 0) {
  687.     if (s1[r] == '%') {
  688.       ++r;
  689.       s[w] = 0;
  690.       switch (s1[r]) {
  691.         case '1':
  692.           strcat(s, f1);
  693.           break;
  694.         case '2':
  695.           strcat(s, f2);
  696.           break;
  697.         case '3':
  698.           strcat(s, f3);
  699.           break;
  700.         case '4':
  701.           strcat(s, f4);
  702.           break;
  703.         case '5':
  704.           strcat(s, f5);
  705.           break;
  706.       }
  707.       w = strlen(s);
  708.       r++;
  709.     } else
  710.       s[w++] = s1[r++];
  711.   }
  712.   s[w] = 0;
  713. }
  714.  
  715. char upcase(char ch)
  716. {
  717.   if ((ch > '`') && (ch < '{'))
  718.     ch = ch - 32;
  719.   return (ch);
  720. }
  721.  
  722.  
  723. char *make_abs_cmd(char *out)
  724. {
  725.   char s[161], s1[161], s2[161], *ss, *ss1;
  726.   char *exts[] = {"", ".COM", ".EXE", ".BAT", 0};
  727.   int i;
  728.  
  729.   strcpy(s1, out);
  730.  
  731.   if (s1[1] == ':') {
  732.     if (s1[2] != '\\') {
  733.       getcurdir(upcase(s1[0]) - 'A' + 1, s);
  734.       sprintf(out, "%c:\\%s\\%s", s1[0], s, s1 + 2);
  735.     }
  736.     goto got_cmd;
  737.   }
  738.   if (out[0] == '\\') {
  739.     sprintf(out, "%c:%s", maindir[0], s1);
  740.     goto got_cmd;
  741.   }
  742.   ss = _fstrchr(s1, ' ');
  743.   if (ss) {
  744.     *ss = 0;
  745.     sprintf(s2, " %s", ss + 1);
  746.   } else {
  747.     s2[0] = 0;
  748.   }
  749.   for (i = 0; exts[i]; i++) {
  750.     if (i == 0) {
  751.       ss1 = _fstrrchr(s1, '\\');
  752.       if (!ss1)
  753.         ss1 = s1;
  754.       if (_fstrchr(ss1, '.') == 0)
  755.         continue;
  756.     }
  757.     sprintf(s, "%s%s", s1, exts[i]);
  758.     if (exist(s)) {
  759.       sprintf(out, "%s%s%s", maindir, s, s2);
  760.       goto got_cmd;
  761.     } else {
  762.       ss1 = searchpath(s);
  763.       if (ss1) {
  764.         sprintf(out, "%s%s", ss1, s2);
  765.         goto got_cmd;
  766.       }
  767.     }
  768.   }
  769.  
  770.   sprintf(out, "%s%s%s", maindir, s1, s2);
  771.  
  772. got_cmd:
  773.   return (out);
  774. }
  775.  
  776.  
  777. void get_arc_cmd(char *out, char *arcfn, int cmd, char *ofn)
  778. {
  779.   char *ss, s[161];
  780.   int i;
  781.  
  782.   out[0] = 0;
  783.   ss = _fstrchr(arcfn, '.');
  784.   if (ss == NULL)
  785.     return;
  786.   ++ss;
  787.   for (i = 0; i < 4; i++)
  788.     if (stricmp(ss, syscfg.arcs[i].extension) == 0) {
  789.       switch (cmd) {
  790.         case 0:
  791.           strcpy(s, syscfg.arcs[i].arcl);
  792.           break;
  793.         case 1:
  794.           strcpy(s, syscfg.arcs[i].arce);
  795.           break;
  796.         case 2:
  797.           strcpy(s, syscfg.arcs[i].arca);
  798.           break;
  799.       }
  800.       if (s[0] == 0)
  801.         return;
  802.       stuff_in(out, s, arcfn, ofn, "", "", "");
  803.       make_abs_cmd(out);
  804.       return;
  805.     }
  806. }
  807.  
  808. void add_extended_description(char *fn, char *desc)
  809. {
  810.   ext_desc_type ed;
  811.   int f;
  812.  
  813.   strcpy(ed.name, fn);
  814.   ed.len = strlen(desc);
  815.   f = sh_open(edlfn, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  816.   sh_lseek(f, 0L, SEEK_END);
  817.   sh_write(f, &ed, sizeof(ext_desc_type));
  818.   sh_write(f, desc, ed.len);
  819.   f = sh_close(f);
  820. }
  821.  
  822.  
  823.  
  824. int get_file_idz(uploadsrec * u, directoryrec * d)
  825. {
  826.   char *b, *ss, cmd[255], cmdline[255], s3[121], s4[121];
  827.   int f, i, ok = 0;
  828.  
  829.   ss = _fstrchr(stripfn(u->filename), '.');
  830.   if (ss == NULL)
  831.     return 1;
  832.   ++ss;
  833.   for (i = 0; i < 4 && !ok; i++)
  834.     if (!ok)
  835.       ok = (stricmp(ss, syscfg.arcs[i].extension) == 0);
  836.   if (!ok)
  837.     return 1;
  838.   sprintf(s4, "%sFILE_ID.DIZ", temp_dir);
  839.   unlink(s4);
  840.   sprintf(s4, "%sDESC.SDI", temp_dir);
  841.   unlink(s4);
  842.   strcpy(s3, d->path);
  843.   cd_to(s3);
  844.   get_dir(s4, 1);
  845.   strcat(s4, stripfn(u->filename));
  846.   cd_to(maindir);
  847.   get_arc_cmd(cmd, s4, 1, "FILE_ID.DIZ DESC.SDI");
  848.   sprintf(cmdline, "%s", cmd);
  849.   cd_to(temp_dir);
  850.   do_it(cmdline);
  851.   cd_to(maindir);
  852.   sprintf(s4, "%sFILE_ID.DIZ", temp_dir);
  853.   if (!exist(s4))
  854.     sprintf(s4, "%sDESC.SDI", temp_dir);
  855.   if (exist(s4)) {
  856.     stripfn(s4);
  857.     if ((b = (char *) farmalloc((long) MAX_DIZ_LINES * 256 + 1)) == NULL)
  858.       return 1;
  859.     f = sh_open1(s4, O_RDONLY | O_BINARY);
  860.     if (filelength(f) < (MAX_DIZ_LINES * 256)) {
  861.       sh_read(f, b, (int) filelength(f));
  862.       b[(int)filelength(f)] = 0;
  863.     } else {
  864.       sh_read(f, b, (int) MAX_DIZ_LINES * 256);
  865.       b[(int) MAX_DIZ_LINES * 256] = 0;
  866.     }
  867.     sh_close(f);
  868.     ss = strtok(b, "\n");
  869.     if (LAST(ss) == '\r')
  870.       LAST(ss) = '\0';
  871.     sprintf(u->description, "%.58s", ss);
  872.     ss = strtok(NULL, "");
  873.     if (ss) {
  874.       for (i = strlen(ss) - 1; i > 0; i--) {
  875.         if ((ss[i] == 26) || (ss[i] == 12))
  876.           ss[i] = 32;
  877.       }
  878.       add_extended_description(u->filename, ss);
  879.       u->mask |= mask_extended;
  880.     }
  881.     if (b)
  882.       farfree(b);
  883.     sprintf(s4, "%sFILE_ID.DIZ", temp_dir);
  884.     unlink(s4);
  885.     sprintf(s4, "%sDESC.SDI", temp_dir);
  886.     unlink(s4);
  887.   }
  888.   return 0;
  889. }
  890.  
  891.  
  892. static char *fdldate(void)
  893. {
  894.   char *ds;
  895.   struct date today;
  896.  
  897.   ds = NULL;
  898.   getdate(&today);
  899.   sprintf(ds, "%02d/%02d/%02d", today.da_mon, today.da_day, today.da_year - 1900);
  900.   return ds;
  901. }
  902.  
  903. int compare(char *s1, char *s2)
  904. {
  905.   int ok, i;
  906.  
  907.   ok = 1;
  908.   for (i = 0; i < 12; i++)
  909.     if ((s1[i] != s2[i]) && (s1[i] != '?') && (s2[i] != '?'))
  910.       ok = 0;
  911.   return (ok);
  912. }
  913.  
  914. void dliscan(int dn)
  915. {
  916.   int i, f;
  917.   long l;
  918.   uploadsrec u;
  919.   directoryrec d;
  920.  
  921.   d = dirs[dn];
  922.   sprintf(dlfn, "%s%s.DIR", syscfg.datadir, d.filename);
  923.   sprintf(edlfn, "%s%s.EXT", syscfg.datadir, d.filename);
  924.   f = sh_open(dlfn, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  925.   i = (int)(filelength(f) / sizeof(uploadsrec));
  926.   if (i == 0) {
  927.     log_it(1, "\n ■ Creating new directory %s.", dlfn);
  928.     memset(&u, 0, sizeof(uploadsrec));
  929.     strcpy(u.filename, "|MARKER|");
  930.     time(&l);
  931.     u.daten = l;
  932.     SETREC(f, 0);
  933.     sh_write(f, (void *) &u, sizeof(uploadsrec));
  934.   } else {
  935.     SETREC(f, 0);
  936.     sh_read(f, (void *) &u, sizeof(uploadsrec));
  937.     if (strcmp(u.filename, "|MARKER|")) {
  938.       numf = (int)u.numbytes;
  939.       memset(&u, 0, sizeof(uploadsrec));
  940.       strcpy(u.filename, "|MARKER|");
  941.       time(&l);
  942.       u.daten = l;
  943.       u.numbytes = numf;
  944.       SETREC(f, 0);
  945.       sh_write(f, &u, sizeof(uploadsrec));
  946.     }
  947.   }
  948.   if (f > -1)
  949.     f = sh_close(f);
  950.   numf = (int)u.numbytes;
  951. }
  952.  
  953.  
  954.  
  955.  
  956. int recno(char *s)
  957. {
  958.   int i, f;
  959.   uploadsrec u;
  960.  
  961.   i = 1;
  962.   if (numf < 1)
  963.     return (-1);
  964.   f = sh_open1(dlfn, O_RDONLY | O_BINARY);
  965.   SETREC(f, i);
  966.   sh_read(f, (void *) &u, sizeof(uploadsrec));
  967.   while ((i < numf) && (compare(s, u.filename) == 0)) {
  968.     ++i;
  969.     SETREC(f, i);
  970.     sh_read(f, (void *) &u, sizeof(uploadsrec));
  971.   }
  972.   f = sh_close(f);
  973.   if (compare(s, u.filename))
  974.     return i;
  975.   else
  976.     return -1;
  977. }
  978.  
  979. char *make_abs_path(unsigned char *checkdir)
  980. {
  981.   char newdir[MAXPATH];
  982.  
  983.   if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
  984.     cd_to(maindir);
  985.     cd_to(checkdir);
  986.     if (LAST(checkdir) == '\\')
  987.       get_dir(newdir, 1);
  988.     else
  989.       get_dir(newdir, 0);
  990.     cd_to(maindir);
  991.     strcpy(checkdir, newdir);
  992.   }
  993.   return checkdir;
  994. }
  995.  
  996. void upload_file(int dn, char *fn, char *desc, char *upby)
  997. {
  998.   char s1[MAXPATH], ff[MAXPATH], temppath[MAXPATH];
  999.   int f;
  1000.   long l;
  1001.   directoryrec d;
  1002.   uploadsrec u, u1;
  1003.  
  1004.   d = dirs[dn];
  1005.  
  1006.   strcpy(u.filename, fn);
  1007.   align(u.filename);
  1008.   u.ownerusr = 1;
  1009.   u.ownersys = 0;
  1010.   u.numdloads = 0;
  1011.   u.filetype = 0;
  1012.   u.mask = 0;
  1013.   strcpy(temppath, d.path);
  1014.   make_abs_path(temppath);
  1015.   sprintf(ff, "%s%s", temppath, fn);
  1016.   f = sh_open1(ff, O_RDONLY | O_BINARY);
  1017.   l = filelength(f);
  1018.   u.numbytes = l;
  1019.   sh_close(f);
  1020.   strcpy(u.upby, upby);
  1021.   strcpy(u.date, fdldate());
  1022.   strcpy(u.description, desc);
  1023.   time(&l);
  1024.   u.daten = l;
  1025.   get_file_idz(&u, &d);
  1026.   f = sh_open(dlfn, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  1027.   SETREC(f, 0);
  1028.   sh_read(f, &u1, sizeof(uploadsrec));
  1029.   numf = (int)u1.numbytes;
  1030.   ++numf;
  1031.   SETREC(f, numf);
  1032.   sh_write(f, (void *) &u, sizeof(uploadsrec));
  1033.   SETREC(f, 0);
  1034.   sh_read(f, &u1, sizeof(uploadsrec));
  1035.   u1.numbytes = numf;
  1036.   u1.daten = l;
  1037.   SETREC(f, 0);
  1038.   sh_write(f, (void *) &u1, sizeof(uploadsrec));
  1039.   f = sh_close(f);
  1040.   sprintf(s1, "FDL : %s uploaded on %s", u.filename, d.name);
  1041.   ssm(s1);
  1042.   log_it(1, "\n ■ %s", s1);
  1043. }
  1044.  
  1045. void free_dirs(void)
  1046. {
  1047.   if (dirs != NULL)
  1048.     farfree(dirs);
  1049.   dirs = NULL;
  1050. }
  1051.  
  1052.  
  1053. void name_file(int msg, char *newname)
  1054. {
  1055.   int ok;
  1056.   struct stat info;
  1057.   int i;
  1058.  
  1059.   ok = 0;
  1060.   for (i = 0; ((i < 10000) && (!ok)); i++) {
  1061.     sprintf(newname, "%s%s\\%s-%04.04d.MSG",
  1062.             net_data, msg ? "CHECKNET" : "SPOOL",
  1063.             msg ? "CHK" : "UNK", i);
  1064.     if (stat(newname, &info) == -1)
  1065.       ok = 1;
  1066.   }
  1067. }
  1068.  
  1069. void move_bad(char *src)
  1070. {
  1071.   char dest[MAXPATH], file[12], ext[5];
  1072.   int i = 0;
  1073.  
  1074.   fnsplit(src, NULL, NULL, file, ext);
  1075.  
  1076.   sprintf(dest, "%sCHECKNET\\%s%s", net_data, file, ext);
  1077.   while (exist(dest))
  1078.     sprintf(dest, "%sCHECKNET\\%s.%03d", net_data, file, i++);
  1079.  
  1080.   if (copyfile(0, src, dest))
  1081.     unlink(src);
  1082. }
  1083.  
  1084. int init(void)
  1085. {
  1086.   int i, i1, f;
  1087.   char fn[MAXPATH];
  1088.  
  1089.   i = i1 = 0;
  1090.   while (environ[i] != NULL) {
  1091.     xenviron[i1++] = environ[i];
  1092.     ++i;
  1093.   }
  1094.   xenviron[i1] = NULL;
  1095.  
  1096.   sprintf(fn, "%sCONFIG.DAT", maindir);
  1097.   f = sh_open1(fn, O_RDONLY | O_BINARY);
  1098.   if (f < 0) {
  1099.     output("\n ■ Unable to read %s.", fn);
  1100.     return 1;
  1101.   }
  1102.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1103.   sh_close(f);
  1104.   return 0;
  1105. }
  1106.  
  1107. main(int argc, char *argv[])
  1108. {
  1109.   char outname[181], buf[MAXPATH], dirfn[21], dirpath[MAXPATH], junk[80];
  1110.   char *ss, argfile[21], s1[181], s2[181], s3[21], s4[21], s5[21], fn[MAXPATH];
  1111.   int i, f, ok, ok1, dn, result, num_dirs;
  1112.   long l;
  1113.   unsigned short dirtype;
  1114.   FILE *in, *out, *fp;
  1115.  
  1116.   detect_multitask();
  1117.  
  1118.   ok1 = 0;
  1119.  
  1120.   if (argc == 4 || argc == 5) {
  1121.     if (strcmpi(argv[1], "-encode") == 0 && argc == 4) {
  1122.       if (((in = fsh_open(argv[2], "r")) != NULL) && ((out = fsh_open(argv[3], "at+")) != NULL)) {
  1123.         output(" %ld bytes.", uuencode(in, out, argv[2]));
  1124.         if (in != NULL)
  1125.           fclose(in);
  1126.         if (out != NULL)
  1127.           fclose(out);
  1128.         ok1 = EXIT_SUCCESS;
  1129.       } else
  1130.         ok1 = EXIT_FAILURE;
  1131.     } else
  1132.       if (strcmpi(argv[1], "-decode") == 0 && argc == 5) {
  1133.       strcpy(argfile, argv[2]);
  1134.       strcpy(temp_dir, argv[3]);
  1135.       strcpy(net_data, argv[4]);
  1136.       strcpy(maindir, argv[0]);
  1137.       while(LAST(maindir) != '\\')
  1138.         LAST(maindir) = 0;
  1139.       if (init()) {
  1140.         log_it(1, "\n ■ Failed to initialize UU variables.");
  1141.         ok1 = EXIT_FAILURE;
  1142.       }
  1143.       cd_to(temp_dir);
  1144.  
  1145.       if ((in = fsh_open(argfile, "r")) != NULL) {
  1146.         net_name[0] = 0;
  1147.         fdldesc[0] = 0;
  1148.         fdltype = 0;
  1149.         fdlfn[0] = 0;
  1150.         scanfdl(in);
  1151.         rewind(in);
  1152.         scanfor("begin", in);
  1153.         result = uudecode(in, temp_dir, outname);
  1154.         if (in != NULL)
  1155.           fclose(in);
  1156.         switch (result) {
  1157.           case UU_NO_MEM:
  1158.             sprintf(s1, "%s%s", temp_dir, argfile);
  1159.             move_bad(s1);
  1160.             cd_to(maindir);
  1161.             sprintf(s1, "Error decoding %s.", argfile);
  1162.             log_it(1, "\n ■ %s", s1);
  1163.             ssm(s1);
  1164.             sprintf(s1, "%s%s", argv[4], outname);
  1165.             unlink(s1);
  1166.             ok1 = EXIT_FAILURE;
  1167.             break;
  1168.           case UU_BAD_BEGIN:
  1169.             sprintf(s1, "%s%s", temp_dir, argfile);
  1170.             name_file(0, s2);
  1171.             if (copyfile(0, s1, s2))
  1172.               move_bad(s2);
  1173.             else
  1174.               unlink(s1);
  1175.             cd_to(maindir);
  1176.             sprintf(s1, "%s%s", argv[4], outname);
  1177.             unlink(s1);
  1178.             ok1 = EXIT_FAILURE;
  1179.             break;
  1180.           case UU_CANT_OPEN:
  1181.             log_it(1, "\n ■ Cannot open %s%s", argv[4], outname);
  1182.             cd_to(maindir);
  1183.             ok1 = EXIT_FAILURE;
  1184.             break;
  1185.           case UU_CHECKSUM:
  1186.             sprintf(s1, "%s%s", temp_dir, argfile);
  1187.             move_bad(s1);
  1188.             cd_to(maindir);
  1189.             sprintf(s1, "Checksum error decoding %s - moved to CHECKNET!", argfile);
  1190.             log_it(1, "\n ■ %s", s1);
  1191.             ssm(s1);
  1192.             sprintf(s1, "%s%s", argv[4], outname);
  1193.             unlink(s1);
  1194.             ok1 = EXIT_FAILURE;
  1195.             break;
  1196.           case UU_BAD_END:
  1197.             sprintf(s1, "%s%s", temp_dir, argfile);
  1198.             move_bad(s1);
  1199.             cd_to(maindir);
  1200.             sprintf(s1, "No \'end\' found in %s - moved to CHECKNET!", argfile);
  1201.             log_it(1, "\n ■ %s", s1);
  1202.             ssm(s1);
  1203.             sprintf(s1, "%s%s", argv[4], outname);
  1204.             unlink(s1);
  1205.             ok1 = EXIT_FAILURE;
  1206.             break;
  1207.           case UU_SUCCESS:
  1208.             sprintf(s1, "%s%s", temp_dir, argfile);
  1209.             unlink(s1);
  1210.             stripfn(outname);
  1211.             fnsplit(outname, NULL, NULL, s4, s3);
  1212.             sprintf(s5, "%s%s", s4, s3);
  1213.             if ((strcmpi(s3, ".NET") == NULL) && (strncmpi(argfile, "PKT", 3) == NULL)) {
  1214.               i = 0;
  1215.               sprintf(s2, "%sP1-%03d.NET", argv[4], i);
  1216.               while (exist(s2))
  1217.                 sprintf(s2, "%sP1-%03d.NET", argv[4], ++i);
  1218.               sprintf(s1, "%s%s", temp_dir, stripfn(outname));
  1219.               if (copyfile(0, s1, s2)) {
  1220.                 log_it(1, "\n ■ Error creating %s", s2);
  1221.                 cd_to(maindir);
  1222.                 ok1 = EXIT_FAILURE;
  1223.                 break;
  1224.               } else
  1225.                 unlink(s1);
  1226.             } else {
  1227.               if (fdltype)
  1228.                 sprintf(s1, "Received : %s (FDL %hu)", s5, fdltype);
  1229.               else
  1230.                 sprintf(s1, "Received transferred file : %s.", s5);
  1231.               ssm(s1);
  1232.               log_it(1, "\n ■ %s", s1);
  1233.               num_dirs = 0;
  1234.               dirs = (directoryrec huge *) mallocx(((long) syscfg.max_dirs) *
  1235.                   ((long) sizeof(directoryrec)));
  1236.               if (dirs == NULL)
  1237.                 log_it(0, "\n - Insufficient memory to read directories!");
  1238.               else {
  1239.                 sprintf(fn, "%sDIRS.DAT", syscfg.datadir);
  1240.                 f = sh_open1(fn, O_RDONLY | O_BINARY);
  1241.                 if (f < 0)
  1242.                   log_it(1, "\n ! Unable to read %s", fn);
  1243.                 else {
  1244.                   num_dirs = (int) huge_xfer(f, dirs, sizeof(directoryrec),
  1245.                                        syscfg.max_dirs, 0) / sizeof(directoryrec);
  1246.                   log_it(0, "\n - Total dirs %d", num_dirs);
  1247.                   if (num_dirs)
  1248.                     l = filelength(f) / num_dirs;
  1249.                   if (l != sizeof(directoryrec))
  1250.                     num_dirs = 0;
  1251.                 }
  1252.                 f =sh_close(f);
  1253.               }
  1254.               sprintf(s1, "%s%s", temp_dir, s5);
  1255.               if (num_dirs) {
  1256.                 dn = 0;
  1257.                 if (fdltype) {
  1258.                   for (i = 0; (i < num_dirs && !dn); i++) {
  1259.                     if (dirs[i].type == fdltype) {
  1260.                       dn = i;
  1261.                       break;
  1262.                     }
  1263.                   }
  1264.                   if (!dn) {
  1265.                     log_it(1, "\n ■ FDL %hu not in DIREDIT... checking FDLFTS.CFG.",
  1266.                            fdltype);
  1267.                     sprintf(fn, "%sFDLFTS.CFG", net_data);
  1268.                     if ((fp = fsh_open(fn, "rt")) == NULL) {
  1269.                       log_it(1, "\n ■ FDLFTS.CFG does not exist... uploading to Sysop.");
  1270.                     } else {
  1271.                       ok = 0;
  1272.                       while ((fgets(buf, 80, fp)) && !ok) {
  1273.                         if (buf[0] == ':')
  1274.                           continue;
  1275.                         if (strncmpi(buf, "FDL", 3) == 0) {
  1276.                           sscanf(buf, "%s %hu %s %s", junk, &dirtype, dirfn, dirpath);
  1277.                           trimstr1(dirfn);
  1278.                           if (dirtype == fdltype) {
  1279.                             for (i = 0; i < num_dirs; i++) {
  1280.                               if (strnicmp((char *)dirs[i].filename, dirfn, strlen(dirfn)) == 0) {
  1281.                                 dn = i;
  1282.                                 ok = 1;
  1283.                                 break;
  1284.                               }
  1285.                             }
  1286.                           }
  1287.                         }
  1288.                       }
  1289.                       if (fp != NULL)
  1290.                         fclose(fp);
  1291.                     }
  1292.                   }
  1293.                   if ((!ok) && (fdltype))
  1294.                     log_it(1, "\n ■ FDL %hu not defined in FDLFTS.CFG... uploading to Sysop.",
  1295.                            fdltype);
  1296.                 } else {
  1297.                   dn = 0;
  1298.                   strcpy(fdldesc, "[No Description Found]");
  1299.                   strcpy(fdlupby, "FILEnet Transfer");
  1300.                   sprintf(fn, "%sFDLFTS.CFG", net_data);
  1301.                   if ((fp = fsh_open(fn, "rt")) == NULL) {
  1302.                     log_it(1, "\n ■ %s does not exist... upload to Sysop.", fn);
  1303.                   } else {
  1304.                     ok = 0;
  1305.                     while ((fgets(buf, 80, fp)) && !ok) {
  1306.                       if (strncmpi(buf, "NOREQUEST_DIR", 13) == 0) {
  1307.                         ss = strtok(buf, " ");
  1308.                         if (ss) {
  1309.                           ss = strtok(NULL, "\r\n");
  1310.                           if (ss) {
  1311.                             strcpy(dirfn, ss);
  1312.                             trimstr1(dirfn);
  1313.                             ok = 1;
  1314.                             for (i = 0; i < num_dirs; i++) {
  1315.                               if (strnicmp(dirs[i].filename, dirfn, strlen(dirfn)) == 0) {
  1316.                                 dn = i;
  1317.                                 break;
  1318.                               }
  1319.                             }
  1320.                           }
  1321.                         }
  1322.                       }
  1323.                     }
  1324.                     if (fp != NULL)
  1325.                       fclose(fp);
  1326.                   }
  1327.                   if (!ok)
  1328.                     log_it(1, "\n ■ NOREQUEST_DIR not defined in %s.", fn);
  1329.                 }
  1330.                 sprintf(s1, "%s%s", temp_dir, s5);
  1331.                 strcpy(buf, (char *)dirs[dn].path);
  1332.                 make_abs_path(buf);
  1333.                 sprintf(s2, "%s%s", buf, s5);
  1334.                 if (exist(s2)) {
  1335.                   log_it(1, "\n ■ %s already exists", s2);
  1336.                   move_bad(s1);
  1337.                 } else {
  1338.                   if (copyfile(0, s1, s2)) {
  1339.                     log_it(1, "\n ■ Error copying %s", s2);
  1340.                     move_bad(s1);
  1341.                   } else {
  1342.                     dliscan(dn);
  1343.                     strcpy(fn, s5);
  1344.                     align(fn);
  1345.                     ok = recno(fn);
  1346.                     if (ok == -1)
  1347.                       upload_file(dn, s5, fdldesc, fdlupby);
  1348.                     else
  1349.                       log_it(1, "\n ■ %s already in %s.", fn, dirs[dn].name);
  1350.                   }
  1351.                 }
  1352.                 unlink(s1);
  1353.               } else {
  1354.                 log_it(1, "\n ■ Moving %s to CHECKNET", s1);
  1355.                 move_bad(s1);
  1356.               }
  1357.               fdltype = 0;
  1358.               fdlfn[0] = 0;
  1359.               fdldesc[0] = 0;
  1360.               free_dirs();
  1361.             }
  1362.             cd_to(maindir);
  1363.             ok1 = EXIT_SUCCESS;
  1364.             break;
  1365.           default:
  1366.             sprintf(s1, "%s%s", temp_dir, argfile);
  1367.             name_file(1, s2);
  1368.             log_it(1, "\n ■ Unknown error %s...", s2);
  1369.             if (copyfile(1, s1, s2))
  1370.               log_it(1, "\n ■ Error during copy...");
  1371.             else
  1372.               unlink(s1);
  1373.             cd_to(maindir);
  1374.             sprintf(s1, "Unknown error %s...", s2);
  1375.             ssm(s1);
  1376.             ok1 = EXIT_FAILURE;
  1377.             break;
  1378.         }
  1379.       } else {
  1380.         cd_to(maindir);
  1381.         log_it(1, "\n ■ Input file %s not found.", argfile);
  1382.         ok1 = EXIT_FAILURE;
  1383.       }
  1384.       }
  1385.   } else
  1386.     output("\n ■ %s\n", version);
  1387.   if (in != NULL)
  1388.     fclose(in);
  1389.   if (out != NULL)
  1390.     fclose(out);
  1391.   return ok1;
  1392. }
  1393.