New script to create `structures.h' which will be used in language
1999-12-05 Martin Baulig <martin@home-of-linux.org> * lib/structures.pl: New script to create `structures.h' which will be used in language bindings code.
This commit is contained in:
committed by
Martin Baulig
parent
4dccb636e2
commit
117af5f59b
@@ -1,3 +1,8 @@
|
|||||||
|
1999-12-05 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
|
* lib/structures.pl: New script to create `structures.h' which will
|
||||||
|
be used in language bindings code.
|
||||||
|
|
||||||
1999-12-05 Martin Baulig <martin@home-of-linux.org>
|
1999-12-05 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
* features.def: Use `pointer(<type>)' as return value for functions
|
* features.def: Use `pointer(<type>)' as return value for functions
|
||||||
|
@@ -5,3 +5,4 @@ Makefile.in
|
|||||||
libgtop.la
|
libgtop.la
|
||||||
*.lo
|
*.lo
|
||||||
lib.c
|
lib.c
|
||||||
|
structures.h
|
||||||
|
@@ -10,13 +10,20 @@ libgtop_la_SOURCES = init.c open.c close.c command.c read.c \
|
|||||||
|
|
||||||
libgtop_la_LDFLAGS = $(LT_VERSION_INFO)
|
libgtop_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||||
|
|
||||||
BUILT_SOURCES = lib.c
|
BUILT_SOURCES = lib.c structures.h
|
||||||
|
|
||||||
lib.c: lib.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl
|
lib.c: lib.pl $(top_builddir)/config.h $(top_srcdir)/features.def $(top_srcdir)/scripts/c_types.pl
|
||||||
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/lib.pl < $(top_srcdir)/features.def > lib-t
|
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/lib.pl < $(top_srcdir)/features.def > lib-t
|
||||||
mv lib-t lib.c
|
mv lib-t lib.c
|
||||||
|
|
||||||
|
structures.h: structures.pl $(top_builddir)/config.h \
|
||||||
|
$(top_srcdir)/features.def $(top_srcdir)/structures.def
|
||||||
|
$(PERL) -I $(top_srcdir)/scripts $(srcdir)/structures.pl \
|
||||||
|
$(top_srcdir)/features.def $(top_srcdir)/structures.def \
|
||||||
|
structures.h > tmp-s
|
||||||
|
mv tmp-s structures.h
|
||||||
|
|
||||||
EXTRA_DIST = lib.pl
|
EXTRA_DIST = lib.pl
|
||||||
|
|
||||||
CLEANFILES = lib.c
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
|
||||||
|
104
lib/structures.pl
Normal file
104
lib/structures.pl
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
die "Usage: $0 features.def structures.def" unless $#ARGV == 2;
|
||||||
|
|
||||||
|
$[ = 1; # set array base to 1
|
||||||
|
$, = ' '; # set output field separator
|
||||||
|
$\ = "\n"; # set output record separator
|
||||||
|
|
||||||
|
sub toupper {
|
||||||
|
local($_) = @_;
|
||||||
|
tr/a-z/A-Z/;
|
||||||
|
return $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub tolower {
|
||||||
|
local($_) = @_;
|
||||||
|
tr/A-Z/a-z/;
|
||||||
|
return $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
$structures{$structure_count++} = 'glibtop';
|
||||||
|
|
||||||
|
open FEATURESDEF, $ARGV[1] or
|
||||||
|
die "open ($ARGV[1]): $!";
|
||||||
|
|
||||||
|
while (<FEATURESDEF>) {
|
||||||
|
chop; # strip record separator
|
||||||
|
|
||||||
|
if (/^[^\#]/) {
|
||||||
|
&parse_features_def ($_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close FEATURESDEF;
|
||||||
|
|
||||||
|
open STRUCTDEF, $ARGV[2] or
|
||||||
|
die "open ($ARGV[2]): $!";
|
||||||
|
|
||||||
|
while (<STRUCTDEF>) {
|
||||||
|
chop; # strip record separator
|
||||||
|
|
||||||
|
if (/^[^\#]/) {
|
||||||
|
&parse_structure_def ($_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close STRUCTDEF;
|
||||||
|
|
||||||
|
$init_structures_code = sprintf
|
||||||
|
(qq[\tscm_glibtop_structure_tags [GLIBTOP_STRUCTURE_GLIBTOP] = scm_make_structure_type\n\t\t("glibtop", sizeof (glibtop));\n]);
|
||||||
|
|
||||||
|
for ($nr = 0; $nr < $structure_count; $nr++) {
|
||||||
|
$structure = $structures{$nr};
|
||||||
|
|
||||||
|
$init_structures_code .= sprintf
|
||||||
|
(qq[\tscm_glibtop_structure_tags [GLIBTOP_STRUCTURE_%s] = scm_make_structure_type\n\t\t("%s", sizeof (%s));\n],
|
||||||
|
toupper($structure), $structure, $structure);
|
||||||
|
}
|
||||||
|
|
||||||
|
print qq[/* structures.h */];
|
||||||
|
print qq[/* This is a generated file. Please modify \`guile.pl\' */];
|
||||||
|
print '';
|
||||||
|
print qq[\#ifndef __GLIBTOP_STRUCTURES_H__];
|
||||||
|
print qq[\#define __GLIBTOP_STRUCTURES_H__];
|
||||||
|
print '';
|
||||||
|
print qq[\#include <glibtop.h>];
|
||||||
|
print '';
|
||||||
|
print qq[BEGIN_LIBGTOP_DECLS];
|
||||||
|
print '';
|
||||||
|
|
||||||
|
for ($nr = 0; $nr < $structure_count; $nr++) {
|
||||||
|
$structure = $structures{$nr};
|
||||||
|
|
||||||
|
printf (qq[\#define %-40s\t%d\n], 'GLIBTOP_STRUCTURE_'.&toupper($structure), $nr);
|
||||||
|
}
|
||||||
|
|
||||||
|
print '';
|
||||||
|
printf (qq[\#define %-40s\t%d\n], 'GLIBTOP_MAX_STRUCTURES', $structure_count);
|
||||||
|
print '';
|
||||||
|
print qq[END_LIBGTOP_DECLS];
|
||||||
|
print '';
|
||||||
|
print qq[\#endif /* __GLIBTOP_STRUCTURES_H__ */];
|
||||||
|
|
||||||
|
sub parse_features_def {
|
||||||
|
local($line) = @_;
|
||||||
|
@line_fields = split(/\|/, $line, 9999);
|
||||||
|
$retval = $line_fields[1];
|
||||||
|
$element_def = $line_fields[3];
|
||||||
|
$feature = $line_fields[2];
|
||||||
|
$param_def = $line_fields[4];
|
||||||
|
|
||||||
|
$feature =~ s/^@//;
|
||||||
|
$features{$feature} = $feature;
|
||||||
|
|
||||||
|
$structures{$structure_count++} = $feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub parse_structure_def {
|
||||||
|
local($line) = @_;
|
||||||
|
@line_fields = split(/\|/, $line, 9999);
|
||||||
|
$name = $line_fields[1];
|
||||||
|
|
||||||
|
$structures{$structure_count++} = $name;
|
||||||
|
}
|
Reference in New Issue
Block a user