18
18
#include "htable.h"
19
19
#include "ptrarray.h"
20
20
#include "fname.h"
21
+ #include "ptrarray.h"
21
22
22
23
#include <string.h> /* strerror */
23
24
#include <stdlib.h> /* exit */
@@ -661,17 +662,36 @@ static void printVersion(void)
661
662
exit (0 );
662
663
}
663
664
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
+
664
686
extern int main (int argc , char * * argv )
665
687
{
666
688
int i ;
667
689
bool ignore_prefix = false;
668
690
669
691
tagPrintOptions printOpts = {0 };
670
692
readOptions readOpts = {0 };
671
- struct inputSpec inputSpec = {
672
- .tagFileName = "tags" ,
673
- .tempFileName = NULL ,
674
- };
693
+ ptrArray * inputSpecs = ptrArrayNew (deleteInputSpec );
694
+
675
695
struct actionSpec actionSpec = {
676
696
.action = ACTION_NONE ,
677
697
.name = NULL ,
@@ -755,7 +775,7 @@ extern int main (int argc, char **argv)
755
775
else if (strcmp (optname , "tag - file ") == 0 )
756
776
{
757
777
if (i + 1 < argc )
758
- inputSpec . tagFileName = argv [++ i ];
778
+ addInputSpec ( inputSpecs , argv [++ i ]) ;
759
779
else
760
780
printUsage (stderr , 1 );
761
781
}
@@ -888,11 +908,12 @@ extern int main (int argc, char **argv)
888
908
case 't' :
889
909
if (arg [j + 1 ] != '\0' )
890
910
{
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 );
893
914
}
894
915
else if (i + 1 < argc )
895
- inputSpec . tagFileName = argv [++ i ];
916
+ addInputSpec ( inputSpecs , argv [++ i ]) ;
896
917
else
897
918
printUsage (stderr , 1 );
898
919
break ;
@@ -964,24 +985,55 @@ extern int main (int argc, char **argv)
964
985
exit (1 );
965
986
}
966
987
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
+
967
1000
#ifdef READTAGS_DSL
968
- if (Sorter )
1001
+ if (Sorter || input_count > 0 )
969
1002
actionSpec .tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc )freeCopiedTag );
970
1003
#endif
971
1004
972
- if (actionSpec . action & ACTION_LIST_PTAGS )
1005
+ if (ptrArrayIsEmpty ( inputSpecs ) )
973
1006
{
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
+ }
979
1034
}
980
1035
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 );
985
1037
986
1038
if (actionSpec .tagEntryArray )
987
1039
{
@@ -1008,13 +1060,5 @@ extern int main (int argc, char **argv)
1008
1060
f_destroy (Formatter );
1009
1061
#endif
1010
1062
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
- }
1019
1063
return 0 ;
1020
1064
}
0 commit comments