use enums, fix typecasts

This commit is contained in:
Enno Rehling 2011-03-07 22:31:06 -08:00
parent 496aa22e65
commit 04b3d7ff45
13 changed files with 30 additions and 82 deletions

View File

@ -1438,7 +1438,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
perror(filename);
return -1;
} else if (enc == XML_CHAR_ENCODING_UTF8) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, F);
}

View File

@ -1495,7 +1495,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
}
if (enc == XML_CHAR_ENCODING_UTF8) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, F);
}
@ -2141,7 +2141,7 @@ report_plaintext(const char *filename, report_context * ctx,
return -1;
}
if (enc == XML_CHAR_ENCODING_UTF8) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, F);
}

View File

@ -149,7 +149,7 @@ void report_summary(summary * s, summary * o, boolean full)
return;
#ifdef SUMMARY_BOM
else {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, F);
}
#endif

View File

@ -3673,7 +3673,7 @@ static battle *make_battle(region * r)
if (!bdebug)
log_error(("battles cannot be debugged\n"));
else {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, bdebug);
fprintf(bdebug, "In %s findet ein Kampf stattactics:\n", rname(r,
default_locale));

View File

@ -22,7 +22,7 @@ extern "C" {
#define SMF_RIDING (1<<2) /* Bonus für berittene - an der rasse */
typedef struct skill {
unsigned int id:8;
int id:8;
unsigned int level:8;
unsigned int weeks:8;
unsigned int old:8;

View File

@ -60,7 +60,7 @@ static int txt_w_flt(struct storage *store, float arg)
static float txt_r_flt(struct storage *store)
{
double result;
fscanf((FILE *) store->userdata, "%lf", &result);
fscanf((FILE *) store->userdata, "%f", &result);
return (float)result;
}
@ -135,7 +135,7 @@ static int txt_open(struct storage *store, const char *filename, int mode)
FILE *F = fopen(filename, modes[mode]);
store->userdata = F;
if (F) {
char utf8_bom[4] = { (char)0xef, (char)0xbb, (char)0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
if (mode == IO_READ) {
char token[8];
/* recognize UTF8 BOM */
@ -154,7 +154,7 @@ static int txt_open(struct storage *store, const char *filename, int mode)
store->version = atoi(token);
}
} else if (store->encoding == XML_CHAR_ENCODING_UTF8) {
fputs(utf8_bom, F);
fputs((const char*)utf8_bom, F);
fprintf(F, "%d\n", RELEASE_VERSION);
}
}

View File

@ -31,10 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/variant.h>
typedef short terrain_t;
typedef short direction_t;
typedef short race_t;
typedef short magic_t;
typedef short skill_t;
typedef short typ_t;
typedef short item_t;
typedef unsigned int spellid_t;
@ -76,8 +73,7 @@ typedef struct ursprung {
/* ----------------- Befehle ----------------------------------- */
typedef unsigned char keyword_t;
enum {
typedef enum {
K_KOMMENTAR,
K_BANNER,
K_WORK,
@ -148,8 +144,8 @@ enum {
K_PROMOTION,
K_PAY,
MAXKEYWORDS,
NOKEYWORD = (keyword_t) - 1
};
NOKEYWORD = -1
} keyword_t;
/* ------------------ Status von Einheiten --------------------- */
@ -165,8 +161,7 @@ enum {
/* ----------------- Parameter --------------------------------- */
typedef unsigned char param_t;
enum {
typedef enum {
P_LOCALE,
P_ANY,
P_EACH,
@ -218,8 +213,8 @@ enum {
P_XELAEN,
P_ALLIANCE,
MAXPARAMS,
NOPARAM = (param_t) - 1
};
NOPARAM = -1
} param_t;
typedef enum { /* Fehler und Meldungen im Report */
MSG_BATTLE,
@ -268,7 +263,7 @@ enum {
/* ------------------ Talente ---------------------------------- */
enum {
typedef enum {
SK_ALCHEMY,
SK_CROSSBOW,
SK_MINING,
@ -299,12 +294,12 @@ enum {
SK_STAMINA,
SK_WEAPONLESS,
MAXSKILLS,
NOSKILL = (skill_t) - 1
};
NOSKILL = -1
} skill_t;
/* ------------- Typ von Einheiten ----------------------------- */
enum {
typedef enum {
RC_DWARF, /* 0 - Zwerg */
RC_ELF,
RC_GOBLIN = 3,
@ -363,11 +358,11 @@ enum {
RC_CLONE,
MAXRACES,
NORACE = (race_t) - 1
};
NORACE = -1
} race_t;
/* Richtungen */
enum {
typedef enum {
D_NORTHWEST,
D_NORTHEAST,
D_EAST,
@ -377,8 +372,8 @@ enum {
MAXDIRECTIONS,
D_PAUSE,
D_SPECIAL,
NODIRECTION = (direction_t) - 1
};
NODIRECTION = -1
} direction_t;
#define DONT_HELP 0
#define HELP_MONEY 1 /* Mitversorgen von Einheiten */

View File

@ -115,9 +115,6 @@
<ClInclude Include="bindings\bindings.h" />
<ClInclude Include="bindings\helpers.h" />
</ItemGroup>
<ItemGroup>
<None Include="Jamfile" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -89,7 +89,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Jamfile" />
</ItemGroup>
</Project>

View File

@ -155,7 +155,7 @@ void score(void)
sprintf(path, "%s/score", basepath());
scoreFP = fopen(path, "w");
if (scoreFP) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
faction *f;
fwrite(utf8_bom, 1, 3, scoreFP);
for (f = factions; f; f = f->next)
@ -176,7 +176,7 @@ void score(void)
sprintf(path, "%s/score.alliances", basepath());
scoreFP = fopen(path, "w");
if (scoreFP) {
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
fwrite(utf8_bom, 1, 3, scoreFP);
fprintf(scoreFP, "# alliance:factions:persons:score\n");

View File

@ -16,8 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#define _GNU_SOURCE
#ifndef CONFIG_H
#define CONFIG_H

View File

@ -30,45 +30,6 @@ INLINE_FUNCTION unsigned int hashstring(const char *s)
return key & 0x7FFFFFFF;
}
/*
static const char *
escape_string_inplace(char * buffer, unsigned int len, unsigned int offset)
{
#define MAXQUOTES 32
char * o;
char * d[MAXQUOTES+1];
int i = 0;
o = strchr(buffer, '"');
if (!o) {
return buffer;
}
while (*o && i<MAXQUOTES) {
char * next = strchr(o, '"');
d[i++] = o;
o = next?next:(o+strlen(o));
}
d[i] = o;
if (i<MAXQUOTES) {
// more than 32 hits! must go recursive
char * start = d[i];
unsigned int nlen = len - (start-buffer) - MAXQUOTES;
escape_string_inplace(start, nlen, MAXQUOTES);
}
o[i] = '\0';
while (--i>0) {
const char * src = d[i];
char * dst = d[i] + i + offset;
size_t mlen = d[i+1] - d[i];
memmove(dst--, src, mlen);
*dst = '\\';
}
return buffer;
}
*/
INLINE_FUNCTION const char *escape_string(const char *str, char *buffer,
unsigned int len)
{

View File

@ -68,25 +68,25 @@ int unicode_utf8_tolower(utf8_t * op, size_t outlen, const utf8_t * ip)
}
int
unicode_latin1_to_utf8(utf8_t * out, size_t * outlen, const char *in,
unicode_latin1_to_utf8(utf8_t * dst, size_t * outlen, const char *in,
size_t * inlen)
{
int is = (int)*inlen;
int os = (int)*outlen;
const char *ip = in;
utf8_t *op = out;
unsigned char *out = (unsigned char *)dst, *op = out;
while (ip - in < is) {
unsigned char c = *ip;
if (c > 0xBF) {
if (op - out >= os - 1)
break;
*op++ = (char) 0xC3;
*op++ = 0xC3;
*op++ = c - 64;
} else if (c > 0x7F) {
if (op - out >= os - 1)
break;
*op++ = (char) 0xC2;
*op++ = 0xC2;
*op++ = c;
} else {
if (op - out >= os)