-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e11ce5
commit 40a2e2d
Showing
10 changed files
with
139 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
|
||
formattedTime_t formatTime(double seconds); | ||
|
||
#endif | ||
void removeTrailingNewLine(char16_t *string); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
CC=gcc | ||
CFLAGS=-fdiagnostics-color=always $(OPTIMIZATIONFLAGS) -Wall -Wno-unused-variable -Wno-unused-function -std=c17 -municode | ||
BIN=rffmpeg | ||
|
||
IDIR=include | ||
ODIR=src/obj | ||
SDIR=src | ||
LDIR=lib | ||
OPTIMIZATIONFLAGS=-s -Os -fdata-sections -ffunction-sections -Wl,--gc-sections -flto | ||
CDIRS=./src | ||
ODIRS=./src/obj | ||
DDIRS=./src/dep | ||
INCDIRS=./include ./include/man | ||
|
||
LIBS=-lm | ||
# This build system builds a file ready to be debugged by default. If you want to use its size optimizations | ||
# for a final build, uncomment OPTFLAGS, comment DBGFLAGS, use `make clean` and just run `make` | ||
|
||
_DEPS=libs.h constants.h mainloop.h handlers.h terminal.h input.h man/help.h types.h | ||
DEPS=$(patsubst %,$(IDIR)/%,$(_DEPS)) | ||
DBGFLAGS=#-g | ||
OPTFLAGS=-s -Os -fdata-sections -ffunction-sections -Wl,--gc-sections -flto | ||
DEPFLAGS=-MP -MD | ||
CCFLAGS=-Wall -Wno-unused-variable -Wno-unused-function -std=c17 -municode -fdiagnostics-color=always -municode $(foreach D,$(INCDIRS),-I$(D)) $(DEPFLAGS) | ||
|
||
_OBJ=main.o typefunctions.o mainloop.o handlers.o input.o terminal.o | ||
OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ)) | ||
CFILES=$(foreach D,$(CDIRS),$(wildcard $(D)/*.c)) | ||
HFILES=$(foreach D,$(INCDIRS),$(wildcard $(D)/*.h)) | ||
OFILES=$(patsubst $(CDIRS)/%.c, $(ODIRS)/%.o, $(CFILES)) | ||
DFILES=$(patsubst $(ODIRS)/%.o, $(DDIRS)/%.d, $(OFILES)) | ||
|
||
$(ODIR)/%.o: $(SDIR)/%.c $(DEPS) | ||
$(CC) -c -o $@ $< $(CFLAGS) | ||
all: $(BIN) | ||
|
||
rffmpeg: $(OBJ) | ||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) | ||
$(BIN): $(OFILES) | ||
$(CC) $(CCFLAGS) $(OPTFLAGS) $(DBGFLAGS) -o $@ $^ | ||
|
||
-include $(DFILES) | ||
|
||
%.o: ../%.c makefile $(HFILES) | ||
$(CC) $(CCFLAGS) $(OPTFLAGS) $(DBGFLAGS) -c -o $@ $< | ||
|
||
.PHONY: clean | ||
|
||
clean: $(OBJ) | ||
rm -f $(OBJ)/*.o | ||
clean: | ||
del /Q .\\src\\obj\\* | ||
# del /Q .\\src\\dep\\* | ||
del .\\rffmpeg.exe | ||
del .\\debug.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,104 @@ | ||
#include "../include/input.h" | ||
|
||
/* Gets the argument strings from a console menu and formats them to be parsed by parseCommandLineArguments() */ | ||
char16_t **parseArgumentsFromTerminal(size_t *outputArgumentsCount, char16_t *outputArguments[]) { | ||
/* Gets and parses the argument strings from console input dialogs */ | ||
errno_t parseArgumentsFromTerminal(arguments_t *arguments) { | ||
size_t currentIndex = 0; | ||
DWORD charactersRead = 0; | ||
HANDLE consoleInput = GetStdHandle(STD_INPUT_HANDLE); | ||
|
||
wprintf_s(u"%ls > %lsInput path: %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
|
||
outputArguments[currentIndex] = calloc(sizeof(u"-path"), sizeof(char16_t)); | ||
wcscpy_s(outputArguments[currentIndex], PATHBUF, u"-path"); | ||
++currentIndex; | ||
|
||
outputArguments[currentIndex] = calloc(PATHBUF, sizeof(char16_t)); | ||
|
||
ReadConsoleW(consoleInput, outputArguments[currentIndex], PATHBUF, &charactersRead, NULL); | ||
|
||
outputArguments[currentIndex][wcscspn(outputArguments[currentIndex], u"\r\n")] = u'\0'; // Remove trailing fgets() newline | ||
|
||
++currentIndex; | ||
ReadConsoleW(consoleInput, arguments->inputPath, PATHBUF, &charactersRead, NULL); | ||
removeTrailingNewLine(arguments->inputPath); | ||
|
||
wprintf_s(u"%ls > %lsTarget format(s): %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
|
||
outputArguments[currentIndex] = calloc(sizeof(u"-fmt"), sizeof(char16_t)); | ||
wcscpy_s(outputArguments[currentIndex], PATHBUF, u"-fmt"); | ||
++currentIndex; | ||
|
||
outputArguments[currentIndex] = calloc(BUFFER, sizeof(char16_t)); | ||
|
||
ReadConsoleW(consoleInput, outputArguments[currentIndex], BUFFER, &charactersRead, NULL); | ||
|
||
outputArguments[currentIndex][wcscspn(outputArguments[currentIndex], u"\r\n")] = u'\0'; | ||
|
||
++currentIndex; | ||
ReadConsoleW(consoleInput, arguments->inputFormatString, SHORTBUF, &charactersRead, NULL); | ||
removeTrailingNewLine(arguments->inputFormatString); | ||
|
||
wprintf_s(u"%ls > %lsFFmpeg options: %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
|
||
outputArguments[currentIndex] = calloc(sizeof(u"-opts"), sizeof(char16_t)); | ||
wcscpy_s(outputArguments[currentIndex], PATHBUF, u"-opts"); | ||
++currentIndex; | ||
|
||
outputArguments[currentIndex] = calloc(BUFFER, sizeof(char16_t)); | ||
|
||
ReadConsoleW(consoleInput, outputArguments[currentIndex], BUFFER, &charactersRead, NULL); | ||
|
||
outputArguments[currentIndex][wcscspn(outputArguments[currentIndex], u"\r\n")] = u'\0'; | ||
|
||
++currentIndex; | ||
ReadConsoleW(consoleInput, arguments->inputParameters, BUFFER, &charactersRead, NULL); | ||
removeTrailingNewLine(arguments->inputParameters); | ||
|
||
wprintf_s(u"%ls > %lsOutput extension: %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
|
||
outputArguments[currentIndex] = calloc(sizeof(u"-ext"), sizeof(char16_t)); | ||
wcscpy_s(outputArguments[currentIndex], PATHBUF, u"-ext"); | ||
++currentIndex; | ||
|
||
outputArguments[currentIndex] = calloc(SHORTBUF, sizeof(char16_t)); | ||
|
||
ReadConsoleW(consoleInput, outputArguments[currentIndex], SHORTBUF, &charactersRead, NULL); | ||
|
||
outputArguments[currentIndex][wcscspn(outputArguments[currentIndex], u"\r\n")] = u'\0'; | ||
|
||
++currentIndex; | ||
|
||
wprintf_s(u"%ls > %lsAdditional flags: %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
ReadConsoleW(consoleInput, arguments->outputFormat, SHORTBUF, &charactersRead, NULL); | ||
removeTrailingNewLine(arguments->outputFormat); | ||
|
||
char16_t optionsString[BUFFER]; | ||
|
||
wprintf_s(u"%ls > %lsAdditional flags: %ls", CHARCOLOR_RED, CHARCOLOR_WHITE, CHARCOLOR_WHITE_BOLD); | ||
ReadConsoleW(consoleInput, optionsString, BUFFER, &charactersRead, NULL); | ||
optionsString[wcscspn(optionsString, u"\r\n")] = u'\0'; | ||
removeTrailingNewLine(optionsString); | ||
|
||
|
||
wchar_t *parserState = NULL; | ||
wchar_t *token = wcstok_s(optionsString, u", ", &parserState); | ||
|
||
char16_t *optionsList[SHORTBUF] = { NULL }; | ||
size_t optionsCount = 0; | ||
|
||
while (token) { | ||
outputArguments[currentIndex] = calloc(SHORTBUF, sizeof(char16_t)); | ||
wcscpy_s(outputArguments[currentIndex], SHORTBUF, token); | ||
for (int i = 0; token != NULL; optionsCount = ++i) { | ||
if ((optionsList[i] = calloc(SHORTBUF, sizeof(char16_t))) == NULL) { | ||
printError(u"not enough memory"); | ||
|
||
return ERROR_NOT_ENOUGH_MEMORY; | ||
} | ||
|
||
wcscpy_s(optionsList[i], SHORTBUF, token); | ||
token = wcstok_s(NULL, u", ", &parserState); | ||
++currentIndex; | ||
} | ||
|
||
*outputArgumentsCount = currentIndex; | ||
parseCommandLineArguments(optionsCount, (const char16_t**)optionsList, arguments); | ||
|
||
for (int i = 0; i < optionsCount; ++i) { | ||
free(optionsList[i]); | ||
optionsList[i] = NULL; | ||
} | ||
|
||
wprintf_s(u"\n"); | ||
wprintf_s(COLOR_DEFAULT); | ||
|
||
return outputArguments; | ||
return NO_ERROR; | ||
} | ||
|
||
/* Parses the arguments after they've been properly formatted into a sequenced array of strings */ | ||
arguments_t parseCommandLineArguments(const int count, const char16_t *rawArguments[]) { | ||
arguments_t parsedArguments; | ||
/* Parses an array of strings to format parsedArguments accordingly */ | ||
errno_t parseCommandLineArguments(const int count, const char16_t *rawArguments[], arguments_t *parsedArguments) { | ||
|
||
for (size_t i = 0; i < count; ++i) { | ||
for (int i = 0; i < count; ++i) { | ||
/* fmt: -i <path> -f <container> -p <params> -o <container> */ | ||
if (wcscmp(rawArguments[i], u"-path") == 0) { | ||
wcsncpy_s(parsedArguments.inputPath, PATHBUF, rawArguments[++i], PATHBUF); | ||
wcsncpy_s(parsedArguments->inputPath, PATHBUF, rawArguments[++i], PATHBUF); | ||
} else if (wcscmp(rawArguments[i], u"-fmt") == 0) { | ||
wcsncpy_s(parsedArguments.inputFormatString, SHORTBUF, rawArguments[++i], BUFFER); | ||
wcsncpy_s(parsedArguments->inputFormatString, SHORTBUF, rawArguments[++i], BUFFER); | ||
} else if (wcscmp(rawArguments[i], u"-opts") == 0) { | ||
wcsncpy_s(parsedArguments.inputParameters, BUFFER, rawArguments[++i], BUFFER); | ||
wcsncpy_s(parsedArguments->inputParameters, BUFFER, rawArguments[++i], BUFFER); | ||
} else if (wcscmp(rawArguments[i], u"-ext") == 0) { | ||
wcsncpy_s(parsedArguments.outputFormat, SHORTBUF, rawArguments[++i], SHORTBUF); | ||
wcsncpy_s(parsedArguments->outputFormat, SHORTBUF, rawArguments[++i], SHORTBUF); | ||
} | ||
|
||
/* fmt: --help, --newfolder=foldername, --delete, --norecursion, --overwrite, */ | ||
if (wcscmp(rawArguments[i], OPT_DISPLAYHELP_STRING) == 0) { | ||
parsedArguments.optionDisplayHelp = true; | ||
parsedArguments->optionDisplayHelp = true; | ||
} else if (wcscmp(rawArguments[i], OPT_DELETEOLDFILES_STRING) == 0) { | ||
parsedArguments.optionDeleteOriginalFiles = true; | ||
parsedArguments->optionDeleteOriginalFiles = true; | ||
} else if (wcscmp(rawArguments[i], OPT_DISABLERECURSION_STRING) == 0) { | ||
parsedArguments.optionDisableRecursiveSearch = true; | ||
parsedArguments->optionDisableRecursiveSearch = true; | ||
} else if (wcscmp(rawArguments[i], OPT_FORCEOVERWRITE_STRING) == 0) { | ||
parsedArguments.optionForceFileOverwrites = true; | ||
parsedArguments->optionForceFileOverwrites = true; | ||
} else if (wcsstr(rawArguments[i], OPT_MAKENEWFOLDER_STRING)) { | ||
parsedArguments.optionMakeNewFolder = true; | ||
parsedArguments->optionMakeNewFolder = true; | ||
|
||
char16_t *argumentBuffer = wcsdup(rawArguments[i]); // duplicate argument string for analysis | ||
char16_t *parserState; | ||
char16_t *token = wcstok_s(argumentBuffer, u"=", &parserState); | ||
|
||
/* If there's an '=' sign, pass the string after it to the foldername argument */ | ||
if ((token = wcstok_s(NULL, u"=", &parserState)) != NULL) { | ||
parsedArguments.optionCustomFolderName = true; | ||
wcscpy_s(parsedArguments.customFolderName, PATHBUF, token); | ||
parsedArguments->optionCustomFolderName = true; | ||
wcscpy_s(parsedArguments->customFolderName, PATHBUF, token); | ||
} | ||
|
||
free(argumentBuffer); | ||
} | ||
} | ||
|
||
return parsedArguments; | ||
return NO_ERROR; | ||
} |
Oops, something went wrong.