[Anjuta-list] [PATCH] Read code from standard input



Hi

I want to make CTAGS read the code from standard input (instead of file 
names) - here is a patch (diff -r -u) against 5.0.1 which adds an option '--' 
to make ctags read the code from standard input instead of a specified file. 
I will be grateful if this feature is added to a future release since I want 
to use this to generate tags from the output of gcc -E (pre-processed file).

I did not find any way to do it using the existing code but if I have missed 
something, please point me to it.

Thanks and regards.
Biswa.
diff -r -u ctags-5.0.1/main.c ctags-5.0.1-patch/main.c
--- ctags-5.0.1/main.c	Sun Apr 15 22:11:08 2001
+++ ctags-5.0.1-patch/main.c	Wed Sep 12 12:19:25 2001
@@ -1096,7 +1096,12 @@
     boolean resize = FALSE;
 
     Assert (entryName != NULL);
-    if (excludedFile (entryName))
+    if (strcmp(entryName, "-") == 0)
+    {
+        verbose("Reading from standard input..\n");
+        resize = parseFile("-");
+    }
+    else if (excludedFile (entryName))
 	verbose ("excluding \"%s\"\n", entryName);
     else if (isSymbolicLink (entryName)  &&  ! Option.followLinks)
 	verbose ("ignoring \"%s\" (symbolic link)\n", entryName);
@@ -1261,7 +1266,7 @@
     boolean files = (boolean)(! cArgOff (args) || Option.fileList != NULL
 			      || Option.filter);
 
-    if (! files  &&  ! Option.recurse)
+    if (! files  &&  ! Option.recurse && ! Option.readStdin)
 	error (FATAL, "No files specified. Try \"%s --help\".",
 	       getExecutableName ());
 
@@ -1271,6 +1276,11 @@
 
     timeStamp (0);
 
+    if (Option.readStdin)
+    {
+        verbose("Creating tags from standard input..\n");
+        resize = createTagsForEntry("-");
+    }
     if (! cArgOff (args))
     {
 	verbose ("Reading command line arguments\n");
diff -r -u ctags-5.0.1/options.c ctags-5.0.1-patch/options.c
--- ctags-5.0.1/options.c	Wed Apr 11 10:44:18 2001
+++ ctags-5.0.1-patch/options.c	Wed Sep 12 12:19:56 2001
@@ -1360,6 +1360,8 @@
 	printProgramIdentification ();
 	exit (0);
     }
+    else if (isOption(""))
+      Option.readStdin = TRUE;
 #ifndef RECURSE_SUPPORTED
     else if (isOption ("recurse"))
 	error (WARNING, "%s option not supported on this host", option);
diff -r -u ctags-5.0.1/options.h ctags-5.0.1-patch/options.h
--- ctags-5.0.1/options.h	Wed Apr 11 10:44:18 2001
+++ ctags-5.0.1-patch/options.h	Wed Sep 12 12:20:14 2001
@@ -95,6 +95,7 @@
     boolean tagRelative;    /* --tag-relative file paths relative to tag file */
     boolean printTotals;    /* --totals  print cumulative statistics */
     boolean lineDirectives; /* --linedirectives  process #line directives */
+    boolean readStdin; /* Read source code from standard input */
 #ifdef DEBUG
     long debugLevel;	    /* -D  debugging output */
     unsigned long breakLine;/* -b  source line at which to call lineBreak() */
diff -r -u ctags-5.0.1/read.c ctags-5.0.1-patch/read.c
--- ctags-5.0.1/read.c	Wed Apr 11 10:44:18 2001
+++ ctags-5.0.1-patch/read.c	Wed Sep 12 12:20:28 2001
@@ -234,7 +234,10 @@
 	File.fp = NULL;
     }
 
-    File.fp = fopen (fileName, openMode);
+    if (strcmp(fileName, "-") == 0)
+        File.fp = stdin;
+    else
+        File.fp = fopen (fileName, openMode);
     if (File.fp == NULL)
 	error (WARNING | PERROR, "cannot open \"%s\"", fileName);
     else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]