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