Mercurial > projects > dmdscript-tango
changeset 1:987135a700f2
tango lib used.
author | saaadel |
---|---|
date | Sun, 24 Jan 2010 18:16:40 +0200 |
parents | 55c2951c07be |
children | cca96fbcc1f8 |
files | dmdscript_tango/textgen/textgen.d |
diffstat | 1 files changed, 62 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/dmdscript_tango/textgen/textgen.d Sun Jan 24 12:34:47 2010 +0200 +++ b/dmdscript_tango/textgen/textgen.d Sun Jan 24 18:16:40 2010 +0200 @@ -1,4 +1,3 @@ - /* Digital Mars DMDScript source code. * Copyright (c) 2000-2002 by Chromium Communications * D version Copyright (c) 2004-2005 by Digital Mars @@ -23,10 +22,12 @@ // Generates: // text.d -import std.c.stdio; -import std.c.stdlib; -import std.stdio; - +//import std.c.stdio; +//import std.c.stdlib; +//import std.stdio; +import tango.core.Exception; +import tango.io.stream.TextFile; +import tango.io.Console; struct Msgtable { @@ -136,46 +137,76 @@ { "Unexpected", 0, "ERR_E_UNEXPECTED"}, ]; +const int EXIT_FAILURE=0; +const int EXIT_SUCCESS=1; + int main() { - FILE* fp; + //FILE* fp; + TextFileOutput fp; uint i; - fp = fopen("errmsgs.d","w"); - if (!fp) - { - printf("can't open errmsgs.d\n"); - exit(EXIT_FAILURE); + //fp = fopen("errmsgs.d","w"); + try { + fp = new TextFileOutput("errmsgs.d"); + } + catch(IOException e) { + Cout("can't open errmsgs.d").newline; + return EXIT_FAILURE; } + //if (!fp) + //{ + //printf("can't open errmsgs.d\n"); + //exit(EXIT_FAILURE); + //} + + fp.formatln("// File generated by textgen.d"); + //fprintf(fp, "// File generated by textgen.d\n"); + fp.formatln("//"); + //fprintf(fp, "//\n"); - fprintf(fp, "// File generated by textgen.d\n"); - fprintf(fp, "//\n"); - - fprintf(fp, "// *** ERROR MESSAGES ***\n"); - fprintf(fp, "//\n"); - fprintf(fp, "module dmdscript.errmsgs;\n"); - fprintf(fp, "enum {\n"); + fp.formatln("// *** ERROR MESSAGES ***"); + //fprintf(fp, "// *** ERROR MESSAGES ***\n"); + fp.formatln("//"); + //fprintf(fp, "//\n"); + fp.formatln("module dmdscript_tango.textgen.errmsgs;"); + //fprintf(fp, "module dmdscript.errmsgs;\n"); + fp.formatln("enum {{"); + //fprintf(fp, "enum {\n"); for (i = 0; i < errtable.length; i++) - { char[] id = errtable[i].ident; + { + char[] id = errtable[i].ident; - if (!id) - id = errtable[i].name; - fwritefln(fp,"\t%s = %d,", id, i); + if (!id) + id = errtable[i].name; + fp.formatln("\t{} = {},", id, i); + //fwritefln(fp,"\t%s = %d,", id, i); } - fprintf(fp, "};\n"); + fp.formatln("};"); + //fprintf(fp, "};\n"); - fprintf(fp, "// *** ERROR MESSAGES ***\n"); - fprintf(fp, "//\n"); - fprintf(fp, "char[][] errmsgtbl = [\n"); + fp.formatln("// *** ERROR MESSAGES ***"); + //fprintf(fp, "// *** ERROR MESSAGES ***\n"); + fp.formatln("//"); + //fprintf(fp, "//\n"); + fp.formatln("char[][] errmsgtbl = ["); + //fprintf(fp, "char[][] errmsgtbl = [\n"); for (i = 0; i < errtable.length; i++) - { char[] id = errtable[i].ident; - char[] p = errtable[i].name; + { + char[] id = errtable[i].ident; + char[] p = errtable[i].name; - fwritefln(fp,"\t\"%s\",", p); + fp.formatln("\t\"{}\",", p); + //fwritefln(fp,"\t\"%s\",", p); } - fprintf(fp, "];\n"); + fp.formatln("];"); + //fprintf(fp, "];\n"); - fclose(fp); + //@saaadel: flush buf + fp.flush; + + fp.close; + //fclose(fp); return EXIT_SUCCESS; }