Commit a4c75d1d authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Remove the old hstags util

parent b1128843
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
#
# 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)
SCRIPT_PREFIX_FILES += prefix.txt
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) $(SCRIPT_PROG)
"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.
#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);
}
#
# 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;
#
# 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';
#
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment