1 | # Oracle VM VirtualBox
|
---|
2 | # VirtualBox to Linux kernel coding style conversion script.
|
---|
3 |
|
---|
4 | #
|
---|
5 | # Copyright (C) 2017-2022 Oracle and/or its affiliates.
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox base platform packages, as
|
---|
8 | # available from https://www.virtualbox.org.
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or
|
---|
11 | # modify it under the terms of the GNU General Public License
|
---|
12 | # as published by the Free Software Foundation, in version 3 of the
|
---|
13 | # License.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful, but
|
---|
16 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | # General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
22 | #
|
---|
23 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
24 | #
|
---|
25 |
|
---|
26 | # This script is for converting code inside the vboxvideo module to Linux
|
---|
27 | # kernel coding style. It assumes correct VirtualBox coding style, will break
|
---|
28 | # break if the coding style is wrong (e.g. tab instead of spaces) and is not
|
---|
29 | # indended to be a generic solution: for example, identifiers will be
|
---|
30 | # translated case by case, not algorithmically. It also assumes that any
|
---|
31 | # flexibility in either coding style will be used where possible to make the
|
---|
32 | # code conform to both at once.
|
---|
33 |
|
---|
34 | # Replace up to six leading groups of four spaces with tabs.
|
---|
35 | s/^ */\t\t\t\t\t\t/g
|
---|
36 | s/^ /\t\t\t\t\t/g
|
---|
37 | s/^ /\t\t\t\t/g
|
---|
38 | s/^ /\t\t\t/g
|
---|
39 | s/^ /\t\t/g
|
---|
40 | s/^ /\t/g
|
---|
41 |
|
---|
42 | # Change various symbols and file names to fit kernel conventions.
|
---|
43 |
|
---|
44 | # Miscellaneous:
|
---|
45 | # Remove @file headers.
|
---|
46 | \|/\*\* @file| {
|
---|
47 | :start
|
---|
48 | N
|
---|
49 | s|\*/|\*/|g
|
---|
50 | T start
|
---|
51 | N
|
---|
52 | d
|
---|
53 | }
|
---|
54 | /^\/\* \$Id:.*\*\/$/d
|
---|
55 | /^typedef .* HGSMIOFFSET;/d
|
---|
56 | /^typedef .* HGSMISIZE;/d
|
---|
57 | s/^#\( *\)include <\([^/]*\)>/#\1include "\2"/g
|
---|
58 |
|
---|
59 | # File names:
|
---|
60 | s/\bHGSMIBase\.h\b/vbox_drv.h/g
|
---|
61 | s/\bHGSMIChannels\.h\b/hgsmi_channels.h/g
|
---|
62 | s/\bHGSMIChSetup\.h\b/hgsmi_ch_setup.h/g
|
---|
63 | s/\bHGSMIContext\.h\b/hgsmi_context.h/g
|
---|
64 | s/\bHGSMIDefs\.h\b/hgsmi_defs.h/g
|
---|
65 | s/\bVBoxVideoGuest\.h\b/vboxvideo_guest.h/g
|
---|
66 | s/\bVBoxVideo\.h\b/vboxvideo.h/g
|
---|
67 | s/\bVBoxVideoIPRT\.h\b/vbox_err.h/g
|
---|
68 | s/\bVBoxVideoVBE\.h\b/vboxvideo_vbe.h/g
|
---|
69 |
|
---|
70 | # Function names:
|
---|
71 | s/\btestQueryConf\b/hgsmi_test_query_conf/g
|
---|
72 | s/\bVBoxHGSMIBufferAlloc\b/hgsmi_buffer_alloc/g
|
---|
73 | s/\bVBoxHGSMIBufferFree\b/hgsmi_buffer_free/g
|
---|
74 | s/\bVBoxHGSMIBufferSubmit\b/hgsmi_buffer_submit/g
|
---|
75 | s/\bVBoxHGSMICursorPosition\b/hgsmi_cursor_position/g
|
---|
76 | s/\bVBoxHGSMIGetModeHints\b/hgsmi_get_mode_hints/g
|
---|
77 | s/\bVBoxHGSMIProcessDisplayInfo\b/hgsmi_process_display_info/g
|
---|
78 | s/\bVBoxHGSMIReportFlagsLocation\b/hgsmi_report_flags_location/g
|
---|
79 | s/\bVBoxHGSMISendCapsInfo\b/hgsmi_send_caps_info/g
|
---|
80 | s/\bVBoxHGSMIUpdateInputMapping\b/hgsmi_update_input_mapping/g
|
---|
81 | s/\bVBoxHGSMIUpdatePointerShape\b/hgsmi_update_pointer_shape/g
|
---|
82 | s/\bvboxHwBufferAvail\b/vbva_buffer_available/g
|
---|
83 | s/\bvboxHwBufferEndUpdate\b/vbva_buffer_end_update/g
|
---|
84 | s/\bvboxHwBufferFlush\b/vbva_buffer_flush/g
|
---|
85 | s/\bvboxHwBufferPlaceDataAt\b/vbva_buffer_place_data_at/g
|
---|
86 | s/\bvboxHwBufferWrite\b/vbva_write/g
|
---|
87 | s/\bVBoxQueryConfHGSMI\b/hgsmi_query_conf/g
|
---|
88 | s/\bVBoxVBVABufferBeginUpdate\b/vbva_buffer_begin_update/g
|
---|
89 | s/\bVBoxVBVABufferEndUpdate\b/vbva_buffer_end_update/g
|
---|
90 | s/\bVBoxVBVADisable\b/vbva_disable/g
|
---|
91 | s/\bVBoxVBVAEnable\b/vbva_enable/g
|
---|
92 | s/\bvboxVBVAInformHost\b/vbva_inform_host/g
|
---|
93 | s/\bvboxVBVASetupBufferContext\b/vbva_setup_buffer_context/g
|
---|
94 | s/\bVBVO_PORT_READ_U8\b/inb/g
|
---|
95 | s/\bVBVO_PORT_READ_U16\b/inw/g
|
---|
96 | s/\bVBVO_PORT_READ_U32\b/inl/g
|
---|
97 | s/\bVBVO_PORT_WRITE_U8\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outb(\2, \1)/g
|
---|
98 | s/\bVBVO_PORT_WRITE_U16\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outw(\2, \1)/g
|
---|
99 | s/\bVBVO_PORT_WRITE_U32\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outl(\2, \1)/g
|
---|
100 | s/\bVBVO_PORT_WRITE_U[0-9]*\b/VBVO_PORT_WRITE_statement_should_be_on_one_line/g
|
---|
101 |
|
---|
102 | # Macros:
|
---|
103 | s/\b_1K\b/1024/g
|
---|
104 | s/\b_4M\b/4*1024*1024/g
|
---|
105 | s/\bAssert\b\([^;]*\);/WARN_ON_ONCE(!(\1));/g
|
---|
106 | s/\bAssertCompile\b/assert_compile/g
|
---|
107 | s/\bAssertCompileSize\b/assert_compile_size/g
|
---|
108 | s/\bAssertPtr\b\([^;]*\);/WARN_ON_ONCE(!(\1));/g
|
---|
109 | s/\bAssertPtrReturn\b/assert_ptr_return/g
|
---|
110 | /AssertPtrNullReturnVoid/d
|
---|
111 | s/\bAssertRC\b\([^;]*\);/WARN_ON_ONCE(RT_FAILURE\1);/g
|
---|
112 | s/\bAssertRC\b/Assert_RC_statement_should_be_on_one_line/g
|
---|
113 | s/\bDECLCALLBACK\b(\([^)]*\))/\1/g
|
---|
114 | s/\bDECLCALLBACKTYPE\b(\([^,)]*\), *\([^,)]*\), *(\([^;)]*\) *) *)/\1 \2(\3)/g
|
---|
115 | s/\bDECLCALLBACKMEMBER\b(\([^,)]*\), *\([^,)]*\), *(\([^;)]*\) *) *)/\1 (*\2)(\3)/g
|
---|
116 | s/^\bDECLHIDDEN\b(\([^)]*\))/\1/g
|
---|
117 | s/\bDECLINLINE\b(\([^)]*\))/static inline \1/g
|
---|
118 | s/\bRT_BIT\b/BIT/g
|
---|
119 | s/\bRT_BOOL\b(\([^)]*\))/(!!(\1))/g
|
---|
120 | /RT_C_DECLS/d
|
---|
121 | s/\bUINT16_MAX\b/U16_MAX/g
|
---|
122 | s/\bUINT32_MAX\b/U32_MAX/g
|
---|
123 | s/\bUINT32_C\b(\(.*\))/\1u/g
|
---|
124 | s/!RT_VALID_PTR(/WARN_ON(!/g
|
---|
125 | s/\bRT_UNTRUSTED_VOLATILE_HOST\b//g
|
---|
126 | s/\bRT_UNTRUSTED_VOLATILE_GUEST\b//g
|
---|
127 | s/\bRT_UNTRUSTED_VOLATILE_HSTGST\b//g
|
---|
128 |
|
---|
129 | # Type names:
|
---|
130 | s/\bint32_t\b/s32/g
|
---|
131 | s/\buint8_t\b/u8/g
|
---|
132 | s/\buint16_t\b/u16/g
|
---|
133 | s/\buint32_t\b/u32/g
|
---|
134 | s/(HGSMIBUFFERLOCATION \*)//g # Remove C++ casts from void.
|
---|
135 | s/typedef struct HGSMIBUFFERLOCATION/struct hgsmi_buffer_location/g
|
---|
136 | s/struct HGSMIBUFFERLOCATION/struct hgsmi_buffer_location/g
|
---|
137 | s/} HGSMIBUFFERLOCATION/}/g
|
---|
138 | s/\bHGSMIBUFFERLOCATION\b/struct hgsmi_buffer_location/g
|
---|
139 | s/\([^*] *\)\bPHGSMIGUESTCOMMANDCONTEXT\b/\1struct gen_pool */g
|
---|
140 | s/(HGSMIHOSTFLAGS \*)//g # Remove C++ casts from void.
|
---|
141 | s/typedef struct HGSMIHOSTFLAGS/struct hgsmi_host_flags/g
|
---|
142 | s/struct HGSMIHOSTFLAGS/struct hgsmi_host_flags/g
|
---|
143 | s/} HGSMIHOSTFLAGS/}/g
|
---|
144 | s/\bHGSMIHOSTFLAGS\b/struct hgsmi_host_flags/g
|
---|
145 | s/\bHGSMIOFFSET\b/u32/g
|
---|
146 | s/\bHGSMISIZE\b/u32/g
|
---|
147 | s/\bRTRECT\b/void/g
|
---|
148 | s/(VBVABUFFERCONTEXT \*)//g # Remove C++ casts from void.
|
---|
149 | s/struct VBVABUFFERCONTEXT/struct vbva_buf_context/g
|
---|
150 | s/} VBVABUFFERCONTEXT/} vbva_buf_context/g
|
---|
151 | s/\bVBVABUFFERCONTEXT\b/struct vbva_buf_context/g
|
---|
152 | s/\([^*] *\)\bPVBVABUFFERCONTEXT\b/\1struct vbva_buf_context */g
|
---|
153 | s/(VBVACAPS \*)//g # Remove C++ casts from void.
|
---|
154 | s/struct VBVACAPS/struct vbva_caps/g
|
---|
155 | s/} VBVACAPS/} vbva_caps/g
|
---|
156 | s/\bVBVACAPS\b/struct vbva_caps/g
|
---|
157 | s/(VBVACONF32 \*)//g # Remove C++ casts from void.
|
---|
158 | s/struct VBVACONF32/struct vbva_conf32/g
|
---|
159 | s/} VBVACONF32/} vbva_conf32/g
|
---|
160 | s/\bVBVACONF32\b/struct vbva_conf32/g
|
---|
161 | s/(VBVACURSORPOSITION \*)//g # Remove C++ casts from void.
|
---|
162 | s/struct VBVACURSORPOSITION/struct vbva_cursor_position/g
|
---|
163 | s/} VBVACURSORPOSITION/} vbva_cursor_position/g
|
---|
164 | s/\bVBVACURSORPOSITION\b/struct vbva_cursor_position/g
|
---|
165 | s/(VBVAENABLE_EX \*)//g # Remove C++ casts from void.
|
---|
166 | s/struct VBVAENABLE_EX/struct vbva_enable_ex/g
|
---|
167 | s/} VBVAENABLE_EX/} vbva_enable_ex/g
|
---|
168 | s/\bVBVAENABLE_EX\b/struct vbva_enable_ex/g
|
---|
169 | s/(VBVAMOUSEPOINTERSHAPE \*)//g # Remove C++ casts from void.
|
---|
170 | s/struct VBVAMOUSEPOINTERSHAPE/struct vbva_mouse_pointer_shape/g
|
---|
171 | s/} VBVAMOUSEPOINTERSHAPE/} vbva_mouse_pointer_shape/g
|
---|
172 | s/\bVBVAMOUSEPOINTERSHAPE\b/struct vbva_mouse_pointer_shape/g
|
---|
173 | s/(VBVAMODEHINT \*)//g # Remove C++ casts from void.
|
---|
174 | s/struct VBVAMODEHINT/struct vbva_modehint/g
|
---|
175 | s/} VBVAMODEHINT/} vbva_modehint/g
|
---|
176 | s/\bVBVAMODEHINT\b/struct vbva_modehint/g
|
---|
177 | s/(VBVAQUERYMODEHINTS \*)//g # Remove C++ casts from void.
|
---|
178 | s/struct VBVAQUERYMODEHINTS/struct vbva_query_mode_hints/g
|
---|
179 | s/} VBVAQUERYMODEHINTS/} vbva_query_mode_hints/g
|
---|
180 | s/\bVBVAQUERYMODEHINTS\b/struct vbva_query_mode_hints/g
|
---|
181 | s/(VBVAREPORTINPUTMAPPING \*)//g # Remove C++ casts from void.
|
---|
182 | s/struct VBVAREPORTINPUTMAPPING/struct vbva_report_input_mapping/g
|
---|
183 | s/} VBVAREPORTINPUTMAPPING/} vbva_report_input_mapping/g
|
---|
184 | s/\bVBVAREPORTINPUTMAPPING\b/struct vbva_report_input_mapping/g
|
---|
185 |
|
---|
186 | # Variable and parameter names:
|
---|
187 | s/\baRecords\b/records/g
|
---|
188 | s/\bau8Data\b/data/g
|
---|
189 | s/\bau32Reserved\b/reserved/g
|
---|
190 | s/\bBase\b/base/g
|
---|
191 | s/\bbEnable\b/enable/g
|
---|
192 | s/\bbRc\b/ret/g
|
---|
193 | s/\bcb\b/len/g
|
---|
194 | s/\bcbBuffer\b/buffer_length/g
|
---|
195 | s/\bcbChunk\b/chunk/g
|
---|
196 | s/\bcbData\b/data_len/g
|
---|
197 | s/\bcbHintsStructureGuest\b/hints_structure_guest_size/g
|
---|
198 | s/\bcbHwBufferAvail\b/available/g
|
---|
199 | s/\bcbLength\b/len/g
|
---|
200 | s/\bcbLocation\b/buf_len/g
|
---|
201 | s/\bcbPartialWriteThreshold\b/partial_write_tresh/g ## @todo fix this?
|
---|
202 | s/\bcbPitch\b/pitch/g
|
---|
203 | s/\bcbPixels\b/pixel_len/g
|
---|
204 | s/\bcBPP\b/bpp/g
|
---|
205 | s/\bcbRecord\b/len_and_flags/g ## @todo fix this?
|
---|
206 | s/\bcDisplay\b/display/g
|
---|
207 | s/\bcHeight\b/height/g
|
---|
208 | s/\bcHintsQueried\b/hints_queried_count/g
|
---|
209 | s/\bcHotX\b/hot_x/g
|
---|
210 | s/\bcHotY\b/hot_y/g
|
---|
211 | s/\bcOriginX\b/origin_x/g
|
---|
212 | s/\bcOriginY\b/origin_y/g
|
---|
213 | s/\bcScreen\b/screen/g
|
---|
214 | s/\bcScreens\b/screens/g
|
---|
215 | s/\bcWidth\b/width/g
|
---|
216 | s/\bfCaps\b/caps/g
|
---|
217 | s/\bfFlags\b/flags/g
|
---|
218 | s/\bfHwBufferOverflow\b/buffer_overflow/g
|
---|
219 | s/\bfReportPosition\b/report_position/g
|
---|
220 | s/\bfu32Flags\b/flags/g
|
---|
221 | s/\bhostFlags\b/host_flags/g
|
---|
222 | s/\bi32Diff\b/diff/g
|
---|
223 | s/\bi32OriginX\b/origin_x/g
|
---|
224 | s/\bi32OriginY\b/origin_y/g
|
---|
225 | s/\bi32Result\b/result/g
|
---|
226 | s/\bindexRecordFirst\b/first_record_index/g
|
---|
227 | s/\bindexRecordFree\b/free_record_index/g
|
---|
228 | s/\bindexRecordNext\b/next/g
|
---|
229 | s/\boff32Data\b/data_offset/g
|
---|
230 | s/\boff32Free\b/free_offset/g
|
---|
231 | s/\boffLocation\b/location/g
|
---|
232 | s/\boffStart\b/start_offset/g
|
---|
233 | s/\boffVRAMBuffer\b/buffer_offset/g
|
---|
234 | s/\bpaHints\b/hints/g
|
---|
235 | s/\bpCtx\b/ctx/g
|
---|
236 | s/\bpPixels\b/pixels/g
|
---|
237 | s/\bpRecord\b/record/g
|
---|
238 | s/\bpulValue\b/value_ret/g
|
---|
239 | s/\bpVBVA\b/vbva/g
|
---|
240 | s/\bpxHost\b/x_host/g
|
---|
241 | s/\bpyHost\b/y_host/g
|
---|
242 | s/\bu16BitsPerPixel\b/bits_per_pixel/g
|
---|
243 | s/\bu16Flags\b/flags/g
|
---|
244 | s/\bu32BytesTillBoundary\b/bytes_till_boundary/g
|
---|
245 | s/\bu32Flags\b/flags/g
|
---|
246 | s/\bu32Height\b/height/g
|
---|
247 | s/\bu32HostEvents\b/host_events/g
|
---|
248 | s/\bu32HostFlags\b/host_flags/g
|
---|
249 | s/\bu32HotX\b/hot_x/g
|
---|
250 | s/\bu32HotY\b/hot_y/g
|
---|
251 | s/\bu32Index\b/index/g
|
---|
252 | s/\bu32LineSize\b/line_size/g
|
---|
253 | s/\bu32Offset\b/offset/g
|
---|
254 | s/\bu32Reserved\b/reserved/g
|
---|
255 | s/\bu32ScreenId\b/screen_id/g
|
---|
256 | s/\bu32StartOffset\b/start_offset/g
|
---|
257 | s/\bu32SupportedOrders\b/supported_orders/g
|
---|
258 | s/\bu32Value\b/value/g
|
---|
259 | s/\bu32ViewIndex\b/view_index/g
|
---|
260 | s/\bu32Width\b/width/g
|
---|
261 | s/\bulValue\b/value/g
|
---|
262 |
|
---|
263 | # Header file guard:
|
---|
264 | s/__HGSMIChannels_h__/__HGSMI_CHANNELS_H__/g
|
---|
265 | s/VBOX_INCLUDED_Graphics_HGSMIChSetup_h/__HGSMI_CH_SETUP_H__/g
|
---|
266 |
|
---|
267 | # And move braces. This must be the last expression as it jumps to the next
|
---|
268 | # line.
|
---|
269 | /..*$/ {
|
---|
270 | N
|
---|
271 | s/^\([\t ][\t ]*\)} *\n[\t ]*else/\1} else/g
|
---|
272 | t continue_else
|
---|
273 | b try_brace
|
---|
274 | :continue_else
|
---|
275 | N
|
---|
276 | :try_brace
|
---|
277 | s/^\([\t ].*\)\n[\t ][\t ]*{/\1 {/g
|
---|
278 | s/^\([^#()]*\)\n[\t ]*{/\1 {/g
|
---|
279 | t done_brace
|
---|
280 | P
|
---|
281 | D
|
---|
282 | :done_brace
|
---|
283 | p
|
---|
284 | d
|
---|
285 | }
|
---|