mirror of
				https://github.com/sqlite/sqlite.git
				synced 2025-11-03 16:53:36 +03:00 
			
		
		
		
	Command-line shell enhancements: Added the ".print" command. Enhanced
the ".width" command so that negative widths will right-justify. FossilOrigin-Name: a1d8269da3868e41a6603c1a683e324fe21fb317
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/shell.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/shell.c
									
									
									
									
									
								
							@@ -696,7 +696,7 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
 | 
			
		||||
          }else{
 | 
			
		||||
            w = 0;
 | 
			
		||||
          }
 | 
			
		||||
          if( w<=0 ){
 | 
			
		||||
          if( w==0 ){
 | 
			
		||||
            w = strlen30(azCol[i] ? azCol[i] : "");
 | 
			
		||||
            if( w<10 ) w = 10;
 | 
			
		||||
            n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue);
 | 
			
		||||
@@ -706,7 +706,11 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
 | 
			
		||||
            p->actualWidth[i] = w;
 | 
			
		||||
          }
 | 
			
		||||
          if( p->showHeader ){
 | 
			
		||||
            fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
 | 
			
		||||
            if( w<0 ){
 | 
			
		||||
              fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": "  ");
 | 
			
		||||
            }else{
 | 
			
		||||
              fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        if( p->showHeader ){
 | 
			
		||||
@@ -714,6 +718,7 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
 | 
			
		||||
            int w;
 | 
			
		||||
            if( i<ArraySize(p->actualWidth) ){
 | 
			
		||||
               w = p->actualWidth[i];
 | 
			
		||||
               if( w<0 ) w = -w;
 | 
			
		||||
            }else{
 | 
			
		||||
               w = 10;
 | 
			
		||||
            }
 | 
			
		||||
@@ -735,8 +740,13 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int
 | 
			
		||||
           strlen30(azArg[i])>w ){
 | 
			
		||||
          w = strlen30(azArg[i]);
 | 
			
		||||
        }
 | 
			
		||||
        fprintf(p->out,"%-*.*s%s",w,w,
 | 
			
		||||
            azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": "  ");
 | 
			
		||||
        if( w<0 ){
 | 
			
		||||
          fprintf(p->out,"%*.*s%s",-w,-w,
 | 
			
		||||
              azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": "  ");
 | 
			
		||||
        }else{
 | 
			
		||||
          fprintf(p->out,"%-*.*s%s",w,w,
 | 
			
		||||
              azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": "  ");
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
@@ -1416,9 +1426,10 @@ static char zHelp[] =
 | 
			
		||||
  "                         list     Values delimited by .separator string\n"
 | 
			
		||||
  "                         tabs     Tab-separated values\n"
 | 
			
		||||
  "                         tcl      TCL list elements\n"
 | 
			
		||||
  ".nullvalue STRING      Print STRING in place of NULL values\n"
 | 
			
		||||
  ".nullvalue STRING      Use STRING in place of NULL values\n"
 | 
			
		||||
  ".output FILENAME       Send output to FILENAME\n"
 | 
			
		||||
  ".output stdout         Send output to the screen\n"
 | 
			
		||||
  ".print STRING...       Print literal STRING\n"
 | 
			
		||||
  ".prompt MAIN CONTINUE  Replace the standard prompts\n"
 | 
			
		||||
  ".quit                  Exit this program\n"
 | 
			
		||||
  ".read FILENAME         Execute SQL in FILENAME\n"
 | 
			
		||||
@@ -2070,6 +2081,15 @@ static int do_meta_command(char *zLine, struct callback_data *p){
 | 
			
		||||
    }
 | 
			
		||||
  }else
 | 
			
		||||
 | 
			
		||||
  if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
 | 
			
		||||
    int i;
 | 
			
		||||
    for(i=1; i<nArg; i++){
 | 
			
		||||
      if( i>1 ) fprintf(p->out, " ");
 | 
			
		||||
      fprintf(p->out, "%s", azArg[i]);
 | 
			
		||||
    }
 | 
			
		||||
    fprintf(p->out, "\n");
 | 
			
		||||
  }else
 | 
			
		||||
 | 
			
		||||
  if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
 | 
			
		||||
    if( nArg >= 2) {
 | 
			
		||||
      strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user