home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / findwork.c < prev    next >
Text File  |  1994-09-25  |  4KB  |  174 lines

  1. /*  findwork.c    Routine to find and process outgoing uucp traffic.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include "uucico.h"
  27. #include <modes.h>
  28. #ifndef _OSK
  29. #include "dir_6809.h"
  30. #else
  31. #include <dir.h>
  32. #endif
  33.  
  34.  
  35. /* This function checks to see if there is any work to do.  Used by slave()
  36.    -- BAS */
  37.  
  38. int anywork()
  39. {
  40.      DIR *dp;
  41.      register struct direct *dirbuf;            /* defined in dir.h */
  42.      flag worktodo = FALSE;
  43.  
  44.      if ((dp = opendir (".")) == NULL)
  45.        {
  46.           logerror ("anywork: not enough memory to read directory");
  47.           longjmp (env, FATAL);
  48.        }
  49.  
  50.      while ((dirbuf = readdir (dp)) != NULL)
  51.           if (strnucmp (dirbuf->d_name, "C.", 2) == 0)
  52.             {
  53.                worktodo = TRUE;
  54.                break;
  55.             }
  56.      closedir (dp);
  57.      return ((int)worktodo);
  58. }
  59.  
  60.  
  61.  
  62. /* findwork() should ONLY be executed when the role is MASTER -- BAS */
  63.  
  64. void findwork()
  65. {
  66.      void dowork();
  67.      DIR *dp;                                  /* defined in dir.h */
  68.      register struct direct *dirbuf;           /*                  */
  69.  
  70.      /* Open spool directory; exit on error.  Our current data directory
  71.         should already be the correct spool directory for this remote. */
  72.  
  73.      if (role == SLAVE)
  74.      {
  75.        if (debuglvl > 1)
  76.             fputs ("findwork: Why is the SLAVE here?\n", log);
  77.  
  78.        return;
  79.      }
  80.  
  81.      if ((dp = opendir (".")) == NULL)
  82.        {
  83.           logerror ("findwork: can't read entire directory--too much work to do");
  84.           /* fatal error, abort back to uucico() */
  85.           longjmp (env, FATAL);
  86.        }
  87.  
  88.      /* scan the directory */
  89.      while ((dirbuf = readdir (dp)) != NULL)
  90.           if (dirbuf->d_name[0] != '.')
  91.                if (strnucmp (dirbuf->d_name, "C.", 2) == 0)
  92.                     dowork (dirbuf->d_name);
  93.      closedir (dp);
  94. }
  95.  
  96.  
  97.  
  98. /* dowork  --do work for one C. file (while in master mode) */
  99.  
  100. void dowork (cfile)
  101. char *cfile;
  102. {
  103.      char line[100];
  104.      FILE *file;
  105.      register char *p;
  106.      flag workdone, killC = TRUE;                      /* assume we succeed */
  107.  
  108.      if ((file = fopen (cfile, "r")) == NULL)                 /* DEBUG */
  109.        {
  110.           fprintf (log, "DEBUG--dowork: can't open C. file '%s'\n", cfile);
  111.           return;
  112.        }
  113.  
  114.      p = line;
  115.      while (mfgets (p, sizeof (line), file) != NULL)
  116.        {
  117.           switch (*p)
  118.             {
  119.                case 'S':
  120.                     workdone = msendfile (p);
  121.                     break;
  122.  
  123.                case 'R':
  124.                     workdone = mrecvfile (p);
  125.                     break;
  126.  
  127.                default:
  128.                     workdone = TRUE;
  129.                     break;
  130.             }
  131.  
  132.           if (!workdone)
  133.                killC = FALSE;
  134.        }
  135.      fclose (file);
  136.  
  137.      /* get rid of C. file only if everything went okay */
  138.      if (killC)
  139.          if (unlink (cfile) == ERROR)
  140.            {
  141.               char tmp[65];
  142.  
  143.               sprintf (tmp,
  144.                        "dowork: can't unlink %s ...error %d\n", cfile, errno);
  145.               logerror (tmp);
  146.            }
  147. }
  148.  
  149.  
  150.  
  151. /* slavework  --do queued work from remote system */
  152.  
  153. int slavework (cline)
  154. char *cline;
  155. {
  156.      char command[120];
  157.  
  158.      strcpy (command, cline);
  159.  
  160.      switch (*cline)
  161.        {
  162.           case 'R':
  163.                srecvfile (command);
  164.                break;
  165.  
  166.           case 'S':
  167.                ssendfile (command);
  168.                break;
  169.  
  170.           default:
  171.                break;
  172.        }
  173. }
  174.