Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

slurp file content from stdin using the specified filename

  • Loading branch information...
commit 8c2fd11fad82d863f41e195d286420cf31f172ee 1 parent a481003
Jake Douglas authored

Showing 4 changed files with 28 additions and 4 deletions. Show diff stats Hide diff stats

  1. +7 2 main.c
  2. +14 1 options.c
  3. +1 0  options.h
  4. +6 1 read.c
9 main.c
@@ -293,7 +293,7 @@ static boolean createTagsForEntry (const char *const entryName)
293 293 verbose ("excluding \"%s\"\n", entryName);
294 294 else if (status->isSymbolicLink && ! Option.followLinks)
295 295 verbose ("ignoring \"%s\" (symbolic link)\n", entryName);
296   - else if (! status->exists)
  296 + else if (! status->exists && ! Option.stdinFileName)
297 297 error (WARNING | PERROR, "cannot open source file \"%s\"", entryName);
298 298 else if (status->isDirectory)
299 299 resize = recurseIntoDirectory (entryName);
@@ -478,7 +478,7 @@ static void makeTags (cookedArgs *args)
478 478 if (filesRequired ())
479 479 error (FATAL, "No files specified. Try \"%s --help\".",
480 480 getExecutableName ());
481   - else if (! Option.recurse && ! etagsInclude ())
  481 + else if (! Option.recurse && ! Option.stdinFileName && ! etagsInclude ())
482 482 return;
483 483 }
484 484
@@ -505,6 +505,11 @@ static void makeTags (cookedArgs *args)
505 505 }
506 506 if (! files && Option.recurse)
507 507 resize = recurseIntoDirectory (".");
  508 +
  509 + if (Option.stdinFileName)
  510 + {
  511 + resize = createTagsForEntry(Option.stdinFileName);
  512 + }
508 513
509 514 timeStamp (1);
510 515
15 options.c
@@ -396,7 +396,7 @@ extern void setDefaultTagFileName (void)
396 396 extern boolean filesRequired (void)
397 397 {
398 398 boolean result = FilesRequired;
399   - if (Option.recurse)
  399 + if (Option.recurse || Option.stdinFileName)
400 400 result = FALSE;
401 401 return result;
402 402 }
@@ -959,6 +959,17 @@ static void processLanguageForceOption (
959 959 else
960 960 Option.language = language;
961 961 }
  962 +
  963 +static void processStdinFileName (
  964 + const char *const option, const char *const parameter)
  965 +{
  966 + if (strlen(parameter) == 0) {
  967 + error (FATAL, "No filename specified for --stdin-filename");
  968 + }
  969 +
  970 + Option.stdinFileName = stringCopy(parameter);
  971 +}
  972 +
962 973 static char* skipPastMap (char* p)
963 974 {
964 975 while (*p != EXTENSION_SEPARATOR &&
@@ -1391,6 +1402,7 @@ static parametricOption ParametricOptions [] = {
1391 1402 { "options", processOptionFile, FALSE },
1392 1403 { "sort", processSortOption, TRUE },
1393 1404 { "version", processVersionOption, TRUE },
  1405 + { "stdin-filename", processStdinFileName, FALSE }
1394 1406 };
1395 1407
1396 1408 static booleanOption BooleanOptions [] = {
@@ -1818,6 +1830,7 @@ extern void freeOptionResources (void)
1818 1830 freeString (&Option.tagFileName);
1819 1831 freeString (&Option.fileList);
1820 1832 freeString (&Option.filterTerminator);
  1833 + freeString (&Option.stdinFileName);
1821 1834
1822 1835 freeList (&Excluded);
1823 1836 freeList (&Option.ignore);
1  options.h
@@ -108,6 +108,7 @@ typedef struct sOptionValues {
108 108 boolean tagRelative; /* --tag-relative file paths relative to tag file */
109 109 boolean printTotals; /* --totals print cumulative statistics */
110 110 boolean lineDirectives; /* --linedirectives process #line directives */
  111 + char* stdinFileName; /* --from-stdin use this as the filename and get the file content from stdin */
111 112 #ifdef DEBUG
112 113 long debugLevel; /* -D debugging output */
113 114 unsigned long breakLine;/* -b source line at which to call lineBreak() */
7 read.c
@@ -259,8 +259,13 @@ extern boolean fileOpen (const char *const fileName, const langType language)
259 259 fclose (File.fp); /* close any open source file */
260 260 File.fp = NULL;
261 261 }
  262 +
  263 + if (Option.stdinFileName) {
  264 + File.fp = stdin;
  265 + } else {
  266 + File.fp = fopen (fileName, openMode);
  267 + }
262 268
263   - File.fp = fopen (fileName, openMode);
264 269 if (File.fp == NULL)
265 270 error (WARNING | PERROR, "cannot open \"%s\"", fileName);
266 271 else

0 comments on commit 8c2fd11

Please sign in to comment.
Something went wrong with that request. Please try again.