1010
1111#include "chunks.h"
1212#include "ctassert.h"
13+ #include "hexify.h"
1314#include "multitape_internal.h"
1415#include "storage.h"
1516#include "sysendian.h"
@@ -243,22 +244,42 @@ print_sep(char sep, int nulls, int num)
243244}
244245
245246/**
246- * statstape_printlist_item(d, tapehash, verbose, print_nulls):
247+ * statstape_printlist_item(d, tapehash, verbose, print_nulls, print_hash ):
247248 * Print the name of the archive with ${tapehash}. If ${verbose} > 0, print
248249 * the creation times; if ${verbose} > 1, print the argument vector of the
249250 * program invocation which created the archive. If ${print_nulls} > 0, print
250251 * null character(s) between archives names and fields instead of newlines,
251- * tabs, and spaces.
252+ * tabs, and spaces. If ${print_hash} > 0 and ${verbose} is 0, print the hash
253+ * instead of the archive name. If ${print_hash} > 0 and ${verbose} > 0,
254+ * print hash in addition to the normal behaviour.
252255 */
253256static int
254257statstape_printlist_item (TAPE_S * d , const uint8_t tapehash [32 ], int verbose ,
255- int print_nulls )
258+ int print_nulls , int print_hash )
256259{
257260 struct tapemetadata tmd ;
261+ char hexstr [65 ];
258262 struct tm * ltime ;
259263 char datebuf [DATEBUFLEN ];
260264 int arg ;
261265
266+ /* Print archive hash. */
267+ if (print_hash ) {
268+ hexify (tapehash , hexstr , 32 );
269+ fprintf (stdout , "%s" , hexstr );
270+
271+ if (verbose == 0 ) {
272+ /* We're finished; print archive separator and quit. */
273+ if (print_sep ('\n' , print_nulls , 1 ))
274+ goto err1 ;
275+ goto done ;
276+ } else {
277+ /* We have more fields; print field separator. */
278+ if (print_sep ('\t' , print_nulls , 2 ))
279+ goto err1 ;
280+ }
281+ }
282+
262283 /* Read the tape metadata. */
263284 if (multitape_metadata_get_byhash (d -> SR , NULL , & tmd , tapehash , 0 ))
264285 goto err0 ;
@@ -317,6 +338,7 @@ statstape_printlist_item(TAPE_S * d, const uint8_t tapehash[32], int verbose,
317338 /* Free parsed metadata. */
318339 multitape_metadata_free (& tmd );
319340
341+ done :
320342 /* Success! */
321343 return (0 );
322344
@@ -328,15 +350,17 @@ statstape_printlist_item(TAPE_S * d, const uint8_t tapehash[32], int verbose,
328350}
329351
330352/**
331- * statstape_printlist(d, verbose, print_nulls):
353+ * statstape_printlist(d, verbose, print_nulls, print_hashes ):
332354 * Print the names of each of the archives in a set. If ${verbose} > 0, print
333355 * the creation times; if ${verbose} > 1, print the argument vector of the
334356 * program invocation which created the archive. If ${print_nulls} > 0, print
335357 * null character(s) between archives names and fields instead of newlines,
336- * tabs, and spaces.
358+ * tabs, and spaces. If ${print_hashes} > 0 and ${verbose} is 0, print hashes
359+ * instead of archive names. If ${print_hashes} > 0 and ${verbose} > 0, print
360+ * hashes in addition to the normal behaviour.
337361 */
338362int
339- statstape_printlist (TAPE_S * d , int verbose , int print_nulls )
363+ statstape_printlist (TAPE_S * d , int verbose , int print_nulls , int print_hashes )
340364{
341365 uint8_t * flist ;
342366 size_t nfiles ;
@@ -349,7 +373,7 @@ statstape_printlist(TAPE_S * d, int verbose, int print_nulls)
349373 /* Iterate through the files. */
350374 for (file = 0 ; file < nfiles ; file ++ ) {
351375 if (statstape_printlist_item (d , & flist [file * 32 ], verbose ,
352- print_nulls ))
376+ print_nulls , print_hashes ))
353377 goto err1 ;
354378 }
355379
0 commit comments