This makes parsing options less complicated and easier to extend. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@xxxxxxxxx> --- tools/aubdump.c | 32 ++++++++++++++++++++++---------- tools/intel_aubdump.in | 22 +++++++++++++++------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tools/aubdump.c b/tools/aubdump.c index a2ac7f1..e82b514 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -430,26 +430,38 @@ static void maybe_init(void) { static bool initialized = false; - const char *args = getenv("INTEL_AUBDUMP_ARGS"); + FILE *config; + char *key, *value; if (initialized) return; initialized = true; - if (sscanf(args, "verbose=%d;file=%m[^;];device=%i", - &verbose, &filename, &device) != 3) - filename = strdup("intel.aub"); - fail_if(filename == NULL, "intel_aubdump: out of memory\n"); + config = fdopen(3, "r"); + while (fscanf(config, "%m[^=]=%m[^\n]\n", &key, &value) != EOF) { + if (!strcmp(key, "verbose")) { + verbose = 1; + } else if (!strcmp(key, "device")) { + device = atoi(value); + device_override = true; + } else if (!strcmp(key, "file")) { + filename = value; + file = fopen(filename, "w+"); + fail_if(file == NULL, + "intel_aubdump: failed to open file '%s'\n", + filename); + } else { + fprintf(stderr, "intel_aubdump: unknown option '%s'\n", key); + } - if (device) - device_override = true; + free(key); + free(value); + } + fclose(config); bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); fail_if(bos == NULL, "intel_aubdump: out of memory\n"); - - file = fopen(filename, "w+"); - fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename); } int diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in index feee23a..445b60f 100644 --- a/tools/intel_aubdump.in +++ b/tools/intel_aubdump.in @@ -21,29 +21,38 @@ EOF exit 0 } -verbose=0 -device=0 +args="" +command="" +file="" + +function add_arg() { + arg=$1 + args="$args$arg\n" +} while true; do case "$1" in -o) file=$2 + add_arg "file=${f:-$(basename ${f}).aub}" shift 2 ;; -v) - verbose=1 + add_arg "verbose=1" shift 1 ;; -o*) file=${1##-o} + add_arg "file=${file:-$(basename ${file}).aub}" shift ;; --output=*) file=${1##--output=} + add_arg "file=${file:-$(basename ${file}).aub}" shift ;; --device=*) - device=${1##--device=} + add_arg "device=${1##--device=}" shift ;; --help) @@ -66,12 +75,11 @@ done [ -z $1 ] && show_help -file=${file:-$(basename $1).aub} +[ -z $file ] && add_arg "file=intel.aub" prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \ - INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \ - exec -- "$@" + exec -- "$@" 3<<< `printf '%b' "$args"` -- 2.9.3 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx