Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff to add print formatting to debugger #1059

Closed
p5pRT opened this issue Jan 20, 2000 · 14 comments
Closed

Diff to add print formatting to debugger #1059

p5pRT opened this issue Jan 20, 2000 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 20, 2000

Migrated from rt.perl.org#2010 (status was 'resolved')

Searchable as RT2010$

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From jbodwin@sebringring.com

p sprintf "%x", $foo

to print the value of $foo in hex instead of decimal.

The following change the perl5db.pl allows a format option to be appended to
the print command
so you can do things like​:

p%x $foo

or even

p%8.8x $foo

  - Jim

===========================

1087a1088,1089

        $cmd =~ s/^p\\%\(\[^\\s\]\+\)$/print \{\\$DB​::OUT\} sprintf

\"\%$1\", \$_/;

        $cmd =~ s/^p\\%\(\[^\\s\]\+\)\\b/print \{\\$DB​::OUT\} sprintf

\"\%$1\", /;
1855d1856
< B<p>B<\%fmt> I<expr> Same as \"I<print {DB​::OUT} sprintf \"\%fmt\"
expr>\" in current package.
1891c1892
< B<p>[B<\%fmt>] I<expr> Print expression (uses script's current
package).


B<p> I<expr> Print expression (uses script's current package).

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

Jim Bodwin writes​:

The following change the perl5db.pl allows a format option to be appended to
the print command
so you can do things like​:

p%x $foo

or even

p%8.8x $foo

- Jim

===========================

1087a1088,1089

a) If you want to send patches, use diff -pu or diff -p.

b) If you want this, why not use aliases?

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

-----Original Message-----
From​: Ilya Zakharevich [mailto​:ilya@​math.ohio-state.edu]
Sent​: Thursday, January 20, 2000 12​:06 PM
To​: jbodwin@​sebringring.com
Cc​: perl5-porters@​perl.org
Subject​: Re​: [ID 20000120.001] Diff to add print formatting to debugger

a) If you want to send patches, use diff -pu or diff -p.

OK. Here it is at the bottom.

b> ) If you want this, why not use aliases?

Aliases don't work for arbitrary command string. I could do something like​:

  =px p sprintf "\%x"

if I just want hex output but if I want to have more generic formats like

  p%8x

aliases won't work (unless I define every possible alias ala =p1x,
=p2x,....).

Also, this seemed like a generic enough extension that even if it was
possible
to do with aliases there is value to others in building it in In general I
prefer
the emacs approach - "build nothing in but provide the tools to do
anything". However
generally useful stuff is often an exception.

  - Jim

=========================

$ diff -pu /tmp/perl5db.pl /perl/5.005/lib/perl5db.pl

Inline Patch
--- /tmp/perl5db.pl	Thu Jan 20 12:50:41 2000
+++ /perl/5.005/lib/perl5db.pl	Thu Jan 20 12:51:04 2000
@@ -1085,6 +1085,8 @@ EOP
 			      unless $hist[$i] =~ /^.?$/;
 			};
 			next CMD; };
+		    $cmd =~ s/^p\%([^\s]+)$/print {\$DB::OUT} sprintf
\"\%$1\", \$_/; \+ $cmd =~ s/^p\\%\(\[^\\s\]\+\)\\b/print \{\\$DB​::OUT\} sprintf \\"\\%$1\\"\, /;   $cmd =~ s/^p$/print \{\\$DB​::OUT\} \\$\_/;   $cmd =~ s/^p\\b/print \{\\$DB​::OUT\} /;   $cmd =~ /^=/ && do \{ @​@​ \-1852\,6 \+1854\,7 @​@​ B\<$psh> \[I\\] Run I\ in subshell   See 'B\ I\' too\. B\ I\<\-number> Display last number commands \(default all\)\. B\

I\ Same as \\"I\\\" in current package\. \+B\

B\<\\%fmt> I\ Same as \\"I\\\" in current package\. B\<|>I\ Run debugger command\, piping DB​::OUT to current pager\. B\<||>I\ Same as B\<|>I\ but DB​::OUT is temporarilly select\(\)ed as well\. B\<\\=> \[I\ I\\] Define a command alias\, or list current aliases\. @​@​ \-1887\,6 \+1890\,7 @​@​ I\   B\ or B\<^D> Quit B\ Attempt a restart I\ B\ Execute perl code\, also see​: B\\,B\\,B\ I\   B\|B\ I\ Evals expr in array context\, dumps the result or lists methods\. \+ B\

