www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Replacing the GDB D patch with dfilt

reply Downs <default_357-line yahoo.de> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The following modified version of dfilt (see the phobos std.demangle doc
for original source) with special handling of the GDB prompt allows for
dfilt to be used with gdb like so

gdb programname |dfilt

The source is

import std.stdio;
import std.ctype;
import std.demangle;

void writefl(char c) {
  writef(c); fflush(null);
}
void writefl(char[] c) {
  writef(c); fflush(null);
}

void mangprint(string line) {
  bool inword=false;
  char[] buffer;

  foreach (ch; line) {
    if (inword) {
      if (ch == '_' || isalnum(ch)) buffer ~= ch;
      else {
        inword = false;
        writefl(demangle(buffer)~ch);
      }
    } else {
      if (ch == '_' || isalpha(ch)) {
        inword=true;
        buffer=[ch];
      } else writefl(ch);
    }
  }
  if (inword) writefl(demangle(buffer));
  writefln;
}

int main() {
  char[] line;
  bool immediate=false;
  int c;

  while ((c = fgetc(stdin)) != EOF) {
    char ch=cast(char)c;
    if (immediate) {
      if (c == 10) {
        writefln;
        immediate=false;
      } else writefl(ch);
      continue;
    }
    if (c == 10) { mangprint(line); line=""; continue; }
    line ~= ch;
    if (line.length!<2 && line[$-2..$]==") ") { immediate=true;
writefl(line); line=""; continue; }
  }
  return 0;
}

Enjoy!
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG7oe1pEPJRr05fBERAuRUAJ9jd2P9uq6kQY+8CrXb1yYwaS6D6gCZAfb2
juWInY7VGoQE5hW7HqeTiIY=
=WJ1i
-----END PGP SIGNATURE-----
Sep 17 2007
parent reply Alexander Panek <alexander.panek brainsware.org> writes:
Downs wrote:
 The source is

License? :) (Just in case)
Sep 17 2007
parent Downs <default_357-line yahoo.de> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Panek wrote:
 Downs wrote:
 The source is

License? :) (Just in case)

So I'm really not sure what applies here. Is it even legal for me to have created this? :o All that notwithstanding, I doubt the program is volumous enough to warrant copyright protection. Why, it's barely more than a sniplet! --downs -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG7otQpEPJRr05fBERAvA+AJ9TRXJn14IQcsgnEy9dVJeZqsQapACghKM0 mxtugoDx402leUzTLu0XU54= =GgWD -----END PGP SIGNATURE-----
Sep 17 2007