Improved implementation of file_import
This commit is contained in:
parent
fec9cffcd6
commit
0de5bb473b
17
src/modal.c
17
src/modal.c
|
@ -99,23 +99,24 @@ device_read(void)
|
||||||
if(dst_ - origin == 0) dst_--;
|
if(dst_ - origin == 0) dst_--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static char *
|
||||||
file_import(char *path)
|
file_import(char *path, char *ptr)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int pr = 0;
|
int pr = 0;
|
||||||
char c;
|
|
||||||
if((f = fopen(path, "r"))) {
|
if((f = fopen(path, "r"))) {
|
||||||
|
char c;
|
||||||
while(fread(&c, 1, 1, f)) {
|
while(fread(&c, 1, 1, f)) {
|
||||||
c = c <= 0x20 ? 0x20 : c;
|
c = c <= 0x20 ? 0x20 : c;
|
||||||
if(c == '(') pr++;
|
if(c == '(') pr++;
|
||||||
if(c == ')') pr--;
|
if(c == ')') pr--;
|
||||||
*dst_++ = c;
|
*ptr++ = c;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if(pr) fprintf(stderr, "Modal program imbalanced.\n");
|
if(pr) fprintf(stderr, "Modal program imbalanced.\n");
|
||||||
} else
|
return ptr;
|
||||||
dst_ = copy("NAF", dst_, 3);
|
}
|
||||||
|
return copy("NAF", ptr, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -127,7 +128,7 @@ write_reg(char r, char *reg)
|
||||||
case '_': {
|
case '_': {
|
||||||
char filepath[0x80];
|
char filepath[0x80];
|
||||||
copy(reg, filepath, walk(reg) - reg);
|
copy(reg, filepath, walk(reg) - reg);
|
||||||
file_import(filepath);
|
dst_ = file_import(filepath, dst_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case '^': { /* op: join */
|
case '^': { /* op: join */
|
||||||
|
@ -322,7 +323,7 @@ main(int argc, char **argv)
|
||||||
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dst_ = bank_a, file_import(argv[i]), dst_ = bank_b;
|
file_import(argv[i], src_);
|
||||||
while(rewrite() && ++rw)
|
while(rewrite() && ++rw)
|
||||||
if(!cycles--) return !fprintf(stderr, "Modal rewrites exceeded.\n");
|
if(!cycles--) return !fprintf(stderr, "Modal rewrites exceeded.\n");
|
||||||
if(!quiet) {
|
if(!quiet) {
|
||||||
|
|
Loading…
Reference in New Issue