Changeset 7

Show
Ignore:
Timestamp:
11/06/05 00:43:12 (3 years ago)
Author:
jcc7
Message:

Got convertToWiki to compile for the first time, but not all of the functionality is there yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/tutorials/converttowiki/convertToWiki.d

    r6 r7  
    1919const char[] endCategoriesMarker = `<h3 class="ex_disp_h3">Examples</h3>`;  /* stop looking for category names */ 
    2020const char[] begTopicMarker = `<li><a href="#topic`; 
    21 const char[] endCatNameMarker = "</a></li>"; 
     21const char[] endCatNameMarker = " ("; 
    2222 
    2323 
     
    5151    if(args.length > 2) 
    5252    { 
    53         inputPath = args[1]; 
     53        inputFile = args[1]; 
    5454        outputPath = args[2] ~ `\`; 
    5555    } 
     
    6060    File inFile = new File(inputFile); 
    6161    while (!inFile.eof()) 
    62         inStr ~= inFile.readLine();     
    63     f.close();     
     62        inStr ~= inFile.readLine() ~ \r\n;     
     63    inFile.close();     
    6464 
    6565 
    6666    begPos = find(inStr, begCategoriesMarker ); 
    67     if(begPos==0) writefln("Error: beginning of Categories section not found!"); 
     67    if(begPos < 0)  
     68    { 
     69        writefln("Error: beginning of Categories section not found!"); 
     70        assert(0); 
     71    } 
    6872    inStr = inStr[begPos..$]; 
    6973 
     
    7276    /* find `<li><a href="#topic` skip the number  
    7377       and the text after ">" and before the "</a></li>" is the name */ 
    74      
    75     while(begPos) /* for each category: */ 
     78 
     79    while(begPos >= 0) /* for each category: */ 
    7680    { 
    7781        inStr = inStr[begPos + begTopicMarker.length .. $]; 
     
    7983 
    8084        begPos = find(inStr, `>`); 
    81         if(begPos==0) writefln("Error: Category name not found!"); 
     85        if(begPos < 0)  
     86        { 
     87            writefln("Error: Category name not found!"); 
     88            assert(0); 
     89        } 
    8290        inStr = inStr[begPos + 1 .. $]; 
    83         midPos = find(inStr, endCatNameMarker); 
     91        endPos = find(inStr, endCategoriesMarker); 
     92        midPos = find(inStr, endCatNameMarker);      
     93        if(midPos < 0)  
     94        { 
     95            writefln("Error: End of Category name not found!"); 
     96            assert(0); 
     97        } 
    8498        oldCategoryName = inStr[0..midPos];  
    8599 
     
    87101        wikiCategories ~= wikiCategory; 
    88102 
     103        debug writefln("Found category: " ~ wikiCategory); 
    89104     
    90105        //mkdir(outputPath ~ `\` ~ wikiCategory);//    Make directory pathname[].  
    91106     
     107 
     108        begPos = find(inStr, begTopicMarker); 
     109        endPos = find(inStr, endCategoriesMarker); 
     110 
     111        debug writefln("begPos: %s, endPos: %s", begPos, endPos); 
     112 
     113        if(endPos < begPos) begPos = -1; 
     114    } 
     115 
     116 
     117 
     118    File outFile = new File(outputPath ~ "index.html", FileMode.OutNew);  
     119 
     120    outFile.writeLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 
     121    outFile.writeLine("<html><head><title>" ~ args[1] ~ "</title>"); 
     122    outFile.writeLine(`<link rel="stylesheet" href="` ~ cssFile ~ `"\>`); 
     123    outFile.writeLine("</head>"); 
     124    outFile.writeLine("<body><pre>= Tutorial Categories =<br/>"); 
     125 
     126     
     127    /* use wikiCategories to list items for main page... */ 
     128    foreach(char[] wc; wikiCategories) 
     129      outFile.writeLine(`  * <a href="` ~ wc ~ `.html">` ~ wc ~ `</a>`); 
     130 
     131    outFile.writeLine("</pre></body></html>"); 
     132    outFile.close(); 
     133 
     134 
     135 
     136     
     137/+   
     138// This code isn't ready yet. 
     139 
     140    /* For each example */ 
     141 
     142 
     143    { 
    92144        File outFile = new File(outputPath ~ wikiCategory ~ ".html", FileMode.OutNew);  
    93145     
    94146        outFile.writeLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 
    95147        outFile.writeLine("<html><head><title>" ~ args[1] ~ "</title>"); 
    96         outFile.writeLine(`<link rel="stylesheet" href="` ~ cssfile ~ `"/>`); 
     148        outFile.writeLine(`<link rel="stylesheet" href="` ~ cssFile ~ `"/>`); 
    97149        outFile.writeLine("</head>"); 
    98150 
    99151        outFile.writeLine(`<body><pre><hr/>= ` ~ oldCategoryName ~ ` =<br/><a href=#"examples"<br/>`); 
    100152 
    101  
    102153        outFile.writeLine(`<hr id="` ~ wikiCategory ~ `" />= ` ~ oldCategoryName ~ " =<br/><br/>"); 
    103         foreach(char[] we; wikiExamples) 
    104           outFile.writeLine(`  * <#"` ~ we ~ `">` & we & `</a><br/>`); 
    105  
     154        foreach(char[] we; wikiExampleNames) 
     155          outFile.writeLine(`  * <#"` ~ we ~ `">` ~ we ~ `</a><br/>`); 
     156     
    106157        outFile.writeLine("</pre></body></html>"); 
    107158        outFile.close(); 
    108  
    109         begPos = find(inStr, begTopicMarker); 
    110  
    111     } 
    112  
    113  
     159    }    
     160+/ 
     161     
     162 
     163 
     164/+ 
    114165 
    115166    /* Create Category File */ 
     
    198249    } 
    199250 
    200  
    201  
    202  
    203     File outFile = new File(outputPath ~ wikiCategory ~ ".html", FileMode.OutNew);  
    204  
    205     outFile.writeLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 
    206     outFile.writeLine("<html><head><title>" ~ args[1] ~ "</title>"); 
    207     outFile.writeLine(`<link rel="stylesheet" href="` ~ cssfile ~ `"\>`); 
    208     outFile.writeLine("</head>"); 
    209     outFile.writeLine("<body><pre>= Tutorial Categories =<br/><br/>"); 
    210  
    211      
    212     /* use wikiCategories to list items for main page... */ 
    213     foreach(char[] wc; wikiCategories) 
    214       outFile.writeLine(`  * <a href="` ~ wc ~ `.html">` & wc & `</a><br/>`); 
    215  
    216     outFile.writeLine("</pre></body></html>"); 
    217     outFile.close(); 
     251+/ 
    218252 
    219253 
  • trunk/src/tutorials/converttowiki/names.d

    r6 r7  
    1  
     1/* used by convertToWiki.d */ 
     2 
     3import std.stdio; /* for writefln */ 
    24 
    35char[] wikiCategoryName(char[] oldCategoryName) 
     
    79    switch(oldCategoryName) 
    810    { 
    9         case "Fundamentals": '(20) 
     11        case "Fundamentals": //(20) 
    1012            c = "TutorialFundamentals"; 
    1113            break; 
    1214 
    13         case "Intermediate": '(14) 
     15        case "Intermediate": //(14) 
    1416            c = "TutorialIntermediate"; 
    1517            break; 
    1618             
    17         case "Advanced": '(8) 
     19        case "Advanced": //(8) 
    1820            c = "TutorialAdvanced"; 
    1921            break; 
    2022     
    21         case "Keywords": '(8) 
     23        case "Keywords": //(8) 
    2224            c = "KeywordsCategory"; 
    2325            break; 
    2426     
    25         case "Arrays" '(5) 
     27        case "Arrays": //(5) 
    2628            c = "ArraysCategory"; 
    2729            break; 
    2830     
    29         case "Common Errors" '(3) 
     31        case "Common Errors": //(3) 
    3032            c = "CommonErrorsCategory"; 
    3133            break; 
    3234     
    33         case "Delegates" '(8) 
     35        case "Delegates": //(8) 
    3436            c = "DelegateCategory"; 
    3537            break; 
    3638     
    37         case "Foreach": '(6) 
     39        case "Foreach": //(6) 
    3840            c = "ForeachCategory"; 
    3941            break; 
    4042     
    41         case "Function Literals": '(2) 
     43        case "Function Literals": //(2) 
    4244            c = "FunctionLiteralsCategory"; 
    4345            break; 
    4446     
    45         case "Handling errors": '(2) 
     47        case "Handling errors": //(2) 
    4648            c = "HandlingErrorsCategory"; 
    4749            break; 
    4850     
    49         case "Operator Overloading": '(4) 
     51        case "Operator Overloading": //(4) 
    5052            c = "OperatorOverloadingCategory"; 
    5153            break; 
    5254     
    53         case "switch / case": '(3) 
     55        case "switch / case": //(3) 
    5456            c = "SwitchCaseCategory"; 
    5557            break; 
    5658     
    57         case "Templates": '(10) 
     59        case "Templates": //(10) 
    5860            c = "TemplatesCategory"; 
    5961            break; 
    6062     
    61         case "Versioning": '(3) 
     63        case "Versioning": //(3) 
    6264            c = "VersioningCategory"; 
    6365            break; 
    6466     
    65         case "DFL": '(7) 
     67        case "DFL": //(7) 
    6668            c = "DflCategory"; 
    6769            break; 
    6870     
    69         case "Mango": '(1) 
     71        case "Mango": //(1) 
    7072            c = "MangoCategory"; 
    7173            break; 
    7274     
    73         case "Standard Library": '(22) 
     75        case "Standard Library": //(22) 
    7476            c = "StandardLibraryCategory"; 
    7577            break; 
    7678     
    77         case "Windows GUI": '(3) 
     79        case "Windows GUI": //(3) 
    7880            c = "WindowsGuiCategory"; 
    7981            break; 
     
    8284            writefln("Unknown category: %s", oldCategoryName); 
    8385    } 
    84     return c; 
     86    return c; assert(0); 
    8587} 
    8688 
     
    9395 
    9496    switch(oldCategoryName) 
     97    { 
    9598        case "Fundamentals": 
    9699            switch(e) 
     
    116119                case "Unittests": s = "UnittestsExample"; break; 
    117120                case "Getch/Getchar": s = ""; break; 
    118                 default: writefln("Unknown example: %", e); 
     121                default: writefln("Unknown example: %", e); assert(0); 
    119122            } break; 
    120123         
     
    136139                case "Runtime Type Information (RTTI)": s = "RuntimeTypeInformationExample"; break; 
    137140                case "Statistics": s = "StatisticsExample"; break; 
    138                 default: writefln("Unknown example: %", e); 
     141                default: writefln("Unknown example: %", e); assert(0); 
    139142            } break; 
    140143         
     
    150153                case "Meta tags (__FILE__, __LINE__, etc.)": s = "MetaTagsExample"; break; 
    151154                case "uudecode": s = "UudecodeExample"; break; 
    152                 default: writefln("Unknown example: %", e); 
     155                default: writefln("Unknown example: %", e); assert(0); 
    153156            } break; 
    154157         
     
    164167                case "goto": s = "GotoExample"; break; 
    165168                case "return": s = "ReturnExample"; break; 
    166                 default: writefln("Unknown example: %", e); 
     169                default: writefln("Unknown example: %", e); assert(0); 
    167170            } break; 
    168171         
     
    175178                case "Returning Arrays from Functions": s = "ReturningArraysFromFunctionsExample"; break; 
    176179                case "Using char[][] args": s = "UsingCharArrayArgumentsExample"; break; 
    177                 default: writefln("Unknown example: %", e); 
     180                default: writefln("Unknown example: %", e); assert(0); 
    178181            } break; 
    179182         
     
    184187                case "Using Objects": s = "UsingObjectsExample"; break; 
    185188                case "Printing a Slice from a String": s = "PrintingSliceFromStringExample"; break; 
    186                 default: writefln("Unknown example: %", e); 
     189                default: writefln("Unknown example: %", e); assert(0); 
    187190            } break; 
    188191         
     
    198201                case "Delegate 1": s = "DelegateNonStaticNestedFunctionExample"; break; 
    199202                case "Delegate 2": s = "IntFunctionDelegateExample"; break; 
    200                 default: writefln("Unknown example: %", e); 
     203                default: writefln("Unknown example: %", e); assert(0); 
    201204            } break; 
    202205         
     
    210213                case "Foreach with key and value pairs": s = "ForeachKeyValuePairsExample"; break; 
    211214                case "Associative array of strings": s = "ForeachStringArrExample"; break; 
    212                 default: writefln("Unknown example: %", e); 
     215                default: writefln("Unknown example: %", e); assert(0); 
    213216            } break; 
    214217         
     
    218221                case "Function Literal Assignment": s = "FunctionLiteralAssignExample"; break; 
    219222                case "Function Literal / Anonymous Function": s = "AnonymousFunctionExample"; break; 
    220                 default: writefln("Unknown example: %", e); 
     223                default: writefln("Unknown example: %", e); assert(0); 
    221224            } break; 
    222225         
     
    226229                case "DBC: basic design by contract": s = "DesignByContractExample"; break; 
    227230                case "Try/Catch/Finally": s = "TryCatchFinallyExample"; break; 
    228                 default: writefln("Unknown example: %", e); 
     231                default: writefln("Unknown example: %", e); assert(0); 
    229232            } break; 
    230233         
     
    236239                case "opCall": s = "OpCallExample"; break; 
    237240                case "Byte.d": s = "ByteOperatingOverloadExample"; break; 
    238                 default: writefln("Unknown example: %", e); 
     241                default: writefln("Unknown example: %", e); assert(0); 
    239242            } break; 
    240243         
     
    245248                case "The Twelve Days of Christmas": s = ""; break; 
    246249                case "The Twelve Days of Christmas (Reprise)": s = "TwelveDaysOfChristmasExampleTwo"; break; 
    247                 default: writefln("Unknown example: %", e); 
     250                default: writefln("Unknown example: %", e); assert(0); 
    248251            } break; 
    249252         
     
    261264                case "Variable Arguments": s = "TemplateVariableArgumentsExample"; break; 
    262265                case "Template RTTI": s = "TemplateRttiExample"; break; 
    263                 default: writefln("Unknown example: %", e); 
     266                default: writefln("Unknown example: %", e); assert(0); 
    264267            } break; 
    265268         
    266269        case "Versioning": 
    267         switch(e) 
    268        
    269             case "Built-in Versions": s = "BuiltInVersionsExample"; break; 
    270             case "Using versions to store multiple programs in one file": s = "UsingVersionsToStoreMultipleProgramInOneFileExample"; break; 
    271             case "Compile time versioning": s = "CompileTimeVersioningExample"; break; 
    272             default: writefln("Unknown example: %", e); 
    273         } break; 
    274         '    *  
     270           switch(e) 
     271           
     272               case "Built-in Versions": s = "BuiltInVersionsExample"; break; 
     273               case "Using versions to store multiple programs in one file": s = "UsingVersionsToStoreMultipleProgramInOneFileExample"; break; 
     274               case "Compile time versioning": s = "CompileTimeVersioningExample"; break; 
     275               default: writefln("Unknown example: %", e); assert(0); 
     276           } break; 
     277         
    275278        case "DFL": 
    276279            switch(e) 
     
    283286                case "Checkboxes": s = "DflCheckboxesExample"; break; 
    284287                case "Controls": s = "DflControlsExample"; break; 
    285                 default: writefln("Unknown example: %", e); 
     288                default: writefln("Unknown example: %", e); assert(0); 
    286289            } break; 
    287290         
     
    290293            { 
    291294                case "I/O with Mango": s = "IoWithMangoExample"; break; 
    292                 default: writefln("Unknown example: %", e); 
    293                 default: writefln("Unknown example: %", e); 
     295                default: writefln("Unknown example: %", e); assert(0); 
    294296            } break; 
    295297         
     
    319321                case "Zlib": s = "ZlibExample"; break; 
    320322                case "Unzip using std.zip": s = "UnzipUsingStdZipExample"; break; 
    321                 default: writefln("Unknown example: %", e); 
     323                default: writefln("Unknown example: %", e); assert(0); 
    322324            } break; 
    323325         
     
    328330                case "TreeView": s = "TreeViewExample"; break; 
    329331                case "MiniCalc - RestorePosition": s = "MiniCalcRestorePositionExample"; break; 
    330                 default: writefln("Unknown example: %", e); 
    331             } break; 
    332         default: writefln("Unknown category: %", e); 
     332                default: writefln("Unknown example: %", e); assert(0); 
     333            } break; 
     334        default: writefln("Unknown category: %", e); assert(0); 
    333335    } 
    334336    return s; 
  • trunk/src/tutorials/converttowiki/run.bat

    r6 r7  
    1 dmd convertToWiki.d 
     1dmd convertToWiki.d names.d -debug 
    22convertToWiki.exe dsource_tutorials_snapshot.html categories 
    33pause