aboutsummaryrefslogtreecommitdiffstats
path: root/lcc/tst/wf1.c
diff options
context:
space:
mode:
authorzakk <zakk@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-08-26 17:39:27 +0000
committerzakk <zakk@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-08-26 17:39:27 +0000
commit6bf20c78f5b69d40bcc4931df93d29198435ab67 (patch)
treee3eda937a05d7db42de725b7013bd0344b987f34 /lcc/tst/wf1.c
parent872d4d7f55af706737ffb361bb76ad13e7496770 (diff)
downloadioquake3-aero-6bf20c78f5b69d40bcc4931df93d29198435ab67.tar.gz
ioquake3-aero-6bf20c78f5b69d40bcc4931df93d29198435ab67.zip
newlines fixed
git-svn-id: svn://svn.icculus.org/quake3/trunk@6 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'lcc/tst/wf1.c')
-rwxr-xr-xlcc/tst/wf1.c202
1 files changed, 101 insertions, 101 deletions
diff --git a/lcc/tst/wf1.c b/lcc/tst/wf1.c
index a95b4ec..d0c6e32 100755
--- a/lcc/tst/wf1.c
+++ b/lcc/tst/wf1.c
@@ -1,101 +1,101 @@
-/* wf1 - print word frequencies; uses structures */
-
-struct node {
- int count; /* frequency count */
- struct node *left; /* left subtree */
- struct node *right; /* right subtree */
- char *word; /* word itself */
-} words[2000];
-int next; /* index of next free entry in words */
-
-struct node *lookup();
-
-main() {
- struct node *root;
- char word[20];
-
- root = 0;
- next = 0;
- while (getword(word))
- lookup(word, &root)->count++;
- tprint(root);
- return 0;
-}
-
-/* err - print error message s and die */
-err(s) char *s; {
- printf("? %s\n", s);
- exit(1);
-}
-
-/* getword - get next input word into buf, return 0 on EOF */
-int getword(buf) char *buf; {
- 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);
-}
-
-/* isletter - return folded version of c if it is a letter, 0 otherwise */
-int isletter(c) {
- 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 */
-struct node *lookup(word, p) char *word; struct node **p; {
- 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 >= 2000)
- 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 */
-tprint(tree) struct node *tree; {
- if (tree) {
- tprint(tree->left);
- printf("%d\t%s\n", tree->count, tree->word);
- tprint(tree->right);
- }
-}
-
-/* strcmp - compare s1 and s2, return <0, 0, or >0 */
-int strcmp(s1, s2) char *s1, *s2; {
- while (*s1 == *s2) {
- if (*s1++ == 0)
- return 0;
- ++s2;
- }
- if (*s1 == 0)
- return -1;
- else if (*s2 == 0)
- return 1;
- return *s1 - *s2;
-}
+/* wf1 - print word frequencies; uses structures */
+
+struct node {
+ int count; /* frequency count */
+ struct node *left; /* left subtree */
+ struct node *right; /* right subtree */
+ char *word; /* word itself */
+} words[2000];
+int next; /* index of next free entry in words */
+
+struct node *lookup();
+
+main() {
+ struct node *root;
+ char word[20];
+
+ root = 0;
+ next = 0;
+ while (getword(word))
+ lookup(word, &root)->count++;
+ tprint(root);
+ return 0;
+}
+
+/* err - print error message s and die */
+err(s) char *s; {
+ printf("? %s\n", s);
+ exit(1);
+}
+
+/* getword - get next input word into buf, return 0 on EOF */
+int getword(buf) char *buf; {
+ 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);
+}
+
+/* isletter - return folded version of c if it is a letter, 0 otherwise */
+int isletter(c) {
+ 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 */
+struct node *lookup(word, p) char *word; struct node **p; {
+ 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 >= 2000)
+ 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 */
+tprint(tree) struct node *tree; {
+ if (tree) {
+ tprint(tree->left);
+ printf("%d\t%s\n", tree->count, tree->word);
+ tprint(tree->right);
+ }
+}
+
+/* strcmp - compare s1 and s2, return <0, 0, or >0 */
+int strcmp(s1, s2) char *s1, *s2; {
+ while (*s1 == *s2) {
+ if (*s1++ == 0)
+ return 0;
+ ++s2;
+ }
+ if (*s1 == 0)
+ return -1;
+ else if (*s2 == 0)
+ return 1;
+ return *s1 - *s2;
+}