diff options
| author | kx <kx@radix-linux.su> | 2026-10-09 18:00:15 +0300 |
|---|---|---|
| committer | kx <kx@radix-linux.su> | 2026-10-09 18:00:15 +0300 |
| commit | 065da3509019b15dd0e678072e6be629e5330bef (patch) | |
| tree | 69c934c9e786ac048b4fbe8f4c4c5571661521f4 /utils/mcpu-version.c | |
| parent | d130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff) | |
| download | libmcpu-0.4.0.tar.xz | |
Version 0.4.00.4.0
Diffstat (limited to 'utils/mcpu-version.c')
| -rw-r--r-- | utils/mcpu-version.c | 67 |
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() */ |
