fprintf(state->file, "\n"); fprintf(state->file, "#define ");
fputc('\n', state->file); fputs("#define ", state->file);
interface(TreeState *state){    IDL_tree iface = state->tree, iter;    char *className = IDL_IDENT(IDL_INTERFACE(iface).ident).str;    char *classNameUpper;    const char *iid;    const char *name_space;    struct nsID id;    char iid_parsed[UUID_LENGTH];    fprintf(state->file,   "\n/* starting interface:    %s */\n",            className);    name_space = IDL_tree_property_get(IDL_INTERFACE(iface).ident, "namespace");    iid = IDL_tree_property_get(IDL_INTERFACE(iface).ident, "uuid");    if (name_space) {        fprintf(state->file, "/* namespace:             %s */\n",                name_space);        fprintf(state->file, "/* fully qualified name:  %s.%s */\n",                name_space,className);    }    if (iid) {        /* Redundant, but a better error than 'cannot parse.' */        if (strlen(iid) != 36) {            IDL_tree_error(state->tree, "IID %s is the wrong length\n", iid);            return FALSE;        }        /*         * Parse uuid and then output resulting nsID to string, to validate         * uuid and normalize resulting .h files.         */        if (!xpidl_parse_iid(&id, iid)) {            IDL_tree_error(state->tree, "cannot parse IID %s\n", iid);            return FALSE;        }        if (!xpidl_sprint_iid(&id, iid_parsed)) {            IDL_tree_error(state->tree, "error formatting IID %s\n", iid);            return FALSE;        }        /* #define NS_ISUPPORTS_IID_STR "00000000-0000-0000-c000-000000000046" */        fprintf(state->file, "\n");        fprintf(state->file, "#define ");        write_classname_iid_define(state->file, className);        fprintf(state->file, "_STR \"%s\"\n", iid_parsed);        /* #define NS_ISUPPORTS_IID { {0x00000000 .... 0x46 }} */        fprintf(state->file, "#define ");        write_classname_iid_define(state->file, className);        fprintf(state->file, " \\\n"                "  {0x%.8x, 0x%.4x, 0x%.4x, \\\n"                "    { 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, "                "0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x }}\n",                id.m0, id.m1, id.m2,                id.m3[0], id.m3[1], id.m3[2], id.m3[3],                id.m3[4], id.m3[5], id.m3[6], id.m3[7]);    }    /*     * #define NS_DECL_NSIFOO - create method prototypes that can be used in     * class definitions that support this interface.     *     * Walk the tree explicitly to prototype a reworking of xpidl to get rid of     * the callback mechanism.     */    fputc('\n', state->file);    fputs("/* Use this when declaring classes that implement this "          "interface. */\n", state->file);    fputs("#define NS_DECL_", state->file);    classNameUpper = className;    while (*classNameUpper != '\0')        fputc(toupper(*classNameUpper++), state->file);    fputs(" \\\n", state->file);    if (IDL_INTERFACE(state->tree).body == NULL)        fputs("/* no methods */", state->file);    for (iter = IDL_INTERFACE(state->tree).body;         iter != NULL;         iter = IDL_LIST(iter).next)    {        IDL_tree data = IDL_LIST(iter).data;        switch(IDL_NODE_TYPE(data)) {          case IDLN_OP_DCL:            fputs("  ", state->file); /* XXX abstract to 'indent' */            write_method_signature(data, state->file);            break;          case IDLN_ATTR_DCL:            fputs("  ", state->file);            if (!write_attr_accessor(data, state->file, TRUE))                return FALSE;            if (!IDL_ATTR_DCL(state->tree).f_readonly) {                fputs("  ", state->file);                if (!write_attr_accessor(data, state->file, FALSE))                    return FALSE;            }            break;          case IDLN_CONST_DCL:              /* ignore it here; it doesn't contribute to the macro. */              continue;          case IDLN_CODEFRAG:/* IDL_tree_warning crashes in libIDL 0.6.5, sometimes */#if !(LIBIDL_MAJOR_VERSION == 0 && LIBIDL_MINOR_VERSION == 6 && \      LIBIDL_MICRO_VERSION == 5)              IDL_tree_warning(iter, IDL_WARNING1,                               "%%{ .. %%} code fragment within interface "                               "ignored when generating NS_DECL_IFOO macro; "                               "if the code fragment contains method "                               "declarations, the macro probably isn't "                               "complete.");#endif              break;          default:            IDL_tree_error(iter,                           "unexpected node type %d! "                           "Please file a bug against the xpidl component.",                           IDL_NODE_TYPE(data));            return FALSE;        }        if (IDL_LIST(iter).next != NULL) {            fprintf(state->file, "; \\\n");        } else {            fprintf(state->file, "; \n");        }    }    fprintf(state->file, "\n");    /* The interface declaration itself. */    fprintf(state->file, "class %s", className);    if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {        fputs(" : ", state->file);        do {            fprintf(state->file, "public %s",                    IDL_IDENT(IDL_LIST(iter).data).str);            if (IDL_LIST(iter).next)                fputs(", ", state->file);        } while ((iter = IDL_LIST(iter).next));    }    fputs(" {\n"          " public: \n", state->file);    if (iid) {        fputs("  NS_DEFINE_STATIC_IID_ACCESSOR(", state->file);        write_classname_iid_define(state->file, className);        fputs(")\n", state->file);    }    state->tree = IDL_INTERFACE(iface).body;    if (state->tree && !xpidl_process_node(state))        return FALSE;    fputs("};\n", state->file);    return TRUE;}