addrom

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

commit 6be8d4fdfc2ab2471371e4ec763dd5782971209d
parent 6a10f2f0461b89ad522d3e5bcf1479f5270c8ab3
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 10 Nov 2015 17:09:42 +0100

Add shell script tool for adding rom from a csv file

Diffstat:
addrom-processcsv.sh | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/addrom-processcsv.sh b/addrom-processcsv.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +ADDROMCMD="addrom" + +OPTIND=1 +iflag= +oflag= +ifile= +ofile= + +usage() +{ + printf "usage: %s %s %s %s %s\n" "$(basename $0)" \ + "-i input-list-file" "[-o output-list-file]" \ + "[--]" "csv-game-list-file" + printf " %s %s %s %s %s\n" "$(basename $0)" \ + "[-i input-list-file]" "-o output-list-file" \ + "[--]" "csv-game-list-file" +} + +while getopts "i:o:" flag +do + case "$flag" in + i) iflag=1 + ifile="$OPTARG" + ;; + o) oflag=1 + ofile="$OPTARG" + ;; + \?) usage + ;; + esac +done + +shift "$((OPTIND-1))" +[ "$1" = "--" ] && shift +csvfile="$*" + +if ([ -z "$iflag" ] && [ -z "$oflag" ]) || [ "$#" -ne 1 ] || \ + [ -e "$ofile" ] || ([ -n "$ifile" ] && [ ! -f "$ifile" ]) || \ + [ ! -f "$csvfile" ] +then + usage + exit 1 +fi + +if [ -n "$ofile" ] +then + if [ -n "$ifile" ] + then + cp "$ifile" "$ofile" + else + dd if=/dev/zero of="$ofile" bs=16 count=1 > /dev/null 2>&1 + fi + ifile="$ofile" +fi + +while IFS=',' read -r chname enname romname +do + if [ -z "$romname" ] + then + printf "Skipping \"%s\", \"%s\": rom name empty\n" \ + "$chname" "$enname" + fi + [ -n "$chname" ] && chopt="-c ${chname}" || chopt= + [ -n "$enname" ] && enopt="-e ${enname}" || enopt= + + $ADDROMCMD -i "$ifile" "$chopt" "$enopt" -r "$romname" +done < "$csvfile"