forked from AlgorithmicBotany/vlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_libobj.sh
More file actions
executable file
·50 lines (42 loc) · 1.92 KB
/
Copy pathfix_libobj.sh
File metadata and controls
executable file
·50 lines (42 loc) · 1.92 KB
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
#!/bin/bash
DIR="Rayshade/libray/libobj"
# Loop through all .c files in the directory
for file in $DIR/*.c; do
# Skip box.c since we manually fixed it
if [[ "$file" == *"/box.c" ]]; then
echo "Skipping $file..."
continue
fi
echo "Processing $file..."
# A. Convert K&R headers to ANSI
# Handles: func(a, b) Vector *a; Ray *b; { ... }
# This sed script looks for function definitions and moves types inside
sed -i 's/int \([A-Za-z0-9]*\)(\([^)]*\))/\nint \1(\2)/g' "$file"
# B. Add explicit casts for Method Registration
# Prevents "incompatible pointer type" errors in GCC 14
sed -i 's/->intersect = /->intersect = (int (*)())/g' "$file"
sed -i 's/->normal = /->normal = (int (*)())/g' "$file"
sed -i 's/->enter = /->enter = (int (*)())/g' "$file"
sed -i 's/->bounds = /->bounds = (void (*)())/g' "$file"
sed -i 's/->stats = /->stats = (void (*)())/g' "$file"
sed -i 's/->uv = /->uv = (void (*)())/g' "$file"
# C. Fix "mindist/maxdist" pointer dereferencing
# Since we changed prototypes to Float *, we must dereference for comparisons
sed -i 's/ < mindist/ < *mindist/g' "$file"
sed -i 's/ < maxdist/ < *maxdist/g' "$file"
sed -i 's/ > maxdist/ > *maxdist/g' "$file"
# D. Clean up potential double-casts if script is re-run
sed -i 's/(int (\*)())(int (\*)())/(int (\*)())/g' "$file"
sed -i 's/(void (\*)())(void (\*)())/(void (\*)())/g' "$file"
done
echo "Cleaning up header files..."
# Standardize headers to allow empty parameter lists to be treated as generic
sed -i 's/extern int \(.*\)();/extern int \1();/g' $DIR/*.h
echo "Fixing specific pointer logic in intersection routines..."
for shape in cone cylinder sphere torus disc hf; do
target="$DIR/$shape.c"
if [ -f "$target" ]; then
sed -i 's/\*mindist = dist/ *mindist = dist/g' "$target"
sed -i 's/\*maxdist = dist/ *maxdist = dist/g' "$target"
fi
done