852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
|
+
+
+
+
+
+
+
-
-
+
+
-
+
+
|
blob_append(pTo, &pFrom->aData[pFrom->iCursor], i - pFrom->iCursor);
}
pFrom->iCursor = i;
}
/*
** Remove comment lines (starting with '#') from a blob pIn.
** Keep lines starting with "\#" but remove the initial backslash.
**
** Store the result in pOut. It is ok for pIn and pOut to be the same blob.
**
** pOut must either be the same as pIn or else uninitialized.
*/
void blob_strip_comment_lines(Blob *pIn, Blob *pOut){
char *z = pIn->aData;
unsigned int i = 0;
unsigned int n = pIn->nUsed;
unsigned int lineStart = 0;
unsigned int copyStart = 0;
int doCopy = 1;
Blob temp;
blob_zero(&temp);
while( i<n ){
if( i==lineStart && z[i]=='#' ){
copyStart = i;
doCopy = 0;
}else if( i==lineStart && z[i]=='\\' && z[i+1]=='#' ){
/* keep lines starting with an escaped '#' (and unescape it) */
copyStart = i + 1;
}
if( z[i]=='\n' ){
if( doCopy ) blob_append(&temp,&pIn->aData[lineStart], i - lineStart + 1);
lineStart = i + 1;
if( doCopy ) blob_append(&temp,&pIn->aData[copyStart], i - copyStart + 1);
lineStart = copyStart = i + 1;
doCopy = 1;
}
i++;
}
/* Last line */
if( doCopy ) blob_append(&temp, &pIn->aData[lineStart], i - lineStart);
if( doCopy ) blob_append(&temp, &pIn->aData[copyStart], i - copyStart);
if( pOut==pIn ) blob_reset(pOut);
*pOut = temp;
}
/*
** COMMAND: test-strip-comment-lines
**
** Usage: %fossil test-strip-comment-lines ?OPTIONS? INPUTFILE
**
** Read INPUTFILE and print it without comment lines (starting with '#').
** Keep lines starting with "\#" but remove the initial backslash.
**
** This is used to test and debug the blob_strip_comment_lines() routine.
**
** Options:
** -y|--side-by-side Show diff of INPUTFILE and output side-by-side
** -W|--width N Width of lines in side-by-side diff
*/
|