@@ -227,6 +227,9 @@ static optionDescription LongOptionDescription [] = {
227227 {1 ,0 ," --filter-terminator=<string>" },
228228 {1 ,0 ," Specify <string> to print to stdout following the tags for each file" },
229229 {1 ,0 ," parsed when --filter is enabled." },
230+ {1 ,0 ," --oneshot=<filename>" },
231+ {1 ,0 ," Behave as a filter, reading file contents from standard input and" },
232+ {1 ,0 ," writing tags to standard output. <filename> is used as the input field of tags." },
230233 {1 ,0 ," --links[=(yes|no)]" },
231234 {1 ,0 ," Indicate whether symbolic links should be followed [yes]." },
232235 {1 ,0 ," --maxdepth=<N>" },
@@ -496,6 +499,8 @@ static optionDescription LongOptionDescription [] = {
496499 {1 ,0 ," Print this option summary including experimental features." },
497500 {1 ,0 ," --license" },
498501 {1 ,0 ," Print details of software license." },
502+ {1 ,0 ," --oneshot-limit=<bytes>" },
503+ {1 ,0 ," Limit the input size in the oneshot mode, in bytes (default is 32MB)." },
499504 {0 ,0 ," --print-language" },
500505 {0 ,0 ," Don't make tags file but just print the guessed language name for" },
501506 {0 ,0 ," input file." },
@@ -1678,6 +1683,27 @@ static void processHelpFullOption (
16781683 exit (0 );
16791684}
16801685
1686+ static void processOneshot (
1687+ const char * const option ,
1688+ const char * const parameter )
1689+ {
1690+ if (!parameter || parameter [0 ] == '\0' )
1691+ error (FATAL , "--%s option requires a non-empty <filename>" , option );
1692+
1693+ static struct interactiveModeArgs args ;
1694+ Option .interactive = INTERACTIVE_ONESHOT ;
1695+
1696+ #ifdef HAVE_SECCOMP
1697+ Option .interactive |= INTERACTIVE_WITH_SANDBOX ;
1698+ #endif
1699+
1700+ args .fname = parameter ;
1701+ args .limit = oneshotLimit ;
1702+ args .sandbox = (Option .interactive & INTERACTIVE_WITH_SANDBOX );
1703+
1704+ setMainLoop (batchOneshot , & args );
1705+ }
1706+
16811707#ifdef HAVE_JANSSON
16821708static void processInteractiveOption (
16831709 const char * const option ,
@@ -2717,6 +2743,28 @@ static bool inOneshotMode (void)
27172743 return (Option .interactive & INTERACTIVE_ONESHOT );
27182744}
27192745
2746+ static void oneshotSetLimit (size_t limit )
2747+ {
2748+ verbose ("adjust input limit of oneshot mode: %lu" , (unsigned long )limit );
2749+ oneshotLimit = limit ;
2750+ }
2751+
2752+ static void processOneshotLimit (
2753+ const char * const option , const char * const parameter )
2754+ {
2755+ if (parameter == NULL || parameter [0 ] == '\0' )
2756+ error (FATAL , "A positive number or 0 is needed after --%s option" , option );
2757+
2758+ unsigned long limit = 0 ;
2759+ if (!strToULong (parameter , 0 , & limit ))
2760+ error (FATAL , "Invalid oneshot limit: %s" , parameter );
2761+ if (limit > SIZE_MAX )
2762+ error (FATAL , "Too large limit: %s (> %lu)" ,
2763+ parameter , (unsigned long )SIZE_MAX );
2764+
2765+ oneshotSetLimit ((size_t )limit );
2766+ }
2767+
27202768static void processSortOption (
27212769 const char * const option , const char * const parameter )
27222770{
@@ -3119,6 +3167,8 @@ static parametricOption ParametricOptions [] = {
31193167 { "list-roles" , processListRolesOption , true, STAGE_ANY },
31203168 { "list-subparsers" , processListSubparsersOption , true, STAGE_ANY },
31213169 { "maxdepth" , processMaxRecursionDepthOption , true, STAGE_ANY },
3170+ { "oneshot" , processOneshot , true, STAGE_ANY },
3171+ { "oneshot-limit" , processOneshotLimit , true, STAGE_ANY },
31223172 { "optlib-dir" , processOptlibDir , false, STAGE_ANY },
31233173 { "options" , processOptionFile , false, STAGE_ANY },
31243174 { "options-maybe" , processOptionFileMaybe , false, STAGE_ANY },
0 commit comments