hmml_to_youtube.c: Deduplicate URLs [#9]

This commit is contained in:
Matt Mascarenhas 2017-05-05 08:18:58 +01:00
parent 7d600534cd
commit 3c628e3df7
1 changed files with 37 additions and 0 deletions

View File

@ -17,6 +17,12 @@ typedef unsigned int bool;
#define TRUE 1
#define FALSE 0
typedef struct
{
unsigned int UniqueRefs;
char RefID[1024][32];
} ref_info;
typedef struct
{
char *Location;
@ -111,6 +117,7 @@ main(int ArgC, char **Args)
return 1;
}
ref_info Refs = { 0 };
ClaimBuffer(MemoryArena, &ClaimedMemory, &Errors, 1024 * 32);
char OutFilename[StringLength(Args[FileIndex]) + 5];
@ -195,6 +202,35 @@ main(int ArgC, char **Args)
if(RefIndex < Anno->reference_count &&
InPtr - Anno->text == Anno->references[RefIndex].offset)
{
char *RefID;
if(Anno->references[RefIndex].isbn)
{
RefID = Anno->references[RefIndex].isbn;
}
else if(Anno->references[RefIndex].url)
{
RefID = Anno->references[RefIndex].url;
}
else
{
fprintf(stderr, "%s: Reference must contain an ISBN or URL\n", Args[FileIndex]);
hmml_free(&HMML);
free(MemoryArena);
return 1;
}
int i;
for(i = 0; i < Refs.UniqueRefs; ++i)
{
if(!StringsDiffer(Refs.RefID[i], RefID))
{
goto SkipRef;
}
}
sprintf(Refs.RefID[i], RefID);
++Refs.UniqueRefs;
if(Anno->references[RefIndex].offset == InOffset)
{
if(Out.Ptr[-1] != '"' && Out.Ptr[-1] != ' ')
@ -244,6 +280,7 @@ main(int ArgC, char **Args)
OutColumn += CopyStringToBuffer(&Out, "%s", Anno->references[RefIndex].url);
}
}
SkipRef:
++RefIndex;
}