]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/ontgaar.py
release commit
[lilypond.git] / buildscripts / ontgaar.py
1 #!@PYTHON@
2 # -*-python-*-
3
4 '''
5
6 Remove (ont-) LilyPond specific kind of HunGA(a)Rian notation.
7
8
9    ontgaar $(find flower lily python -name '*cc' -o -name '*hh' -o -name '*ll' -o -name '*yy')
10
11    for i in $(find flower lily python -name '*.ontgaar'); do diff -u $(dirname $i)/$(basename $i .ontgaar) $i; done > pats
12
13
14
15 When done, move this to Coding Standads doco.
16
17
18 Mandatory suffixes:
19   _       :  _       member var
20
21
22 Optional suffixes:
23   _b      : bool
24   _p      : as in lispy pair_p ()?
25   _x      : x-coor
26   _y      : y-coor
27
28   _byte   :
29   _char   :
30   _count  : counter
31   _drul   : Drul_array
32   _global : global var
33   _grob   : Grob
34   _mom    : moment
35   _req    : Request
36   _scm    : SCM
37   _str    : C string
38   _str0   : C string
39   _string : C++ string
40
41 Prefixes:
42   get_    :  
43   gh_     :  Do not use: part of deprecated Guile api
44   ly_     :
45   scm_    :
46
47
48 The Grand Ontgaaring (some may remain):
49
50   _str    -> _string
51   _ch   -> _str0
52   _ch_C -> _str0
53   _sz   -> _str0
54   
55   _ch    -> _char
56   
57   _C     : junk
58   _c     : junk
59   _f     : junk
60   _i     : junk
61   _l     : junk
62   _p     : junk, except for lispy is_foo_p ()
63   _arr   : junk
64   _array : junk
65
66
67
68
69 Voor alle suffixen waar het funcienamen betreft, als ik zeg maar wat,
70 multiplicity_i (), wordt naam dan zoveel mogelijk: get_mulitiplity ().
71 Als je dat niet doet, krijg je naam clashes met variabelen.
72
73
74
75
76 '''
77                   
78 import re
79 import sys
80
81 files = sys.argv[1:]
82
83 for f in files:
84         print f
85         s = open (f).read ()
86         
87         # shield stuff
88         s = re.sub (r'equal_p', r'equal_pX', s)
89         s = re.sub (r'less_p', r'less_pX', s)
90         s = re.sub (r'pair_p', r'pair_pX', s)
91         s = re.sub (r'smob_p', r'smob_pX', s)
92         s = re.sub (r'list_p(\W)', r'list_pX\1', s)
93
94         s = re.sub (r'(gh_\w*_(p|str)) *\(', r'\1X (', s)
95         s = re.sub (r'(ly_\w*_(p|str)) *\(', r'\1X (', s)
96         s = re.sub (r'(scm_\w*_(p|str)) *\(', r'\1X (', s)
97         
98         s = re.sub (r'to_c(\W)', r'to_cX\1', s)
99         s = re.sub (r'P_C', r'P_XC', s)
100
101         s = re.sub (r'(\W)get_music(\W)', r'\1Yget_pending_events\2', s)
102
103         s = re.sub (r'2_i(\W)', r'2int\1', s)
104         s = re.sub (r'2_u(\W)', r'2unsigned\1', s)
105         s = re.sub (r'2_f(\W)', r'2double\1', s)
106
107         s = re.sub (r'(\w+)_str *\(', r'\1_string (', s)
108
109
110         # member vars or multipart names
111         s = re.sub (r'(\w+)_(c|f|i|l|p)_(\W)', r'\1_\3', s)
112         s = re.sub (r'(\w+)_(c|f|i|l|p)_arr(_|\W)', r'\1_array\3', s)
113         s = re.sub (r'(\w+)_arr_', r'\1_array_', s)
114         s = re.sub (r'(\w+)_str_', r'\1_string_', s)
115         s = re.sub (r'(\w+)_sz', r'\1_str0', s)
116         
117         # functions
118         s = re.sub (r'(\W)ch_C *\(', r'\1Yto_str0 (', s)
119         s = re.sub (r'(\W)byte_C *\(', r'\1Yto_bytes (', s)
120         s = re.sub (r'(\W)byte_l *\(', r'\1Yget_bytes (', s)
121         s = re.sub (r'(\W)value_i *\(', r'\1Yto_int (', s)
122         s = re.sub (r'(\W)value_f *\(', r'\1Yto_double (', s)
123         s = re.sub (r'find_i *\(', r'Yfind_index (', s)
124         s = re.sub (r'compare_i *\)', r'compare)', s)
125
126         
127         s = re.sub (r'(\w+)_(c|f|i|l|p) *\(', r'Yget_\1 (', s)
128         
129         s = re.sub (r'(\w+)_arr *\(', r'\1_array (', s)
130         s = re.sub (r'(\w+)_ch *\(', r'\1_str0 (', s)
131         s = re.sub (r'(\w+)_str *\(', r'\1_string (', s)
132         
133         s = re.sub (r'(\W)str *\(', r'\1string (', s)
134         s = re.sub (r'(\W)arr *\(', r'\1array (', s)
135         
136         s = re.sub (r'(\w+)_ch_C *\(', r'\1_str0 (', s)
137         s = re.sub (r'(\w+)_ch *\(', r'\1_str0 (', s)
138
139         # more member vars or multipart names
140         s = re.sub (r'(\w+)_ch_C', r'\1_str0', s)
141         s = re.sub (r'(\w+)_ch_', r'\1_char_', s)
142         s = re.sub (r'(\W)ch_C(\W)', r'\1str0\2', s)
143
144         # plain vars -- can't do, as we have
145         # Real foo_f, int foo_i, SCM foo constructs
146         # s = re.sub (r'(\w+)_(c|f|i|l|p)(\W)', r'\1_\3', s)
147
148         
149         # but these will go
150         s = re.sub (r'(\W)arr_(l|p)(\W)', r'\1array\3', s)
151         s = re.sub (r'new_(l|p)', r'new_pX', s)
152         s = re.sub (r'(\w+)_(l|p)(\W)', r'\1\3', s)
153
154         s = re.sub (r'(\w+)_arr(\W)', r'\1_array\2', s)
155         s = re.sub (r'(\w+)_str(\W)', r'\1_string\2', s)
156         
157         s = re.sub (r'(\w+)_ch_C(\W)', r'\1_str0\2', s)
158         s = re.sub (r'(\w+)_ch(\W)', r'\1_char\2', s)
159
160         s = re.sub (r'(\w+)_C(\W)', r'\1\2', s)
161         
162         # fixups
163         s = re.sub (r'Yfind', 'find', s)
164         s = re.sub (r'Yget_argument_to', 'get_argument_index', s)
165         s = re.sub (r'Yget_compare', 'compare', s)
166         s = re.sub (r'Yget_cons', 'cons', s)
167         s = re.sub (r'Yget_create', 'create', s)
168         s = re.sub (r'Yget_find', 'find', s)
169         s = re.sub (r'Yget_hex', 'hex', s)
170         s = re.sub (r'Yget_index', 'index', s)
171         s = re.sub (r'Yget_length', 'length', s)
172         s = re.sub (r'Yget_remove', 'remove', s)
173         s = re.sub (r'Yget_report', 'report', s)
174         s = re.sub (r'Yget_size', 'size', s)
175         s = re.sub (r'Yget_get', 'get', s)
176         s = re.sub (r'Yget', 'get', s)
177         s = re.sub (r'Yto', 'to', s)
178
179         
180         s = re.sub (r'(bin2dec|bin2hex|dec2bin|hex2bin)_string', r'\1', s)
181         s = re.sub (r'i2hex_string', 'int2hex', s)
182         s = re.sub (r'u2hex_string', 'unsigned2hex', s)
183         s = re.sub (r'i2dec_string', 'int2dec', s)
184
185         # Would this work?
186         s = re.sub (r'split_array', 'split', s)
187         s = re.sub (r'custos_array', 'custodes', s)
188         s = re.sub (r'primitives_array', 'primitives', s)
189         s = re.sub (r'span_array', 'spanners', s)
190         s = re.sub (r'(Pointer|Link|Drul|get|heap|_of|remove)_array',
191                     r'\1_Xarray', s)
192         s = re.sub (r'([a-rt-zA-RT-Z])_array', r'\1s', s)
193         s = re.sub (r'([sS])_array', r'\1es', s)
194         s = re.sub (r'_Xarray', '_array', s)
195         
196         # shields down
197         s = re.sub (r'_pX', r'_p', s)
198         s = re.sub (r'_cX', r'_c', s)
199         s = re.sub (r'_strX', r'_str', s)
200         s = re.sub (r'P_XC', 'P_C', s)
201         s = re.sub (r'Xget_music', 'get_music', s)
202
203         h = open (f + '.ontgaar', 'w')
204         h.write (s)
205         h.close ()
206