mirror of
https://gitea.home.endeavr.de/Marcel/Tarstats-pp.git
synced 2025-12-10 00:39:01 +01:00
this put console output into its own function
This commit is contained in:
14
main.cpp
14
main.cpp
@@ -15,7 +15,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
// GENERAL VARIABLES
|
// GENERAL VARIABLES
|
||||||
//count the types of all items
|
//count the types of all items
|
||||||
std::map<std::string, uint> typecount{
|
std::map<std::string, uintmax_t> typecount{
|
||||||
{tarconstant::typeFile, 0}, {tarconstant::typeDir, 0}, {tarconstant::typeSym, 0},
|
{tarconstant::typeFile, 0}, {tarconstant::typeDir, 0}, {tarconstant::typeSym, 0},
|
||||||
{tarconstant::typeHard, 0}, {tarconstant::typeOther, 0}
|
{tarconstant::typeHard, 0}, {tarconstant::typeOther, 0}
|
||||||
};
|
};
|
||||||
@@ -30,6 +30,10 @@ int main(int argc, char** argv) {
|
|||||||
// Getting name from argument lists on startup. Trivial and errorprone. Placeholder for now.
|
// Getting name from argument lists on startup. Trivial and errorprone. Placeholder for now.
|
||||||
std::string archiveFilename(argv[1]);
|
std::string archiveFilename(argv[1]);
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++){
|
||||||
|
std::cout << argv[i] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
//Open tar File.
|
//Open tar File.
|
||||||
std::ifstream file(archiveFilename, std::ios::binary);
|
std::ifstream file(archiveFilename, std::ios::binary);
|
||||||
if(!file) {
|
if(!file) {
|
||||||
@@ -70,11 +74,9 @@ int main(int argc, char** argv) {
|
|||||||
delete[] headbuffer;
|
delete[] headbuffer;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
std::cout << "Archive size: " << std::filesystem::file_size(archiveFilename) << " Bytes"<< '\n';
|
|
||||||
std::cout << "Size of all items: " << sizeof_allfiles << " Bytes" << '\n' << '\n';
|
tar::consolestats(typecount, std::filesystem::file_size(archiveFilename), sizeof_allfiles);
|
||||||
for (auto &i : typecount) {
|
|
||||||
std::cout << i.first <<": " << i.second << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
10
tarfunc.cpp
10
tarfunc.cpp
@@ -7,6 +7,8 @@
|
|||||||
#include "tarconst.h"
|
#include "tarconst.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
// checks if a valid modern tar file - ustar
|
// checks if a valid modern tar file - ustar
|
||||||
bool tar::validTar(std::istream &file) {
|
bool tar::validTar(std::istream &file) {
|
||||||
@@ -57,4 +59,12 @@ std::string tar::getitemtype(char &n) {
|
|||||||
default:
|
default:
|
||||||
return tarconstant::typeOther;
|
return tarconstant::typeOther;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tar::consolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall) {
|
||||||
|
std::cout << "Archive size: " << tarfilesize << " Bytes"<< '\n';
|
||||||
|
std::cout << "Size of all items: " << sizeofall << " Bytes" << '\n' << '\n';
|
||||||
|
for (auto &i : typecount) {
|
||||||
|
std::cout << i.first <<": " << i.second << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
#ifndef TARSTATS___TARFUNC_H
|
#ifndef TARSTATS___TARFUNC_H
|
||||||
@@ -20,6 +22,8 @@ namespace tar {
|
|||||||
|
|
||||||
// gets type of an item
|
// gets type of an item
|
||||||
std::string getitemtype(char &n);
|
std::string getitemtype(char &n);
|
||||||
|
//
|
||||||
|
void consolestats (std::map<std::string, uintmax_t> &typecount, uintmax_t tarfilesize, uintmax_t sizeofall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user