Browse Source

improves testability

pull/7/head
Martin Monperrus 12 years ago
parent
commit
4743902994
  1. 21
      bibtexbrowser.php

21
bibtexbrowser.php

@ -367,7 +367,7 @@ class StateBasedBibtexParser {
$this->delegate = &$delegate; $this->delegate = &$delegate;
} }
function parse($bibfilename) {
function parse($handle) {
$delegate = &$this->delegate; $delegate = &$this->delegate;
// STATE DEFINITIONS // STATE DEFINITIONS
@define('NOTHING',1); @define('NOTHING',1);
@ -398,8 +398,6 @@ class StateBasedBibtexParser {
$delegate->beginFile(); $delegate->beginFile();
$handle = fopen($bibfilename, "r");
if (!$handle) die ('cannot open '.$bibfilename);
// if you encounter this error "Allowed memory size of xxxxx bytes exhausted" // if you encounter this error "Allowed memory size of xxxxx bytes exhausted"
// then decrease the size of the temp buffer below // then decrease the size of the temp buffer below
$bufsize=BUFFERSIZE; $bufsize=BUFFERSIZE;
@ -566,7 +564,6 @@ class StateBasedBibtexParser {
} // end for } // end for
} // end while } // end while
$delegate->endFile(); $delegate->endFile();
fclose($handle);
//$d = &$this->delegate;print_r($d); //$d = &$this->delegate;print_r($d);
} // end function } // end function
} // end class } // end class
@ -637,10 +634,20 @@ class BibDBBuilder {
return $this; return $this;
} }
function build($filename) {
$this->filename = $filename;
function build($bibfilename) {
if (gettype($bibfilename)=='string') {
$this->filename = $bibfilename;
$handle = fopen($bibfilename, "r");
} else {
$this->filename = uniqid();
$handle = $bibfilename;
}
if (!$handle) die ('cannot open '.$bibfilename);
$parser = new StateBasedBibtexParser($this); $parser = new StateBasedBibtexParser($this);
$parser->parse($filename);
$parser->parse($handle);
fclose($handle);
//print_r(array_keys(&$this->builtdb)); //print_r(array_keys(&$this->builtdb));
//print_r(&$this->builtdb); //print_r(&$this->builtdb);
} }

Loading…
Cancel
Save