PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/scotch_5.1.11/src/libscotch/common_string.c

#
C | 109 lines | 42 code | 14 blank | 53 comment | 7 complexity | 14870dde0f6c9b0fd87c2167fc9f40a0 MD5 | raw file
  1. /* Copyright 2010 ENSEIRB, INRIA & CNRS
  2. **
  3. ** This file is part of the Scotch software package for static mapping,
  4. ** graph partitioning and sparse matrix ordering.
  5. **
  6. ** This software is governed by the CeCILL-C license under French law
  7. ** and abiding by the rules of distribution of free software. You can
  8. ** use, modify and/or redistribute the software under the terms of the
  9. ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
  10. ** URL: "http://www.cecill.info".
  11. **
  12. ** As a counterpart to the access to the source code and rights to copy,
  13. ** modify and redistribute granted by the license, users are provided
  14. ** only with a limited warranty and the software's author, the holder of
  15. ** the economic rights, and the successive licensors have only limited
  16. ** liability.
  17. **
  18. ** In this respect, the user's attention is drawn to the risks associated
  19. ** with loading, using, modifying and/or developing or reproducing the
  20. ** software by the user in light of its specific status of free software,
  21. ** that may mean that it is complicated to manipulate, and that also
  22. ** therefore means that it is reserved for developers and experienced
  23. ** professionals having in-depth computer knowledge. Users are therefore
  24. ** encouraged to load and test the software's suitability as regards
  25. ** their requirements in conditions enabling the security of their
  26. ** systems and/or data to be ensured and, more generally, to use and
  27. ** operate it in the same conditions as regards security.
  28. **
  29. ** The fact that you are presently reading this means that you have had
  30. ** knowledge of the CeCILL-C license and that you accept its terms.
  31. */
  32. /************************************************************/
  33. /** **/
  34. /** NAME : common_string.c **/
  35. /** **/
  36. /** AUTHORS : Francois PELLEGRINI **/
  37. /** **/
  38. /** FUNCTION : Part of a parallel direct block solver. **/
  39. /** These lines are common routines used **/
  40. /** by all modules. **/
  41. /** **/
  42. /** DATES : # Version 5.1 : from : 23 jul 2010 **/
  43. /** to 23 jul 2010 **/
  44. /** **/
  45. /************************************************************/
  46. /*
  47. ** The defines and includes.
  48. */
  49. #define COMMON
  50. #ifndef COMMON_NOMODULE
  51. #include "module.h"
  52. #endif /* COMMON_NOMODULE */
  53. #include <time.h>
  54. #include "common.h"
  55. /********************************/
  56. /* */
  57. /* String substitution routine. */
  58. /* */
  59. /********************************/
  60. static
  61. void
  62. stringSubst2 (
  63. char * const bsrcptr,
  64. char * const bdstptr,
  65. const char * const pattstr,
  66. const char * const replstr,
  67. const int pattsiz,
  68. const int replsiz)
  69. {
  70. char * pattptr;
  71. int pattidx;
  72. pattptr = strstr (bsrcptr, pattstr); /* Search for the pattern in the remaining source string */
  73. pattidx = (pattptr == NULL) ? (strlen (bsrcptr) + 1): (pattptr - bsrcptr); /* Get length of unchanged part */
  74. if (replsiz < pattsiz) /* If replacement is smaller, pre-move unchanged part */
  75. memMov (bdstptr, bsrcptr, pattidx * sizeof (char));
  76. if (pattptr != NULL) /* If remaining part of string has to be processed */
  77. stringSubst2 (pattptr + pattsiz, bdstptr + pattidx + replsiz, pattstr, replstr, pattsiz, replsiz);
  78. if (replsiz > pattsiz) /* If replacement is longer, post-move unchanged part */
  79. memMov (bdstptr, bsrcptr, pattidx * sizeof (char));
  80. if (pattptr != NULL) /* If there is something to replace */
  81. memCpy (bdstptr + pattidx, replstr, replsiz * sizeof (char)); /* Write replacement string */
  82. return;
  83. }
  84. void
  85. stringSubst (
  86. char * const buffptr, /* String to search into */
  87. const char * const pattstr, /* Pattern to search for */
  88. const char * const replstr) /* Replacement string */
  89. {
  90. int pattsiz;
  91. int replsiz;
  92. pattsiz = strlen (pattstr);
  93. replsiz = strlen (replstr);
  94. stringSubst2 (buffptr, buffptr, pattstr, replstr, pattsiz, replsiz);
  95. }