Skip to content

Commit

Permalink
Abendlicher Zwischenstand
Browse files Browse the repository at this point in the history
  • Loading branch information
drolbr committed Jan 22, 2009
1 parent 0cc773f commit b07cd7b
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 38 deletions.
43 changes: 32 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@ conflict_$(suffix) \
report_$(suffix) \
detect_odd_nodes_$(suffix)

objects = expat_justparse_interface.o cgi-helper.o user_interface.o script_queries.o script_tools.o script-interpreter.o vigilance_control.o $(stmts)

objects = expat_justparse_interface.o cgi-helper.o user_interface.o script_queries.o script_tools.o vigilance_control.o $(stmts)
executables_objects = script-interpreter.o add_rule.o update_rule.o osm2load_infile.o
executables = cgi-bin/interpreter cgi-bin/add_rule cgi-bin/update_rule import_osm osmy_vigilance
tool_headers = expat_justparse_interface.h script_datatypes.h script_queries.h script_tools.h user_interface.h

main: $(executables)

suffix = statement.o
main: suffix = statement.o
main: $(objects)
g++ -o cgi-bin/input-interpreter -O3 -Wall -lexpat $(objects) `mysql_config --libs`
cgi-bin/interpreter: suffix = statement.o
cgi-bin/interpreter: $(objects) script-interpreter.o
g++ -o cgi-bin/interpreter -O3 -Wall -lexpat $(objects) script-interpreter.o `mysql_config --libs`

init_db: expat_justparse_interface.o cgi-helper.o user_interface.o osm2load_infile.o
g++ -o osm2load_infile -O3 -Wall -lexpat expat_justparse_interface.o cgi-helper.o user_interface.o osm2load_infile.o `mysql_config --libs`
suffix = statement.o
cgi-bin/add_rule: suffix = statement.o
cgi-bin/add_rule: $(objects) add_rule.o
g++ -o cgi-bin/add_rule -O3 -Wall -lexpat $(objects) add_rule.o `mysql_config --libs`

suffix = statement.o
cgi-bin/update_rule: suffix = statement.o
cgi-bin/update_rule: $(objects) update_rule.o
g++ -o cgi-bin/update_rule -O3 -Wall -lexpat $(objects) update_rule.o `mysql_config --libs`

import_osm: expat_justparse_interface.o cgi-helper.o user_interface.o osm2load_infile.o
g++ -o import_osm -O3 -Wall -lexpat expat_justparse_interface.o cgi-helper.o user_interface.o osm2load_infile.o `mysql_config --libs`

osmy_vigilance: osmy_vigilance.c
g++ -o osmy_vigilance -O3 -Wall `mysql_config --include` osmy_vigilance.c `mysql_config --libs`
Expand All @@ -45,16 +58,24 @@ script_tools.o: script_tools.c $(tool_headers) vigilance_control.h
%_statement.o: %_statement.c $(tool_headers) %_statement.h
g++ -c -O3 -Wall `mysql_config --include` $<

vigilance_control.o: vigilance_control.c vigilance_control.h script_datatypes.h expat_justparse_interface.h cgi-helper.h user_interface.h
g++ -c -O3 -Wall vigilance_control.c

suffix = statement.h
script-interpreter.o: script-interpreter.c expat_justparse_interface.h user_interface.h script_datatypes.h script_queries.h script_tools.h $(stmts) statement_factory.h
g++ -c -O3 -Wall `mysql_config --include` script-interpreter.c

suffix = statement.h
add_rule.o: add_rule.c expat_justparse_interface.h user_interface.h script_datatypes.h script_queries.h script_tools.h $(stmts) statement_factory.h
g++ -c -O3 -Wall `mysql_config --include` add_rule.c

suffix = statement.h
update_rule.o: update_rule.c expat_justparse_interface.h user_interface.h script_datatypes.h script_queries.h script_tools.h $(stmts) statement_factory.h
g++ -c -O3 -Wall `mysql_config --include` update_rule.c

osm2load_infile.o: osm2load_infile.c script_datatypes.h expat_justparse_interface.h cgi-helper.h user_interface.h
g++ -c -O3 -Wall `mysql_config --include` osm2load_infile.c

vigilance_control.o: vigilance_control.c vigilance_control.h script_datatypes.h expat_justparse_interface.h cgi-helper.h user_interface.h osmy_vigilance
g++ -c -O3 -Wall vigilance_control.c

clean: suffix = statement.o
clean:
rm -f $(objects)
rm -f $(objects) $(executable_objects)
143 changes: 143 additions & 0 deletions add_rule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include <cctype>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <stdlib.h>
#include <vector>
#include "expat_justparse_interface.h"
#include "script_datatypes.h"
#include "script_queries.h"
#include "script_tools.h"
#include "statement_factory.h"
#include "user_interface.h"

#include <mysql.h>

using namespace std;

static int output_mode(HTML);

