summaryrefslogtreecommitdiff
path: root/utils/mcpu-version.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/mcpu-version.c')
-rw-r--r--utils/mcpu-version.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/utils/mcpu-version.c b/utils/mcpu-version.c
new file mode 100644
index 0000000..74e0a83
--- /dev/null
+++ b/utils/mcpu-version.c
@@ -0,0 +1,67 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "mcpu-version.h"
+
+static const char *
+program_basename( const char *name )
+{
+ const char *p;
+
+ if( name == NULL || *name == 0 )
+ return( "mcpu" );
+
+ p = name + strlen( name );
+ while( p != name && p[-1] != '/' ) --p;
+ return( p );
+
+} /* End of program_basename() */
+
+
+int
+mcpu_version_parse_option( const char *option, mcpu_version_action *action )
+{
+ if( option == NULL || action == NULL )
+ return( 0 );
+
+ if( !strcmp( option, "--version" ) )
+ {
+ *action = MCPU_VERSION_FULL;
+ return( 1 );
+ }
+
+ if( !strcmp( option, "--dump-version" ) )
+ {
+ *action = MCPU_VERSION_DUMP;
+ return( 1 );
+ }
+
+ return( 0 );
+
+} /* End of mcpu_version_parse_option() */
+
+
+int
+mcpu_version_print( const char *progname, mcpu_version_action action )
+{
+ int rc;
+
+ if( action == MCPU_VERSION_FULL )
+ rc = printf( "%s (MCPU) %s\n", program_basename( progname ),
+ PACKAGE_VERSION );
+ else if( action == MCPU_VERSION_DUMP )
+ rc = printf( "%s\n", PACKAGE_VERSION );
+ else
+ {
+ errno = EINVAL;
+ return( -1 );
+ }
+
+ return( rc < 0 ? -1 : 0 );
+
+} /* End of mcpu_version_print() */