cc04868ac8e7b663ac9f6308e0c7f54a143c5ae5
[h316.git] / pc-tools / ldc2 / src / tool.cpp
1 #include <vector>
2 #include <string>
3
4 #include <stdio.h>
5
6 #include "config.hh"
7
8 using namespace std;
9
10 /*!
11 *\brief Output a vector of strings to out_fd.
12 *\arg strings A vector containing text.
13 *\retval 0 The vector was empty.
14 *\retval 1 The vector contained text.
15 */
16 int dump_vector(vector<string> strings){
17 int res=0;
18 for (vector<string>::iterator iter=strings.begin();iter<strings.end();iter++){
19 char buffer[50000];
20 snprintf(buffer,50000,"%s\n",(*iter).c_str());
21 write (out_fd,buffer,strlen(buffer));
22 res=1;
23 }
24 return res;
25 }
26
27 /*!
28 *\brief Output a vector of strings.
29 *\arg strings A vector containing text.
30 *\arg fp A FILE pointer where to write to.
31 *\retval 0 The vector was empty.
32 *\retval 1 The vector contained text.
33 */
34 int dump_vector_fp(vector<string> strings, FILE * fp){
35 int res=0;
36 for (vector<string>::iterator iter=strings.begin();iter<strings.end();iter++){
37 fprintf(fp,"%s\n",(*iter).c_str());
38 res=1;
39 }
40 return res;
41 }
42
43 /*!
44 *\brief add contents of one vector to another vector uniquely.
45 *\param target Reference to the target vector.
46 *\param source Reference to the vector whose contents are to be added
47 * to target.
48 */
49 template<typename T>
50 void merge_vector_unique(vector<T> &target, const vector<T> & source){
51 for (unsigned int isource=0; isource<source.size();isource++){
52 bool already_present=false;
53 for (int itarget=0;itarget<target.size();itarget++)
54 if (target[itarget]==source[isource]){
55 already_present=true;
56 break;
57 }
58 if (!already_present) target.insert(target.end().source[isource]);
59 }
60 }