Fossil SCM

cleaned up error handling a bit, minor code style changes, s/import/commit/

stephan 2008-05-14 20:26 trunk
Commit feee32d3af2760a8c90e6811ac358905e17f38ab
1 file changed +31 -19
+31 -19
--- src/wiki.c
+++ src/wiki.c
@@ -606,11 +606,11 @@
606606
}
607607
608608
/*
609609
** COMMAND: wiki
610610
**
611
-** Usage: %fossil wiki (export|import|list) WikiName
611
+** Usage: %fossil wiki (export|commit|list) WikiName
612612
**
613613
** Run various subcommands to fetch wiki entries.
614614
**
615615
** %fossil wiki export WikiName
616616
**
@@ -623,11 +623,11 @@
623623
**
624624
**
625625
** TODOs:
626626
**
627627
** %fossil export WikiName ?UUID? ?-f outfile?
628
-** %fossil import WikiName ?-f infile?
628
+** %fossil commit WikiName ?-f infile?
629629
*/
630630
void wiki_cmd(void){
631631
int n;
632632
db_find_and_open_repository(1);
633633
if( g.argc<3 ){
@@ -646,21 +646,18 @@
646646
char * sql;
647647
if( g.argc!=4 ){
648648
usage("export EntryName");
649649
}
650650
wname = g.argv[3];
651
- //printf("exporting wiki entry %s\n",wname);
652651
rid = -1;
653
-
654
- sql = mprintf("select x.rid from tag t, tagxref x "
655
- "where x.tagid=t.tagid and t.tagname='wiki-%q' "
656
- " order by x.mtime desc limit 1",
652
+ sql = mprintf("SELECT x.rid FROM tag t, tagxref x"
653
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
654
+ " ORDER BY x.mtime DESC LIMIT 1",
657655
wname );
658656
db_prepare(&q, "%z", sql );
659
- while( db_step(&q) == SQLITE_ROW ){
657
+ if( db_step(&q) == SQLITE_ROW ){
660658
rid = db_column_int(&q,0);
661
- break;
662659
}
663660
db_finalize(&q);
664661
if( -1 == rid ){
665662
fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
666663
exit(1);
@@ -690,10 +687,16 @@
690687
if( *it == '\n') { ++it; break; }
691688
++it;
692689
}
693690
continue;
694691
}
692
+ if( ! *it )
693
+ {
694
+ fprintf(stderr,
695
+ "export reached end of input before finding a 'W' card.\n");
696
+ exit(1);
697
+ }
695698
++it;
696699
while( (*it) && (*it != '\n') ){
697700
if( isspace(*it) ) { ++it; continue; }
698701
blob_append(&numbuf,it,1);
699702
++it;
@@ -700,32 +703,41 @@
700703
}
701704
if( '\n' == *it ) ++it;
702705
if( 0 == blob_size(&numbuf) ){
703706
fprintf(stderr,
704707
"export error: didn't find \"W NUMBER\" line in input!\n");
705
- blob_zero(&buf);
706
- blob_zero(&numbuf);
708
+ blob_reset(&buf);
709
+ blob_reset(&numbuf);
707710
exit(1);
708711
}
709712
len = atoi(blob_buffer(&numbuf));
710
- //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf));
711
- blob_zero(&numbuf);
713
+ //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len);
714
+ blob_reset(&numbuf);
715
+ if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){
716
+ fprintf(stderr,
717
+ "export error: manifest data doesn't match actual data size!"
718
+ " Manifest says [%s (%d)] bytes.\n",
719
+ blob_buffer(&numbuf), len );
720
+ blob_reset(&buf);
721
+ blob_reset(&numbuf);
722
+ exit(1);
723
+ }
712724
fwrite(it,sizeof(char),len,stdout);
713
- blob_zero(&buf);
725
+ blob_reset(&buf);
714726
return;
715727
}
716728
}
717
- blob_zero(&buf);
729
+ blob_reset(&buf);
718730
return;
719731
}else
720
- if( strncmp(g.argv[2],"import",n)==0 ){
732
+ if( strncmp(g.argv[2],"commit",n)==0 ){
721733
char *wname;
722734
if( g.argc!=4 ){
723
- usage("import EntryName");
735
+ usage("commit EntryName");
724736
}
725737
wname = g.argv[3];
726
- fprintf(stderr,"import not yet implemented.\n");
738
+ fprintf(stderr,"commit not yet implemented.\n");
727739
exit(1);
728740
}else
729741
if( strncmp(g.argv[2],"delete",n)==0 ){
730742
if( g.argc!=5 ){
731743
usage("delete WikiName");
@@ -749,8 +761,8 @@
749761
goto wiki_cmd_usage;
750762
}
751763
return;
752764
753765
wiki_cmd_usage:
754
- usage("delete|export|import|list [EntryName]");
766
+ usage("delete|export|commit|list [EntryName]");
755767
}
756768
757769
--- src/wiki.c
+++ src/wiki.c
@@ -606,11 +606,11 @@
606 }
607
608 /*
609 ** COMMAND: wiki
610 **
611 ** Usage: %fossil wiki (export|import|list) WikiName
612 **
613 ** Run various subcommands to fetch wiki entries.
614 **
615 ** %fossil wiki export WikiName
616 **
@@ -623,11 +623,11 @@
623 **
624 **
625 ** TODOs:
626 **
627 ** %fossil export WikiName ?UUID? ?-f outfile?
628 ** %fossil import WikiName ?-f infile?
629 */
630 void wiki_cmd(void){
631 int n;
632 db_find_and_open_repository(1);
633 if( g.argc<3 ){
@@ -646,21 +646,18 @@
646 char * sql;
647 if( g.argc!=4 ){
648 usage("export EntryName");
649 }
650 wname = g.argv[3];
651 //printf("exporting wiki entry %s\n",wname);
652 rid = -1;
653
654 sql = mprintf("select x.rid from tag t, tagxref x "
655 "where x.tagid=t.tagid and t.tagname='wiki-%q' "
656 " order by x.mtime desc limit 1",
657 wname );
658 db_prepare(&q, "%z", sql );
659 while( db_step(&q) == SQLITE_ROW ){
660 rid = db_column_int(&q,0);
661 break;
662 }
663 db_finalize(&q);
664 if( -1 == rid ){
665 fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
666 exit(1);
@@ -690,10 +687,16 @@
690 if( *it == '\n') { ++it; break; }
691 ++it;
692 }
693 continue;
694 }
 
 
 
 
 
 
695 ++it;
696 while( (*it) && (*it != '\n') ){
697 if( isspace(*it) ) { ++it; continue; }
698 blob_append(&numbuf,it,1);
699 ++it;
@@ -700,32 +703,41 @@
700 }
701 if( '\n' == *it ) ++it;
702 if( 0 == blob_size(&numbuf) ){
703 fprintf(stderr,
704 "export error: didn't find \"W NUMBER\" line in input!\n");
705 blob_zero(&buf);
706 blob_zero(&numbuf);
707 exit(1);
708 }
709 len = atoi(blob_buffer(&numbuf));
710 //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf));
711 blob_zero(&numbuf);
 
 
 
 
 
 
 
 
 
712 fwrite(it,sizeof(char),len,stdout);
713 blob_zero(&buf);
714 return;
715 }
716 }
717 blob_zero(&buf);
718 return;
719 }else
720 if( strncmp(g.argv[2],"import",n)==0 ){
721 char *wname;
722 if( g.argc!=4 ){
723 usage("import EntryName");
724 }
725 wname = g.argv[3];
726 fprintf(stderr,"import not yet implemented.\n");
727 exit(1);
728 }else
729 if( strncmp(g.argv[2],"delete",n)==0 ){
730 if( g.argc!=5 ){
731 usage("delete WikiName");
@@ -749,8 +761,8 @@
749 goto wiki_cmd_usage;
750 }
751 return;
752
753 wiki_cmd_usage:
754 usage("delete|export|import|list [EntryName]");
755 }
756
757
--- src/wiki.c
+++ src/wiki.c
@@ -606,11 +606,11 @@
606 }
607
608 /*
609 ** COMMAND: wiki
610 **
611 ** Usage: %fossil wiki (export|commit|list) WikiName
612 **
613 ** Run various subcommands to fetch wiki entries.
614 **
615 ** %fossil wiki export WikiName
616 **
@@ -623,11 +623,11 @@
623 **
624 **
625 ** TODOs:
626 **
627 ** %fossil export WikiName ?UUID? ?-f outfile?
628 ** %fossil commit WikiName ?-f infile?
629 */
630 void wiki_cmd(void){
631 int n;
632 db_find_and_open_repository(1);
633 if( g.argc<3 ){
@@ -646,21 +646,18 @@
646 char * sql;
647 if( g.argc!=4 ){
648 usage("export EntryName");
649 }
650 wname = g.argv[3];
 
651 rid = -1;
652 sql = mprintf("SELECT x.rid FROM tag t, tagxref x"
653 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
654 " ORDER BY x.mtime DESC LIMIT 1",
 
655 wname );
656 db_prepare(&q, "%z", sql );
657 if( db_step(&q) == SQLITE_ROW ){
658 rid = db_column_int(&q,0);
 
659 }
660 db_finalize(&q);
661 if( -1 == rid ){
662 fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
663 exit(1);
@@ -690,10 +687,16 @@
687 if( *it == '\n') { ++it; break; }
688 ++it;
689 }
690 continue;
691 }
692 if( ! *it )
693 {
694 fprintf(stderr,
695 "export reached end of input before finding a 'W' card.\n");
696 exit(1);
697 }
698 ++it;
699 while( (*it) && (*it != '\n') ){
700 if( isspace(*it) ) { ++it; continue; }
701 blob_append(&numbuf,it,1);
702 ++it;
@@ -700,32 +703,41 @@
703 }
704 if( '\n' == *it ) ++it;
705 if( 0 == blob_size(&numbuf) ){
706 fprintf(stderr,
707 "export error: didn't find \"W NUMBER\" line in input!\n");
708 blob_reset(&buf);
709 blob_reset(&numbuf);
710 exit(1);
711 }
712 len = atoi(blob_buffer(&numbuf));
713 //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len);
714 blob_reset(&numbuf);
715 if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){
716 fprintf(stderr,
717 "export error: manifest data doesn't match actual data size!"
718 " Manifest says [%s (%d)] bytes.\n",
719 blob_buffer(&numbuf), len );
720 blob_reset(&buf);
721 blob_reset(&numbuf);
722 exit(1);
723 }
724 fwrite(it,sizeof(char),len,stdout);
725 blob_reset(&buf);
726 return;
727 }
728 }
729 blob_reset(&buf);
730 return;
731 }else
732 if( strncmp(g.argv[2],"commit",n)==0 ){
733 char *wname;
734 if( g.argc!=4 ){
735 usage("commit EntryName");
736 }
737 wname = g.argv[3];
738 fprintf(stderr,"commit not yet implemented.\n");
739 exit(1);
740 }else
741 if( strncmp(g.argv[2],"delete",n)==0 ){
742 if( g.argc!=5 ){
743 usage("delete WikiName");
@@ -749,8 +761,8 @@
761 goto wiki_cmd_usage;
762 }
763 return;
764
765 wiki_cmd_usage:
766 usage("delete|export|commit|list [EntryName]");
767 }
768
769

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button