Utility.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * File: Utility.h $XConsortium: Utility.h /main/4 1995/10/26 15:31:55 rswiston $
  25. * Language: C
  26. *
  27. * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
  28. *
  29. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  30. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  31. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  32. * (c) Copyright 1993, 1994 Novell, Inc. *
  33. */
  34. #ifndef _Dt_Utility_h
  35. #define _Dt_Utility_h
  36. /******************************************************************************
  37. *
  38. * _DtVectorizeInPlace() takes a string which is made up a group of
  39. * components, separated by a common separator character, and breaks
  40. * the string up into the separate components. To reduce the amount of
  41. * memory used (and to reduce memory fragmentation), the string is simply
  42. * searched for each occurrence of the separator, and the separator is then
  43. * replaced by a NULL character. Pointers to the individual components are
  44. * returned as a NULL-terminated array of pointers.
  45. *
  46. * The passed-in string should be malloc'ed space, since the string will
  47. * eventually be freed when the application frees the returned array. If
  48. * you don't want the original string modified, then a copy should be made,
  49. * before calling this function.
  50. *
  51. * The application is responsible for freeing up this memory, and should do
  52. * so by calling _DtFreeStringVector().
  53. *
  54. * Parameters:
  55. *
  56. * string A NULL-terminated string, which is to be vectorized.
  57. *
  58. * separator The character which separates the components within
  59. * the string.
  60. *
  61. *****************************************************************************/
  62. extern char ** _DtVectorizeInPlace( char * string,
  63. char separator );
  64. /******************************************************************************
  65. *
  66. * _DtFreeStringVector will free up the vectorized string array returned by
  67. * a call to _DtVectorizeInPlace(). Both the array used to return the
  68. * vectorized strings, and the original string itself will be freed up.
  69. *
  70. * Parameters:
  71. *
  72. * stringVector The array to be freed; originally obtained by a call
  73. * to _DtVectorizeInPlace().
  74. *
  75. *****************************************************************************/
  76. extern void _DtFreeStringVector( char ** stringVector );
  77. /*****************************************************************************
  78. * DtCmd String Utility routines.
  79. *
  80. *****************************************************************************
  81. *
  82. * _DtCmdStringToArrayOfStrings - takes a string and an array of pointers
  83. * to strings and breaks the string into whitespace separated words.
  84. *
  85. * A "word" is a sequence of characters that has no whitespace with
  86. * the following exception:
  87. *
  88. * - A word may contain contain whitespace if it is delimited
  89. * by a pair of matching single or double qotes.
  90. *
  91. * "Whitespace" is a tab or blank character.
  92. *
  93. *
  94. * NOTES:
  95. *
  96. * - The space for the "words" is malloc'd and must be free'd by
  97. * the caller.
  98. * - _DtCmdFreeStringVector() should be used to free up string vectors
  99. * created by _DtCmdStringToArrayOfStrings().
  100. *
  101. * - "theArray" is NULL terminated.
  102. *
  103. * PARAMETERS:
  104. *
  105. * char theString[]; - The string to parse.
  106. *
  107. * char *theArray[]; - MODIFIED: gets filled with pointers to
  108. * the words that are parsed.
  109. *
  110. *****************************************************************************/
  111. /******************************************************************************
  112. *
  113. * _DtCmdFreeStringVector - takes an array of pointers to strings and
  114. * frees the malloc'd space for the strings.
  115. *
  116. * This does NOT free the string vector itself; It assumes that
  117. * stringv is a static i.e. char *stringv[N].
  118. *
  119. * PARAMETERS:
  120. *
  121. * char **stringv; - MODIFIED: Each string in the array is freed.
  122. *
  123. *****************************************************************************/
  124. extern void _DtCmdStringToArrayOfStrings(
  125. char theString[],
  126. char *theArray[]) ;
  127. extern void _DtCmdFreeStringVector(
  128. char **stringv) ;
  129. #endif /* _Dt_Utility_h */
  130. /* DON'T ADD ANYTHING AFTER THIS #endif */