1# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
22
23# initialize
24SET(ignore_list
25  xdr_array
26  xdr_bool
27  xdr_bytes
28  xdr_char
29  xdr_double
30  xdr_enum
31  xdr_float
32  xdr_int
33  xdr_int8_t
34  xdr_int16_t
35  xdr_int32_t
36  xdr_int64_t
37  xdr_long
38  xdr_opaque
39  xdr_pointer
40  xdr_reference
41  xdr_short
42  xdr_string
43  xdr_u_char
44  xdr_u_int
45  xdr_uint8_t
46  xdr_uint16_t
47  xdr_uint32_t
48  xdr_uint64_t
49  xdr_u_long
50  xdr_u_short
51  xdr_union
52  xdr_vector
53  xdr_void
54  xdr_wrapstring
55  xdr_checked_data
56  )
57
58# Run rpcgen
59#MESSAGE("${RPCGEN_EXECUTABLE} -DXCOM_PROTO_VERS=${XCOM_PROTO_VERS} -C -c ${x_tmp_x_canonical_name} > ${rpcgen_output}")
60EXECUTE_PROCESS(
61  COMMAND ${RPCGEN_EXECUTABLE} -DXCOM_PROTO_VERS=${XCOM_PROTO_VERS} -C -c ${x_tmp_x_canonical_name}
62  OUTPUT_FILE ${rpcgen_output}
63  )
64
65#MESSAGE("Reading ${rpcgen_output}")
66FILE(STRINGS ${rpcgen_output} xcom_vp_def)
67
68#MESSAGE("writing ${x_gen_c}")
69
70# Process file line by line, and add version numbers and code stubs
71SET(blurb 0)
72FOREACH(line ${xcom_vp_def})
73  STRING(REGEX MATCH "^BEGIN" xxx "${line}")
74  IF(xxx)
75	SET(blurb 1)
76	SET(suppress 1)
77  ENDIF()
78
79  STRING(REGEX MATCH "^END" xxx "${line}")
80  IF(xxx)
81	SET(blurb 0)
82	SET(suppress 1)
83  ENDIF()
84
85  # Save lines if within BEGIN..END
86  IF(blurb)
87	IF(suppress)
88	  SET(suppress 0)
89	ELSE()
90	  SET(code "${code}\n${line}")
91	ENDIF()
92  ELSE()
93	# Output saved lines when we see "return TRUE"
94	STRING(REGEX MATCH "return TRUE" xxx "${line}")
95	IF(xxx)
96	  IF(code)
97		FILE(APPEND ${x_gen_c} "/* BEGIN protocol conversion code */${code}\n/* END protocol conversion code */\n")
98		UNSET(code)
99	  ENDIF()
100	ENDIF()
101
102	IF(suppress)
103	  SET(suppress 0)
104	ELSE()
105	  # Add version suffix to any xdr_* functions in this line
106	  STRING(REGEX REPLACE "(xdr_[a-zA-Z0-9_]+)" \\1${version} vline "${line}")
107          # If we added the suffix to a xdr function from the ignore list, revert to the name without the suffix.
108	  FOREACH(IGNORE_PATTERN ${ignore_list})
109              SET(IGNORE_PATTERN_WITH_VERSION "${IGNORE_PATTERN}${version}")
110              STRING(REPLACE "${IGNORE_PATTERN_WITH_VERSION}" "${IGNORE_PATTERN}" vline "${vline}")
111	  ENDFOREACH()
112	  FILE(APPEND ${x_gen_c} "${vline}\n")
113	ENDIF()
114  ENDIF()
115ENDFOREACH()
116
117FILE(REMOVE ${rpcgen_output})
118
119