aboutsummaryrefslogtreecommitdiff
path: root/scripts/parse-help-patches.pl
blob: 1511686a3c2b84b4ecc94daee531b600cffe817b (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl

# WARNING!  This script is really ugly!

use strict;
use warnings;

my $line = "";
my @lines;
my $lineCount = 0;
my $column;
my $lastColumn = 0;
my $printText = "";

my %xyhash = ();

my $library = "";
my $name = "";
my $fileName = "";

#------------------------------------------------------------------------------#
# THE OUTPUT FORMAT
#------------------------------------------------------------------------------#
format OBJECTCLASS =
{{Infobox Objectclass
| name                   = ^*
                           $name
| library                = ^*
                           $library
| author                 = {{^* author}}
                           $library
| status                 = {{^* status}}
                           $library
| website                = {{^* website}}
                           $library
| release date           = {{^* release date}}
                           $library
| license                = {{^* license}}
                           $library
| platform               = [[GNU/Linux]], [[Mac OS X]], [[Windows]]
| language               = English
| distributions          = {{^* distributions}}
                           $library
}}

@*
$printText

==Inlets==

==Outlets==

==Arguments== 

==Messages==

{{objectclass-stub}}
[[Category:objectclass]]
[[Category:^*]
$library
.


#------------------------------------------------------------------------------#
# THE PROGRAM
#------------------------------------------------------------------------------#

foreach (`/sw/bin/find /Applications/Pd-extended.app/Contents/Resources/doc/5.reference/ -type f -name '*.pd'`) {
  chop;
  $fileName = "";
  if (m|.*/doc/5\.reference/([a-zA-Z0-9_-]+)/(.+)-help\.pd|) {
	 print("library: $1  name: $2\n");
	 $library = lc($1);
	 $name = $2;
	 $fileName = $_;
  } elsif (m|.*/doc/5\.reference/([a-zA-Z0-9_-]+)/(.+)\.pd|) {
	 print("library: $1  name: $2 \t\t(no -help)\n");
	 $library = lc($1);
	 $name = $2;
	 $fileName = $_;
  }

#  print "filename: $fileName\n";  
  if ($fileName) {
	 open(HELPPATCH, "$fileName");
	 undef $/;						  # $/ defines the "end of record" character
	 $_ = <HELPPATCH>;			  # read the whole file into the scalar 
	 close HELPPATCH;
	 $/ = "\n";						  # Restore for normal behaviour later in script
  
	 s| \\||g;						  # remove Pd-style escaping
	 s|([^;])\n|$1 |g;			  # remove extra newlines
	 s|\(http://.*\)\([ \n]\)|[$1]$2|g;
  
	 @lines = split(';\n', $_);


	 foreach (@lines) {
		if (m|^#X text ([0-9]+) ([0-9]+) (.*)|) {
		  $xyhash{ $2 }{ $1 } = $3;
		  #	 print("$lineCount @ $1,$2: $3\n");
		}
		$lineCount++;
	 }

	 $printText = "";
	 for ($column = -300; $column < 1501; $column += 300) {
		foreach my $yKey ( sort {$a <=> $b} keys(%xyhash) ) {
		  foreach my $xKey ( keys(%{$xyhash{$yKey}}) ) {
			 if ( ($xKey > $lastColumn) && ($xKey < $column) ) {
				$printText .= "$xyhash{$yKey}{$xKey}\n\n";
				#$printText .= "$xKey,$yKey: $xyhash{$yKey}{$xKey}\n";
			 }
		  }
		}
		$lastColumn = $column;
	 }
	 #print("\n\n\nPRINTTEXT:\n$printText\n\n");
  
	 mkdir($library);
	 open(OBJECTCLASS, ">$library/${name}.txt");
	 write(OBJECTCLASS);
	 close(OBJECTCLASS);
  }
}