Fixing paths

This commit is contained in:
Matteo Paonessa 2017-11-12 12:29:10 +01:00
parent a0cd632098
commit a0f1a34f14
11 changed files with 347 additions and 41 deletions

161
.gitignore vendored
View File

@ -10,6 +10,163 @@ Thumbs.db
.Spotlight-V100
.Trashes
.idea
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-*
build
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### macOS template
# General
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.TemporaryItems
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Linux template
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Windows template
# Windows thumbnail cache files
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
### C template
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
caesiumclt

2
.idea/caesium-clt.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@ -0,0 +1,125 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClangTidyInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="DeprecatedAPI" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="DuplicateSwitchCase" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="EndlessLoop" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="EqualityInConditionalOperator" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="FormatSpecifiers" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="FunctionImplicitDeclarationInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="HidesUpperScope" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="HidingNonVirtualFunction" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="ImplicitIntegerAndEnumConversion" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="ImplicitPointerAndIntegerConversion" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="IncompatibleEnums" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="IncompatibleInitializers" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="IncompatiblePointers" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="InfiniteRecursion" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="KRUnspecifiedParameters" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="LocalValueEscapesScope" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="MissingReturn" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="MissingSwitchCase" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="NotImplementedFunctions" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="NotInitializedVariable" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="NotSuperclass" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCDFAInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCLoopDoesntUseConditionVariableInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCSimplifyInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCUnusedGlobalDeclarationInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCUnusedMacroInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCUnusedStructInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="OCUnusedTemplateParameterInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="RedundantCast" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="ResourceNotFoundInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="SignednessMismatch" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnreachableCode" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedExpressionResult" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedImportStatement" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedLocalVariable" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedLocalization" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedParameter" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="UnusedValue" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
<inspection_tool class="ValueMayNotFitIntoReceiver" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="Inspection" level="WARNING" enabled="true" />
</inspection_tool>
</profile>
</component>

12
.idea/misc.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<sourceRoots>
<file path="$PROJECT_DIR$/src" />
</sourceRoots>
<excludeRoots>
<file path="$PROJECT_DIR$/cmake-build-debug/CMakeFiles" />
</excludeRoots>
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/caesium-clt.iml" filepath="$PROJECT_DIR$/.idea/caesium-clt.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,3 @@
<component name="DependencyValidationManager">
<scope name="Inspection" pattern="!file:src/optparse.c&amp;&amp;!file:src/optparse.h&amp;&amp;!file:src/tinydir.h&amp;&amp;!file:.gitignore" />
</component>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -7,7 +7,7 @@
#include <windows.h>
#define getcwd _getcwd
#else
#include <unistd.h>
#endif
#include "helper.h"
@ -40,33 +40,27 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
while ((option = optparse_long(&opts, longopts, NULL)) != -1) {
switch (option) {
case 'q':
options->jpeg.quality = atoi(opts.optarg);
options->jpeg.quality = (int)strtol(opts.optarg, (char **)NULL, 10);;
if (options->jpeg.quality < 0 || options->jpeg.quality > 100) {
display_error(ERROR, 1);
}
break;
case 'e':
options->jpeg.exif_copy = true;
case 'p':
options->jpeg.progressive = false;
break;
case 'o':
realpath(opts.optarg, parameters.output_folder);
//TODO Resolve ~
if (opts.optarg[0] == '~') {
snprintf(parameters.output_folder, strlen(parameters.output_folder), "%s", parameters.output_folder);
if (opts.optarg[strlen(opts.optarg) - 1] == '/' || opts.optarg[strlen(opts.optarg) - 1] == '\\') {
snprintf(parameters.output_folder, strlen(opts.optarg) + 1, "%s", opts.optarg);
} else {
#ifdef _WIN32
snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s\\", opts.optarg);
#else
snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s/", opts.optarg);
#endif
}
} else {
realpath(opts.optarg, parameters.output_folder);
}
// if (opts.optarg[strlen(opts.optarg) - 1] == '/' || opts.optarg[strlen(opts.optarg) - 1] == '\\') {
// snprintf(parameters.output_folder, strlen(opts.optarg) + 1, "%s", opts.optarg);
// } else {
//#ifdef _WIN32
// snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s\\", opts.optarg);
//#else
// snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s/", opts.optarg);
//#endif
// }
//Prepend the current directory if necessary
break;
case 'R':
parameters.recursive = true;
@ -89,7 +83,6 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
display_error(ERROR, 2);
}
}
//Remaining arguments
char *arg;
bool files_flag = false, folders_flag = false;
@ -101,25 +94,23 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
}
//Check if it's a directory and add its content
realpath(arg, resolved_path);
//TODO Resolve ~
if (arg[0] == '~') {
snprintf(resolved_path, strlen(resolved_path), "%s", resolved_path);
if (arg[strlen(arg) - 1] == '/' || arg[strlen(arg) - 1] == '\\') {
snprintf(resolved_path, strlen(arg), "%s", arg);
} else {
#ifdef _WIN32
snprintf(resolved_path, strlen(arg) + 1, "%s\\", arg);
#else
snprintf(resolved_path, strlen(arg) + 1, "%s/", arg);
#endif
}
} else {
realpath(arg, resolved_path);
}
if (is_directory(resolved_path)) {
if (!files_flag) {
folders_flag = true;
snprintf(parameters.input_folder, strlen(resolved_path) + 1, "%s", resolved_path);
// if (arg[strlen(arg) - 1] == '/' || arg[strlen(arg) - 1] == '\\') {
// parameters.input_folder = strdup(arg);
// } else {
// parameters.input_folder = malloc((strlen(arg) + 2) * sizeof(char));
//#ifdef _WIN32
// snprintf(parameters.input_folder, (strlen(arg) + 2), "%s\\", arg);
//#else
// snprintf(parameters.input_folder, (strlen(arg) + 2), "%s/", arg);
//#endif
// }
int count = 0;
count = scan_folder(resolved_path, &parameters, parameters.recursive);
if (count == 0) {
@ -199,7 +190,8 @@ int start_compression(cclt_options *options, cs_image_pars *parameters)
snprintf(output_full_folder, strlen(options->output_folder) + size + 1, "%s%s",
options->output_folder, &options->input_files[i][index]);
output_full_path = malloc((strlen(output_full_folder) + strlen(filename) + 1) * sizeof(char));
snprintf(output_full_path, strlen(output_full_folder) + strlen(filename) + 1, "%s%s", output_full_folder,
snprintf(output_full_path, strlen(output_full_folder) + strlen(filename) + 1, "%s%s",
output_full_folder,
filename);
mkpath(output_full_folder);

View File

@ -4,8 +4,6 @@
#include <caesium.h>
#include "utils.h"
#include <unistd.h>
int main(int argc, char *argv[])
{
@ -29,7 +27,7 @@ int main(int argc, char *argv[])
start_compression(&options, &compress_options);
//Cleanup the two memory allocated objects
//Cleanup the memory allocated objects
free(options.input_files);
//Get the difference

View File

@ -4,7 +4,6 @@
#include <caesium.h>
#include <limits.h>
#include <math.h>
#include <ctype.h>
#include "utils.h"
#include "tinydir.h"
@ -21,7 +20,6 @@ void print_help()
"Options:\n"
"\t-q, --quality\t\tset output file quality between [0-100], 0 for optimization\n"
"\t-e, --exif\t\tkeeps EXIF info during compression\n"
"\t-p, --progressive\t\toutputs a progressive JPEG\n"
"\t-o, --output\t\toutput folder\n"
"\t-R, --recursive\t\tif input is a folder, scan subfolders too\n"
"\t-S, --keep-structure\tkeep the folder structure, use with -R\n"
@ -141,6 +139,10 @@ off_t get_file_size(const char *path)
char *get_human_size(off_t size)
{
if (size == 0) {
return "0.00 B";
}
//We should not get more than TB images
char *unit[5] = {"B", "KB", "MB", "GB", "TB"};
//Index of the array containing the correct unit