File: setcompat.c

package info (click to toggle)
freeciv 3.2.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 286,492 kB
  • sloc: ansic: 484,452; cpp: 37,766; sh: 10,374; makefile: 7,425; python: 2,938; xml: 652; sed: 11
file content (87 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***********************************************************************
 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************/

#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif

/* ANSI */
#include <stdlib.h>

/* utility */
#include "support.h"

/* server */
#include "settings.h"

#include "setcompat.h"

struct set_name_compat {
  const char *old_name;
  const char *new_name;
};

static struct set_name_compat set_name_compat_S3_1_to_S3_2[] =
{
  { "spaceship_travel_time", "spaceship_travel_pct" },
  { NULL, NULL }
};


/**********************************************************************//**
  Version agnostic helper function to find new name of a setting when
  updating between two versions.
**************************************************************************/
static const char *setcompat_name_generic(const char *old_name,
                                          struct set_name_compat *compats)
{
  int i;

  for (i = 0; compats[i].old_name != NULL; i++) {
    if (!fc_strcasecmp(old_name, compats[i].old_name)) {
      return compats[i].new_name;
    }
  }

  return old_name;
}

/**********************************************************************//**
  Find a 3.2 name of the setting with the given 3.1 name.
**************************************************************************/
const char *setcompat_S3_2_name_from_S3_1(const char *old_name)
{
  return setcompat_name_generic(old_name, set_name_compat_S3_1_to_S3_2);
}

/**********************************************************************//**
  Find a 3.2 value of the setting with the given 3.1 value.
**************************************************************************/
const char *setcompat_S3_2_val_from_S3_1(struct setting *pset,
                                         const char *val)
{
  if (!fc_strcasecmp("compresstype", setting_name(pset))
      && !fc_strcasecmp("BZIP2", val)) {
#ifdef FREECIV_HAVE_LIBZSTD
    return "ZSTD";
#elif FREECIV_HAVE_LIBLZMA
    return "XZ";
#elif FREECIV_HAVE_LIBZ
    return "LIBZ";
#else
    return "PLAIN";
#endif
  }

  return NULL;
}