mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Add snippet tool to interact with AaruFormat images.
This commit is contained in:
@@ -157,4 +157,12 @@ endif()
|
|||||||
|
|
||||||
include_directories(include 3rdparty/uthash/src)
|
include_directories(include 3rdparty/uthash/src)
|
||||||
|
|
||||||
add_subdirectory(tests)
|
include(CheckLibraryExists)
|
||||||
|
|
||||||
|
check_library_exists(m log "" HAVE_LIB_M)
|
||||||
|
if(HAVE_LIB_M)
|
||||||
|
TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat m)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(tests)
|
||||||
|
add_subdirectory(tool)
|
||||||
4
tool/CMakeLists.txt
Normal file
4
tool/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
project(aaruformattool)
|
||||||
|
|
||||||
|
add_executable(aaruformattool main.c main.h aaruformattool.h identify.c)
|
||||||
|
target_link_libraries(aaruformattool "aaruformat")
|
||||||
24
tool/aaruformattool.h
Normal file
24
tool/aaruformattool.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
|
* Copyright (c) 2019-2022 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
#ifndef LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||||
|
#define LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||||
|
|
||||||
|
int identify(char* path);
|
||||||
|
|
||||||
|
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||||
46
tool/identify.c
Normal file
46
tool/identify.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
|
* Copyright (c) 2019-2022 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <aaruformat.h>
|
||||||
|
|
||||||
|
int identify(char* path)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = aaruf_identify(path);
|
||||||
|
|
||||||
|
if(ret < 0) { printf("Error %d while trying to identify file.\n", ret); }
|
||||||
|
else if(ret == 0)
|
||||||
|
{
|
||||||
|
printf("The specified file is not a support AaruFormat image.\n");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else if(ret == 100)
|
||||||
|
{
|
||||||
|
printf("The specified file is a supported AaruFormat image.\n");
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("The library has not enough confidence this is an AaruFormat image, and this shall NEVER happen.\n");
|
||||||
|
ret = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
82
tool/main.c
Normal file
82
tool/main.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
|
* Copyright (c) 2019-2022 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <aaruformat.h>
|
||||||
|
|
||||||
|
#include "aaruformattool.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
void usage()
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
printf("Usage:\n");
|
||||||
|
printf("aaruformattool <verb> [arguments]\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Available verbs:\n");
|
||||||
|
printf("\tidentify\tIdentifies if the indicated file is a supported AaruFormat image.\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("For help on the verb invoke the tool with the verb and no arguments.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void usage_identify()
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
printf("Usage:\n");
|
||||||
|
printf("aaruformattool identify <filename>\n");
|
||||||
|
printf("Identifies if the indicated file is a support AaruFormat image.\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Arguments:\n");
|
||||||
|
printf("\t<filename>\tPath to file to identify if it is a supported AaruFormat image.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
printf("AaruFormat Tool version %d.%d\n", AARUFORMAT_TOOL_MAJOR_VERSION, AARUFORMAT_TOOL_MINOR_VERSION);
|
||||||
|
printf("Copyright (C) 2019-2022 Natalia Portillo\n");
|
||||||
|
printf("libaaruformat version %d.%d\n", LIBAARUFORMAT_MAJOR_VERSION, LIBAARUFORMAT_MINOR_VERSION);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strncmp(argv[1], "identify", strlen("identify")) == 0)
|
||||||
|
{
|
||||||
|
if(argc == 2)
|
||||||
|
{
|
||||||
|
usage_identify();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(argc > 3)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid number of arguments\n");
|
||||||
|
usage_identify();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return identify(argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
tool/main.h
Normal file
26
tool/main.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
|
* Copyright (c) 2019-2022 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBAARUFORMAT_TOOL_MAIN_H_
|
||||||
|
#define LIBAARUFORMAT_TOOL_MAIN_H_
|
||||||
|
|
||||||
|
#define AARUFORMAT_TOOL_MAJOR_VERSION 1
|
||||||
|
#define AARUFORMAT_TOOL_MINOR_VERSION 0
|
||||||
|
|
||||||
|
#endif // LIBAARUFORMAT_TOOL_MAIN_H_
|
||||||
Reference in New Issue
Block a user