#!/usr/bin/perl # $Id: getapps.pl 147 2005-12-08 20:47:24Z bklang $ use strict; use warnings; use HTML::Entities; open(AST, "asterisk -nqrx 'show applications'|") or die("Unable to run asterisk\n"); my %applications; while (<AST>) { chomp; if ($_ =~ /^\s+(.*):\s+(.*)$/) { $applications{$1}{'description'} = encode_entities($2); } } close(AST); print "<?xml version=\"1.0\"?>\n"; print "<asterisk type=\"applist\">"; foreach my $app (keys %applications) { open(AST, "asterisk -nqrx 'show application $app'|") or die("Unable to run asterisk for application $app\n"); my $synopsis = 0; my $usage = 0; APP: while (<AST>) { chomp; my $line = $_; $line =~ s/\c[\[\d+;\d+;\d+m//g; $line =~ s/\c[\[\d+;\d+m//g; if ($synopsis != 0) { $applications{$app}{'synopsis'} = encode_entities($line); $synopsis = 0; next APP; } if ($usage != 0) { $applications{$app}{'usage'} .= encode_entities("$line\n"); next APP; } if ($line =~ /^\[Synopsis\]:/) { $synopsis = 1; next APP; } if ($line =~ /\[Description]:$/) { $usage = 1; next APP; } } print STDERR "Found $app.\n"; close(AST); print " <application name=\"$app\">\n"; print " <synopsis>".$applications{$app}{'synopsis'}."</synopsis>\n"; print " <usage>".$applications{$app}{'usage'}."</usage>\n"; print " </application>\n"; } print "</asterisk>";