this cleaned up functions and global constants and hid them away in to their header and source files

This commit is contained in:
Marcel Nowicki
2022-02-10 20:45:09 +01:00
parent 2af7cf5adf
commit 3b2e3aa2ff
5 changed files with 147 additions and 89 deletions

40
tarconst.h Normal file
View File

@@ -0,0 +1,40 @@
/* this headerfile contains global constant variables needed during parsing of a tar file
*
* by Marcel Nowicki (github@epenis.de | github.com/blindi0815)
*/
#ifndef TARSTATS___TARCONST_H
#define TARSTATS___TARCONST_H
#include <string>
#include <utility>
namespace tarconstant {
// global itemtype definition
inline std::string const typeFile = "FILES";
inline std::string const typeDir = "DIRECTORIES";
inline std::string const typeSym = "SYMLINKS";
inline std::string const typeHard = "HARDLINKS";
inline std::string const typeOther = "OTHER";
// valid magicfield
inline std::string const mgcfield = "ustar";
// Byte offsets
inline uint16_t blocksize = 512; // tar consists of continuous 512 Byte data blocks
inline uint8_t itemtypeByte = 156;
inline std::pair<uint16_t, uint8_t> mgcfieldByte {257,6}; // { offset , length }
inline std::pair<uint8_t , uint8_t> itemoctlnByte {124,11}; // at offset 124 because first byte
// marks octal or base256 coding
inline std::string helptext
{"usage: tarstats-pp [-h] [-j] [-f] tarfile.\n"
"A tool to calculate basics statistics on tarball. Shamelessly inspired by github.com/isotopp/tarstats!\n\n"
"mandatory argument:\n"
"tarfile a tarfile to calculate stats on\n\n"
"optional arguments\n"
"-h this helptext\n"
"-j stats in JSON format printed to stdout\n"
"-f print stats to file <tarfilename>.txt or .json if -j invoked"};
}
#endif //TARSTATS___TARCONST_H