Browse files

Make the loadbc function private and add the public lorito_load_bytecode

  • Loading branch information...
1 parent 2268684 commit feaf970747a57840b1e239ae076f0aa113ccdda0 @atrodo committed Jan 18, 2011
Showing with 32 additions and 4 deletions.
  1. +30 −2 loader.c
  2. +1 −1 loader.h
  3. +1 −1 main.c
View
32 loader.c
@@ -21,6 +21,10 @@
#include "loader.h"
#include <stdio.h>
+/* Pre-declare private function */
+Lorito_File *
+loadbc(Lorito_Interp *interp, const char* filename);
+
void file_info(Lorito_Interp *interp)
{
int i, j;
@@ -45,13 +49,37 @@ void file_info(Lorito_Interp *interp)
}
Lorito_File *
-loadbc(Lorito_Interp *interp, char* filename)
+lorito_load_bytecode(Lorito_Interp *interp, Lorito_Str* filename)
+{
+ // TODO This should have a path
+ Lorito_File *result;
+ result = loadbc(interp, filename->original);
+
+ if (result == NULL)
+ {
+ char *with_ext = (char *) malloc(strlen(filename->original) + 4);
+ strcat(with_ext, filename->original);
+ strcat(with_ext, ".ito");
+ result = loadbc(interp, filename->original);
+ free(with_ext);
+ }
+
+ if (result == NULL)
+ {
+ printf("(%s)\n", filename);
+ perror("Failed to open file");
+ }
+
+ return result;
+}
+
+Lorito_File *
+loadbc(Lorito_Interp *interp, const char* filename)
{
int fileid = interp->next_fileid++;
int segid = 0;
FILE *input = fopen(filename, "rb");
if (input == NULL) {
- perror("Failed to open file");
return;
}
View
2 loader.h
@@ -11,6 +11,6 @@
#define SEG_FLAG_main 0x02
Lorito_File *
-loadbc(Lorito_Interp *interp, char* filename);
+lorito_load_bytecode(Lorito_Interp *interp, Lorito_Str* filename);
#endif /* LORITO_LOADER_H_GUARD */
View
2 main.c
@@ -21,7 +21,7 @@ main(int argc, const char *argv[])
for (i = 1; i < argc; i++)
{
- loadbc(interp, argv[i]);
+ lorito_load_bytecode(interp, lorito_string(interp, 0, argv[i]));
}
int retval = lorito_run(interp);

0 comments on commit feaf970

Please sign in to comment.