-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_input_json.sh
executable file
·69 lines (58 loc) · 1.82 KB
/
generate_input_json.sh
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
#!/bin/bash
# Define paths
circom_file_path="./circuit.circom"
output_file_path="./input.json"
# Check if the circom file exists
if [ ! -f "$circom_file_path" ]; then
echo -e "\033[91mThe file $circom_file_path does not exist.\033[0m"
exit 1
fi
# Function to extract inputs and prepare JSON content
prepare_json_content() {
local circom_file=$1
local json_content="{"
local first_entry=true
while IFS= read -r line; do
if [[ $line =~ signal\ input\ ([a-zA-Z0-9_]+)(\[([0-9]+)\])?\; ]]; then
local input_name="${BASH_REMATCH[1]}"
local array_size="${BASH_REMATCH[3]}"
if [ "$first_entry" = true ]; then
json_content+="\n"
first_entry=false
else
json_content+=",\n"
fi
if [ -n "$array_size" ]; then
# Handle array inputs
json_content+="\t\"$input_name\": [$(printf '0,'%.0s $(seq 1 $((array_size-1))))0]"
else
# Handle single inputs
json_content+="\t\"$input_name\": 0"
fi
fi
done < "$circom_file"
json_content+="\n}"
echo -e "$json_content"
}
# Check if the output file already exists
if [ -f "$output_file_path" ]; then
echo -n "input.json already exists. Do you want to override it? (y/n): "
read -r choice
case "$choice" in
y|Y )
;;
n|N )
echo "Exiting without changes."
exit 0
;;
* )
echo "Invalid option. Exiting."
exit 1
;;
esac
fi
# Prepare JSON content
json_content=$(prepare_json_content "$circom_file_path")
# Write to the output file
echo -e "$json_content" > "$output_file_path"
echo "$output_file_path has been updated."