84af181997-11-14Per Hedbor /* This is a Roxen Challenger(r) module. Copyright (c) Idonex 1997. * Released under GPL * made by Per Hedbor */
558cba1998-08-17Peter Bortas constant cvs_version = "$Id: wizard_tag.pike,v 1.14 1998/08/17 04:24:00 peter Exp $";
84af181997-11-14Per Hedbor constant thread_safe=1; #include <module.h> inherit "module"; inherit "wizard"; mixed *register_module() {
276a371997-11-14Per Hedbor  return ({MODULE_PARSER,"Wizard generator",
fc57521998-03-06Per Hedbor  "Generates wizards<p>See &lt;wizard help&gt; for more information\n", ({}),1,});
84af181997-11-14Per Hedbor }
f1be801998-02-22Per Hedbor string internal_page(string t, mapping args, string contents, int l, int ol, mapping f)
84af181997-11-14Per Hedbor {
f1be801998-02-22Per Hedbor  f->pages +=({({contents,ol+l})});
84af181997-11-14Per Hedbor }
6d03cf1998-07-22Johan Schön string internal_done(string t, mapping args, string contents, int l, int ol, mapping f) { f->done=contents; }
f1be801998-02-22Per Hedbor string fix_relative(string file, object id) { if(file != "" && file[0] == '/') return file; file = combine_path(dirname(id->not_query) + "/", file); return file; } string old_pike = ""; object old_wizard = 0;
959a491998-07-03Marcus Comstedt string tag_wizard(string t, mapping args, string contents, object id, object file, mapping defines)
84af181997-11-14Per Hedbor {
558cba1998-08-17Peter Bortas  if(!id->misc->line) id->misc->line=-1;
84af181997-11-14Per Hedbor  mapping f = ([ "pages":({}) ]);
62fbb11998-07-19Henrik Grubbström (Grubba)  string pike = ("inherit \"wizard\";\n" + #if (__VERSION__ >= 0.6)
558cba1998-08-17Peter Bortas  sprintf("# "+id->misc->line+" %O\n"
62fbb11998-07-19Henrik Grubbström (Grubba)  "string name = %O;\n", id->not_query, (args->name||"unnamed")) #else
558cba1998-08-17Peter Bortas  "# "+id->misc->line+" \""+id->not_query+"\"\n"
62fbb11998-07-19Henrik Grubbström (Grubba)  "string name=\""+(args->name||"unnamed") + "\";\n" #endif /* __VERSION__ >= 0.6 */ );
84af181997-11-14Per Hedbor  int p;
41d0f91998-02-20Per Hedbor  foreach(glob("*-label", indices(args)), string a) {
62fbb11998-07-19Henrik Grubbström (Grubba) #if __VERSION__ >= 0.6
558cba1998-08-17Peter Bortas  pike += sprintf("# "+id->misc->line+" %O\n",
62fbb11998-07-19Henrik Grubbström (Grubba)  id->not_query); pike += sprintf(" string "+replace(replace(a,"-","_"),({"(",")","+",">"}), ({"","","",""}))+ " = %O;\n", args[a]); #else
558cba1998-08-17Peter Bortas  pike += ("# "+id->misc->line+" \""+id->not_query+"\"\n");
41d0f91998-02-20Per Hedbor  pike += " string "+replace(replace(a,"-","_"),({"(",")","+",">"}), ({"","","",""}))+ " = \""+replace(args[a], ({"\"","\n","\r", "\\"}), ({"\\\"", "\\n", "\\r", "\\\\"}))+"\";\n";
62fbb11998-07-19Henrik Grubbström (Grubba) #endif /* __VERSION__ >= 0.6 */
41d0f91998-02-20Per Hedbor  }
f1be801998-02-22Per Hedbor  if(args->ok) {
62fbb11998-07-19Henrik Grubbström (Grubba) #if __VERSION__ >= 0.6
558cba1998-08-17Peter Bortas  pike += sprintf("# "+id->misc->line+" %O\n", id->not_query);
62fbb11998-07-19Henrik Grubbström (Grubba)  pike += sprintf("mixed wizard_done(object id)\n" "{\n" " id->not_query = %O;\n\""+ " return roxen->get_file( id );\n" "}\n\n", fix_relative(args->ok, id)); #else
558cba1998-08-17Peter Bortas  pike += ("# "+id->misc->line+" \""+id->not_query+"\"\n");
f1be801998-02-22Per Hedbor  pike += ("mixed wizard_done(object id)\n" "{\n" " id->not_query = \""+ fix_relative(replace(args->ok, ({"\"","\n","\r", "\\"}), ({"\\\"", "\\n", "\\r", "\\\\"})),id)+"\";\n" " return roxen->get_file( id );\n" "}\n\n");
62fbb11998-07-19Henrik Grubbström (Grubba) #endif /* __VERSION__ >= 0.6 */
f1be801998-02-22Per Hedbor  }
6d03cf1998-07-22Johan Schön  parse_html_lines(contents, ([]), ([ "page":internal_page, "done":internal_done ]),
558cba1998-08-17Peter Bortas  (int)id->misc->line,f);
0487401998-08-05Henrik Grubbström (Grubba)  if (f->done && !args->ok) { #if __VERSION__ >= 0.6 pike += sprintf("mixed wizard_done(object id)\n" "{\n" " return parse_rxml(%O, id);\n" "}\n", f->done); #else
6d03cf1998-07-22Johan Schön  pike += ("mixed wizard_done(object id)\n" "{\n" " return parse_rxml(\""+replace(f->done, ({"\"","\n","\r", "\\"}), ({"\\\"", "\\n", "\\r", "\\\\"}))+ "\",id);\n" "}\n");
0487401998-08-05Henrik Grubbström (Grubba) #endif /* __VERSION__ >= 0.6 */ }
f1be801998-02-22Per Hedbor  foreach(f->pages, array q)
84af181997-11-14Per Hedbor  {
62fbb11998-07-19Henrik Grubbström (Grubba) #if __VERSION__ >= 0.6 pike += sprintf("# "+q[1]+" %O\n", id->not_query); pike += sprintf("string page_"+p+"(object id) {" + " return %O;\n" "}\n", q[0]); #else
f1be801998-02-22Per Hedbor  pike += ("# "+q[1]+" \""+id->not_query+"\"\n");
84af181997-11-14Per Hedbor  pike += ("string page_"+p+"(object id) {" +
f1be801998-02-22Per Hedbor  "return \""+replace(q[0], ({"\"","\n","\r", "\\"}),
84af181997-11-14Per Hedbor  ({"\\\"", "\\n", "\\r", "\\\\"}))+"\";}\n");
62fbb11998-07-19Henrik Grubbström (Grubba) #endif /* __VERSION__ >= 0.6 */
84af181997-11-14Per Hedbor  p++; }
f1be801998-02-22Per Hedbor  object w; if(pike == old_pike) w = old_wizard; else { old_wizard = w = compile_string(pike)(); old_pike = pike; }
6d03cf1998-07-22Johan Schön  mixed res = w->wizard_for(id,fix_relative(args->cancel||args->done||"",id));
f1be801998-02-22Per Hedbor 
84af181997-11-14Per Hedbor  if(mappingp(res)) {
959a491998-07-03Marcus Comstedt  defines[" _error"] = res->error; defines[" _extra_heads"] = res->extra_heads;
f1be801998-02-22Per Hedbor  return res->data||(res->file&&res->file->read())||"";
84af181997-11-14Per Hedbor  } return res; } mapping query_container_callers() { return ([ "wizard" : tag_wizard ]); }
b956721998-02-03Per Hedbor void start() { }