mrrrp
This commit is contained in:
parent
f7dd2dd766
commit
07c7f6df35
16
amogus.h
16
amogus.h
|
@ -1 +1,15 @@
|
|||
int entry(char* regex, char** output);
|
||||
// int entry(...)
|
||||
//
|
||||
// Parse regex. Find matching string.
|
||||
// If found:
|
||||
// call callback(
|
||||
// matched string (only valid before callback return),
|
||||
// length of the string including NUL delimiter,
|
||||
// data passed in the data argument
|
||||
// )
|
||||
// return 0
|
||||
// Else:
|
||||
// return 1
|
||||
|
||||
typedef void (entry_callback)(char* match, int size, void* data);
|
||||
int entry(char* regex, entry_callback *callback, void *data);
|
||||
|
|
22
meow.s
22
meow.s
|
@ -10,11 +10,11 @@ _start:
|
|||
pop %rax
|
||||
mov %rax,argv(%rip)
|
||||
cmp $1,%rdi
|
||||
jg endif
|
||||
jg _start_endif
|
||||
mov $1,%rdi
|
||||
call usage
|
||||
jmp _exit
|
||||
endif:
|
||||
_start_endif:
|
||||
|
||||
mov $0,%rdi
|
||||
jmp _exit
|
||||
|
@ -58,17 +58,33 @@ write:
|
|||
mov $1,%rdi
|
||||
syscall
|
||||
ret
|
||||
|
||||
help0:
|
||||
.ascii "Usage: "
|
||||
.set help0l, .-help0
|
||||
help1:
|
||||
.ascii " regex0 [regex1 ...]\nstdout: NUL-separated list of matching strings\n"
|
||||
.set help1l, .-help1
|
||||
|
||||
# rdi - exit code
|
||||
_exit:
|
||||
mov $0x3c,%rax
|
||||
syscall
|
||||
ret
|
||||
|
||||
entry:
|
||||
push %r12
|
||||
sub $8,%r12
|
||||
mov %rsp,%r12
|
||||
entry_parse_begin:
|
||||
test %rdi,%rdi
|
||||
jnz entry_parse_end
|
||||
mov %rdi,%rcx
|
||||
inc %rdi
|
||||
entry_parse_end:
|
||||
mov %r12,%rsp
|
||||
add $8,%r12
|
||||
pop %r12
|
||||
ret
|
||||
|
||||
.bss
|
||||
|
@ -76,5 +92,3 @@ argc:
|
|||
.zero 8
|
||||
argv:
|
||||
.zero 8
|
||||
buf:
|
||||
.zero 65536
|
||||
|
|
10
test.c
10
test.c
|
@ -1,9 +1,17 @@
|
|||
#include <amogus.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
void callback(char* str, int size, void* data) {
|
||||
char** out = (char**)data;
|
||||
*out = (char*)malloc(size);
|
||||
memcpy(str, *out, size);
|
||||
}
|
||||
|
||||
int main() {
|
||||
char* match;
|
||||
if(!entry("meow.*|m(r(r(p..*)))",&match))
|
||||
if(!entry("meow.*|m(r(r(p..*)))",callback,&match))
|
||||
return 1;
|
||||
printf("%s",match);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue