home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / strscale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-19  |  1.5 KB  |  80 lines

  1. #ifndef NO_IDENT
  2. static    char    *Id = "$Id: strscale.c,v 1.3 1995/02/19 18:20:55 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    strscale.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    06 Jun 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototypes
  11.  *
  12.  * Function:    This procedure creates a column-scale, with numbers for use in
  13.  *        editors, etc.  For example, if the initial column is 1, then
  14.  *        a scale such as the following might be returned:
  15.  *
  16.  *        "....+...10....+...20....+...30"
  17.  *
  18.  *        If the starting column is not 1, the procedure properly starts
  19.  *        on the substring of the global scale.
  20.  *
  21.  * Parameters:    co_    => output buffer
  22.  *        col    =  beginning column number
  23.  *        len    =  length of output buffer
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. #include "strutils.h"
  30.  
  31. static    char    ten[] = "....+....|";
  32.  
  33. void
  34. strscale (
  35.     char    *co_,
  36.     int    col,
  37.     int    len)
  38. {
  39.     int    first    = 1,        /* flag for leading 0's column    */
  40.         numlen;
  41.     char    number[20],
  42.         catbfr[20];
  43.  
  44.     if (col < 1)    col = 1;
  45.     *co_ = '\0';
  46.  
  47.     while (len > 0)
  48.     {
  49.         int    base10    = (col / 10) * 10,
  50.             next10    = base10 + 10,
  51.             units    = col - base10;
  52.         char    *s_    = catbfr;
  53.  
  54.         sprintf (number, "%d", next10);
  55.         numlen    = strlen (number);
  56.         if (units)
  57.         {
  58.             strcpy (catbfr, &ten[units-1]);
  59.             units = strlen (catbfr);
  60.             if (units > numlen + 2)
  61.                 strcpy (&catbfr[units-numlen], number);
  62.         }
  63.         else
  64.         {
  65.             if (first)
  66.                 *co_++ = '|', *co_ = '\0', len--;
  67.             strcpy (catbfr, ten);
  68.             strcpy (&catbfr[10-numlen], number);
  69.         }
  70.         while (*s_ && len > 0)
  71.         {
  72.             *co_++ = *s_++;
  73.             *co_   = '\0';
  74.             len--;
  75.         }
  76.         col    = next10;
  77.         first    = 0;
  78.     }
  79. }
  80.