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

30
LICENSE Normal file
View File

@@ -0,0 +1,30 @@
Copyright (c) 2010 Michael Dvorkin. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation
are those of the authors and contributors and should not be interpreted
as representing official policies, either expressed or implied, of
anybody else.

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>

View File

@@ -1,4 +1,14 @@
module Pit
# 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.
module PitTest
module Date
def should_parse_alpha_dates

View File

@@ -1,5 +1,16 @@
module Pit
# 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.
module PitTest
module Note
def should_not_segfault
`#{@pit} p -c test`
`#{@pit} t -c test`
@@ -21,5 +32,6 @@ module Pit
`#{@pit} n -e #{n} xxx`
end
end
end
end

View File

@@ -1,4 +1,14 @@
module Pit
# 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.
module PitTest
module Project
def should_create_project
@@ -27,5 +37,6 @@ module Pit
`#{@pit} project`.should_not.match /[\s|\*] 2:/m
`#{@pit} project`.should.match /\s 1:/m
end
end
end

View File

@@ -1,4 +1,14 @@
module Pit
# 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.
module PitTest
module Task
def should_do_cascading_task_delete

View File

@@ -1,7 +1,17 @@
#!/usr/bin/env ruby
#
# 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.
BASE = File.dirname(File.expand_path(__FILE__))
require "#{BASE}/pit_should"
require "#{BASE}/tiny_should"
require "#{BASE}/pit_date"
require "#{BASE}/pit_project"
require "#{BASE}/pit_task"
@@ -33,10 +43,10 @@ class PitTestRunner
`#{@pit} init -f`
end
include Pit::Date
include Pit::Project
include Pit::Task
include Pit::Note
include PitTest::Date
include PitTest::Project
include PitTest::Task
include PitTest::Note
end
PitTestRunner.run

View File

@@ -1,10 +1,17 @@
class Hand < RuntimeError
def oops(msg)
puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}"
end
end
# 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.
class String
# I am well aware there is Test::Unit, minitest, rspec, shoulda,
# bacon and a dozen of other testing frameworks. I just had fun
# writing this one and frankly that's all I need for basic testing.
module TinyShould
def should
def self.equal(expected)
raise Hand unless self == expected
@@ -42,6 +49,16 @@ class String
end
end
class Hand < RuntimeError
def oops(msg)
puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}"
end
end
class String
include TinyShould
end
if $0 == __FILE__
"123".should.equal "123"
"123".should.equal "321"
@@ -55,5 +72,3 @@ if $0 == __FILE__
"abc".should_not.match /xyz/
"abc".should_not.match /abc/
end