aboutsummaryrefslogblamecommitdiff
path: root/5.20/dcl.c
blob: 085c4240ee4dfbeaece5409c5da69de6911a3120 (plain) (tree)



























                                                        
                                      

                                       

                                            
                
                                                           



                                                                   
                              


                                                                        
                                                                       

                                                                   





                                                           




                              
 





                                                                             
 



                                                 
 
#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 == ')') {
		prevtoken = YES;
	} else if (tokentype == NAME) {
		if (!strlen(name))
			strcpy(name, token);
	} else {
		printf("%c - %d : ", tokentype, tokentype);
		warn("expected () or name or (dcl)");
	}

	while ((type = gettoken()) == PARENS || type == BRACKETS ||
		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 {
			strncat(out, " array", OUTLEN - 1);
			strncat(out, token, OUTLEN - 1);
			strncat(out, " of", OUTLEN - 1);
		}
	}
}

void parmdcl(void)
{
	char parmdt[MAXTOKEN];

	do {
		strncpy(parmdt, (tokentype == ',') ? "," : "", MAXTOKEN - 1);
		while (gettoken() == NAME && isdtspec()) {
			strncat(parmdt, " ", MAXTOKEN - 1);
			strncat(parmdt, token, MAXTOKEN - 1);
		}

		prevtoken = YES;
		dcl();
		strncat(out, parmdt, OUTLEN - 1);
	} while (tokentype == ',');
}