Skip to content

Commit 14c8140

Browse files
committed
democlient: simple working democlient
1 parent 614826f commit 14c8140

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Diff for: democlient/democlient.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ class CppcheckExecutor : public ErrorLogger {
3939
}
4040

4141
void run(const char code[]) {
42-
printf("%s\n", ErrorLogger::ErrorMessage::getXMLHeader(2).c_str());
4342
cppcheck.check("test.c", code);
44-
printf("%s\n", ErrorLogger::ErrorMessage::getXMLFooter(2).c_str());
45-
printf("\n\n");
4643
}
4744

4845
void reportOut(const std::string &outmsg) { }
4946
void reportErr(const ErrorLogger::ErrorMessage &msg) {
50-
const std::string str(msg.toXML(true,2U));
51-
printf("%s\n", str.c_str());
47+
printf("%s\n", msg.toString(true).c_str());
5248
}
5349

5450
void reportProgress(const
@@ -70,28 +66,38 @@ int main()
7066
{
7167
char data[4096] = {0};
7268

69+
const char *query_string = getenv("QUERY_STRING");
70+
if (query_string)
71+
std::strncpy(data, query_string, sizeof(data)-2);
72+
7373
const char *lenstr = getenv("CONTENT_LENGTH");
7474
if (lenstr) {
7575
int len = std::min(1 + atoi(lenstr), (int)(sizeof(data) - 2));
7676
fgets(data, len, stdin);
77-
} else {
78-
const char *s = getenv("QUERY_STRING");
79-
std::strncpy(data, s?s:"", sizeof(data)-2);
8077
}
8178

8279
char code[4096] = {0};
8380
unencode(data, code);
8481

82+
if (strlen(code) > 1000) {
83+
puts("Content-type: text/html\r\n\r\n");
84+
puts("<html><body>For performance reasons the code must be shorter than 1000 chars.</body></html>");
85+
return EXIT_SUCCESS;
86+
}
87+
8588
FILE *logfile = fopen("democlient.log", "at");
8689
if (logfile != NULL) {
8790
fprintf(logfile, "===========================================================\n%s\n", code);
8891
fclose(logfile);
8992
}
9093

91-
printf("Content-type: text/plain\n\n");
94+
puts("Content-type: text/html\r\n\r\n");
95+
puts("<html><body><pre>");
9296

9397
CppcheckExecutor cppcheckExecutor;
9498
cppcheckExecutor.run(code);
9599

100+
puts("</pre>Done!</body></html>");
101+
96102
return EXIT_SUCCESS;
97103
}

Diff for: htdocs/demo/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function checkCodeLength() {
4646
<div id="content">
4747
<div class="wrap">
4848
<h2>Online Demo</h2>
49-
<form action="/demo/report/" name="f" onsubmit="return checkCodeLength();" method="post" target="_blank">
49+
<form action="/cgi-bin/democlient-test.cgi" name="f" onsubmit="return checkCodeLength();" method="get" target="_blank">
5050
<p><label for="code">Enter code:</label> <span class="maxChars">(max 1024 characters)</span><br />
5151
<textarea id="code" name="code" rows="20" cols="80">
5252
void f()

Diff for: runastyle

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ options="--pad-header --unpad-paren --suffix=none --convert-tabs"
1818

1919
astyle $style $options cli/*.cpp
2020
astyle $style $options cli/*.h
21+
astyle $style $options democlient/*.cpp
2122
astyle $style $options gui/*.cpp
2223
astyle $style $options gui/*.h
2324
astyle $style $options -r gui/test/*.cpp

0 commit comments

Comments
 (0)