From d0feb8570adf0ae8201d0b081a4faa71b2a362e2 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 8 Jan 2004 10:20:44 +0000 Subject: [PATCH] (copy, atopi, same): Remove, use strcpy(), atoi(), strcmp(). Callers changed. Remove empty source files. --- include/misc.h | 1 - include/prototypes.h | 3 - src/client/misc.h | 1 - src/lib/commands/chan.c | 2 +- src/lib/commands/offe.c | 4 +- src/lib/gen/Makefile | 14 +-- src/lib/gen/atopi.c | 55 ------------ src/lib/gen/copy.c | 7 -- src/lib/gen/same.c | 45 ---------- src/lib/gen/vsprintf.c | 188 ---------------------------------------- src/lib/player/empdis.c | 2 +- 11 files changed, 11 insertions(+), 311 deletions(-) delete mode 100644 src/lib/gen/atopi.c delete mode 100644 src/lib/gen/same.c delete mode 100644 src/lib/gen/vsprintf.c diff --git a/include/misc.h b/include/misc.h index 032eb45e..b6fb7000 100644 --- a/include/misc.h +++ b/include/misc.h @@ -149,7 +149,6 @@ extern long random(); double dmax _PROTO((double n1, double n2)); double dmin _PROTO((double n1, double n2)); -extern s_char *copy _PROTO((s_char *s1, s_char *s2)); extern s_char *numstr _PROTO((s_char buf[], int n)); extern s_char *esplur _PROTO((int n)); extern s_char *splur _PROTO((int n)); diff --git a/include/prototypes.h b/include/prototypes.h index 9c3a86d5..cbd7ef39 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -410,11 +410,9 @@ extern int emp_config(char *file); extern void print_config(FILE * fp); extern int atoip(s_char **); -extern int atopi(s_char *); extern int roll(int); extern int roundavg(double); extern int chance(double); -extern s_char *copy(register s_char *, register s_char *); extern void disassoc(void); extern int getfdtablesize(void); extern void setfdtablesize(int, int); @@ -447,7 +445,6 @@ extern s_char *iesplur(int); extern s_char *plur(int, s_char *, s_char *); extern int ldround(double, int); extern int roundintby(int, int); -extern int same(register s_char *, register s_char *); extern int scthash(register int, register int, int); #ifdef NOSTRDUP extern char *strdup(char *x); diff --git a/src/client/misc.h b/src/client/misc.h index fac70177..e54dc81e 100644 --- a/src/client/misc.h +++ b/src/client/misc.h @@ -102,7 +102,6 @@ extern double dmax(); extern double dmin(); extern s_char *fmt(); -extern s_char *copy(); extern s_char *numstr(); extern s_char *esplur(); extern s_char *splur(); diff --git a/src/lib/commands/chan.c b/src/lib/commands/chan.c index b9d61080..cc6744ed 100644 --- a/src/lib/commands/chan.c +++ b/src/lib/commands/chan.c @@ -90,7 +90,7 @@ chan(void) return RET_SYN; p[sizeof(us->nat_cnam) - 1] = 0; for (cn = 0; NULL != (natp = getnatp(cn)); cn++) { - if (same(p, natp->nat_cnam)) { + if (!strcmp(p, natp->nat_cnam)) { pr("Country #%d is already called `%s'!\n", cn, p); return RET_FAIL; } diff --git a/src/lib/commands/offe.c b/src/lib/commands/offe.c index 72e0291c..12c6f5ec 100644 --- a/src/lib/commands/offe.c +++ b/src/lib/commands/offe.c @@ -128,8 +128,8 @@ do_treaty(void) cp = getstring("Proposed treaty duration? (days) ", buf); if (cp == 0) return RET_FAIL; - j = atopi(cp); - if (j == 0) { + j = atoi(cp); + if (j <= 0) { pr("Bad treaty duration.\n"); return RET_SYN; } diff --git a/src/lib/gen/Makefile b/src/lib/gen/Makefile index cb972b40..443935a6 100644 --- a/src/lib/gen/Makefile +++ b/src/lib/gen/Makefile @@ -35,17 +35,17 @@ include ../../make.defs LIB = $(SRCDIR)/lib/libgen.a NTLIB = $(SRCDIR)\lib\libgen.lib -OBJS = atoip.o atopi.o bit.o chance.o copy.o disassoc.o dtable.o \ +OBJS = atoip.o bit.o chance.o copy.o disassoc.o dtable.o \ emp_config.o getstarg.o getstring.o hpux.o inet.o io.o \ io_mask.o ioqueue.o lock.o mapdist.o minmax.o numstr.o onearg.o \ - parse.o plur.o queue.o round.o same.o scthash.o \ - strdup.o vsprintf.o + parse.o plur.o queue.o round.o scthash.o \ + strdup.o -NTOBJS = atoip.obj atopi.obj bit.obj chance.obj copy.obj disassoc.obj \ - dtable.obj emp_config.obj getstarg.obj getstring.obj hpux.obj \ +NTOBJS = atoip.obj bit.obj chance.obj copy.obj disassoc.obj dtable.obj \ + emp_config.obj getstarg.obj getstring.obj hpux.obj \ inet.obj io.obj io_mask.obj ioqueue.obj lock.obj mapdist.obj minmax.obj \ - numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj same.obj \ - scthash.obj strdup.obj vsprintf.obj + numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj \ + scthash.obj strdup.obj all: $(LIB) diff --git a/src/lib/gen/atopi.c b/src/lib/gen/atopi.c deleted file mode 100644 index d3d8be46..00000000 --- a/src/lib/gen/atopi.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure - * - * 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 of the License, 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. - * - * 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 - * - * --- - * - * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the - * related information and legal notices. It is expected that any future - * projects/authors will amend these files as needed. - * - * --- - * - * atopi.c: Return positive integer from string. - * - * Known contributors to this file: - * - */ - -#include "gen.h" - -/* - * atopi.c - * - * from PSL Empire, 1985 - */ - -int -atopi(s_char *p) -{ - register int r11; - - if (p) { - r11 = atoi(p); - if (r11 < 0) - r11 = -r11; - return r11; - } else { - return (0); - } -} diff --git a/src/lib/gen/copy.c b/src/lib/gen/copy.c index e49450ec..38c1f1ff 100644 --- a/src/lib/gen/copy.c +++ b/src/lib/gen/copy.c @@ -37,13 +37,6 @@ #include "gen.h" #include "optlist.h" -s_char * -copy(register s_char *s1, register s_char *s2) -{ - while ((*s2++ = *s1++) != 0) ; - return s2 - 1; -} - #ifdef hpux #include diff --git a/src/lib/gen/same.c b/src/lib/gen/same.c deleted file mode 100644 index 3db1b4bc..00000000 --- a/src/lib/gen/same.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure - * - * 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 of the License, 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. - * - * 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 - * - * --- - * - * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the - * related information and legal notices. It is expected that any future - * projects/authors will amend these files as needed. - * - * --- - * - * same.c: Return true if strings are the same - * - * Known contributors to this file: - * - */ - -#include "misc.h" -#include "gen.h" - -int -same(register s_char *s1, register s_char *s2) -{ - while (*s1 == *s2++) { - if (*s1++ == 0) - return 1; - } - return 0; -} diff --git a/src/lib/gen/vsprintf.c b/src/lib/gen/vsprintf.c deleted file mode 100644 index b7f7a0fd..00000000 --- a/src/lib/gen/vsprintf.c +++ /dev/null @@ -1,188 +0,0 @@ -#if !defined(_WIN32) -#ifndef __STDC__ - -/* Portable vsprintf by Robert A. Larson */ - -/* Copyright 1989 Robert A. Larson. - * Distribution in any form is allowed as long as the author - * retains credit, changes are noted by their author and the - * copyright message remains intact. This program comes as-is - * with no warentee of fitness for any purpouse. - * - * Thanks to Doug Gwen, Chris Torek, and others who helped clarify - * the ansi printf specs. - * - * Please send any bug fixes and improvments to blarson@skat.usc.edu . - * The use of goto is NOT a bug. - */ - -/* Feb 7, 1989 blarson First usenet release */ - -/* This code implements the vsprintf function, without relying on - * the existance of _doprint or other system specific code. - * - * Define NOVOID if void * is not a supported type. - * - * Two compile options are available for efficency: - * INTSPRINTF should be defined if sprintf is int and returns - * the number of chacters formated. - * LONGINT should be defined if sizeof(long) == sizeof(int) - * - * They only make the code smaller and faster, they need not be - * defined. - * - * UNSIGNEDSPECIAL should be defined if unsigned is treated differently - * than int in argument passing. If this is definded, and LONGINT is not, - * the compiler must support the type unsingned long. - * - * Most quirks and bugs of the available sprintf fuction are duplicated, - * however * in the width and precision fields will work correctly - * even if sprintf does not support this, as will the n format. - * - * Bad format strings, or those with very long width and precision - * fields (including expanded * fields) will cause undesired results. - */ -#include "misc.h" -#include "gen.h" - -#ifdef OSK /* os9/68k can take advantage of both */ -#define LONGINT -#define INTSPRINTF -#endif - -#define NOVOID - -/* This must be a typedef not a #define! */ -#ifdef NOVOID -typedef s_char *pointer; -#else -typedef void *pointer; -#endif - -#ifdef INTSPRINTF -#define Sprintf(string,format,arg) (sprintf((string),(format),(arg))) -#else -#define Sprintf(string,format,arg) (\ - sprintf((string),(format),(arg)),\ - strlen(string)\ -) -#endif - -#include - -typedef int *intp; - -int -vsprintf(dest, format, args) -s_char *dest; -register s_char *format; -va_list args; -{ - register s_char *dp = dest; - register s_char c; - register s_char *tp; - s_char tempfmt[64]; -#ifndef LONGINT - int longflag; -#endif - - tempfmt[0] = '%'; - while (c = *format++) { - if (c == '%') { - tp = &tempfmt[1]; -#ifndef LONGINT - longflag = 0; -#endif - continue_format: - switch (c = *format++) { - case 's': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, s_char *)); - break; - case 'u': - case 'x': - case 'o': - case 'X': -#ifdef UNSIGNEDSPECIAL - *tp++ = c; - *tp = '\0'; -#ifndef LONGINT - if (longflag) - dp += - Sprintf(dp, tempfmt, va_arg(args, unsigned long)); - else -#endif - dp += Sprintf(dp, tempfmt, va_arg(args, unsigned)); - break; -#endif - case 'd': - case 'c': - case 'i': - *tp++ = c; - *tp = '\0'; -#ifndef LONGINT - if (longflag) - dp += Sprintf(dp, tempfmt, va_arg(args, long)); - else -#endif - dp += Sprintf(dp, tempfmt, va_arg(args, int)); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, double)); - break; - case 'p': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, pointer)); - break; - case '-': - case '+': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '.': - case ' ': - case '#': - case 'h': - *tp++ = c; - goto continue_format; - case 'l': -#ifndef LONGINT - longflag = 1; - *tp++ = c; -#endif - goto continue_format; - case '*': - tp += Sprintf(tp, "%d", va_arg(args, int)); - goto continue_format; - case 'n': - *va_arg(args, intp) = dp - dest; - break; - case '%': - default: - *dp++ = c; - break; - } - } else - *dp++ = c; - } - *dp = '\0'; - return dp - dest; -} - -#endif /* __STDC__ */ -#endif diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index 5c9da90b..858dc938 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -84,7 +84,7 @@ getcommand(s_char *combufp) player_commands_index = 0; sprintf(player_commands[player_commands_index], "%3d %3d %s", player_commands_index, player->cnum, buf); - copy(buf, combufp); + strcpy(combufp, buf); return (strlen(combufp)); }