\[B\<\\%fmt>\] I\ Print expression \(uses script's current package\)\.   B\ \[\[B\<\!>\]I\\] List subroutine names \[not\] matching pattern   B\ \[I\ \[I\\]\] List Variables in Package\. Vars can be ~pattern or \!pattern\.   B\ \[I\\] Same as \\"B\ I\ \[I\\]\\"\. $

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

On Thu, Jan 20, 2000 at 01​:07​:25PM -0800, Jim Bodwin wrote​:

b> ) If you want this, why not use aliases?

Aliases don't work for arbitrary command string.

Do not they? I thought they do. If they do not, this is what need to
be addressed.

I could do something like​:

      =px p sprintf "\\%x"

if I just want hex output but if I want to have more generic formats like

p%8x

aliases won't work (unless I define every possible alias ala =p1x,
=p2x,....).

If you cannot alias an arbitrary string, alias 'p', and type things as

  p %8x $var

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

a) If you want to send patches, use diff -pu or diff -p.

Why would you use -p for Perl code?

  % man 1 diff
  ...
  -p Show which C function each change is in.

Also, -p isn't even in POSIX.2, so I don't know how you can expect people
to have it. Then again, neither is -u.

http​://www.opengroup.org/onlinepubs/007908799/xcu/diff.html

  The following options are supported​:

  -b Cause any amount of white space at the end of a line to be treated as a
  single newline character (that is, the white-space characters
  preceding the newline character are ignored) and other strings of
  white-space characters, not including newline characters, to compare
  equal.
  -c Produce output in a form that provides three lines of context.
  -C n
  Produce output in a form that provides n lines of context (where n will
  be interpreted as a positive decimal integer).
  -e Produce output in a form suitable as input for the ed utility, which can
  then be used to convert file1 into file2.
  -f Produce output in an alternative form, similar in format to -e, but
  unsuitable as input for the ed utility, and in the opposite order.
  -r Apply diff recursively to files and directories of the same name when
  file1 and file2 are both directories.

--tom

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

On Thu, Jan 20, 2000 at 02​:13​:51PM -0700, Tom Christiansen wrote​:

a) If you want to send patches, use diff -pu or diff -p.

Why would you use -p for Perl code?

Because it makes it easier to read patches. Why else?

% man 1 diff
\.\.\.
   \-p     Show which C function each change is in\.

Also, -p isn't even in POSIX.2, so I don't know how you can expect people
to have it.

Why is it important "how do I expect" things? What is important is
that people have it. Though mentioning -c for a fallback would be
nice indeed...

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

On Thu, Jan 20, 2000 at 02​:13​:51PM -0700, Tom Christiansen wrote​:

a) If you want to send patches, use diff -pu or diff -p.

Why would you use -p for Perl code?

Because it makes it easier to read patches. Why else?

Oh. I'd never used -p. It looks like diff -c to me. Does
it look that to you?

--tom

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

On Thu, Jan 20, 2000 at 02​:25​:14PM -0700, Tom Christiansen wrote​:

On Thu, Jan 20, 2000 at 02​:13​:51PM -0700, Tom Christiansen wrote​:

a) If you want to send patches, use diff -pu or diff -p.

Why would you use -p for Perl code?

Because it makes it easier to read patches. Why else?

Oh. I'd never used -p. It looks like diff -c to me. Does
it look that to you?

Yes. The only difference is the "global context" half-line at the
beginning of each chunk. If you are lucky, it will identify subroutine/block
which this chunk is editing.

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

Aliases don't work for arbitrary command string.

Do not they? I thought they do. If they do not, this is what need to
be addressed.

I should be cleared - even though the first alias string is used as a
pattern
element the operation the user types is used as an index to find the
pattern.
So, something like

  =p\%(.) p sprintf "\%$1"

winds up in the alias hash with an index of "p\%(.)". Typing​:

  p%x $foo

