From: Lukas Krickl Date: Mon, 13 Nov 2023 13:14:02 +0000 (+0100) Subject: WIP: asm step X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=20fd0255d7865ff45be6f63ad540d45e214d41c8;p=ulas%2F.git WIP: asm step --- diff --git a/include/ulas.h b/include/ulas.h index b1df177..d5d4178 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -291,9 +291,13 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, size_t *n); /** - * Assembly step + * Assembly step */ +// returns 0 if no more data can be read +// > 0 if data was read +// -1 on error +int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n); int ulas_asm(FILE *dst, FILE *src); #endif diff --git a/src/ulas.c b/src/ulas.c index 8aca72d..630b472 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -689,8 +689,35 @@ int ulas_preproc(FILE *dst, FILE *src) { * Assembly step */ +int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n) { + int rc = 1; + if (fgets(buf, n, src) != NULL) { + ulas.line++; + + fprintf(dst, "%s", buf); + // size_t buflen = strlen(buf); + } else { + rc = 0; + } + return rc; +} + int ulas_asm(FILE *dst, FILE *src) { + char buf[ULAS_LINEMAX]; + memset(buf, 0, ULAS_LINEMAX); int rc = 0; + // init + struct ulas_preproc pp = ulas_preprocinit(); + + // preproc + while ((rc = ulas_asmnext(dst, src, buf, ULAS_LINEMAX)) > 0) { + } + + // cleanup + ulas_preprocfree(&pp); + + return rc; + return rc; }