Input completed.
This commit is contained in:
1 parent
d7de27a54b
commit
c6cce2a9a5
5 files changed
+29
-3
No files matched your search
@@ -14,6 +14,8 @@ typedef uint8_t rot8_ins_size;
|
||||
// #define DATA_WIDTH (sizeof(rot8_data) * CHAR_BIT)
|
||||
#define UNIT_SIZE 8 // Just for test.
|
||||
|
||||
#define ROT8_BC_TO_CHAR(bc) ("><+-[].,"[(bc)])
|
||||
|
||||
typedef enum {
|
||||
STP, // Step Tape Pointer,'>'
|
||||
BTP, // Back Tape Pointer,'<'
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
void rot8_out_io(rot8_iter *it);
|
||||
void rot8_inp_io(rot8_iter *it);
|
||||
|
||||
void read_tape(const char *filename, char *tape);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "rot8/rot8_io.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rot8/rot8.h"
|
||||
|
||||
void rot8_out_io(rot8_iter *it) {
|
||||
// putchar(out(it));
|
||||
@@ -11,3 +14,16 @@ void rot8_inp_io(rot8_iter *it) {
|
||||
scanf("%d", &n);
|
||||
inp(it, n);
|
||||
}
|
||||
|
||||
void read_tape(const char *filename, char *tape) {
|
||||
char *tail = tape;
|
||||
|
||||
FILE *fp = fopen(filename, "r");
|
||||
|
||||
char get;
|
||||
while ((get = fgetc(fp)) != EOF) {
|
||||
if (strchr("><+-[].,", get) != NULL) *tail = get;
|
||||
tail++;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
,>-+-+-+-+-+-+-+-+<>[<[-]+.>-+]<
|
||||
+8
-3
@@ -1,9 +1,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rot8/rot8.h"
|
||||
#include "rot8/rot8_io.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
char ins[] = ",>-+-+-+-+-+-+-+-+[<[-]+>-+]<";
|
||||
run(ins, sizeof(ins) / sizeof(ins[0]) - 1);
|
||||
char *ins = (char *)malloc(sizeof(char) * INS_SIZE);
|
||||
read_tape(argv[1], ins);
|
||||
run(ins, strlen(ins) - 1);
|
||||
free(ins);
|
||||
return (0);
|
||||
}
|
||||
Reference in new issue
Block a user