summaryrefslogtreecommitdiff
path: root/utils/hstags
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hstags')
-rw-r--r--utils/hstags/Makefile70
-rw-r--r--utils/hstags/README10
-rw-r--r--utils/hstags/hstags-help.c59
-rw-r--r--utils/hstags/hstags.prl94
-rw-r--r--utils/hstags/prefix.txt9
5 files changed, 242 insertions, 0 deletions
diff --git a/utils/hstags/Makefile b/utils/hstags/Makefile
new file mode 100644
index 0000000000..981bafd897
--- /dev/null
+++ b/utils/hstags/Makefile
@@ -0,0 +1,70 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/version.mk
+
+# Note: might be overridden from cmd-line (see install rule below)
+INSTALLING=0
+
+C_PROG=hstags-help
+SRC_CC_OPTS += -O
+
+SCRIPT_PROG=hstags
+SCRIPT_OBJS=hstags.prl
+
+SCRIPT_SUBST_VARS=\
+ INSTALLING \
+ TOP_PWD \
+ ProjectVersionInt
+
+ifneq "$(BIN_DIST)" "1"
+SCRIPT_SUBST_VARS += libdir libexecdir DEFAULT_TMPDIR
+endif
+
+#
+# The hstags script is configured with different
+# set of config variables, depending on whether it
+# is to be installed or not.
+#
+ifeq "$(INSTALLING)" "1"
+TOP_PWD := $(prefix)
+ifeq "$(BIN_DIST)" "1"
+SCRIPT_PREFIX_FILES += prefix.txt
+endif
+else
+TOP_PWD := $(FPTOOLS_TOP_ABS)
+HSP_IMPORTS:="$(TOP_PWD)/ghc/lib/ghc":"$(TOP_PWD)/ghc/lib/required":"$(TOP_PWD)/ghc/lib/glaExts":"$(TOP_PWD)/ghc/lib/concurrent"
+SCRIPT_SUBST_VARS += HSP_IMPORTS
+endif
+
+#
+# no INTERP: do *not* want #! script stuck on the front
+#
+# what's the deal? I'll add it for now (and perhaps pay for it later :-)
+# -- SOF
+INTERP=perl
+
+#
+# install setup
+#
+INSTALL_SCRIPTS+=$(SCRIPT_PROG)
+INSTALL_LIBEXECS=$(C_PROG)
+
+#
+# Before really installing the script, we have to
+# reconfigure it such that the paths it refers to,
+# point to the installed utils.
+#
+install ::
+ @$(RM) $(SCRIPT_PROG)
+ @$(MAKE) $(MFLAGS) INSTALLING=1 $(SCRIPT_PROG)
+
+include $(TOP)/mk/target.mk
+
+
+# Hack to re-create the in-situ build tree script after
+# having just installed it.
+#
+install ::
+ @$(RM) $(SCRIPT_PROG)
+ @$(MAKE) $(MFLAGS) BIN_DIST=0 $(SCRIPT_PROG)
+
diff --git a/utils/hstags/README b/utils/hstags/README
new file mode 100644
index 0000000000..b457ef125a
--- /dev/null
+++ b/utils/hstags/README
@@ -0,0 +1,10 @@
+"hstags" is a relatively sophisticated program to produce Emacs TAGS
+files for Glasgow-Haskell-compilable programs. (It is "sophisticated"
+only in that it uses the GHC parser to find "interesting" things in
+the source files.)
+
+With GHC 2.01: doesn't work yet.
+
+A simpler alternative is Denis Howe's "fptags" script, which is
+distributed in the ghc/CONTRIB directory.
+
diff --git a/utils/hstags/hstags-help.c b/utils/hstags/hstags-help.c
new file mode 100644
index 0000000000..92604876ff
--- /dev/null
+++ b/utils/hstags/hstags-help.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <string.h> /* for strlen */
+
+/* typedef enum { False, True } Boolean; */
+
+#define SKIP /* Algol-68 lives */
+
+main(argc,argv)
+int argc;
+char **argv;
+{
+ unsigned line;
+ FILE *srcf;
+ int thisline = 0, lastline = 0, linestart = 0;
+ char linebuff[1024];
+
+ if(argc < 2)
+ {
+ fprintf(stderr,"usage: %s sourcefile",argv[0]);
+ exit(1);
+ }
+
+ if((srcf=fopen(argv[1],"r")) == NULL)
+ {
+ fprintf(stderr,"can't read %s\n",argv[1]);
+ exit(2);
+ }
+
+ *linebuff = '\0';
+
+ while(scanf("%u",&line)!=EOF)
+ {
+ if(line != lastline)
+ {
+ while(thisline < line && !feof(srcf))
+ {
+ linestart+=strlen(linebuff);
+ fgets(linebuff,1023,srcf);
+ thisline++;
+ }
+
+ if(thisline >= line)
+ {
+ char *chpos;
+ for(chpos = linebuff; *chpos != '=' && *chpos != '\n' && *chpos != '\0'; ++chpos)
+ putchar(*chpos);
+
+ if(*chpos == '=')
+ putchar('=');
+
+ printf("%c%d,%d\n",0177,line,linestart);
+ }
+ lastline = line;
+ }
+ }
+
+ fclose(srcf);
+ exit(0);
+}
diff --git a/utils/hstags/hstags.prl b/utils/hstags/hstags.prl
new file mode 100644
index 0000000000..16e770bd8a
--- /dev/null
+++ b/utils/hstags/hstags.prl
@@ -0,0 +1,94 @@
+#
+# To fully function, this script needs the following variables
+# set:
+#
+# INSTALLING
+# DEFAULT_TMPDIR
+# TOP_PWD
+# libdir
+# libexecdir
+# ProjectVersionInt
+# HSP_IMPORTS
+
+if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
+ $tmp = $ENV{'TMPDIR'} . "/$$.eht";
+} else {
+ $tmp ="${DEFAULT_TMPDIR}/$$.eht";
+ $ENV{'TMPDIR'} = ${DEFAULT_TMPDIR}; # set the env var as well
+}
+
+$TopPwd = "${TOP_PWD}"; # *Only* needed when using it in-situ (i.e., INSTALLING=0).
+$InstLibDirGhc = "${libdir}";
+$InstLibExecDirGhc = "${libexecdir}";
+
+$Unlit = ( $INSTALLING ?
+ "${InstLibExecDirGhc}/unlit" :
+ "${TopPwd}/ghc/utils/unlit/unlit" );
+# but this is re-set to "cat" (after options) if -cpp not seen
+$HsCpp = ( $INSTALLING ?
+ "${InstLibDirGhc}/hscpp" :
+ "${TopPwd}/ghc/utils/hscpp/hscpp" );
+$HsP = ( $INSTALLING ?
+ "${InstLibExecDirGhc}/hsp" :
+ "${TopPwd}/ghc/compiler/hsp" );
+$HsTagsHelp =
+ ( $INSTALLING ?
+ "${InstLibExecDirGhc}/hstags-help" :
+ "${TopPwd}/ghc/utils/hstags/hstags-help" );
+
+$Verbose = 0;
+$Append = '>';
+$DoCpp = 0;
+$Cpp_opts = '';
+$HsP_opts = '';
+@Files = ();
+
+while ($ARGV[0] =~ /^-./) {
+ $_ = shift(@ARGV);
+ /^--/ && last;
+ /^-v/ && ($Verbose = 1, next);
+ /^-a$/ && ($Append = '>>', next);
+ /^-fglasgow-exts/ && ($HsP_opts .= ' -N', next);
+ /^-optP(.*)/ && ($Cpp_opts .= " $1", next);
+ /^-[UDI]/ && ($Cpp_opts .= " $_", next);
+ /^-cpp/ && ($DoCpp = 1, next);
+ /^-/ && next; # ignore the rest
+ push(@Files, $_);
+}
+
+$DoHsCpp = ( ! $DoCpp ) ? 'cat'
+ : "$HsCpp -D__HASKELL1__=2 -D__GLASGOW_HASKELL__=$ProjectVersionInt $Cpp_opts";
+
+# to find Prelude.hi and friends.
+$HsP_opts .= ( $INSTALLING ?
+ "-J${InstLibDirGhc}/imports" :
+ ( '-J' . join(' -J',split(/:/,${HSP_IMPORTS})) ));
+
+open(STDOUT, "$Append TAGS") || die "can't create TAGS";
+
+foreach $f ( @ARGV ) {
+ # if file is in a dir && we are CPPing, then we add its dir to the -I list.
+ if ( $DoCpp && $f =~ /(.+)\/[^\/]+$/ ) {
+ $Idir = "-I$1";
+ } else {
+ $Idir = '';
+ }
+
+ if ( $f =~ /\.lhs$/ ) {
+ $ToDo = "$Unlit $f - | $DoHsCpp $Idir | $HsP -E $HsP_opts | $HsTagsHelp $f > $tmp";
+ } else {
+ $ToDo = "$DoHsCpp $Idir < $f | $HsP -E $HsP_opts | $HsTagsHelp $f > $tmp";
+ }
+ print STDERR "$ToDo\n" if $Verbose;
+ system($ToDo);
+ $return_val = $?;
+ die "Fatal error $return_val\n" if $return_val != 0;
+
+ ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+ $atime,$mtime, $ctime,$blksize,$blocks) = stat("$tmp");
+
+ print STDOUT "\f\n$f,${size}\n";
+ print STDOUT `cat $tmp`;
+}
+
+unlink $tmp;
diff --git a/utils/hstags/prefix.txt b/utils/hstags/prefix.txt
new file mode 100644
index 0000000000..b67c009c49
--- /dev/null
+++ b/utils/hstags/prefix.txt
@@ -0,0 +1,9 @@
+#
+# hstags - generating a tags file from Haskell source
+#
+# To use the script on your system, the following variable
+# needs to be set (and uncommented!), if it hasn't already
+# been set above:
+#
+#$libdir='/local/fp/lib/sparc-sun-sunos4/ghc-2.02';
+#