-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbricksyncinput.c
4042 lines (3564 loc) · 184 KB
/
bricksyncinput.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -----------------------------------------------------------------------------
*
* Copyright (c) 2014-2019 Alexis Naveros.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* -----------------------------------------------------------------------------
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "cpuconfig.h"
#include "cc.h"
#include "ccstr.h"
#include "mm.h"
#include "mmatomic.h"
#include "mmbitmap.h"
#include "iolog.h"
#include "debugtrack.h"
#include "cpuinfo.h"
#include "rand.h"
#if CC_UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#elif CC_WINDOWS
#include <windows.h>
#include <direct.h>
#else
#error Unknown/Unsupported platform!
#endif
#include "tcp.h"
#include "tcphttp.h"
#include "oauth.h"
#include "exclperm.h"
#include "journal.h"
#include "bsx.h"
#include "bsxpg.h"
#include "json.h"
#include "bsorder.h"
#include "bricklink.h"
#include "brickowl.h"
#include "colortable.h"
#include "bstranslation.h"
#include "bsevalgrade.h"
#include "bricksync.h"
////
#define BS_COMMAND_LOCATE_ITEM_PARAM_MAX (4)
static bsxItem *bsCmdLocateItem( bsContext *context, bsxInventory *inv, char *str )
{
int index, length, paramcount, paramflags;
int32_t colorid;
int64_t boid, lotid;
bsxItem *item;
char *strend;
char *params[BS_COMMAND_LOCATE_ITEM_PARAM_MAX+1];
char condition, separator;
if( !( str ) )
goto syntaxerror;
strend = ccStrEndWord( str );
if( !( strend ) )
goto syntaxerror;
*strend = 0;
length = (int)( strend - str );
params[0] = str;
paramcount = 1;
paramflags = 0x0;
/*
paramflags : 0x0 : BlLotID
paramflags : 0x1 : BOID-BoColor-Condition
paramflags : 0x2 : BL_ID:BlColor:Condition
paramflags : 0x4 : BoLotID
*/
for( index = 0 ; index < length ; index++ )
{
if( str[index] == '-' )
paramflags |= 0x1;
else if( str[index] == ':' )
paramflags |= 0x2;
else if( str[index] == '*' )
paramflags |= 0x4;
}
separator = 0;
if( paramflags & 0x2 )
{
paramflags = 0x2;
separator = ':';
}
else if( paramflags & 0x1 )
{
paramflags = 0x1;
separator = '-';
}
if( separator )
{
for( index = 0 ; index < length ; index++ )
{
if( str[index] == separator )
{
str[index] = 0;
params[ paramcount++ ] = &str[index+1];
}
if( paramcount >= (BS_COMMAND_LOCATE_ITEM_PARAM_MAX+1) )
goto syntaxerror;
}
}
#if 0
printf( "COMMAND: Item flags 0x%x\n", paramflags );
for( index = 0 ; index < paramcount ; index++ )
printf( "COMMAND: Item param %d : %s\n", index, params[index] );
#endif
if( paramflags == 0x0 )
{
if( !( ccStrParseInt64( params[0], &lotid ) ) )
goto syntaxerror;
item = bsxFindLotID( inv, lotid );
if( !( item ) )
ioPrintf( &context->output, 0, BSMSG_ERROR "No item found with BrickLink LotID " IO_RED CC_LLD IO_WHITE ".\n", (long long)lotid );
}
else if( ( paramflags == 0x1 ) || ( paramflags == 0x2 ) )
{
colorid = 0;
condition = 'N';
if( paramcount >= 2 )
{
if( !( ccStrParseInt32( params[1], &colorid ) ) )
goto syntaxerror;
}
if( paramcount == 3 )
{
if( params[2][1] != 0 )
goto syntaxerror;
if( ( params[2][0] == 'n' ) || ( params[2][0] == 'N' ) )
condition = 'N';
else if( ( params[2][0] == 'u' ) || ( params[2][0] == 'U' ) )
condition = 'U';
else
goto syntaxerror;
}
if( paramflags == 0x1 )
{
if( !( ccStrParseInt64( params[0], &boid ) ) )
goto syntaxerror;
item = bsxFindItemBOID( inv, boid, bsTranslateColorBo2Bl( colorid ), condition );
if( !( item ) )
ioPrintf( &context->output, 0, BSMSG_ERROR "No item found with BOID " IO_RED CC_LLD IO_WHITE ", BoColor " IO_RED "%d" IO_WHITE ", Condition " IO_RED "%c" IO_WHITE ".\n", (long long)boid, (int)colorid, condition );
}
else
{
item = bsxFindItemNoType( inv, params[0], colorid, condition );
if( !( item ) )
ioPrintf( &context->output, 0, BSMSG_ERROR "No item found with BLID " IO_RED "%s" IO_WHITE ", BlColor " IO_RED "%d" IO_WHITE ", Condition " IO_RED "%c" IO_WHITE ".\n", params[0], (int)colorid, condition );
}
}
else if( paramflags == 0x4 )
{
if( paramcount != 2 )
goto syntaxerror;
if( !( ccStrParseInt64( params[1], &lotid ) ) )
goto syntaxerror;
item = bsxFindOwlLotID( inv, lotid );
if( !( item ) )
ioPrintf( &context->output, 0, BSMSG_ERROR "No item found with BrickOwl LotID " IO_RED CC_LLD IO_WHITE ".\n", (long long)lotid );
}
else
goto syntaxerror;
return item;
syntaxerror:
ioPrintf( &context->output, 0, BSMSG_ERROR "Item identifier syntax error. Can be any of: BlLotID *BoLotID BL_ID:BlColor:Condition BOID-BoColor-Condition\n" );
return 0;
}
////
#define BS_PRINT_ITEM_BOLD_BLID (1<<0)
#define BS_PRINT_ITEM_BOLD_BOID (1<<1)
#define BS_PRINT_ITEM_BOLD_NAME (1<<2)
#define BS_PRINT_ITEM_BOLD_TYPENAME (1<<3)
#define BS_PRINT_ITEM_BOLD_TYPEID (1<<4)
#define BS_PRINT_ITEM_BOLD_COLORNAME (1<<5)
#define BS_PRINT_ITEM_BOLD_BLCOLORID (1<<6)
#define BS_PRINT_ITEM_BOLD_BOCOLORID (1<<7)
#define BS_PRINT_ITEM_BOLD_CATEGORYNAME (1<<8)
#define BS_PRINT_ITEM_BOLD_CATEGORYID (1<<9)
#define BS_PRINT_ITEM_BOLD_CONDITION (1<<10)
#define BS_PRINT_ITEM_BOLD_QUANTITY (1<<11)
#define BS_PRINT_ITEM_BOLD_PRICE (1<<12)
#define BS_PRINT_ITEM_BOLD_BULK (1<<13)
#define BS_PRINT_ITEM_BOLD_COMMENTS (1<<14)
#define BS_PRINT_ITEM_BOLD_REMARKS (1<<15)
#define BS_PRINT_ITEM_BOLD_BLLOTID (1<<16)
#define BS_PRINT_ITEM_BOLD_BOLOTID (1<<17)
static void bsCmdPrintItem( bsContext *context, bsxItem *item, uint32_t boldmask )
{
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BLID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BLID: %s\n", ( item->id ? item->id : "???" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BOID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BOID: "CC_LLD"\n", (long long)item->boid );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_NAME ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Name: \"%s\"\n", ( item->name ? item->name : "???" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_TYPENAME ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Type Name: \"%s\"\n", ( item->typename ? item->typename : "???" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_TYPEID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Type ID: \"%c\"\n", item->typeid );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_COLORNAME ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Color Name: \"%s\"\n", ( item->colorname ? item->colorname : "???" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BLCOLORID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BL Color ID: %d\n", item->colorid );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BOCOLORID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BO Color ID: %d\n", bsTranslateColorBl2Bo( item->colorid ) );
if( item->categoryname )
{
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_CATEGORYNAME ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Category: \"%s\"\n", ( item->categoryname ? item->categoryname : "???" ) );
}
if( item->categoryid )
{
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_CATEGORYID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Category ID: %d\n", item->categoryid );
}
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_CONDITION ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Condition: \"%s\"\n", ( item->condition == 'N' ? "New" : "Used" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_QUANTITY ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Quantity: %d\n", item->quantity );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_PRICE ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Price: %.3f\n", item->price );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BULK ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Bulk: %d\n", item->bulk );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_COMMENTS ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Comments: \"%s\"\n", ( item->comments ? item->comments : "" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_REMARKS ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "Remarks: \"%s\"\n", ( item->remarks ? item->remarks : "" ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BLLOTID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BL Lot ID: \""CC_LLD"\"\n", (long long)item->lotid );
ioPrintf( &context->output, IO_MODEBIT_NODATE, " %s", ( boldmask & BS_PRINT_ITEM_BOLD_BOLOTID ? IO_CYAN : IO_DEFAULT ) );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "BO Lot ID: \""CC_LLD"\"\n", (long long)item->bolotid );
return;
}
static int bsCmdFindNumericalArg( char *arg )
{
for( ; *arg ; arg++ )
{
if( ( ( *arg < '0' ) || ( *arg > '9' ) ) && ( *arg != '.' ) )
return 0;
}
return 1;
}
static void bsCmdInventoryModified( bsContext *context )
{
journalDef journal;
journalAlloc( &journal, 4 );
if( !( bsSaveInventory( context, &journal ) ) )
{
bsFatalError( context );
return;
}
context->stateflags |= BS_STATE_FLAGS_BRICKLINK_MUST_UPDATE | BS_STATE_FLAGS_BRICKOWL_MUST_UPDATE;
if( !( bsSaveState( context, &journal ) ) )
{
bsFatalError( context );
return;
}
if( !( journalExecute( BS_JOURNAL_FILE, BS_JOURNAL_TEMP_FILE, &context->output, journal.entryarray, journal.entrycount ) ) )
{
ioPrintf( &context->output, IO_MODEBIT_FLUSH, BSMSG_ERROR "Failed to execute journal!\n" );
bsFatalError( context );
return;
}
journalFree( &journal );
return;
}
////
#define BS_COMMAND_FIND_MAX (16)
typedef struct
{
int findcount;
int64_t findint[BS_COMMAND_FIND_MAX];
float findfloat[BS_COMMAND_FIND_MAX];
char *findstring[BS_COMMAND_FIND_MAX];
int activeitemindex;
} bsCmdFind;
static void bsCmdFindInit( bsCmdFind *cmdfind, int findcount, char **findterms )
{
int findindex;
if( findcount > BS_COMMAND_FIND_MAX )
findcount = BS_COMMAND_FIND_MAX;
for( findindex = 0 ; findindex < findcount ; findindex++ )
{
if( !( findterms[findindex] ) )
break;
cmdfind->findstring[findindex] = findterms[findindex];
cmdfind->findint[findindex] = -1;
cmdfind->findfloat[findindex] = -1.0;
if( bsCmdFindNumericalArg( findterms[findindex] ) )
{
if( !( ccStrParseInt64( cmdfind->findstring[findindex], &cmdfind->findint[findindex] ) ) )
cmdfind->findint[findindex] = -1;
if( !( ccStrParseFloat( cmdfind->findstring[findindex], &cmdfind->findfloat[findindex] ) ) )
cmdfind->findfloat[findindex] = -1.0;
}
}
cmdfind->findcount = findindex;
cmdfind->activeitemindex = 0;
return;
}
static void bsCmdFindReset( bsCmdFind *cmdfind )
{
cmdfind->activeitemindex = 0;
return;
}
static bsxItem *bsCmdFindInv( bsCmdFind *cmdfind, bsxInventory *inv, int *retmatchmask )
{
int itemindex, findindex, matchcount, matchmask, matchpartmask;
bsxItem *item;
itemindex = cmdfind->activeitemindex;
item = &inv->itemlist[ itemindex ];
for( ; itemindex < inv->itemcount ; itemindex++, item++ )
{
if( item->flags & BSX_ITEM_FLAGS_DELETED )
continue;
matchcount = 0;
matchmask = 0;
for( findindex = 0 ; findindex < cmdfind->findcount ; findindex++ )
{
matchpartmask = 0;
if( ccStrFindStr( item->id, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_BLID;
if( ccStrFindStr( item->name, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_NAME;
if( ccStrFindStr( item->typename, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_TYPENAME;
if( ccStrFindStr( item->colorname, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_COLORNAME;
if( ccStrFindStr( item->categoryname, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_CATEGORYNAME;
if( ccStrFindStr( item->comments, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_COMMENTS;
if( ccStrFindStr( item->remarks, cmdfind->findstring[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_REMARKS;
if( cmdfind->findint[findindex] >= 0 )
{
if( item->boid == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_BOID;
if( item->colorid == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_BLCOLORID;
if( bsTranslateColorBl2Bo( item->colorid ) == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_BOCOLORID;
if( item->quantity == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_QUANTITY;
if( item->lotid == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_BLLOTID;
if( item->bolotid == cmdfind->findint[findindex] )
matchpartmask |= BS_PRINT_ITEM_BOLD_BOLOTID;
}
if( ( cmdfind->findfloat[findindex] >= 0.0 ) && bsInvPriceEqual( item->price, cmdfind->findfloat[findindex] ) )
matchpartmask |= BS_PRINT_ITEM_BOLD_PRICE;
if( !( matchpartmask ) )
break;
matchmask |= matchpartmask;
matchcount++;
}
if( ( matchcount == cmdfind->findcount ) && ( matchmask ) )
{
cmdfind->activeitemindex = itemindex + 1;
if( retmatchmask )
*retmatchmask = matchmask;
return item;
}
}
return 0;
}
////
#define BS_COMMAND_ARGSTD_FLAG_FORCE (0x1)
#define BS_COMMAND_ARGSTD_FLAG_VERBOSE (0x2)
#define BS_COMMAND_ARGSTD_FLAG_SHORT (0x4)
#define BS_COMMAND_ARGSTD_FLAG_PRETEND (0x8)
static int bsCmdArgStdParse( bsContext *context, int argc, char **argv, int paramlistmin, int paramlistmax, char **retparamlist, int *retcmdflags, int optcmdflags )
{
int argindex, cmdflags, paramlistindex;
char *argstring;
paramlistindex = 0;
memset( retparamlist, 0, paramlistmax * sizeof(char *) );
cmdflags = 0x0;
for( argindex = 1 ; argindex < argc ; argindex++ )
{
argstring = argv[argindex];
if( argstring[0] == '-' )
{
if( ccStrCmpEqual( &argstring[1], "f" ) )
{
if( !( optcmdflags & BS_COMMAND_ARGSTD_FLAG_FORCE ) )
{
ioPrintf( &context->output, 0, BSMSG_ERROR "Invalid flag \"" IO_MAGENTA "-%c" IO_WHITE "\" for command.\n", (char)argstring[1] );
return 0;
}
cmdflags |= BS_COMMAND_ARGSTD_FLAG_FORCE;
}
else if( ccStrCmpEqual( &argstring[1], "v" ) )
{
if( !( optcmdflags & BS_COMMAND_ARGSTD_FLAG_VERBOSE ) )
{
ioPrintf( &context->output, 0, BSMSG_ERROR "Invalid flag \"" IO_MAGENTA "-%c" IO_WHITE "\" for command.\n", (char)argstring[1] );
return 0;
}
cmdflags |= BS_COMMAND_ARGSTD_FLAG_VERBOSE;
}
else if( ccStrCmpEqual( &argstring[1], "s" ) )
{
if( !( optcmdflags & BS_COMMAND_ARGSTD_FLAG_SHORT ) )
{
ioPrintf( &context->output, 0, BSMSG_ERROR "Invalid flag \"" IO_MAGENTA "-%c" IO_WHITE "\" for command.\n", (char)argstring[1] );
return 0;
}
cmdflags |= BS_COMMAND_ARGSTD_FLAG_SHORT;
}
else if( ccStrCmpEqual( &argstring[1], "p" ) )
{
if( !( optcmdflags & BS_COMMAND_ARGSTD_FLAG_PRETEND ) )
{
ioPrintf( &context->output, 0, BSMSG_ERROR "Invalid flag \"" IO_MAGENTA "-%c" IO_WHITE "\" for command.\n", (char)argstring[1] );
return 0;
}
cmdflags |= BS_COMMAND_ARGSTD_FLAG_PRETEND;
}
}
else
{
if( paramlistindex >= paramlistmax )
{
if( paramlistmax >= 2 )
ioPrintf( &context->output, 0, BSMSG_ERROR "Command only allows %d parameters, you have an extra parameter \"" IO_MAGENTA "%s" IO_WHITE "\".\n", paramlistmax, argstring );
else if( paramlistmax >= 1 )
ioPrintf( &context->output, 0, BSMSG_ERROR "Command only allows one parameter, you specified both \"" IO_MAGENTA "%s" IO_WHITE "\" and \"" IO_MAGENTA "%s" IO_WHITE "\".\n", retparamlist[0], argstring );
else
ioPrintf( &context->output, 0, BSMSG_ERROR "Command does not allow a parameter \"" IO_MAGENTA "" IO_WHITE "\n", argstring );
return 0;
}
retparamlist[ paramlistindex ] = argstring;
paramlistindex++;
}
}
if( paramlistindex < paramlistmin )
{
if( paramlistmin >= 2 )
ioPrintf( &context->output, 0, BSMSG_ERROR "Command requires %d parameters.\n", paramlistmin );
else
ioPrintf( &context->output, 0, BSMSG_ERROR "Command requires a parameter.\n" );
return 0;
}
if( retcmdflags )
*retcmdflags = cmdflags;
return 1;
}
////
static void bsPrintCheckSyncTimes( bsContext *context )
{
time_t lasttime;
struct tm timeinfo;
char timebuf[64];
ccGrowth growth;
lasttime = context->bricklink.lastchecktime;
if( lasttime )
{
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->curtime - (int64_t)lasttime, 4 );
timeinfo = *( localtime( &lasttime ) );
strftime( timebuf, 64, "%Y-%m-%d %H:%M:%S", &timeinfo );
ioPrintf( &context->output, 0, BSMSG_INFO "Time of last BrickLink order check : " IO_CYAN "%s" IO_DEFAULT " (%s ago).\n", timebuf, growth.data );
ccGrowthFree( &growth );
}
lasttime = context->brickowl.lastchecktime;
if( lasttime )
{
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->curtime - (int64_t)lasttime, 4 );
timeinfo = *( localtime( &lasttime ) );
strftime( timebuf, 64, "%Y-%m-%d %H:%M:%S", &timeinfo );
ioPrintf( &context->output, 0, BSMSG_INFO "Time of last BrickOwl order check : " IO_CYAN "%s" IO_DEFAULT " (%s ago).\n", timebuf, growth.data );
ccGrowthFree( &growth );
}
lasttime = context->bricklink.lastsynctime;
if( lasttime )
{
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->curtime - (int64_t)lasttime, 4 );
timeinfo = *( localtime( &lasttime ) );
strftime( timebuf, 64, "%Y-%m-%d %H:%M:%S", &timeinfo );
ioPrintf( &context->output, 0, BSMSG_INFO "Time of last BrickLink deep sync : " IO_CYAN "%s" IO_DEFAULT " (%s ago).\n", timebuf, growth.data );
ccGrowthFree( &growth );
}
lasttime = context->brickowl.lastsynctime;
if( lasttime )
{
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->curtime - (int64_t)lasttime, 4 );
timeinfo = *( localtime( &lasttime ) );
strftime( timebuf, 64, "%Y-%m-%d %H:%M:%S", &timeinfo );
ioPrintf( &context->output, 0, BSMSG_INFO "Time of last BrickOwl deep sync : " IO_CYAN "%s" IO_DEFAULT " (%s ago).\n", timebuf, growth.data );
ccGrowthFree( &growth );
}
return;
}
////
#define BS_LOADINV_VERIFYFLAGS_PRICES (0x1)
#define BS_LOADINV_VERIFYFLAGS_REMARKS (0x2)
static int bsLoadVerifyInventory( bsContext *context, bsxInventory *inv, int verifyflags )
{
int warningcount, itemindex;
bsxItem *item, *stockitem;
bsxInventory *stockinv;
stockinv = context->inventory;
warningcount = 0;
for( itemindex = 0 ; itemindex < inv->itemcount ; itemindex++ )
{
item = &inv->itemlist[itemindex];
if( item->flags & BSX_ITEM_FLAGS_DELETED )
continue;
stockitem = 0;
if( item->bolotid >= 0 )
stockitem = bsxFindOwlLotID( stockinv, item->bolotid );
if( item->lotid >= 0 )
stockitem = bsxFindLotID( stockinv, item->lotid );
if( !( stockitem ) || !( ccStrCmpEqualTest( item->id, stockitem->id ) ) || ( item->typeid != stockitem->typeid ) || ( item->colorid != stockitem->colorid ) || ( item->condition != stockitem->condition ) )
{
if( ( item->bolotid >= 0 ) || ( item->lotid >= 0 ) )
ioPrintf( &context->output, IO_MODEBIT_LOGONLY | IO_MODEBIT_FLUSH, "LOG: Mismatch for item with LotID " CC_LLD " and OwlLotID " CC_LLD ", dropping item's Lot ID references.\n", item->lotid, item->bolotid );
item->lotid = -1;
item->bolotid = -1;
}
if( ( verifyflags & BS_LOADINV_VERIFYFLAGS_PRICES ) && ( item->price <= 0.0005 ) )
{
ioPrintf( &context->output, 0, BSMSG_WARNING "Lot has price of zero : \"" IO_CYAN "%s" IO_WHITE "\" (" IO_GREEN "%s" IO_WHITE ") in \"" IO_CYAN "%s" IO_WHITE "\" and \"" IO_CYAN "%s" IO_WHITE "\", with quantity of " IO_GREEN "%d" IO_WHITE ".\n", ( item->name ? item->name : "???" ), ( item->id ? item->id : "???" ), ( item->colorname ? item->colorname : "???" ), ( item->condition == 'N' ? "New" : "Used" ), (int)item->quantity );
item->price = 0.01;
warningcount++;
}
if( ( verifyflags & BS_LOADINV_VERIFYFLAGS_REMARKS ) && !( item->remarks ) )
{
ioPrintf( &context->output, 0, BSMSG_WARNING "Lot has no remarks : \"" IO_CYAN "%s" IO_WHITE "\" (" IO_GREEN "%s" IO_WHITE ") in \"" IO_CYAN "%s" IO_WHITE "\" and \"" IO_CYAN "%s" IO_WHITE "\", with quantity of " IO_GREEN "%d" IO_WHITE ".\n", ( item->name ? item->name : "???" ), ( item->id ? item->id : "???" ), ( item->colorname ? item->colorname : "???" ), ( item->condition == 'N' ? "New" : "Used" ), (int)item->quantity );
warningcount++;
}
}
return warningcount;
}
////
static char bsFindItemTypeFromInvBLID( bsxInventory *inv, char *blid )
{
int itemindex, typeidindex, matchpriority;
static const char typeidlist[] = { 'P', 'M', 'S', 'G', 'I', 'O', '#', 0 };
char matchitemtypeid;
bsxItem *item;
matchitemtypeid = 0;
matchpriority = 255;
for( itemindex = 0 ; itemindex < inv->itemcount ; itemindex++ )
{
item = &inv->itemlist[itemindex];
if( item->flags & BSX_ITEM_FLAGS_DELETED )
continue;
if( ccStrCmpEqual( item->id, blid ) )
{
for( typeidindex = 0 ; typeidlist[ typeidindex ] ; typeidindex++ )
{
if( item->typeid == typeidlist[ typeidindex ] )
break;
}
if( typeidindex < matchpriority )
{
matchitemtypeid = item->typeid;
matchpriority = typeidindex;
}
}
}
return matchitemtypeid;
}
////
static void bsPrintCpuInfo( bsContext *context, cpuInfo *cpu )
{
switch( cpu->arch )
{
case CPUINFO_ARCH_AMD64:
ioPrintf( &context->output, 0, BSMSG_INFO "Arch : x86-64/AMD64\n" );
break;
case CPUINFO_ARCH_IA32:
ioPrintf( &context->output, 0, BSMSG_INFO "Arch : x86/IA32\n" );
break;
case CPUINFO_ARCH_UNKNOWN:
default:
break;
}
if( cpu->vendorstring[0] )
ioPrintf( &context->output, 0, BSMSG_INFO "Vendor : %s\n", cpu->vendorstring );
if( cpu->identifier[0] )
ioPrintf( &context->output, 0, BSMSG_INFO "Identifier : %s\n", cpu->identifier );
if( cpu->family )
ioPrintf( &context->output, 0, BSMSG_INFO "Family : %d\n", cpu->family );
if( cpu->model )
ioPrintf( &context->output, 0, BSMSG_INFO "Model : %d\n", cpu->model );
if( cpu->cacheline )
ioPrintf( &context->output, 0, BSMSG_INFO "Cache Line Size : %d bytes\n", cpu->cacheline );
if( ( cpu->capclflush ) &&( cpu->clflushsize ) )
ioPrintf( &context->output, 0, BSMSG_INFO "Cache Flush Size : %d bytes\n", cpu->clflushsize );
ioPrintf( &context->output, 0, BSMSG_INFO "Processor Layout\n" );
if( cpu->socketlogicalcores )
ioPrintf( &context->output, 0, BSMSG_INFO " Socket Logical Cores : %d\n", cpu->socketlogicalcores );
if( cpu->socketphysicalcores )
ioPrintf( &context->output, 0, BSMSG_INFO " Socket Physical Cores : %d\n", cpu->socketphysicalcores );
if( cpu->socketcount )
ioPrintf( &context->output, 0, BSMSG_INFO " Socket Count : %d\n", cpu->socketcount );
if( cpu->totalcorecount )
ioPrintf( &context->output, 0, BSMSG_INFO " Total Cores Count : %d\n", cpu->totalcorecount );
if( cpu->wordsize )
ioPrintf( &context->output, 0, BSMSG_INFO "Word Size : %d bits\n", cpu->wordsize );
if( cpu->sysmemory )
ioPrintf( &context->output, 0, BSMSG_INFO "User-Space Memory : "CC_LLD" bytes ( %.2fMb )\n", (long long)cpu->sysmemory, (double)cpu->sysmemory / 1048576.0 );
ioPrintf( &context->output, 0, BSMSG_INFO "Capabilities :" );
if( cpu->capcmov )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " CMOV" );
if( cpu->capclflush )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " CLFLUSH" );
if( cpu->captsc )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " TSC" );
if( cpu->capmmx )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " MMX" );
if( cpu->capmmxext )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " MMXEXT" );
if( cpu->cap3dnow )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " 3DNow" );
if( cpu->cap3dnowext )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " 3DNowExt" );
if( cpu->capsse )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE" );
if( cpu->capsse2 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE2" );
if( cpu->capsse3 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE3" );
if( cpu->capssse3 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSSE3" );
if( cpu->capsse4p1 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE4.1" );
if( cpu->capsse4p2 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE4.2" );
if( cpu->capsse4a )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SSE4A" );
if( cpu->capavx )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX" );
if( cpu->capavx2 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX2" );
if( cpu->capxop )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " XOP" );
if( cpu->capfma3 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " FMA3" );
if( cpu->capfma4 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " FMA4" );
if( cpu->capmisalignsse )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " MisalignSSE" );
if( cpu->capavx512f )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512F" );
if( cpu->capavx512dq )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512DQ" );
if( cpu->capavx512pf )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512PF" );
if( cpu->capavx512er )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512ER" );
if( cpu->capavx512cd )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512CD" );
if( cpu->capavx512bw )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512BW" );
if( cpu->capavx512vl )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AVX512VL" );
if( cpu->capaes )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " AES" );
if( cpu->capsha )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " SHA" );
if( cpu->cappclmul )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " PCLMUL" );
if( cpu->caprdrnd )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " RDRND" );
if( cpu->caprdseed )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " RDSEED" );
if( cpu->capcmpxchg16b )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " CMPXCHG16B" );
if( cpu->cappopcnt )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " POPCNT" );
if( cpu->caplzcnt )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " LZCNT" );
if( cpu->capmovbe )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " MOVBE" );
if( cpu->caprdtscp )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " RDTSCP" );
if( cpu->capconstanttsc )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " ConstantTSC" );
if( cpu->capf16c )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " F16C" );
if( cpu->capbmi )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " BMI" );
if( cpu->capbmi2 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " BMI2" );
if( cpu->capbmi2 )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " TBM" );
if( cpu->capadx )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " ADX" );
if( cpu->caphyperthreading )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " HyperThreading" );
if( cpu->capmwait )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " MWAIT" );
if( cpu->caplongmode )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " LongMode" );
if( cpu->capthermalsensor )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " ThermalSensor" );
if( cpu->capclockmodulation )
ioPrintf( &context->output, IO_MODEBIT_NODATE, " ClockModulation" );
ioPrintf( &context->output, IO_MODEBIT_NODATE, "\n" );
if( ( cpu->cachesizeL1code > 0 ) && ( cpu->cachesizeL1data > 0 ) && ( cpu->cacheunifiedL1 ) )
{
ioPrintf( &context->output, 0, BSMSG_INFO "L1 Unified Cache Memory\n" );
ioPrintf( &context->output, 0, BSMSG_INFO " Cache Size : %d kb\n", cpu->cachesizeL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Line Size : %d bytes\n", cpu->cachelineL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Associativity : %d way(s)\n", cpu->cacheassociativityL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Shared : %d core(s)\n", cpu->cachesharedL1code );
}
else
{
if( cpu->cachesizeL1code > 0 )
{
ioPrintf( &context->output, 0, BSMSG_INFO "L1 Code Cache Memory\n" );
ioPrintf( &context->output, 0, BSMSG_INFO " Cache Size : %d kb\n", cpu->cachesizeL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Line Size : %d bytes\n", cpu->cachelineL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Associativity : %d way(s)\n", cpu->cacheassociativityL1code );
ioPrintf( &context->output, 0, BSMSG_INFO " Shared : %d core(s)\n", cpu->cachesharedL1code );
}
if( cpu->cachesizeL1data > 0 )
{
ioPrintf( &context->output, 0, BSMSG_INFO "L1 Data Cache Memory\n" );
ioPrintf( &context->output, 0, BSMSG_INFO " Cache Size : %d kb\n", cpu->cachesizeL1data );
ioPrintf( &context->output, 0, BSMSG_INFO " Line Size : %d bytes\n", cpu->cachelineL1data );
ioPrintf( &context->output, 0, BSMSG_INFO " Associativity : %d way(s)\n", cpu->cacheassociativityL1data );
ioPrintf( &context->output, 0, BSMSG_INFO " Shared : %d core(s)\n", cpu->cachesharedL1data );
}
}
if( cpu->cachesizeL2 > 0 )
{
ioPrintf( &context->output, 0, BSMSG_INFO "L2 Cache Memory\n" );
ioPrintf( &context->output, 0, BSMSG_INFO " Cache Size : %d kb\n", cpu->cachesizeL2 );
ioPrintf( &context->output, 0, BSMSG_INFO " Line Size : %d bytes\n", cpu->cachelineL2 );
ioPrintf( &context->output, 0, BSMSG_INFO " Associativity : %d way(s)\n", cpu->cacheassociativityL2 );
ioPrintf( &context->output, 0, BSMSG_INFO " Shared : %d core(s)\n", cpu->cachesharedL2 );
}
if( cpu->cachesizeL3 > 0 )
{
ioPrintf( &context->output, 0, BSMSG_INFO "L3 Cache Memory\n" );
ioPrintf( &context->output, 0, BSMSG_INFO " Cache Size : %d kb\n", cpu->cachesizeL3 );
ioPrintf( &context->output, 0, BSMSG_INFO " Line Size : %d bytes\n", cpu->cachelineL3 );
ioPrintf( &context->output, 0, BSMSG_INFO " Associativity : %d way(s)\n", cpu->cacheassociativityL3 );
ioPrintf( &context->output, 0, BSMSG_INFO " Shared : %d core(s)\n", cpu->cachesharedL3 );
}
return;
}
static void bsPrintHelpItemCommand( bsContext *context, char *command, char *suffix )
{
if( !( suffix ) )
suffix = "";
ioPrintf( &context->output, 0, BSMSG_INFO "The item identifier can be " IO_GREEN "BLLotID" IO_DEFAULT ", example: " IO_GREEN "%s 55985466 %s" IO_DEFAULT "\n", command, suffix );
ioPrintf( &context->output, 0, BSMSG_INFO "The item identifier can be " IO_GREEN "*BOLotID" IO_DEFAULT ", example: " IO_GREEN "%s *2727357 %s" IO_DEFAULT "\n", command, suffix );
ioPrintf( &context->output, 0, BSMSG_INFO "The item identifier can be " IO_GREEN "BLID:BLColor:Condition" IO_DEFAULT ", example: " IO_GREEN "%s 3001:11:N %s" IO_DEFAULT "\n", command, suffix );
ioPrintf( &context->output, 0, BSMSG_INFO "The item identifier can be " IO_GREEN "BOID-BOColor-Condition" IO_DEFAULT ", example: " IO_GREEN "%s 771344-38-N %s" IO_DEFAULT "\n", command, suffix );
ioPrintf( &context->output, 0, BSMSG_INFO "When applicable, the condition parameter (" IO_GREEN "N" IO_DEFAULT " or " IO_GREEN "U" IO_DEFAULT ") is optional, it is assumed " IO_GREEN "N" IO_DEFAULT " if ommited.\n", command, suffix );
ioPrintf( &context->output, 0, BSMSG_INFO "If multiple items match (duplicate lots), only the first item found is displayed. See the " IO_CYAN "find" IO_DEFAULT " command to list all matches.\n", command, suffix );
return;
}
////
static char BS_STARTUP_TIME[64];
void bsSetStartupTime() {
time_t t = time(NULL);
struct tm *tm = localtime(&t);
size_t ret = strftime(BS_STARTUP_TIME, sizeof(BS_STARTUP_TIME), "%Y-%m-%d %H:%M:%S", tm);
assert(ret);
}
void bsCommandStatus( bsContext *context, int argc, char **argv )
{
int cmdflags;
int64_t freediskspace;
bsxInventory *inv, *deltainv;
ccGrowth growth;
char *colorstring;
float apihistoryratio;
if( !( bsCmdArgStdParse( context, argc, argv, 0, 0, 0, &cmdflags, BS_COMMAND_ARGSTD_FLAG_SHORT ) ) )
{
ioPrintf( &context->output, 0, BSMSG_ERROR "Usage is \"" IO_CYAN "status [-s]" IO_WHITE "\"" IO_DEFAULT ".\n" );
return;
}
inv = context->inventory;
bsxRecomputeTotals( inv );
if( !( cmdflags & BS_COMMAND_ARGSTD_FLAG_SHORT ) )
ioPrintf( &context->output, 0, BSMSG_INFO "BrickSync Status Report.\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "Software version : " IO_GREEN "%s" IO_DEFAULT " - " IO_GREEN "%s %s" IO_DEFAULT ".\n", BS_VERSION_STRING, __DATE__, __TIME__ );
ioPrintf( &context->output, 0, BSMSG_INFO "Software launch time : " IO_CYAN "%s" IO_DEFAULT ".\n", BS_STARTUP_TIME);
if( ( context->storename ) && ( context->username ) )
ioPrintf( &context->output, 0, BSMSG_INFO "Store name : " IO_GREEN "%s" IO_DEFAULT " by " IO_GREEN "%s" IO_DEFAULT ".\n", context->storename, context->username );
else if( context->storename )
ioPrintf( &context->output, 0, BSMSG_INFO "Store name : " IO_GREEN "%s" IO_DEFAULT ".\n", context->storename );
ioPrintf( &context->output, 0, BSMSG_INFO "Tracked inventory : " IO_GREEN "%d" IO_DEFAULT " items in " IO_GREEN "%d" IO_DEFAULT " lots.\n", inv->partcount, inv->itemcount - inv->itemfreecount );
ioPrintf( &context->output, 0, BSMSG_INFO "Inventory sale price : " IO_GREEN "%.2f" IO_DEFAULT " %s.\n", inv->totalprice, context->storecurrency );
#if BS_ENABLE_REGISTRATION
ioPrintf( &context->output, 0, BSMSG_INFO "BrickSync registration status : %s.\n", ( context->contextflags & BS_CONTEXT_FLAGS_REGISTERED ? IO_GREEN "Registered" IO_DEFAULT : IO_YELLOW "Unregistered" IO_DEFAULT ) );
#endif
ioPrintf( &context->output, 0, BSMSG_INFO "Autocheck mode is currently : %s.\n", ( context->contextflags & BS_CONTEXT_FLAGS_AUTOCHECK_MODE ? IO_GREEN "Enabled" IO_DEFAULT : IO_YELLOW "Disabled" IO_DEFAULT ) );
if( context->stateflags & BS_STATE_FLAGS_BRICKLINK_MASTER_MODE )
ioPrintf( &context->output, 0, BSMSG_INFO "The " IO_MAGENTA "BrickLink Master Mode" IO_DEFAULT " is currently " IO_YELLOW "enabled" IO_DEFAULT ". All synchronization is suspended.\n" );
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->bricklink.pollinterval, 4 );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink polling interval : " IO_GREEN "%s" IO_DEFAULT ".\n", growth.data );
ccGrowthFree( &growth );
ccGrowthInit( &growth, 512 );
ccGrowthElapsedTimeString( &growth, (int64_t)context->bricklink.pollinterval, 4 );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl polling interval : " IO_GREEN "%s" IO_DEFAULT ".\n", growth.data );
ccGrowthFree( &growth );
bsPrintCheckSyncTimes( context );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink has pending updates : %s.\n", ( context->stateflags & BS_STATE_FLAGS_BRICKLINK_MUST_UPDATE ? IO_RED "True" IO_DEFAULT : IO_GREEN "False" IO_DEFAULT ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl has pending updates : %s.\n", ( context->stateflags & BS_STATE_FLAGS_BRICKOWL_MUST_UPDATE ? IO_RED "True" IO_DEFAULT : IO_GREEN "False" IO_DEFAULT ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink in sync : %s.\n", ( context->stateflags & BS_STATE_FLAGS_BRICKLINK_MUST_SYNC ? IO_RED "False" IO_DEFAULT : IO_GREEN "True" IO_DEFAULT ) );
if( ( context->stateflags & BS_STATE_FLAGS_BRICKLINK_MUST_SYNC ) && ( context->bricklink.synctime > context->curtime ) )
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink will attempt SYNC again in " IO_GREEN "%d" IO_DEFAULT " seconds.\n", (int)( context->bricklink.synctime - context->curtime ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl in sync : %s.\n", ( context->stateflags & BS_STATE_FLAGS_BRICKOWL_MUST_SYNC ? IO_RED "False" IO_DEFAULT : IO_GREEN "True" IO_DEFAULT ) );
if( ( context->stateflags & BS_STATE_FLAGS_BRICKOWL_MUST_SYNC ) && ( context->brickowl.synctime > context->curtime ) )
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl will attempt SYNC again in " IO_GREEN "%d" IO_DEFAULT " seconds.\n", (int)( context->brickowl.synctime - context->curtime ) );
if( !( cmdflags & BS_COMMAND_ARGSTD_FLAG_SHORT ) )
{
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink API connection status : %s.\n", ( httpGetStatus( context->bricklink.http ) ? IO_GREEN "Keep-alive, waiting" IO_DEFAULT : IO_GREEN "Closed" IO_DEFAULT ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink WEB connection status : %s.\n", ( httpGetStatus( context->bricklink.webhttp ) ? IO_GREEN "Keep-alive, waiting" IO_DEFAULT : IO_GREEN "Closed" IO_DEFAULT ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl API connection status : %s.\n", ( httpGetStatus( context->brickowl.http ) ? IO_GREEN "Keep-alive, waiting" IO_DEFAULT : IO_GREEN "Closed" IO_DEFAULT ) );
}
apihistoryratio = (float)context->bricklink.apihistory.total / (float)context->bricklink.apicountlimit;
if( apihistoryratio > 0.75 )
colorstring = IO_RED;
else if( apihistoryratio > 0.50 )
colorstring = IO_YELLOW;
else
colorstring = IO_GREEN;
ioPrintf( &context->output, 0, BSMSG_INFO "BrickLink API usage : " "%s" "%d" IO_DEFAULT " (" "%s" "%.2f%%" IO_DEFAULT ") in the past 24 hours; " "%s" "%d" IO_DEFAULT " in the past hour.\n", colorstring, (int)context->bricklink.apihistory.total, colorstring, 100.0 * apihistoryratio, colorstring, bsApiHistoryCountPeriod( &context->bricklink.apihistory, 3600 ) );
ioPrintf( &context->output, 0, BSMSG_INFO "BrickOwl API usage : " IO_GREEN "%d" IO_DEFAULT " in the past 24 hours; " IO_GREEN "%d" IO_DEFAULT " in the past hour.\n", (int)context->brickowl.apihistory.total, bsApiHistoryCountPeriod( &context->brickowl.apihistory, 3600 ) );
freediskspace = ccGetFreeDiskSpace( BS_BACKUP_DIR );
if( freediskspace >= 0 )
{
if( freediskspace < ( 2 * BS_DISK_SPACE_CRITICAL ) )
colorstring = IO_RED;
else if( freediskspace < ( 2 * BS_DISK_SPACE_WARNING ) )
colorstring = IO_YELLOW;
else
colorstring = IO_GREEN;
ioPrintf( &context->output, 0, BSMSG_INFO "Available disk space : %s" CC_LLD " MB" IO_DEFAULT ".\n", colorstring, (long long)( freediskspace / 1048576 ) );
}
return;
}
static void bsCommandHelp( bsContext *context, int argc, char **argv )
{
char *sysname, *pgcacheformat;
cpuInfo cpuinfo;
ccGrowth growth;
if( argc <= 1 )
{
ioPrintf( &context->output, 0, BSMSG_INFO IO_GREEN "BrickSync Help.\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "Type \"" IO_GREEN "help " IO_CYAN "[command]" IO_DEFAULT "\" for help on a specific command.\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "Type \"" IO_GREEN "help " IO_CYAN "[topic]" IO_DEFAULT "\" for help on a specific topic.\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "General commands:\n" IO_DEFAULT );
//ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "status help check sync verify autocheck about message runfile backup quit prunebackups resetapihistory" IO_DEFAULT "\n" );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "status help check sync verify autocheck about runfile backup quit prunebackups resetapihistory" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Inventory management commands:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "sort blmaster add sub loadprices loadnotes loadmycost loadall merge invblxml invmycost setallremarksfromblid" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Item management commands:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "find item listempty setquantity setprice setcomments setremarks setblid delete owlresolve consolidate regradeused" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Evaluation commands:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "evalset evalgear evalpartout evalinv checkprices" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Order commands:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "findorder findordertime saveorderlist" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Catalog commands:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "owlqueryblid owlsubmitblid owlupdateblid owlforceblid owlsubmitdims owlsubmitweight" IO_DEFAULT "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO "\n" );
ioPrintf( &context->output, 0, BSMSG_INFO IO_WHITE "Help topics:\n" IO_DEFAULT );
ioPrintf( &context->output, IO_MODEBIT_NODATE, BSMSG_INFO IO_CYAN "paths sysinfo conf\n" );
return;
}
if( ccStrLowCmpWord( argv[1], "status" ) )
ioPrintf( &context->output, 0, BSMSG_INFO "Print general information about BrickSync's current status.\n" );
else if( ccStrLowCmpWord( argv[1], "help" ) )
ioPrintf( &context->output, 0, BSMSG_INFO "Print the list of commands.\n" );