--- /dev/null
+#! /usr/bin/php4 -qC
+<?php
+/* vim: set binary expandtab tabstop=4 shiftwidth=4:
+-------------------------------------------------------------------------------
+Creado: jue jul 31 14:01:57 ART 2003
+Autor: Martin Marrese <mmarre@mecon.gov.ar>
+-------------------------------------------------------------------------------
+$Id$
+-----------------------------------------------------------------------------*/
+//////////////////////
+// TAG's XML
+//////////////////////
+$comienzo = <<<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
+ <XMI.content>
+ <umlobjects>
+EOT;
+$medio = <<<EOT2
+ </umlobjects>
+ <listview>
+ <listitem open="1" type="800" id="-1" label="Views" >
+ <listitem open="1" type="801" id="-1" label="Logical View" >
+EOT2;
+$fin = <<<EOT3
+ </listitem>
+ <listitem open="1" type="802" id="-1" label="Use Case View" />
+ </listitem>
+ </listview>
+ </XMI.content>
+</XMI>
+EOT3;
+
+
+$umlclass = '<UML:Class stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" >';
+$umlclass_c = '</UML:Class>';
+
+$umloperation = '<UML:Operation stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##">';
+$umloperation_c = '</UML:Operation>';
+
+$umlparameter = '<UML:Parameter stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
+
+$umlattribute = '<UML:Attribute stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
+
+$umllistitem = '<listitem open="0" type="##TYPE##" id="##ID##" label="##LABEL##" >';
+$umllistitem_c = '</listitem>';
+
+//////////////////////
+
+
+$ID = 0;
+$IDPARAM = 0;
+$ARRAY = array();
+
+for ($j = 1; $j < count($argv); $j++) {
+ $file = $argv[$j];
+ // Si es un directorio, agrego cada archivo legible .php al argv.
+ if (is_dir($file)) {
+ $dh = opendir($file);
+ while (($f = readdir($dh)) !== false) {
+ if (is_readable("$file/$f") and substr($f, -4) == '.php') {
+ $argv[] = "$file/$f";
+ }
+ }
+ closedir($dh);
+ continue;
+ // Si no, si se puede leer el archivo y es .php, lo procesa.
+ } elseif (is_readable($file) and substr($file, -4) == '.php') {
+ $cont = file ($file);
+
+ $DOCUMENTANDO = false;
+ $opciones = array ();
+ $cont_param = 0;
+ foreach ($cont as $linea) {
+ $linea = trim ($linea);
+ $tmp = preg_split ('/[^\w_\/\*\@\$\']+/', $linea);
+ //Agrego la documentacion
+ if ($tmp['0'] == '/**') { //Comienza la documentacion
+ $DOCUMENTANDO = true;
+ }
+ if ($tmp['0'] == '*/') { //Termina la documentacion
+ $DOCUMENTANDO = false;
+ }
+
+ if ($DOCUMENTANDO) {
+ if ($tmp['0'] = '*') {
+ array_shift($tmp);
+ }
+ switch ($tmp['0']) {
+ case '@access':
+ switch ($tmp['1']) {
+ case 'private' : $opciones['access'] = 201;
+ break;
+ case 'protected': $opciones['access'] = 202;
+ break;
+ default : $opciones['access'] = 200;
+ }
+ break;
+ case '@package' : $opciones['package'] = $tmp['1'];
+ break;
+ case '@abstract': $opciones['abstract'] = 1;
+ break;
+ case '@static' : $opciones['static'] = 1;
+ break;
+ case '@var' : $opciones['type'] = $tmp['1'];
+ break;
+ case '@return' : $opciones['type'] = $tmp['1'];
+ break;
+ case '@param' : $opciones['param'][$cont_param]['type'] = $tmp['1'];
+ $opciones['param'][$cont_param]['documentacion'] = implode (' ', array_slice($tmp,3));
+ $cont_param++;
+ break;
+ default:
+ if (array_key_exists('0',$tmp)) {
+ @$opciones['documentacion'].= implode (' ',$tmp)."\n";
+ }
+ }
+ }
+
+ //CLASE
+ if (!$DOCUMENTANDO && $tmp['0'] == 'class') {
+ $ID++;
+ $IDCLASE = $ID;
+
+ $ARRAY[$ID]['id'] = $ID;
+ $ARRAY[$ID]['name'] = $tmp['1'];
+ $ARRAY[$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
+ $ARRAY[$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
+ $ARRAY[$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
+ $ARRAY[$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
+ $ARRAY[$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
+ $ARRAY[$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
+ $ARRAY[$ID]['operations'] = array();
+ $ARRAY[$ID]['attributes'] = array();
+ $opciones = array();
+ }
+ //FUNCION
+ if (!$DOCUMENTANDO && $tmp['0'] == 'function') {
+ $ID++;
+ $ARRAY[$IDCLASE]['operations'][$ID]['id'] = $ID;
+ $ARRAY[$IDCLASE]['operations'][$ID]['name'] = $tmp['1'];
+ $ARRAY[$IDCLASE]['operations'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
+ $ARRAY[$IDCLASE]['operations'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
+ $ARRAY[$IDCLASE]['operations'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
+ $ARRAY[$IDCLASE]['operations'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'] = array();
+
+ //PARAMETROS
+ array_shift($tmp); //SACO EL FUNCTION
+ array_shift($tmp); //SACO EL NOMBRE DE LA FUNCION
+ for ($i = 0; $i <= count($tmp); $i++) {
+ if ($tmp[$i]{0} == '$') { //AL FINAL DEJE EL $ PARA DIFERENCIAR LOS PARAMETROS DE LOS VALORES INICIALES QUE TOMAN
+ $tmp[$i] = substr($tmp[$i], 1); //SACO EL $
+ $OPANT = $i;
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['id'] = $i;
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['name'] = $tmp[$i];
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['stereotype'] = (@$opciones['param'][$i]['stereotype']) ? $opciones['param'][$i]['stereotype'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['package'] = (@$opciones['param'][$i]['package']) ? $opciones['param'][$i]['package'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['abstract'] = (@$opciones['param'][$i]['abstract']) ? $opciones['param'][$i]['abstract'] : 0;
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['documentation'] = (@$opciones['param'][$i]['documentacion']) ? $opciones['param'][$i]['documentacion'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['static'] = (@$opciones['param'][$i]['static']) ? $opciones['param'][$i]['static'] : 0;
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['scope'] = (@$opciones['param'][$i]['access']) ? $opciones['param'][$i]['access'] : '';
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['type'] = (@$opciones['param'][$i]['type']) ? $opciones['param'][$i]['type'] : '';
+ }
+ elseif ($tmp[$i] != '//' && $tmp[$i] != 'X2C' && $tmp[$i] != '') {
+ $ARRAY[$IDCLASE]['operations'][$ID]['param'][$OPANT]['value'] .= $tmp[$i];
+ }
+ }
+ $opciones = array();
+ $cont_param = 0;
+ }
+ //ATRIBUTOS
+ if (!$DOCUMENTANDO && $tmp['0'] == 'var') {
+ $ID++;
+ $tmp['1'] = substr($tmp['1'], 1); //SACO EL $
+ if ($tmp['1']{0} == '_') {
+ $tmp['1'] = substr($tmp['1'],1); //SACO EL _
+ if (!(@$opciones['access'])) {
+ $opciones['access'] = 201;
+ }
+ }
+ //Agrego si tiene valor inicial
+ if (array_key_exists('2',$tmp)) {
+ $opciones['value'] = $tmp['2'];
+ }
+
+ $ARRAY[$IDCLASE]['attributes'][$ID]['id'] = $ID;
+ $ARRAY[$IDCLASE]['attributes'][$ID]['name'] = $tmp['1'];
+ $ARRAY[$IDCLASE]['attributes'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
+ $ARRAY[$IDCLASE]['attributes'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
+ $ARRAY[$IDCLASE]['attributes'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
+ $ARRAY[$IDCLASE]['attributes'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
+ $ARRAY[$IDCLASE]['attributes'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
+ $ARRAY[$IDCLASE]['attributes'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
+ $ARRAY[$IDCLASE]['attributes'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
+ $ARRAY[$IDCLASE]['attributes'][$ID]['value'] = (@$opciones['value']) ? $opciones['value'] : '';
+ $opciones = array(operations);
+ }
+ }
+ }
+}
+
+$m = fopen ('./umlOut.xmi', 'w');
+fwrite($m, $comienzo);
+$LISTITEM = '';
+//CLASES
+foreach ($ARRAY as $ar) {
+ //PREPARO LA CLASE {{{
+ $tmp2 = $umlclass;
+ fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/',
+ '/##STATIC##/','/##SCOPE##/'),
+ array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],$ar['documentation'],$ar['name'],
+ $ar['static'],$ar['scope']),
+ $tmp2)."\n");
+ //PREPARO LOS LISTITEM {{{
+ $tmp2 = $umllistitem;
+ $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n";
+
+ //OPERACIONES
+ foreach ($ar['operations'] as $op) {
+ $tmp2 = $umloperation;
+ fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
+ '/##NAME##/','/##STATIC##/','/##SCOPE##/'),
+ array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],
+ $op['name'],$op['static'],$op['scope']) ,
+ $tmp2)."\n");
+ //PARAMETROS NO TIENE LISTITEM
+ foreach ($op['param'] as $pa) {
+ $tmp2 = $umlparameter;
+ fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
+ '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
+ array($pa['stereotype'],$pa['package'],$pa['id'],$pa['type'],$pa['abstract'],$pa['documentation'],
+ $pa['name'],$pa['static'],$pa['scope'],$pa['value']),
+ $tmp2)."\n");
+ }
+ fwrite($m,$umloperation_c."\n");
+ //PREPARO LOS LISTITEM {{{
+ $tmp2 = $umllistitem;
+ $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n";
+ $LISTITEM.=$umllistitem_c."\n";
+ }
+ //ATRIBUTOS
+ foreach ($ar['attributes'] as $op) {
+ $tmp2 = $umlattribute;
+ fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
+ '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
+ array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],$op['name'],
+ $op['static'],$op['scope'],$op['value']),
+ $tmp2)."\n");
+ //PREPARO LOS LISTITEM {{{
+ $tmp2 = $umllistitem;
+ $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n";
+ $LISTITEM.=$umllistitem_c."\n";
+ }
+ fwrite($m,$umlclass_c);
+ $LISTITEM.=$umllistitem_c."\n";
+ //}}}
+}
+fwrite($m, $medio. $LISTITEM."\n".$fin);
+?>