home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / unix.subproj / jobid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  3.9 KB  |  170 lines

  1. /* jobid.c
  2.    Convert file names to jobids and vice versa.
  3.  
  4.    Copyright (C) 1991, 1992, 1995 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #include "uuconf.h"
  29. #include "uudefs.h"
  30. #include "sysdep.h"
  31. #include "system.h"
  32.  
  33. /* Translate a file name and an associated system into a job id.
  34.    These job ids are used by uustat.  */
  35.  
  36. char *
  37. zsfile_to_jobid (qsys, zfile, bgrade)
  38.      const struct uuconf_system *qsys;
  39.      const char *zfile;
  40.      int bgrade;
  41. {
  42.   size_t clen;
  43.   char *zret;
  44.  
  45.   clen = strlen (qsys->uuconf_zname);
  46.  
  47. #if ! SPOOLDIR_TAYLOR
  48.  
  49.   /* We use the system name attached to the grade and sequence number.
  50.      This won't work correctly if the file name was actually created
  51.      by some other version of uucp that uses a different length for
  52.      the sequence number.  Too bad.  */
  53.  
  54.   zret = zbufalc (clen + CSEQLEN + 2);
  55.   memcpy (zret, qsys->uuconf_zname, clen);
  56.   zret[clen] = bgrade;
  57.   memcpy (zret + clen + 1, zfile + strlen (zfile) - CSEQLEN, CSEQLEN + 1);
  58.  
  59. #else
  60.  
  61.   /* We use the system name followed by a dot, the grade, and the
  62.      sequence number.  In this case, the sequence number is a long
  63.      string.  */
  64.  
  65.   {
  66.     size_t cseqlen;
  67.  
  68.     /* zfile is SYS/C./C.gseq.  */
  69.     zfile = strrchr (zfile, '/');
  70.  
  71. #if DEBUG > 0
  72.     if (zfile == NULL
  73.     || zfile[1] != 'C'
  74.     || zfile[2] != '.'
  75.     || zfile[3] == '\0')
  76.       ulog (LOG_FATAL, "zsfile_to_jobid: Can't happen");
  77. #endif
  78.  
  79.     /* Make zfile point at .gseq.  */
  80.     zfile += 2;
  81.  
  82.     cseqlen = strlen (zfile);
  83.     zret = zbufalc (clen + cseqlen + 1);
  84.     memcpy (zret, qsys->uuconf_zname, clen);
  85.     memcpy (zret + clen, zfile, cseqlen + 1);
  86.   }
  87.  
  88. #endif
  89.  
  90.   return zret;
  91. }
  92.  
  93. /* Turn a job id back into a file name.  */
  94.  
  95. char *
  96. zsjobid_to_file (zid, pzsystem, pbgrade)
  97.      const char *zid;
  98.      char **pzsystem;
  99.      char *pbgrade;
  100. {
  101. #if ! SPOOLDIR_TAYLOR
  102.   size_t clen;
  103.   const char *zend;
  104.   char *zsys;
  105.   char abname[CSEQLEN + 11];
  106.   char *zret;
  107.  
  108.   clen = strlen (zid);
  109.   if (clen <= CSEQLEN)
  110.     {
  111.       ulog (LOG_ERROR, "%s: Bad job id", zid);
  112.       return NULL;
  113.     }
  114.  
  115.   zend = zid + clen - CSEQLEN - 1;
  116.  
  117.   zsys = zbufalc (clen - CSEQLEN);
  118.   memcpy (zsys, zid, clen - CSEQLEN - 1);
  119.   zsys[clen - CSEQLEN - 1] = '\0';
  120.  
  121.   /* This must correspond to zsfile_name.  */
  122.   sprintf (abname, "C.%.7s%s", zsys, zend);
  123.  
  124.   zret = zsfind_file (abname, zsys, *zend);
  125.  
  126.   if (zret != NULL && pzsystem != NULL)
  127.     *pzsystem = zsys;
  128.   else
  129.     ubuffree (zsys);
  130.  
  131.   if (pbgrade != NULL)
  132.     *pbgrade = *zend;
  133.  
  134.   return zret;
  135. #else /* SPOOLDIR_TAYLOR */
  136.   char *zdot;
  137.   size_t csyslen;
  138.   char *zsys;
  139.   char ab[15];
  140.   char *zret;
  141.  
  142.   zdot = strrchr (zid, '.');
  143.   if (zdot == NULL)
  144.     {
  145.       ulog (LOG_ERROR, "%s: Bad job id", zid);
  146.       return NULL;
  147.     }
  148.  
  149.   csyslen = zdot - zid;
  150.   zsys = zbufalc (csyslen + 1);
  151.   memcpy (zsys, zid, csyslen);
  152.   zsys[csyslen] = '\0';
  153.  
  154.   ab[0] = 'C';
  155.   strcpy (ab + 1, zdot);
  156.  
  157.   zret = zsfind_file (ab, zsys, zdot[1]);
  158.  
  159.   if (zret != NULL && pzsystem != NULL)
  160.     *pzsystem = zsys;
  161.   else
  162.     ubuffree (zsys);
  163.  
  164.   if (pbgrade != NULL)
  165.     *pbgrade = zdot[1];
  166.  
  167.   return zret;
  168. #endif /* SPOOLDIR_TAYLOR */
  169. }
  170.