aboutsummaryrefslogtreecommitdiff
path: root/5.20/dcl.c
diff options
context:
space:
mode:
Diffstat (limited to '5.20/dcl.c')
-rw-r--r--5.20/dcl.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/5.20/dcl.c b/5.20/dcl.c
new file mode 100644
index 0000000..e504919
--- /dev/null
+++ b/5.20/dcl.c
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <string.h>
+#include "token.h"
+#include "err.h"
+#include "dcl.h"
+
+char out[OUTLEN];
+char name[MAXTOKEN];
+
+void dcl(void)
+{
+ int ns;
+
+ for (ns = 0; gettoken() == '*';)
+ ns++;
+ dirdcl();
+ while (ns-- > 0)
+ strncat(out, " pointer to", OUTLEN - 1);
+}
+
+void dirdcl(void)
+{
+ int type;
+
+ if (tokentype == '(') {
+ dcl();
+ if (tokentype != ')')
+ warn("missing )");
+ } else if (tokentype == ')' || tokentype == ',') {
+ prevtoken = YES;
+ } else if (tokentype == NAME) {
+ strcpy(name, token);
+ } else {
+ warn("expected () or name or (dcl)");
+ }
+
+ while ((type = gettoken()) == PARENS || type == BRACKETS ||
+ type == '(' || type == ',') {
+ if (type == PARENS) {
+ strncat(out, " function returning", OUTLEN - 1);
+ } else if (type == '(') {
+ strncat(out, " function expecting", OUTLEN - 1);
+ parmdcl();
+ strncat(out, " and returning", OUTLEN - 1);
+ } else if (type == ',') {
+ parmdcl();
+ strncat(out, ",", OUTLEN - 1);
+ } else {
+ strncat(out, " array", OUTLEN - 1);
+ strncat(out, token, OUTLEN - 1);
+ strncat(out, " of", OUTLEN - 1);
+ }
+ }
+
+ if (tokentype == '\n')
+ prevtoken = YES;
+}
+
+void parmdcl(void)
+{
+ char parmdt[MAXTOKEN];
+ parmdt[0] = '\0';
+
+ while (gettoken() == NAME && isdatatyp()) {
+ strncat(parmdt, " ", MAXTOKEN - 1);
+ strncat(parmdt, token, MAXTOKEN - 1);
+ }
+
+ prevtoken = YES;
+ dcl();
+ strncat(out, parmdt, OUTLEN - 1);
+}