Pārlūkot izejas kodu

Added bbSourceForName().

Brucey 5 gadi atpakaļ
vecāks
revīzija
c5b8e87940
2 mainītis faili ar 34 papildinājumiem un 14 dzēšanām
  1. 33 14
      blitz.mod/blitz_debug.c
  2. 1 0
      blitz.mod/blitz_debug.h

+ 33 - 14
blitz.mod/blitz_debug.c

@@ -80,23 +80,42 @@ void bbRegisterSource(BBULONG sourceId, const char * source) {
 }
 
 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;
+	if (bpCount > 0) {
+		unsigned int first = 0;
+		unsigned int last = bpCount - 1;
+		unsigned int index = 0;
+		
+		while (first <= last) {
+			index = (first + last) / 2;
+			if (sources[index].id == id) {
+				return &sources[index];
 			} else {
-				last = index - 1;
+				if (sources[index].id < id) {
+					first = index + 1;
+				} else {
+					if (index == 0) {
+						return 0;
+					}
+					last = index - 1;
+				}
 			}
 		}
 	}
-
-	return "<Error:Unmapped source>";
+	return 0;
 }
 
+BBSource * bbSourceForName(BBString * filename) {
+	if (bpCount > 0) {
+		char path[512];
+		size_t len = 512;
+		bbStringToUTF8StringBuffer(filename, path, &len);
+		path[len] = 0;
+		
+		for (int i = 0; i < bpCount; i++) {
+			if (strcmp(path, sources[i].file) == 0) {
+				return &sources[i];
+			}
+		}
+	}
+	return 0;
+}

+ 1 - 0
blitz.mod/blitz_debug.h

@@ -80,6 +80,7 @@ extern void (*bbOnDebugUnhandledEx)( BBObject *ex );
 
 void bbRegisterSource(BBULONG sourceId, const char * source);
 BBSource * bbSourceForId(BBULONG id);
+BBSource * bbSourceForName(BBString * filename);
 
 #ifdef __cplusplus
 }