Commit 6cd67232 authored by Michael Rouse's avatar Michael Rouse

Some organization of everything. Started with SQLITE

parent a4ffe1f6
*.exe
build/
# Prerequisites
*.d
......
......@@ -3,6 +3,7 @@
"*.tests": "c",
"*.driver": "c",
"stdio.h": "c",
"args.h": "c"
"args.h": "c",
"sqlite3.h": "c"
}
}
\ No newline at end of file
# Time Slime Make File
CC=gcc
CFLAGS=-g -Wall
LANGUAGE_FLAGS=-x c
OUT=timeslime
CC = gcc
CC_FLAGS = -g -Wall
# Files to compile (for all targets)
SOURCES=./src/*.c ./src/args/*.c
BUILD_DIR = build
SHELL_OUT = $(BUILD_DIR)/timeslime
SHELL_SOURCES = shell/shell.c shell/args/args.c
SHELL_HEADERS = shell/args/args.h
LIBRARY_SOURCES = timeslime.c sqlite3.c
LIBRARY_HEADERS = timeslime.h sqlite3.h
all:
$(CC) $(CFLAGS) $(LANGUAGE_FLAGS) $(SOURCES) -o $(OUT)
MKDIR = mkdir
debug:
$(CC) $(CFLAGS) -D DEBUG $(LANGUAGE_FLAGS) $(SOURCES) -o $(OUT)
\ No newline at end of file
ifeq ($(OS),Windows_NT)
RMDIR = cmd /C rmdir /S /Q
else
RMDIR = rmdir -f -r
endif
.PHONY: all
all: build_executable
# Enable debugging output
debug: CC_FLAGS += -DDEBUG
debug: all
build_executable: prep $(LIBRARY_SOURCES) $(LIBRARY_HEADERS) $(SHELL_SOURCES)
@$(CC) $(CC_FLAGS) $(LIBRARY_SOURCES) $(SHELL_SOURCES) -o $(SHELL_OUT)
prep: clean
@$(MKDIR) $(BUILD_DIR)
clean: clean_all
clean_all:
@$(RMDIR) $(BUILD_DIR)
/**
* Wrapper around the timeslime library to allow use from the command line
*/
#include "../timeslime.h"
#include "logger.h"
#include "args/args.h"
/**
* Entry point to the command line interface for Time Slime
*/
int main(int argc, char *argv[])
{
TimeSlime_Initialize("build");
TimeSlime_Close();
return 0;
}
\ No newline at end of file
......@@ -34,5 +34,7 @@
#define PROGRAM_VERSION "2018.08.14"
#define DATABASE_FILE "timeslime.db"
#define DATABASE_TABLE "meow"
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/**
* Time Slime - Command Line Time Sheet
*
* Authors: Michael Rouse
*/
#ifndef __TIME_SLIME_H__
#define __TIME_SLIME_H__
#include <stdlib.h>
#include <string.h>
#include "args/args.h"
#include "logger.h"
#include "string_literals.h"
/* Add to the time sheet */
void perform_add_action(timeslime_args args);
/* Clock In or Out */
void perform_clock_action(timeslime_args args);
/* Show time worked for a period of time */
void perform_report_action(timeslime_args args);
/* Displays the help screen */
void display_help(void);
#endif
\ No newline at end of file
......@@ -4,16 +4,111 @@
* Authors: Michael Rouse
*/
#include "timeslime.h"
#include "sqlite3.h"
static sqlite3 *db;
static char *database_file_path;
/*
void setup_database(void)
{
int rc;
rc = sqlite3_open(DATABASE_FILE, &db);
printf("Yay!\n");
char *sql;
sql = "CREATE TABLE meow(" \
"ID INTEGER PRIMARY KEY AUTOINCREMENT," \
"StartTime DATETIME NOT NULL," \
"EndTime DATETIME, " \
"Hours REAL" \
")";
char *zErrMsg = 0;
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
} else {
fprintf(stdout, "Table created successfully\n");
}
}*/
/*
* Initializes the Time Slime library
*/
TIMESLIME_STATUS_t TimeSlime_Initialize(char directory_for_database[])
{
// Generate path for database file
database_file_path = malloc((strlen(directory_for_database) + strlen("\\timeslime.db")) * sizeof(char));
if (database_file_path == NULL)
return TIMESLIME_UNKOWN_ERROR;
sprintf(database_file_path, "%s\\%s", directory_for_database, "timeslime.db"); // Append the file name
// Create database if it doesn't exist
db = NULL;
int rc = sqlite3_open(database_file_path, &db);
if (rc != SQLITE_OK)
return TIMESLIME_SQLITE_ERROR;
return TIMESLIME_OK;
}
/* Safely close out of the Time Slime library */
TIMESLIME_STATUS_t TimeSlime_Close(void)
{
if (db != NULL)
sqlite3_close(db);
if (database_file_path != NULL)
{
free(database_file_path);
database_file_path = NULL;
}
return TIMESLIME_OK;
}
/* Add to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_Add(int hours, int year, int month, int day)
{
return TIMESLIME_OK;
}
/* Clock in to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockIn(int year, int month, int day, int hour, int minute)
{
return TIMESLIME_OK;
}
/* Clock out of the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockOut(int year, int month, int day, int hour, int minute)
{
return TIMESLIME_OK;
}
/**
* Entry point for program, parsed arguments and
* acts according to the arguments
*/
int main(int argc, char *argv[])
*
int main2(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++)
log_dull(argv[i]);
log_dull("==== Time Slime ====\n")
setup_database();
timeslime_args parsed_args;
parsed_args = parse_args(argc, argv);
......@@ -33,7 +128,7 @@ int main(int argc, char *argv[])
perform_report_action(parsed_args);
}
sqlite3_close(db);
printf("\n");
return 0;
}
......@@ -41,7 +136,7 @@ int main(int argc, char *argv[])
/**
* Add to the time sheet
*/
*
void perform_add_action(timeslime_args args)
{
if (args.modifier1 == NULL)
......@@ -71,7 +166,7 @@ void perform_add_action(timeslime_args args)
}
/* Clock in and clock out of the time sheet */
/* Clock in and clock out of the time sheet *
void perform_clock_action(timeslime_args args)
{
if (args.modifier1 == NULL)
......@@ -92,7 +187,7 @@ void perform_clock_action(timeslime_args args)
log_info("Clocking %s", direction);
}
/* Show all time worked */
/* Show all time worked *
void perform_report_action(timeslime_args args)
{
if (args.modifier1 == NULL)
......@@ -131,7 +226,7 @@ void perform_report_action(timeslime_args args)
}
/* Help Screen */
/* Help Screen *
void display_help(void)
{
printf("Author: %s\n", AUTHOR);
......@@ -161,4 +256,13 @@ void display_help(void)
printf("\t%s report YYYY/MM/DDD YYYY/MM/DDD\n", PROGRAM_NAME);
printf("\n");
}
\ No newline at end of file
}
static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
*/
\ No newline at end of file
/**
* Time Slime - Command Line Time Sheet
*
* Authors: Michael Rouse
*/
#ifndef __TIME_SLIME_H__
#define __TIME_SLIME_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Datatypes */
typedef int TIMESLIME_STATUS_t;
/* Constants */
/* These are used when you want to use the current date */
#define TIMESLIME_NOW 0, 0, 0
#define TIMESLIME_CLOCK_IN_NOW TIMESLIME_NOW, 0, 0
#define TIMESLIME_CLOCK_OUT_NOW TIMESLIME_NOW, 0, 0
/* Result Codes */
#define TIMESLIME_OK 0
#define TIMESLIME_UNKOWN_ERROR 100
#define TIMESLIME_SQLITE_ERROR 50
#define TIMESLIME_INVALID_YEAR 10
#define TIMESLIME_INVALID_MONTH 11
#define TIMESLIME_INVALID_DAY 12
#define TIMESLIME_INVALID_HOUR 13
#define TIMESLIME_INVALID_MINUTE 14
/* Initialize the Time Slime library */
TIMESLIME_STATUS_t TimeSlime_Initialize(char directory_for_database[]);
/* Safely close out of the Time Slime library */
TIMESLIME_STATUS_t TimeSlime_Close(void);
/* Add to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_Add(int hours, int year, int month, int day);
/* Clock in to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockIn(int year, int month, int day, int hour, int minute);
/* Clock out of the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockOut(int year, int month, int day, int hour, int minute);
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment