-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcxgo.yml
597 lines (596 loc) · 16.2 KB
/
cxgo.yml
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
vcs: https://github.com/skyrpex/potrace.git
branch: 'master'
root: ./src
out: .
package: gotrace
int_size: 8
ptr_size: 8
use_go_int: true
keep_free: false
do_not_edit: true
define:
- name: VERSION
value: '"dev"'
- name: POTRACE
value: '"potrace"'
- name: MKBITMAP
value: '"potrace"'
idents:
# rename functions and types to be more Go-like
- name: bm_new
rename: NewBitmap
- name: bm_read
rename: bitmapRead
- name: potrace_trace
rename: traceBitmap
- name: potrace_param_default
rename: DefaultConfig
- name: potrace_word
rename: Word
- name: potrace_dpoint_s
rename: DPoint
- name: point_s
rename: Point
- name: potrace_progress_t
alias: true
- name: potrace_progress_s
rename: Progress
- name: progress_t
alias: true
- name: progress_s
rename: progress
- name: potrace_param_s
rename: Config
fields:
- name: turdsize
rename: TurdSize
- name: turnpolicy
rename: TurnPolicy
- name: alphamax
rename: AlphaMax
- name: opticurve
rename: OptiCurve
type: bool
- name: opttolerance
rename: OptTolerance
- name: potrace_curve_s
rename: Curve
fields:
- name: tag
type: slice
- name: c
type: slice
- name: privcurve_s
rename: privCurve
fields:
- name: tag
type: slice
- name: c
type: slice
- name: vertex
type: slice
- name: alpha
type: slice
- name: alpha0
type: slice
- name: beta
type: slice
- name: potrace_path_s
rename: Path
- name: potrace_state_s
rename: traceState
- name: potrace_bitmap_s
rename: Bitmap
fields:
- name: map
type: slice
# looks like a way to introduce private types or something
# alias those types directly
- name: potrace_dpoint_t
alias: true
- name: dpoint_t
alias: true
- name: point_t
alias: true
- name: potrace_state_t
alias: true
- name: potrace_path_t
alias: true
- name: potrace_privpath_t
alias: true
- name: potrace_privpath_s
fields:
- name: pt
type: slice
- name: sums
type: slice
- name: lon
type: slice
- name: po
type: slice
- name: potrace_curve_t
alias: true
- name: potrace_bitmap_t
alias: true
- name: potrace_param_t
alias: true
- name: greymap_s
rename: Greymap
fields:
- name: base
type: slice
- name: map
type: slice
- name: greymap_t
alias: true
- name: gm_sample_t
rename: Sample
- name: gm_new
rename: NewGreymap
- name: gm_read
rename: GreymapRead
- name: imginfo_s
rename: imgInfo
- name: imginfo_t
alias: true
- name: dim_t
alias: true
- name: dim_s
rename: Dim
- name: trans_t
alias: true
- name: trans_s
rename: transT
- name: path_t
alias: true
- name: privpath_t
alias: true
- name: privcurve_t
alias: true
- name: sums_t
alias: true
- name: dpoint3_t
alias: true
- name: POTRACE_TURNPOLICY_BLACK
rename: TurnBlack
- name: POTRACE_TURNPOLICY_WHITE
rename: TurnWhite
- name: POTRACE_TURNPOLICY_LEFT
rename: TurnLeft
- name: POTRACE_TURNPOLICY_RIGHT
rename: TurnRight
- name: POTRACE_TURNPOLICY_MINORITY
rename: TurnMinority
- name: POTRACE_TURNPOLICY_MAJORITY
rename: TurnMajority
- name: POTRACE_TURNPOLICY_RANDOM
rename: TurnRandom
replace:
- regexp: 'libc\.Free\(unsafe\.Pointer\([\w&.\[\]]+\)\)'
- old: 'potrace dev'
new: 'potrace "+Version+"'
- old: 'potracelib dev'
new: 'potracelib "+Version+"'
- old: 'unsafe.Sizeof(Word(0))'
new: 'sizeofWord'
- old: POTRACE_TURNPOLICY_BLACK
new: TurnBlack
- old: POTRACE_TURNPOLICY_WHITE
new: TurnWhite
- old: POTRACE_TURNPOLICY_LEFT
new: TurnLeft
- old: POTRACE_TURNPOLICY_RIGHT
new: TurnRight
- old: POTRACE_TURNPOLICY_MINORITY
new: TurnMinority
- old: POTRACE_TURNPOLICY_MAJORITY
new: TurnMajority
- old: POTRACE_TURNPOLICY_RANDOM
new: TurnRandom
- old: POTRACE_STATUS_OK
new: statusOK
- old: POTRACE_STATUS_INCOMPLETE
new: statusIncomplete
- old: DEFAULT_PAPERWIDTH
new: DefaultPaperWidth
- old: DEFAULT_PAPERHEIGHT
new: DefaultPaperHeight
src_files:
- name: 'bitmap_fnc.c'
content: |
#include <stdbool.h>
#include "bitmap.h"
bool BM_GET_fnc(const potrace_bitmap_t *bm, int x, int y) { return BM_GET(bm, x, y); }
void BM_PUT_fnc(const potrace_bitmap_t *bm, int x, int y, bool b) { BM_PUT(bm, x, y, b); }
files:
- name: auxiliary.h
skip:
- potrace_dpoint_s
- point_s
idents:
- name: interval
rename: aux_interval
- name: backend_svg.c
idents:
- name: info_s
rename: RenderConf
fields:
- name: debug
type: bool
- name: opaque
type: bool
- name: compress
type: bool
replace:
- old: 'func unit('
new: 'func unit(info *RenderConf, '
- old: 'func svg_moveto('
new: 'func svg_moveto(info *RenderConf, '
- old: 'func svg_rmoveto('
new: 'func svg_rmoveto(info *RenderConf, '
- old: 'func svg_lineto('
new: 'func svg_lineto(info *RenderConf, '
- old: 'func svg_curveto('
new: 'func svg_curveto(info *RenderConf, '
- old: 'func svg_path('
new: 'func svg_path(info *RenderConf, '
- old: 'func svg_jaggy_path('
new: 'func svg_jaggy_path(info *RenderConf, '
- old: 'func write_paths_opaque('
new: 'func write_paths_opaque(info *RenderConf, '
- old: 'func write_paths_transparent_rec('
new: 'func write_paths_transparent_rec(info *RenderConf, '
- old: 'func write_paths_transparent('
new: 'func write_paths_transparent(info *RenderConf, '
- old: 'func page_svg('
new: 'func page_svg(info *RenderConf, '
- old: 'func page_gimp('
new: 'func page_gimp(info *RenderConf, '
- old: 'unit(p)'
new: 'unit(info, p)'
- old: 'unit(p1)'
new: 'unit(info, p1)'
- old: 'unit(p2)'
new: 'unit(info, p2)'
- old: 'unit(p3)'
new: 'unit(info, p3)'
- old: 'svg_moveto(fout'
new: 'svg_moveto(info, fout'
- old: 'svg_rmoveto(fout'
new: 'svg_rmoveto(info, fout'
- old: 'svg_lineto(fout'
new: 'svg_lineto(info, fout'
- old: 'svg_curveto(fout'
new: 'svg_curveto(info, fout'
- old: 'svg_jaggy_path(fout'
new: 'svg_jaggy_path(info, fout'
- old: 'svg_path(fout'
new: 'svg_path(info, fout'
- old: 'write_paths_opaque(fout'
new: 'write_paths_opaque(info, fout'
- old: 'write_paths_transparent_rec(fout'
new: 'write_paths_transparent_rec(info, fout'
- old: 'write_paths_transparent(fout'
new: 'write_paths_transparent(info, fout'
- old: 'page_svg(fout'
new: 'page_svg(info, fout'
- name: backend_pdf.c
idents:
- name: ship
rename: pdf_ship
- name: unit
rename: pdf_unit
- name: color_t
rename: pdfColor
- name: info_s
rename: RenderConf
fields:
- name: debug
type: bool
- name: opaque
type: bool
- name: compress
type: bool
- name: intarray_t
alias: true
- name: intarray_s
fields:
- name: data
type: slice
replace:
- old: 'func render0('
new: 'func render0(info *RenderConf, '
- old: 'func render0_opaque('
new: 'func render0_opaque(info *RenderConf, '
- old: 'func pdf_render('
new: 'func pdf_render(info *RenderConf, '
- old: 'func pdf_callbacks('
new: 'func pdf_callbacks(info *RenderConf, '
- old: 'func pdf_unit('
new: 'func pdf_unit(info *RenderConf, '
- old: 'func pdf_coords('
new: 'func pdf_coords(info *RenderConf, '
- old: 'func pdf_moveto('
new: 'func pdf_moveto(info *RenderConf, '
- old: 'func pdf_lineto('
new: 'func pdf_lineto(info *RenderConf, '
- old: 'func pdf_curveto('
new: 'func pdf_curveto(info *RenderConf, '
- old: 'func pdf_path('
new: 'func pdf_path(info *RenderConf, '
- old: 'func pdf_pageinit('
new: 'func pdf_pageinit(info *RenderConf, '
- old: 'func page_pdfpage('
new: 'func page_pdfpage(info *RenderConf, '
- old: 'func page_pdf('
new: 'func page_pdf(info *RenderConf, '
- old: 'func init_pdf('
new: 'func init_pdf(info *RenderConf, '
- old: 'func term_pdf('
new: 'func term_pdf(info *RenderConf, '
- old: 'render0_opaque(plist)'
new: 'render0_opaque(info, plist)'
- old: 'render0(plist)'
new: 'render0(info, plist)'
- old: 'pdf_unit(p'
new: 'pdf_unit(info, p'
- old: 'pdf_coords(p'
new: 'pdf_coords(info, p'
- old: 'pdf_moveto(*'
new: 'pdf_moveto(info, *'
- old: 'pdf_lineto(*'
new: 'pdf_lineto(info, *'
- old: 'pdf_curveto(*'
new: 'pdf_curveto(info, *'
- old: 'pdf_callbacks(fout'
new: 'pdf_callbacks(info, fout'
- old: 'pdf_pageinit(imginfo'
new: 'pdf_pageinit(info, imginfo'
- old: 'pdf_render(plist'
new: 'pdf_render(info, plist'
- old: 'pdf_path(&'
new: 'pdf_path(info, &'
- old: 'p = (*int)(libc.Realloc(unsafe.Pointer(&ar.Data[0]), s*int(unsafe.Sizeof(int(0)))))'
new: 'old := p; p = make([]int, s); copy(p, old)'
- old: 'p *int'
new: 'p []int'
- name: backend_dxf.c
skip:
- iprod
- M_PI
idents:
- name: xprod
rename: xprodf
- name: ship
rename: dxf_ship
- name: interval
rename: aux_interval
replace:
- old: 'func page_dxf('
new: 'func page_dxf(info *RenderConf, '
- name: bbox.c
skip:
- potrace_dpoint_s
- name: bitmap.h
skip:
# it "flips" the bitmap by allowing to index a pointer with negative offsets
# this conflicts with override of that field type to a Go slice
# in any case, we can implement that tiny function on our own
- bm_flip
replace:
# we cannot replace this pattern automatically because it doesn't refer to
# a slice element inside the calloc
- old: 'bm.Map = []Word((*Word)(libc.Calloc(1, int(size))))'
new: 'bm.Map = make([]Word, uintptr(size)/unsafe.Sizeof(Word(0)))'
# TODO: allow changing type of local variables
- old: 'newmap *Word'
new: 'newmap []Word'
- old: 'newmap = (*Word)(libc.Realloc(unsafe.Pointer(&bm.Map[0]), int(newsize)))'
new: 'newmap = make([]Word, uintptr(newsize)/unsafe.Sizeof(Word(0))); copy(newmap, bm.Map)'
- old: 'bm.Map = ([]Word)(newmap)'
new: 'bm.Map = newmap'
- old: 'bm_base(bm) = nil'
new: 'bm.Map = nil'
- old: 'libc.Errno = libc.ENOMEM'
new: 'panic("out of memory")'
- name: bitmap_fnc.c
replace:
- old: 'func BM_GET_fnc(bm *Bitmap, '
new: 'func (bm *Bitmap) Get('
- old: 'func BM_PUT_fnc(bm *Bitmap, '
new: 'func (bm *Bitmap) Put('
- old: 'import "unsafe"'
- name: bitmap_io.c
- name: bitops.h
- name: curve.c
skip:
- potrace_path_s
replace:
- old: '"github.com/gotranspile/cxgo/runtime/libc"'
- old: '"unsafe"'
- old: '}())[0] == nil {'
new: '}()) == nil {'
- old: 'curve.C = [][3]DPoint((*[3]DPoint)(unsafe.Pointer(&make([][3]DPoint, n)[0][0])))'
new: 'curve.C = make([][3]DPoint, n)'
- name: decompose.c
replace:
- old: 'pt1 = (*Point)(libc.Realloc(unsafe.Pointer(pt), size*int(unsafe.Sizeof(Point{}))))'
new: 'pt1 = make([]Point, size); copy(pt1, pt)'
- old: |
pt *Point
pt1 *Point
new: |
pt, pt1 []Point
- old: 'p.Priv.Pt = ([]Point)(pt)'
new: 'p.Priv.Pt = pt'
- old: '(*(*Point)(unsafe.Add(unsafe.Pointer(pt), unsafe.Sizeof(Point{})*uintptr(len_)))).X = x'
new: 'pt[len_].X = x'
- old: '(*(*Point)(unsafe.Add(unsafe.Pointer(pt), unsafe.Sizeof(Point{})*uintptr(len_)))).Y = y'
new: 'pt[len_].Y = y'
- old: '"unsafe"'
# - name: flate.c
# skip:
# - lzw_xship
- name: greymap.c
skip:
- fgetc_ws
- readnum
- readbit
- bmp_info_s
- bmp_info_t
- bmp_count
- bmp_pos
- bmp_readint
- bmp_pad_reset
- bmp_pad
- bmp_forward
- gm_flip
idents:
- name: getsize
rename: gm_getsize
replace:
- old: 'gm.Base = []Sample((*Sample)(libc.Calloc(1, int(size))))'
new: 'gm.Base = make([]Sample, uintptr(size)/unsafe.Sizeof(Sample(0)))'
- old: 'newbase *Sample'
new: 'newbase []Sample'
- old: 'newbase = (*Sample)(libc.Realloc(unsafe.Pointer(&gm.Base[0]), int(newsize)))'
new: 'newbase = make([]Sample, uintptr(newsize)/unsafe.Sizeof(Sample(0))); copy(newbase, gm.Base)'
- old: '([]Sample)(newbase)'
new: 'newbase'
- old: 'libc.Errno = libc.ENOMEM'
new: 'panic("out of memory")'
- name: trace.c
skip:
- COS179
idents:
# collisions with functions defined in other files
# and yes, those functions do different things
- name: iprod
rename: trace_iprod
- name: interval
rename: aux_interval
- name: bezier
rename: trace_bezier
replace:
- old: 'INFTY'
new: 'infty'
- name: trans.c
- name: progress.h
# - name: progress_bar.c
- name: potracelib.c
skip:
- potrace_version
- potrace_state_free
- potrace_param_free
replace:
- old: 'libc.MemCpy(unsafe.Pointer(p), unsafe.Pointer(¶m_default), int(unsafe.Sizeof(Config{})))'
new: '*p = param_default'
- old: '"github.com/gotranspile/cxgo/runtime/libc"'
- name: main.c
skip:
- M_PI
- DEFAULT_DIM_NAME
- DEFAULT_PAPERFORMAT
- info_t
- pageformat_s
- pageformat_t
- pageformat
- turnpolicy
- turnpolicy_s
- turnpolicy_t
- backend
- backend_s
- backend_t
- backend_lookup
- backend_list
- license
- show_defaults
- usage
- parse_dimension
- parse_dimensions
- parse_color
- longopts
- shortopts
- dopts
- my_fopen_read
- my_fopen_write
- my_fclose
- make_outfilename
- process_file
- info
- main
idents:
- name: info_s
rename: RenderConf
fields:
- name: debug
type: bool
- name: opaque
type: bool
- name: compress
type: bool
- name: backend_s
rename: BackendInfo
fields:
- name: pixel
type: bool
- name: fixed
type: bool
replace:
- old: 'func calc_dimensions('
new: 'func calc_dimensions(info *RenderConf, '
- old: '1e+30'
new: 'undef'
- regexp: 'Param\s+\*Config'
- regexp: 'Progress_bar\s+\*progress_bar_t'
- old: |
const (
OPT_TIGHT = iota + 300
OPT_FILLCOLOR
OPT_OPAQUE
OPT_GROUP
OPT_FLAT
OPT_PROGRESS
OPT_TTY
)
- old: |
const DIM_IN = 72
const DIM_CM = 72
const DIM_MM = 72
const DIM_PT = 1
const DEFAULT_DIM = 72
- name: mkbitmap.c
idents:
- name: process_file
rename: processFile
- name: info_s
rename: FileConfig
fields:
- name: invert
type: bool
- name: lowpass
type: bool
- name: highpass
type: bool
- name: linear
type: bool
- name: bilevel
type: bool
skip:
# we don't need the cli itself
- longopts
- shortopts
- dopts
- main
- make_outfilename
- license
- usage
- my_fopen_read
- my_fopen_write
- my_fclose
# we use replace directive to pass it as an arg
- info
- info_t
replace:
- old: 'func processFile('
new: 'func processFile(info *FileConfig, '