Listing 4

int is_c_function_declaration (char *start_ptr) {

  int i;
  int returnval = TRUE;
  int openparen = FALSE;
  int lasttoken = ERROR,
    lasttoken_2 = ERROR, 
    lasttoken_3 = ERROR;
  int lasttoken_ptr;    
  char *buf;
  char *open_block_ptr; 

  if ((open_block_ptr = index (start_ptr, '{')) == NULL)
    return FALSE;

  if ((buf = (char *) calloc (open_block_ptr - start_ptr + 2, 
			      sizeof (char))) == NULL)
    error ("Is_c_function_declaration: %s", strerror (errno));


  strncpy (buf, start_ptr, open_block_ptr - start_ptr + 1);
  buf[open_block_ptr - start_ptr + 1] = 0;

  tokenize (buf);

  if (c_messages[c_message_ptr + 1] -> tokentype != OPENBLOCK)
    parser_error 
      ("Is_c_function_declaration: Function start not found.");

  for (i = N_MESSAGES; i > c_message_ptr; i--) {

    if ((c_messages[i] -> tokentype == WHITESPACE) ||
	(c_messages[i] -> tokentype == NEWLINE))
      continue;

    switch ( c_messages[i] -> tokentype )
      {
      case LABEL:
	if (!strcmp (c_messages[i] -> name, "main"))
	  main_declaration = TRUE;
	break;
      case OPENPAREN:
	if ((c_messages[lasttoken_ptr] -> tokentype != LABEL) ||
	    is_c_keyword (c_messages[lasttoken_ptr]->name))
	  returnval = FALSE;
	if ((lasttoken_2 != LABEL) && (lasttoken_2 != CHAR))
	  returnval = FALSE;
	/* Check for a method declaration. */
	if ((lasttoken_3 == LABEL) && (lasttoken_2 == LABEL) && 
	    (lasttoken == LABEL))
	  returnval = FALSE;
	openparen = TRUE;
	break;
      case CLOSEPAREN:
	if (!openparen)
	  returnval = FALSE;
	break;
      case SEMICOLON:
	returnval = FALSE;
	goto done;
	break;
      case OPENBLOCK:
	if (c_messages[lasttoken_ptr] -> tokentype != CLOSEPAREN)
	  returnval = FALSE;
	break;
      case CLOSEBLOCK:
	returnval = FALSE;
      default:
	break;
      }

    lasttoken_ptr = i;
    lasttoken_3 = lasttoken_2;
    lasttoken_2 = lasttoken;
    lasttoken = c_messages[i] -> tokentype;
  }

 done:
  delete_c_messages ();
  free (buf);

  return returnval;
  
}