lib_str.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. *********************************************************************************************************
  3. * uC/LIB
  4. * CUSTOM LIBRARY MODULES
  5. *
  6. * (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
  7. *
  8. * All rights reserved. Protected by international copyright laws.
  9. *
  10. * uC/LIB is provided in source form to registered licensees ONLY. It is
  11. * illegal to distribute this source code to any third party unless you receive
  12. * written permission by an authorized Micrium representative. Knowledge of
  13. * the source code may NOT be used to develop a similar product.
  14. *
  15. * Please help us continue to provide the Embedded community with the finest
  16. * software available. Your honesty is greatly appreciated.
  17. *
  18. * You can contact us at www.micrium.com.
  19. *********************************************************************************************************
  20. */
  21. /*
  22. *********************************************************************************************************
  23. *
  24. * ASCII STRING MANAGEMENT
  25. *
  26. * Filename : lib_str.h
  27. * Version : V1.35.00
  28. * Programmer(s) : ITJ
  29. * JDH
  30. *********************************************************************************************************
  31. * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
  32. *
  33. * (a) ALL standard library functions are implemented in the custom library modules :
  34. *
  35. * (1) \<Custom Library Directory>\lib_*.*
  36. *
  37. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  38. *
  39. * where
  40. * <Custom Library Directory> directory path for custom library software
  41. * <cpu> directory name for specific processor (CPU)
  42. * <compiler> directory name for specific compiler
  43. *
  44. * (b) Product-specific library functions are implemented in individual products.
  45. *********************************************************************************************************
  46. */
  47. /*
  48. *********************************************************************************************************
  49. * MODULE
  50. *
  51. * Note(s) : (1) This string library header file is protected from multiple pre-processor inclusion through
  52. * use of the string library module present pre-processor macro definition.
  53. *********************************************************************************************************
  54. */
  55. #ifndef LIB_STR_MODULE_PRESENT /* See Note #1. */
  56. #define LIB_STR_MODULE_PRESENT
  57. /*$PAGE*/
  58. /*
  59. *********************************************************************************************************
  60. * ASCII STRING CONFIGURATION DEFINES
  61. *
  62. * Note(s) : (1) Some ASCII string configuration #define's MUST be available PRIOR to including any
  63. * application configuration (see 'INCLUDE FILES Note #1a').
  64. *********************************************************************************************************
  65. */
  66. /*
  67. *********************************************************************************************************
  68. * STRING FLOATING POINT DEFINES
  69. *
  70. * Note(s) : (1) (a) (1) The maximum accuracy for 32-bit floating-point numbers :
  71. *
  72. *
  73. * Maximum Accuracy log [Internal-Base ^ (Number-Internal-Base-Digits)]
  74. * 32-bit Floating-point Number = -----------------------------------------------------
  75. * log [External-Base]
  76. *
  77. * log [2 ^ 24]
  78. * = --------------
  79. * log [10]
  80. *
  81. * < 7.225 Base-10 Digits
  82. *
  83. * where
  84. * Internal-Base Internal number base of floating-
  85. * point numbers (i.e. 2)
  86. * External-Base External number base of floating-
  87. * point numbers (i.e. 10)
  88. * Number-Internal-Base-Digits Number of internal number base
  89. * significant digits (i.e. 24)
  90. *
  91. * (2) Also, since some 32-bit floating-point calculations are converted to 32-bit
  92. * unsigned numbers, the maximum accuracy is limited to the maximum accuracy
  93. * for 32-bit unsigned numbers of 9 digits.
  94. *
  95. * (b) Some CPUs' &/or compilers' floating-point implementations MAY further reduce the
  96. * maximum accuracy.
  97. *********************************************************************************************************
  98. */
  99. #define LIB_STR_FP_MAX_NBR_DIG_SIG_MIN 1u
  100. #define LIB_STR_FP_MAX_NBR_DIG_SIG_MAX 9u /* See Note #1a2. */
  101. #define LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT 7u /* See Note #1a1. */
  102. /*$PAGE*/
  103. /*
  104. *********************************************************************************************************
  105. * INCLUDE FILES
  106. *
  107. * Note(s) : (1) The custom library software files are located in the following directories :
  108. *
  109. * (a) \<Your Product Application>\app_cfg.h
  110. *
  111. * (b) \<Custom Library Directory>\lib_*.*
  112. *
  113. * where
  114. * <Your Product Application> directory path for Your Product's Application
  115. * <Custom Library Directory> directory path for custom library software
  116. *
  117. * (2) CPU-configuration software files are located in the following directories :
  118. *
  119. * (a) \<CPU-Compiler Directory>\cpu_*.*
  120. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  121. *
  122. * where
  123. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  124. * <cpu> directory name for specific processor (CPU)
  125. * <compiler> directory name for specific compiler
  126. *
  127. * (3) Compiler MUST be configured to include as additional include path directories :
  128. *
  129. * (a) '\<Your Product Application>\' directory See Note #1a
  130. *
  131. * (b) '\<Custom Library Directory>\' directory See Note #1b
  132. *
  133. * (c) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  134. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  135. *
  136. * (4) NO compiler-supplied standard library functions SHOULD be used.
  137. *
  138. * #### The reference to standard library header files SHOULD be removed once all custom
  139. * library functions are implemented WITHOUT reference to ANY standard library function(s).
  140. *
  141. * See also 'STANDARD LIBRARY MACRO'S Note #1'.
  142. *********************************************************************************************************
  143. */
  144. #include <cpu.h>
  145. #include <lib_def.h>
  146. #include <lib_ascii.h>
  147. #include <app_cfg.h>
  148. #if 0 /* See Note #4. */
  149. #include <stdio.h>
  150. #endif
  151. /*
  152. *********************************************************************************************************
  153. * EXTERNS
  154. *********************************************************************************************************
  155. */
  156. #ifdef LIB_STR_MODULE
  157. #define LIB_STR_EXT
  158. #else
  159. #define LIB_STR_EXT extern
  160. #endif
  161. /*$PAGE*/
  162. /*
  163. *********************************************************************************************************
  164. * DEFAULT CONFIGURATION
  165. *********************************************************************************************************
  166. */
  167. /*
  168. *********************************************************************************************************
  169. * STRING FLOATING POINT CONFIGURATION
  170. *
  171. * Note(s) : (1) Configure LIB_STR_CFG_FP_EN to enable/disable floating point string function(s).
  172. *
  173. * (2) Configure LIB_STR_CFG_FP_MAX_NBR_DIG_SIG to configure the maximum number of significant
  174. * digits to calculate &/or display for floating point string function(s).
  175. *
  176. * See also 'STRING FLOATING POINT DEFINES Note #1'.
  177. *********************************************************************************************************
  178. */
  179. /* Configure floating point feature(s) [see Note #1] : */
  180. #ifndef LIB_STR_CFG_FP_EN
  181. #define LIB_STR_CFG_FP_EN DEF_DISABLED
  182. /* DEF_DISABLED Floating point functions DISABLED */
  183. /* DEF_ENABLED Floating point functions ENABLED */
  184. #endif
  185. /* Configure floating point feature(s)' number of ... */
  186. /* ... significant digits (see Note #2). */
  187. #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
  188. #define LIB_STR_CFG_FP_MAX_NBR_DIG_SIG LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT
  189. #endif
  190. /*
  191. *********************************************************************************************************
  192. * DEFINES
  193. *********************************************************************************************************
  194. */
  195. /*
  196. *********************************************************************************************************
  197. * DATA TYPES
  198. *********************************************************************************************************
  199. */
  200. /*
  201. *********************************************************************************************************
  202. * GLOBAL VARIABLES
  203. *********************************************************************************************************
  204. */
  205. /*$PAGE*/
  206. /*
  207. *********************************************************************************************************
  208. * MACRO'S
  209. *********************************************************************************************************
  210. */
  211. /*
  212. *********************************************************************************************************
  213. * STANDARD LIBRARY MACRO'S
  214. *
  215. * Note(s) : (1) NO compiler-supplied standard library functions SHOULD be used.
  216. *
  217. * #### The reference to standard memory functions SHOULD be removed once all custom library
  218. * functions are implemented WITHOUT reference to ANY standard library function(s).
  219. *
  220. * See also 'INCLUDE FILES Note #3'.
  221. *********************************************************************************************************
  222. */
  223. /* See Note #1. */
  224. #define Str_FmtPrint snprintf
  225. #define Str_FmtScan sscanf
  226. /*$PAGE*/
  227. /*
  228. *********************************************************************************************************
  229. * FUNCTION PROTOTYPES
  230. *********************************************************************************************************
  231. */
  232. /* ------------------ STR LEN FNCTS ------------------ */
  233. CPU_SIZE_T Str_Len (const CPU_CHAR *pstr);
  234. CPU_SIZE_T Str_Len_N (const CPU_CHAR *pstr,
  235. CPU_SIZE_T len_max);
  236. /* ------------------ STR COPY FNCTS ------------------ */
  237. CPU_CHAR *Str_Copy ( CPU_CHAR *pstr_dest,
  238. const CPU_CHAR *pstr_src);
  239. CPU_CHAR *Str_Copy_N ( CPU_CHAR *pstr_dest,
  240. const CPU_CHAR *pstr_src,
  241. CPU_SIZE_T len_max);
  242. CPU_CHAR *Str_Cat ( CPU_CHAR *pstr_dest,
  243. const CPU_CHAR *pstr_cat);
  244. CPU_CHAR *Str_Cat_N ( CPU_CHAR *pstr_dest,
  245. const CPU_CHAR *pstr_cat,
  246. CPU_SIZE_T len_max);
  247. /* ------------------ STR CMP FNCTS ------------------ */
  248. CPU_INT16S Str_Cmp (const CPU_CHAR *p1_str,
  249. const CPU_CHAR *p2_str);
  250. CPU_INT16S Str_Cmp_N (const CPU_CHAR *p1_str,
  251. const CPU_CHAR *p2_str,
  252. CPU_SIZE_T len_max);
  253. CPU_INT16S Str_CmpIgnoreCase (const CPU_CHAR *p1_str,
  254. const CPU_CHAR *p2_str);
  255. CPU_INT16S Str_CmpIgnoreCase_N(const CPU_CHAR *p1_str,
  256. const CPU_CHAR *p2_str,
  257. CPU_SIZE_T len_max);
  258. /* ------------------ STR SRCH FNCTS ------------------ */
  259. CPU_CHAR *Str_Char (const CPU_CHAR *pstr,
  260. CPU_CHAR srch_char);
  261. CPU_CHAR *Str_Char_N (const CPU_CHAR *pstr,
  262. CPU_SIZE_T len_max,
  263. CPU_CHAR srch_char);
  264. CPU_CHAR *Str_Char_Last (const CPU_CHAR *pstr,
  265. CPU_CHAR srch_char);
  266. CPU_CHAR *Str_Char_Last_N (const CPU_CHAR *pstr,
  267. CPU_SIZE_T len_max,
  268. CPU_CHAR srch_char);
  269. CPU_CHAR *Str_Str (const CPU_CHAR *pstr,
  270. const CPU_CHAR *pstr_srch);
  271. CPU_CHAR *Str_Str_N (const CPU_CHAR *pstr,
  272. const CPU_CHAR *pstr_srch,
  273. CPU_SIZE_T len_max);
  274. /*$PAGE*/
  275. /* ------------------ STR FMT FNCTS ------------------ */
  276. CPU_CHAR *Str_FmtNbr_Int32U ( CPU_INT32U nbr,
  277. CPU_INT08U nbr_dig,
  278. CPU_INT08U nbr_base,
  279. CPU_CHAR lead_char,
  280. CPU_BOOLEAN lower_case,
  281. CPU_BOOLEAN nul,
  282. CPU_CHAR *pstr);
  283. CPU_CHAR *Str_FmtNbr_Int32S ( CPU_INT32S nbr,
  284. CPU_INT08U nbr_dig,
  285. CPU_INT08U nbr_base,
  286. CPU_CHAR lead_char,
  287. CPU_BOOLEAN lower_case,
  288. CPU_BOOLEAN nul,
  289. CPU_CHAR *pstr);
  290. #if (LIB_STR_CFG_FP_EN == DEF_ENABLED)
  291. CPU_CHAR *Str_FmtNbr_32 ( CPU_FP32 nbr,
  292. CPU_INT08U nbr_dig,
  293. CPU_INT08U nbr_dp,
  294. CPU_CHAR lead_char,
  295. CPU_BOOLEAN nul,
  296. CPU_CHAR *pstr);
  297. #endif
  298. /* ----------------- STR PARSE FNCTS ------------------ */
  299. CPU_INT32U Str_ParseNbr_Int32U(const CPU_CHAR *pstr,
  300. CPU_CHAR **pstr_next,
  301. CPU_INT08U nbr_base);
  302. CPU_INT32S Str_ParseNbr_Int32S(const CPU_CHAR *pstr,
  303. CPU_CHAR **pstr_next,
  304. CPU_INT08U nbr_base);
  305. /*$PAGE*/
  306. /*
  307. *********************************************************************************************************
  308. * CONFIGURATION ERRORS
  309. *********************************************************************************************************
  310. */
  311. #ifndef LIB_STR_CFG_FP_EN
  312. #error "LIB_STR_CFG_FP_EN not #define'd in 'app_cfg.h'"
  313. #error " [MUST be DEF_DISABLED] "
  314. #error " [ || DEF_ENABLED ] "
  315. #elif ((LIB_STR_CFG_FP_EN != DEF_DISABLED) && \
  316. (LIB_STR_CFG_FP_EN != DEF_ENABLED ))
  317. #error "LIB_STR_CFG_FP_EN illegally #define'd in 'app_cfg.h'"
  318. #error " [MUST be DEF_DISABLED] "
  319. #error " [ || DEF_ENABLED ] "
  320. #elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
  321. #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
  322. #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG not #define'd in 'app_cfg.h' "
  323. #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
  324. #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
  325. #elif (DEF_CHK_VAL(LIB_STR_CFG_FP_MAX_NBR_DIG_SIG, \
  326. LIB_STR_FP_MAX_NBR_DIG_SIG_MIN, \
  327. LIB_STR_FP_MAX_NBR_DIG_SIG_MAX) != DEF_OK)
  328. #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG illegally #define'd in 'app_cfg.h' "
  329. #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
  330. #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
  331. #endif
  332. #endif
  333. /*
  334. *********************************************************************************************************
  335. * MODULE END
  336. *********************************************************************************************************
  337. */
  338. #endif /* End of lib str module include. */