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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* $Id: common.c,v 1.23 2001/12/21 23:48:12 riq Exp $ */
/* Tenes Empanadas Graciela
*
* Copyright (C) 2000 Ricardo Quesada
*
* Author: Ricardo Calixto Quesada <rquesada@core-sdi.com>
*
* 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; only version 2 of the License
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* @file common.c
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include "all.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
char *g_colores[] = {
N_("red"),
N_("yellow"),
N_("blue"),
N_("black"),
N_("pink"),
N_("green"),
N_("n/a") /* cuando todavia no tiene un color */
};
/* XXX sync con common.h */
char *g_reglas[] = {
N_("TEG"),
N_("Risk"),
N_("1914"),
N_("other"),
};
/* XXX: estos estados deben estar synced con los de common.h */
char *g_estados[] = {
N_("disconnected"),
N_("connected"),
N_("game over"),
N_("enabled"),
N_("started"),
N_("placing armies"),
N_("postarmies"),
N_("placing armies 2"),
N_("postarmies 2"),
N_("idle"),
N_("placing armies 3"),
N_("exchanging cards"),
N_("postarmies 3"),
N_("making a pact"),
N_("starting turn"),
N_("attacking"),
N_("moving armies"),
N_("regrouping"),
N_("gettting card"),
N_("ending turn")
};
/**
* @fn int get_int_from_dev_random( void )
* Devuelve un entero de /dev/random o 0 si no puede
*/
int get_int_from_dev_random( void )
{
int fd;
char buf[sizeof(int)];
int l;
int *ret;
fd = open("/dev/random", O_RDONLY);
if( fd < 0) {
fprintf(stderr,"Couldn't open '/dev/random'\n");
return 0;
}
l = read( fd, buf, sizeof(buf));
if( l != sizeof(buf) )
fprintf(stderr,"Returning a not so random number");
ret = (int *)&buf;
close(fd);
return *ret;
}
/**
* @fn int cuantos_x_canje( int c )
* Dado el nro de canje dice la cantidad de ejercitos que le corresponden
*/
int cuantos_x_canje( int c )
{
if( c < 1 )
return 0;
switch( c ) {
case 0:
return 0;
case 1:
return 4;
case 2:
return 7;
case 3:
return 10;
default:
return (c-1) * 5;
}
}
/**
* @fn TEG_STATUS strip_invalid( char *n )
*/
TEG_STATUS strip_invalid( char *n )
{
int l = strlen(n);
int i;
assert(n);
for(i=0;i<l;i++) {
if( n[i]=='=' || n[i]==';' || n[i]=='\\' || n[i]==',' || n[i]==':' || n[i]=='/' || n[i]=='%')
n[i] = '.';
}
return TEG_STATUS_SUCCESS;
}
/**
* @fn TEG_STATUS strip_invalid( char *n )
*/
TEG_STATUS strip_invalid_msg( char *n )
{
int l = strlen(n);
int i;
assert(n);
for(i=0;i<l;i++) {
if( n[i]=='"' || n[i]=='%')
n[i]='\'';
}
return TEG_STATUS_SUCCESS;
}
|