From 7ef22ed2f152bf7ebd9edfb7aeddb615d3e9b549 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 21 Mar 2011 21:16:13 +1100 Subject: [PATCH] programs/common.[ch] : Add function program_name(). --- ChangeLog | 6 ++++++ programs/common.c | 17 +++++++++++++++++ programs/common.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index fb6816a9..ee09b881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-21 Erik de Castro Lopo + + * programs/common.[ch] + Add function program_name() which returns the program name minus the path + from argv [0]. + 2011-03-20 Erik de Castro Lopo * src/wav.c diff --git a/programs/common.c b/programs/common.c index 89e512b4..41b8e6e4 100644 --- a/programs/common.c +++ b/programs/common.c @@ -360,3 +360,20 @@ sfe_dump_format_map (void) } ; } /* sfe_dump_format_map */ + +const char * +program_name (const char * argv0) +{ const char * tmp ; + + tmp = strrchr (argv0, '/') ; + argv0 = tmp ? tmp + 1 : argv0 ; + + tmp = strrchr (argv0, '/') ; + argv0 = tmp ? tmp + 1 : argv0 ; + + /* Remove leading libtool name mangling. */ + if (strstr (argv0, "lt-") == argv0) + return argv0 + 3 ; + + return argv0 ; +} /* program_name */ diff --git a/programs/common.h b/programs/common.h index 69cb7a0c..999690d9 100644 --- a/programs/common.h +++ b/programs/common.h @@ -69,3 +69,5 @@ void sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ; int sfe_file_type_of_ext (const char *filename, int format) ; void sfe_dump_format_map (void) ; + +const char * program_name (const char * argv0) ;