/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /* ** Copyright (c) 2013 D. Richard Hipp ** ** 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. ** ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ******************************************************************************* ** This file implements some test/demo code for working with wiki pages. */ #include "fossil-scm/fossil-cli.h" /* Fossil App mini-framework */ static void fcli_local_help(){ printf("Usage:\n\t%s [options] command\n\n", fcli.appName); puts("Commands:"); puts("\n\texport PageName [-o|--output-file=FILENAME]\n\t" "Exports the most recent version of " "the given page (to stdout by default). " "PageName may optionally be specified using [-p|--page Name]." ); puts("\n\tls [-n|--names]\n\t" "Lists the most recent versions of all wiki pages. " "Use -V for more info."); puts("\n\tsave PageName InputFile " "[-n|--dry-run] " "[-t|--mime-type=TYPE]" "[--new]"); puts("\t" "Imports a file to a wiki page. " "PageName and InputFile may optionally be specified using " "[-p|--page Name] resp. [-f|--file NAME]. The --new option allows the " "creation of new pages. Without that option, saving will fail for " "non-existing pages in order to avoid that a typo fills the repo " "with unwanted pages." ); } fsl_int32_t wiki_page_count(){ return fsl_db_g_int32(fsl_cx_db_repo(fcli.f), -1, "SELECT count(*) FROM tag " "WHERE tagname GLOB 'wiki-*'"); } static struct { char listNamesOnly; char * pageName; } WikiApp = { 0/*listNamesOnly*/, NULL/*pageName*/ }; static int cb_f_wiki_list( fsl_cx * f, fsl_deck const * d, void * state ){ fsl_db * db = fsl_cx_db_repo(fcli.f); char * ts = fsl_db_julian_to_iso8601(db, d->D, 0); int * counter = (int*)state; if(WikiApp.listNamesOnly){ f_out("%b\n", &d->L); }else{ ts[10] = '@'; if(0 == (*counter)++){ if(fcli.verbose){ f_out("RID "); } f_out("%-19s %-8s Name\n", "Timestamp", "UUID"); } if(fcli.verbose){ f_out("%-6"FSL_ID_T_PFMT" ", d->rid); } f_out("%-19s %.*s %b\n", ts, 8, d->uuid, &d->L); fsl_free(ts); } #if defined(DEBUG) { int rc; fsl_id_t ridCheck = 0; rc = fsl_wiki_latest_rid(f, fsl_buffer_cstr(&d->L), &ridCheck); assert(!rc); if(d->rid!=ridCheck){ f_out("d->rid=%"FSL_ID_T_PFMT", ridCheck=%"FSL_ID_T_PFMT"\n", d->rid, ridCheck); } assert(d->rid==ridCheck); } #endif return 0; } static int fcmd_wiki_list(){ fsl_cx * f = fcli.f; int counter = 0; int rc; WikiApp.listNamesOnly = fcli_flag2("n", "names", NULL); if(fcli_has_unused_flags(1)){ return FSL_RC_MISUSE; } if(WikiApp.listNamesOnly){ fsl_list li = fsl_list_empty; fsl_size_t i; rc = fsl_wiki_names_get(f, &li); for( i = 0; !rc && (i