Added Makefile
This commit is contained in:
parent
134037bfde
commit
3a86a83f54
Binary file not shown.
31095
sqlite3/shell.c
Normal file
31095
sqlite3/shell.c
Normal file
File diff suppressed because it is too large
Load Diff
257673
sqlite3/sqlite3.c
Normal file
257673
sqlite3/sqlite3.c
Normal file
File diff suppressed because it is too large
Load Diff
13425
sqlite3/sqlite3.h
Normal file
13425
sqlite3/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
16
src/Makefile
Normal file
16
src/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
.POSIX:
|
||||||
|
|
||||||
|
SRC = dodo.c sqlite3.c x_string.c
|
||||||
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
|
all: dodo
|
||||||
|
|
||||||
|
$(OBJ):
|
||||||
|
|
||||||
|
dodo: $(OBJ)
|
||||||
|
$(CC) -o $@ $(OBJ)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f dodo $(OBJ)
|
||||||
|
|
||||||
|
.PHONY: clean
|
4
src/config.h
Normal file
4
src/config.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef DB_PATH
|
||||||
|
#define DB_PATH "db.db"
|
||||||
|
#endif
|
||||||
|
|
36
src/dodo.c
Normal file
36
src/dodo.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "sqlite3.h"
|
||||||
|
#include "x_string.h"
|
||||||
|
|
||||||
|
#define HOME_DIR "HOME"
|
||||||
|
#define DB_DIR "/current_projects/dodo/db/"
|
||||||
|
#define FILENAME "db.db"
|
||||||
|
|
||||||
|
int initdb(sqlite3 *db, char* filename){
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
rc = sqlite3_open(filename, &db);
|
||||||
|
|
||||||
|
if ( rc != 0 ){
|
||||||
|
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
|
||||||
|
sqlite3_close(db);
|
||||||
|
return(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv ){
|
||||||
|
sqlite3 *db;
|
||||||
|
char* home_dir = getenv(HOME_DIR);
|
||||||
|
char* filename = x_strconcat(home_dir, DB_DIR);
|
||||||
|
|
||||||
|
filename = x_strconcat(filename, FILENAME);
|
||||||
|
initdb(db, filename);
|
||||||
|
|
||||||
|
puts(filename);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
257673
src/sqlite3.c
Normal file
257673
src/sqlite3.c
Normal file
File diff suppressed because it is too large
Load Diff
13425
src/sqlite3.h
Normal file
13425
src/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
12
src/test.c
12
src/test.c
@ -1,12 +0,0 @@
|
|||||||
#include "sqlite3.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main( int argc, char **argv ){
|
|
||||||
sqlite3 *db;
|
|
||||||
char* filename = "test.db";
|
|
||||||
int rc = sqlite3_open(filename, &db);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
43
src/x_string.c
Normal file
43
src/x_string.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int x_strlen(char* str){
|
||||||
|
char* ptr = str;
|
||||||
|
while(*ptr != '\0'){
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
return ptr - str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void x_strcpy(char* dest, char* src, const int size_dest){
|
||||||
|
char* dest_ptr = dest;
|
||||||
|
char* src_ptr = src;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while(*src_ptr != '\0'){
|
||||||
|
if (i >= size_dest){
|
||||||
|
fprintf(stderr, "Error: x_strcpy\nSource string exeeds destination memory\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
*dest_ptr = *src_ptr;
|
||||||
|
dest_ptr++;
|
||||||
|
src_ptr++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char* x_strconcat(char* str1, char* str2){
|
||||||
|
|
||||||
|
char* new_string;
|
||||||
|
|
||||||
|
int len1 = x_strlen(str1);
|
||||||
|
int len2 = x_strlen(str2);
|
||||||
|
int new_length = len1 + len2;
|
||||||
|
|
||||||
|
new_string = malloc( sizeof(*new_string) * new_length );
|
||||||
|
x_strcpy(new_string, str1, new_length);
|
||||||
|
x_strcpy(&new_string[len1], str2, new_length - len1);
|
||||||
|
|
||||||
|
return new_string;
|
||||||
|
}
|
8
src/x_string.h
Normal file
8
src/x_string.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef X_STRING_H
|
||||||
|
#define X_STRING_H
|
||||||
|
|
||||||
|
int x_strlen(char*);
|
||||||
|
void x_strcpy(char*, char*, const int);
|
||||||
|
char* x_strconcat(char*, char*);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user