#include #include #include #include #include #define VTIME_IMPL #include "vtime.h" void help() { fprintf(stdout, "vtime [FORMAT]\n\ \t[YYYY/yy].[mm].dd Sets the date. Can set only the day/month.\n\ \t Instead of dot(.) coult be any non-numeric character.\n\ \t+/-[k](d/w/m/y) Add/subtract k units from the date. k is implicitly 1\n\ \tt[his]/n[ext] Wday\n\ \tl[ast]/p[rev] Wday Go to next/previous week day. Wday is the week day prefix.\n\ \tb[egining]\n\ts[tart]\n\tf[irst]\n\ \te[nd] w[eek]/m[onth]/y[ear] Go to first/last day in week/month/year.\n\ "); } int main(int argc, char **argv) { int i; time_t now = time(NULL); struct tm out = *(localtime(&now)); if (argc == 1) { help(); return 0; } char *fmt, *pnt; size_t len = 0; for (i = 1; i < argc; i++) { len += 1 + strlen(argv[i]); } fmt = calloc(len, sizeof(*fmt)); if (fmt == NULL) { fprintf(stderr, "Failed malloc\n"); return 1; } for (i = 1, pnt = fmt; i < argc; i++) { pnt = stpcpy(pnt, argv[i]); if (i != argc-1) *(pnt++) = ' '; } if (vtime(&out, fmt, 0)) { fprintf(stderr, "Wrong format\n"); return 1; } fprintf(stdout, "%s", asctime(&out)); return 0; }