mirror of
				https://github.com/flynx/photobook.git
				synced 2025-10-31 19:30:08 +00:00 
			
		
		
		
	better error checking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									91932d3137
								
							
						
					
					
						commit
						5308600350
					
				| @ -91,7 +91,7 @@ IMAGE_PAGE=${IMAGE_PAGE:=imagepage} | |||||||
| # NOTE: the index here corresponds to the number of images found in a  | # NOTE: the index here corresponds to the number of images found in a  | ||||||
| #		spread directory... | #		spread directory... | ||||||
| if [ ${#IMAGE_SPREAD[@]} = 0 ] ; then | if [ ${#IMAGE_SPREAD[@]} = 0 ] ; then | ||||||
| 	if ! [ ${#CFG_IMAGE_SPREAD[@]} = 0 ] ; then | 	if [ ${#CFG_IMAGE_SPREAD[@]} != 0 ] ; then | ||||||
| 		IMAGE_SPREAD=() | 		IMAGE_SPREAD=() | ||||||
| 		for i in ${!CFG_IMAGE_SPREAD[@]} ; do | 		for i in ${!CFG_IMAGE_SPREAD[@]} ; do | ||||||
| 			IMAGE_SPREAD[$i]=${CFG_IMAGE_SPREAD[$i]} | 			IMAGE_SPREAD[$i]=${CFG_IMAGE_SPREAD[$i]} | ||||||
| @ -278,21 +278,23 @@ readCaption(){ | |||||||
| # usage: | # usage: | ||||||
| #	getTemplate SPREAD TYPE | #	getTemplate SPREAD TYPE | ||||||
| # | # | ||||||
| # XXX REVISE... |  | ||||||
| getTemplate(){ | getTemplate(){ | ||||||
| 	local spread=$1 | 	local spread=$1 | ||||||
| 	local type=$2 | 	local name=$2 | ||||||
| 	local template | 	local template | ||||||
| 
 | 
 | ||||||
|  | 	if [[ $name =~ .*\.tex ]] ; then  | ||||||
| 		# already an existing template... | 		# already an existing template... | ||||||
| 	if [[ $type =~ .*\.tex ]] && [ -e "$type" ] ; then | 		if [ -e "$name" ] ; then | ||||||
| 		echo $type | 			echo $name | ||||||
| 			return | 			return | ||||||
| 		fi | 		fi | ||||||
| 
 | 		# normalize... | ||||||
|  | 		name=${name%.tex} | ||||||
|  | 	fi | ||||||
| 	# normalize template name... | 	# normalize template name... | ||||||
| 	if [[ $type =~ .*\.tpl ]] ; then | 	if [[ $name =~ .*\.tpl ]] ; then | ||||||
| 		type=$( echo $type \ | 		name=$( echo $name \ | ||||||
| 			| sed \ | 			| sed \ | ||||||
| 				-e 's/.tpl$//' \ | 				-e 's/.tpl$//' \ | ||||||
| 				-e "s%$spread/%%" \ | 				-e "s%$spread/%%" \ | ||||||
| @ -300,15 +302,16 @@ getTemplate(){ | |||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
| 	# local template... | 	# local template... | ||||||
| 	template=($spread/*-$type.tex) | 	template=($spread/*-$name.tex) | ||||||
| 	if [ ${#template[@]} != 0 ] ; then | 	if [ ${#template[@]} != 0 ] ; then | ||||||
| 		template=${template[0]} | 		template=${template[0]} | ||||||
| 	else | 	else | ||||||
| 		template=($spread/$type.tex) | 		template=($spread/$name.tex) | ||||||
| 	fi | 	fi | ||||||
| 	# global template... | 	# global template... | ||||||
| 	if [ -z $template ] || ! [ -e "$template" ] ; then | 	if [ -z $template ] \ | ||||||
| 		 template="$TEMPLATE_DIR/${type}.tex" | 			|| ! [ -e "$template" ] ; then | ||||||
|  | 		 template="$TEMPLATE_DIR/${name}.tex" | ||||||
| 	fi | 	fi | ||||||
| 	# check if the thing exists... | 	# check if the thing exists... | ||||||
| 	if ! [ -e $template ] ; then | 	if ! [ -e $template ] ; then | ||||||
| @ -378,7 +381,7 @@ populateTemplate(){ | |||||||
| 	local i=0 | 	local i=0 | ||||||
| 	for var in ${slots[@]} ; do | 	for var in ${slots[@]} ; do | ||||||
| 		name=${var//[0-9]/} | 		name=${var//[0-9]/} | ||||||
| 		if ! [ ${name} = "IMAGE" ] ; then | 		if [ ${name} != "IMAGE" ] ; then | ||||||
| 			continue | 			continue | ||||||
| 		fi | 		fi | ||||||
| 
 | 
 | ||||||
| @ -405,7 +408,7 @@ populateTemplate(){ | |||||||
| 	# pass 2: captions... | 	# pass 2: captions... | ||||||
| 	for var in ${slots[@]} ; do | 	for var in ${slots[@]} ; do | ||||||
| 		name=${var//[0-9]/} | 		name=${var//[0-9]/} | ||||||
| 		if ! [ ${name} = "CAPTION" ] ; then | 		if [ ${name} != "CAPTION" ] ; then | ||||||
| 			continue | 			continue | ||||||
| 		fi | 		fi | ||||||
| 
 | 
 | ||||||
| @ -449,7 +452,7 @@ populateTemplate(){ | |||||||
| 	# print out the filled template... | 	# print out the filled template... | ||||||
| 	echo % template: $tpl | 	echo % template: $tpl | ||||||
| 	echo "${text}" | 	echo "${text}" | ||||||
| 	return 0 | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -590,21 +593,29 @@ handleSpread(){ | |||||||
| 					# ignore the rest of the items when we are done  | 					# ignore the rest of the items when we are done  | ||||||
| 					# creating two pages... | 					# creating two pages... | ||||||
| 					[ $C == 2 ] \ | 					[ $C == 2 ] \ | ||||||
| 						&& return 0 | 						&& return | ||||||
| 				done | 				done | ||||||
| 			fi | 			fi | ||||||
| 		fi | 		fi | ||||||
| 		# formatting done... | 		# formatting done... | ||||||
| 		[ -z $template ] \ | 		[ -z $template ] \ | ||||||
| 			&& return 0 | 			&& return | ||||||
| 
 | 
 | ||||||
| 		# XXX check for errors... | 		# resolve the template path... | ||||||
|  | 		local p=$template | ||||||
| 		template=$(getTemplate "$spread" "$template") | 		template=$(getTemplate "$spread" "$template") | ||||||
|  | 
 | ||||||
|  | 		# not found... | ||||||
|  | 		if [ -z $template ] ; then | ||||||
|  | 			echo "%" | ||||||
|  | 			echo "% ERROR: could not resolve template: $p" | tee >(cat >&2) | ||||||
|  | 			echo "%" | ||||||
|  | 		fi | ||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
| 	populateTemplate "$spread" "$template" "${img[@]}" "${txt[@]}" | 	populateTemplate "$spread" "$template" "${img[@]}" "${txt[@]}" | ||||||
| 
 | 
 | ||||||
| 	return 0 | 	return $? | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user