Changeset 7
- Timestamp:
- 11/06/05 00:43:12 (3 years ago)
- Files:
-
- trunk/src/tutorials/converttowiki/categories/index.html (added)
- trunk/src/tutorials/converttowiki/convertToWiki.d (modified) (7 diffs)
- trunk/src/tutorials/converttowiki/names.d (modified) (21 diffs)
- trunk/src/tutorials/converttowiki/run.bat (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/tutorials/converttowiki/convertToWiki.d
r6 r7 19 19 const char[] endCategoriesMarker = `<h3 class="ex_disp_h3">Examples</h3>`; /* stop looking for category names */ 20 20 const char[] begTopicMarker = `<li><a href="#topic`; 21 const char[] endCatNameMarker = " </a></li>";21 const char[] endCatNameMarker = " ("; 22 22 23 23 … … 51 51 if(args.length > 2) 52 52 { 53 input Path= args[1];53 inputFile = args[1]; 54 54 outputPath = args[2] ~ `\`; 55 55 } … … 60 60 File inFile = new File(inputFile); 61 61 while (!inFile.eof()) 62 inStr ~= inFile.readLine() ;63 f.close();62 inStr ~= inFile.readLine() ~ \r\n; 63 inFile.close(); 64 64 65 65 66 66 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 } 68 72 inStr = inStr[begPos..$]; 69 73 … … 72 76 /* find `<li><a href="#topic` skip the number 73 77 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: */ 76 80 { 77 81 inStr = inStr[begPos + begTopicMarker.length .. $]; … … 79 83 80 84 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 } 82 90 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 } 84 98 oldCategoryName = inStr[0..midPos]; 85 99 … … 87 101 wikiCategories ~= wikiCategory; 88 102 103 debug writefln("Found category: " ~ wikiCategory); 89 104 90 105 //mkdir(outputPath ~ `\` ~ wikiCategory);// Make directory pathname[]. 91 106 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 { 92 144 File outFile = new File(outputPath ~ wikiCategory ~ ".html", FileMode.OutNew); 93 145 94 146 outFile.writeLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 95 147 outFile.writeLine("<html><head><title>" ~ args[1] ~ "</title>"); 96 outFile.writeLine(`<link rel="stylesheet" href="` ~ css file ~ `"/>`);148 outFile.writeLine(`<link rel="stylesheet" href="` ~ cssFile ~ `"/>`); 97 149 outFile.writeLine("</head>"); 98 150 99 151 outFile.writeLine(`<body><pre><hr/>= ` ~ oldCategoryName ~ ` =<br/><a href=#"examples"<br/>`); 100 152 101 102 153 outFile.writeLine(`<hr id="` ~ wikiCategory ~ `" />= ` ~ oldCategoryName ~ " =<br/><br/>"); 103 foreach(char[] we; wikiExample s)104 outFile.writeLine(` * <#"` ~ we ~ `">` & we &`</a><br/>`);105 154 foreach(char[] we; wikiExampleNames) 155 outFile.writeLine(` * <#"` ~ we ~ `">` ~ we ~ `</a><br/>`); 156 106 157 outFile.writeLine("</pre></body></html>"); 107 158 outFile.close(); 108 109 begPos = find(inStr, begTopicMarker); 110 111 } 112 113 159 } 160 +/ 161 162 163 164 /+ 114 165 115 166 /* Create Category File */ … … 198 249 } 199 250 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 +/ 218 252 219 253 trunk/src/tutorials/converttowiki/names.d
r6 r7 1 1 /* used by convertToWiki.d */ 2 3 import std.stdio; /* for writefln */ 2 4 3 5 char[] wikiCategoryName(char[] oldCategoryName) … … 7 9 switch(oldCategoryName) 8 10 { 9 case "Fundamentals": '(20)11 case "Fundamentals": //(20) 10 12 c = "TutorialFundamentals"; 11 13 break; 12 14 13 case "Intermediate": '(14)15 case "Intermediate": //(14) 14 16 c = "TutorialIntermediate"; 15 17 break; 16 18 17 case "Advanced": '(8)19 case "Advanced": //(8) 18 20 c = "TutorialAdvanced"; 19 21 break; 20 22 21 case "Keywords": '(8)23 case "Keywords": //(8) 22 24 c = "KeywordsCategory"; 23 25 break; 24 26 25 case "Arrays" '(5)27 case "Arrays": //(5) 26 28 c = "ArraysCategory"; 27 29 break; 28 30 29 case "Common Errors" '(3)31 case "Common Errors": //(3) 30 32 c = "CommonErrorsCategory"; 31 33 break; 32 34 33 case "Delegates" '(8)35 case "Delegates": //(8) 34 36 c = "DelegateCategory"; 35 37 break; 36 38 37 case "Foreach": '(6)39 case "Foreach": //(6) 38 40 c = "ForeachCategory"; 39 41 break; 40 42 41 case "Function Literals": '(2)43 case "Function Literals": //(2) 42 44 c = "FunctionLiteralsCategory"; 43 45 break; 44 46 45 case "Handling errors": '(2)47 case "Handling errors": //(2) 46 48 c = "HandlingErrorsCategory"; 47 49 break; 48 50 49 case "Operator Overloading": '(4)51 case "Operator Overloading": //(4) 50 52 c = "OperatorOverloadingCategory"; 51 53 break; 52 54 53 case "switch / case": '(3)55 case "switch / case": //(3) 54 56 c = "SwitchCaseCategory"; 55 57 break; 56 58 57 case "Templates": '(10)59 case "Templates": //(10) 58 60 c = "TemplatesCategory"; 59 61 break; 60 62 61 case "Versioning": '(3)63 case "Versioning": //(3) 62 64 c = "VersioningCategory"; 63 65 break; 64 66 65 case "DFL": '(7)67 case "DFL": //(7) 66 68 c = "DflCategory"; 67 69 break; 68 70 69 case "Mango": '(1)71 case "Mango": //(1) 70 72 c = "MangoCategory"; 71 73 break; 72 74 73 case "Standard Library": '(22)75 case "Standard Library": //(22) 74 76 c = "StandardLibraryCategory"; 75 77 break; 76 78 77 case "Windows GUI": '(3)79 case "Windows GUI": //(3) 78 80 c = "WindowsGuiCategory"; 79 81 break; … … 82 84 writefln("Unknown category: %s", oldCategoryName); 83 85 } 84 return c; 86 return c; assert(0); 85 87 } 86 88 … … 93 95 94 96 switch(oldCategoryName) 97 { 95 98 case "Fundamentals": 96 99 switch(e) … … 116 119 case "Unittests": s = "UnittestsExample"; break; 117 120 case "Getch/Getchar": s = ""; break; 118 default: writefln("Unknown example: %", e); 121 default: writefln("Unknown example: %", e); assert(0); 119 122 } break; 120 123 … … 136 139 case "Runtime Type Information (RTTI)": s = "RuntimeTypeInformationExample"; break; 137 140 case "Statistics": s = "StatisticsExample"; break; 138 default: writefln("Unknown example: %", e); 141 default: writefln("Unknown example: %", e); assert(0); 139 142 } break; 140 143 … … 150 153 case "Meta tags (__FILE__, __LINE__, etc.)": s = "MetaTagsExample"; break; 151 154 case "uudecode": s = "UudecodeExample"; break; 152 default: writefln("Unknown example: %", e); 155 default: writefln("Unknown example: %", e); assert(0); 153 156 } break; 154 157 … … 164 167 case "goto": s = "GotoExample"; break; 165 168 case "return": s = "ReturnExample"; break; 166 default: writefln("Unknown example: %", e); 169 default: writefln("Unknown example: %", e); assert(0); 167 170 } break; 168 171 … … 175 178 case "Returning Arrays from Functions": s = "ReturningArraysFromFunctionsExample"; break; 176 179 case "Using char[][] args": s = "UsingCharArrayArgumentsExample"; break; 177 default: writefln("Unknown example: %", e); 180 default: writefln("Unknown example: %", e); assert(0); 178 181 } break; 179 182 … … 184 187 case "Using Objects": s = "UsingObjectsExample"; break; 185 188 case "Printing a Slice from a String": s = "PrintingSliceFromStringExample"; break; 186 default: writefln("Unknown example: %", e); 189 default: writefln("Unknown example: %", e); assert(0); 187 190 } break; 188 191 … … 198 201 case "Delegate 1": s = "DelegateNonStaticNestedFunctionExample"; break; 199 202 case "Delegate 2": s = "IntFunctionDelegateExample"; break; 200 default: writefln("Unknown example: %", e); 203 default: writefln("Unknown example: %", e); assert(0); 201 204 } break; 202 205 … … 210 213 case "Foreach with key and value pairs": s = "ForeachKeyValuePairsExample"; break; 211 214 case "Associative array of strings": s = "ForeachStringArrExample"; break; 212 default: writefln("Unknown example: %", e); 215 default: writefln("Unknown example: %", e); assert(0); 213 216 } break; 214 217 … … 218 221 case "Function Literal Assignment": s = "FunctionLiteralAssignExample"; break; 219 222 case "Function Literal / Anonymous Function": s = "AnonymousFunctionExample"; break; 220 default: writefln("Unknown example: %", e); 223 default: writefln("Unknown example: %", e); assert(0); 221 224 } break; 222 225 … … 226 229 case "DBC: basic design by contract": s = "DesignByContractExample"; break; 227 230 case "Try/Catch/Finally": s = "TryCatchFinallyExample"; break; 228 default: writefln("Unknown example: %", e); 231 default: writefln("Unknown example: %", e); assert(0); 229 232 } break; 230 233 … … 236 239 case "opCall": s = "OpCallExample"; break; 237 240 case "Byte.d": s = "ByteOperatingOverloadExample"; break; 238 default: writefln("Unknown example: %", e); 241 default: writefln("Unknown example: %", e); assert(0); 239 242 } break; 240 243 … … 245 248 case "The Twelve Days of Christmas": s = ""; break; 246 249 case "The Twelve Days of Christmas (Reprise)": s = "TwelveDaysOfChristmasExampleTwo"; break; 247 default: writefln("Unknown example: %", e); 250 default: writefln("Unknown example: %", e); assert(0); 248 251 } break; 249 252 … … 261 264 case "Variable Arguments": s = "TemplateVariableArgumentsExample"; break; 262 265 case "Template RTTI": s = "TemplateRttiExample"; break; 263 default: writefln("Unknown example: %", e); 266 default: writefln("Unknown example: %", e); assert(0); 264 267 } break; 265 268 266 269 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 275 278 case "DFL": 276 279 switch(e) … … 283 286 case "Checkboxes": s = "DflCheckboxesExample"; break; 284 287 case "Controls": s = "DflControlsExample"; break; 285 default: writefln("Unknown example: %", e); 288 default: writefln("Unknown example: %", e); assert(0); 286 289 } break; 287 290 … … 290 293 { 291 294 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); 294 296 } break; 295 297 … … 319 321 case "Zlib": s = "ZlibExample"; break; 320 322 case "Unzip using std.zip": s = "UnzipUsingStdZipExample"; break; 321 default: writefln("Unknown example: %", e); 323 default: writefln("Unknown example: %", e); assert(0); 322 324 } break; 323 325 … … 328 330 case "TreeView": s = "TreeViewExample"; break; 329 331 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); 333 335 } 334 336 return s; trunk/src/tutorials/converttowiki/run.bat
r6 r7 1 dmd convertToWiki.d 1 dmd convertToWiki.d names.d -debug 2 2 convertToWiki.exe dsource_tutorials_snapshot.html categories 3 3 pause
