Eagle Libraries Search Engine

http://kner.at/home/_eaglesearch/eaglesearch.php



Die Suchmaschine verwendet als Datenbasis eine reduzierte Version der Bibliotheken (es sind nur mehr die für die Suche benötigten Informationen enthalten) als Textdatei.

Diese Datei muss in einem ersten Schritt extrahiert werden; anschließend werden die beiden dat-Files auf den Server gespielt und über reguläre Ausdrücke abgesucht.



#!/usr/bin/php -q 
<?php 
/* Condense Libraries  kner 2013*/

$found_array = array(); 
$all_libs = array(); 
$all_packages = array(); 

$path = realpath('/opt/eagle-6.4.0/lbr'); 

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); 

foreach ($objects as $libraryname => $object) { 

    $fn = $object->getFileName(); 
    if ($fn == ".") 
        continue; 
    if ($fn == "..") 
        continue; 
    $ext = pathinfo($fn, PATHINFO_EXTENSION); 
    if ($ext != "lbr") 
        continue; 
    if (is_file($libraryname)) { 
        $libname = basename($libraryname); 
        libxml_use_internal_errors(true); 

        $xml = simplexml_load_file($libraryname, "SimpleXMLElement", LIBXML_NOCDATA); 
        $errors = libxml_get_errors(); 
        foreach ($errors as $error) { 
            echo display_xml_error($error, $xml); 
        } 
        // PACKAGES 
        foreach ($xml->drawing->library->packages->package as $key=>$package) { 
            $packagename = (string) $package->attributes()->{'name'}; 
            $description = (string) $package->description; 
            $all_packages[$libname][] = array($packagename,$description); 
        } 
        // DEVICES 
        $all_libs[$libname]['description'] = (string) $xml->drawing->library->description; 
        foreach ($xml->drawing->library->devicesets->deviceset as $ds) { 
            $device = (string) $ds->attributes()->{'name'}; 
            $description = (string) $ds->description; 
            $all_libs[$libname]['ds'][$device]['des'] = $description; 
            foreach ($ds->gates->gate as $g) { 
                $attr = $g->attributes(); 
                $s = (string) $attr->{'symbol'}; 
                $all_libs[$libname]['ds'][$device]['s'][$s] = $s; 
            } 
           
            foreach ($ds->devices->device as $d1) { 
                $attr = $d1->attributes(); 
                $name = (string) $attr->{'name'}; 
                $package = (string) $attr->{'package'}; 
                $all_libs[$libname]['ds'][$device]['ds'][$name]['p'] = $package; 
                //$all_libs[$libname]['ds'][$device]['ds'][$name][] = $name; 
                foreach ($ds->devices->device->technologies->technology as $t) { 
                    $attr = $t->attributes(); 
                    $techn = (string) $attr->{'name'}; 
                    if (empty($techn)){ continue;} 
                    $all_libs[$libname]['ds'][$device]['ds'][$name]['t'][] = $techn; 
                } 
            } 
        } 
        echo "<br>$libraryname\n"; 
    } 
} 
file_put_contents("/home/roland/Dropbox/home/_eaglesearch/dat.dat", json_encode($all_libs)); 
file_put_contents("/home/roland/Dropbox/home/_eaglesearch/pack.dat", json_encode($all_packages));