@@ -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." },
@@ -1675,6 +1680,27 @@ static void processHelpFullOption (
16751680 exit (0 );
16761681}
16771682
1683+ static void processOneshot (
1684+ const char * const option ,
1685+ const char * const parameter )
1686+ {
1687+ if (!parameter || parameter [0 ] == '\0' )
1688+ error (FATAL , "No input file name given to --%s=%s" , option , parameter );
1689+
1690+ static struct interactiveModeArgs args = { .sandbox = false, };
1691+ Option .interactive |= INTERACTIVE_MODE |INTERACTIVE_ONESHOT ;
1692+
1693+ #ifdef HAVE_SECCOMP
1694+ Option .interactive |= INTERACTIVE_WITH_SANDBOX ;
1695+ args .sandbox = true;
1696+ #endif
1697+
1698+ args .fname = parameter ;
1699+ args .limit = oneshotLimit ;
1700+
1701+ setMainLoop (interactiveOneshot , & args );
1702+ }
1703+
16781704#ifdef HAVE_JANSSON
16791705static void processInteractiveOption (
16801706 const char * const option ,
@@ -2723,6 +2749,28 @@ static bool inOneshotMode (void)
27232749 return (Option .interactive & INTERACTIVE_ONESHOT );
27242750}
27252751
2752+ static void oneshotSetLimit (size_t limit )
2753+ {
2754+ verbose ("adjust input limit of oneshot mode: %lu" , (unsigned long )limit );
2755+ oneshotLimit = limit ;
2756+ }
2757+
2758+ static void processOneshotLimit (
2759+ const char * const option , const char * const parameter )
2760+ {
2761+ if (parameter == NULL || parameter [0 ] == '\0' )
2762+ error (FATAL , "A positive number or 0 is needed after --%s option" , option );
2763+
2764+ unsigned long limit = 0 ;
2765+ if (!strToULong (parameter , 0 , & limit ))
2766+ error (FATAL , "Invalid oneshot limit: %s" , parameter );
2767+ if (limit > SIZE_MAX )
2768+ error (FATAL , "Too large limit: %s (> %lu)" ,
2769+ parameter , (unsigned long )SIZE_MAX );
2770+
2771+ oneshotSetLimit ((size_t )limit );
2772+ }
2773+
27262774static void processSortOption (
27272775 const char * const option , const char * const parameter )
27282776{
@@ -3125,6 +3173,8 @@ static parametricOption ParametricOptions [] = {
31253173 { "list-roles" , processListRolesOption , true, STAGE_ANY },
31263174 { "list-subparsers" , processListSubparsersOption , true, STAGE_ANY },
31273175 { "maxdepth" , processMaxRecursionDepthOption , true, STAGE_ANY },
3176+ { "oneshot" , processOneshot , true, STAGE_ANY },
3177+ { "oneshot-limit" , processOneshotLimit , true, STAGE_ANY },
31283178 { "optlib-dir" , processOptlibDir , false, STAGE_ANY },
31293179 { "options" , processOptionFile , false, STAGE_ANY },
31303180 { "options-maybe" , processOptionFileMaybe , false, STAGE_ANY },
0 commit comments