|
This class permits symbols (identifiers) manipulation. It should not overload the memory affected to PHP, especting that the system memory is mostly involved, because it works with an opened file.
See the in source documentation for details and exemples.
Feedback will be apreciated, whatever it is positive or negative.
If you use this work, send a feedback. AND if you would like to donate, make a donation to dame-la-mano.net...
Have a lot of fun,
Patrick
<? /**
This object class had been tested usign utf-8 encoded characters.
The symbols file is made of a set of records of a same '$oRecLen' width. A record contains the characters composing the symbol and finished with the character ASCII 'LF' (10). It is filled, in beetwin and if necessary, with the character ASCII 'SPACE' (32), in this source file.
The second part of the file is separated from the first with the unknown character 0x80 (128) which is forbiden in utf-8. This second part is composed of numbers represented in hexadecimal characters, separated by the pipe character '|'. Each of these numbers represent the position of a record in the ascending order.
Here is an exemple of the content of a file:
+++ ← ← ← ← ← ← ← ← Symbol it self
↓ ++++++++ ← ← ← ← fillers (' ')
↓ ↓↓ + ← ← ← EOL ("\n")
↓↓↓ ↓↓ ↓
ccc --|
aaa --+ ← ← Order in which the symboles have been inserted
bbb --|
�1|2|0 ← ← ← ← ← ← Ordered liste: Hexadecimal numbers separated by the pipe character ('|')
↑
+ ← ← ← ← ← ← ← ← ← Header separator (kHeadSep <- "\200")
Record # Ordered
ccc -- 0 --1
aaa -- 1 --2
bbb -- 2 --0
This source file defines a class permiting the construction and use of such file. Note that in the following interface, the method suffix 'Pointed' means that the numéric parameter passed will be considered relative to the entry order of the symboles, while 'Handled' suffix will be considered as index of the ordered table. The property $oRecOrdWhere is relativ to the ordered table.
The interface is:
__construct (string $symbFName, string $mode, [numeric $keyRecSize]).
- $symbFName: The existing file name or to be constructed file name.
- $mode: The way the file should be open. Can be 'r', 'w' or 'a'. 'r' is for reading only and 'w' is for a new file creation. 'a' is for opening an existing file for reading and/or adding more symboles.
- $keyRecSize: This optional parameter must be specifier for file creation.
__destruct ().
This function is called by the garbedge collector, or when the variable holding the istance is reaffected, or when the instance is explicitly destructed (unset()).
IsIn (string $what, [boolean $noCase]).
- $what is the the string representing the symbole you would like to know if it is allready in the list. If this string is too long, it will be shorted.
- $noCase This otional parameter is false by default. The compare while searching is made case sensitive if false, and case unsensitive otherwise. This is not utf-8 complient. The case is onlt related to the ASCII alphabetic codes.
Place ().
This method writes the symbole we where looking for with IsIn() and was not found. So, ALLWAYS call this method immediately after IsIn(), but it is logical, isn't it ?. This is because IsIn() sets properties ($oStr2Search, $oRecOrdWhere...) permiting a quick placement.
GetPointed (numeric $recNbr, [boolean $clean])
Returns the symbol having position $recNbr in the record suit. That is, the order it has been inserted.
PutPointed (string $what, numeric $recNbr, [boolean $format=true])
Puts the string $what in the list of records, at position $recNbr. Handle this method with care if you set the parameter $format to false when calling: this could destroy the symbols file.
GetHandled ($indexNbr, [boolean $clean=true])
Similar to GetPointed(), exepted that it uses table indirection (ordered list).
PutHandled (string $what, numeric $indexNbr, [boolean $format=true])
Similar to PutPointed(), exepted that it uses table indirection (ordered list). Use this method with property $oRecOrdWhere to add information tu a record, if necessary.
Erase ()
Erase all the symboles and the indirection table.
DebugDump ()
Display some debugging helpfull informations.
Real file content exemple:
Dudu
Didi
Dada
Dodo
Dédé
�2|1|3|0|4
Exemples:
The first exemple is is simple demonstration. It create a symboles file from a table in memory then print its content in ascending order, then, the file is re-open to add an other symbol and display the new content. Finaly, the symbols file is deleted.
it outputs:
Symboles handling class test:
New symboles file creation:
Ordered print out of resulting symboles file content:
Dada, Didi, Dodo, Dudu, Dédé
Re-opening the symboles file to add a symbole:
Dada, Didi, Dodo, Dudu, Dédé
Ordered print out of resulting symboles file content:
Dada, Didi, Dodo, Dudu, Dydy, Dédé
Record length: 35;
Symbols file name: exemple.symb;
File descriptor handle: Resource id #11;
Ordered records indexing list: 2, 1, 3, 0, 5, 4;
Number of records (or indexes in mémory): 6;
walking bit: 16;
Last index found by Symbo::IsIn(): 0;
Last result of Symbo::IsIn(): 0;
String to look for or to insert: '';
Modifyable file ? no.
The second exemple reads this file (initaly named 'class_Symbols_en.php') and counts the words found in it. Note that the seek is done 'case insensitive'.
it outputs:
Symboles handling class test:
538 words found in file 'class_Symbols_en.php'
_:3, __construct:3, __destruct:3, __FILE__:15, __LINE__:15, a:22, aaa:3, acceptée:2, add:5, adding:2, after:2, again:2, ajout:2, ajouter:2, all:2, allready:4, ALLWAYS:2, alphabetic:2, an:6, and:12, André:2, append:3, après:2, argument:1, array:3, array_push:2, Arrivée:2, as:3, ascending:3, ASCII:5, at:2, ATTENTION:4, AUTORISER:1, basename:17, bbb:3, be:8, because:2, been:4, beetwin:2, bit:4, boolean:6, break:2, but:2, by:7, c:10, call:2, called:2, calling:2, Can:2, cant:2, caracte:2, care:2, case:5, ccc:3, champ:3, character:6, characters:4, chaîne:5, chercher:2, cherché:2, class:8, class_Symbols_en:7, classe:2, Claudie:2, clean:7, close:2, closes:2, codes:2, collector:2, compar:2, compare:2, complient:2, composed:2, composing:2, compris:2, considered:3, const:2, constructed:2, construction:2, contains:2, content:10, contenu:2, contient:3, correspondance:2, could:2, count:3, counts:2, courtée:3, create:2, creation:5, criture:2, Créer:3, ctype_alnum:2, ctype_alpha:2, d:21, Dada:6, Daniel:2, dans:5, de:19, deb:2, DebugDump:4, debugging:2, default:2, defines:2, DEL:2, deleted:2, delta:8, demonstration:2, Dernier:2, derrière:2, des:8, descripteur:2, descriptor:3, destroy:2, destructed:2, devant:2, Didi:6, die:15, display:3, do:4, Dodo:6, does:2, doit:2, Dominique:2, DONE:2, du:5, Dudu:6, dummy:3, dupliquer:2, Dydy:4, déclaration:2, Dédé:6, déplacer:2, déterminer:2, dû:2, Each:2, ECRITURE:1, else:11, elseif:3, en:7, encoded:2, end:2, enregis:2, enregistrement:8, enregistrements:7, ensemble:2, entiers:2, entre:2, entry:2, EOL:2, Erase:4, Erreur:7, error:2, est:10, et:6, eu:2, exemple:10, exempleFileName:10, Exemples:2, exepted:3, exist:2, existe:2, existing:3, explicitly:2, explode:3, faire:4, false:14, fclose:2, Ferme:2, fgets:2, fichier:12, file:36, file_get_contents:2, file_put_contents:2, filesize:2, filled:2, fillers:2, Fin:5, final:2, Finaly:2, finished:2, first:3, following:2, fopen:3, for:25, forbiden:2, foreach:2, format:11, formatée:3, found:7, fread:2, French:2, from:3, fs:2, fscanf:2, fseek:6, fStr:5, function:13, fwrite:5, gale:3, garbedge:2, gauche:1, GetHandled:8, GetPointed:5, gSymbo:32, Gustave:2, génère:1, had:2, handle:4, Handled:2, handling:5, has:2, have:2, having:2, Header:2, helpfull:2, Here:2, Hexadecimal:3, holding:2, i:44, ici:2, id:2, Idx:7, if:43, il:1, immediately:2, importe:2, Impossible:2, in:21, incorrect:2, index:6, indexes:3, indexing:3, indexNbr:11, indexs:5, indique:2, indirection:4, information:2, informations:2, infructueuse:2, inférieure:3, initaly:2, insensitive:2, Inserer:2, insert:4, inserted:3, instance:2, inStr:4, insérer:2, inséré:2, interface:3, Introuvable:2, Intéressant:2, invalide:1, is:32, IsIn:17, isn:2, istance:2, it:14, its:2, jour:2, keyRecSize:12, kHeadSep:5, know:2, l:12, la:19, Last:5, lCount:4, le:17, lecture:4, length:3, les:5, LF:2, like:2, limites:3, list:11, liste:2, logical:2, long:2, longueur:3, look:3, looking:2, lu:2, made:3, mauvais:5, means:2, members:3, memory:2, method:6, mise:2, mode:15, Modifyable:3, more:2, must:2, mémoire:2, mémory:3, n:47, name:5, named:2, names:2, ne:5, necessary:3, new:11, nick:5, nickname:3, no:3, noCase:5, Nom:2, nombre:4, nommée:2, non:3, not:3, Note:3, nt:2, Number:3, numbers:4, numeric:5, numéric:2, numéro:3, Nº:5, object:2, of:22, oFileHand:18, oFileName:5, on:2, onlt:2, only:2, open:3, opening:4, Optimisation:2, optional:2, oPtrTable:19, oPw2RecCnt:9, or:10, ord:3, order:6, Ordered:15, ordre:2, oRecLen:17, oRecOrdWhere:18, oSearchResu:9, oStr2Search:7, other:2, otherwise:2, otional:2, oTotRecCnt:25, ou:7, out:7, outputs:3, ouverture:3, ouvrir:2, par:4, parameter:5, part:3, Pas:7, passed:2, permiting:3, peut:3, php:7, pipe:3, Place:11, placement:2, placer:6, placée:2, Pointed:2, pointeur:2, poiteurs:2, portant:2, position:5, Possibilité:2, possible:2, Pour:5, premier:2, previous:2, print:35, private:10, prog:6, properly:2, properties:2, property:3, propriétés:2, précédemment:2, Prépare:2, public:13, PutHandled:4, PutPointed:5, Puts:2, que:3, quick:2, quoi:2, r:15, Re:4, reading:3, reads:2, reaffected:2, Real:2, recherche:4, recNbr:13, Record:8, records:7, recStr:4, related:2, relativ:2, relative:2, represent:2, represented:2, representing:2, représentant:2, require:3, Resource:2, resu:4, result:3, resulting:5, Retourne:2, return:13, Returns:2, rw:7, résultat:2, s:19, same:2, Se:3, searching:2, second:4, Seek:3, self:2, sensitive:2, separated:4, separator:2, sera:2, set:3, sets:2, seule:3, shorted:3, shoud:2, should:2, Show:2, si:14, Similar:3, simple:2, sinon:2, So:2, some:2, souhaitable:2, source:3, SPACE:2, specifier:2, sprintf:3, sscanf:4, str:8, str_replace:2, strcasecmp:2, strcmp:2, String:11, strlen:5, strpos:2, substr:3, such:2, suffix:3, suit:2, Suite:4, Supprimer:2, sur:2, symb:4, symbFName:17, Symbo:16, symbol:6, symbole:10, symboles:23, Symbols:7, séparateur:2, t:3, table:10, tableau:2, tables:2, taille:4, test:5, tested:2, that:7, the:66, then:3, these:2, this:130, to:17, too:2, toujours:3, traité:2, tre:6, trim:2, trouvé:3, true:13, tu:2, TUE:2, té:2, un:8, une:2, unknown:2, unlink:2, unsensitive:2, unset:8, Use:5, uses:6, usign:2, utf:4, valeur:2, valide:2, variable:2, ventuelle:2, ventuellement:2, vers:1, vide:4, Vérification:3, vérifié:1, w:10, walkBit:5, walking:4, Warning:2, was:2, way:2, we:2, what:26, when:4, where:2, which:3, while:3, width:2, will:4, with:7, word:11, words:4, would:2, writes:2, x:3, x7F:2, x80:2, x80000000:2, y:2, yes:2, you:3,
// Use exemple 1: -----------------------------------------------------------
print(" Symboles handling class test:\n");
require('class_Symbols_en.php');
$exempleFileName='exemple.symb';
print(" New symboles file creation:\n");
$gSymbo=new Symbo($exempleFileName, 'w', 35);
$members=explode('|', 'Dudu|Didi|Dada|Dodo|Dédé');
// French nick names for Gustave, Claudie, Daniel, Dominique and André :-)
foreach ($members as $nick)
if (!$gSymbo->IsIn($nick))
$gSymbo->Place();
else // This cant append!
print(" The nickname $nick is allready in the list!\n");
unset($gSymbo); // This closes properly the symboles file
print(" Ordered print out of resulting symboles file content:\n");
$gSymbo=new Symbo("$exempleFileName", 'r');
for ($i=0; $i<$gSymbo->oTotRecCnt; $i++)
print(($i ? ', ' : '').$gSymbo->GetHandled($i));
print("\n");
unset($gSymbo);
print(" Re-opening the symboles file to add a symbole:\n");
$gSymbo=new Symbo("$exempleFileName", 'a');
// Show again the 'previous content
for ($i=0; $i<$gSymbo->oTotRecCnt; $i++)
print(($i ? ', ' : '').$gSymbo->GetHandled($i));
print("\n");
if (!$gSymbo->IsIn('Dydy'))
$gSymbo->Place();
else // This shoud't append!
print(" The nickname 'Dydy' is allready in the list!\n");
unset($gSymbo);
print(" Ordered print out of resulting symboles file content:\n");
$gSymbo=new Symbo("$exempleFileName", 'r');
// For an ordered print out:
for ($i=0; $i<$gSymbo->oTotRecCnt; $i++)
print(($i ? ', ' : '').$gSymbo->GetHandled($i));
print("\n\n");
$gSymbo->DebugDump();
unset($gSymbo);
unlink($exempleFileName);
// Use exemple 2: -----------------------------------------------------------
print(" Symboles handling class test:\n");
require('class_Symbols_en.php');
$exempleFileName='exemple.symb';
$inStr=file_get_contents('class_Symbols_en.php');
$gSymbo=new Symbo($exempleFileName, 'w', 80);
for ($dummy=$word='', $l=strlen($inStr), $i=0; $i<$l; $i++) {
$c=$inStr[$i];
if ($word)
if (ctype_alnum($c) || ($c=='_') || (ord($c)>0x7F))
$word.=$c;
else {
if (!$gSymbo->IsIn($word, true)) // This word does'nt exist in the list
$gSymbo->Place();
else {
list($dummy, $uses)=sscanf($gSymbo->GetHandled($gSymbo->oRecOrdWhere), '%s %d');
$word.=sprintf(' %d', $uses+($uses ? 1 : 2));
$gSymbo->PutHandled($word, $gSymbo->oRecOrdWhere);
}
$word='';
}
elseif ((ord($c)<128) && ((ctype_alpha($c) || ($c=='_')))) // word===''
$word=$c;
}
unset($gSymbo);
$gSymbo=new Symbo("$exempleFileName", 'r');
// For an ordered print out:
print($l=$gSymbo->oTotRecCnt." words found in file 'class_Symbols_en.php'\n");
for ($i=0; $i<$l; $i++) {
$s=$gSymbo->GetHandled($i);
print(strpos($s, ' ')===false ? $s.':1, ' : str_replace(' ', ':', $s).", ");
}
print("\n");
unset($gSymbo);
*/
class Symbo {
const kHeadSep="\200";
private $oRecLen; // Longueur d'un enregistrement symbole +++
private $oFileName; // Nom du fichier symbols
private $oFileHand; // pointeur sur le descripteur du fichier $this->oFileName
private $oPtrTable; // Contient une suite d'entiers représentant le numéro d'ordre d'un enregistrement
public $oTotRecCnt; // Nombre d'enregistrements / de poiteurs en mémoire
private $oPw2RecCnt; // "walking bit"
public $oRecOrdWhere=0; // Index trouvé par Symbo::IsIn
private $oSearchResu=0; // Dernier résultat de recherche dans Symbo::IsIn
private $oStr2Search=''; // Chaîne à chercher ou à insérer
private $rw; // Possibilité d'ajouter un symbole si "true"
public function __construct ($symbFName, $mode, $keyRecSize=0) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
// Prépare l'ensemble des propriétés à l'ajout de symboles. $mode == 'w' indique que les tables nommée $symbFName est à créer. Si $mode=='r-', l'ouverture d'un fichier symboles vide est acceptée si ($keyRecSize est == 0) et ($mode != 'w'), le premier champ du fichier est lu pour déterminer la longueur.
$this->oFileName=$symbFName; // suite d'enregistrements de taille $this->oRecLen
if (($mode!='r-') && ($mode!='r') && ($mode!='w') && ($mode!='a'))
die(basename(__FILE__).'['.__LINE__.'] '."Le mode d'ouverture pour \"".basename($symbFName)."\" est incorrect (doit être 'r', 'r+', 'w' ou 'a').\n");
$this->rw=($mode[0]!='r');
if ($mode=='w') {
if (($this->oRecLen=$keyRecSize)<=1) // Suite d'enregistrements "symbole deb end\n"
die(basename(__FILE__).'['.__LINE__.'] '."La taille des enregistrements de ".basename($symbFName)." (ici: $keyRecSize) ne peut pas être inférieure ou égale à un.\n");
$this->oPtrTable=array();
$this->oTotRecCnt=0;
$this->oPw2RecCnt=1;
file_put_contents($symbFName, ""); // Créer le fichier...
return($this->oFileHand=fopen($symbFName, "r+"));
}
else {
if (!($fs=@filesize($symbFName)))
die(basename(__FILE__).'['.__LINE__.'] '."Le fichier symboles \"$symbFName\" n'existe pas ou est vide.\n");
if (!($this->oFileHand=fopen($symbFName, "r+")))
die(basename(__FILE__).'['.__LINE__.'] '."Impossible d'ouvrir le fichier \"$symbFName\".\n");
for ($lCount=$keyRecSize=0; ($str=fgets($this->oFileHand))!==false ; ) {
if ($str[0]===Symbo::kHeadSep) // Arrivée à la table des indexs ?
break;
$lCount++;
if (!$keyRecSize) {
if (($keyRecSize=strlen($str))<=1)
die(basename(__FILE__).'['.__LINE__.'] '."La taille des enregistrements ne peut pas être inférieure ou égale à un.\n");
}
elseif (strlen($str)!=$keyRecSize)
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de contenu du fichier (\"$symbFName\").\n");
}
if ($str==false)
die(basename(__FILE__).'['.__LINE__.'] '."Le fichier symboles (\"$symbFName\") ne contient pas de table d'index.\n");
$this->oRecLen=$keyRecSize;
$this->oPtrTable=explode("|", substr($str, 1)); // La table des indexs est en $str
for ($l=count($this->oPtrTable), $i=0; $i<$l; $i++)
sscanf($this->oPtrTable[$i], "%x", $this->oPtrTable[$i]);
if (($this->oTotRecCnt=$l)!=$lCount)
if ($mode!='r-')
die(basename(__FILE__).'['.__LINE__.'] '."\"$symbFName\": Non correspondance entre nombre d'enregistrements et nombre d'indexs.\n");
for ($walkBit=0x80000000; !(($walkBit>>1) & $this->oTotRecCnt); $walkBit>>=1);
$this->oPw2RecCnt=$walkBit<<1;
}
}
public function __destruct () { // close
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
// Ferme le fichier après mise à jour éventuelle
if ($this->rw) { // Si écriture possible:
@fseek($this->oFileHand, $this->oTotRecCnt*$this->oRecLen); // Se placer à la fin des enregis
@fwrite($this->oFileHand, Symbo::kHeadSep); // Inserer le caracte ASCII "DEL"
for ($fStr='', $i=0; $i<$this->oTotRecCnt; $i++)
$fStr.=($i ? "|" : "").sprintf("%x", $this->oPtrTable[$i]);
if ($fStr)
@fwrite($this->oFileHand, $fStr); // Placer le tableau des indexs
}
@fclose($this->oFileHand);
}
private function Format (&$what) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
// Return TUE si la chaîne n'a pas eu à être écourtée, FALSE si la chaîne a dû être écourtée
if (($i=strlen($what))>=$this->oRecLen-1) { // Vérification si "dans les limites"...
$what=substr($what, 0, $this->oRecLen-1)."\n";
return($i<=$this->oRecLen-1);
}
else for (; $i<($this->oRecLen-1); $i++)
$what.=' ';
$what.="\n";
return(true);
}
public function IsIn ($what, $noCase=false) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
// Recherche la position (souhaitable) pour le symbole $what. La Place en $this->oRecOrdWhere. Retourne false si la recherche est infructueuse. La valeur placée en $this->oRecOrdWhere est toujours valide.
/// Attention un champ vide ($what==='') sera traité. Et éventuellement inséré par $this::Place()!
if (!$this->Format($what)) // Vérification si "dans les limites"...
if (!$this->rw) // Si en lecture seule:
return(false); // Pas trouvé!
else
print("Warning: symbol shorted.\n");
sscanf($this->oStr2Search=$what, '%s', $what); /** */
if ($this->oTotRecCnt==0)
return(false);
for ($Idx=$this->oPw2RecCnt>>1, $delta=$Idx>>1; ; ) {
$do=true;
if (($Idx-1)>=$this->oTotRecCnt) {
/// Optimisation: ne faire de lecture+compar. que si !$delta
$this->oRecOrdWhere=($this->oTotRecCnt-1);
if (!($do=($delta==0)))
$this->oSearchResu=-1;
}
else
$this->oRecOrdWhere=($Idx-1);
if ($do) {
if (-1==fseek($this->oFileHand, $this->oPtrTable[$this->oRecOrdWhere]*$this->oRecLen))
die(basename(__FILE__)."[".__LINE__."] Seek error\n");
fscanf($this->oFileHand, '%s ', $recStr); /** */
$this->oSearchResu=($noCase ? strcasecmp($what, $recStr) : strcmp($what, $recStr));
}
if (!$this->oSearchResu)
return(true);
if (!$delta)
return(false);
if ($this->oSearchResu<0)
$Idx-=$delta;
else
$Idx+=$delta;
$delta>>=1;
}
return(false); // Introuvable
}
public function Place () {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
/* Insert le numéro de l'enregistrement portant le symbole $what précédemment cherché par IsIn() */
/// Se placer à la fin: on place toujours à la fin
fseek($this->oFileHand, $this->oTotRecCnt*$this->oRecLen);
fwrite($this->oFileHand, $this->oStr2Search); /// La chaîne a été formatée dans $this->IsIn()
array_push($this->oPtrTable, $this->oTotRecCnt); // Intéressant, ou n'importe quoi!
/// Faire de la Place et placer
// Pour faire de la Place, déplacer y compris $this->oPtrTable[$this->oRecOrdWhere] (=> le dupliquer)
for ($i=count($this->oPtrTable)-2; $i>=$this->oRecOrdWhere;
$this->oPtrTable[$i+1]=$this->oPtrTable[$i--]);
/// Si $this->oSearchResu < 0, placer devant $this->oRecOrdWhere, sinon derrière
$this->oPtrTable[$this->oRecOrdWhere+=($this->oSearchResu>0)]=$this->oTotRecCnt;
$this->oPw2RecCnt<<=(++$this->oTotRecCnt >= $this->oPw2RecCnt);
}
public function GetPointed ($recNbr, $clean=true) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
if (($recNbr<0) || ($recNbr>=$this->oTotRecCnt))
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de prog.: mauvais Nº d'enregistrement.\n");
fseek($this->oFileHand, $recNbr*$this->oRecLen);
$resu=fread($this->oFileHand, $this->oRecLen); /// Attention: séparateur==' '
if ($clean)
return(trim($resu)); // Supprimer les ' ' et le "\n" final
return($resu);
}
public function PutPointed ($what, $recNbr, $format=true) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
if ($format)
$this->Format($what);
if (($recNbr<0) || ($recNbr>=$this->oTotRecCnt))
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de prog.: mauvais Nº d'enregistrement.\n");
fseek($this->oFileHand, $recNbr*$this->oRecLen);
fwrite($this->oFileHand, $what); /// ATTENTION si non formatée !!!
}
public function GetHandled ($indexNbr, $clean=true) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
if (($indexNbr<0) || ($indexNbr>=$this->oTotRecCnt))
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de prog.: mauvais Nº d'enregistrement.\n");
return($this->GetPointed($this->oPtrTable[$indexNbr], $clean));
}
public function PutHandled ($what, $indexNbr, $format=true) {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
if (($indexNbr<0) || ($indexNbr>=$this->oTotRecCnt))
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de prog.: mauvais Nº d'enregistrement.\n");
$this->PutPointed($what, $this->oPtrTable[$indexNbr], $format);
}
public function Erase () {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
if ($this->rw) {
$this->oTotRecCnt=$this->oRecOrdWhere=0;
$this->oPtrTable=array();
$this->oPw2RecCnt=1;
$this->oStr2Search='';
}
else
die(basename(__FILE__).'['.__LINE__.'] '."Erreur de prog.: fichier en lecture seule.\n");
}
public function DebugDump () {
/// <s"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*">
print("Record length: ".$this->oRecLen.";\n");
print("Symbols file name: ".$this->oFileName.";\n");
print("File descriptor handle: ".$this->oFileHand.";\n");
print("Ordered records indexing list: ");
for ($i=0; $i<$this->oTotRecCnt; $i++)
print(($i ? ', ' : '').$this->oPtrTable[$i]);
print(";\n");
print("Number of records (or indexes in mémory): ".$this->oTotRecCnt.";\n");
print("walking bit: ".$this->oPw2RecCnt.";\n");
print("Last index found by Symbo::IsIn(): ".$this->oRecOrdWhere.";\n");
print("Last result of Symbo::IsIn(): ".$this->oSearchResu.";\n");
print("String to look for or to insert: '".$this->oStr2Search."';\n");
print("Modifyable file ? ".($this->rw ? 'yes' : 'no').".\n");
}
} // Fin de déclaration de la classe.
?>
Sign up to add your own comment here!
|
|