<?php
/*******************************************************************************
INGETIK
================================================================================
Ingetik is a simple language to compress similar looking phrases
Copyright (C) 2006 An RPG Advancement
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
================================================================================
VERSION PROGRESS:
0.02:
- added enumeration
- added
0.03:
- added
- added
TODO:
- operatorul de legare decizii @fs@
- operatorul de despartire decizii $fs$
- erorile sa arate unde s-a gresit
*******************************************************************************/
function ingetik($text)
/*
Function: str ingetik (str $text)
Version: 2
Purpose: Recursive function that analizes the input string and
randomly chooses words to be included
Created: 2006-08-31 11:13:00+02:00
Modified: 2006-08-31 21:32:00+02:00
Author: rpgadvance
Maintainer: rpgadvance
*/
{
$raspuns = ''; // stringul care trebuie intors
$cuvinte = array(); // cuvintele dintre care trebuie ales
$cuv = 0; // indexul cuvantului cu care se lucreaza
$cauta = false; // daca se cauta cuvantul curent sau pur si simplu se adauga la raspuns
$paran = 0; // paranteze patrate gasite. pentru '[' se incrementeaza, pentru ']' se decrementeaza
for ($i=0; $i<strlen($text); $i++)
{
if ($text[$i] == '[')
{
if ($cauta)
{
$paran++;
$cuvinte[$cuv] .= $text[$i];
}
else $cauta = true;
}
elseif ($text[$i] == ']')
{
if ($cauta)
{
if ($paran > 0)
{
$paran--;
$cuvinte[$cuv] .= $text[$i];
}
elseif ($paran == 0)
{
$raspuns .= ingetik($cuvinte[mt_rand(0,$cuv)]);
$cauta = false;
$cuv = 0;
$cuvinte = array();
}
else die('Nu are ce cauta "]" aici');
}
else die('Nu are ce cauta "]" aici');
}
elseif ($text[$i] == '/')
{
if ($cauta)
{
if ($paran == 0) $cuv++;
else $cuvinte[$cuv] .= $text[$i];
}
else die('Nu are ce cauta "/" aici');
}
else
{
if ($cauta) $cuvinte[$cuv] .= $text[$i];
else $raspuns .= $text[$i];
}
}
return $raspuns;
}
?>