Skip to content

Commit

Permalink
working on internal moving and copyign utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 15, 2018
1 parent 863d8cb commit c256a93
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/DataUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef DATA_UTIL_H
#define DATA_UTIL_H

#include <string.h>
#include "WindType.h"

// This header handles utils to copy, move, and transport data from one unsigned char*
// to another

// Copies data from src to dest, until src End is reached.
int DataUtil_copy(unsigned char* dest,
const unsigned char* src,
const unsigned char* srcEnd);

#endif
1 change: 1 addition & 0 deletions src/flow/WindExec.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ int WindExec_save(void)
WindState_write_err("File path '%s' cannot be written to.", savePath);
return 0;
}
printf("saved @ %s\n", savePath);
return 1;
}
42 changes: 42 additions & 0 deletions src/util/DataUtil.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "DataUtil.h"

int DataUtil_copy(unsigned char* dest, const unsigned char* src, const unsigned char* srcEnd)
{
while(src != srcEnd)
{
switch(*src)
{
case WindType_Not:
case WindType_Sep:
case WindType_Assign:
case WindType_None:
case WindType_Del:
case WindType_Lt:
case WindType_Gt:
case WindType_Plus:
case WindType_Minus:
case WindType_Multiply:
case WindType_Divide:
*dest++ = *src++;
break;
case WindType_Bool:
*dest++ = *src++;
*dest++ = *src++;
break;
case WindType_Number:
WindComp_BUF[0] = *item++;
for(size_t ds = 1; ds < sizeof(double) + 1; ds++)
WindComp_BUF[ds] = *item++;
WindComp_ITEM_LEN = sizeof(unsigned char) + sizeof(double);
return WindComp_ITEM_LEN;
case WindType_String:
WindComp_BUF[0] = *item++;
WindComp_ITEM_LEN = *(unsigned*)(item) + sizeof(unsigned) + sizeof(unsigned char);
memcpy(WindComp_BODY, (unsigned char*)item, WindComp_ITEM_LEN);
return WindComp_ITEM_LEN;
default:
return 0;
}
}
return 1;
}

0 comments on commit c256a93

Please sign in to comment.