summaryrefslogtreecommitdiff
path: root/shortnames/names.c
blob: e4beff95a18cee33f4ebdd535bae98002c7fd116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 *	A quick and dirty C program to spit out possible identifiers
 *	from a stream of *.c and *.h files.  Takes a single parameter
 *	which specifies the minimum length of an identifier to be
 *	extracted.
 *
 */
 
#include <stdio.h>
#include <ctype.h>

#define FIRSTCHAR(a) (isalpha(a) || (a)=='_')
#define OTHERCHAR(a) (FIRSTCHAR(a) || isdigit(a))
#define TRUE 1
#define FALSE 0

int size = 0;
char buffer[512];
char *bp = buffer;

main (argc, argv)
     int argc;
     char *argv[];
{
  register int ch;
  register int spitout;
  register int eating_comment;

  if (argc == 2)
    {
      size = atoi (argv[1]);
    }
  spitout = FALSE;
  eating_comment = FALSE;
  while ((ch = getchar()) != EOF)
    {
      if (ch == '/')
	{
	  if ((ch = getchar()) == EOF)
	    {
	      fprintf (stderr, "unexpected EOF!\n");
	      exit (1);
	    }
	  else
	    {
	      if (ch == '*')
		{
		  eating_comment = TRUE;
		}
	      else
		{
		  ungetc (ch, stdin);
		}
	    }
	}
      else if (eating_comment && ch == '*')
	{
	  if ((ch = getchar()) == EOF)
	    {
	      fprintf (stderr, "unexpected EOF!\n");
	      exit (1);
	    }
	  else
	    {
	      if (ch == '/')
		{
		  eating_comment = FALSE;
		}
	      else
		{
		  ungetc (ch, stdin);
		}
	    }
	}
      else if (!eating_comment)
	{
	  if (!spitout && FIRSTCHAR(ch))
	    {
	      spitout = TRUE;
	      *bp++ = ch;
	    }
	  else if (spitout && OTHERCHAR(ch))
	    {
	      *bp++ = ch;
	    }
	  else if (spitout)
	    {
	      *bp++ = '\000';
	      bp = buffer;
	      if (strlen (bp) >= size)
		{
		  printf ("%s\n", bp);
		}
	      spitout = FALSE;
	    }
	}
    }
  return (0);
}