File: hex.c

package info (click to toggle)
ytree 1.94-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 836 kB
  • ctags: 1,510
  • sloc: ansic: 15,271; makefile: 208
file content (162 lines) | stat: -rw-r--r-- 3,029 bytes parent folder | download | duplicates (7)
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
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/hex.c,v 1.15 2003/08/31 11:11:00 werner Exp $
 *
 * View-Hex-Kommando-Bearbeitung
 *
 ***************************************************************************/


#include "ytree.h"



static int ViewHexFile(char *file_path);
static int ViewHexArchiveFile(char *file_path);



int ViewHex(char *file_path)
{
  switch( mode )
  {
    case DISK_MODE :
    case USER_MODE :     return( ViewHexFile( file_path ) );
    case TAPE_MODE : 
    case RPM_FILE_MODE : 
    case TAR_FILE_MODE : 
    case ZOO_FILE_MODE :
    case ZIP_FILE_MODE :
    case LHA_FILE_MODE :
    case ARC_FILE_MODE : return( ViewHexArchiveFile( file_path ) );
    default:             beep(); return( -1 );
  }
}




static int ViewHexFile(char *file_path)
{
  char *command_line;
  int  compress_method;
  int result = -1;

  if( access( file_path, R_OK ) )
  {
    (void) sprintf( message, 
		    "HexView not possible!*\"%s\"*%s", 
		    file_path, 
		    strerror(errno) 
		  );
    MESSAGE( message );
    ESCAPE;
  }

  InternalView(file_path);
  return(0);
  
  if( ( command_line = (char *)malloc( COMMAND_LINE_LENGTH + 1 ) ) == NULL )
  {
    ERROR_MSG( "Malloc failed*ABORT" );
    exit( 1 );
  }


  compress_method = GetFileMethod( file_path );


  if( compress_method == FREEZE_COMPRESS )
  {
    (void) sprintf( command_line, 
		    "%s < '%s' %s | %s | %s", 
		    MELT, 
		    file_path, 
		    ERR_TO_STDOUT,
		    HEXDUMP, 
		    PAGER 
		  );
  }
  else if( compress_method == COMPRESS_COMPRESS )
  {
    (void) sprintf( command_line, 
		    "%s < '%s' %s | %s | %s", 
		    UNCOMPRESS, 
		    file_path, 
		    ERR_TO_STDOUT,
		    HEXDUMP, 
		    PAGER 
		  );
  }
  else if( compress_method == GZIP_COMPRESS )
  {
    (void) sprintf( command_line, 
		    "%s < '%s' %s | %s | %s", 
		    GNUUNZIP, 
		    file_path, 
		    ERR_TO_STDOUT,
		    HEXDUMP, 
		    PAGER 
		  );
  }
  else
  {
    (void) sprintf( command_line, 
		    "%s '%s' | %s", 
		    HEXDUMP, 
		    file_path, 
		    PAGER 
		  );
  }
    
  
  if((result = SilentSystemCall( command_line )))
  {
    (void) sprintf( message, "can't execute*%s", command_line );
    MESSAGE( message );
  }

  free( command_line );

FNC_XIT:

  return( result );
}



static int ViewHexArchiveFile(char *file_path)
{
  char *command_line;
  char *archive;
  char buffer[80];
  int result = -1;

  if( ( command_line = (char *)malloc( COMMAND_LINE_LENGTH + 1 ) ) == NULL )
  {
    ERROR_MSG( "Malloc failed*ABORT" );
    exit( 1 );
  }

  (void) sprintf( buffer, "| %s | %s", HEXDUMP, PAGER );

  archive = (mode == TAPE_MODE) ? statistic.tape_name : statistic.login_path;

  MakeExtractCommandLine( command_line, 
			  archive,
			  file_path, 
			  buffer
			);

  if((result = SilentSystemCall( command_line )))
  {
    (void) sprintf( message, "can't execute*%s", command_line );
    MESSAGE( message );
  }

  free( command_line );

  return( result );
}