Added LICENSE file and copyright notices; more general cleanup before

releasing it into the wild
This commit is contained in:
Mike Dvorkin
2010-08-21 15:24:23 -07:00
parent 255e5daaa1
commit 306abfa7f6
22 changed files with 342 additions and 74 deletions

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -7,11 +18,11 @@ static void action_list()
{
pit_db_load();
if (actions->number_of_records > 0) {
PFormat pf = pit_pager_initialize(PAGER_ACTION, 0, actions->number_of_records);
PFormat pf = pit_format_initialize(FORMAT_ACTION, 0, actions->number_of_records);
for_each_action(pa) {
pit_pager_print(pf, (char *)pa);
pit_format(pf, (char *)pa);
}
pit_pager_flush(pf);
pit_format_flush(pf);
}
}

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -14,7 +25,7 @@ int pit_arg_option(char **arg)
if (pit_arg_is_option(arg)) {
return *(*arg + 1);
} else {
die("invalid option");
die("invalid option: %s", *arg);
return 0;
}
}
@@ -95,7 +106,7 @@ time_t pit_arg_date(char **arg, char *required)
if (required && (!*arg || pit_arg_is_option(arg))) {
die("missing %s", required);
} else if (!strcmp(*arg, "none")) { /* Drop dat value */
} else if (!strcmp(*arg, "none")) { /* Drop date value */
return -1;
} else {
bool alpha_date = isalpha(**arg);
@@ -113,7 +124,7 @@ time_t pit_arg_date(char **arg, char *required)
strcpy(format, "%m/%d/%Y %H:%M"); /* 10/10/1992 19:30 */
}
} else {
if (strlen(*arg) >= 12) {
if (strlen(*arg) >= 12) { /* TODO: this is too simplistic... */
if (alpha_date) {
strcpy(format, "%b %d, %Y %H"); /* Oct 10, 1992 19 */
} else {
@@ -142,17 +153,17 @@ time_t pit_arg_date(char **arg, char *required)
adjust_time(arg, format); /* Replace %H with %I%p for am/pm time */
/* Ready to roll :-) */
// printf("format: %s\n", format);
/* printf("format: %s\n", format); */
if (strptime(*arg, format, &tm)) {
// printf("then: %s\n", asctime(&tm));
/* printf("then: %s\n", asctime(&tm)); */
if (!tm.tm_mday) tm.tm_mday = ptm->tm_mday;
if (!tm.tm_mon) tm.tm_mon = ptm->tm_mon;
if (!tm.tm_year) tm.tm_year = ptm->tm_year;
tm.tm_isdst = -1;
// printf(" now: %s\n", asctime(ptm));
// printf(" adj: %s\n", asctime(&tm));
/* printf(" now: %s\n", asctime(ptm)); */
/* printf(" adj: %s\n", asctime(&tm)); */
seconds = mktime(&tm);
// printf("ctime: %s", ctime(&seconds));
/* printf("ctime: %s", ctime(&seconds)); */
if (seconds == (time_t)-1) {
perish("invalid date");
}

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -144,11 +155,11 @@ static void print_tasks_with_date_and_time(PFormat pf)
}
}
PFormat pit_pager_initialize(int type, int indent, int number_of_entries)
PFormat pit_format_initialize(int type, int indent, int number_of_entries)
{
PFormat pf = calloc(1, sizeof(Pager));
PFormat pf = calloc(1, sizeof(Format));
memset(pf, 0, sizeof(Pager));
memset(pf, 0, sizeof(Format));
pf->type = type;
pf->indent = indent;
pf->entries = calloc(number_of_entries + 1, sizeof(char *));
@@ -156,7 +167,7 @@ PFormat pit_pager_initialize(int type, int indent, int number_of_entries)
return pf;
}
void pit_pager_print(PFormat pf, char *entry)
void pit_format(PFormat pf, char *entry)
{
char str[32];
@@ -165,14 +176,14 @@ void pit_pager_print(PFormat pf, char *entry)
for_each_entry(pf, pentry) {
switch(pf->type) {
case PAGER_PROJECT:
case FORMAT_PROJECT:
sprintf(str, "%d", PROJECT(id));
pf->max.project.id = max(pf->max.project.id, strlen(str));
pf->max.project.username = max(pf->max.project.username, strlen(PROJECT(username)));
pf->max.project.name = max(pf->max.project.name, strlen(PROJECT(name)));
pf->max.project.status = max(pf->max.project.status, strlen(PROJECT(status)));
break;
case PAGER_TASK:
case FORMAT_TASK:
sprintf(str, "%d", TASK(id));
pf->max.task.id = max(pf->max.task.id, strlen(str));
pf->max.task.username = max(pf->max.task.username, strlen(TASK(username)));
@@ -186,25 +197,25 @@ void pit_pager_print(PFormat pf, char *entry)
pf->max.task.time = max(pf->max.task.time, strlen(format_time(TASK(time))));
}
break;
case PAGER_NOTE:
case FORMAT_NOTE:
sprintf(str, "%d", NOTE(id));
pf->max.note.id = max(pf->max.note.id, strlen(str));
pf->max.note.username = max(pf->max.note.username, strlen(NOTE(username)));
break;
case PAGER_ACTION:
case FORMAT_ACTION:
pf->max.action.username = max(pf->max.action.username, strlen(ACTION(username)));
pf->max.action.message = max(pf->max.action.message, strlen(ACTION(message)));
break;
default:
die("invalid pager type: %d\n", pf->type);
die("invalid format: %d\n", pf->type);
}
}
}
void pit_pager_flush(PFormat pf)
void pit_format_flush(PFormat pf)
{
switch(pf->type) {
case PAGER_TASK:
case FORMAT_TASK:
if (!pf->max.task.date && !pf->max.task.time) {
print_tasks(pf); /* Neither date nor time. */
} else if (pf->max.task.date) {
@@ -218,26 +229,26 @@ void pit_pager_flush(PFormat pf)
}
break;
case PAGER_PROJECT:
case FORMAT_PROJECT:
print_projects(pf);
break;
case PAGER_ACTION:
case FORMAT_ACTION:
print_actions(pf);
break;
case PAGER_NOTE:
case FORMAT_NOTE:
print_notes(pf);
break;
default:
pit_pager_free(pf);
die("invalid pager type: %d\n", pf->type);
pit_format_free(pf);
die("invalid format: %d\n", pf->type);
}
pit_pager_free(pf);
pit_format_free(pf);
}
void pit_pager_free(PFormat pf)
void pit_format_free(PFormat pf)
{
free(pf->entries);
free(pf);

View File

@@ -1,12 +1,23 @@
#if !defined(__PAGER_H__)
#define __PAGER_H__
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#if !defined(__FORMAT_H__)
#define __FORMAT_H__
#define PAGER_ACTION 1
#define PAGER_PROJECT 2
#define PAGER_TASK 4
#define PAGER_NOTE 8
#define FORMAT_ACTION 1
#define FORMAT_PROJECT 2
#define FORMAT_TASK 4
#define FORMAT_NOTE 8
typedef struct _Pager {
typedef struct _Format {
int type;
int indent;
int number_of_entries;
@@ -36,11 +47,11 @@ typedef struct _Pager {
int username;
} note;
} max;
} Pager, *PFormat;
} Format, *PFormat;
PFormat pit_pager_initialize(int type, int indent, int number_of_entries);
void pit_pager_print(PFormat pf, char *entry);
void pit_pager_flush(PFormat pf);
void pit_pager_free(PFormat pf);
PFormat pit_format_initialize(int type, int indent, int number_of_entries);
void pit_format(PFormat pf, char *entry);
void pit_format_flush(PFormat pf);
void pit_format_free(PFormat pf);
#endif

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -115,14 +126,14 @@ void pit_note_list(PTask pt)
if (!notes) pit_db_load();
if (notes->number_of_records > 0) {
PFormat pf = pit_pager_initialize(PAGER_NOTE, pt ? 4 : 0, notes->number_of_records);
PFormat pf = pit_format_initialize(FORMAT_NOTE, pt ? 4 : 0, notes->number_of_records);
if (!pt) pt = (PTask)pit_table_current(tasks);
for_each_note(pn) {
if (pt && pn->task_id != pt->id)
continue;
pit_pager_print(pf, (char *)pn);
pit_format(pf, (char *)pn);
}
pit_pager_flush(pf);
pit_format_flush(pf);
}
}

View File

@@ -1,5 +1,16 @@
#if !defined(__MODELS_H__)
#define __MODELS_H__
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#if !defined(__OBJECT_H__)
#define __OBJECT_H__
typedef struct _Header {
char signature[3];

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#if !defined(__PIT_H__)
#define __PIT_H__
#define PIT_VERSION "0.1.0"

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -70,14 +81,14 @@ static void project_list(POptions po)
pit_db_load();
if (projects->number_of_records > 0) {
pf = pit_pager_initialize(PAGER_PROJECT, 0, projects->number_of_records);
pf = pit_format_initialize(FORMAT_PROJECT, 0, projects->number_of_records);
for_each_project(pp) {
if ((po->project.name && !stristr(pp->name, po->project.name)) ||
(po->project.status && !stristr(pp->status, po->project.status)))
continue;
pit_pager_print(pf, (char *)pp);
pit_format(pf, (char *)pp);
}
pit_pager_flush(pf);
pit_format_flush(pf);
}
}

View File

@@ -1,3 +1,19 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
/*
** Sqlite probably is a great backend alternative for pit. I just
** figured I would have more fun writing it myself.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -197,15 +213,15 @@ char *pit_table_insert(PTable pt, char *record)
register char **pi = table_available_index(pt);
*pi = pr;
/*
** Update record id if the table has primary key. The id must be the first
** record field of type "unsigned long".
** Update record id if the table has primary key. The id must
** be the first record field of type "unsigned long".
*/
pt->auto_increment++;
*(int *)*pi = pt->auto_increment;
}
/*
** Update created_at and/or updated_at which must be last one or two record
** fields of type "time_t".
** Update created_at and/or updated_at which must be last one or
** two record fields of type "time_t".
*/
if (HAS_CREATED_AT(pt) || HAS_UPDATED_AT(pt)) {
*(time_t *)(pr + pt->record_size - sizeof(time_t)) = now;
@@ -229,7 +245,7 @@ char *pit_table_current(PTable pt)
*/
char *pit_table_mark(PTable pt, int id)
{
return pit_table_find(pt, pt->current = id);
return pit_table_find(pt, pt->current = id); /* <-- Assign and pass as parameter */
}
/*

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#if !defined(__TABLE_H__)
#define __TABLE_H__

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -229,7 +240,7 @@ void pit_task_list(POptions po, PProject pp)
if (!tasks) pit_db_load();
if (tasks->number_of_records > 0) {
PFormat pf = pit_pager_initialize(PAGER_TASK, (pp ? 4 : 0), tasks->number_of_records);
PFormat pf = pit_format_initialize(FORMAT_TASK, (pp ? 4 : 0), tasks->number_of_records);
if (!pp) pp = (PProject)pit_table_current(projects);
for_each_task(pt) {
@@ -242,9 +253,9 @@ void pit_task_list(POptions po, PProject pp)
(po->task.time && pt->time < po->task.time) ||
(po->task.time_max && pt->time > po->task.time_max))
)) continue;
pit_pager_print(pf, (char *)pt);
pit_format(pf, (char *)pt);
}
pit_pager_flush(pf);
pit_format_flush(pf);
}
}

View File

@@ -1,3 +1,14 @@
/*
** Copyright (c) 2010 Michael Dvorkin
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
**
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>