[LDAPsh-cvs] ldapsh ldapsh,1.22,1.23
Status: Beta
Brought to you by:
rcorvalan
From: <rco...@us...> - 2003-09-19 20:12:32
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv8702 Modified Files: ldapsh Log Message: Merged with branch "PATCH-778409" which added enhanced redir Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ldapsh 28 Aug 2003 23:52:35 -0000 1.22 --- ldapsh 19 Sep 2003 12:59:30 -0000 1.23 *************** *** 140,143 **** --- 140,172 ---- =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 *************** *** 237,240 **** --- 266,274 ---- }; + my $Output = { + NAME => "STDOUT", + FILEHANDLE => \*STDOUT + }; + my ($CWD, $PROMPT, $CONNPARAMS, $LDAPCONN, $ENTRIES, $EDITOR, $G); my ($Term, $TermAttribs); *************** *** 246,252 **** } - open(STDOUTBCK, '>&STDOUT'); - select(select(STDOUTBCK)); # Avoid -w warning about useless filehandle - if (-r $Opts->{GlobalRCFile}) { loadrc($Opts->{GlobalRCFile}); --- 280,283 ---- *************** *** 419,425 **** my ($key, $value, $showattribnames) = @_; if ($showattribnames) { ! printf("%s:%s\n", $key, $value); } else { ! print("$value\n"); } } --- 450,456 ---- my ($key, $value, $showattribnames) = @_; if ($showattribnames) { ! printf {$Output->{FILEHANDLE}} ("%s:%s\n", $key, $value); } else { ! print {$Output->{FILEHANDLE}} ("$value\n"); } } *************** *** 883,889 **** } if (-s $podfile) { ! print STDERR "------------------------------\n"; ! $parser->parse_from_file($podfile, \*STDERR); ! print STDERR "------------------------------\n"; $found = 1; last; --- 914,920 ---- } if (-s $podfile) { ! print {$Output->{FILEHANDLE}} "\n------------------------------\n"; ! $parser->parse_from_file($podfile, $Output->{FILEHANDLE}); ! print {$Output->{FILEHANDLE}} "\n------------------------------\n"; $found = 1; last; *************** *** 1132,1136 **** 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)> --- 1163,1167 ---- B<Synopsis>: C<echo @list> ! Display each item in the list, appending a carriage return after each item. Example: C<echo scalar(@$ENTRIES)> *************** *** 1138,1142 **** =cut ! sub echo { print(join("\n", @_, '')); } --- 1169,1173 ---- =cut ! sub echo { print {$Output->{FILEHANDLE}} (join("\n", @_, '')); } *************** *** 1421,1425 **** sub lpwd { ! print Cwd::getcwd() . "\n"; } --- 1452,1456 ---- sub lpwd { ! print {$Output->{FILEHANDLE}} Cwd::getcwd() . "\n"; } *************** *** 1511,1515 **** require Net::LDAP::LDIF; ! Net::LDAP::LDIF->new(\*STDOUT,"w")->write(@$entries); return $entries; } --- 1542,1546 ---- require Net::LDAP::LDIF; ! Net::LDAP::LDIF->new($Output->{FILEHANDLE},"w")->write(@$entries); return $entries; } *************** *** 1626,1632 **** unshift @fields, 'DN' if $localArgs->{'dn'}; ! print join($localArgs->{'fs'}, @fields) . "\n"; foreach my $entry (@$entries) { ! print join( $localArgs->{'fs'}, map { --- 1657,1663 ---- 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 { *************** *** 1658,1662 **** foreach my $entry (@$entries) { ! printf("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; --- 1689,1693 ---- foreach my $entry (@$entries) { ! printf {$Output->{FILEHANDLE}} ("%s\n", $localArgs->{'l'} ? $entry->dn : rdn($entry->dn)); } print STDERR "-----\n" . scalar(@$entries) . " entries found.\n"; *************** *** 1668,1675 **** =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 --- 1699,1706 ---- =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 *************** *** 1683,1697 **** =back =cut sub redir { ! my $out = shift || ">&STDOUTBCK"; ! open(tmpSTDOUTBCK, '>&STDOUT'); ! open STDOUT, $out || return 0; ! select STDOUT; $|=1; ! return(\*tmpSTDOUTBCK); } =head2 Changing entries --- 1714,1761 ---- =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 *************** *** 2388,2398 **** 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); my $APP = $Globals->{_APPENDRESULTS}{VALUE} ? '** ' : ''; --- 2452,2472 ---- while (s/([\s,])(-\w|\.)([\s,]|$)/$1'$2'$3/g) {}; ! # Create a context so $previous is deallocated after used, so the temporary ! # filehadle is closed ! { ! # This will chech for "<ldapsh command> ;| <sheel command>" usage ! # If so, we do a temporary output redirection ! my $previous; ! if (s/;\s*([|>][\s\w\d_\/.-]+)//) { ! $previous = redir($1); ! } ! ! eval() || print STDERR $@; ! ! # If we temporary redirected the output, come back and close the ! # temporary filehandle ! $Output = $previous if ($previous); ! } my $APP = $Globals->{_APPENDRESULTS}{VALUE} ? '** ' : ''; |