some libs done
This commit is contained in:
10
Makefile
10
Makefile
@@ -1,13 +1,10 @@
|
||||
prefix = /usr/bin
|
||||
|
||||
YAIT_SRCS := $(wildcard yait/*.c)
|
||||
YAIT_DOC_SRCS := $(wildcard yait-doc/*.c)
|
||||
|
||||
YAIT_OBJS := $(patsubst yait/%.c,obj/yait/%.o,$(YAIT_SRCS))
|
||||
YAIT_DOC_OBJS := $(patsubst yait-doc/%.c,obj/yait-doc/%.o,$(YAIT_DOC_SRCS))
|
||||
|
||||
YAIT := bin/yait
|
||||
YAIT_DOC := bin/yait-doc
|
||||
|
||||
-include config.mak
|
||||
|
||||
@@ -20,7 +17,7 @@ else
|
||||
all: obj bin $(YAIT) $(YAIT_DOC)
|
||||
|
||||
obj:
|
||||
mkdir -p obj/yait obj/yait-doc
|
||||
mkdir -p obj/yait
|
||||
|
||||
bin:
|
||||
mkdir -p bin
|
||||
@@ -28,14 +25,9 @@ bin:
|
||||
obj/yait/%.o: yait/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
obj/yait-doc/%.o: yait-doc/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(YAIT): $(YAIT_OBJS)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(YAIT_DOC): $(YAIT_DOC_OBJS)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
endif
|
||||
|
||||
|
||||
9
lib/e.h
Normal file
9
lib/e.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ERROR_H
|
||||
#define ERROR_H
|
||||
|
||||
typedef struct {
|
||||
int stat;
|
||||
const char *src;
|
||||
} error_t;
|
||||
|
||||
#endif
|
||||
22
lib/file.c
Normal file
22
lib/file.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "file.h"
|
||||
#include "e.h"
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
error_t write(char *path, char *format, ...) {
|
||||
error_t err;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
FILE *fp;
|
||||
fp = fopen(path, "w");
|
||||
if (!fp) {
|
||||
err.stat = errno;
|
||||
err.src = strerror(errno);
|
||||
}
|
||||
vfprintf(fp, format, args);
|
||||
fclose(fp);
|
||||
va_end(args);
|
||||
return err;
|
||||
}
|
||||
9
lib/file.h
Normal file
9
lib/file.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
#include "e.h"
|
||||
|
||||
error_t write(char *, char *, ...);
|
||||
void printfn(char *, ...);
|
||||
|
||||
#endif
|
||||
14
lib/print.c
Normal file
14
lib/print.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "print.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int printfn(char *format, ...) {
|
||||
int len;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
printf("yait: ");
|
||||
len = vfprintf(stderr, format, args);
|
||||
putchar('\n');
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
9
lib/print.h
Normal file
9
lib/print.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int printfn(char *, ...);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello, Yait-doc!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello, Yait!\n");
|
||||
printf("Hello, Yait!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user