source: MondoRescue/branches/stable/monitas/from-mondo.c@ 1205

Last change on this file since 1205 was 1168, checked in by Bruno Cornec, 17 years ago

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

File size: 5.7 KB
Line 
1/* from-mondo.c
2
3- subroutines copied from Mondo
4
5*/
6
7#include "structs.h"
8#include "mr_str.h"
9
10
11//extern void log_it_SUB(char*, t_loglevel, char*);
12char *call_program_and_get_last_line_of_output(char*);
13int call_program_and_log_output (char *);
14bool does_file_exist (char *);
15int make_hole_for_file (char *);
16
17
18
19
20
21/*************************************************************************
22 * *call_program_and_get_last_line_of_ouput() -- Hugo Rabson *
23 * *
24 * Purpose: *
25 * Called by: *
26 * Returns: *
27 *************************************************************************/
28
29char *
30call_program_and_get_last_line_of_output (char *call)
31{
32 /** buffers ******************************************************/
33 static char result[MAX_STR_LEN+1];
34 char tmp[MAX_STR_LEN+1];
35
36 /** pointers *****************************************************/
37 FILE *fin;
38
39 /** initialize data **********************************************/
40 result[0] = '\0';
41
42 /***********************************************************************/
43 if ((fin = popen (call, "r")))
44 {
45 for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin);
46 fgets (tmp, MAX_STR_LEN, fin))
47 {
48 if (strlen (tmp) > 1)
49 {
50 strcpy (result, tmp);
51 }
52 }
53 pclose (fin);
54 }
55 mr_strip_spaces (result);
56 return (result);
57}
58
59
60
61
62
63
64/*************************************************************************
65 * call_program_and_log_output() -- Hugo Rabson *
66 * *
67 * Purpose: *
68 * Called by: *
69 * Returns: *
70 *************************************************************************/
71int
72call_program_and_log_output (char *program)
73{
74 /** buffer *******************************************************/
75 char callstr[MAX_STR_LEN+1];
76 char incoming[MAX_STR_LEN+1];
77 char tmp[MAX_STR_LEN+1];
78
79 /** int **********************************************************/
80 int res;
81 int i;
82 int len;
83
84 /** pointers ****************************************************/
85 FILE *fin;
86 char *p;
87
88 /** end vars ****************************************************/
89 sprintf (callstr, "%s > /tmp/mondo-run-prog.tmp 2> /tmp/mondo-run-prog.err",
90 program);
91 while ((p = strchr (callstr, '\r')))
92 {
93 *p = ' ';
94 }
95 while ((p = strchr (callstr, '\n')))
96 {
97 *p = ' ';
98 } /* single '=' is intentional */
99 res = system (callstr);
100 len = strlen (program);
101 for (i = 0; i < 35 - len / 2; i++)
102 {
103 tmp[i] = '-';
104 }
105 tmp[i] = '\0';
106 strcat (tmp, " ");
107 strcat (tmp, program);
108 strcat (tmp, " ");
109 for (i = 0; i < 35 - len / 2; i++)
110 {
111 strcat (tmp, "-");
112 }
113 log_it (debug, tmp);
114 system ("cat /tmp/mondo-run-prog.err >> /tmp/mondo-run-prog.tmp");
115 unlink ("/tmp/mondo-run-prog.err");
116 fin = fopen ("/tmp/mondo-run-prog.tmp", "r");
117 if (fin)
118 {
119 for (fgets (incoming, MAX_STR_LEN, fin); !feof (fin);
120 fgets (incoming, MAX_STR_LEN, fin))
121 {
122/* for(i=0; incoming[i]!='\0'; i++);
123 for(; i>0 && incoming[i-1]<=32; i--);
124 incoming[i]='\0';
125*/
126 mr_strip_spaces (incoming);
127 log_it (debug, incoming);
128 }
129 fclose (fin);
130 }
131 log_it
132 (debug, "--------------------------------end of output------------------------------");
133 if (res)
134 {
135 log_it (debug, "...ran with errors.");
136 }
137 /* else { log_it(debug, "...ran just fine. :-)"); } */
138 return (res);
139}
140
141
142
143
144
145/*************************************************************************
146 * does_file_exist() -- Hugo Rabson *
147 * *
148 * Purpose: *
149 * Called by: *
150 * Returns: *
151 *************************************************************************/
152bool
153does_file_exist (char *filename)
154{
155
156 /** structures ***************************************************/
157 struct stat buf;
158 /*****************************************************************/
159
160 if (lstat (filename, &buf))
161 {
162 return (false);
163 }
164 else
165 {
166 return (true);
167 }
168}
169
170
171
172
173
174/*-----------------------------------------------------------*/
175
176
177
178/*************************************************************************
179 * make_hole_for_file() -- Hugo Rabson *
180 * *
181 * Purpose: *
182 * Called by: *
183 * Returns: *
184 *************************************************************************/
185int
186make_hole_for_file (char *outfile_fname)
187{
188 /** buffer *******************************************************/
189 char command[MAX_STR_LEN+1];
190
191 /** int *********************************************************/
192 int res = 0;
193
194 /** end vars ****************************************************/
195
196 sprintf (command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
197 res += system (command);
198 sprintf (command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
199 res += system (command);
200 sprintf (command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
201 res += system (command);
202 unlink (outfile_fname);
203 return (0);
204}
205
Note: See TracBrowser for help on using the repository browser.