objnames.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # ***************************************************************************
  2. # * _ _ ____ _
  3. # * Project ___| | | | _ \| |
  4. # * / __| | | | |_) | |
  5. # * | (__| |_| | _ <| |___
  6. # * \___|\___/|_| \_\_____|
  7. # *
  8. # * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. # *
  10. # * This software is licensed as described in the file COPYING, which
  11. # * you should have received as part of this distribution. The terms
  12. # * are also available at https://curl.haxx.se/docs/copyright.html.
  13. # *
  14. # * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # * copies of the Software, and permit persons to whom the Software is
  16. # * furnished to do so, under the terms of the COPYING file.
  17. # *
  18. # * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # * KIND, either express or implied.
  20. # *
  21. # ***************************************************************************
  22. #
  23. # This file is sourced from curl/packages/OS400/initscript.sh and
  24. # other Bourne shell scripts. Keep it as portable as possible.
  25. #
  26. #
  27. # curl_10char_object_name
  28. #
  29. # This shell function accepts a single string argument with unspecified
  30. # length representing a (*.c) source file name and returns a string which
  31. # is a transformation of given argument.
  32. #
  33. # The intended purpose of this function is to transliterate a (*.c) source
  34. # file name that may be longer than 10 characters, or not, into a string
  35. # with at most 10 characters which may be used as an OS/400 object name.
  36. #
  37. # This function might not be universally useful, nor we care about it.
  38. #
  39. # It is intended to be used with libcurl's (*.c) source file names, so
  40. # dependency on libcurl's source file naming scheme is acceptable and
  41. # good enough for its intended use. Specifically it makes use of the fact
  42. # that libcurl's (*.c) source file names which may be longer than 10 chars
  43. # are conformed with underscore '_' separated substrings, or separated by
  44. # other character which does not belong to the [0-9], [a-z] or [A-Z] sets.
  45. #
  46. # This allows repeatable and automatic short object name generation with
  47. # no need for a hardcoded mapping table.
  48. #
  49. # Transformation is done in the following way:
  50. #
  51. # 1) Leading directory components are removed.
  52. # 2) Leftmost dot character and any other char following it are removed.
  53. # 3) Lowercase characters are transliterated to uppercase.
  54. # 4) Characters not in [A-Z] or [0-9] are transliterated to underscore '_'.
  55. # 5) Every sequence of one or more underscores is replaced with a single one.
  56. # 6) Five leftmost substrings which end in an underscore character are
  57. # replaced by the first character of each substring, while retaining
  58. # the rest of the string.
  59. # 7) Finally the result is truncated to 10 characters.
  60. #
  61. # Resulting object name may be shorter than 10 characters.
  62. #
  63. # Test case 1221 does unit testng of this function and also verifies
  64. # that it is possible to generate distinct short object names for all
  65. # curl and libcurl *.c source file names.
  66. #
  67. curl_10char_object_name() {
  68. echo "${1}" | \
  69. sed -e 's:.*/::' \
  70. -e 's:[.].*::' \
  71. -e 'y:abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:' \
  72. -e 's:[^ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_]:_:g' \
  73. -e 's:__*:_:g' \
  74. -e 's:\([^_]\)[^_]*_\(.*\):\1\2:' \
  75. -e 's:\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3:' \
  76. -e 's:\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4:' \
  77. -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5:' \
  78. -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5\6:' \
  79. -e 's:^\(..........\).*:\1:'
  80. }
  81. #
  82. # curl_8char_object_name
  83. #
  84. # Same as curl_10char_object_name() description and details above, except
  85. # that object name is limited to 8 characters maximum.
  86. #
  87. curl_8char_object_name() {
  88. echo "${1}" | \
  89. sed -e 's:.*/::' \
  90. -e 's:[.].*::' \
  91. -e 'y:abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:' \
  92. -e 's:[^ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_]:_:g' \
  93. -e 's:__*:_:g' \
  94. -e 's:\([^_]\)[^_]*_\(.*\):\1\2:' \
  95. -e 's:\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3:' \
  96. -e 's:\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4:' \
  97. -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5:' \
  98. -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5\6:' \
  99. -e 's:^\(........\).*:\1:'
  100. }
  101. # end of objectname.inc