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

  1. /* jobid.c
  2.    Convert file names to jobids and vice versa.
  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 "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.  We use the system name attached
  35.    to the grade and sequence number.  This won't work correctly if the
  36.    file name was actually created by some other version of uucp that
  37.    uses a different length for the sequence number.  Too bad.  */
  38.  
  39. char *
  40. zsfile_to_jobid (qsys, zfile, bgrade)
  41.      const struct uuconf_system *qsys;
  42.      const char *zfile;
  43.      int bgrade;
  44. {
  45.   size_t clen;
  46.   char *zret;
  47.  
  48.   clen = strlen (qsys->uuconf_zname);
  49.   zret = zbufalc (clen + CSEQLEN + 2);
  50.   memcpy (zret, qsys->uuconf_zname, clen);
  51.   zret[clen] = bgrade;
  52.   memcpy (zret + clen + 1, zfile + strlen (zfile) - CSEQLEN, CSEQLEN + 1);
  53.   return zret;
  54. }
  55.  
  56. /* Turn a job id back into a file name.  */
  57.  
  58. char *
  59. zsjobid_to_file (zid, pzsystem, pbgrade)
  60.      const char *zid;
  61.      char **pzsystem;
  62.      char *pbgrade;
  63. {
  64.   size_t clen;
  65.   const char *zend;
  66.   char *zsys;
  67.   char abname[CSEQLEN + 11];
  68.   char *zret;
  69.  
  70.   clen = strlen (zid);
  71.   if (clen <= CSEQLEN)
  72.     {
  73.       ulog (LOG_ERROR, "%s: Bad job id", zid);
  74.       return NULL;
  75.     }
  76.  
  77.   zend = zid + clen - CSEQLEN - 1;
  78.  
  79.   zsys = zbufalc (clen - CSEQLEN);
  80.   memcpy (zsys, zid, clen - CSEQLEN - 1);
  81.   zsys[clen - CSEQLEN - 1] = '\0';
  82.  
  83.   /* This must correspond to zsfile_name.  */
  84. #if ! SPOOLDIR_TAYLOR
  85.   sprintf (abname, "C.%.7s%s", zsys, zend);
  86. #else
  87.   sprintf (abname, "C.%s", zend);
  88. #endif
  89.  
  90.   zret = zsfind_file (abname, zsys, *zend);
  91.  
  92.   if (zret != NULL && pzsystem != NULL)
  93.     *pzsystem = zsys;
  94.   else
  95.     ubuffree (zsys);
  96.  
  97.   if (pbgrade != NULL)
  98.     *pbgrade = *zend;
  99.  
  100.   return zret;
  101. }
  102.