1 /***************************************************************************
2 *
3 * $Header: /usr/local/cvsroot/utils/ytree/lha.c,v 1.12 2000/05/20 20:41:11 werner Exp $
4 *
5 * Funktionen zum Lesen des Dateibaumes aus LHA-Dateien
6 *
7 ***************************************************************************/
8
9
10 #include "ytree.h"
11
12
13
14 static int GetStatFromLHA(char *lha_line, char *name, struct stat *stat);
15
16
17
18
19 /* Dateibaum aus LHA-Listing lesen */
20 /*---------------------------------*/
21
ReadTreeFromLHA(DirEntry * dir_entry,FILE * f)22 int ReadTreeFromLHA(DirEntry *dir_entry, FILE *f)
23 {
24 char lha_line[LHA_LINE_LENGTH + 1];
25 char path_name[PATH_LENGTH +1];
26 struct stat stat;
27 BOOL dir_flag = FALSE;
28
29 *dir_entry->name = '\0';
30
31 while( fgets( lha_line, LHA_LINE_LENGTH, f ) != NULL )
32 {
33 /* \n loeschen */
34 /*-------------*/
35
36 lha_line[ strlen( lha_line ) - 1 ] = '\0';
37
38 if( ( (strlen( lha_line ) > (unsigned) 55 && lha_line[55] == ':' ) ||
39 (strlen( lha_line ) > (unsigned) 61 && lha_line[61] == ':' ) ) &&
40 lha_line[34] != '*' && strncmp( &lha_line[1], "Total", 5 ) )
41 {
42 /* gueltiger Eintrag */
43 /*-------------------*/
44
45 if( GetStatFromLHA( lha_line, path_name, &stat ) )
46 {
47 (void) sprintf( message, "unknown lhainfo*%s", lha_line );
48 MESSAGE( message );
49 }
50 else
51 {
52 /* File */
53 /*------*/
54
55 #ifdef DEBUG
56 fprintf( stderr, "FILE: \"%s\"\n", path_name );
57 #endif
58 (void) InsertArchiveFileEntry( dir_entry, path_name, &stat );
59 }
60 }
61 }
62
63
64 if( dir_flag == FALSE )
65 {
66 statistic.disk_total_directories++;
67 (void) memset( (char *) &dir_entry->stat_struct, 0, sizeof( struct stat ) );
68 dir_entry->stat_struct.st_mode = S_IFDIR;
69 }
70 return( MinimizeArchiveTree( dir_entry ) );
71 }
72
73
74
75
76
GetStatFromLHA(char * lha_line,char * name,struct stat * stat)77 static int GetStatFromLHA(char *lha_line, char *name, struct stat *stat)
78 {
79 char *t, *old;
80 char modus[11];
81 BOOL dos_mode = FALSE;
82 int i, id;
83 struct tm tm_struct;
84 static char *month[] = { "Jan", "Feb", "Mar", "Apr", "Mai", "Jun",
85 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
86
87
88 (void) memset( stat, 0, sizeof( struct stat ) );
89
90 stat->st_nlink = 1;
91
92 t = Strtok_r( lha_line, " \t", &old ); if( t == NULL ) return( -1 );
93
94 /* Attributes */
95 /*------------*/
96
97 if( strlen( t ) == 9 && *t != '[' )
98 {
99 *modus = '-';
100 (void) strcpy( &modus[1], t );
101 stat->st_mode = GetModus( modus );
102 }
103 else if( *t == '[' )
104 {
105 stat->st_mode = GetModus( "-rw-r--r--" );
106 dos_mode = TRUE;
107 }
108 else return( -1 );
109
110 t = Strtok_r( NULL, " \t/", &old ); if( t == NULL ) return( -1 );
111
112 if( dos_mode )
113 {
114 stat->st_uid = getuid();
115 stat->st_gid = getgid();
116 }
117 else
118 {
119 /* Owner */
120 /*-------*/
121
122 id = atoi( t );
123 stat->st_uid = (unsigned) id;
124 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
125
126 /* Group */
127 /*-------*/
128
129 id = atoi( t );
130 stat->st_gid = (unsigned) id;
131 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
132 }
133
134 /* Packed-Size */
135 /*-------------*/
136
137 if( !isdigit( *t ) ) return( -1 );
138 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
139
140 /* Dateilaenge */
141 /*-------------*/
142
143 if( !isdigit( *t ) ) return( -1 );
144 stat->st_size = AtoLL( t );
145 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
146
147 /* Ratio */
148 /*-------*/
149
150 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
151
152 /* CRC */
153 /*-----*/
154
155 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
156
157 if( lha_line[61] == ':' )
158 {
159 /* ??? */
160 /*-----*/
161
162 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
163 }
164
165 /* M-Datum */
166 /*---------*/
167
168 for( i=0; i < 12; i++ )
169 {
170 if( !strcmp( t, month[i] ) ) break;
171 }
172 if( i >= 12 ) i = 0;
173
174 tm_struct.tm_mon = i;
175 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
176
177 tm_struct.tm_mday = atoi( t );
178 t = Strtok_r( NULL, " \t:", &old ); if( t == NULL ) return( -1 );
179
180 tm_struct.tm_hour = atoi( t );
181 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
182
183 tm_struct.tm_min = atoi( t );
184 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
185
186 if( lha_line[41] == '-' )
187 {
188 /* ??? */
189 tm_struct.tm_year = 70; /* Start UNIX-Time */
190 }
191 else
192 {
193 tm_struct.tm_year = atoi( t ) - 1900;
194 t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
195 }
196
197 tm_struct.tm_sec = 0;
198
199 tm_struct.tm_isdst = -1;
200
201 stat->st_atime = 0;
202 stat->st_ctime = 0;
203
204 stat->st_mtime = Mktime( &tm_struct );
205
206 /* Dateiname */
207 /*-----------*/
208
209 (void) strcpy( name, t );
210
211 return( 0 );
212 }
213
214
215