remote TABs in doc/ and test/

This commit is contained in:
Christian Groessler
2019-02-12 22:50:49 +01:00
parent b9ea77b185
commit 7445550831
97 changed files with 5956 additions and 5963 deletions

View File

@@ -16,12 +16,12 @@ FILE *in;
struct node
{
int count; /* frequency count */
struct node *left; /* left subtree */
struct node *right; /* right subtree */
char *word; /* word itself */
int count; /* frequency count */
struct node *left; /* left subtree */
struct node *right; /* right subtree */
char *word; /* word itself */
} words[MAXWORDS];
int next; /* index of next free entry in words */
int next; /* index of next free entry in words */
/*struct node *lookup();*/
@@ -38,14 +38,14 @@ struct node *lookup(char *word, struct node **p);
int isletter(char c);
/* err - print error message s and die */
/* err - print error message s and die */
#ifndef NO_OLD_FUNC_DECL
err(s) char *s; {
#else
int err(char *s) {
#endif
printf("? %s\n", s);
exit(1);
printf("? %s\n", s);
exit(1);
}
/* getword - get next input word into buf, return 0 on EOF */
@@ -55,25 +55,25 @@ int getword(buf) char *buf;
int getword(char *buf)
#endif
{
char *s;
int c;
char *s;
int c;
while (((c = getchar()) != -1) && (isletter(c) == 0))
;
;
for (s = buf; (c = isletter(c)); c = getchar())
*s++ = c;
*s = 0;
if (s > buf)
return 1;
return 0;
*s++ = c;
*s = 0;
if (s > buf)
return 1;
return 0;
}
/* isletter - return folded version of c if it is a letter, 0 otherwise */
int isletter(char c)
{
if ((c >= 'A') && (c <= 'Z')) c += 'a' - 'A';
if ((c >= 'a') && (c <= 'z')) return c;
return 0;
if ((c >= 'A') && (c <= 'Z')) c += 'a' - 'A';
if ((c >= 'a') && (c <= 'z')) return c;
return 0;
}
/* lookup - lookup word in tree; install if necessary */
@@ -84,27 +84,27 @@ char *word; struct node **p;
struct node *lookup(char *word, struct node **p)
#endif
{
int cond;
/* char *malloc(); */
int cond;
/* char *malloc(); */
if (*p) {
cond = strcmp(word, (*p)->word);
if (cond < 0)
return lookup(word, &(*p)->left);
else if (cond > 0)
return lookup(word, &(*p)->right);
else
return *p;
}
if (next >= MAXWORDS)
err("out of node storage");
words[next].count = 0;
words[next].left = words[next].right = 0;
words[next].word = malloc(strlen(word) + 1);
if (words[next].word == 0)
err("out of word storage");
strcpy(words[next].word, word);
return *p = &words[next++];
if (*p) {
cond = strcmp(word, (*p)->word);
if (cond < 0)
return lookup(word, &(*p)->left);
else if (cond > 0)
return lookup(word, &(*p)->right);
else
return *p;
}
if (next >= MAXWORDS)
err("out of node storage");
words[next].count = 0;
words[next].left = words[next].right = 0;
words[next].word = malloc(strlen(word) + 1);
if (words[next].word == 0)
err("out of word storage");
strcpy(words[next].word, word);
return *p = &words[next++];
}
/* tprint - print tree */
@@ -113,28 +113,28 @@ void tprint(tree) struct node *tree; {
#else
void tprint(struct node *tree) {
#endif
if (tree) {
tprint(tree->left);
printf("%d:%s\n", tree->count, tree->word);
tprint(tree->right);
}
if (tree) {
tprint(tree->left);
printf("%d:%s\n", tree->count, tree->word);
tprint(tree->right);
}
}
int main(void)
{
struct node *root;
char word[20];
struct node *root;
char word[20];
in = fopen("wf1.in","rb");
if (in == NULL) {
return EXIT_FAILURE;
}
root = 0;
next = 0;
while (getword(word))
lookup(word, &root)->count++;
tprint(root);
root = 0;
next = 0;
while (getword(word))
lookup(word, &root)->count++;
tprint(root);
fclose(in);
return 0;