# wordsinid.awk, 19 Aug 03
#
# Find words within identifiers, the underscore is treated as
# a separator.
#
BEGIN {
	max_id_len=0
	in_idents=0
	}

$1 == "__E__O__F__"  {
	next
	}

$1 == "$___$" {
	in_idents=1
	next
	}

	{
	if (in_idents == 1) {
	   lower_id=tolower($1)
	   sub(/_+$/, "", $1)
	   if ($1 == "") {
	      next
	      }
	   cur_splits=split($1, sub_ids, "_")
	   num_splits[cur_splits]++
	   num_words=0
	   for (s=1; s <= cur_splits; s++)
	      {
	      if (word[sub_ids[s]] != 0)
	         {
	         num_words++
	         word[sub_ids[s]]++
		 }
	      }
	   words_in_id[num_words]++
	} else {
	   word[tolower($1)]=1
	}
	next
	}

END {
    TEMP_FILE="TeMp.tEmP"
    printf("") > TEMP_FILE
    for (ind in words_in_id)
       print ind " " 0+words_in_id[ind] >> TEMP_FILE
    close(TEMP_FILE)
    print "File: idwords.d"
    system("sort -g < " TEMP_FILE)
    print "End File"
    printf("") > TEMP_FILE
    for (ind in num_splits)
       print ind " " 0+num_splits[ind] >> TEMP_FILE
    close(TEMP_FILE)
    print "File: idunders.d"
    system("sort -g < " TEMP_FILE)
    print "End File"
    
    printf("") > TEMP_FILE
    for (ind in word)
       if (word[ind] > 1)
          print ind " " word[ind]-1 >> TEMP_FILE
    close(TEMP_FILE)
    print "File: word_cnt.d"
    system("sort -k 2 -nr < " TEMP_FILE)
    print "End File"
    
    system("rm " TEMP_FILE)
    }

