File: tabcomplete.pl

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (55 lines) | stat: -rw-r--r-- 2,299 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
#!/usr/bin/perl
##########################################################################
##
## pgAdmin III - Tab completion
## 
## Copyright (C) 2002 - 2014, The pgAdmin Development Team
## This software is released under the PostgreSQL Licence
##
## tab-complete.pl - Script to build tab-complete.inc 
##
##########################################################################


# This script builds tab-complete.inc from tab-complete.c. The
# source file (tab-complete.c) should be copied from the latest
# PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
# have to do all the work ourselves...

use strict;
use warnings;

open(F, "tab-complete.c") || die("Could not open tab-complete.c!");
undef $/;
my $alltxt = <F>;
close(F);

# Get rid of everything before and after the parts we're interested in
$alltxt =~ /.*(typedef struct SchemaQuery.*)\/\* GENERATOR FUNCTIONS\s+.*/s || die("Failed match 1");
$alltxt = $1;

# Get rid of forward declarations and initialize_readline
$alltxt =~ /(.*)\/\*\s+Forward declaration of functions \*\/.*(\/\* The completion function\..*)/s || die("Failed match 2");
$alltxt = $1 . $2;

# Get rid of completion macros, we define them ourselves
$alltxt =~ /(.*)\/\* A couple of macros to ease typing.*\*\/\s+#define COMPLETE_WITH_QUERY.*\s+(\/\*\s+\* Assembly instructions.*)/s || die("Failed match 4");
$alltxt = $1 . $2;

# Rewrite matches that don't use the macros
$alltxt =~ s/completion_matches\(text, create_command_generator\)/complete_create_command\(text\)/gs || die("Failed match 5");
$alltxt =~ s/completion_matches\(text, filename_completion_function\)/complete_filename\(\)/gs || die("Failed match 6");

# We're going to return char*, not char**
$alltxt =~ s/static char \*\*\s+psql_completion/static char \* psql_completion/s || die("Failed match 7");
$alltxt =~ s/char\s+\*\*matches = NULL/char \*matches = NULL/s || die("Failed match 8");

# Add an extra parameter to psql_completion
$alltxt =~ s/psql_completion\(char \*text, int start, int end\)/psql_completion\(char \*text, int start, int end, void \*dbptr\)/s || die("Failed match 9");

open(F,">tab-complete.inc") || die("Could not open tab-complete.inc!");
print F $alltxt;
print F "\n\n";
close(F);

print "Done.\n";