]> Shamusworld >> Repos - rmac/blobdiff - direct.c
Fix for bug #167
[rmac] / direct.c
index 9070a4165ea8d88e64978f3c10b360141ab3fdf5..d6d6c3f2e63499d7301253b41f9881eb72daef08 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -559,7 +559,7 @@ int d_noclear(void)
 
 
 //
-// Include binary file
+// Include binary file (can add addition size & position params, comma separated)
 //
 int d_incbin(void)
 {
@@ -584,8 +584,9 @@ int d_incbin(void)
 
        // Attempt to open the include file in the current directory, then (if that
        // failed) try list of include files passed in the enviroment string or by
-       // the "-d" option.
+       // the "-i" option.
        TOKEN filename = tok[1];
+
        if ((fd = open(string[filename], _OPEN_INC)) < 0)
        {
                for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
@@ -608,6 +609,7 @@ int d_incbin(void)
 allright:
 
        tok += 2;
+
        if (*tok != EOL)
        {
                // Check size parameter (can be omitted)
@@ -637,6 +639,7 @@ allright:
                                                close(fd);
                                                return ERROR;
                                        }
+
                                        lseek(fd, pos, SEEK_SET);
                                        size -= pos;
                                }
@@ -647,17 +650,18 @@ allright:
                                }
                        }
                        else
-                               return(comma_error);
+                               return error(comma_error);
                }
                else
                        pos = lseek(fd, 0L, SEEK_SET);
        }
        else
        {
-               //size_pos_fallthrough:
+               // size & pos not given, so assume offset of 0 and all of the binary
                size = lseek(fd, 0L, SEEK_END);
                pos = lseek(fd, 0L, SEEK_SET);
        }
+
        chcheck(size);
 
        DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[filename], size); }