fix most compiler errors
This commit is contained in:
parent
efa6fe674f
commit
905a0e9056
12
Makefile
12
Makefile
@ -9,8 +9,16 @@ clean:
|
||||
|
||||
bin:
|
||||
mkdir -p bin
|
||||
build:
|
||||
mkdir -p build
|
||||
|
||||
bin/blang: bin src/*.c
|
||||
$(CC) $(CFLAGS) -o $@ src/*.c
|
||||
build/blang.o: build src/blang.c src/blang.h
|
||||
$(CC) -c -o $@ src/blang.c
|
||||
|
||||
build/ops.o: build src/blang.h src/ops.c src/ops.h
|
||||
$(CC) -c -o $@ src/ops.c
|
||||
|
||||
bin/blang: bin build/blang.o build/ops.o
|
||||
$(CC) $(CFLAGS) -o $@ build/*.o
|
||||
|
||||
.PHONY: all clean
|
||||
|
50
src/blang.c
50
src/blang.c
@ -1,42 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned char get = 0;
|
||||
static unsigned char _stack[4];
|
||||
static unsigned char *stack = _stack;
|
||||
static unsigned char *state;
|
||||
#include "blang.h"
|
||||
#include "ops.h"
|
||||
|
||||
int main(){
|
||||
int main(int argc, char **argv){
|
||||
struct State s;
|
||||
int c;
|
||||
while((c = getchar()) != EOF){
|
||||
if(stack == (unsigned char *)0)
|
||||
return (char)state;
|
||||
if(get){
|
||||
state = (char *)c;
|
||||
get = 0;
|
||||
void (*op)(struct State *);
|
||||
|
||||
s.chart = *argv;
|
||||
|
||||
while((c = getc(stdin)) != EOF){
|
||||
/* proper exit is ^* */
|
||||
if(s.chart == (char *)0)
|
||||
return (int)s.hand;
|
||||
if((op = Ops_lookup(c)) == NULL)
|
||||
continue;
|
||||
else
|
||||
op(&s);
|
||||
}
|
||||
switch(c){
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\v':
|
||||
break;
|
||||
case '!': state = stack; break;
|
||||
case '$': stack = state; state = (char *)*_stack; break;
|
||||
case '%': *stack = (char)state; break;
|
||||
case '^': state = (char *)0; break;
|
||||
case '+': ++state; break;
|
||||
case '-': --state; break;
|
||||
case '>': putchar((char)state); break;
|
||||
case '<': get = 1; break;
|
||||
case ':':
|
||||
while((c = getchar()) != '\n')
|
||||
if(c == EOF)
|
||||
goto fin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fin: return 1;
|
||||
return 1;
|
||||
}
|
||||
|
7
src/blang.h
Normal file
7
src/blang.h
Normal file
@ -0,0 +1,7 @@
|
||||
#if !defined _BLANG_H
|
||||
# define _BLANG_H
|
||||
struct State{
|
||||
unsigned char hand;
|
||||
char *chart;
|
||||
}
|
||||
#endif
|
18
src/ops.c
18
src/ops.c
@ -8,36 +8,36 @@ void Ops_bang(struct State *s){
|
||||
return;
|
||||
}
|
||||
|
||||
void Ops_dollar(struct State *s){
|
||||
s->chart = (char *)0;
|
||||
}
|
||||
|
||||
void Ops_percent(struct State *s){
|
||||
*(s->chart) = s->hand;
|
||||
}
|
||||
|
||||
void Ops_carat(struct State *s){
|
||||
s->state = 0;
|
||||
s->hand = 0;
|
||||
}
|
||||
|
||||
void Ops_ampersand(struct State *s){
|
||||
s->hand = s->chart;
|
||||
}
|
||||
|
||||
void Ops_splat(struct State *s){
|
||||
s->chart = s->hand;
|
||||
}
|
||||
|
||||
void Ops_plus(struct State *s){
|
||||
++(s->state);
|
||||
++(s->hand);
|
||||
}
|
||||
|
||||
void Ops_dash(struct State *s){
|
||||
--(s->state);
|
||||
--(s->hand);
|
||||
}
|
||||
|
||||
void Ops_right(struct State *s){
|
||||
putc((char)s->state, stdout);
|
||||
putc((char)s->hand, stdout);
|
||||
}
|
||||
|
||||
void Ops_left(struct State *s){
|
||||
s->state = getc(stdin);
|
||||
s->hand = getc(stdin);
|
||||
}
|
||||
|
||||
void Ops_semi(struct State *s){
|
||||
|
Loading…
Reference in New Issue
Block a user