mirror of https://github.com/BOINC/boinc.git
139 lines
3.6 KiB
C
139 lines
3.6 KiB
C
// Berkeley Open Infrastructure for Network Computing
|
|
// http://boinc.berkeley.edu
|
|
// Copyright (C) 2005 University of California
|
|
//
|
|
// 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.
|
|
//
|
|
// 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.
|
|
//
|
|
// 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
|
|
|
|
// worker - application without BOINC runtime system;
|
|
// used for testing wrapper.
|
|
// What this does:
|
|
//
|
|
// copies one line of stdin to stdout
|
|
// copies one line of "in" to "out"
|
|
// uses 10 sec of CPU time
|
|
// (or as specified by a command-line arg)
|
|
//
|
|
// THIS PROGRAM SHOULDN'T USE ANY BOINC CODE. That's the whole point.
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
char buf[256];
|
|
FILE* in, *out;
|
|
|
|
fprintf(stderr, "worker starting\n");
|
|
in = fopen("in", "r");
|
|
out = fopen("out", "w");
|
|
if (!in || !out) {
|
|
fprintf(stderr, "missing file\n");
|
|
exit(1);
|
|
}
|
|
fgets(buf, 256, in);
|
|
fputs(buf, out);
|
|
|
|
fgets(buf, 256, stdin);
|
|
fputs(buf, stdout);
|
|
|
|
int start = time(0);
|
|
int nsec = 10;
|
|
if (argc > 1) nsec = atoi(argv[1]);
|
|
|
|
while (time(0) < start+nsec) {
|
|
double x=5;
|
|
for (int i=0; i<10000000; i++) {
|
|
x /= 2.1;
|
|
x += 1.5;
|
|
}
|
|
}
|
|
fputs("done!\n", stdout);
|
|
return 0;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
|
|
// take a string containing some space separated words.
|
|
// return an array of pointers to the null-terminated words.
|
|
// Modifies the string arg.
|
|
// Returns argc
|
|
// TODO: use strtok here
|
|
|
|
#define NOT_IN_TOKEN 0
|
|
#define IN_SINGLE_QUOTED_TOKEN 1
|
|
#define IN_DOUBLE_QUOTED_TOKEN 2
|
|
#define IN_UNQUOTED_TOKEN 3
|
|
|
|
int parse_command_line(char* p, char** argv) {
|
|
int state = NOT_IN_TOKEN;
|
|
int argc=0;
|
|
|
|
while (*p) {
|
|
switch(state) {
|
|
case NOT_IN_TOKEN:
|
|
if (isspace(*p)) {
|
|
} else if (*p == '\'') {
|
|
p++;
|
|
argv[argc++] = p;
|
|
state = IN_SINGLE_QUOTED_TOKEN;
|
|
break;
|
|
} else if (*p == '\"') {
|
|
p++;
|
|
argv[argc++] = p;
|
|
state = IN_DOUBLE_QUOTED_TOKEN;
|
|
break;
|
|
} else {
|
|
argv[argc++] = p;
|
|
state = IN_UNQUOTED_TOKEN;
|
|
}
|
|
break;
|
|
case IN_SINGLE_QUOTED_TOKEN:
|
|
if (*p == '\'') {
|
|
*p = 0;
|
|
state = NOT_IN_TOKEN;
|
|
}
|
|
break;
|
|
case IN_DOUBLE_QUOTED_TOKEN:
|
|
if (*p == '\"') {
|
|
*p = 0;
|
|
state = NOT_IN_TOKEN;
|
|
}
|
|
break;
|
|
case IN_UNQUOTED_TOKEN:
|
|
if (isspace(*p)) {
|
|
*p = 0;
|
|
state = NOT_IN_TOKEN;
|
|
}
|
|
break;
|
|
}
|
|
p++;
|
|
}
|
|
argv[argc] = 0;
|
|
return argc;
|
|
}
|
|
|
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
|
|
LPSTR command_line;
|
|
char* argv[100];
|
|
int argc;
|
|
|
|
command_line = GetCommandLine();
|
|
argc = parse_command_line( command_line, argv );
|
|
return main(argc, argv);
|
|
}
|
|
#endif
|