Fossil

Check-in [feee32d3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cleaned up error handling a bit, minor code style changes, s/import/commit/
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: feee32d3af2760a8c90e6811ac358905e17f38ab
User & Date: stephan 2008-05-14 20:26:13
Context
2008-05-14
20:59
Cleanup and simplify the code for the recently added "wiki" command. check-in: decac09b user: drh tags: trunk
20:26
cleaned up error handling a bit, minor code style changes, s/import/commit/ check-in: feee32d3 user: stephan tags: trunk
20:02
removed 2 remaining debug lines. Cleaned up help text. check-in: 87a1a31d user: stephan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wiki.c.

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
...
644
645
646
647
648
649
650
651
652
653


654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
...
688
689
690
691
692
693
694






695
696
697
698
699
700
701
702
703
704
705
706
707
708
709






710

711


712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
...
747
748
749
750
751
752
753
754
755
756
{
	fwrite(blob_buffer(b), 1, blob_size(b), stdout);
}

/*
** COMMAND: wiki
**
** Usage: %fossil wiki (export|import|list) WikiName
**
** Run various subcommands to fetch wiki entries.
**
**     %fossil wiki export WikiName
**
**         Sends the latest version of the WikiName wiki
**         entry to stdout.
................................................................................
**
**         Lists all wiki entries, one per line.
**
**
** TODOs:
**
**     %fossil export WikiName ?UUID? ?-f outfile?
**     %fossil import WikiName ?-f infile?
*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }
................................................................................
    Blob buf;
    int rid;
    char * sql;
    if( g.argc!=4 ){
      usage("export EntryName");
    }
    wname = g.argv[3];
    //printf("exporting wiki entry %s\n",wname);
    rid = -1;



    sql = mprintf("select x.rid from tag t, tagxref x "
          "where x.tagid=t.tagid and t.tagname='wiki-%q' "
      " order by x.mtime desc limit 1",
      wname );
    db_prepare(&q, "%z", sql );
    while( db_step(&q) == SQLITE_ROW ){
      rid = db_column_int(&q,0);
      break;
    }
    db_finalize(&q);
    if( -1 == rid ){
      fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
      exit(1);
    }
    if( ! content_get(rid,&buf) ){
................................................................................
          ++it;
          while( *it ){
            if( *it == '\n') { ++it; break; }
            ++it;
          }
          continue;
        }






        ++it;
        while( (*it) && (*it != '\n') ){
          if( isspace(*it) ) { ++it; continue; }
          blob_append(&numbuf,it,1);
          ++it;
        }
        if( '\n' == *it ) ++it;
        if( 0 == blob_size(&numbuf) ){
          fprintf(stderr,
          "export error: didn't find \"W NUMBER\" line in input!\n");
          blob_zero(&buf);
          blob_zero(&numbuf);
          exit(1);
        }
        len = atoi(blob_buffer(&numbuf));






        //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf));

        blob_zero(&numbuf);


        fwrite(it,sizeof(char),len,stdout);
        blob_zero(&buf);
        return;
      }
    }
    blob_zero(&buf);
    return;
  }else
  if( strncmp(g.argv[2],"import",n)==0 ){
    char *wname;
    if( g.argc!=4 ){
      usage("import EntryName");
    }
    wname = g.argv[3];
    fprintf(stderr,"import not yet implemented.\n");
    exit(1);
  }else
  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete WikiName");
    }
    fprintf(stderr,"delete not yet implemented.\n");
................................................................................
  }else
  {
    goto wiki_cmd_usage;
  }
  return;

wiki_cmd_usage:
  usage("delete|export|import|list [EntryName]");
}








|







 







|







 







<

<
>
>
|
<
<


|

<







 







>
>
>
>
>
>










|
|



>
>
>
>
>
>
|
>
|
>
>

|



|


|


|


|







 







|


604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
...
644
645
646
647
648
649
650

651

652
653
654


655
656
657
658

659
660
661
662
663
664
665
...
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
759
760
761
762
763
764
765
766
767
768
{
	fwrite(blob_buffer(b), 1, blob_size(b), stdout);
}

/*
** COMMAND: wiki
**
** Usage: %fossil wiki (export|commit|list) WikiName
**
** Run various subcommands to fetch wiki entries.
**
**     %fossil wiki export WikiName
**
**         Sends the latest version of the WikiName wiki
**         entry to stdout.
................................................................................
**
**         Lists all wiki entries, one per line.
**
**
** TODOs:
**
**     %fossil export WikiName ?UUID? ?-f outfile?
**     %fossil commit WikiName ?-f infile?
*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }
................................................................................
    Blob buf;
    int rid;
    char * sql;
    if( g.argc!=4 ){
      usage("export EntryName");
    }
    wname = g.argv[3];

    rid = -1;

    sql = mprintf("SELECT x.rid FROM tag t, tagxref x"
      " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
      " ORDER BY x.mtime DESC LIMIT 1",


      wname );
    db_prepare(&q, "%z", sql );
    if( db_step(&q) == SQLITE_ROW ){
      rid = db_column_int(&q,0);

    }
    db_finalize(&q);
    if( -1 == rid ){
      fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
      exit(1);
    }
    if( ! content_get(rid,&buf) ){
................................................................................
          ++it;
          while( *it ){
            if( *it == '\n') { ++it; break; }
            ++it;
          }
          continue;
        }
        if( ! *it )
        {
            fprintf(stderr,
              "export reached end of input before finding a 'W' card.\n");
            exit(1);
        }
        ++it;
        while( (*it) && (*it != '\n') ){
          if( isspace(*it) ) { ++it; continue; }
          blob_append(&numbuf,it,1);
          ++it;
        }
        if( '\n' == *it ) ++it;
        if( 0 == blob_size(&numbuf) ){
          fprintf(stderr,
          "export error: didn't find \"W NUMBER\" line in input!\n");
          blob_reset(&buf);
          blob_reset(&numbuf);
          exit(1);
        }
        len = atoi(blob_buffer(&numbuf));
        //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len);
        blob_reset(&numbuf);
        if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){
          fprintf(stderr,
            "export error: manifest data doesn't match actual data size!"
            " Manifest says [%s (%d)] bytes.\n",
            blob_buffer(&numbuf), len );
          blob_reset(&buf);
          blob_reset(&numbuf);
          exit(1);
        }
        fwrite(it,sizeof(char),len,stdout);
        blob_reset(&buf);
        return;
      }
    }
    blob_reset(&buf);
    return;
  }else
  if( strncmp(g.argv[2],"commit",n)==0 ){
    char *wname;
    if( g.argc!=4 ){
      usage("commit EntryName");
    }
    wname = g.argv[3];
    fprintf(stderr,"commit not yet implemented.\n");
    exit(1);
  }else
  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete WikiName");
    }
    fprintf(stderr,"delete not yet implemented.\n");
................................................................................
  }else
  {
    goto wiki_cmd_usage;
  }
  return;

wiki_cmd_usage:
  usage("delete|export|commit|list [EntryName]");
}