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