/***************************************************************************
* This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
* is provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
***************************************************************************/
define(struct abbrev
**, char *, char *),
def_abbrev(struct abbrev
**),
private unsigned int hash(char *);
private struct abbrev
* lookup(struct abbrev
**, char *);
private unsigned int hash();
private struct abbrev
* lookup();
private struct abbrev
*A_tables
[NMAJORS
+ 1][HASHSIZE
] = {0};
register unsigned int hashval
= 0;
hashval
= (hashval
<< 2) + c
;
struct abbrev
*table
[HASHSIZE
];
strcpy(abbrev
, ask((char *) 0, "abbrev: "));
strcpy(phrase
, ask((char *) 0, "abbrev: %s phrase: ", abbrev
));
define(table
, abbrev
, phrase
);
register struct abbrev
*table
[HASHSIZE
];
register struct abbrev
*ap
;
for (ap
= table
[h
% HASHSIZE
]; ap
; ap
= ap
->a_next
)
if (ap
->a_hash
== h
&& strcmp(ap
->a_abbrev
, abbrev
) == 0)
define(table
, abbrev
, phrase
)
register struct abbrev
*table
[HASHSIZE
];
register struct abbrev
*ap
;
ap
= lookup(table
, abbrev
);
register unsigned int h
= hash(abbrev
);
ap
= (struct abbrev
*) emalloc(sizeof *ap
);
ap
->a_abbrev
= copystr(abbrev
);
ap
->a_phrase
= copystr(phrase
);
register char *wp
= wordbuf
,
#if !(defined(IBMPC) || defined(MAC))
WITH_TABLE(curbuf
->b_major
)
while (curchar
< point
.p_char
&& ismword(c
= linebuf
[curchar
])) {
#if (defined(IBMPC) || defined(MAC))
if ((ap
= lookup(A_tables
[curbuf
->b_major
], wordbuf
)) == 0 &&
(ap
= lookup(A_tables
[GLOBAL
], wordbuf
)) == 0) {
del_char(BACKWARD
, (wp
- wordbuf
));
for (cp
= ap
->a_phrase
; c
= *cp
; ) {
insert_c(islower(c
) && UC_count
&&
(cp
== ap
->a_phrase
|| (UC_count
> 1 && (cp
[-1] == ' '))) ?
private char *mode_names
[NMAJORS
+ 1] = {
fp
= open_file(file
, buf
, F_WRITE
, COMPLAIN
, QUIET
);
for (i
= 0; i
<= GLOBAL
; i
++) {
fprintf(fp
, "------%s abbrevs------\n", mode_names
[i
]);
for (tp
= A_tables
[i
]; tp
< &A_tables
[i
][HASHSIZE
]; tp
++)
for (ap
= *tp
; ap
; ap
= ap
->a_next
) {
add_mess(" %d written.", count
);
mode
= -1, /* Will be ++'d immediately */
fp
= open_file(file
, buf
, F_READ
, COMPLAIN
, QUIET
);
eof
= f_gets(fp
, genbuf
, LBSIZE
);
if (eof
|| genbuf
[0] == '\0')
if (strncmp(genbuf
, "------", 6) == 0) {
fmterr
: complain("Abbrev. format error, line %d.", file
, lnum
);
phrase_p
= index(genbuf
, ':');
*phrase_p
++ = '\0'; /* Null terminate the abbrev. */
define(A_tables
[mode
], genbuf
, phrase_p
);
def_abbrev(A_tables
[GLOBAL
]);
def_abbrev(A_tables
[curbuf
->b_major
]);
save_abbrevs(ask_file((char *) 0, (char *) 0, filebuf
));
rest_abbrevs(ask_file((char *) 0, (char *) 0, filebuf
));
char *tname
= "jove_wam.$$$",
*EditName
= "Abbreviation Edit";
if (ebuf
= buf_exists(EditName
)) {
if (ebuf
->b_type
!= B_SCRATCH
)
confirm("Over-write buffer %b?", ebuf
);
SetBuf(ebuf
= do_select(curwind
, EditName
));
ebuf
->b_type
= B_SCRATCH
;
/* Empty buffer. Save the definitions to a tmp file
and read them into this buffer so we can edit them. */
message("[Edit definitions and then type C-X C-C]");
Recur(); /* We edit them ... now */
/* RESetBuf in case we deleted the buffer while we were editing. */
SetBuf(ebuf
= do_select(curwind
, EditName
));
SetBuf(do_select(curwind
, obuf
->b_name
));
word
= ask((char *) 0, "Word: ");
if ((ap
= lookup(A_tables
[curbuf
->b_major
], word
)) == 0 &&
(ap
= lookup(A_tables
[GLOBAL
], word
)) == 0)
complain("%s: unknown abbrev.", word
);
hook
= findmac("Macro: ");
complain("[Undefined macro]");