home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / desklib / !DeskLib / h_doc / Str < prev    next >
Encoding:
Text File  |  1996-12-10  |  5.7 KB  |  190 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Str.h
  12.     Author:  Copyright © 1992, 1993, 1994, 1995 Jason Williams, Jason Howat, 
  13.                                                 Julian Smith
  14.     Version: 1.12 (17 May 1993)
  15.     Purpose: Useful string functions not provided by ANSI, including functions
  16.                to deal with CR-terminated strings, as used by the RISC OS Wimp.
  17.     Mods:
  18.              28 Sep 1995 JS Added strncpy0.
  19.              17 Apr 1996 JS Removed duplicate declaration of stricmp.
  20.              09 Dec 1996 JS Added Desk_Str_strdupcr().
  21.  
  22. */
  23.  
  24. #ifndef __Desk_Str_h
  25. #define __Desk_Str_h
  26.  
  27. #ifdef __cplusplus
  28.     extern "C" {
  29. #endif
  30.  
  31. /* We need size_t from stddef.h */
  32. #include <stddef.h>
  33.  
  34.  
  35. extern int Desk_strlencr(const char *s);
  36.   /*  strlencr() == strlen()
  37.    *  NOTE **** With release 2 of DeskLib this has been changed to return
  38.    *  the length of the string EXCLUDING the terminator (i.e. it now returns
  39.    *  1 less than it used to in Desklib 1)
  40.    */
  41.  
  42. extern int Desk_strcmpcr(const char *s1, const char *s2);
  43.   /*  strcmpcr() == strcmp)
  44.    *  Returns 0 if the strings match
  45.    *  Returns -1 if s1 < s2  (alphabetically less than, and/or shorter)
  46.    *  Returns +1 if s1 > s2  (alphabetcally greater than, and/or longer)
  47.    */
  48.  
  49.  
  50. extern char *Desk_strcatcr(char *s1, const char *s2);
  51.   /*  strcatcr() == strcat
  52.    *  Concatenates s2 onto the end of s1. Returns s1.
  53.    *  The returned string will be zero terminated.
  54.    */
  55.  
  56.  
  57. extern char *Desk_strcpycr(char *s1, const char *s2);
  58.   /*  strcpycr() == strcpy
  59.    *  Copies s2 into s1. Returns s1.
  60.    *  The returned string will be zero terminated.
  61.    */
  62.  
  63.  
  64. extern char *Desk_strncpycr(char *s1, const char *s2, int n);
  65.   /*  strncpycr() == strncpy
  66.    *  Copies at most n chars of s2 into s1. Returns s1.
  67.    *  NOTE that this will NOT terminate the string if s2 is longer than 'n'
  68.    *  characters in length. If it is shorter, s1 will be zero-terminated.
  69.    */
  70.  
  71.  
  72. extern char *Desk_Str_LeafName(const char *path);
  73.   /*  LeafName()
  74.    *  Return a pointer to the leaf of 'FullPath'.
  75.    *  Note that this pointer is within the 'FullPath' string.
  76.    *  If no '.' is encountered in FullPath, then the pointer FullPath
  77.    *  is returned
  78.    */
  79.  
  80. #define Desk_LeafName Desk_Str_LeafName
  81.  
  82.  
  83.  
  84. extern int Desk_stricmp(const char *s1, const char *s2);
  85. /*
  86. Purpose:  As ANSI strcmp() function, but case insensitive.
  87. */
  88.  
  89.  
  90. extern int Desk_strnicmp(const char *s1, const char *s2, size_t n);
  91. /*
  92.     Purpose:  As ANSI strncmp() function, but case insensitive.
  93. */
  94.  
  95.  
  96. extern int Desk_stricmpcr(const char *s1, const char *s2);
  97. /*
  98. As stricmp() except works on CR-terminated strings.
  99. */
  100.  
  101. extern int Desk_strnicmpcr(const char *s1, const char *s2, size_t n);
  102. /*
  103. Purpose:  As strnicmp() function, but works on CR-terminated strings.
  104. */
  105.  
  106.  
  107. extern char *Desk_strdup( const char *s);
  108. /*
  109.     Inputs:   s - the string to copy
  110.     Returns:  Address of new string, or NULL if out of memory.
  111.     Purpose:  Allocate memory for a copy of the string using Desk_DeskMem_XMalloc, 
  112.               and copy the string into this memory.
  113. */
  114.  
  115.  
  116. extern void Desk_Str_MakeCR(char *s, int Desk_max_len);
  117. /*
  118.     Inputs:   s - pointer to the string to change to a CR-terminated string.
  119.                 Desk_max_len - the number of characters to look for the null
  120.                               terminator in before giving up (in which case it is
  121.                               terminated at the Desk_max_len'th character).
  122.     Purpose:  Converts a 0-terminated (ASCIIZ) string into a CR-terminated
  123.                 string.
  124.     SeeAlso:  Desk_Str_MakeASCIIZ()
  125. */
  126.  
  127.  
  128. extern void Desk_Str_MakeASCIIZ(char *s, int Desk_max_len);
  129. /*
  130.     void Desk_Str_MakeASCIIZ(char *s, int Desk_max_len);
  131.  
  132.     Inputs:   s - pointer to the string to change to a 0-terminated string.
  133.                 Desk_max_len - the number of characters to look for the null
  134.                               terminator in before giving up (in which case it is
  135.                               terminated at the Desk_max_len'th character).
  136.     Purpose:  Converts a CR (or any other ctrl character)-terminated string
  137.               into a 0-terminated (ASCIIZ) string.
  138.     SeeAlso:  Desk_Str_MakeCR()
  139. */
  140.  
  141.  
  142. extern char Desk_Str_MakeHex(int n);
  143. /*
  144.     char Desk_Str_MakeHex(int n);
  145.  
  146.     Inputs:   n - the digit to convert to hexadecimal (n should be in the
  147.                       range 0-15).
  148.     Returns:  The character representing the digit; '0'..'9', 'A'..'Z'.
  149.     Purpose:  Converts an integer in the range 0 to 15 to a character that
  150.                 represents it in hexadecimal.
  151.                 If n is outside the range, '?' is returned.
  152.     SeeAlso:  Desk_Str_DecodeHex()
  153. */
  154.  
  155.  
  156. extern int Desk_Str_DecodeHex(char digit);
  157. /*
  158.     int Desk_Str_DecodeHex(char digit);
  159.  
  160.     Inputs:   digit - character representing the hex digit to convert.
  161.     Returns:  The integer value of 'digit', or -1 for error.
  162.     Purpose:  Convert a hexadecimal digit of the form '0'..'9', 'A'..'Z'
  163.                 into an integer.
  164.                 If the character is not a legal hexadecimal digit, -1 is
  165.                 returned.
  166.     SeeAlso:  HexDigit()
  167. */
  168.  
  169.  
  170. extern char *Desk_Str_StrNCpy0( char *s1, const char *s2, int n);
  171. /*
  172. As strncpy, but sets s1[n]=0 .
  173.  */
  174.  
  175. #define    Desk_strncpy0( s1, s2, n)    Desk_Str_StrNCpy0( s1, s2, n)
  176.  
  177.  
  178. char*    Desk_Str_strdupcr( const char* s);
  179. /*
  180. Duplicates the specified ctrl-terminated string. Output string is 0
  181. terminated.
  182.  */
  183.  
  184.  
  185. #ifdef __cplusplus
  186. }
  187. #endif
  188.  
  189. #endif
  190.