Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bricksync.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ bsContext *bsInit( char *statepath, int *retstateloaded )
context->priceguideflags = BSX_PRICEGUIDE_FLAGS_BRICKSTOCK;
context->priceguidecachetime = BS_PRICEGUIDE_CACHETIME_DEFAULT;
context->retainemptylotsflag = 0;
context->syncsalerates = 0;
context->checkmessageflag = 0;
context->curtime = time( 0 );
context->messagetime = 0;
Expand Down
3 changes: 3 additions & 0 deletions bricksync.conf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ retainemptylots = 0;
// Set to non-zero to reuse existing and empty BrickOwl lots with matching external_id/LotIDs
brickowl.reuseempty = 0;

// Set to non-zero to sync sales rates from BrickLink to BrickOwl
syncsalerates = 0;

// Set to zero if you don't want to check for new versions of BrickSync or any broadcast message
checkmessage = 1;

Expand Down
1 change: 1 addition & 0 deletions bricksync.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ typedef struct

/* User options */
int retainemptylotsflag;
int syncsalerates;
int checkmessageflag;

#if BS_ENABLE_LIMITS
Expand Down
6 changes: 6 additions & 0 deletions bricksyncconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ static int bsConfParse( bsContext *context, bsConfParser *parser )
goto error;
context->retainemptylotsflag = (int)readint;
}
else if( ccStrMatchSeq( "syncsalerates", tokenstring, token->length ) )
{
if( !( bsConfReadInteger( context, parser, &readint ) ) )
goto error;
context->syncsalerates = (int)readint;
}
else if( ccStrMatchSeq( "checkmessage", tokenstring, token->length ) )
{
if( !( bsConfReadInteger( context, parser, &readint ) ) )
Expand Down
4 changes: 4 additions & 0 deletions bsapplydiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ static void bsBrickOwlApplyDiffUpdate( bsContext *context, bsxItem *item, int it
ccGrowthPrintf( &postgrowth, "&bulk_qty=%d", ( item->bulk > 0 ? item->bulk : 1 ) );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_MYCOST )
ccGrowthPrintf( &postgrowth, "&my_cost=%.3f", item->mycost );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT )
ccGrowthPrintf( &postgrowth, "&sale_percent=%d", item->sale );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_USEDGRADE )
{
conditionstring = 0;
Expand Down Expand Up @@ -881,6 +883,8 @@ static void bsBrickOwlApplyDiffUpdate( bsContext *context, bsxItem *item, int it
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "; Set bulk to %d", item->bulk );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_MYCOST )
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "; Set mycost to %.3f", item->mycost );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT )
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "; Set sale_percent to %d", item->sale );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_USEDGRADE )
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "; Set usedgrade to %c", item->usedgrade );
if( item->flags & BSX_ITEM_XFLAGS_UPDATE_TIERPRICES )
Expand Down
9 changes: 8 additions & 1 deletion bssync.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ void bsSyncAddDeltaItem( bsContext *context, bsxInventory *deltainv, bsxItem *st
updateflags |= BSX_ITEM_XFLAGS_UPDATE_TIERPRICES;
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "LOG: Set TierPrices from [[%d,%.3f],[%d,%.3f],[%d,%.3f]] to [[%d,%.3f],[%d,%.3f],[%d,%.3f]]%s\n", item->tq1, item->tp1, item->tq2, item->tp2, item->tq3, item->tp3, stockitem->tq1, stockitem->tp1, stockitem->tq2, stockitem->tp2, stockitem->tq3, stockitem->tp3, itemstringbuffer );
}
if ( ( deltamode == BS_SYNC_DELTA_MODE_BRICKOWL ) && ( stockitem->sale != item->sale ) && ( context->syncsalerates ) )
{
updateflags |= BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT;
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_NODATE, "LOG: Set Sale Percent from %d to %d%s\n", item->sale, stockitem->sale, itemstringbuffer );
}


/* TODO: Remove this once we made sure we are properly importing OwlLotIDs everywhere! */
Expand Down Expand Up @@ -241,6 +246,8 @@ void bsSyncAddDeltaItem( bsContext *context, bsxInventory *deltainv, bsxItem *st
deltaitem->boid = item->boid;
deltaitem->bolotid = item->bolotid;
deltaitem->quantity = stockitem->quantity - item->quantity;
if (updateflags & BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT)
deltaitem->sale = stockitem->sale;
deltaitem->flags |= BSX_ITEM_XFLAGS_TO_UPDATE | updateflags;
/* Increment counters */
if( deltaitem->quantity > 0 )
Expand All @@ -257,7 +264,7 @@ void bsSyncAddDeltaItem( bsContext *context, bsxInventory *deltainv, bsxItem *st
stats->match_lotcount++;

/* Track updatedata updates */
if( updateflags & ( BSX_ITEM_XFLAGS_UPDATE_PRICE | BSX_ITEM_XFLAGS_UPDATE_COMMENTS | BSX_ITEM_XFLAGS_UPDATE_REMARKS | BSX_ITEM_XFLAGS_UPDATE_BULK | BSX_ITEM_XFLAGS_UPDATE_MYCOST | BSX_ITEM_XFLAGS_UPDATE_USEDGRADE | BSX_ITEM_XFLAGS_UPDATE_TIERPRICES ) )
if( updateflags & ( BSX_ITEM_XFLAGS_UPDATE_PRICE | BSX_ITEM_XFLAGS_UPDATE_COMMENTS | BSX_ITEM_XFLAGS_UPDATE_REMARKS | BSX_ITEM_XFLAGS_UPDATE_BULK | BSX_ITEM_XFLAGS_UPDATE_MYCOST | BSX_ITEM_XFLAGS_UPDATE_USEDGRADE | BSX_ITEM_XFLAGS_UPDATE_TIERPRICES | BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT ) )
{
stats->updatedata_partcount += stockitem->quantity;
stats->updatedata_lotcount++;
Expand Down
8 changes: 6 additions & 2 deletions bsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2326,13 +2326,17 @@ void bsxSetItemColorName( bsxItem *item, char *colorname, int len )

void bsxSetItemComments( bsxItem *item, char *comments, int len )
{
bsxSetItemString( item, offsetof(bsxItem,comments), comments, len, BSX_ITEM_FLAGS_ALLOC_COMMENTS );
char *trimmed_comments = ccStrTrimWhitespace(comments);
bsxSetItemString( item, offsetof(bsxItem,comments), trimmed_comments, -1, BSX_ITEM_FLAGS_ALLOC_COMMENTS );
free(trimmed_comments);
return;
}

void bsxSetItemRemarks( bsxItem *item, char *remarks, int len )
{
bsxSetItemString( item, offsetof(bsxItem,remarks), remarks, len, BSX_ITEM_FLAGS_ALLOC_REMARKS );
char *trimmed_remarks = ccStrTrimWhitespace(remarks);
bsxSetItemString( item, offsetof(bsxItem,remarks), trimmed_remarks, -1, BSX_ITEM_FLAGS_ALLOC_REMARKS );
free(trimmed_remarks);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion bsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ typedef struct
#define BSX_ITEM_XFLAGS_UPDATE_USEDGRADE (0x800000)
#define BSX_ITEM_XFLAGS_UPDATE_TIERPRICES (0x1000000)
#define BSX_ITEM_XFLAGS_FETCH_PRICE_GUIDE (0x2000000)
#define BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT (0x4000000)

/* Mask of all update flags */
#define BSX_ITEM_XFLAGS_UPDATEMASK (BSX_ITEM_XFLAGS_UPDATE_QUANTITY|BSX_ITEM_XFLAGS_UPDATE_COMMENTS|BSX_ITEM_XFLAGS_UPDATE_REMARKS|BSX_ITEM_XFLAGS_UPDATE_PRICE|BSX_ITEM_XFLAGS_UPDATE_BULK|BSX_ITEM_XFLAGS_UPDATE_STOCKROOM|BSX_ITEM_XFLAGS_UPDATE_MYCOST|BSX_ITEM_XFLAGS_UPDATE_USEDGRADE|BSX_ITEM_XFLAGS_UPDATE_TIERPRICES)
#define BSX_ITEM_XFLAGS_UPDATEMASK (BSX_ITEM_XFLAGS_UPDATE_QUANTITY|BSX_ITEM_XFLAGS_UPDATE_COMMENTS|BSX_ITEM_XFLAGS_UPDATE_REMARKS|BSX_ITEM_XFLAGS_UPDATE_PRICE|BSX_ITEM_XFLAGS_UPDATE_BULK|BSX_ITEM_XFLAGS_UPDATE_STOCKROOM|BSX_ITEM_XFLAGS_UPDATE_MYCOST|BSX_ITEM_XFLAGS_UPDATE_USEDGRADE|BSX_ITEM_XFLAGS_UPDATE_TIERPRICES|BSX_ITEM_XFLAGS_UPDATE_SALE_PERCENT)

#define BSX_ITEM_STOCKFLAGS_RETAIN (0x1)
#define BSX_ITEM_STOCKFLAGS_STOCKROOM (0x2)
Expand Down
37 changes: 35 additions & 2 deletions ccstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,47 @@
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>

#include "cc.h"
#include "ccstr.h"


////

char *ccStrTrimWhitespace( char *str )
{
char *start = str;
char *end;
char *new_str;
size_t len;

if( str == NULL )
return NULL;

// Trim leading space
while( isspace( (unsigned char)*start ) )
start++;

if( *start == 0 ) // All spaces?
return ccStrDup( start );

// Trim trailing space
end = start + strlen(start) - 1;
while( end > start && isspace( (unsigned char)*end ) )
end--;

// Allocate and copy the trimmed string
len = (end - start) + 1;
new_str = (char *)malloc( len + 1 );
if( new_str == NULL )
return NULL; // Allocation failed

memcpy( new_str, start, len );
new_str[len] = 0;

return new_str;
}
#define CC_CHAR_IS_CONTROL(c) ((c)<' ')
#define CC_CHAR_IS_DELIMITER(c) ((c)<=' ')

Expand Down Expand Up @@ -800,9 +833,9 @@ char *ccStrDup( const char *str )
if( !( str ) )
return 0;
len = strlen( str );
if( !( len ) )
return 0;
newstr = malloc( ( len + 1 ) * sizeof(char) );
if( !newstr )
return 0;
memcpy( newstr, str, len + 1 );
return newstr;
}
Expand Down
1 change: 1 addition & 0 deletions ccstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ int ccSeqParseDouble( char *seq, int seqlength, double *retdouble );

int ccStrParseHex( char *str, int hexchars );

char *ccStrTrimWhitespace( char *str );

////

Expand Down