[LDAPsh-cvs] ldapsh ldapsh,1.20.8.1,1.20.8.1.2.1
Status: Beta
Brought to you by:
rcorvalan
From: <rco...@us...> - 2003-09-17 17:26:58
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv2697 Modified Files: Tag: PATCH-778409 ldapsh Log Message: Applied James patch 778409 enhacing "redir" Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.20.8.1 retrieving revision 1.20.8.1.2.1 diff -C2 -d -r1.20.8.1 -r1.20.8.1.2.1 *** ldapsh 27 Jul 2003 07:47:25 -0000 1.20.8.1 --- ldapsh 17 Sep 2003 17:26:50 -0000 1.20.8.1.2.1 *************** *** 138,141 **** --- 138,170 ---- =back + =head2 REDIRECTION + + By default, LDAP results are displayed on the "standard output" while + diagnostic messages are printed to the "standard error". + + You may redirect search results using the L<redir|redir> command. This will + stay in effect until L<noredir> is called. + + Alternatively, you can use a special shell syntax which will have only a + temporary effect. The special syntax is appending "; | ..." to your command, + where "..." is a parameter to the C<open> function. + + For example: + + ldapsh> redir '|awk "/Smith/{print}"' + ldapsh> cat + cn: Jack Smith + sn: Smith + cn: Jill Smith + sn: Smith + ldapsh> version;|cat + LDAP Shell (ldapsh) by Rafael Corvalan. + ldapsh> cat + cn: Jack Smith + sn: Smith + cn: Jill Smith + sn: Smith + ldapsh> noredir + =head1 PREREQUISITES *************** *** 235,238 **** --- 264,272 ---- }; + my $Output = { + NAME => "STDOUT", + FILEHANDLE => \*STDOUT + }; + my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $G); my ($Term, $TermAttribs); *************** *** 244,250 **** } - open(STDOUTBCK, '>&STDOUT'); - select(select(STDOUTBCK)); # Avoid -w warning about useless filehandle - if (-r $Opts->{GlobalRCFile}) { loadrc($Opts->{GlobalRCFile}); --- 278,281 ---- *************** *** 417,423 **** my ($key, $value, $showattribnames) = @_; if ($showattribnames) { ! printf("%s:%s\n", $key, $value); } else { ! print("$value\n"); } } --- 448,454 ---- my ($key, $value, $showattribnames) = @_; if ($showattribnames) { ! printf {$Output->{FILEHANDLE}} ("%s:%s\n", $key, $value); } else { ! print {$Output->{FILEHANDLE}} ("$value\n"); } } *************** *** 781,787 **** ); if (-s $podfile) { ! print STDERR "\n------------------------------\n"; ! $parser->parse_from_file($podfile, \*STDERR); ! print STDERR "\n------------------------------\n"; $found = 1; last; --- 812,818 ---- ); if (-s $podfile) { ! print {$Output->{FILEHANDLE}} "\n------------------------------\n"; ! $parser->parse_from_file($podfile, $Output->{FILEHANDLE}); ! print {$Output->{FILEHANDLE}} "\n------------------------------\n"; $found = 1; last; *************** *** 793,797 **** unlink $podfile; } else { ! $parser->parse_from_file($0, \*STDERR); } return 1; --- 824,828 ---- unlink $podfile; } else { ! $parser->parse_from_file($0, $Output->{FILEHANDLE}); } return 1; *************** *** 1022,1026 **** B<Synopsis>: C<echo @list> ! Display each item in the list to STDOUT, appending a carriage return after each item. Example: C<echo scalar(@$ENTRIES)> --- 1053,1057 ---- B<Synopsis>: C<echo @list> ! Display each item in the list, appending a carriage return after each item. Example: C<echo scalar(@$ENTRIES)> *************** *** 1028,1032 **** =cut ! sub echo { print(join("\n", @_, '')); } --- 1059,1063 ---- =cut ! sub echo { print {$Output->{FILEHANDLE}} (join("\n", @_, '')); } *************** *** 1307,1311 **** sub lpwd { ! print Cwd::getcwd() . "\n"; } --- 1338,1342 ---- sub lpwd { ! print {$Output->{FILEHANDLE}} Cwd::getcwd() . "\n"; } *************** *** 1397,1401 **** require Net::LDAP::LDIF; ! Net::LDAP::LDIF->new(\*STDOUT,"w")->write(@$entries); return $entries; } --- 1428,1432 ---- require Net::LDAP::LDIF; ! Net::LDAP::LDIF->new($Output->{FILEHANDLE},"w")->write(@$entries); return $entries; } *************** *** 1512,1518 **** unshift @fields, 'DN' if $localArgs->{'dn'}; ! print join($localArgs->{'fs'}, @fields) . "\n"; foreach my $entry (@$entries) { ! print join( $localArgs->{'fs'}, map { --- 1543,1549 ---- unshift @fields, 'DN' if $localArgs->{'dn'}; ! print {$Output->{FILEHANDLE}} join($localArgs->{'fs'}, @fields) . "\n"; foreach my $entry (@$entries) { ! print {$Output->{FILEHANDLE}} join( $localArgs->{'fs'}, map { *************** *** 1544,1548 **** foreach my $entry (@$entries) { ! printf("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; --- 1575,1579 ---- foreach my $entry (@$entries) { ! printf {$Output->{FILEHANDLE}} ("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; *************** *** 1554,1561 **** =head3 redir ! B<Synopsis>: C<redir $spec> ! Redirect the standard output. C<$spec> is used as a parameter to the C<open> ! function, so you can specify for example: =over 8 --- 1585,1592 ---- =head3 redir ! B<Synopsis>: C<redir ['E<lt>specE<gt>']> ! Redirect ldapsh's output. C<spec> is used as a parameter to the C<open> ! function, so you can specify, for example: =over 8 *************** *** 1569,1583 **** =back =cut sub redir { ! my $out = shift || ">&STDOUTBCK"; ! open(tmpSTDOUTBCK, '>&STDOUT'); ! open STDOUT, $out || return 0; ! select STDOUT; $|=1; ! return(\*tmpSTDOUTBCK); } =head2 Changing entries --- 1600,1647 ---- =back + If no argument is given, the current redirection will be displayed. + =cut sub redir { ! my $out = shift; ! my $previous = $Output; ! ! if (!defined $out) { ! print STDERR $Output->{NAME} . "\n"; ! return $Output; ! } ! ! my $new = { ! NAME => $out, ! FILEHANDLE => undef ! }; ! ! open $new->{FILEHANDLE}, $out || return $previous; ! ! $Output = $new; ! $Output->{FILEHANDLE}->autoflush(1); ! ! return $previous; } + =head3 noredir + + B<Synopsis>: C<noredir> + + No longer perform any of the redirections that were previously specified using L<redir|redir>. + + =cut + + sub noredir { + my $previous = $Output; + $Output = { + NAME => "STDOUT", + FILEHANDLE => \*STDOUT + }; + return $previous; + } + =head2 Changing entries *************** *** 2156,2166 **** while (s/([\s,])(-\w)([\s,]|$)/$1'$2'$3/g) {}; ! my $redir; ! if ($redir = s/;\s*([|>][\s\w\d_\/.-]+)//) { ! redir($1); } eval() || print STDERR $@; ! redir if ($redir); } --- 2220,2230 ---- while (s/([\s,])(-\w)([\s,]|$)/$1'$2'$3/g) {}; ! my $previous; ! if (s/;\s*([|>][\s\w\d_\/.-]+)//) { ! $previous = redir($1); } eval() || print STDERR $@; ! $Output = $previous if ($previous); } |