-
- /*
- * move on to next char, and set flags accordingly
- */
-
- sp++;
- if (c == '\n') {
- tp = token = sp = line;
- lineftell = ftell( inf );
-#ifdef DEBUG
- printf("lineftell saved as %ld\n",lineftell);
-#endif
- number = gotone = midtoken = inquote = inchar = FALSE;
- lineno++;
- }
- }
-}
-
-/*
- * This routine checks to see if the current token is
- * at the start of a function. It updates the input line
- * so that the '(' will be in it when it returns.
- */
-start_func(lp,token,tp)
-char **lp,*token,*tp;
-{
-
- reg char c,*sp,*tsp;
- static logical found;
- logical firsttok; /* T if have seen first token in ()'s */
- int bad;
-
- sp = *lp;
- c = *sp;
- bad = FALSE;
- if (!number) /* space is not allowed in macro defs */
- while (iswhite(c)) {
- *++sp = c = getc(inf);
-#ifdef DEBUG
- printf("%2.2s:\n",unctrl(c));
-#endif
- }
- /* the following tries to make it so that a #define a b(c) */
- /* doesn't count as a define of b. */
- else {
- logical define;
-
- define = TRUE;
- for (tsp = "define"; *tsp && token < tp; tsp++)
- if (*tsp != *token++) {
- define = FALSE;
- break;
- }
- if (define)
- found = 0;
- else
- found++;
- if (found >= 2) {
- gotone = TRUE;
-badone: bad = TRUE;
- goto ret;
- }
- }
- if (c != '(')
- goto badone;
- firsttok = FALSE;
- while ((*++sp=c=getc(inf)) != ')') {
- /*
- * This line used to confuse ctags:
- * int (*oldhup)();
- * This fixes it. A nonwhite char before the first
- * token, other than a / (in case of a comment in there)
- * makes this not a declaration.
- */
- if (begtoken(c) || c=='/') firsttok++;
- else if (!iswhite(c) && !firsttok) goto badone;
-#ifdef DEBUG
- printf("%2.2s:\n",unctrl(c));
-#endif
- }
-#ifdef DEBUG
- printf("%2.2s:\n",unctrl(c));
-#endif
- while (iswhite(*++sp=c=getc(inf)))
-#ifdef DEBUG
- printf("%2.2s:\n",unctrl(c))
-#endif
- ;
-#ifdef DEBUG
- printf("%2.2s:\n",unctrl(c));
-#endif
-ret:
- *lp = --sp;
- ungetc(c,inf);
- return !bad && isgood(c);
-}
-
-/*
- * This routine adds a function to the list
- */
-add_func(token)
-char *token;
-{
- reg char *fp,*pp;
- reg NODE *np;
-
- if ((np = (NODE *) calloc(1,sizeof (NODE))) == NULL) {
- printf("too many functions to sort\n");
- put_funcs(head);
- free_tree(head);
- head = np = (NODE *) calloc(1,sizeof (NODE));
- }
- if (strcmp(token,"main") == 0) {
- /*
- * Since there are so many directories with lots of
- * misc. complete programs in them, main tends to get
- * redefined a lot. So we change all mains to instead
- * refer to the name of the file, without leading
- * pathname components and without a trailing .c.
- */
- fp = curfile;
- for (pp=curfile; *pp; pp++)
- if (*pp == '/')
- fp = pp+1;
- *token = 'M';
- strcpy(token+1, fp);
- pp = &token[strlen(token)-2];
- if (*pp == '.')
- *pp = 0;
- }
- fp = np->func = (char *) calloc(strlen(token)+1,sizeof (char));
- np->file = curfile;
- strcpy(fp, token);
- { /*
- * this change to make the whole line the pattern
- */
- long saveftell = ftell( inf );
- int patlen;
- char ch;
-
- patlen = 0;
- fseek( inf , lineftell , 0 );
-#ifdef DEBUG
- printf("saveftell=%ld, lseek back to %ld\n",saveftell,lineftell);
-#endif
- ch = getc( inf );
- while ( ch != '\n' && ch != searchar && patlen < MAXPATTERN ) {
- patlen ++;
- ch = getc( inf );
- }
- pp = np -> pat = (char *) calloc( patlen + 2 , sizeof( char ) );
- fseek( inf , lineftell , 0 );
- ch = getc( inf );
- while ( patlen -- ) {
- *pp ++ = ch;
- ch = getc( inf );
- }
- if ( ch == '\n' )
- *pp ++ = '$';
- *pp = '\0';
- fseek( inf , saveftell , 0 );
-#ifdef DEBUG
- printf("seek back to %ld, ftell is now %ld\n",saveftell,ftell(inf));
-#endif
- }
-#ifdef DEBUG
- printf("\"%s\"\t\"%s\"\t\"%s\"\n",np->func,np->file,np->pat);
-#endif
- if (head == NULL)
- head = np;
- else
- add_node(np,head);
-}
-
-/*
- * This routine cfrees the entire tree from the node down.
- */
-free_tree(node)
-NODE *node;
-{
-
- while (node) {
- free_tree(node->right);
- cfree(node);
- node = node->left;
- }
-}
-
-/*
- * This routine finds the node where the new function node
- * should be added.
- */
-add_node(node,cur_node)
-NODE *node,*cur_node;
-{
-
- reg int dif;
-
- dif = strcmp(node->func,cur_node->func);
-#ifdef DEBUG
- printf("strcmp(\"%s\",\"%s\") == %d\n",node->func,cur_node->func,dif);
-#endif
- if (dif == 0) {
- if (node->file == cur_node->file) {
- if (!wflag) {
- fprintf(stderr,"Duplicate function in file \"%s\", line %d: %s\n",node->file,lineno,node->func);
- fprintf(stderr,"Second entry ignored\n");
- }
- return;
- }
- else {
- if (!cur_node->been_warned)
- if (!wflag)
- fprintf(stderr,"Duplicate function name in files %s and %s: %s (Warning only)\n",
- node->file, cur_node->file, node->func);
- cur_node->been_warned = TRUE;
- }
- }
- if (dif < 0)
- if (cur_node->left != NULL)
- add_node(node,cur_node->left);
- else {
-#ifdef DEBUG
- printf("adding to left branch\n");
-#endif
- cur_node->left = node;
- }
- else
- if (cur_node->right != NULL)
- add_node(node,cur_node->right);
- else {
-#ifdef DEBUG
- printf("adding to right branch\n");
-#endif
- cur_node->right = node;