home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / ST_JUST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  1.2 KB  |  79 lines

  1. /*********************
  2.  *
  3.  *  st_just.c - string justification routines.
  4.  *
  5.  *  Purpose: This file contains functions to justify and center strings.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include <string.h>
  13. #include "blackstr.h"
  14. #include "kb_head.h"
  15.  
  16.  
  17. /********
  18.  *
  19.  *   st_movr(str,n) - move string n bytes to right
  20.  *
  21.  **/
  22.  
  23. void st_movr(char *str, int n)
  24. {
  25.     int i,l;
  26.  
  27.     l = strlen(str);            /* end */
  28.     for(i=0; i<=l; ++i)
  29.     str[l+n-i] = str[l-i];
  30.     for(i=0; i<n; ++i)
  31.     str[i] = BLANK;         /* blank fill */
  32. }
  33.  
  34.  
  35. /********
  36.  *
  37.  *   st_movl(str,n) - move string n bytes to left
  38.  *
  39.  **/
  40.  
  41. void st_movl(char *str, int n)
  42. {
  43.     int i,l;
  44.  
  45.     l = strlen(str)-n;      /* end */
  46.     for(i=0; i<=l; ++i) {
  47.     str[i] = str[i+n];
  48.     }
  49. }
  50.  
  51.  
  52. /********
  53.  *
  54.  *   st_jusr(str,n) - justify sting right in n byte field
  55.  *
  56.  **/
  57.  
  58. void st_jusr(char *str, int n)
  59. {
  60.     st_movr(str,(n - strlen(str)));
  61. }
  62.  
  63.  
  64. /********
  65.  *
  66.  *   st_cntr(str,n) - center string in n byte field
  67.  *
  68.  **/
  69.  
  70. void st_cntr(char *str, int n)
  71. {
  72.     int i;
  73.  
  74.     i = (n- strlen(str))/2;
  75.     st_movr(str,i);
  76.     while(i--)
  77.     strcat(str," ");
  78. }
  79.