Skip to content

Commit

Permalink
Update string functions and syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tmatijevich committed Oct 22, 2022
1 parent d3f5fd4 commit d3bb47b
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions BuildVer/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,49 @@
#include <stdint.h>
#include <stdbool.h>

static void stringCopy(char *destination, char *source, uint32_t size);
static void stringConcat(char *destination, char *source, uint32_t size);
static void stringCopy(char *destination, uint32_t size, char *source);
static void stringConcat(char *destination, uint32_t size, char *source);

ArEventLogGetIdent_typ getLogIdent;
ArEventLogWrite_typ writeToLog;
char message[121];

/* Program initialization */
void _INIT ProgramInit(void) {
stringCopy(getLogIdent.Name, "$arlogusr", sizeof(getLogIdent.Name));
void _INIT ProgramInit(void)
{
stringCopy(getLogIdent.Name, sizeof(getLogIdent.Name), "$arlogusr");
getLogIdent.Execute = true;
do {
do
{
ArEventLogGetIdent(&getLogIdent);
} while(!getLogIdent.Done && !getLogIdent.Error);
}
while (!getLogIdent.Done && !getLogIdent.Error);

writeToLog.Ident = getLogIdent.Ident;
stringCopy(message, "Project BuildVersion=", sizeof(message));
stringConcat(message, BuildVersion.Git.Version, sizeof(message));
stringConcat(message, " Branch=", sizeof(message));
stringConcat(message, BuildVersion.Git.Branch, sizeof(message));
if(BuildVersion.Git.ChangeWarning) {
stringCopy(message, sizeof(message), "Project BuildVersion=");
stringConcat(message, sizeof(message), BuildVersion.Git.Version);
stringConcat(message, sizeof(message), " Branch=");
stringConcat(message, sizeof(message), BuildVersion.Git.Branch);
if (BuildVersion.Git.ChangeWarning)
{
writeToLog.EventID = ArEventLogMakeEventID(arEVENTLOG_SEVERITY_WARNING, 10, 100);
stringConcat(message, " Changes=TRUE", sizeof(message));
stringConcat(message, sizeof(message), " Changes=TRUE");
}
else {
else
{
writeToLog.EventID = ArEventLogMakeEventID(arEVENTLOG_SEVERITY_INFO, 10, 100);
stringConcat(message, " Changes=FALSE", sizeof(message));
stringConcat(message, sizeof(message), " Changes=FALSE");
}
writeToLog.AddDataFormat = arEVENTLOG_ADDFORMAT_TEXT;
writeToLog.AddDataSize = strlen(message) + 1;
writeToLog.AddData = (uint32_t)message;
stringCopy(writeToLog.ObjectID, "BuildVersion", sizeof(writeToLog.ObjectID));
stringCopy(writeToLog.ObjectID, sizeof(writeToLog.ObjectID), "BuildVersion");
writeToLog.Execute = true;
do {
do
{
ArEventLogWrite(&writeToLog);
} while(!writeToLog.Done && !writeToLog.Error);
}
while (!writeToLog.Done && !writeToLog.Error);

getLogIdent.Execute = false;
ArEventLogGetIdent(&getLogIdent);
Expand All @@ -53,22 +60,19 @@ void _INIT ProgramInit(void) {
}

/* Copies source to destination up to size (of destination) or source length */
void stringCopy(char *destination, char *source, uint32_t size)
void stringCopy(char *destination, uint32_t size, char *source)
{
uint32_t bytes_remaining = size - 1;
if (destination == NULL || source == NULL || size == 0) return;

while (bytes_remaining--)
{
if (*source == '\0') break;
/* Copy, decrement first for size - 1 characters remaining */
while (--size && *source != '\0')
*destination++ = *source++;
}

*destination = '\0';
}

/* Concatentate source to destination up to size (of destination) or source length */
void stringConcat(char *destination, char *source, uint32_t size)
void stringConcat(char *destination, uint32_t size, char *source)
{
if (destination == NULL || source == NULL || size == 0) return;
strncat(destination, source, size - 1);
Expand Down

0 comments on commit d3bb47b

Please sign in to comment.