X-Git-Url: https://git.llucax.com/mecon/scripts.git/blobdiff_plain/123eac53f1d3cdf23ebcdfec2c695c6f48636cc2..cba4ec1c8ae5acc82e95cd512170ba76a7b66df6:/code2xmi/code2xmi.php?ds=inline diff --git a/code2xmi/code2xmi.php b/code2xmi/code2xmi.php index 1bdeee8..b123a23 100755 --- a/code2xmi/code2xmi.php +++ b/code2xmi/code2xmi.php @@ -1,29 +1,36 @@ -#! /usr/bin/php4 -qC +#!/usr/bin/php4 -qC +Created: jue jul 31 14:01:57 ART 2003 +Author : Martin Marrese ------------------------------------------------------------------------------- $Id$ -----------------------------------------------------------------------------*/ -//Recibe como parametros el directorio o una lista de archivos a diagramar +// CONVERTS A STRING TO XML ENTITIES {{{ +function xmlentities($s) { + return str_replace( + array('&', '"', '<', '>'), + array('&', '"', '<', '>'), + $s); +} +// }}} //TAG's XML {{{ -$comienzo = << EOT; -$medio = << EOT2; -$fin = << @@ -35,7 +42,7 @@ $fin = << EOT3; //}}} -//LINEAS TEMPLATES XMI {{{ +//TEMPLATES XMI {{{ $umlclass = ''; $umlclass_c = ''; @@ -49,17 +56,15 @@ $umlattribute = ''; $umllistitem_c = ''; //}}} -//VARIABLES GLOBALES {{{ -$ID = 0; -$IDPARAM = 0; -$ARRAY = array(); +//GLOBALS {{{ +$ID = 0; //Global ID +$IDPARAM = 0; //Functions parameter ID +$ARRAY = array(); //Array with information obtained from the code file //}}} -//CHUPO LA INFO DE LOS ARCHIVOS {{{ +//GETTING DATA FROM FILES {{{ for ($j = 1; $j < count($argv); $j++) { $file = $argv[$j]; - //ARMO LA LISTA DE ARCHIVOS {{{ - // Si es un directorio, agrego cada archivo legible .php al argv. if (is_dir($file)) { $dh = opendir($file); while (($f = readdir($dh)) !== false) { @@ -70,214 +75,211 @@ for ($j = 1; $j < count($argv); $j++) { closedir($dh); continue; } - //}}} - //GUARDO LA INFO{{{ + //PARSING INFORMATION {{{ elseif (is_readable($file) and substr($file, -4) == '.php') { $cont = file ($file); - $DOCUMENTANDO = false; - $opciones = array (); + $DOCUMENTING = false; + $options = array (); $cont_param = -1; - foreach ($cont as $linea) { - $linea = trim ($linea); - $tmp = preg_split ('/[^\w_\/\*\@\$\&\.\']+/', $linea); - //DOCUMENTANDO? {{{ - if ($tmp['0'] == '/**') { //Comienza la documentacion - $DOCUMENTANDO = true; - $doc_param = 0; + foreach ($cont as $line) { + $line = trim ($line); + $tmp = preg_split ('/[^\w_\/\*\@\$\&\.\']+/', $line); + //DOCUMENTING? {{{ + if ($tmp['0'] == '/**') { //Starts documentation + $DOCUMENTING = true; + $doc_param = 0; //If 1 the line belongs to a parameter documentation } - if ($tmp['0'] == '*/') { //Termina la documentacion - $DOCUMENTANDO = false; + if ($tmp['0'] == '*/') { //Ends documentation + $DOCUMENTING = false; $doc_param = 0; } //}}} - //DOCUMENTANDO{{{ - if ($DOCUMENTANDO) { - $tmp2 = ltrim ($linea,'* /**'); //Elimino el * o /** del comienzo de la linea - $accion = substr($tmp2, 0, strpos($tmp2,' ')); //Obtengo la accion - $accion = ($accion === '') ? $tmp2 : $accion; - $value = trim(strstr($tmp2, ' ')); //Solo me importa lo que esta detras del @ - //SWITCH ACCIONES {{{ - switch ($accion) { + //Parse documentation {{{ + if ($DOCUMENTING) { + $tmp2 = ltrim ($line,'* /**'); //Removes * or /** from the beginning of the line + $action = substr($tmp2, 0, strpos($tmp2,' ')); //Gets the action (evrerything before the @) + $action = ($action === '') ? $tmp2 : $action; + $value = trim(strstr($tmp2, ' ')); //Action value + //SWITCH ACTION {{{ + switch ($action) { case '@access' : switch ($value) { - case 'private' : $opciones['access'] = 201; + case 'private' : $options['access'] = 201; break; - case 'protected': $opciones['access'] = 202; + case 'protected': $options['access'] = 202; break; - default : $opciones['access'] = 200; + default : $options['access'] = 200; } $doc_param = 0; break; - case '@package' : $opciones['package'] = $value; + case '@package' : $options['package'] = $value; $doc_param = 0; break; - case '@abstract': $opciones['abstract'] = 1; + case '@abstract': $options['abstract'] = 1; $doc_param = 0; break; - case '@static' : $opciones['static'] = 1; + case '@static' : $options['static'] = 1; $doc_param = 0; break; - case '@var' : $opciones['type'] = substr($value, 0, strpos($value,' ')); + case '@var' : $options['type'] = substr($value, 0, strpos($value,' ')); $doc_param = 0; break; case '@return' : $type = substr($value, 0, strpos($value,' ')); - $resto = (strpos($value,' ')) ? substr($value, strpos($value,' ')) : ''; + $rest = (strpos($value,' ')) ? substr($value, strpos($value,' ')) : ''; if ($type === '') { $type = $value; } if (strtolower($type) == 'object') { - $resto = trim($resto); - $type = substr($resto, 0, strpos($resto,' ')); - $resto = (strpos($resto,' ')) ? substr($resto, strpos($resto,' ')) : ''; + $rest = trim($rest); + $type = substr($rest, 0, strpos($rest,' ')); + $rest = (strpos($rest,' ')) ? substr($rest, strpos($rest,' ')) : ''; } - $opciones['type'] = $type; - if (trim($resto)) { - $opciones['documentacion'].= "Returns: ".trim($resto); + $options['type'] = $type; + //If there is more documentation, I add it to the main documentation + if (trim($rest)) { + $options['documentation'].= "Returns: ".xmlentities(trim($rest))."\n"; } $doc_param = 0; - $resto = ''; + $rest = ''; break; case '@param' : $cont_param++; $type = substr($value, 0, strpos($value,' ')); - $resto = substr($value, strpos($value,' ') + 1); + $rest = substr($value, strpos($value,' ') + 1); if (strtolower($type) == 'object') { - $resto = trim($resto); - $type = substr($resto, 0, strpos($resto,' ')); - $resto = substr($resto, strpos($resto,' ') + 1); + $rest = trim($rest); + $type = substr($rest, 0, strpos($rest,' ')); + $rest = substr($rest, strpos($rest,' ') + 1); } - $opciones['param'][$cont_param]['type'] = $type; - $opciones['param'][$cont_param]['documentacion'] = trim(substr(trim($resto), strpos(trim($resto), ' '))); + $options['param'][$cont_param]['type'] = $type; + $options['param'][$cont_param]['documentation'] = + xmlentities(trim(substr(trim($rest), strpos(trim($rest), ' ')))); $doc_param = 1; break; default: - $tmp2 = str_replace('"', '"', $tmp2); - $tmp2 = str_replace('<', '<' , $tmp2); - $tmp2 = str_replace('>', '>' , $tmp2); - $tmp2 = str_replace('&', '&' , $tmp2); + $tmp2 = xmlentities($tmp2); if (@$doc_param) { - $opciones['param'][$cont_param]['documentacion'].= "\n".$tmp2; + $options['param'][$cont_param]['documentation'].= "\n".$tmp2; } else { - @$opciones['documentacion'].= $tmp2."\n"; + @$options['documentation'].= $tmp2."\n"; } } //}}} } //}}} - //CLASE {{{ - if (!$DOCUMENTANDO && $tmp['0'] == 'class') { + //CLASS {{{ + if (!$DOCUMENTING && $tmp['0'] == 'class') { $ID++; - $IDCLASE = $ID; - + $IDCLASS = $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]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : ''; + $ARRAY[$ID]['package'] = (@$options['package']) ? $options['package'] : ''; + $ARRAY[$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0; + $ARRAY[$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : ''; + $ARRAY[$ID]['static'] = (@$options['static']) ? $options['static'] : 0; + $ARRAY[$ID]['scope'] = (@$options['access']) ? $options['access'] : 200; $ARRAY[$ID]['operations'] = array(); $ARRAY[$ID]['attributes'] = array(); - $opciones = array(); + $options = array(); } //}}} - //FUNCION {{{ - if (!$DOCUMENTANDO && $tmp['0'] == 'function') { + //FUNCTION {{{ + if (!$DOCUMENTING && $tmp['0'] == 'function') { $ID++; if ($tmp['1']{0} == '&') { - $tmp['1'] = substr($tmp['1'], 1); //SACO EL & - $opciones['type'] = (@$opciones['type']) ? '&'.$opciones['type'] : ''; + $tmp['1'] = substr($tmp['1'], 1); //Removes the & + $options['type'] = (@$options['type']) ? '&'.$options['type'] : ''; } if ($tmp['1']{0} == '_') { - $tmp['1'] = substr($tmp['1'], 1); //SACO EL _ + $tmp['1'] = substr($tmp['1'], 1); //Removes the _ } - $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(); + $ARRAY[$IDCLASS]['operations'][$ID]['id'] = $ID; + $ARRAY[$IDCLASS]['operations'][$ID]['name'] = $tmp['1']; + $ARRAY[$IDCLASS]['operations'][$ID]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['package'] = (@$options['package']) ? $options['package'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0; + $ARRAY[$IDCLASS]['operations'][$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['static'] = (@$options['static']) ? $options['static'] : 0; + $ARRAY[$IDCLASS]['operations'][$ID]['scope'] = (@$options['access']) ? $options['access'] : 200; + $ARRAY[$IDCLASS]['operations'][$ID]['type'] = (@$options['type']) ? $options['type'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'] = array(); - //PARAMETROS {{{ - $param_line = trim(substr(strstr($linea,'('),0),'{ '); //Saco la ultima { - $param = parseParentesis($param_line); + //PARAMETERS {{{ + $param_line = trim(substr(strstr($line,'('),0),'{ '); //Removes the last { + $param = parseParenthesis($param_line); $i = 0; foreach ($param as $par) { - if ($par['name']{0} == '$'|| $par['name']{0} == '&') { //Veo si empiezo con $ o & + if ($par['name']{0} == '$'|| $par['name']{0} == '&') { //If starts with $ or & switch ($par['name']{0}) { - case '$': $par['name'] = substr($par['name'], 1); //SACO EL $ + case '$': $par['name'] = substr($par['name'], 1); //Removes the $ break; - case '&': $par['name'] = substr($par['name'], 2); //SACO EL & Y EL $ - $opciones['param'][$i]['type'] = - (@$opciones['param'][$i]['type']) ? '&'.$opciones['param'][$i]['type'] : ''; + case '&': $par['name'] = substr($par['name'], 2); //Removes the & and the $ + $options['param'][$i]['type'] = + (@$options['param'][$i]['type']) ? '&'.$options['param'][$i]['type'] : ''; break; } - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['id'] = $i; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['name'] = $par['name']; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['stereotype'] = - (@$opciones['param'][$i]['stereotype']) ? $opciones['param'][$i]['stereotype'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['id'] = $i; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['name'] = $par['name']; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['stereotype'] = + (@$options['param'][$i]['stereotype']) ? $options['param'][$i]['stereotype'] : ''; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['package'] = - (@$opciones['param'][$i]['package']) ? $opciones['param'][$i]['package'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['package'] = + (@$options['param'][$i]['package']) ? $options['param'][$i]['package'] : ''; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['abstract'] = - (@$opciones['param'][$i]['abstract']) ? $opciones['param'][$i]['abstract'] : 0; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['abstract'] = + (@$options['param'][$i]['abstract']) ? $options['param'][$i]['abstract'] : 0; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['documentation'] = - (@$opciones['param'][$i]['documentacion']) ? $opciones['param'][$i]['documentacion'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['documentation'] = + (@$options['param'][$i]['documentation']) ? $options['param'][$i]['documentation'] : ''; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['static'] = - (@$opciones['param'][$i]['static']) ? $opciones['param'][$i]['static'] : 0; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['static'] = + (@$options['param'][$i]['static']) ? $options['param'][$i]['static'] : 0; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['scope'] = - (@$opciones['param'][$i]['access']) ? $opciones['param'][$i]['access'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['scope'] = + (@$options['param'][$i]['access']) ? $options['param'][$i]['access'] : ''; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['type'] = - (@$opciones['param'][$i]['type']) ? $opciones['param'][$i]['type'] : ''; + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['type'] = + (@$options['param'][$i]['type']) ? $options['param'][$i]['type'] : ''; - $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['value'] = + $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['value'] = (@$par['value']) ? $par['value'] : ''; } $i++; } //}}} - $opciones = array(); + $options = array(); $cont_param = -1; $i = 0; } //}}} - //ATRIBUTOS {{{ - if (!$DOCUMENTANDO && $tmp['0'] == 'var') { + //ATRIBUTTES {{{ + if (!$DOCUMENTING && $tmp['0'] == 'var') { $ID++; - $tmp['1'] = substr($tmp['1'], 1); //SACO EL $ + $tmp['1'] = substr($tmp['1'], 1); //Removes the $ if ($tmp['1']{0} == '_') { - $tmp['1'] = substr($tmp['1'],1); //SACO EL _ - if (!(@$opciones['access'])) { - $opciones['access'] = 201; + $tmp['1'] = substr($tmp['1'],1); //Removes the _ + if (!(@$options['access'])) { + $options['access'] = 201; } } - //Agrego si tiene valor inicial + //Check for default values if (array_key_exists('2',$tmp)) { - $opciones['value'] = $tmp['2']; + $options['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(); + $ARRAY[$IDCLASS]['attributes'][$ID]['id'] = $ID; + $ARRAY[$IDCLASS]['attributes'][$ID]['name'] = $tmp['1']; + $ARRAY[$IDCLASS]['attributes'][$ID]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : ''; + $ARRAY[$IDCLASS]['attributes'][$ID]['package'] = (@$options['package']) ? $options['package'] : ''; + $ARRAY[$IDCLASS]['attributes'][$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0; + $ARRAY[$IDCLASS]['attributes'][$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : ''; + $ARRAY[$IDCLASS]['attributes'][$ID]['static'] = (@$options['static']) ? $options['static'] : 0; + $ARRAY[$IDCLASS]['attributes'][$ID]['scope'] = (@$options['access']) ? $options['access'] : 200; + $ARRAY[$IDCLASS]['attributes'][$ID]['type'] = (@$options['type']) ? $options['type'] : ''; + $ARRAY[$IDCLASS]['attributes'][$ID]['value'] = (@$options['value']) ? $options['value'] : ''; + $options = array(); } //}}} } @@ -286,25 +288,24 @@ for ($j = 1; $j < count($argv); $j++) { } //}}} - -//GUARDO EN EL ARCHIVO {{{ +//WRITES XMI FILE {{{ $m =fopen ('./umlOut.xmi', 'w'); -fwrite($m, $comienzo); +fwrite($m, $xmi_start); $LISTITEM = ''; -//CLASES +//CLASS foreach ($ARRAY as $ar) { - //PREPARO LA CLASE + //Prepare class line $tmp2 = $umlclass; fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/', '/##STATIC##/','/##SCOPE##/'), array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],trim($ar['documentation']),$ar['name'], $ar['static'],$ar['scope']), $tmp2)."\n"); - //PREPARO LOS LISTITEM + //Prepare class listitem line $tmp2 = $umllistitem; $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n"; - //OPERACIONES + //FUNCTIONS foreach ($ar['operations'] as $op) { $tmp2 = $umloperation; fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/', @@ -312,7 +313,8 @@ foreach ($ARRAY as $ar) { array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],trim($op['documentation']), $op['name'],$op['static'],$op['scope']) , $tmp2)."\n"); - //PARAMETROS NO TIENE LISTITEM + //PARAMETERS + //Parameters aren't listed in listview foreach ($op['param'] as $pa) { $tmp2 = $umlparameter; fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/', @@ -322,12 +324,12 @@ foreach ($ARRAY as $ar) { $tmp2)."\n"); } fwrite($m,$umloperation_c."\n"); - //PREPARO LOS LISTITEM + //Pepare function lisitem line $tmp2 = $umllistitem; $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n"; $LISTITEM.=$umllistitem_c."\n"; } - //ATRIBUTOS + //ATTRIBUTES foreach ($ar['attributes'] as $op) { $tmp2 = $umlattribute; fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/', @@ -335,7 +337,7 @@ foreach ($ARRAY as $ar) { array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],trim($op['documentation']),$op['name'], $op['static'],$op['scope'],$op['value']), $tmp2)."\n"); - //PREPARO LOS LISTITEM + //Prepare attributes listitem line $tmp2 = $umllistitem; $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n"; $LISTITEM.=$umllistitem_c."\n"; @@ -343,26 +345,24 @@ foreach ($ARRAY as $ar) { fwrite($m,$umlclass_c); $LISTITEM.=$umllistitem_c."\n"; } -fwrite($m, $medio. $LISTITEM."\n".$fin); +fwrite($m, $xmi_half. $LISTITEM."\n".$xmi_end); exit; //}}} - - - - -//PARSER_PARENTESIS {{{ -//Funcion que parsea por el contenido entre parentesis -//Devuelve un array de arrays -function parseParentesis($value) { +//parsePARENTHESIS {{{ +//This function receives the content between the parenthesis ( with the ( and the ) ) +//It's a recursive function +//Returns an array of arrays +function parseParenthesis($value) { - $pos = 0; + $pos = 0; $content = true; - $char = true; - $value = substr(substr(trim($value), 1), 0, strrpos(substr(trim($value), 1),')')); + $char = true; + $value = substr(substr(trim($value), 1), 0, strrpos(substr(trim($value), 1),')')); //Removes the ( and the ) while ($char) { - //Busco la siguiente separacion ( , o = ) {{{ + //I look for the following separation ( , or = ) {{{ + //If its an = then I check if the next character is an > if (!strpos($value, ',') && !strpos($value, '=')) { $char = false; } @@ -390,12 +390,12 @@ function parseParentesis($value) { } //}}} - //Obtengo el nombre a partir del caracter de separacion {{{ + //Get's the option name {{{ $result[$pos]['name'] = (strpos($value, $char)) ? substr($value, 0, strpos($value, $char)) : $value; $pos_del = strpos($value, $char); //}}} - //Busco el valor asociado {{{ + //If $char is an = or an =>, gets the option value {{{ if ($char == '=') { $op_value = (strpos($value, $char)) ? trim(substr($value, strpos($value, $char) + 1)) : false; } @@ -404,10 +404,10 @@ function parseParentesis($value) { } //}}} - //Parseo el resto de la linea {{{ + //Parse the rest of the line {{{ if ($op_value) { if ($op_value{0} == "'" || $op_value{0} == '"') { - $pos_del = parseComillas($op_value); + $pos_del = parseString($op_value); if ($pos_del == 0) { $result[$pos]['value'] = "''"; } @@ -416,36 +416,36 @@ function parseParentesis($value) { $result[$pos]['value'] = substr($op_value, 0, $pos_del); } } - elseif (trim(strtolower(substr($op_value, 0 ,5))) == 'array') { //RECURSIVIDAD {{{ + elseif (trim(strtolower(substr($op_value, 0 ,5))) == 'array') { //Recursive part {{{ $op_value = trim(substr($op_value, 5)); - $op_value = trim(substr($op_value, 1)); //Saco el ( + $op_value = trim(substr($op_value, 1)); //Removes the ( if ($op_value{0} == ')') { $result[$pos]['value'] = 'array()'; } else { - //Busco a manopla el ) que cierra el array(##ALGO##) {{{ + //I look for the colsing ) {{{ $subpos = 0; - $seguir = true; + $continue = true; $temp = $op_value; - while ($seguir) { + while ($continue) { if (($temp{$subpos} == '"' || $temp{$subpos} == "'") && $temp{$subpos - 1} != '\\') { - $pos_del = parseComillas(substr($temp,$subpos)) + $subpos; + $pos_del = parseString(substr($temp,$subpos)) + $subpos; $subpos = $pos_del + 2; if (trim($temp{$subpos}) == ')') { - $seguir = false; + $continue = false; } } else { if ($subpos > strlen($temp)) { - $seguir = false; + $continue = false; } $subpos++; } } //}}} - $par = parseParentesis('('.substr($op_value, 0 , $subpos).')'); + $par = parseParenthesis('('.substr($op_value, 0 , $subpos).')'); $result[$pos]['value'] = 'array('; foreach ($par as $p) { $result[$pos]['value'] .= $p['name']; @@ -462,8 +462,8 @@ function parseParentesis($value) { } } //}}} else { - //Busco la , de separacion con el proximo parametro - //en caso de ser el utlimo lo asigno como viene + //Look for the next parameter. If its the last one + //I assign it as it came. if ($pos_del = strpos($op_value, ',')) { $result[$pos]['value'] = ($pos_del) ? trim(substr($op_value, 0, $pos_del)): $op_value; } @@ -472,7 +472,7 @@ function parseParentesis($value) { } //}}} - //Borro de $value lo que ya parsee {{{ + //Removes from $value the part that's alredy parsed {{{ if ($pos_del) { $value = trim(substr(trim($value), $pos_del + 2)); } @@ -486,10 +486,10 @@ function parseParentesis($value) { return $result; } //}}} -//PARSER_COMILLAS {{{ -//Funcion que parsea por el contenido entre comillas -//Devuelve la pos de la ' que cierra el comentario -function parseComillas($value) { +//parseString {{{ +//Funtion that parse the content between "" or '' +//Returns the position of the final ' or " +function parseString($value) { $result = -1; $ii = 1; $cont = true; @@ -501,7 +501,7 @@ function parseComillas($value) { $char = '"'; break; }//}}} - $value = substr($value, 1); //Saco la ' o " del comienzo del string + $value = substr($value, 1); //Removes the ' or the " from the beginning of the string if ($value{0} == $char) { $result = 0; }