File: wmmltohtml2

package info (click to toggle)
pike7 7.0.361-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 14,876 kB
  • ctags: 12,334
  • sloc: ansic: 142,667; makefile: 1,526; sh: 1,035; lisp: 290; sed: 34; perl: 3
file content (87 lines) | stat: -rwxr-xr-x 1,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/local/bin/pike

import Stdio;
#if __VERSION__ >= 0.6
import ".";
#endif /* __VERSION__ >= 0.6 */

#include "types.h"

int main(int argc, string *argv)
{
#if constant(signal)
  signal(signum("SIGQUIT"),lambda()
	 {
	   master()->handle_error( ({"\nSIGQUIT recived, printing backtrace and continuing.\n",backtrace() }) );
	 });
#endif
  random_seed(0); // increase cache hit potential

  mixed *ER=catch {
    program output=(program)argv[2];
    Wmml->output_format=argv[2];
    if (!output) error("can't cast %O to program\n",argv[2]);
    object out=output();
    if (!out->output) error("%O doesn't have an output method",argv[2]);

    add_constant("illustration",out->illustration);
    add_constant("illustration_jpeg",
		 out->illustration_jpeg ||
		 out->illustration);

    werror("Reading ");
    string input=Stdio.read_file(argv[1]);
    werror("Lexing ");
    mixed data=Sgml.lex(input,argv[1]);
    werror("Grouping ");
    data=Sgml.group(data);

    werror("Expanding macros\n");
    data=Wmml.expand_macros(data);

    werror("Verifying\n");
    Wmml.verify(data,input,argv[1]);
    werror("Concretizing\n");
    WMML wmml=Wmml.make_concrete_wmml(data);
#ifdef WALL
    werror("Undocumented functions: \n%-#75s\n",(indices(all_constants()) - indices(wmml->index_data))*"\n");
#endif
    werror("\nWriting output\n");
    out->output(argv[3],wmml);
    write("Ok\n");
    exit(0);
  };

  if(ER)
  {
    catch {
      if(arrayp(ER) && sizeof(ER)>1 && arrayp(ER[1]))
      {
	mixed x;
	x=ER[1];
	x=reverse(x);
	foreach(x,x)
	  {
	    for(int e=3;e<sizeof(x);e++)
	    {
	      mixed s=x[e];
	      if(!arrayp(s)) s=({s});
	      foreach(s,s)
		{
		  if(object_program(s)==Sgml.Tag)
		  {
		    if(s->pos)
		    {
		      werror("\nThis error occured close to tag "+s->tag+" near "+s->location()+"\n");
		      werror("\nThe tag had the following options: %O\n",s->params);
		      throw(0);
		    }
		  }
		}
	    }
	  }
      }
    };
    throw(ER);
  }
}