aboutsummaryrefslogtreecommitdiff
path: root/6.5/word.c
diff options
context:
space:
mode:
Diffstat (limited to '6.5/word.c')
-rw-r--r--6.5/word.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/6.5/word.c b/6.5/word.c
new file mode 100644
index 0000000..045eaf7
--- /dev/null
+++ b/6.5/word.c
@@ -0,0 +1,58 @@
+// #include <stdio.h>
+// #include <stdlib.h>
+// #include <stdint.h>
+#include <ctype.h>
+// #include <string.h>
+// #include <error.h>
+// #include <errno.h>
+#include "getch.h"
+#include "word.h"
+
+// #define MAXBUFF 100
+//
+// uint32_t top;
+// char *wstack[MAXBUFF];
+
+char getword(char *word, int lim)
+{
+ char *w = word;
+
+ // if (top > 0)
+ // return *wstack[--top];
+
+ while (isblank(*w = getch()))
+ ;
+
+ if (isalpha(*w)) {
+ while ((isalnum(*++w = getch()) || *w == '_') && --lim > 0)
+ ;
+ ungetch(*w--);
+ } else if (*w == '#') {
+ --lim;
+ do {
+ *++w = getch();
+ } while (isalpha(*w) && --lim > 0);
+ ungetch(*w--);
+ }
+
+ *++w = '\0';
+ return word[0];
+}
+//
+// void ungetword(char *word)
+// {
+// if (top < MAXBUFF) {
+// if ((wstack[top++] = strdup(word)) == NULL)
+// error(EXIT_FAILURE, ENOBUFS, "ungetword");
+// } else {
+// error(EXIT_FAILURE, ENOBUFS, "ungetword");
+// }
+// }
+//
+// void wordfree(void)
+// {
+// uint32_t i;
+//
+// for (i = 0; i < top; ++i)
+// free(wstack[i]);
+// }