home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / RULELINE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  64 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  RULER.C(PP) - A utility to create text ruler lines
  5. **
  6. **  R.F. Pels. Dec. 1993. Placed in public domain.
  7. */
  8.  
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include "snip_str.h"
  12.  
  13. #if defined(__cplusplus) && __cplusplus
  14.  extern "C" {
  15. #endif
  16.  
  17. char * rule_line(char * s,
  18.                  unsigned short len,
  19.                  short units,
  20.                  char * digits,
  21.                  char filler)
  22. {
  23.       /*  If possible, initialize directly with correct value!    */
  24.       short           whichdigit = 0;
  25.       short           digitlen = strlen(digits);
  26.       unsigned short  i;
  27.  
  28.       memset(s, filler, len);             /*  Fill string with all filler   */
  29.       s[len]  = NUL;                      /*  Tack on an ASCIIZ             */
  30.  
  31.       for (i = 0; i < len; i += units)
  32.       {
  33.             s[i] = digits[whichdigit];    /*  Put in digit                  */
  34.             whichdigit++;                 /*  Add 1 and reset to 0 if...    */
  35.             whichdigit %= digitlen;       /* ...bigger than length of digits*/
  36.       }
  37.       return s;
  38. }
  39.  
  40. #if defined(__cplusplus) && __cplusplus
  41.  }
  42. #endif
  43.  
  44. #ifdef TEST
  45.  
  46. char text[41] = "abcdefghijabcdefhijkabcdefghijabcdefghij", ruler[41];
  47.  
  48. main(void)
  49. {
  50.       puts(text);
  51.       printf("%s\n\n", rule_line(ruler, 40,   1, "123", ' '));
  52.       puts(text);
  53.       printf("%s\n\n", rule_line(ruler, 40,   1, "12345", ' '));
  54.       puts(text);
  55.       printf("%s\n\n", rule_line(ruler, 40,   1, "1234567890", ' '));
  56.       puts(text);
  57.       printf("%s\n\n", rule_line(ruler, 40,   5, "0123456789", ' '));
  58.       puts(text);
  59.       printf("%s\n\n", rule_line(ruler, 40,  10, "1234567890", ' '));
  60.       return 0;
  61. }
  62.  
  63. #endif /* TEST */
  64.