summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/linux/drm/indent.sed
blob: 53c8a4ce6731fc80fbe14fbd0f73282a090fb3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Oracle VM VirtualBox
# VirtualBox to Linux kernel coding style conversion script.

#
# Copyright (C) 2017-2020 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#

# This script is for converting code inside the vboxvideo module to Linux
# kernel coding style.  It assumes correct VirtualBox coding style, will break
# break if the coding style is wrong (e.g. tab instead of spaces) and is not
# indended to be a generic solution: for example, identifiers will be
# translated case by case, not algorithmically.  It also assumes that any
# flexibility in either coding style will be used where possible to make the
# code conform to both at once.

# Replace up to six leading groups of four spaces with tabs.
s/^                         */\t\t\t\t\t\t/g
s/^                    /\t\t\t\t\t/g
s/^                /\t\t\t\t/g
s/^            /\t\t\t/g
s/^        /\t\t/g
s/^    /\t/g

# Change various symbols and file names to fit kernel conventions.

# Miscellaneous:
# Remove @file headers.
\|/\*\* @file| {
:start
  N
  s|\*/|\*/|g
  T start
  N
  d
}
/^\/\* \$Id:.*\*\/$/d
/^typedef .* HGSMIOFFSET;/d
/^typedef .* HGSMISIZE;/d
s/^#\( *\)include <\([^/]*\)>/#\1include "\2"/g

# File names:
s/\bHGSMIBase\.h\b/vbox_drv.h/g
s/\bHGSMIChannels\.h\b/hgsmi_channels.h/g
s/\bHGSMIChSetup\.h\b/hgsmi_ch_setup.h/g
s/\bHGSMIContext\.h\b/hgsmi_context.h/g
s/\bHGSMIDefs\.h\b/hgsmi_defs.h/g
s/\bVBoxVideoGuest\.h\b/vboxvideo_guest.h/g
s/\bVBoxVideo\.h\b/vboxvideo.h/g
s/\bVBoxVideoIPRT\.h\b/vbox_err.h/g
s/\bVBoxVideoVBE\.h\b/vboxvideo_vbe.h/g

# Function names:
s/\btestQueryConf\b/hgsmi_test_query_conf/g
s/\bVBoxHGSMIBufferAlloc\b/hgsmi_buffer_alloc/g
s/\bVBoxHGSMIBufferFree\b/hgsmi_buffer_free/g
s/\bVBoxHGSMIBufferSubmit\b/hgsmi_buffer_submit/g
s/\bVBoxHGSMICursorPosition\b/hgsmi_cursor_position/g
s/\bVBoxHGSMIGetModeHints\b/hgsmi_get_mode_hints/g
s/\bVBoxHGSMIProcessDisplayInfo\b/hgsmi_process_display_info/g
s/\bVBoxHGSMIReportFlagsLocation\b/hgsmi_report_flags_location/g
s/\bVBoxHGSMISendCapsInfo\b/hgsmi_send_caps_info/g
s/\bVBoxHGSMIUpdateInputMapping\b/hgsmi_update_input_mapping/g
s/\bVBoxHGSMIUpdatePointerShape\b/hgsmi_update_pointer_shape/g
s/\bvboxHwBufferAvail\b/vbva_buffer_available/g
s/\bvboxHwBufferEndUpdate\b/vbva_buffer_end_update/g
s/\bvboxHwBufferFlush\b/vbva_buffer_flush/g
s/\bvboxHwBufferPlaceDataAt\b/vbva_buffer_place_data_at/g
s/\bvboxHwBufferWrite\b/vbva_write/g
s/\bVBoxQueryConfHGSMI\b/hgsmi_query_conf/g
s/\bVBoxVBVABufferBeginUpdate\b/vbva_buffer_begin_update/g
s/\bVBoxVBVABufferEndUpdate\b/vbva_buffer_end_update/g
s/\bVBoxVBVADisable\b/vbva_disable/g
s/\bVBoxVBVAEnable\b/vbva_enable/g
s/\bvboxVBVAInformHost\b/vbva_inform_host/g
s/\bvboxVBVASetupBufferContext\b/vbva_setup_buffer_context/g
s/\bVBVO_PORT_READ_U8\b/inb/g
s/\bVBVO_PORT_READ_U16\b/inw/g
s/\bVBVO_PORT_READ_U32\b/inl/g
s/\bVBVO_PORT_WRITE_U8\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outb(\2, \1)/g
s/\bVBVO_PORT_WRITE_U16\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outw(\2, \1)/g
s/\bVBVO_PORT_WRITE_U32\b *( *\(\b[^(),]*\b\) *, *\(\b[^(),]*\b\) *)/outl(\2, \1)/g
s/\bVBVO_PORT_WRITE_U[0-9]*\b/VBVO_PORT_WRITE_statement_should_be_on_one_line/g

