1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include "ytree.h"
extern int chdir(const char *);
int Pipe(DirEntry *dir_entry, FileEntry *file_entry)
{
static char input_buffer[COMMAND_LINE_LENGTH + 1] = "| ";
char file_name_path[PATH_LENGTH+1];
char file_name_p_aux[PATH_LENGTH+1];
char *command_line;
char *archive;
char cwd[PATH_LENGTH+1];
char path[PATH_LENGTH+1];
int result;
result = -1;
if( ( command_line = (char *)malloc( COMMAND_LINE_LENGTH + 1 ) ) == NULL )
{
ERROR_MSG( "Malloc failed*ABORT" );
exit( 1 );
}
(void) GetRealFileNamePath( file_entry, file_name_path );
(void) StrCp( file_name_p_aux, file_name_path);
ClearHelp();
MvAddStr( LINES - 2, 1, "Pipe-Command:" );
if( GetPipeCommand( &input_buffer[2] ) == 0 )
{
move( LINES - 2, 1 ); clrtoeol();
if( Getcwd( cwd, PATH_LENGTH ) == NULL )
{
WARNING( "Getcwd failed*\".\"assumed" );
(void) strcpy( cwd, "." );
}
(void) GetPath( dir_entry, path );
if( mode == DISK_MODE || mode == USER_MODE )
{
(void) sprintf( command_line, "%s %s %s",
CAT,
file_name_p_aux,
input_buffer
);
}
else
{
archive = (mode == TAPE_MODE) ? statistic.tape_name : statistic.login_path;
MakeExtractCommandLine( command_line,
archive,
file_name_p_aux,
input_buffer
);
}
refresh();
result = QuerySystemCall( command_line );
}
else
{
move( LINES - 2, 1 ); clrtoeol();
}
free( command_line );
return( result );
}
int GetPipeCommand(char *pipe_command)
{
int result;
result = -1;
ClearHelp();
MvAddStr( LINES - 2, 1, "Pipe-Command: " );
if( InputString( pipe_command, LINES - 2, 15, 0, COLS - 16, "\r\033" ) == CR )
{
result = 0;
}
move( LINES - 2, 1 ); clrtoeol();
return( result );
}
int PipeTaggedFiles(FileEntry *fe_ptr, WalkingPackage *walking_package)
{
int i, n;
char from_path[PATH_LENGTH+1];
char buffer[2048];
walking_package->new_fe_ptr = fe_ptr;
(void) GetRealFileNamePath( fe_ptr, from_path );
if( ( i = open( from_path, O_RDONLY ) ) == -1 )
{
(void) sprintf( message,
"Can't open file*\"%s\"*%s",
from_path,
strerror(errno)
);
MESSAGE( message );
return( -1 );
}
while( ( n = read( i, buffer, sizeof( buffer ) ) ) > 0 )
{
if( fwrite( buffer,
n,
1,
walking_package->function_data.pipe_cmd.pipe_file ) != 1
)
{
(void) sprintf( message, "Write-Error!*%s", strerror(errno) );
MESSAGE( message );
(void) close( i );
return( -1 );
}
}
(void) close( i );
return( 0 );
}
|