Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)
Home

[Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 17 Oct 2001 00:45:11 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Oct 16, 2001 at 02:47:16PM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
> +static const char hex_chars[] = "0123456789abcdef";
>  static const char terrain_chars[] = "adfghjm prstu";

> +#define bin2ascii_hex(value, halfbyte_wanted)       \
> +  hex_chars[((value) >> ((halfbyte_wanted) * 4)) & 0xf]
> +

> +static int ascii_hex2bin(char ch, int offset)
> +{
> +  if (!isxdigit(ch)) {
> +    if (ch == ' ') {
> +      return 0; /* sane value */
> +    } else {
> +      freelog(LOG_FATAL, "unknown hex value ('%c')", ch);
> +      exit(1);
> +    }
> +  }
> +  return (ch-(isdigit(ch) ? '0' : 'a'-10)) << (offset * 4);
> +}

> +static int char2terrain(char ch)
> +{
> +  char *pch = strchr(terrain_chars, ch);
> +  if(!pch) {
> +    freelog(LOG_FATAL, "unknown terrain type: '%c'", ch);
> +    exit(1);
> +  }
> +  return pch - terrain_chars;
> +}

This still leaves the use-char-array-and-strchar-vs-if-or-?: issue.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Transported to a surreal landscape, a young girl kills the first woman
  she meets and then teams up with three complete strangers to kill again."
    -- TV listing for the Wizard of Oz in the Marin Independent Journal


[Prev in Thread] Current Thread [Next in Thread]