Diff

Differences From Artifact [833dbdb173]:

To Artifact [f1fa196b14]:


     1      1   #! /usr/bin/env bash
     2      2   
     3      3   cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
     4      4   
     5      5   cat libcackey_wrap.c.in
     6      6   
            7  +functionList=()
            8  +while IFS='' read -r line; do
            9  +	function="$(echo "${line}" | cut -f 2 -d , | cut -f 1 -d ')' | sed 's@ *@@g')"
           10  +
           11  +	if [ "${function}" = 'C_LoginMutexArg' ]; then
           12  +		continue
           13  +	fi
           14  +
           15  +	functionList=("${functionList[@]}" "${function}")
           16  +done < <(grep '^CK_DEFINE_FUNCTION' ../cackey.c)
           17  +
     7     18   grep '^CK_DEFINE_FUNCTION' ../cackey.c | while IFS='' read -r line; do
     8     19   	function="$(echo "${line}" | cut -f 2 -d , | cut -f 1 -d ')' | sed 's@ *@@g')"
           20  +
           21  +	if [ "${function}" = 'C_LoginMutexArg' ]; then
           22  +		continue
           23  +	fi
           24  +
     9     25   	args="$(echo "${line}" | cut -f 3 -d '(' | cut -f 1 -d ')' | tr ',' $'\n' | sed 's@^ *@@')"
    10     26   	argNames=()
    11     27   	while read argType argName; do
    12     28   		argNames=("${argNames[@]}" "${argName}")
    13     29   	done <<<"${args}"
    14     30   
    15     31   	argNamesList=''
................................................................................
    17     33   		argNamesList="${argNamesList}, ${argName}"
    18     34   	done
    19     35   	argNamesList="$(echo "${argNamesList}" | cut -c 3-)"
    20     36   
    21     37   	echo ''
    22     38   	echo "${line}"
    23     39   	echo $'\t'"CK_RV (*func)($(echo "${args}" | tr $'\n' ',' | sed 's@,*$@@;s@,@, @g'));"
           40  +	case "${function}" in
           41  +		C_Finalize)
           42  +			echo $'\t''CK_RV retval;'
           43  +			;;
           44  +		C_Initialize)
           45  +			echo $'\t''CK_C_INITIALIZE_ARGS CK_PTR args, localargs;'
           46  +			;;
           47  +		C_GetFunctionList)
           48  +			echo $'\t''CK_RV retval;'
           49  +			echo $'\t''CK_FUNCTION_LIST_PTR pFunctionList;'
           50  +			;;
           51  +	esac
           52  +
    24     53   	echo ''
    25     54   	echo $'\t''libcackey_wrap_init();'
           55  +
           56  +	if [ "${function}" = 'C_Initialize' ]; then
           57  +		echo ''
           58  +		echo $'\t''if (pInitArgs) {'
           59  +		echo $'\t\t''args = pInitArgs;'
           60  +		echo $'\t\t''if ((args->flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK) {'
           61  +#echo 'fprintf(stderr, "replacing=%p\n", pInitArgs); fflush(stderr); abort();'
           62  +		echo $'\t\t\t''memcpy(&localargs, args, sizeof(*args));'
           63  +		echo $'\t\t\t''localargs.CreateMutex = libcackey_wrap_createmutex;'
           64  +		echo $'\t\t\t''localargs.DestroyMutex = libcackey_wrap_destroymutex;'
           65  +		echo $'\t\t\t''localargs.LockMutex = libcackey_wrap_lockmutex;'
           66  +		echo $'\t\t\t''localargs.UnlockMutex = libcackey_wrap_unlockmutex;'
           67  +		echo $'\t\t\t''localargs.flags &= ~CKF_OS_LOCKING_OK;'
           68  +		echo $'\t\t\t''pInitArgs = &localargs;'
           69  +		echo $'\t\t''}'
           70  +		echo $'\t''}'
           71  +	fi
    26     72   	echo ''
    27     73   	echo $'\t'"func = dlsym(libcackey_wrap_handle, \"${function}\");"
    28     74   	echo ''
    29         -	echo $'\t'"return(func($argNamesList));"
           75  +	if [ "${function}" = 'C_Finalize' ]; then
           76  +		echo $'\t'"retval = func($argNamesList);"
           77  +		echo ''
           78  +		echo $'\t''libcackey_wrap_fini();'
           79  +		echo ''
           80  +		echo $'\t''return(retval);'
           81  +	elif [ "${function}" = 'C_GetFunctionList' ]; then
           82  +		echo $'\t'"retval = func($argNamesList);"
           83  +		echo ''
           84  +		echo $'\t''if (retval == CKR_OK) {'
           85  +		echo $'\t\t''pFunctionList = *ppFunctionList;'
           86  +		for function in "${functionList[@]}"; do
           87  +			echo $'\t\t'"pFunctionList->${function} = ${function};"
           88  +		done
           89  +		echo $'\t''}'
           90  +		echo ''
           91  +		echo $'\t''return(retval);'
           92  +	else
           93  +		echo $'\t'"return(func($argNamesList));"
           94  +	fi
    30     95   	echo '}'
    31     96   done