home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / uucp-1.04 / unix / splcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-13  |  2.9 KB  |  116 lines

  1. /* splcmd.c
  2.    Spool a command.
  3.  
  4.    Copyright (C) 1991, 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #include "uudefs.h"
  29. #include "uuconf.h"
  30. #include "sysdep.h"
  31. #include "system.h"
  32.  
  33. #include <errno.h>
  34. #include <ctype.h>
  35.  
  36. /* Given a set of commands to execute for a remote system, create a
  37.    command file holding them.  This creates a single command file
  38.    holding all the commands passed in.  It returns a jobid.  */
  39.  
  40. char *
  41. zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds)
  42.      const struct uuconf_system *qsys;
  43.      int bgrade;
  44.      int ccmds;
  45.      const struct scmd *pascmds;
  46. {
  47.   char *z;
  48.   FILE *e;
  49.   int i;
  50.   const struct scmd *q;
  51.   char *zjobid;
  52.  
  53. #if DEBUG > 0
  54.   if (! UUCONF_GRADE_LEGAL (bgrade))
  55.     ulog (LOG_FATAL, "Bad grade %d", bgrade);
  56. #endif
  57.  
  58.   z = zscmd_file (qsys, bgrade);
  59.   if (z == NULL)
  60.     return NULL;
  61.  
  62.   e = esysdep_fopen (z, FALSE, FALSE, TRUE);
  63.   if (e == NULL)
  64.     {
  65.       ubuffree (z);
  66.       return NULL;
  67.     }
  68.  
  69.   for (i = 0, q = pascmds; i < ccmds; i++, q++)
  70.     {
  71.       switch (q->bcmd)
  72.     {
  73.     case 'S':
  74.       fprintf (e, "S %s %s %s -%s %s 0%o %s\n", q->zfrom, q->zto,
  75.            q->zuser, q->zoptions, q->ztemp, q->imode,
  76.            q->znotify == NULL ? (const char *) "" : q->znotify);
  77.       break;
  78.     case 'R':
  79.       fprintf (e, "R %s %s %s -%s\n", q->zfrom, q->zto, q->zuser,
  80.            q->zoptions);
  81.       break;
  82.     case 'X':
  83.       fprintf (e, "X %s %s %s -%s\n", q->zfrom, q->zto, q->zuser,
  84.            q->zoptions);
  85.       break;
  86.     case 'E':
  87.       fprintf (e, "E %s %s %s -%s %s 0%o %s 0 %s\n", q->zfrom, q->zto,
  88.            q->zuser, q->zoptions, q->ztemp, q->imode,
  89.            q->znotify, q->zcmd);
  90.       break;
  91.     default:
  92.       ulog (LOG_ERROR,
  93.         "zsysdep_spool_commands: Unrecognized type %d",
  94.         q->bcmd);
  95.       (void) fclose (e);
  96.       (void) remove (z);
  97.       ubuffree (z);
  98.       return NULL;
  99.     }
  100.     }
  101.  
  102.   if (fclose (e) != 0)
  103.     {
  104.       ulog (LOG_ERROR, "fclose: %s", strerror (errno));
  105.       (void) remove (z);
  106.       ubuffree (z);
  107.       return NULL;
  108.     }
  109.  
  110.   zjobid = zsfile_to_jobid (qsys, z, bgrade);
  111.   if (zjobid == NULL)
  112.     (void) remove (z);
  113.   ubuffree (z);
  114.   return zjobid;
  115. }
  116.