| Posted by a.c.edwards | PermalinkReply |
|
a.c.edwards
| Gentlemen,
By share luck and a whole lot of trial and error, I've hacked a small utility
program to reconcile a few reports. It's not very effective but it gets the job
done. I'm wondering if you could look at it and tell me where I've gone wrong
and if possible how I could do things better.
Thanks in advance,
Andrew
-----code-----
# import std.file;
# import std.stdio;
# import std.stream;
# import std.string;
#
# extern(C) int system(char*);
#
# static char[][] files = [
# "94410_TAM(Unit).txt", "94411_TAM(Unit).txt",
# "94420_TAM(Unit).txt", "94430_TAM(Unit).txt",
# ];
#
# void remove(char[] file)
# {
# if(exists(file))
# std.file.remove(file);
# }
#
# uint _in(char[][] str, char[] val)
# {
# foreach(int ndx, char[] s; str)
# if(val == s)
# return ndx;
# return -1;
# }
#
# int main()
# {
#
# uint dl;
# char[] lastTam;
# char[] unit;
#
# char[] dir = getcwd();
#
# remove("opendocs.txt");
# remove("secreps.txt");
#
# chdir(r"\dpr");
# system("parse");
# system("splitdpr");
# system("move opendocs.txt " ~ dir);
# system("move secreps.txt " ~ dir);
# chdir(dir);
#
# char[][] opendocs = splitlines(cast(char[])read("opendocs.txt"));
# char[] lastFile;
# bool over = false;
# foreach(int n, char[] file; files) {
#
# unit = file[0 .. 5] ~ ".rtf";
# remove(unit);
# append(unit, open);
# if(exists(file))
# {
# if(exists(file[0 .. 5] ~ "dl.txt"))
# remove(file[0 .. 5] ~ "dl.txt");
# char[][] tam = splitlines(cast(char[])read(file));
#
# bool newfile = true;
# foreach(int ndx, char[] line; tam) {
#
# if (_in(mares, line[2 .. 7]) != -1 &&
# (line[65] == 'M' || line[65] == 'C' ||
# (line[60..62] == "05" && line[65] == 'N') ||
# (line[60..62] == "02" && line[65] == 'N')))
# {
# if (line[2..7] != lastTam) {
# append(unit, `\par ` ~ "\n");
# if (newfile) {
# newfile = false;
# last:
# if( dl > 0)
# append (lastFile ~ "dl.txt", lastTam ~ " " ~
rjustify(toString(dl), 3) ~ "\r\n");
# }
# else
# {
# if(dl > 0)
# append (file[0 .. 5] ~ "dl.txt", lastTam ~ " " ~
rjustify(toString(dl), 3) ~ "\r\n");
# dl = 0;
# lastTam = "";
# }
# }
# if(line[65] == 'M' && line[69] == '2')
# dl++;
# append(unit, `\par ` ~ line ~ "\n");
# lastTam = line[2 .. 7];
# documents(unit, opendocs, line[128 .. 133]);
# if (n == files.length - 1 && over)
# goto end;
# }
# else if (_in(mares, line[2 .. 7]) != -1 &&
# (line[65] == 'M' || line[65] == 'C' ||
# (line[60..62] == "05" && line[65] == 'N') ||
# (line[60..62] == "02" && line[65] == 'N')))
# {
# if (line[2..7] != lastTam)
# append(unit, `\par ` ~ "\n");
# append(unit, `\par ` ~ line ~ "\n");
# lastTam = line[2 .. 7];
# documents(unit, opendocs, line[128 .. 133]);
# }
# }
# if (n == files.length - 1)
# {
# lastFile = file[0 .. 5];
# over = true;
# goto last;
# }
# }
# end:
# append(unit, close);
# lastFile = file[0 .. 5];
# }
# return 0;
# }
#
# void documents(char[] file, char[][] opendocs, char[] ero)
# {
# char[] info;
# info.length = 51;
# info[] = ' ';
#
# foreach(char[] doc; opendocs)
# if(doc[0 .. 5] == ero)
# {
# append(file, `\par ` ~ info ~ doc[6 .. length] ~ "\n");
# }
# }
#
# static char[][] mares = [
# "A0000", "A0001", "A0002",
# "B0000", "B0001", "B0002",
# "C0000", "C0001", "C0002",
# "D0000", "D0001", "D0002",
# "E0000", "E0001", "E0002",
# "F0000", "F0001", "F0002",
# ];
|