1818#include "htable.h"
1919#include "ptrarray.h"
2020#include "fname.h"
21+ #include "ptrarray.h"
2122
2223#include <string.h> /* strerror */
2324#include <stdlib.h> /* exit */
@@ -661,17 +662,36 @@ static void printVersion(void)
661662 exit (0 );
662663}
663664
665+ static void deleteInputSpec (void * data )
666+ {
667+ struct inputSpec * inputSpec = data ;
668+ if (inputSpec -> tempFileName )
669+ {
670+ remove (inputSpec -> tempFileName );
671+ eFree (inputSpec -> tempFileName );
672+ }
673+ eFree (data );
674+ }
675+
676+ static void addInputSpec (ptrArray * inputSpecs , const char * name )
677+ {
678+ struct inputSpec * i = eMalloc (sizeof (struct inputSpec ));
679+
680+ i -> tagFileName = name ;
681+ i -> tempFileName = NULL ;
682+
683+ ptrArrayAdd (inputSpecs , i );
684+ }
685+
664686extern int main (int argc , char * * argv )
665687{
666688 int i ;
667689 bool ignore_prefix = false;
668690
669691 tagPrintOptions printOpts = {0 };
670692 readOptions readOpts = {0 };
671- struct inputSpec inputSpec = {
672- .tagFileName = "tags" ,
673- .tempFileName = NULL ,
674- };
693+ ptrArray * inputSpecs = ptrArrayNew (deleteInputSpec );
694+
675695 struct actionSpec actionSpec = {
676696 .action = ACTION_NONE ,
677697 .name = NULL ,
@@ -755,7 +775,7 @@ extern int main (int argc, char **argv)
755775 else if (strcmp (optname , "tag - file ") == 0 )
756776 {
757777 if (i + 1 < argc )
758- inputSpec . tagFileName = argv [++ i ];
778+ addInputSpec ( inputSpecs , argv [++ i ]) ;
759779 else
760780 printUsage (stderr , 1 );
761781 }
@@ -888,11 +908,12 @@ extern int main (int argc, char **argv)
888908 case 't' :
889909 if (arg [j + 1 ] != '\0' )
890910 {
891- inputSpec .tagFileName = arg + j + 1 ;
892- j += strlen (inputSpec .tagFileName );
911+ const char * tname = arg + j + 1 ;
912+ addInputSpec (inputSpecs , tname );
913+ j += strlen (tname );
893914 }
894915 else if (i + 1 < argc )
895- inputSpec . tagFileName = argv [++ i ];
916+ addInputSpec ( inputSpecs , argv [++ i ]) ;
896917 else
897918 printUsage (stderr , 1 );
898919 break ;
@@ -964,24 +985,55 @@ extern int main (int argc, char **argv)
964985 exit (1 );
965986 }
966987
988+ size_t input_count = ptrArrayCount (inputSpecs );
989+ #ifndef READTAGS_DSL
990+ if (input_count > 0 )
991+ {
992+ /* mk_mingw.mak sets -DREADTAGS_DSL.
993+ * mk_mvc.mak doesn't. */
994+ fprintf (stderr ,
995+ "Processsing multiple tags is not supported with this (!READTAGS_DSL) build confiugraion." );
996+ exit (1 );
997+ }
998+ #endif
999+
9671000#ifdef READTAGS_DSL
968- if (Sorter )
1001+ if (Sorter || input_count > 0 )
9691002 actionSpec .tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc )freeCopiedTag );
9701003#endif
9711004
972- if (actionSpec . action & ACTION_LIST_PTAGS )
1005+ if (ptrArrayIsEmpty ( inputSpecs ) )
9731006 {
974- if (actionSpec .canonicalizing )
975- actionSpec .canon .ptags = true;
976- listTags (& inputSpec , true, & printOpts , & actionSpec );
977- if (actionSpec .canonicalizing )
978- actionSpec .canon .ptags = false;
1007+ addInputSpec (inputSpecs , "tags" );
1008+ input_count ++ ;
1009+ }
1010+
1011+ for (unsigned int i = 0 ; i < input_count ; i ++ )
1012+ {
1013+ struct inputSpec * inputSpec = ptrArrayItem (inputSpecs , i );
1014+
1015+ if (actionSpec .action & ACTION_LIST_PTAGS )
1016+ {
1017+ if (actionSpec .canonicalizing )
1018+ actionSpec .canon .ptags = true;
1019+ listTags (inputSpec , true, & printOpts , & actionSpec );
1020+ if (actionSpec .canonicalizing )
1021+ actionSpec .canon .ptags = false;
1022+ }
1023+
1024+ if (actionSpec .action & ACTION_FIND )
1025+ findTag (inputSpec , actionSpec .name , & readOpts , & printOpts , & actionSpec );
1026+ else if (actionSpec .action & ACTION_LIST )
1027+ listTags (inputSpec , false, & printOpts , & actionSpec );
1028+
1029+ if (actionSpec .canon .cacheTable )
1030+ {
1031+ canonFnameCacheTableDelete (actionSpec .canon .cacheTable );
1032+ actionSpec .canon .cacheTable = NULL ;
1033+ }
9791034 }
9801035
981- if (actionSpec .action & ACTION_FIND )
982- findTag (& inputSpec , actionSpec .name , & readOpts , & printOpts , & actionSpec );
983- else if (actionSpec .action & ACTION_LIST )
984- listTags (& inputSpec , false, & printOpts , & actionSpec );
1036+ ptrArrayDelete (inputSpecs );
9851037
9861038 if (actionSpec .tagEntryArray )
9871039 {
@@ -1008,13 +1060,5 @@ extern int main (int argc, char **argv)
10081060 f_destroy (Formatter );
10091061#endif
10101062
1011- if (actionSpec .canon .cacheTable )
1012- canonFnameCacheTableDelete (actionSpec .canon .cacheTable );
1013-
1014- if (inputSpec .tempFileName )
1015- {
1016- remove (inputSpec .tempFileName );
1017- eFree (inputSpec .tempFileName );
1018- }
10191063 return 0 ;
10201064}
0 commit comments