# Macros:
s/\b_1K\b/1024/g
s/\b_4M\b/4*1024*1024/g
s/\bAssert\b\([^;]*\);/WARN_ON_ONCE(!(\1));/g
s/\bAssertCompile\b/assert_compile/g
s/\bAssertCompileSize\b/assert_compile_size/g
s/\bAssertPtr\b\([^;]*\);/WARN_ON_ONCE(!(\1));/g
s/\bAssertPtrReturn\b/assert_ptr_return/g
/AssertPtrNullReturnVoid/d
s/\bAssertRC\b\([^;]*\);/WARN_ON_ONCE(RT_FAILURE\1);/g
s/\bAssertRC\b/Assert_RC_statement_should_be_on_one_line/g
s/\bDECLCALLBACK\b(\([^)]*\))/\1/g
s/\bDECLCALLBACKMEMBER\b(\([^,)]*\), *\([^,)]*\))/\1 (*\2)/g
s/^\bDECLHIDDEN\b(\([^)]*\))/\1/g
s/\bDECLINLINE\b(\([^)]*\))/static inline \1/g
s/\bRT_BIT\b/BIT/g
s/\bRT_BOOL\b(\([^)]*\))/(!!(\1))/g
/RT_C_DECLS/d
s/\bUINT16_MAX\b/U16_MAX/g
s/\bUINT32_MAX\b/U32_MAX/g
s/\bUINT32_C\b(\(.*\))/\1u/g
s/!VALID_PTR(/WARN_ON(!/g
s/\bRT_UNTRUSTED_VOLATILE_HOST\b//g
s/\bRT_UNTRUSTED_VOLATILE_GUEST\b//g
s/\bRT_UNTRUSTED_VOLATILE_HSTGST\b//g

# Type names:
s/\bint32_t\b/s32/g
s/\buint8_t\b/u8/g
s/\buint16_t\b/u16/g
s/\buint32_t\b/u32/g
s/(HGSMIBUFFERLOCATION \*)//g  # Remove C++ casts from void.
s/typedef struct HGSMIBUFFERLOCATION/struct hgsmi_buffer_location/g
s/struct HGSMIBUFFERLOCATION/struct hgsmi_buffer_location/g
s/} HGSMIBUFFERLOCATION/}/g
s/\bHGSMIBUFFERLOCATION\b/struct hgsmi_buffer_location/g
s/\([^*] *\)\bPHGSMIGUESTCOMMANDCONTEXT\b/\1struct gen_pool */g
s/(HGSMIHOSTFLAGS \*)//g  # Remove C++ casts from void.
s/typedef struct HGSMIHOSTFLAGS/struct hgsmi_host_flags/g
s/struct HGSMIHOSTFLAGS/struct hgsmi_host_flags/g
s/} HGSMIHOSTFLAGS/}/g
s/\bHGSMIHOSTFLAGS\b/struct hgsmi_host_flags/g
s/\bHGSMIOFFSET\b/u32/g
s/\bHGSMISIZE\b/u32/g
s/\bRTRECT\b/void/g
s/(VBVABUFFERCONTEXT \*)//g  # Remove C++ casts from void.
s/struct VBVABUFFERCONTEXT/struct vbva_buf_context/g
s/} VBVABUFFERCONTEXT/} vbva_buf_context/g
s/\bVBVABUFFERCONTEXT\b/struct vbva_buf_context/g
s/\([^*] *\)\bPVBVABUFFERCONTEXT\b/\1struct vbva_buf_context */g
s/(VBVACAPS \*)//g  # Remove C++ casts from void.
s/struct VBVACAPS/struct vbva_caps/g
s/} VBVACAPS/} vbva_caps/g
s/\bVBVACAPS\b/struct vbva_caps/g
s/(VBVACONF32 \*)//g  # Remove C++ casts from void.
s/struct VBVACONF32/struct vbva_conf32/g
s/} VBVACONF32/} vbva_conf32/g
s/\bVBVACONF32\b/struct vbva_conf32/g
s/(VBVACURSORPOSITION \*)//g  # Remove C++ casts from void.
s/struct VBVACURSORPOSITION/struct vbva_cursor_position/g
s/} VBVACURSORPOSITION/} vbva_cursor_position/g
s/\bVBVACURSORPOSITION\b/struct vbva_cursor_position/g
s/(VBVAENABLE_EX \*)//g  # Remove C++ casts from void.
s/struct VBVAENABLE_EX/struct vbva_enable_ex/g
s/} VBVAENABLE_EX/} vbva_enable_ex/g
s/\bVBVAENABLE_EX\b/struct vbva_enable_ex/g
s/(VBVAMOUSEPOINTERSHAPE \*)//g  # Remove C++ casts from void.
s/struct VBVAMOUSEPOINTERSHAPE/struct vbva_mouse_pointer_shape/g
s/} VBVAMOUSEPOINTERSHAPE/} vbva_mouse_pointer_shape/g
s/\bVBVAMOUSEPOINTERSHAPE\b/struct vbva_mouse_pointer_shape/g
s/(VBVAMODEHINT \*)//g  # Remove C++ casts from void.
s/struct VBVAMODEHINT/struct vbva_modehint/g
s/} VBVAMODEHINT/} vbva_modehint/g
s/\bVBVAMODEHINT\b/struct vbva_modehint/g
s/(VBVAQUERYMODEHINTS \*)//g  # Remove C++ casts from void.
s/struct VBVAQUERYMODEHINTS/struct vbva_query_mode_hints/g
s/} VBVAQUERYMODEHINTS/} vbva_query_mode_hints/g
s/\bVBVAQUERYMODEHINTS\b/struct vbva_query_mode_hints/g
s/(VBVAREPORTINPUTMAPPING \*)//g  # Remove C++ casts from void.
s/struct VBVAREPORTINPUTMAPPING/struct vbva_report_input_mapping/g
s/} VBVAREPORTINPUTMAPPING/} vbva_report_input_mapping/g
s/\bVBVAREPORTINPUTMAPPING\b/struct vbva_report_input_mapping/g

# Variable and parameter names:
s/\baRecords\b/records/g
s/\bau8Data\b/data/g
s/\bau32Reserved\b/reserved/g
s/\bBase\b/base/g
s/\bbEnable\b/enable/g
s/\bbRc\b/ret/g
s/\bcb\b/len/g
s/\bcbBuffer\b/buffer_length/g
s/\bcbChunk\b/chunk/g
s/\bcbData\b/data_len/g
s/\bcbHintsStructureGuest\b/hints_structure_guest_size/g
s/\bcbHwBufferAvail\b/available/g
s/\bcbLength\b/len/g
s/\bcbLocation\b/buf_len/g
s/\bcbPartialWriteThreshold\b/partial_write_tresh/g  ## @todo fix this?
s/\bcbPitch\b/pitch/g
s/\bcbPixels\b/pixel_len/g
s/\bcBPP\b/bpp/g
s/\bcbRecord\b/len_and_flags/g  ## @todo fix this?
s/\bcDisplay\b/display/g
s/\bcHeight\b/height/g
s/\bcHintsQueried\b/hints_queried_count/g
s/\bcHotX\b/hot_x/g
s/\bcHotY\b/hot_y/g
s/\bcOriginX\b/origin_x/g
s/\bcOriginY\b/origin_y/g
s/\bcScreen\b/screen/g
s/\bcScreens\b/screens/g
s/\bcWidth\b/width/g
s/\bfCaps\b/caps/g
s/\bfFlags\b/flags/g
s/\bfHwBufferOverflow\b/buffer_overflow/g
s/\bfReportPosition\b/report_position/g
s/\bfu32Flags\b/flags/g
s/\bhostFlags\b/host_flags/g
s/\bi32Diff\b/diff/g
s/\bi32OriginX\b/origin_x/g
s/\bi32OriginY\b/origin_y/g
s/\bi32Result\b/result/g
s/\bindexRecordFirst\b/first_record_index/g
s/\bindexRecordFree\b/free_record_index/g
s/\bindexRecordNext\b/next/g
s/\boff32Data\b/data_offset/g
s/\boff32Free\b/free_offset/g
s/\boffLocation\b/location/g
s/\boffStart\b/start_offset/g
s/\boffVRAMBuffer\b/buffer_offset/g
s/\bpaHints\b/hints/g
s/\bpCtx\b/ctx/g
s/\bpPixels\b/pixels/g
s/\bpRecord\b/record/g
s/\bpulValue\b/value_ret/g
s/\bpVBVA\b/vbva/g
s/\bpxHost\b/x_host/g
s/\bpyHost\b/y_host/g
s/\bu16BitsPerPixel\b/bits_per_pixel/g
s/\bu16Flags\b/flags/g
s/\bu32BytesTillBoundary\b/bytes_till_boundary/g
s/\bu32Flags\b/flags/g
s/\bu32Height\b/height/g
s/\bu32HostEvents\b/host_events/g
s/\bu32HostFlags\b/host_flags/g
s/\bu32HotX\b/hot_x/g
s/\bu32HotY\b/hot_y/g
s/\bu32Index\b/index/g
s/\bu32LineSize\b/line_size/g
s/\bu32Offset\b/offset/g
s/\bu32Reserved\b/reserved/g
s/\bu32ScreenId\b/screen_id/g
s/\bu32StartOffset\b/start_offset/g
s/\bu32SupportedOrders\b/supported_orders/g
s/\bu32Value\b/value/g
s/\bu32ViewIndex\b/view_index/g
s/\bu32Width\b/width/g
s/\bulValue\b/value/g

# Header file guard:
s/__HGSMIChannels_h__/__HGSMI_CHANNELS_H__/g
s/VBOX_INCLUDED_Graphics_HGSMIChSetup_h/__HGSMI_CH_SETUP_H__/g

# And move braces.  This must be the last expression as it jumps to the next
# line.
/..*$/ {
  N
  s/^\([\t ][\t ]*\)} *\n[\t ]*else/\1} else/g
  t continue_else
  b try_brace
:continue_else
  N
:try_brace
  s/^\([\t ].*\)\n[\t ][\t ]*{/\1 {/g
  s/^\([^#()]*\)\n[\t ]*{/\1 {/g
  t done_brace
  P
  D
:done_brace
  p
  d
}