static void list_qdisc(struct nl_object *obj, void *arg) { struct rtnl_qdisc *qdisc = nl_object_priv(obj); struct rtnl_tc *tc = (struct rtnl_tc *) qdisc; nl_object_dump(obj, ¶ms); list_cls(rtnl_tc_get_ifindex(tc), rtnl_tc_get_handle(tc)); if (rtnl_tc_get_parent(tc) == TC_H_ROOT) { list_cls(rtnl_tc_get_ifindex(tc), TC_H_ROOT); list_classes(rtnl_tc_get_ifindex(tc), TC_H_ROOT); } list_classes(rtnl_tc_get_ifindex(tc), rtnl_tc_get_handle(tc)); }
void push (umlclassnode *node, batch *b) { umlclasslist used_classes, tmpnode; module *m; declaration *d; namelist l_tmp; if (node == NULL || find_class (node) != NULL) { return; } l_tmp = NEW (namenode); l_tmp->name = strdup (node->key->name); l_tmp->next = tmp_classes; tmp_classes = l_tmp; used_classes = list_classes (node, b); /* Make sure all classes that this one depends on are already pushed. */ tmpnode = used_classes; while (tmpnode != NULL) { /* don't push this class !*/ if (! eq (node->key->name, tmpnode->key->name) && ! (is_present (tmp_classes, tmpnode->key->name) ^ b->mask)) { push (tmpnode, b); } tmpnode = tmpnode->next; } if (node->key->package != NULL) { umlpackagelist pkglist = make_package_list (node->key->package); m = find_or_add_module (&decls, pkglist); if (m->contents == NULL) { m->contents = NEW (declaration); d = m->contents; d->prev = NULL; } else { /* We can simply append because all classes that we depend on are already pushed. */ d = append_decl (m->contents); } } else { if (decls == NULL) { decls = NEW (declaration); d = decls; d->prev = NULL; } else { d = append_decl (decls); /* We can simply append because all classes that we depend on are already pushed. */ } } d->decl_kind = dk_class; d->next = NULL; d->u.this_class = NEW (umlclassnode); memcpy (d->u.this_class, node, sizeof(umlclassnode)); if (strncmp (node->key->stereotype, "CORBA", 5) == 0) use_corba = 1; }
static void list_class(struct nl_object *obj, void *arg) { struct rtnl_tc *tc = nl_object_priv(obj); nl_object_dump(obj, ¶ms); list_classes(rtnl_tc_get_ifindex(tc), rtnl_tc_get_handle(tc)); list_qdiscs(rtnl_tc_get_ifindex(tc), rtnl_tc_get_handle(tc)); }
void determine_includes (declaration *d, batch *b) { // si c'est un namespace ... if (d->decl_kind == dk_module) { declaration *inner = d->u.this_module->contents; while (inner != NULL) { determine_includes (inner, b); inner = inner->next; } // sinon on push_include()... } else { umlclasslist cl = list_classes (d->u.this_class, b); while (cl != NULL) { push_include (cl); cl = cl->next; } } }
void generate_code_csharp (batch *b) { umlclasslist tmplist = b->classlist; FILE *licensefile = NULL; /* open license file */ if (b->license != NULL) { licensefile = fopen (b->license, "r"); if (!licensefile) { fprintf (stderr, "Can't open the license file.\n"); exit (1); } } while (tmplist != NULL) { char *tmpname; char outfilename[SMALL_BUFFER]; umlclasslist used_classes; if (is_present (b->classes, tmplist->key->name) ^ b->mask) { tmplist = tmplist->next; continue; } sprintf (outfilename, "%s.cs", tmplist->key->name); spec = open_outfile (outfilename, b); if (spec == NULL) { tmplist = tmplist->next; continue; } /* add license to the header */ if (b->license != NULL) { char lc; rewind (licensefile); while ((lc = fgetc (licensefile)) != EOF) print ("%c", lc); } emit ("%s", "using System;\n\n"); /* We generate the import clauses */ used_classes = list_classes (tmplist, b); if (used_classes != NULL) { while (used_classes != NULL) { umlpackagelist pkg = make_package_list (used_classes->key->package); if (pkg != NULL) { if (strcmp (pkg->key->id, tmplist->key->package->id)) { /* This class' package and our current class' package are not the same */ emit ("using %s.%s;\n", pkgname (pkg), used_classes->key->name); } } else { /* No info for this class' package, we include it directly */ /*emit ("import %s;\n",used_classes->key->name);*/ } used_classes = used_classes->next; } emit ("\n"); } if (tmplist->key->package != NULL) { umlpackagelist pkg = make_package_list (tmplist->key->package); emit ("namespace %s {\n\n", pkgname (pkg)); indentlevel++; } print ("public "); tmpname = strtolower (tmplist->key->stereotype); if (eq ("interface", tmpname)) { emit ("interface "); } else { if (tmplist->key->isabstract) { emit ("interface "); } else emit ("class "); } free (tmpname); emit ("%s", tmplist->key->name); if (tmplist->parents != NULL) { umlclasslist parents = tmplist->parents; while (parents != NULL) { tmpname = strtolower (parents->key->stereotype); if (eq (tmpname, "interface")) { emit (" : "); } else { emit (" : "); } free (tmpname); emit ("%s", parents->key->name); parents = parents->next; } } emit (" {\n\n"); indentlevel++; if (tmplist->key->attributes != NULL) { umlattrlist umla = tmplist->key->attributes; print ("// Attributes and properties\n"); while (umla != NULL) { switch (umla->key.visibility) { case '0': print ("public "); break; case '1': print ("private "); break; case '2': print ("protected "); break; } if (umla->key.isstatic) { emit ("static "); } emit ("%s %s", umla->key.type, umla->key.name); if (umla->key.value[0] != 0) { emit (" = %s", umla->key.value); } int wp = 0, rp = 0; if (eq (umla->key.comment, "rproperty")) rp = 1; else if (eq (umla->key.comment, "wproperty")) wp = 1; else if (eq (umla->key.comment, "rwproperty")) rp = wp = 1; if (wp || rp) { emit (" {\n"); indentlevel++; if (rp) print ("get;\n"); if (wp) print ("set;\n"); indentlevel--; print ("}\n"); } else emit (";\n"); umla = umla->next; } emit ("\n"); } if (tmplist->associations != NULL) { umlassoclist assoc = tmplist->associations; print ("// Associations \n"); while (assoc != NULL) { /* Not sure how to do this actually...*/ if (assoc->composite ) print ("protected "); else print ("private "); emit ("%s %s;\n", assoc->key->name, assoc->name); assoc = assoc->next; } emit ("\n"); } if (tmplist->key->operations != NULL) { umloplist umlo = tmplist->key->operations; while (umlo != NULL) { umlattrlist tmpa = umlo->key.parameters; print ("// Operation\n"); while (tmpa != NULL) { print ("// param %s\n", tmpa->key.name); tmpa = tmpa->next; } if (strcmp (umlo->key.attr.type, "void")) print ("// return %s\n", umlo->key.attr.type); print (""); if (umlo->key.attr.isabstract) { /*emit ("public ");*/ umlo->key.attr.value[0] = '0'; } else { switch (umlo->key.attr.visibility) { case '0': emit ("public "); break; case '1': emit ("private "); break; case '2': emit ("protected "); break; } } if (umlo->key.attr.isstatic) { emit ("static "); } if (strlen (umlo->key.attr.type) > 0) { emit ("%s ", umlo->key.attr.type); } emit ("%s (", umlo->key.attr.name); tmpa = umlo->key.parameters; while (tmpa != NULL) { emit ("%s %s", tmpa->key.type, tmpa->key.name); /* if ( tmpa->key.value[0] != 0 ){ emit (" = %s",tmpa->key.value); } */ tmpa = tmpa->next; if (tmpa != NULL) emit (", "); } emit (")"); if (umlo->key.attr.isabstract ) { emit (";\n"); } else { emit ("\n"); print ("{\n"); indentlevel++; if (umlo->key.implementation != NULL) { print ("%s\n", umlo->key.implementation); } else if (strcmp (umlo->key.attr.type, "void") != 0) { print ("%s\n", "throw new System.Exception (\"Not implemented yet!\");"); } indentlevel--; print ("}\n"); } umlo = umlo->next; } emit ("\n"); } indentlevel--; print ("}\n\n"); if (tmplist->key->package != NULL) { indentlevel--; print ("}\n\n"); } fclose (spec); tmplist = tmplist->next; } }
void generate_code_java(batch *b) { umlclasslist tmplist, parents; umlassoclist associations; umlattrlist umla, tmpa; umlpackagelist tmppcklist; umloplist umlo; char *tmpname; char outfilename[90]; FILE * outfile, *dummyfile, *licensefile = NULL; int file_found = 0; umlclasslist used_classes; #define CLASSTYPE_CLASS 0 #define CLASSTYPE_ABSTRACT 1 #define CLASSTYPE_INTERFACE 2 int classtype; int tmpdirlgth, tmpfilelgth; if (b->outdir == NULL) b->outdir = "."; tmpdirlgth = strlen(b->outdir); tmplist = b->classlist; /* open license file */ if ( b->license != NULL ) { licensefile = fopen(b->license, "r"); if(!licensefile) { fprintf(stderr, "Can't open the license file.\n"); exit(2); } } while ( tmplist != NULL ) { if ( ! ( is_present(b->classes, tmplist->key->name) ^ b->mask ) ) { tmpname = tmplist->key->name; /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } sprintf(outfilename, "%s/%s.java", b->outdir, tmplist->key->name); dummyfile = fopen(outfilename, "r"); file_found = dummyfile != NULL; if (file_found) { d2c_parse_impl(dummyfile, "//", ""); fclose(dummyfile); if (d2c_backup(outfilename)) exit(5); } if ( b->clobber || ! file_found ) { outfile = fopen(outfilename, "w"); if ( outfile == NULL ) { fprintf(stderr, "Can't open file %s for writing\n", outfilename); exit(3); } d2c_dump_impl(outfile, "opening", ""); /* add license to the header */ if(b->license != NULL) { char lc; rewind(licensefile); while((lc = fgetc(licensefile)) != EOF) d2c_fputc(lc, outfile); } tmppcklist = make_package_list(tmplist->key->package); if ( tmppcklist != NULL ){ d2c_fprintf(outfile,"package %s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while ( tmppcklist != NULL ) { d2c_fprintf(outfile,".%s",tmppcklist->key->name); tmppcklist=tmppcklist->next; } d2c_fputs(";\n\n", outfile); } /* We generate the import clauses */ used_classes = list_classes(tmplist, b); while (used_classes != NULL) { tmppcklist = make_package_list(used_classes->key->package); if ( tmppcklist != NULL ) { if ( strcmp(tmppcklist->key->id,tmplist->key->package->id)) { /* This class' package and our current class' package are not the same */ d2c_fprintf(outfile,"import %s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while ( tmppcklist != NULL ) { d2c_fprintf(outfile, ".%s", tmppcklist->key->name); tmppcklist=tmppcklist->next; } d2c_fprintf(outfile,".%s;\n",used_classes->key->name); } } else { /* No info for this class' package, we include it directly */ d2c_fprintf(outfile, "import %s;\n",used_classes->key->name); } used_classes = used_classes->next; } d2c_dump_impl(outfile, "import", ""); d2c_fprintf(outfile, "\npublic "); tmpname = strtolower(tmplist->key->stereotype); if (eq("interface", tmpname) ) classtype = CLASSTYPE_INTERFACE; else { if (tmplist->key->isabstract) classtype = CLASSTYPE_ABSTRACT; else classtype = CLASSTYPE_CLASS; } free(tmpname); switch(classtype) { case CLASSTYPE_INTERFACE: d2c_fprintf(outfile, "interface "); break; case CLASSTYPE_ABSTRACT: d2c_fprintf(outfile, "abstract class "); break; case CLASSTYPE_CLASS: d2c_fprintf(outfile, "class "); break; } d2c_fprintf(outfile, "%s", tmplist->key->name); if (java_manage_parents(outfile, tmplist->parents, JAVA_EXTENDS) == 0) { d2c_fprintf(outfile, "\n"); d2c_dump_impl(outfile, "extends", ""); } java_manage_parents(outfile, tmplist->parents, JAVA_IMPLEMENTS); // At this point we need to make a decision: // If you want to implement flexibility to add "extends", then the brace must be on the next line. if (1) // if (dumping_implementations) d2c_fprintf(outfile, "\n"); d2c_dump_impl(outfile, "inheritence", ""); d2c_open_brace(outfile, ""); umla = tmplist->key->attributes; if( umla != NULL) d2c_fprintf(outfile, "/** Attributes */\n"); while ( umla != NULL) { d2c_fprintf(outfile, "%s ", dia_visibility_to_string(umla->key.visibility)); if (umla->key.isstatic) d2c_fprintf(outfile, "static "); d2c_fprintf(outfile, "%s %s", umla->key.type, umla->key.name); if ( umla->key.value[0] != 0 ) d2c_fprintf(outfile, " = %s", umla->key.value); d2c_fprintf(outfile, ";\n"); umla = umla->next; } if (classtype != CLASSTYPE_INTERFACE) d2c_dump_impl(outfile, "attributes", ""); associations = tmplist->associations; if (associations != NULL) d2c_fprintf(outfile, "/** Associations */\n"); while ( associations != NULL ) { d2c_fprintf(outfile, "private %s %s;\n", associations->key->name, associations->name); associations = associations->next; } d2c_dump_impl(outfile, "associations", ""); // Operations here // umlo = tmplist->key->operations; while ( umlo != NULL) { d2c_fprintf(outfile, "/**\n"); d2c_fprintf(outfile, " * Operation\n"); d2c_fprintf(outfile, " *\n"); tmpa = umlo->key.parameters; while (tmpa != NULL) { d2c_fprintf(outfile, " * @param %s\n", tmpa->key.name); tmpa = tmpa->next; } if(strcmp(umlo->key.attr.type, "void")) d2c_fprintf(outfile, " * @return %s\n", umlo->key.attr.type); d2c_fprintf(outfile, " */\n"); //d2c_fprintf(outfile, " "); if ( umlo->key.attr.isabstract ) { d2c_fprintf(outfile, "abstract "); umlo->key.attr.value[0] = '0'; } d2c_fprintf(outfile, "%s ", dia_visibility_to_string(umlo->key.attr.visibility)); if ( umlo->key.attr.isstatic ) d2c_fprintf(outfile, "static "); if (strlen(umlo->key.attr.type) > 0) d2c_fprintf(outfile, "%s ", umlo->key.attr.type); d2c_fprintf(outfile, "%s ( ", umlo->key.attr.name); tmpa = umlo->key.parameters; while (tmpa != NULL) { d2c_fprintf(outfile, "%s %s", tmpa->key.type, tmpa->key.name); /* if ( tmpa->key.value[0] != 0 ){ d2c_fprintf(outfile," = %s",tmpa->key.value); } */ tmpa = tmpa->next; if (tmpa != NULL) d2c_fprintf(outfile, ", "); } d2c_fprintf(outfile, " )"); // RK - Not sure this is right but I did it. This // prevents curly braces from being applied when CLASSTYPE is interface. if ( umlo->key.attr.isabstract || classtype == CLASSTYPE_INTERFACE) d2c_fprintf(outfile, ";\n"); else { d2c_open_brace(outfile, ""); d2c_dump_impl(outfile, "method", d2c_operation_mangle_name(umlo)); if ( umlo->key.implementation != NULL ) d2c_fprintf(outfile, "%s\n", umlo->key.implementation); d2c_close_brace(outfile, ""); } umlo = umlo->next; } if (classtype != CLASSTYPE_INTERFACE) d2c_dump_impl(outfile, "other.operations", ""); d2c_close_brace(outfile, "\n"); d2c_dump_impl(outfile, "closing", ""); d2c_deprecate_impl(outfile, "//", ""); fclose(outfile); } } tmplist = tmplist->next; } }
void generate_code_ruby(batch *b) { umlclasslist tmplist, parents, incparent; umlassoclist associations; umlattrlist umla, tmpa, parama; umlpackagelist tmppcklist; umloplist umlo; char *tmpname; char outfilename[BIG_BUFFER]; FILE * outfile, *dummyfile, *licensefile = NULL; umlclasslist used_classes; int tmpdirlgth, tmpfilelgth; if (b->outdir == NULL) { b->outdir = "."; } tmpdirlgth = strlen(b->outdir); tmplist = b->classlist; /* open license file */ if ( b->license != NULL ) { licensefile = fopen(b->license, "r"); if(!licensefile) { fprintf(stderr, "Can't open the license file.\n"); exit(2); } } while ( tmplist != NULL ) { if ( ! ( is_present(b->classes, tmplist->key->name) ^ b->mask ) ) { char *pretty_outfilename; tmpname = tmplist->key->name; /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } pretty_outfilename = strtolower(tmplist->key->name); sprintf(outfilename, "%s/%s.class.rb", b->outdir, pretty_outfilename); dummyfile = fopen(outfilename, "r"); if ( b->clobber || ! dummyfile ) { int have_parent = 0; outfile = fopen(outfilename, "w"); if ( outfile == NULL ) { fprintf(stderr, "Can't open file %s for writing\n", outfilename); exit(3); } /* header */ /* add license to the header */ if (b->license != NULL) { char lc; rewind(licensefile); while((lc = fgetc(licensefile)) != EOF) { fprintf(outfile,"%c",lc); } } fprintf(outfile,"#!/usr/bin/env ruby\n#Source generated by dia2code.\n\n" ); /* We generate the include clauses */ used_classes = list_classes(tmplist, b); while (used_classes != NULL) { tmppcklist = make_package_list(used_classes->key->package); if ( tmppcklist != NULL ) { if ( strcmp(tmppcklist->key->id,tmplist->key->package->id)) { /* This class' package and our current class' package are not the same */ fprintf(outfile, "include "); fprintf(outfile,"%s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while (tmppcklist != NULL) { fprintf(outfile, "%s", tmppcklist->key->name); tmppcklist=tmppcklist->next; } fprintf(outfile,"%s\n",used_classes->key->name); } } else { /* No info for this class' package, we include it directly fprintf(outfile, "require \"%s.class.rb\"\n",strtolower(used_classes->key->name)); */ } used_classes = used_classes->next; } incparent = tmplist->parents; if (incparent != NULL) { while (incparent!= NULL) { tmpname = strtolower(incparent->key->stereotype); if (eq("interface", tmpname) ) { if (strcmp("Enumerable",incparent->key->name) && strcmp("Comparable",incparent->key->name)) { fprintf(outfile, "require \""); fprintf(outfile, "%s.module.rb\" \n", strtolower(incparent->key->name)); } else { break; } } else { fprintf(outfile, "require \""); fprintf(outfile, "%s.class.rb\" \n", strtolower(incparent->key->name)); } free(tmpname); incparent = incparent->next; } } fprintf(outfile,"\n\n"); fprintf(outfile,"# %s - short description\n", pretty_outfilename); fprintf(outfile,"# Author:: <*****@*****.**>\n"); fprintf(outfile,"# Copyright:: (C) XXX\n"); fprintf(outfile,"# License:: GPL\n"); tmppcklist = make_package_list(tmplist->key->package); if ( tmppcklist != NULL ) { int packcounter = 0; /* fprintf(outfile,"# == MODULES\n#module %s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while ( tmppcklist != NULL ){ if( packcounter == 1 ) { fprintf(outfile,"\n" ); fprintf(outfile,"# === SUBMODULES\n# submodule %s",tmppcklist->key->name); } else { fprintf(outfile,".%s",tmppcklist->key->name); } tmppcklist=tmppcklist->next; packcounter++; } fprintf(outfile,"\n"); */ } tmpname = strtolower(tmplist->key->stereotype); /* if (eq("interface", tmpname)) { fprintf(outfile," * @interface\n" ); } else { */ if ( strlen(tmplist->key->comment) > 0 ) { fprintf(outfile,"# %s\n",tmplist->key->comment); } else { fprintf(outfile,"# XXX\n",tmplist->key->comment); } if (tmplist->key->isabstract) { fprintf(outfile,"# * this class is abstract\n" ); } /* } */ fprintf(outfile,"\n"); free(tmpname); fprintf(outfile, "class %s", tmplist->key->name); parents = tmplist->parents; if (parents != NULL) { while ( parents != NULL ) { tmpname = strtolower(parents->key->stereotype); if (strcmp("interface", tmpname)) { /* printf("We're in: %s, type: %s",parents->key->name,tmpname); */ if (have_parent) { fprintf(outfile, " # can't inherit %s\n", parents->key->name); } else { fprintf(outfile, " < "); fprintf(outfile, "%s", parents->key->name); have_parent = 1; } } free(tmpname); parents = parents->next; } } free(parents); parents = tmplist->parents; fprintf(outfile,"\n"); if (parents != NULL) { while ( parents != NULL ) { tmpname = strtolower(parents->key->stereotype); if (eq("interface", tmpname)) { fprintf(outfile,"%sinclude %s\n",TABS,parents->key->name); } free(tmpname); parents = parents->next; } } fprintf(outfile, "\n"); umla = tmplist->key->attributes; while (umla != NULL) { if ( strlen(umla->key.comment) > 0 ) { fprintf(outfile, "%s# %s \n", TABS, umla->key.comment); } else { fprintf(outfile, "%s# XXX \n", TABS); } fprintf(outfile, "%s# * access ", TABS); switch (umla->key.visibility) { case '0': fprintf (outfile, "public"); break; case '1': fprintf (outfile, "private"); break; case '2': fprintf (outfile, "protected"); break; } fprintf(outfile,"\n" ); /* if (umla->key.isstatic) { fprintf(outfile, "static "); } */ /* fprintf(outfile, "%s %s", umla->key.type, umla->key.name); */ if ( umla->key.value[0] != 0 ) { fprintf(outfile, "%s@%s = %s\n", TABS, umla->key.name, umla->key.value); } if ( umla->key.isstatic ) { fprintf(outfile, "%s@@%s = nil\n", TABS, umla->key.name ); } fprintf(outfile, TABS); if (umla->key.visibility == '0') { /* make it public */ fprintf(outfile, "attr_acessor :%s\n", umla->key.name); fprintf(outfile, "%spublic :%s\n\n",TABS, umla->key.name); } else if (umla->key.visibility == '1') { /* make it private */ fprintf(outfile, "attr :%s\n", umla->key.name); fprintf(outfile, "%sprivate :%s\n\n", TABS, umla->key.name); } else { fprintf(outfile, "attr :%s\n", umla->key.name); fprintf(outfile, "%sprotected :%s\n\n",TABS, umla->key.name); } umla = umla->next; } associations = tmplist->associations; /* I've turned off associations coz they are: not working and * i can't think of how it could be used in source */ while ( associations != NULL && 0) { fprintf(outfile, "# association %s to %s\n", associations->key->name, associations->name); fprintf(outfile, "%s# access private\n", TABS ); fprintf(outfile, "%s# attribute @%s;\n\n", TABS, associations->name); associations = associations->next; } umlo = tmplist->key->operations; while ( umlo != NULL) { int bracket_opened = 0; if ( strlen(umlo->key.attr.comment) > 0 ) { fprintf(outfile,"%s# %s\n", TABS, umlo->key.attr.comment ); } else { fprintf(outfile,"%s# XXX\n", TABS ); } if ( umlo->key.attr.isabstract ) { fprintf(outfile,"%s# * abstract\n", TABS ); umlo->key.attr.value[0] = '0'; } fprintf(outfile,"%s# * access ", TABS ); switch (umlo->key.attr.visibility) { case '0': fprintf (outfile, "public "); break; case '1': fprintf (outfile, "private "); break; case '2': fprintf (outfile, "protected "); break; } fprintf(outfile,"\n" ); /* if ( umlo->key.attr.isstatic ) { fprintf(outfile, "static "); } */ if (strlen(umlo->key.attr.type) > 0) { fprintf(outfile,"%s# * returns %s\n", TABS,umlo->key.attr.type); } parama = umlo->key.parameters; /* document parameters */ while (parama != NULL) { char *comment = ""; if (strlen(parama->key.comment) > 0) comment = parama->key.comment; fprintf(outfile, "%s# * param %s %s %s\n", TABS, parama->key.type, parama->key.name, comment); parama= parama->next; } fprintf(outfile, TABS); fprintf(outfile, "def %s", umlo->key.attr.name); tmpa = umlo->key.parameters; if (tmpa != NULL) { fprintf(outfile, "( "); bracket_opened = 1; } while (tmpa != NULL) { fprintf(outfile, "%s", tmpa->key.name); if ( tmpa->key.value[0] != 0 ) { fprintf(outfile," = %s",tmpa->key.value); } tmpa = tmpa->next; if (tmpa != NULL) fprintf(outfile, ", "); } if (bracket_opened) { fprintf(outfile, " )"); } /* if ( umlo->key.attr.isabstract ) { fprintf(outfile, ";\n"); } else { */ fprintf(outfile, "\n"); if ( umlo->key.implementation != NULL ) { fprintf(outfile, "%s%s\n",TABS, umlo->key.implementation); } else { fprintf(outfile, "%s%sraise NotImplementedError, 'This is auto-gen. method, please implement.'\n", TABS, TABS); } fprintf(outfile, "%send\n", TABS); /* } */ switch (umlo->key.attr.visibility) { case '0': fprintf(outfile, "%spublic :%s\n\n", TABS, umlo->key.attr.name); break; case '1': fprintf(outfile, "%sprivate :%s\n\n", TABS, umlo->key.attr.name); break; case '2': fprintf(outfile, "%sprotected :%s\n\n", TABS, umlo->key.attr.name); break; } umlo = umlo->next; } fprintf(outfile, "end\n\n"); fprintf(outfile, "\n\n"); fclose(outfile); } } tmplist = tmplist->next; } }
void generate_code_php(batch *b) { umlclasslist tmplist, parents, incparent; umlassoclist associations; umlattrlist umla, tmpa, parama; umlpackagelist tmppcklist; umloplist umlo; char *tmpname; char outfilename[90]; FILE * outfile, *dummyfile, *licensefile = NULL; umlclasslist used_classes; int tmpdirlgth, tmpfilelgth; if (b->outdir == NULL) { b->outdir = "."; } tmpdirlgth = strlen(b->outdir); tmplist = b->classlist; /* open license file */ if ( b->license != NULL ) { licensefile = fopen(b->license, "r"); if(!licensefile) { fprintf(stderr, "Can't open the license file.\n"); exit(2); } } while ( tmplist != NULL ) { if ( ! ( is_present(b->classes, tmplist->key->name) ^ b->mask ) ) { tmpname = tmplist->key->name; /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } sprintf(outfilename, "%s/%s.class.php", b->outdir, tmplist->key->name); dummyfile = fopen(outfilename, "r"); if ( b->clobber || ! dummyfile ) { outfile = fopen(outfilename, "w"); if ( outfile == NULL ) { fprintf(stderr, "Can't open file %s for writing\n", outfilename); exit(3); } /* header */ /* add license to the header */ if(b->license != NULL){ char lc; rewind(licensefile); while((lc = fgetc(licensefile)) != EOF){ fprintf(outfile,"%c",lc); } } fprintf(outfile,"<?php\n\n" ); /* We generate the include clauses */ used_classes = list_classes(tmplist, b); while (used_classes != NULL) { tmppcklist = make_package_list(used_classes->key->package); if ( tmppcklist != NULL ){ if ( strcmp(tmppcklist->key->id,tmplist->key->package->id)){ /* This class' package and our current class' package are not the same */ fprintf(outfile, "#include (\""); fprintf(outfile,"%s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while ( tmppcklist != NULL ){ fprintf(outfile, "/%s", tmppcklist->key->name); tmppcklist=tmppcklist->next; } fprintf(outfile,"/"); fprintf(outfile,"%s.class.php\");\n",used_classes->key->name); } } else { /* No info for this class' package, we include it directly */ fprintf(outfile, "#include( \"%s.class.php\" );\n",used_classes->key->name); } used_classes = used_classes->next; } incparent = tmplist->parents; if (incparent != NULL) { while ( incparent!= NULL ) { tmpname = strtolower(incparent->key->stereotype); fprintf(outfile, "include( \""); free(tmpname); fprintf(outfile, "%s.class.php\" );\n", incparent->key->name); incparent = incparent->next; } } fprintf(outfile,"/**\n" ); fprintf(outfile," * XXX detailed description\n" ); fprintf(outfile," *\n" ); fprintf(outfile," * @author XXX\n" ); fprintf(outfile," * @copyright XXX\n" ); tmppcklist = make_package_list(tmplist->key->package); if ( tmppcklist != NULL ){ int packcounter = 0; fprintf(outfile," * @package %s",tmppcklist->key->name); tmppcklist=tmppcklist->next; while ( tmppcklist != NULL ){ if( packcounter == 1 ) { fprintf(outfile,"\n" ); fprintf(outfile," * @subpackage %s",tmppcklist->key->name); } else { fprintf(outfile,".%s",tmppcklist->key->name); } tmppcklist=tmppcklist->next; packcounter++; } fprintf(outfile,"\n"); } tmpname = strtolower(tmplist->key->stereotype); /* if ( ! strcmp("interface", tmpname) ) { fprintf(outfile," * @interface\n" ); } else { */ if (tmplist->key->isabstract) { fprintf(outfile," * @abstract\n" ); } /* } */ free(tmpname); fprintf(outfile," */\n" ); fprintf(outfile, "class %s", tmplist->key->name); parents = tmplist->parents; if (parents != NULL) { while ( parents != NULL ) { tmpname = strtolower(parents->key->stereotype); fprintf(outfile, " extends "); free(tmpname); fprintf(outfile, "%s", parents->key->name); parents = parents->next; } } fprintf(outfile, " {\n"); fprintf(outfile, "%s// Attributes\n", TABS); umla = tmplist->key->attributes; while ( umla != NULL) { fprintf(outfile," /**\n" ); fprintf(outfile," * XXX\n" ); fprintf(outfile," * @access " ); switch (umla->key.visibility) { case '0': fprintf (outfile, "public"); break; case '1': fprintf (outfile, "private"); break; case '2': fprintf (outfile, "protected"); break; } fprintf(outfile,"\n" ); fprintf(outfile," */\n" ); /* if (umla->key.isstatic) { fprintf(outfile, "static "); } */ /* fprintf(outfile, "%s %s", umla->key.type, umla->key.name); */ fprintf(outfile, TABS); fprintf(outfile, "var $%s", umla->key.name); if ( umla->key.value[0] != 0 ) { fprintf(outfile, " = %s", umla->key.value); } fprintf(outfile, ";\n\n"); umla = umla->next; } fprintf(outfile, "%s// Associations\n", TABS); associations = tmplist->associations; while ( associations != NULL ) { fprintf(outfile," /**\n" ); fprintf(outfile," * XXX\n" ); fprintf(outfile," * @accociation %s to %s\n", associations->key->name, associations->name); fprintf(outfile," * @access private\n" ); fprintf(outfile," */\n" ); fprintf(outfile, "%s#var $%s;\n\n", TABS, associations->name); associations = associations->next; } umlo = tmplist->key->operations; fprintf(outfile, "%s// Operations\n", TABS); while ( umlo != NULL) { fprintf(outfile," /**\n" ); fprintf(outfile," * XXX\n" ); fprintf(outfile," * \n" ); if ( umlo->key.attr.isabstract ) { fprintf(outfile," * @abstract\n" ); umlo->key.attr.value[0] = '0'; } fprintf(outfile," * @access " ); switch (umlo->key.attr.visibility) { case '0': fprintf (outfile, "public "); break; case '1': fprintf (outfile, "private "); break; case '2': fprintf (outfile, "protected "); break; } fprintf(outfile,"\n" ); /* if ( umlo->key.attr.isstatic ) { fprintf(outfile, "static "); } */ if (strlen(umlo->key.attr.type) > 0) { fprintf(outfile," * @returns %s\n", umlo->key.attr.type); } parama = umlo->key.parameters; // document parameters while (parama != NULL) { fprintf(outfile," * @param %s $%s XXX\n", parama->key.type, parama->key.name); parama= parama->next; } fprintf(outfile," */\n" ); fprintf(outfile, TABS); fprintf(outfile, "function %s ( ", umlo->key.attr.name); tmpa = umlo->key.parameters; while (tmpa != NULL) { fprintf(outfile, "$%s", tmpa->key.name); if ( tmpa->key.value[0] != 0 ){ fprintf(outfile," = %s",tmpa->key.value); } tmpa = tmpa->next; if (tmpa != NULL) fprintf(outfile, ", "); } fprintf(outfile, " )"); /* if ( umlo->key.attr.isabstract ) { fprintf(outfile, ";\n"); } else { */ fprintf(outfile, "{\n"); if ( umlo->key.implementation != NULL ) { fprintf(outfile, "%s\n", umlo->key.implementation); } fprintf(outfile, "%s}\n\n", TABS); /* } */ umlo = umlo->next; } fprintf(outfile, "}\n\n"); fprintf(outfile,"\n\n?>\n" ); fclose(outfile); } } tmplist = tmplist->next; } }