diff options
Diffstat (limited to 'lib-src')
33 files changed, 0 insertions, 15574 deletions
diff --git a/lib-src/=aixcc.lex b/lib-src/=aixcc.lex deleted file mode 100644 index b7b44701b18..00000000000 --- a/lib-src/=aixcc.lex +++ /dev/null @@ -1,301 +0,0 @@ -%Start ErrorText ErrorMessage OtherText - -EC [0-9][0-9][0-9][0-9]-[0-9][0-9][0-9] -D [0-9] -D3 [0-9 ][0-9 ][0-9] -D4 [0-9 ][0-9 ][0-9 ][0-9] -D5 [0-9 ][0-9 ][0-9 ][0-9 ][0-9] -DS [0-9 ] - -%{ -/* moore@wilma.cs.utk.edu - - * Hack to work around the AIX C compiler's brain-damaged error messages - * so that emacs can parse them. It runs /bin/cc as a subprocess, and - * tries to rearrange the error messages so that (a) each message contains - * both the filename and line number where the error occurred, and (b) - * the error message(s) for a particular line get displayed *before* the - * line itself. - * - * to compile: - * lex aixcc.lex - * cc -o aixcc lex.yy.c - * - * - * Copyright December 1991 by Keith Moore - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * TODO: figure out how the compiler counts file numbers for included - * files, keep track of which file corresponds to which number, and - * always output the right file name. - */ - -#include <stdio.h> -#include <string.h> - -char *current_file; -int line; -int debug = 0; -char bigbuf[10240]; -char *bufptr = bigbuf; -int last_line_was_error = 0; - -spaces (s) -char *s; -{ - while (*s++) - *bufptr++ = ' '; -} - -char * -strsave (s) -char *s; -{ - char *ptr = malloc (strlen (s) + 1); - strcpy (ptr, s); - return ptr; -} - -yywrap () -{ - *bufptr = '\0'; - bufptr = bigbuf; - while (*bufptr) - putc (*bufptr++, yyout); - return 1; -} - -%} -%% -^File\ Line\ Column\ Message\ text[^\n]* { - /* - * ignore this. don't treat it as error text - */ -} - -^{DS}{DS}{DS}\ {D5}\ \| { - /* - * (optional) nesting level, followed by line number, followed - * by the source code fragment that caused the error - */ - - /* - * save the line number for later - */ - line = atoi (yytext+4); - - if (debug) { - fprintf (yyout, "line <= %d\n", line); - fprintf (yyout, "%s\n", yytext); - } - - /* - * if the last line was an error message, to flush out all of - * the old source text before starting to save the new source text. - */ - if (last_line_was_error) { - *bufptr = '\0'; - bufptr = bigbuf; - while (*bufptr) - putc (*bufptr++, yyout); - bufptr = bigbuf; - last_line_was_error = 0; - } - /* - * stuff enough spaces in the text buffer so that the - * saved text will line up properly when displayed. - */ - spaces (yytext); - - BEGIN ErrorText; /* continue below */ -} - -<ErrorText>[^\n]*$ { - char *ptr; - - /* - * Save the text until we see the error message(s), then print it. - * This because emacs puts the error message at the top of the - * window, and it's nice to be able to see the text below it. - */ - - ptr = yytext; - while (*ptr) - *bufptr++ = *ptr++; - *bufptr++ = '\n'; - - BEGIN 0; -} - -^Processing\ include\ file\ .*$ { - /* - * name of a new include file being processed. Increment file number - * and remember the file name corresponding to this file number. - */ - - current_file = strsave (yytext+24); - - if (debug) { - fprintf (yyout, "current_file <= %s\n", current_file); - fprintf (yyout, "%s\n", yytext); - } -} - -^([a-z]\ -)?\ *{EC}: { - /* - * error message (which we print immediately) preceded by an - * error code (which we ignore) - */ - - fprintf (yyout, "\"%s\", line %d: %c -", current_file, line, *yytext); - last_line_was_error = 1; - BEGIN ErrorMessage; -} - -^{D3}\ {D5}\ {D4}\ {EC}: { - /* - * (optional) nesting level, followed by line number, followed - * by column number, followed by error message text. - */ - - /* - * save the line number for later - */ - line = atoi (yytext+4); - - if (debug) { - fprintf (yyout, "line <= %d\n", line); - fprintf (yyout, "%s\n", yytext); - } - - /* - * if the last line was an error message, flush out all of - * the old source text before printing this error message. - */ - if (last_line_was_error) { - *bufptr = '\0'; - bufptr = bigbuf; - while (*bufptr) - putc (*bufptr++, yyout); - bufptr = bigbuf; - last_line_was_error = 0; - } - fprintf (yyout, "\"%s\", line %d:", current_file, line); - last_line_was_error = 1; - BEGIN ErrorMessage; -} - -<ErrorMessage>[^\n]*$ { - fprintf (yyout, "%s\n", yytext); - BEGIN 0; -} - - -^[^ :]+".c:"\ *$ { - /* name of new source file being processed */ - - char *ptr; - - if (current_file) - free (current_file); - ptr = strchr (yytext, ':'); - *ptr = '\0'; - current_file = strsave (yytext); -} - -^[^\n] { - /* - * other text starting with a newline. We have to break it up this - * way to keep this rule from matching any of the above patterns - */ - - if (last_line_was_error) { - *bufptr = '\0'; - bufptr = bigbuf; - while (*bufptr) - putc (*bufptr++, yyout); - bufptr = bigbuf; - last_line_was_error = 0; - } - - *bufptr++ = *yytext; - BEGIN OtherText; -} - -<OtherText>[^\n]*$ { - char *ptr; - - ptr = yytext; - while (*ptr) - *bufptr++ = *ptr++; - *bufptr++ = '\n'; - - BEGIN 0; -} - -\n ; - -%% - -main (argc, argv) -char **argv; -{ - int pfd[2]; - int child_pid; - int i; - - current_file = strsave ("/dev/null"); - - line = 0; - - for (i = 1; i < argc; ++i) { - char *ptr = strrchr (argv[i], '.'); - if (ptr && ptr[1] == 'c' && ptr[2] == '\0') { - current_file = strsave (argv[i]); - break; - } - } - - if (pipe (pfd) < 0) { - perror ("pipe"); - exit (1); - } - if ((child_pid = fork()) > 0) { - int status; - - close (pfd[1]); - yyin = fdopen (pfd[0], "r"); - yyout = stderr; - yylex(); - - wait (&status); - exit ((status >> 8) & 0xff); - } - else if (child_pid == 0) { - dup2 (pfd[1], 2); - close (pfd[0]); - close (pfd[1]); - argv[0] = "cc"; - execv ("/bin/cc", argv); - perror ("/bin/cc"); - exit (1); - } - else { - perror ("fork"); - exit (1); - } -} diff --git a/lib-src/=etags-vmslib.c b/lib-src/=etags-vmslib.c deleted file mode 100644 index cddb68085f8..00000000000 --- a/lib-src/=etags-vmslib.c +++ /dev/null @@ -1,155 +0,0 @@ -/* File name wild card expansion for VMS. - This file is part of the etags program. - Copyright (C) 1987 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <stdio.h> -typedef char tbool; - -/* This is a BUG! ANY arbitrary limit is a BUG! - Won't someone please fix this? */ -#define MAX_FILE_SPEC_LEN 255 -typedef struct { - short curlen; - char body[MAX_FILE_SPEC_LEN + 1]; -} vspec; -#define EOS '\0' -#define NO 0 -#define YES 1 -#define NULL 0 - -/* gfnames - return in successive calls the - name of each file specified by all the remaining args in the command-line - expanding wild cards and - stepping over arguments when they have been processed completely -*/ -char* -gfnames(pac, pav, p_error) - int *pac; - char **pav[]; - tbool *p_error; -{ - static vspec filename = {MAX_FILE_SPEC_LEN, "\0"}; - short fn_exp(); - - while (1) - if (*pac == 0) - { - *p_error = NO; - return(NULL); - } - else switch(fn_exp(&filename, **pav)) - { - case 1: - *p_error = NO; - return(filename.body); - break; - case 0: - --*pac; - ++*pav; - break; - default: - *p_error = YES; - return(filename.body); - break; - } - -} - -/* fn_exp - expand specification of list of file names - returning in each successive call the next filename matching the input - spec. The function expects that each in_spec passed - to it will be processed to completion; in particular, up to and - including the call following that in which the last matching name - is returned, the function ignores the value of in_spec, and will - only start processing a new spec with the following call. - If an error occurs, on return out_spec contains the value - of in_spec when the error occurred. - - With each successive filename returned in out_spec, the - function's return value is one. When there are no more matching - names the function returns zero. If on the first call no file - matches in_spec, or there is any other error, -1 is returned. -*/ - -#include <rmsdef.h> -#include <descrip.h> -#define OUTSIZE MAX_FILE_SPEC_LEN -short -fn_exp(out, in) - vspec *out; - char *in; -{ - static long context = 0; - static struct dsc$descriptor_s o; - static struct dsc$descriptor_s i; - static tbool pass1 = YES; - long status; - short retval; - - if (pass1) - { - pass1 = NO; - o.dsc$a_pointer = (char *) out; - o.dsc$w_length = (short)OUTSIZE; - i.dsc$a_pointer = in; - i.dsc$w_length = (short)strlen(in); - i.dsc$b_dtype = DSC$K_DTYPE_T; - i.dsc$b_class = DSC$K_CLASS_S; - o.dsc$b_dtype = DSC$K_DTYPE_VT; - o.dsc$b_class = DSC$K_CLASS_VS; - } - if ( (status = lib$find_file(&i, &o, &context, 0, 0)) == RMS$_NORMAL) - { - out->body[out->curlen] = EOS; - return(1); - } - else if (status == RMS$_NMF) - retval = 0; - else - { - strcpy(out->body, in); - retval = -1; - } - lib$find_file_end(&context); - pass1 = YES; - return(retval); -} - -#ifndef OLD /* Newer versions of VMS do provide `system'. */ -system(cmd) - char *cmd; -{ - fprintf(stderr, "system() function not implemented under VMS\n"); -} -#endif - -#define VERSION_DELIM ';' -char *massage_name(s) - char *s; -{ - char *start = s; - - for ( ; *s; s++) - if (*s == VERSION_DELIM) - { - *s = EOS; - break; - } - else - *s = tolower(*s); - return(start); -} diff --git a/lib-src/=rcs2log b/lib-src/=rcs2log deleted file mode 100644 index 44a12bd3da8..00000000000 --- a/lib-src/=rcs2log +++ /dev/null @@ -1,612 +0,0 @@ -#! /bin/sh - -# RCS to ChangeLog generator - -# Generate a change log prefix from RCS files and the ChangeLog (if any). -# Output the new prefix to standard output. -# You can edit this prefix by hand, and then prepend it to ChangeLog. - -# Ignore log entries that start with `#'. -# Clump together log entries that start with `{topic} ', -# where `topic' contains neither white space nor `}'. - -# Author: Paul Eggert <eggert@twinsun.com> - -# $Id: rcs2log,v 1.34 1996/10/13 05:59:42 eggert Exp eggert $ - -# Copyright 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -tab=' ' -nl=' -' - -# Parse options. - -# defaults -: ${AWK=awk} -: ${TMPDIR=/tmp} -changelog=ChangeLog # change log file name -datearg= # rlog date option -hostname= # name of local host (if empty, will deduce it later) -indent=8 # indent of log line -length=79 # suggested max width of log line -logins= # login names for people we know fullnames and mailaddrs of -loginFullnameMailaddrs= # login<tab>fullname<tab>mailaddr triplets -logTZ= # time zone for log dates (if empty, use local time) -recursive= # t if we want recursive rlog -revision= # t if we want revision numbers -rlog_options= # options to pass to rlog -tabwidth=8 # width of horizontal tab - -while : -do - case $1 in - -c) changelog=${2?}; shift;; - -i) indent=${2?}; shift;; - -h) hostname=${2?}; shift;; - -l) length=${2?}; shift;; - -[nu]) # -n is obsolescent; it is replaced by -u. - case $1 in - -n) case ${2?}${3?}${4?} in - *"$tab"* | *"$nl"*) - echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed" - exit 1 - esac - loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$2$tab$3$tab$4 - shift; shift; shift;; - -u) - # If $2 is not tab-separated, use colon for separator. - case ${2?} in - *"$nl"*) - echo >&2 "$0: -u '$2': newlines not allowed" - exit 1;; - *"$tab"*) - t=$tab;; - *) - t=: - esac - case $2 in - *"$t"*"$t"*"$t"*) - echo >&2 "$0: -u '$2': too many fields" - exit 1;; - *"$t"*"$t"*) - ;; - *) - echo >&2 "$0: -u '$2': not enough fields" - exit 1 - esac - loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$2 - shift - esac - logins=$logins$nl$login - ;; - -r) rlog_options=$rlog_options$nl${2?}; shift;; - -R) recursive=t;; - -t) tabwidth=${2?}; shift;; - -v) revision=t;; - -*) echo >&2 "$0: usage: $0 [options] [file ...] -Options: - [-c changelog] [-h hostname] [-i indent] [-l length] [-R] - [-r rlog_option] [-t tabwidth] [-v] - [-u 'login<TAB>fullname<TAB>mailaddr']..." - exit 1;; - *) break - esac - shift -done - -month_data=' - m[0]="Jan"; m[1]="Feb"; m[2]="Mar" - m[3]="Apr"; m[4]="May"; m[5]="Jun" - m[6]="Jul"; m[7]="Aug"; m[8]="Sep" - m[9]="Oct"; m[10]="Nov"; m[11]="Dec" -' - - -# Put rlog output into $rlogout. - -# If no rlog options are given, -# log the revisions checked in since the first ChangeLog entry. -# Since ChangeLog is only by date, some of these revisions may be duplicates of -# what's already in ChangeLog; it's the user's responsibility to remove them. -case $rlog_options in -'') - if test -s "$changelog" - then - e=' - /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{ - # ISO 8601 date - print $1 - exit - } - /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{ - # old-fashioned date and time (Emacs 19.31 and earlier) - '"$month_data"' - year = $5 - for (i=0; i<=11; i++) if (m[i] == $2) break - dd = $3 - printf "%d-%02d-%02d\n", year, i+1, dd - exit - } - ' - d=`$AWK "$e" <"$changelog"` || exit - case $d in - ?*) datearg="-d>$d" - esac - fi -esac - -# Use TZ specified by ChangeLog local variable, if any. -if test -s "$changelog" -then - extractTZ=' - /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{ - s//\1/; p; q - } - /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{ - s//UTC0/; p; q - } - ' - logTZ=`tail "$changelog" | sed -n "$extractTZ"` - case $logTZ in - ?*) TZ=$logTZ; export TZ - esac -fi - -# If CVS is in use, examine its repository, not the normal RCS files. -if test ! -f CVS/Repository -then - rlog=rlog - repository= -else - rlog='cvs log' - repository=`sed 1q <CVS/Repository` || exit - test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit - case $CVSROOT in - *:/*) - # remote repository - ;; - *) - # local repository - case $repository in - /*) ;; - *) repository=${CVSROOT?}/$repository - esac - if test ! -d "$repository" - then - echo >&2 "$0: $repository: bad repository (see CVS/Repository)" - exit 1 - fi - esac -fi - -# Use $rlog's -zLT option, if $rlog supports it. -case `$rlog -zLT 2>&1` in -*' option'*) ;; -*) rlog_options=-zLT$nl$rlog_options -esac - -# With no arguments, examine all files under the RCS directory. -case $# in -0) - case $repository in - '') - oldIFS=$IFS - IFS=$nl - case $recursive in - t) - RCSdirs=`find . -name RCS -type d -print` - filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||' - files=` - { - case $RCSdirs in - ?*) find $RCSdirs -type f -print - esac - find . -name '*,v' -print - } | - sort -u | - sed "$filesFromRCSfiles" - `;; - *) - files= - for file in RCS/.* RCS/* .*,v *,v - do - case $file in - RCS/. | RCS/..) continue;; - RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue - esac - files=$files$nl$file - done - case $files in - '') exit 0 - esac - esac - set x $files - shift - IFS=$oldIFS - esac -esac - -llogout=$TMPDIR/rcs2log$$l -rlogout=$TMPDIR/rcs2log$$r -trap exit 1 2 13 15 -trap "rm -f $llogout $rlogout; exit 1" 0 - -case $datearg in -?*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogout;; -'') $rlog $rlog_options ${1+"$@"} >$rlogout -esac || exit - - -# Get the full name of each author the logs mention, and set initialize_fullname -# to awk code that initializes the `fullname' awk associative array. -# Warning: foreign authors (i.e. not known in the passwd file) are mishandled; -# you have to fix the resulting output by hand. - -initialize_fullname= -initialize_mailaddr= - -case $loginFullnameMailaddrs in -?*) - case $loginFullnameMailaddrs in - *\"* | *\\*) - sed 's/["\\]/\\&/g' >$llogout <<EOF || exit -$loginFullnameMailaddrs -EOF - loginFullnameMailaddrs=`cat $llogout` - esac - - oldIFS=$IFS - IFS=$nl - for loginFullnameMailaddr in $loginFullnameMailaddrs - do - case $loginFullnameMailaddr in - *"$tab"*) IFS=$tab;; - *) IFS=: - esac - set x $loginFullnameMailaddr - login=$2 - fullname=$3 - mailaddr=$4 - initialize_fullname="$initialize_fullname - fullname[\"$login\"] = \"$fullname\"" - initialize_mailaddr="$initialize_mailaddr - mailaddr[\"$login\"] = \"$mailaddr\"" - done - IFS=$oldIFS -esac - -case $llogout in -?*) sort -u -o $llogout <<EOF || exit -$logins -EOF -esac -output_authors='/^date: / { - if ($2 ~ /^[0-9]*[-\/][0-9][0-9][-\/][0-9][0-9]$/ && $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9:]*;$/ && $4 == "author:" && $5 ~ /^[^;]*;$/) { - print substr($5, 1, length($5)-1) - } -}' -authors=` - $AWK "$output_authors" <$rlogout | - case $llogout in - '') sort -u;; - ?*) sort -u | comm -23 - $llogout - esac -` -case $authors in -?*) - cat >$llogout <<EOF || exit -$authors -EOF - initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/' - initialize_author=`sed -e "$initialize_author_script" <$llogout` - awkscript=' - BEGIN { - alphabet = "abcdefghijklmnopqrstuvwxyz" - ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - '"$initialize_author"' - } - { - if (author[$1]) { - fullname = $5 - if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) { - # Remove the junk from fullnames like "0000-Admin(0000)". - fullname = substr(fullname, index(fullname, "-") + 1) - fullname = substr(fullname, 1, index(fullname, "(") - 1) - } - if (fullname ~ /,[^ ]/) { - # Some sites put comma-separated junk after the fullname. - # Remove it, but leave "Bill Gates, Jr" alone. - fullname = substr(fullname, 1, index(fullname, ",") - 1) - } - abbr = index(fullname, "&") - if (abbr) { - a = substr($1, 1, 1) - A = a - i = index(alphabet, a) - if (i) A = substr(ALPHABET, i, 1) - fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1) - } - - # Quote quotes and backslashes properly in full names. - # Do not use gsub; traditional awk lacks it. - quoted = "" - rest = fullname - for (;;) { - p = index(rest, "\\") - q = index(rest, "\"") - if (p) { - if (q && q<p) p = q - } else { - if (!q) break - p = q - } - quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1) - rest = substr(rest, p+1) - } - - printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest - author[$1] = 0 - } - } - ' - - initialize_fullname=` - ( - cat /etc/passwd - for author in $authors - do nismatch $author passwd.org_dir - done - ypmatch $authors passwd - ) 2>/dev/null | - $AWK -F: "$awkscript" - `$initialize_fullname -esac - - -# Function to print a single log line. -# We don't use awk functions, to stay compatible with old awk versions. -# `Log' is the log message (with \n replaced by \r). -# `files' contains the affected files. -printlogline='{ - - # Following the GNU coding standards, rewrite - # * file: (function): comment - # to - # * file (function): comment - if (Log ~ /^\([^)]*\): /) { - i = index(Log, ")") - files = files " " substr(Log, 1, i) - Log = substr(Log, i+3) - } - - # If "label: comment" is too long, break the line after the ":". - sep = " " - if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string - - # Print the label. - printf "%s*%s:", indent_string, files - - # Print each line of the log, transliterating \r to \n. - while ((i = index(Log, CR)) != 0) { - logline = substr(Log, 1, i-1) - if (logline ~ /[^'"$tab"' ]/) { - printf "%s%s\n", sep, logline - } else { - print "" - } - sep = indent_string - Log = substr(Log, i+1) - } -}' - -# Pattern to match the `revision' line of rlog output. -rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$' - -case $hostname in -'') - hostname=`( - hostname || uname -n || uuname -l || cat /etc/whoami - ) 2>/dev/null` || { - echo >&2 "$0: cannot deduce hostname" - exit 1 - } - - case $hostname in - *.*) ;; - *) - domainname=`(domainname) 2>/dev/null` && - case $domainname in - *.*) hostname=$hostname.$domainname - esac - esac -esac - - -# Process the rlog output, generating ChangeLog style entries. - -# First, reformat the rlog output so that each line contains one log entry. -# Transliterate \n to \r so that multiline entries fit on a single line. -# Discard irrelevant rlog output. -$AWK <$rlogout ' - BEGIN { repository = "'"$repository"'" } - /^RCS file:/ { - if (repository != "") { - filename = $3 - if (substr(filename, 1, length(repository) + 1) == repository "/") { - filename = substr(filename, length(repository) + 2) - } - if (filename ~ /,v$/) { - filename = substr(filename, 1, length(filename) - 2) - } - if (filename ~ /(^|\/)Attic\/[^\/]*$/) { - i = length(filename) - while (substr(filename, i, 1) != "/") i-- - filename = substr(filename, 1, i - 6) substr(filename, i + 1) - } - } - rev = "?" - } - /^Working file:/ { if (repository == "") filename = $3 } - /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ { - if ($0 ~ /'"$rlog_revision_pattern"'/) { - rev = $2 - next - } - if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) { - date = $2 - if (date ~ /\//) { - # This is a traditional RCS format date YYYY/MM/DD. - # Replace "/"s with "-"s to get ISO format. - newdate = "" - while ((i = index(date, "/")) != 0) { - newdate = newdate substr(date, 1, i-1) "-" - date = substr(date, i+1) - } - date = newdate date - } - time = substr($3, 1, length($3) - 1) - author = substr($5, 1, length($5)-1) - printf "%s %s %s %s %s %c", filename, rev, date, time, author, 13 - rev = "?" - next - } - if ($0 ~ /^branches: /) { next } - if ($0 ~ /^(-----------*|===========*)$/) { print ""; next } - printf "%s%c", $0, 13 - } -' | - -# Now each line is of the form -# FILENAME REVISION YYYY-MM-DD HH:MM:SS[+-TIMEZONE] AUTHOR \rLOG -# where \r stands for a carriage return, -# and each line of the log is terminated by \r instead of \n. -# Sort the log entries, first by date+time (in reverse order), -# then by author, then by log entry, and finally by file name and revision -# (just in case). -sort +2 -4r +4 +0 | - -# Finally, reformat the sorted log entries. -$AWK ' - BEGIN { - logTZ = "'"$logTZ"'" - revision = "'"$revision"'" - - # Some awk variants do not understand "\r" or "\013", so we have to - # put a carriage return directly in the file. - CR="
" # <-- There is a single CR between the " chars here. - - # Initialize the fullname and mailaddr associative arrays. - '"$initialize_fullname"' - '"$initialize_mailaddr"' - - # Initialize indent string. - indent_string = "" - i = '"$indent"' - if (0 < '"$tabwidth"') - for (; '"$tabwidth"' <= i; i -= '"$tabwidth"') - indent_string = indent_string "\t" - while (1 <= i--) - indent_string = indent_string " " - } - - { - newlog = substr($0, 1 + index($0, CR)) - - # Ignore log entries prefixed by "#". - if (newlog ~ /^#/) { next } - - if (Log != newlog || date != $3 || author != $5) { - - # The previous log and this log differ. - - # Print the old log. - if (date != "") '"$printlogline"' - - # Logs that begin with "{clumpname} " should be grouped together, - # and the clumpname should be removed. - # Extract the new clumpname from the log header, - # and use it to decide whether to output a blank line. - newclumpname = "" - sep = "\n" - if (date == "") sep = "" - if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) { - i = index(newlog, "}") - newclumpname = substr(newlog, 1, i) - while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++ - newlog = substr(newlog, i+1) - if (clumpname == newclumpname) sep = "" - } - printf sep - clumpname = newclumpname - - # Get ready for the next log. - Log = newlog - if (files != "") - for (i in filesknown) - filesknown[i] = 0 - files = "" - } - if (date != $3 || author != $5) { - # The previous date+author and this date+author differ. - # Print the new one. - date = $3 - time = $4 - author = $5 - - zone = "" - if (logTZ && ((i = index(time, "-")) || (i = index(time, "+")))) - zone = " " substr(time, i) - - # Print "date[ timezone] fullname <email address>". - # Get fullname and email address from associative arrays; - # default to author and author@hostname if not in arrays. - if (fullname[author]) - auth = fullname[author] - else - auth = author - printf "%s%s %s ", date, zone, auth - if (mailaddr[author]) - printf "<%s>\n\n", mailaddr[author] - else - printf "<%s@%s>\n\n", author, "'"$hostname"'" - } - if (! filesknown[$1]) { - filesknown[$1] = 1 - if (files == "") files = " " $1 - else files = files ", " $1 - if (revision && $2 != "?") files = files " " $2 - } - } - END { - # Print the last log. - if (date != "") { - '"$printlogline"' - printf "\n" - } - } -' && - - -# Exit successfully. - -exec rm -f $llogout $rlogout - -# Local Variables: -# tab-width:4 -# End: diff --git a/lib-src/=timer.c b/lib-src/=timer.c deleted file mode 100644 index 9bd547ce8f2..00000000000 --- a/lib-src/=timer.c +++ /dev/null @@ -1,368 +0,0 @@ -/* timer.c --- daemon to provide a tagged interval timer service - - This little daemon runs forever waiting for commands to schedule events. - SIGALRM causes - it to check its queue for events attached to the current second; if - one is found, its label is written to stdout. SIGTERM causes it to - terminate, printing a list of pending events. - - This program is intended to be used with the lisp package called - timer.el. The first such program was written anonymously in 1990. - This version was documented and rewritten for portability by - esr@snark.thyrsus.com, Aug 7 1992. */ - -#include <stdio.h> -#include <signal.h> -#include <errno.h> -#include <sys/types.h> /* time_t */ - -#include <../src/config.h> -#undef read - -#ifdef LINUX -/* Perhaps this is correct unconditionally. */ -#undef signal -#endif -#ifdef _CX_UX -/* I agree with the comment above, this probably should be unconditional (it - * is already unconditional in a couple of other files in this directory), - * but in the spirit of minimizing the effects of my port, I am making it - * conditional on _CX_UX. - */ -#undef signal -#endif - - -extern int errno; -extern char *strerror (); -extern time_t time (); - -/* - * The field separator for input. This character shouldn't occur in dates, - * and should be printable so event strings are readable by people. - */ -#define FS '@' - -struct event - { - char *token; - time_t reply_at; - }; -int events_size; /* How many slots have we allocated? */ -int num_events; /* How many are actually scheduled? */ -struct event *events; /* events[0 .. num_events-1] are the - valid events. */ - -char *pname; /* program name for error messages */ - -/* This buffer is used for reading commands. - We make it longer when necessary, but we never free it. */ -char *buf; -/* This is the allocated size of buf. */ -int buf_size; - -/* Non-zero means don't handle an alarm now; - instead, just set alarm_deferred if an alarm happens. - We set this around parts of the program that call malloc and free. */ -int defer_alarms; - -/* Non-zero if an alarm came in during the reading of a command. */ -int alarm_deferred; - -/* Schedule one event, and arrange an alarm for it. - STR is a string of two fields separated by FS. - First field is string for get_date, saying when to wake-up. - Second field is a token to identify the request. */ - -void -schedule (str) - char *str; -{ - extern time_t get_date (); - extern char *strcpy (); - time_t now; - register char *p; - static struct event *ep; - - /* check entry format */ - for (p = str; *p && *p != FS; p++) - continue; - if (!*p) - { - fprintf (stderr, "%s: bad input format: %s\n", pname, str); - return; - } - *p++ = 0; - - /* allocate an event slot */ - ep = events + num_events; - - /* If the event array is full, stretch it. After stretching, we know - that ep will be pointing to an available event spot. */ - if (ep == events + events_size) - { - int old_size = events_size; - - events_size *= 2; - events = ((struct event *) - realloc (events, events_size * sizeof (struct event))); - if (! events) - { - fprintf (stderr, "%s: virtual memory exhausted.\n", pname); - /* Since there is so much virtual memory, and running out - almost surely means something is very very wrong, - it is best to exit rather than continue. */ - exit (1); - } - - while (old_size < events_size) - events[old_size++].token = NULL; - } - - /* Don't allow users to schedule events in past time. */ - ep->reply_at = get_date (str, NULL); - if (ep->reply_at - time (&now) < 0) - { - fprintf (stderr, "%s: bad time spec: %s%c%s\n", pname, str, FS, p); - return; - } - - /* save the event description */ - ep->token = (char *) malloc ((unsigned) strlen (p) + 1); - if (! ep->token) - { - fprintf (stderr, "%s: malloc %s: %s%c%s\n", - pname, strerror (errno), str, FS, p); - return; - } - - strcpy (ep->token, p); - num_events++; -} - -/* Print the notification for the alarmed event just arrived if any, - and schedule an alarm for the next event if any. */ - -void -notify () -{ - time_t now, tdiff, waitfor = -1; - register struct event *ep; - - /* Inhibit interference with alarms while changing global vars. */ - defer_alarms = 1; - alarm_deferred = 0; - - now = time ((time_t *) NULL); - - for (ep = events; ep < events + num_events; ep++) - /* Are any events ready to fire? */ - if (ep->reply_at <= now) - { - fputs (ep->token, stdout); - putc ('\n', stdout); - fflush (stdout); - free (ep->token); - - /* We now have a hole in the event array; fill it with the last - event. */ - ep->token = events[num_events - 1].token; - ep->reply_at = events[num_events - 1].reply_at; - num_events--; - - /* We ought to scan this event again. */ - ep--; - } - else - { - /* next timeout should be the soonest of any remaining */ - if ((tdiff = ep->reply_at - now) < waitfor || waitfor < 0) - waitfor = (long)tdiff; - } - - /* If there are no more events, we needn't bother setting an alarm. */ - if (num_events > 0) - alarm (waitfor); - - /* Now check if there was another alarm - while we were handling an explicit request. */ - defer_alarms = 0; - if (alarm_deferred) - notify (); - alarm_deferred = 0; -} - -/* Read one command from command from standard input - and schedule the event for it. */ - -void -getevent () -{ - int i; - - /* In principle the itimer should be disabled on entry to this - function, but it really doesn't make any important difference - if it isn't. */ - - if (buf == 0) - { - buf_size = 80; - buf = (char *) malloc (buf_size); - } - - /* Read a line from standard input, expanding buf if it is too short - to hold the line. */ - for (i = 0; ; i++) - { - char c; - int nread; - - if (i >= buf_size) - { - buf_size *= 2; - alarm_deferred = 0; - defer_alarms = 1; - buf = (char *) realloc (buf, buf_size); - defer_alarms = 0; - if (alarm_deferred) - notify (); - alarm_deferred = 0; - } - - /* Read one character into c. */ - while (1) - { - nread = read (fileno (stdin), &c, 1); - - /* Retry after transient error. */ - if (nread < 0 - && (1 -#ifdef EINTR - || errno == EINTR -#endif -#ifdef EAGAIN - || errno == EAGAIN -#endif - )) - continue; - - /* Report serious errors. */ - if (nread < 0) - { - perror ("read"); - exit (1); - } - - /* On eof, exit. */ - if (nread == 0) - exit (0); - - break; - } - - if (c == '\n') - { - buf[i] = '\0'; - break; - } - - buf[i] = c; - } - - /* Register the event. */ - alarm_deferred = 0; - defer_alarms = 1; - schedule (buf); - defer_alarms = 0; - notify (); - alarm_deferred = 0; -} - -/* Handle incoming signal SIG. */ - -SIGTYPE -sigcatch (sig) - int sig; -{ - struct event *ep; - - /* required on older UNIXes; harmless on newer ones */ - signal (sig, sigcatch); - - switch (sig) - { - case SIGALRM: - if (defer_alarms) - alarm_deferred = 1; - else - notify (); - break; - case SIGTERM: - fprintf (stderr, "Events still queued:\n"); - for (ep = events; ep < events + num_events; ep++) - fprintf (stderr, "%d = %ld @ %s\n", - ep - events, ep->reply_at, ep->token); - exit (0); - break; - } -} - -/*ARGSUSED*/ -int -main (argc, argv) - int argc; - char **argv; -{ - for (pname = argv[0] + strlen (argv[0]); - *pname != '/' && pname != argv[0]; - pname--); - if (*pname == '/') - pname++; - - events_size = 16; - events = ((struct event *) malloc (events_size * sizeof (*events))); - num_events = 0; - - signal (SIGALRM, sigcatch); - signal (SIGTERM, sigcatch); - - /* Loop reading commands from standard input - and scheduling alarms accordingly. - The alarms are handled asynchronously, while we wait for commands. */ - while (1) - getevent (); -} - -#ifndef HAVE_STRERROR -char * -strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum >= 0 && errnum < sys_nerr) - return sys_errlist[errnum]; - return (char *) "Unknown error"; -} - -#endif /* ! HAVE_STRERROR */ - -long * -xmalloc (size) - int size; -{ - register long *val; - - val = (long *) malloc (size); - - if (!val && size) - { - fprintf (stderr, "timer: virtual memory exceeded\n"); - exit (1); - } - - return val; -} - -/* timer.c ends here */ diff --git a/lib-src/=wakeup.c b/lib-src/=wakeup.c deleted file mode 100644 index 389519ba1f7..00000000000 --- a/lib-src/=wakeup.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Program to produce output at regular intervals. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <sys/types.h> - -#ifdef TIME_WITH_SYS_TIME -#include <sys/time.h> -#include <time.h> -#else -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#else -#include <time.h> -#endif -#endif - -struct tm *localtime (); - -void -main (argc, argv) - int argc; - char **argv; -{ - int period = 60; - time_t when; - struct tm *tp; - - if (argc > 1) - period = atoi (argv[1]); - - while (1) - { - /* Make sure wakeup stops when Emacs goes away. */ - if (getppid () == 1) - exit (0); - printf ("Wake up!\n"); - fflush (stdout); - /* If using a period of 60, produce the output when the minute - changes. */ - if (period == 60) - { - time (&when); - tp = localtime (&when); - sleep (60 - tp->tm_sec); - } - else - sleep (period); - } -} diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in deleted file mode 100644 index 24eec646375..00000000000 --- a/lib-src/Makefile.in +++ /dev/null @@ -1,419 +0,0 @@ -# Makefile for lib-src subdirectory in GNU Emacs. -# Copyright (C) 1985, 1987, 1988, 1993, 1994 Free Software Foundation, Inc. - -# This file is part of GNU Emacs. - -# GNU Emacs is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# GNU Emacs is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with GNU Emacs; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -# Avoid trouble on systems where the `SHELL' variable might be -# inherited from the environment. -SHELL = /bin/sh - -# ==================== Things `configure' will edit ==================== - -CC=@CC@ -CFLAGS=@CFLAGS@ -ALLOCA=@ALLOCA@ -YACC=@YACC@ -version=@version@ -configuration=@configuration@ - -# ==================== Where To Install Things ==================== - -# The default location for installation. Everything is placed in -# subdirectories of this directory. The default values for many of -# the variables below are expressed in terms of this one, so you may -# not need to change them. This is set with the --prefix option to -# `../configure'. -prefix=@prefix@ - -# Like `prefix', but used for architecture-specific files. This is -# set with the --exec-prefix option to `../configure'. -exec_prefix=@exec_prefix@ - -# Where to install Emacs and other binaries that people will want to -# run directly (like etags). This is set with the --bindir option -# to `../configure'. -bindir=@bindir@ - -# Where to install and expect executable files to be run by Emacs -# rather than directly by users, and other architecture-dependent -# data. ${archlibdir} is usually below this. This is set with the -# --libexecdir option to `../configure'. -libexecdir=@libexecdir@ - -# Where to find the source code. This is set by the configure -# script's `--srcdir' option. However, the value of ${srcdir} in -# this makefile is not identical to what was specified with --srcdir, -# since the variable here has `/lib-src' added at the end. -srcdir=@srcdir@ -VPATH=@srcdir@ - -# The top-level source directory, also set by configure. -top_srcdir=@top_srcdir@ - -# ==================== Emacs-specific directories ==================== - -# These variables hold the values Emacs will actually use. They are -# based on the values of the standard Make variables above. - -# Where to put executables to be run by Emacs rather than the user. -# This path usually includes the Emacs version and configuration name, -# so that multiple configurations for multiple versions of Emacs may -# be installed at once. This can be set with the --archlibdir option -# to `../configure'. -archlibdir=@archlibdir@ - -# ==================== Utility Programs for the Build ================= - -# ../configure figures out the correct values for these. -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_DATA = @INSTALL_DATA@ -# By default, we uphold the dignity of our programs. -INSTALL_STRIP = - -# ========================== Lists of Files =========================== - -# Things that a user might actually run, -# which should be installed in bindir. -INSTALLABLES = etags ctags emacsclient b2m -INSTALLABLE_SCRIPTS = rcs-checkin - -# Things that Emacs runs internally, or during the build process, -# which should not be installed in bindir. -UTILITIES= profile digest-doc \ - sorted-doc movemail cvtmail fakemail yow emacsserver hexl - -DONT_INSTALL= test-distrib make-docfile - -# Like UTILITIES, but they're not system-dependent, and should not be -# deleted by the distclean target. -SCRIPTS= rcs2log vcdiff - -EXECUTABLES= ${UTILITIES} ${INSTALLABLES} ${SCRIPTS} ${INSTALLABLE_SCRIPTS} - -SOURCES = COPYING ChangeLog Makefile.in README emacs.csh \ - makedoc.com *.[chy] rcs2log vcdiff - -# Additional -D flags for movemail (add to MOVE_FLAGS if desired): -# MAIL_USE_POP Support mail retrieval from a POP mailbox. -# MAIL_USE_MMDF Support MMDF mailboxes. -# MAIL_USE_FLOCK Use flock for file locking (see the comments -# about locking in movemail.c) -# MAIL_UNLINK_SPOOL Unlink the user's spool mailbox after reading -# it (instead of just emptying it). -# KERBEROS Support Kerberized POP. -# KRB5 Support Kerberos Version 5 pop instead of -# Version 4 (define this in addition to -# KERBEROS). -# HESIOD Support Hesiod lookups of user mailboxes. -# MAILHOST A string, the host name of the default POP -# mail host for the site. -MOVE_FLAGS= - -# ========================== start of cpp stuff ======================= -/* From here on, comments must be done in C syntax. */ - -#define NO_SHORTNAMES -#define THIS_IS_MAKEFILE -#define NOT_C_CODE -#include "../src/config.h" - -/* We won't really call alloca; - don't let the file name alloca.c get messed up. */ -#ifdef alloca -#undef alloca -#endif - -/* Some machines don't find the standard C libraries in the usual place. */ -#ifndef ORDINARY_LINK -#ifndef LIB_STANDARD_LIBSRC -#define LIB_STANDARD_LIBSRC -lc -#endif -#else -#ifndef LIB_STANDARD_LIBSRC -#define LIB_STANDARD_LIBSRC -#endif -#endif - -/* Some s/SYSTEM.h files define this to request special libraries. */ -#ifndef LIBS_SYSTEM -#define LIBS_SYSTEM -#endif - -/* Some m/MACHINE.h files define this to request special libraries. */ -#ifndef LIBS_MACHINE -#define LIBS_MACHINE -#endif - -#ifndef C_SWITCH_SYSTEM -#define C_SWITCH_SYSTEM -#endif - -#ifndef C_SWITCH_MACHINE -#define C_SWITCH_MACHINE -#endif - -#undef MOVEMAIL_NEEDS_BLESSING -#ifndef MAIL_USE_FLOCK -#ifndef MAIL_USE_LOCKF -#define MOVEMAIL_NEEDS_BLESSING -#endif -#endif - -#ifdef MOVEMAIL_NEEDS_BLESSING -#define BLESSMAIL blessmail -#else -#define BLESSMAIL -#endif - -#ifdef KERBEROS -#ifdef HAVE_LIBKRB - /* For krb5, use -lkrb5 */ - KRBLIB=-lkrb -#endif -#ifdef HAVE_LIBDES - /* For krb4, use -lcrypto */ - DESLIB=-ldes -#endif -#ifdef HAVE_LIBCOM_ERR - COM_ERRLIB=-lcom_err -#endif -#endif /* KERBEROS */ - -/* If HESIOD is defined, set this to "-lhesiod". */ -HESIODLIB= - -MOVE_LIBS=$(KRBLIB) $(DESLIB) $(COM_ERRLIB) $(HESIODLIB) - -#ifdef HAVE_LIBMAIL -LIBMAIL=-lmail -#endif - -LOADLIBES=LIBS_SYSTEM LIBS_MACHINE LIB_STANDARD_LIBSRC - -/* We need to #define emacs to get the right versions of some files. - Some other files - those shared with other GNU utilities - need - HAVE_CONFIG_H #defined before they know they can take advantage of - the information in ../src/config.h. */ -ALL_CFLAGS = C_SWITCH_SYSTEM C_SWITCH_MACHINE -DHAVE_CONFIG_H \ - -I. -I../src -I${srcdir} -I${srcdir}/../src ${LDFLAGS} ${CPPFLAGS} ${CFLAGS} -LINK_CFLAGS = C_SWITCH_SYSTEM C_SWITCH_MACHINE -DHAVE_CONFIG_H \ - -I. -I../src -I${srcdir} -I${srcdir}/../src ${LDFLAGS} ${CFLAGS} -CPP_CFLAGS = C_SWITCH_SYSTEM C_SWITCH_MACHINE -DHAVE_CONFIG_H \ - -I. -I../src -I${srcdir} -I${srcdir}/../src ${CPPFLAGS} ${CFLAGS} -/* This was all of CPP_CFLAGS except -Demacs. - Now that -Demacs has been deleted from CPP_CFLAGS, - this is actually the same as CPP_CFLAGS, but let's not delete it yet. */ -BASE_CFLAGS = C_SWITCH_SYSTEM C_SWITCH_MACHINE -DHAVE_CONFIG_H \ - -I. -I../src -I${srcdir} -I${srcdir}/../src ${CPPFLAGS} ${CFLAGS} - -/* This is the default compilation command. - But we should never rely on it, because some make version - failed to find it for getopt.o. - Using an explicit command made it work. */ -.c.o: - ${CC} -c ${CPP_CFLAGS} $< - -all: ${DONT_INSTALL} ${UTILITIES} ${INSTALLABLES} - -#ifdef MOVEMAIL_NEEDS_BLESSING -blessmail: - ../src/emacs -batch -l $(srcdir)/../lisp/blessmail.el - chmod +x blessmail -#endif - -maybe-blessmail: BLESSMAIL -#ifdef MOVEMAIL_NEEDS_BLESSING -/* Don't charge ahead and do it! Let the installer decide. - ./blessmail ${archlibdir}/movemail */ - @if [ `wc -l <blessmail` != 2 ] ; then \ - dir=`sed -n -e 's/echo mail directory = \(.*\)/\1/p' blessmail`; \ - echo Assuming $$dir is really the mail spool directory, you should; \ - echo run lib-src/blessmail ${archlibdir}/movemail; \ - echo as root, to give movemail appropriate permissions.; \ - echo Do that after running make install.; \ - fi -#endif - -/* Install the internal utilities. Until they are installed, we can - just run them directly from lib-src. */ -${archlibdir}: all - @echo - @echo "Installing utilities run internally by Emacs." - $(top_srcdir)/mkinstalldirs ${archlibdir} - if [ `(cd ${archlibdir} && /bin/pwd)` != `/bin/pwd` ]; then \ - for file in ${UTILITIES}; do \ - $(INSTALL_PROGRAM) $(INSTALL_STRIP) $$file ${archlibdir}/$$file ; \ - done ; \ - fi - if [ `(cd ${archlibdir} && /bin/pwd)` \ - != `(cd ${srcdir} && /bin/pwd)` ]; then \ - for file in ${SCRIPTS}; do \ - $(INSTALL_PROGRAM) ${srcdir}/$$file ${archlibdir}/$$file; \ - done ; \ - fi - -install: ${archlibdir} - @echo - @echo "Installing utilities for users to run." - for file in ${INSTALLABLES} ; do \ - $(INSTALL_PROGRAM) $${file} ${bindir}/$${file} ; \ - chmod a+rx ${bindir}/$${file}; \ - done - for file in ${INSTALLABLE_SCRIPTS} ; do \ - $(INSTALL_PROGRAM) ${srcdir}/$${file} ${bindir}/$${file} ; \ - chmod a+rx ${bindir}/$${file}; \ - done - -uninstall: - (cd ${bindir}; \ - rm -f ${INSTALLABLES} ${INSTALLABLE_SCRIPTS}) - (cd ${archlibdir}; \ - rm -f ${UTILITIES} ${INSTALLABLES} ${SCRIPTS} ${INSTALLABLE_SCRIPTS}) - -mostlyclean: - -rm -f core *.o - -clean: mostlyclean - -rm -f ${INSTALLABLES} ${UTILITIES} ${DONT_INSTALL} - -rm -f ../etc/DOC* *.tab.c *.tab.h - -distclean: clean - -rm -f TAGS - -rm -f Makefile Makefile.c blessmail - -maintainer-clean: distclean - true - -extraclean: maintainer-clean - -rm -f *~ \#* - -unlock: - chmod u+w $(SOURCES) - -relock: - chmod u-w $(SOURCES) - -/* Test the contents of the directory. */ -check: - @echo "We don't have any tests for GNU Emacs yet." - -tags: TAGS -TAGS: etags - etags *.[ch] - -/* This verifies that the non-ASCII characters in the file `testfile' - have not been clobbered by whatever means were used to copy and - distribute Emacs. If they were clobbered, all the .elc files were - clobbered too. */ -test-distrib: ${srcdir}/test-distrib.c - $(CC) ${ALL_CFLAGS} -o test-distrib ${srcdir}/test-distrib.c - ./test-distrib ${srcdir}/testfile - -GETOPTOBJS = getopt.o getopt1.o $(ALLOCA) -GETOPTDEPS = $(GETOPTOBJS) ${srcdir}/getopt.h -getopt.o: ${srcdir}/getopt.c ${srcdir}/getopt.h - ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt.c -getopt1.o: ${srcdir}/getopt1.c ${srcdir}/getopt.h - ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt1.c -alloca.o: ${srcdir}/alloca.c - ${CC} -c ${BASE_CFLAGS} ${srcdir}/alloca.c - -#ifdef REGEXP_IN_LIBC -REGEXPOBJ = -REGEXPDEPS = -#else -REGEXPOBJ = regex.o -REGEXPDEPS = $(REGEXPOBJ) ../src/regex.h -#endif - -regex.o: ../src/regex.c ../src/regex.h ../src/config.h - ${CC} -c ${BASE_CFLAGS} -DCONFIG_BROKETS -DINHIBIT_STRING_HEADER ${srcdir}/../src/regex.c - -etags: ${srcdir}/etags.c $(GETOPTDEPS) $(REGEXPDEPS) ../src/config.h - $(CC) ${ALL_CFLAGS} -DVERSION="\"${version}\"" -DETAGS_REGEXPS ${srcdir}/etags.c $(GETOPTOBJS) $(REGEXPOBJ) $(LOADLIBES) -o etags - -/* We depend on etags to assure that parallel makes don't write two - etags.o files on top of each other. */ -ctags: etags - $(CC) ${ALL_CFLAGS} -DCTAGS -DVERSION="\"${version}\"" -DETAGS_REGEXPS ${srcdir}/etags.c $(GETOPTOBJS) $(REGEXPOBJ) $(LOADLIBES) -o ctags - -profile: ${srcdir}/profile.c - $(CC) ${ALL_CFLAGS} ${srcdir}/profile.c $(LOADLIBES) -o profile - -make-docfile: ${srcdir}/make-docfile.c - $(CC) ${ALL_CFLAGS} ${srcdir}/make-docfile.c $(LOADLIBES) -o make-docfile - -digest-doc: ${srcdir}/digest-doc.c - $(CC) ${ALL_CFLAGS} ${srcdir}/digest-doc.c $(LOADLIBES) -o digest-doc - -sorted-doc: ${srcdir}/sorted-doc.c ${ALLOCA} - $(CC) ${ALL_CFLAGS} ${srcdir}/sorted-doc.c ${ALLOCA} $(LOADLIBES) -o sorted-doc - -b2m: ${srcdir}/b2m.c ../src/config.h - $(CC) ${ALL_CFLAGS} ${srcdir}/b2m.c $(LOADLIBES) -o b2m - -movemail: movemail.o pop.o - $(CC) ${LINK_CFLAGS} ${MOVE_FLAGS} movemail.o pop.o $(LOADLIBES) $(LIBMAIL) $(MOVE_LIBS) -o movemail - -movemail.o: ${srcdir}/movemail.c ../src/config.h - $(CC) -c ${CPP_CFLAGS} -Demacs ${MOVE_FLAGS} ${srcdir}/movemail.c - -pop.o: ${srcdir}/pop.c - $(CC) -c ${CPP_CFLAGS} ${MOVE_FLAGS} ${srcdir}/pop.c - -cvtmail: ${srcdir}/cvtmail.c - $(CC) ${ALL_CFLAGS} ${srcdir}/cvtmail.c $(LOADLIBES) -o cvtmail - -fakemail: ${srcdir}/fakemail.c ../src/config.h - $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail - -yow: ${srcdir}/yow.c ../src/paths.h - $(CC) ${ALL_CFLAGS} ${srcdir}/yow.c $(LOADLIBES) -o yow - -emacsserver: ${srcdir}/emacsserver.c ../src/config.h - $(CC) ${ALL_CFLAGS} ${srcdir}/emacsserver.c $(LOADLIBES) -o emacsserver - -emacsclient: ${srcdir}/emacsclient.c ../src/config.h $(GETOPTDEPS) - $(CC) ${ALL_CFLAGS} ${srcdir}/emacsclient.c $(GETOPTOBJS) \ - -DVERSION=`sed -n -e '/(defconst emacs-version/ s/^[^"]*\("[^"]*"\).*/\1/p' ${srcdir}/../lisp/version.el` \ - $(LOADLIBES) -o emacsclient - -hexl: ${srcdir}/hexl.c - $(CC) ${ALL_CFLAGS} ${srcdir}/hexl.c $(LOADLIBES) -o hexl - -/* These are NOT included in INSTALLABLES or UTILITIES. - See ../src/Makefile.in. */ -emacstool: ${srcdir}/emacstool.c - $(CC) ${srcdir}/emacstool.c -o emacstool ${ALL_CFLAGS} \ - -lsuntool -lsunwindow -lpixrect $(LOADLIBES) - -/* For SUN Japanese Language Environment. */ -nemacstool: ${srcdir}/emacstool.c - $(CC) -o nemacstool -DJLE ${ALL_CFLAGS} ${srcdir}/emacstool.c \ - -lsuntool -lmle -lsunwindow -lpixrect $(LOADLIBES) - -xvetool: ${srcdir}/emacstool.c - $(CC) -o xvetool -DXVIEW ${ALL_CFLAGS} ${srcdir}/emacstool.c \ - -lxview -lX -I$(OPENWINHOME)/include -L$(OPENWINHOME)/lib \ - $(LOADLIBES) - -xveterm: ${srcdir}/emacstool.c - $(CC) -o xveterm -DXVIEW -DTTERM ${ALL_CFLAGS} ${srcdir}/emacstool.c \ - -lxview -lolgx -lX -I$(OPENWINHOME)/include -L$(OPENWINHOME)/lib \ - $(LOADLIBES) diff --git a/lib-src/b2m.c b/lib-src/b2m.c deleted file mode 100644 index 88d0acd5cd8..00000000000 --- a/lib-src/b2m.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * b2m - a filter for Babyl -> Unix mail files - * - * usage: b2m < babyl > mailbox - * - * I find this useful whenever I have to use a - * system which - shock horror! - doesn't run - * Gnu emacs. At least now I can read all my - * Gnumacs Babyl format mail files! - * - * it's not much but it's free! - * - * Ed Wilkinson - * E.Wilkinson@massey.ac.nz - * Mon Nov 7 15:54:06 PDT 1988 - */ - -/* Made conformant to the GNU coding standards January, 1995 - by Francesco Potorti` <pot@cnuce.cnr.it>. */ - -#include <stdio.h> -#include <time.h> -#include <sys/types.h> -#ifdef MSDOS -#include <fcntl.h> -#endif - -#ifdef HAVE_CONFIG_H -#include <config.h> -/* On some systems, Emacs defines static as nothing for the sake - of unexec. We don't want that here since we don't use unexec. */ -#undef static -#endif - -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE 0 - -/* Exit codes for success and failure. */ -#ifdef VMS -#define GOOD 1 -#define BAD 0 -#else -#define GOOD 0 -#define BAD 1 -#endif - -#define streq(s,t) (strcmp (s, t) == 0) -#define strneq(s,t,n) (strncmp (s, t, n) == 0) - -typedef int logical; - -/* - * A `struct linebuffer' is a structure which holds a line of text. - * `readline' reads a line from a stream into a linebuffer and works - * regardless of the length of the line. - */ -struct linebuffer -{ - long size; - char *buffer; -}; - -extern char *strtok(); - -long *xmalloc (), *xrealloc (); -char *concat (); -long readline (); -void fatal (); - -/* - * xnew -- allocate storage. SYNOPSIS: Type *xnew (int n, Type); - */ -#define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) - - - -char *progname; - -main (argc, argv) - int argc; - char **argv; -{ - logical labels_saved, printing, header; - time_t ltoday; - char *labels, *p, *today; - struct linebuffer data; - -#ifdef MSDOS - _fmode = O_BINARY; /* all of files are treated as binary files */ -#if __DJGPP__ > 1 - if (!isatty (fileno (stdout))) - setmode (fileno (stdout), O_BINARY); - if (!isatty (fileno (stdin))) - setmode (fileno (stdin), O_BINARY); -#else /* not __DJGPP__ > 1 */ - (stdout)->_flag &= ~_IOTEXT; - (stdin)->_flag &= ~_IOTEXT; -#endif /* not __DJGPP__ > 1 */ -#endif - progname = argv[0]; - - if (argc != 1) - { - fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", progname); - exit (GOOD); - } - labels_saved = printing = header = FALSE; - ltoday = time (0); - today = ctime (<oday); - data.size = 200; - data.buffer = xnew (200, char); - - if (readline (&data, stdin) == 0 - || !strneq (data.buffer, "BABYL OPTIONS:", 14)) - fatal ("standard input is not a Babyl mailfile."); - - while (readline (&data, stdin) > 0) - { - if (streq (data.buffer, "*** EOOH ***") && !printing) - { - printing = header = TRUE; - printf ("From \"Babyl to mail by %s\" %s", progname, today); - continue; - } - - if (data.buffer[0] == '\037') - { - if (data.buffer[1] == '\0') - continue; - else if (data.buffer[1] == '\f') - { - /* Save labels. */ - readline (&data, stdin); - p = strtok (data.buffer, " ,\r\n\t"); - labels = "X-Babyl-Labels: "; - - while (p = strtok (NULL, " ,\r\n\t")) - labels = concat (labels, p, ", "); - - p = &labels[strlen (labels) - 2]; - if (*p == ',') - *p = '\0'; - printing = header = FALSE; - labels_saved = TRUE; - continue; - } - } - - if ((data.buffer[0] == '\0') && header) - { - header = FALSE; - if (labels_saved) - puts (labels); - } - - if (printing) - puts (data.buffer); - } -} - - - -/* - * Return a newly-allocated string whose contents - * concatenate those of s1, s2, s3. - */ -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = xnew (len1 + len2 + len3 + 1, char); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - result[len1 + len2 + len3] = '\0'; - - return result; -} - -/* - * Read a line of text from `stream' into `linebuffer'. - * Return the number of characters read from `stream', - * which is the length of the line including the newline, if any. - */ -long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - register FILE *stream; -{ - char *buffer = linebuffer->buffer; - register char *p = linebuffer->buffer; - register char *pend; - int chars_deleted; - - pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */ - - while (1) - { - register int c = getc (stream); - if (p == pend) - { - linebuffer->size *= 2; - buffer = (char *) xrealloc (buffer, linebuffer->size); - p += buffer - linebuffer->buffer; - pend = buffer + linebuffer->size; - linebuffer->buffer = buffer; - } - if (c == EOF) - { - chars_deleted = 0; - break; - } - if (c == '\n') - { - if (p[-1] == '\r' && p > buffer) - { - *--p = '\0'; - chars_deleted = 2; - } - else - { - *p = '\0'; - chars_deleted = 1; - } - break; - } - *p++ = c; - } - - return (p - buffer + chars_deleted); -} - -/* - * Like malloc but get fatal error if memory is exhausted. - */ -long * -xmalloc (size) - unsigned int size; -{ - long *result = (long *) malloc (size); - if (result == NULL) - fatal ("virtual memory exhausted"); - return result; -} - -long * -xrealloc (ptr, size) - char *ptr; - unsigned int size; -{ - long *result = (long *) realloc (ptr, size); - if (result == NULL) - fatal ("virtual memory exhausted"); - return result; -} - -void -fatal (message) -{ - fprintf (stderr, "%s: %s\n", progname, message); - exit (BAD); -} - diff --git a/lib-src/cvtmail.c b/lib-src/cvtmail.c deleted file mode 100644 index 20ef3412439..00000000000 --- a/lib-src/cvtmail.c +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright (C) 1985, 1994 Free Software Foundation - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* cvtmail: - * Program to convert oldstyle goslings emacs mail directories into - * gnu-rmail format. Program expects a directory called Messages to - * exist in your home directory, containing individual mail messages in - * separate files in the standard gosling emacs mail reader format. - * - * Program takes one argument: an output file. This file will contain - * all the messages in Messages directory, in berkeley mail format. - * If no output file is mentioned, messages are put in ~/OMAIL. - * - * In order to get rmail to read the messages, the resulting file must - * be mv'ed to ~/mbox, and then have rmail invoked on them. - * - * Author: Larry Kolodney, 1985 - */ - - -#include <stdio.h> - -char *malloc (); -char *realloc (); -char *getenv (); - -char *xmalloc (); -char *xrealloc (); -void skip_to_lf (); -void sysfail (); - -int -main (argc, argv) - int argc; - char *argv[]; -{ - char *hd; - char *md; - char *mdd; - char *mfile; - char *cf; - int cflen; - FILE *mddf; - FILE *mfilef; - FILE *cff; - char pre[10]; - char name[14]; - int c; - - hd = (char *) getenv ("HOME"); - - md = (char *) xmalloc (strlen (hd) + 10); - strcpy (md, hd); - strcat (md, "/Messages"); - - mdd = (char *) xmalloc (strlen (md) + 11); - strcpy (mdd, md); - strcat (mdd, "/Directory"); - - cflen = 100; - cf = (char *) xmalloc (cflen); - - mddf = fopen (mdd, "r"); - if (!mddf) - sysfail (mdd); - if (argc > 1) - mfile = argv[1]; - else - { - mfile = (char *) xmalloc (strlen (hd) + 7); - strcpy (mfile, hd); - strcat (mfile, "/OMAIL"); - } - mfilef = fopen (mfile, "w"); - if (!mfilef) - sysfail (mfile); - - skip_to_lf (mddf); - while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) - { - if (cflen < strlen (md) + strlen (name) + 2) - { - cflen = strlen (md) + strlen (name) + 2; - cf = (char *) xrealloc (cf, cflen); - } - strcpy (cf, md); - strcat (cf,"/"); - strcat (cf, name); - cff = fopen (cf, "r"); - if (!cff) - perror (cf); - else - { - while ((c = getc(cff)) != EOF) - putc (c, mfilef); - putc ('\n', mfilef); - skip_to_lf (mddf); - fclose (cff); - } - } - fclose (mddf); - fclose (mfilef); - return 0; -} - -void -skip_to_lf (stream) - FILE *stream; -{ - register int c; - while ((c = getc(stream)) != EOF && c != '\n') - ; -} - - -void -error (s1, s2) - char *s1, *s2; -{ - fprintf (stderr, "cvtmail: "); - fprintf (stderr, s1, s2); - fprintf (stderr, "\n"); -} - -/* Print error message and exit. */ - -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -void -sysfail (s) - char *s; -{ - fprintf (stderr, "cvtmail: "); - perror (s); - exit (1); -} - -char * -xmalloc (size) - unsigned size; -{ - char *result = malloc (size); - if (!result) - fatal ("virtual memory exhausted", 0); - return result; -} - -char * -xrealloc (ptr, size) - char *ptr; - unsigned size; -{ - char *result = realloc (ptr, size); - if (!result) - fatal ("virtual memory exhausted"); - return result; -} diff --git a/lib-src/digest-doc.c b/lib-src/digest-doc.c deleted file mode 100644 index 1d47ce0a0ce..00000000000 --- a/lib-src/digest-doc.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Give this program DOCSTR.mm.nn as standard input - and it outputs to standard output - a file of nroff output containing the doc strings. - - See also sorted-doc.c, which produces similar output - but in texinfo format and sorted by function/variable name. */ - -#include <stdio.h> - -int -main () -{ - register int ch; - register int notfirst = 0; - - printf (".TL\n"); - printf ("Command Summary for GNU Emacs\n"); - printf (".AU\nRichard M. Stallman\n"); - while ((ch = getchar ()) != EOF) - { - if (ch == '\037') - { - if (notfirst) - printf ("\n.DE"); - else - notfirst = 1; - - printf ("\n.SH\n"); - - ch = getchar (); - printf (ch == 'F' ? "Function " : "Variable "); - - while ((ch = getchar ()) != '\n') /* Changed this line */ - { - if (ch != EOF) - putchar (ch); - else - { - ungetc (ch, stdin); - break; - } - } - printf ("\n.DS L\n"); - } - else - putchar (ch); - } - return 0; -} diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c deleted file mode 100644 index 2e99e9d34ad..00000000000 --- a/lib-src/emacsclient.c +++ /dev/null @@ -1,494 +0,0 @@ -/* Client process that communicates with GNU Emacs acting as server. - Copyright (C) 1986, 1987, 1994 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - - -#define NO_SHORTNAMES -#include <../src/config.h> -#undef read -#undef write -#undef open -#undef close -#undef signal - -#include <stdio.h> -#include <getopt.h> - -char *getenv (), *getwd (); -char *getcwd (); -int geteuid (); - -/* This is defined with -D from the compilation command, - which extracts it from ../lisp/version.el. */ - -#ifndef VERSION -#define VERSION "unspecified" -#endif - -/* Name used to invoke this program. */ -char *progname; - -/* Nonzero means don't wait for a response from Emacs. --no-wait. */ -int nowait = 0; - -struct option longopts[] = -{ - { "no-wait", no_argument, NULL, 'n' }, - { "help", no_argument, NULL, 'H' }, - { "version", no_argument, NULL, 'V' }, - { 0 } -}; - -/* Decode the options from argv and argc. - The global variable `optind' will say how many arguments we used up. */ - -void -decode_options (argc, argv) - int argc; - char **argv; -{ - while (1) - { - int opt = getopt_long (argc, argv, - "VHn", longopts, 0); - - if (opt == EOF) - break; - - switch (opt) - { - case 0: - /* If getopt returns 0, then it has already processed a - long-named option. We should do nothing. */ - break; - - case 'n': - nowait = 1; - break; - - case 'V': - fprintf (stderr, "Version %s\n", VERSION); - exit (1); - break; - - case 'H': - default: - print_help_and_exit (); - } - } -} - -print_help_and_exit () -{ - fprintf (stderr, - "Usage: %s [-n] [--no-wait] [+LINENUMBER] FILENAME\n", - progname); - fprintf (stderr, - "Report bugs to bug-gnu-emacs@prep.ai.mit.edu.\n"); - exit (1); -} - -/* Return a copy of NAME, inserting a & - before each &, each space, and any initial -. - Change spaces to underscores, too, so that the - return value never contains a space. */ - -char * -quote_file_name (name) - char *name; -{ - char *copy = (char *) malloc (strlen (name) * 2 + 1); - char *p, *q; - - p = name; - q = copy; - while (*p) - { - if (*p == ' ') - { - *q++ = '&'; - *q++ = '_'; - p++; - } - else - { - if (*p == '&' || (*p == '-' && p == name)) - *q++ = '&'; - *q++ = *p++; - } - } - *q++ = 0; - - return copy; -} - -#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) - -main (argc, argv) - int argc; - char **argv; -{ - fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", - argv[0]); - fprintf (stderr, "on systems with Berkeley sockets or System V IPC.\n"); - exit (1); -} - -#else /* HAVE_SOCKETS or HAVE_SYSVIPC */ - -#if defined (HAVE_SOCKETS) && ! defined (NO_SOCKETS_IN_FILE_SYSTEM) -/* BSD code is very different from SYSV IPC code */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <sys/stat.h> -#include <errno.h> - -extern char *strerror (); -extern int errno; - -int -main (argc, argv) - int argc; - char **argv; -{ - char system_name[32]; - int s, i; - FILE *out, *in; - struct sockaddr_un server; - char *homedir, *cwd, *str; - char string[BUFSIZ]; - - progname = argv[0]; - - /* Process options. */ - decode_options (argc, argv); - - if (argc - optind < 1) - print_help_and_exit (); - - /* - * Open up an AF_UNIX socket in this person's home directory - */ - - if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) - { - fprintf (stderr, "%s: ", argv[0]); - perror ("socket"); - exit (1); - } - server.sun_family = AF_UNIX; -#ifndef SERVER_HOME_DIR - { - struct stat statbfr; - - gethostname (system_name, sizeof (system_name)); - sprintf (server.sun_path, "/tmp/esrv%d-%s", geteuid (), system_name); - - if (stat (server.sun_path, &statbfr) == -1) - { - if (errno == ENOENT) - fprintf (stderr, - "%s: can't find socket; have you started the server?\n", - argv[0]); - else - fprintf (stderr, "%s: can't stat %s: %s\n", - argv[0], server.sun_path, strerror (errno)); - exit (1); - } - if (statbfr.st_uid != geteuid ()) - { - fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); - exit (1); - } - } -#else - if ((homedir = getenv ("HOME")) == NULL) - { - fprintf (stderr, "%s: No home directory\n", argv[0]); - exit (1); - } - strcpy (server.sun_path, homedir); - strcat (server.sun_path, "/.emacs-server-"); - gethostname (system_name, sizeof (system_name)); - strcat (server.sun_path, system_name); -#endif - - if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) - < 0) - { - fprintf (stderr, "%s: ", argv[0]); - perror ("connect"); - exit (1); - } - - /* We use the stream OUT to send our command to the server. */ - if ((out = fdopen (s, "r+")) == NULL) - { - fprintf (stderr, "%s: ", argv[0]); - perror ("fdopen"); - exit (1); - } - - /* We use the stream IN to read the response. - We used to use just one stream for both output and input - on the socket, but reversing direction works nonportably: - on some systems, the output appears as the first input; - on other systems it does not. */ - if ((in = fdopen (s, "r+")) == NULL) - { - fprintf (stderr, "%s: ", argv[0]); - perror ("fdopen"); - exit (1); - } - -#ifdef BSD_SYSTEM - cwd = getwd (string); -#else - cwd = getcwd (string, sizeof string); -#endif - if (cwd == 0) - { - /* getwd puts message in STRING if it fails. */ - fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno)); - exit (1); - } - - if (nowait) - fprintf (out, "-nowait "); - - for (i = optind; i < argc; i++) - { - if (*argv[i] == '+') - { - char *p = argv[i] + 1; - while (*p >= '0' && *p <= '9') p++; - if (*p != 0) - fprintf (out, "%s/", cwd); - } - else if (*argv[i] != '/') - fprintf (out, "%s/", cwd); - - fprintf (out, "%s ", quote_file_name (argv[i])); - } - fprintf (out, "\n"); - fflush (out); - - /* Maybe wait for an answer. */ - if (nowait) - return 0; - - printf ("Waiting for Emacs..."); - fflush (stdout); - - /* Now, wait for an answer and print any messages. On some systems, - the first line we read will actually be the output we just sent. - We can't predict whether that will happen, so if it does, we - detect it by recognizing `Client: ' at the beginning. */ - - while (str = fgets (string, BUFSIZ, in)) - printf ("%s", str); - - return 0; -} - -#else /* This is the SYSV IPC section */ - -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/msg.h> -#include <sys/utsname.h> -#include <stdio.h> - -char *getwd (), *getcwd (), *getenv (); -struct utsname system_name; - -main (argc, argv) - int argc; - char **argv; -{ - int s; - key_t key; - /* Size of text allocated in MSGP. */ - int size_allocated = BUFSIZ; - /* Amount of text used in MSGP. */ - int used; - struct msgbuf *msgp - = (struct msgbuf *) malloc (sizeof (struct msgbuf) + size_allocated); - struct msqid_ds * msg_st; - char *homedir, buf[BUFSIZ]; - char gwdirb[BUFSIZ]; - char *cwd; - char *temp; - - progname = argv[0]; - - /* Process options. */ - decode_options (argc, argv); - - if (argc - optind < 1) - print_help_and_exit (); - - /* - * Create a message queue using ~/.emacs-server as the path for ftok - */ - if ((homedir = getenv ("HOME")) == NULL) - { - fprintf (stderr, "%s: No home directory\n", argv[0]); - exit (1); - } - strcpy (buf, homedir); -#ifndef HAVE_LONG_FILE_NAMES - /* If file names are short, we can't fit the host name. */ - strcat (buf, "/.emacs-server"); -#else - strcat (buf, "/.emacs-server-"); - uname (&system_name); - strcat (buf, system_name.nodename); -#endif - creat (buf, 0600); - key = ftok (buf, 1); /* unlikely to be anyone else using it */ - s = msgget (key, 0600 | IPC_CREAT); - if (s == -1) - { - fprintf (stderr, "%s: ", argv[0]); - perror ("msgget"); - exit (1); - } - - /* Determine working dir, so we can prefix it to all the arguments. */ -#ifdef BSD_SYSTEM - temp = getwd (gwdirb); -#else - temp = getcwd (gwdirb, sizeof gwdirb); -#endif - - cwd = gwdirb; - if (temp != 0) - { - /* On some systems, cwd can look like `@machine/...'; - ignore everything before the first slash in such a case. */ - while (*cwd && *cwd != '/') - cwd++; - strcat (cwd, "/"); - } - else - { - fprintf (stderr, "%s: %s\n", argv[0], cwd); - exit (1); - } - - msgp->mtext[0] = 0; - used = 0; - - if (nowait) - { - strcat (msgp->mtext, "-nowait "); - used += 8; - } - - argc -= optind; - argv += optind; - - while (argc) - { - int need_cwd = 0; - char *modified_arg = argv[0]; - - if (*modified_arg == '+') - { - char *p = modified_arg + 1; - while (*p >= '0' && *p <= '9') p++; - if (*p != 0) - need_cwd = 1; - } - else if (*modified_arg != '/') - need_cwd = 1; - - modified_arg = quote_file_name (modified_arg); - - if (need_cwd) - used += strlen (cwd); - used += strlen (modified_arg) + 1; - while (used + 2 > size_allocated) - { - size_allocated *= 2; - msgp = (struct msgbuf *) realloc (msgp, - (sizeof (struct msgbuf) - + size_allocated)); - } - - if (need_cwd) - strcat (msgp->mtext, cwd); - - strcat (msgp->mtext, modified_arg); - strcat (msgp->mtext, " "); - argv++; argc--; - } - strcat (msgp->mtext, "\n"); -#ifdef HPUX /* HPUX has a bug. */ - if (strlen (msgp->mtext) >= 512) - { - fprintf (stderr, "%s: args too long for msgsnd\n", progname); - exit (1); - } -#endif - msgp->mtype = 1; - if (msgsnd (s, msgp, strlen (msgp->mtext)+1, 0) < 0) - { - fprintf (stderr, "%s: ", progname); - perror ("msgsnd"); - exit (1); - } - - /* Maybe wait for an answer. */ - if (nowait) - return 0; - - printf ("Waiting for Emacs..."); - fflush (stdout); - - msgrcv (s, msgp, BUFSIZ, getpid (), 0); /* wait for anything back */ - strcpy (buf, msgp->mtext); - - printf ("\n"); - if (*buf) - printf ("%s\n", buf); - exit (0); -} - -#endif /* HAVE_SYSVIPC */ - -#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */ - -#ifndef HAVE_STRERROR -char * -strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum >= 0 && errnum < sys_nerr) - return sys_errlist[errnum]; - return (char *) "Unknown error"; -} - -#endif /* ! HAVE_STRERROR */ diff --git a/lib-src/emacsserver.c b/lib-src/emacsserver.c deleted file mode 100644 index 9fbf3e86516..00000000000 --- a/lib-src/emacsserver.c +++ /dev/null @@ -1,564 +0,0 @@ -/* Communication subprocess for GNU Emacs acting as server. - Copyright (C) 1986, 1987, 1992, 1994 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - - -/* The GNU Emacs edit server process is run as a subprocess of Emacs - under control of the file lisp/server.el. - This program accepts communication from client (program emacsclient.c) - and passes their commands (consisting of keyboard characters) - up to the Emacs which then executes them. */ - -#define NO_SHORTNAMES -#include <signal.h> -#include <../src/config.h> -#undef read -#undef write -#undef open -#undef close -#undef signal - -#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) -#include <stdio.h> - -main () -{ - fprintf (stderr, "Sorry, the Emacs server is supported only on systems\n"); - fprintf (stderr, "with Berkeley sockets or System V IPC.\n"); - exit (1); -} - -#else /* HAVE_SOCKETS or HAVE_SYSVIPC */ - -#if defined (HAVE_SOCKETS) && ! defined (NO_SOCKETS_IN_FILE_SYSTEM) -/* BSD code is very different from SYSV IPC code */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <stdio.h> -#include <errno.h> -#include <sys/stat.h> - -extern int errno; - -/* Copied from src/process.c */ -#ifdef FD_SET -/* We could get this from param.h, but better not to depend on finding that. - And better not to risk that it might define other symbols used in this - file. */ -#ifdef FD_SETSIZE -#define MAXDESC FD_SETSIZE -#else -#define MAXDESC 64 -#endif -#define SELECT_TYPE fd_set -#else /* no FD_SET */ -#define MAXDESC 32 -#define SELECT_TYPE int - -/* Define the macros to access a single-int bitmap of descriptors. */ -#define FD_SET(n, p) (*(p) |= (1 << (n))) -#define FD_CLR(n, p) (*(p) &= ~(1 << (n))) -#define FD_ISSET(n, p) (*(p) & (1 << (n))) -#define FD_ZERO(p) (*(p) = 0) -#endif /* no FD_SET */ - -/* This is the file name of the socket that we made. */ - -char *socket_name; - -/* Name of this program. */ - -char *progname; - -/* Handle fatal signals. */ - -/* This is the handler. */ - -SIGTYPE -delete_socket (sig) - int sig; -{ - signal (sig, SIG_DFL); - unlink (socket_name); - kill (getpid (), sig); -} - -/* Set up to handle all the signals. */ - -handle_signals () -{ - signal (SIGHUP, delete_socket); - signal (SIGINT, delete_socket); - signal (SIGQUIT, delete_socket); - signal (SIGILL, delete_socket); - signal (SIGTRAP, delete_socket); -#ifdef SIGABRT - signal (SIGABRT, delete_socket); -#endif -#ifdef SIGHWE - signal (SIGHWE, delete_socket); -#endif -#ifdef SIGPRE - signal (SIGPRE, delete_socket); -#endif -#ifdef SIGORE - signal (SIGORE, delete_socket); -#endif -#ifdef SIGUME - signal (SIGUME, delete_socket); -#endif -#ifdef SIGDLK - signal (SIGDLK, delete_socket); -#endif -#ifdef SIGCPULIM - signal (SIGCPULIM, delete_socket); -#endif -#ifdef SIGIOT - /* This is missing on some systems - OS/2, for example. */ - signal (SIGIOT, delete_socket); -#endif -#ifdef SIGEMT - signal (SIGEMT, delete_socket); -#endif - signal (SIGFPE, delete_socket); -#ifdef SIGBUS - signal (SIGBUS, delete_socket); -#endif - signal (SIGSEGV, delete_socket); -#ifdef SIGSYS - signal (SIGSYS, delete_socket); -#endif - signal (SIGTERM, delete_socket); -#ifdef SIGXCPU - signal (SIGXCPU, delete_socket); -#endif -#ifdef SIGXFSZ - signal (SIGXFSZ, delete_socket); -#endif /* SIGXFSZ */ - -#ifdef AIX -/* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */ - signal (SIGXCPU, delete_socket); -#ifndef _I386 - signal (SIGIOINT, delete_socket); -#endif - signal (SIGGRANT, delete_socket); - signal (SIGRETRACT, delete_socket); - signal (SIGSOUND, delete_socket); - signal (SIGMSG, delete_socket); -#endif /* AIX */ -} - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ -void -error (s1, s2) - char *s1, *s2; -{ - fprintf (stderr, "%s: ", progname); - fprintf (stderr, s1, s2); - fprintf (stderr, "\n"); -} - -/* Print error message and exit. */ -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -long * -xmalloc (size) - unsigned int size; -{ - long *result = (long *) malloc (size); - if (result == NULL) - fatal ("virtual memory exhausted", 0); - return result; -} - -int -main (argc, argv) - int argc; - char **argv; -{ - char system_name[32]; - int s, infd; - size_t fromlen; - struct sockaddr_un server, fromunix; - char *homedir; - char *str, string[BUFSIZ], code[BUFSIZ]; - FILE *infile; - FILE **openfiles; - int openfiles_size; - struct stat statbuf; - -#ifndef convex - char *getenv (); -#endif - - progname = argv[0]; - - openfiles_size = 20; - openfiles = (FILE **) malloc (openfiles_size * sizeof (FILE *)); - if (openfiles == 0) - abort (); - - /* - * Open up an AF_UNIX socket in this person's home directory - */ - - if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) - { - perror_1 ("socket"); - exit (1); - } - server.sun_family = AF_UNIX; -#ifndef SERVER_HOME_DIR - gethostname (system_name, sizeof (system_name)); - sprintf (server.sun_path, "/tmp/esrv%d-%s", geteuid (), system_name); - - if (unlink (server.sun_path) == -1 && errno != ENOENT) - { - perror_1 ("unlink"); - exit (1); - } -#else - if ((homedir = getenv ("HOME")) == NULL) - fatal_error ("No home directory\n"); - - strcpy (server.sun_path, homedir); - strcat (server.sun_path, "/.emacs-server-"); - gethostname (system_name, sizeof (system_name)); - strcat (server.sun_path, system_name); - /* Delete anyone else's old server. */ - unlink (server.sun_path); -#endif - - /* Save the socket name so we can delete it. */ - socket_name = (char *) xmalloc (strlen (server.sun_path) + 1); - strcpy (socket_name, server.sun_path); - - handle_signals (); - - if (bind (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0) - { - perror_1 ("bind"); - exit (1); - } - /* Only this user can send commands to this Emacs. */ - if (stat (server.sun_path, &statbuf) < 0) - { - perror_1 ("bind"); - exit (1); - } - - chmod (server.sun_path, statbuf.st_mode & 0600); - /* - * Now, just wait for everything to come in.. - */ - if (listen (s, 5) < 0) - { - perror_1 ("listen"); - exit (1); - } - - /* Disable sigpipes in case luser kills client... */ - signal (SIGPIPE, SIG_IGN); - for (;;) - { - SELECT_TYPE rmask; - FD_ZERO (&rmask); - FD_SET (0, &rmask); - FD_SET (s, &rmask); - if (select (s + 1, &rmask, 0, 0, 0) < 0) - perror_1 ("select"); - if (FD_ISSET (s, &rmask)) /* client sends list of filenames */ - { - fromlen = sizeof (fromunix); - fromunix.sun_family = AF_UNIX; - infd = accept (s, (struct sockaddr *) &fromunix, &fromlen); - if (infd < 0) - { - if (errno == EMFILE || errno == ENFILE) - fprintf (stderr, "Error: too many clients.\n"); - else - perror_1 ("accept"); - continue; - } - - if (infd >= openfiles_size) - { - openfiles_size *= 2; - openfiles = (FILE **) realloc (openfiles, - openfiles_size * sizeof (FILE *)); - if (openfiles == 0) - abort (); - } - - infile = fdopen (infd, "r+"); /* open stream */ - if (infile == NULL) - { - fprintf (stderr, "Error: too many clients.\n"); - write (infd, "Too many clients.\n", 18); - close (infd); /* Prevent descriptor leak.. */ - continue; - } - str = fgets (string, BUFSIZ, infile); - if (str == NULL) - { - perror_1 ("fgets"); - close (infd); /* Prevent descriptor leak.. */ - continue; - } - openfiles[infd] = infile; - printf ("Client: %d %s", infd, string); - /* If what we read did not end in a newline, - it means there is more. Keep reading from the socket - and outputting to Emacs, until we get the newline. */ - while (string[strlen (string) - 1] != '\n') - { - if (fgets (string, BUFSIZ, infile) == 0) - break; - printf ("%s", string); - } - fflush (stdout); - fflush (infile); - continue; - } - else if (FD_ISSET (0, &rmask)) /* emacs sends codeword, fd, and string message */ - { - /* Read command codeword and fd */ - clearerr (stdin); - scanf ("%s %d%*c", code, &infd); - if (ferror (stdin) || feof (stdin)) - fatal_error ("server: error reading from standard input\n"); - - /* Transfer text from Emacs to the client, up to a newline. */ - infile = openfiles[infd]; - rewind (infile); - while (1) - { - if (fgets (string, BUFSIZ, stdin) == 0) - break; - fprintf (infile, "%s", string); - if (string[strlen (string) - 1] == '\n') - break; - } - fflush (infile); - - /* If command is close, close connection to client. */ - if (strncmp (code, "Close:", 6) == 0) - if (infd > 2) - { - fclose (infile); - close (infd); - } - continue; - } - } -} - -#else /* This is the SYSV IPC section */ - -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/msg.h> -#include <setjmp.h> -#include <errno.h> -#include <sys/utsname.h> - -struct utsname system_name; - -#ifndef errno -extern int errno; -#endif - -jmp_buf msgenv; - -SIGTYPE -msgcatch () -{ - longjmp (msgenv, 1); -} - - -/* "THIS has to be fixed. Remember, stderr may not exist...-rlk." - Incorrect. This program runs as an inferior of Emacs. - Its stderr always exists--rms. */ -#include <stdio.h> - -main () -{ - int s, infd, fromlen, ioproc; - key_t key; - struct msgbuf * msgp = - (struct msgbuf *) malloc (sizeof *msgp + BUFSIZ); - struct msqid_ds msg_st; - int p; - char *homedir, *getenv (); - char string[BUFSIZ]; - FILE *infile; - - /* - * Create a message queue using ~/.emacs-server as the path for ftok - */ - if ((homedir = getenv ("HOME")) == NULL) - fatal_error ("No home directory\n"); - - strcpy (string, homedir); -#ifndef HAVE_LONG_FILE_NAMES - /* If file names are short, we can't fit the host name. */ - strcat (string, "/.emacs-server"); -#else - strcat (string, "/.emacs-server-"); - uname (&system_name); - strcat (string, system_name.nodename); -#endif - creat (string, 0600); - key = ftok (string, 1); /* unlikely to be anyone else using it */ - s = msgget (key, 0600 | IPC_CREAT); - if (s == -1) - { - perror_1 ("msgget"); - exit (1); - } - - /* Fork so we can close connection even if parent dies */ - p = fork (); - if (setjmp (msgenv)) - { - msgctl (s, IPC_RMID, 0); - if (p > 0) - kill (p, SIGKILL); - exit (0); - } - signal (SIGTERM, msgcatch); - signal (SIGINT, msgcatch); - signal (SIGHUP, msgcatch); - if (p > 0) - { - /* This is executed in the original process that did the fork above. */ - /* Get pid of Emacs itself. */ - p = getppid (); - setpgrp (); /* Gnu kills process group on exit */ - while (1) - { - /* Is Emacs still alive? */ - if (kill (p, 0) < 0) - { - msgctl (s, IPC_RMID, 0); - exit (0); - } - sleep (10); - } - } - - /* This is executed in the child made by forking above. - Call it c1. Make another process, ioproc. */ - - ioproc = fork (); - if (ioproc == 0) - { - /* In process ioproc, wait for text from Emacs, - and send it to the process c1. - This way, c1 only has to wait for one source of input. */ - while (fgets (msgp->mtext, BUFSIZ, stdin)) - { - msgp->mtype = 1; - msgsnd (s, msgp, strlen (msgp->mtext) + 1, 0); - } - exit (1); - } - - /* In the process c1, - listen for messages from clients and pass them to Emacs. */ - while (1) - { - if ((fromlen = msgrcv (s, msgp, BUFSIZ - 1, 1, 0)) < 0) - { -#ifdef EINTR - if (errno == EINTR) - continue; -#endif - perror_1 ("msgrcv"); - exit (1); - } - else - { - msgctl (s, IPC_STAT, &msg_st); - - /* Distinguish whether the message came from a client, or from - ioproc. */ - if (msg_st.msg_lspid == ioproc) - { - char code[BUFSIZ]; - int inproc; - - /* Message from ioproc: tell a client we are done. */ - msgp->mtext[strlen (msgp->mtext)-1] = 0; - sscanf (msgp->mtext, "%s %d", code, &inproc); - msgp->mtype = inproc; - msgsnd (s, msgp, strlen (msgp->mtext) + 1, 0); - continue; - } - - /* This is a request from a client: copy to stdout - so that Emacs will get it. Include msg_lspid - so server.el can tell us where to send the reply. */ - strncpy (string, msgp->mtext, fromlen); - string[fromlen] = 0; /* make sure */ - /* Newline is part of string.. */ - printf ("Client: %d %s", msg_st.msg_lspid, string); - fflush (stdout); - } - } -} - -#endif /* HAVE_SYSVIPC */ - -#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */ - -/* This is like perror but puts `Error: ' at the beginning. */ - -perror_1 (string) - char *string; -{ - char *copy = (char *) malloc (strlen (string) + 8); - if (copy == 0) - fatal_error ("Virtual memory exhausted"); - - strcpy (copy, "Error: "); - strcat (copy, string); - perror (copy); -} - -fatal_error (string) - char *string; -{ - fprintf (stderr, "%s", "Error: "); - fprintf (stderr, string); - exit (1); -} diff --git a/lib-src/emacstool.c b/lib-src/emacstool.c deleted file mode 100644 index a246e1faacb..00000000000 --- a/lib-src/emacstool.c +++ /dev/null @@ -1,500 +0,0 @@ -/* - Copyright (C) 1986, 1988, 1990, 1991 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* - * For Emacs in SunView/Sun-Windows: (supported by Sun Unix v3.2 or greater) - * Insert a notifier filter-function to convert all useful input - * to "key" sequences that emacs can understand. See: Emacstool(1). - * - * Author: Jeff Peck, Sun Microsystems, Inc. <peck@eng.sun.com> - * - * Original Idea: Ian Batten - * Updated 15-Mar-88, Jeff Peck: set IN_EMACSTOOL, TERM, TERMCAP - * Updated 10-Sep-88, Jeff Peck: add XVIEW and JLE support - * Updated 8-Oct-90, Jeff Peck: add Meta-bit for Xview - * Updated 6-Mar-91, Jeff Peck: Hack to detect -Wt invocation - * [note, TTYSW limitation means you must Click-To-Type in Openwin] - * [fixed in OW3 or use local/tty.o] - * for better results, this should move to using TERMSW. - * Updated 10-Mar-91, Jeff Peck, et al: support for TERMSW (TTERM) - * allows point-to-type even in OW2 - * - * [note: xvetool should be started with the "-nw" flag for emacs!] - */ - -#ifdef XVIEW -#include <xview/xview.h> -#include <xview/panel.h> -#include <xview/attr.h> -#include <xview/tty.h> -#include <xview/ttysw.h> /* private defines */ -#include <xview/termsw.h> /* -DTTERM */ -#include <xview/font.h> /* for testing */ -#else -#include <suntool/sunview.h> -#include <suntool/tty.h> -#include <suntool/ttysw.h> -#endif XVIEW - -#ifdef JLE -# include <locale.h> -#endif JLE - -#include <stdio.h> -#include <sys/file.h> - -#define BUFFER_SIZE 128 /* Size of all the buffers */ - -/* define WANT_CAPS_LOCK to make f-key T1 (aka F1) behave as CapsLock */ -#define WANT_CAPS_LOCK -#ifdef WANT_CAPS_LOCK -int caps_lock; /* toggle indicator for f-key T1 caps lock */ -static char *Caps = "[CAPS] "; /* Caps Lock prefix string */ -#define CAPS_LEN 7 /* strlen (Caps) */ -#endif - -static char *mouse_prefix = "\030\000"; /* C-x C-@ */ -static int m_prefix_length = 2; /* mouse_prefix length */ - -static char *key_prefix = "\030*"; /* C-x * */ -static int k_prefix_length = 2; /* key_prefix length */ - -#ifdef JLE -static char *emacs_name = "nemacs"; /* default run command */ -static char *title = "NEmacstool - "; /* initial title */ -#else -static char *emacs_name = "emacs"; /* default run command */ -static char *title = "Emacstool - "; /* initial title */ -#endif JLE - -static char buffer[BUFFER_SIZE]; /* send to ttysw_input */ -static char *bold_name = 0; /* for -bold option */ - -Frame frame; /* Base frame for system */ - -#ifndef TTERM -#define SWTYPE TTY -Tty tty_win; /* Where emacs is reading */ -#else -#define SWTYPE TERMSW -Termsw tty_win; /* Termsw does follow-mouse */ -#endif TTERM - -#ifdef XVIEW -Xv_Window tty_view; /* Where the events are in Xview*/ -#else -Tty tty_view; /* SunView place filler */ -#endif XVIEW - -int font_width, font_height; /* For translating pixels to chars */ -int left_margin = 0; /* default window -- frame offset */ - -int console_fd = 0; /* for debugging: setenv DEBUGEMACSTOOL */ -FILE *console; /* for debugging: setenv DEBUGEMACSTOOL */ - -Icon frame_icon; -/* make an icon_image for the default frame_icon */ -static short default_image[258] = -{ -#include <images/terminal.icon> -}; -mpr_static(icon_image, 64, 64, 1, default_image); - -/* - * Assign a value to a set of keys - */ -int -button_value (event) - Event *event; -{ - int retval = 0; - /* - * Code up the current situation: - * - * 1 = MS_LEFT; - * 2 = MS_MIDDLE; - * 4 = MS_RIGHT; - * 8 = SHIFT; - * 16 = CONTROL; - * 32 = META; - * 64 = DOUBLE; - * 128 = UP; - */ - - if (MS_LEFT == (event_id (event))) retval = 1; - if (MS_MIDDLE == (event_id (event))) retval = 2; - if (MS_RIGHT == (event_id (event))) retval = 4; - - if (event_shift_is_down (event)) retval += 8; - if (event_ctrl_is_down (event)) retval += 16; - if (event_meta_is_down (event)) retval += 32; - if (event_is_up (event)) retval += 128; - return retval; -} - -/* - * Variables to store the time of the previous mouse event that was - * sent to emacs. - * - * The theory is that to time double clicks while ignoring UP buttons, - * we must keep track of the accumulated time. - * - * If someone writes a SUN-SET-INPUT-MASK for emacstool, - * That could be used to selectively disable UP events, - * and then this cruft wouldn't be necessary. - */ -static long prev_event_sec = 0; -static long prev_event_usec = 0; - -/* - * Give the time difference in milliseconds, where one second - * is considered infinite. - */ -int -time_delta (now_sec, now_usec, prev_sec, prev_usec) - long now_sec, now_usec, prev_sec, prev_usec; -{ - long sec_delta = now_sec - prev_sec; - long usec_delta = now_usec - prev_usec; - - if (usec_delta < 0) { /* "borrow" a second */ - usec_delta += 1000000; - --sec_delta; - } - - if (sec_delta >= 10) - return (9999); /* Infinity */ - else - return ((sec_delta * 1000) + (usec_delta / 1000)); -} - - -/* - * Filter function to translate selected input events for emacs - * Mouse button events become ^X^@(button x-col y-line time-delta) . - * Function keys: ESC-*{c}{lrt} l,r,t for Left, Right, Top; - * {c} encodes the keynumber as a character [a-o] - */ -static Notify_value -input_event_filter_function (window, event, arg, type) -#ifdef XVIEW - Xv_Window window; -#else - Window window; -#endif XVIEW - Event *event; - Notify_arg arg; - Notify_event_type type; -{ - struct timeval time_stamp; - - if (console_fd) fprintf(console, "Event: %d\n", event_id(event)); - - /* UP L1 is the STOP key */ - if (event_id(event) == WIN_STOP) { - ttysw_input(tty_win, "\007\007\007\007\007\007\007", 7); - return NOTIFY_IGNORED; - } - - /* UP L5 & L7 is Expose & Open, let them pass to sunview */ - if (event_id(event) == KEY_LEFT(5) || event_id(event) == KEY_LEFT(7)) - if(event_is_up (event)) - return notify_next_event_func (window, event, arg, type); - else return NOTIFY_IGNORED; - - if (event_is_button (event)) { /* do Mouse Button events */ -/* Commented out so that we send mouse up events too. - if (event_is_up (event)) - return notify_next_event_func (window, event, arg, type); -*/ - time_stamp = event_time (event); - ttysw_input (tty_win, mouse_prefix, m_prefix_length); - sprintf (buffer, "(%d %d %d %d)\015", - button_value (event), - (event_x (event) - left_margin) / font_width, - event_y (event) / font_height, - time_delta (time_stamp.tv_sec, time_stamp.tv_usec, - prev_event_sec, prev_event_usec) - ); - ttysw_input (tty_win, buffer, strlen(buffer)); - prev_event_sec = time_stamp.tv_sec; - prev_event_usec = time_stamp.tv_usec; - return NOTIFY_IGNORED; - } - - { /* Do the function key events */ - int d; - char c = (char) 0; - if ((event_is_key_left (event)) ? - ((d = event_id(event) - KEY_LEFT(1) + 'a'), c='l') : - ((event_is_key_right (event)) ? - ((d = event_id(event) - KEY_RIGHT(1) + 'a'), c='r') : - ((event_is_key_top (event)) ? - ((d = event_id(event) - KEY_TOP(1) + 'a'), c='t') : 0))) - { - if (event_is_up(event)) return NOTIFY_IGNORED; - if (event_shift_is_down (event)) c = c - 32; - /* this will give a non-{lrt} for unshifted keys */ - if (event_ctrl_is_down (event)) c = c - 64; - if (event_meta_is_down (event)) c = c + 128; -#ifdef WANT_CAPS_LOCK -/* set a toggle and relabel window so T1 can act like caps-lock */ - if (event_id(event) == KEY_TOP(1)) - { - /* make a frame label with and without CAPS */ - strcpy (buffer, Caps); - title = &buffer[CAPS_LEN]; - strncpy (title, (char *)window_get (frame, FRAME_LABEL), - BUFFER_SIZE - CAPS_LEN); - buffer[BUFFER_SIZE] = (char) 0; - if (strncmp (title, Caps, CAPS_LEN) == 0) - title += CAPS_LEN; /* already Caps */ - caps_lock = (caps_lock ? 0 : CAPS_LEN); - window_set(frame, FRAME_LABEL, (title -= caps_lock), 0); - return NOTIFY_IGNORED; - } -#endif - ttysw_input (tty_win, key_prefix, k_prefix_length); - sprintf (buffer, "%c%c", d, c); - ttysw_input(tty_win, buffer, strlen(buffer)); - - return NOTIFY_IGNORED; - } - } - if ((event_is_ascii(event) || event_is_meta(event)) - && event_is_up(event)) return NOTIFY_IGNORED; -#ifdef WANT_CAPS_LOCK -/* shift alpha chars to upper case if toggle is set */ - if ((caps_lock) && event_is_ascii(event) - && (event_id(event) >= 'a') && (event_id(event) <= 'z')) - event_set_id(event, (event_id(event) - 32)); -/* crufty, but it works for now. is there an UPCASE(event)? */ -#endif -#ifndef NO_META_BIT -/* under Openwindows/X, the meta bit is not set in the key event, - * emacs expects this so we add it in here: - */ - if (event_is_ascii(event) && event_meta_is_down(event)) - event_set_id(event, 128 | event_id(event)); -#endif - return notify_next_event_func (window, event, arg, type); -} - -main (argc, argv) - int argc; - char **argv; -{ - int error_code; /* Error codes */ - -#ifdef JLE - setlocale(LC_ALL, ""); -#endif JLE - - if(getenv("DEBUGEMACSTOOL")) - console = fdopen (console_fd = open("/dev/console",O_WRONLY), "w"); - - putenv("IN_EMACSTOOL=t"); /* notify subprocess that it is in emacstool */ - - if (putenv("TERM=sun") != 0) /* TTY_WIN will be a TERM=sun window */ - {fprintf (stderr, "%s: Could not set TERM=sun, using `%s'\n", - argv[0], (char *)getenv("TERM")) ;}; - /* - * If TERMCAP starts with a slash, it is the pathname of the - * termcap file, not an entry extracted from it, so KEEP it! - * Otherwise, it may not relate to the new TERM, so Nuke-It. - * If there is no TERMCAP environment variable, don't make one. - */ - { - char *termcap ; /* Current TERMCAP value */ - termcap = (char *)getenv("TERMCAP") ; - if (termcap && (*termcap != '/')) - { - if (putenv("TERMCAP=") != 0) - {fprintf (stderr, "%s: Could not clear TERMCAP\n", argv[0]) ;} ; - } ; - } ; - - /* find command to run as subprocess in window */ - if (!(argv[0] = (char *)getenv("EMACSTOOL"))) /* Set emacs command name */ - argv[0] = emacs_name; - /* Emacstool recognizes two special args: -rc <file> and -bold <bold-name> */ - for (argc = 1; argv[argc]; argc++) /* Use last one on line */ - { - if(!(strcmp ("-rc", argv[argc]))) /* Override if -rc given */ - {int i = argc; - argv[argc--]=0; /* kill the -rc argument */ - if (argv[i+1]) { /* move to argv[0] and squeeze the rest */ - argv[0]=argv[i+1]; - for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0)); - } - } - - if (!(strcmp ("-bold", argv[argc]))) - {int i = argc; - argv[argc--]=0; /* kill the -bold argument */ - if (argv[i+1]) { /* move to bold_name and squeeze the rest */ - bold_name = argv[i+1]; - for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0)); - } - } - }; - - strcpy (buffer, title); - strncat (buffer, argv[0], /* append run command name */ - (BUFFER_SIZE - (strlen (buffer)) - (strlen (argv[0]))) - 1); - - error_code = interpose_on_window(argc,argv); - if (error_code != 0) { /* Barf */ - fprintf (stderr, "notify_interpose_event_func returns %d.\n", error_code); - exit (1); - } - -#ifdef XVIEW - xv_main_loop (frame); /* And away we go */ -#else - window_main_loop (frame); -#endif XVIEW -} - -#ifdef XVIEW -int interpose_on_window(argc,argv) - int argc; - char **argv; -{ -#ifndef TTERM - int i, font_width_adjust = 1; /* hackery, and heuristics */ - /* if -Wt is not supplied, then font comes out as lucida-14 (width=8) - * rather than the screen.r.12 (width=7) typically used - * this hack attempts to workaround it. - * could use a env var EMACSTOOL_DEFAULT_FONT_WIDTH instead */ - for (i = 1; argv[i]; i++) { - if (!(strcmp ("-Wt", argv[i]))) - {font_width_adjust = 0; - if (console_fd) fprintf(console, "-Wt = %d\n", font_width_adjust); - break;} - } -#endif TTERM - /* initialize Xview, and strip window args */ - xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0); - - /* do this first, so arglist can override it */ - frame_icon = icon_create (ICON_LABEL, "Emacstool", - ICON_IMAGE, &icon_image, - 0); - - /* Build a frame to run in */ - frame = xv_create ((Xv_Window)NULL, FRAME, - FRAME_LABEL, buffer, - FRAME_ICON, frame_icon, - 0); - - /* Create a tty with emacs in it */ - tty_win = xv_create (frame, SWTYPE, WIN_IS_CLIENT_PANE, - TTY_QUIT_ON_CHILD_DEATH, TRUE, - TTY_BOLDSTYLE, TTYSW_BOLD_INVERT, - TTY_ARGV, argv, - 0); - - if (bold_name) { - (void)xv_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0); - } - - { - Xv_font font; /* declare temp font variable */ - font = (Xv_font)xv_get (tty_win, XV_FONT); - font_height = (int)xv_get (font, FONT_DEFAULT_CHAR_HEIGHT); - font_width = (int)xv_get (font, FONT_DEFAULT_CHAR_WIDTH); - } - if (console_fd) fprintf(console, "Width = %d\n", font_width); - -#ifndef TTERM - font_width -= font_width_adjust; /* A guess! font bug in ttysw*/ -#else - /* make the termsw act as a tty */ - xv_set(tty_win, TERMSW_MODE, TTYSW_MODE_TYPE, 0); - /* termsw has variable offset depending on scrollbar size/location */ - left_margin = (int)xv_get (tty_win, TEXTSW_LEFT_MARGIN); -#endif TTERM - - tty_view = (Xv_Window) xv_get (tty_win, OPENWIN_NTH_VIEW, 0); - xv_set(tty_view, - WIN_CONSUME_EVENTS, - WIN_MOUSE_BUTTONS, WIN_UP_EVENTS, - ACTION_ADJUST, ACTION_MENU, - WIN_ASCII_EVENTS, - WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, - 0, - 0); - /* Interpose my event function */ - return (int) notify_interpose_event_func - (tty_view, input_event_filter_function, NOTIFY_SAFE); -} -#else -int interpose_on_window (argc, argv) - int argc; - char **argv; -{ - /* do this first, so arglist can override it */ - frame_icon = icon_create (ICON_LABEL, "Emacstool", - ICON_IMAGE, &icon_image, - 0); - - /* Build a frame to run in */ - frame = window_create ((Window)NULL, FRAME, - FRAME_LABEL, buffer, - FRAME_ICON, frame_icon, - FRAME_ARGC_PTR_ARGV, &argc, argv, - 0); - - /* Create a tty with emacs in it */ - tty_win = window_create (frame, TTY, - TTY_QUIT_ON_CHILD_DEATH, TRUE, - TTY_BOLDSTYLE, TTYSW_BOLD_INVERT, - TTY_ARGV, argv, - 0); - - if (bold_name) { - (void)window_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0); - } - - /* ttysw uses pf_default, one must set WIN_FONT explicitly */ - window_set (tty_win, WIN_FONT, pf_default(), 0); - font_height = (int)window_get (tty_win, WIN_ROW_HEIGHT); - font_width = (int)window_get (tty_win, WIN_COLUMN_WIDTH); - - tty_view = tty_win; - window_set(tty_view, - WIN_CONSUME_PICK_EVENTS, - WIN_STOP, - WIN_MOUSE_BUTTONS, WIN_UP_EVENTS, - /* LOC_WINENTER, LOC_WINEXIT, LOC_MOVE, */ - 0, - WIN_CONSUME_KBD_EVENTS, - WIN_STOP, - WIN_ASCII_EVENTS, - WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, - /* WIN_UP_ASCII_EVENTS, */ - 0, - 0); - /* Interpose my event function */ - return (int) notify_interpose_event_func - (tty_view, input_event_filter_function, NOTIFY_SAFE); -} -#endif XVIEW diff --git a/lib-src/env.c b/lib-src/env.c deleted file mode 100644 index 2ae81a630b8..00000000000 --- a/lib-src/env.c +++ /dev/null @@ -1,353 +0,0 @@ -/* env - manipulate environment and execute a program in that environment - Copyright (C) 1986, 1994 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Mly 861126 */ - -/* If first argument is "-", then a new environment is constructed - from scratch; otherwise the environment is inherited from the parent - process, except as modified by other options. - - So, "env - foo" will invoke the "foo" program in a null environment, - whereas "env foo" would invoke "foo" in the same environment as that - passed to "env" itself. - - Subsequent arguments are interpreted as follows: - - * "variable=value" (i.e., an arg containing a "=" character) - means to set the specified environment variable to that value. - `value' may be of zero length ("variable="). Note that setting - a variable to a zero-length value is different from unsetting it. - - * "-u variable" or "-unset variable" - means to unset that variable. - If that variable isn't set, does nothing. - - * "-s variable value" or "-set variable value" - same as "variable=value". - - * "-" or "--" - are used to indicate that the following argument is the program - to invoke. This is only necessary when the program's name - begins with "-" or contains a "=". - - * anything else - The first remaining argument specifies a program to invoke - (it is searched for according to the specification of the PATH - environment variable) and any arguments following that are - passed as arguments to that program. - - If no program-name is specified following the environment - specifications, the resulting environment is printed. - This is like specifying a program-name of "printenv". - - Examples: - If the environment passed to "env" is - { USER=rms EDITOR=emacs PATH=.:/gnubin:/hacks } - - * "env DISPLAY=gnu:0 nemacs" - calls "nemacs" in the environment - { USER=rms EDITOR=emacs PATH=.:/gnubin:/hacks DISPLAY=gnu:0 } - - * "env - USER=foo /hacks/hack bar baz" - calls the "hack" program on arguments "bar" and "baz" - in an environment in which the only variable is "USER". - Note that the "-" option clears out the PATH variable, - so one should be careful to specify in which directory - to find the program to call. - - * "env -u EDITOR USER=foo PATH=/energy -- e=mc2 bar baz" - The program "/energy/e=mc2" is called with environment - { USER=foo PATH=/energy } -*/ - -#ifdef EMACS -#define NO_SHORTNAMES -#include "../src/config.h" -#endif /* EMACS */ - -#include <stdio.h> - -extern int execvp (); - -char *xmalloc (), *xrealloc (); -char *concat (); - -extern char **environ; - -char **nenv; -int nenv_size; - -char *progname; -void setenv (); -void fatal (); -char *myindex (); - -extern char *strerror (); - - -main (argc, argv, envp) - register int argc; - register char **argv; - char **envp; -{ - register char *tem; - - progname = argv[0]; - argc--; - argv++; - - nenv_size = 100; - nenv = (char **) xmalloc (nenv_size * sizeof (char *)); - *nenv = (char *) 0; - - /* "-" flag means to not inherit parent's environment */ - if (argc && !strcmp (*argv, "-")) - { - argc--; - argv++; - } - else - /* Else pass on existing env vars. */ - for (; *envp; envp++) - { - tem = myindex (*envp, '='); - if (tem) - { - *tem = '\000'; - setenv (*envp, tem + 1); - } - } - - while (argc > 0) - { - tem = myindex (*argv, '='); - if (tem) - /* If arg contains a "=" it specifies to set a variable */ - { - *tem = '\000'; - setenv (*argv, tem + 1); - argc--; - argv++; - continue; - } - - if (**argv != '-') - /* Remaining args are program name and args to pass it */ - break; - - if (argc < 2) - fatal ("no argument for `%s' option", *argv); - if (!strcmp (*argv, "-u") - || !strcmp (*argv, "-unset")) - /* Unset a variable */ - { - argc--; - argv++; - setenv (*argv, (char *) 0); - argc--; - argv++; - } - else if (!strcmp (*argv, "-s") || - !strcmp (*argv, "-set")) - /* Set a variable */ - { - argc--; - argv++; - tem = *argv; - if (argc < 2) - fatal ("no value specified for variable \"%s\"", tem); - argc--; - argv++; - setenv (tem, *argv); - argc--; - argv++; - } - else if (!strcmp (*argv, "-") || !strcmp (*argv, "--")) - { - argc--; - argv++; - break; - } - else - { - fatal ("unrecognized option `%s'", *argv); - } - } - - /* If no program specified print the environment and exit */ - if (argc <= 0) - { - while (*nenv) - printf ("%s\n", *nenv++); - exit (0); - } - else - { - extern int errno; - extern char *strerror (); - - environ = nenv; - (void) execvp (*argv, argv); - - fprintf (stderr, "%s: cannot execute `%s': %s\n", - progname, *argv, strerror (errno)); - exit (errno != 0 ? errno : 1); - } -} - -void -setenv (var, val) - register char *var, *val; -{ - register char **e; - int len = strlen (var); - - { - register char *tem = myindex (var, '='); - if (tem) - fatal ("environment variable names can not contain `=': %s", var); - else if (*var == '\000') - fatal ("zero-length environment variable name specified"); - } - - for (e = nenv; *e; e++) - if (!strncmp (var, *e, len) && (*e)[len] == '=') - { - if (val) - goto set; - else - do - { - *e = *(e + 1); - } while (*e++); - return; - } - - if (!val) - return; /* Nothing to unset */ - - len = e - nenv; - if (len + 1 >= nenv_size) - { - nenv_size += 100; - nenv = (char **) xrealloc (nenv, nenv_size * sizeof (char *)); - e = nenv + len; - } - -set: - val = concat (var, "=", val); - if (*e) - free (*e); - else - *(e + 1) = (char *) 0; - *e = val; - return; -} - -void -fatal (msg, arg1, arg2) - char *msg, *arg1, *arg2; -{ - fprintf (stderr, "%s: ", progname); - fprintf (stderr, msg, arg1, arg2); - putc ('\n', stderr); - exit (1); -} - - -extern char *malloc (), *realloc (); - -void -memory_fatal () -{ - fatal ("virtual memory exhausted"); -} - -char * -xmalloc (size) - int size; -{ - register char *value; - value = (char *) malloc (size); - if (!value) - memory_fatal (); - return (value); -} - -char * -xrealloc (ptr, size) - char *ptr; - int size; -{ - register char *value; - value = (char *) realloc (ptr, size); - if (!value) - memory_fatal (); - return (value); -} - -/* Return a newly-allocated string whose contents concatenate - those of S1, S2, S3. */ - -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = (char *) xmalloc (len1 + len2 + len3 + 1); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - result[len1 + len2 + len3] = 0; - - return result; -} - -/* Return a pointer to the first occurrence in STR of C, - or 0 if C does not occur. */ - -char * -myindex (str, c) - char *str; - char c; -{ - char *s = str; - - while (*s) - { - if (*s == c) - return s; - s++; - } - return 0; -} - -#ifndef HAVE_STRERROR -char * -strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum >= 0 && errnum < sys_nerr) - return sys_errlist[errnum]; - return (char *) "Unknown error"; -} - -#endif /* ! HAVE_STRERROR */ diff --git a/lib-src/etags.c b/lib-src/etags.c deleted file mode 100644 index 0120226b38c..00000000000 --- a/lib-src/etags.c +++ /dev/null @@ -1,4577 +0,0 @@ -/* Tags file maker to go with GNU Emacs - Copyright (C) 1984, 87, 88, 89, 93, 94, 95 - Free Software Foundation, Inc. and Ken Arnold - -This file is not considered part of GNU Emacs. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, -Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* - * Authors: - * Ctags originally by Ken Arnold. - * Fortran added by Jim Kleckner. - * Ed Pelegri-Llopart added C typedefs. - * Gnu Emacs TAGS format and modifications by RMS? - * Sam Kendall added C++. - * Francesco Potorti` reorganised C and C++ based on work by Joe Wells. - * Regexp tags by Tom Tromey. - * - * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer. - */ - -char pot_etags_version[] = "@(#) pot revision number is 11.80"; - -#define TRUE 1 -#define FALSE 0 - -#ifndef DEBUG -# define DEBUG FALSE -#endif - -#ifdef MSDOS -# include <string.h> -# include <fcntl.h> -# include <sys/param.h> -#endif /* MSDOS */ - -#ifdef WINDOWSNT -# include <stdlib.h> -# include <fcntl.h> -# include <string.h> -# include <io.h> -# define MAXPATHLEN _MAX_PATH -#endif - -#if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS) -#include <stdlib.h> -#include <string.h> -#endif - -#ifdef HAVE_CONFIG_H -# include <config.h> - /* On some systems, Emacs defines static as nothing for the sake - of unexec. We don't want that here since we don't use unexec. */ -# undef static -#endif - -#include <stdio.h> -#include <ctype.h> -#include <errno.h> -#ifndef errno -extern int errno; -#endif -#include <sys/types.h> -#include <sys/stat.h> - -#if !defined (S_ISREG) && defined (S_IFREG) -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif - -#include <getopt.h> - -#ifdef ETAGS_REGEXPS -# include <regex.h> -#endif /* ETAGS_REGEXPS */ - -/* Define CTAGS to make the program "ctags" compatible with the usual one. - Let it undefined to make the program "etags", which makes emacs-style - tag tables and tags typedefs, #defines and struct/union/enum by default. */ -#ifdef CTAGS -# undef CTAGS -# define CTAGS TRUE -#else -# define CTAGS FALSE -#endif - -/* Exit codes for success and failure. */ -#ifdef VMS -# define GOOD 1 -# define BAD 0 -#else -# define GOOD 0 -# define BAD 1 -#endif - -/* C extensions. */ -#define C_PLPL 0x00001 /* C++ */ -#define C_STAR 0x00003 /* C* */ -#define YACC 0x10000 /* yacc file */ - -#define streq(s,t) ((DEBUG && (s) == NULL && (t) == NULL \ - && (abort (), 1)) || !strcmp (s, t)) -#define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \ - && (abort (), 1)) || !strncmp (s, t, n)) - -#define lowcase(c) tolower ((char)c) - -#define iswhite(arg) (_wht[arg]) /* T if char is white */ -#define begtoken(arg) (_btk[arg]) /* T if char can start token */ -#define intoken(arg) (_itk[arg]) /* T if char can be in token */ -#define endtoken(arg) (_etk[arg]) /* T if char ends tokens */ - -#ifdef DOS_NT -# define absolutefn(fn) (fn[0] == '/' \ - || (fn[1] == ':' && fn[2] == '/')) -#else -# define absolutefn(fn) (fn[0] == '/') -#endif - - -/* - * xnew -- allocate storage - * - * SYNOPSIS: Type *xnew (int n, Type); - */ -#define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) - -typedef int logical; - -typedef struct nd_st -{ /* sorting structure */ - char *name; /* function or type name */ - char *file; /* file name */ - logical is_func; /* use pattern or line no */ - logical been_warned; /* set if noticed dup */ - int lno; /* line number tag is on */ - long cno; /* character number line starts on */ - char *pat; /* search pattern */ - struct nd_st *left, *right; /* left and right sons */ -} NODE; - -extern char *getenv (); - -char *concat (); -char *savenstr (), *savestr (); -char *etags_strchr (), *etags_strrchr (); -char *etags_getcwd (); -char *relative_filename (), *absolute_filename (), *absolute_dirname (); -void grow_linebuffer (); -long *xmalloc (), *xrealloc (); - -typedef void Lang_function (); -#if FALSE /* many compilers barf on this */ -Lang_function Asm_labels; -Lang_function default_C_entries; -Lang_function C_entries; -Lang_function Cplusplus_entries; -Lang_function Cstar_entries; -Lang_function Erlang_functions; -Lang_function Fortran_functions; -Lang_function Yacc_entries; -Lang_function Lisp_functions; -Lang_function Pascal_functions; -Lang_function Perl_functions; -Lang_function Prolog_functions; -Lang_function Scheme_functions; -Lang_function TeX_functions; -Lang_function just_read_file; -#else /* so let's write it this way */ -void Asm_labels (); -void C_entries (); -void default_C_entries (); -void plain_C_entries (); -void Cplusplus_entries (); -void Cstar_entries (); -void Erlang_functions (); -void Fortran_functions (); -void Yacc_entries (); -void Lisp_functions (); -void Pascal_functions (); -void Perl_functions (); -void Prolog_functions (); -void Scheme_functions (); -void TeX_functions (); -void just_read_file (); -#endif - -Lang_function *get_language_from_name (); -Lang_function *get_language_from_interpreter (); -Lang_function *get_language_from_suffix (); -int total_size_of_entries (); -long readline (); -long readline_internal (); -#ifdef ETAGS_REGEXPS -void add_regex (); -#endif -void add_node (); -void error (); -void suggest_asking_for_help (); -void fatal (), pfatal (); -void find_entries (); -void free_tree (); -void getit (); -void init (); -void initbuffer (); -void pfnote (); -void process_file (); -void put_entries (); -void takeprec (); - - -char searchar = '/'; /* use /.../ searches */ - -int lineno; /* line number of current line */ -long charno; /* current character number */ -long linecharno; /* charno of start of line */ - -char *curfile; /* current input file name */ -char *tagfile; /* output file */ -char *progname; /* name this program was invoked with */ -char *cwd; /* current working directory */ -char *tagfiledir; /* directory of tagfile */ - -FILE *tagf; /* ioptr for tags file */ -NODE *head; /* the head of the binary tree of tags */ - -/* - * A `struct linebuffer' is a structure which holds a line of text. - * `readline' reads a line from a stream into a linebuffer and works - * regardless of the length of the line. - */ -struct linebuffer -{ - long size; - char *buffer; -}; - -struct linebuffer lb; /* the current line */ -struct linebuffer token_name; /* used by C_entries as a temporary area */ -struct -{ - long linepos; - struct linebuffer lb; /* used by C_entries instead of lb */ -} lbs[2]; - -/* boolean "functions" (see init) */ -logical _wht[0177], _etk[0177], _itk[0177], _btk[0177]; -char - /* white chars */ - *white = " \f\t\n\013", - /* token ending chars */ - *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", - /* token starting chars */ - *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@", - /* valid in-token chars */ - *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789"; - -logical append_to_tagfile; /* -a: append to tags */ -/* The following three default to TRUE for etags, but to FALSE for ctags. */ -logical typedefs; /* -t: create tags for typedefs */ -logical typedefs_and_cplusplus; /* -T: create tags for typedefs, level */ - /* 0 struct/enum/union decls, and C++ */ - /* member functions. */ -logical constantypedefs; /* -d: create tags for C #define and enum */ - /* constants. */ - /* -D: opposite of -d. Default under ctags. */ -logical update; /* -u: update tags */ -logical vgrind_style; /* -v: create vgrind style index output */ -logical no_warnings; /* -w: suppress warnings */ -logical cxref_style; /* -x: create cxref style output */ -logical cplusplus; /* .[hc] means C++, not C */ -logical noindentypedefs; /* -I: ignore indentation in C */ - -struct option longopts[] = -{ - { "append", no_argument, NULL, 'a' }, - { "backward-search", no_argument, NULL, 'B' }, - { "c++", no_argument, NULL, 'C' }, - { "cxref", no_argument, NULL, 'x' }, - { "defines", no_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "help", no_argument, NULL, 'H' }, - { "ignore-indentation", no_argument, NULL, 'I' }, - { "include", required_argument, NULL, 'i' }, - { "language", required_argument, NULL, 'l' }, - { "no-defines", no_argument, NULL, 'D' }, - { "no-regex", no_argument, NULL, 'R' }, - { "no-warn", no_argument, NULL, 'w' }, - { "output", required_argument, NULL, 'o' }, - { "regex", required_argument, NULL, 'r' }, - { "typedefs", no_argument, NULL, 't' }, - { "typedefs-and-c++", no_argument, NULL, 'T' }, - { "update", no_argument, NULL, 'u' }, - { "version", no_argument, NULL, 'V' }, - { "vgrind", no_argument, NULL, 'v' }, - { 0 } -}; - -#ifdef ETAGS_REGEXPS -/* Structure defining a regular expression. Elements are - the compiled pattern, and the name string. */ -struct pattern -{ - struct re_pattern_buffer *pattern; - struct re_registers regs; - char *name_pattern; - logical error_signaled; -}; - -/* Number of regexps found. */ -int num_patterns = 0; - -/* Array of all regexps. */ -struct pattern *patterns = NULL; -#endif /* ETAGS_REGEXPS */ - -/* - * Language stuff. - */ - -/* Non-NULL if language fixed. */ -Lang_function *lang_func = NULL; - -/* Assembly code */ -char *Asm_suffixes [] = { "a", /* Unix assembler */ - "asm", /* Microcontroller assembly */ - "def", /* BSO/Tasking definition includes */ - "inc", /* Microcontroller include files */ - "ins", /* Microcontroller include files */ - "s", "sa", /* Unix assembler */ - "src", /* BSO/Tasking C compiler output */ - NULL - }; - -/* Note that .c and .h can be considered C++, if the --c++ flag was - given. That is why default_C_entries is called here. */ -char *default_C_suffixes [] = - { "c", "h", NULL }; - -/* .M is for Objective C++ files. */ -char *Cplusplus_suffixes [] = - { "C", "H", "c++", "cc", "cpp", "cxx", "h++", "hh", "hpp", "hxx", "M", NULL}; - -char *Cstar_suffixes [] = - { "cs", "hs", NULL }; - -char *Erlang_suffixes [] = - { "erl", "hrl", NULL }; - -char *Fortran_suffixes [] = - { "F", "f", "f90", "for", NULL }; - -char *Lisp_suffixes [] = - { "cl", "clisp", "el", "l", "lisp", "lsp", "ml", NULL }; - -char *Pascal_suffixes [] = - { "p", "pas", NULL }; - -char *Perl_suffixes [] = - { "pl", "pm", NULL }; -char *Perl_interpreters [] = - { "perl", "@PERL@", NULL }; - -char *plain_C_suffixes [] = - { "pc", /* Pro*C file */ - "m", /* Objective C file */ - "lm", /* Objective lex file */ - NULL }; - -char *Prolog_suffixes [] = - { "prolog", NULL }; - -/* Can't do the `SCM' or `scm' prefix with a version number. */ -char *Scheme_suffixes [] = - { "SCM", "SM", "oak", "sch", "scheme", "scm", "sm", "t", NULL }; - -char *TeX_suffixes [] = - { "TeX", "bib", "clo", "cls", "ltx", "sty", "tex", NULL }; - -char *Yacc_suffixes [] = - { "y", "ym", NULL }; /* .ym is Objective yacc file */ - -/* Table of language names and corresponding functions, file suffixes - and interpreter names. - It is ok for a given function to be listed under more than one - name. I just didn't. */ -struct lang_entry -{ - char *name; - Lang_function *function; - char **suffixes; - char **interpreters; -}; - -struct lang_entry lang_names [] = -{ - { "asm", Asm_labels, Asm_suffixes, NULL }, - { "c", default_C_entries, default_C_suffixes, NULL }, - { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL }, - { "c*", Cstar_entries, Cstar_suffixes, NULL }, - { "erlang", Erlang_functions, Erlang_suffixes, NULL }, - { "fortran", Fortran_functions, Fortran_suffixes, NULL }, - { "lisp", Lisp_functions, Lisp_suffixes, NULL }, - { "pascal", Pascal_functions, Pascal_suffixes, NULL }, - { "perl", Perl_functions, Perl_suffixes, Perl_interpreters }, - { "proc", plain_C_entries, plain_C_suffixes, NULL }, - { "prolog", Prolog_functions, Prolog_suffixes, NULL }, - { "scheme", Scheme_functions, Scheme_suffixes, NULL }, - { "tex", TeX_functions, TeX_suffixes, NULL }, - { "yacc", Yacc_entries, Yacc_suffixes, NULL }, - { "auto", NULL }, /* default guessing scheme */ - { "none", just_read_file }, /* regexp matching only */ - { NULL, NULL } /* end of list */ -}; - - -void -print_language_names () -{ - struct lang_entry *lang; - char **ext; - - puts ("\nThese are the currently supported languages, along with the\n\ -default file name suffixes:"); - for (lang = lang_names; lang->name != NULL; lang++) - { - printf ("\t%s\t", lang->name); - if (lang->suffixes != NULL) - for (ext = lang->suffixes; *ext != NULL; ext++) - printf (" .%s", *ext); - puts (""); - } - puts ("Where `auto' means use default language for files based on file\n\ -name suffix, and `none' means only do regexp processing on files.\n\ -If no language is specified and no matching suffix is found,\n\ -the first line of the file is read for a sharp-bang (#!) sequence\n\ -followed by the name of an interpreter. If no such sequence is found,\n\ -Fortran is tried first; if no tags are found, C is tried next."); -} - -#ifndef VERSION -# define VERSION "19" -#endif -void -print_version () -{ - printf ("%s (GNU Emacs %s)\n", (CTAGS) ? "ctags" : "etags", VERSION); - puts ("Copyright (C) 1996 Free Software Foundation, Inc. and Ken Arnold"); - puts ("This program is distributed under the same terms as Emacs"); - - exit (GOOD); -} - -void -print_help () -{ - printf ("These are the options accepted by %s. You may use unambiguous\n\ -abbreviations for the long option names. A - as file name means read\n\ -names from stdin.", progname); - if (!CTAGS) - printf (" Absolute names are stored in the output file as they\n\ -are. Relative ones are stored relative to the output file's directory."); - puts ("\n"); - - puts ("-a, --append\n\ - Append tag entries to existing tags file."); - - if (CTAGS) - puts ("-B, --backward-search\n\ - Write the search commands for the tag entries using '?', the\n\ - backward-search command instead of '/', the forward-search command."); - - puts ("-C, --c++\n\ - Treat files whose name suffix defaults to C language as C++ files."); - - if (CTAGS) - puts ("-d, --defines\n\ - Create tag entries for C #define constants and enum constants, too."); - else - puts ("-D, --no-defines\n\ - Don't create tag entries for C #define constants and enum constants.\n\ - This makes the tags file smaller."); - - if (!CTAGS) - { - puts ("-i FILE, --include=FILE\n\ - Include a note in tag file indicating that, when searching for\n\ - a tag, one should also consult the tags file FILE after\n\ - checking the current file."); - puts ("-l LANG, --language=LANG\n\ - Force the following files to be considered as written in the\n\ - named language up to the next --language=LANG option."); - } - -#ifdef ETAGS_REGEXPS - puts ("-r /REGEXP/, --regex=/REGEXP/\n\ - Make a tag for each line matching pattern REGEXP in the\n\ - following files. REGEXP is anchored (as if preceded by ^).\n\ - The form /REGEXP/NAME/ creates a named tag. For example Tcl\n\ - named tags can be created with:\n\ - --regex=/proc[ \\t]+\\([^ \\t]+\\)/\\1/."); - puts ("-R, --no-regex\n\ - Don't create tags from regexps for the following files."); -#endif /* ETAGS_REGEXPS */ - puts ("-o FILE, --output=FILE\n\ - Write the tags to FILE."); - puts ("-I, --ignore-indentation\n\ - Don't rely on indentation quite as much as normal. Currently,\n\ - this means not to assume that a closing brace in the first\n\ - column is the final brace of a function or structure\n\ - definition in C and C++."); - - if (CTAGS) - { - puts ("-t, --typedefs\n\ - Generate tag entries for C typedefs."); - puts ("-T, --typedefs-and-c++\n\ - Generate tag entries for C typedefs, C struct/enum/union tags,\n\ - and C++ member functions."); - puts ("-u, --update\n\ - Update the tag entries for the given files, leaving tag\n\ - entries for other files in place. Currently, this is\n\ - implemented by deleting the existing entries for the given\n\ - files and then rewriting the new entries at the end of the\n\ - tags file. It is often faster to simply rebuild the entire\n\ - tag file than to use this."); - puts ("-v, --vgrind\n\ - Generates an index of items intended for human consumption,\n\ - similar to the output of vgrind. The index is sorted, and\n\ - gives the page number of each item."); - puts ("-w, --no-warn\n\ - Suppress warning messages about entries defined in multiple\n\ - files."); - puts ("-x, --cxref\n\ - Like --vgrind, but in the style of cxref, rather than vgrind.\n\ - The output uses line numbers instead of page numbers, but\n\ - beyond that the differences are cosmetic; try both to see\n\ - which you like."); - } - - puts ("-V, --version\n\ - Print the version of the program.\n\ --h, --help\n\ - Print this help message."); - - print_language_names (); - - puts (""); - puts ("Report bugs to bug-gnu-emacs@prep.ai.mit.edu"); - - exit (GOOD); -} - - -enum argument_type -{ - at_language, - at_regexp, - at_filename -}; - -/* This structure helps us allow mixing of --lang and filenames. */ -typedef struct -{ - enum argument_type arg_type; - char *what; - Lang_function *function; -} argument; - -#ifdef VMS /* VMS specific functions */ - -#define EOS '\0' - -/* This is a BUG! ANY arbitrary limit is a BUG! - Won't someone please fix this? */ -#define MAX_FILE_SPEC_LEN 255 -typedef struct { - short curlen; - char body[MAX_FILE_SPEC_LEN + 1]; -} vspec; - -/* - v1.05 nmm 26-Jun-86 fn_exp - expand specification of list of file names - returning in each successive call the next filename matching the input - spec. The function expects that each in_spec passed - to it will be processed to completion; in particular, up to and - including the call following that in which the last matching name - is returned, the function ignores the value of in_spec, and will - only start processing a new spec with the following call. - If an error occurs, on return out_spec contains the value - of in_spec when the error occurred. - - With each successive filename returned in out_spec, the - function's return value is one. When there are no more matching - names the function returns zero. If on the first call no file - matches in_spec, or there is any other error, -1 is returned. -*/ - -#include <rmsdef.h> -#include <descrip.h> -#define OUTSIZE MAX_FILE_SPEC_LEN -short -fn_exp (out, in) - vspec *out; - char *in; -{ - static long context = 0; - static struct dsc$descriptor_s o; - static struct dsc$descriptor_s i; - static logical pass1 = TRUE; - long status; - short retval; - - if (pass1) - { - pass1 = FALSE; - o.dsc$a_pointer = (char *) out; - o.dsc$w_length = (short)OUTSIZE; - i.dsc$a_pointer = in; - i.dsc$w_length = (short)strlen(in); - i.dsc$b_dtype = DSC$K_DTYPE_T; - i.dsc$b_class = DSC$K_CLASS_S; - o.dsc$b_dtype = DSC$K_DTYPE_VT; - o.dsc$b_class = DSC$K_CLASS_VS; - } - if ((status = lib$find_file(&i, &o, &context, 0, 0)) == RMS$_NORMAL) - { - out->body[out->curlen] = EOS; - return 1; - } - else if (status == RMS$_NMF) - retval = 0; - else - { - strcpy(out->body, in); - retval = -1; - } - lib$find_file_end(&context); - pass1 = TRUE; - return retval; -} - -/* - v1.01 nmm 19-Aug-85 gfnames - return in successive calls the - name of each file specified by the provided arg expanding wildcards. -*/ -char * -gfnames (arg, p_error) - char *arg; - logical *p_error; -{ - static vspec filename = {MAX_FILE_SPEC_LEN, "\0"}; - - switch (fn_exp (&filename, arg)) - { - case 1: - *p_error = FALSE; - return filename.body; - case 0: - *p_error = FALSE; - return NULL; - default: - *p_error = TRUE; - return filename.body; - } -} - -#ifndef OLD /* Newer versions of VMS do provide `system'. */ -system (cmd) - char *cmd; -{ - fprintf (stderr, "system() function not implemented under VMS\n"); -} -#endif - -#define VERSION_DELIM ';' -char *massage_name (s) - char *s; -{ - char *start = s; - - for ( ; *s; s++) - if (*s == VERSION_DELIM) - { - *s = EOS; - break; - } - else - *s = lowcase (*s); - return start; -} -#endif /* VMS */ - - -int -main (argc, argv) - int argc; - char *argv[]; -{ - int i; - unsigned int nincluded_files = 0; - char **included_files = xnew (argc, char *); - char *this_file; - argument *argbuffer; - int current_arg = 0, file_count = 0; - struct linebuffer filename_lb; -#ifdef VMS - logical got_err; -#endif - -#ifdef DOS_NT - _fmode = O_BINARY; /* all of files are treated as binary files */ -#endif /* DOS_NT */ - - progname = argv[0]; - - /* Allocate enough no matter what happens. Overkill, but each one - is small. */ - argbuffer = xnew (argc, argument); - -#ifdef ETAGS_REGEXPS - /* Set syntax for regular expression routines. */ - re_set_syntax (RE_SYNTAX_EMACS); -#endif /* ETAGS_REGEXPS */ - - /* - * If etags, always find typedefs and structure tags. Why not? - * Also default is to find macro constants and enum constants. - */ - if (!CTAGS) - typedefs = typedefs_and_cplusplus = constantypedefs = TRUE; - - while (1) - { - int opt = getopt_long (argc, argv, - "-aCdDf:Il:o:r:RStTi:BuvxwVhH", longopts, 0); - - if (opt == EOF) - break; - - switch (opt) - { - case 0: - /* If getopt returns 0, then it has already processed a - long-named option. We should do nothing. */ - break; - - case 1: - /* This means that a filename has been seen. Record it. */ - argbuffer[current_arg].arg_type = at_filename; - argbuffer[current_arg].what = optarg; - ++current_arg; - ++file_count; - break; - - /* Common options. */ - case 'a': - append_to_tagfile = TRUE; - break; - case 'C': - cplusplus = TRUE; - break; - case 'd': - constantypedefs = TRUE; - break; - case 'D': - constantypedefs = FALSE; - break; - case 'f': /* for compatibility with old makefiles */ - case 'o': - if (tagfile) - { - fprintf (stderr, "%s: -%c option may only be given once.\n", - progname, opt); - suggest_asking_for_help (); - } - tagfile = optarg; - break; - case 'I': - case 'S': /* for backward compatibility */ - noindentypedefs = TRUE; - break; - case 'l': - argbuffer[current_arg].function = get_language_from_name (optarg); - argbuffer[current_arg].arg_type = at_language; - ++current_arg; - break; -#ifdef ETAGS_REGEXPS - case 'r': - argbuffer[current_arg].arg_type = at_regexp; - argbuffer[current_arg].what = optarg; - ++current_arg; - break; - case 'R': - argbuffer[current_arg].arg_type = at_regexp; - argbuffer[current_arg].what = NULL; - ++current_arg; - break; -#endif /* ETAGS_REGEXPS */ - case 'V': - print_version (); - break; - case 'h': - case 'H': - print_help (); - break; - case 't': - typedefs = TRUE; - break; - case 'T': - typedefs = typedefs_and_cplusplus = TRUE; - break; -#if (!CTAGS) - /* Etags options */ - case 'i': - included_files[nincluded_files++] = optarg; - break; -#else /* CTAGS */ - /* Ctags options. */ - case 'B': - searchar = '?'; - break; - case 'u': - update = TRUE; - break; - case 'v': - vgrind_style = TRUE; - /*FALLTHRU*/ - case 'x': - cxref_style = TRUE; - break; - case 'w': - no_warnings = TRUE; - break; -#endif /* CTAGS */ - default: - suggest_asking_for_help (); - } - } - - for (; optind < argc; ++optind) - { - argbuffer[current_arg].arg_type = at_filename; - argbuffer[current_arg].what = argv[optind]; - ++current_arg; - ++file_count; - } - - if (nincluded_files == 0 && file_count == 0) - { - fprintf (stderr, "%s: No input files specified.\n", progname); - suggest_asking_for_help (); - } - - if (tagfile == NULL) - tagfile = CTAGS ? "tags" : "TAGS"; - cwd = etags_getcwd (); /* the current working directory */ - if (cwd[strlen (cwd) - 1] != '/') - cwd = concat (cwd, "/", ""); - if (streq (tagfile, "-")) - tagfiledir = cwd; - else - tagfiledir = absolute_dirname (tagfile, cwd); - - init (); /* set up boolean "functions" */ - - initbuffer (&lb); - initbuffer (&token_name); - initbuffer (&lbs[0].lb); - initbuffer (&lbs[1].lb); - initbuffer (&filename_lb); - - if (!CTAGS) - { - if (streq (tagfile, "-")) - { - tagf = stdout; -#ifdef DOS_NT - /* Switch redirected `stdout' to binary mode (setting `_fmode' - doesn't take effect until after `stdout' is already open). */ - if (!isatty (fileno (stdout))) - setmode (fileno (stdout), O_BINARY); -#endif /* DOS_NT */ - } - else - tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); - if (tagf == NULL) - pfatal (tagfile); - } - - /* - * Loop through files finding functions. - */ - for (i = 0; i < current_arg; ++i) - { - switch (argbuffer[i].arg_type) - { - case at_language: - lang_func = argbuffer[i].function; - break; -#ifdef ETAGS_REGEXPS - case at_regexp: - add_regex (argbuffer[i].what); - break; -#endif - case at_filename: -#ifdef VMS - while ((this_file = gfnames (argbuffer[i].what, &got_err)) != NULL) - { - if (got_err) - { - error ("Can't find file %s\n", this_file); - argc--, argv++; - } - else - { - this_file = massage_name (this_file); - } -#else - this_file = argbuffer[i].what; -#endif - /* Input file named "-" means read file names from stdin - and use them. */ - if (streq (this_file, "-")) - while (readline_internal (&filename_lb, stdin) > 0) - process_file (filename_lb.buffer); - else - process_file (this_file); -#ifdef VMS - } -#endif - break; - } - } - - if (!CTAGS) - { - while (nincluded_files-- > 0) - fprintf (tagf, "\f\n%s,include\n", *included_files++); - - fclose (tagf); - exit (GOOD); - } - - /* If CTAGS, we are here. process_file did not write the tags yet, - because we want them ordered. Let's do it now. */ - if (cxref_style) - { - put_entries (head); - exit (GOOD); - } - - if (update) - { - char cmd[BUFSIZ]; - for (i = 0; i < current_arg; ++i) - { - if (argbuffer[i].arg_type != at_filename) - continue; - sprintf (cmd, - "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS", - tagfile, argbuffer[i].what, tagfile); - if (system (cmd) != GOOD) - fatal ("failed to execute shell command", (char *)NULL); - } - append_to_tagfile = TRUE; - } - - tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); - if (tagf == NULL) - pfatal (tagfile); - put_entries (head); - fclose (tagf); - - if (update) - { - char cmd[BUFSIZ]; - sprintf (cmd, "sort %s -o %s", tagfile, tagfile); - exit (system (cmd)); - } - return GOOD; -} - - -/* - * Return a Lang_function given the name. - */ -Lang_function * -get_language_from_name (name) - char *name; -{ - struct lang_entry *lang; - - if (name != NULL) - for (lang = lang_names; lang->name != NULL; lang++) - { - if (streq (name, lang->name)) - return lang->function; - } - - fprintf (stderr, "%s: language \"%s\" not recognized.\n", - progname, optarg); - suggest_asking_for_help (); - - /* This point should never be reached. The function should either - return a function pointer or never return. Note that a NULL - pointer cannot be considered as an error, as it means that the - language has not been explicitely imposed by the user ("auto"). */ - return NULL; /* avoid warnings from compiler */ -} - - -/* - * Return a Lang_function given the interpreter name. - */ -Lang_function * -get_language_from_interpreter (interpreter) - char *interpreter; -{ - struct lang_entry *lang; - char **iname; - - if (interpreter == NULL) - return NULL; - for (lang = lang_names; lang->name != NULL; lang++) - if (lang->interpreters != NULL) - for (iname = lang->interpreters; *iname != NULL; iname++) - if (streq (*iname, interpreter)) - return lang->function; - - return NULL; -} - - - -/* - * Return a Lang_function given the file suffix. - */ -Lang_function * -get_language_from_suffix (suffix) - char *suffix; -{ - struct lang_entry *lang; - char **ext; - - if (suffix == NULL) - return NULL; - for (lang = lang_names; lang->name != NULL; lang++) - if (lang->suffixes != NULL) - for (ext = lang->suffixes; *ext != NULL; ext++) - if (streq (*ext, suffix)) - return lang->function; - - return NULL; -} - - -/* - * This routine is called on each file argument. - */ -void -process_file (file) - char *file; -{ - struct stat stat_buf; - FILE *inf; -#ifdef DOS_NT - char *p; - - for (p = file; *p != '\0'; p++) - if (*p == '\\') - *p = '/'; -#endif - - if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode)) - { - fprintf (stderr, "Skipping %s: it is not a regular file.\n", file); - return; - } - if (streq (file, tagfile) && !streq (tagfile, "-")) - { - fprintf (stderr, "Skipping inclusion of %s in self.\n", file); - return; - } - inf = fopen (file, "r"); - if (inf == NULL) - { - perror (file); - return; - } - - find_entries (file, inf); - - if (!CTAGS) - { - char *filename; - - if (absolutefn (file)) - { - /* file is an absolute filename. Canonicalise it. */ - filename = absolute_filename (file, cwd); - } - else - { - /* file is a filename relative to cwd. Make it relative - to the directory of the tags file. */ - filename = relative_filename (file, tagfiledir); - } - fprintf (tagf, "\f\n%s,%d\n", filename, total_size_of_entries (head)); - free (filename); - put_entries (head); - free_tree (head); - head = NULL; - } -} - -/* - * This routine sets up the boolean pseudo-functions which work - * by setting boolean flags dependent upon the corresponding character - * Every char which is NOT in that string is not a white char. Therefore, - * all of the array "_wht" is set to FALSE, and then the elements - * subscripted by the chars in "white" are set to TRUE. Thus "_wht" - * of a char is TRUE if it is the string "white", else FALSE. - */ -void -init () -{ - register char *sp; - register int i; - - for (i = 0; i < 0177; i++) - _wht[i] = _etk[i] = _itk[i] = _btk[i] = FALSE; - for (sp = white; *sp; sp++) - _wht[*sp] = TRUE; - for (sp = endtk; *sp; sp++) - _etk[*sp] = TRUE; - for (sp = intk; *sp; sp++) - _itk[*sp] = TRUE; - for (sp = begtk; *sp; sp++) - _btk[*sp] = TRUE; - _wht[0] = _wht['\n']; - _etk[0] = _etk['\n']; - _btk[0] = _btk['\n']; - _itk[0] = _itk['\n']; -} - -/* - * This routine opens the specified file and calls the function - * which finds the function and type definitions. - */ -void -find_entries (file, inf) - char *file; - FILE *inf; -{ - char *cp; - Lang_function *function; - NODE *old_last_node; - extern NODE *last_node; - - - /* Memory leakage here: the memory block pointed by curfile is never - released. The amount of memory leaked here is the sum of the - lengths of the input file names. */ - curfile = savestr (file); - - /* If user specified a language, use it. */ - function = lang_func; - if (function != NULL) - { - function (inf); - fclose (inf); - return; - } - - cp = etags_strrchr (file, '.'); - if (cp != NULL) - { - cp += 1; - function = get_language_from_suffix (cp); - if (function != NULL) - { - function (inf); - fclose (inf); - return; - } - } - - /* Look for sharp-bang as the first two characters. */ - if (readline_internal (&lb, inf) > 2 - && lb.buffer[0] == '#' - && lb.buffer[1] == '!') - { - char *lp; - - /* Set lp to point at the first char after the last slash in the - line or, if no slashes, at the first nonblank. Then set cp to - the first successive blank and terminate the string. */ - lp = etags_strrchr (lb.buffer+2, '/'); - if (lp != NULL) - lp += 1; - else - for (lp = lb.buffer+2; *lp != '\0' && isspace (*lp); lp++) - continue; - for (cp = lp; *cp != '\0' && !isspace (*cp); cp++) - continue; - *cp = '\0'; - - if (strlen (lp) > 0) - { - function = get_language_from_interpreter (lp); - if (function != NULL) - { - function (inf); - fclose (inf); - return; - } - } - } - rewind (inf); - - /* Try Fortran. */ - old_last_node = last_node; - Fortran_functions (inf); - - /* No Fortran entries found. Try C. */ - if (old_last_node == last_node) - { - rewind (inf); - default_C_entries (inf); - } - fclose (inf); - return; -} - -/* Record a tag. */ -void -pfnote (name, is_func, linestart, linelen, lno, cno) - char *name; /* tag name, or NULL if unnamed */ - logical is_func; /* tag is a function */ - char *linestart; /* start of the line where tag is */ - int linelen; /* length of the line where tag is */ - int lno; /* line number */ - long cno; /* character number */ -{ - register NODE *np; - - if (CTAGS && name == NULL) - return; - - np = xnew (1, NODE); - - /* If ctags mode, change name "main" to M<thisfilename>. */ - if (CTAGS && !cxref_style && streq (name, "main")) - { - register char *fp = etags_strrchr (curfile, '/'); - np->name = concat ("M", fp == 0 ? curfile : fp + 1, ""); - fp = etags_strrchr (np->name, '.'); - if (fp && fp[1] != '\0' && fp[2] == '\0') - fp[0] = 0; - } - else - np->name = name; - np->been_warned = FALSE; - np->file = curfile; - np->is_func = is_func; - np->lno = lno; - /* Our char numbers are 0-base, because of C language tradition? - ctags compatibility? old versions compatibility? I don't know. - Anyway, since emacs's are 1-base we expect etags.el to take care - of the difference. If we wanted to have 1-based numbers, we would - uncomment the +1 below. */ - np->cno = cno /* + 1 */ ; - np->left = np->right = NULL; - if (CTAGS && !cxref_style) - { - if (strlen (linestart) < 50) - np->pat = concat (linestart, "$", ""); - else - np->pat = savenstr (linestart, 50); - } - else - np->pat = savenstr (linestart, linelen); - - add_node (np, &head); -} - -/* - * free_tree () - * recurse on left children, iterate on right children. - */ -void -free_tree (node) - register NODE *node; -{ - while (node) - { - register NODE *node_right = node->right; - free_tree (node->left); - if (node->name != NULL) - free (node->name); - free (node->pat); - free ((char *) node); - node = node_right; - } -} - -/* - * add_node () - * Adds a node to the tree of nodes. In etags mode, we don't keep - * it sorted; we just keep a linear list. In ctags mode, maintain - * an ordered tree, with no attempt at balancing. - * - * add_node is the only function allowed to add nodes, so it can - * maintain state. - */ -NODE *last_node = NULL; -void -add_node (node, cur_node_p) - NODE *node, **cur_node_p; -{ - register int dif; - register NODE *cur_node = *cur_node_p; - - if (cur_node == NULL) - { - *cur_node_p = node; - last_node = node; - return; - } - - if (!CTAGS) - { - /* Etags Mode */ - if (last_node == NULL) - fatal ("internal error in add_node", (char *)NULL); - last_node->right = node; - last_node = node; - } - else - { - /* Ctags Mode */ - dif = strcmp (node->name, cur_node->name); - - /* - * If this tag name matches an existing one, then - * do not add the node, but maybe print a warning. - */ - if (!dif) - { - if (streq (node->file, cur_node->file)) - { - if (!no_warnings) - { - fprintf (stderr, "Duplicate entry in file %s, line %d: %s\n", - node->file, lineno, node->name); - fprintf (stderr, "Second entry ignored\n"); - } - } - else if (!cur_node->been_warned && !no_warnings) - { - fprintf - (stderr, - "Duplicate entry in files %s and %s: %s (Warning only)\n", - node->file, cur_node->file, node->name); - cur_node->been_warned = TRUE; - } - return; - } - - /* Actually add the node */ - add_node (node, dif < 0 ? &cur_node->left : &cur_node->right); - } -} - -void -put_entries (node) - register NODE *node; -{ - register char *sp; - - if (node == NULL) - return; - - /* Output subentries that precede this one */ - put_entries (node->left); - - /* Output this entry */ - - if (!CTAGS) - { - if (node->name != NULL) - fprintf (tagf, "%s\177%s\001%d,%d\n", - node->pat, node->name, node->lno, node->cno); - else - fprintf (tagf, "%s\177%d,%d\n", - node->pat, node->lno, node->cno); - } - else - { - if (node->name == NULL) - error ("internal error: NULL name in ctags mode.", (char *)NULL); - - if (cxref_style) - { - if (vgrind_style) - fprintf (stdout, "%s %s %d\n", - node->name, node->file, (node->lno + 63) / 64); - else - fprintf (stdout, "%-16s %3d %-16s %s\n", - node->name, node->lno, node->file, node->pat); - } - else - { - fprintf (tagf, "%s\t%s\t", node->name, node->file); - - if (node->is_func) - { /* a function */ - putc (searchar, tagf); - putc ('^', tagf); - - for (sp = node->pat; *sp; sp++) - { - if (*sp == '\\' || *sp == searchar) - putc ('\\', tagf); - putc (*sp, tagf); - } - putc (searchar, tagf); - } - else - { /* a typedef; text pattern inadequate */ - fprintf (tagf, "%d", node->lno); - } - putc ('\n', tagf); - } - } - - /* Output subentries that follow this one */ - put_entries (node->right); -} - -/* Length of a number's decimal representation. */ -int -number_len (num) - long num; -{ - int len = 0; - if (!num) - return 1; - for (; num; num /= 10) - ++len; - return len; -} - -/* - * Return total number of characters that put_entries will output for - * the nodes in the subtree of the specified node. Works only if - * we are not ctags, but called only in that case. This count - * is irrelevant with the new tags.el, but is still supplied for - * backward compatibility. - */ -int -total_size_of_entries (node) - register NODE *node; -{ - register int total; - - if (node == NULL) - return 0; - - total = 0; - for (; node; node = node->right) - { - /* Count left subentries. */ - total += total_size_of_entries (node->left); - - /* Count this entry */ - total += strlen (node->pat) + 1; - total += number_len ((long) node->lno) + 1 + number_len (node->cno) + 1; - if (node->name != NULL) - total += 1 + strlen (node->name); /* \001name */ - } - - return total; -} - -/* - * The C symbol tables. - */ -enum sym_type -{ - st_none, st_C_objprot, st_C_objimpl, st_C_objend, st_C_gnumacro, - st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec -}; - -/* Feed stuff between (but not including) %[ and %] lines to: - gperf -c -k 1,3 -o -p -r -t -%[ -struct C_stab_entry { char *name; int c_ext; enum sym_type type; } -%% -@interface, 0, st_C_objprot -@protocol, 0, st_C_objprot -@implementation,0, st_C_objimpl -@end, 0, st_C_objend -class, C_PLPL, st_C_struct -namespace, C_PLPL, st_C_struct -domain, C_STAR, st_C_struct -union, 0, st_C_struct -struct, 0, st_C_struct -enum, 0, st_C_enum -typedef, 0, st_C_typedef -define, 0, st_C_define -bool, C_PLPL, st_C_typespec -long, 0, st_C_typespec -short, 0, st_C_typespec -int, 0, st_C_typespec -char, 0, st_C_typespec -float, 0, st_C_typespec -double, 0, st_C_typespec -signed, 0, st_C_typespec -unsigned, 0, st_C_typespec -auto, 0, st_C_typespec -void, 0, st_C_typespec -extern, 0, st_C_typespec -static, 0, st_C_typespec -const, 0, st_C_typespec -volatile, 0, st_C_typespec -explicit, C_PLPL, st_C_typespec -mutable, C_PLPL, st_C_typespec -typename, C_PLPL, st_C_typespec -# DEFUN used in emacs, the next three used in glibc (SYSCALL only for mach). -DEFUN, 0, st_C_gnumacro -SYSCALL, 0, st_C_gnumacro -ENTRY, 0, st_C_gnumacro -PSEUDO, 0, st_C_gnumacro -# These are defined inside C functions, so currently they are not met. -# EXFUN used in glibc, DEFVAR_* in emacs. -#EXFUN, 0, st_C_gnumacro -#DEFVAR_, 0, st_C_gnumacro -%] -and replace lines between %< and %> with its output. */ -/*%<*/ -/* C code produced by gperf version 2.1 (K&R C version) */ -/* Command-line: gperf -c -k 1,3 -o -p -r -t */ - - -struct C_stab_entry { char *name; int c_ext; enum sym_type type; }; - -#define MIN_WORD_LENGTH 3 -#define MAX_WORD_LENGTH 15 -#define MIN_HASH_VALUE 34 -#define MAX_HASH_VALUE 121 -/* - 34 keywords - 88 is the maximum key range -*/ - -static int -hash (str, len) - register char *str; - register unsigned int len; -{ - static unsigned char hash_table[] = - { - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 45, 121, 121, 121, 16, 19, - 61, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 10, 121, 121, 20, 53, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 41, 45, 22, - 60, 47, 37, 28, 121, 55, 121, 121, 20, 14, - 29, 30, 5, 121, 50, 59, 30, 54, 6, 121, - 121, 121, 121, 121, 121, 121, 121, 121, - }; - return len + hash_table[str[2]] + hash_table[str[0]]; -} - -struct C_stab_entry * -in_word_set (str, len) - register char *str; - register unsigned int len; -{ - - static struct C_stab_entry wordlist[] = - { - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"volatile", 0, st_C_typespec}, - {"PSEUDO", 0, st_C_gnumacro}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"typedef", 0, st_C_typedef}, - {"typename", C_PLPL, st_C_typespec}, - {"",}, {"",}, {"",}, - {"SYSCALL", 0, st_C_gnumacro}, - {"",}, {"",}, {"",}, - {"mutable", C_PLPL, st_C_typespec}, - {"namespace", C_PLPL, st_C_struct}, - {"long", 0, st_C_typespec}, - {"",}, {"",}, - {"const", 0, st_C_typespec}, - {"",}, {"",}, {"",}, - {"explicit", C_PLPL, st_C_typespec}, - {"",}, {"",}, {"",}, {"",}, - {"void", 0, st_C_typespec}, - {"",}, - {"char", 0, st_C_typespec}, - {"class", C_PLPL, st_C_struct}, - {"",}, {"",}, {"",}, - {"float", 0, st_C_typespec}, - {"",}, - {"@implementation", 0, st_C_objimpl}, - {"auto", 0, st_C_typespec}, - {"",}, - {"ENTRY", 0, st_C_gnumacro}, - {"@end", 0, st_C_objend}, - {"bool", C_PLPL, st_C_typespec}, - {"domain", C_STAR, st_C_struct}, - {"",}, - {"DEFUN", 0, st_C_gnumacro}, - {"extern", 0, st_C_typespec}, - {"@interface", 0, st_C_objprot}, - {"",}, {"",}, {"",}, - {"int", 0, st_C_typespec}, - {"",}, {"",}, {"",}, {"",}, - {"signed", 0, st_C_typespec}, - {"short", 0, st_C_typespec}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"define", 0, st_C_define}, - {"@protocol", 0, st_C_objprot}, - {"enum", 0, st_C_enum}, - {"static", 0, st_C_typespec}, - {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, - {"union", 0, st_C_struct}, - {"struct", 0, st_C_struct}, - {"",}, {"",}, {"",}, {"",}, - {"double", 0, st_C_typespec}, - {"unsigned", 0, st_C_typespec}, - }; - - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) - { - register char *s = wordlist[key].name; - - if (*s == *str && !strncmp (str + 1, s + 1, len - 1)) - return &wordlist[key]; - } - } - return 0; -} -/*%>*/ - -enum sym_type -C_symtype (str, len, c_ext) - char *str; - int len; - int c_ext; -{ - register struct C_stab_entry *se = in_word_set (str, len); - - if (se == NULL || (se->c_ext && !(c_ext & se->c_ext))) - return st_none; - return se->type; -} - - /* - * C functions are recognized using a simple finite automaton. - * funcdef is its state variable. - */ -enum -{ - fnone, /* nothing seen */ - ftagseen, /* function-like tag seen */ - fstartlist, /* just after open parenthesis */ - finlist, /* in parameter list */ - flistseen, /* after parameter list */ - fignore /* before open brace */ -} funcdef; - - - /* - * typedefs are recognized using a simple finite automaton. - * typdef is its state variable. - */ -enum -{ - tnone, /* nothing seen */ - ttypedseen, /* typedef keyword seen */ - tinbody, /* inside typedef body */ - tend, /* just before typedef tag */ - tignore /* junk after typedef tag */ -} typdef; - - - /* - * struct-like structures (enum, struct and union) are recognized - * using another simple finite automaton. `structdef' is its state - * variable. - */ -enum -{ - snone, /* nothing seen yet */ - skeyseen, /* struct-like keyword seen */ - stagseen, /* struct-like tag seen */ - scolonseen, /* colon seen after struct-like tag */ - sinbody /* in struct body: recognize member func defs*/ -} structdef; - -/* - * When structdef is stagseen, scolonseen, or sinbody, structtag is the - * struct tag, and structtype is the type of the preceding struct-like - * keyword. - */ -char *structtag = "<uninited>"; -enum sym_type structtype; - -/* - * When objdef is different from onone, objtag is the name of the class. - */ -char *objtag = "<uninited>"; - -/* - * Yet another little state machine to deal with preprocessor lines. - */ -enum -{ - dnone, /* nothing seen */ - dsharpseen, /* '#' seen as first char on line */ - ddefineseen, /* '#' and 'define' seen */ - dignorerest /* ignore rest of line */ -} definedef; - -/* - * State machine for Objective C protocols and implementations. - */ -enum -{ - onone, /* nothing seen */ - oprotocol, /* @interface or @protocol seen */ - oimplementation, /* @implementations seen */ - otagseen, /* class name seen */ - oparenseen, /* parenthesis before category seen */ - ocatseen, /* category name seen */ - oinbody, /* in @implementation body */ - omethodsign, /* in @implementation body, after +/- */ - omethodtag, /* after method name */ - omethodcolon, /* after method colon */ - omethodparm, /* after method parameter */ - oignore /* wait for @end */ -} objdef; - -/* - * Set this to TRUE, and the next token considered is called a function. - * Used only for GNU emacs's function-defining macros. - */ -logical next_token_is_func; - -/* - * TRUE in the rules part of a yacc file, FALSE outside (parse as C). - */ -logical yacc_rules; - -/* - * methodlen is the length of the method name stored in token_name. - */ -int methodlen; - -/* - * consider_token () - * checks to see if the current token is at the start of a - * function, or corresponds to a typedef, or is a struct/union/enum - * tag, or #define, or an enum constant. - * - * *IS_FUNC gets TRUE iff the token is a function or #define macro - * with args. C_EXT is which language we are looking at. - * - * In the future we will need some way to adjust where the end of - * the token is; for instance, implementing the C++ keyword - * `operator' properly will adjust the end of the token to be after - * whatever follows `operator'. - * - * Globals - * funcdef IN OUT - * structdef IN OUT - * definedef IN OUT - * typdef IN OUT - * objdef IN OUT - * next_token_is_func IN OUT - */ - -logical -consider_token (str, len, c, c_ext, cblev, parlev, is_func) - register char *str; /* IN: token pointer */ - register int len; /* IN: token length */ - register char c; /* IN: first char after the token */ - int c_ext; /* IN: C extensions mask */ - int cblev; /* IN: curly brace level */ - int parlev; /* IN: parenthesis level */ - logical *is_func; /* OUT: function found */ -{ - enum sym_type toktype = C_symtype (str, len, c_ext); - - /* - * Advance the definedef state machine. - */ - switch (definedef) - { - case dnone: - /* We're not on a preprocessor line. */ - break; - case dsharpseen: - if (toktype == st_C_define) - { - definedef = ddefineseen; - } - else - { - definedef = dignorerest; - } - return FALSE; - case ddefineseen: - /* - * Make a tag for any macro, unless it is a constant - * and constantypedefs is FALSE. - */ - definedef = dignorerest; - *is_func = (c == '('); - if (!*is_func && !constantypedefs) - return FALSE; - else - return TRUE; - case dignorerest: - return FALSE; - default: - error ("internal error: definedef value.", (char *)NULL); - } - - /* - * Now typedefs - */ - switch (typdef) - { - case tnone: - if (toktype == st_C_typedef) - { - if (typedefs) - typdef = ttypedseen; - funcdef = fnone; - return FALSE; - } - break; - case ttypedseen: - switch (toktype) - { - case st_none: - case st_C_typespec: - typdef = tend; - break; - case st_C_struct: - case st_C_enum: - break; - } - /* Do not return here, so the structdef stuff has a chance. */ - break; - case tend: - switch (toktype) - { - case st_C_typespec: - case st_C_struct: - case st_C_enum: - return FALSE; - } - return TRUE; - } - - /* - * This structdef business is currently only invoked when cblev==0. - * It should be recursively invoked whatever the curly brace level, - * and a stack of states kept, to allow for definitions of structs - * within structs. - * - * This structdef business is NOT invoked when we are ctags and the - * file is plain C. This is because a struct tag may have the same - * name as another tag, and this loses with ctags. - */ - switch (toktype) - { - case st_C_struct: - case st_C_enum: - if (typdef == ttypedseen - || (typedefs_and_cplusplus && cblev == 0 && structdef == snone)) - { - structdef = skeyseen; - structtype = toktype; - } - return FALSE; - } - - if (structdef == skeyseen) - { - /* Save the tag for struct/union/class, for functions that may be - defined inside. */ - if (structtype == st_C_struct) - structtag = savenstr (str, len); - else - structtag = "<enum>"; - structdef = stagseen; - return TRUE; - } - - /* Avoid entering funcdef stuff if typdef is going on. */ - if (typdef != tnone) - { - definedef = dnone; - return FALSE; - } - - /* Detect GNU macros. - - DEFUN note for writers of emacs C code: - The DEFUN macro, used in emacs C source code, has a first arg - that is a string (the lisp function name), and a second arg that - is a C function name. Since etags skips strings, the second arg - is tagged. This is unfortunate, as it would be better to tag the - first arg. The simplest way to deal with this problem would be - to name the tag with a name built from the function name, by - removing the initial 'F' character and substituting '-' for '_'. - Anyway, this assumes that the conventions of naming lisp - functions will never change. Currently, this method is not - implemented, so writers of emacs code are recommended to put the - first two args of a DEFUN on the same line. */ - if (definedef == dnone && toktype == st_C_gnumacro) - { - next_token_is_func = TRUE; - return FALSE; - } - if (next_token_is_func) - { - next_token_is_func = FALSE; - funcdef = fignore; - *is_func = TRUE; - return TRUE; - } - - /* Detect Objective C constructs. */ - switch (objdef) - { - case onone: - switch (toktype) - { - case st_C_objprot: - objdef = oprotocol; - return FALSE; - case st_C_objimpl: - objdef = oimplementation; - return FALSE; - } - break; - case oimplementation: - /* Save the class tag for functions that may be defined inside. */ - objtag = savenstr (str, len); - objdef = oinbody; - return FALSE; - case oprotocol: - /* Save the class tag for categories. */ - objtag = savenstr (str, len); - objdef = otagseen; - *is_func = TRUE; - return TRUE; - case oparenseen: - objdef = ocatseen; - *is_func = TRUE; - return TRUE; - case oinbody: - break; - case omethodsign: - if (parlev == 0) - { - objdef = omethodtag; - methodlen = len; - grow_linebuffer (&token_name, methodlen+1); - strncpy (token_name.buffer, str, len); - token_name.buffer[methodlen] = '\0'; - return TRUE; - } - return FALSE; - case omethodcolon: - if (parlev == 0) - objdef = omethodparm; - return FALSE; - case omethodparm: - if (parlev == 0) - { - objdef = omethodtag; - methodlen += len; - grow_linebuffer (&token_name, methodlen+1); - strncat (token_name.buffer, str, len); - return TRUE; - } - return FALSE; - case oignore: - if (toktype == st_C_objend) - { - /* Memory leakage here: the string pointed by objtag is - never released, because many tests would be needed to - avoid breaking on incorrect input code. The amount of - memory leaked here is the sum of the lengths of the - class tags. - free (objtag); */ - objdef = onone; - } - return FALSE; - } - - /* A function or enum constant? */ - switch (toktype) - { - case st_C_typespec: - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; /* should be useless */ - return FALSE; - case st_none: - if (constantypedefs && structdef == sinbody && structtype == st_C_enum) - return TRUE; - if (funcdef == fnone) - { - funcdef = ftagseen; - *is_func = TRUE; - return TRUE; - } - } - - return FALSE; -} - -/* - * C_entries () - * This routine finds functions, typedefs, #define's, enum - * constants and struct/union/enum definitions in C syntax - * and adds them to the list. - */ -typedef struct -{ - logical valid; - char *str; - logical named; - int linelen; - int lineno; - long linepos; - char *buffer; -} TOKEN; - -#define current_lb_is_new (newndx == curndx) -#define switch_line_buffers() (curndx = 1 - curndx) - -#define curlb (lbs[curndx].lb) -#define othlb (lbs[1-curndx].lb) -#define newlb (lbs[newndx].lb) -#define curlinepos (lbs[curndx].linepos) -#define othlinepos (lbs[1-curndx].linepos) -#define newlinepos (lbs[newndx].linepos) - -#define CNL_SAVE_DEFINEDEF \ -do { \ - curlinepos = charno; \ - lineno++; \ - linecharno = charno; \ - charno += readline (&curlb, inf); \ - lp = curlb.buffer; \ - quotednl = FALSE; \ - newndx = curndx; \ -} while (0) - -#define CNL \ -do { \ - CNL_SAVE_DEFINEDEF; \ - if (savetok.valid) \ - { \ - tok = savetok; \ - savetok.valid = FALSE; \ - } \ - definedef = dnone; \ -} while (0) - - -void -make_C_tag (isfun, tokp) - logical isfun; - TOKEN *tokp; -{ - char *name = NULL; - - /* This function should never be called when tok.valid is FALSE, but - we must protect against invalid input or internal errors. */ - if (tokp->valid) - { - if (CTAGS || tokp->named) - name = savestr (token_name.buffer); - pfnote (name, isfun, - tokp->buffer, tokp->linelen, tokp->lineno, tokp->linepos); - tokp->valid = FALSE; - } - else if (DEBUG) - abort (); -} - - -void -C_entries (c_ext, inf) - int c_ext; /* extension of C */ - FILE *inf; /* input file */ -{ - register char c; /* latest char read; '\0' for end of line */ - register char *lp; /* pointer one beyond the character `c' */ - int curndx, newndx; /* indices for current and new lb */ - TOKEN tok; /* latest token read */ - register int tokoff; /* offset in line of start of current token */ - register int toklen; /* length of current token */ - int cblev; /* current curly brace level */ - int parlev; /* current parenthesis level */ - logical incomm, inquote, inchar, quotednl, midtoken; - logical cplpl; - TOKEN savetok; /* token saved during preprocessor handling */ - - - curndx = newndx = 0; - lineno = 0; - charno = 0; - lp = curlb.buffer; - *lp = 0; - - funcdef = fnone; typdef = tnone; structdef = snone; - definedef = dnone; objdef = onone; - next_token_is_func = yacc_rules = FALSE; - midtoken = inquote = inchar = incomm = quotednl = FALSE; - tok.valid = savetok.valid = FALSE; - cblev = 0; - parlev = 0; - cplpl = c_ext & C_PLPL; - - while (!feof (inf)) - { - c = *lp++; - if (c == '\\') - { - /* If we're at the end of the line, the next character is a - '\0'; don't skip it, because it's the thing that tells us - to read the next line. */ - if (*lp == '\0') - { - quotednl = TRUE; - continue; - } - lp++; - c = ' '; - } - else if (incomm) - { - switch (c) - { - case '*': - if (*lp == '/') - { - c = *lp++; - incomm = FALSE; - } - break; - case '\0': - /* Newlines inside comments do not end macro definitions in - traditional cpp. */ - CNL_SAVE_DEFINEDEF; - break; - } - continue; - } - else if (inquote) - { - switch (c) - { - case '"': - inquote = FALSE; - break; - case '\0': - /* Newlines inside strings do not end macro definitions - in traditional cpp, even though compilers don't - usually accept them. */ - CNL_SAVE_DEFINEDEF; - break; - } - continue; - } - else if (inchar) - { - switch (c) - { - case '\0': - /* Hmmm, something went wrong. */ - CNL; - /* FALLTHRU */ - case '\'': - inchar = FALSE; - break; - } - continue; - } - else - switch (c) - { - case '"': - inquote = TRUE; - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; - continue; - case '\'': - inchar = TRUE; - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; - continue; - case '/': - if (*lp == '*') - { - lp++; - incomm = TRUE; - continue; - } - else if (/* cplpl && */ *lp == '/') - { - c = '\0'; - break; - } - else - break; - case '%': - if ((c_ext & YACC) && *lp == '%') - { - /* entering or exiting rules section in yacc file */ - lp++; - definedef = dnone; funcdef = fnone; - typdef = tnone; structdef = snone; - next_token_is_func = FALSE; - midtoken = inquote = inchar = incomm = quotednl = FALSE; - cblev = 0; - yacc_rules = !yacc_rules; - continue; - } - else - break; - case '#': - if (definedef == dnone) - { - char *cp; - logical cpptoken = TRUE; - - /* Look back on this line. If all blanks, or nonblanks - followed by an end of comment, this is a preprocessor - token. */ - for (cp = newlb.buffer; cp < lp-1; cp++) - if (!iswhite (*cp)) - { - if (*cp == '*' && *(cp+1) == '/') - { - cp++; - cpptoken = TRUE; - } - else - cpptoken = FALSE; - } - if (cpptoken) - definedef = dsharpseen; - } /* if (definedef == dnone) */ - - continue; - } /* switch (c) */ - - - /* Consider token only if some complicated conditions are satisfied. */ - if ((definedef != dnone - || (cblev == 0 && structdef != scolonseen) - || (cblev == 1 && cplpl && structdef == sinbody) - || (structdef == sinbody && structtype == st_C_enum)) - && typdef != tignore - && definedef != dignorerest - && funcdef != finlist) - { - if (midtoken) - { - if (endtoken (c)) - { - if (c == ':' && cplpl && *lp == ':' && begtoken(*(lp + 1))) - { - /* - * This handles :: in the middle, but not at the - * beginning of an identifier. - */ - lp += 2; - toklen += 3; - } - else - { - logical is_func = FALSE; - - if (yacc_rules - || consider_token (newlb.buffer + tokoff, toklen, c, - c_ext, cblev, parlev, &is_func)) - { - if (structdef == sinbody - && definedef == dnone - && is_func) - /* function defined in C++ class body */ - { - grow_linebuffer (&token_name, - strlen(structtag)+2+toklen+1); - strcpy (token_name.buffer, structtag); - strcat (token_name.buffer, "::"); - strncat (token_name.buffer, - newlb.buffer+tokoff, toklen); - tok.named = TRUE; - } - else if (objdef == ocatseen) - /* Objective C category */ - { - grow_linebuffer (&token_name, - strlen(objtag)+2+toklen+1); - strcpy (token_name.buffer, objtag); - strcat (token_name.buffer, "("); - strncat (token_name.buffer, - newlb.buffer+tokoff, toklen); - strcat (token_name.buffer, ")"); - tok.named = TRUE; - } - else if (objdef == omethodtag - || objdef == omethodparm) - /* Objective C method */ - { - tok.named = TRUE; - } - else - { - grow_linebuffer (&token_name, toklen+1); - strncpy (token_name.buffer, - newlb.buffer+tokoff, toklen); - token_name.buffer[toklen] = '\0'; - if (structdef == stagseen - || typdef == tend - || (is_func - && definedef == dignorerest)) /* macro */ - tok.named = TRUE; - else - tok.named = FALSE; - } - tok.lineno = lineno; - tok.linelen = tokoff + toklen + 1; - tok.buffer = newlb.buffer; - tok.linepos = newlinepos; - tok.valid = TRUE; - - if (definedef == dnone - && (funcdef == ftagseen - || structdef == stagseen - || typdef == tend - || objdef != onone)) - { - if (current_lb_is_new) - switch_line_buffers (); - } - else - make_C_tag (is_func, &tok); - } - midtoken = FALSE; - } - } /* if (endtoken (c)) */ - else if (intoken (c)) - { - toklen++; - continue; - } - } /* if (midtoken) */ - else if (begtoken (c)) - { - switch (definedef) - { - case dnone: - switch (funcdef) - { - case fstartlist: - funcdef = finlist; - continue; - case flistseen: - make_C_tag (TRUE, &tok); - funcdef = fignore; - break; - case ftagseen: - funcdef = fnone; - break; - } - if (structdef == stagseen) - structdef = snone; - break; - case dsharpseen: - savetok = tok; - } - if (!yacc_rules || lp == newlb.buffer + 1) - { - tokoff = lp - 1 - newlb.buffer; - toklen = 1; - midtoken = TRUE; - } - continue; - } /* if (begtoken) */ - } /* if must look at token */ - - - /* Detect end of line, colon, comma, semicolon and various braces - after having handled a token.*/ - switch (c) - { - case ':': - if (definedef != dnone) - break; - switch (objdef) - { - case otagseen: - objdef = oignore; - make_C_tag (TRUE, &tok); - break; - case omethodtag: - case omethodparm: - objdef = omethodcolon; - methodlen += 1; - grow_linebuffer (&token_name, methodlen+1); - strcat (token_name.buffer, ":"); - break; - } - if (structdef == stagseen) - structdef = scolonseen; - else - switch (funcdef) - { - case ftagseen: - if (yacc_rules) - { - make_C_tag (FALSE, &tok); - funcdef = fignore; - } - break; - case fstartlist: - funcdef = fnone; - break; - } - break; - case ';': - if (definedef != dnone) - break; - if (cblev == 0) - switch (typdef) - { - case tend: - make_C_tag (FALSE, &tok); - /* FALLTHRU */ - default: - typdef = tnone; - } - if (funcdef != fignore) - { - funcdef = fnone; - /* The following instruction invalidates the token. - Probably the token should be invalidated in all - other cases where some state machine is reset. */ - tok.valid = FALSE; - } - if (structdef == stagseen) - structdef = snone; - break; - case ',': - if (definedef != dnone) - break; - switch (objdef) - { - case omethodtag: - case omethodparm: - make_C_tag (TRUE, &tok); - objdef = oinbody; - break; - } - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; - if (structdef == stagseen) - structdef = snone; - break; - case '[': - if (definedef != dnone) - break; - if (cblev == 0 && typdef == tend) - { - typdef = tignore; - make_C_tag (FALSE, &tok); - break; - } - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; - if (structdef == stagseen) - structdef = snone; - break; - case '(': - if (definedef != dnone) - break; - if (objdef == otagseen && parlev == 0) - objdef = oparenseen; - switch (funcdef) - { - case fnone: - switch (typdef) - { - case ttypedseen: - case tend: - /* Make sure that the next char is not a '*'. - This handles constructs like: - typedef void OperatorFun (int fun); */ - if (tok.valid && *lp != '*') - { - typdef = tignore; - make_C_tag (FALSE, &tok); - } - break; - } /* switch (typdef) */ - break; - case ftagseen: - funcdef = fstartlist; - break; - case flistseen: - funcdef = finlist; - break; - } - parlev++; - break; - case ')': - if (definedef != dnone) - break; - if (objdef == ocatseen && parlev == 1) - { - make_C_tag (TRUE, &tok); - objdef = oignore; - } - if (--parlev == 0) - { - switch (funcdef) - { - case fstartlist: - case finlist: - funcdef = flistseen; - break; - } - if (cblev == 0 && typdef == tend) - { - typdef = tignore; - make_C_tag (FALSE, &tok); - } - } - else if (parlev < 0) /* can happen due to ill-conceived #if's. */ - parlev = 0; - break; - case '{': - if (definedef != dnone) - break; - if (typdef == ttypedseen) - typdef = tinbody; - switch (structdef) - { - case skeyseen: /* unnamed struct */ - structdef = sinbody; - structtag = "_anonymous_"; - break; - case stagseen: - case scolonseen: /* named struct */ - structdef = sinbody; - make_C_tag (FALSE, &tok); - break; - } - switch (funcdef) - { - case flistseen: - make_C_tag (TRUE, &tok); - /* FALLTHRU */ - case fignore: - funcdef = fnone; - break; - case fnone: - switch (objdef) - { - case otagseen: - make_C_tag (TRUE, &tok); - objdef = oignore; - break; - case omethodtag: - case omethodparm: - make_C_tag (TRUE, &tok); - objdef = oinbody; - break; - default: - /* Neutralize `extern "C" {' grot. */ - if (cblev == 0 && structdef == snone && typdef == tnone) - cblev = -1; - } - } - cblev++; - break; - case '*': - if (definedef != dnone) - break; - if (funcdef == fstartlist) - funcdef = fnone; /* avoid tagging `foo' in `foo (*bar()) ()' */ - break; - case '}': - if (definedef != dnone) - break; - if (!noindentypedefs && lp == newlb.buffer + 1) - { - cblev = 0; /* reset curly brace level if first column */ - parlev = 0; /* also reset paren level, just in case... */ - } - else if (cblev > 0) - cblev--; - if (cblev == 0) - { - if (typdef == tinbody) - typdef = tend; - /* Memory leakage here: the string pointed by structtag is - never released, because I fear to miss something and - break things while freeing the area. The amount of - memory leaked here is the sum of the lengths of the - struct tags. - if (structdef == sinbody) - free (structtag); */ - - structdef = snone; - structtag = "<error>"; - } - break; - case '+': - case '-': - if (objdef == oinbody && cblev == 0) - { - objdef = omethodsign; - break; - } - /* FALLTHRU */ - case '=': case '#': case '~': case '&': case '%': case '/': - case '|': case '^': case '!': case '<': case '>': case '.': case '?': - if (definedef != dnone) - break; - /* These surely cannot follow a function tag. */ - if (funcdef != finlist && funcdef != fignore) - funcdef = fnone; - break; - case '\0': - if (objdef == otagseen) - { - make_C_tag (TRUE, &tok); - objdef = oignore; - } - /* If a macro spans multiple lines don't reset its state. */ - if (quotednl) - CNL_SAVE_DEFINEDEF; - else - CNL; - break; - } /* switch (c) */ - - } /* while not eof */ -} - -/* - * Process either a C++ file or a C file depending on the setting - * of a global flag. - */ -void -default_C_entries (inf) - FILE *inf; -{ - C_entries (cplusplus ? C_PLPL : 0, inf); -} - -/* Always do plain ANSI C. */ -void -plain_C_entries (inf) - FILE *inf; -{ - C_entries (0, inf); -} - -/* Always do C++. */ -void -Cplusplus_entries (inf) - FILE *inf; -{ - C_entries (C_PLPL, inf); -} - -/* Always do C*. */ -void -Cstar_entries (inf) - FILE *inf; -{ - C_entries (C_STAR, inf); -} - -/* Always do Yacc. */ -void -Yacc_entries (inf) - FILE *inf; -{ - C_entries (YACC, inf); -} - -/* Fortran parsing */ - -char *dbp; - -logical -tail (cp) - char *cp; -{ - register int len = 0; - - while (*cp && lowcase(*cp) == lowcase(dbp[len])) - cp++, len++; - if (*cp == '\0' && !intoken(dbp[len])) - { - dbp += len; - return TRUE; - } - return FALSE; -} - -void -takeprec () -{ - while (isspace (*dbp)) - dbp++; - if (*dbp != '*') - return; - dbp++; - while (isspace (*dbp)) - dbp++; - if (strneq (dbp, "(*)", 3)) - { - dbp += 3; - return; - } - if (!isdigit (*dbp)) - { - --dbp; /* force failure */ - return; - } - do - dbp++; - while (isdigit (*dbp)); -} - -void -getit (inf) - FILE *inf; -{ - register char *cp; - - while (isspace (*dbp)) - dbp++; - if (*dbp == '\0') - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - if (dbp[5] != '&') - return; - dbp += 6; - while (isspace (*dbp)) - dbp++; - } - if (!isalpha (*dbp) - && *dbp != '_' - && *dbp != '$') - return; - for (cp = dbp + 1; - (*cp - && (isalpha (*cp) || isdigit (*cp) || (*cp == '_') || (*cp == '$'))); - cp++) - continue; - pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE, - lb.buffer, cp - lb.buffer + 1, lineno, linecharno); -} - -void -Fortran_functions (inf) - FILE *inf; -{ - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - if (*dbp == '%') - dbp++; /* Ratfor escape to fortran */ - while (isspace (*dbp)) - dbp++; - if (*dbp == '\0') - continue; - switch (lowcase (*dbp)) - { - case 'i': - if (tail ("integer")) - takeprec (); - break; - case 'r': - if (tail ("real")) - takeprec (); - break; - case 'l': - if (tail ("logical")) - takeprec (); - break; - case 'c': - if (tail ("complex") || tail ("character")) - takeprec (); - break; - case 'd': - if (tail ("double")) - { - while (isspace (*dbp)) - dbp++; - if (*dbp == '\0') - continue; - if (tail ("precision")) - break; - continue; - } - break; - } - while (isspace (*dbp)) - dbp++; - if (*dbp == '\0') - continue; - switch (lowcase (*dbp)) - { - case 'f': - if (tail ("function")) - getit (inf); - continue; - case 's': - if (tail ("subroutine")) - getit (inf); - continue; - case 'e': - if (tail ("entry")) - getit (inf); - continue; - case 'p': - if (tail ("program")) - { - getit (inf); - continue; - } - if (tail ("procedure")) - getit (inf); - continue; - } - } -} - -/* - * Bob Weiner, Motorola Inc., 4/3/94 - * Unix and microcontroller assembly tag handling - * look for '^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]' - */ -void -Asm_labels (inf) - FILE *inf; -{ - register char *cp; - - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - cp = lb.buffer; - - /* If first char is alphabetic or one of [_.$], test for colon - following identifier. */ - if (isalpha (*cp) || *cp == '_' || *cp == '.' || *cp == '$') - { - /* Read past label. */ - cp++; - while (isalnum (*cp) || *cp == '_' || *cp == '.' || *cp == '$') - cp++; - if (*cp == ':' || isspace (*cp)) - { - /* Found end of label, so copy it and add it to the table. */ - pfnote ((CTAGS) ? savenstr(lb.buffer, cp-lb.buffer) : NULL, TRUE, - lb.buffer, cp - lb.buffer + 1, lineno, linecharno); - } - } - } -} - -/* - * Perl support by Bart Robinson <lomew@cs.utah.edu> - * Perl sub names: look for /^sub[ \t\n]+[^ \t\n{]+/ - */ -void -Perl_functions (inf) - FILE *inf; -{ - register char *cp; - - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - cp = lb.buffer; - - if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace(*cp++)) - { - while (*cp && isspace(*cp)) - cp++; - while (*cp && ! isspace(*cp) && *cp != '{') - cp++; - pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE, - lb.buffer, cp - lb.buffer + 1, lineno, linecharno); - } - } -} - -/* Added by Mosur Mohan, 4/22/88 */ -/* Pascal parsing */ - -/* - * Locates tags for procedures & functions. Doesn't do any type- or - * var-definitions. It does look for the keyword "extern" or - * "forward" immediately following the procedure statement; if found, - * the tag is skipped. - */ -void -Pascal_functions (inf) - FILE *inf; -{ - struct linebuffer tline; /* mostly copied from C_entries */ - long save_lcno; - int save_lineno, save_len; - char c, *cp, *namebuf; - - logical /* each of these flags is TRUE iff: */ - incomment, /* point is inside a comment */ - inquote, /* point is inside '..' string */ - get_tagname, /* point is after PROCEDURE/FUNCTION - keyword, so next item = potential tag */ - found_tag, /* point is after a potential tag */ - inparms, /* point is within parameter-list */ - verify_tag; /* point has passed the parm-list, so the - next token will determine whether this - is a FORWARD/EXTERN to be ignored, or - whether it is a real tag */ - - lineno = 0; - charno = 0; - dbp = lb.buffer; - *dbp = '\0'; - save_len = 0; - initbuffer (&tline); - - incomment = inquote = FALSE; - found_tag = FALSE; /* have a proc name; check if extern */ - get_tagname = FALSE; /* have found "procedure" keyword */ - inparms = FALSE; /* found '(' after "proc" */ - verify_tag = FALSE; /* check if "extern" is ahead */ - - /* long main loop to get next char */ - while (!feof (inf)) - { - c = *dbp++; - if (c == '\0') /* if end of line */ - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - if (*dbp == '\0') - continue; - if (!((found_tag && verify_tag) || - get_tagname)) - c = *dbp++; /* only if don't need *dbp pointing - to the beginning of the name of - the procedure or function */ - } - if (incomment) - { - if (c == '}') /* within { } comments */ - incomment = FALSE; - else if (c == '*' && *dbp == ')') /* within (* *) comments */ - { - dbp++; - incomment = FALSE; - } - continue; - } - else if (inquote) - { - if (c == '\'') - inquote = FALSE; - continue; - } - else - switch (c) - { - case '\'': - inquote = TRUE; /* found first quote */ - continue; - case '{': /* found open { comment */ - incomment = TRUE; - continue; - case '(': - if (*dbp == '*') /* found open (* comment */ - { - incomment = TRUE; - dbp++; - } - else if (found_tag) /* found '(' after tag, i.e., parm-list */ - inparms = TRUE; - continue; - case ')': /* end of parms list */ - if (inparms) - inparms = FALSE; - continue; - case ';': - if (found_tag && !inparms) /* end of proc or fn stmt */ - { - verify_tag = TRUE; - break; - } - continue; - } - if (found_tag && verify_tag && (*dbp != ' ')) - { - /* check if this is an "extern" declaration */ - if (*dbp == '\0') - continue; - if (lowcase (*dbp == 'e')) - { - if (tail ("extern")) /* superfluous, really! */ - { - found_tag = FALSE; - verify_tag = FALSE; - } - } - else if (lowcase (*dbp) == 'f') - { - if (tail ("forward")) /* check for forward reference */ - { - found_tag = FALSE; - verify_tag = FALSE; - } - } - if (found_tag && verify_tag) /* not external proc, so make tag */ - { - found_tag = FALSE; - verify_tag = FALSE; - pfnote (namebuf, TRUE, - tline.buffer, save_len, save_lineno, save_lcno); - continue; - } - } - if (get_tagname) /* grab name of proc or fn */ - { - if (*dbp == '\0') - continue; - - /* save all values for later tagging */ - grow_linebuffer (&tline, strlen (lb.buffer) + 1); - strcpy (tline.buffer, lb.buffer); - save_lineno = lineno; - save_lcno = linecharno; - - /* grab block name */ - for (cp = dbp + 1; *cp && (!endtoken (*cp)); cp++) - continue; - namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL; - dbp = cp; /* set dbp to e-o-token */ - save_len = dbp - lb.buffer + 1; - get_tagname = FALSE; - found_tag = TRUE; - continue; - - /* and proceed to check for "extern" */ - } - else if (!incomment && !inquote && !found_tag) - { - /* check for proc/fn keywords */ - switch (lowcase (c)) - { - case 'p': - if (tail ("rocedure")) /* c = 'p', dbp has advanced */ - get_tagname = TRUE; - continue; - case 'f': - if (tail ("unction")) - get_tagname = TRUE; - continue; - } - } - } /* while not eof */ - - free (tline.buffer); -} - -/* - * lisp tag functions - * look for (def or (DEF, quote or QUOTE - */ -int -L_isdef (strp) - register char *strp; -{ - return ((strp[1] == 'd' || strp[1] == 'D') - && (strp[2] == 'e' || strp[2] == 'E') - && (strp[3] == 'f' || strp[3] == 'F')); -} - -int -L_isquote (strp) - register char *strp; -{ - return ((*(++strp) == 'q' || *strp == 'Q') - && (*(++strp) == 'u' || *strp == 'U') - && (*(++strp) == 'o' || *strp == 'O') - && (*(++strp) == 't' || *strp == 'T') - && (*(++strp) == 'e' || *strp == 'E') - && isspace(*(++strp))); -} - -void -L_getit () -{ - register char *cp; - - if (*dbp == '\'') /* Skip prefix quote */ - dbp++; - else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */ - { - dbp += 7; - while (isspace(*dbp)) - dbp++; - } - for (cp = dbp /*+1*/; - *cp && *cp != '(' && *cp != ' ' && *cp != ')'; - cp++) - continue; - if (cp == dbp) - return; - - pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE, - lb.buffer, cp - lb.buffer + 1, lineno, linecharno); -} - -void -Lisp_functions (inf) - FILE *inf; -{ - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - if (dbp[0] == '(') - { - if (L_isdef (dbp)) - { - while (!isspace (*dbp)) - dbp++; - while (isspace (*dbp)) - dbp++; - L_getit (); - } - else - { - /* Check for (foo::defmumble name-defined ... */ - do - dbp++; - while (*dbp && !isspace (*dbp) - && *dbp != ':' && *dbp != '(' && *dbp != ')'); - if (*dbp == ':') - { - do - dbp++; - while (*dbp == ':'); - - if (L_isdef (dbp - 1)) - { - while (!isspace (*dbp)) - dbp++; - while (isspace (*dbp)) - dbp++; - L_getit (); - } - } - } - } - } -} - -/* - * Scheme tag functions - * look for (def... xyzzy - * look for (def... (xyzzy - * look for (def ... ((...(xyzzy .... - * look for (set! xyzzy - */ - -void get_scheme (); - -void -Scheme_functions (inf) - FILE *inf; -{ - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - if (dbp[0] == '(' && - (dbp[1] == 'D' || dbp[1] == 'd') && - (dbp[2] == 'E' || dbp[2] == 'e') && - (dbp[3] == 'F' || dbp[3] == 'f')) - { - while (!isspace (*dbp)) - dbp++; - /* Skip over open parens and white space */ - while (*dbp && (isspace (*dbp) || *dbp == '(')) - dbp++; - get_scheme (); - } - if (dbp[0] == '(' && - (dbp[1] == 'S' || dbp[1] == 's') && - (dbp[2] == 'E' || dbp[2] == 'e') && - (dbp[3] == 'T' || dbp[3] == 't') && - (dbp[4] == '!' || dbp[4] == '!') && - (isspace (dbp[5]))) - { - while (!isspace (*dbp)) - dbp++; - /* Skip over white space */ - while (isspace (*dbp)) - dbp++; - get_scheme (); - } - } -} - -void -get_scheme () -{ - register char *cp; - - if (*dbp == '\0') - return; - /* Go till you get to white space or a syntactic break */ - for (cp = dbp + 1; - *cp && *cp != '(' && *cp != ')' && !isspace (*cp); - cp++) - continue; - pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE, - lb.buffer, cp - lb.buffer + 1, lineno, linecharno); -} - -/* Find tags in TeX and LaTeX input files. */ - -/* TEX_toktab is a table of TeX control sequences that define tags. - Each TEX_tabent records one such control sequence. - CONVERT THIS TO USE THE Stab TYPE!! */ -struct TEX_tabent -{ - char *name; - int len; -}; - -struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens */ - -/* Default set of control sequences to put into TEX_toktab. - The value of environment var TEXTAGS is prepended to this. */ - -char *TEX_defenv = "\ -:chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\ -:part:appendix:entry:index"; - -void TEX_mode (); -struct TEX_tabent *TEX_decode_env (); -int TEX_Token (); -#if TeX_named_tokens -void TEX_getit (); -#endif - -char TEX_esc = '\\'; -char TEX_opgrp = '{'; -char TEX_clgrp = '}'; - -/* - * TeX/LaTeX scanning loop. - */ -void -TeX_functions (inf) - FILE *inf; -{ - char *lasthit; - - lineno = 0; - charno = 0; - - /* Select either \ or ! as escape character. */ - TEX_mode (inf); - - /* Initialize token table once from environment. */ - if (!TEX_toktab) - TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv); - - while (!feof (inf)) - { /* Scan each line in file */ - lineno++; - linecharno = charno; - charno += readline (&lb, inf); - dbp = lb.buffer; - lasthit = dbp; - while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */ - { - register int i; - - if (!*(++dbp)) - break; - linecharno += dbp - lasthit; - lasthit = dbp; - i = TEX_Token (lasthit); - if (0 <= i) - { - pfnote ((char *)NULL, TRUE, - lb.buffer, strlen (lb.buffer), lineno, linecharno); -#if TeX_named_tokens - TEX_getit (lasthit, TEX_toktab[i].len); -#endif - break; /* We only save a line once */ - } - } - } -} - -#define TEX_LESC '\\' -#define TEX_SESC '!' -#define TEX_cmt '%' - -/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping - chars accordingly. */ -void -TEX_mode (inf) - FILE *inf; -{ - int c; - - while ((c = getc (inf)) != EOF) - { - /* Skip to next line if we hit the TeX comment char. */ - if (c == TEX_cmt) - while (c != '\n') - c = getc (inf); - else if (c == TEX_LESC || c == TEX_SESC ) - break; - } - - if (c == TEX_LESC) - { - TEX_esc = TEX_LESC; - TEX_opgrp = '{'; - TEX_clgrp = '}'; - } - else - { - TEX_esc = TEX_SESC; - TEX_opgrp = '<'; - TEX_clgrp = '>'; - } - rewind (inf); -} - -/* Read environment and prepend it to the default string. - Build token table. */ -struct TEX_tabent * -TEX_decode_env (evarname, defenv) - char *evarname; - char *defenv; -{ - register char *env, *p; - - struct TEX_tabent *tab; - int size, i; - - /* Append default string to environment. */ - env = getenv (evarname); - if (!env) - env = defenv; - else - env = concat (env, defenv, ""); - - /* Allocate a token table */ - for (size = 1, p = env; p;) - if ((p = etags_strchr (p, ':')) && *(++p)) - size++; - /* Add 1 to leave room for null terminator. */ - tab = xnew (size + 1, struct TEX_tabent); - - /* Unpack environment string into token table. Be careful about */ - /* zero-length strings (leading ':', "::" and trailing ':') */ - for (i = 0; *env;) - { - p = etags_strchr (env, ':'); - if (!p) /* End of environment string. */ - p = env + strlen (env); - if (p - env > 0) - { /* Only non-zero strings. */ - tab[i].name = savenstr (env, p - env); - tab[i].len = strlen (tab[i].name); - i++; - } - if (*p) - env = p + 1; - else - { - tab[i].name = NULL; /* Mark end of table. */ - tab[i].len = 0; - break; - } - } - return tab; -} - -#if TeX_named_tokens -/* Record a tag defined by a TeX command of length LEN and starting at NAME. - The name being defined actually starts at (NAME + LEN + 1). - But we seem to include the TeX command in the tag name. */ -void -TEX_getit (name, len) - char *name; - int len; -{ - char *p = name + len; - - if (*name == '\0') - return; - - /* Let tag name extend to next group close (or end of line) */ - while (*p && *p != TEX_clgrp) - p++; - pfnote (savenstr (name, p-name), TRUE, - lb.buffer, strlen (lb.buffer), lineno, linecharno); -} -#endif - -/* If the text at CP matches one of the tag-defining TeX command names, - return the pointer to the first occurrence of that command in TEX_toktab. - Otherwise return -1. - Keep the capital `T' in `Token' for dumb truncating compilers - (this distinguishes it from `TEX_toktab' */ -int -TEX_Token (cp) - char *cp; -{ - int i; - - for (i = 0; TEX_toktab[i].len > 0; i++) - if (strneq (TEX_toktab[i].name, cp, TEX_toktab[i].len)) - return i; - return -1; -} - -/* - * Prolog support (rewritten) by Anders Lindgren, Mar. 96 - * - * Assumes that the predicate starts at column 0. - * Only the first clause of a predicate is added. - */ -void -Prolog_functions (inf) - FILE *inf; -{ - int prolog_pred (); - void prolog_skip_comment (); - - char * last; - int len; - int allocated; - - allocated = 0; - len = 0; - last = NULL; - - lineno = 0; - linecharno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno += charno; - charno = readline (&lb, inf); - dbp = lb.buffer; - if (dbp[0] == '\0') /* Empty line */ - continue; - else if (isspace (dbp[0])) /* Not a predicate */ - continue; - else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */ - prolog_skip_comment (&lb, inf); - else if (len = prolog_pred (dbp, last)) - { - /* Predicate. Store the function name so that we only - generate a tag for the first clause. */ - if (last == NULL) - last = xnew(len + 1, char); - else if (len + 1 > allocated) - last = (char *) xrealloc(last, len + 1); - allocated = len + 1; - strncpy (last, dbp, len); - last[len] = '\0'; - } - } -} - - -void -prolog_skip_comment (plb, inf) - struct linebuffer *plb; - FILE *inf; -{ - char *cp; - - do - { - for (cp = plb->buffer; *cp != '\0'; cp++) - if (cp[0] == '*' && cp[1] == '/') - return; - lineno++; - linecharno += readline (plb, inf); - } - while (!feof(inf)); -} - -/* - * A predicate definition is added if it matches: - * <beginning of line><Prolog Atom><whitespace>( - * - * It is added to the tags database if it doesn't match the - * name of the previous clause header. - * - * Return the size of the name of the predicate, or 0 if no header - * was found. - */ -int -prolog_pred (s, last) - char *s; - char *last; /* Name of last clause. */ -{ - int prolog_atom(); - int prolog_white(); - - int pos; - int len; - - pos = prolog_atom(s, 0); - if (pos < 1) - return 0; - - len = pos; - pos += prolog_white(s, pos); - - if ((s[pos] == '(') || (s[pos] == '.')) - { - if (s[pos] == '(') - pos++; - - /* Save only the first clause. */ - if ((last == NULL) || - (len != strlen(last)) || - (strncmp(s, last, len) != 0)) - { - pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, - s, pos, lineno, linecharno); - return len; - } - } - return 0; -} - -/* - * Consume a Prolog atom. - * Return the number of bytes consumed, or -1 if there was an error. - * - * A prolog atom, in this context, could be one of: - * - An alphanumeric sequence, starting with a lower case letter. - * - A quoted arbitrary string. Single quotes can escape themselves. - * Backslash quotes everything. - */ -int -prolog_atom (s, pos) - char *s; - int pos; -{ - int origpos; - - origpos = pos; - - if (islower(s[pos]) || (s[pos] == '_')) - { - /* The atom is unquoted. */ - pos++; - while (isalnum(s[pos]) || (s[pos] == '_')) - { - pos++; - } - return pos - origpos; - } - else if (s[pos] == '\'') - { - pos++; - - while (1) - { - if (s[pos] == '\'') - { - pos++; - if (s[pos] != '\'') - break; - pos++; /* A double quote */ - } - else if (s[pos] == '\0') - /* Multiline quoted atoms are ignored. */ - return -1; - else if (s[pos] == '\\') - { - if (s[pos+1] == '\0') - return -1; - pos += 2; - } - else - pos++; - } - return pos - origpos; - } - else - return -1; -} - -/* Consume whitespace. Return the number of bytes eaten. */ -int -prolog_white (s, pos) - char *s; - int pos; -{ - int origpos; - - origpos = pos; - - while (isspace(s[pos])) - pos++; - - return pos - origpos; -} - -/* - * Support for Erlang -- Anders Lindgren, Feb 1996. - * - * Generates tags for functions, defines, and records. - * - * Assumes that Erlang functions start at column 0. - */ -void -Erlang_functions (inf) - FILE *inf; -{ - int erlang_func (); - void erlang_attribute (); - - char * last; - int len; - int allocated; - - allocated = 0; - len = 0; - last = NULL; - - lineno = 0; - linecharno = 0; - charno = 0; - - while (!feof (inf)) - { - lineno++; - linecharno += charno; - charno = readline (&lb, inf); - dbp = lb.buffer; - if (dbp[0] == '\0') /* Empty line */ - continue; - else if (isspace (dbp[0])) /* Not function nor attribute */ - continue; - else if (dbp[0] == '%') /* comment */ - continue; - else if (dbp[0] == '"') /* Sometimes, strings start in column one */ - continue; - else if (dbp[0] == '-') /* attribute, e.g. "-define" */ - { - erlang_attribute(dbp); - last = NULL; - } - else if (len = erlang_func (dbp, last)) - { - /* - * Function. Store the function name so that we only - * generates a tag for the first clause. - */ - if (last == NULL) - last = xnew(len + 1, char); - else if (len + 1 > allocated) - last = (char *) xrealloc(last, len + 1); - allocated = len + 1; - strncpy (last, dbp, len); - last[len] = '\0'; - } - } -} - - -/* - * A function definition is added if it matches: - * <beginning of line><Erlang Atom><whitespace>( - * - * It is added to the tags database if it doesn't match the - * name of the previous clause header. - * - * Return the size of the name of the function, or 0 if no function - * was found. - */ -int -erlang_func (s, last) - char *s; - char *last; /* Name of last clause. */ -{ - int erlang_atom (); - int erlang_white (); - - int pos; - int len; - - pos = erlang_atom(s, 0); - if (pos < 1) - return 0; - - len = pos; - pos += erlang_white(s, pos); - - if (s[pos++] == '(') - { - /* Save only the first clause. */ - if ((last == NULL) || - (len != strlen(last)) || - (strncmp(s, last, len) != 0)) - { - pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, - s, pos, lineno, linecharno); - return len; - } - } - return 0; -} - - -/* - * Handle attributes. Currently, tags are generated for defines - * and records. - * - * They are on the form: - * -define(foo, bar). - * -define(Foo(M, N), M+N). - * -record(graph, {vtab = notable, cyclic = true}). - */ -void -erlang_attribute (s) - char *s; -{ - int erlang_atom (); - int erlang_white (); - - int pos; - int len; - - if ((strncmp(s, "-define", 7) == 0) || - (strncmp(s, "-record", 7) == 0)) - { - pos = 7; - pos += erlang_white(s, pos); - - if (s[pos++] == '(') - { - pos += erlang_white(s, pos); - - if (len = erlang_atom(s, pos)) - { - pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE, - s, pos + len, lineno, linecharno); - } - } - } - return; -} - - -/* - * Consume an Erlang atom (or variable). - * Return the number of bytes consumed, or -1 if there was an error. - */ -int -erlang_atom (s, pos) - char *s; - int pos; -{ - int origpos; - - origpos = pos; - - if (isalpha (s[pos]) || s[pos] == '_') - { - /* The atom is unquoted. */ - pos++; - while (isalnum (s[pos]) || s[pos] == '_') - pos++; - return pos - origpos; - } - else if (s[pos] == '\'') - { - pos++; - - while (1) - { - if (s[pos] == '\'') - { - pos++; - break; - } - else if (s[pos] == '\0') - /* Multiline quoted atoms are ignored. */ - return -1; - else if (s[pos] == '\\') - { - if (s[pos+1] == '\0') - return -1; - pos += 2; - } - else - pos++; - } - return pos - origpos; - } - else - return -1; -} - -/* Consume whitespace. Return the number of bytes eaten */ -int -erlang_white (s, pos) - char *s; - int pos; -{ - int origpos; - - origpos = pos; - - while (isspace (s[pos])) - pos++; - - return pos - origpos; -} - -#ifdef ETAGS_REGEXPS -/* Take a string like "/blah/" and turn it into "blah", making sure - that the first and last characters are the same, and handling - quoted separator characters. Actually, stops on the occurrence of - an unquoted separator. Also turns "\t" into a Tab character. - Returns pointer to terminating separator. Works in place. Null - terminates name string. */ -char * -scan_separators (name) - char *name; -{ - char sep = name[0]; - char *copyto = name; - logical quoted = FALSE; - - for (++name; *name != '\0'; ++name) - { - if (quoted) - { - if (*name == 't') - *copyto++ = '\t'; - else if (*name == sep) - *copyto++ = sep; - else - { - /* Something else is quoted, so preserve the quote. */ - *copyto++ = '\\'; - *copyto++ = *name; - } - quoted = FALSE; - } - else if (*name == '\\') - quoted = TRUE; - else if (*name == sep) - break; - else - *copyto++ = *name; - } - - /* Terminate copied string. */ - *copyto = '\0'; - return name; -} - -/* Turn a name, which is an ed-style (but Emacs syntax) regular - expression, into a real regular expression by compiling it. */ -void -add_regex (regexp_pattern) - char *regexp_pattern; -{ - char *name; - const char *err; - struct re_pattern_buffer *patbuf; - - if (regexp_pattern == NULL) - { - /* Remove existing regexps. */ - num_patterns = 0; - patterns = NULL; - return; - } - - if (regexp_pattern[0] == '\0') - { - error ("missing regexp", (char *)NULL); - return; - } - if (regexp_pattern[strlen(regexp_pattern)-1] != regexp_pattern[0]) - { - error ("%s: unterminated regexp", regexp_pattern); - return; - } - name = scan_separators (regexp_pattern); - if (regexp_pattern[0] == '\0') - { - error ("null regexp", (char *)NULL); - return; - } - (void) scan_separators (name); - - patbuf = xnew (1, struct re_pattern_buffer); - patbuf->translate = NULL; - patbuf->fastmap = NULL; - patbuf->buffer = NULL; - patbuf->allocated = 0; - - err = re_compile_pattern (regexp_pattern, strlen (regexp_pattern), patbuf); - if (err != NULL) - { - error ("%s while compiling pattern", err); - return; - } - - num_patterns += 1; - if (num_patterns == 1) - patterns = xnew (1, struct pattern); - else - patterns = ((struct pattern *) - xrealloc (patterns, - (num_patterns * sizeof (struct pattern)))); - patterns[num_patterns - 1].pattern = patbuf; - patterns[num_patterns - 1].name_pattern = savestr (name); - patterns[num_patterns - 1].error_signaled = FALSE; -} - -/* - * Do the substitutions indicated by the regular expression and - * arguments. - */ -char * -substitute (in, out, regs) - char *in, *out; - struct re_registers *regs; -{ - char *result = NULL, *t; - int size = 0; - - /* Pass 1: figure out how much size to allocate. */ - for (t = out; *t; ++t) - { - if (*t == '\\') - { - ++t; - if (!*t) - { - fprintf (stderr, "%s: pattern substitution ends prematurely\n", - progname); - return NULL; - } - if (isdigit (*t)) - { - int dig = *t - '0'; - size += regs->end[dig] - regs->start[dig]; - } - } - } - - /* Allocate space and do the substitutions. */ - result = xnew (size + 1, char); - size = 0; - for (; *out; ++out) - { - if (*out == '\\') - { - ++out; - if (isdigit (*out)) - { - /* Using "dig2" satisfies my debugger. Bleah. */ - int dig2 = *out - '0'; - strncpy (result + size, in + regs->start[dig2], - regs->end[dig2] - regs->start[dig2]); - size += regs->end[dig2] - regs->start[dig2]; - } - else - result[size++] = *out; - } - else - result[size++] = *out; - } - result[size] = '\0'; - - return result; -} - -#endif /* ETAGS_REGEXPS */ -/* Initialize a linebuffer for use */ -void -initbuffer (linebuffer) - struct linebuffer *linebuffer; -{ - linebuffer->size = 200; - linebuffer->buffer = xnew (200, char); -} - -/* - * Read a line of text from `stream' into `linebuffer'. - * Return the number of characters read from `stream', - * which is the length of the line including the newline, if any. - */ -long -readline_internal (linebuffer, stream) - struct linebuffer *linebuffer; - register FILE *stream; -{ - char *buffer = linebuffer->buffer; - register char *p = linebuffer->buffer; - register char *pend; - int chars_deleted; - - pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */ - - while (1) - { - register int c = getc (stream); - if (p == pend) - { - linebuffer->size *= 2; - buffer = (char *) xrealloc (buffer, linebuffer->size); - p += buffer - linebuffer->buffer; - pend = buffer + linebuffer->size; - linebuffer->buffer = buffer; - } - if (c == EOF) - { - *p = '\0'; - chars_deleted = 0; - break; - } - if (c == '\n') - { - if (p > buffer && p[-1] == '\r') - { - *--p = '\0'; -#ifdef DOS_NT - /* Assume CRLF->LF translation will be performed by Emacs - when loading this file, so CRs won't appear in the buffer. - It would be cleaner to compensate within Emacs; - however, Emacs does not know how many CRs were deleted - before any given point in the file. */ - chars_deleted = 1; -#else - chars_deleted = 2; -#endif - } - else - { - *p = '\0'; - chars_deleted = 1; - } - break; - } - *p++ = c; - } - - return p - buffer + chars_deleted; -} - -/* - * Like readline_internal, above, but try to match the input - * line against any existing regular expressions. - */ -long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - FILE *stream; -{ - /* Read new line. */ - long result = readline_internal (linebuffer, stream); -#ifdef ETAGS_REGEXPS - int i; - - /* Match against all listed patterns. */ - for (i = 0; i < num_patterns; ++i) - { - int match = re_match (patterns[i].pattern, linebuffer->buffer, - (int)result, 0, &patterns[i].regs); - switch (match) - { - case -2: - /* Some error. */ - if (!patterns[i].error_signaled) - { - error ("error while matching pattern %d", i); - patterns[i].error_signaled = TRUE; - } - break; - case -1: - /* No match. */ - break; - default: - /* Match occurred. Construct a tag. */ - if (patterns[i].name_pattern[0] != '\0') - { - /* Make a named tag. */ - char *name = substitute (linebuffer->buffer, - patterns[i].name_pattern, - &patterns[i].regs); - if (name != NULL) - pfnote (name, TRUE, - linebuffer->buffer, match, lineno, linecharno); - } - else - { - /* Make an unnamed tag. */ - pfnote ((char *)NULL, TRUE, - linebuffer->buffer, match, lineno, linecharno); - } - break; - } - } -#endif /* ETAGS_REGEXPS */ - - return result; -} - -/* - * Read a file, but do no processing. This is used to do regexp - * matching on files that have no language defined. - */ -void -just_read_file (inf) - FILE *inf; -{ - lineno = 0; - charno = 0; - - while (!feof (inf)) - { - ++lineno; - linecharno = charno; - charno += readline (&lb, inf) + 1; - } -} - - -/* - * Return a pointer to a space of size strlen(cp)+1 allocated - * with xnew where the string CP has been copied. - */ -char * -savestr (cp) - char *cp; -{ - return savenstr (cp, strlen (cp)); -} - -/* - * Return a pointer to a space of size LEN+1 allocated with xnew where - * the string CP has been copied for at most the first LEN characters. - */ -char * -savenstr (cp, len) - char *cp; - int len; -{ - register char *dp; - - dp = xnew (len + 1, char); - strncpy (dp, cp, len); - dp[len] = '\0'; - return dp; -} - -/* - * Return the ptr in sp at which the character c last - * appears; NULL if not found - * - * Identical to System V strrchr, included for portability. - */ -char * -etags_strrchr (sp, c) - register char *sp, c; -{ - register char *r; - - r = NULL; - do - { - if (*sp == c) - r = sp; - } while (*sp++); - return r; -} - - -/* - * Return the ptr in sp at which the character c first - * appears; NULL if not found - * - * Identical to System V strchr, included for portability. - */ -char * -etags_strchr (sp, c) - register char *sp, c; -{ - do - { - if (*sp == c) - return sp; - } while (*sp++); - return NULL; -} - -/* Print error message and exit. */ -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (BAD); -} - -void -pfatal (s1) - char *s1; -{ - perror (s1); - exit (BAD); -} - -void -suggest_asking_for_help () -{ - fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n", - progname); - exit (BAD); -} - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ -void -error (s1, s2) - char *s1, *s2; -{ - fprintf (stderr, "%s: ", progname); - fprintf (stderr, s1, s2); - fprintf (stderr, "\n"); -} - -/* Return a newly-allocated string whose contents - concatenate those of s1, s2, s3. */ -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = xnew (len1 + len2 + len3 + 1, char); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - result[len1 + len2 + len3] = '\0'; - - return result; -} - -/* Does the same work as the system V getcwd, but does not need to - guess the buffer size in advance. */ -char * -etags_getcwd () -{ -#ifdef HAVE_GETCWD - int bufsize = 200; - char *path = xnew (bufsize, char); - - while (getcwd (path, bufsize) == NULL) - { - if (errno != ERANGE) - pfatal ("getcwd"); - bufsize *= 2; - path = xnew (bufsize, char); - } - -#if WINDOWSNT - { - /* Convert backslashes to slashes. */ - char *p; - for (p = path; *p != '\0'; p++) - if (*p == '\\') - *p = '/'; - } -#endif - - return path; - -#else /* not HAVE_GETCWD */ -#ifdef MSDOS - char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */ - - getwd (path); - - for (p = path; *p != '\0'; p++) - if (*p == '\\') - *p = '/'; - else - *p = lowcase (*p); - - return strdup (path); -#else /* not MSDOS */ - struct linebuffer path; - FILE *pipe; - - initbuffer (&path); - pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); - if (pipe == NULL || readline_internal (&path, pipe) == 0) - pfatal ("pwd"); - pclose (pipe); - - return path.buffer; -#endif /* not MSDOS */ -#endif /* not HAVE_GETCWD */ -} - -/* Return a newly allocated string containing the filename - of FILE relative to the absolute directory DIR (which - should end with a slash). */ -char * -relative_filename (file, dir) - char *file, *dir; -{ - char *fp, *dp, *abs, *res; - - /* Find the common root of file and dir (with a trailing slash). */ - abs = absolute_filename (file, cwd); - fp = abs; - dp = dir; - while (*fp++ == *dp++) - continue; - fp--, dp--; /* back to the first differing char */ - do /* look at the equal chars until / */ - fp--, dp--; - while (*fp != '/'); - - /* Build a sequence of "../" strings for the resulting relative filename. */ - for (dp = etags_strchr (dp + 1, '/'), res = ""; - dp != NULL; - dp = etags_strchr (dp + 1, '/')) - { - res = concat (res, "../", ""); - } - - /* Add the filename relative to the common root of file and dir. */ - res = concat (res, fp + 1, ""); - free (abs); - - return res; -} - -/* Return a newly allocated string containing the - absolute filename of FILE given CWD (which should - end with a slash). */ -char * -absolute_filename (file, cwd) - char *file, *cwd; -{ - char *slashp, *cp, *res; - - if (absolutefn (file)) - res = concat (file, "", ""); -#ifdef DOS_NT - /* We don't support non-absolute filenames with a drive - letter, like `d:NAME' (it's too much hassle). */ - else if (file[1] == ':') - fatal ("%s: relative filenames with drive letters not supported", file); -#endif - else - res = concat (cwd, file, ""); - - /* Delete the "/dirname/.." and "/." substrings. */ - slashp = etags_strchr (res, '/'); - while (slashp != NULL && slashp[0] != '\0') - { - if (slashp[1] == '.') - { - if (slashp[2] == '.' - && (slashp[3] == '/' || slashp[3] == '\0')) - { - cp = slashp; - do - cp--; - while (cp >= res && !absolutefn (cp)); - if (*cp == '/') - { - strcpy (cp, slashp + 3); - } -#ifdef DOS_NT - /* Under MSDOS and NT we get `d:/NAME' as absolute - filename, so the luser could say `d:/../NAME'. - We silently treat this as `d:/NAME'. */ - else if (cp[1] == ':') - strcpy (cp + 3, slashp + 4); -#endif - else /* else (cp == res) */ - { - if (slashp[3] != '\0') - strcpy (cp, slashp + 4); - else - return "."; - } - slashp = cp; - continue; - } - else if (slashp[2] == '/' || slashp[2] == '\0') - { - strcpy (slashp, slashp + 2); - continue; - } - } - - slashp = etags_strchr (slashp + 1, '/'); - } - - return res; -} - -/* Return a newly allocated string containing the absolute - filename of dir where FILE resides given CWD (which should - end with a slash). */ -char * -absolute_dirname (file, cwd) - char *file, *cwd; -{ - char *slashp, *res; - char save; -#ifdef DOS_NT - char *p; - - for (p = file; *p != '\0'; p++) - if (*p == '\\') - *p = '/'; -#endif - - slashp = etags_strrchr (file, '/'); - if (slashp == NULL) - return cwd; - save = slashp[1]; - slashp[1] = '\0'; - res = absolute_filename (file, cwd); - slashp[1] = save; - - return res; -} - -/* Increase the size of a linebuffer. */ -void -grow_linebuffer (bufp, toksize) - struct linebuffer *bufp; - int toksize; -{ - while (bufp->size < toksize) - bufp->size *= 2; - bufp->buffer = (char *) xrealloc (bufp->buffer, bufp->size); -} - -/* Like malloc but get fatal error if memory is exhausted. */ -long * -xmalloc (size) - unsigned int size; -{ - long *result = (long *) malloc (size); - if (result == NULL) - fatal ("virtual memory exhausted", (char *)NULL); - return result; -} - -long * -xrealloc (ptr, size) - char *ptr; - unsigned int size; -{ - long *result = (long *) realloc (ptr, size); - if (result == NULL) - fatal ("virtual memory exhausted", (char *)NULL); - return result; -} diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c deleted file mode 100644 index 1deeec352b2..00000000000 --- a/lib-src/fakemail.c +++ /dev/null @@ -1,751 +0,0 @@ -/* sendmail-like interface to /bin/mail for system V, - Copyright (C) 1985, 1994 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - - -#define NO_SHORTNAMES -#include <../src/config.h> - -#if defined (BSD_SYSTEM) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) -/* This program isnot used in BSD, so just avoid loader complaints. */ -int -main () -{ - return 0; -} -#else /* not BSD 4.2 (or newer) */ -#ifdef MSDOS -int -main () -{ - return 0; -} -#else /* not MSDOS */ -/* This conditional contains all the rest of the file. */ - -/* These are defined in config in some versions. */ - -#ifdef static -#undef static -#endif - -#ifdef read -#undef read -#undef write -#undef open -#undef close -#endif - -#ifdef WINDOWSNT -#include "ntlib.h" -#endif - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <time.h> -#include <pwd.h> - -/* Type definitions */ - -#define boolean int -#define true 1 -#define false 0 - -/* Various lists */ - -struct line_record -{ - char *string; - struct line_record *continuation; -}; -typedef struct line_record *line_list; - -struct header_record -{ - line_list text; - struct header_record *next; - struct header_record *previous; -}; -typedef struct header_record *header; - -struct stream_record -{ - FILE *handle; - int (*action)(); - struct stream_record *rest_streams; -}; -typedef struct stream_record *stream_list; - -/* A `struct linebuffer' is a structure which holds a line of text. - * `readline' reads a line from a stream into a linebuffer - * and works regardless of the length of the line. - */ - -struct linebuffer -{ - long size; - char *buffer; -}; - -struct linebuffer lb; - -#define new_list() \ - ((line_list) xmalloc (sizeof (struct line_record))) -#define new_header() \ - ((header) xmalloc (sizeof (struct header_record))) -#define new_stream() \ - ((stream_list) xmalloc (sizeof (struct stream_record))) -#define alloc_string(nchars) \ - ((char *) xmalloc ((nchars) + 1)) - -/* Global declarations */ - -#define BUFLEN 1024 -#define KEYWORD_SIZE 256 -#define FROM_PREFIX "From" -#define MY_NAME "fakemail" -#define NIL ((line_list) NULL) -#define INITIAL_LINE_SIZE 200 - -#ifndef MAIL_PROGRAM_NAME -#define MAIL_PROGRAM_NAME "/bin/mail" -#endif - -static char *my_name; -static char *the_date; -static char *the_user; -static line_list file_preface; -static stream_list the_streams; -static boolean no_problems = true; - -extern FILE *popen (); -extern int fclose (), pclose (); - -#ifdef CURRENT_USER -extern struct passwd *getpwuid (); -extern unsigned short geteuid (); -static struct passwd *my_entry; -#define cuserid(s) \ -(my_entry = getpwuid (((int) geteuid ())), \ - my_entry->pw_name) -#endif - -/* Utilities */ - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ - -static void -error (s1, s2) - char *s1, *s2; -{ - printf ("%s: ", my_name); - printf (s1, s2); - printf ("\n"); - no_problems = false; -} - -/* Print error message and exit. */ - -static void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -static long * -xmalloc (size) - int size; -{ - long *result = (long *) malloc (((unsigned) size)); - if (result == ((long *) NULL)) - fatal ("virtual memory exhausted", 0); - return result; -} - -static long * -xrealloc (ptr, size) - long *ptr; - int size; -{ - long *result = (long *) realloc (ptr, ((unsigned) size)); - if (result == ((long *) NULL)) - fatal ("virtual memory exhausted"); - return result; -} - -/* Initialize a linebuffer for use */ - -void -init_linebuffer (linebuffer) - struct linebuffer *linebuffer; -{ - linebuffer->size = INITIAL_LINE_SIZE; - linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); -} - -/* Read a line of text from `stream' into `linebuffer'. - * Return the length of the line. - */ - -long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - FILE *stream; -{ - char *buffer = linebuffer->buffer; - char *p = linebuffer->buffer; - char *end = p + linebuffer->size; - - while (true) - { - int c = getc (stream); - if (p == end) - { - linebuffer->size *= 2; - buffer = ((char *) xrealloc (buffer, linebuffer->size)); - p = buffer + (p - linebuffer->buffer); - end = buffer + linebuffer->size; - linebuffer->buffer = buffer; - } - if (c < 0 || c == '\n') - { - *p = 0; - break; - } - *p++ = c; - } - - return p - buffer; -} - -/* Extract a colon-terminated keyword from the string FIELD. - Return that keyword as a string stored in a static buffer. - Store the address of the rest of the string into *REST. - - If there is no keyword, return NULL and don't alter *REST. */ - -char * -get_keyword (field, rest) - register char *field; - char **rest; -{ - static char keyword[KEYWORD_SIZE]; - register char *ptr; - register char c; - - ptr = &keyword[0]; - c = *field++; - if (isspace (c) || c == ':') - return ((char *) NULL); - *ptr++ = (islower (c) ? toupper (c) : c); - while (((c = *field++) != ':') && ! isspace (c)) - *ptr++ = (islower (c) ? toupper (c) : c); - *ptr++ = '\0'; - while (isspace (c)) - c = *field++; - if (c != ':') - return ((char *) NULL); - *rest = field; - return &keyword[0]; -} - -/* Nonzero if the string FIELD starts with a colon-terminated keyword. */ - -boolean -has_keyword (field) - char *field; -{ - char *ignored; - return (get_keyword (field, &ignored) != ((char *) NULL)); -} - -/* Store the string FIELD, followed by any lines in THE_LIST, - into the buffer WHERE. - Concatenate lines, putting just a space between them. - Delete everything contained in parentheses. - When a recipient name contains <...>, we discard - everything except what is inside the <...>. - - We don't pay attention to overflowing WHERE; - the caller has to make it big enough. */ - -char * -add_field (the_list, field, where) - line_list the_list; - register char *field, *where; -{ - register char c; - while (true) - { - char *this_recipient_where; - int in_quotes = 0; - - *where++ = ' '; - this_recipient_where = where; - - while ((c = *field++) != '\0') - { - if (c == '\\') - *where++ = c; - else if (c == '"') - { - in_quotes = ! in_quotes; - *where++ = c; - } - else if (in_quotes) - *where++ = c; - else if (c == '(') - { - while (*field && *field != ')') ++field; - if (! (*field++)) break; /* no close */ - continue; - } - else if (c == ',') - { - *where++ = ' '; - /* When we get to the end of one recipient, - don't discard it if the next one has <...>. */ - this_recipient_where = where; - } - else if (c == '<') - /* Discard everything we got before the `<'. */ - where = this_recipient_where; - else if (c == '>') - /* Discard the rest of this name that follows the `>'. */ - { - while (*field && *field != ',') ++field; - if (! (*field++)) break; /* no comma */ - continue; - } - else - *where++ = c; - } - if (the_list == NIL) break; - field = the_list->string; - the_list = the_list->continuation; - } - return where; -} - -line_list -make_file_preface () -{ - char *the_string, *temp; - long idiotic_interface; - long prefix_length; - long user_length; - long date_length; - line_list result; - - prefix_length = strlen (FROM_PREFIX); - time (&idiotic_interface); - the_date = ctime (&idiotic_interface); - /* the_date has an unwanted newline at the end */ - date_length = strlen (the_date) - 1; - the_date[date_length] = '\0'; - temp = cuserid ((char *) NULL); - user_length = strlen (temp); - the_user = alloc_string (user_length + 1); - strcpy (the_user, temp); - the_string = alloc_string (3 + prefix_length + - user_length + - date_length); - temp = the_string; - strcpy (temp, FROM_PREFIX); - temp = &temp[prefix_length]; - *temp++ = ' '; - strcpy (temp, the_user); - temp = &temp[user_length]; - *temp++ = ' '; - strcpy (temp, the_date); - result = new_list (); - result->string = the_string; - result->continuation = ((line_list) NULL); - return result; -} - -void -write_line_list (the_list, the_stream) - register line_list the_list; - FILE *the_stream; -{ - for ( ; - the_list != ((line_list) NULL) ; - the_list = the_list->continuation) - { - fputs (the_list->string, the_stream); - putc ('\n', the_stream); - } - return; -} - -int -close_the_streams () -{ - register stream_list rem; - for (rem = the_streams; - rem != ((stream_list) NULL); - rem = rem->rest_streams) - no_problems = (no_problems && - ((*rem->action) (rem->handle) == 0)); - the_streams = ((stream_list) NULL); - return (no_problems ? 0 : 1); -} - -void -add_a_stream (the_stream, closing_action) - FILE *the_stream; - int (*closing_action)(); -{ - stream_list old = the_streams; - the_streams = new_stream (); - the_streams->handle = the_stream; - the_streams->action = closing_action; - the_streams->rest_streams = old; - return; -} - -int -my_fclose (the_file) - FILE *the_file; -{ - putc ('\n', the_file); - fflush (the_file); - return fclose (the_file); -} - -boolean -open_a_file (name) - char *name; -{ - FILE *the_stream = fopen (name, "a"); - if (the_stream != ((FILE *) NULL)) - { - add_a_stream (the_stream, my_fclose); - if (the_user == ((char *) NULL)) - file_preface = make_file_preface (); - write_line_list (file_preface, the_stream); - return true; - } - return false; -} - -void -put_string (s) - char *s; -{ - register stream_list rem; - for (rem = the_streams; - rem != ((stream_list) NULL); - rem = rem->rest_streams) - fputs (s, rem->handle); - return; -} - -void -put_line (string) - char *string; -{ - register stream_list rem; - for (rem = the_streams; - rem != ((stream_list) NULL); - rem = rem->rest_streams) - { - char *s = string; - int column = 0; - - /* Divide STRING into lines. */ - while (*s != 0) - { - char *breakpos; - - /* Find the last char that fits. */ - for (breakpos = s; *breakpos && column < 78; ++breakpos) - { - if (*breakpos == '\t') - column += 8; - else - column++; - } - /* If we didn't reach end of line, break the line. */ - if (*breakpos) - { - /* Back up to just after the last comma that fits. */ - while (breakpos != s && breakpos[-1] != ',') --breakpos; - - if (breakpos == s) - { - /* If no comma fits, move past the first address anyway. */ - while (*breakpos != 0 && *breakpos != ',') ++breakpos; - if (*breakpos != 0) - /* Include the comma after it. */ - ++breakpos; - } - } - /* Output that much, then break the line. */ - fwrite (s, 1, breakpos - s, rem->handle); - column = 8; - - /* Skip whitespace and prepare to print more addresses. */ - s = breakpos; - while (*s == ' ' || *s == '\t') ++s; - if (*s != 0) - fputs ("\n\t", rem->handle); - } - putc ('\n', rem->handle); - } - return; -} - -#define mail_error error - -/* Handle an FCC field. FIELD is the text of the first line (after - the header name), and THE_LIST holds the continuation lines if any. - Call open_a_file for each file. */ - -void -setup_files (the_list, field) - register line_list the_list; - register char *field; -{ - register char *start; - register char c; - while (true) - { - while (((c = *field) != '\0') - && (c == ' ' - || c == '\t' - || c == ',')) - field += 1; - if (c != '\0') - { - start = field; - while (((c = *field) != '\0') - && c != ' ' - && c != '\t' - && c != ',') - field += 1; - *field = '\0'; - if (!open_a_file (start)) - mail_error ("Could not open file %s", start); - *field = c; - if (c != '\0') continue; - } - if (the_list == ((line_list) NULL)) - return; - field = the_list->string; - the_list = the_list->continuation; - } -} - -/* Compute the total size of all recipient names stored in THE_HEADER. - The result says how big to make the buffer to pass to parse_header. */ - -int -args_size (the_header) - header the_header; -{ - register header old = the_header; - register line_list rem; - register int size = 0; - do - { - char *field; - register char *keyword = get_keyword (the_header->text->string, &field); - if ((strcmp (keyword, "TO") == 0) - || (strcmp (keyword, "CC") == 0) - || (strcmp (keyword, "BCC") == 0)) - { - size += 1 + strlen (field); - for (rem = the_header->text->continuation; - rem != NIL; - rem = rem->continuation) - size += 1 + strlen (rem->string); - } - the_header = the_header->next; - } while (the_header != old); - return size; -} - -/* Scan the header described by the lists THE_HEADER, - and put all recipient names into the buffer WHERE. - Precede each recipient name with a space. - - Also, if the header has any FCC fields, call setup_files for each one. */ - -parse_header (the_header, where) - header the_header; - register char *where; -{ - register header old = the_header; - do - { - char *field; - register char *keyword = get_keyword (the_header->text->string, &field); - if (strcmp (keyword, "TO") == 0) - where = add_field (the_header->text->continuation, field, where); - else if (strcmp (keyword, "CC") == 0) - where = add_field (the_header->text->continuation, field, where); - else if (strcmp (keyword, "BCC") == 0) - { - where = add_field (the_header->text->continuation, field, where); - the_header->previous->next = the_header->next; - the_header->next->previous = the_header->previous; - } - else if (strcmp (keyword, "FCC") == 0) - setup_files (the_header->text->continuation, field); - the_header = the_header->next; - } while (the_header != old); - *where = '\0'; - return; -} - -/* Read lines from the input until we get a blank line. - Create a list of `header' objects, one for each header field, - each of which points to a list of `line_list' objects, - one for each line in that field. - Continuation lines are grouped in the headers they continue. */ - -header -read_header () -{ - register header the_header = ((header) NULL); - register line_list *next_line = ((line_list *) NULL); - - init_linebuffer (&lb); - - do - { - long length; - register char *line; - - readline (&lb, stdin); - line = lb.buffer; - length = strlen (line); - if (length == 0) break; - - if (has_keyword (line)) - { - register header old = the_header; - the_header = new_header (); - if (old == ((header) NULL)) - { - the_header->next = the_header; - the_header->previous = the_header; - } - else - { - the_header->previous = old; - the_header->next = old->next; - old->next = the_header; - } - next_line = &(the_header->text); - } - - if (next_line == ((line_list *) NULL)) - { - /* Not a valid header */ - exit (1); - } - *next_line = new_list (); - (*next_line)->string = alloc_string (length); - strcpy (((*next_line)->string), line); - next_line = &((*next_line)->continuation); - *next_line = NIL; - - } while (true); - - return the_header->next; -} - -void -write_header (the_header) - header the_header; -{ - register header old = the_header; - do - { - register line_list the_list; - for (the_list = the_header->text; - the_list != NIL; - the_list = the_list->continuation) - put_line (the_list->string); - the_header = the_header->next; - } while (the_header != old); - put_line (""); - return; -} - -int -main (argc, argv) - int argc; - char **argv; -{ - char *command_line; - header the_header; - long name_length; - char *mail_program_name; - char buf[BUFLEN + 1]; - register int size; - FILE *the_pipe; - - extern char *getenv (); - - mail_program_name = getenv ("FAKEMAILER"); - if (!(mail_program_name && *mail_program_name)) - mail_program_name = MAIL_PROGRAM_NAME; - name_length = strlen (mail_program_name); - - my_name = MY_NAME; - the_streams = ((stream_list) NULL); - the_date = ((char *) NULL); - the_user = ((char *) NULL); - - the_header = read_header (); - command_line = alloc_string (name_length + args_size (the_header)); - strcpy (command_line, mail_program_name); - parse_header (the_header, &command_line[name_length]); - - the_pipe = popen (command_line, "w"); - if (the_pipe == ((FILE *) NULL)) - fatal ("cannot open pipe to real mailer"); - - add_a_stream (the_pipe, pclose); - - write_header (the_header); - - /* Dump the message itself */ - - while (!feof (stdin)) - { - size = fread (buf, 1, BUFLEN, stdin); - buf[size] = '\0'; - put_string (buf); - } - - exit (close_the_streams ()); -} - -#endif /* not MSDOS */ -#endif /* not BSD 4.2 (or newer) */ diff --git a/lib-src/hexl.c b/lib-src/hexl.c deleted file mode 100644 index 9731321d4ae..00000000000 --- a/lib-src/hexl.c +++ /dev/null @@ -1,262 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> -#ifdef DOS_NT -#include <fcntl.h> -#if __DJGPP__ >= 2 -#include <io.h> -#endif -#endif -#ifdef WINDOWSNT -#include <io.h> -#endif - -#define DEFAULT_GROUPING 0x01 -#define DEFAULT_BASE 16 - -#undef TRUE -#undef FALSE -#define TRUE (1) -#define FALSE (0) - -int base = DEFAULT_BASE, un_flag = FALSE, iso_flag = FALSE, endian = 1; -int group_by = DEFAULT_GROUPING; -char *progname; - -void usage(); - -int -main (argc, argv) - int argc; - char *argv[]; -{ - register long address; - char string[18]; - FILE *fp; - - progname = *argv++; --argc; - - /* - ** -hex hex dump - ** -oct Octal dump - ** -group-by-8-bits - ** -group-by-16-bits - ** -group-by-32-bits - ** -group-by-64-bits - ** -iso iso character set. - ** -big-endian Big Endian - ** -little-endian Little Endian - ** -un || -de from hexl format to binary. - ** -- End switch list. - ** <filename> dump filename - ** - (as filename == stdin) - */ - - while (*argv && *argv[0] == '-' && (*argv)[1]) - { - /* A switch! */ - if (!strcmp (*argv, "--")) - { - --argc; argv++; - break; - } - else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de")) - { - un_flag = TRUE; - --argc; argv++; - } - else if (!strcmp (*argv, "-hex")) - { - base = 16; - --argc; argv++; - } - else if (!strcmp (*argv, "-iso")) - { - iso_flag = TRUE; - --argc; argv++; - } - else if (!strcmp (*argv, "-oct")) - { - base = 8; - --argc; argv++; - } - else if (!strcmp (*argv, "-big-endian")) - { - endian = 1; - --argc; argv++; - } - else if (!strcmp (*argv, "-little-endian")) - { - endian = 0; - --argc; argv++; - } - else if (!strcmp (*argv, "-group-by-8-bits")) - { - group_by = 0x00; - --argc; argv++; - } - else if (!strcmp (*argv, "-group-by-16-bits")) - { - group_by = 0x01; - --argc; argv++; - } - else if (!strcmp (*argv, "-group-by-32-bits")) - { - group_by = 0x03; - --argc; argv++; - } - else if (!strcmp (*argv, "-group-by-64-bits")) - { - group_by = 0x07; - endian = 0; - --argc; argv++; - } - else - { - fprintf (stderr, "%s: invalid switch: \"%s\".\n", progname, - *argv); - usage (); - } - } - - do - { - if (*argv == NULL) - fp = stdin; - else - { - char *filename = *argv++; - - if (!strcmp (filename, "-")) - fp = stdin; - else if ((fp = fopen (filename, "r")) == NULL) - { - perror (filename); - continue; - } - } - - if (un_flag) - { - char buf[18]; - -#ifdef DOS_NT -#if (__DJGPP__ >= 2) || (defined WINDOWSNT) - if (!isatty (fileno (stdout))) - setmode (fileno (stdout), O_BINARY); -#else - (stdout)->_flag &= ~_IOTEXT; /* print binary */ - _setmode (fileno (stdout), O_BINARY); -#endif -#endif - for (;;) - { - register int i, c, d; - -#define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) - - fread (buf, 1, 10, fp); /* skip 10 bytes */ - - for (i=0; i < 16; ++i) - { - if ((c = getc (fp)) == ' ' || c == EOF) - break; - - d = getc (fp); - c = hexchar (c) * 0x10 + hexchar (d); - putchar (c); - - if ((i&group_by) == group_by) - getc (fp); - } - - if (c == ' ') - { - while ((c = getc (fp)) != '\n' && c != EOF) - ; - - if (c == EOF) - break; - } - else - { - if (i < 16) - break; - - fread (buf, 1, 18, fp); /* skip 18 bytes */ - } - } - } - else - { -#ifdef DOS_NT -#if (__DJGPP__ >= 2) || (defined WINDOWSNT) - if (!isatty (fileno (fp))) - setmode (fileno (fp), O_BINARY); -#else - (fp)->_flag &= ~_IOTEXT; /* read binary */ - _setmode (fileno (fp), O_BINARY); -#endif -#endif - address = 0; - string[0] = ' '; - string[17] = '\0'; - for (;;) - { - register int i, c; - - for (i=0; i < 16; ++i) - { - if ((c = getc (fp)) == EOF) - { - if (!i) - break; - - fputs (" ", stdout); - string[i+1] = '\0'; - } - else - { - if (!i) - printf ("%08x: ", address); - - if (iso_flag) - string[i+1] = - (c < 0x20 || (c >= 0x7F && c < 0xa0)) ? '.' :c; - else - string[i+1] = (c < 0x20 || c >= 0x7F) ? '.' : c; - - printf ("%02x", c); - } - - if ((i&group_by) == group_by) - putchar (' '); - } - - if (i) - puts (string); - - if (c == EOF) - break; - - address += 0x10; - - } - } - - if (fp != stdin) - fclose (fp); - - } while (*argv != NULL); - return 0; -} - -void -usage () -{ - fprintf (stderr, "usage: %s [-de] [-iso]\n", progname); - exit (1); -} diff --git a/lib-src/leditcfns.c b/lib-src/leditcfns.c deleted file mode 100644 index b8a7a6bfe1f..00000000000 --- a/lib-src/leditcfns.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <sgtty.h> -#include <signal.h> -#define STRLEN 100 -static char str[STRLEN+1] = "%?emacs"; /* extra char for the null */ - -switch_to_proc(){ - char *ptr = str; - while (*ptr) ioctl(0, TIOCSTI, ptr++); - ioctl(0, TIOCSTI, "\n"); - kill(getpid(), SIGTSTP); - } - -set_proc_str(ptr) char *ptr; { - if (strlen(ptr) <= STRLEN) - strcpy(str, ptr); - else - printf("string too long for set-proc-str: %s\n", ptr); - } diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c deleted file mode 100644 index b0072672114..00000000000 --- a/lib-src/make-docfile.c +++ /dev/null @@ -1,887 +0,0 @@ -/* Generate doc-string file for GNU Emacs from source files. - Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* The arguments given to this program are all the C and Lisp source files - of GNU Emacs. .elc and .el and .c files are allowed. - A .o file can also be specified; the .c file it was made from is used. - This helps the makefile pass the correct list of files. - - The results, which go to standard output or to a file - specified with -a or -o (-a to append, -o to start from nothing), - are entries containing function or variable names and their documentation. - Each entry starts with a ^_ character. - Then comes F for a function or V for a variable. - Then comes the function or variable name, terminated with a newline. - Then comes the documentation for that function or variable. - */ - -#define NO_SHORTNAMES /* Tell config not to load remap.h */ -#include <../src/config.h> - -#include <stdio.h> -#ifdef MSDOS -#include <fcntl.h> -#endif /* MSDOS */ -#ifdef WINDOWSNT -#include <stdlib.h> -#include <fcntl.h> -#include <direct.h> -#endif /* WINDOWSNT */ - -#ifdef DOS_NT -#define READ_TEXT "rt" -#define READ_BINARY "rb" -#else /* not DOS_NT */ -#define READ_TEXT "r" -#define READ_BINARY "r" -#endif /* not DOS_NT */ - -int scan_file (); -int scan_lisp_file (); -int scan_c_file (); - -#ifdef MSDOS -/* s/msdos.h defines this as sys_chdir, but we're not linking with the - file where that function is defined. */ -#undef chdir -#endif - -/* Stdio stream for output to the DOC file. */ -FILE *outfile; - -/* Name this program was invoked with. */ -char *progname; - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ - -/* VARARGS1 */ -void -error (s1, s2) - char *s1, *s2; -{ - fprintf (stderr, "%s: ", progname); - fprintf (stderr, s1, s2); - fprintf (stderr, "\n"); -} - -/* Print error message and exit. */ - -/* VARARGS1 */ -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -long * -xmalloc (size) - unsigned int size; -{ - long *result = (long *) malloc (size); - if (result == NULL) - fatal ("virtual memory exhausted", 0); - return result; -} - -int -main (argc, argv) - int argc; - char **argv; -{ - int i; - int err_count = 0; - int first_infile; - - progname = argv[0]; - - outfile = stdout; - - /* Don't put CRs in the DOC file. */ -#ifdef MSDOS - _fmode = O_BINARY; -#if 0 /* Suspicion is that this causes hanging. - So instead we require people to use -o on MSDOS. */ - (stdout)->_flag &= ~_IOTEXT; - _setmode (fileno (stdout), O_BINARY); -#endif - outfile = 0; -#endif /* MSDOS */ -#ifdef WINDOWSNT - _fmode = O_BINARY; - _setmode (fileno (stdout), O_BINARY); -#endif /* WINDOWSNT */ - - /* If first two args are -o FILE, output to FILE. */ - i = 1; - if (argc > i + 1 && !strcmp (argv[i], "-o")) - { - outfile = fopen (argv[i + 1], "w"); - i += 2; - } - if (argc > i + 1 && !strcmp (argv[i], "-a")) - { - outfile = fopen (argv[i + 1], "a"); - i += 2; - } - if (argc > i + 1 && !strcmp (argv[i], "-d")) - { - chdir (argv[i + 1]); - i += 2; - } - - if (outfile == 0) - fatal ("No output file specified", ""); - - first_infile = i; - for (; i < argc; i++) - { - int j; - /* Don't process one file twice. */ - for (j = first_infile; j < i; j++) - if (! strcmp (argv[i], argv[j])) - break; - if (j == i) - err_count += scan_file (argv[i]); - } -#ifndef VMS - exit (err_count > 0); -#endif /* VMS */ - return err_count > 0; -} - -/* Read file FILENAME and output its doc strings to outfile. */ -/* Return 1 if file is not found, 0 if it is found. */ - -int -scan_file (filename) - char *filename; -{ - int len = strlen (filename); - if (len > 4 && !strcmp (filename + len - 4, ".elc")) - return scan_lisp_file (filename, READ_BINARY); - else if (len > 3 && !strcmp (filename + len - 3, ".el")) - return scan_lisp_file (filename, READ_TEXT); - else - return scan_c_file (filename, READ_TEXT); -} - -char buf[128]; - -/* Skip a C string from INFILE, - and return the character that follows the closing ". - If printflag is positive, output string contents to outfile. - If it is negative, store contents in buf. - Convert escape sequences \n and \t to newline and tab; - discard \ followed by newline. */ - -int -read_c_string (infile, printflag) - FILE *infile; - int printflag; -{ - register int c; - char *p = buf; - - c = getc (infile); - while (c != EOF) - { - while (c != '"' && c != EOF) - { - if (c == '\\') - { - c = getc (infile); - if (c == '\n') - { - c = getc (infile); - continue; - } - if (c == 'n') - c = '\n'; - if (c == 't') - c = '\t'; - } - if (printflag > 0) - putc (c, outfile); - else if (printflag < 0) - *p++ = c; - c = getc (infile); - } - c = getc (infile); - if (c != '"') - break; - /* If we had a "", concatenate the two strings. */ - c = getc (infile); - } - - if (printflag < 0) - *p = 0; - - return c; -} - -/* Write to file OUT the argument names of function FUNC, whose text is in BUF. - MINARGS and MAXARGS are the minimum and maximum number of arguments. */ - -void -write_c_args (out, func, buf, minargs, maxargs) - FILE *out; - char *func, *buf; - int minargs, maxargs; -{ - register char *p; - int in_ident = 0; - int just_spaced = 0; - int need_space = 1; - - fprintf (out, "(%s", func); - - if (*buf == '(') - ++buf; - - for (p = buf; *p; p++) - { - char c = *p; - int ident_start = 0; - - /* Notice when we start printing a new identifier. */ - if ((('A' <= c && c <= 'Z') - || ('a' <= c && c <= 'z') - || ('0' <= c && c <= '9') - || c == '_') - != in_ident) - { - if (!in_ident) - { - in_ident = 1; - ident_start = 1; - - if (need_space) - putc (' ', out); - - if (minargs == 0 && maxargs > 0) - fprintf (out, "&optional "); - just_spaced = 1; - - minargs--; - maxargs--; - } - else - in_ident = 0; - } - - /* Print the C argument list as it would appear in lisp: - print underscores as hyphens, and print commas as spaces. - Collapse adjacent spaces into one. */ - if (c == '_') c = '-'; - if (c == ',') c = ' '; - - /* In C code, `default' is a reserved word, so we spell it - `defalt'; unmangle that here. */ - if (ident_start - && strncmp (p, "defalt", 6) == 0 - && ! (('A' <= p[6] && p[6] <= 'Z') - || ('a' <= p[6] && p[6] <= 'z') - || ('0' <= p[6] && p[6] <= '9') - || p[6] == '_')) - { - fprintf (out, "DEFAULT"); - p += 5; - in_ident = 0; - just_spaced = 0; - } - else if (c != ' ' || ! just_spaced) - { - if (c >= 'a' && c <= 'z') - /* Upcase the letter. */ - c += 'A' - 'a'; - putc (c, out); - } - - just_spaced = (c == ' '); - need_space = 0; - } -} - -/* Read through a c file. If a .o file is named, - the corresponding .c file is read instead. - Looks for DEFUN constructs such as are defined in ../src/lisp.h. - Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ - -int -scan_c_file (filename, mode) - char *filename, *mode; -{ - FILE *infile; - register int c; - register int commas; - register int defunflag; - register int defvarperbufferflag; - register int defvarflag; - int minargs, maxargs; - int extension = filename[strlen (filename) - 1]; - - if (extension == 'o') - filename[strlen (filename) - 1] = 'c'; - - infile = fopen (filename, mode); - - /* No error if non-ex input file */ - if (infile == NULL) - { - perror (filename); - return 0; - } - - /* Reset extension to be able to detect duplicate files. */ - filename[strlen (filename) - 1] = extension; - - c = '\n'; - while (!feof (infile)) - { - if (c != '\n') - { - c = getc (infile); - continue; - } - c = getc (infile); - if (c == ' ') - { - while (c == ' ') - c = getc (infile); - if (c != 'D') - continue; - c = getc (infile); - if (c != 'E') - continue; - c = getc (infile); - if (c != 'F') - continue; - c = getc (infile); - if (c != 'V') - continue; - c = getc (infile); - if (c != 'A') - continue; - c = getc (infile); - if (c != 'R') - continue; - c = getc (infile); - if (c != '_') - continue; - - defvarflag = 1; - defunflag = 0; - - c = getc (infile); - defvarperbufferflag = (c == 'P'); - - c = getc (infile); - } - else if (c == 'D') - { - c = getc (infile); - if (c != 'E') - continue; - c = getc (infile); - if (c != 'F') - continue; - c = getc (infile); - defunflag = c == 'U'; - defvarflag = 0; - } - else continue; - - while (c != '(') - { - if (c < 0) - goto eof; - c = getc (infile); - } - - c = getc (infile); - if (c != '"') - continue; - c = read_c_string (infile, -1); - - if (defunflag) - commas = 5; - else if (defvarperbufferflag) - commas = 2; - else if (defvarflag) - commas = 1; - else /* For DEFSIMPLE and DEFPRED */ - commas = 2; - - while (commas) - { - if (c == ',') - { - commas--; - if (defunflag && (commas == 1 || commas == 2)) - { - do - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\t'); - if (c < 0) - goto eof; - ungetc (c, infile); - if (commas == 2) /* pick up minargs */ - fscanf (infile, "%d", &minargs); - else /* pick up maxargs */ - if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ - maxargs = -1; - else - fscanf (infile, "%d", &maxargs); - } - } - if (c < 0) - goto eof; - c = getc (infile); - } - while (c == ' ' || c == '\n' || c == '\t') - c = getc (infile); - if (c == '"') - c = read_c_string (infile, 0); - while (c != ',') - c = getc (infile); - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\t') - c = getc (infile); - - if (c == '"') - { - putc (037, outfile); - putc (defvarflag ? 'V' : 'F', outfile); - fprintf (outfile, "%s\n", buf); - c = read_c_string (infile, 1); - - /* If this is a defun, find the arguments and print them. If - this function takes MANY or UNEVALLED args, then the C source - won't give the names of the arguments, so we shouldn't bother - trying to find them. */ - if (defunflag && maxargs != -1) - { - char argbuf[1024], *p = argbuf; - while (c != ')') - { - if (c < 0) - goto eof; - c = getc (infile); - } - /* Skip into arguments. */ - while (c != '(') - { - if (c < 0) - goto eof; - c = getc (infile); - } - /* Copy arguments into ARGBUF. */ - *p++ = c; - do - *p++ = c = getc (infile); - while (c != ')'); - *p = '\0'; - /* Output them. */ - fprintf (outfile, "\n\n"); - write_c_args (outfile, buf, argbuf, minargs, maxargs); - } - } - } - eof: - fclose (infile); - return 0; -} - -/* Read a file of Lisp code, compiled or interpreted. - Looks for - (defun NAME ARGS DOCSTRING ...) - (defmacro NAME ARGS DOCSTRING ...) - (autoload (quote NAME) FILE DOCSTRING ...) - (defvar NAME VALUE DOCSTRING) - (defconst NAME VALUE DOCSTRING) - (fset (quote NAME) (make-byte-code ... DOCSTRING ...)) - (fset (quote NAME) #[... DOCSTRING ...]) - (defalias (quote NAME) #[... DOCSTRING ...]) - starting in column zero. - (quote NAME) may appear as 'NAME as well. - - We also look for #@LENGTH CONTENTS^_ at the beginning of the line. - When we find that, we save it for the following defining-form, - and we use that instead of reading a doc string within that defining-form. - - For defun, defmacro, and autoload, we know how to skip over the arglist. - For defvar, defconst, and fset we skip to the docstring with a kludgy - formatting convention: all docstrings must appear on the same line as the - initial open-paren (the one in column zero) and must contain a backslash - and a double-quote immediately after the initial double-quote. No newlines - must appear between the beginning of the form and the first double-quote. - The only source file that must follow this convention is loaddefs.el; aside - from that, it is always the .elc file that we look at, and they are no - problem because byte-compiler output follows this convention. - The NAME and DOCSTRING are output. - NAME is preceded by `F' for a function or `V' for a variable. - An entry is output only if DOCSTRING has \ newline just after the opening " - */ - -void -skip_white (infile) - FILE *infile; -{ - char c = ' '; - while (c == ' ' || c == '\t' || c == '\n') - c = getc (infile); - ungetc (c, infile); -} - -void -read_lisp_symbol (infile, buffer) - FILE *infile; - char *buffer; -{ - char c; - char *fillp = buffer; - - skip_white (infile); - while (1) - { - c = getc (infile); - if (c == '\\') - *(++fillp) = getc (infile); - else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')') - { - ungetc (c, infile); - *fillp = 0; - break; - } - else - *fillp++ = c; - } - - if (! buffer[0]) - fprintf (stderr, "## expected a symbol, got '%c'\n", c); - - skip_white (infile); -} - -int -scan_lisp_file (filename, mode) - char *filename, *mode; -{ - FILE *infile; - register int c; - char *saved_string = 0; - - infile = fopen (filename, mode); - if (infile == NULL) - { - perror (filename); - return 0; /* No error */ - } - - c = '\n'; - while (!feof (infile)) - { - char buffer[BUFSIZ]; - char type; - - if (c != '\n') - { - c = getc (infile); - continue; - } - c = getc (infile); - /* Detect a dynamic doc string and save it for the next expression. */ - if (c == '#') - { - c = getc (infile); - if (c == '@') - { - int length = 0; - int i; - - /* Read the length. */ - while ((c = getc (infile), - c >= '0' && c <= '9')) - { - length *= 10; - length += c - '0'; - } - - /* The next character is a space that is counted in the length - but not part of the doc string. - We already read it, so just ignore it. */ - length--; - - /* Read in the contents. */ - if (saved_string != 0) - free (saved_string); - saved_string = (char *) malloc (length); - for (i = 0; i < length; i++) - saved_string[i] = getc (infile); - /* The last character is a ^_. - That is needed in the .elc file - but it is redundant in DOC. So get rid of it here. */ - saved_string[length - 1] = 0; - /* Skip the newline. */ - c = getc (infile); - while (c != '\n') - c = getc (infile); - } - continue; - } - - if (c != '(') - continue; - - read_lisp_symbol (infile, buffer); - - if (! strcmp (buffer, "defun") || - ! strcmp (buffer, "defmacro")) - { - type = 'F'; - read_lisp_symbol (infile, buffer); - - /* Skip the arguments: either "nil" or a list in parens */ - - c = getc (infile); - if (c == 'n') /* nil */ - { - if ((c = getc (infile)) != 'i' || - (c = getc (infile)) != 'l') - { - fprintf (stderr, "## unparsable arglist in %s (%s)\n", - buffer, filename); - continue; - } - } - else if (c != '(') - { - fprintf (stderr, "## unparsable arglist in %s (%s)\n", - buffer, filename); - continue; - } - else - while (c != ')') - c = getc (infile); - skip_white (infile); - - /* If the next three characters aren't `dquote bslash newline' - then we're not reading a docstring. - */ - if ((c = getc (infile)) != '"' || - (c = getc (infile)) != '\\' || - (c = getc (infile)) != '\n') - { -#ifdef DEBUG - fprintf (stderr, "## non-docstring in %s (%s)\n", - buffer, filename); -#endif - continue; - } - } - - else if (! strcmp (buffer, "defvar") || - ! strcmp (buffer, "defconst")) - { - char c1 = 0, c2 = 0; - type = 'V'; - read_lisp_symbol (infile, buffer); - - if (saved_string == 0) - { - - /* Skip until the first newline; remember the two previous chars. */ - while (c != '\n' && c >= 0) - { - c2 = c1; - c1 = c; - c = getc (infile); - } - - /* If two previous characters were " and \, - this is a doc string. Otherwise, there is none. */ - if (c2 != '"' || c1 != '\\') - { -#ifdef DEBUG - fprintf (stderr, "## non-docstring in %s (%s)\n", - buffer, filename); -#endif - continue; - } - } - } - - else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias")) - { - char c1 = 0, c2 = 0; - type = 'F'; - - c = getc (infile); - if (c == '\'') - read_lisp_symbol (infile, buffer); - else - { - if (c != '(') - { - fprintf (stderr, "## unparsable name in fset in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - if (strcmp (buffer, "quote")) - { - fprintf (stderr, "## unparsable name in fset in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - c = getc (infile); - if (c != ')') - { - fprintf (stderr, - "## unparsable quoted name in fset in %s\n", - filename); - continue; - } - } - - if (saved_string == 0) - { - /* Skip until the first newline; remember the two previous chars. */ - while (c != '\n' && c >= 0) - { - c2 = c1; - c1 = c; - c = getc (infile); - } - - /* If two previous characters were " and \, - this is a doc string. Otherwise, there is none. */ - if (c2 != '"' || c1 != '\\') - { -#ifdef DEBUG - fprintf (stderr, "## non-docstring in %s (%s)\n", - buffer, filename); -#endif - continue; - } - } - } - - else if (! strcmp (buffer, "autoload")) - { - type = 'F'; - c = getc (infile); - if (c == '\'') - read_lisp_symbol (infile, buffer); - else - { - if (c != '(') - { - fprintf (stderr, "## unparsable name in autoload in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - if (strcmp (buffer, "quote")) - { - fprintf (stderr, "## unparsable name in autoload in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - c = getc (infile); - if (c != ')') - { - fprintf (stderr, - "## unparsable quoted name in autoload in %s\n", - filename); - continue; - } - } - skip_white (infile); - if ((c = getc (infile)) != '\"') - { - fprintf (stderr, "## autoload of %s unparsable (%s)\n", - buffer, filename); - continue; - } - read_c_string (infile, 0); - skip_white (infile); - - if (saved_string == 0) - { - /* If the next three characters aren't `dquote bslash newline' - then we're not reading a docstring. */ - if ((c = getc (infile)) != '"' || - (c = getc (infile)) != '\\' || - (c = getc (infile)) != '\n') - { -#ifdef DEBUG - fprintf (stderr, "## non-docstring in %s (%s)\n", - buffer, filename); -#endif - continue; - } - } - } - -#ifdef DEBUG - else if (! strcmp (buffer, "if") || - ! strcmp (buffer, "byte-code")) - ; -#endif - - else - { -#ifdef DEBUG - fprintf (stderr, "## unrecognised top-level form, %s (%s)\n", - buffer, filename); -#endif - continue; - } - - /* At this point, we should either use the previous - dynamic doc string in saved_string - or gobble a doc string from the input file. - - In the latter case, the opening quote (and leading - backslash-newline) have already been read. */ - - putc (037, outfile); - putc (type, outfile); - fprintf (outfile, "%s\n", buffer); - if (saved_string) - { - fputs (saved_string, outfile); - /* Don't use one dynamic doc string twice. */ - free (saved_string); - saved_string = 0; - } - else - read_c_string (infile, 1); - } - fclose (infile); - return 0; -} diff --git a/lib-src/make-path.c b/lib-src/make-path.c deleted file mode 100644 index c4e5bf93144..00000000000 --- a/lib-src/make-path.c +++ /dev/null @@ -1,105 +0,0 @@ -/* Make all the directories along a path. - Copyright (C) 1992 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* This program works like mkdir, except that it generates - intermediate directories if they don't exist. This is just like - the `mkdir -p' command on most systems; unfortunately, the mkdir - command on some of the purer BSD systems (like Mt. Xinu) don't have - that option. */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <stdio.h> -#include <errno.h> - -extern int errno; - -char *prog_name; - -/* Create directory DIRNAME if it does not exist already. - Then give permission for everyone to read and search it. - Return 0 if successful, 1 if not. */ - -int -touchy_mkdir (dirname) - char *dirname; -{ - struct stat buf; - - /* If DIRNAME already exists and is a directory, don't create. */ - if (! (stat (dirname, &buf) >= 0 - && (buf.st_mode & S_IFMT) == S_IFDIR)) - { - /* Otherwise, try to make it. If DIRNAME exists but isn't a directory, - this will signal an error. */ - if (mkdir (dirname, 0777) < 0) - { - fprintf (stderr, "%s: ", prog_name); - perror (dirname); - return 1; - } - } - - /* Make sure everyone can look at this directory. */ - if (stat (dirname, &buf) < 0) - { - fprintf (stderr, "%s: ", prog_name); - perror (dirname); - return 1; - } - if (chmod (dirname, 0555 | (buf.st_mode & 0777)) < 0) - { - fprintf (stderr, "%s: ", prog_name); - perror (dirname); - } - - return 0; -} - -int -main (argc, argv) - int argc; - char **argv; -{ - prog_name = *argv; - - for (argc--, argv++; argc > 0; argc--, argv++) - { - char *dirname = *argv; - int i; - - /* Stop at each slash in dirname and try to create the directory. - Skip any initial slash. */ - for (i = (dirname[0] == '/') ? 1 : 0; dirname[i]; i++) - if (dirname[i] == '/') - { - dirname[i] = '\0'; - if (touchy_mkdir (dirname) < 0) - goto next_dirname; - dirname[i] = '/'; - } - - touchy_mkdir (dirname); - - next_dirname: - ; - } - - return 0; -} diff --git a/lib-src/makefile.nt b/lib-src/makefile.nt deleted file mode 100644 index 29bb209b1ad..00000000000 --- a/lib-src/makefile.nt +++ /dev/null @@ -1,357 +0,0 @@ -# Makefile for GNU Emacs lib-src directory. -# Geoff Voelker (voelker@cs.washington.edu) -# Copyright (C) 1994 Free Software Foundation, Inc. -# -# This file is part of GNU Emacs. -# -# GNU Emacs is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# GNU Emacs is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Emacs; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. -# - -# -# Sets up the system dependent macros. -# -!include ..\nt\makefile.def - -LOCAL_FLAGS = -DWINDOWSNT -DDOS_NT -DSTDC_HEADERS=1 -DNO_LDAV=1 -DNO_ARCHIVES=1 -I..\nt\inc -I..\src - -LINK_FLAGS = $(ARCH_LDFLAGS) -debug:PARTIAL -machine:$(ARCH) -subsystem:console -entry:mainCRTStartup setargv.obj - -ALL = $(BLD)\make-docfile.exe \ - $(BLD)\hexl.exe \ - $(BLD)\ctags.exe \ - $(BLD)\etags.exe \ - $(BLD)\movemail.exe \ - $(BLD)\fakemail.exe \ - - -# don't know what (if) to do with these yet... -# -# $(BLD)\sorted-doc.exe \ -# $(BLD)\env.exe \ -# $(BLD)\server.exe \ -# $(BLD)\emacstool.exe \ -# $(BLD)\leditcfns.exe \ -# $(BLD)\emacsclient.exe \ -# $(BLD)\cvtmail.exe \ -# $(BLD)\digest-doc.exe \ -# $(BLD)\test-distrib.exe \ - - -LIBS = $(BASE_LIBS) - -$(BLD)\make-docfile.exe: $(BLD)\make-docfile.obj $(BLD)\ntlib.obj - $(LINK) -out:$@ $(LINK_FLAGS) $(BLD)\make-docfile.obj $(BLD)\ntlib.obj $(LIBS) -$(BLD)\hexl.exe: $(BLD)\hexl.obj -$(BLD)\movemail.exe: $(BLD)\movemail.obj $(BLD)\pop.obj $(BLD)\ntlib.obj - $(LINK) -out:$@ $(LINK_FLAGS) -debug:FULL $(BLD)\movemail.obj $(BLD)\pop.obj $(BLD)\ntlib.obj $(LIBS) wsock32.lib -$(BLD)\fakemail.exe: $(BLD)\fakemail.obj $(BLD)\ntlib.obj - $(LINK) -out:$@ $(LINK_FLAGS) -debug:full $(BLD)\fakemail.obj $(BLD)\ntlib.obj $(LIBS) - -make-docfile: $(BLD) $(BLD)\make-docfile.exe -etags: $(BLD) $(BLD)\etags.exe -hexl: $(BLD) $(BLD)\hexl.exe -movemail: $(BLD) $(BLD)\movemail.exe -fakemail: $(BLD) $(BLD)\fakemail.exe - -ETAGSOBJ = $(BLD)\etags.obj \ - $(BLD)\getopt.obj \ - $(BLD)\getopt1.obj \ - $(BLD)\ntlib.obj \ - $(BLD)\regex.obj \ - $(BLD)\alloca.obj - - -$(BLD)\etags.exe: $(ETAGSOBJ) - $(LINK) -out:$@ $(LINK_FLAGS) $(ETAGSOBJ) $(LIBS) - - -$(BLD)\regex.obj: ../src/regex.c ../src/regex.h ../src/config.h - $(CC) $(CFLAGS) -DCONFIG_BROKETS -DINHIBIT_STRING_HEADER \ - ../src/regex.c -Fo$@ - -ETAGS_CFLAGS = -DETAGS_REGEXPS -DHAVE_GETCWD -$(BLD)\etags.obj: etags.c - $(CC) $(CFLAGS) $(ETAGS_CFLAGS) -Fo$@ etags.c - -CTAGSOBJ = $(BLD)\ctags.obj \ - $(BLD)\getopt.obj \ - $(BLD)\getopt1.obj \ - $(BLD)\ntlib.obj \ - $(BLD)\regex.obj \ - $(BLD)\alloca.obj - -$(BLD)\ctags.exe: ctags.c $(CTAGSOBJ) - $(LINK) -out:$@ $(LINK_FLAGS) $(CTAGSOBJ) $(LIBS) - -ctags.c: etags.c - - $(DEL) ctags.c - copy etags.c ctags.c - -CTAGS_CFLAGS = -DCTAGS $(ETAGS_CFLAGS) -$(BLD)\ctags.obj: ctags.c - $(CC) $(CFLAGS) $(CTAGS_CFLAGS) -Fo$@ ctags.c - -# -# don't know what to do with these yet... -# -# $(BLD)\sorted-doc.exe: $(BLD)\sorted-doc.obj -# $(BLD)\yow.exe: $(BLD)\yow.obj -# $(BLD)\emacstool.exe: $(BLD)\emacstool.obj -# $(BLD)\leditcfns.exe: $(BLD)\leditcfns.obj -# $(BLD)\server.exe: $(BLD)\server.obj -# $(BLD)\cvtmail.exe: $(BLD)\cvtmail.obj -# $(BLD)\digest-doc.exe: $(BLD)\digest-doc.obj -# $(BLD)\emacsclient.exe: $(BLD)\emacsclient.obj -# $(BLD)\test-distrib.exe: $(BLD)\test-distrib.obj - -# -# From ..\src\makefile.nt. -# -obj = abbrev.c alloc.c alloca.c buffer.c bytecode.c callint.c callproc.c casefiddle.c cm.c cmds.c data.c dired.c dispnew.c doc.c doprnt.c editfns.c eval.c fileio.c filelock.c filemode.c fns.c indent.c insdel.c keyboard.c keymap.c lastfile.c lread.c macros.c marker.c minibuf.c xfaces.c mocklisp.c nt.c ntheap.c ntinevt.c ntproc.c ntterm.c print.c process.c regex.c scroll.c search.c syntax.c sysdep.c term.c termcap.c tparam.c undo.c unexnt.c window.c xdisp.c casetab.c floatfns.c frame.c gmalloc.c intervals.c ralloc.c textprop.c vm-limit.c region-cache.c strftime.c w32term.c w32xfns.c w32fns.c w32faces.c w32select.c w32menu.c w32reg.c - -lispdir = ..\lisp - -# -# These are the lisp files that are loaded up in loadup.el -# -lisp= \ - $(lispdir)\subr.elc \ - $(lispdir)\byte-run.elc \ - $(lispdir)\map-ynp.elc \ - $(lispdir)\loaddefs.el \ - $(lispdir)\simple.elc \ - $(lispdir)\help.elc \ - $(lispdir)\files.elc \ - $(lispdir)\format.elc \ - $(lispdir)\indent.elc \ - $(lispdir)\window.elc \ - $(lispdir)\frame.elc \ - $(lispdir)\mouse.elc \ - $(lispdir)\menu-bar.elc \ - $(lispdir)\scroll-bar.elc \ - $(lispdir)\select.elc \ - $(lispdir)\paths.el \ - $(lispdir)\startup.elc \ - $(lispdir)\lisp.elc \ - $(lispdir)\page.elc \ - $(lispdir)\register.elc \ - $(lispdir)\paragraphs.elc \ - $(lispdir)\lisp-mode.elc \ - $(lispdir)\text-mode.elc \ - $(lispdir)\fill.elc \ - $(lispdir)\c-mode.elc \ - $(lispdir)\isearch.elc \ - $(lispdir)\replace.elc \ - $(lispdir)\abbrev.elc \ - $(lispdir)\buff-menu.elc \ - $(lispdir)\ls-lisp.elc \ - $(lispdir)\winnt.elc \ - $(lispdir)\float-sup.elc \ - $(lispdir)\vc-hooks.elc \ - $(lispdir)\version.el \ - $(lispdir)\dos-nt.elc - -DOC = DOC -$(DOC): $(BLD)\make-docfile.exe - - $(DEL) $(DOC) - $(BLD)\make-docfile -d ..\src $(obj) > $(DOC) - $(BLD)\make-docfile -d ..\src $(lisp) >> $(DOC) - $(CP) $(DOC) ..\etc\DOC-X - - mkdir ..\src\$(OBJDIR) - - mkdir ..\src\$(OBJDIR)\etc - $(CP) $(DOC) ..\src\$(OBJDIR)\etc\DOC-X - -{$(BLD)}.obj{$(BLD)}.exe: - $(LINK) -out:$@ $(LINK_FLAGS) $*.obj $(LIBS) - -.c{$(BLD)}.obj: - $(CC) $(CFLAGS) -Fo$@ $< - -# -# Build the executables -# -all: $(BLD) $(ALL) $(DOC) - -# -# Assuming INSTALL_DIR is defined, build and install emacs in it. -# -INSTALL_FILES = $(ALL) -install: $(INSTALL_FILES) - - mkdir $(INSTALL_DIR)\bin - $(CP) $(BLD)\etags.exe $(INSTALL_DIR)\bin - $(CP) $(BLD)\ctags.exe $(INSTALL_DIR)\bin - $(CP) $(BLD)\hexl.exe $(INSTALL_DIR)\bin - $(CP) $(BLD)\movemail.exe $(INSTALL_DIR)\bin - $(CP) $(BLD)\fakemail.exe $(INSTALL_DIR)\bin - - mkdir $(INSTALL_DIR)\etc - $(CP) $(DOC) $(INSTALL_DIR)\etc - -# -# Maintenance -# -clean:; - $(DEL) *~ *.pdb DOC* - - $(DEL_TREE) deleted - - $(DEL_TREE) $(OBJDIR) - -# -# Headers we would preprocess if we could. -# -..\src\config.h: ..\nt\$(CONFIG_H) - $(CP) $** $@ -..\src\paths.h: ..\nt\paths.h - $(CP) $** $@ - -### DEPENDENCIES ### - -EMACS_ROOT = .. -SRC = . - -$(BLD)\alloca.obj : \ - $(SRC)\alloca.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\src\config.h \ - $(EMACS_ROOT)\src\blockinput.h - -$(BLD)\b2m.obj : \ - $(SRC)\b2m.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h - -$(BLD)\cvtmail.obj : \ - $(SRC)\cvtmail.c - -$(BLD)\digest-doc.obj : \ - $(SRC)\digest-doc.c - -$(BLD)\emacsclient.obj : \ - $(SRC)\emacsclient.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h - -$(BLD)\emacsserver.obj : \ - $(SRC)\emacsserver.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h \ - $(EMACS_ROOT)\nt\inc\sys\file.h - -$(BLD)\emacstool.obj : \ - $(SRC)\emacstool.c \ - $(EMACS_ROOT)\nt\inc\sys\file.h - -$(BLD)\etags.obj : \ - $(SRC)\etags.c \ - $(EMACS_ROOT)\nt\inc\sys\param.h \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h \ - $(SRC)\getopt.h - -$(BLD)\fakemail.obj : \ - $(SRC)\fakemail.c \ - $(SRC)\ntlib.h \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h \ - $(EMACS_ROOT)\nt\inc\pwd.h - -$(BLD)\getdate.obj : \ - $(SRC)\getdate.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\src\config.h \ - $(MSTOOLS_SYS)\types.h - -$(BLD)\getopt.obj : \ - $(SRC)\getopt.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\src\config.h \ - $(SRC)\getopt.h - -$(BLD)\getopt1.obj : \ - $(SRC)\getopt1.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\src\config.h \ - $(SRC)\getopt.h - -$(BLD)\hexl.obj : \ - $(SRC)\hexl.c - -$(BLD)\leditcfns.obj : \ - $(SRC)\leditcfns.c - -$(BLD)\make-docfile.obj : \ - $(SRC)\make-docfile.c \ - $(EMACS_ROOT)\src\config.h - -$(BLD)\make-path.obj : \ - $(SRC)\make-path.c - -$(BLD)\movemail.obj : \ - $(SRC)\movemail.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h \ - $(EMACS_ROOT)\nt\inc\sys\file.h \ - $(EMACS_ROOT)\src\vmsproc.h \ - $(EMACS_ROOT)\lib-src\..\src\syswait.h \ - $(EMACS_ROOT)\nt\inc\pwd.h - $(CC) $(CFLAGS) -DUSG -Fo$@ movemail.c - -$(BLD)\ntlib.obj : \ - $(SRC)\ntlib.c \ - $(SRC)\ntlib.h \ - $(EMACS_ROOT)\nt\inc\pwd.h - -$(BLD)\pop.obj : \ - $(SRC)\pop.c \ - $(SRC)\pop.h \ - $(SRC)\ntlib.h - -$(BLD)\profile.obj : \ - $(SRC)\profile.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h \ - $(EMACS_ROOT)\src\vmstime.h \ - $(EMACS_ROOT)\lib-src\..\src\systime.h - -$(BLD)\qsort.obj : \ - $(SRC)\qsort.c - -$(BLD)\sorted-doc.obj : \ - $(SRC)\sorted-doc.c - -$(BLD)\tcp.obj : \ - $(SRC)\tcp.c - -$(BLD)\test-distrib.obj : \ - $(SRC)\test-distrib.c - -$(BLD)\timer.obj : \ - $(SRC)\timer.c \ - $(EMACS_ROOT)\src\s\windowsnt.h \ - $(EMACS_ROOT)\src\m\intel386.h \ - $(EMACS_ROOT)\lib-src\..\src\config.h - -$(BLD)\yow.obj : \ - $(SRC)\yow.c \ - $(EMACS_ROOT)\lib-src\..\src\paths.h diff --git a/lib-src/movemail.c b/lib-src/movemail.c deleted file mode 100644 index 79ea6dcabab..00000000000 --- a/lib-src/movemail.c +++ /dev/null @@ -1,752 +0,0 @@ -/* movemail foo bar -- move file foo to file bar, - locking file foo the way /bin/mail respects. - Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will - cause loss of mail* if you do it on a system that does not normally - use flock as its way of interlocking access to inbox files. The - setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the - system's own conventions. It is not a choice that is up to you. - - So, if your system uses lock files rather than flock, then the only way - you can get proper operation is to enable movemail to write lockfiles there. - This means you must either give that directory access modes - that permit everyone to write lockfiles in it, or you must make movemail - a setuid or setgid program. */ - -/* - * Modified January, 1986 by Michael R. Gretzinger (Project Athena) - * - * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP - * movemail will accept input filename arguments of the form - * "po:username". This will cause movemail to open a connection to - * a pop server running on $MAILHOST (environment variable). Movemail - * must be setuid to root in order to work with POP. - * - * New module: popmail.c - * Modified routines: - * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ()) - * after POP code. - * New routines in movemail.c: - * get_errmsg - return pointer to system error message - * - * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies) - * - * Move all of the POP code into a separate file, "pop.c". - * Use strerror instead of get_errmsg. - * - */ - -#define NO_SHORTNAMES /* Tell config not to load remap.h */ -#include <../src/config.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include <stdio.h> -#include <errno.h> -#include <../src/syswait.h> -#ifdef MAIL_USE_POP -#include "pop.h" -#endif - -#ifdef MSDOS -#undef access -#endif /* MSDOS */ - -#ifndef DIRECTORY_SEP -#define DIRECTORY_SEP '/' -#endif -#ifndef IS_DIRECTORY_SEP -#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) -#endif - -#ifdef WINDOWSNT -#undef access -#undef unlink -#define fork() 0 -#define sys_wait(var) (*(var) = 0) -/* Unfortunately, Samba doesn't seem to properly lock Unix files even - though the locking call succeeds (and indeed blocks local access from - other NT programs). If you have direct file access using an NFS - client or something other than Samba, the locking call might work - properly - make sure it does before you enable this! */ -#define DISABLE_DIRECT_ACCESS -#endif /* WINDOWSNT */ - -#ifdef USG -#include <fcntl.h> -#include <unistd.h> -#ifndef F_OK -#define F_OK 0 -#define X_OK 1 -#define W_OK 2 -#define R_OK 4 -#endif -#endif /* USG */ - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#if defined (XENIX) || defined (WINDOWSNT) -#include <sys/locking.h> -#endif - -#ifdef MAIL_USE_LOCKF -#define MAIL_USE_SYSTEM_LOCK -#endif - -#ifdef MAIL_USE_FLOCK -#define MAIL_USE_SYSTEM_LOCK -#endif - -#ifdef MAIL_USE_MMDF -extern int lk_open (), lk_close (); -#endif - -/* Cancel substitutions made by config.h for Emacs. */ -#undef open -#undef read -#undef write -#undef close - -#ifndef errno -extern int errno; -#endif -char *strerror (); - -void fatal (); -void error (); -void pfatal_with_name (); -void pfatal_and_delete (); -char *concat (); -long *xmalloc (); -int popmail (); -int pop_retr (); -int mbx_write (); -int mbx_delimit_begin (); -int mbx_delimit_end (); - -/* Nonzero means this is name of a lock file to delete on fatal error. */ -char *delete_lockname; - -int -main (argc, argv) - int argc; - char **argv; -{ - char *inname, *outname; - int indesc, outdesc; - int nread; - WAITTYPE status; - -#ifndef MAIL_USE_SYSTEM_LOCK - struct stat st; - long now; - int tem; - char *lockname, *p; - char *tempname; - int desc; -#endif /* not MAIL_USE_SYSTEM_LOCK */ - - delete_lockname = 0; - - if (argc < 3) - { - fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n"); - exit(1); - } - - inname = argv[1]; - outname = argv[2]; - -#ifdef MAIL_USE_MMDF - mmdf_init (argv[0]); -#endif - - if (*outname == 0) - fatal ("Destination file name is empty", 0); - - /* Check access to output file. */ - if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) - pfatal_with_name (outname); - - /* Also check that outname's directory is writable to the real uid. */ - { - char *buf = (char *) xmalloc (strlen (outname) + 1); - char *p; - strcpy (buf, outname); - p = buf + strlen (buf); - while (p > buf && !IS_DIRECTORY_SEP (p[-1])) - *--p = 0; - if (p == buf) - *p++ = '.'; - if (access (buf, W_OK) != 0) - pfatal_with_name (buf); - free (buf); - } - -#ifdef MAIL_USE_POP - if (!strncmp (inname, "po:", 3)) - { - int status; - - status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL); - exit (status); - } - - setuid (getuid ()); -#endif /* MAIL_USE_POP */ - -#ifndef DISABLE_DIRECT_ACCESS - - /* Check access to input file. */ - if (access (inname, R_OK | W_OK) != 0) - pfatal_with_name (inname); - -#ifndef MAIL_USE_MMDF -#ifndef MAIL_USE_SYSTEM_LOCK - /* Use a lock file named after our first argument with .lock appended: - If it exists, the mail file is locked. */ - /* Note: this locking mechanism is *required* by the mailer - (on systems which use it) to prevent loss of mail. - - On systems that use a lock file, extracting the mail without locking - WILL occasionally cause loss of mail due to timing errors! - - So, if creation of the lock file fails - due to access permission on the mail spool directory, - you simply MUST change the permission - and/or make movemail a setgid program - so it can create lock files properly. - - You might also wish to verify that your system is one - which uses lock files for this purpose. Some systems use other methods. - - If your system uses the `flock' system call for mail locking, - define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file - and recompile movemail. If the s- file for your system - should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report - to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ - - lockname = concat (inname, ".lock", ""); - tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); - strcpy (tempname, inname); - p = tempname + strlen (tempname); - while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) - p--; - *p = 0; - strcpy (p, "EXXXXXX"); - mktemp (tempname); - unlink (tempname); - - while (1) - { - /* Create the lock file, but not under the lock file name. */ - /* Give up if cannot do that. */ - desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666); - if (desc < 0) - { - char *message = (char *) xmalloc (strlen (tempname) + 50); - sprintf (message, "%s--see source file lib-src/movemail.c", - tempname); - pfatal_with_name (message); - } - close (desc); - - tem = link (tempname, lockname); - unlink (tempname); - if (tem >= 0) - break; - sleep (1); - - /* If lock file is five minutes old, unlock it. - Five minutes should be good enough to cope with crashes - and wedgitude, and long enough to avoid being fooled - by time differences between machines. */ - if (stat (lockname, &st) >= 0) - { - now = time (0); - if (st.st_ctime < now - 300) - unlink (lockname); - } - } - - delete_lockname = lockname; -#endif /* not MAIL_USE_SYSTEM_LOCK */ -#endif /* not MAIL_USE_MMDF */ - - if (fork () == 0) - { - int lockcount = 0; - int status; - - setuid (getuid ()); - -#ifndef MAIL_USE_MMDF -#ifdef MAIL_USE_SYSTEM_LOCK - indesc = open (inname, O_RDWR); -#else /* if not MAIL_USE_SYSTEM_LOCK */ - indesc = open (inname, O_RDONLY); -#endif /* not MAIL_USE_SYSTEM_LOCK */ -#else /* MAIL_USE_MMDF */ - indesc = lk_open (inname, O_RDONLY, 0, 0, 10); -#endif /* MAIL_USE_MMDF */ - - if (indesc < 0) - pfatal_with_name (inname); - -#if defined (BSD_SYSTEM) || defined (XENIX) - /* In case movemail is setuid to root, make sure the user can - read the output file. */ - /* This is desirable for all systems - but I don't want to assume all have the umask system call */ - umask (umask (0) & 0333); -#endif /* BSD_SYSTEM || XENIX */ - outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); - if (outdesc < 0) - pfatal_with_name (outname); - - /* This label exists so we can retry locking - after a delay, if it got EAGAIN or EBUSY. */ - retry_lock: - - /* Try to lock it. */ -#ifdef MAIL_USE_SYSTEM_LOCK -#ifdef MAIL_USE_LOCKF - status = lockf (indesc, F_LOCK, 0); -#else /* not MAIL_USE_LOCKF */ -#ifdef XENIX - status = locking (indesc, LK_RLCK, 0L); -#else -#ifdef WINDOWSNT - status = locking (indesc, LK_RLCK, -1L); -#else - status = flock (indesc, LOCK_EX); -#endif -#endif -#endif /* not MAIL_USE_LOCKF */ -#endif /* MAIL_USE_SYSTEM_LOCK */ - - /* If it fails, retry up to 5 times - for certain failure codes. */ - if (status < 0) - { - if (++lockcount <= 5) - { -#ifdef EAGAIN - if (errno == EAGAIN) - { - sleep (1); - goto retry_lock; - } -#endif -#ifdef EBUSY - if (errno == EBUSY) - { - sleep (1); - goto retry_lock; - } -#endif - } - - pfatal_with_name (inname); - } - - { - char buf[1024]; - - while (1) - { - nread = read (indesc, buf, sizeof buf); - if (nread != write (outdesc, buf, nread)) - { - int saved_errno = errno; - unlink (outname); - errno = saved_errno; - pfatal_with_name (outname); - } - if (nread < sizeof buf) - break; - } - } - -#ifdef BSD_SYSTEM - if (fsync (outdesc) < 0) - pfatal_and_delete (outname); -#endif - - /* Check to make sure no errors before we zap the inbox. */ - if (close (outdesc) != 0) - pfatal_and_delete (outname); - -#ifdef MAIL_USE_SYSTEM_LOCK -#if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT) - /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ - close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); -#else - ftruncate (indesc, 0L); -#endif /* STRIDE or XENIX */ -#endif /* MAIL_USE_SYSTEM_LOCK */ - -#ifdef MAIL_USE_MMDF - lk_close (indesc, 0, 0, 0); -#else - close (indesc); -#endif - -#ifndef MAIL_USE_SYSTEM_LOCK - /* Delete the input file; if we can't, at least get rid of its - contents. */ -#ifdef MAIL_UNLINK_SPOOL - /* This is generally bad to do, because it destroys the permissions - that were set on the file. Better to just empty the file. */ - if (unlink (inname) < 0 && errno != ENOENT) -#endif /* MAIL_UNLINK_SPOOL */ - creat (inname, 0600); -#endif /* not MAIL_USE_SYSTEM_LOCK */ - - exit (0); - } - - wait (&status); - if (!WIFEXITED (status)) - exit (1); - else if (WRETCODE (status) != 0) - exit (WRETCODE (status)); - -#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) - unlink (lockname); -#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ - -#endif /* ! DISABLE_DIRECT_ACCESS */ - - return 0; -} - -/* Print error message and exit. */ - -void -fatal (s1, s2) - char *s1, *s2; -{ - if (delete_lockname) - unlink (delete_lockname); - error (s1, s2); - exit (1); -} - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ - -void -error (s1, s2, s3) - char *s1, *s2, *s3; -{ - fprintf (stderr, "movemail: "); - fprintf (stderr, s1, s2, s3); - fprintf (stderr, "\n"); -} - -void -pfatal_with_name (name) - char *name; -{ - char *s = concat ("", strerror (errno), " for %s"); - fatal (s, name); -} - -void -pfatal_and_delete (name) - char *name; -{ - char *s = concat ("", strerror (errno), " for %s"); - unlink (name); - fatal (s, name); -} - -/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ - -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = (char *) xmalloc (len1 + len2 + len3 + 1); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - *(result + len1 + len2 + len3) = 0; - - return result; -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -long * -xmalloc (size) - unsigned size; -{ - long *result = (long *) malloc (size); - if (!result) - fatal ("virtual memory exhausted", 0); - return result; -} - -/* This is the guts of the interface to the Post Office Protocol. */ - -#ifdef MAIL_USE_POP - -#ifndef WINDOWSNT -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#else -#undef _WINSOCKAPI_ -#include <winsock.h> -#endif -#include <stdio.h> -#include <pwd.h> - -#ifdef USG -#include <fcntl.h> -/* Cancel substitutions made by config.h for Emacs. */ -#undef open -#undef read -#undef write -#undef close -#endif /* USG */ - -#define NOTOK (-1) -#define OK 0 -#define DONE 1 - -char *progname; -FILE *sfi; -FILE *sfo; -char ibuffer[BUFSIZ]; -char obuffer[BUFSIZ]; -char Errmsg[80]; - -popmail (user, outfile, password) - char *user; - char *outfile; - char *password; -{ - int nmsgs, nbytes; - register int i; - int mbfi; - FILE *mbf; - char *getenv (); - int mbx_write (); - popserver server; - extern char *strerror (); - - server = pop_open (0, user, password, POP_NO_GETPASS); - if (! server) - { - error (pop_error); - return (1); - } - - if (pop_stat (server, &nmsgs, &nbytes)) - { - error (pop_error); - return (1); - } - - if (!nmsgs) - { - pop_close (server); - return (0); - } - - mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); - if (mbfi < 0) - { - pop_close (server); - error ("Error in open: %s, %s", strerror (errno), outfile); - return (1); - } - fchown (mbfi, getuid (), -1); - - if ((mbf = fdopen (mbfi, "wb")) == NULL) - { - pop_close (server); - error ("Error in fdopen: %s", strerror (errno)); - close (mbfi); - unlink (outfile); - return (1); - } - - for (i = 1; i <= nmsgs; i++) - { - mbx_delimit_begin (mbf); - if (pop_retr (server, i, mbx_write, mbf) != OK) - { - error (Errmsg); - close (mbfi); - return (1); - } - mbx_delimit_end (mbf); - fflush (mbf); - if (ferror (mbf)) - { - error ("Error in fflush: %s", strerror (errno)); - pop_close (server); - close (mbfi); - return (1); - } - } - - /* On AFS, a call to write only modifies the file in the local - * workstation's AFS cache. The changes are not written to the server - * until a call to fsync or close is made. Users with AFS home - * directories have lost mail when over quota because these checks were - * not made in previous versions of movemail. */ - -#ifdef BSD_SYSTEM - if (fsync (mbfi) < 0) - { - error ("Error in fsync: %s", strerror (errno)); - return (1); - } -#endif - - if (close (mbfi) == -1) - { - error ("Error in close: %s", strerror (errno)); - return (1); - } - - for (i = 1; i <= nmsgs; i++) - { - if (pop_delete (server, i)) - { - error (pop_error); - pop_close (server); - return (1); - } - } - - if (pop_quit (server)) - { - error (pop_error); - return (1); - } - - return (0); -} - -pop_retr (server, msgno, action, arg) - popserver server; - int (*action)(); -{ - extern char *strerror (); - char *line; - int ret; - - if (pop_retrieve_first (server, msgno, &line)) - { - strncpy (Errmsg, pop_error, sizeof (Errmsg)); - Errmsg[sizeof (Errmsg)-1] = '\0'; - return (NOTOK); - } - - while (! (ret = pop_retrieve_next (server, &line))) - { - if (! line) - break; - - if ((*action)(line, arg) != OK) - { - strcpy (Errmsg, strerror (errno)); - pop_close (server); - return (NOTOK); - } - } - - if (ret) - { - strncpy (Errmsg, pop_error, sizeof (Errmsg)); - Errmsg[sizeof (Errmsg)-1] = '\0'; - return (NOTOK); - } - - return (OK); -} - -/* Do this as a macro instead of using strcmp to save on execution time. */ -#define IS_FROM_LINE(a) ((a[0] == 'F') \ - && (a[1] == 'r') \ - && (a[2] == 'o') \ - && (a[3] == 'm') \ - && (a[4] == ' ')) - -int -mbx_write (line, mbf) - char *line; - FILE *mbf; -{ - if (IS_FROM_LINE (line)) - { - if (fputc ('>', mbf) == EOF) - return (NOTOK); - } - if (fputs (line, mbf) == EOF) - return (NOTOK); - if (fputc (0x0a, mbf) == EOF) - return (NOTOK); - return (OK); -} - -int -mbx_delimit_begin (mbf) - FILE *mbf; -{ - if (fputs ("\f\n0, unseen,,\n", mbf) == EOF) - return (NOTOK); - return (OK); -} - -mbx_delimit_end (mbf) - FILE *mbf; -{ - if (putc ('\037', mbf) == EOF) - return (NOTOK); - return (OK); -} - -#endif /* MAIL_USE_POP */ - -#ifndef HAVE_STRERROR -char * -strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum >= 0 && errnum < sys_nerr) - return sys_errlist[errnum]; - return (char *) "Unknown error"; -} - -#endif /* ! HAVE_STRERROR */ diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c deleted file mode 100644 index d5f6177f4a2..00000000000 --- a/lib-src/ntlib.c +++ /dev/null @@ -1,216 +0,0 @@ -/* Utility and Unix shadow routines for GNU Emacs support programs on NT. - Copyright (C) 1994 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. - - Geoff Voelker (voelker@cs.washington.edu) 10-8-94 -*/ - -#include <windows.h> -#include <stdlib.h> -#include <stdio.h> -#include <time.h> -#include <direct.h> - -#include "ntlib.h" - -#define MAXPATHLEN _MAX_PATH - -/* Emulate sleep...we could have done this with a define, but that - would necessitate including windows.h in the files that used it. - This is much easier. */ -void -sleep(int seconds) -{ - Sleep (seconds * 1000); -} - -/* Get the current working directory. */ -char * -getwd (char *dir) -{ - if (GetCurrentDirectory (MAXPATHLEN, dir) > 0) - return dir; - return NULL; -} - -int -getpid () -{ - return _getpid (); -} - -static HANDLE getppid_parent; -static int getppid_ppid; - -int -getppid(void) -{ - char *ppid; - DWORD result; - - ppid = getenv ("__PARENT_PROCESS_ID"); - if (!ppid) - { - printf("no pid.\n"); - return 0; - } - else - { - getppid_ppid = atoi (ppid); - } - - if (!getppid_parent) - { - getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid)); - if (!getppid_parent) - { - printf ("Failed to open handle to parent process: %d\n", - GetLastError()); - exit (1); - } - } - - result = WaitForSingleObject (getppid_parent, 0); - switch (result) - { - case WAIT_TIMEOUT: - /* The parent is still alive. */ - return getppid_ppid; - case WAIT_OBJECT_0: - /* The parent is gone. Return the pid of Unix init (1). */ - return 1; - case WAIT_FAILED: - default: - printf ("Checking parent status failed: %d\n", GetLastError()); - exit (1); - } -} - -char * -getlogin () -{ - static char user_name[256]; - DWORD length = sizeof (user_name); - - if (GetUserName (user_name, &length)) - return user_name; - return NULL; -} - -char * -cuserid (char * s) -{ - char * name = getlogin (); - if (s) - return strcpy (s, name ? name : ""); - return name; -} - -int -getuid () -{ - return 0; -} - -int -setuid (int uid) -{ - return 0; -} - -struct passwd * -getpwuid (int uid) -{ - return NULL; -} - -char * -getpass (const char * prompt) -{ - static char input[256]; - HANDLE in; - HANDLE err; - DWORD count; - - in = GetStdHandle (STD_INPUT_HANDLE); - err = GetStdHandle (STD_ERROR_HANDLE); - - if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE) - return NULL; - - if (WriteFile (err, prompt, strlen (prompt), &count, NULL)) - { - int istty = (GetFileType (in) == FILE_TYPE_CHAR); - DWORD old_flags; - int rc; - - if (istty) - { - if (GetConsoleMode (in, &old_flags)) - SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); - else - istty = 0; - } - rc = ReadFile (in, input, sizeof (input), &count, NULL); - if (count >= 2 && input[count - 2] == '\r') - input[count - 2] = '\0'; - else - { - char buf[256]; - while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0) - if (count >= 2 && buf[count - 2] == '\r') - break; - } - WriteFile (err, "\r\n", 2, &count, NULL); - if (istty) - SetConsoleMode (in, old_flags); - if (rc) - return input; - } - - return NULL; -} - -int -fchown (int fd, int uid, int gid) -{ - return 0; -} - -/* Place a wrapper around the MSVC version of ctime. It returns NULL - on network directories, so we handle that case here. - (Ulrich Leodolter, 1/11/95). */ -char * -sys_ctime (const time_t *t) -{ - char *str = (char *) ctime (t); - return (str ? str : "Sun Jan 01 00:00:00 1970"); -} - -FILE * -sys_fopen(const char * path, const char * mode) -{ - return fopen (path, mode); -} - -int -sys_chdir (const char * path) -{ - return _chdir (path); -} diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h deleted file mode 100644 index 6de27d64c67..00000000000 --- a/lib-src/ntlib.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Utility and Unix shadow routines for GNU Emacs support programs on NT. - Copyright (C) 1994 Free Software Foundation, Inc. - - This file is part of GNU Emacs. - - GNU Emacs is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any later - version. - - GNU Emacs is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License - along with GNU Emacs; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - -*/ - -#include <pwd.h> -#include <malloc.h> - -void sleep(int seconds); -char *getwd (char *dir); -int getppid(void); -char * getlogin (); -char * cuserid (char * s); -int getuid (); -int setuid (int uid); -struct passwd * getpwuid (int uid); -char * getpass (const char * prompt); -int fchown (int fd, int uid, int gid); - -#ifndef BSTRING -#define bzero(b, l) memset(b, 0, l) -#define bcopy(s, d, l) memcpy(d, s, l) -#define bcmp(a, b, l) memcmp(a, b, l) - -#define index strchr -#define rindex strrchr -#endif - -/* end of ntlib.h */ diff --git a/lib-src/pop.c b/lib-src/pop.c deleted file mode 100644 index 9292998e288..00000000000 --- a/lib-src/pop.c +++ /dev/null @@ -1,1555 +0,0 @@ -/* pop.c: client routines for talking to a POP3-protocol post-office server - Copyright (c) 1991, 1993, 1996 Free Software Foundation, Inc. - Written by Jonathan Kamens, jik@security.ov.com. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#define NO_SHORTNAMES /* Tell config not to load remap.h */ -#include <../src/config.h> -#else -#define MAIL_USE_POP -#endif - -#ifdef MAIL_USE_POP - -#ifdef HAVE_CONFIG_H -/* Cancel these substitutions made in config.h */ -#undef open -#undef read -#undef write -#undef close -#endif - -#include <sys/types.h> -#ifdef WINDOWSNT -#include "ntlib.h" -#include <winsock.h> -#undef SOCKET_ERROR -#define RECV(s,buf,len,flags) recv(s,buf,len,flags) -#define SEND(s,buf,len,flags) send(s,buf,len,flags) -#define CLOSESOCKET(s) closesocket(s) -#else -#include <netinet/in.h> -#include <sys/socket.h> -#define RECV(s,buf,len,flags) read(s,buf,len) -#define SEND(s,buf,len,flags) write(s,buf,len) -#define CLOSESOCKET(s) close(s) -#endif -#include <pop.h> - -#ifdef sun -#include <malloc.h> -#endif /* sun */ - -#ifdef HESIOD -#include <hesiod.h> -/* - * It really shouldn't be necessary to put this declaration here, but - * the version of hesiod.h that Athena has installed in release 7.2 - * doesn't declare this function; I don't know if the 7.3 version of - * hesiod.h does. - */ -extern struct servent *hes_getservbyname (/* char *, char * */); -#endif - -#include <pwd.h> -#include <netdb.h> -#include <errno.h> -#include <stdio.h> - -#ifdef KERBEROS -#ifndef KRB5 -#ifndef SOLARIS2 -#include <des.h> -#include <krb.h> -#else /* not SOLARIS2 */ -#include <kerberos/des.h> -#include <kerberos/krb.h> -#endif /* not SOLARIS2 */ -#else /* KRB5 */ -#include <krb5/krb5.h> -#include <krb5/ext-proto.h> -#include <ctype.h> -#endif /* KRB5 */ -#endif /* KERBEROS */ - -extern char *getenv (/* char * */); -extern char *getlogin (/* void */); -extern char *getpass (/* char * */); -extern char *strerror (/* int */); -extern char *index (); - -#ifdef KERBEROS -#ifndef KRB5 -extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *, - u_long, MSG_DAT *, CREDENTIALS *, Key_schedule, - struct sockaddr_in *, struct sockaddr_in *, - char * */); -extern char *krb_realmofhost (/* char * */); -#endif /* ! KRB5 */ -#endif /* KERBEROS */ - -#ifndef WINDOWSNT -#if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H) -extern int h_errno; -#endif -#endif - -static int socket_connection (/* char *, int */); -static char *getline (/* popserver */); -static int sendline (/* popserver, char * */); -static int fullwrite (/* int, char *, int */); -static int getok (/* popserver */); -#if 0 -static int gettermination (/* popserver */); -#endif -static void pop_trash (/* popserver */); -static char *find_crlf (/* char * */); - -#define ERROR_MAX 80 /* a pretty arbitrary size */ -#define POP_PORT 110 -#define KPOP_PORT 1109 -#ifdef WINDOWSNT -#define POP_SERVICE "pop3" /* we don't want the POP2 port! */ -#else -#define POP_SERVICE "pop" -#endif -#ifdef KERBEROS -#ifdef KRB5 -#define KPOP_SERVICE "k5pop"; -#else -#define KPOP_SERVICE "kpop" -#endif -#endif - -char pop_error[ERROR_MAX]; -int pop_debug = 0; - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -/* - * Function: pop_open (char *host, char *username, char *password, - * int flags) - * - * Purpose: Establishes a connection with a post-office server, and - * completes the authorization portion of the session. - * - * Arguments: - * host The server host with which the connection should be - * established. Optional. If omitted, internal - * heuristics will be used to determine the server host, - * if possible. - * username - * The username of the mail-drop to access. Optional. - * If omitted, internal heuristics will be used to - * determine the username, if possible. - * password - * The password to use for authorization. If omitted, - * internal heuristics will be used to determine the - * password, if possible. - * flags A bit mask containing flags controlling certain - * functions of the routine. Valid flags are defined in - * the file pop.h - * - * Return value: Upon successful establishment of a connection, a - * non-null popserver will be returned. Otherwise, null will be - * returned, and the string variable pop_error will contain an - * explanation of the error. - */ -popserver -pop_open (host, username, password, flags) - char *host; - char *username; - char *password; - int flags; -{ - int sock; - popserver server; - - /* Determine the user name */ - if (! username) - { - username = getenv ("USER"); - if (! (username && *username)) - { - username = getlogin (); - if (! (username && *username)) - { - struct passwd *passwd; - passwd = getpwuid (getuid ()); - if (passwd && passwd->pw_name && *passwd->pw_name) - { - username = passwd->pw_name; - } - else - { - strcpy (pop_error, "Could not determine username"); - return (0); - } - } - } - } - - /* - * Determine the mail host. - */ - - if (! host) - { - host = getenv ("MAILHOST"); - } - -#ifdef HESIOD - if ((! host) && (! (flags & POP_NO_HESIOD))) - { - struct hes_postoffice *office; - office = hes_getmailhost (username); - if (office && office->po_type && (! strcmp (office->po_type, "POP")) - && office->po_name && *office->po_name && office->po_host - && *office->po_host) - { - host = office->po_host; - username = office->po_name; - } - } -#endif - -#ifdef MAILHOST - if (! host) - { - host = MAILHOST; - } -#endif - - if (! host) - { - strcpy (pop_error, "Could not determine POP server"); - return (0); - } - - /* Determine the password */ -#ifdef KERBEROS -#define DONT_NEED_PASSWORD (! (flags & POP_NO_KERBEROS)) -#else -#define DONT_NEED_PASSWORD 0 -#endif - - if ((! password) && (! DONT_NEED_PASSWORD)) - { - if (! (flags & POP_NO_GETPASS)) - { - password = getpass ("Enter POP password:"); - } - if (! password) - { - strcpy (pop_error, "Could not determine POP password"); - return (0); - } - } - if (password) - flags |= POP_NO_KERBEROS; - else - password = username; - - sock = socket_connection (host, flags); - if (sock == -1) - return (0); - - server = (popserver) malloc (sizeof (struct _popserver)); - if (! server) - { - strcpy (pop_error, "Out of memory in pop_open"); - return (0); - } - server->buffer = (char *) malloc (GETLINE_MIN); - if (! server->buffer) - { - strcpy (pop_error, "Out of memory in pop_open"); - free ((char *) server); - return (0); - } - - server->file = sock; - server->data = 0; - server->buffer_index = 0; - server->buffer_size = GETLINE_MIN; - server->in_multi = 0; - server->trash_started = 0; - - if (getok (server)) - return (0); - - /* - * I really shouldn't use the pop_error variable like this, but.... - */ - if (strlen (username) > ERROR_MAX - 6) - { - pop_close (server); - strcpy (pop_error, - "Username too long; recompile pop.c with larger ERROR_MAX"); - return (0); - } - sprintf (pop_error, "USER %s", username); - - if (sendline (server, pop_error) || getok (server)) - { - return (0); - } - - if (strlen (password) > ERROR_MAX - 6) - { - pop_close (server); - strcpy (pop_error, - "Password too long; recompile pop.c with larger ERROR_MAX"); - return (0); - } - sprintf (pop_error, "PASS %s", password); - - if (sendline (server, pop_error) || getok (server)) - { - return (0); - } - - return (server); -} - -/* - * Function: pop_stat - * - * Purpose: Issue the STAT command to the server and return (in the - * value parameters) the number of messages in the maildrop and - * the total size of the maildrop. - * - * Return value: 0 on success, or non-zero with an error in pop_error - * in failure. - * - * Side effects: On failure, may make further operations on the - * connection impossible. - */ -int -pop_stat (server, count, size) - popserver server; - int *count; - int *size; -{ - char *fromserver; - - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_stat"); - return (-1); - } - - if (sendline (server, "STAT") || (! (fromserver = getline (server)))) - return (-1); - - if (strncmp (fromserver, "+OK ", 4)) - { - if (0 == strncmp (fromserver, "-ERR", 4)) - { - strncpy (pop_error, fromserver, ERROR_MAX); - } - else - { - strcpy (pop_error, - "Unexpected response from POP server in pop_stat"); - pop_trash (server); - } - return (-1); - } - - *count = atoi (&fromserver[4]); - - fromserver = index (&fromserver[4], ' '); - if (! fromserver) - { - strcpy (pop_error, - "Badly formatted response from server in pop_stat"); - pop_trash (server); - return (-1); - } - - *size = atoi (fromserver + 1); - - return (0); -} - -/* - * Function: pop_list - * - * Purpose: Performs the POP "list" command and returns (in value - * parameters) two malloc'd zero-terminated arrays -- one of - * message IDs, and a parallel one of sizes. - * - * Arguments: - * server The pop connection to talk to. - * message The number of the one message about which to get - * information, or 0 to get information about all - * messages. - * - * Return value: 0 on success, non-zero with error in pop_error on - * failure. - * - * Side effects: On failure, may make further operations on the - * connection impossible. - */ -int -pop_list (server, message, IDs, sizes) - popserver server; - int message; - int **IDs; - int **sizes; -{ - int how_many, i; - char *fromserver; - - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_list"); - return (-1); - } - - if (message) - how_many = 1; - else - { - int count, size; - if (pop_stat (server, &count, &size)) - return (-1); - how_many = count; - } - - *IDs = (int *) malloc ((how_many + 1) * sizeof (int)); - *sizes = (int *) malloc ((how_many + 1) * sizeof (int)); - if (! (*IDs && *sizes)) - { - strcpy (pop_error, "Out of memory in pop_list"); - return (-1); - } - - if (message) - { - sprintf (pop_error, "LIST %d", message); - if (sendline (server, pop_error)) - { - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - if (! (fromserver = getline (server))) - { - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - if (strncmp (fromserver, "+OK ", 4)) - { - if (! strncmp (fromserver, "-ERR", 4)) - strncpy (pop_error, fromserver, ERROR_MAX); - else - { - strcpy (pop_error, - "Unexpected response from server in pop_list"); - pop_trash (server); - } - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - (*IDs)[0] = atoi (&fromserver[4]); - fromserver = index (&fromserver[4], ' '); - if (! fromserver) - { - strcpy (pop_error, - "Badly formatted response from server in pop_list"); - pop_trash (server); - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - (*sizes)[0] = atoi (fromserver); - (*IDs)[1] = (*sizes)[1] = 0; - return (0); - } - else - { - if (pop_multi_first (server, "LIST", &fromserver)) - { - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - for (i = 0; i < how_many; i++) - { - if (pop_multi_next (server, &fromserver)) - { - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - (*IDs)[i] = atoi (fromserver); - fromserver = index (fromserver, ' '); - if (! fromserver) - { - strcpy (pop_error, - "Badly formatted response from server in pop_list"); - free ((char *) *IDs); - free ((char *) *sizes); - pop_trash (server); - return (-1); - } - (*sizes)[i] = atoi (fromserver); - } - if (pop_multi_next (server, &fromserver)) - { - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - else if (fromserver) - { - strcpy (pop_error, - "Too many response lines from server in pop_list"); - free ((char *) *IDs); - free ((char *) *sizes); - return (-1); - } - (*IDs)[i] = (*sizes)[i] = 0; - return (0); - } -} - -/* - * Function: pop_retrieve - * - * Purpose: Retrieve a specified message from the maildrop. - * - * Arguments: - * server The server to retrieve from. - * message The message number to retrieve. - * markfrom - * If true, then mark the string "From " at the beginning - * of lines with '>'. - * - * Return value: A string pointing to the message, if successful, or - * null with pop_error set if not. - * - * Side effects: May kill connection on error. - */ -char * -pop_retrieve (server, message, markfrom) - popserver server; - int message; - int markfrom; -{ - int *IDs, *sizes, bufsize, fromcount = 0, cp = 0; - char *ptr, *fromserver; - int ret; - - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_retrieve"); - return (0); - } - - if (pop_list (server, message, &IDs, &sizes)) - return (0); - - if (pop_retrieve_first (server, message, &fromserver)) - { - return (0); - } - - /* - * The "5" below is an arbitrary constant -- I assume that if - * there are "From" lines in the text to be marked, there - * probably won't be more than 5 of them. If there are, I - * allocate more space for them below. - */ - bufsize = sizes[0] + (markfrom ? 5 : 0); - ptr = (char *)malloc (bufsize); - free ((char *) IDs); - free ((char *) sizes); - - if (! ptr) - { - strcpy (pop_error, "Out of memory in pop_retrieve"); - pop_retrieve_flush (server); - return (0); - } - - while (! (ret = pop_retrieve_next (server, &fromserver))) - { - int linesize; - - if (! fromserver) - { - ptr[cp] = '\0'; - return (ptr); - } - if (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' && - fromserver[2] == 'o' && fromserver[3] == 'm' && - fromserver[4] == ' ') - { - if (++fromcount == 5) - { - bufsize += 5; - ptr = (char *)realloc (ptr, bufsize); - if (! ptr) - { - strcpy (pop_error, "Out of memory in pop_retrieve"); - pop_retrieve_flush (server); - return (0); - } - fromcount = 0; - } - ptr[cp++] = '>'; - } - linesize = strlen (fromserver); - bcopy (fromserver, &ptr[cp], linesize); - cp += linesize; - ptr[cp++] = '\n'; - } - - if (ret) - { - free (ptr); - return (0); - } -} - -int -pop_retrieve_first (server, message, response) - popserver server; - int message; - char **response; -{ - sprintf (pop_error, "RETR %d", message); - return (pop_multi_first (server, pop_error, response)); -} - -int -pop_retrieve_next (server, line) - popserver server; - char **line; -{ - return (pop_multi_next (server, line)); -} - -int -pop_retrieve_flush (server) - popserver server; -{ - return (pop_multi_flush (server)); -} - -int -pop_top_first (server, message, lines, response) - popserver server; - int message, lines; - char **response; -{ - sprintf (pop_error, "TOP %d %d", message, lines); - return (pop_multi_first (server, pop_error, response)); -} - -int -pop_top_next (server, line) - popserver server; - char **line; -{ - return (pop_multi_next (server, line)); -} - -int -pop_top_flush (server) - popserver server; -{ - return (pop_multi_flush (server)); -} - -int -pop_multi_first (server, command, response) - popserver server; - char *command; - char **response; -{ - if (server->in_multi) - { - strcpy (pop_error, - "Already in multi-line query in pop_multi_first"); - return (-1); - } - - if (sendline (server, command) || (! (*response = getline (server)))) - { - return (-1); - } - - if (0 == strncmp (*response, "-ERR", 4)) - { - strncpy (pop_error, *response, ERROR_MAX); - return (-1); - } - else if (0 == strncmp (*response, "+OK", 3)) - { - for (*response += 3; **response == ' '; (*response)++) /* empty */; - server->in_multi = 1; - return (0); - } - else - { - strcpy (pop_error, - "Unexpected response from server in pop_multi_first"); - return (-1); - } -} - -int -pop_multi_next (server, line) - popserver server; - char **line; -{ - char *fromserver; - - if (! server->in_multi) - { - strcpy (pop_error, "Not in multi-line query in pop_multi_next"); - return (-1); - } - - fromserver = getline (server); - if (! fromserver) - { - return (-1); - } - - if (fromserver[0] == '.') - { - if (! fromserver[1]) - { - *line = 0; - server->in_multi = 0; - return (0); - } - else - { - *line = fromserver + 1; - return (0); - } - } - else - { - *line = fromserver; - return (0); - } -} - -int -pop_multi_flush (server) - popserver server; -{ - char *line; - - if (! server->in_multi) - { - return (0); - } - - while (! pop_multi_next (server, &line)) - { - if (! line) - { - return (0); - } - } - - return (-1); -} - -/* Function: pop_delete - * - * Purpose: Delete a specified message. - * - * Arguments: - * server Server from which to delete the message. - * message Message to delete. - * - * Return value: 0 on success, non-zero with error in pop_error - * otherwise. - */ -int -pop_delete (server, message) - popserver server; - int message; -{ - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_delete"); - return (-1); - } - - sprintf (pop_error, "DELE %d", message); - - if (sendline (server, pop_error) || getok (server)) - return (-1); - - return (0); -} - -/* - * Function: pop_noop - * - * Purpose: Send a noop command to the server. - * - * Argument: - * server The server to send to. - * - * Return value: 0 on success, non-zero with error in pop_error - * otherwise. - * - * Side effects: Closes connection on error. - */ -int -pop_noop (server) - popserver server; -{ - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_noop"); - return (-1); - } - - if (sendline (server, "NOOP") || getok (server)) - return (-1); - - return (0); -} - -/* - * Function: pop_last - * - * Purpose: Find out the highest seen message from the server. - * - * Arguments: - * server The server. - * - * Return value: If successful, the highest seen message, which is - * greater than or equal to 0. Otherwise, a negative number with - * the error explained in pop_error. - * - * Side effects: Closes the connection on error. - */ -int -pop_last (server) - popserver server; -{ - char *fromserver; - - if (server->in_multi) - { - strcpy (pop_error, "In multi-line query in pop_last"); - return (-1); - } - - if (sendline (server, "LAST")) - return (-1); - - if (! (fromserver = getline (server))) - return (-1); - - if (! strncmp (fromserver, "-ERR", 4)) - { - strncpy (pop_error, fromserver, ERROR_MAX); - return (-1); - } - else if (strncmp (fromserver, "+OK ", 4)) - { - strcpy (pop_error, "Unexpected response from server in pop_last"); - pop_trash (server); - return (-1); - } - else - { - return (atoi (&fromserver[4])); - } -} - -/* - * Function: pop_reset - * - * Purpose: Reset the server to its initial connect state - * - * Arguments: - * server The server. - * - * Return value: 0 for success, non-0 with error in pop_error - * otherwise. - * - * Side effects: Closes the connection on error. - */ -int -pop_reset (server) - popserver server; -{ - if (pop_retrieve_flush (server)) - { - return (-1); - } - - if (sendline (server, "RSET") || getok (server)) - return (-1); - - return (0); -} - -/* - * Function: pop_quit - * - * Purpose: Quit the connection to the server, - * - * Arguments: - * server The server to quit. - * - * Return value: 0 for success, non-zero otherwise with error in - * pop_error. - * - * Side Effects: The popserver passed in is unusable after this - * function is called, even if an error occurs. - */ -int -pop_quit (server) - popserver server; -{ - int ret = 0; - - if (server->file >= 0) - { - if (pop_retrieve_flush (server)) - { - ret = -1; - } - - if (sendline (server, "QUIT") || getok (server)) - { - ret = -1; - } - - close (server->file); - } - - if (server->buffer) - free (server->buffer); - free ((char *) server); - - return (ret); -} - -#ifdef WINDOWSNT -static int have_winsock = 0; -#endif - -/* - * Function: socket_connection - * - * Purpose: Opens the network connection with the mail host, without - * doing any sort of I/O with it or anything. - * - * Arguments: - * host The host to which to connect. - * flags Option flags. - * - * Return value: A file descriptor indicating the connection, or -1 - * indicating failure, in which case an error has been copied - * into pop_error. - */ -static int -socket_connection (host, flags) - char *host; - int flags; -{ - struct hostent *hostent; - struct servent *servent; - struct sockaddr_in addr; - char found_port = 0; - char *service; - int sock; -#ifdef KERBEROS -#ifdef KRB5 - krb5_error_code rem; - krb5_ccache ccdef; - krb5_principal client, server; - krb5_error *err_ret; - register char *cp; -#else - KTEXT ticket; - MSG_DAT msg_data; - CREDENTIALS cred; - Key_schedule schedule; - int rem; - char *realhost; -#endif /* KRB5 */ -#endif /* KERBEROS */ - - int try_count = 0; - -#ifdef WINDOWSNT - { - WSADATA winsockData; - if (WSAStartup (0x101, &winsockData) == 0) - have_winsock = 1; - } -#endif - - do - { - hostent = gethostbyname (host); - try_count++; - if ((! hostent) && ((h_errno != TRY_AGAIN) || (try_count == 5))) - { - strcpy (pop_error, "Could not determine POP server's address"); - return (-1); - } - } while (! hostent); - - bzero ((char *) &addr, sizeof (addr)); - addr.sin_family = AF_INET; - -#ifdef KERBEROS - service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE; -#else - service = POP_SERVICE; -#endif - -#ifdef HESIOD - if (! (flags & POP_NO_HESIOD)) - { - servent = hes_getservbyname (service, "tcp"); - if (servent) - { - addr.sin_port = servent->s_port; - found_port = 1; - } - } -#endif - if (! found_port) - { - servent = getservbyname (service, "tcp"); - if (servent) - { - addr.sin_port = servent->s_port; - } - else - { -#ifdef KERBEROS - addr.sin_port = htons ((flags & POP_NO_KERBEROS) ? - POP_PORT : KPOP_PORT); -#else - addr.sin_port = htons (POP_PORT); -#endif - } - } - -#define SOCKET_ERROR "Could not create socket for POP connection: " - - sock = socket (PF_INET, SOCK_STREAM, 0); - if (sock < 0) - { - strcpy (pop_error, SOCKET_ERROR); - strncat (pop_error, strerror (errno), - ERROR_MAX - sizeof (SOCKET_ERROR)); - return (-1); - - } - - while (*hostent->h_addr_list) - { - bcopy (*hostent->h_addr_list, (char *) &addr.sin_addr, - hostent->h_length); - if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr))) - break; - hostent->h_addr_list++; - } - -#define CONNECT_ERROR "Could not connect to POP server: " - - if (! *hostent->h_addr_list) - { - CLOSESOCKET (sock); - strcpy (pop_error, CONNECT_ERROR); - strncat (pop_error, strerror (errno), - ERROR_MAX - sizeof (CONNECT_ERROR)); - return (-1); - - } - -#ifdef KERBEROS -#define KRB_ERROR "Kerberos error connecting to POP server: " - if (! (flags & POP_NO_KERBEROS)) - { -#ifdef KRB5 - krb5_init_ets (); - - if (rem = krb5_cc_default (&ccdef)) - { - krb5error: - strcpy (pop_error, KRB_ERROR); - strncat (pop_error, error_message (rem), - ERROR_MAX - sizeof(KRB_ERROR)); - CLOSESOCKET (sock); - return (-1); - } - - if (rem = krb5_cc_get_principal (ccdef, &client)) - { - goto krb5error; - } - - for (cp = hostent->h_name; *cp; cp++) - { - if (isupper (*cp)) - { - *cp = tolower (*cp); - } - } - - if (rem = krb5_sname_to_principal (hostent->h_name, POP_SERVICE, - FALSE, &server)) - { - goto krb5error; - } - - rem = krb5_sendauth ((krb5_pointer) &sock, "KPOPV1.0", client, server, - AP_OPTS_MUTUAL_REQUIRED, - 0, /* no checksum */ - 0, /* no creds, use ccache instead */ - ccdef, - 0, /* don't need seq # */ - 0, /* don't need subsession key */ - &err_ret, - 0); /* don't need reply */ - krb5_free_principal (server); - if (rem) - { - if (err_ret && err_ret->text.length) - { - strcpy (pop_error, KRB_ERROR); - strncat (pop_error, error_message (rem), - ERROR_MAX - sizeof (KRB_ERROR)); - strncat (pop_error, " [server says '", - ERROR_MAX - strlen (pop_error) - 1); - strncat (pop_error, err_ret->text.data, - min (ERROR_MAX - strlen (pop_error) - 1, - err_ret->text.length)); - strncat (pop_error, "']", - ERROR_MAX - strlen (pop_error) - 1); - } - else - { - strcpy (pop_error, KRB_ERROR); - strncat (pop_error, error_message (rem), - ERROR_MAX - sizeof (KRB_ERROR)); - } - if (err_ret) - krb5_free_error (err_ret); - - CLOSESOCKET (sock); - return (-1); - } -#else /* ! KRB5 */ - ticket = (KTEXT) malloc (sizeof (KTEXT_ST)); - realhost = strdup (hostent->h_name); - rem = krb_sendauth (0L, sock, ticket, "pop", realhost, - (char *) krb_realmofhost (realhost), - (unsigned long) 0, &msg_data, &cred, schedule, - (struct sockaddr_in *) 0, - (struct sockaddr_in *) 0, - "KPOPV0.1"); - free ((char *) ticket); - free (realhost); - if (rem != KSUCCESS) - { - strcpy (pop_error, KRB_ERROR); - strncat (pop_error, krb_err_txt[rem], - ERROR_MAX - sizeof (KRB_ERROR)); - CLOSESOCKET (sock); - return (-1); - } -#endif /* KRB5 */ - } -#endif /* KERBEROS */ - - return (sock); -} /* socket_connection */ - -/* - * Function: getline - * - * Purpose: Get a line of text from the connection and return a - * pointer to it. The carriage return and linefeed at the end of - * the line are stripped, but periods at the beginnings of lines - * are NOT dealt with in any special way. - * - * Arguments: - * server The server from which to get the line of text. - * - * Returns: A non-null pointer if successful, or a null pointer on any - * error, with an error message copied into pop_error. - * - * Notes: The line returned is overwritten with each call to getline. - * - * Side effects: Closes the connection on error. - */ -static char * -getline (server) - popserver server; -{ -#define GETLINE_ERROR "Error reading from server: " - - int ret; - int search_offset = 0; - - if (server->data) - { - char *cp = find_crlf (server->buffer + server->buffer_index); - if (cp) - { - int found; - int data_used; - - found = server->buffer_index; - data_used = (cp + 2) - server->buffer - found; - - *cp = '\0'; /* terminate the string to be returned */ - server->data -= data_used; - server->buffer_index += data_used; - - if (pop_debug) - fprintf (stderr, "<<< %s\n", server->buffer + found); - return (server->buffer + found); - } - else - { - bcopy (server->buffer + server->buffer_index, - server->buffer, server->data); - /* Record the fact that we've searched the data already in - the buffer for a CRLF, so that when we search below, we - don't have to search the same data twice. There's a "- - 1" here to account for the fact that the last character - of the data we have may be the CR of a CRLF pair, of - which we haven't read the second half yet, so we may have - to search it again when we read more data. */ - search_offset = server->data - 1; - server->buffer_index = 0; - } - } - else - { - server->buffer_index = 0; - } - - while (1) - { - /* There's a "- 1" here to leave room for the null that we put - at the end of the read data below. We put the null there so - that find_crlf knows where to stop when we call it. */ - if (server->data == server->buffer_size - 1) - { - server->buffer_size += GETLINE_INCR; - server->buffer = (char *)realloc (server->buffer, server->buffer_size); - if (! server->buffer) - { - strcpy (pop_error, "Out of memory in getline"); - pop_trash (server); - return (0); - } - } - ret = RECV (server->file, server->buffer + server->data, - server->buffer_size - server->data - 1, 0); - if (ret < 0) - { - strcpy (pop_error, GETLINE_ERROR); - strncat (pop_error, strerror (errno), - ERROR_MAX - sizeof (GETLINE_ERROR)); - pop_trash (server); - return (0); - } - else if (ret == 0) - { - strcpy (pop_error, "Unexpected EOF from server in getline"); - pop_trash (server); - return (0); - } - else - { - char *cp; - server->data += ret; - server->buffer[server->data] = '\0'; - - cp = find_crlf (server->buffer + search_offset); - if (cp) - { - int data_used = (cp + 2) - server->buffer; - *cp = '\0'; - server->data -= data_used; - server->buffer_index = data_used; - - if (pop_debug) - fprintf (stderr, "<<< %s\n", server->buffer); - return (server->buffer); - } - search_offset += ret; - } - } - - /* NOTREACHED */ -} - -/* - * Function: sendline - * - * Purpose: Sends a line of text to the POP server. The line of text - * passed into this function should NOT have the carriage return - * and linefeed on the end of it. Periods at beginnings of lines - * will NOT be treated specially by this function. - * - * Arguments: - * server The server to which to send the text. - * line The line of text to send. - * - * Return value: Upon successful completion, a value of 0 will be - * returned. Otherwise, a non-zero value will be returned, and - * an error will be copied into pop_error. - * - * Side effects: Closes the connection on error. - */ -static int -sendline (server, line) - popserver server; - char *line; -{ -#define SENDLINE_ERROR "Error writing to POP server: " - int ret; - - ret = fullwrite (server->file, line, strlen (line)); - if (ret >= 0) - { /* 0 indicates that a blank line was written */ - ret = fullwrite (server->file, "\r\n", 2); - } - - if (ret < 0) - { - pop_trash (server); - strcpy (pop_error, SENDLINE_ERROR); - strncat (pop_error, strerror (errno), - ERROR_MAX - sizeof (SENDLINE_ERROR)); - return (ret); - } - - if (pop_debug) - fprintf (stderr, ">>> %s\n", line); - - return (0); -} - -/* - * Procedure: fullwrite - * - * Purpose: Just like write, but keeps trying until the entire string - * has been written. - * - * Return value: Same as write. Pop_error is not set. - */ -static int -fullwrite (fd, buf, nbytes) - int fd; - char *buf; - int nbytes; -{ - char *cp; - int ret; - - cp = buf; - while ((ret = SEND (fd, cp, nbytes, 0)) > 0) - { - cp += ret; - nbytes -= ret; - } - - return (ret); -} - -/* - * Procedure getok - * - * Purpose: Reads a line from the server. If the return indicator is - * positive, return with a zero exit status. If not, return with - * a negative exit status. - * - * Arguments: - * server The server to read from. - * - * Returns: 0 for success, else for failure and puts error in pop_error. - * - * Side effects: On failure, may make the connection unusable. - */ -static int -getok (server) - popserver server; -{ - char *fromline; - - if (! (fromline = getline (server))) - { - return (-1); - } - - if (! strncmp (fromline, "+OK", 3)) - return (0); - else if (! strncmp (fromline, "-ERR", 4)) - { - strncpy (pop_error, fromline, ERROR_MAX); - pop_error[ERROR_MAX-1] = '\0'; - return (-1); - } - else - { - strcpy (pop_error, - "Unexpected response from server; expecting +OK or -ERR"); - pop_trash (server); - return (-1); - } -} - -#if 0 -/* - * Function: gettermination - * - * Purpose: Gets the next line and verifies that it is a termination - * line (nothing but a dot). - * - * Return value: 0 on success, non-zero with pop_error set on error. - * - * Side effects: Closes the connection on error. - */ -static int -gettermination (server) - popserver server; -{ - char *fromserver; - - fromserver = getline (server); - if (! fromserver) - return (-1); - - if (strcmp (fromserver, ".")) - { - strcpy (pop_error, - "Unexpected response from server in gettermination"); - pop_trash (server); - return (-1); - } - - return (0); -} -#endif - -/* - * Function pop_close - * - * Purpose: Close a pop connection, sending a "RSET" command to try to - * preserve any changes that were made and a "QUIT" command to - * try to get the server to quit, but ignoring any responses that - * are received. - * - * Side effects: The server is unusable after this function returns. - * Changes made to the maildrop since the session was started (or - * since the last pop_reset) may be lost. - */ -void -pop_close (server) - popserver server; -{ - pop_trash (server); - free ((char *) server); - - return; -} - -/* - * Function: pop_trash - * - * Purpose: Like pop_close or pop_quit, but doesn't deallocate the - * memory associated with the server. It is legal to call - * pop_close or pop_quit after this function has been called. - */ -static void -pop_trash (server) - popserver server; -{ - if (server->file >= 0) - { - /* avoid recursion; sendline can call pop_trash */ - if (server->trash_started) - return; - server->trash_started = 1; - - sendline (server, "RSET"); - sendline (server, "QUIT"); - - CLOSESOCKET (server->file); - server->file = -1; - if (server->buffer) - { - free (server->buffer); - server->buffer = 0; - } - } - -#ifdef WINDOWSNT - if (have_winsock) - WSACleanup (); -#endif -} - -/* Return a pointer to the first CRLF in IN_STRING, - or 0 if it does not contain one. */ - -static char * -find_crlf (in_string) - char *in_string; -{ - while (1) - { - if (! *in_string) - return (0); - else if (*in_string == '\r') - { - if (*++in_string == '\n') - return (in_string - 1); - } - else - in_string++; - } - /* NOTREACHED */ -} - -#endif /* MAIL_USE_POP */ diff --git a/lib-src/pop.h b/lib-src/pop.h deleted file mode 100644 index 9121425661a..00000000000 --- a/lib-src/pop.h +++ /dev/null @@ -1,82 +0,0 @@ -/* pop.h: Header file for the "pop.c" client POP3 protocol. - Copyright (c) 1991,1993 Free Software Foundation, Inc. - Written by Jonathan Kamens, jik@security.ov.com. - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -#include <stdio.h> - -#define GETLINE_MIN 1024 /* the getline buffer starts out this */ - /* size */ -#define GETLINE_INCR 1024 /* the getline buffer is grown by this */ - /* size when it needs to grow */ - -extern char pop_error[]; -extern int pop_debug; - -struct _popserver -{ - int file, data; - char *buffer; - int buffer_size, buffer_index; - int in_multi; - int trash_started; -}; - -typedef struct _popserver *popserver; - -/* - * Valid flags for the pop_open function. - */ - -#define POP_NO_KERBEROS (1<<0) -#define POP_NO_HESIOD (1<<1) -#define POP_NO_GETPASS (1<<2) - -#ifdef __STDC__ -#define _ARGS(a) a -#else -#define _ARGS(a) () -#endif - -extern popserver pop_open _ARGS((char *host, char *username, char *password, - int flags)); -extern int pop_stat _ARGS((popserver server, int *count, int *size)); -extern int pop_list _ARGS((popserver server, int message, int **IDs, - int **size)); -extern char *pop_retrieve _ARGS((popserver server, int message, int markfrom)); -extern int pop_retrieve_first _ARGS((popserver server, int message, - char **response)); -extern int pop_retrieve_next _ARGS((popserver server, char **line)); -extern int pop_retrieve_flush _ARGS((popserver server)); -extern int pop_top_first _ARGS((popserver server, int message, int lines, - char **response)); -extern int pop_top_next _ARGS((popserver server, char **line)); -extern int pop_top_flush _ARGS((popserver server)); -extern int pop_multi_first _ARGS((popserver server, char *command, - char **response)); -extern int pop_multi_next _ARGS((popserver server, char **line)); -extern int pop_multi_flush _ARGS((popserver server)); -extern int pop_delete _ARGS((popserver server, int message)); -extern int pop_noop _ARGS((popserver server)); -extern int pop_last _ARGS((popserver server)); -extern int pop_reset _ARGS((popserver server)); -extern int pop_quit _ARGS((popserver server)); -extern void pop_close _ARGS((popserver)); - -#undef _ARGS diff --git a/lib-src/profile.c b/lib-src/profile.c deleted file mode 100644 index b0c713e69dd..00000000000 --- a/lib-src/profile.c +++ /dev/null @@ -1,104 +0,0 @@ -/* profile.c --- generate periodic events for profiling of Emacs Lisp code. - Copyright (C) 1992, 1994 Free Software Foundation, Inc. - - Author: Boaz Ben-Zvi <boaz@lcs.mit.edu> - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - - -/** - ** To be run as an emacs process. Input string that starts with: - ** 'z' -- resets the watch (to zero). - ** 'p' -- return time (on stdout) as string with format <sec>.<micro-sec> - ** 'q' -- exit. - ** - ** abstraction : a stopwatch - ** operations: reset_watch, get_time - */ -#include <stdio.h> -#include <../src/config.h> -#include <../src/systime.h> - -static EMACS_TIME TV1, TV2; -static int watch_not_started = 1; /* flag */ -static char time_string[30]; - -/* Reset the stopwatch to zero. */ - -void -reset_watch () -{ - EMACS_GET_TIME (TV1); - watch_not_started = 0; -} - -/* This call returns the time since the last reset_watch call. The time - is returned as a string with the format <seconds>.<micro-seconds> - If reset_watch was not called yet, exit. */ - -char * -get_time () -{ - if (watch_not_started) - exit (1); /* call reset_watch first ! */ - EMACS_GET_TIME (TV2); - EMACS_SUB_TIME (TV2, TV2, TV1); - sprintf (time_string, "%lu.%06lu", EMACS_SECS (TV2), EMACS_USECS (TV2)); - return time_string; -} - -#if ! defined (HAVE_GETTIMEOFDAY) && defined (HAVE_TIMEVAL) - -/* ARGSUSED */ -gettimeofday (tp, tzp) - struct timeval *tp; - struct timezone *tzp; -{ - extern long time (); - - tp->tv_sec = time ((long *)0); - tp->tv_usec = 0; - if (tzp != 0) - tzp->tz_minuteswest = -1; -} - -#endif - -int -main () -{ - int c; - while ((c = getchar ()) != EOF) - { - switch (c) - { - case 'z': - reset_watch (); - break; - case 'p': - puts (get_time ()); - break; - case 'q': - exit (0); - } - /* Anything remaining on the line is ignored. */ - while (c != '\n' && c != EOF) - c = getchar (); - } - exit (1); -} diff --git a/lib-src/rcs-checkin b/lib-src/rcs-checkin deleted file mode 100755 index f954e54bd45..00000000000 --- a/lib-src/rcs-checkin +++ /dev/null @@ -1,98 +0,0 @@ -#! /bin/sh - -# This script accepts any number of file arguments and checks them into RCS. -# -# Arguments which are detectably either RCS masters (with names ending in ,v) -# or Emacs version files (with names of the form foo.~<number>~) are ignored. -# For each file foo, the script looks for Emacs version files related to it. -# These files are checked in as deltas, oldest first, so that the contents of -# the file itself becomes the latest revision in the master. -# -# The first line of each file is used as its description text. The file itself -# is not deleted, as under VC with vc-keep-workfiles at its default of t, but -# all the version files are. -# -# If an argument file is already version-controlled under RCS, any version -# files are added to the list of deltas and deleted, and then the workfile -# is checked in again as the latest version. This is probably not quite -# what was wanted, and is the main reason VC doesn't simply call this to -# do checkins. -# -# This script is intended to be used to convert files with an old-Emacs-style -# version history for use with VC (the Emacs 19 version-control interface), -# which likes to use RCS as its back end. It was written by Paul Eggert -# and revised/documented for use with VC by Eric S. Raymond, Mar 19 1993. - -case $# in -0) - echo "rcs-checkin: usage: rcs-checkin file ..." - echo "rcs-checkin: function: checks file.~*~ and file into a new RCS file" - echo "rcs-checkin: function: uses the file's first line for the description" -esac - -# expr pattern to extract owner from ls -l output -ls_owner_pattern='[^ ][^ ]* *[^ ][^ ]* *\([^ ][^ ]*\)' - -for file -do - # Make it easier to say `rcs-checkin *' - # by ignoring file names that already contain `~', or end in `,v'. - case $file in - *~* | *,v) continue - esac - # Ignore non-files too. - test -f "$file" || continue - - # Check that file is readable. - test -r "$file" || exit - - # If the RCS file does not already exist, - # initialize it with a description from $file's first line. - rlog -R "$file" >/dev/null 2>&1 || - rcs -i -q -t-"`sed 1q $file`" "$file" || exit - - # Get list of old files. - oldfiles=` - ls $file.~[0-9]*~ 2>/dev/null | - sort -t~ -n +1 - ` - - # Check that they are properly sorted by date. - case $oldfiles in - ?*) - oldfiles_by_date=`ls -rt $file $oldfiles` - test " $oldfiles -$file" = " $oldfiles_by_date" || { - echo >&2 "rcs-checkin: skipping $file, because its mod times are out of order. - -Sorted by mod time: -$oldfiles_by_date - -Sorted by name: -$oldfiles -$file" - continue - } - esac - - echo >&2 rcs-checkin: checking in: $oldfiles $file - - # Save $file as $file.~-~ temporarily. - mv "$file" "$file.~-~" || exit - - # Rename each old file to $file, and check it in. - for oldfile in $oldfiles - do - mv "$oldfile" "$file" || exit - ls_l=`ls -l "$file"` || exit - owner=-w`expr " $ls_l" : " $ls_owner_pattern"` || owner= - echo "Formerly ${oldfile}" | ci -d -l -q $owner "$file" || exit - done - - # Bring $file back from $file.~-~, and check it in. - mv "$file.~-~" "$file" || exit - ls_l=`ls -l "$file"` || exit - owner=-w`expr " $ls_l" : " $ls_owner_pattern"` || owner= - ci -d -q -u $owner -m"entered into RCS" "$file" || exit -done - diff --git a/lib-src/rcs2log b/lib-src/rcs2log deleted file mode 100755 index 44a12bd3da8..00000000000 --- a/lib-src/rcs2log +++ /dev/null @@ -1,612 +0,0 @@ -#! /bin/sh - -# RCS to ChangeLog generator - -# Generate a change log prefix from RCS files and the ChangeLog (if any). -# Output the new prefix to standard output. -# You can edit this prefix by hand, and then prepend it to ChangeLog. - -# Ignore log entries that start with `#'. -# Clump together log entries that start with `{topic} ', -# where `topic' contains neither white space nor `}'. - -# Author: Paul Eggert <eggert@twinsun.com> - -# $Id: rcs2log,v 1.34 1996/10/13 05:59:42 eggert Exp eggert $ - -# Copyright 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -tab=' ' -nl=' -' - -# Parse options. - -# defaults -: ${AWK=awk} -: ${TMPDIR=/tmp} -changelog=ChangeLog # change log file name -datearg= # rlog date option -hostname= # name of local host (if empty, will deduce it later) -indent=8 # indent of log line -length=79 # suggested max width of log line -logins= # login names for people we know fullnames and mailaddrs of -loginFullnameMailaddrs= # login<tab>fullname<tab>mailaddr triplets -logTZ= # time zone for log dates (if empty, use local time) -recursive= # t if we want recursive rlog -revision= # t if we want revision numbers -rlog_options= # options to pass to rlog -tabwidth=8 # width of horizontal tab - -while : -do - case $1 in - -c) changelog=${2?}; shift;; - -i) indent=${2?}; shift;; - -h) hostname=${2?}; shift;; - -l) length=${2?}; shift;; - -[nu]) # -n is obsolescent; it is replaced by -u. - case $1 in - -n) case ${2?}${3?}${4?} in - *"$tab"* | *"$nl"*) - echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed" - exit 1 - esac - loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$2$tab$3$tab$4 - shift; shift; shift;; - -u) - # If $2 is not tab-separated, use colon for separator. - case ${2?} in - *"$nl"*) - echo >&2 "$0: -u '$2': newlines not allowed" - exit 1;; - *"$tab"*) - t=$tab;; - *) - t=: - esac - case $2 in - *"$t"*"$t"*"$t"*) - echo >&2 "$0: -u '$2': too many fields" - exit 1;; - *"$t"*"$t"*) - ;; - *) - echo >&2 "$0: -u '$2': not enough fields" - exit 1 - esac - loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$2 - shift - esac - logins=$logins$nl$login - ;; - -r) rlog_options=$rlog_options$nl${2?}; shift;; - -R) recursive=t;; - -t) tabwidth=${2?}; shift;; - -v) revision=t;; - -*) echo >&2 "$0: usage: $0 [options] [file ...] -Options: - [-c changelog] [-h hostname] [-i indent] [-l length] [-R] - [-r rlog_option] [-t tabwidth] [-v] - [-u 'login<TAB>fullname<TAB>mailaddr']..." - exit 1;; - *) break - esac - shift -done - -month_data=' - m[0]="Jan"; m[1]="Feb"; m[2]="Mar" - m[3]="Apr"; m[4]="May"; m[5]="Jun" - m[6]="Jul"; m[7]="Aug"; m[8]="Sep" - m[9]="Oct"; m[10]="Nov"; m[11]="Dec" -' - - -# Put rlog output into $rlogout. - -# If no rlog options are given, -# log the revisions checked in since the first ChangeLog entry. -# Since ChangeLog is only by date, some of these revisions may be duplicates of -# what's already in ChangeLog; it's the user's responsibility to remove them. -case $rlog_options in -'') - if test -s "$changelog" - then - e=' - /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{ - # ISO 8601 date - print $1 - exit - } - /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{ - # old-fashioned date and time (Emacs 19.31 and earlier) - '"$month_data"' - year = $5 - for (i=0; i<=11; i++) if (m[i] == $2) break - dd = $3 - printf "%d-%02d-%02d\n", year, i+1, dd - exit - } - ' - d=`$AWK "$e" <"$changelog"` || exit - case $d in - ?*) datearg="-d>$d" - esac - fi -esac - -# Use TZ specified by ChangeLog local variable, if any. -if test -s "$changelog" -then - extractTZ=' - /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{ - s//\1/; p; q - } - /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{ - s//UTC0/; p; q - } - ' - logTZ=`tail "$changelog" | sed -n "$extractTZ"` - case $logTZ in - ?*) TZ=$logTZ; export TZ - esac -fi - -# If CVS is in use, examine its repository, not the normal RCS files. -if test ! -f CVS/Repository -then - rlog=rlog - repository= -else - rlog='cvs log' - repository=`sed 1q <CVS/Repository` || exit - test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit - case $CVSROOT in - *:/*) - # remote repository - ;; - *) - # local repository - case $repository in - /*) ;; - *) repository=${CVSROOT?}/$repository - esac - if test ! -d "$repository" - then - echo >&2 "$0: $repository: bad repository (see CVS/Repository)" - exit 1 - fi - esac -fi - -# Use $rlog's -zLT option, if $rlog supports it. -case `$rlog -zLT 2>&1` in -*' option'*) ;; -*) rlog_options=-zLT$nl$rlog_options -esac - -# With no arguments, examine all files under the RCS directory. -case $# in -0) - case $repository in - '') - oldIFS=$IFS - IFS=$nl - case $recursive in - t) - RCSdirs=`find . -name RCS -type d -print` - filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||' - files=` - { - case $RCSdirs in - ?*) find $RCSdirs -type f -print - esac - find . -name '*,v' -print - } | - sort -u | - sed "$filesFromRCSfiles" - `;; - *) - files= - for file in RCS/.* RCS/* .*,v *,v - do - case $file in - RCS/. | RCS/..) continue;; - RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue - esac - files=$files$nl$file - done - case $files in - '') exit 0 - esac - esac - set x $files - shift - IFS=$oldIFS - esac -esac - -llogout=$TMPDIR/rcs2log$$l -rlogout=$TMPDIR/rcs2log$$r -trap exit 1 2 13 15 -trap "rm -f $llogout $rlogout; exit 1" 0 - -case $datearg in -?*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogout;; -'') $rlog $rlog_options ${1+"$@"} >$rlogout -esac || exit - - -# Get the full name of each author the logs mention, and set initialize_fullname -# to awk code that initializes the `fullname' awk associative array. -# Warning: foreign authors (i.e. not known in the passwd file) are mishandled; -# you have to fix the resulting output by hand. - -initialize_fullname= -initialize_mailaddr= - -case $loginFullnameMailaddrs in -?*) - case $loginFullnameMailaddrs in - *\"* | *\\*) - sed 's/["\\]/\\&/g' >$llogout <<EOF || exit -$loginFullnameMailaddrs -EOF - loginFullnameMailaddrs=`cat $llogout` - esac - - oldIFS=$IFS - IFS=$nl - for loginFullnameMailaddr in $loginFullnameMailaddrs - do - case $loginFullnameMailaddr in - *"$tab"*) IFS=$tab;; - *) IFS=: - esac - set x $loginFullnameMailaddr - login=$2 - fullname=$3 - mailaddr=$4 - initialize_fullname="$initialize_fullname - fullname[\"$login\"] = \"$fullname\"" - initialize_mailaddr="$initialize_mailaddr - mailaddr[\"$login\"] = \"$mailaddr\"" - done - IFS=$oldIFS -esac - -case $llogout in -?*) sort -u -o $llogout <<EOF || exit -$logins -EOF -esac -output_authors='/^date: / { - if ($2 ~ /^[0-9]*[-\/][0-9][0-9][-\/][0-9][0-9]$/ && $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9:]*;$/ && $4 == "author:" && $5 ~ /^[^;]*;$/) { - print substr($5, 1, length($5)-1) - } -}' -authors=` - $AWK "$output_authors" <$rlogout | - case $llogout in - '') sort -u;; - ?*) sort -u | comm -23 - $llogout - esac -` -case $authors in -?*) - cat >$llogout <<EOF || exit -$authors -EOF - initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/' - initialize_author=`sed -e "$initialize_author_script" <$llogout` - awkscript=' - BEGIN { - alphabet = "abcdefghijklmnopqrstuvwxyz" - ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - '"$initialize_author"' - } - { - if (author[$1]) { - fullname = $5 - if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) { - # Remove the junk from fullnames like "0000-Admin(0000)". - fullname = substr(fullname, index(fullname, "-") + 1) - fullname = substr(fullname, 1, index(fullname, "(") - 1) - } - if (fullname ~ /,[^ ]/) { - # Some sites put comma-separated junk after the fullname. - # Remove it, but leave "Bill Gates, Jr" alone. - fullname = substr(fullname, 1, index(fullname, ",") - 1) - } - abbr = index(fullname, "&") - if (abbr) { - a = substr($1, 1, 1) - A = a - i = index(alphabet, a) - if (i) A = substr(ALPHABET, i, 1) - fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1) - } - - # Quote quotes and backslashes properly in full names. - # Do not use gsub; traditional awk lacks it. - quoted = "" - rest = fullname - for (;;) { - p = index(rest, "\\") - q = index(rest, "\"") - if (p) { - if (q && q<p) p = q - } else { - if (!q) break - p = q - } - quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1) - rest = substr(rest, p+1) - } - - printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest - author[$1] = 0 - } - } - ' - - initialize_fullname=` - ( - cat /etc/passwd - for author in $authors - do nismatch $author passwd.org_dir - done - ypmatch $authors passwd - ) 2>/dev/null | - $AWK -F: "$awkscript" - `$initialize_fullname -esac - - -# Function to print a single log line. -# We don't use awk functions, to stay compatible with old awk versions. -# `Log' is the log message (with \n replaced by \r). -# `files' contains the affected files. -printlogline='{ - - # Following the GNU coding standards, rewrite - # * file: (function): comment - # to - # * file (function): comment - if (Log ~ /^\([^)]*\): /) { - i = index(Log, ")") - files = files " " substr(Log, 1, i) - Log = substr(Log, i+3) - } - - # If "label: comment" is too long, break the line after the ":". - sep = " " - if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string - - # Print the label. - printf "%s*%s:", indent_string, files - - # Print each line of the log, transliterating \r to \n. - while ((i = index(Log, CR)) != 0) { - logline = substr(Log, 1, i-1) - if (logline ~ /[^'"$tab"' ]/) { - printf "%s%s\n", sep, logline - } else { - print "" - } - sep = indent_string - Log = substr(Log, i+1) - } -}' - -# Pattern to match the `revision' line of rlog output. -rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$' - -case $hostname in -'') - hostname=`( - hostname || uname -n || uuname -l || cat /etc/whoami - ) 2>/dev/null` || { - echo >&2 "$0: cannot deduce hostname" - exit 1 - } - - case $hostname in - *.*) ;; - *) - domainname=`(domainname) 2>/dev/null` && - case $domainname in - *.*) hostname=$hostname.$domainname - esac - esac -esac - - -# Process the rlog output, generating ChangeLog style entries. - -# First, reformat the rlog output so that each line contains one log entry. -# Transliterate \n to \r so that multiline entries fit on a single line. -# Discard irrelevant rlog output. -$AWK <$rlogout ' - BEGIN { repository = "'"$repository"'" } - /^RCS file:/ { - if (repository != "") { - filename = $3 - if (substr(filename, 1, length(repository) + 1) == repository "/") { - filename = substr(filename, length(repository) + 2) - } - if (filename ~ /,v$/) { - filename = substr(filename, 1, length(filename) - 2) - } - if (filename ~ /(^|\/)Attic\/[^\/]*$/) { - i = length(filename) - while (substr(filename, i, 1) != "/") i-- - filename = substr(filename, 1, i - 6) substr(filename, i + 1) - } - } - rev = "?" - } - /^Working file:/ { if (repository == "") filename = $3 } - /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ { - if ($0 ~ /'"$rlog_revision_pattern"'/) { - rev = $2 - next - } - if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) { - date = $2 - if (date ~ /\//) { - # This is a traditional RCS format date YYYY/MM/DD. - # Replace "/"s with "-"s to get ISO format. - newdate = "" - while ((i = index(date, "/")) != 0) { - newdate = newdate substr(date, 1, i-1) "-" - date = substr(date, i+1) - } - date = newdate date - } - time = substr($3, 1, length($3) - 1) - author = substr($5, 1, length($5)-1) - printf "%s %s %s %s %s %c", filename, rev, date, time, author, 13 - rev = "?" - next - } - if ($0 ~ /^branches: /) { next } - if ($0 ~ /^(-----------*|===========*)$/) { print ""; next } - printf "%s%c", $0, 13 - } -' | - -# Now each line is of the form -# FILENAME REVISION YYYY-MM-DD HH:MM:SS[+-TIMEZONE] AUTHOR \rLOG -# where \r stands for a carriage return, -# and each line of the log is terminated by \r instead of \n. -# Sort the log entries, first by date+time (in reverse order), -# then by author, then by log entry, and finally by file name and revision -# (just in case). -sort +2 -4r +4 +0 | - -# Finally, reformat the sorted log entries. -$AWK ' - BEGIN { - logTZ = "'"$logTZ"'" - revision = "'"$revision"'" - - # Some awk variants do not understand "\r" or "\013", so we have to - # put a carriage return directly in the file. - CR="
" # <-- There is a single CR between the " chars here. - - # Initialize the fullname and mailaddr associative arrays. - '"$initialize_fullname"' - '"$initialize_mailaddr"' - - # Initialize indent string. - indent_string = "" - i = '"$indent"' - if (0 < '"$tabwidth"') - for (; '"$tabwidth"' <= i; i -= '"$tabwidth"') - indent_string = indent_string "\t" - while (1 <= i--) - indent_string = indent_string " " - } - - { - newlog = substr($0, 1 + index($0, CR)) - - # Ignore log entries prefixed by "#". - if (newlog ~ /^#/) { next } - - if (Log != newlog || date != $3 || author != $5) { - - # The previous log and this log differ. - - # Print the old log. - if (date != "") '"$printlogline"' - - # Logs that begin with "{clumpname} " should be grouped together, - # and the clumpname should be removed. - # Extract the new clumpname from the log header, - # and use it to decide whether to output a blank line. - newclumpname = "" - sep = "\n" - if (date == "") sep = "" - if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) { - i = index(newlog, "}") - newclumpname = substr(newlog, 1, i) - while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++ - newlog = substr(newlog, i+1) - if (clumpname == newclumpname) sep = "" - } - printf sep - clumpname = newclumpname - - # Get ready for the next log. - Log = newlog - if (files != "") - for (i in filesknown) - filesknown[i] = 0 - files = "" - } - if (date != $3 || author != $5) { - # The previous date+author and this date+author differ. - # Print the new one. - date = $3 - time = $4 - author = $5 - - zone = "" - if (logTZ && ((i = index(time, "-")) || (i = index(time, "+")))) - zone = " " substr(time, i) - - # Print "date[ timezone] fullname <email address>". - # Get fullname and email address from associative arrays; - # default to author and author@hostname if not in arrays. - if (fullname[author]) - auth = fullname[author] - else - auth = author - printf "%s%s %s ", date, zone, auth - if (mailaddr[author]) - printf "<%s>\n\n", mailaddr[author] - else - printf "<%s@%s>\n\n", author, "'"$hostname"'" - } - if (! filesknown[$1]) { - filesknown[$1] = 1 - if (files == "") files = " " $1 - else files = files ", " $1 - if (revision && $2 != "?") files = files " " $2 - } - } - END { - # Print the last log. - if (date != "") { - '"$printlogline"' - printf "\n" - } - } -' && - - -# Exit successfully. - -exec rm -f $llogout $rlogout - -# Local Variables: -# tab-width:4 -# End: diff --git a/lib-src/sorted-doc.c b/lib-src/sorted-doc.c deleted file mode 100644 index 0ba419d4907..00000000000 --- a/lib-src/sorted-doc.c +++ /dev/null @@ -1,254 +0,0 @@ -/* Give this program DOCSTR.mm.nn as standard input - and it outputs to standard output - a file of texinfo input containing the doc strings. - - This version sorts the output by function name. - */ - -#include <stdio.h> -#include <ctype.h> - -extern char *malloc (); -char *xmalloc (); - -#define NUL '\0' -#define MARKER '\037' - -#define DEBUG 0 - -typedef struct line LINE; - -struct line -{ - LINE *next; /* ptr to next or NULL */ - char *line; /* text of the line */ -}; - -typedef struct docstr DOCSTR; - -struct docstr /* Allocated thing for an entry. */ -{ - DOCSTR *next; /* next in the chain */ - char *name; /* name of the function or var */ - LINE *first; /* first line of doc text. */ - char type; /* 'F' for function, 'V' for variable */ -}; - - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ - -void -error (s1, s2) - char *s1, *s2; -{ - fprintf (stderr, "sorted-doc: "); - fprintf (stderr, s1, s2); - fprintf (stderr, "\n"); -} - -/* Print error message and exit. */ - -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -char * -xmalloc (size) - int size; -{ - char *result = malloc ((unsigned)size); - if (result == NULL) - fatal ("%s", "virtual memory exhausted"); - return result; -} - -char * -xstrdup (str) - char * str; -{ - char *buf = xmalloc (strlen (str) + 1); - (void) strcpy (buf, str); - return (buf); -} - -/* Comparison function for qsort to call. */ - -int -cmpdoc (a, b) - DOCSTR **a; - DOCSTR **b; -{ - register int val = strcmp ((*a)->name, (*b)->name); - if (val) return val; - return (*a)->type - (*b)->type; -} - - -enum state -{ - WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET -}; - -char *states[] = -{ - "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET" -}; - -int -main () -{ - register DOCSTR *dp = NULL; /* allocated DOCSTR */ - register LINE *lp = NULL; /* allocated line */ - register char *bp; /* ptr inside line buffer */ - register enum state state = WAITING; /* state at start */ - int cnt = 0; /* number of DOCSTRs read */ - - DOCSTR *docs; /* chain of allocated DOCSTRS */ - char buf[512]; /* line buffer */ - - while (1) /* process one char at a time */ - { - /* this char from the DOCSTR file */ - register int ch = getchar (); - - /* Beginnings */ - - if (state == WAITING) - { - if (ch == MARKER) - state = BEG_NAME; - } - else if (state == BEG_NAME) - { - cnt++; - if (dp == NULL) /* first dp allocated */ - { - docs = dp = (DOCSTR*) xmalloc (sizeof (DOCSTR)); - } - else /* all the rest */ - { - dp->next = (DOCSTR*) xmalloc (sizeof (DOCSTR)); - dp = dp->next; - } - lp = NULL; - dp->next = NULL; - bp = buf; - state = NAME_GET; - /* Record whether function or variable. */ - dp->type = ch; - ch = getchar (); - } - else if (state == BEG_DESC) - { - if (lp == NULL) /* first line for dp */ - { - dp->first = lp = (LINE*)xmalloc (sizeof (LINE)); - } - else /* continuing lines */ - { - lp->next = (LINE*)xmalloc (sizeof (LINE)); - lp = lp->next; - } - lp->next = NULL; - bp = buf; - state = DESC_GET; - } - - /* process gets */ - - if (state == NAME_GET || state == DESC_GET) - { - if (ch != MARKER && ch != '\n' && ch != EOF) - { - *bp++ = ch; - } - else /* saving and changing state */ - { - *bp = NUL; - bp = xstrdup (buf); - - if (state == NAME_GET) - dp->name = bp; - else - lp->line = bp; - - bp = buf; - state = (ch == MARKER) ? BEG_NAME : BEG_DESC; - } - } /* NAME_GET || DESC_GET */ - if (ch == EOF) - break; - } - - { - DOCSTR **array; - register int i; /* counter */ - - /* build array of ptrs to DOCSTRs */ - - array = (DOCSTR**)xmalloc (cnt * sizeof (*array)); - for (dp = docs, i = 0; dp != NULL ; dp = dp->next) - array[i++] = dp; - - /* sort the array by name; within each name, by type */ - - qsort ((char*)array, cnt, sizeof (DOCSTR*), cmpdoc); - - /* write the output header */ - - printf ("\\input texinfo @c -*-texinfo-*-\n"); - printf ("@setfilename ../info/summary\n"); - printf ("@settitle Command Summary for GNU Emacs\n"); - printf ("@unnumbered Command Summary for GNU Emacs\n"); - printf ("@table @asis\n"); - printf ("\n"); - printf ("@let@ITEM@item\n"); - printf ("@def@item{@filbreak@vskip5pt@ITEM}\n"); - printf ("@font@tensy cmsy10 scaled @magstephalf\n"); - printf ("@font@teni cmmi10 scaled @magstephalf\n"); - printf ("@def\\{{@tensy@char110}}\n"); /* this backslash goes with cmr10 */ - printf ("@def|{{@tensy@char106}}\n"); - printf ("@def@{{{@tensy@char102}}\n"); - printf ("@def@}{{@tensy@char103}}\n"); - printf ("@def<{{@teni@char62}}\n"); - printf ("@def>{{@teni@char60}}\n"); - printf ("@chardef@@64\n"); - printf ("@catcode43=12\n"); - printf ("@tableindent-0.2in\n"); - - /* print each function from the array */ - - for (i = 0; i < cnt; i++) - { - printf ("\n@item %s @code{%s}\n@display\n", - array[i]->type == 'F' ? "Function" : "Variable", - array[i]->name); - - for (lp = array[i]->first; lp != NULL ; lp = lp->next) - { - for (bp = lp->line; *bp; bp++) - { - /* the characters "@{}" need special treatment */ - if (*bp == '@' || *bp == '{' || *bp == '}') - { - putchar('@'); - } - putchar(*bp); - } - putchar ('\n'); - } - printf("@end display\n"); - } - - printf ("@end table\n"); - printf ("@bye\n"); - } - - return 0; -} diff --git a/lib-src/tcp.c b/lib-src/tcp.c deleted file mode 100644 index 5741b52d132..00000000000 --- a/lib-src/tcp.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * TCP/IP stream emulation for GNU Emacs. - * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc. - - * Author: Masanobu Umeda - * Maintainer: umerin@mse.kyutech.ac.jp - -This file is part of GNU Emacs. - -GNU Emacs is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. - - * - * Yasunari, Itoh at PFU limited contributed for Fujitsu UTS and SX/A. - * - * Thu Apr 6 13:47:37 JST 1989 - * USG fixes by Sakaeda <saka@mickey.trad.pf.fujitsu.junet> - * - * For Fujitsu UTS compile with: - * cc -O -o tcp tcp.c -DFUJITSU_UTS -lu -lsocket - */ - -#include <stdio.h> -#include <fcntl.h> -#include <ctype.h> -#include <sys/types.h> - -#ifdef FUJITSU_UTS -#define USG -#include <sys/ucbtypes.h> -#include <sys/tisp/socket.h> -#include <netdb.h> -#include <sys/tisp/in.h> -#else -#include <sys/socket.h> -#include <netdb.h> -#include <netinet/in.h> -#endif - -#ifdef USG -#include <sys/stat.h> -#include <signal.h> -#endif - -#ifdef FUJITSU_UTS -#define bcopy(f, t, n) memcpy (t, f, n) -#define bcmp(b1, b2, n) (memcmp (b1, b2, n)!=0) -#define bzero(b, n) memset (b, 0, n) -#endif - -#ifdef USG -int selectable = 1; - -sigout () -{ - fcntl (fileno (stdin), F_SETFL, 0); - exit (-1); -} -#endif - -main (argc, argv) - int argc; - char *argv[]; -{ - struct hostent *host; - struct sockaddr_in sockin, sockme; - struct servent *serv; - char *hostname = NULL; - char *service = "nntp"; - int port; - int readfds; - int writefds; - int server; /* NNTP Server */ - int emacsIn = fileno (stdin); /* Emacs intput */ - int emacsOut = fileno (stdout); /* Emacs output */ - char buffer[1024]; - int nbuffer; /* Number of bytes in buffer */ - int wret; - char *retry; /* retry bufferp */ - int false = 0; /* FALSE flag for setsockopt () */ - - if (argc < 2) - { - fprintf (stderr, "Usage: %s HOST [SERVICE]\n", argv[0]); - exit (1); - } - if (argc >= 2) - hostname = argv[1]; - if (argc >= 3) - service = argv[2]; - - if ((host = gethostbyname (hostname)) == NULL) - { - perror ("gethostbyname"); - exit (1); - } - if (isdigit (service[0])) - port = atoi (service); - else - { - serv = getservbyname (service, "tcp"); - if (serv == NULL) - { - perror ("getservbyname"); - exit (1); - } - port = serv->s_port; - } - - bzero (&sockin, sizeof (sockin)); - sockin.sin_family = host->h_addrtype; - bcopy (host->h_addr, &sockin.sin_addr, host->h_length); - sockin.sin_port = htons (port); - if ((server = socket (AF_INET, SOCK_STREAM, 0)) < 0) - { - perror ("socket"); - exit (1); - } - if (setsockopt (server, SOL_SOCKET, SO_REUSEADDR, &false, sizeof (false))) - { - perror ("setsockopt"); - exit (1); - } - bzero (&sockme, sizeof (sockme)); - sockme.sin_family = sockin.sin_family; - sockme.sin_addr.s_addr = INADDR_ANY; - if (bind (server, &sockme, sizeof (sockme)) < 0) - { - perror ("bind"); - exit (1); - } - if (connect (server, &sockin, sizeof (sockin)) < 0) - { - perror ("connect"); - close (server); - exit (1); - } - -#ifdef O_NDELAY - fcntl (server, F_SETFL, O_NDELAY); - -#ifdef USG - /* USG pipe cannot not select emacsIn */ - { - struct stat statbuf; - fstat (emacsIn, &statbuf); - if (statbuf.st_mode & 010000) - selectable = 0; - if (!selectable) - { - signal (SIGINT, sigout); - fcntl (emacsIn, F_SETFL, O_NDELAY); - } - } -#endif -#endif - - /* Connection established. */ - while (1) - { - readfds = (1 << server) | (1 << emacsIn); - if (select (32, &readfds, NULL, NULL, (struct timeval *)NULL) == -1) - { - perror ("select"); - exit (1); - } - if (readfds & (1 << emacsIn)) - { - /* From Emacs */ - nbuffer = read (emacsIn, buffer, sizeof buffer -1); - -#ifdef USG - if (selectable && nbuffer == 0) - { - goto finish; - } - else if (!(readfds & (1 << server)) && nbuffer == 0) - { - sleep (1); - } - else -#else - if (nbuffer == 0) - goto finish; -#endif - for (retry = buffer; nbuffer > 0; nbuffer -= wret, retry += wret) - { - writefds = 1 << server; - if (select (server+1, NULL, &writefds, NULL, (struct timeval*)NULL) == -1) - { - perror ("select"); - exit (1); - } - wret = write (server, retry, nbuffer); - if (wret < 0) goto finish; - } - } - if (readfds & (1 << server)) - { - /* From NNTP server */ - nbuffer = read (server, buffer, sizeof buffer -1); - if (nbuffer == 0) - goto finish; - for (retry = buffer; nbuffer > 0; nbuffer -= wret, retry += wret) - { - writefds = 1 << emacsOut; -#ifdef USG - if (selectable) -#endif - if (select (emacsOut+1, NULL, &writefds, NULL, (struct timeval*)NULL) == -1) - { - perror ("select"); - exit (1); - } - wret = write (emacsOut, retry, nbuffer); - if (wret < 0) goto finish; - } - } - } - - /* End of communication. */ - finish: - close (server); -#ifdef USG - if (!selectable) fcntl (emacsIn, F_SETFL, 0); -#endif - close (emacsIn); - close (emacsOut); - exit (0); -} diff --git a/lib-src/test-distrib.c b/lib-src/test-distrib.c deleted file mode 100644 index 01897b83a7f..00000000000 --- a/lib-src/test-distrib.c +++ /dev/null @@ -1,84 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -/* Cancel substitutions made by config.h for Emacs. */ -#undef open -#undef read -#undef write -#undef close - -#include <stdio.h> - -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif - - -/* Break string in two parts to avoid buggy C compilers that ignore characters - after nulls in strings. */ - -char string1[] = "Testing distribution of nonprinting chars:\n\ -Should be 0177: \177 Should be 0377: \377 Should be 0212: \212.\n\ -Should be 0000: "; - -char string2[] = ".\n\ -This file is read by the `test-distribution' program.\n\ -If you change it, you will make that program fail.\n"; - -char buf[300]; - -/* Like `read' but keeps trying until it gets SIZE bytes or reaches eof. */ -int -cool_read (fd, buf, size) - int fd; - char *buf; - int size; -{ - int num, sofar = 0; - - while (1) - { - if ((num = read (fd, buf + sofar, size - sofar)) == 0) - return sofar; - else if (num < 0) - return num; - sofar += num; - } -} - -int -main (argc, argv) - int argc; - char **argv; -{ - int fd; - - if (argc != 2) - { - fprintf (stderr, "Usage: %s testfile\n", argv[0]); - exit (2); - } - fd = open (argv[1], O_RDONLY); - if (fd < 0) - { - perror (argv[1]); - exit (2); - } - if (cool_read (fd, buf, sizeof string1) != sizeof string1 || - strcmp (buf, string1) || - cool_read (fd, buf, sizeof string2) != sizeof string2 - 1 || - strncmp (buf, string2, sizeof string2 - 1)) - { - fprintf (stderr, "Data in file `%s' has been damaged.\n\ -Most likely this means that many nonprinting characters\n\ -have been corrupted in the files of Emacs, and it will not work.\n", - argv[1]); - exit (2); - } - close (fd); -#ifdef VMS - exit (1); /* On VMS, success is 1. */ -#endif - return (0); -} diff --git a/lib-src/vcdiff b/lib-src/vcdiff deleted file mode 100755 index e2023809e01..00000000000 --- a/lib-src/vcdiff +++ /dev/null @@ -1,93 +0,0 @@ -#! /bin/sh -# -# Enhanced sccs diff utility for use with vc mode. -# This version is more compatible with rcsdiff(1). -# -# $Id: vcdiff,v 1.5 1995/07/07 22:47:57 eggert Exp $ -# - -DIFF="diff" -usage="$0: Usage: vcdiff [--brief] [-q] [-r<sid1>] [-r<sid2>] [diffopts] sccsfile..." - -PATH=$PATH:/usr/ccs/bin:/usr/sccs:/usr/xpg4/bin # common SCCS hangouts - -echo= -sid1= sid2= - -for f -do - case $f in - -*) - case $f in - --brief) - DIFF=cmp;; - -q) - echo=:;; - -r?*) - case $sid1 in - '') - sid1=$f - ;; - *) - case $sid2 in - ?*) echo "$usage" >&2; exit 2 ;; - esac - sid2=$f - ;; - esac - ;; - *) - options="$options $f" - ;; - esac - shift - ;; - *) - break - ;; - esac -done - -case $# in -0) - echo "$usage" >&2 - exit 2 -esac - - -rev1= rev2= status=0 -trap 'status=2; exit' 1 2 13 15 -trap 'rm -f $rev1 $rev2 || status=2; exit $status' 0 - -for f -do - s=2 - - case $f in - s.* | */s.*) - if - rev1=/tmp/geta$$ - get -s -p -k $sid1 "$f" > $rev1 && - case $sid2 in - '') - workfile=`expr " /$f" : '.*/s.\(.*\)'` - ;; - *) - rev2=/tmp/getb$$ - get -s -p -k $sid2 "$f" > $rev2 - workfile=$rev2 - esac - then - $echo $DIFF $options $sid1 $sid2 $workfile >&2 - $DIFF $options $rev1 $workfile - s=$? - fi - ;; - *) - echo "$0: $f is not an SCCS file" >&2 - esac - - if test $status -lt $s - then status=$s - fi -done diff --git a/lib-src/yow.c b/lib-src/yow.c deleted file mode 100644 index b67d2f1eeee..00000000000 --- a/lib-src/yow.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * yow.c - * - * Print a quotation from Zippy the Pinhead. - * Qux <Kaufman-David@Yale> March 6, 1986 - * - * This file is in the public domain because the author published it - * with no copyright notice before the US signed the Bern Convention. - * - * With dynamic memory allocation. - */ - -#include <stdio.h> -#include <ctype.h> -#include <../src/paths.h> /* For PATH_DATA. */ - -#define BUFSIZE 80 -#define SEP '\0' - -#ifndef YOW_FILE -#define YOW_FILE "yow.lines" -#endif - -#ifdef MSDOS -#define rootrelativepath(rel) \ -({\ - static char res[BUFSIZE], *p;\ - strcpy (res, argv[0]);\ - p = res + strlen (res);\ - while (p != res && *p != '/' && *p != '\\' && *p != ':') p--;\ - strcpy (p + 1, "../");\ - strcpy (p + 4, rel);\ - &res;}) -#endif - -char *malloc(), *realloc(); - -void yow(); -void setup_yow(); - -int -main (argc, argv) - int argc; - char *argv[]; -{ - FILE *fp; - char file[BUFSIZ]; - - if (argc > 2 && !strcmp (argv[1], "-f")) - strcpy (file, argv[2]); - else -#ifdef vms - sprintf (file, "%s%s", PATH_DATA, YOW_FILE); -#else - sprintf (file, "%s/%s", PATH_DATA, YOW_FILE); -#endif - - if ((fp = fopen(file, "r")) == NULL) { - fprintf(stderr, "yow: "); - perror(file); - exit(1); - } - - /* initialize random seed */ - srand((int) (getpid() + time((long *) 0))); - - setup_yow(fp); - yow(fp); - fclose(fp); - return 0; -} - -static long len = -1; -static long header_len; - -#define AVG_LEN 40 /* average length of a quotation */ - -/* Sets len and header_len */ -void -setup_yow(fp) - FILE *fp; -{ - int c; - - /* Get length of file */ - /* Because the header (stuff before the first SEP) can be very long, - * thus biasing our search in favor of the first quotation in the file, - * we explicitly skip that. */ - while ((c = getc(fp)) != SEP) { - if (c == EOF) { - fprintf(stderr, "yow: file contains no separators\n"); - exit(2); - } - } - header_len = ftell(fp); - if (header_len > AVG_LEN) - header_len -= AVG_LEN; /* allow the first quotation to appear */ - - if (fseek(fp, 0L, 2) == -1) { - perror("yow"); - exit(1); - } - len = ftell(fp) - header_len; -} - - -/* go to a random place in the file and print the quotation there */ -void -yow (fp) - FILE *fp; -{ - long offset; - int c, i = 0; - char *buf; - unsigned int bufsize; - - offset = rand() % len + header_len; - if (fseek(fp, offset, 0) == -1) { - perror("yow"); - exit(1); - } - - /* Read until SEP, read next line, print it. - (Note that we will never print anything before the first separator.) - If we hit EOF looking for the first SEP, just recurse. */ - while ((c = getc(fp)) != SEP) - if (c == EOF) { - yow(fp); - return; - } - - /* Skip leading whitespace, then read in a quotation. - If we hit EOF before we find a non-whitespace char, recurse. */ - while (isspace(c = getc(fp))) - ; - if (c == EOF) { - yow(fp); - return; - } - - bufsize = BUFSIZE; - buf = malloc(bufsize); - if (buf == (char *)0) { - fprintf(stderr, "yow: virtual memory exhausted\n"); - exit (3); - } - - buf[i++] = c; - while ((c = getc(fp)) != SEP && c != EOF) { - buf[i++] = c; - - if (i == bufsize-1) { - /* Yow! Is this quotation too long yet? */ - bufsize *= 2; - buf = realloc(buf, bufsize); - if (buf == (char *)0) { - fprintf(stderr, "yow: virtual memory exhausted\n"); - exit (3); - } - } - } - buf[i++] = 0; - printf("%s\n", buf); -} - |