summaryrefslogtreecommitdiff
path: root/utils/mcpu-version.c
blob: 74e0a8326ebb9388d1abdf604e8e55042b51c661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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() */