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,8 +12,8 @@
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;
@ -107,20 +107,20 @@ Stack *stack_callback_pointer;
void stack_init_callback(Stack *stack) void stack_init_callback(Stack *stack)
{ {
stack_callback_pointer = stack; stack_callback_pointer = stack;
} }
uint16_t stack_pop_callback(void) uint16_t stack_pop_callback(void)
{ {
return stack_pop(stack_callback_pointer); return stack_pop(stack_callback_pointer);
} }
void stack_push_callback(uint16_t number) void stack_push_callback(uint16_t number)
{ {
stack_push(stack_callback_pointer, number); stack_push(stack_callback_pointer, number);
} }
size_t stack_len_callback(void) size_t stack_len_callback(void)
{ {
return stack_callback_pointer->pointer; return stack_callback_pointer->pointer;
} }

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);