[Kst] kdeextragear-2/kst/datapush
George Staikos
staikos at kde.org
Wed Aug 13 09:02:14 CEST 2003
CVS commit by staikos:
parser for the format file, and return a list of all the filenames
M +31 -11 main.cpp 1.4
--- kdeextragear-2/kst/datapush/main.cpp #1.3:1.4
@@ -36,5 +36,5 @@ using namespace std;
-int parseFormatFile(FILE *fp);
+int parseFormatFile(FILE *fp, std::vector<std::string>& filenames);
int mainLoop(Listener *l, FILE *fp);
int handlePassiveMode(int& n, std::list<Socket*>& sockets, fd_set& rfds, fd_set& efds);
@@ -97,5 +97,6 @@ int main(int argc, char **argv) {
// try to parse it
- if (0 != parseFormatFile(fp)) {
+ std::vector<std::string> filenames;
+ if (0 != parseFormatFile(fp, filenames)) {
fclose(fp);
return -1;
@@ -261,13 +262,13 @@ int handleCommandMode(int& n, std::list<
char buf[1024];
if (0 < s->read(buf, 1024)) {
- if (0 == strncmp(buf, "quit", 4)) { // user requested quit
+ if (0 == ::strncmp(buf, "quit", 4)) { // user requested quit
s->close();
- } else if (0 == strncmp(buf, "format", 6)) { // user requested format
- lseek(fd, 0, SEEK_SET);
+ } else if (0 == ::strncmp(buf, "format", 6)) { // user requested format
+ ::lseek(fd, 0, SEEK_SET);
int rc;
- while ((rc = read(fd, buf, 1024)) > 0) {
+ while ((rc = ::read(fd, buf, 1024)) > 0) {
s->write(buf, rc);
}
- } else if (0 == strncmp(buf, "go", 2)) {
+ } else if (0 == ::strncmp(buf, "go", 2)) {
activations.push_back(s);
/*
@@ -276,5 +277,5 @@ int handleCommandMode(int& n, std::list<
buf[10] = 0; // truncate
sscanf(buf, "%ld", &pt);
- if (pt >= 0 && lseek(fd, pt, SEEK_SET) == pt) {
+ if (pt >= 0 && ::lseek(fd, pt, SEEK_SET) == pt) {
long readsz = fsize - pt;
@@ -287,5 +288,5 @@ int handleCommandMode(int& n, std::list<
#undef MIN
readsz -= len;
- if (read(fd, buf, len) != len) {
+ if (::read(fd, buf, len) != len) {
clearList(sockets);
return -1;
@@ -343,5 +344,5 @@ int handlePassiveMode(int& n, std::list<
char buf[1024];
if (0 < s->read(buf, 1024)) {
- if (0 == strncmp(buf, "quit", 4)) { // user requested quit
+ if (0 == ::strncmp(buf, "quit", 4)) { // user requested quit
s->close();
}
@@ -372,5 +373,24 @@ return 0;
-int parseFormatFile(FILE *fp) {
+int parseFormatFile(FILE *fp, std::vector<std::string>& filenames) {
+char buf[256];
+
+ while (!::feof(fp)) {
+ if (::fgets(buf, 256, fp)) {
+ char *tok = ::strtok(buf, " \n\r\t");
+ if (tok && tok[0] != '#') {
+ std::string field = tok;
+ std::vector<std::string> args;
+ while ((tok = ::strtok(0L, " \n\r\t")) != 0L) {
+ args.push_back(tok);
+ }
+
+ if (!args.empty() && args.front() == "RAW") {
+ filenames.push_back(field);
+ }
+ }
+ }
+ }
+
return 0;
}
More information about the Kst
mailing list