MYSQL* mysql(NULL);

vector< Statement* > statement_stack;
vector< string > text_stack;

void start(const char *el, const char **attr)
{
Statement* statement(generate_statement(el));
if (statement)
{
statement->set_attributes(attr);
statement_stack.push_back(statement);
text_stack.push_back(get_parsed_text());
reset_parsed_text();
}
}

void end(const char *el)
{
if ((is_known_element(el)) && (statement_stack.size() > 1))
{
Statement* statement(statement_stack.back());
statement->add_final_text(get_parsed_text());
reset_parsed_text();
//Include an end-control to catch e.g. empty query-statements?
statement_stack.pop_back();
statement_stack.back()->add_statement(statement, text_stack.back());
text_stack.pop_back();
}
else if ((is_known_element(el)) && (statement_stack.size() == 1))
statement_stack.front()->add_final_text(get_parsed_text());
}

int main(int argc, char *argv[])
{
string xml_raw(get_xml_raw());
if (display_encoding_errors(cout))
return 0;
if (display_parse_errors(cout, xml_raw))
return 0;

parse(xml_raw, start, end);
if (display_parse_errors(cout, xml_raw))
return 0;
// getting special information for rules
string rule_name("");
int rule_replace(0);
Root_Statement* root_statement(dynamic_cast< Root_Statement* >(statement_stack.front()));
if (root_statement)
{
rule_name = root_statement->get_rule_name();
rule_replace = root_statement->get_rule_replace();
}
if (rule_name == "")
add_static_error("Adding a rule requires the name of the rule.");
if (rule_replace)
add_static_error("Providing a version-id while adding a rule is not allowed.");

xml_raw = xml_raw.substr(xml_raw.find("<osm-script"));
xml_raw = xml_raw.substr(xml_raw.find('>') + 1);
if (xml_raw.find("</osm-script>") != string::npos)
xml_raw = xml_raw.substr(0, xml_raw.find("</osm-script>"));
else
add_static_error("No content between start and end of the root-tag.");

if (display_static_errors(cout, xml_raw))
return 0;

//Sanity-Check

mysql = mysql_init(NULL);

if (!mysql_real_connect(mysql, "localhost", "osm", "osm", "osm", 0, NULL,
CLIENT_LOCAL_FILES))
{
runtime_error("Connection to database failed.\n", cout);
return 0;
}

out_header(cout, output_mode);

int body_id(int_query(mysql, "select max(id) from rule_bodys")+1);

ostringstream temp;
temp<<"select id from rule_names where name = '";
escape_insert(temp, rule_name);
temp<<'\'';
int name_id(int_query(mysql, temp.str()));

if (name_id)
{
temp.str("");
temp<<"Rule '"<<rule_name<<"' already exists in the database.";
runtime_error(temp.str(), cout);
out_footer(cout, output_mode);
return 0;
}

name_id = int_query(mysql, "select max(id) from rule_names") + 1;
temp.str("");
temp<<"insert rule_names values ("<<name_id<<", '";
escape_insert(temp, rule_name);
temp<<"')";
mysql_query(mysql, temp.str().c_str());

temp.str("");
temp<<"insert rule_bodys values ("<<body_id<<", "<<name_id<<", '";
escape_insert(temp, xml_raw);
temp<<"')";
mysql_query(mysql, temp.str().c_str());

temp.str("");
temp<<"Rule '"<<rule_name<<"' successfully updated.";
runtime_remark(temp.str(), cout);

//Rule execution

out_footer(cout, output_mode);

mysql_close(mysql);

return 0;
}
2 changes: 1 addition & 1 deletion expat_justparse_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ inline Ostream& escape_xml(Ostream& out, string s)
}

