From b1e9d17a54041feee196de1fdd5ba6a5f4240c21 Mon Sep 17 00:00:00 2001 From: "Liam J. Foy" Date: Thu, 1 Sep 2005 22:45:35 +0000 Subject: [PATCH] K&R style function removal. Update functions to ANSI style. Also a few minor cleans. Submitted by: Peter Avalos --- games/fortune/fortune/fortune.c | 108 +++++++++++--------------------- games/fortune/strfile/strfile.c | 34 +++++----- games/fortune/unstr/unstr.c | 16 ++--- 3 files changed, 60 insertions(+), 98 deletions(-) diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c index fbb1411c67..c4d33940f4 100644 --- a/games/fortune/fortune/fortune.c +++ b/games/fortune/fortune/fortune.c @@ -38,7 +38,7 @@ * $FreeBSD: src/games/fortune/fortune/fortune.c,v 1.18.2.1 2001/07/02 00:35:27 dd Exp $ */ /* $FreeBSD: src/games/fortune/fortune/fortune.c,v 1.18.2.1 2001/07/02 00:35:27 dd Exp $ */ -/* $DragonFly: src/games/fortune/fortune/fortune.c,v 1.4 2005/08/08 15:25:42 joerg Exp $ */ +/* $DragonFly: src/games/fortune/fortune/fortune.c,v 1.5 2005/09/01 22:45:35 liamfoy Exp $ */ # include # include @@ -178,9 +178,7 @@ char *regcmp(), *regex(); #endif int -main(ac, av) -int ac; -char *av[]; +main(int ac, char **av) { #ifdef OK_TO_WRITE_DISK int fd; @@ -234,8 +232,7 @@ char *av[]; } void -display(fp) -FILEDESC *fp; +display(FILEDESC *fp) { char *p; unsigned char ch; @@ -268,7 +265,7 @@ FILEDESC *fp; * Return the length of the fortune. */ int -fortlen() +fortlen(void) { int nchar; char line[BUFSIZ]; @@ -291,9 +288,7 @@ fortlen() * This routine evaluates the arguments on the command line */ void -getargs(argc, argv) -int argc; -char **argv; +getargs(int argc, char **argv) { int ignore_case; # ifndef NO_REGEX @@ -395,9 +390,7 @@ char **argv; * Form the file list from the file specifications. */ int -form_file_list(files, file_cnt) -char **files; -int file_cnt; +form_file_list(char **files, int file_cnt) { int i, percent; char *sp; @@ -459,12 +452,7 @@ int file_cnt; * Add a file to the file list. */ int -add_file(percent, file, dir, head, tail, parent) -int percent; -char *file; -char *dir; -FILEDESC **head, **tail; -FILEDESC *parent; +add_file(int percent, char *file, char *dir, FILEDESC **head, FILEDESC **tail, FILEDESC *parent) { FILEDESC *fp; int fd; @@ -589,7 +577,7 @@ over: * Return a pointer to an initialized new FILEDESC. */ FILEDESC * -new_fp() +new_fp(void) { FILEDESC *fp; @@ -614,8 +602,7 @@ new_fp() * Return a pointer to the offensive version of a file of this name. */ char * -off_name(file) -char *file; +off_name(char *file) { char *new; @@ -628,8 +615,7 @@ char *file; * Is the file an offensive-style name? */ int -is_off_name(file) -char *file; +is_off_name(char *file) { int len; @@ -643,9 +629,7 @@ char *file; * there are two children to be a parent of. */ void -all_forts(fp, offensive) -FILEDESC *fp; -char *offensive; +all_forts(FILEDESC *fp, char *offensive) { char *sp; FILEDESC *scene, *obscene; @@ -693,8 +677,7 @@ char *offensive; * Add the contents of an entire directory. */ int -add_dir(fp) -FILEDESC *fp; +add_dir(FILEDESC *fp) { DIR *dir; struct dirent *dirent; @@ -731,8 +714,7 @@ FILEDESC *fp; * Return TRUE if the file is a directory, FALSE otherwise. */ int -is_dir(file) -char *file; +is_dir(char *file) { auto struct stat sbuf; @@ -750,9 +732,7 @@ char *file; */ /* ARGSUSED */ int -is_fortfile(file, datp, posp, check_for_offend) -char *file, **datp, **posp; -int check_for_offend; +is_fortfile(char *file, char **datp, char **posp, int check_for_offend) { int i; char *sp; @@ -831,9 +811,7 @@ int check_for_offend; * Return a malloc()'ed copy of the string */ char * -copy(str, len) -char *str; -unsigned int len; +copy(char *str, unsigned int len) { char *new, *sp; @@ -850,8 +828,7 @@ unsigned int len; * Do a malloc, checking for NULL return. */ void * -do_malloc(size) -unsigned int size; +do_malloc(unsigned int size) { void *new; @@ -867,8 +844,7 @@ unsigned int size; * Free malloc'ed space, if any. */ void -do_free(ptr) -void *ptr; +do_free(void *ptr) { if (ptr != NULL) free(ptr); @@ -879,7 +855,7 @@ void *ptr; * Initialize the fortune probabilities. */ void -init_prob() +init_prob(void) { FILEDESC *fp, *last = NULL; int percent, num_noprob, frac; @@ -951,7 +927,7 @@ init_prob() * Get the fortune data file's seek pointer for the next fortune. */ void -get_fort() +get_fort(void) { FILEDESC *fp; int choice; @@ -1014,8 +990,7 @@ get_fort() * Pick a child from a chosen parent. */ FILEDESC * -pick_child(parent) -FILEDESC *parent; +pick_child(FILEDESC *parent) { FILEDESC *fp; int choice; @@ -1051,8 +1026,7 @@ FILEDESC *parent; * Sum up all the noprob probabilities, starting with fp. */ void -sum_noprobs(fp) -FILEDESC *fp; +sum_noprobs(FILEDESC *fp) { static bool did_noprobs = FALSE; @@ -1068,8 +1042,7 @@ FILEDESC *fp; } int -max(i, j) -int i, j; +max(int i, int j) { return (i >= j ? i : j); } @@ -1079,8 +1052,7 @@ int i, j; * Assocatiate a FILE * with the given FILEDESC. */ void -open_fp(fp) -FILEDESC *fp; +open_fp(FILEDESC *fp) { if (fp->inf == NULL && (fp->inf = fdopen(fp->fd, "r")) == NULL) { perror(fp->path); @@ -1093,8 +1065,7 @@ FILEDESC *fp; * Open up the dat file if we need to. */ void -open_dat(fp) -FILEDESC *fp; +open_dat(FILEDESC *fp) { if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, 0)) < 0) { perror(fp->datfile); @@ -1108,8 +1079,7 @@ FILEDESC *fp; * return a random number. */ void -get_pos(fp) -FILEDESC *fp; +get_pos(FILEDESC *fp) { #ifdef OK_TO_WRITE_DISK int fd; @@ -1139,8 +1109,7 @@ FILEDESC *fp; * Get the tbl data file the datfile. */ void -get_tbl(fp) -FILEDESC *fp; +get_tbl(FILEDESC *fp) { auto int fd; FILEDESC *child; @@ -1179,8 +1148,7 @@ FILEDESC *fp; * Zero out the fields we care about in a tbl structure. */ void -zero_tbl(tp) -STRFILE *tp; +zero_tbl(STRFILE *tp) { tp->str_numstr = 0; tp->str_longlen = 0; @@ -1192,8 +1160,7 @@ STRFILE *tp; * Merge the tbl data of t2 into t1. */ void -sum_tbl(t1, t2) -STRFILE *t1, *t2; +sum_tbl(STRFILE *t1, STRFILE *t2) { t1->str_numstr += t2->str_numstr; if (t1->str_longlen < t2->str_longlen) @@ -1209,7 +1176,7 @@ STRFILE *t1, *t2; * Print out the file list */ void -print_file_list() +print_file_list(void) { print_list(File_list, 0); } @@ -1219,9 +1186,7 @@ print_file_list() * Print out the actual list, recursively. */ void -print_list(list, lev) -FILEDESC *list; -int lev; +print_list(FILEDESC *list, int lev) { while (list != NULL) { fprintf(stderr, "%*s", lev * 4, ""); @@ -1245,8 +1210,7 @@ int lev; * Convert the pattern to an ignore-case equivalent. */ char * -conv_pat(orig) -char *orig; +conv_pat(char *orig) { char *sp; unsigned int cnt; @@ -1288,7 +1252,7 @@ char *orig; * Find all the fortunes which match the pattern we've been given. */ int -find_matches() +find_matches(void) { Fort_len = maxlen_in_list(File_list); DPRINTF(2, (stderr, "Maximum length is %d\n", Fort_len)); @@ -1306,8 +1270,7 @@ find_matches() * Return the maximum fortune len in the file list. */ int -maxlen_in_list(list) -FILEDESC *list; +maxlen_in_list(FILEDESC *list) { FILEDESC *fp; int len, maxlen; @@ -1332,8 +1295,7 @@ FILEDESC *list; * Print out the matches from the files in the list. */ void -matches_in_list(list) -FILEDESC *list; +matches_in_list(FILEDESC *list) { char *sp, *p; FILEDESC *fp; @@ -1385,7 +1347,7 @@ FILEDESC *list; # endif /* NO_REGEX */ void -usage() +usage(void) { (void) fprintf(stderr, "fortune [-a"); #ifdef DEBUG diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c index 098cb0522b..6424df23c6 100644 --- a/games/fortune/strfile/strfile.c +++ b/games/fortune/strfile/strfile.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/games/fortune/strfile/strfile.c,v 1.15.2.2 2001/03/05 11:52:37 kris Exp $ - * $DragonFly: src/games/fortune/strfile/strfile.c,v 1.3 2003/11/12 14:53:53 eirikn Exp $ + * $DragonFly: src/games/fortune/strfile/strfile.c,v 1.4 2005/09/01 22:45:35 liamfoy Exp $ * * @(#) Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. * @(#)strfile.c 8.1 (Berkeley) 5/31/93 @@ -138,9 +138,8 @@ void usage (void); * CHUNKSIZE blocks; if the latter, we just write each pointer, * and then seek back to the beginning to write in the table. */ -int main(ac, av) -int ac; -char **av; +int +main(int ac, char **av) { char *sp, dc; FILE *inf, *outf; @@ -255,9 +254,8 @@ char **av; /* * This routine evaluates arguments from the command line */ -void getargs(argc, argv) -int argc; -char **argv; +void +getargs(int argc, char **argv) { int ch; @@ -309,7 +307,8 @@ char **argv; } } -void usage() +void +usage(void) { (void) fprintf(stderr, "strfile [-Ciorsx] [-c char] sourcefile [datafile]\n"); @@ -320,9 +319,8 @@ void usage() * add_offset: * Add an offset to the list, or write it out, as appropriate. */ -void add_offset(fp, off) -FILE *fp; -long off; +void +add_offset(FILE *fp, long off) { long net; @@ -340,7 +338,8 @@ long off; * do_order: * Order the strings alphabetically (possibly ignoring case). */ -void do_order() +void +do_order(void) { int i; long *lp; @@ -359,8 +358,8 @@ void do_order() Tbl.str_flags |= STR_ORDERED; } -static int collate_range_cmp (c1, c2) - int c1, c2; +static int +collate_range_cmp (int c1, int c2) { static char s1[2], s2[2]; int ret; @@ -380,8 +379,8 @@ static int collate_range_cmp (c1, c2) * cmp_str: * Compare two strings in the file */ -int cmp_str(s1, s2) -const void *s1, *s2; +int +cmp_str(const void *s1, const void *s2) { const STR *p1, *p2; int c1, c2; @@ -436,7 +435,8 @@ const void *s1, *s2; * not to randomize across delimiter boundaries. All * randomization is done within each block. */ -void randomize() +void +randomize(void) { int cnt, i; long tmp; diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c index a9f88ffa9b..37240c60ae 100644 --- a/games/fortune/unstr/unstr.c +++ b/games/fortune/unstr/unstr.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/games/fortune/unstr/unstr.c,v 1.5 1999/11/16 02:57:01 billf Exp $ - * $DragonFly: src/games/fortune/unstr/unstr.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/fortune/unstr/unstr.c,v 1.3 2005/09/01 22:45:35 liamfoy Exp $ * * @(#) Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved. * @(#)unstr.c 8.1 (Berkeley) 5/31/93 @@ -57,6 +57,7 @@ # include # include # include +# include # include # include "strfile.h" @@ -69,9 +70,8 @@ FILE *Inf, *Dataf; void getargs(), order_unstr(); /* ARGSUSED */ -int main(ac, av) -int ac; -char **av; +int +main(int ac, char **av) { static STRFILE tbl; /* description table */ @@ -101,8 +101,8 @@ char **av; exit(0); } -void getargs(av) -char *av[]; +void +getargs(char *av[]) { if (!*++av) { (void) fprintf(stderr, "usage: unstr datafile\n"); @@ -113,8 +113,8 @@ char *av[]; (void) strcat(Datafile, ".dat"); } -void order_unstr(tbl) -STRFILE *tbl; +void +order_unstr(STRFILE *tbl) { int i; char *sp; -- 2.41.0