summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-11-15 16:26:51 -0500
committerSteven <steven.vasilogianis@gmail.com>2021-11-15 16:26:51 -0500
commit0595afddc6a88980edc6b411b53385e0d8a14f82 (patch)
tree5be22b08df4e725fc292d874470ef65b5076485f
parent9b0a321b43172446c9758248aa5308a6908d2956 (diff)
Retain the order of the variables as they appear in the input scad file when printing the variables with -p. Properly quote OpenSCAD strings.
-rwxr-xr-xcubbies.sh19
-rwxr-xr-xdovetail_test_fits.sh1
-rwxr-xr-xshopenscad.sh16
3 files changed, 25 insertions, 11 deletions
diff --git a/cubbies.sh b/cubbies.sh
index 925b822..d29769d 100755
--- a/cubbies.sh
+++ b/cubbies.sh
@@ -1,8 +1,9 @@
1#!/bin/bash 1#!/bin/bash
2# this script started off generated using shopenscad.sh -s cubbies.scad 2# this script started off generated using "shopenscad.sh -s cubbies.scad"
3 3
4usage() { 4usage() {
5 cat <<EOF 5 cat <<EOF
6Usage:
6$0 cubby-depth cubby-height cubby-width1 [cubby-width2 ... cubby-widthN] 7$0 cubby-depth cubby-height cubby-width1 [cubby-width2 ... cubby-widthN]
7 8
8Examples: 9Examples:
@@ -35,17 +36,17 @@ shopenscad_cmd="./shopenscad.sh cubbies.scad "
35 36
36export $(echo $($shopenscad_cmd -p)) 37export $(echo $($shopenscad_cmd -p))
37# # $ ./shopenscad.sh -p cubbies.scad 38# # $ ./shopenscad.sh -p cubbies.scad
38# tab_padding=5 39# part='"both"'
39# tab_width=10 40# cubby_width=40
40# max_bridge=0
41# cubby_width=150
42# cubby_depth=120 41# cubby_depth=120
43# strut_thickness=5
44# screw_tabs=true
45# cubby_height=90 42# cubby_height=90
46# #part="both" 43# thickness=5
47# thickness=3 44# strut_thickness=5
45# max_bridge=0
46# tab_width=10
47# tab_padding=5
48# tab_tolerance=0.5 48# tab_tolerance=0.5
49# screw_tabs=true
49 50
50cubby_depth=$1; shift 51cubby_depth=$1; shift
51cubby_height=$1; shift 52cubby_height=$1; shift
diff --git a/dovetail_test_fits.sh b/dovetail_test_fits.sh
index 1881392..74dbcdf 100755
--- a/dovetail_test_fits.sh
+++ b/dovetail_test_fits.sh
@@ -1,6 +1,7 @@
1#!/bin/bash 1#!/bin/bash
2usage() { 2usage() {
3 cat <<EOF 3 cat <<EOF
4Usage:
4$0 5$0
5$0 [depth] [tolerance1 tolerance2 .. toleranceN] 6$0 [depth] [tolerance1 tolerance2 .. toleranceN]
6 7
diff --git a/shopenscad.sh b/shopenscad.sh
index eba5e81..be1a9ec 100755
--- a/shopenscad.sh
+++ b/shopenscad.sh
@@ -158,6 +158,7 @@ main()
158 val_sep="-" 158 val_sep="-"
159 var_sep="," 159 var_sep=","
160 declare -A SCAD 160 declare -A SCAD
161 declare -a scad_var_order
161 162
162 while IFS= read -r line; do 163 while IFS= read -r line; do
163 [ "$line" ] || continue; 164 [ "$line" ] || continue;
@@ -173,6 +174,7 @@ main()
173 fi 174 fi
174 175
175 if [ "$var" ] && [ "$val" ]; then 176 if [ "$var" ] && [ "$val" ]; then
177 scad_var_order+=($var);
176 SCAD[$var]="$val" 178 SCAD[$var]="$val"
177 output_params+="-D '$var=$val' " 179 output_params+="-D '$var=$val' "
178 VALUES+="$(val_to_filename "$val")${val_sep}" 180 VALUES+="$(val_to_filename "$val")${val_sep}"
@@ -182,8 +184,17 @@ main()
182 strip_multiline_comments |strip_nonassignments |strip_trailing_semicolon) 184 strip_multiline_comments |strip_nonassignments |strip_trailing_semicolon)
183 185
184 if [ "$PRINT_VARS" ]; then 186 if [ "$PRINT_VARS" ]; then
185 for k in "${!SCAD[@]}"; do 187 for k in "${scad_var_order[@]}"; do
186 echo ${k}=${SCAD[$k]} 188 # if the value is an OpenSCAD string, it needs to be wrapped in
189 # quotes
190 if [ '"' == "${SCAD[$k]:0:1}" ]; then
191 line="${k}='${SCAD[$k]}'"
192 elif [ "'" == "${SCAD[$k]:0:1}" ]; then
193 line=${k}="\"${SCAD[$k]}\""
194 else
195 line="${k}=${SCAD[$k]}"
196 fi
197 echo $line
187 done 198 done
188 exit 199 exit
189 fi 200 fi
@@ -228,3 +239,4 @@ EOF
228} 239}
229 240
230main "$@" 241main "$@"
242#parse_options "$@"