template < class Ostream >
inline Ostream& escape_insert(Ostream& out, string s)
inline Ostream& escape_insert(Ostream& out, string s)
{
unsigned int i(0);
while (i < s.size())
Expand Down
18 changes: 16 additions & 2 deletions html/testseite.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
</head>
<body>

<h1>Eingabe f&uuml;r Input-Interpreter</h1>
<h1>Eingabe f&uuml;r Interpreter</h1>

<form action="cgi-bin/input-interpreter" method="post" accept-charset="UTF-8">
<form action="cgi-bin/interpreter" method="post" accept-charset="UTF-8">
<textarea name="data" rows="25" cols="80"></textarea>
<input type="submit">
</form>

<h1>Eingabe f&uuml;r "Update Rule"</h1>

<form action="cgi-bin/update_rule" method="post" accept-charset="UTF-8">
<textarea name="data" rows="25" cols="80"></textarea>
<input type="submit">
</form>

<h1>Eingabe f&uuml;r "Add Rule"</h1>

<form action="cgi-bin/add_rule" method="post" accept-charset="UTF-8">
<textarea name="data" rows="25" cols="80"></textarea>
<input type="submit">
</form>
Expand Down
26 changes: 4 additions & 22 deletions init_database
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,7 @@ mysql -u osm -posm osm -e "create table key_s (id int unsigned, key_ varchar(218
mysql -u osm -posm osm -e "create table value_s (id int unsigned, value_ varchar(21844))"


mysql -u osm -posm osm -e "create table conflicts (id int, message varchar(21844))"
mysql -u osm -posm osm -e "create table node_conflicts (id int, conflict int)"
mysql -u osm -posm osm -e "create table way_conflicts (id int, conflict int)"
mysql -u osm -posm osm -e "create table relation_conflicts (id int, conflict int)"


mysql -u osm -posm osm -e "create table areas (id int)"
mysql -u osm -posm osm -e "create table area_segments (id int, lat_idx int, min_lat int, min_lon int, max_lat int, max_lon int)"
mysql -u osm -posm osm -e "create table area_tags (id int, key_ int unsigned, value_ int unsigned)"


bunzip2 <$1 | osm2load_infile --savemem --limit-node-tags --split-tables
bunzip2 <$1 | import_osm --savemem --limit-node-tags --split-tables


echo "Collecting statements ... "
Expand Down Expand Up @@ -151,16 +140,6 @@ echo "alter table member_roles add unique key(id);" >>init_database.sql
echo "alter table key_s add unique key(id), add index(key_);" >>init_database.sql
echo "alter table value_s add unique key(id), add index(value_);" >>init_database.sql

echo "alter table conflicts add unique key(id);" >>init_database.sql
echo "insert conflicts values (0, '');" >>init_database.sql
echo "alter table node_conflicts add key(id);" >>init_database.sql
echo "alter table way_conflicts add key(id);" >>init_database.sql
echo "alter table relation_conflicts add key(id);" >>init_database.sql
echo "alter table areas add unique key(id);" >>init_database.sql
echo "insert areas values (0);" >>init_database.sql
echo "alter table area_segments add key(id), add index(lat_idx, min_lon);" >>init_database.sql
echo "alter table area_tags add key(id);" >>init_database.sql

stmt="nodes_0"
i=1
while [[ $i -lt $numberofsubtables ]];
Expand Down Expand Up @@ -214,3 +193,6 @@ echo "create table way_tags (id int unsigned, key_ int unsigned, value_ int unsi

echo "Creating indices and merged tables ... "
mysql -u osm -posm osm <init_database.sql


./init_derived_database YES
49 changes: 49 additions & 0 deletions init_derived_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

PATH=./:$PATH
CONFIRM=$1
if [[ $1 != "YES" ]]; then
{
read -p "Proceeding will drop the current derived data in database osm. Do you really want to continue? " CONFIRM
};
fi

if [[ $CONFIRM != "YES" ]]; then
{
echo "Aborted on user request"
exit 0
};
fi


echo "drop table if exists rule_names, rule_bodys, conflicts, conflict_classes, node_conflicts, way_conflicts, relation_conflicts, areas, area_segments, area_tags;" >init_derived_data.sql

echo "create table rule_names (id int, name varchar(21844));" >>init_derived_data.sql

echo "create table rule_bodys (id int, rule int, source varchar(21844));" >>init_derived_data.sql

echo "create table conflicts (id int, message varchar(21844));" >>init_derived_data.sql
echo "create table node_conflicts (id int, conflict int);" >>init_derived_data.sql
echo "create table way_conflicts (id int, conflict int);" >>init_derived_data.sql
echo "create table relation_conflicts (id int, conflict int);" >>init_derived_data.sql

echo "create table areas (id int);" >>init_derived_data.sql
echo "create table area_segments (id int, lat_idx int, min_lat int, min_lon int, max_lat int, max_lon int);" >>init_derived_data.sql
echo "create table area_tags (id int, key_ int unsigned, value_ int unsigned);" >>init_derived_data.sql

echo "alter table rule_names add unique key(id), add key(name);" >>init_derived_data.sql
echo "alter table rule_bodys add key(id), add key(rule);" >>init_derived_data.sql
echo "alter table conflicts add unique key(id);" >>init_derived_data.sql
echo "insert conflicts values (0, '');" >>init_derived_data.sql
echo "alter table node_conflicts add key(id);" >>init_derived_data.sql
echo "alter table way_conflicts add key(id);" >>init_derived_data.sql
echo "alter table relation_conflicts add key(id);" >>init_derived_data.sql
echo "alter table areas add unique key(id);" >>init_derived_data.sql
echo "insert areas values (0);" >>init_derived_data.sql
echo "alter table area_segments add key(id), add index(lat_idx, min_lon);" >>init_derived_data.sql
echo "alter table area_tags add key(id);" >>init_derived_data.sql


echo "Creating tables for derived data ... "

mysql -u osm -posm osm <init_derived_data.sql
Loading

0 comments on commit b07cd7b

Please sign in to comment.