/ Changes On Branch cli-char-width
Login

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

Changes In Branch cli-char-width Excluding Merge-Ins

This is equivalent to a diff from 4bee8295e3 to b1a9e2916f

2015-02-26
16:32
Fix a real bug (in test code) that was introduced while trying to eliminate harmless compiler warnings from OpenBSD (see check-in [10321910990195878c]). (check-in: a62ba58c73 user: drh tags: trunk)
14:27
In the command-line shell, change the units on the ".width" directive from bytes to characters. (Leaf check-in: b1a9e2916f user: drh tags: cli-char-width)
02:33
Simplifications to the description of the nByte parameter to sqlite3_prepare() and friends. (check-in: 4bee8295e3 user: drh tags: trunk)
2015-02-25
14:25
Make sure the sqlite3_mutex.id field is initialized in the Win32 mutex implementation, even when SQLITE_DEBUG is turned off. (check-in: 6d132e7a22 user: drh tags: trunk)

Changes to src/shell.c.

783
784
785
786
787
788
789










































790
791
792
793
794
795
796
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







static void interrupt_handler(int NotUsed){
  UNUSED_PARAMETER(NotUsed);
  seenInterrupt++;
  if( seenInterrupt>2 ) exit(1);
  if( db ) sqlite3_interrupt(db);
}
#endif

/*
** Return the length of a string in characters.  Multibyte UTF8 characters
** count as a single character.
*/
static int strlenChar(const char *z){
  int n = 0;
  while( *z ){
    if( (0xc0&*(z++))!=0x80 ) n++;
  }
  return n;
}

/*
** Print abs(w) characters of string "z" on FILE "out".
**
** w is in units of characters, not bytes!
**
** The output is always exactly abs(w) characters wide.  If z contains
** more than abs(w) characters, it is truncated.  If z contains fewer
** than abs(w) characters it is padded with spaces.  Spaces are added
** on the right if w>0 (left justification) or on the left if w<0
** (right justification).
*/
static void outputFixedWidth(FILE *out, int w, const char *z){
  int n = strlenChar(z);
  int absw = w<0 ? -w : w;
  int i;

  if( n<=absw ){
    if( w<0 ) for(i=absw-n; i>0; i--) putc(' ', out);
    fputs(z, out);
    if( w>0 ) for(i=absw-n; i>0; i--) putc(' ', out);
  }else{
    for(i=n=0; z[i]; i++){
      if( (z[i]&0xc0)==0x80 ) continue;
      if( n==absw ) break;
      n++;
    }
    fwrite(z, 1, i, out);
  }
}

/*
** This is the callback routine that the shell
** invokes for each row of a query result.
*/
static int shell_callback(
  void *pArg,
824
825
826
827
828
829
830
831

832
833

834
835
836
837
838
839
840
841
842


843
844
845
846
847
848
849
850
851
852
853
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







-
+

-
+






-
-
-
+
+
-
-
-
-







          int w, n;
          if( i<ArraySize(p->colWidth) ){
            w = p->colWidth[i];
          }else{
            w = 0;
          }
          if( w==0 ){
            w = strlen30(azCol[i] ? azCol[i] : "");
            w = strlenChar(azCol[i] ? azCol[i] : "");
            if( w<10 ) w = 10;
            n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue);
            n = strlenChar(azArg && azArg[i] ? azArg[i] : p->nullValue);
            if( w<n ) w = n;
          }
          if( i<ArraySize(p->actualWidth) ){
            p->actualWidth[i] = w;
          }
          if( p->showHeader ){
            if( w<0 ){
              fprintf(p->out,"%*.*s%s",-w,-w,azCol[i],
                      i==nArg-1 ? p->rowSeparator : "  ");
            outputFixedWidth(p->out, w, azCol[i]);
            fprintf(p->out, "%s", i==nArg-1 ? p->rowSeparator : "  ");
            }else{
              fprintf(p->out,"%-*.*s%s",w,w,azCol[i],
                      i==nArg-1 ? p->rowSeparator : "  ");
            }
          }
        }
        if( p->showHeader ){
          for(i=0; i<nArg; i++){
            int w;
            if( i<ArraySize(p->actualWidth) ){
               w = p->actualWidth[i];
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
903
904
905
906
907
908
909

910
911
912
913
914
915
916
917




918
919





920
921
922
923
924
925
926







-
+







-
-
-
-
+
+
-
-
-
-
-







        int w;
        if( i<ArraySize(p->actualWidth) ){
           w = p->actualWidth[i];
        }else{
           w = 10;
        }
        if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){
          w = strlen30(azArg[i]);
          w = strlenChar(azArg[i]);
        }
        if( i==1 && p->aiIndent && p->pStmt ){
          if( p->iIndent<p->nIndent ){
            fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
          }
          p->iIndent++;
        }
        if( w<0 ){
          fprintf(p->out,"%*.*s%s",-w,-w,
              azArg[i] ? azArg[i] : p->nullValue,
              i==nArg-1 ? p->rowSeparator : "  ");
        outputFixedWidth(p->out, w, azArg[i] ? azArg[i] : p->nullValue);
        fprintf(p->out, "%s", i==nArg-1 ? p->rowSeparator : "  ");
        }else{
          fprintf(p->out,"%-*.*s%s",w,w,
              azArg[i] ? azArg[i] : p->nullValue,
              i==nArg-1 ? p->rowSeparator : "  ");
        }
      }
      break;
    }
    case MODE_Semi:
    case MODE_List: {
      if( p->cnt++==0 && p->showHeader ){
        for(i=0; i<nArg; i++){