-
Notifications
You must be signed in to change notification settings - Fork 1
/
crealSimMain.c
2315 lines (1462 loc) · 96.1 KB
/
crealSimMain.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
/*
*
*
*
*
*
* #include <math.h>
double fmod(double x, double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
*
*
*
* */
#include <stdio.h> //standard library
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h> //for file descriptor stuff
/*This stuff below can actually go into the made binary */
/* This application is called Cerebro */
#include <pthread.h> // using posix threads only
#include <regex.h> //this is used for regular expression
#include <omp.h> //this is used for regular expression
#include <math.h> //this is the standard math library for figureing out math functions
/* This is the actual cool stuff right here */
#include <jansson.h> //this is jansson
#include "include/libcudacreal.h"
#include "include/struct_definitions.h" //struct definitions
/* These are function prototypes */
int abstractJsonData(json_t **root, FILE **fp); //this is used to print out the json data to a file or stdout
int returnNumberOfCrealNodes(json_t **root); //used to return the expression
int returnNumberOfCrealProperties(json_t **root); //returns the number of creal properties
int returnHighestCrealPropertyID(json_t **root); //returns the highest creal property id in the json data
int printOutStaticActionList(uint actionCount, uint conditionCount, FILE **stream ); //this is to print out the action list right here
int printOutStaticCrealNodes(uint actionListCount, uint propertiesCount, FILE **stream); //this function actually prints out the static creal node data
int printOutNodeActionAndPropArrays(uint crealNodeCount, uint actionListCount, uint propertiesCount, FILE **stream); //this function will output basic necissity
int printOutMaxPreprocessedValues(uint propMax, uint actListMax, uint actAndCondMax, uint nodeMax, FILE **stream); //this is used to print out the max values to be used inside of creal_ng
int returnNumberOfCoresOnSystem(void); //this function will return the amount of cores available on the system
int createPipeFile(const char *path); //this will create a pipe in a specified location
int writeOutActionConditionFunctions(json_t **root, FILE **fp); //this function is used to write out functions for actions and conditions, and assign them to function pointers
int writeOutActionConditionFunctionsPrototypes(json_t **root, FILE **fp); //this function writes out the prototypes for the functions in the simulator
int ctcpdCommunicationFunction(const char *inputFile, const char *outputFile, const char *inputString, char outputString[]); //this is the main function for communicating to ctcpd
int quitCtcpd(const char *inputFile, const char *outputFile); //this will make the ctcpd daemon exit
int readFromPipe(const char *path, char buffer[]); //read from a FIFO file (not really a pipe)
int writeToPipe(const char *path, const char *string); //write to a FIFO file (not really a pipe)
int printOutFromCTF(const char *path, FILE **fp); //this function will print out a ctf file and place it inside of the application
/* Global variables here, sometimes we don't want things declared in the stack */
char tempString[256]; //this is here to just make a path for our function in order to run our parse daemon
pid_t crealPid; //this is used to grab the pid of the process
pid_t pid, sid, cpid; // this is the pid for our daemon process redundant
int main(int argc, char **argv)
{
if (argc <= 2)
{
//nothing was entered to start the application correctly
quitWithError(USAGE); //shows application usage
}
if (!argv[1])
{
quitWithError("A path to the json file was not entered!\n"); //shows application usage
}
if (!argv[2])
{
quitWithError("An output file was not entered\n"); //shows application usage
}
FILE *outputFP = NULL; //this is to actually write the file
outputFP = fopen(argv[2],"w"); //open the file descriptor
if (outputFP < 0)
{
perror("Something happening trying to open output file descriptor\n"); //error
exit(EXIT_FAILURE); //exit with failure
}
/* The stuff below is used for grabing the amount of processors on the system */
const int numCPU = returnNumberOfCoresOnSystem(); //this is the number of cpus available for use
if (numCPU <= 0) { quitWithError("We didn't get a proper CPU count!!"); }
crealPid = getpid(); //getting the pid of creal
/* The json processing */
json_t *root; //json root
json_error_t error; //json error
root = json_load_file(argv[1], 0, &error); //this loads up the json data right here
/* Main processing should happen here*/
fputs(CREAL_HEADERS,outputFP); //these are the headers of creal the next generation
fputs(ETC_BEGINNING_DEFINITIONS,outputFP); //these are the other headers needed
printOutMaxPreprocessedValues(55, 55, 55, 55, &outputFP);
fputs(CREAL_T_TYPE,outputFP); //these are the headers of creal the next generation
fputs(ACTION_FUNCTION_POINTER,outputFP); //the function pointer declaration
fputs(PRE_ACTION_STRUCT,outputFP); //action
fputs(PRE_CONDITIONLIST_STRUCT,outputFP); //conditions
fputs(PRE_ACTION_LIST,outputFP); //the action list
printOutStaticActionList(10, 10, &outputFP ); //this is used to print out the contents of the
printOutStaticCrealNodes(1000,1000,&outputFP); //this prints out the static creal node data
fputs(CREAL_CSV_STRUCTS,outputFP);
printOutNodeActionAndPropArrays(1000,1000,1000,&outputFP); //print out the structures
fputs(MAIN_CREAL_PROCESSING_FUNCTIONS,outputFP);
writeOutActionConditionFunctionsPrototypes(&root, &outputFP); //these are the function prototypes
fputs(MAIN_PART,outputFP); //beginning of the
//~
//~ puts(USAGE);
//~
fputs(MAIN_GAME_LOOP,outputFP);
fputs(END_PART,outputFP);
writeOutActionConditionFunctions(&root, &outputFP); //this is where we write out the functions in relation to the
printOutFromCTF("code_templates/process_functions.ctf",&outputFP);
fputs("void crealInit(void)\n{",outputFP);
abstractJsonData(&root, &outputFP); //this is the main function of abstracting json data
fputs("}",outputFP);
json_decref(root); //free jansson parsing data
//~ unlink(PIPE_IN_FILE); //delete the input pipe file
//~ unlink(PIPE_OUT_FILE); //delete the output pipe file
fclose(outputFP); //make sure to close the file pointer/descriptor
exit(EXIT_SUCCESS); //beep-boop .. a success!!
}
int returnNumberOfCrealNodes(json_t **root)
{
return (int) json_array_size(*root);
}
int returnNumberOfCrealProperties(json_t **root)
{
json_t *jsonPropertiesList, *temp0; //json properties, actions, etc
int propertiesCount = 0; //this is the property count
int count = (int) json_array_size(*root); //the count of the elements, for multithreading
int i = 0;
for (i = 0; i < count; i++)
{
temp0 = json_array_get(*root, i); //this is used temporary to get the value for the object
if(!json_is_object(temp0))
{
//~ printf("Array element : %d is not considered a json object!!\n",i);
return -1;
}
else
{
jsonPropertiesList = json_object_get(temp0, "properties");
if(!json_is_object(jsonPropertiesList))
{
//not ideal, something weird happens here where I cannot exit out of this fucking thing if something goes sour
//~ printf("Element : %d contains properties that is not considered a json object!!\n",i);
//~ quitWithError("json array element was not an object!"); //this happens when json data is all messed up
}
else
{
//add the accumulations of properties for one unified array
//elements in the creal stuff should be quick sorted
propertiesCount += (int) json_object_size(jsonPropertiesList); //increase summation
}
}
}
return propertiesCount;
}
int returnHighestCrealPropertyID(json_t **root)
{
const char *key = NULL;
json_t *jsonPropertiesList, *temp0; //json properties, actions, etc
void *iter; //used for iteration
int highestPropertyNumber = 0; //used to compare
int tempValue = 0; //used for temp value
int count = (int) json_array_size(*root); //the count of the elements, for multithreading
int i = 0;
for (i = 0; i < count; i++)
{
temp0 = json_array_get(*root, i); //this is used temporary to get the value for the object
if(!json_is_object(temp0))
{
//~ printf("Array element : %d is not considered a json object!!\n",i);
return -1;
}
else
{
jsonPropertiesList = json_object_get(temp0, "properties");
if(!json_is_object(jsonPropertiesList))
{
//not ideal, something weird happens here where I cannot exit out of this fucking thing if something goes sour
//~ printf("Element : %d contains properties that is not considered a json object!!\n",i);
//~ quitWithError("json array element was not an object!"); //this happens when json data is all messed up
}
else
{
//add the accumulations of properties for one unified array
//elements in the creal stuff should be quick sorted
iter = json_object_iter(jsonPropertiesList); //this is needed, the golden ticket
while(iter)
{
key = json_object_iter_key(iter);
tempValue = atoi(key);
if (tempValue > highestPropertyNumber)
{
highestPropertyNumber = tempValue; //assign
}
//~ puts(key); //use this to debug the key stuff
iter = json_object_iter_next(jsonPropertiesList, iter); //this iterates through the json data
}
//~ propertiesCount += (int) json_object_size(jsonPropertiesList); //increase summation
}
}
}
//~ json_decref(jsonPropertiesList); //free jansson parsing data
//~ json_decref(temp0); //free jansson parsing data
//~ free(iter); //free jansson parsing data
return highestPropertyNumber; //return the highest number
}
int returnHighestCrealActionID(json_t **root)
{
const char *key = NULL;
json_t *jsonPropertiesList, *temp0; //json properties, actions, etc
void *iter; //used for iteration
int highestPropertyNumber = 0; //used to compare
int tempValue = 0; //used for temp value
int count = (int) json_array_size(*root); //the count of the elements, for multithreading
int i = 0;
for (i = 0; i < count; i++)
{
temp0 = json_array_get(*root, i); //this is used temporary to get the value for the object
if(!json_is_object(temp0))
{
//~ printf("Array element : %d is not considered a json object!!\n",i);
return -1;
}
else
{
jsonPropertiesList = json_object_get(temp0, "action list");
if(!json_is_object(jsonPropertiesList))
{
//not ideal, something weird happens here where I cannot exit out of this fucking thing if something goes sour
//~ printf("Element : %d contains properties that is not considered a json object!!\n",i);
//~ quitWithError("json array element was not an object!"); //this happens when json data is all messed up
}
else
{
//add the accumulations of properties for one unified array
//elements in the creal stuff should be quick sorted
iter = json_object_iter(jsonPropertiesList); //this is needed, the golden ticket
while(iter)
{
key = json_object_iter_key(iter);
tempValue = atoi(key);
if (tempValue > highestPropertyNumber)
{
highestPropertyNumber = tempValue; //assign
}
//~ puts(key); //use this to debug the key stuff
iter = json_object_iter_next(jsonPropertiesList, iter); //this iterates through the json data
}
//~ propertiesCount += (int) json_object_size(jsonPropertiesList); //increase summation
}
}
}
//~ json_decref(jsonPropertiesList); //free jansson parsing data
//~ json_decref(temp0); //free jansson parsing data
//~ free(iter); //free jansson parsing data
return highestPropertyNumber; //return the highest number
}
int abstractJsonData(json_t **root, FILE **fp)
{
uint numOfCrealNodes = (uint) json_array_size(*root);
const char *key, *key0;
key = key0 = NULL; //hehe
json_t *jsonPropertiesList, *temp0, *temp1, *value, *type, *id, *properties, *actions, *conditions,
*actionItems, *tempForActionAndConditions, *tempForActionAndConditions2, *tempForActionAndConditionsObjects; //json properties, actions, etc
void *iter, *iter0; //used for iteration
char *text = NULL; //this is used to slurp all of the json data into a string
char *text2 = NULL; //this is used to slurp all of the json data into a string
char *text3 = NULL; //this is used to slurp all of the json data into a string
char *text4 = NULL; //this is used to slurp all of the json data into a string
int stringLength = 0;
int check = 0;
//~ int count = (int) json_array_size(*root); //the count of the elements, for multithreading
int i = 0;
int n = 0;
int k, p, o, m, c, t; //these are extras needed
k = p = o = m = c = t = 0; //setting the counter variables
int insideActionBlockIncrementer = 0; //this is used in for iteration inside of the action block
int propertyCounter = 0;
int actionCounter = 0;
int actionItemCounter = 0;
int conditionCounter = 0;
/* setting up some temporary variables unsigned integers*/
creal_t tempPropVar0, tempPropVar1, tempPropVar2, targetValue, conditionsValue;
tempPropVar0 = tempPropVar1 = tempPropVar2 = targetValue = conditionsValue = 0;
uint tempVar, idVar, propVar, actVar, condVar, numOfPropertiesInNode, numOfActionsInNode, numOfConditionsInNode, numOfActionItems, actionType, targetID, field, relation;
tempVar = idVar = propVar = actVar = condVar = numOfPropertiesInNode = numOfConditionsInNode = numOfActionItems = relation = 0; //assigning everything to zero
//~ static char inputPipePath[256], outputPipePath[256]; //these are static variable so we don't allocate too much on the damn stack
//~ sprintf(inputPipePath,"%s%d",PIPE_IN_FILE,crealPid); //creating a path for the pipe file
//~ sprintf(outputPipePath,"%s%d",PIPE_OUT_FILE,crealPid); //creating a path for the pipe file
//~
//~
//~ puts(inputPipePath);
//~ puts(outputPipePath);
//~
//~ sprintf(tempString,"ctcpd %s %s & \0", PIPE_IN_FILE, PIPE_OUT_FILE); //this is used to create an argu
//~ puts(tempString); //this is used to debug
//~ system(tempString); //start the parsing agent right here
//~ sleep(199);
for (i = 0; i < numOfCrealNodes; i++)
{
actionItemCounter = conditionCounter = actionCounter = propertyCounter = 0; //reset the property, and action counters of the creal node
//~ 0;
temp0 = json_array_get(*root, i); //this is used temporary to get the value for the object
if(!(json_is_object(temp0)))
{
return -1; //json data is messed up and it is not an object!
}
else
{
id = json_object_get(temp0, "id");
if (!(json_is_string(id)))
{
return -1; //the id value was not
}
else
{
json_unpack(id,"s",&text); //this unpacks the value right into value
/*This is where you output the print functions */
//~ puts(text); //debug
idVar = (uint) atoi(text); //This is the id value, this value will be used too print out data for print
//~ fprintf(*fp,"%s[%d];\n",NAME_CREAL_NODE_STRUCTURE,idVar); //this is where we start parsing values //this is debug for now
}//end of else
/* now we are parsing the objects, make sure to use for loop iterations*/
properties = json_object_get(temp0, "properties");
if(!(json_is_object(properties)))
{
//~ return -1; //the properties objects are not formatted right, they need to be corrected
}
else
{
numOfPropertiesInNode = (uint ) json_object_size(properties); //assigning the amount of properties in the node
fprintf(*fp,"%s[%d].numberOfProperties = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,numOfPropertiesInNode); //we are assigning how much creal properties are in the node
iter = json_object_iter(properties); //this is needed, the golden ticket
while(iter)
{
key = json_object_iter_key(iter);
temp1 = json_object_iter_value(iter);
if(!(json_is_object(temp1)))
{
//~ return -1; //this happens when json data is all messed up
}
else
{
propVar = atoi(key); //hopefully this is good
//~ printf("The array index of the property value of this node is : %d, it is connected to %d\n ",propertyCounter, propVar); //debug
//~ puts(key); //debug
//stuff goes here
fprintf(*fp,"%s[%d].properties[%d] = &%s[%d];\n",NAME_CREAL_NODE_STRUCTURE,idVar,propertyCounter,NAME_CREAL_PROP_STRUCTURE,propVar); //we are assigning how much creal properties are in the node
propertyCounter++; //increase the property counter
type = json_object_get(temp1,"type");
if(!(json_is_string(type)))
{
//~ return -1; //this portion is not a string at all
}
else
{
json_unpack(type,"s",&text); //this unpacks the value right into value
if (strcmp(text, "number") == 0)
{
//making sure we only get numerical data from Json
value = json_object_get(temp1,"value"); //getting the value from the data
json_unpack(value,"s",&text); //this unpacks the value right into value
//assign value, this helps us take away this will have to be taken away later
tempPropVar0 = atof(text);
fprintf(*fp,"%s[%d] = %f;\n",NAME_CREAL_PROP_STRUCTURE,propVar,tempPropVar0); //we are assigning how much creal properties are in the node
//~ puts(text);
}
//this is where we do something with the type
}
}
iter = json_object_iter_next(properties, iter); //this iterates through the json data
}
}//end of else
/* These are were the actions take place */
actions = json_object_get(temp0, "action list");
if(!(json_is_object(actions)))
{
//~ return -1; //something is wrong with the action stuff
}
else
{
//Actions are taking place right here
numOfActionsInNode = (uint) json_object_size(actions);
fprintf(*fp,"%s[%d].numberOfActions = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,numOfActionsInNode); //we are assigning how much creal properties are in the node
iter = json_object_iter(actions); //this is needed, the golden ticket
while(iter)
{
//Now this is set up to take the actions and conditions
key = json_object_iter_key(iter);
temp1 = json_object_iter_value(iter);
if(!(json_is_object(temp1)))
{
//~ return -1; //this happens when json data is all messed up
}
else
{
/* This is where all the action processing taking place */
//~ puts(key); //debug
actVar = (uint) atoi(key); //add the action index
/*Changed from reverse reference to a regular reference */
//~ fprintf(*fp,"%s[%d] = &%s[%d].actionList[%d];\n",NAME_CREAL_ACT_STRUCTURE,actVar,NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter); //we are assigning how much creal properties are in the node
//~ fprintf(*fp,"%s[%d] = &%s[%d].actionList[%d];\n",NAME_CREAL_ACT_STRUCTURE,actVar,NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter); //we are assigning how much creal properties are in the node
//below is the type of format that will be used for references with creal actions
fprintf(*fp, "%s[%d].actionsList[%d] = &%s[%d];\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,NAME_CREAL_ACT_STRUCTURE,actVar);
/* Assigning the action id to the original array of structures*/
//~ fprintf(*fp,"%s[%d].actionsList[%d].alID = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,actVar); //we are assigning how much creal properties are in the node
//this is how we are going to set up the action right here
fprintf(*fp,"%s[%d].alID = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,actVar); //we are assigning how much creal properties are in the node
//Iterate through everything in the action list right here, get all of the elements
//the actual actions right here
actionItems = json_object_get(temp1, "actions");
if(!(json_is_array(actionItems)))
{
//right here we should return zero for the number of action items
//~ puts("This (Action) is not an object you clod!"); //this is bead
fprintf(*fp,"%s[%d].numberOfActionItems = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,0); //THIS HAS BEEN REDONE
}
else
{
//the number of elements right here
numOfActionItems = (uint) json_array_size(actionItems); //remember these actions are arrays
//~ fprintf(*fp,"%s[%d] = &%s[%d].actionList[%d].numberOfActions = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,numOfActionItems); //we are assigning how much creal properties are in the node
//~ fprintf(*fp,"%s[%d].actionlist[%d].numberOfActionItems = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,numOfActionItems); //this is where we are assigning the number of action items
fprintf(*fp,"%s[%d].numberOfActionItems = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,numOfActionItems); //THIS HAS BEEN REDONE
//RIGHT HERE ,NAME_CREAL_ACT_STRUCTURE,actVar,actVar
//~ insideActionBlockIncrementer
for (insideActionBlockIncrementer = 0; insideActionBlockIncrementer < numOfActionItems; insideActionBlockIncrementer++)
{
//Actions!
/* This right here is for iterating into the action items */
tempForActionAndConditions = json_array_get(actionItems, insideActionBlockIncrementer); //this is used temporary to get the value for the object
//~ "action_type" //unpack right here
//For action type
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "action_type");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
//Do an action here to signify that the condition is null
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
actionType = (uint) atoi(text3); //getting the value of the action_type
//~ fprintf(*fp,"%s[%d].actionlist[%d].actions[%d].actionType = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,actionType); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actions[%d].actionType = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,actionCounter,insideActionBlockIncrementer,actionType); //this is where we are assigning the number of action items
//changed 5/20/13
fprintf(*fp,"%s[%d].actions[%d].actionType = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,actionType); //this is where we are assigning the number of action items
//For target ID
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "target_id");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
targetID = (uint) atoi(text3); //getting the value of target_id
//~ fprintf(*fp,"%s[%d].actionlist[%d].actions[%d].targetID = %d ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,targetID); //this is where we are assigning the number of action items
//Changed 5/20/13
fprintf(*fp,"%s[%d].actions[%d].targetID = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,targetID); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actionlist[%d].actions[%d].targetID = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,tempPropVar1); //this is where we are assigning the number of action items
//For target value
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "target_value");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
targetValue = (creal_t) atof(text3); //getting the value target value
//~ fprintf(*fp,"%s[%d].actionlist[%d].actions[%d].targetValue = %f ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,targetValue); //this is where we are assigning the number of action items
//Changed 5/20/13
fprintf(*fp,"%s[%d].actions[%d].targetValue = %f;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,targetValue); //this is where we are assigning the number of action items
/* Added 6/3/13... Making sure we make functions */
/* //~ actionFunction_AID_INCREMENTOR() - This right here is the action function */
fprintf(*fp,"%s[%d].actions[%d].actionFunction = &actionFunction_%d_%d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,actVar,insideActionBlockIncrementer); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actionlist[%d].actions[%d].targetValue = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,tempPropVar1); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actionlist[%d].numberOfActionItems = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,numOfActionItems); //this is where we are assigning the number of action items
}
//~ fprintf(*fp,"Number of Action Items %d \n",numOfActionItems); //we are assigning how much creal properties are in the node
}//end of the else statement
//Good work
//also iterate through the conditions
conditions = json_object_get(temp1, "conditions");
if(!(json_is_array(conditions)))
{
//right here we should return zero for the number of conditions
//~ puts("This (Condition) is not an object you clod!"); //this is bead
fprintf(*fp,"%s[%d].numberOfConditions = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,0); //this is where we are assigning the number of conditions within an action list
}
else
{
//the number of elements right here
numOfConditionsInNode = (uint) json_array_size(conditions); //remember these conditions are arrays
//Changed 5/20/13
fprintf(*fp,"%s[%d].numberOfConditions = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,numOfConditionsInNode); //this is where we are assigning the number of conditions within an action list
//~ fprintf(*fp,"%s[%d].numberOfActionItems = %d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,numOfActionItems); //THIS HAS BEEN REDONE
for (insideActionBlockIncrementer = 0; insideActionBlockIncrementer < numOfConditionsInNode; insideActionBlockIncrementer++)
{
//conditions!!
/* This right here is for iterating into the action items */
tempForActionAndConditions = json_array_get(conditions, insideActionBlockIncrementer); //this is used temporary to get the value for the object
//For the field of the conditions
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "field");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
field = (uint) atoi(text3); //getting the value of the action_type
//Changed 5/20/13
//~ fprintf(*fp,"%s[%d].actionlist[%d].conditions[%d].field = %d ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,field); //this is where we are assigning the number of action items
fprintf(*fp,"%s[%d].conditions[%d].field = %d ;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,field); //this is the new shit
//For the relation of the conditions
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "relation");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
relation = (uint) atoi(text3); //getting the value of the action_type
//~ fprintf(*fp,"%s[%d].actionlist[%d].conditions[%d].relationType = %d ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,relation); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actionlist[%d].conditions[%d].relationType = %d ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,relation); //this is where we are assigning the number of action items
fprintf(*fp,"%s[%d].conditions[%d].relationType = %d ;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,relation); //this is the new shit
//For the value of the conditions
tempForActionAndConditionsObjects = json_object_get(tempForActionAndConditions, "value");
if(!(json_is_string(tempForActionAndConditionsObjects)))
{
puts("OH BOY"); //not good
}
//We want to unpack a string variable here
json_unpack(tempForActionAndConditionsObjects,"s",&text3); //this unpacks the value right into value
//~ puts(text3);
conditionsValue = (creal_t) atof(text3); //getting the value of the action_type
//~ fprintf(*fp,"%s[%d].actionlist[%d].conditions[%d].value = %f ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,conditionsValue); //this is where we are assigning the number of action items
//~ fprintf(*fp,"%s[%d].actionlist[%d].conditions[%d].value = %f ;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,insideActionBlockIncrementer,conditionsValue); //this is where we are assigning the number of action items
//changed 5/20/13
fprintf(*fp,"%s[%d].conditions[%d].value = %f ;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,conditionsValue); //this is the new shit
//~ puts("This right here is the incrementer for conditions");
//~ fprintf(*fp,"%s[%d].actionlist[%d].numberOfActionItems = %d;\n",NAME_CREAL_NODE_STRUCTURE,idVar,actionCounter,numOfActionItems); //this is where we are assigning the number of action items
/* 6/4/13 -=This stuff is added right here for now=-
* conditionFunction_AID_INCREMENTOR() //
* ->actionFunction = &actionFunction_%d_%d
* */
fprintf(*fp,"%s[%d].conditions[%d].conditionFunction = &conditionFunction_%d_%d;\n",NAME_CREAL_ACT_STRUCTURE,actVar,insideActionBlockIncrementer,actVar,insideActionBlockIncrementer); //this is the new shit
}
//~ fprintf(*fp,"Number of Conditions %d \n",numOfConditionsInNode); //we are assigning how much creal properties are in the node
}//end of the else statement
//I AM RIGHT LEGEND
//Make sure to increment the counter!! or else it all goes astray!
actionCounter++; //increment the action counter
}
iter = json_object_iter_next(actions, iter); //this iterates through the json data
}
}//end of else statement
/*
This is where we are going to work on the conditions
conditions = json_object_get(temp0, "conditions");
if(!(json_is_object(conditions)))
{
//~ return -1; //something is wrong with the action stuff
}
else
{
numOfActionsInNode = (uint) json_object_size(actions);
}//end of else statement
This needs to be more thought out of right here
*/
}
}
//this is the end of the function
}
int printOutStaticActionList(uint actionCount, uint conditionCount, FILE **stream )
{
/* This is where we pring out what the hell is going on here */
fprintf(*stream, " struct pre_actions actions[%d]; \n struct pre_conditionlist conditions[%d]; \n", actionCount, conditionCount);
fprintf(*stream, "%s\n\n\n", CLOSE_THE_STRUCT_CURLY);
return 0; //everything is ok
} //this is used to finish the
int printOutNodeActionAndPropArrays(uint crealNodeCount, uint actionListCount, uint propertiesCount, FILE **stream)
{
/* This portion of the code will print out everything related to the creal nodes */
/* Creal Nodes*/
fprintf(*stream,"%s%d%s;\n",CREAL_NODE, crealNodeCount, END_CREAL_BRACKET);
/* Creal Properties */
fprintf(*stream,"%s%d%s;\n",CREAL_PROP, crealNodeCount, END_CREAL_BRACKET);
/* Summing Vector for properties... its a temporary buffer to actually change the properties */
fprintf(*stream,"%s%d%s;\n",CREAL_SUM_VECTORS, crealNodeCount, END_CREAL_BRACKET);
/* Creal Actions*/
fprintf(*stream,"%s%d%s;\n\n",CREAL_ACTIONS, crealNodeCount, END_CREAL_BRACKET);
return 0; //everything is ok
}
int printOutStaticCrealNodes(uint actionListCount, uint propertiesCount, FILE **stream)
{
/* This function prints out the static creal node data*/
/* Top portion*/
fprintf(*stream,"%s\n",CREAL_NODE_STRUCTURE_TOP);
/* Property IDs*/
fprintf(*stream,"\t\t%s%d%s;\n",CREAL_NODE_STRUCTURE_PROP_ID,propertiesCount,END_CREAL_NODE_STRUCTURE_BRACKET);
/* Creal Properties*/
fprintf(*stream,"\t\t%s%d%s;\n",CREAL_NODE_STRUCTURE_PROPERTIES,propertiesCount,END_CREAL_NODE_STRUCTURE_BRACKET);
/* Action Lists*/
fprintf(*stream,"\t\t%s%d%s;\n",CREAL_NODE_STRUCTURE_ACTIONLIST,actionListCount,END_CREAL_NODE_STRUCTURE_BRACKET);
/*Close the structure */
fprintf(*stream, "%s;\n\n", END_CREAL_NODE_STRUCTURE_STRUCTDEC);
return 0; //everything is ok
}
int printOutMaxPreprocessedValues(uint propMax, uint actListMax, uint actAndCondMax, uint nodeMax, FILE **stream)
{
/* This function prints out precompiler macro declarations for creal_ng*/
fprintf(*stream,"%s %d\n",CREAL_MAX_PROPERTIES,propMax);
fprintf(*stream,"%s %d\n",CREAL_MAX_ACTION_LISTS,actListMax);
fprintf(*stream,"%s %d\n",CREAL_MAX_ACTIONS_AND_CONDITIONS,actAndCondMax);
fprintf(*stream,"%s %d\n",CREAL_MAX_CREAL_NODES,nodeMax);
return 1;
}
int returnNumberOfCoresOnSystem(void)
{
/* This function is used to find the number of cpus on the system, its a shell function */
return sysconf( _SC_NPROCESSORS_ONLN ); //this is used to get the cpu count
}
int createPipeFile(const char *path)
{
/* This function is used to create a pipe file with the argument going to a specified path*/
unlink(path); //this is redundant right here
if (mkfifo(path, 0777) < 0) //make the pipe
{
/* */
return -1;
}
/* Below is a very long long functional call, but it allows us to set permissions on the file to everything open */
chmod(path, S_ISUID | S_ISGID | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
return 1;
}
int writeOutActionConditionFunctions(json_t **root, FILE **fp)
{