Annotation of embedaddon/curl/tests/objnames.inc, revision 1.1.1.1

1.1       misho       1: # ***************************************************************************
                      2: # *                                  _   _ ____  _
                      3: # *  Project                     ___| | | |  _ \| |
                      4: # *                             / __| | | | |_) | |
                      5: # *                            | (__| |_| |  _ <| |___
                      6: # *                             \___|\___/|_| \_\_____|
                      7: # *
                      8: # * Copyright (C) 2012 - 2020, 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: #
                     24: # This file is sourced from curl/packages/OS400/initscript.sh and
                     25: # other Bourne shell scripts. Keep it as portable as possible.
                     26: #
                     27: 
                     28: #
                     29: # curl_10char_object_name
                     30: #
                     31: # This shell function accepts a single string argument with unspecified
                     32: # length representing a (*.c) source file name and returns a string which
                     33: # is a transformation of given argument.
                     34: #
                     35: # The intended purpose of this function is to transliterate a (*.c) source
                     36: # file name that may be longer than 10 characters, or not, into a string
                     37: # with at most 10 characters which may be used as an OS/400 object name.
                     38: #
                     39: # This function might not be universally useful, nor we care about it.
                     40: #
                     41: # It is intended to be used with libcurl's (*.c) source file names, so
                     42: # dependency on libcurl's source file naming scheme is acceptable and
                     43: # good enough for its intended use. Specifically it makes use of the fact
                     44: # that libcurl's (*.c) source file names which may be longer than 10 chars
                     45: # are conformed with underscore '_' separated substrings, or separated by
                     46: # other character which does not belong to the [0-9], [a-z] or [A-Z] sets.
                     47: #
                     48: # This allows repeatable and automatic short object name generation with
                     49: # no need for a hardcoded mapping table.
                     50: #
                     51: # Transformation is done in the following way:
                     52: #
                     53: # 1) Leading directory components are removed.
                     54: # 2) Leftmost dot character and any other char following it are removed.
                     55: # 3) Lowercase characters are transliterated to uppercase.
                     56: # 4) Characters not in [A-Z] or [0-9] are transliterated to underscore '_'.
                     57: # 5) Every sequence of one or more underscores is replaced with a single one.
                     58: # 6) Five leftmost substrings which end in an underscore character are
                     59: #    replaced by the first character of each substring, while retaining
                     60: #    the rest of the string.
                     61: # 7) Finally the result is truncated to 10 characters.
                     62: #
                     63: # Resulting object name may be shorter than 10 characters.
                     64: #
                     65: # Test case 1221 does unit testng of this function and also verifies
                     66: # that it is possible to generate distinct short object names for all
                     67: # curl and libcurl *.c source file names.
                     68: #
                     69: 
                     70: curl_10char_object_name() {
                     71:   echo "${1}" | \
                     72:   sed -e 's:.*/::' \
                     73:    -e 's:[.].*::' \
                     74:    -e 'y:abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:' \
                     75:    -e 's:[^ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_]:_:g' \
                     76:    -e 's:__*:_:g' \
                     77:    -e 's:\([^_]\)[^_]*_\(.*\):\1\2:' \
                     78:    -e 's:\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3:' \
                     79:    -e 's:\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4:' \
                     80:    -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5:' \
                     81:    -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5\6:' \
                     82:    -e 's:^\(..........\).*:\1:'
                     83: }
                     84: 
                     85: #
                     86: # curl_8char_object_name
                     87: #
                     88: # Same as curl_10char_object_name() description and details above, except
                     89: # that object name is limited to 8 characters maximum.
                     90: #
                     91: 
                     92: curl_8char_object_name() {
                     93:   echo "${1}" | \
                     94:   sed -e 's:.*/::' \
                     95:    -e 's:[.].*::' \
                     96:    -e 'y:abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:' \
                     97:    -e 's:[^ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_]:_:g' \
                     98:    -e 's:__*:_:g' \
                     99:    -e 's:\([^_]\)[^_]*_\(.*\):\1\2:' \
                    100:    -e 's:\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3:' \
                    101:    -e 's:\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4:' \
                    102:    -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5:' \
                    103:    -e 's:\([^_]\)\([^_]\)\([^_]\)\([^_]\)\([^_]\)[^_]*_\(.*\):\1\2\3\4\5\6:' \
                    104:    -e 's:^\(........\).*:\1:'
                    105: }
                    106: 
                    107: # end of objectname.inc

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>