/* loop.c * last revised at 1, Feb. 1994 * * Copyright (C) 1994, All rights reserved. * written by Gyudong Kim(chilly@eleceng.adelaide.edu.au) * * With acknowledgement to * Mario Mene' * & Kalawathi Thevi Nagappan * for their valuable suggestions on loop detection * */ #include "findhier.h" static struct names *stack; extern int WARN; void pop() { struct names *tmp; if (stack==NULL) return; tmp = stack->next; myfree(stack); stack = tmp; } static void loop_report(tmp) struct names *tmp; { struct names *pmt; warning("Recursion Found for %s",tmp->name); for(pmt=stack;pmt!=tmp;pmt=pmt->next) warning(" - %s",pmt->name); warning("\n",""); exit(1); } int check(name) char *name; { struct names *tmp; if (stack==NULL) return(0); for(tmp=stack;tmp!=NULL;tmp=tmp->next) { if (tmp->name != name) continue; if (WARN) loop_report(tmp); return(1); } return(0); } void push(name) char *name; { struct names *tmp; tmp=(struct names *)myalloc(sizeof(struct names),"push"); tmp->name = name; tmp->next = stack; stack = tmp; } /* loop.c */