Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
T
time-slime
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Michael Rouse
time-slime
Commits
0c80cd80
Commit
0c80cd80
authored
Aug 19, 2018
by
Michael Rouse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More features from the command line
parent
d7a09e07
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
67 deletions
+91
-67
shell/args/args.c
shell/args/args.c
+12
-11
shell/args/args.h
shell/args/args.h
+11
-14
shell/shell.c
shell/shell.c
+50
-35
shell/string_literals.h
shell/string_literals.h
+1
-1
timeslime.c
timeslime.c
+17
-6
No files found.
shell/args/args.c
View file @
0c80cd80
#include "args.h"
#include "../string_literals.h"
#include "../logger.h"
timeslime_args
parse_args
(
int
argc
,
char
**
argv
)
args_t
args_parse
(
int
argc
,
char
**
argv
)
{
// Copy the arguments
char
**
args
=
NULL
;
...
...
@@ -13,8 +14,8 @@ timeslime_args parse_args(int argc, char **argv)
int
num_args
=
argc
-
1
;
// Adjust because the filename was dropped
// Create parsed args result and set defaults
timeslime_args
result
;
result
.
help
=
False
;
args_t
result
;
result
.
help
=
ARGS_
False
;
result
.
error
=
0
;
result
.
action
=
NULL
;
result
.
modifier1
=
NULL
;
...
...
@@ -26,7 +27,7 @@ timeslime_args parse_args(int argc, char **argv)
result
.
action
=
args
[
0
];
if
(
strcmp
(
HELP_ACTION
,
args
[
0
])
==
0
)
{
result
.
help
=
True
;
result
.
help
=
ARGS_
True
;
return
result
;
// Nothing else matters
}
...
...
@@ -48,12 +49,12 @@ timeslime_args parse_args(int argc, char **argv)
#define DAY 2
/* Parse a date */
timeslime_date
parse_date
(
char
*
dateStr
)
date_t
args_
parse_date
(
char
*
dateStr
)
{
log_debug
(
"Parsing Date: %s"
,
dateStr
);
timeslime_date
date
;
date
.
error
=
False
;
date_t
date
;
date
.
error
=
ARGS_
False
;
date
.
month
=
0
;
date
.
day
=
0
;
date
.
year
=
0
;
...
...
@@ -76,7 +77,7 @@ timeslime_date parse_date(char *dateStr)
if
(
tmp
<
1000
)
{
log_error
(
"Invalid year, %d; dates must be in the format YYYY/MM/DD"
,
tmp
);
date
.
error
=
True
;
date
.
error
=
ARGS_
True
;
return
date
;
}
...
...
@@ -88,7 +89,7 @@ timeslime_date parse_date(char *dateStr)
if
(
tmp
<
1
||
tmp
>
12
)
{
log_error
(
"Invalid month, %d; dates must be in the format YYYY/MM/DD"
,
tmp
);
date
.
error
=
True
;
date
.
error
=
ARGS_
True
;
return
date
;
}
...
...
@@ -100,7 +101,7 @@ timeslime_date parse_date(char *dateStr)
if
(
tmp
<
1
||
tmp
>
31
)
{
log_error
(
"Invalid day, %d; dates must be in the format YYYY/MM/DD"
,
tmp
);
date
.
error
=
True
;
date
.
error
=
ARGS_
True
;
return
date
;
}
...
...
shell/args/args.h
View file @
0c80cd80
...
...
@@ -4,36 +4,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../logger.h"
#include "../string_literals.h"
#define ARGS_False 0
#define ARGS_True 1
typedef
char
args_bool_t
;
#define False 0
#define True 1
typedef
char
bool
;
typedef
struct
_timeslime_args_t
{
bool
help
;
typedef
struct
_args_t
{
args_bool_t
help
;
char
*
action
;
char
*
modifier1
;
char
*
modifier2
;
char
*
modifier3
;
int
error
;
}
timeslime_args
;
}
args_t
;
typedef
struct
_
timeslime_
date_t
{
bool
error
;
typedef
struct
_date_t
{
args_bool_t
error
;
int
month
;
int
day
;
int
year
;
char
str
[
256
];
}
timeslime_date
;
}
date_t
;
/* Parse the command line arguments */
timeslime_args
parse_args
(
int
argc
,
char
**
argv
);
args_t
args_parse
(
int
argc
,
char
**
argv
);
/* Parse into a date */
timeslime_date
parse_date
(
char
*
date
);
date_t
args_
parse_date
(
char
*
date
);
#endif
\ No newline at end of file
shell/shell.c
View file @
0c80cd80
...
...
@@ -4,66 +4,61 @@
#include "../timeslime.h"
#include "logger.h"
#include "args/args.h"
#include "string_literals.h"
static
TIMESLIME_STATUS_t
status
;
static
void
perform_add_action
(
args_t
args
);
static
void
perform_clock_action
(
args_t
args
);
/**
* Entry point to the command line interface for Time Slime
*/
int
main
(
int
argc
,
char
*
argv
[])
{
TimeSlime_Initialize
(
"build"
);
return
0
;
}
/**
* Entry point for program, parsed arguments and
* acts according to the arguments
*
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();
status
=
TimeSlime_Initialize
(
"build"
);
if
(
status
!=
TIMESLIME_OK
)
{
printf
(
"An error occured: %d
\n
"
,
status
);
return
-
1
;
}
timeslime_args parsed_args;
parsed_args = parse_args(argc, argv);
// Parse command line arguments
args_t
parsed_args
;
parsed_args
=
args_parse
(
argc
,
argv
);
if
(
parsed_args
.
help
)
{
display_help();
//
display_help();
}
else
{
else
{
if
(
strcmp
(
parsed_args
.
action
,
ADD_ACTION
)
==
0
)
perform_add_action
(
parsed_args
);
else
if
(
strcmp
(
parsed_args
.
action
,
CLOCK_ACTION
)
==
0
)
perform_clock_action
(
parsed_args
);
else if (strcmp(parsed_args.action, REPORT_ACTION) == 0)
perform_report_action(parsed_args);
//else if (strcmp(parsed_args.action, REPORT_ACTION) == 0)
// perform_report_action(parsed_args);
if
(
status
!=
TIMESLIME_OK
)
{
printf
(
"Error: %d
\n
"
,
status
);
}
}
sqlite3_close(db
);
printf("\n");
TimeSlime_Close
(
);
return
0
;
}
/**
* Add to the time sheet
*
void perform_add_action(timeslime_args
args)
*
/
static
void
perform_add_action
(
args_t
args
)
{
if
(
args
.
modifier1
==
NULL
)
{
...
...
@@ -89,11 +84,23 @@ void perform_add_action(timeslime_args args)
// Show message for what is about to happen
log_info
(
"Adding %.2f hour(s) to the time sheet for %s"
,
toAdd
,
date
);
}
if
(
strcmp
(
date
,
TODAY
)
==
0
)
{
status
=
TimeSlime_AddHours
(
toAdd
,
TIMESLIME_DATE_NOW
);
}
else
{
date_t
parsed
=
args_parse_date
(
date
);
if
(
!
parsed
.
error
)
{
status
=
TimeSlime_AddHours
(
toAdd
,
parsed
.
year
,
parsed
.
month
,
parsed
.
day
);
}
}
}
/* Clock in and clock out of the time sheet *
void perform_clock_action(timeslime_args
args)
/* Clock in and clock out of the time sheet *
/
static
void
perform_clock_action
(
args_t
args
)
{
if
(
args
.
modifier1
==
NULL
)
{
...
...
@@ -111,6 +118,14 @@ void perform_clock_action(timeslime_args args)
// Show message for what is about to happen
log_info
(
"Clocking %s"
,
direction
);
if
(
strcmp
(
direction
,
CLOCK_IN
)
==
0
)
{
status
=
TimeSlime_ClockIn
(
TIMESLIME_CLOCK_IN_NOW
);
}
else
{
status
=
TimeSlime_ClockOut
(
TIMESLIME_CLOCK_OUT_NOW
);
}
}
/* Show all time worked *
...
...
shell/string_literals.h
View file @
0c80cd80
...
...
@@ -20,7 +20,7 @@
/* Misc. */
#define TODAY "
T
oday"
#define TODAY "
t
oday"
#define CLOCK_IN "in"
#define CLOCK_OUT "out"
...
...
timeslime.c
View file @
0c80cd80
...
...
@@ -53,14 +53,18 @@ TIMESLIME_STATUS_t TimeSlime_Initialize(char directory_for_database[])
sprintf
(
database_file_path
,
"%s
\\
%s"
,
directory_for_database
,
"timeslime.db"
);
// Append the file name
// Create database if it doesn't exist
int
rc
=
sqlite3_open
(
database_file_path
,
&
db
);
int
rc
;
rc
=
sqlite3_open
(
database_file_path
,
&
db
);
if
(
rc
!=
SQLITE_OK
)
{
return
TIMESLIME_SQLITE_ERROR
;
}
// Initialize the results array
database_results
=
malloc
(
TIMESLIME_DEFAULT_RESULT_LIMIT
*
sizeof
(
TIMESLIME_INTERNAL_ROW_t
*
));
if
(
database_results
==
NULL
)
return
TIMESLIME_UNKOWN_ERROR
;
result_array_size
=
TIMESLIME_DEFAULT_RESULT_LIMIT
;
int
i
;
for
(
i
=
0
;
i
<
result_array_size
;
i
++
)
...
...
@@ -75,8 +79,15 @@ TIMESLIME_STATUS_t TimeSlime_Initialize(char directory_for_database[])
*/
TIMESLIME_STATUS_t
TimeSlime_Close
(
void
)
{
int
rc
;
if
(
db
!=
NULL
)
sqlite3_close
(
db
);
{
rc
=
sqlite3_close
(
db
);
if
(
rc
!=
SQLITE_OK
)
{
printf
(
"SQLITE CLOSING ERROR: %d
\n
"
,
rc
);
}
}
if
(
database_file_path
!=
NULL
)
{
...
...
@@ -214,7 +225,7 @@ static TIMESLIME_STATUS_t _TimeSlime_CreateTables(void)
char
*
sql
;
// Create time sheet table
sql
=
"CREATE TABLE TimeSheet("
\
sql
=
"CREATE TABLE
IF NOT EXISTS
TimeSheet("
\
"ID INTEGER PRIMARY KEY AUTOINCREMENT,"
\
"HoursAdded REAL NOT NULL DEFAULT 0,"
\
"HoursAddedDate DATE DEFAULT NULL,"
\
...
...
@@ -223,9 +234,9 @@ static TIMESLIME_STATUS_t _TimeSlime_CreateTables(void)
"CreationTime DATETIME DEFAULT (DATETIME('now', 'localtime')), "
\
"LastUpdateTime DATETIME DEFAULT (DATETIME('now', 'localtime'))"
\
"); "
\
"CREATE INDEX HoursAdded_Index ON TimeSheet (HoursAddedDate);"
\
"CREATE INDEX ClockIn_Index ON TimeSheet (ClockInTime);"
\
"CREATE INDEX ClockOut_Index ON TimeSheet (ClockOutTime);"
;
"CREATE INDEX
IF NOT EXISTS
HoursAdded_Index ON TimeSheet (HoursAddedDate);"
\
"CREATE INDEX
IF NOT EXISTS
ClockIn_Index ON TimeSheet (ClockInTime);"
\
"CREATE INDEX
IF NOT EXISTS
ClockOut_Index ON TimeSheet (ClockOutTime);"
;
rc
=
sqlite3_exec
(
db
,
sql
,
NULL
,
0
,
&
errMsg
);
if
(
rc
!=
SQLITE_OK
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment