Fossil SCM

Take care that xfer error messages and user prompts always begin at the start of a new line.

drh 2012-11-28 19:28 trunk
Commit f1ef22136f6e8427e09e8e09add679fccf1fa319
--- src/http_transport.c
+++ src/http_transport.c
@@ -193,10 +193,11 @@
193193
blob_appendf(&zCmd, " -P %d", g.urlPort);
194194
#else
195195
blob_appendf(&zCmd, " -p %d", g.urlPort);
196196
#endif
197197
}
198
+ fossil_force_newline();
198199
fossil_print("%s", blob_str(&zCmd)); /* Show the base of the SSH command */
199200
if( g.urlUser && g.urlUser[0] ){
200201
zHost = mprintf("%s@%s", g.urlUser, g.urlName);
201202
#ifdef __MINGW32__
202203
/* Only win32 (and specifically PLINK.EXE) support the -pw option */
203204
--- src/http_transport.c
+++ src/http_transport.c
@@ -193,10 +193,11 @@
193 blob_appendf(&zCmd, " -P %d", g.urlPort);
194 #else
195 blob_appendf(&zCmd, " -p %d", g.urlPort);
196 #endif
197 }
 
198 fossil_print("%s", blob_str(&zCmd)); /* Show the base of the SSH command */
199 if( g.urlUser && g.urlUser[0] ){
200 zHost = mprintf("%s@%s", g.urlUser, g.urlName);
201 #ifdef __MINGW32__
202 /* Only win32 (and specifically PLINK.EXE) support the -pw option */
203
--- src/http_transport.c
+++ src/http_transport.c
@@ -193,10 +193,11 @@
193 blob_appendf(&zCmd, " -P %d", g.urlPort);
194 #else
195 blob_appendf(&zCmd, " -p %d", g.urlPort);
196 #endif
197 }
198 fossil_force_newline();
199 fossil_print("%s", blob_str(&zCmd)); /* Show the base of the SSH command */
200 if( g.urlUser && g.urlUser[0] ){
201 zHost = mprintf("%s@%s", g.urlUser, g.urlName);
202 #ifdef __MINGW32__
203 /* Only win32 (and specifically PLINK.EXE) support the -pw option */
204
+4
--- src/main.c
+++ src/main.c
@@ -712,10 +712,11 @@
712712
once = 0;
713713
cgi_printf("<p class=\"generalError\">%h</p>", z);
714714
cgi_reply();
715715
}else if( !g.fQuiet ){
716716
char *zOut = mprintf("%s: %s\n", g.argv[0], z);
717
+ fossil_force_newline();
717718
fossil_puts(zOut, 1);
718719
fossil_free(zOut);
719720
}
720721
}
721722
free(z);
@@ -745,10 +746,11 @@
745746
g.cgiOutput = 0;
746747
cgi_printf("<p class=\"generalError\">%h</p>", z);
747748
cgi_reply();
748749
}else if( !g.fQuiet ){
749750
char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
751
+ fossil_force_newline();
750752
fossil_puts(zOut, 1);
751753
fossil_free(zOut);
752754
}
753755
}
754756
free(z);
@@ -787,10 +789,11 @@
787789
g.cgiOutput = 0;
788790
cgi_printf("<p class=\"generalError\">%h</p>", z);
789791
cgi_reply();
790792
}else{
791793
char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
794
+ fossil_force_newline();
792795
fossil_puts(zOut, 1);
793796
fossil_free(zOut);
794797
}
795798
}
796799
db_force_rollback();
@@ -813,10 +816,11 @@
813816
{
814817
if( g.cgiOutput ){
815818
cgi_printf("<p class=\"generalError\">%h</p>", z);
816819
}else{
817820
char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
821
+ fossil_force_newline();
818822
fossil_puts(zOut, 1);
819823
fossil_free(zOut);
820824
}
821825
}
822826
free(z);
823827
--- src/main.c
+++ src/main.c
@@ -712,10 +712,11 @@
712 once = 0;
713 cgi_printf("<p class=\"generalError\">%h</p>", z);
714 cgi_reply();
715 }else if( !g.fQuiet ){
716 char *zOut = mprintf("%s: %s\n", g.argv[0], z);
 
717 fossil_puts(zOut, 1);
718 fossil_free(zOut);
719 }
720 }
721 free(z);
@@ -745,10 +746,11 @@
745 g.cgiOutput = 0;
746 cgi_printf("<p class=\"generalError\">%h</p>", z);
747 cgi_reply();
748 }else if( !g.fQuiet ){
749 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
 
750 fossil_puts(zOut, 1);
751 fossil_free(zOut);
752 }
753 }
754 free(z);
@@ -787,10 +789,11 @@
787 g.cgiOutput = 0;
788 cgi_printf("<p class=\"generalError\">%h</p>", z);
789 cgi_reply();
790 }else{
791 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
 
792 fossil_puts(zOut, 1);
793 fossil_free(zOut);
794 }
795 }
796 db_force_rollback();
@@ -813,10 +816,11 @@
813 {
814 if( g.cgiOutput ){
815 cgi_printf("<p class=\"generalError\">%h</p>", z);
816 }else{
817 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
 
818 fossil_puts(zOut, 1);
819 fossil_free(zOut);
820 }
821 }
822 free(z);
823
--- src/main.c
+++ src/main.c
@@ -712,10 +712,11 @@
712 once = 0;
713 cgi_printf("<p class=\"generalError\">%h</p>", z);
714 cgi_reply();
715 }else if( !g.fQuiet ){
716 char *zOut = mprintf("%s: %s\n", g.argv[0], z);
717 fossil_force_newline();
718 fossil_puts(zOut, 1);
719 fossil_free(zOut);
720 }
721 }
722 free(z);
@@ -745,10 +746,11 @@
746 g.cgiOutput = 0;
747 cgi_printf("<p class=\"generalError\">%h</p>", z);
748 cgi_reply();
749 }else if( !g.fQuiet ){
750 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
751 fossil_force_newline();
752 fossil_puts(zOut, 1);
753 fossil_free(zOut);
754 }
755 }
756 free(z);
@@ -787,10 +789,11 @@
789 g.cgiOutput = 0;
790 cgi_printf("<p class=\"generalError\">%h</p>", z);
791 cgi_reply();
792 }else{
793 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
794 fossil_force_newline();
795 fossil_puts(zOut, 1);
796 fossil_free(zOut);
797 }
798 }
799 db_force_rollback();
@@ -813,10 +816,11 @@
816 {
817 if( g.cgiOutput ){
818 cgi_printf("<p class=\"generalError\">%h</p>", z);
819 }else{
820 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
821 fossil_force_newline();
822 fossil_puts(zOut, 1);
823 fossil_free(zOut);
824 }
825 }
826 free(z);
827
+21 -2
--- src/printf.c
+++ src/printf.c
@@ -818,27 +818,46 @@
818818
free(g.zErrMsg);
819819
g.zErrMsg = 0;
820820
g.iErrPriority = 0;
821821
}
822822
823
+/* True if the last character standard output cursor is setting at
824
+** the beginning of a blank link. False if a \r has been to move the
825
+** cursor to the beginning of the line or if not at the beginning of
826
+** a line.
827
+** was a \n
828
+*/
829
+static int stdoutAtBOL = 1;
830
+
823831
/*
824832
** Write to standard output or standard error.
825833
**
826834
** On windows, transform the output into the current terminal encoding
827835
** if the output is going to the screen. If output is redirected into
828836
** a file, no translation occurs. No translation ever occurs on unix.
829837
*/
830838
void fossil_puts(const char *z, int toStdErr){
839
+ int n = (int)strlen(z);
840
+ if( n==0 ) return;
841
+ if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n');
831842
#if defined(_WIN32)
832
- if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
843
+ if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){
833844
return;
834845
}
835846
#endif
836847
assert( toStdErr==0 || toStdErr==1 );
837
- fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
848
+ fwrite(z, 1, n, toStdErr ? stderr : stdout);
838849
fflush(toStdErr ? stderr : stdout);
839850
}
851
+
852
+/*
853
+** Force the the standard output cursor to move to the beginning
854
+** of a line, if it is not there already.
855
+*/
856
+void fossil_force_newline(void){
857
+ if( g.cgiOutput==0 && stdoutAtBOL==0 ) fossil_puts("\n", 0);
858
+}
840859
841860
/*
842861
** Write output for user consumption. If g.cgiOutput is enabled, then
843862
** send the output as part of the CGI reply. If g.cgiOutput is false,
844863
** then write on standard output.
845864
--- src/printf.c
+++ src/printf.c
@@ -818,27 +818,46 @@
818 free(g.zErrMsg);
819 g.zErrMsg = 0;
820 g.iErrPriority = 0;
821 }
822
 
 
 
 
 
 
 
 
823 /*
824 ** Write to standard output or standard error.
825 **
826 ** On windows, transform the output into the current terminal encoding
827 ** if the output is going to the screen. If output is redirected into
828 ** a file, no translation occurs. No translation ever occurs on unix.
829 */
830 void fossil_puts(const char *z, int toStdErr){
 
 
 
831 #if defined(_WIN32)
832 if( fossil_utf8_to_console(z, strlen(z), toStdErr) >= 0 ){
833 return;
834 }
835 #endif
836 assert( toStdErr==0 || toStdErr==1 );
837 fwrite(z, 1, strlen(z), toStdErr ? stderr : stdout);
838 fflush(toStdErr ? stderr : stdout);
839 }
 
 
 
 
 
 
 
 
840
841 /*
842 ** Write output for user consumption. If g.cgiOutput is enabled, then
843 ** send the output as part of the CGI reply. If g.cgiOutput is false,
844 ** then write on standard output.
845
--- src/printf.c
+++ src/printf.c
@@ -818,27 +818,46 @@
818 free(g.zErrMsg);
819 g.zErrMsg = 0;
820 g.iErrPriority = 0;
821 }
822
823 /* True if the last character standard output cursor is setting at
824 ** the beginning of a blank link. False if a \r has been to move the
825 ** cursor to the beginning of the line or if not at the beginning of
826 ** a line.
827 ** was a \n
828 */
829 static int stdoutAtBOL = 1;
830
831 /*
832 ** Write to standard output or standard error.
833 **
834 ** On windows, transform the output into the current terminal encoding
835 ** if the output is going to the screen. If output is redirected into
836 ** a file, no translation occurs. No translation ever occurs on unix.
837 */
838 void fossil_puts(const char *z, int toStdErr){
839 int n = (int)strlen(z);
840 if( n==0 ) return;
841 if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n');
842 #if defined(_WIN32)
843 if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){
844 return;
845 }
846 #endif
847 assert( toStdErr==0 || toStdErr==1 );
848 fwrite(z, 1, n, toStdErr ? stderr : stdout);
849 fflush(toStdErr ? stderr : stdout);
850 }
851
852 /*
853 ** Force the the standard output cursor to move to the beginning
854 ** of a line, if it is not there already.
855 */
856 void fossil_force_newline(void){
857 if( g.cgiOutput==0 && stdoutAtBOL==0 ) fossil_puts("\n", 0);
858 }
859
860 /*
861 ** Write output for user consumption. If g.cgiOutput is enabled, then
862 ** send the output as part of the CGI reply. If g.cgiOutput is false,
863 ** then write on standard output.
864
+1
--- src/user.c
+++ src/user.c
@@ -132,10 +132,11 @@
132132
*/
133133
void prompt_user(const char *zPrompt, Blob *pIn){
134134
char *z;
135135
char zLine[1000];
136136
blob_zero(pIn);
137
+ fossil_force_newline();
137138
fossil_print("%s", zPrompt);
138139
fflush(stdout);
139140
z = fgets(zLine, sizeof(zLine), stdin);
140141
if( z ){
141142
strip_string(pIn, z);
142143
--- src/user.c
+++ src/user.c
@@ -132,10 +132,11 @@
132 */
133 void prompt_user(const char *zPrompt, Blob *pIn){
134 char *z;
135 char zLine[1000];
136 blob_zero(pIn);
 
137 fossil_print("%s", zPrompt);
138 fflush(stdout);
139 z = fgets(zLine, sizeof(zLine), stdin);
140 if( z ){
141 strip_string(pIn, z);
142
--- src/user.c
+++ src/user.c
@@ -132,10 +132,11 @@
132 */
133 void prompt_user(const char *zPrompt, Blob *pIn){
134 char *z;
135 char zLine[1000];
136 blob_zero(pIn);
137 fossil_force_newline();
138 fossil_print("%s", zPrompt);
139 fflush(stdout);
140 z = fgets(zLine, sizeof(zLine), stdin);
141 if( z ){
142 strip_string(pIn, z);
143
+3 -2
--- src/xfer.c
+++ src/xfer.c
@@ -1692,11 +1692,12 @@
16921692
defossilize(zMsg);
16931693
if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
16941694
syncFlags &= ~SYNC_PUSH;
16951695
zMsg = 0;
16961696
}
1697
- fossil_print("\rServer says: %s\n", zMsg);
1697
+ fossil_force_newline();
1698
+ fossil_print("Server says: %s\n", zMsg);
16981699
}else
16991700
17001701
/* pragma NAME VALUE...
17011702
**
17021703
** The server can send pragmas to try to convey meta-information to
@@ -1804,11 +1805,11 @@
18041805
** information which is only sent on the second round.
18051806
*/
18061807
if( cloneSeqno<=0 && nCycle>1 ) go = 0;
18071808
};
18081809
transport_stats(&nSent, &nRcvd, 1);
1809
- if( (syncFlags & SYNC_VERBOSE)==0 ) fossil_print("\n");
1810
+ fossil_force_newline();
18101811
fossil_print(
18111812
"%s finished with %lld bytes sent, %lld bytes received\n",
18121813
zOpType, nSent, nRcvd);
18131814
transport_close();
18141815
transport_global_shutdown();
18151816
--- src/xfer.c
+++ src/xfer.c
@@ -1692,11 +1692,12 @@
1692 defossilize(zMsg);
1693 if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1694 syncFlags &= ~SYNC_PUSH;
1695 zMsg = 0;
1696 }
1697 fossil_print("\rServer says: %s\n", zMsg);
 
1698 }else
1699
1700 /* pragma NAME VALUE...
1701 **
1702 ** The server can send pragmas to try to convey meta-information to
@@ -1804,11 +1805,11 @@
1804 ** information which is only sent on the second round.
1805 */
1806 if( cloneSeqno<=0 && nCycle>1 ) go = 0;
1807 };
1808 transport_stats(&nSent, &nRcvd, 1);
1809 if( (syncFlags & SYNC_VERBOSE)==0 ) fossil_print("\n");
1810 fossil_print(
1811 "%s finished with %lld bytes sent, %lld bytes received\n",
1812 zOpType, nSent, nRcvd);
1813 transport_close();
1814 transport_global_shutdown();
1815
--- src/xfer.c
+++ src/xfer.c
@@ -1692,11 +1692,12 @@
1692 defossilize(zMsg);
1693 if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1694 syncFlags &= ~SYNC_PUSH;
1695 zMsg = 0;
1696 }
1697 fossil_force_newline();
1698 fossil_print("Server says: %s\n", zMsg);
1699 }else
1700
1701 /* pragma NAME VALUE...
1702 **
1703 ** The server can send pragmas to try to convey meta-information to
@@ -1804,11 +1805,11 @@
1805 ** information which is only sent on the second round.
1806 */
1807 if( cloneSeqno<=0 && nCycle>1 ) go = 0;
1808 };
1809 transport_stats(&nSent, &nRcvd, 1);
1810 fossil_force_newline();
1811 fossil_print(
1812 "%s finished with %lld bytes sent, %lld bytes received\n",
1813 zOpType, nSent, nRcvd);
1814 transport_close();
1815 transport_global_shutdown();
1816

Keyboard Shortcuts

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