File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
269269 Add the specified builtin script to the list of executed scripts.
270270 Available builtin scripts are: <literal>tpcb-like</>,
271271 <literal>simple-update</> and <literal>select-only</>.
272+ Unambiguous prefixes of builtin names are accepted.
272273 With special name <literal>list</>, show the list of builtin scripts
273274 and exit immediately.
274275 </para>
Original file line number Diff line number Diff line change @@ -2746,22 +2746,36 @@ listAvailableScripts(void)
27462746 fprintf (stderr , "\n" );
27472747}
27482748
2749+ /* return builtin script "name" if unambiguous */
27492750static char *
27502751findBuiltin (const char * name , char * * desc )
27512752{
2752- int i ;
2753+ int i ,
2754+ found = 0 ,
2755+ len = strlen (name );
2756+ char * commands = NULL ;
27532757
27542758 for (i = 0 ; i < N_BUILTIN ; i ++ )
27552759 {
2756- if (strncmp (builtin_script [i ].name , name ,
2757- strlen (builtin_script [i ].name )) == 0 )
2760+ if (strncmp (builtin_script [i ].name , name , len ) == 0 )
27582761 {
27592762 * desc = builtin_script [i ].desc ;
2760- return builtin_script [i ].commands ;
2763+ commands = builtin_script [i ].commands ;
2764+ found ++ ;
27612765 }
27622766 }
27632767
2764- fprintf (stderr , "no builtin script found for name \"%s\"\n" , name );
2768+ /* ok, unambiguous result */
2769+ if (found == 1 )
2770+ return commands ;
2771+
2772+ /* error cases */
2773+ if (found == 0 )
2774+ fprintf (stderr , "no builtin script found for name \"%s\"\n" , name );
2775+ else /* found > 1 */
2776+ fprintf (stderr ,
2777+ "ambiguous builtin name: %d builtin scripts found for prefix \"%s\"\n" , found , name );
2778+
27652779 listAvailableScripts ();
27662780 exit (1 );
27672781}
You can’t perform that action at this time.
0 commit comments