2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-06-13 23:17:33 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-06-13 23:17:33 +00:00
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-06-13 23:17:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-06-13 23:17:33 +00:00
|
|
|
#include <string>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdarg>
|
2004-06-13 23:17:33 +00:00
|
|
|
#endif
|
2004-06-12 04:45:36 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
|
2004-06-30 22:16:26 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
MIOFILE::MIOFILE() {
|
|
|
|
mf = 0;
|
|
|
|
f = 0;
|
|
|
|
buf = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MIOFILE::~MIOFILE() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIOFILE::init_mfile(MFILE* _mf) {
|
|
|
|
mf = _mf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIOFILE::init_file(FILE* _f) {
|
|
|
|
f = _f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIOFILE::init_buf(char* _buf) {
|
|
|
|
buf = _buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MIOFILE::printf(const char* format, ...) {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
if (mf) {
|
|
|
|
retval = mf->vprintf(format, ap);
|
|
|
|
} else {
|
|
|
|
retval = vfprintf(f, format, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* MIOFILE::fgets(char* dst, int len) {
|
|
|
|
if (f) {
|
|
|
|
return ::fgets(dst, len, f);
|
|
|
|
}
|
|
|
|
char* q = strchr(buf, '\n');
|
|
|
|
if (!q) return 0;
|
|
|
|
|
|
|
|
q++;
|
2004-07-02 22:03:23 +00:00
|
|
|
int n = (int)(q - buf);
|
2004-06-12 04:45:36 +00:00
|
|
|
if (n > len-1) n = len-1;
|
|
|
|
memcpy(dst, buf, n);
|
|
|
|
dst[n] = 0;
|
|
|
|
|
|
|
|
buf = q;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy from a file to static buffer
|
|
|
|
//
|
|
|
|
int copy_element_contents(MIOFILE& in, const char* end_tag, char* p, int len) {
|
|
|
|
char buf[256];
|
2004-09-22 21:08:26 +00:00
|
|
|
int n;
|
2004-06-12 04:45:36 +00:00
|
|
|
|
|
|
|
strcpy(p, "");
|
|
|
|
while (in.fgets(buf, 256)) {
|
|
|
|
if (strstr(buf, end_tag)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-23 07:24:51 +00:00
|
|
|
n = (int)strlen(buf);
|
2004-09-22 21:08:26 +00:00
|
|
|
if (n >= len-1) return ERR_XML_PARSE;
|
2004-06-12 04:45:36 +00:00
|
|
|
strcat(p, buf);
|
2004-09-22 21:08:26 +00:00
|
|
|
len -= n;
|
2004-06-12 04:45:36 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int copy_element_contents(MIOFILE& in, const char* end_tag, string& str) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
str = "";
|
|
|
|
while (in.fgets(buf, 256)) {
|
|
|
|
if (strstr(buf, end_tag)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
str += buf;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "copy_element_contents(): no end tag\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_37339d4dc0 = "$Id$";
|