Compare commits
3 Commits
c5f8f95059
...
0fe401d0a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fe401d0a7 | |||
| a356913c39 | |||
| a371b6ebb0 |
+1
-1
@@ -1,3 +1,3 @@
|
||||
cescal
|
||||
/cescal
|
||||
*.o
|
||||
*.d
|
||||
|
||||
@@ -23,3 +23,7 @@ cescal: $(OFILES)
|
||||
-include $(DFILES)
|
||||
%.o: %.c
|
||||
$(CC) -c $< $(CFLAGS) -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(OFILES) $(DFILES)
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "cescal/state.h"
|
||||
#include "cescal/log.h"
|
||||
|
||||
static void
|
||||
help(void)
|
||||
@@ -37,7 +38,7 @@ main(int argc, char **argv)
|
||||
int opt;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("fatal: too few arguments\n");
|
||||
cc_error("too few arguments\n");
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_LOG_H
|
||||
#define CESCAL_LOG_H 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define cc_trace(fmt, ...) \
|
||||
printf("[\033[34;40mtrace\033[0m]: ", ##__VA_ARGS__)
|
||||
#define cc_error(fmt, ...) \
|
||||
printf("[\033[31;40merror\033[0m]: ", ##__VA_ARGS__)
|
||||
|
||||
#endif /* !CESCAL_LOG_H */
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_READBUF_H
|
||||
#define CESCAL_READBUF_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define READBUF_CAP 128
|
||||
|
||||
/*
|
||||
* Represents a read buffer that reduces system call
|
||||
* overhead.
|
||||
*
|
||||
* @buf: Read buffer
|
||||
* @size: Total populated size of offer
|
||||
* @tail: Tail pointer from start of buffer
|
||||
*/
|
||||
struct readbuf {
|
||||
char buf[READBUF_CAP];
|
||||
size_t size;
|
||||
size_t tail;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize a read buffer
|
||||
*
|
||||
* @rb: Readbuffer to initialize
|
||||
*
|
||||
* Returns zero on success
|
||||
*/
|
||||
int readbuf_init(struct readbuf *rb);
|
||||
|
||||
/*
|
||||
* Read from a read buffer and populate if needed
|
||||
*
|
||||
* @rb: Target readbuffer
|
||||
* @fd: File descriptor to read from
|
||||
*
|
||||
* Returns the character read on success, '\0' on
|
||||
* failure.
|
||||
*/
|
||||
char readbuf_read(struct readbuf *rb, int fd);
|
||||
|
||||
#endif /* !CESCAL_READBUF_H */
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause
|
||||
*/
|
||||
|
||||
#ifndef CESCAL_STATE_H
|
||||
#define CESCAL_STATE_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cescal/readbuf.h"
|
||||
|
||||
/*
|
||||
* Compiler state machine
|
||||
*
|
||||
* @in_fd: Input file descriptor
|
||||
* @rb: Read buffer
|
||||
*/
|
||||
struct cescal_state {
|
||||
int in_fd;
|
||||
struct readbuf rb;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize the compiler state machine
|
||||
*
|
||||
* @state: Compiler state machine
|
||||
* @pathname: Path of input source file
|
||||
*
|
||||
* Returns zero on success
|
||||
*/
|
||||
int state_init(struct cescal_state *state, const char *pathname);
|
||||
|
||||
/*
|
||||
* Close the compiler state machine
|
||||
*
|
||||
* @state: Compiler state machine to close
|
||||
*/
|
||||
void state_close(struct cescal_state *state);
|
||||
|
||||
#endif /* !CESCAL_STATE_H */
|
||||
Reference in New Issue
Block a user