このスクリプトは、K.Maebashi's BBS OTDバージョンの過去ログを HTMLに変換する際に使用したものです。 言語はcrowbarです。
このまま他の誰かの役に立つことは絶対にないシロモノではありますが、 crowbarのサンプルソースとして、一応上げておきます。
1: for (i = 0; i < 28; i++) { 2: do_conv(i); 3: } 4: 5: function add_zero(num) { 6: str = "" + num; 7: while (str.length() < 3) { 8: str = "0" + str; 9: } 10: return str; 11: } 12: 13: function do_conv(num) { 14: in_fname = "bbslog" + add_zero(num) + ".html"; 15: if (num > 0) { 16: prev_fname = "otdlog" + add_zero(num-1) + ".html"; 17: } else { 18: prev_fname = null; 19: } 20: if (num < 27) { 21: next_fname = "otdlog" + add_zero(num+1) + ".html"; 22: } else { 23: next_fname = null; 24: } 25: in_fname = "bbslog" + add_zero(num) + ".html"; 26: out_fname = "otdlog" + add_zero(num) + ".html"; 27: in_fp = fopen(in_fname, "r"); 28: out_fp = fopen(out_fname, "w"); 29: 30: state = "first"; 31: 32: while ((line = fgets(in_fp)) != null) { 33: if (reg_match(%%r"^ <script ", line) && state == "first") { 34: state = "javascript"; 35: } elsif (reg_match(%%r"</head>", line) && state == "javascript") { 36: state = "end_head"; 37: } elsif (reg_match(%%r"^<body", line) && state == "end_head") { 38: line = reg_replace(%%r"<!--.*", "\n", line); 39: fputs(line, out_fp); 40: fgets(in_fp); 41: line = "<div style=\"\n"; 42: state = "body"; 43: } elsif (reg_match(%%r|<img src="counter?|, line) && state == "body") { 44: line = "この記事は、K.Maebashi's BBSの過去ログです。<br>\n" 45: + "書き込む場合は、<a href=\"http://kmaebashi.com/bbs/list.php?boardid=kmaebashibbs\">" 46: + "新しい掲示板</a>へお願いします。<br>"; 47: } elsif (reg_match(%%r"^ <CENTER>", line) && state == "body") { 48: fputs("<CENTER>\n", out_fp); 49: if (prev_fname != null) { 50: fputs(" <a href=\"./" + prev_fname + "\">ひとつ前の過去ログ</a> | ", out_fp); 51: } 52: if (next_fname != null) { 53: fputs(" <a href=\"./" + next_fname + "\">ひとつ後の過去ログ</a>", out_fp); 54: } 55: fputs("</CENTER>\n", out_fp); 56: fputs(" <br><br></br>\n", out_fp); 57: fputs(" </body>\n", out_fp); 58: fputs("</html>\n", out_fp); 59: return; 60: } 61: 62: if (state != "javascript") { 63: fputs(line, out_fp); 64: } 65: } 66: fclose(in_fp); 67: fclose(out_fp); 68: }