home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / inc-dec / source / lib / str_utl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-21  |  1.8 KB  |  129 lines  |  [TEXT/KAHL]

  1. /* ==========================================
  2.  
  3.     str_utl.c    
  4.  
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.         
  13.    ========================================== */
  14.  
  15. #include "str_utl.proto.h"
  16.  
  17. /* ========================================== */
  18.  
  19. void pStrFromC( StringPtr dst, char *src )
  20. {
  21.     int     count = 0;
  22.     char c;
  23.         
  24.     while (c = *src++)
  25.         dst[++count] = c;
  26.         
  27.     dst[0] = count;
  28. }
  29.  
  30. void pStrCopy( StringPtr dst, StringPtr src )
  31. {
  32.     int len;
  33.     
  34.     len = *dst++ = *src++;
  35.     
  36.     while (--len>=0)
  37.         *dst++=*src++;
  38. }
  39.  
  40. void pStrAppend( StringPtr dst, StringPtr new )
  41. {
  42.     int    old, add, i;
  43.     
  44.     old = dst[0];
  45.     
  46.     if (add = new[0])
  47.         if ((old + add) < 256) {
  48.             for (i = 1; i <= add; i++) dst[old+i] = new[i];
  49.             dst[0] = old + add;
  50.             }
  51. }
  52.  
  53. void pStrAppendC( StringPtr dst, char *src )
  54. {
  55.     int     count;
  56.     char c;
  57.     
  58.     count = dst[0];
  59.     
  60.     while (c = *src++) dst[++count] = c;
  61.         
  62.     if (count < 256)
  63.         dst[0] = count;
  64. }
  65.  
  66. int pStrEqual( StringPtr one, StringPtr two )
  67. {
  68.     int len;
  69.     
  70.     len = one[0];
  71.     
  72.     if (len != two[0])
  73.         return( 0 );
  74.         
  75.     while (len) {
  76.         if ( one[len] != two[len] )
  77.             return(0);
  78.         len--;
  79.         }
  80.         
  81.     return(1);
  82. }
  83.  
  84. /* ========================================== */
  85.  
  86. int    cStrEqual( char *p, char *q )
  87. {
  88.     char c;
  89.     
  90.     do {
  91.         c = *p++;
  92.         if (c!=*q++) return(0);
  93.     } while ( c != 0 );
  94.             
  95.     return(1);
  96. }
  97.  
  98. int    cStrLen( char *p )
  99. {
  100.     int    len;
  101.     
  102.     len = 0;
  103.     
  104.     while ( *p++ ) len++;
  105.             
  106.     return( len );
  107. }
  108.  
  109. void cStrFromNum( char *p, int width, int num )
  110. {
  111.     int        i,j;
  112.     Str32    string;
  113.     
  114.     NumToString( num, string );
  115.     
  116.     j = string[0];
  117.     
  118.     if ( j > width )
  119.         for ( i = 0 ; i < width ; i++ )        // not enough room
  120.             p[i] = '*';
  121.         
  122.     i = width;
  123.     
  124.     while ( i )
  125.         if ( j )
  126.             p[--i] = string[j--];            // right justify
  127.         else
  128.             p[--i] = ' ';
  129. }