diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 5ed50cfac7df72a1c5c94b5c90f591f1a556cb8d
parent 2ecf809f92c75da07671f6f0417c7ec2b9a5e7c6
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sun, 17 Jan 2021 13:25:22 +0100

Rename date_fmt to fmt

As long as there is only one relevant format, simply call it 'fmt',
because it matches better the short option '-f'.

Diffstat:
MREADME.md | 4++--
Mdiary.1 | 8++++----
Mdiary.c | 16++++++++--------
Mdiary.cfg | 2+-
Mdiary.h | 4++--
5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md @@ -86,4 +86,4 @@ The file `~/.config/diary/diary.cfg` should adhere to a basic `key = value` form | `--dir`, `-d`, or first non-option argument | `dir` | ~/diary | n/a | Diary directory. Path that holds the journal text files. | | `--range` or `-r` | `range` | 10 | 1 | Number of years to show before/after todays date | | `--weekday` or `-w` | `weekday` | 0 | 1 | First weekday, `0` = Sunday, `1` = Monday, ..., `6` = Saturday. Use `0` to display week beginning at Sunday ("S-M-T-W-T-F-S"), or `1` for "M-T-W-T-F-S-S" (default) | -| `--date_fmt` or `-f` | `date_fmt` | %d_%b_%y | %Y-%m-%d | Date format and file name for the files inside the `dir`. For the format specifiers, see [`man strftime`](https://man7.org/linux/man-pages/man3/strftime.3.html). Be careful: If you change this, you might no longer find your existing diary entries, because the diary assumes to find the journal files under another file name. Hence, a change in FMT shows an empty diary, at first. Rename all files in the DIARY_DIR to migrate to a new FMT. | -\ No newline at end of file +| `--fmt` or `-f` | `fmt` | %d_%b_%y | %Y-%m-%d | Date format and file name for the files inside the `dir`. For the format specifiers, see [`man strftime`](https://man7.org/linux/man-pages/man3/strftime.3.html). Be careful: If you change this, you might no longer find your existing diary entries, because the diary assumes to find the journal files under another file name. Hence, a change in FMT shows an empty diary, at first. Rename all files in the DIARY_DIR to migrate to a new FMT. | +\ No newline at end of file diff --git a/diary.1 b/diary.1 @@ -29,7 +29,7 @@ RANGE is the number of years to show before/after todays date First day of the week. DAY is an integer in range (0..6), interpreted as 0 = Sun, 1 = Mon, ..., 6 = Sat .TP -\fB\-f\fR, \fB\-\-date_fmt\fR=\fI\,FMT\/\fR +\fB\-f\fR, \fB\-\-fmt\fR=\fI\,FMT\/\fR FMT is a custom date and file format. Change with care, because the diary reads and writes to files with file name FMT. The new FMT is only applied to newly saved entries. Existing entries with the old FMT are not @@ -43,8 +43,8 @@ Rename all files in the DIARY_DIR to migrate to a new FMT. If this variable is set to a directory that can be opened, .B diary will use it to store diary files. Diary files are simple text files named -after their date, formatted like FMT (see '-f'/'--date_fmt' options and -'date_fmt' config key). The format defaults to "%Y-%m-%d", which is "YYYY-MM-DD" +after their date, formatted like FMT (see '-f'/'--fmt' options and +'fmt' config key). The format defaults to "%Y-%m-%d", which is "YYYY-MM-DD" (see man strftime). All other files different from FMT are ignored. .IP EDITOR @@ -83,7 +83,7 @@ Install an example config file with defaults: # 0 = Sunday, 1 = Monday, ..., 6 = Saturday weekday = 1 # Date and file format, change with care - date_fmt = %Y-%m-%d' | sed 's/^[[:space:]]*//' > ~/.config/diary/diary.cfg + fmt = %Y-%m-%d' | sed 's/^[[:space:]]*//' > ~/.config/diary/diary.cfg .fi Use characters '#' or ';' for commenting lines. diff --git a/diary.c b/diary.c @@ -213,7 +213,7 @@ bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i) void get_date_str(const struct tm* date, char* date_str, size_t date_str_size) { - strftime(date_str, date_str_size, CONFIG.date_fmt, date); + strftime(date_str, date_str_size, CONFIG.fmt, date); } /* Writes file path for 'date' entry to 'rpath'. '*rpath' is NULL on error. */ @@ -327,9 +327,9 @@ bool read_config(const char* file_path) CONFIG.range = atoi(value_buf); } else if (strcmp("weekday", key_buf) == 0) { CONFIG.weekday = atoi(value_buf); - } else if (strcmp("date_fmt", key_buf) == 0) { - CONFIG.date_fmt = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); - strcpy(CONFIG.date_fmt, value_buf); + } else if (strcmp("fmt", key_buf) == 0) { + CONFIG.fmt = (char *) malloc(strlen(value_buf) + 1 * sizeof(char)); + strcpy(CONFIG.fmt, value_buf); } } } @@ -349,7 +349,7 @@ void usage() { printf(" -d, --dir DIARY_DIR : Diary storage directory DIARY_DIR\n"); printf(" -r, --range RANGE : RANGE is the number of years to show before/after today's date\n"); printf(" -w, --weekday DAY : First day of the week, 0 = Sun, 1 = Mon, ..., 6 = Sat\n"); - printf(" -f, --date_fmt FMT : Date and file format, change with care\n"); + printf(" -f, --fmt FMT : Date and file format, change with care\n"); printf("\n"); printf("Full docs and keyboard shortcuts: DIARY(1)\n"); printf("or online via: <https://github.com/in0rdr/diary>\n"); @@ -427,7 +427,7 @@ int main(int argc, char** argv) { { "dir", required_argument, 0, 'd' }, { "range", required_argument, 0, 'r' }, { "weekday", required_argument, 0, 'w' }, - { "date_fmt", required_argument, 0, 'f' }, + { "fmt", required_argument, 0, 'f' }, { 0, 0, 0, 0 } }; @@ -467,8 +467,8 @@ int main(int argc, char** argv) { break; case 'f': // set date format from option character - CONFIG.date_fmt = (char *) calloc(strlen(optarg) + 1, sizeof(char)); - strcpy(CONFIG.date_fmt, optarg); + CONFIG.fmt = (char *) calloc(strlen(optarg) + 1, sizeof(char)); + strcpy(CONFIG.fmt, optarg); break; default: printf("?? getopt returned character code 0%o ??\n", option_char); diff --git a/diary.cfg b/diary.cfg @@ -5,4 +5,4 @@ range = 1 # 0 = Sunday, 1 = Monday, ..., 6 = Saturday weekday = 1 # Date and file format, change with care -date_fmt = %Y-%m-%d +fmt = %Y-%m-%d diff --git a/diary.h b/diary.h @@ -50,13 +50,13 @@ typedef struct // 0 = Sunday, 1 = Monday, ..., 6 = Saturday int weekday; // 2020-12-31 - char* date_fmt; + char* fmt; } config; config CONFIG = { .range = 1, .weekday = 1, - .date_fmt = "%Y-%m-%d" + .fmt = "%Y-%m-%d" }; #endif