9 #include "file_operations.h"
14 { .onNo = cli_onNoMatch,
15 .onFull = cli_onFullMatch,
16 .onBeginOutput = cli_onBeginOutput,
17 .onBetweenIndividualOutputs = cli_onBetweenIndividualOutputs,
18 .onEndOutput = cli_onEndOutput,
22 int matchCliFileWithLicenses(
MonkState* state,
const Licenses* licenses,
int argi,
char** argv) {
25 file.fileName = argv[argi];
26 if (!readTokensFromFile(file.fileName, &(file.tokens), DELIMITERS))
31 tokens_free(file.tokens);
36 int handleCliMode(
MonkState* state,
const Licenses* licenses,
int argc,
char** argv,
int fileOptInd) {
37 #ifdef MONK_MULTI_THREAD
42 MonkState* threadLocalState = &threadLocalStateStore;
44 #ifdef MONK_MULTI_THREAD
45 #pragma omp for schedule(dynamic)
47 for (
int fileId = fileOptInd; fileId < argc; fileId++) {
48 matchCliFileWithLicenses(threadLocalState, licenses, fileId, argv);
56 if (state->verbosity >= 1) {
57 printf(
"File %s contains license(s) No_license_found\n", file->fileName);
60 printf(
"{\"type\":\"no-match\"}");
67 printf(
"{\"type\":\"full\",\"license\":\"%s\",\"ref-pk\":%ld,\"matched\":\"%zu+%zu\"}",
69 matchInfo->text.start, matchInfo->text.length);
71 printf(
"found full match between \"%s\" and \"%s\" (rf_pk=%ld); matched: %zu+%zu\n",
73 matchInfo->text.start, matchInfo->text.length);
79 unsigned short rank = diffResult->percentual;
81 char * formattedMatchArray = formatMatchArray(diffResult->matchedInfo);
84 printf(
"{\"type\":\"diff\",\"license\":\"%s\",\"ref-pk\":%ld,\"rank\":%u,\"diffs\":\"%s\"}",
86 rank, formattedMatchArray);
88 printf(
"found diff match between \"%s\" and \"%s\" (rf_pk=%ld); rank %u; diffs: {%s}\n",
94 free(formattedMatchArray);
105 int cli_onBetweenIndividualOutputs(
MonkState* state) {
void matchFileWithLicenses(const string &sContent, unsigned long pFileId, CopyrightState const &state, int agentId, CopyrightDatabaseHandler &databaseHandler)
Scan a given file with all available scanners and save findings to database.