home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XS.ZIP / LIB / GETSEQ.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  4KB  |  112 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    g e t s e q . c                                                 */
  3. /*                                                                    */
  4. /*    Job sequence number routines for UUPC/extended                  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*                          RCS Information                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Header: E:\SRC\UUPC\LIB\RCS\GETSEQ.C 1.2 1992/11/19 02:58:00 ahd Exp $
  13.  *
  14.  *    Revision history:
  15.  *    $Log: GETSEQ.C $
  16.  * Revision 1.2  1992/11/19  02:58:00  ahd
  17.  * drop rcsid
  18.  *
  19.  * Revision 1.1  1992/11/16  05:00:26  ahd
  20.  * Initial revision
  21.  *
  22.  */
  23.  
  24.  
  25. /*--------------------------------------------------------------------*/
  26. /*                        System include files                        */
  27. /*--------------------------------------------------------------------*/
  28.  
  29. #include <stdio.h>
  30.  
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                    UUPC/extended include files                     */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. #include "lib.h"
  37. #include "hlib.h"
  38. #include "getseq.h"
  39.  
  40. currentfile();
  41.  
  42. /*--------------------------------------------------------------------*/
  43. /*    g e t s e q                                                     */
  44. /*                                                                    */
  45. /*    Return next available sequence number for UUPC processing       */
  46. /*--------------------------------------------------------------------*/
  47.  
  48. long getseq()
  49. {
  50.    char seqfile[FILENAME_MAX];
  51.    FILE *seqfile_fp;
  52.    long seq;
  53.  
  54.    mkfilename(seqfile, E_confdir, SFILENAME);
  55.    printmsg(4, "getseq: opening %s", seqfile);
  56.    if ((seqfile_fp = FOPEN(seqfile, "r", TEXT)) != nil(FILE)) {
  57.       fscanf(seqfile_fp, "%ld", &seq);
  58.       fclose(seqfile_fp);
  59.    } else {
  60.       printmsg(0, "getseq: can't find %s, creating", seqfile);
  61.       seq = 1;
  62.    };
  63.  
  64. /*--------------------------------------------------------------------*/
  65. /*                       Update sequence number                       */
  66. /*--------------------------------------------------------------------*/
  67.  
  68.    printmsg(5, "getseq: seq#=%ld", seq);
  69.  
  70.    if ((seqfile_fp = FOPEN(seqfile, "w", TEXT)) != nil(FILE))
  71.    {
  72.       fprintf(seqfile_fp, "%ld\n", seq+1);
  73.       fclose(seqfile_fp);
  74.    }
  75.    else {
  76.       printerr( seqfile );
  77.       panic();
  78.    }
  79.  
  80.    return seq;
  81.  
  82. } /*getseq*/
  83.  
  84. /*--------------------------------------------------------------------*/
  85. /*    J o b N u m b e r                                               */
  86. /*                                                                    */
  87. /*    Given a job sequence number, returns a character string for use */
  88. /*    in file names                                                   */
  89. /*--------------------------------------------------------------------*/
  90.  
  91. char *JobNumber( long sequence )
  92. {
  93.       static char buf[4];
  94.       const long base = bflag[F_ONECASE] ? 36 : 62;
  95.       static const char set[] =
  96.          "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  97.       size_t count = sizeof buf - 1;
  98.  
  99.       buf[count] = '\0';
  100.  
  101.       sequence %= (base*base*base);
  102.  
  103.       while( count-- > 0 )
  104.       {
  105.          buf[count] = set[ (int) (sequence % base) ];
  106.          sequence /= base ;
  107.       } /* while */
  108.  
  109.       return buf;
  110.  
  111. } /* JobNumber */
  112.