#ifdef HAVE_CONFIG_H #include #endif #include #include #include #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() */