summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c')
-rw-r--r--[-rwxr-xr-x]mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
index 8eddc7b78..ef80872e5 100755..100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
@@ -10,9 +10,9 @@
#include "mrdberror.h"
#include "apilist.h"
#include "apistring.h"
-#include "mruby/compile.h"
-#include "mruby/irep.h"
-#include "mruby/debug.h"
+#include <mruby/compile.h>
+#include <mruby/irep.h>
+#include <mruby/debug.h>
#define LINE_BUF_SIZE MAX_COMMAND_LINE
@@ -46,18 +46,18 @@ build_path(mrb_state *mrb, const char *dir, const char *base)
len = strlen(base) + 1;
if (strcmp(dir, ".")) {
- len += strlen(dir) + strlen("/");
+ len += strlen(dir) + sizeof("/") - 1;
}
- if ((path = mrb_malloc(mrb, len)) != NULL) {
- memset(path, 0, len);
+ path = (char*)mrb_malloc(mrb, len);
+ memset(path, 0, len);
- if (strcmp(dir, ".")) {
- strcat(path, dir);
- strcat(path, "/");
- }
- strcat(path, base);
+ if (strcmp(dir, ".")) {
+ strcat(path, dir);
+ strcat(path, "/");
}
+ strcat(path, base);
+
return path;
}
@@ -65,14 +65,15 @@ static char*
dirname(mrb_state *mrb, const char *path)
{
size_t len;
- char *p;
+ const char *p;
+ char *dir;
if (path == NULL) {
return NULL;
}
p = strrchr(path, '/');
- len = p != NULL ? p - path : strlen(path);
+ len = p != NULL ? (size_t)(p - path) : strlen(path);
return mrb_debug_strndup(mrb, path, len);
}
@@ -80,11 +81,9 @@ dirname(mrb_state *mrb, const char *path)
static source_file*
source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
{
- source_file *file = NULL;
+ source_file *file;
- if ((file = mrb_malloc(mrb, sizeof(source_file))) == NULL) {
- return NULL;
- }
+ file = (source_file*)mrb_malloc(mrb, sizeof(source_file));
memset(file, '\0', sizeof(source_file));
file->fp = fopen(filename, "rb");
@@ -95,7 +94,8 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
}
file->lineno = 1;
- if ((file->path = mrb_debug_strdup(mrb, filename)) == NULL) {
+ file->path = mrb_debug_strdup(mrb, filename);
+ if (file->path == NULL) {
source_file_free(mrb, file);
return NULL;
}
@@ -175,9 +175,13 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
FILE *fp;
const char *search_path[3];
char *path = NULL;
+ const char *srcname = strrchr(filename, '/');
+
+ if (srcname) srcname++;
+ else srcname = filename;
search_path[0] = srcpath;
- search_path[1] = dirname(mrb, mrb_debug_get_filename(mrdb->dbg->root_irep, 0));
+ search_path[1] = dirname(mrb, mrb_debug_get_filename(mrb, mrdb->dbg->irep, 0));
search_path[2] = ".";
for (i = 0; i < 3; i++) {
@@ -185,7 +189,7 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
continue;
}
- if ((path = build_path(mrb, search_path[i], filename)) == NULL) {
+ if ((path = build_path(mrb, search_path[i], srcname)) == NULL) {
continue;
}