addrom

Simple tool for adding a rom entry to a Pandora's Box 3 list.dat
Log | Files | Refs | README | LICENSE

addrom-processcsv.sh (1302B)


      1 #!/bin/sh
      2 
      3 ADDROMCMD="addrom"
      4 
      5 OPTIND=1
      6 cflag=0
      7 eflag=0
      8 iflag=
      9 ifile=
     10 oflag=
     11 ofile=
     12 
     13 usage()
     14 {
     15 	printf "usage: %s %s %s %s %s %s %s\n" "$(basename $0)"    \
     16 	    "-c" "-e" "-i input-list-file" "[-o output-list-file]" \
     17 	    "[--]" "csv-game-list-file"
     18 	printf "       %s %s %s %s %s %s %s\n" "$(basename $0)"    \
     19 	    "-c" "-e" "[-i input-list-file]" "-o output-list-file" \
     20 	    "[--]" "csv-game-list-file"
     21 }
     22 
     23 while getopts "cei:o:" flag
     24 do
     25 	case "$flag" in
     26 	c)	cflag=1
     27 		;;
     28 	e)	eflag=1
     29 		;;
     30 	i)	iflag=1
     31 		ifile="$OPTARG"
     32 		;;
     33 	o)	oflag=1
     34 		ofile="$OPTARG"
     35 		;;
     36 	\?)	usage
     37 		;;
     38 	esac
     39 done
     40 
     41 shift "$((OPTIND-1))"
     42 [ "$1" = "--"  ] && shift
     43 csvfile="$*"
     44 
     45 if ([ -z "$iflag" ] && [ -z "$oflag" ]) || [ "$#" -ne 1 ] ||    \
     46    [ -e "$ofile" ] || ([ -n "$ifile" ] && [ ! -f "$ifile" ]) || \
     47    [ ! -f "$csvfile" ]
     48 then
     49 	usage
     50 	exit 1
     51 fi
     52 
     53 if [ -n "$ofile" ]
     54 then
     55 	if [ -n "$ifile" ]
     56 	then
     57 		cp "$ifile" "$ofile"
     58 	else
     59 		dd if=/dev/zero of="$ofile" bs=16 count=1 > /dev/null 2>&1
     60 	fi
     61 	ifile="$ofile"
     62 fi
     63 
     64 while IFS=',' read -r chname enname romname
     65 do
     66 	if [ -z "$romname" ]
     67 	then
     68 		printf "Skipping \"%s\", \"%s\": rom name empty\n" \
     69 		    "$chname" "$enname"
     70 	fi
     71 	[ "$cflag" -eq 1 ] || chname=
     72 	[ "$eflag" -eq 1 ] || enname=
     73 
     74 	$ADDROMCMD -i "$ifile" -c "$chname" -e "$enname" -r "$romname"
     75 done < "$csvfile"