@@ -64,123 +64,6 @@ namespace bsys=boost::system;
6464
6565namespace SCIRun {
6666
67- // //////////////////////////////////////////////////////////
68- //
69- // InsertStringInFile
70- //
71- // If "match" is found in "filename", then add "add_text" text
72- // to the file _after_ the location of the matched text.
73- //
74- // Normally, I would just use sed via system() to edit a file,
75- // but for some reason system() calls never work from Dataflow
76- // processes in linux. Oh well, sed isn't natively available
77- // under windows, so I'd have to do something like this anyhow
78- // - Chris Moulding
79-
80- void
81- InsertStringInFile (char * filename, const char * match, const char * add_text)
82- {
83- // / @todo: rewrite in C++
84- char * newfilename = new char [strlen (filename)+2 ];
85- char c;
86- sprintf (newfilename," %s~" ,filename);
87- FILE* ifile;
88- FILE* ofile;
89-
90- /* create a copy of the original file */
91- ifile = fopen (filename," r" );
92-
93- if ( !ifile ) {
94- printf ( " ERROR: In Core/Util/FileUtils.cc: InsertStringInFile:\n " );
95- printf (" File '%s' does not exist!\n " , filename );
96- printf ( " There is something seriously wrong with your SCIRun installation.\n " );
97- printf (
" Please contact [email protected] .\n " );
98- exit ( 1 );
99- }
100-
101- ofile = fopen (newfilename," w" );
102-
103- c = (char )fgetc (ifile);
104- while (c!=(char )EOF) {
105- fprintf (ofile," %c" ,c);
106- c = (char )fgetc (ifile);
107- }
108- fclose (ifile);
109- fclose (ofile);
110-
111- // Search the copy for an instance of "match"...
112- int index1 = 0 ;
113- unsigned int index2 = 0 ;
114- int foundat = -1 ;
115- ifile = fopen (newfilename," r" );
116- c = (char )fgetc (ifile);
117- while (c!=(char )EOF) {
118- if (c==match[index2]) {
119- foundat = index1 + strlen (match);
120- while (index2<strlen (match) && c!=(char )EOF && c==match[index2]) {
121- c = (char )fgetc (ifile);
122- index1++;
123- index2++;
124- }
125- if ( foundat >= 0 && index2 != strlen (match) ) {
126- foundat = -1 ;
127- index2 = 0 ;
128- } else {
129- break ;
130- }
131- }
132- c = (char )fgetc (ifile);
133- index1++;
134- }
135- fclose (ifile);
136-
137- // If an instance of match was found, insert the indicated string...
138- if ( foundat >= 0 ) {
139- index1 = 0 ;
140- ifile = fopen (newfilename," r" );
141- ofile = fopen (filename," w" );
142- c = (char )fgetc (ifile);
143- while (c!=(char )EOF) {
144- if ( index1 == foundat ) {
145- fprintf ( ofile, " %s" , add_text );
146- }
147- fprintf (ofile," %c" ,c);
148- c = (char )fgetc (ifile);
149- index1++;
150- }
151- fclose (ifile);
152- fclose (ofile);
153- }
154- }
155-
156- std::map<int ,char *>*
157- GetFilenamesEndingWith (const char * d, const char * ext)
158- {
159- std::map<int ,char *>* newmap = nullptr ;
160- dirent* file = nullptr ;
161- DIR* dir = opendir (d);
162- char * newstring = nullptr ;
163-
164- if (!dir)
165- return nullptr ;
166-
167- newmap = new std::map<int ,char *>;
168-
169- file = readdir (dir);
170- while (file) {
171- if ((strlen (file->d_name )>=strlen (ext)) &&
172- (strcmp (&(file->d_name [strlen (file->d_name )-strlen (ext)]),ext)==0 )) {
173- newstring = new char [strlen (file->d_name )+1 ];
174- sprintf (newstring," %s" ,file->d_name );
175- newmap->insert (std::pair<int ,char *>(newmap->size (),newstring));
176- }
177- file = readdir (dir);
178- }
179-
180- closedir (dir);
181- return newmap;
182- }
183-
18467std::string
18568substituteTilde ( const std::string & dirstr ) {
18669 std::string realdirstr = dirstr;
0 commit comments