Fix formatting.

This commit is contained in:
bʰedoh₂ swé 2024-06-18 05:01:37 +05:00
parent b666de95af
commit f4791c5177
2 changed files with 29 additions and 18 deletions

View File

@ -12,7 +12,7 @@
Stack *program_init(uint16_t stacksize) Stack *program_init(uint16_t stacksize)
{ {
Stack *stack = calloc(1,sizeof(&stack) + sizeof(Instruction) * PROGRAM_MAXSIZE + sizeof(int16_t) * MAX_LABELS + Stack *stack = calloc(1, sizeof(&stack) + sizeof(Instruction) * PROGRAM_MAXSIZE + sizeof(int16_t) * MAX_LABELS +
sizeof(uint16_t) * stacksize); sizeof(uint16_t) * stacksize);
stack->stacksize = stacksize; stack->stacksize = stacksize;

View File

@ -3,46 +3,57 @@
#include <stdlib.h> #include <stdlib.h>
#include "wincompat.h" #include "wincompat.h"
size_t getline(char **lineptr, size_t *n, FILE *stream) { size_t getline(char **lineptr, size_t *n, FILE *stream)
{
char *bufptr = NULL; char *bufptr = NULL;
char *p = bufptr; char *p = bufptr;
size_t size; size_t size;
int c; int c;
if (lineptr == NULL) { if (lineptr == NULL)
{
return -1; return -1;
} }
if (stream == NULL) { if (stream == NULL)
{
return -1; return -1;
} }
if (n == NULL) { if (n == NULL)
{
return -1; return -1;
} }
bufptr = *lineptr; bufptr = *lineptr;
size = *n; size = *n;
c = fgetc(stream); c = fgetc(stream);
if (c == EOF) { if (c == EOF)
{
return -1; return -1;
} }
if (bufptr == NULL) { if (bufptr == NULL)
{
bufptr = malloc(128); bufptr = malloc(128);
if (bufptr == NULL) { if (bufptr == NULL)
{
return -1; return -1;
} }
size = 128; size = 128;
} }
p = bufptr; p = bufptr;
while(c != EOF) { while (c != EOF)
if ((p - bufptr) > (size - 1)) { {
if ((p - bufptr) > (size - 1))
{
size = size + 128; size = size + 128;
bufptr = realloc(bufptr, size); bufptr = realloc(bufptr, size);
if (bufptr == NULL) { if (bufptr == NULL)
{
return -1; return -1;
} }
} }
*p++ = c; *p++ = c;
if (c == '\n') { if (c == '\n')
{
break; break;
} }
c = fgetc(stream); c = fgetc(stream);