aboutsummaryrefslogtreecommitdiff
path: root/6.1.1/word.c
diff options
context:
space:
mode:
Diffstat (limited to '6.1.1/word.c')
-rw-r--r--6.1.1/word.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/6.1.1/word.c b/6.1.1/word.c
new file mode 100644
index 0000000..538198f
--- /dev/null
+++ b/6.1.1/word.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <ctype.h>
+#include "getch.h"
+#include "word.h"
+
+char scomment();
+
+int getword(char *word, int lim)
+{
+ int instr = 0;
+ char *w = word;
+
+ while (isblank(*w = getch()) || *w == '"' || *w == '/') {
+ if (*w == '"') {
+ while ((*w = getch()) != '"' && *w != EOF)
+ ;
+ if (*w == EOF)
+ ungetch(*w);
+ } else if (*w == '/' && !scomment()) {
+ break;
+ }
+ }
+
+ if (isalpha(*w)) {
+ while ((isalnum(*w) || *w == '_') && --lim > 0)
+ *++w = getch();
+ ungetch(*w--);
+ } else if (*w == '#' && --lim > 0) {
+ do {
+ *++w = getch();
+ } while (isalpha(*w) && --lim > 0);
+ ungetch(*w--);
+ }
+
+ *++w = '\0';
+ return word[0];
+}
+
+char scomment()
+{
+ char c;
+
+ switch (c = getch()) {
+ case '/' :
+ while ((c = getch()) != EOF && c != '\n')
+ ;
+ if (c == EOF)
+ ungetch(c);
+
+ return '/';
+ case '*' :
+ while ((c = getch()) != EOF && !(c == '*' && (c = getch()) == '/'))
+ if (c == '*')
+ ungetch(c);
+ if (c == EOF)
+ ungetch(c);
+
+ return '*';
+ default:
+ ungetch(c);
+ return 0;
+ }
+}