Skip to content

Commit

Permalink
buffered IO, other small IO update
Browse files Browse the repository at this point in the history
  • Loading branch information
Stvff committed Mar 12, 2022
1 parent d03500d commit 1d57253
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
4 changes: 3 additions & 1 deletion aasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void functionswitch(int instruction, num_t* args[], int types[], qua_t* qargs[])
break;
case print:
doprint = true;
if(args[0]->nump[0] > 9) rettype = string;
break;
case nprint:
doprint = false;
Expand Down Expand Up @@ -225,13 +226,14 @@ void functionswitch(int instruction, num_t* args[], int types[], qua_t* qargs[])
rettype = string;
break;
case input:
inputfailed:
fgets(userInput, inputlen, stdin);
if(userInput[0] >= '0' && userInput[0] <= '9')
inpstrtonum(args[0], userInput, 0, bigEndian);
else if (userInput[0] == '"'){
strtostrnum(args[0], userInput, 1);
rettype = string;
} else {printf("Input must be a number or string\n"); doprint = false;}
} else {printf("Input must be a number or string\n"); goto inputfailed;}
break;
case sinput:
fgets(userInput, inputlen, stdin);
Expand Down
30 changes: 22 additions & 8 deletions arbnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ void printnum(num_t* number, int isbigend){//add 2 to isbigend to make it not ne
bool donewline = true;
if(isbigend > 1){ donewline = false; isbigend -= 2;}

for(int i = isbigend*((int)number->len-1); i != (1-isbigend)*(int)number->len - isbigend; i+= (1 - 2*isbigend))
printf("%u ", number->nump[i]);
char* buffer = (char*) malloc((4 + number->len*2)*sizeof(char));
int j = 0;
for(int i = isbigend*((int)number->len-1); i != (1-isbigend)*(int)number->len - isbigend; i+= (1 - 2*isbigend)){
buffer[j] = 0x30 + number->nump[i];
buffer[j + 1] = ' ';
j += 2 ;
}

switch (number->dim){
case 1: printf("i"); break;
case 2: printf("j"); break;
case 3: printf("k"); break;
} if (number->sign == 1) printf("-");
if(donewline) printf("\n");
case 1: buffer[j] = 'i'; j++; break;
case 2: buffer[j] = 'j'; j++; break;
case 3: buffer[j] = 'k'; j++; break;
} if (number->sign == 1){ buffer[j] = '-'; j++;}

if(donewline){ buffer[j] = '\n'; j++;}
buffer[j] = '\0';
printf("%s", buffer);
free(buffer);
}

int numtoint(num_t* num, bool considersign){
Expand Down Expand Up @@ -172,8 +182,12 @@ int strtostrnum(num_t* number, char str[], int offset){
}

void printstrnum(num_t* number){
char* buffer = (char*) malloc((1 + number->len)*sizeof(char));
for(unsigned int i = 0; i < number->len; i++)
printf("%c", number->nump[i]);
buffer[i] = (char)number->nump[i];
buffer[number->len] = '\0';
printf("%s", buffer);
free(buffer);
}

void savenum(FILE* fp, num_t* num){//File needs to be opened already!
Expand Down
5 changes: 2 additions & 3 deletions scripts/bigtest/expectedoutput.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endian is 0
1 2 3 -
123-:
1 2 3 -
3 2 1 -
1 2 3 -

endian is 1
123456789:
Expand All @@ -47,7 +47,7 @@ endian is 1
1 2 3 -
123-:
1 2 3 -
3 2 1 -
1 2 3 -

endian is 0
1 + 2i + 3j + 4k:
Expand All @@ -59,4 +59,3 @@ endian is 0

##################END OF TEST

Script completed.
4 changes: 2 additions & 2 deletions scripts/bigtest/inputs.aa
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ print gr1

print "123-:"
print 123-
set gr1, 321-
set gr1, 123-
print gr1


Expand All @@ -43,7 +43,7 @@ print gr1

print "123-:"
print 123-
set gr1, 321-
set gr1, 123-
print gr1

set endian, 0
Expand Down
25 changes: 14 additions & 11 deletions scripts/test.aa
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
set loop, 1
sprint "Test nprint (1) or sprint (2)?\n> "
input gr2

sprint "\\\\\\ "
sinput gr1

set gr2, gr1
dget gr2, 0
cmp gr2, "9"
Cg sprint gr1
Cg sprint "\n"
set loop, 0
set endian, 0
cmp gr2, 2
Cs set gr1, ""
Cs shf gr1, 000 000 001
Cs print gr1
Cs print time

cmp gr2, "\\"
Ce set loop, 0
Ce sprint "path?\n> "
Ce sinput gr2
Ce set gr1, 000 000 000 1
Ce fread gr1, gr2, 0
Ce sprint gr1
Ce print time

0 comments on commit 1d57253

Please sign in to comment.