Better ANSI C compatibility and portability:

+ Addition of function prototypes and include files.
+ Change function definitions to ANSI C style.
+ Initial support for CMake
.
This commit is contained in:
carl 2019-02-19 00:44:19 +08:00
parent 750a6bc684
commit cc27fd471d

View file

@ -15,6 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
extern char *ProgName; extern char *ProgName;
@ -24,10 +25,21 @@ extern char *ProgName;
int maxlen = DEF_LENGTH; int maxlen = DEF_LENGTH;
BeginOfProgram() {}
DoOption(str) void InsertId(char *);
char *str; char *Malloc(unsigned int);
char *Salloc(char *);
int EnHash(char*);
void EndOfProgram(void);
void DoOption(char*);
void CheckId(char *, int);
void BeginOfProgram(void) {}
void DoOption(char* str)
{ {
switch (str[1]) { switch (str[1]) {
@ -45,8 +57,7 @@ DoOption(str)
} }
} }
CheckId(id, len) void CheckId(char *id, int len)
char *id;
{ {
if (len >= maxlen) { if (len >= maxlen) {
InsertId(id); InsertId(id);
@ -62,10 +73,7 @@ struct idf {
struct idf *hash_tab[HASHSIZE]; struct idf *hash_tab[HASHSIZE];
char *Malloc(), *Salloc(); void InsertId(char *id)
InsertId(id)
char *id;
{ {
int hash_val = EnHash(id); int hash_val = EnHash(id);
register struct idf *idp = hash_tab[hash_val]; register struct idf *idp = hash_tab[hash_val];
@ -85,11 +93,9 @@ InsertId(id)
} }
} }
char * char *Malloc(unsigned int n)
Malloc(n)
unsigned n;
{ {
char *mem, *malloc(); char *mem;
if ((mem = malloc(n)) == 0) { if ((mem = malloc(n)) == 0) {
fprintf(stderr, "%s: out of memory\n", ProgName); fprintf(stderr, "%s: out of memory\n", ProgName);
@ -98,21 +104,19 @@ Malloc(n)
return mem; return mem;
} }
char * char *Salloc(char *str)
Salloc(str)
char *str;
{ {
if (str == 0) if (str == 0)
str = ""; str = "";
return strcpy(Malloc((unsigned)strlen(str) + 1), str); return strcpy(Malloc((unsigned)strlen(str) + 1), str);
} }
EnHash(id) int EnHash(char *id)
char *id;
{ {
register unsigned hash_val = 0; register unsigned hash_val = 0;
register n = maxlen; register int n = maxlen;
while (n-- && *id) while (n-- && *id)
hash_val = 31 * hash_val + *id++; hash_val = 31 * hash_val + *id++;
@ -120,7 +124,7 @@ EnHash(id)
return hash_val % (unsigned) HASHSIZE; return hash_val % (unsigned) HASHSIZE;
} }
EndOfProgram() void EndOfProgram(void)
{ {
register struct idf *idp; register struct idf *idp;
register int i; register int i;