99# env WARNING_NO_IMAGE
1010# env WARNING_NO_PINS
1111# env WARNING_DUPE
12+ # env WARNING_PARSE
1213# same options as WARNINGS
1314
1415if [ " $DEBUG " = " true" ]; then
@@ -18,6 +19,7 @@ if [ "$DEBUG" = "true" ]; then
1819 echo " WARNING_NO_IMAGE: $WARNING_NO_IMAGE "
1920 echo " WARNING_NO_PINS: $WARNING_NO_PINS "
2021 echo " WARNING_DUPE: $WARNING_DUPE "
22+ echo " WARNING_PARSE: $WARNING_PARSE "
2123fi
2224
2325SCRIPTDIR=$( dirname " $0 " )
@@ -52,31 +54,34 @@ if [ $(echo "$CONNECTORS" | grep -v ^$ | wc -l) -eq 0 ]; then
5254fi
5355
5456FILES=$( for f in $CONNECTORS ; do
55- ORDER=$( yq e ' .info.order' " $f " )
56- echo " $f $ORDER "
57+ ORDER=$( yq e ' .info.order' " $f " )
58+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $f "
59+ echo " $f $ORDER "
5760done)
5861CONNECTORS=$( echo " $FILES " | sort -k2 | cut -d ' ' -f 1)
5962
6063# Make a temp directory for symlinks to actual files.
6164mkdir -p pinoutstmp
6265
66+
6367for c in $CONNECTORS ; do
6468 echo " Processing: $c "
65- if [ $( yq e ' .pins.[].pin' " $c " | wc -c) -lt 1 ] ; then
66- if ! handle_warning " $WARNING_NO_PINS " " WARNING: No pins found in definition $c " ; then continue ; fi
67- fi
69+ PINCNT= $( yq e ' .pins.[].pin' " $c " | wc -c)
70+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
71+ [ " $PINCNT " -gt 0 ] || handle_warning " $WARNING_NO_PINS " " WARNING: No pins found in definition $c " || continue
6872 DUPES=$( yq e ' .pins.[].pin' " $c " | grep -v " null" | sort | uniq -d | tr -d ' \n' )
69- if [ -n " $DUPES " ]; then
70- if ! handle_warning " $WARNING_DUPE " " WARNING: Duplicate pins in $c : $DUPES " ; then continue ; fi
71- fi
73+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
74+ [ -z " $DUPES " ] || handle_warning " $WARNING_DUPE " " WARNING: Duplicate pins in $c : $DUPES " || continue
7275 POSDUPES=$( yq e ' .info.pins.[].pin' " $c " | grep -v " null" | sort | uniq -d | tr -d ' \n' )
76+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
7377 POSDUPES+=$( yq e ' .info.image.pins.[].pin' " $c " | grep -v " null" | sort | uniq -d | tr -d ' \n' )
74- if [ -n " $POSDUPES " ]; then
75- if ! handle_warning " $WARNING_DUPE " " WARNING: Duplicate pin positionss in $c : $POSDUPES " ; then continue ; fi
76- fi
78+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
79+ [ -z " $POSDUPES " ] || handle_warning " $WARNING_DUPE " " WARNING: Duplicate pin positionss in $c : $POSDUPES " || continue
7780 # Get the directory and title, if they exist
7881 DIRECTORY=$( yq e ' .info.directory' " $c " )
82+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
7983 TITLE=$( yq e ' .info.title' " $c " )
84+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
8085 # Build the temp path, removing leading ./ and /
8186 DIR=" pinoutstmp/" $( dirname " $c " | sed -e ' s/^\.\///' -e ' s/^\///' )
8287 # If we have a directory field
@@ -149,35 +154,41 @@ for c in $CONNECTORS; do
149154 if [ " $DEBUG " = " true" ]; then
150155 echo " File Name: $NAME "
151156 fi
152- if [ " $( yq e ' .info.cid' " $c " ) " == " null " ] ; then
153- if ! handle_warning " $WARNING_NO_CID " " WARNING: Missing yaml cid field in info section of $c " ; then continue ; fi
154- fi
157+ CID= $( yq e ' .info.cid' " $c " )
158+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
159+ [ " $CID " != " null " ] || handle_warning " $WARNING_NO_CID " " WARNING: Missing yaml cid field in info section of $c " || continue
155160 IMG=$( yq e ' .info.image.file' " $c " )
156- if [ $? -ne 0 ] || [ " $IMG " = " null" ]; then
161+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
162+ if [ " $IMG " = " null" ]; then
157163 IMP=$( yq e ' .info.image.import' " $c " )
158- if [ $? -ne 0 ] || [ " $IMP " = " null" ]; then
159- if ! handle_warning " $WARNING_NO_IMAGE " " WARNING: $c missing image" ; then continue ; fi
164+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
165+ if [ " $IMP " = " null" ]; then
166+ handle_warning " $WARNING_NO_IMAGE " " WARNING: $c missing image" || continue
160167 else
161168 IMG=$( yq e ' .image.file' " $( dirname " $c " ) /$IMP " )
169+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
162170 echo " Image: $IMG "
163171 cp " $( dirname $( dirname " $c " ) /$IMP ) /$IMG " " $DIR "
164172 yq --inplace ea ' .info.image = .image | select(fi == 0)' " $c " " $( dirname " $c " ) /$IMP "
173+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
165174 fi
166175 else
167176 echo " Image: $IMG "
168177 cp " $( dirname " $c " ) /$IMG " " $DIR "
169178 # Patch legacy YAMLs by moving .info.pins to .info.image.pins
170179 yq --inplace e ' .info.image.pins = .info.pins' " $c "
180+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
171181 yq --inplace e ' del(.info.pins)' " $c "
182+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
172183 fi
184+ JSON=$( yq -o=json e " $c " )
185+ [ $? -eq 0 ] || handle_warning " $WARNING_PARSE " " WARNING: parse error in definition $c " || continue
173186 if [ -f " $DIR /index.html" ]; then
174- bash " $SCRIPTDIR " /append.sh " $( yq -o=json e " $c " ) " " $DIR /index.html"
187+ bash " $SCRIPTDIR " /append.sh " $JSON " " $DIR /index.html"
175188 else
176- bash " $SCRIPTDIR " /gen.sh " $( yq -o=json e " $c " ) " " $DIR /index.html"
177- fi
178- if [ $? -ne 0 ]; then
179- if ! handle_warning " unset" " WARNING: Failed to generate or append to pinout" ; then continue ; fi
189+ bash " $SCRIPTDIR " /gen.sh " $JSON " " $DIR /index.html"
180190 fi
191+ [ $? -eq 0 ] || handle_warning " unset" " WARNING: Failed to generate or append to pinout" || continue
181192done
182193
183194# Delete all symbolic links and empty directories from the temp dir.
@@ -190,7 +201,7 @@ find pinoutstmp -type d -empty -delete
190201find pinouts/ -type f -name ' index.html' -print0 | while IFS= read -r -d ' ' f; do
191202 DUPES=$( grep " cid\" : " " $f " | uniq -d | tr -d ' \n' )
192203 if [ -n " $DUPES " ]; then
193- if ! handle_warning " $WARNING_DUPE " " WARNING: Duplicate cids in $f : $DUPES " ; then continue ; fi
204+ handle_warning " $WARNING_DUPE " " WARNING: Duplicate cids in $f : $DUPES " || continue
194205 fi
195206done
196207
0 commit comments