Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Ticket #5: bcdgen.patch

File bcdgen.patch, 29.4 kB (added by MrSunshine, 15 years ago)
  • bcd/gen/bcdgen.d

    old new  
    2929version (Windows) { 
    3030    import common.path; 
    3131} else { 
    32     import std.path; 
     32//    import std.path; 
    3333} 
     34import tango.stdc.string; 
     35import tango.util.PathUtil; 
     36import tango.stdc.stringz; 
     37import tango.stdc.stdlib; 
     38import tango.sys.Process; 
     39import tango.sys.Environment; 
     40import tango.io.FilePath; 
     41import tango.io.File; 
     42import tango.io.Stdout; 
     43import tango.text.Util; 
     44import Integer = tango.text.convert.Integer; 
     45import tango.core.Exception; 
     46import tango.io.stream.FileStream; 
     47import tango.io.stream.LineStream; 
     48//import std.file; 
     49//import std.process; 
     50//import std.stdio; 
     51//import std.stream; 
     52//import std.string; 
    3453 
    35 import std.file; 
    36 import std.process; 
    37 import std.stdio; 
    38 import std.stream; 
    39 import std.string; 
     54//import std.c.stdlib; 
     55//alias std.string.atoi atoi; 
     56//alias std.c.stdlib.free free; 
     57//alias std.process.system system; 
    4058 
    41 import std.c.stdlib; 
    42 alias std.string.atoi atoi; 
    43 alias std.c.stdlib.free free; 
    44 alias std.process.system system; 
    45  
    4659private import bcd.gen.libxml2; 
    4760 
     61char [] getName(char [] name) { 
     62    Stdout.formatln("path: {}, filename: {}", ((new FilePath(name)).path()),  (new FilePath(name)).name()); 
     63    return ((new FilePath(name)).path()) ~ (new FilePath(name)).name().dup; 
     64} 
     65 
    4866extern (C) char* getenv(char*); 
    49  
     67extern (C) int system(char *); 
    5068// some global variables (yay) 
    5169private { 
    5270/** The full path to the current file */ 
     
    126144    } 
    127145 
    128146    if (args.length < 3) { 
    129         writefln("Use:"); 
    130         writefln("bcdgen <.h file> <D namespace> [options]"); 
    131         writefln("Options:"); 
    132         writefln("  -I<include prefix>"); 
    133         writefln("  -C"); 
    134         writefln("    Read/write C instead of C++"); 
    135         writefln("  -A"); 
    136         writefln("    Include all symbols provided by headers in the same"); 
    137         writefln("    directory as the provided one, regardless of whether"); 
    138         writefln("    they are actually provded by the included file."); 
    139         writefln("  -F<forced import>"); 
    140         writefln("  -R<include directory>=<BCD/D namespace>"); 
    141         writefln("    Depend upon other BCD namespaces."); 
    142         writefln("  -r"); 
    143         writefln("    Reflect C++ classes such that D classes can derive from"); 
    144         writefln("    them."); 
    145         writefln("  -E"); 
    146         writefln("    Generate const int's for unnamed enum values"); 
    147         writefln("  -T<template class>[=<count>]"); 
    148         writefln("    Make the given template class accessable from D.  If the"); 
    149         writefln("    class has more than one template parameter, also provide"); 
    150         writefln("    the count."); 
    151         writefln("  -N<symbol to ignore>"); 
    152         writefln("  -P"); 
    153         writefln("    Pollute namespaces (make named enum values public)"); 
    154         writefln("  -b"); 
    155         writefln("    Do not prepend 'bcd.' to the D namespace."); 
    156         writefln("  -DV"); 
    157         writefln("    Generate default values for function arguments."); 
     147        Stdout.formatln("Use:"); 
     148           Stdout.formatln("bcdgen <.h file> <D namespace> [options]"); 
     149        Stdout.formatln("Options:"); 
     150        Stdout.formatln("  -I<include prefix>"); 
     151        Stdout.formatln("  -C"); 
     152        Stdout.formatln("    Read/write C instead of C++"); 
     153        Stdout.formatln("  -A"); 
     154        Stdout.formatln("    Include all symbols provided by headers in the same"); 
     155        Stdout.formatln("    directory as the provided one, regardless of whether"); 
     156        Stdout.formatln("    they are actually provded by the included file."); 
     157        Stdout.formatln("  -F<forced import>"); 
     158        Stdout.formatln("  -R<include directory>=<BCD/D namespace>"); 
     159        Stdout.formatln("    Depend upon other BCD namespaces."); 
     160        Stdout.formatln("  -r"); 
     161        Stdout.formatln("    Reflect C++ classes such that D classes can derive from"); 
     162        Stdout.formatln("    them."); 
     163        Stdout.formatln("  -E"); 
     164        Stdout.formatln("    Generate const int's for unnamed enum values"); 
     165        Stdout.formatln("  -T<template class>[=<count>]"); 
     166        Stdout.formatln("    Make the given template class accessable from D.  If the"); 
     167        Stdout.formatln("    class has more than one template parameter, also provide"); 
     168        Stdout.formatln("    the count."); 
     169        Stdout.formatln("  -N<symbol to ignore>"); 
     170        Stdout.formatln("  -P"); 
     171        Stdout.formatln("    Pollute namespaces (make named enum values public)"); 
     172        Stdout.formatln("  -b"); 
     173        Stdout.formatln("    Do not prepend 'bcd.' to the D namespace."); 
     174        Stdout.formatln("  -DV"); 
     175        Stdout.formatln("    Generate default values for function arguments."); 
    158176        return 1; 
    159177    } 
    160178 
     
    166184    curFile = args[1]; 
    167185    version (Windows) { 
    168186        // get*Name only works with \, but gccxml only works with / 
    169         curFile = replace(curFile, "\\", "/"); 
     187        curFile = substitute(curFile, "\\", "/"); 
    170188        char[] backslashName = replace(args[1], "/", "\\"); 
    171         baseDir = replace(getDirName(backslashName), "\\", "/"); 
    172         shortName = getBaseName(backslashName); 
     189        baseDir = substitute((new FilePath(backslashName)).path(), "\\", "/"); 
     190        shortName = (new FilePath(backslashName)).file(); 
    173191    } else { 
    174         baseDir = getDirName(args[1]); 
    175         shortName = getBaseName(args[1]); 
     192        baseDir = (new FilePath(args[1])).path(); 
     193        shortName = (new FilePath(args[1])).file(); 
    176194    } 
    177     if (find(shortName, '.') != -1) { 
    178         shortName = getName(shortName); 
     195    if (locate(shortName, '.') != shortName.length) { 
     196   shortName = getName(shortName); 
    179197    } 
    180198    shortName = safeName(shortName); 
    181199     
     
    192210             
    193211        } else if (args[i][0..2] == "-R") { 
    194212            char[] req = args[i][2..args[i].length]; 
    195             int eqloc = find(req, '='); 
    196             if (eqloc == -1) { 
    197                 writefln("Argument %s not recognized.", args[i]); 
     213            int eqloc = locate(req, '='); 
     214            if (eqloc == req.length) { 
     215                Stdout.formatln("Argument %s not recognized.", args[i]); 
    198216                continue; 
    199217            } 
    200218            reqDependencies[req[0..eqloc]] = req[eqloc + 1 .. req.length]; 
     
    209227            char[] temp = args[i][2..args[i].length]; 
    210228            int count = 1, eqloc; 
    211229             
    212             eqloc = find(temp, '='); 
    213             if (eqloc != -1) { 
    214                 count = atoi(temp[eqloc + 1 .. temp.length]); 
     230            eqloc = locate(temp, '='); 
     231            if (eqloc != temp.length) { 
     232                count = Integer.parse(temp[eqloc + 1 .. temp.length]); 
    215233                temp = temp[0..eqloc]; 
    216234            } 
    217235             
     
    234252        } else if (args[i] == "-DV") { 
    235253            defaultValues = true; 
    236254        } else { 
    237             writefln("Argument %s not recognized.", args[i]); 
     255            Stdout.formatln("Argument %s not recognized.", args[i]); 
    238256        } 
    239257    } 
    240258     
     
    253271    cout ~= "#include <stdlib.h>\n"; 
    254272    cout ~= "#include <string.h>\n"; 
    255273    cout ~= "#include \"../bind.h\"\n"; 
    256     cout ~= "#include \"" ~ incPrefix ~ getBaseName(args[1]) ~ "\"\n"; 
     274    cout ~= "#include \"" ~ incPrefix ~ (new FilePath(args[1])).file() ~ "\"\n"; 
    257275    if (!outputC) cout ~= "extern \"C\" {\n"; 
    258276     
    259277    // make the directories 
    260278    try { 
    261         mkdir("bcd"); 
    262     } catch (FileException e) {} // ignore errors 
    263     try { 
    264         mkdir("bcd/" ~ dNamespace); 
    265     } catch (FileException e) {} // ignore errors 
     279        (new FilePath("bcd/" ~ dNamespace)).create(); 
     280    } catch (IOException e) { 
     281        Stdout.formatln("hora"); 
     282    } // ignore errors 
    266283     
    267284    // make the template file if requested 
    268285    if (templates != "") { 
    269         write("bcd/" ~ dNamespace ~ "/template_D.h", 
     286        (new File("bcd/" ~ dNamespace ~ "/template_D.h")).write( 
    270287              "#include \"../bind.h\"\n" ~ 
    271               "#include \"" ~ incPrefix ~ getBaseName(args[1]) ~ "\"\n" ~ 
     288              "#include \"" ~ incPrefix ~ (new FilePath(args[1])).file() ~ "\"\n" ~ 
    272289              templates); 
    273290        templates = "-include bcd/" ~ dNamespace ~ "/template_D.h "; 
    274291    } 
    275292     
    276293    // gccxml options 
    277     char[] gccxmlopts = templates ~  
    278     toString(getenv(toStringz(outputC ? "CFLAGS" : "CXXFLAGS"))); 
     294    char[] gccxmlopts = templates ~ Environment.get(outputC ? "CFLAGS" : "CXXFLAGS"); 
     295 
     296//    toString(getenv(toStringz(outputC ? "CFLAGS" : "CXXFLAGS"))); 
    279297     
    280298    // preprocess it 
    281     if (system(gccxmlExe ~ " -E -dD " ~ gccxmlopts ~ " -o out.i " ~ args[1])) { 
     299    if(system(toStringz(gccxmlExe ~ " -E -dD " ~ gccxmlopts ~ " -o out.i " ~ args[1])) == -1) 
    282300        return 2; 
    283     } 
    284301     
    285302    parse_Defines(); 
    286303     
    287304    // xml-ize it 
    288     if (system(gccxmlExe ~ " " ~ gccxmlopts ~ 
    289                " -fxml=out.xml " ~ args[1])) { 
    290         return 2; 
    291     } 
     305    system(toStringz(gccxmlExe ~ " " ~ gccxmlopts ~" -fxml=out.xml " ~ args[1])); 
    292306     
    293307    // then initialize libxml2 
    294308    xmlDoc *doc = null; 
     
    300314    doc = xmlReadFile("out.xml", null, 0); 
    301315     
    302316    if (doc == null) { 
    303         writefln("Failed to parse the GCCXML-produced XML file!"); 
     317        Stdout.formatln("Failed to parse the GCCXML-produced XML file!"); 
    304318        return 3; 
    305319    } 
    306320     
     
    314328    if (!outputC) cout ~= "}\n"; 
    315329     
    316330    // write out the files 
    317     write("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".d", 
    318           dhead ~ dtail); 
     331    (new File("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".d")).write(dhead ~ dtail); 
    319332    if (!outputC) { 
    320         write("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".cc", 
    321               cout); 
     333        (new File("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".cc")).write(cout); 
    322334    } 
    323335     
    324336    // get rid of the files we no longer need 
    325337    if (templates != "") { 
    326         std.file.remove("bcd/" ~ dNamespace ~ "/template_D.h"); 
     338        (new FilePath("bcd/" ~ dNamespace ~ "/template_D.h")).remove(); 
    327339    } 
    328340    //std.file.remove("out.i"); 
    329341    //std.file.remove("out.xml"); 
     
    398410        ret ~= "_"; 
    399411    } 
    400412     
    401     ret = replace(ret, ".", "_"); 
    402     ret = replace(ret, "-", "_"); 
     413    ret = substitute(ret, ".", "_"); 
     414    ret = substitute(ret, "-", "_"); 
    403415     
    404416    // drop any template info 
    405     int tloc = find(ret, '<'); 
    406     if (tloc != -1) { 
     417    int tloc = locate(ret, '<'); 
     418    if (tloc != ret.length) { 
    407419        ret = ret[0..tloc] ~ "_D"; 
    408420    } 
    409421     
     
    431443char[] toStringFree(char* from) 
    432444{ 
    433445    char[] ret; 
    434     ret ~= toString(from); 
     446    ret ~= fromStringz(from); 
    435447    free(from); 
    436448    return ret; 
    437449} 
     
    474486        // if it's not in a file we should be parsing, don't output it 
    475487        if (outputAll) { 
    476488            if (files[sfile].length <= baseDir.length || 
    477                 !fnmatch(files[sfile][0..baseDir.length], baseDir)) return false; 
     489                !patternMatch(files[sfile][0..baseDir.length], baseDir)) return false; 
    478490        } else { 
    479491            if (files[sfile] != curFile) return false; 
    480492        } 
     
    522534    if (!members) return; 
    523535     
    524536    char[] smembers = toStringFree(members); 
    525     char[][] memberList = split(smembers); 
     537    char[][] memberList = delimit(smembers, " "); 
    526538     
    527539    // parse each member in the memberList 
    528540    foreach (m; memberList) { 
     
    541553    // first parse for files and fundamental types 
    542554    for (curNode = gccxml.children; curNode; curNode = curNode.next) { 
    543555        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    544             char[] nname = toString(curNode.name); 
     556            char[] nname = fromStringz(curNode.name); 
    545557             
    546558            //writefln("  %s", nname); 
    547559             
     
    554566    // then parse for namespaces, typedefs, enums (all of which can be top-level) 
    555567    for (curNode = gccxml.children; curNode; curNode = curNode.next) { 
    556568        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    557             char[] nname = toString(curNode.name); 
     569            char[] nname = fromStringz(curNode.name); 
    558570             
    559571            //writefln("  %s", nname); 
    560572             
     
    567579            } else if (nname == "Class") { 
    568580                // special case for template classes 
    569581                char[] sname = toStringFree(xmlGetProp(curNode, "name")); 
    570                 if (find(sname, "<DReflectedClass>") != -1) { 
     582                if (locatePattern(sname, "<DReflectedClass>") != sname.length) { 
    571583                    parse_Class(curNode); 
    572584                } 
    573585            } 
     
    585597     
    586598    for (curNode = gccxml.children; curNode; curNode = curNode.next) { 
    587599        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    588             char[] nname = toString(curNode.name); 
    589              
     600            char[] nname = fromStringz(curNode.name); 
     601            
    590602            char *id = xmlGetProp(curNode, "id"); 
    591             if (parseFor != toStringFree(id)) continue; 
     603         
     604        if (parseFor != toStringFree(id)) continue; 
    592605 
    593606            if (nname == "Constructor") { 
    594607                // this may be private or otherwise unparsable, but we do have one 
    595608                hasConstructor = true; 
    596609            } 
    597              
     610            
    598611            // types that can be nameless: 
    599612            if (!parseThis(curNode, true)) continue; 
    600613             
    601             if (nname == "Struct" || nname == "Class") { 
     614       if (nname == "Struct" || nname == "Class") { 
    602615                // structs and classes are the same in C[++] 
    603616                if (outputC) { 
    604617                    if (types) parse_Struct(curNode); 
     
    633646            } else if (nname == "Enumeration") { 
    634647                if (types && !reflection) parse_Enumeration(curNode); 
    635648            } else { 
    636                 writefln("I don't know how to parse %s!", nname); 
     649                Stdout.formatln("I don't know how to parse %s!", nname); 
    637650            } 
    638651        } 
    639652    } 
     
    649662    id = xmlGetProp(node, "id"); 
    650663    name = xmlGetProp(node, "name"); 
    651664    if (id && name) { 
    652         char[] sname = toString(name); 
     665        char[] sname = fromStringz(name); 
    653666         
    654667        files[toStringFree(id)] = sname; 
    655668         
    656669        // import it in D 
    657670         
    658671        // first try our own namespace if we didn't use -A 
    659         if (!outputAll && getDirName(sname) == baseDir) { 
    660             char[] baseName = sname[baseDir.length + 1 .. sname.length]; 
    661             if (find(baseName, '.') != -1) { 
     672        if (!outputAll && (new FilePath(sname)).path() == baseDir) { 
     673            char[] baseName = sname[baseDir.length .. sname.length]; 
     674            if (locate(baseName, '.') != baseName.length) { 
    662675                baseName = getName(baseName); 
    663676            } 
    664677             
     678        Stdout.formatln("dNamespaceBase: {}, dNamespace: {}, safeName(baseName): {}, baseName: {}", dNamespaceBase, dNamespace, safeName(baseName), baseName); 
    665679            if (baseName != shortName) 
    666680                dhead ~= "public import " ~ dNamespaceBase ~ dNamespace ~ "." ~ safeName(baseName) ~ ";\n"; 
    667681        } 
    668682         
    669683        // then others 
    670684        foreach (req; reqDependencies.keys) { 
    671             if (getDirName(sname) == req) { 
    672                 char[] baseName = sname[req.length + 1 .. sname.length]; 
    673                 if (find(baseName, '.') != -1) { 
     685            if ((new FilePath(sname)).path() == req) { 
     686                char[] baseName = sname[req.length .. sname.length]; 
     687                if (locate(baseName, '.') != baseName.length) { 
    674688                    baseName = getName(baseName); 
    675689                } 
    676690                 
     
    718732    xmlNode *curNode = null; 
    719733    for (curNode = node.children; curNode; curNode = curNode.next) { 
    720734        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    721             if (toString(curNode.name) == "Base") { 
     735            if (fromStringz(curNode.name) == "Base") { 
    722736                ParsedType pt = parseType(toStringFree(xmlGetProp(curNode, "type"))); 
    723737                base = pt.DType; 
    724738                break; 
     
    727741    } 
    728742     
    729743    // if this is derived from a template, the derivation is worthless from D 
    730     if (find(base, '<') != -1) base = "bcd.bind.BoundClass"; 
     744    if (locate(base, '<') != base.length) base = "bcd.bind.BoundClass"; 
    731745     
    732746    dtail ~= "class " ~ safeName(name) ~ " : " ~ base ~ " {\n"; 
    733747     
     
    846860    xmlNode *curNode = null; 
    847861    for (curNode = node.children; curNode; curNode = curNode.next) { 
    848862        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    849             if (toString(curNode.name) == "Base") { 
     863            if (fromStringz(curNode.name) == "Base") { 
    850864                 
    851865                // find the base class 
    852866                char[] type = toStringFree(xmlGetProp(curNode, "type")); 
     
    873887 */ 
    874888void parse_Struct(xmlNode *node) 
    875889{ 
    876     char[] type = toString(node.name); 
     890    char[] type = fromStringz(node.name); 
    877891    char[] name = getNName(node); 
    878892    char[] mangled = toStringFree(getMangled(node)); 
    879893    char[] demangled = toStringFree(getDemangled(node)); 
    880894    char[] prevCurClass = curClass; 
    881895     
     896    Stdout.formatln("parse struct"); 
    882897    parseMembers(node, true, true); 
    883898     
    884899    if (type == "Union") { 
     
    9911006     
    9921007    for (curNode = node.children; curNode; curNode = curNode.next) { 
    9931008        if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    994             char[] nname = toString(curNode.name); 
    995             char[] def = toString(xmlGetProp(curNode, "default")); 
     1009            char[] nname = fromStringz(curNode.name); 
     1010            char[] def = fromStringz(xmlGetProp(curNode, "default")); 
    9961011 
    9971012            if(def == "NULL") 
    9981013                def = "null"; 
     
    10001015            if (nname == "Argument") { 
    10011016                ParsedType atype = parseType(toStringFree(xmlGetProp(curNode, "type"))); 
    10021017                char[] aname = getNName(curNode); 
    1003                 if (aname == "") aname = "_" ~ toString(onParam); 
     1018                if (aname == "") aname = "_" ~ Integer.toString(onParam); 
    10041019                aname = safeName(aname); 
    10051020                 
    10061021                if(def == "0" && 
    1007                    (find(atype.DType, "*") != -1 || 
     1022                   (locate(atype.DType, '*') != atype.DType.length || 
    10081023                    atype.isFunctionPtr)) 
    10091024                    def = "null"; 
    10101025 
     
    10521067                    if (atype.isClass) { 
    10531068                        Dcall ~= "new " ~ atype.className ~ "(cast(ifloat) 0, " ~ aname ~ ")"; 
    10541069                    } else if (atype.isClassPtr) { 
    1055                         Dcall ~= "cast(" ~ atype.DType ~ ") new " ~ replace(atype.DType, " *", "") ~ "(cast(ifloat) 0, " ~ aname ~ ")"; 
     1070                        Dcall ~= "cast(" ~ atype.DType ~ ") new " ~ substitute(atype.DType, " *", "") ~ "(cast(ifloat) 0, " ~ aname ~ ")"; 
    10561071                    } else { 
    10571072                        Dcall ~= aname; 
    10581073                    } 
     
    11041119                Ccall ~= "..."; 
    11051120                 
    11061121            } else { 
    1107                 writefln("I don't know how to parse %s!", nname); 
     1122                Stdout.formatln("I don't know how to parse %s!", nname); 
    11081123            } 
    11091124             
    11101125            onParam++; 
     
    14351450    char[] Ccall; 
    14361451     
    14371452    // the demangled name includes () 
    1438     int demparen = find(demangled, '('); 
    1439     if (demparen != -1) { 
     1453    int demparen = locate(demangled, '('); 
     1454    if (demparen != demangled.length) { 
    14401455        demangled = demangled[0..demparen]; 
    14411456    } 
    14421457     
     
    14571472    char[] mangled = toStringFree(getMangled(node)); 
    14581473    if (reflection) mangled ~= "_R"; 
    14591474     
    1460     while (find(mangled, "*INTERNAL*") != -1) { 
    1461         mangled = replace(mangled, " *INTERNAL* ", ""); 
     1475    while (locatePattern(mangled, "*INTERNAL*") != mangled.length) { 
     1476        mangled = substitute(mangled, " *INTERNAL* ", ""); 
    14621477    } 
    14631478 
    14641479    // no artificial constructors 
     
    15811596         
    15821597            for (curNode = node.children; curNode; curNode = curNode.next) { 
    15831598                if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    1584                     char[] nname = toString(curNode.name); 
     1599                    char[] nname = fromStringz(curNode.name); 
    15851600                 
    15861601                    if (nname == "EnumValue") { 
    15871602                        dhead ~= safeName(getNName(curNode)) ~ "=" ~ 
    15881603                        toStringFree(xmlGetProp(curNode, "init")) ~ ",\n"; 
    15891604                    } else { 
    1590                         writefln("I don't know how to parse %s!", nname); 
     1605                        Stdout.formatln("I don't know how to parse %s!", nname); 
    15911606                    } 
    15921607                } 
    15931608            } 
     
    15981613            { 
    15991614            for (curNode = node.children; curNode; curNode = curNode.next) { 
    16001615                if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    1601                     char[] nname = toString(curNode.name); 
     1616                    char[] nname = fromStringz(curNode.name); 
    16021617                 
    16031618                    if (nname == "EnumValue") { 
    16041619                            dhead ~= "alias " ~ safeName(aname) ~ "." ~ safeName(getNName(curNode)) ~ " " ~ 
    16051620                            safeName(getNName(curNode)) ~ ";\n"; 
    16061621                } else { 
    1607                         writefln("I don't know how to parse %s!", nname); 
     1622                        Stdout.formatln("I don't know how to parse %s!", nname); 
    16081623                    } 
    16091624            } 
    16101625        } 
     
    16141629        if (outputEnumConst && !realName) { 
    16151630            for (curNode = node.children; curNode; curNode = curNode.next) { 
    16161631                if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    1617                     char[] nname = toString(curNode.name); 
     1632                    char[] nname = fromStringz(curNode.name); 
    16181633                 
    16191634                    if (nname == "EnumValue") { 
    16201635                        dhead ~= "const int " ~ safeName(getNName(curNode)) ~ " = " ~ 
    16211636                        toStringFree(xmlGetProp(curNode, "init")) ~ ";\n"; 
    16221637                    } else { 
    1623                         writefln("I don't know how to parse %s!", nname); 
     1638                        Stdout.formatln("I don't know how to parse %s!", nname); 
    16241639                    } 
    16251640                } 
    16261641            } 
     
    16741689    ParsedType t = parseType(type); 
    16751690    if (t.isStaticArray) { 
    16761691        // can't return a static array, convert it into a pointer 
    1677         int bloc = rfind(t.DType, '['); 
    1678         if (bloc != -1) { 
     1692        int bloc = locatePrior(t.DType, '['); 
     1693        if (bloc != t.DType.length) { 
    16791694            // cut off the [...] 
    16801695            t.DType = t.DType[0..bloc] ~ "*"; 
    16811696            t.isStaticArray = false; 
     
    17081723         
    17091724        for (curNode = gccxml.children; curNode; curNode = curNode.next) { 
    17101725            if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 
    1711                 char[] nname = toString(curNode.name); 
     1726                char[] nname = fromStringz(curNode.name); 
    17121727                 
    17131728                char[] id = toStringFree(xmlGetProp(curNode, "id")); 
    17141729                if (id != type) continue; 
     
    17941809                         
    17951810                        default: 
    17961811                            parsedCache[type] = new ParsedType("void", "void"); 
    1797                             writefln("I don't know how translate %s to D.", ctype); 
     1812                            Stdout.formatln("I don't know how translate %s to D.", ctype); 
    17981813                    } 
    17991814                 
    18001815                } else if (nname == "PointerType") { 
     
    18271842                } else if (nname == "ArrayType") { 
    18281843                    ParsedType baseType = 
    18291844                        parseType(toStringFree(xmlGetProp(curNode, "type"))); 
    1830                     int size = atoi(toStringFree(xmlGetProp(curNode, "max"))) + 1; 
     1845                    int size = Integer.parse(toStringFree(xmlGetProp(curNode, "max"))) + 1; 
    18311846                 
    18321847                    // make a typedef and an alias 
    18331848                    static bool[char[]] handledArrays; 
     
    18361851                        handledArrays[type] = true; 
    18371852                     
    18381853                        cout ~= "typedef " ~ baseType.CType ~ " _BCD_array_" ~ type ~ 
    1839                         "[" ~ toString(size) ~ "];\n"; 
     1854                        "[" ~ Integer.toString(size) ~ "];\n"; 
    18401855                    } 
    18411856                 
    18421857                    baseType.CType = "_BCD_array_" ~ type; 
    1843                     baseType.DType ~= " [" ~ toString(size) ~ "]"; 
     1858                    baseType.DType ~= " [" ~ Integer.toString(size) ~ "]"; 
    18441859                 
    18451860                    ParsedType pt = new ParsedType(baseType); 
    18461861                    pt.isStaticArray = true; 
     
    18631878                        // we need to treat this as a pointer in D, but a reference in C 
    18641879                     
    18651880                        // 1) cut off the * 
    1866                         int l = rfind(baseType.CType, '*'); 
    1867                         if (l != -1) baseType.CType[l] = ' '; 
     1881                        int l = locatePrior(baseType.CType, '*'); 
     1882                        if (l != baseType.CType.length) baseType.CType[l] = ' '; 
    18681883                         
    18691884                        // 2) add the & 
    18701885                        if (outputC) { 
     
    19952010                        xmlNode *curArg; 
    19962011                        for (curArg = curNode.children; curArg; curArg = curArg.next) { 
    19972012                            if (curArg.type == xmlElementType.XML_ELEMENT_NODE) { 
    1998                                 char[] aname = toString(curArg.name); 
     2013                                char[] aname = fromStringz(curArg.name); 
    19992014                                 
    20002015                                if (aname == "Argument") { 
    20012016                                    ParsedType argType = 
     
    20332048                        pt = new ParsedType("_BCD_func_" ~ type, "_BCD_func_" ~ type); 
    20342049                        pt.isFunction = true; 
    20352050                    } else { 
    2036                         writefln("WARNING: method types/delegates are not yet supported"); 
     2051                        Stdout.formatln("WARNING: method types/delegates are not yet supported"); 
    20372052                        pt = new ParsedType("_BCD_func_" ~ type, "bcd.bind.CXXDelegate"); 
    20382053                        pt.isFunction = true; 
    20392054                    } 
     
    20582073                        if (context != "") { 
    20592074                            ParsedType pt = parseType(context); 
    20602075                             
    2061                             pt.CType = replace(pt.CType, " *", ""); 
     2076                            pt.CType = substitute(pt.CType, " *", ""); 
    20622077                             
    20632078                            if (pt.CType == "") { 
    20642079                                pt.CType = "enum " ~ aname; 
     
    20812096                 
    20822097                } else { 
    20832098                    parsedCache[type] = new ParsedType("void", "void"); 
    2084                     writefln("I don't know how to parse the type %s.", nname); 
     2099                    Stdout.formatln("I don't know how to parse the type %s.", nname); 
    20852100                } 
    20862101                 
    20872102                break; 
     
    20902105         
    20912106        if (!(type in parsedCache)) { 
    20922107            parsedCache[type] = new ParsedType("void", "void"); 
    2093             writefln("Type %s not found!", type); 
     2108            Stdout.formatln("Type %s not found!", type); 
    20942109        } 
    20952110    } 
    20962111     
     
    21022117 */ 
    21032118void parse_Defines() 
    21042119{ 
    2105     File f = new File("out.i", FileMode.In); 
     2120    LineInput ls = new LineInput(new FileInput("out.i")); 
     2121 
    21062122    bool inOurFile = false; 
    21072123     
    21082124    bool[char[]] curDefines; 
    21092125     
    2110     while (!f.eof()) { 
    2111         char[] ln = f.readLine(); 
    2112         char[][] lns = split(ln); 
     2126    foreach(ln; ls) {     
     2127        char[][] lns = delimit(ln, " "); 
    21132128         
    21142129        if (lns.length >= 1 && 
    21152130            lns[0].length >= 1 && 
    2116             lns[0][0] == '#') { 
     2131       lns[0][0] == '#') { 
    21172132            if (lns[0] == "#") { 
    21182133                // this is a file specification 
    21192134                if (lns.length >= 3 && 
     
    21242139                    inOurFile = true; 
    21252140                    if (outputAll) { 
    21262141                        if (fname.length <= baseDir.length || 
    2127                             !fnmatch(fname[0..baseDir.length], baseDir)) inOurFile = false; 
     2142                            !patternMatch(fname[0..baseDir.length], baseDir)) inOurFile = false; 
    21282143                    } else { 
    21292144                        if (fname != curFile) inOurFile = false; 
    21302145                    } 
    21312146                } 
    21322147                 
    21332148            } else if (lns[0] == "#define" && inOurFile) { 
     2149        foreach(line; lns) Stdout.formatln("line [{}]", line); 
    21342150                // turn the #define into a const int or const double 
    21352151                if (lns.length >= 3) { 
     2152            if(lns[2].length >= 1) { 
    21362153                    if (isNumeric(lns[2])) { 
    21372154                        curDefines[lns[1]] = true; 
    21382155                         
     
    21412158                        if (lns[2][$-1] == 'L') lns[2] = lns[2][0..$-1]; 
    21422159                         
    21432160                        // int or double? 
    2144                         if (find(lns[2], '.') != -1 || 
    2145                             find(lns[2], 'e') != -1 || 
    2146                             find(lns[2], 'E') != -1) { 
     2161                        if (locate(lns[2], '.') != lns[2].length || 
     2162                            locate(lns[2], 'e') != lns[2].length || 
     2163                            locate(lns[2], 'E') != lns[2].length) { 
    21472164                            dhead ~= "const double " ~ safeName(lns[1]) ~ 
    21482165                                " = " ~ lns[2] ~ ";\n"; 
    21492166                        } else { 
     
    21652182                        // could be #define'ing to something already #defined 
    21662183                        dhead ~= "alias " ~ safeName(lns[2]) ~ " " ~ safeName(lns[1]) ~ ";\n"; 
    21672184                    } 
     2185            } 
    21682186                } 
    21692187            } 
    21702188        } 
    21712189    } 
    21722190     
    2173     f.close(); 
     2191    ls.close(); 
    21742192}