looks at $alias{"p%x"} which doesn't match the above. A fix would be to
make the alias hash an array and do pattern matching on EACH alias instead
of just the one that matches the hash index. However, that would require
the aliases to be carefully constructed so as not to match more than one
command. That would mess up lots of people who use them now.

If you cannot alias an arbitrary string, alias 'p', and type things as

p %8x $var

Same problem here. Since the LHS of the pattern is used as the alias index
the only possible pattern to use is "p". That prohibits me from having
something
that matches "p %8x" and replacing it with "p sprintf "%8x".

And this goes back to the "general usefulness" issue. Since this extends
the
functionality of the print command w/o getting into anyones way...

  - Jim

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From @tamias

On Thu, Jan 20, 2000 at 01​:35​:39PM -0800, Jim Bodwin wrote​:

And this goes back to the "general usefulness" issue. Since this extends
the functionality of the print command w/o getting into anyones way...

The space between p and [expr] is optional​:

  DB<1> %x = (a => 1, b => 2)

  DB<2> p%x
a1b2

Ronald

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

On Thu, Jan 20, 2000 at 01​:35​:39PM -0800, Jim Bodwin wrote​:

Aliases don't work for arbitrary command string.

Do not they? I thought they do. If they do not, this is what need to
be addressed.

Yes, I see that aliases are recognized via the first
white-space-separated token. One should be able to do it via regular
expressions.

If you cannot alias an arbitrary string, alias 'p', and type things as

p %8x $var

Same problem here. Since the LHS of the pattern is used as the alias index
the only possible pattern to use is "p". That prohibits me from having
something
that matches "p %8x" and replacing it with "p sprintf "%8x".

No. As far as it starts with "p ", you can do an arbitrary
substitution in your alias.

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

Same problem here. Since the LHS of the pattern is used as
the alias index
the only possible pattern to use is "p". That prohibits me
from having
something
that matches "p %8x" and replacing it with "p sprintf "%8x".

No. As far as it starts with "p ", you can do an arbitrary
substitution in your alias.

Yes, I can do an arbitrary substitution but the ONLY thing that
I can substitue for is "p ".

  - Jim

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From [Unknown Contact. See original ticket]

-----Original Message-----
From​: Ronald J Kimball [mailto​:rjk@​linguist.dartmouth.edu]
Sent​: Thursday, January 20, 2000 1​:35 PM
To​: Jim Bodwin
Cc​: 'Ilya Zakharevich'; perl5-porters@​perl.org
Subject​: Re​: [ID 20000120.001] Diff to add print formatting
to debugger

On Thu, Jan 20, 2000 at 01​:35​:39PM -0800, Jim Bodwin wrote​:

And this goes back to the "general usefulness" issue.
Since this extends
the functionality of the print command w/o getting into
anyones way...

The space between p and [expr] is optional​:

DB<1> %x = (a => 1, b => 2)

DB<2> p%x
a1b2

Hmm. I didn't realize that the space was optional. I guess this isn't
COMPLETELY transparent but the rest of the argument hold.

  - Jim

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2000

From @ysth

In article <20000120161815.A29781@​monk.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@​math.ohio-state.edu> wrote​:

On Thu, Jan 20, 2000 at 02​:13​:51PM -0700, Tom Christiansen wrote​:

a) If you want to send patches, use diff -pu or diff -p.

Why would you use -p for Perl code?

Because it makes it easier to read patches. Why else?

% man 1 diff
\.\.\.
   \-p     Show which C function each change is in\.

Also, -p isn't even in POSIX.2, so I don't know how you can expect people
to have it.

Why is it important "how do I expect" things? What is important is
that people have it. Though mentioning -c for a fallback would be
nice indeed...

perldoc perlhack​:
  Always submit patches to perl5-porters@​perl.org. This
  lets other porters review your patch, which catches a
  surprising number of errors in patches. Either use the
  diff program (available in source code form from
  ftp​://ftp.gnu.org/pub/gnu/), or use Johan Vromans'
  makepatch (available from CPAN/authors/id/JV/). Unified
  diffs are preferred, but context diffs are accepted. Do
  not send RCS-style diffs or diffs without context lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant