|
@@ -23,3 +23,80 @@ void (*bbOnDebugPopExState)()=debugNop;
|
|
|
|
|
|
void (*bbOnDebugUnhandledEx)( BBObject *ex )=debugUnhandledEx;
|
|
|
|
|
|
+static unsigned int bpCount = 0;
|
|
|
+static unsigned int bpSize = 0;
|
|
|
+static BBSource * sources = 0;
|
|
|
+
|
|
|
+static void swap(BBSource* a, BBSource* b) {
|
|
|
+ BBSource s = *a;
|
|
|
+ *a = *b;
|
|
|
+ *b = s;
|
|
|
+}
|
|
|
+
|
|
|
+static int partition (BBSource arr[], int low, int high) {
|
|
|
+ BBULONG pivot = arr[high].id;
|
|
|
+ int i = (low - 1);
|
|
|
+ for (int j = low; j <= high- 1; j++) {
|
|
|
+ if (arr[j].id < pivot) {
|
|
|
+ i++;
|
|
|
+ swap(&arr[i], &arr[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ swap(&arr[i + 1], &arr[high]);
|
|
|
+ return (i + 1);
|
|
|
+}
|
|
|
+
|
|
|
+static void sort(BBSource arr[], int low, int high) {
|
|
|
+ if (low < high) {
|
|
|
+ int part = partition(arr, low, high);
|
|
|
+ sort(arr, low, part - 1);
|
|
|
+ sort(arr, part + 1, high);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void bbRegisterSource(BBULONG sourceId, const char * source) {
|
|
|
+ if (sources == 0) {
|
|
|
+ bpSize = 32;
|
|
|
+ sources = calloc(bpSize, sizeof(BBSource));
|
|
|
+ } else {
|
|
|
+ if (bpCount == bpSize) {
|
|
|
+ BBSource * bp = calloc(bpSize * 2, sizeof(BBSource));
|
|
|
+ memcpy(bp, sources, bpSize * sizeof(BBSource));
|
|
|
+ BBSource * old = sources;
|
|
|
+ sources = bp;
|
|
|
+ free(old);
|
|
|
+ bpSize *= 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sources[bpCount].id = sourceId;
|
|
|
+ sources[bpCount].file = source;
|
|
|
+
|
|
|
+ bpCount++;
|
|
|
+
|
|
|
+ if (bpCount > 1) {
|
|
|
+ sort(sources, 0, bpCount - 1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+BBSource * bbSourceForId(BBULONG id) {
|
|
|
+ unsigned first = 0;
|
|
|
+ unsigned last = bpCount - 1;
|
|
|
+ unsigned index = 0;
|
|
|
+
|
|
|
+ while (first <= last) {
|
|
|
+ index = (first + last) / 2;
|
|
|
+ if (sources[index].id == id) {
|
|
|
+ return &sources[index];
|
|
|
+ } else {
|
|
|
+ if (sources[index].id < id) {
|
|
|
+ first = index + 1;
|
|
|
+ } else {
|
|
|
+ last = index - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "<Error:Unmapped source>";
|
|
|
+}
|
|
|
+
|