1
0
mirror of https://github.com/rfivet/uemacs.git synced 2025-11-23 11:41:15 -05:00

180 Commits
cigue ... 4.2.2

Author SHA1 Message Date
9669fea1ce Review buffer list and mode line printing.
Increase version number as two buffer modes have been removed (Spell and Crypt).
2016-03-24 15:25:48 +08:00
645a0d734b Remove encryption as implementation is too weak. 2016-03-23 21:11:05 +08:00
8c968322f6 Remove Spell buffer mode as it is not connected to any implemented functionality. 2016-03-23 20:25:16 +08:00
3af4ee19a2 Adjust maximum file length in pklock. 2016-03-19 14:36:27 +08:00
a0ea6d07e6 Increase maximum file name length to 255 (Windows & Linux). 2016-03-19 11:37:54 +08:00
187b0ce4a3 Review echo of input on message line. 2016-03-12 12:58:05 +08:00
910e6576b5 Update Makefile after make depend.
Suppress warning when reaching end of main on Linux.
2016-03-03 21:17:23 +08:00
f781d458aa Review universal arg command and Alt-# processing in kbd_loop. 2016-03-03 21:15:45 +08:00
7188773d13 Move command loop from main to kbd_loop in execute. 2016-03-02 21:37:43 +08:00
5c6aac1ae9 Review execute keystroke handling logic. 2016-03-02 19:17:31 +08:00
ee667b25ed Move insbrace and fmatch to execute.
Review execute.
2016-03-01 19:17:39 +08:00
14ef4f50ab Review insbrace, getfence and fmatch.
Adjust timing to pause when highlighting matching brace.
$tpause <= 0 disable matching brace highlight.
2016-02-29 21:23:43 +08:00
663fc2e554 Fix: In C-mode, auto-indent increment was not correct when matching opening brace is first character of buffer. 2016-02-29 19:02:09 +08:00
775b16c7b1 Rewrite cinsert to avoid buffer size constraint when doing indentation in C mode. 2016-02-25 21:50:04 +08:00
a42c60045d Improve consistency of tab insertion behaviour while indenting and brace matching. 2016-02-25 17:08:27 +08:00
998559464b In C mode, insure indentation is correct when inserting newline at end of white lines. 2016-02-24 22:18:37 +08:00
15e5796426 In C mode, insertion of pound # can take a count as argument. 2016-02-24 21:43:11 +08:00
3436443807 Introduce boolean $hardtab to control insertion of hardcoded tab or soft ones (spaces). Review insert_tab accordingly. 2016-02-24 21:17:45 +08:00
8dfa92ba44 Review inspound, '#' insertion in C mode. 2016-02-24 20:00:44 +08:00
c390cf2a3e Remove tab width constraints, was [2, 4, 8], now [1... 2016-02-24 13:22:54 +08:00
3e27fcf19e Fix: handle tab size other than 8 in overwrite mode. 2016-02-23 22:00:05 +08:00
893658b3ef Fix issue #5 by rolling back commit 06b0d3f. This insure compatibility with both CYGWIN and XTERM terminals under Cygwin. 2016-02-12 13:11:50 +08:00
c378a80204 Recompile with -pedantic. 2015-11-25 10:42:33 +08:00
e3d7efda7f Add CRYPT mode to buffer when doing a set-encryption-key on a buffer where the mode is not set yet. 2015-11-06 11:33:05 +08:00
8aeb526a2a Clean up abs usage versus implementation.
Clarify ernd() behaviour.
2015-10-27 12:51:40 +08:00
83b4028c95 Avoid 176719 periodicity of &rnd 0. 2015-10-22 16:57:56 +08:00
9b1c5f48a2 Consistent use of upmode() to update all mode lines. 2015-10-22 15:26:07 +08:00
c1ebad4808 Always re-write entire line if reversed. This avoid minor redraw error with apropos.
Remove DEC Rainbow 100 specific code.
2015-10-22 10:10:39 +08:00
e5e2ca0636 Fix CID114556: Copy into fixed size buffer. 2015-10-05 17:44:05 +08:00
4feb70b484 Fix CID114555: Unchecked return value. 2015-10-05 17:42:57 +08:00
fa96d9e63e Merge branch 'execute' 2015-10-05 14:22:39 +08:00
4918da601c Increase version number before merge to master branch. 2015-10-05 14:20:15 +08:00
45f138ac07 Remove mlreply after transition to replacement newmlarg. 2015-10-05 14:15:24 +08:00
15453a9d52 Spawn commands based on newmlarg (replacement of mlreply). 2015-10-05 14:06:53 +08:00
bcba236265 Exec commands based on newmlarg (replacement of mlreply). 2015-10-05 13:27:45 +08:00
b59a47bb3a File commands based on newmlarg (replacement of mlreply). 2015-10-05 11:34:33 +08:00
b86ceeaf5e Buffer commands based on newmlarg (replacement of mlreply). 2015-10-01 09:11:54 +08:00
db30d6d734 Mode commands based on newmlarg (replacement of mlreply). 2015-10-01 08:19:39 +08:00
575659b1c1 apropos based on newmlarg (replacement of mlreply). 2015-10-01 08:03:14 +08:00
9682cdb2d2 Maps M-S to hunt-forward to match DOS Alt-S behavior. 2015-10-01 07:38:41 +08:00
06b0d3f00d Switch back from termio to posix for Cygwin to be better aligned with Linux. 2015-10-01 07:26:15 +08:00
d3b02af275 Missing random.c from commit 198980b, review of newmlargt interface. 2015-09-29 15:06:08 +08:00
f13ae3957c Replace mlreply by newmlarg in eval, allowing user variable length to exceed 255 bytes. 2015-09-29 11:43:30 +08:00
7f5f0dd7b3 Introduce newmlarg as alternative to mlreply.
Rewrite gotoline accordingly.
2015-09-29 10:43:19 +08:00
198980b81f Review newmlargt interface and obsolete mlreplyt. 2015-09-29 10:25:36 +08:00
ce4d105794 Allow either dynamic or pre-defined input size from message line.
Insure to capture ABORT status when doing input from message line.
2015-09-28 17:46:00 +08:00
3ffa8967ef Align implementation of overwrite-string with insert-string. 2015-09-28 13:37:22 +08:00
cbbd860bdc Rework insert-string for dynamic token input. 2015-09-27 22:13:20 +08:00
cfa5c7fb65 Review getnewtoken, introduce getnewtokval and rewrite function evaluation accordingly. 2015-09-27 21:11:51 +08:00
b5eb424ad0 Introduce newtoken()/getnewtoken() for full length extraction of tokens. 2015-09-27 19:19:55 +08:00
2c9cbbfb1e write-message buffer adjust to full width of the terminal. 2015-09-18 17:55:35 +08:00
e0550db4d1 $line returns a full copy of the current line instead of truncated at NSTRING. 2015-09-18 17:53:58 +08:00
c3f4666ff3 Review usage of mlreply/ macarg/ gettokval according to execution context. 2015-09-01 11:29:08 +08:00
8d412dc388 Review file scope of functions dealing with token extraction and token evaluation. 2015-08-25 16:34:15 +08:00
51967939b8 Harmonize usage of mlreply, mlreplyt and nextarg based on actual needs (input always terminated either on meta or newline characters). 2015-08-25 09:17:41 +08:00
1ab601071e In order to support # as comment indicator, buffer content prefix is changed to '='. #buffername becomes =buffername. 2015-08-19 15:46:40 +08:00
6b3061cedb '#' as an alternative to ';' to start a comment. 2015-08-19 15:43:50 +08:00
02d12c5d84 Allow -x cmdfile as an alternative to @cmdfile options. 2015-08-19 15:42:16 +08:00
84bf4de212 Review function name table search in eval.c:gtfun. 2015-07-24 10:21:37 +08:00
c10b525fb5 Clarify code intent of emergencyexit(). 2015-07-17 10:48:17 +08:00
2522a858c1 Fix CID#39937 Copy into fixed size buffer. 2015-07-17 10:44:35 +08:00
dfc9a50fcf Fix CID#39903 Unchecked return value. 2015-07-17 10:01:17 +08:00
4d19ef668a Literals starting with '-' were interpreted as command token instead of literal token, "-3 set %i" failed as -3 was tried as command instead of an argument to set. 2015-06-12 21:06:18 +08:00
26f0f2eb8b Offer va_list version of mlwrite. 2015-06-12 17:05:43 +08:00
405d8683dc Tabs are rendered as spaces on message line. This fixes debug info when $debug is TRUE. 2015-06-12 13:42:23 +08:00
90c170e200 FIX: 'insert-string &add -1 -2147483647' was '-./,),(-*,(' instead of '-2147483648'. 2015-06-06 08:25:44 +08:00
4a0759fa89 Rename parameter to avoid OpenHub line counter misinterpretation as C++. 2015-05-27 16:43:33 +08:00
783ad9c2f0 Add Coverity badge to README. 2015-05-08 17:10:34 +08:00
1adae6bead Fix: list-buffers sizes reported wrong sizes as it used curbp to access EOL flags in buffer mode. 2015-05-06 09:11:23 +08:00
6dfc2f057e Add 2 as a valid value of tab length. {2, 4, 8} 2015-05-05 19:42:53 +08:00
42d4a6be70 sizes reported by list-buffers are aligned with size reported by buffer-position. 2015-05-05 19:34:12 +08:00
0dc28967b5 Update project description. 2015-05-05 12:19:13 +08:00
af919c3f9c ^X= buffer-position displays EOL character as \r for DOS. Number of characters in file is also reported correctly. 2015-05-05 12:17:56 +08:00
267c218b9b Only display program name and version on the bottom mode line. 2015-04-19 11:59:31 +08:00
4ac1913cd1 CID 39934: Fix potential buffer overflow. 2015-04-13 18:26:06 +08:00
e3b6d1e076 Fix potential overflow during file look-up. 2015-03-26 15:56:33 +08:00
8597e3adcd Prefix number argument to execute-command-line is used as iteration count. 2015-03-26 11:04:36 +08:00
247fcfdfb8 Merge common code for setting prompt of search and incremental search. 2015-03-26 10:15:50 +08:00
ac267617ae Review potential buffer overflow when prompting for (incremental-)search pattern. 2015-03-25 15:15:43 +08:00
cfed6fdddf Extra allocation check during initialisation. 2015-03-24 17:49:12 +08:00
5a900d59e6 Fix CID 39917 Dereference null return value. 2015-03-24 11:59:10 +08:00
e34c15741e Fix CID 39919 Insecure temporary file. 2015-03-24 11:58:04 +08:00
4042ebe3d1 Fix CID 39916: potential dereference of Null pointer. 2015-03-24 11:57:10 +08:00
f8eb3531a4 Fix potential buffer overflow and align failure message display method on exit. 2015-03-23 19:12:38 +08:00
66649313ae Insure file descriptor is properly closed when doing filename completion. 2015-03-22 22:02:16 +08:00
8502fb66c6 Use binary search to locate function in sorted function name list. 2015-03-20 15:07:47 +08:00
70a5812928 Review function table format. 2015-03-19 22:37:41 +08:00
d57257d653 FIX: User variable names first 10 characters are now significant.
Also CID 39927 Unbounded source buffer, 39933 Copy into fixed size buffer.
2015-03-19 20:52:55 +08:00
7f7cc5b6fd Fix CID 39905, 39906, 39907: Operands don't affect result. 2015-03-19 14:29:24 +08:00
9b40894342 Fix CID 39908: Dead code. 2015-03-19 14:27:58 +08:00
8de64f81be Use strncpy instead of strcpy. (CID 39928 eval, 39931 file, 39932 exec, 39938 bind). 2015-03-19 12:42:47 +08:00
eb7217f8ec Fix CID 39910: &rnd 0 return a pseudo-random number instead of triggering a zero divide crash. 2015-03-18 12:27:55 +08:00
b1cc7bfe3a Fix CID 39902: Insure that buffer is properly terminated after a strncpy. 2015-03-17 17:17:35 +08:00
911b4cd402 Insure that coverity locs number is aligned with result from lc. 2015-03-17 17:14:43 +08:00
d01649bf3a Return error if &div or &mod by 0. 2015-03-17 09:04:22 +08:00
f97746a87b CID 39914: Fallthrough in switch was altering value of $gflags when assigning to $line. 2015-03-16 13:47:03 +08:00
5f9de6bb89 CID 39925: Missing size check on buffer name when creating a new buffer. 2015-03-16 13:24:08 +08:00
d56b3af45a CID 39909, 39912, 39918, 39920, 39922. 2015-03-16 11:17:28 +08:00
87350f4c16 Review getgoal code. 2015-03-16 10:46:51 +08:00
80cbd37f5c Add extra warning check and fix signed to unsigned comparison issues. 2015-02-28 20:29:00 +08:00
e8bb7b1ea2 Review apropos/buildlist/strinc.
Potential sign extension issue while converting key description to keycode.
2015-02-22 16:22:48 +08:00
61f5fe7e2d Fix off by one buffer access.
Minor variable scope review.
2015-02-22 14:58:25 +08:00
4b2c50f6d2 Clean up splint warnings:
- Inconsistencies between defines.h and estruct.h.
- Review scope of termio local variables.
- Type mismatch in utf8.
2015-02-16 13:41:59 +08:00
e2be62323b Review scope of exported variables and functions for bind, eval, file,fileio, random. 2015-02-16 11:39:16 +08:00
e556f7714b Avoid calling mlwrite with computed string as format parameter. 2015-02-15 17:32:13 +08:00
2b8992350d Avoid unnecessary sprintf & buffers when updating message or status line. 2015-02-15 16:10:44 +08:00
c10c550bdd Valid compilation when CLEAN is set.
Use assert() and robust fallback instead of exit() to handle 'impossible' cases.
2015-02-15 14:41:35 +08:00
115d9babae When reading file, identify encoding (ASCII, UTF-8, EXTENDED, MIXED). 2015-02-15 13:30:54 +08:00
fbe92a1f52 Only support UTF-8 keyboard sequence on Cygwin.
FIX: Missing on  Linux, ue --help prints progname set in Makefile.
2015-02-14 10:21:50 +08:00
703c472f0b Review message line outputs. 2015-02-13 21:48:05 +08:00
bb44fc57ad Limit the scope of mlforce to eval. 2015-02-13 17:46:42 +08:00
2953531913 Insure that mlwrite( "") as same effect as mlerase(). 2015-02-13 15:33:21 +08:00
5e5558e00b Align naming convention for output of text on the message line: mlout*. (Was a mix of log & write). 2015-02-13 12:31:59 +08:00
6021a22b60 Move rdonly() in scope of line which is the first user module in the dependency list. 2015-02-13 11:54:17 +08:00
f8df147015 Insure restflag and resterr() belong to same scope. 2015-02-13 11:23:12 +08:00
e13bc9ca7e Version 4.2
Consistent display of µEMACS as program name among
- ue --version
- on status bar
- insert-string $progname
- write-message $progname (FIX).
2015-02-12 13:15:45 +08:00
b2306e379d Alternate version of make source based on $() functions instead of shell commands. 2015-02-11 20:22:43 +08:00
a68c05ed77 When detecting target platform, remove Windows variable part to reduce to CYGWIN and MINGW32. 2015-02-11 15:19:11 +08:00
cbb6a26e33 Revise sanity check on UTF-8 keyboard input sequence. 2015-02-10 18:09:59 +08:00
5401aec485 Accept UTF-8 sequence as keyboard input. 2015-02-10 17:07:43 +08:00
7da7916b28 describe-key displays keycode in hexadecimal.
mlwrite assume parameter is unsigned int when doing %x format.
ostring output bytes > 0x7F as unsigned char.
2015-02-09 19:27:49 +08:00
3f1ac2596c Fix getccol reporting when dealing with characters in range 0x80 .. 0xA0. 2015-02-09 13:31:39 +08:00
135238106c backward char movement consistent with mixed byte/UTF-8 content. 2015-02-08 19:11:26 +08:00
356a003194 buffer-position reports character under cursor according to type (either 0xXX or \uXXXX). 2015-02-08 14:47:56 +08:00
bdbd2d5437 Assert that unicode are limited to 0-10FFFF. 2015-02-08 14:26:07 +08:00
2cef071492 Insure correct UTF-8 encoding: asc( chr( 0x800)) == 0x800.
buffer-position displays unicode value of character under cursor instead of first byte of unicode sequence.
2015-02-06 13:20:51 +08:00
4cbf1e9ae1 Review cursor movement in presence of mixed latin1/unicode encoding. 2015-02-04 12:37:57 +08:00
a2d1b54c61 README.md edited online with Bitbucket 2015-02-03 05:08:17 +00:00
de04424e51 Align scope and parameter type for linsert and is_beginning_utf8. 2015-02-02 19:44:35 +08:00
83b323272d Put back the Micro in uEMACS both in status line and version string (ue --version). 2015-02-02 19:20:48 +08:00
91455a2e5a Insure &asc &chr 128 equals 128.
Insert-string can't handle character code > 0xFF.
2015-02-02 12:50:52 +08:00
7c74bfdc1a Align cursor movement according to character representation (^c and \nn). 2015-01-31 07:57:26 +08:00
a6a8936b8d Move unsupported OS files to fridge. 2015-01-29 22:08:34 +08:00
ebe4b9b2cc Use standard exit code as parameter to exit() in bindable. 2015-01-29 21:35:47 +08:00
639d912c88 Display correct mode on first empty buffer. 2015-01-27 20:22:47 +08:00
bc90c36603 Use temporary buffer in nextarg to avoid issue with strncpy under Linux. 2015-01-26 20:05:02 +08:00
fe1eaf7348 Insure message line is correct after startup script execution and command line arguments processed. 2015-01-23 22:13:21 +08:00
7018880551 Review/Retest mlerase when erase to eol is not available. 2015-01-23 13:13:07 +08:00
5a235ecf8c Insure that last character of the message line is displayed. 2015-01-23 12:13:52 +08:00
09d5907f9e Insure writing on message line does not exceed terminal size. 2015-01-22 20:26:22 +08:00
daa6395128 Minor review of mlerase in relationship to usage in mlwrite. 2015-01-22 17:36:11 +08:00
15ae2d4135 Transition from logger/logwrite/mlwrite to writestr/writefmt. 2015-01-21 21:30:01 +08:00
891f4c3238 Restrict scope of mlputs to display. 2015-01-21 17:16:43 +08:00
b101f703c0 Insure consistent use of TTbeep for bell (instead of alternative TTputc( BEL)). 2015-01-21 14:48:03 +08:00
fbfaa29497 Add %B in string format of mlwrite to ring a bell. 2015-01-21 14:12:24 +08:00
4ca3f53385 Make use of logger to replace sequences of TTbeep-mlwrite-return. 2015-01-20 22:34:28 +08:00
36f24332c2 Review mkupper and ltos in eval. 2015-01-17 14:45:50 +08:00
f60e3fbc9f Review startup and associated prototypes. 2015-01-16 21:12:27 +08:00
5fda2735a5 Do not use a temporary buffer to prompt user in mlyesno, thus avoiding problem with '%' or overflow. 2015-01-16 17:55:23 +08:00
434c9ba7ab Review mlforce to avoid necessity to double '%' in input string, thus avoiding potential buffer overflow in caller functions (mdbugout and write-message). 2015-01-15 17:57:12 +08:00
01a84a3ac0 Insure debug output fits inside terminal and buffer width. 2015-01-15 16:46:45 +08:00
e3c8805260 Unify macro debugging code in eval and exec. 2015-01-15 14:36:19 +08:00
259de639e4 Limit scope of cbuf to exec. 2015-01-14 17:16:33 +08:00
84919039a5 Hide details of token extraction inside exec. 2015-01-13 16:42:14 +08:00
a634ae5087 Retest gflags and limit implementation details to eval. 2015-01-10 16:23:19 +08:00
f8c405f501 Limit visibility of token types to eval. 2015-01-09 17:53:29 +08:00
63776bb3f8 Restrict to local scope some internal funtions of eval. 2015-01-09 16:00:11 +08:00
3ce31669ae Clean up eval: local scope for gtfun, gtenv, gtusr. Review initial allocation of result buffer returned by gtfun. 2015-01-09 15:35:03 +08:00
57e5338ebd Insure &low and &upp don't point to the stack. 2015-01-09 09:46:03 +08:00
4070a97fc9 Review buffer usage in & function evaluation. 2015-01-08 17:36:25 +08:00
a6669903b2 Double maximum size of a user variable (128 -> 256). 2015-01-08 14:57:02 +08:00
8ddc8676ef More dynamic argument string size as parameters to predefined functions. 2015-01-08 14:16:15 +08:00
b596a3a09c macarg takes buffer length as parameter instead of assuming all buffer have NSTRING size. 2015-01-08 12:46:46 +08:00
d2d3581e74 Redimension result char array when doing &lef, &mid, &rig. 2015-01-07 14:47:13 +08:00
5756354dd5 Redimension result char array when doing &cat.
Intermediary step in supporting longer string retuns in functions.
2015-01-07 14:11:58 +08:00
534da43d08 Insure strings created by &lef and &mid are properly terminated. 2015-01-06 17:55:11 +08:00
e096092d5b Adjust MAXROW/MAXCOL to values aligned with 1920x1080 landscape resolution. If smaller font or portrait, limit to 400x150 (colxrow). 2015-01-05 16:54:21 +08:00
48ea9279a6 Allocate video buffers based on MAXROW/MAXCOL even if os window is smaller at initialization. 2015-01-02 20:26:34 +08:00
923d7bdc8e Insure resizing screen commands are aligned with OS window sizes. 2015-01-02 17:50:31 +08:00
c64d4ad381 README.md edited online with Bitbucket 2015-01-02 06:25:15 +00:00
20d21435e0 Rebuild on Linux.
Remove warnings on system and write call without return code check.
2015-01-02 14:20:07 +08:00
b6bd5c2927 Review header dependencies controlled by POSIX and MINGW32 flags. 2015-01-02 10:54:35 +08:00
5f7a1aa1a9 Rewrite make depend rule, replacing ed by sed. 2014-12-31 09:47:15 +08:00
8de97e3323 README.md edited online with Bitbucket 2014-12-25 03:30:41 +00:00
f0874a8497 Rebuild on Linux (xubuntu32).
Fix wrapper.h mode.
Silence warning of unused return value of system() in spawn.
2014-12-25 10:51:47 +08:00
7e8654faa1 CYGWIN not necessary to be set at build time if not making posix based version. 2014-12-24 11:18:52 +08:00
14bfe4fa5f Don't use 'char' for number of lines. Based on commit 8841922 from uEMACS/PK 2014-12-24 10:01:37 +08:00
3a67809c74 Merge remote-tracking branch 'origin/cigue' 2014-12-24 09:49:30 +08:00
bdd71519c4 Revert "Don't use 'char' for number of lines"
This reverts commit 8841922689.
2014-12-24 09:48:56 +08:00
Linus Torvalds
8841922689 Don't use 'char' for number of lines
Heh.  My new UHD monitor makes it easy to have more than 127 lines of
text.  I guess the 'char' could be an unsigned char, but quite frankly,
trying to save a couple of bytes per open editor window seems a bit
excessive these days.  So just make it 'int'.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-08 14:53:04 -08:00
64 changed files with 3589 additions and 3653 deletions

167
Makefile
View File

@@ -1,8 +1,8 @@
# Makefile for emacs, updated Mon, Nov 17, 2014 1:05:02 PM
# Makefile for emacs, updated Fri, Feb 13, 2015 12:02:52 PM
SRC=ansi.c basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c ibmpc.c input.c isearch.c line.c lock.c log.c main.c mingw32.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c wscreen.c
OBJ=ansi.o basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o ibmpc.o input.o isearch.o line.o lock.o log.o main.o mingw32.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o wscreen.o
HDR=basic.h bind.h bindable.h buffer.h crypt.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h log.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
SRC=basic.c bind.c bindable.c buffer.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mingw32.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c window.c word.c wrapper.c wscreen.c
OBJ=basic.o bind.o bindable.o buffer.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mingw32.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o window.o word.o wrapper.o wscreen.o
HDR=basic.h bind.h bindable.h buffer.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
# DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them
@@ -19,18 +19,22 @@ endif
export E Q
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
# for windows based target, insure we strip the variant part
# CYGWIN_NT-6.1, CYGWIN_NT-6.1-WOW, CYGWIN_NT-6.1-WOW64, MINGW32_NT-6.1
uname_S := $(shell sh -c 'echo $(uname_S) | sed s/_.*$$//')
PROGRAM=ue
CC=gcc
WARNINGS=-Wall -Wstrict-prototypes
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
CFLAGS=-O2 $(WARNINGS)
#CC=c89 +O3 # HP
#CFLAGS= -D_HPUX_SOURCE -DSYSV
#CFLAGS=-O4 -DSVR4 # Sun
#CFLAGS=-O -qchars=signed # RS/6000
ifeq ($(uname_S),Linux)
DEFINES=-DAUTOCONF -DPOSIX -DUSG -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) -DPOSIX -DUSG -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
LIBS=-lcurses
endif
ifeq ($(uname_S),FreeBSD)
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_FREEBSD_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
@@ -38,15 +42,11 @@ endif
ifeq ($(uname_S),Darwin)
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
endif
ifeq ($(uname_S),CYGWIN_NT-6.1-WOW64)
DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM)
LIBS=-lcurses # SYSV
ifeq ($(uname_S),CYGWIN)
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
LIBS=-lcurses
endif
ifeq ($(uname_S),CYGWIN_NT-6.1)
DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM)
LIBS=-lcurses # SYSV
endif
ifeq ($(uname_S),MINGW32_NT-6.1)
ifeq ($(uname_S),MINGW32)
DEFINES=-DAUTOCONF -DSYSV -DMINGW32 -DPROGRAM=$(PROGRAM)
LIBS=
endif
@@ -86,6 +86,9 @@ lint: ${SRC}
lint ${LFLAGS} ${SRC} >lintout
cat lintout
splint:
splint -weak $(DEFINES) $(SRC) -booltype boolean -booltrue TRUE -boolfalse FALSE +posixlib +matchanyintegral
errs:
@rm -f makeout
make $(PROGRAM) >makeout
@@ -98,111 +101,99 @@ source:
@mv Makefile Makefile.bak
@echo "# Makefile for emacs, updated `date`" >Makefile
@echo '' >>Makefile
#Sorted
@echo SRC=`ls *.c` >>Makefile
@echo OBJ=`ls *.c | sed s/c$$/o/` >>Makefile
@echo HDR=`ls *.h` >>Makefile
#UnSorted
# @echo SRC=$(wildcard *.c) >>Makefile
# @echo OBJ=$(patsubst %.c,%.o,$(wildcard *.c)) >>Makefile
# @echo HDR=$(wildcard *.h) >>Makefile
@echo '' >>Makefile
@sed -n -e '/^# DO NOT ADD OR MODIFY/,$$p' <Makefile.bak >>Makefile
depend: ${SRC}
@mv Makefile Makefile.bak
@sed -n -e '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
@echo >> Makefile
@for i in ${SRC}; do\
cc ${DEFINES} -MM $$i ; done >makedep
@echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
@echo '$$r ./makedep' >>eddep
@echo 'w' >>eddep
@cp Makefile Makefile.bak
@ed - Makefile <eddep
@rm eddep makedep
cc ${DEFINES} -MM $$i ; done >> Makefile
@echo '' >>Makefile
@echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile
@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>Makefile
@echo '# see make depend above' >>Makefile
# @for i in ${SRC}; do\
# cc ${DEFINES} -M $$i | sed -e 's, \./, ,' | grep -v '/usr/include' | \
# awk '{ if ($$1 != prev) { if (rec != "") print rec; \
# rec = $$0; prev = $$1; } \
# else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
# else rec = rec " " $$2 } } \
# END { print rec }'; done >makedep
.c.o:
$(E) " CC " $@
$(Q) ${CC} ${CFLAGS} ${DEFINES} -c $*.c
# DO NOT DELETE THIS LINE -- make depend uses it
ansi.o: ansi.c estruct.h
basic.o: basic.c basic.h buffer.h crypt.h line.h utf8.h display.h \
estruct.h input.h bind.h random.h terminal.h defines.h retcode.h \
window.h
bind.o: bind.c bind.h estruct.h bindable.h buffer.h crypt.h line.h utf8.h \
display.h ebind.h exec.h retcode.h file.h flook.h input.h names.h \
window.h defines.h
bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \
utf8.h display.h estruct.h file.h retcode.h input.h bind.h lock.h \
terminal.h
buffer.o: buffer.c buffer.h crypt.h line.h utf8.h defines.h display.h \
estruct.h file.h retcode.h input.h bind.h window.h
crypt.o: crypt.c crypt.h
display.o: display.c display.h buffer.h crypt.h line.h utf8.h estruct.h \
input.h bind.h termio.h terminal.h defines.h retcode.h version.h \
wrapper.h window.h
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
crypt.h line.h utf8.h eval.h exec.h retcode.h file.h isearch.h random.h \
region.h search.h spawn.h window.h defines.h word.h
eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h exec.h retcode.h execute.h flook.h input.h random.h \
search.h terminal.h defines.h termio.h version.h window.h
exec.o: exec.c exec.h retcode.h buffer.h crypt.h line.h utf8.h bind.h \
display.h estruct.h eval.h file.h flook.h input.h random.h window.h \
basic.o: basic.c basic.h buffer.h line.h retcode.h utf8.h estruct.h \
input.h bind.h mlout.h random.h terminal.h defines.h window.h
bind.o: bind.c bind.h estruct.h bindable.h buffer.h line.h retcode.h \
utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h window.h \
defines.h
execute.o: execute.c execute.h estruct.h bind.h random.h display.h file.h \
buffer.h crypt.h line.h utf8.h retcode.h terminal.h defines.h window.h
file.o: file.c file.h buffer.h crypt.h line.h utf8.h retcode.h defines.h \
estruct.h execute.h fileio.h input.h bind.h lock.h log.h window.h
fileio.o: fileio.c fileio.h crypt.h retcode.h defines.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h crypt.h
ibmpc.o: ibmpc.c estruct.h
bindable.o: bindable.c bindable.h defines.h buffer.h line.h retcode.h \
utf8.h display.h estruct.h file.h input.h bind.h lock.h mlout.h \
terminal.h
buffer.o: buffer.c buffer.h line.h retcode.h utf8.h defines.h estruct.h \
file.h input.h bind.h mlout.h window.h
display.o: display.c display.h estruct.h buffer.h line.h retcode.h utf8.h \
input.h bind.h termio.h terminal.h defines.h version.h wrapper.h \
window.h
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
search.h spawn.h window.h defines.h word.h
eval.o: eval.c eval.h basic.h bind.h buffer.h line.h retcode.h utf8.h \
display.h estruct.h exec.h execute.h flook.h input.h random.h search.h \
terminal.h defines.h termio.h version.h window.h
exec.o: exec.c exec.h retcode.h buffer.h line.h utf8.h bind.h display.h \
estruct.h eval.h file.h flook.h input.h random.h window.h defines.h
execute.o: execute.c execute.h estruct.h bind.h random.h retcode.h \
display.h file.h buffer.h line.h utf8.h input.h mlout.h search.h \
terminal.h defines.h window.h
file.o: file.c file.h buffer.h line.h retcode.h utf8.h defines.h \
display.h estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h \
window.h
fileio.o: fileio.c fileio.h defines.h retcode.h utf8.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h
input.o: input.c input.h bind.h estruct.h bindable.h display.h exec.h \
retcode.h names.h terminal.h defines.h wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h exec.h retcode.h input.h bind.h search.h terminal.h \
defines.h window.h
line.o: line.c line.h utf8.h buffer.h crypt.h estruct.h log.h retcode.h \
retcode.h names.h terminal.h defines.h utf8.h wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h line.h retcode.h utf8.h \
display.h estruct.h exec.h input.h bind.h search.h terminal.h defines.h \
window.h
line.o: line.c line.h retcode.h utf8.h buffer.h estruct.h mlout.h \
window.h defines.h
lock.o: lock.c estruct.h lock.h
log.o: log.c log.h retcode.h
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h utf8.h display.h eval.h execute.h file.h retcode.h input.h lock.h \
log.h random.h search.h terminal.h defines.h termio.h version.h window.h
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h line.h \
retcode.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h \
random.h search.h terminal.h defines.h termio.h version.h window.h
mingw32.o: mingw32.c
names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h utf8.h display.h eval.h exec.h retcode.h file.h isearch.h \
mlout.o: mlout.c mlout.h
names.o: names.c names.h basic.h bind.h bindable.h buffer.h line.h \
retcode.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.h \
region.h random.h search.h spawn.h window.h defines.h word.h
pklock.o: pklock.c estruct.h pklock.h
posix.o: posix.c termio.h
random.o: random.c random.h basic.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h execute.h input.h bind.h log.h retcode.h search.h \
terminal.h defines.h window.h
region.o: region.c region.h line.h utf8.h buffer.h crypt.h estruct.h \
log.h retcode.h random.h window.h defines.h
search.o: search.c search.h line.h utf8.h basic.h buffer.h crypt.h \
display.h estruct.h input.h bind.h log.h retcode.h terminal.h defines.h \
posix.o: posix.c
random.o: random.c random.h retcode.h basic.h buffer.h line.h utf8.h \
display.h estruct.h execute.h input.h bind.h search.h terminal.h \
defines.h window.h
region.o: region.c region.h line.h retcode.h utf8.h buffer.h estruct.h \
mlout.h random.h window.h defines.h
search.o: search.c search.h line.h retcode.h utf8.h basic.h buffer.h \
display.h estruct.h input.h bind.h mlout.h terminal.h defines.h window.h
spawn.o: spawn.c spawn.h defines.h buffer.h line.h retcode.h utf8.h \
display.h estruct.h exec.h file.h flook.h input.h bind.h terminal.h \
window.h
spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h exec.h retcode.h file.h flook.h input.h bind.h log.h \
terminal.h window.h
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
termio.h
termio.o: termio.c termio.h estruct.h retcode.h utf8.h
utf8.o: utf8.c utf8.h
vmsvt.o: vmsvt.c estruct.h
vt52.o: vt52.c estruct.h
window.o: window.c window.h defines.h buffer.h crypt.h line.h utf8.h \
basic.h display.h estruct.h execute.h terminal.h retcode.h wrapper.h
word.o: word.c word.h basic.h buffer.h crypt.h line.h utf8.h estruct.h \
log.h retcode.h random.h region.h window.h defines.h
window.o: window.c window.h defines.h buffer.h line.h retcode.h utf8.h \
basic.h display.h estruct.h execute.h terminal.h wrapper.h
word.o: word.c word.h basic.h buffer.h line.h retcode.h utf8.h estruct.h \
mlout.h random.h region.h window.h defines.h
wrapper.o: wrapper.c wrapper.h
wscreen.o: wscreen.c wscreen.h

View File

@@ -1,29 +1,19 @@
# README #
Cigue is ue on Cygwin, based on uEmacs/PK from kernel.org.
Ciguë is µEMACS (ue) on Cygwin/Linux, based on uEmacs/PK (em) from kernel.org.
### What is this repository for? ###
### Changes compare to uEmacs/PK ###
* Line termination detection with new buffer mode (either Unix or DOS).
* Encoding detection (ASCII, Extended ASCII, UTF-8 or Mixed).
* Some fixes related to size either unchecked or limited (strcpy, insert-string, filenames, $kill).
* Major refactoring of headers and file dependencies, hopefully to improve maintenance.
* Reactivation of target 'source' and 'depend' in Makefile.
* Some defaults changed due to 'finger habits': ue instead of em, ^S in commands mapping...
* Quick summary
* Version
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
### How to build ###
* dependencies: ncurses.
* make depend ; make
* MINGW32 target is experimental and lacks screen/kbd support.
### How do I get set up? ###
* Summary of set up
* Configuration
* Dependencies
* Database configuration
* How to run tests
* Deployment instructions
### Contribution guidelines ###
* Writing tests
* Code review
* Other guidelines
### Who do I talk to? ###
* Repo owner or admin
* Other community or team contact
### Badges ###
[![Coverity Status](https://scan.coverity.com/projects/4449/badge.svg)](https://scan.coverity.com/projects/4449)

92
basic.c
View File

@@ -19,10 +19,10 @@
#include <stdlib.h>
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "input.h"
#include "line.h"
#include "mlout.h"
#include "random.h"
#include "terminal.h"
#include "utf8.h"
@@ -38,35 +38,34 @@ int curgoal ; /* Goal for C-P, C-N */
* column, return the best choice for the offset. The offset is returned.
* Used by "C-N" and "C-P".
*/
static int getgoal(struct line *dlp)
{
int col;
int newcol;
int dbo;
int len = llength(dlp);
static unsigned getgoal( struct line *dlp) {
int col ;
unsigned idx ;
const unsigned len = llength( dlp) ;
col = 0;
dbo = 0;
while (dbo != len) {
unicode_t c;
int width = utf8_to_unicode(dlp->l_text, dbo, len, &c);
newcol = col;
col = 0 ;
idx = 0 ;
while( idx < len) {
unicode_t c ;
unsigned width = utf8_to_unicode( dlp->l_text, idx, len, &c) ;
/* Take tabs, ^X and \xx hex characters into account */
if (c == '\t')
newcol |= tabmask;
else if (c < 0x20 || c == 0x7F)
++newcol;
else if (c >= 0x80 && c <= 0xa0)
newcol += 2;
if( c == '\t')
col += tabwidth - col % tabwidth ;
else if( c < 0x20 || c == 0x7F)
col += 2 ;
else if( c >= 0x80 && c <= 0xA0)
col += 3 ;
else
col += 1 ;
++newcol;
if (newcol > curgoal)
break;
col = newcol;
dbo += width;
if( col > curgoal)
break ;
idx += width ;
}
return dbo;
return idx ;
}
/*
@@ -92,24 +91,26 @@ int gotoeol(int f, int n)
*
* @n: The specified line position at the current buffer.
*/
int gotoline(int f, int n)
{
int status;
char arg[NSTRING]; /* Buffer to hold argument. */
int gotoline( int f, int n) {
/* Get an argument if one doesnt exist. */
if (f == FALSE) {
if ((status =
mlreply("Line to GOTO: ", arg, NSTRING)) != TRUE) {
mlwrite("(Aborted)");
return status;
if( f == FALSE) {
int status ;
char *arg ; /* Buffer to hold argument. */
status = newmlarg( &arg, "Line to GOTO: ", 0) ;
if( status != TRUE) {
mloutstr( "(Aborted)") ;
return status ;
}
n = atoi(arg);
n = atoi( arg) ;
free( arg) ;
}
/* Handle the case where the user may be passed something like this:
* em filename +
* In this case we just go to the end of the buffer.
*/
/* Handle the case where the user may be passed something like this:
* em filename +
* In this case we just go to the end of the buffer.
*/
if (n == 0)
return gotoeob(f, n);
@@ -314,8 +315,8 @@ int setmark(int f, int n)
{
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
mlwrite("(Mark set)");
return TRUE;
mloutstr( "(Mark set)") ;
return TRUE ;
}
/*
@@ -329,10 +330,11 @@ int swapmark(int f, int n)
struct line *odotp;
int odoto;
if (curwp->w_markp == NULL) {
mlwrite("No mark in this window");
return FALSE;
if( curwp->w_markp == NULL) {
mloutstr( "No mark in this window") ;
return FALSE ;
}
odotp = curwp->w_dotp;
odoto = curwp->w_doto;
curwp->w_dotp = curwp->w_markp;

190
bind.c
View File

@@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "estruct.h"
@@ -27,13 +28,22 @@
#include "window.h"
#if APROP
static int buildlist( char *mstring) ;
static int strinc( char *source, char *sub) ;
#endif
static void cmdstr( int c, char *seq) ;
static unsigned int getckey( int mflag) ;
static unsigned int stock( char *keyname) ;
static int unbindchar( unsigned c) ;
static char *getfname( fn_t) ;
int help(int f, int n)
{ /* give me some help!!!!
bring up a fake buffer and read the help file
into it with view mode */
struct window *wp; /* scaning pointer to windows */
struct buffer *bp; /* buffer pointer to help */
char *fname = NULL; /* ptr to file returned by flook() */
@@ -62,11 +72,7 @@ int help(int f, int n)
/* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW;
curwp->w_bufp->b_flag |= BFINVS;
wp = wheadp;
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
upmode() ;
return TRUE;
}
@@ -81,7 +87,9 @@ int deskey(int f, int n)
/* get the command sequence to describe
change it to something we can print as well */
cmdstr(c = getckey(FALSE), &outseq[0]);
c = getckey( FALSE) ;
mlwrite( ": describe-key 0x%x, ", c) ;
cmdstr( c, &outseq[ 0]) ;
/* and dump it out */
ostring(outseq);
@@ -221,8 +229,7 @@ int unbindkey(int f, int n)
*
* int c; command key to unbind
*/
int unbindchar(int c)
{
static int unbindchar( unsigned c) {
struct key_tab *ktp; /* pointer into the command table */
struct key_tab *sktp; /* saved pointer into the command table */
int found; /* matched command flag */
@@ -262,39 +269,37 @@ int unbindchar(int c)
* bring up a fake buffer and list the key bindings
* into it with view mode
*/
int desbind(int f, int n)
int desbind( int f, int n) {
#if APROP
{
buildlist(TRUE, "");
return TRUE;
return buildlist( "") ;
}
int apro(int f, int n)
{ /* Apropos (List functions that match a substring) */
char mstring[NSTRING]; /* string to match cmd names to */
int status; /* status return */
/* Apropos (List functions that match a substring) */
int apro( int f, int n) {
char *mstring ; /* string to match cmd names to */
int status ; /* status return */
status = mlreply("Apropos string: ", mstring, NSTRING - 1);
if (status != TRUE)
return status;
status = newmlarg( &mstring, "Apropos string: ", 0) ;
if( status == TRUE) {
status = buildlist( mstring) ;
free( mstring) ;
} else if( status == FALSE)
status = buildlist( "") ; /* build list of all commands */
return buildlist(FALSE, mstring);
return status ;
}
/*
* build a binding list (limited or full)
*
* int type; true = full list, false = partial list
* char *mstring; match string if a partial list
* char *mstring; match string if a partial list, "" matches all
*/
int buildlist(int type, char *mstring)
static int buildlist( char *mstring) {
#endif
{
struct window *wp; /* scanning pointer to windows */
struct key_tab *ktp; /* pointer into the command table */
struct name_bind *nptr; /* pointer into the name binding table */
struct buffer *bp; /* buffer to put binding list into */
int cpos; /* current position to use in outseq */
char outseq[80]; /* output buffer for keystroke sequence */
/* split the current window to make room for the binding list */
@@ -333,20 +338,20 @@ int buildlist(int type, char *mstring)
wp->w_marko = 0;
/* build the contents of this window, inserting it line by line */
nptr = &names[0];
while (nptr->n_func != NULL) {
/* add in the command name */
strcpy(outseq, nptr->n_name);
cpos = strlen(outseq);
for( nptr = &names[ 0] ; nptr->n_func != NULL ; nptr++) {
int cpos ; /* current position to use in outseq */
#if APROP
/* if we are executing an apropos command..... */
if (type == FALSE &&
/* and current string doesn't include the search string */
strinc(outseq, mstring) == FALSE)
goto fail;
if( *mstring && strinc( nptr->n_name, mstring) == FALSE)
continue ;
#endif
/* add in the command name */
strncpy( outseq, nptr->n_name, sizeof outseq - 1) ;
outseq[ sizeof outseq - 1] = '\0' ;
cpos = strlen(outseq);
/* search down any keys bound to this */
ktp = &keytab[0];
while (ktp->k_fp != NULL) {
@@ -375,20 +380,13 @@ int buildlist(int type, char *mstring)
if (linstr(outseq) != TRUE)
return FALSE;
}
fail: /* and on to the next name */
++nptr;
}
curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
curbp->b_flag &= ~BFCHG; /* don't flag this as a change */
bp->b_mode |= MDVIEW; /* put this buffer view mode */
bp->b_flag &= ~BFCHG; /* don't flag this as a change */
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
wp->w_doto = 0;
wp = wheadp; /* and update ALL mode lines */
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
upmode() ; /* and update ALL mode lines */
mlwrite(""); /* clear the mode line */
return TRUE;
}
@@ -401,34 +399,25 @@ int buildlist(int type, char *mstring)
* char *source; string to search in
* char *sub; substring to look for
*/
int strinc(char *source, char *sub)
{
char *sp; /* ptr into source */
char *nxtsp; /* next ptr into source */
char *tp; /* ptr into substring */
static int strinc( char *source, char *sub) {
/* for each character in the source string */
sp = source;
while (*sp) {
tp = sub;
nxtsp = sp;
for( ; *source ; source++) {
char *nxtsp ; /* next ptr into source */
char *tp ; /* ptr into substring */
nxtsp = source;
/* is the substring here? */
while (*tp) {
if (*nxtsp++ != *tp)
break;
else
tp++;
}
for( tp = sub ; *tp ; tp++)
if( *nxtsp++ != *tp)
break ;
/* yes, return a success */
if (*tp == 0)
return TRUE;
/* no, onward */
sp++;
if( *tp == 0)
return TRUE ;
}
return FALSE;
return FALSE ;
}
#endif
@@ -437,46 +426,44 @@ int strinc(char *source, char *sub)
*
* int mflag; going for a meta sequence?
*/
unsigned int getckey(int mflag)
{
unsigned int c; /* character fetched */
char tok[NSTRING]; /* command incoming */
static unsigned int getckey( int mflag) {
unsigned int c ; /* character fetched */
/* check to see if we are executing a command line */
if (clexec) {
macarg(tok); /* get the next token */
return stock(tok);
}
if( clexec) {
char *tok ; /* command incoming */
tok = getnewtokval() ; /* get the next token */
if( tok == NULL)
c = 0 ; /* return dummy key on failure */
else {
c = stock( tok) ;
free( tok) ;
}
} else { /* or the normal way */
if( mflag)
c = get1key() ;
else
c = getcmd() ;
}
/* or the normal way */
if (mflag)
c = get1key();
else
c = getcmd();
return c;
return c ;
}
/*
* execute the startup file
*
* char *sfname; name of startup file (null if default)
* char *fname; name of startup file (null if default)
*/
int startup(char *sfname)
{
char *fname; /* resulting file name to execute */
int startup( const char *fname) {
if( !fname || *fname == 0) /* use default if empty parameter */
fname = rcfname ;
/* look up the startup file */
if (*sfname != 0)
fname = flook(sfname, TRUE);
else
fname = flook( rcfname, TRUE);
fname = flook( fname, TRUE) ; /* look up the startup file */
if( fname == NULL) /* if it isn't around, don't sweat it */
return TRUE ;
/* if it isn't around, don't sweat it */
if (fname == NULL)
return TRUE;
/* otherwise, execute the sucker */
return dofile(fname);
return dofile( fname) ; /* otherwise, execute the sucker */
}
/*
@@ -485,8 +472,7 @@ int startup(char *sfname)
* int c; sequence to translate
* char *seq; destination string for sequence
*/
void cmdstr(int c, char *seq)
{
static void cmdstr( int c, char *seq) {
char *ptr; /* pointer into current position in sequence */
ptr = seq;
@@ -526,8 +512,7 @@ void cmdstr(int c, char *seq)
*
* int c; key to find what is bound to it
*/
int (*getbind(int c))(int, int)
{
fn_t getbind( unsigned c) {
struct key_tab *ktp;
ktp = &keytab[0]; /* Look in key table. */
@@ -586,8 +571,7 @@ int (*fncmatch(char *fname)) (int, int)
*
* char *keyname; name of key to translate to Command key form
*/
unsigned int stock(char *keyname)
{
static unsigned int stock( char *keyname) {
unsigned int c; /* key sequence to return */
/* parse it up */
@@ -627,7 +611,7 @@ unsigned int stock(char *keyname)
*keyname -= 32;
/* the final sequence... */
c |= *keyname;
c |= *keyname & 0xFFU ;
return c;
}

10
bind.h
View File

@@ -5,7 +5,6 @@
#if APROP
int apro( int f, int n) ;
int strinc( char *source, char *sub) ;
#endif
/* Some global fuction declarations. */
@@ -15,15 +14,10 @@ int help( int f, int n) ;
int deskey( int f, int n) ;
int bindtokey( int f, int n) ;
int unbindkey( int f, int n) ;
int unbindchar( int c) ;
int desbind( int f, int n) ;
int buildlist( int type, char *mstring) ;
unsigned int getckey( int mflag) ;
int startup( char *sfname) ;
void cmdstr( int c, char *seq) ;
fn_t getbind( int c) ;
int startup( const char *fname) ;
fn_t getbind( unsigned keycode) ;
fn_t fncmatch( char *) ;
unsigned int stock( char *keyname) ;
char *transbind( char *skey) ;
#endif

View File

@@ -11,17 +11,9 @@
#include "file.h"
#include "input.h"
#include "lock.h"
#include "mlout.h"
#include "terminal.h"
#if VMS
#include <ssdef.h>
#define GOOD (SS$_NORMAL)
#endif
#ifndef GOOD
#define GOOD 0
#endif
/*
* Fancy quit command, as implemented by Norm. If the any buffer has
* changed do a write on that buffer and exit emacs, otherwise simply exit.
@@ -40,10 +32,10 @@ int quickexit(int f, int n)
&& (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */
&& (bp->b_flag & BFINVS) == 0) { /* Real. */
curbp = bp; /* make that buffer cur */
mlwrite("(Saving %s)", bp->b_fname);
mloutfmt( "(Saving %s)", bp->b_fname) ;
#if PKCODE
#else
mlwrite("\n");
mloutstr( "\n") ;
#endif
if ((status = filesave(f, n)) != TRUE) {
curbp = oldcb; /* restore curbp */
@@ -75,16 +67,16 @@ int quit(int f, int n)
TTputc('\r');
TTclose();
TTkclose();
exit(1);
exit( EXIT_FAILURE) ;
}
#endif
vttidy();
if (f)
exit(n);
else
exit(GOOD);
exit( EXIT_SUCCESS) ;
}
mlwrite("");
mloutstr( "") ;
return s;
}
@@ -96,10 +88,10 @@ int quit(int f, int n)
int ctlxlp(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
mloutstr( "%Macro already active") ;
return FALSE;
}
mlwrite("(Start macro)");
mloutstr( "(Start macro)") ;
kbdptr = &kbdm[0];
kbdend = kbdptr;
kbdmode = RECORD;
@@ -113,11 +105,11 @@ int ctlxlp(int f, int n)
int ctlxrp(int f, int n)
{
if (kbdmode == STOP) {
mlwrite("%%Macro not active");
mloutstr( "%Macro not active") ;
return FALSE;
}
if (kbdmode == RECORD) {
mlwrite("(End macro)");
mloutstr( "(End macro)") ;
kbdmode = STOP;
}
return TRUE;
@@ -131,7 +123,7 @@ int ctlxrp(int f, int n)
int ctlxe(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
mloutstr( "%Macro already active") ;
return FALSE;
}
if (n <= 0)
@@ -147,12 +139,10 @@ int ctlxe(int f, int n)
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
* Sometimes called as a routine, to do general aborting of stuff.
*/
int ctrlg(int f, int n)
{
TTbeep();
kbdmode = STOP;
mlwrite("(Aborted)");
return ABORT;
int ctrlg( int f, int n) {
kbdmode = STOP ;
mloutfmt( "%B(Aborted)") ;
return ABORT ;
}
/* user function that does NOTHING */

229
buffer.c
View File

@@ -17,10 +17,10 @@
#include <string.h>
#include "defines.h"
#include "display.h"
#include "estruct.h"
#include "file.h"
#include "input.h"
#include "mlout.h"
#include "window.h"
@@ -29,19 +29,14 @@ struct buffer *bheadp ; /* Head of list of buffers */
struct buffer *blistp ; /* Buffer for C-X C-B */
const char *modename[] = { /* name of modes */
"Wrap", "Cmode", "Spell", "Exact", "View", "Over",
"Wrap", "Cmode", "Exact", "View", "Over",
"Magic",
#if CRYPT
"Crypt",
#else
"",
#endif
"Asave", "Utf-8", "Dos"
} ;
int gmode = 0 ; /* global editor mode */
static const char modecode[] = "WCSEVOMYAUD" ; /* letters to represent modes */
static const char modecode[] = "WCEVOMAUD" ; /* letters to represent modes */
static int makelist( int iflag) ;
@@ -55,17 +50,24 @@ static void l_to_a( char *buf, int width, long num) ;
* if the use count is 0. Otherwise, they come
* from some other window.
*/
int usebuffer(int f, int n)
{
struct buffer *bp;
int s;
bname_t bufn ;
int usebuffer( int f, int n) {
struct buffer *bp ;
int status ;
char *bufn ;
if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE)
return s;
if ((bp = bfind(bufn, TRUE, 0)) == NULL)
return FALSE;
return swbuffer(bp);
/* Get buffer name */
status = newmlarg( &bufn, "Use buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* Find buffer in list */
bp = bfind( bufn, TRUE, 0) ;
free( bufn) ;
if( bp == NULL)
return FALSE ;
/* Switch to buffer */
return swbuffer( bp) ;
}
/*
@@ -164,19 +166,26 @@ int swbuffer(struct buffer *bp)
* if the buffer has been changed). Then free the header
* line and the buffer header. Bound to "C-X K".
*/
int killbuffer(int f, int n)
{
struct buffer *bp;
int s;
bname_t bufn ;
int killbuffer( int f, int n) {
struct buffer *bp ;
int status ;
char *bufn ;
if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE)
return s;
if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
return TRUE;
if (bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE; /* by doing nothing. */
return zotbuf(bp);
/* Get buffer name */
status = newmlarg( &bufn, "Kill buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* Find buffer in list */
bp = bfind( bufn, FALSE, 0) ;
free( bufn) ;
if( bp == NULL) /* Easy if unknown. */
return TRUE ;
if( bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE ; /* by doing nothing. */
return zotbuf( bp) ;
}
/*
@@ -189,7 +198,7 @@ int zotbuf(struct buffer *bp)
int s;
if (bp->b_nwnd != 0) { /* Error if on screen. */
mlwrite("Buffer is being displayed");
mloutstr("Buffer is being displayed");
return FALSE;
}
if ((s = bclear(bp)) != TRUE) /* Blow text away. */
@@ -215,31 +224,39 @@ int zotbuf(struct buffer *bp)
*
* int f, n; default Flag & Numeric arg
*/
int namebuffer(int f, int n)
{
struct buffer *bp; /* pointer to scan through all buffers */
bname_t bufn ; /* buffer to hold buffer name */
int namebuffer( int f, int n) {
struct buffer *bp ; /* pointer to scan through all buffers */
int status ;
char *bufn ; /* buffer to hold buffer name */
/* prompt for and get the new buffer name */
ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) !=
TRUE)
return FALSE;
/* prompt for and get the new buffer name */
ask:
status = newmlarg( &bufn, "Change buffer name to: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* and check for duplicates */
bp = bheadp;
while (bp != NULL) {
if (bp != curbp) {
/* if the names the same */
if (strcmp(bufn, bp->b_bname) == 0)
goto ask; /* try again */
/* and check for duplicates */
bp = bheadp ;
while( bp != NULL) {
if( bp != curbp) {
/* retry if the names are the same */
if( strcmp( bufn, bp->b_bname) == 0) {
free( bufn) ;
goto ask ; /* try again */
}
}
bp = bp->b_bufp; /* onward */
bp = bp->b_bufp ; /* onward */
}
strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */
curwp->w_flag |= WFMODE; /* make mode line replot */
mlerase();
return TRUE;
/* copy buffer name to structure */
strncpy( curbp->b_bname, bufn, sizeof( bname_t) - 1) ;
curbp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
free( bufn) ;
curwp->w_flag |= WFMODE ; /* make mode line replot */
mloutstr( "") ; /* erase message line */
return TRUE ;
}
/*
@@ -299,7 +316,12 @@ int listbuffers(int f, int n)
*
* int iflag; list hidden buffer flag
*/
#define MAXLINE MAXCOL
/* Layout: "ACT MODES Size Buffer File"
AAA MMMMMMMMMSSSSSSSSSS BBBBBBBBBBBBBBB FFF...
FNAMSTART ---------------------------------------^
*/
#define FNAMSTART (3 + 1 + NUMMODES + 10 + 1 + (sizeof( bname_t) - 1) + 1)
static int makelist( int iflag)
{
char *cp1;
@@ -310,24 +332,22 @@ static int makelist( int iflag)
int s;
int i;
long nbytes; /* # of bytes in current buffer */
char b[ 8 + 1] ;
char line[MAXLINE];
long nlines ; /* # of lines in current buffer */
char line[ FNAMSTART + sizeof( fname_t)] ;
blistp->b_flag &= ~BFCHG; /* Don't complain! */
if ((s = bclear(blistp)) != TRUE) /* Blow old text away */
return s;
strcpy(blistp->b_fname, "");
blistp->b_fname[ 0] = 0 ;
if( addline("ACT MODES Size Buffer File") == FALSE
|| addline("--- ----- ---- ------ ----") == FALSE)
|| addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE)
return FALSE;
bp = bheadp; /* For all buffers */
/* build line to report global mode settings */
cp1 = &line[0];
*cp1++ = ' ';
*cp1++ = ' ';
*cp1++ = ' ';
*cp1++ = ' ';
strcpy( line, " ") ;
cp1 = &line[ 4] ;
/* output the mode codes */
for (i = 0; i < NUMMODES; i++)
@@ -335,36 +355,27 @@ static int makelist( int iflag)
*cp1++ = modecode[i];
else
*cp1++ = '.';
strcpy(cp1, " Global Modes");
strcpy(cp1, " Global Modes");
if (addline(line) == FALSE)
return FALSE;
/* output the list of buffers */
while (bp != NULL) {
/* skip invisable buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE)) {
bp = bp->b_bufp;
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp) { /* For all buffers */
/* skip invisible buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE))
continue;
}
cp1 = &line[0]; /* Start at left edge */
/* output status of ACTIVE flag (has the file been read in? */
if (bp->b_active == TRUE) /* "@" if activated */
*cp1++ = '@';
else
*cp1++ = ' ';
/* output status of changed flag */
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed */
*cp1++ = '*';
else
*cp1++ = ' ';
/* output status of ACTIVE flag ('@' when the file has been read in) */
*cp1++ = (bp->b_active == TRUE) ? '@' : ' ' ;
/* report if the file is truncated */
if ((bp->b_flag & BFTRUNC) != 0)
*cp1++ = '#';
else
*cp1++ = ' ';
*cp1++ = ((bp->b_flag & BFTRUNC) != 0) ? '#' : ' ' ;
/* output status of changed flag ('*' when the buffer is changed) */
*cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
*cp1++ = ' '; /* space */
@@ -376,39 +387,43 @@ static int makelist( int iflag)
*cp1++ = '.';
}
/* No gap as buffer size if left padded with space */
/* No gap as buffer size is left-padded with space */
/* Buffer size */
nbytes = 0L; /* Count bytes in buf. */
nlines = 0 ;
lp = lforw(bp->b_linep);
while (lp != bp->b_linep) {
nbytes += (long) llength(lp) + 1L;
nlines += 1 ;
lp = lforw(lp);
}
l_to_a( b, sizeof b, nbytes) ; /* 8 digits string buffer size. */
cp2 = &b[0];
while ((c = *cp2++) != 0)
*cp1++ = c;
if( bp->b_mode & MDDOS)
nbytes += nlines ;
l_to_a( cp1, 10 + 1, nbytes) ; /* "%10d" formatted numbers */
cp1 += 10 ;
*cp1++ = ' '; /* Gap. */
cp2 = &bp->b_bname[0]; /* Buffer name */
while ((c = *cp2++) != 0)
*cp1++ = c;
cp2 = &bp->b_fname[0]; /* File name */
if (*cp2 != 0) {
while( cp1 < &line[ 3 + 1 + NUMMODES + 8 + 1 + (NBUFN-1) + 1])
*cp1++ = ' ';
while ((c = *cp2++) != 0) {
if (cp1 < &line[MAXLINE - 1])
*cp1++ = c;
}
}
*cp1 = 0; /* Add to the buffer. */
if (addline(line) == FALSE)
return FALSE;
bp = bp->b_bufp;
if( bp->b_fname[ 0] != 0) {
while( cp1 < &line[ FNAMSTART])
*cp1++ = ' ' ;
strncpy( cp1, bp->b_fname, &line[ sizeof line - 1] - cp1) ;
line[ sizeof line - 1] = 0 ;
} else
*cp1 = 0 ; /* Terminate string */
if( addline( line) == FALSE) /* Add to the buffer. */
return FALSE ;
}
return TRUE; /* All done */
return TRUE ; /* All done */
}
static void l_to_a(char *buf, int width, long num)
@@ -528,11 +543,9 @@ struct buffer *bfind( const char *bname, int cflag, int bflag)
bp->b_mode = gmode;
bp->b_nwnd = 0;
bp->b_linep = lp;
strcpy(bp->b_fname, "");
strcpy(bp->b_bname, bname);
#if CRYPT
bp->b_key[0] = 0;
#endif
bp->b_fname[ 0] = '\0' ;
strncpy( bp->b_bname, bname, sizeof( bname_t) - 1) ;
bp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
lp->l_fp = lp;
lp->l_bp = lp;
}

View File

@@ -1,16 +1,10 @@
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "crypt.h"
#include "line.h"
typedef char fname_t[ 80] ; /* file name type */
typedef char bname_t[ 16] ; /* buffer name type */
#define NBUFN sizeof( bname_t)
#if CRYPT
typedef char ekey_t[ 128] ; /* encryption key type */
#endif
typedef char fname_t[ 256] ; /* file name type */
typedef char bname_t[ 16] ; /* buffer name type */
/*
* Text is kept in buffers. A buffer header, described below, exists for every
@@ -36,9 +30,6 @@ struct buffer {
char b_flag; /* Flags */
fname_t b_fname ; /* File name */
bname_t b_bname ; /* Buffer name */
#if CRYPT
ekey_t b_key ; /* current encrypted key */
#endif
};
extern struct buffer *curbp ; /* Current buffer */
@@ -50,21 +41,17 @@ extern struct buffer *blistp ; /* Buffer for C-X C-B */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 11 /* # of defined modes */
#define NUMMODES 9 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#if CRYPT
#define MDCRYPT 0x0080 /* encrytion mode active */
#endif
#define MDASAVE 0x0100 /* auto-save mode */
#define MDUTF8 0x0200 /* utf8 mode */
#define MDDOS 0x0400 /* CRLF eol mode */
#define MDEXACT 0x0004 /* Exact matching for searches */
#define MDVIEW 0x0008 /* read-only buffer */
#define MDOVER 0x0010 /* overwrite mode */
#define MDMAGIC 0x0020 /* regular expresions in search */
#define MDASAVE 0x0040 /* auto-save mode */
#define MDUTF8 0x0080 /* utf8 mode */
#define MDDOS 0x0100 /* CRLF eol mode */
extern const char *modename[] ; /* text names of modes */

190
crypt.c
View File

@@ -1,190 +0,0 @@
/* crypt.c -- implements crypt.h */
#include "crypt.h"
/* CRYPT.C
*
* Encryption routines
*
* written by Dana Hoggatt and Daniel Lawrence
*/
#if CRYPT
#include <stdio.h>
static int mod95(int);
/**********
*
* myencrypt - in place encryption/decryption of a buffer
*
* (C) Copyright 1986, Dana L. Hoggatt
* 1216, Beck Lane, Lafayette, IN
*
* When consulting directly with the author of this routine,
* please refer to this routine as the "DLH-POLY-86-B CIPHER".
*
* This routine was written for Dan Lawrence, for use in V3.8 of
* MicroEMACS, a public domain text/program editor.
*
* I kept the following goals in mind when preparing this function:
*
* 1. All printable characters were to be encrypted back
* into the printable range, control characters and
* high-bit characters were to remain unaffected. this
* way, encrypted would still be just as cheap to
* transmit down a 7-bit data path as they were before.
*
* 2. The encryption had to be portable. The encrypted
* file from one computer should be able to be decrypted
* on another computer.
*
* 3. The encryption had to be inexpensive, both in terms
* of speed and space.
*
* 4. The system needed to be secure against all but the
* most determined of attackers.
*
* For encryption of a block of data, one calls myencrypt passing
* a pointer to the data block and its length. The data block is
* encrypted in place, that is, the encrypted output overwrites
* the input. Decryption is totally isomorphic, and is performed
* in the same manner by the same routine.
*
* Before using this routine for encrypting data, you are expected
* to specify an encryption key. This key is an arbitrary string,
* to be supplied by the user. To set the key takes two calls to
* myencrypt(). First, you call
*
* myencrypt(NULL, vector)
*
* This resets all internal control information. Typically (and
* specifically in the case on MICRO-emacs) you would use a "vector"
* of 0. Other values can be used to customize your editor to be
* "incompatable" with the normally distributed version. For
* this purpose, the best results will be obtained by avoiding
* multiples of 95.
*
* Then, you "encrypt" your password by calling
*
* myencrypt(pass, strlen(pass))
*
* where "pass" is your password string. Myencrypt() will destroy
* the original copy of the password (it becomes encrypted),
* which is good. You do not want someone on a multiuser system
* to peruse your memory space and bump into your password.
* Still, it is a better idea to erase the password buffer to
* defeat memory perusal by a more technical snooper.
*
* For the interest of cryptologists, at the heart of this
* function is a Beaufort Cipher. The cipher alphabet is the
* range of printable characters (' ' to '~'), all "control"
* and "high-bit" characters are left unaltered.
*
* The key is a variant autokey, derived from a wieghted sum
* of all the previous clear text and cipher text. A counter
* is used as salt to obiterate any simple cyclic behavior
* from the clear text, and key feedback is used to assure
* that the entire message is based on the original key,
* preventing attacks on the last part of the message as if
* it were a pure autokey system.
*
* Overall security of encrypted data depends upon three
* factors: the fundamental cryptographic system must be
* difficult to compromise; exhaustive searching of the key
* space must be computationally expensive; keys and plaintext
* must remain out of sight. This system satisfies this set
* of conditions to within the degree desired for MicroEMACS.
*
* Though direct methods of attack (against systems such as
* this) do exist, they are not well known and will consume
* considerable amounts of computing time. An exhaustive
* search requires over a billion investigations, on average.
*
* The choice, entry, storage, manipulation, alteration,
* protection and security of the keys themselves are the
* responsiblity of the user.
*
*
* char *bptr; buffer of characters to be encrypted
* unsigned len; number of characters in the buffer
*
**********/
void myencrypt(char *bptr, unsigned len)
{
int cc; /* current character being considered */
static long key = 0; /* 29 bit encipherment key */
static int salt = 0; /* salt to spice up key with */
if (!bptr) { /* is there anything here to encrypt? */
key = len; /* set the new key */
salt = len; /* set the new salt */
return;
}
while (len--) { /* for every character in the buffer */
cc = *bptr; /* get a character out of the buffer */
/* only encipher printable characters */
if ((cc >= ' ') && (cc <= '~')) {
/** If the upper bit (bit 29) is set, feed it back into the key. This
assures us that the starting key affects the entire message. **/
key &= 0x1FFFFFFFL; /* strip off overflow */
if (key & 0x10000000L) {
key ^= 0x0040A001L; /* feedback */
}
/** Down-bias the character, perform a Beaufort encipherment, and
up-bias the character again. We want key to be positive
so that the left shift here will be more portable and the
mod95() faster **/
cc = mod95((int) (key % 95) - (cc - ' ')) + ' ';
/** the salt will spice up the key a little bit, helping to obscure
any patterns in the clear text, particularly when all the
characters (or long sequences of them) are the same. We do
not want the salt to go negative, or it will affect the key
too radically. It is always a good idea to chop off cyclics
to prime values. **/
if (++salt >= 20857) { /* prime modulus */
salt = 0;
}
/** our autokey (a special case of the running key) is being
generated by a wieghted checksum of clear text, cipher
text, and salt. **/
key = key + key + cc + *bptr + salt;
}
*bptr++ = cc; /* put character back into buffer */
}
return;
}
static int mod95(int val)
{
/* The mathematical MOD does not match the computer MOD */
/* Yes, what I do here may look strange, but it gets the
job done, and portably at that. */
while (val >= 9500)
val -= 9500;
while (val >= 950)
val -= 950;
while (val >= 95)
val -= 95;
while (val < 0)
val += 95;
return val;
}
#endif

10
crypt.h
View File

@@ -1,10 +0,0 @@
#ifndef _CRYPT_H_
#define _CRYPT_H_
#define CRYPT 1 /* file encryption enabled? */
#if CRYPT
void myencrypt( char *bptr, unsigned len) ;
#endif
#endif

View File

@@ -1,3 +1,9 @@
/* defines.h -- */
#ifndef __DEFINES_H__
#define __DEFINES_H__
/* Must define one of
VMS | V7 | USG | BSD | MSDOS
*/
@@ -14,5 +20,11 @@
#define CTLX 0x40000000 /* ^X flag, or'ed in */
#define SPEC 0x80000000 /* special key (function keys) */
#define MAXCOL 500
#define MAXROW 500
/* Actual 380x134 on a 1920x1080 screen in landscape,
if smaller font or portrait orientation limit to 400x150 */
#define MAXCOL 400
#define MAXROW 150
#endif
/* end of defines.h */

459
display.c
View File

@@ -73,6 +73,8 @@ static int taboff = 0 ; /* tab offset for display */
int mpresf = FALSE ; /* TRUE if message in last line */
int scrollcount = 1 ; /* number of lines to scroll */
int discmd = TRUE ; /* display command flag */
int disinp = TRUE ; /* display input characters (echo) */
static int reframe(struct window *wp);
static void updone(struct window *wp);
@@ -87,14 +89,11 @@ static void modeline(struct window *wp);
static void mlputi(int i, int r);
static void mlputli(long l, int r);
static void mlputf(int s);
static void mlputs( unsigned char *s) ;
#if SIGWINCH
static int newscreensize(int h, int w);
#endif
#if RAINBOW
static void putline(int row, int col, char *buf);
#endif
/*
* Initialize the data structures used by the display code. The edge vectors
* used to access the screens are set up. The operating system's terminal I/O
@@ -158,13 +157,17 @@ void vtfree(void)
*/
void vttidy(void)
{
mlerase();
movecursor(term.t_nrow, 0);
TTflush();
mlerase() ; /* ends with movecursor( term.t_nrow, 0) and TTflush() */
TTclose();
TTkclose();
#ifdef PKCODE
write(1, "\r", 1);
{
int ret ;
ret = write( 1, "\r", 1) ;
if( ret != 1) {
/* some error handling here */
}
}
#endif
}
@@ -209,8 +212,9 @@ static void vtputc(int c)
if (c == '\t') {
do {
vtputc(' ');
} while (((vtcol + taboff) & tabmask) != 0);
return;
} while( ((vtcol + taboff) % tabwidth) != 0) ;
return ;
}
if (c < 0x20) {
@@ -238,6 +242,17 @@ static void vtputc(int c)
++vtcol;
}
static int vtputs( const char *s) {
int n = 0 ;
while( *s) {
vtputc( *s++) ;
n += 1 ;
}
return n ;
}
/*
* Erase from the end of the software cursor to the end of the line on which
* the software cursor is located.
@@ -565,14 +580,16 @@ void updpos(void)
i = 0;
while (i < curwp->w_doto) {
unicode_t c;
int bytes;
bytes = utf8_to_unicode(lp->l_text, i, curwp->w_doto, &c);
i += bytes;
if (c == '\t')
curcol |= tabmask;
++curcol;
i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ;
if( c == '\t')
curcol += tabwidth - curcol % tabwidth ;
else if( c < 0x20 || c == 0x7F)
curcol += 2 ; /* displayed as ^c */
else if( c >= 0x80 && c <= 0xA0)
curcol += 3 ; /* displayed as \xx */
else
curcol += 1 ;
}
/* if extended, flag so and update the virtual line image */
@@ -891,8 +908,7 @@ static void updext(void)
/*
* Update a single line. This does not know how to use insert or delete
* character sequences; we are using VT52 functionality. Update the physical
* row and column variables. It does try an exploit erase to end of line. The
* RAINBOW version of this routine uses fast video.
* row and column variables. It does try an exploit erase to end of line.
*/
#if MEMMAP
/* UPDATELINE specific code for the IBM-PC and other compatables */
@@ -939,29 +955,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
*/
static int updateline(int row, struct video *vp1, struct video *vp2)
{
#if RAINBOW
/* UPDATELINE specific code for the DEC rainbow 100 micro */
unicode_t *cp1;
unicode_t *cp2;
int nch;
/* since we don't know how to make the rainbow do this, turn it off */
flags &= (~VFREV & ~VFREQ);
cp1 = &vp1->v_text[0]; /* Use fast video. */
cp2 = &vp2->v_text[0];
putline(row + 1, 1, cp1);
nch = term.t_ncol;
do {
*cp2 = *cp1;
++cp2;
++cp1;
}
while (--nch);
*flags &= ~VFCHG;
#else
/* UPDATELINE code for all other versions */
unicode_t *cp1;
@@ -986,20 +979,18 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
#endif
#if REVSTA | COLOR
/* if we need to change the reverse video status of the
current line, we need to re-write the entire line */
/* do a re-write of the entire line if it is reverse or there
** is a request to change the reverse status */
rev = (vp1->v_flag & VFREV) == VFREV;
req = (vp1->v_flag & VFREQ) == VFREQ;
if ((rev != req)
if( req || (req != rev)
#if COLOR
|| (vp1->v_fcolor != vp1->v_rfcolor)
|| (vp1->v_bcolor != vp1->v_rbcolor)
#endif
) {
movecursor(row, 0); /* Go to start of line. */
/* set rev video if needed */
if (rev != req)
(*term.t_rev) (req);
TTrev( req) ; /* set needed rev video state */
/* scan through the line and dump it to the screen and
the virtual screen array */
@@ -1009,9 +1000,8 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
++ttcol;
*cp2++ = *cp1++;
}
/* turn rev video off */
if (rev != req)
(*term.t_rev) (FALSE);
TTrev( FALSE) ; /* turn rev video off */
/* update the needed flags */
vp1->v_flag &= ~VFCHG;
@@ -1089,7 +1079,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
#endif
vp1->v_flag &= ~VFCHG; /* flag this line as updated */
return TRUE;
#endif
}
#endif
@@ -1101,14 +1090,11 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
*/
static void modeline(struct window *wp)
{
char *cp;
int c;
int n; /* cursor position count */
struct buffer *bp;
int i; /* loop index */
int lchar; /* character to draw line in buffer with */
int firstm; /* is this the first mode? */
char tline[NLINE]; /* buffer for part of mode line */
n = wp->w_toprow + wp->w_ntrows; /* Location. */
vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL; /* Redraw next time. */
@@ -1132,78 +1118,45 @@ static void modeline(struct window *wp)
lchar = '-';
bp = wp->w_bufp;
#if PKCODE == 0
if ((bp->b_flag & BFTRUNC) != 0)
vtputc('#');
vtputc( ((bp->b_flag & BFTRUNC) != 0) ? '#' : lchar) ; /* truncated? */
vtputc( ((bp->b_flag & BFCHG) != 0) ? '*' : lchar) ; /* changed? */
vtputc( ' ') ;
if( n == term.t_nrow - 1)
n = 3 + vtputs( PROGRAM_NAME_LONG " " VERSION ": ") ;
else
#endif
vtputc(lchar);
n = 3 ;
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed. */
vtputc('*');
else
vtputc(lchar);
n = 2;
cp = " " PROGRAM_NAME_LONG " " VERSION ": " ;
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
cp = &bp->b_bname[0];
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
strcpy(tline, " (");
n += vtputs( bp->b_bname) ;
n += vtputs( " (") ;
/* display the modes */
firstm = TRUE;
if ((bp->b_flag & BFTRUNC) != 0) {
firstm = FALSE;
strcat(tline, "Truncated");
}
n += vtputs( "Truncated") ;
} else
firstm = TRUE ;
for (i = 0; i < NUMMODES; i++) /* add in the mode flags */
if (wp->w_bufp->b_mode & (1 << i)) {
if (firstm != TRUE)
strcat(tline, " ");
firstm = FALSE;
strcat( tline, modename[ i]) ;
}
strcat(tline, ") ");
n += vtputs( " ") ;
else
firstm = FALSE ;
cp = &tline[0];
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
n += vtputs( modename[ i]) ;
}
n += vtputs( ") ") ;
#if PKCODE
if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0)
if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0) {
#else
if (bp->b_fname[0] != 0) /* File name. */
if (bp->b_fname[0] != 0) { /* File name. */
n += vtputs( "File: ") ;
#endif
{
#if PKCODE == 0
cp = "File: ";
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
#endif
cp = &bp->b_fname[0];
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
n += vtputs( bp->b_fname) ;
vtputc(' ');
++n;
}
@@ -1217,6 +1170,7 @@ static void modeline(struct window *wp)
struct line *lp = wp->w_linep;
int rows = wp->w_ntrows;
char *msg = NULL;
char tline[ 6] ; /* buffer for part of mode line */
vtcol = n - 7; /* strlen(" top ") plus a couple */
while (rows--) {
@@ -1238,7 +1192,7 @@ static void modeline(struct window *wp)
}
if (!msg) {
struct line *lp;
int numlines, predlines, ratio;
int numlines, predlines ;
lp = lforw(bp->b_linep);
numlines = 0;
@@ -1253,22 +1207,28 @@ static void modeline(struct window *wp)
if (wp->w_dotp == bp->b_linep) {
msg = " Bot ";
} else {
ratio = 0;
int ratio = 0 ;
if (numlines != 0)
ratio =
(100L * predlines) / numlines;
if (ratio > 99)
ratio = 99;
sprintf(tline, " %2d%% ", ratio);
tline[ 0] = ' ' ;
tline[ 1] = ratio / 10 + '0' ;
tline[ 2] = ratio % 10 + '0' ;
tline[ 3] = '%' ;
tline[ 4] = ' ' ;
tline[ 5] = 0 ;
if( tline[ 1] == '0')
tline[ 1] = ' ' ;
msg = tline;
}
}
cp = msg;
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
n += vtputs( msg) ;
}
}
@@ -1302,30 +1262,47 @@ void movecursor(int row, int col)
* is not considered to be part of the virtual screen. It always works
* immediately; the terminal buffer is flushed via a call to the flusher.
*/
void mlerase(void)
{
int i;
movecursor(term.t_nrow, 0);
if (discmd == FALSE)
return;
void mlerase( void) {
movecursor( term.t_nrow, 0) ;
if( discmd != FALSE) {
#if COLOR
TTforg(7);
TTbacg(0);
TTforg( 7) ;
TTbacg( 0) ;
#endif
if (eolexist == TRUE)
TTeeol();
else {
for (i = 0; i < term.t_ncol - 1; i++)
TTputc(' ');
movecursor(term.t_nrow, 1); /* force the move! */
movecursor(term.t_nrow, 0);
if( eolexist == TRUE)
TTeeol() ;
else {
for( ttcol = 0 ; ttcol < term.t_ncol ; ttcol++)
TTputc( ' ') ;
movecursor( term.t_nrow, 0) ;
}
mpresf = FALSE ;
}
TTflush();
mpresf = FALSE;
TTflush() ;
}
static void mlputc( char c) {
if( ttcol < term.t_ncol) {
TTputc( c) ;
++ttcol ;
}
}
/*
* output a string of output characters
*
* char *s; string to output
*/
void ostring( char *s) {
if( discmd)
while( *s)
mlputc( *s++ & 0xFF) ;
}
/*
* Write a message into the message line. Keep track of the physical cursor
* position. A small class of printf like format items is handled. Assumes the
@@ -1335,10 +1312,8 @@ void mlerase(void)
* char *fmt; format string for output
* char *arg; pointer to first argument to print
*/
void mlwrite(const char *fmt, ...)
{
void vmlwrite( const char *fmt, va_list ap) {
int c; /* current char in format string */
va_list ap;
/* if we are not currently echoing on the command line, abort this */
if (discmd == FALSE) {
@@ -1352,18 +1327,16 @@ void mlwrite(const char *fmt, ...)
#endif
/* if we can not erase to end-of-line, do it manually */
if (eolexist == FALSE) {
mlerase();
TTflush();
}
if( eolexist == FALSE)
mlerase() ; /* ends with movecursor( term.t_nrow, 0) and TTflush() */
else
movecursor( term.t_nrow, 0) ;
movecursor(term.t_nrow, 0);
va_start(ap, fmt);
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
while ((c = *fmt++) != 0) {
if (c != '%') {
TTputc(c);
++ttcol;
} else {
if (c != '%')
mlputc( c) ;
else {
c = *fmt++;
switch (c) {
case 'd':
@@ -1383,43 +1356,38 @@ void mlwrite(const char *fmt, ...)
break;
case 's':
mlputs(va_arg(ap, char *));
mlputs( (unsigned char *) va_arg( ap, char *)) ;
break;
case 'f':
mlputf(va_arg(ap, int));
break;
case 'B': /* ring a bell */
TTbeep() ;
break ;
default:
TTputc(c);
++ttcol;
mlputc( '%') ;
case '%':
mlputc( c) ;
}
}
}
va_end(ap);
/* if we can, erase to the end of screen */
if (eolexist == TRUE)
TTeeol();
if( eolexist == TRUE && ttcol < term.t_ncol)
TTeeol() ;
TTflush();
mpresf = TRUE;
}
/*
* Force a string out to the message line regardless of the
* current $discmd setting. This is needed when $debug is TRUE
* and for the write-message and clear-message-line commands
*
* char *s; string to force out
*/
void mlforce(char *s)
{
int oldcmd; /* original command display flag */
oldcmd = discmd; /* save the discmd value */
discmd = TRUE; /* and turn display on */
mlwrite(s); /* write the string out */
discmd = oldcmd; /* and restore the original setting */
void mlwrite( const char *fmt, ...) {
va_list ap ;
va_start( ap, fmt) ;
vmlwrite( fmt, ap) ;
va_end( ap) ;
}
/*
@@ -1427,13 +1395,31 @@ void mlforce(char *s)
* the characters in the string all have width "1"; if this is not the case
* things will get screwed up a little.
*/
void mlputs(char *s)
{
int c;
static void mlputs( unsigned char *s) {
unicode_t c ;
while ((c = *s++) != 0) {
TTputc(c);
++ttcol;
while( ((c = *s++) != 0) && (ttcol < term.t_ncol)) {
if( c == '\t') /* Don't render tabulation */
c = ' ' ;
else if( c > 0xC1 && c <= 0xF4) { /* Accept UTF-8 sequence */
char utf[ 4] ;
char cc ;
int bytes ;
utf[ 0] = c ;
utf[ 1] = cc = *s ;
if( (c & 0x20) && ((cc & 0xC0) == 0x80)) { /* at least 3 bytes and a valid encoded char */
utf[ 2] = cc = s[ 1] ;
if( (c & 0x10) && ((cc & 0xC0) == 0x80)) /* at least 4 bytes and a valid encoded char */
utf[ 3] = s[ 2] ;
}
bytes = utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &c) ;
s += bytes - 1 ;
}
TTputc( c) ;
++ttcol ;
}
}
@@ -1441,44 +1427,43 @@ void mlputs(char *s)
* Write out an integer, in the specified radix. Update the physical cursor
* position.
*/
static void mlputi(int i, int r)
{
int q;
static char hexdigits[] = "0123456789ABCDEF";
static void mlputi( int i, int r) {
int q ;
unsigned u ;
static char hexdigits[] = "0123456789ABCDEF" ;
if (i < 0) {
i = -i;
TTputc('-');
if( r == 16 || i >= 0)
u = i ;
else {
u = -i ;
mlputc( '-') ;
}
q = i / r;
q = u / r ;
if (q != 0)
mlputi(q, r);
if( q != 0)
mlputi( q, r) ;
TTputc(hexdigits[i % r]);
++ttcol;
mlputc( hexdigits[ u % r]) ;
}
/*
* do the same except as a long integer.
*/
static void mlputli(long l, int r)
{
long q;
static void mlputli( long l, int r) {
long q ;
if (l < 0) {
l = -l;
TTputc('-');
if( l < 0) {
l = -l ;
mlputc( '-') ;
}
q = l / r;
q = l / r ;
if (q != 0)
mlputli(q, r);
if( q != 0)
mlputli( q, r) ;
TTputc((int) (l % r) + '0');
++ttcol;
mlputc( (int) (l % r) + '0') ;
}
/*
@@ -1486,35 +1471,21 @@ static void mlputli(long l, int r)
*
* int s; scaled integer to output
*/
static void mlputf(int s)
{
int i; /* integer portion of number */
int f; /* fractional portion of number */
static void mlputf( int s) {
int i ; /* integer portion of number */
int f ; /* fractional portion of number */
/* break it up */
i = s / 100;
f = s % 100;
i = s / 100 ;
f = s % 100 ;
/* send out the integer portion */
mlputi(i, 10);
TTputc('.');
TTputc((f / 10) + '0');
TTputc((f % 10) + '0');
ttcol += 3;
mlputi( i, 10) ;
mlputc('.') ;
mlputc((f / 10) + '0') ;
mlputc((f % 10) + '0') ;
}
#if RAINBOW
static void putline(int row, int col, char *buf)
{
int n;
n = strlen(buf);
if (col + n - 1 > term.t_ncol)
n = term.t_ncol - col + 1;
Put_Data(row, col, n, buf);
}
#endif
/* Get terminal size from system.
Store number of lines into *heightp and width into *widthp.
@@ -1544,8 +1515,12 @@ void sizesignal(int signr)
getscreensize(&w, &h);
if (h && w && (h - 1 != term.t_nrow || w != term.t_ncol))
newscreensize(h, w);
if( h > 0 && w > 0) {
term.t_mrow = h = h < MAXROW ? h : MAXROW ;
term.t_mcol = w = w < MAXCOL ? w : MAXCOL ;
if( h - 1 != term.t_nrow || w != term.t_ncol)
newscreensize( h, w) ;
}
signal(SIGWINCH, sizesignal);
errno = old_errno;
@@ -1560,9 +1535,9 @@ static int newscreensize(int h, int w)
return FALSE;
}
chg_width = chg_height = 0;
if (h - 1 < term.t_mrow)
if( h <= term.t_mrow)
newsize(TRUE, h);
if (w < term.t_mcol)
if( w <= term.t_mcol)
newwidth(TRUE, w);
update(TRUE);
@@ -1570,3 +1545,27 @@ static int newscreensize(int h, int w)
}
#endif
/*
* output a character when echo is enabled
*
* char c ; character to output
*/
void echoc( char c) {
if( disinp)
TTputc( c) ;
}
/*
* output a string of characters when display input is enabled
*
* char *s; string to output
*/
void echos( char *s) {
if( disinp)
while( *s)
TTputc( *s++) ;
}
/* end of display.c */

View File

@@ -1,9 +1,14 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
#include <stdarg.h>
#include "estruct.h"
extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
extern int discmd ; /* display command flag */
extern int disinp ; /* display input characters (echo) */
extern int gfcolor ; /* global forgrnd color (white) */
extern int gbcolor ; /* global backgrnd color (black) */
@@ -20,13 +25,20 @@ int updupd( int force) ;
void upmode( void) ;
void movecursor( int row, int col) ;
void mlerase( void) ;
void vmlwrite( const char *fmt, va_list ap) ;
void mlwrite( const char *fmt, ...) ;
void mlforce( char *s) ;
void mlputs( char *s) ;
void ostring( char *s) ;
void echoc( char c) ;
void echos( char *s) ;
void getscreensize( int *widthp, int *heightp) ;
#if UNIX
#include <signal.h>
#ifdef SIGWINCH
extern int chg_width, chg_height ;
void sizesignal( int signr) ;
#endif
#endif
#endif

View File

@@ -270,10 +270,6 @@ struct key_tab keytab[NBINDS] = {
,
{META | 'D', delfword}
,
#if CRYPT
{META | 'E', set_encryption_key}
,
#endif
{META | 'F', forwword}
,
{META | 'G', gotoline}
@@ -301,8 +297,8 @@ struct key_tab keytab[NBINDS] = {
{META | 'R', sreplace}
,
#if PKCODE
{META | 'S', forwsearch}
, /* alternative P.K. */
{META | 'S', forwhunt}
,
#else
#if BSD
{META | 'S', bktoshell}

View File

@@ -1,6 +1,6 @@
/* Structure for the table of initial key bindings. */
struct key_tab {
int k_code ; /* Key code */
unsigned k_code ; /* Key code */
int (*k_fp)( int, int) ; /* Routine to handle it */
} ;

View File

@@ -183,12 +183,6 @@
#define poke(a,b,c,d) movedata(FP_SEG(c),FP_OFF(c),a,b,d)
#endif
#if VMS
#define atoi xatoi
#define abs xabs
#define getname xgetname
#endif
#if MSDOS & MSC
#include <dos.h>
#include <memory.h>
@@ -215,12 +209,6 @@
#define ENVFUNC 0
#endif
/* Internal defined functions */
#ifdef abs
#undef abs
#endif
/* DIFCASE represents the integer difference between upper
and lower case letters. It is an xor-able value, which is
fortunate, since the relative positions of upper to lower
@@ -257,11 +245,11 @@
#else
#define isletter(c) isxletter((0xFF & (c)))
#define isletter(c) __isxletter((0xFF & (c)))
#define islower(c) isxlower((0xFF & (c)))
#define isupper(c) isxupper((0xFF & (c)))
#define isxletter(c) (('a' <= c && LASTLL >= c) || ('A' <= c && LASTUL >= c) || (192<=c && c<=255))
#define __isxletter(c) (('a' <= c && LASTLL >= c) || ('A' <= c && LASTUL >= c) || (192<=c /* && c<=255 */))
#define isxlower(c) (('a' <= c && LASTLL >= c) || (224 <= c && 252 >= c))
#define isxupper(c) (('A' <= c && LASTUL >= c) || (192 <= c && 220 >= c))
@@ -297,7 +285,7 @@ void release( void *ptr) ;
#if CLEAN
#define exit(a) cexit(a)
int cexit( int status) ;
void cexit( int status) ;
#endif
#endif

902
eval.c

File diff suppressed because it is too large Load Diff

39
eval.h
View File

@@ -4,53 +4,26 @@
#define DEBUGM 1 /* $debug triggers macro debugging */
#if DEBUGM
/* Vars needed for macro debugging output. */
extern char outline[] ; /* Global string to hold debug line text. */
int mdbugout( char *fmt, ...) ;
#endif
/* Emacs global flag bit definitions (for gflags). */
#define GFREAD 1
extern int gflags ; /* global control flag */
extern int macbug ; /* macro debuging flag */
extern int cmdstatus ; /* last command status */
extern int flickcode ; /* do flicker supression? */
extern int rval ; /* return value of a subprocess */
extern long envram ; /* # of bytes current in use by malloc */
/* Macro argument token types */
#define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */
int gettyp( char *token) ;
int readfirst_f( void) ;
int is_it_cmd( char *token) ;
void varinit( void) ;
char *gtfun( char *fname) ;
char *gtusr( char *vname) ;
char *gtenv( char *vname) ;
int setvar( int f, int n) ;
char *i_to_a( int i) ;
char *getval( char *token) ;
int stol( char *val) ;
char *mkupper( char *str) ;
char *mklower( char *str) ;
int abs( int x) ;
int ernd( void) ;
int sindex( char *source, char *pattern) ;
char *xlat( char *source, char *lookup, char *trans) ;
int clrmes( int f, int n) ;
int writemsg( int f, int n) ;
#endif

1652
exec.c

File diff suppressed because it is too large Load Diff

13
exec.h
View File

@@ -12,21 +12,20 @@ int execproc( int f, int n) ;
#endif
extern char *execstr ; /* pointer to string to execute */
extern boolean clexec ; /* command line execution flag */
void ue_system( const char *cmd) ;
int namedcmd( int f, int n) ;
int execcmd( int f, int n) ;
char *token( char *src, char *tok, int size) ;
int macarg( char *tok) ;
int nextarg( const char *prompt, char *buffer, int size, int terminator) ;
void gettoken( char *tok, int maxtoksize) ;
boolean gettokval( char *tok, int maxtoksize) ;
char *getnewtokval( void) ;
int storemac( int f, int n) ;
int execbuf( int f, int n) ;
int execfile( int f, int n) ;
int dofile( char *fname) ;
int cbuf( int f, int n, int bufnum) ;
int dofile( const char *fname) ;
int cbuf1( int f, int n) ;
int cbuf2( int f, int n) ;
int cbuf3( int f, int n) ;

452
execute.c
View File

@@ -1,108 +1,418 @@
/* execute.c -- implements execute.h */
#include "execute.h"
#define CLRMSG 0 /* space clears the message line with no insert */
#include <stdlib.h>
#include <unistd.h>
#include "estruct.h"
#include "bind.h"
#include "random.h"
#include "display.h"
#include "file.h"
#include "input.h"
#include "mlout.h"
#include "search.h"
#include "terminal.h"
#include "window.h"
int gasave = 256 ; /* global ASAVE size */
int gacount = 256 ; /* count until next ASAVE */
/* insert a # into the text here...we are in CMODE */
static int inspound( int n) {
/* if we are at the beginning of the line, no go */
if( n == 1 && curwp->w_doto != 0) {
int i ;
/* scan to see if all space before this is white space */
for( i = curwp->w_doto - 1 ; i >= 0 ; i -= 1) {
int ch ; /* last character before input */
ch = lgetc( curwp->w_dotp, i) ;
if( ch != ' ' && ch != '\t')
break ;
}
/* delete back first */
if( i < 0)
while( getccol( FALSE) >= 1)
backdel( FALSE, 1) ;
}
/* and insert the required pound */
return linsert( n, '#') ;
}
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (if not }, just normal insertion).
*/
static int insbrace( int n, int c) {
int ch ; /* last character before input */
int oc ; /* caractere oppose a c */
int i, count ;
int target ; /* column brace should go after */
struct line *oldlp ;
int oldoff ;
/* if not called with {, acts as insertion */
if( c == '}')
oc = '{' ;
else
return linsert( n, c) ;
/* scan to see if all preceding spaces are white spaces, if not, insert */
for( i = curwp->w_doto - 1 ; i >= 0 ; --i) {
ch = lgetc( curwp->w_dotp, i) ;
if( ch != ' ' && ch != '\t')
return linsert( n, c) ;
}
oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto ;
count = 1 ;
do {
if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) {
/* at beginning of buffer, no match to be found */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
return linsert( n, c) ;
}
backchar( FALSE, 1) ;
/* if not eol */
if( curwp->w_doto != llength( curwp->w_dotp)) {
ch = lgetc( curwp->w_dotp, curwp->w_doto) ;
if( ch == c)
++count ;
else if( ch == oc)
--count ;
}
} while( count > 0) ;
curwp->w_doto = 0 ; /* debut de ligne */
/* aller au debut de la ligne apres la tabulation */
while( (ch = lgetc( curwp->w_dotp, curwp->w_doto)) == ' '
|| ch == '\t')
forwchar( FALSE, 1) ;
/* delete back first */
target = getccol( FALSE) ; /* c'est l'indent que l'on doit avoir */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
while( target != getccol( FALSE)) {
if( target < getccol( FALSE)) /* on doit detruire des caracteres */
while( getccol( FALSE) > target)
backdel( FALSE, 1) ;
else { /* on doit en inserer */
while( target - getccol( FALSE) >= tabwidth)
insert_tab( FALSE, 1) ;
linsert( target - getccol( FALSE), ' ') ;
}
}
/* and insert the required brace(s) */
return linsert( n, c) ;
}
#if CFENCE
/*
* Close fences are matched against their partners, and if
* on screen the cursor briefly lights there
*
* char ch; fence type to match against
*/
static void fmatch( int ch) {
struct line *oldlp ; /* original line pointer */
int oldoff ; /* and offset */
struct line *toplp ; /* top line in current window */
int count ; /* current fence level count */
int opench ; /* open fence */
/* $tpause <= 0 disable fmatch */
if( term.t_pause <= 0)
return ;
/* first get the display update out there */
update( FALSE) ;
/* save the original cursor position */
oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto ;
/* setup proper open fence for passed close fence */
if( ch == ')')
opench = '(' ;
else if( ch == '}')
opench = '{' ;
else
opench = '[' ;
/* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp ;
backchar( FALSE, 1) ; /* . was after the }, move back */
/* scan back until we find it, or reach past the top of the window */
count = 1 ;
do {
/* At beginning of window or buffer, no match to be found */
if( curwp->w_dotp == toplp
|| boundry( curwp->w_dotp, curwp->w_doto, REVERSE))
break ;
backchar( FALSE, 1) ;
/* if not eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
int c ; /* current character in scan */
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
if( c == ch)
++count ;
else if( c == opench)
--count ;
}
} while( count > 0) ;
/* if count is zero, we have a match, display the sucker */
if( count == 0) {
int i ;
/* there is a real machine dependant timing problem here we have
yet to solve......... */
for( i = 0 ; i < term.t_pause ; i++) {
update( FALSE) ;
usleep( 10000L) ;
}
}
/* restore the current position */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
}
#endif
/*
* This is the general command execution routine. It handles the fake binding
* of all the keys to "self-insert". It also clears out the "thisflag" word,
* and arranges to move it to the "lastflag", so that the next command can
* look at it. Return the status of command.
*/
int execute(int c, int f, int n)
{
int status;
fn_t execfunc;
int execute( int c, int f, int n) {
int status ;
fn_t execfunc ;
/* if the keystroke is a bound function...do it */
execfunc = getbind(c);
if (execfunc != NULL) {
thisflag = 0;
status = (*execfunc) (f, n);
lastflag = thisflag;
return status;
/* if the keystroke is a bound function...do it */
execfunc = getbind( c) ;
if( execfunc != NULL) {
thisflag = 0 ;
status = execfunc( f, n) ;
lastflag = thisflag ;
return status ;
}
/*
* If a space was typed, fill column is defined, the argument is non-
* negative, wrap mode is enabled, and we are now past fill column,
* and we are not read-only, perform word wrap.
*/
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
n >= 0 && getccol(FALSE) > fillcol &&
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
execute(META | SPEC | 'W', FALSE, 1);
/* non insertable character can only be bound to function */
if( c < 0x20
|| (c >= 0x7F && c < 0xA0)
|| c > 0x10FFFF) { /* last valid unicode */
lastflag = 0 ; /* Fake last flags. */
mloutfmt( "%B(Key not bound)") ; /* Complain */
return FALSE ;
}
#if PKCODE
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
#if IBMPC
|| (c >= 0x80 && c <= 0xFE)) {
#else
#if VMS || BSD || USG /* 8BIT P.K. */
|| (c >= 0xA0 && c <= 0x10FFFF)) {
#else
) {
#endif
#endif
#else
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
#endif
if (n <= 0) { /* Fenceposts. */
lastflag = 0;
return n < 0 ? FALSE : TRUE;
/* insertable character => self insert, check if buffer is read only */
if( curbp->b_mode & MDVIEW) {
lastflag = 0 ;
return rdonly() ;
}
/* check valid count */
if( n <= 0) {
lastflag = 0 ;
return n < 0 ? FALSE : TRUE ;
}
/* wrap on space after fill column in wrap mode */
if( c == ' '
&& (curwp->w_bufp->b_mode & MDWRAP)
&& fillcol > 0
&& getccol( FALSE) > fillcol) {
status = execute( META | SPEC | 'W', FALSE, 1) ; /* defaults to wrapword */
if( status != TRUE) {
lastflag = 0 ;
return status ;
}
thisflag = 0; /* For the future. */
}
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forword */
if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
(curwp->w_doto) % 8 == 7))
ldelchar(1, FALSE);
thisflag = 0 ; /* For the future. */
/* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
status = insbrace(n, c);
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
status = inspound();
else
status = linsert(n, c);
/* following handling of overwrite is only valid when n == 1 */
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forward */
if( curbp->b_mode & MDOVER
&& curwp->w_doto < curwp->w_dotp->l_used
&& (lgetc( curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
ldelchar( 1, FALSE) ;
/* do the appropriate insertion */
switch( c) {
case '}':
case ']':
case ')':
case '#':
if( (curbp->b_mode & MDCMOD) != 0) {
if( c == '#')
status = inspound( n) ;
else {
status = insbrace( n, c) ;
#if CFENCE
/* check for CMODE fence matching */
if ((c == '}' || c == ')' || c == ']') &&
(curbp->b_mode & MDCMOD) != 0)
fmatch(c);
if( status == TRUE)
fmatch( c) ; /* check for CMODE fence matching */
#endif
/* check auto-save mode */
if (curbp->b_mode & MDASAVE)
if (--gacount == 0) {
/* and save the file if needed */
upscreen(FALSE, 0);
filesave(FALSE, 0);
gacount = gasave;
}
lastflag = thisflag;
return status;
break ;
}
default:
status = linsert( n, c) ;
}
TTbeep();
mlwrite("(Key not bound)"); /* complain */
lastflag = 0; /* Fake last flags. */
return FALSE;
/* perform auto-save */
if( status == TRUE /* successful insertion */
&& (curbp->b_mode & MDASAVE) /* auto save is on */
&& (--gacount == 0)) { /* insertion count reached */
/* and save the file if needed */
upscreen( FALSE, 0) ;
filesave( FALSE, 0) ;
gacount = gasave ;
}
lastflag = thisflag ;
return status ;
}
void kbd_loop( void) {
int c = -1 ; /* command character */
/* Setup to process commands. */
lastflag = 0 ; /* Fake last flags. */
for( ;;) {
int saveflag ; /* temp store for lastflag */
int basec ; /* c stripped of meta character */
int f ; /* default flag */
int n ; /* numeric repeat count */
/* Execute the "command" macro...normally null. */
saveflag = lastflag ; /* Preserve lastflag through this. */
execute( META | SPEC | 'C', FALSE, 1) ;
lastflag = saveflag ;
#if TYPEAH && PKCODE
if( typahead()) {
int newc ;
newc = getcmd() ;
update( FALSE) ;
do {
fn_t execfunc ;
if( c == newc
&& (execfunc = getbind( c)) != NULL
&& execfunc != insert_newline
&& execfunc != insert_tab)
newc = getcmd() ;
else
break ;
} while( typahead()) ;
c = newc ;
} else {
update( FALSE) ;
c = getcmd() ;
}
#else
/* Fix up the screen */
update( FALSE) ;
/* get the next command from the keyboard */
c = getcmd() ;
#endif
/* if there is something on the command line, clear it */
if( mpresf != FALSE) {
mloutstr( "") ;
update( FALSE) ;
#if CLRMSG
if( c == ' ') /* ITS EMACS does this */
continue ;
#endif
}
f = FALSE ;
n = 1 ;
/* do META-# processing if needed */
/* do ^U repeat argument processing */
while( c == reptc
||( (c & META)
&& (((basec = c & ~META) >= '0' && basec <= '9') || basec == '-'))) {
int mflag = 0 ; /* minus flag, default to positive */
f = TRUE ;
if( c == reptc) {
n = 4 ;
basec = 2 ; /* lead by universal arg cmd */
} else if( c & META) {
if( basec == '-') {
mflag = TRUE ; /* negative */
n = 1 ;
basec = 1 ; /* lead by M-- */
} else {
n = basec - '0' ;
basec = 0 ; /* lead by M-# */
}
}
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
while( ((c = getcmd()) >= '0' && c <= '9') || c == '-') {
if( c == '-') {
if( basec == 2) { /* directly follows universal arg cmd */
n = 1 ;
basec = 1 ;
mflag = TRUE ;
} else
break ;
} else {
if( basec) { /* follows universal arg cmd or leading dash */
n = c - '0' ;
basec = 0 ;
} else if( n <= 0xCCCCCCB) /* avoid overflow */
n = n * 10 + c - '0' ;
}
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
}
if( mflag)
n = -n ;
}
/* and execute the command */
execute( c, f, n) ;
}
}
/* end of execute.c */

View File

@@ -2,4 +2,4 @@ extern int gasave ; /* global ASAVE size */
extern int gacount ; /* count until next ASAVE */
int execute( int c, int f, int n) ;
void kbd_loop( void) ;

441
file.c
View File

@@ -12,19 +12,20 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "buffer.h"
#include "crypt.h"
#include "defines.h"
#include "display.h"
#include "estruct.h"
#include "execute.h"
#include "fileio.h"
#include "input.h"
#include "line.h"
#include "lock.h"
#include "log.h"
#include "mlout.h"
#include "window.h"
#if PKCODE
@@ -48,8 +49,24 @@ static const char *eolname[] = {
"MIXED"
} ;
static const char *codename[] = {
"ASCII",
"UTF-8",
"EXTENDED",
"MIXED"
} ;
boolean restflag = FALSE ; /* restricted use? */
static int ifile( const char *fname) ;
boolean resterr( void) {
mloutfmt( "%B(That command is RESTRICTED)") ;
return FALSE ;
}
/*
* Read a file into the current
* buffer. This is really easy; all you do it
@@ -57,16 +74,20 @@ boolean restflag = FALSE ; /* restricted use? */
* "read a file into the current buffer" code.
* Bound to "C-X C-R".
*/
int fileread(int f, int n)
{
int s;
fname_t fname ;
int fileread( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
return s;
return readin(fname, TRUE);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = readin( fname, TRUE) ;
free( fname) ;
}
return status ;
}
/*
@@ -76,20 +97,26 @@ int fileread(int f, int n)
* "insert a file into the current buffer" code.
* Bound to "C-X C-I".
*/
int insfile(int f, int n)
{
int s;
fname_t fname ;
int insfile( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = ifile(fname)) != TRUE)
return s;
return reposition(TRUE, -1);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = ifile( fname) ;
free( fname) ;
}
if( status != TRUE)
return status ;
return reposition( TRUE, -1) ;
}
/*
@@ -101,108 +128,51 @@ int insfile(int f, int n)
* text, and switch to the new buffer.
* Bound to C-X C-F.
*/
int filefind(int f, int n)
{
fname_t fname ; /* file user wishes to find */
int s; /* status return */
int filefind( int f, int n) {
char *fname ; /* file user wishes to find */
int status ; /* status return */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
return s;
return getfile(fname, TRUE);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = getfile( fname, TRUE) ;
free( fname) ;
}
return status ;
}
int viewfile(int f, int n)
{ /* visit a file in VIEW mode */
fname_t fname ; /* file user wishes to find */
int s; /* status return */
struct window *wp; /* scan for windows that need updating */
int viewfile( int f, int n) { /* visit a file in VIEW mode */
char *fname ; /* file user wishes to find */
int status ; /* status return */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
return s;
s = getfile(fname, FALSE);
if (s) { /* if we succeed, put it in view mode */
curwp->w_bufp->b_mode |= MDVIEW;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = getfile(fname, FALSE) ;
free( fname) ;
}
if( status == TRUE) { /* if we succeed, put it in view mode */
struct window *wp ; /* scan for windows that need updating */
curwp->w_bufp->b_mode |= MDVIEW ;
/* scan through and update mode lines of all windows */
wp = wheadp;
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
wp = wheadp ;
while( wp != NULL) {
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
}
return s;
return status ;
}
#if CRYPT
void cryptbufferkey( struct buffer *bp) {
myencrypt( (char *) NULL, 0) ;
myencrypt( bp->b_key, strlen( bp->b_key)) ;
}
/*
* reset encryption key of current buffer
*
* int f; default flag
* int n; numeric argument
*/
int set_encryption_key(int f, int n)
{
int status; /* return status */
int odisinp; /* original vlaue of disinp */
ekey_t key ; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, sizeof key - 1);
disinp = odisinp;
if (status != TRUE)
return status;
/* save it off and encrypt it*/
strcpy(curbp->b_key, key);
cryptbufferkey( curbp) ;
logwrite(" "); /* clear it off the bottom line */
return TRUE;
}
static int resetkey(void)
{ /* reset the encryption key if needed */
int s; /* return status */
/* turn off the encryption flag */
is_crypted = FALSE;
/* if we are in crypt mode */
if (curbp->b_mode & MDCRYPT) {
if (curbp->b_key[0] == 0) {
s = set_encryption_key(FALSE, 0);
if (s != TRUE)
return s;
}
/* let others know... */
is_crypted = TRUE;
/* and set up the key to be used! */
/* de-encrypt it */
cryptbufferkey( curbp) ;
/* re-encrypt it...seeding it to start */
cryptbufferkey( curbp) ;
}
return TRUE;
}
#endif
/*
* getfile()
*
@@ -231,23 +201,30 @@ int getfile( const char *fname, boolean lockfl)
curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD;
cknewwindow();
logwrite("(Old buffer)");
mloutstr( "(Old buffer)") ;
return TRUE;
}
}
makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
char *new_bname ;
/* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, sizeof bname);
if (s == ABORT) /* ^G to just quit */
return s;
if (s == FALSE) { /* CR to clobber it */
makename(bname, fname);
break;
s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
if( s == ABORT) /* ^G to just quit */
return s ;
else if (s == FALSE) { /* CR to clobber it */
makename( bname, fname) ;
break ;
} else { /* TRUE */
strncpy( bname, new_bname, sizeof bname - 1) ;
bname[ sizeof bname - 1] = '\0' ;
free( new_bname) ;
}
}
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
logwrite("Cannot create buffer");
mloutstr( "Cannot create buffer") ;
return FALSE;
}
if (--curbp->b_nwnd == 0) { /* Undisplay. */
@@ -285,7 +262,7 @@ int readin(const char *fname, boolean lockfl)
eoltype found_eol ;
int nbytes;
int nline;
char mesg[NSTRING];
char *errmsg ;
#if (FILOCK && BSD) || SVR4
if (lockfl && lockchk(fname) == ABORT)
@@ -299,17 +276,13 @@ int readin(const char *fname, boolean lockfl)
#else
return ABORT;
#endif
#endif
#if CRYPT
s = resetkey();
if (s != TRUE)
return s;
#endif
bp = curbp; /* Cheap. */
if ((s = bclear(bp)) != TRUE) /* Might be old. */
return s;
bp->b_flag &= ~(BFINVS | BFCHG);
strcpy(bp->b_fname, fname);
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
/* let a user macro get hold of things...if he wants */
execute(META | SPEC | 'R', FALSE, 1);
@@ -318,12 +291,12 @@ int readin(const char *fname, boolean lockfl)
goto out;
if (s == FIOFNF) { /* File not found. */
logwrite("(New file)");
mloutstr( "(New file)") ;
goto out;
}
/* read the file in */
logwrite("(Reading file)");
mloutstr( "(Reading file)") ;
nline = 0;
while ((s = ffgetline()) == FIOSUC) {
nbytes = fpayload ;
@@ -347,7 +320,7 @@ int readin(const char *fname, boolean lockfl)
}
if( s == FIOERR)
logwrite( "File read error") ;
mloutstr( "File read error") ;
switch( ftype) {
case FTYPE_DOS:
@@ -365,28 +338,29 @@ int readin(const char *fname, boolean lockfl)
break ;
default:
found_eol = EOL_MIXED ;
curbp->b_mode |= MDVIEW ; /* add view mode as we have lost
** information */
curbp->b_mode |= MDVIEW ; /* force view mode as we have lost
** EOL information */
}
ffclose(); /* Ignore errors. */
strcpy(mesg, "(");
if (s == FIOERR) {
strcat(mesg, "I/O ERROR, ");
curbp->b_flag |= BFTRUNC;
}
if (s == FIOMEM) {
strcat(mesg, "OUT OF MEMORY, ");
curbp->b_flag |= BFTRUNC;
}
sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
if (nline != 1)
strcat(mesg, "s");
if( fcode == FCODE_UTF_8)
curbp->b_mode |= MDUTF8 ;
strcat( mesg, ", eol = ") ;
strcat( mesg, eolname[ found_eol]) ;
strcat(mesg, ")");
logwrite(mesg);
if( s == FIOERR) {
errmsg = "I/O ERROR, " ;
curbp->b_flag |= BFTRUNC ;
} else if( s == FIOMEM) {
errmsg = "OUT OF MEMORY, " ;
curbp->b_flag |= BFTRUNC ;
} else
errmsg = "" ;
mloutfmt( "(%sRead %d line%s, code/eol: %s/%s)",
errmsg,
nline,
(nline != 1) ? "s" : "",
codename[ fcode & (FCODE_MASK -1)],
eolname[ found_eol]) ;
ffclose(); /* Ignore errors. */
out:
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@@ -477,27 +451,38 @@ void unqname(char *name)
* is more compatable with Gosling EMACS than
* with ITS EMACS. Bound to "C-X C-W".
*/
int filewrite(int f, int n)
{
struct window *wp;
int s;
fname_t fname ;
int filewrite( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname);
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return s;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
if( status == TRUE) {
if( strlen( fname) > sizeof( fname_t) - 1)
status = FALSE ;
else {
status = writeout( fname) ;
if( status == TRUE) {
struct window *wp ;
strcpy( curbp->b_fname, fname) ;
curbp->b_flag &= ~BFCHG ;
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
}
}
free( fname) ;
}
return status ;
}
/*
@@ -518,14 +503,14 @@ int filesave(int f, int n)
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
return TRUE;
if (curbp->b_fname[0] == 0) { /* Must have a name. */
logwrite("No file name");
mloutstr( "No file name") ;
return FALSE;
}
/* complain about truncated files */
if ((curbp->b_flag & BFTRUNC) != 0) {
if (mlyesno("Truncated file ... write it out") == FALSE) {
logwrite("(Aborted)");
mloutstr( "(Aborted)") ;
return FALSE;
}
}
@@ -556,23 +541,17 @@ int writeout( const char *fn)
struct line *lp;
int nline;
#if CRYPT
s = resetkey();
if (s != TRUE)
return s;
#endif
if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
logwrite( "Cannot open file for writing") ;
mloutstr( "Cannot open file for writing") ;
return FALSE;
}
logwrite("(Writing...)"); /* tell us were writing */
mloutstr( "(Writing...)") ; /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) {
s = ffputline( &lp->l_text[0], llength(lp), curbp->b_mode & MDDOS) ;
if( s != FIOSUC) {
logwrite( "Write I/O error") ;
mloutstr( "Write I/O error") ;
break;
}
@@ -583,11 +562,11 @@ int writeout( const char *fn)
s = ffclose();
if (s == FIOSUC) { /* No close error. */
if (nline == 1)
logwrite("(Wrote 1 line)");
mloutstr( "(Wrote 1 line)") ;
else
logwrite("(Wrote %d lines)", nline);
mloutfmt( "(Wrote %d lines)", nline) ;
} else
logwrite( "Error closing file") ;
mloutstr( "Error closing file") ;
} else /* Ignore close error */
ffclose(); /* if a write error. */
if (s != FIOSUC) /* Some sort of error. */
@@ -604,28 +583,35 @@ int writeout( const char *fn)
* as needing an update. You can type a blank line at the
* prompt if you wish.
*/
int filename(int f, int n)
{
struct window *wp;
int s;
fname_t fname ;
int filename( int f, int n) {
struct window *wp ;
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
return s;
if (s == FALSE)
strcpy(curbp->b_fname, "");
else
strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
if( status == ABORT)
return status ;
else if( status == FALSE)
curbp->b_fname[ 0] = '\0' ;
else { /* TRUE */
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
free( fname) ;
}
curbp->b_mode &= ~MDVIEW; /* no longer read only mode */
return TRUE;
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
return TRUE ;
}
/*
@@ -633,8 +619,7 @@ int filename(int f, int n)
* buffer, Called by insert file command. Return the final
* status of the read.
*/
int ifile( const char *fname)
{
static int ifile( const char *fname) {
struct line *lp0;
struct line *lp1;
struct line *lp2;
@@ -642,7 +627,7 @@ int ifile( const char *fname)
int s;
int nbytes;
int nline;
char mesg[NSTRING];
char *errmsg ;
bp = curbp; /* Cheap. */
bp->b_flag |= BFCHG; /* we have changed */
@@ -650,16 +635,11 @@ int ifile( const char *fname)
if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if (s == FIOFNF) { /* File not found. */
logwrite("(No such file)");
mloutstr( "(No such file)") ;
return FALSE;
}
logwrite("(Inserting file)");
mloutstr( "(Inserting file)") ;
#if CRYPT
s = resetkey();
if (s != TRUE)
return s;
#endif
/* back up a line and save the mark here */
curwp->w_dotp = lback(curwp->w_dotp);
curwp->w_doto = 0;
@@ -689,22 +669,21 @@ int ifile( const char *fname)
}
ffclose(); /* Ignore errors. */
curwp->w_markp = lforw(curwp->w_markp);
strcpy(mesg, "(");
if (s == FIOERR) {
strcat(mesg, "I/O ERROR, ");
if( s == FIOERR) {
errmsg = "I/O ERROR, " ;
curbp->b_flag |= BFTRUNC ;
} else if( s == FIOMEM) {
errmsg = "OUT OF MEMORY, " ;
curbp->b_flag |= BFTRUNC;
}
if (s == FIOMEM) {
strcat(mesg, "OUT OF MEMORY, ");
curbp->b_flag |= BFTRUNC;
}
sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline);
if (nline > 1)
strcat(mesg, "s");
strcat(mesg, ")");
logwrite(mesg);
} else
errmsg = "" ;
mloutfmt( "(%sInserted %d line%s)",
errmsg,
nline,
(nline > 1) ? "s" : "") ;
out:
out:
/* advance to the next line and mark the window for changes */
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_flag |= WFHARD | WFMODE;

8
file.h
View File

@@ -2,15 +2,10 @@
#define _FILE_H_
#include "buffer.h"
#include "crypt.h"
#include "retcode.h"
#if CRYPT
void cryptbufferkey( struct buffer *bp) ;
int set_encryption_key( int f, int n) ;
#endif
extern boolean restflag ; /* restricted use? */
boolean resterr( void) ; /* restricted error message */
int fileread( int f, int n) ;
int insfile( int f, int n) ;
@@ -24,6 +19,5 @@ int filewrite( int f, int n) ;
int filesave( int f, int n) ;
int writeout( const char *fn) ;
int filename( int f, int n) ;
int ifile( const char *fname) ;
#endif

View File

@@ -21,14 +21,12 @@
#include "defines.h"
#include "retcode.h"
#if CRYPT
boolean is_crypted ; /* currently encrypting? */
#endif
#include "utf8.h"
char *fline = NULL ; /* dynamic return line */
int flen = 0 ; /* current allocated length of fline */
static int flen = 0 ; /* current allocated length of fline */
int ftype ;
int fcode ; /* encoding type FCODE_xxxxx */
int fpayload ; /* actual length of fline content */
@@ -45,6 +43,7 @@ fio_code ffropen( const char *fn)
return FIOFNF;
eofflag = FALSE;
ftype = FTYPE_NONE ;
fcode = FCODE_ASCII ;
return FIOSUC;
}
@@ -79,6 +78,7 @@ fio_code ffclose(void)
}
eofflag = FALSE;
ftype = FTYPE_NONE ;
fcode = FCODE_ASCII ;
#if MSDOS & CTRLZ
fputc(26, ffp); /* add a ^Z at the end of the file */
@@ -99,20 +99,6 @@ fio_code ffclose(void)
* Check only at the newline.
*/
fio_code ffputline( char *buf, int nbuf, int dosflag) {
#if CRYPT
if( is_crypted) {
int i ;
for( i = 0 ; i < nbuf ; i++) {
char c ;
c = buf[ i] ;
myencrypt( &c, 1) ;
fputc( c, ffp) ;
}
} else
#endif
fwrite( buf, 1, nbuf, ffp) ;
if( dosflag)
@@ -136,6 +122,7 @@ fio_code ffgetline(void)
{
int c; /* current character read */
int i; /* current index into fline */
int lcode = FCODE_ASCII ; /* line encoding, defaults to ASCII */
/* if we are at the end...return it */
if (eofflag)
@@ -156,6 +143,7 @@ fio_code ffgetline(void)
i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') {
fline[i++] = c;
lcode |= c ;
/* if it's longer, get more room */
if (i >= flen) {
char *tmpline; /* temp storage for expanding line */
@@ -173,6 +161,24 @@ fio_code ffgetline(void)
}
fpayload = i ;
lcode &= FCODE_MASK ;
if( lcode && (fcode != FCODE_MIXED)) { /* line contains extended chars */
/* Check if consistent UTF-8 encoding */
int bytes ;
int pos = 0 ;
unicode_t uc ;
while( (pos < i) && (lcode != FCODE_MIXED)) {
bytes = utf8_to_unicode( fline, pos, i, &uc) ;
pos += bytes ;
if( bytes > 1) /* Multi byte UTF-8 sequence */
lcode |= FCODE_UTF_8 ;
else if( uc > 127) /* Extended ASCII */
lcode |= FCODE_EXTND ;
}
fcode |= lcode ;
}
/* test for any errors that may have occured */
if (c == EOF) {
@@ -193,11 +199,7 @@ fio_code ffgetline(void)
} else /* c == '\n' */
ftype |= FTYPE_UNIX ;
/* terminate and decrypt the string */
/* terminate the string */
fline[i] = 0;
#if CRYPT
if( is_crypted)
myencrypt( fline, fpayload);
#endif
return FIOSUC;
}

View File

@@ -1,8 +1,6 @@
#ifndef _FILEIO_H_
#define _FILEIO_H_
#include "crypt.h"
typedef enum {
FIOSUC, /* File I/O, success. */
FIOFNF, /* File I/O, file not found. */
@@ -18,15 +16,15 @@ typedef enum {
#define FTYPE_MAC 4
/* FTYPE_MIXED [ 3, 5, 6, 7] */
#if CRYPT
#include "retcode.h"
extern boolean is_crypted ; /* currently encrypting? */
#endif
#define FCODE_ASCII 0
#define FCODE_MASK 0x80
#define FCODE_UTF_8 0x81
#define FCODE_EXTND 0x82
#define FCODE_MIXED 0x83
extern char *fline ; /* dynamic return line */
extern int flen ; /* current allocated length of fline */
extern int ftype ;
extern int fcode ; /* encoding type */
extern int fpayload ; /* actual length of fline content */
fio_code ffclose( void) ;

66
flook.c
View File

@@ -76,33 +76,44 @@ boolean fexist( const char *fname)
*/
char *flook( const char *fname, boolean hflag)
{
int i; /* index */
unsigned i ; /* index */
int len ;
static char fspec[NSTRING]; /* full path spec to search */
#if ENVFUNC
char *path; /* environmental PATH variable */
#endif
len = sizeof fspec - strlen( fname) - 1 ;
if( len < 0)
return NULL ;
#if ENVFUNC
if (hflag) {
char *home; /* path to home directory */
home = getenv("HOME");
if (home != NULL) {
if( len > (int) strlen( home) + 1) {
/* build home dir file spec */
strcpy(fspec, home);
strcat(fspec, "/");
strcat(fspec, fname);
strcpy( fspec, home) ;
strcat(fspec, "/");
strcat(fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
if( fexist( fspec))
return fspec ;
}
}
}
#endif
/* always try the current directory first */
strcpy( fspec, fname) ;
if( fexist( fspec))
return fspec ;
if( len >= 0) {
strcpy( fspec, fname) ;
if( fexist( fspec))
return fspec ;
}
#if ENVFUNC
#if V7 | USG | BSD
@@ -116,21 +127,29 @@ char *flook( const char *fname, boolean hflag)
if (path != NULL)
while (*path) {
char *sp; /* pointer into path spec */
int cnt ;
cnt = len ;
/* build next possible file spec */
sp = fspec;
while (*path && (*path != PATHCHR))
*sp++ = *path++;
while( *path && (*path != PATHCHR)) {
if( cnt-- > 0)
*sp++ = *path ;
path += 1 ;
}
if( cnt >= 0) {
/* add a terminating dir separator if we need it */
if (sp != fspec)
*sp++ = '/';
*sp = 0;
strcat(fspec, fname);
if (sp != fspec)
*sp++ = '/';
*sp = 0;
strcat(fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
if( fexist( fspec))
return fspec ;
}
if (*path == PATHCHR)
++path;
@@ -138,14 +157,15 @@ char *flook( const char *fname, boolean hflag)
#endif
/* look it up via the old table method */
for( i = 2; i < PATHNAME_SIZE ; i++) {
strcpy(fspec, pathname[i]);
strcat(fspec, fname);
for( i = 2; i < PATHNAME_SIZE ; i++)
if( len >= (int) strlen( pathname[ i])) {
strcpy( fspec, pathname[ i]) ;
strcat( fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
}
if( fexist( fspec))
return fspec ;
}
return NULL; /* no such luck */
}

232
input.c
View File

@@ -21,6 +21,7 @@
#include "exec.h"
#include "names.h"
#include "terminal.h"
#include "utf8.h"
#include "wrapper.h"
#if PKCODE
@@ -44,14 +45,15 @@ kbdstate kbdmode = STOP ; /* current keyboard macro mode */
int lastkey = 0 ; /* last keystoke */
int kbdrep = 0 ; /* number of repetitions */
int disinp = TRUE ; /* display input characters */
int metac = CONTROL | '[' ; /* current meta character */
int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
int reptc = CONTROL | 'U' ; /* current universal repeat char */
int abortc = CONTROL | 'G' ; /* current abort command char */
static const int quotec = 0x11 ; /* quote char during mlreply() */
const int nlc = CONTROL | 'J' ; /* end of input char */
static const int quotec = 0x11 ; /* quote char during getstring() */
/*
* Ask a yes or no question in the message line. Return either TRUE, FALSE, or
@@ -61,13 +63,10 @@ static const int quotec = 0x11 ; /* quote char during mlreply() */
int mlyesno( const char *prompt)
{
char c; /* input character */
char buf[ NSTRING] ; /* prompt to user */
for (;;) {
/* build and prompt the user */
strcpy(buf, prompt);
strcat(buf, " (y/n)? ");
mlwrite(buf);
/* prompt the user */
mlwrite( "%s (y/n)? ", prompt) ;
/* get the response */
c = tgetc();
@@ -83,6 +82,47 @@ int mlyesno( const char *prompt)
}
}
/*
* newnextarg:
* get the next argument
*
* char **outbufref ; buffer to put token into
* const char *prompt ; prompt to use if we must be interactive
* int size ; size of the buffer
* int terminator ; terminating char to be used on interactive fetch
*/
static int newnextarg( char **outbufref, const char *prompt, int size,
int terminator) {
int status ;
char *buf ;
/* if we are interactive, go get it! */
if( clexec == FALSE) {
if( size <= 1) {
size = term.t_ncol - strlen( prompt) + 1 ;
if( size < 24)
size = 24 ;
}
buf = malloc( size) ;
if( buf == NULL)
status = FALSE ;
else {
status = getstring( prompt, buf, size, terminator) ;
if( TRUE != status) {
free( buf) ;
buf = NULL ;
}
}
} else {
buf = getnewtokval() ;
status = (buf == NULL) ? FALSE : TRUE ;
}
*outbufref = buf ;
return status ;
}
/*
* Write a prompt into the message line, then read back a response. Keep
* track of the physical position of the cursor. If we are in a keyboard
@@ -91,14 +131,12 @@ int mlyesno( const char *prompt)
* return. Handle erase, kill, and abort keys.
*/
int mlreply( const char *prompt, char *buf, int nbuf)
{
return nextarg(prompt, buf, nbuf, ctoec('\n'));
int newmlarg( char **outbufref, const char *prompt, int size) {
return newnextarg( outbufref, prompt, size, nlc) ;
}
int mlreplyt(const char *prompt, char *buf, int nbuf, int eolchar)
{
return nextarg(prompt, buf, nbuf, eolchar);
int newmlargt( char **outbufref, const char *prompt, int size) {
return newnextarg( outbufref, prompt, size, metac) ;
}
/*
@@ -115,18 +153,6 @@ int ectoc(int c)
return c;
}
/*
* ctoec:
* character to extended character
* pull out the CONTROL and SPEC prefixes (if possible)
*/
int ctoec(int c)
{
if (c >= 0x00 && c <= 0x1F)
c = CONTROL | (c + '@');
return c;
}
/*
* get a command name from the command line. Command completion means
* that pressing a <SPACE> will attempt to complete an unfinished command
@@ -135,8 +161,6 @@ int ctoec(int c)
fn_t getname(void)
{
int cpos; /* current column on screen output */
int c;
char *sp; /* pointer to string for output */
struct name_bind *ffp; /* first ptr to entry in name binding table */
struct name_bind *cffp; /* current ptr to entry in name binding table */
struct name_bind *lffp; /* last ptr to entry in name binding table */
@@ -147,13 +171,15 @@ fn_t getname(void)
/* if we are executing a command line get the next arg and match it */
if (clexec) {
if (macarg(buf) != TRUE)
if( TRUE != gettokval( buf, sizeof buf))
return NULL;
return fncmatch(&buf[0]);
}
/* build a name string from the keyboard */
while (TRUE) {
int c ;
c = tgetc();
/* if we are at the end, just match it */
@@ -170,9 +196,7 @@ fn_t getname(void)
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */
if (cpos != 0) {
TTputc('\b');
TTputc(' ');
TTputc('\b');
echos( "\b \b") ;
--ttcol;
--cpos;
TTflush();
@@ -180,9 +204,7 @@ fn_t getname(void)
} else if (c == 0x15) { /* C-U, kill */
while (cpos != 0) {
TTputc('\b');
TTputc(' ');
TTputc('\b');
echos( "\b \b") ;
--cpos;
--ttcol;
}
@@ -203,9 +225,7 @@ fn_t getname(void)
(buf, (ffp + 1)->n_name,
strlen(buf)) != 0)) {
/* no...we match, print it */
sp = ffp->n_name + cpos;
while (*sp)
TTputc(*sp++);
echos( ffp->n_name + cpos) ;
TTflush();
return ffp->n_func;
} else {
@@ -249,8 +269,7 @@ fn_t getname(void)
}
/* add the character */
TTputc(buf
[cpos++]);
echoc( buf[ cpos++]) ;
}
/* << << << << << << << << << << << << << << << << << */
}
@@ -266,7 +285,7 @@ fn_t getname(void)
} else {
if (cpos < NSTRING - 1 && c > ' ') {
buf[cpos++] = c;
TTputc(c);
echoc( c) ;
}
++ttcol;
@@ -457,6 +476,26 @@ handle_CSI:
return CTLX | c;
}
#ifdef CYGWIN
/* Accept UTF-8 sequence */
if( c <= 0xC1 || c > 0xF4)
return c ;
else {
char utf[ 4] ;
char cc ;
utf[ 0] = c ;
utf[ 1] = cc = get1key() ;
if( (c & 0x20) && ((cc & 0xC0) == 0x80)) { /* at least 3 bytes and a valid encoded char */
utf[ 2] = cc = get1key() ;
if( (c & 0x10) && ((cc & 0xC0) == 0x80)) /* at least 4 bytes and a valid encoded char */
utf[ 3] = get1key() ;
}
utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &c) ;
}
#endif
/* otherwise, just return it */
return c;
}
@@ -480,19 +519,16 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
static char tmp[] = "/tmp/meXXXXXX";
FILE *tmpf = NULL;
#endif
ffile = (strcmp(prompt, "Find file: ") == 0
|| strcmp(prompt, "View file: ") == 0
|| strcmp(prompt, "Insert file: ") == 0
|| strcmp(prompt, "Write file: ") == 0
|| strcmp(prompt, "Read file: ") == 0
|| strcmp(prompt, "File to execute: ") == 0);
/* Look for "Find file: ", "View file: ", "Insert file: ", "Write file: ",
** "Read file: ", "Execute file: " */
ffile = NULL != strstr( prompt, " file: ") ;
#endif
cpos = 0;
quotef = FALSE;
/* prompt the user for the input string */
mlwrite(prompt);
mlwrite( "%s", prompt);
for (;;) {
#if COMPLC
@@ -519,6 +555,11 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
mlwrite("");
TTflush();
if( tmpf != NULL) {
fclose( tmpf) ;
unlink( tmp) ;
}
/* if we default the buffer, return FALSE */
if (buf[0] == 0)
return FALSE;
@@ -533,19 +574,24 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
/* Abort the input? */
ctrlg(FALSE, 0);
TTflush();
if( tmpf != NULL) {
fclose( tmpf) ;
unlink( tmp) ;
}
return ABORT;
} else if ((c == 0x7F || c == 0x08) && quotef == FALSE) {
/* rubout/erase */
if (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
@@ -555,15 +601,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
} else if (c == 0x15 && quotef == FALSE) {
/* C-U, kill */
while (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
}
@@ -583,15 +629,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
didtry = 1;
ocpos = cpos;
while (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
if (buf[cpos] == '*' || buf[cpos] == '?')
@@ -608,18 +654,21 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
if (nskip < 0) {
buf[ocpos] = 0;
#if UNIX
if (tmpf != NULL)
if (tmpf != NULL) {
fclose(tmpf);
strcpy(tmp, "/tmp/meXXXXXX");
strcpy(ffbuf, "echo ");
strcat(ffbuf, buf);
if (!iswild)
strcat(ffbuf, "*");
strcat(ffbuf, " >");
xmkstemp(tmp);
strcat(ffbuf, tmp);
strcat(ffbuf, " 2>&1");
system(ffbuf);
tmpf = NULL ;
unlink( tmp) ;
}
strcpy( tmp, "/tmp/meXXXXXX") ;
xmkstemp( tmp) ;
if( strlen( buf) < sizeof ffbuf - 26 - 1)
sprintf( ffbuf, "echo %s%s >%s 2>&1", buf,
!iswild ? "*" : "", tmp) ;
else
sprintf( ffbuf, "echo ERROR >%s 2>&1", tmp) ;
ue_system( ffbuf) ;
tmpf = fopen(tmp, "r");
#endif
#if MSDOS
@@ -675,16 +724,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
for (n = 0; n < cpos; n++) {
c = buf[n];
if ((c < ' ') && (c != '\n')) {
outstring("^");
echos("^");
++ttcol;
c ^= 0x40;
}
if (c != '\n') {
if (disinp)
TTputc(c);
} else { /* put out <NL> for <ret> */
outstring("<NL>");
if( c != '\n')
echoc( c) ;
else { /* put out <NL> for <ret> */
echos("<NL>");
ttcol += 3;
}
++ttcol;
@@ -692,7 +740,6 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
TTflush();
#if UNIX
rewind(tmpf);
unlink(tmp);
#endif
#endif
@@ -704,16 +751,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
buf[cpos++] = c;
if ((c < ' ') && (c != '\n')) {
outstring("^");
echos("^");
++ttcol;
c ^= 0x40;
}
if (c != '\n') {
if (disinp)
TTputc(c);
} else { /* put out <NL> for <ret> */
outstring("<NL>");
if( c != '\n')
echoc( c) ;
else { /* put out <NL> for <ret> */
echos("<NL>");
ttcol += 3;
}
++ttcol;
@@ -722,27 +768,3 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
}
}
}
/*
* output a string of characters
*
* char *s; string to output
*/
void outstring(char *s)
{
if (disinp)
while (*s)
TTputc(*s++);
}
/*
* output a string of output characters
*
* char *s; string to output
*/
void ostring(char *s)
{
if (discmd)
while (*s)
TTputc(*s++);
}

10
input.h
View File

@@ -13,24 +13,22 @@ extern int kbdrep ; /* number of repetitions */
extern int kbdm[] ; /* Holds kayboard macro data */
extern int *kbdptr ; /* current position in keyboard buf */
extern int *kbdend ; /* ptr to end of the keyboard */
extern int disinp ; /* display input characters */
extern int metac; /* current meta character */
extern int ctlxc; /* current control X prefix char */
extern int reptc; /* current universal repeat char */
extern int abortc; /* current abort command char */
extern const int nlc ; /* end of input char */
int mlyesno( const char *prompt) ;
int mlreply( const char *prompt, char *buf, int nbuf) ;
int mlreplyt( const char *prompt, char *buf, int nbuf, int eolchar) ;
int newmlarg( char **outbufref, const char *prompt, int size) ;
int newmlargt( char **outbufref, const char *prompt, int size) ;
int ectoc( int c) ;
int ctoec( int c) ;
fn_t getname( void) ;
int tgetc( void) ;
int get1key( void) ;
int getcmd( void) ;
int getstring( const char *prompt, char *buf, int nbuf, int eolchar) ;
void outstring( char *s) ;
void ostring( char *s) ;
#endif

View File

@@ -185,7 +185,7 @@ static int isearch(int f, int n)
{
int status; /* Search status */
int col; /* prompt column */
int cpos; /* character number in search string */
unsigned cpos ; /* character number in search string */
int c; /* current input character */
int expc; /* function expanded input char */
spat_t pat_save ; /* Saved copy of the old pattern str */
@@ -198,7 +198,8 @@ static int isearch(int f, int n)
cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy( pat_save, pat, sizeof pat_save) ; /* Save the old pattern string */
strncpy( pat_save, pat, sizeof pat_save - 1) ; /* Save the old pattern string */
pat_save[ sizeof pat_save - 1] = '\0' ;
curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */
@@ -208,7 +209,7 @@ static int isearch(int f, int n)
start_over:
/* ask the user for the text of a pattern */
col = promptpattern("ISearch: "); /* Prompt, remember the col */
col = promptpattern( "ISearch") ; /* Prompt, remember the col */
cpos = 0; /* Start afresh */
status = TRUE; /* Assume everything's cool */
@@ -300,7 +301,7 @@ static int isearch(int f, int n)
pat[cpos] = 0; /* null terminate the buffer */
col = echo_char(c, col); /* Echo the character */
if (!status) { /* If we lost last time */
TTputc(BELL); /* Feep again */
TTbeep() ; /* Feep again */
TTflush(); /* see that the feep feeps */
} else /* Otherwise, we must have won */ if (!(status = checknext(c, pat, n))) /* See if match */
status = scanmore(pat, n); /* or find the next match */
@@ -377,7 +378,7 @@ static int scanmore(char *patrn, int dir) /* search forward or back for a patter
sts = scanner(patrn, FORWARD, PTEND); /* Nope. Go forward */
if (!sts) {
TTputc(BELL); /* Feep if search fails */
TTbeep() ; /* Feep if search fails */
TTflush(); /* see that the feep feeps */
}
@@ -397,7 +398,7 @@ static int scanmore(char *patrn, int dir) /* search forward or back for a patter
*/
static int match_pat(char *patrn) /* See if the pattern string matches string at "." */
{
int i; /* Generic loop index/offset */
unsigned i ; /* Generic loop index/offset */
int buffchar; /* character at current position */
struct line *curline; /* current line during scan */
int curoff; /* position within current line */
@@ -431,10 +432,7 @@ static int promptpattern(char *prompt)
{
char tpat[NPAT + 20];
strcpy(tpat, prompt); /* copy prompt to output string */
strcat(tpat, " ("); /* build new prompt string */
expandp(pat, &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
setprompt( tpat, NPAT / 2, prompt, pat) ;
/* check to see if we are executing a command line */
if (!clexec) {

177
line.c
View File

@@ -22,11 +22,11 @@
#include "buffer.h"
#include "estruct.h"
#include "log.h"
#include "mlout.h"
#include "window.h"
int tabmask = 0x07 ; /* tabulator mask */
int tabwidth = 8 ; /* column span of a tab */
#define BLOCK_SIZE 16 /* Line block chunk size. */
@@ -92,30 +92,52 @@ char *getkill( void) {
* location. Error if you try and move out of the buffer. Set the flag if the
* line pointer for dot changes.
*/
int backchar(int f, int n)
{
struct line *lp;
int backchar( int f, int n) {
if( n < 0)
return forwchar( f, -n) ;
if (n < 0)
return forwchar(f, -n);
while (n--) {
if (curwp->w_doto == 0) {
if ((lp = lback(curwp->w_dotp)) == curbp->b_linep)
return FALSE;
curwp->w_dotp = lp;
curwp->w_doto = llength(lp);
curwp->w_flag |= WFMOVE;
while( n--) {
if( curwp->w_doto == 0) {
struct line *lp ;
lp = lback( curwp->w_dotp) ;
if( lp == curbp->b_linep)
return FALSE ;
curwp->w_dotp = lp ;
curwp->w_doto = llength( lp) ;
curwp->w_flag |= WFMOVE ;
} else {
do {
unsigned char c;
curwp->w_doto--;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto);
unsigned pos ;
pos = curwp->w_doto -= 1 ;
if( pos > 0) {
unsigned char *p ;
p = (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]) ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
int delta = 0 ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
delta = 1 ;
else if( ((c & 0xC0) == 0x80) && (pos > 1)) {
c = *--p ;
if( (c & 0xF0) == 0xE0) /* valid 3 bytes unicode seq */
delta = 2 ;
else if( ((c & 0xC0) == 0x80) && (pos > 2))
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
curwp->w_doto -= delta ;
}
}
}
}
return TRUE;
return TRUE ;
}
/*
@@ -137,13 +159,11 @@ int forwchar(int f, int n)
curwp->w_doto = 0;
curwp->w_flag |= WFMOVE;
} else {
do {
unsigned char c;
curwp->w_doto++;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto < len);
unicode_t unc ;
unsigned bytes ;
bytes = utf8_to_unicode( curwp->w_dotp->l_text, curwp->w_doto, len, &unc) ;
curwp->w_doto += bytes ;
}
}
return TRUE;
@@ -164,7 +184,7 @@ struct line *lalloc(int used)
if (size == 0) /* Assume that is an empty. */
size = BLOCK_SIZE; /* Line is for type-in. */
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
logwrite( "(OUT OF MEMORY)") ;
mloutstr( "(OUT OF MEMORY)") ;
return NULL;
}
lp->l_size = size;
@@ -253,6 +273,8 @@ int insspace(int f, int n)
return TRUE;
}
static int linsert_byte( int n, int c) ;
/*
* linstr -- Insert a string at the current point
*/
@@ -261,15 +283,17 @@ int linstr( char *instr) {
int status = TRUE ;
if( instr != NULL) {
char tmpc ;
unicode_t tmpc ;
while( (tmpc = *instr++)) {
while( (tmpc = *instr++ & 0xFF)) {
status =
(tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ;
(tmpc == '\n' ? lnewline() : linsert_byte( 1, tmpc)) ;
/* Insertion error? */
if( status != TRUE)
return logger( status, FALSE, "%%Out of memory while inserting") ;
if( status != TRUE) {
mloutstr( "%Out of memory while inserting") ;
return status ;
}
}
}
@@ -306,7 +330,7 @@ static int linsert_byte(int n, int c)
lp1 = curwp->w_dotp; /* Current line */
if (lp1 == curbp->b_linep) { /* At the end: special */
if (curwp->w_doto != 0) {
logwrite( "bug: linsert") ;
mloutstr( "bug: linsert") ;
return FALSE;
}
if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */
@@ -367,26 +391,30 @@ static int linsert_byte(int n, int c)
return TRUE;
}
int linsert(int n, int c)
{
char utf8[6];
int bytes, i ;
assert( n > 0) ;
int linsert( int n, unicode_t c) {
assert( n >= 0) ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) {
int j;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
if( n > 0) {
char utf8[ 6] ;
int bytes, i ;
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) {
int j;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
}
}
}
return TRUE;
}
@@ -395,13 +423,15 @@ int linsert(int n, int c)
*
* int c; character to overwrite on current position
*/
static int lowrite(int c)
{
if (curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask))
ldelchar(1, FALSE);
return linsert(1, c);
static int lowrite( int c) {
if( curwp->w_doto < curwp->w_dotp->l_used
&& (
lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)
))
ldelchar( 1, FALSE) ;
return linsert( 1, c) ;
}
/*
@@ -418,8 +448,10 @@ int lover( char *ostr) {
(tmpc == '\n' ? lnewline() : lowrite(tmpc));
/* Insertion error? */
if( status != TRUE)
return logger( status, FALSE, "%%Out of memory while overwriting") ;
if( status != TRUE) {
mloutstr( "%Out of memory while overwriting") ;
return status ;
}
}
}
@@ -594,14 +626,24 @@ char *getctext(void)
int size; /* length of line to return */
char *sp; /* string pointer into line */
char *dp; /* string pointer into returned line */
static char rline[NSTRING]; /* line to return */
static int rsize = 0 ;
static char *rline ; /* line to return */
/* find the contents of the current line and its length */
lp = curwp->w_dotp;
sp = lp->l_text;
size = lp->l_used;
if (size >= NSTRING)
size = NSTRING - 1;
if( size >= rsize) {
if( rsize)
free( rline) ;
rsize = size + 1 ;
rline = malloc( rsize) ;
if( rline == NULL) {
rsize = 0 ;
return "" ;
}
}
/* copy it across */
dp = rline;
@@ -807,3 +849,12 @@ int yank(int f, int n)
}
return TRUE;
}
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
boolean rdonly( void) {
mloutfmt( "%B(Key illegal in VIEW mode)") ;
return FALSE ;
}

7
line.h
View File

@@ -1,6 +1,7 @@
#ifndef LINE_H_
#define LINE_H_
#include "retcode.h"
#include "utf8.h"
#define NLINE 256 /* # of bytes, input line */
@@ -27,7 +28,7 @@ struct line {
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used)
extern int tabmask ;
extern int tabwidth ;
char *getkill( void) ;
@@ -38,7 +39,7 @@ void lfree( struct line *lp) ;
void lchange( int flag) ;
int insspace( int f, int n) ;
int linstr( char *instr) ;
int linsert( int n, int c) ;
int linsert( int n, unicode_t c) ;
int lover( char *ostr) ;
int lnewline( void) ;
int ldelete( long n, int kflag) ;
@@ -50,4 +51,6 @@ int kinsert( int c) ;
int yank( int f, int n) ;
struct line *lalloc( int) ; /* Allocate a line. */
boolean rdonly( void) ; /* Read Only error message */
#endif /* LINE_H_ */

7
lock.c
View File

@@ -1,3 +1,5 @@
/* lock.c -- implements lock.h */
#include "estruct.h"
#include "lock.h"
@@ -167,4 +169,9 @@ void lckerror(char *errstr)
strcat(obuf, strerror(errno));
mlwrite(obuf);
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of lock.c */

38
log.c
View File

@@ -1,38 +0,0 @@
#include "log.h"
static void logdump( const char *buf, ...) {
}
void (*logwrite)( const char *, ...) = logdump ;
static boolean logit( boolean retcode, boolean beep_f, const char *buf, ...) {
return retcode ;
}
boolean (*logger)( boolean, boolean, const char *, ...) = logit ;
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
boolean rdonly(void)
{
/* TTbeep();
mlwrite("(Key illegal in VIEW mode)");
return FALSE;
*/
return logger( FALSE, TRUE, "(Key illegal in VIEW mode)");
}
boolean resterr(void)
{
/* TTbeep();
mlwrite("(That command is RESTRICTED)");
return FALSE;
*/
return logger( FALSE, TRUE, "(That command is RESTRICTED)");
}

8
log.h
View File

@@ -1,8 +0,0 @@
#include "retcode.h"
boolean rdonly( void) ;
boolean resterr( void) ;
extern void (*logwrite)( const char *, ...) ;
extern boolean (*logger)( boolean, boolean, const char *, ...) ;

271
main.c
View File

@@ -1,10 +1,12 @@
/* main.c -- */
#define CLRMSG 0 /* space clears the message line with no insert */
/*
* main.c
*
* µEMACS 4.2
*
* Based on:
*
* uEmacs/PK 4.0
*
* Based on:
@@ -53,10 +55,14 @@
*
* 4.0 Petri Kutvonen, 1-Sep-91
*
* This modified version is now called uEmacs/rf.
* This modified version is now called uEMACS.
*
* 4.1 Renaud Fivet, 1-May-13
*
* Renamed as µEMACS to emphasize UTF-8 support.
*
* 4.2 Renaud Fivet, 2015-02-12
*
*/
#include <stdio.h>
@@ -76,9 +82,8 @@
#include "eval.h"
#include "execute.h"
#include "file.h"
#include "input.h"
#include "lock.h"
#include "log.h"
#include "mlout.h"
#include "random.h"
#include "search.h"
#include "terminal.h"
@@ -99,14 +104,14 @@ extern unsigned _stklen = 32766;
static void emergencyexit(int signr)
{
quickexit(FALSE, 0);
quit(TRUE, 0);
quit( TRUE, 0) ; /* If quickexit fails (to save changes), do a force quit */
}
#endif
static void edinit( char *bname) ;
static void version( void) {
fputs( PROGRAM_NAME_LONG " version " VERSION "\n", stdout) ;
fputs( PROGRAM_NAME_PFX PROGRAM_NAME_LONG " version " VERSION "\n", stdout) ;
}
@@ -116,52 +121,32 @@ static void usage( void) {
" +<n> start at line <n>\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
" @cmdfile execute command file\n"
" @cmdfile execute startup file\n"
" -a|A process error file\n"
" -e|E edit file\n"
" -g|G<n> go to line <n>\n"
#if CRYPT
" -k|K<key> use code key\n"
#endif
" -r|R restrictive use\n"
" -s|S<string> search string\n"
" -v|V view file\n"
" -x|Xcmdfile\n"
" -x|X cmdfile execute command file\n"
, stdout) ;
}
static boolean mllog( boolean retcode, boolean beep_f, const char *buf, ...) {
if( beep_f)
TTbeep() ;
mlwrite( buf) ;
return retcode ;
}
int main(int argc, char **argv)
{
int c = -1; /* command character */
int f; /* default flag */
int n; /* numeric repeat count */
int mflag; /* negative flag on repeat */
struct buffer *bp; /* temp buffer pointer */
int firstfile; /* first file flag */
int carg; /* current arg to scan */
int startflag; /* startup executed flag */
struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */
int basec; /* c stripped of meta character */
int viewflag; /* are we starting in view mode? */
int gotoflag; /* do we need to goto a line at start? */
int gline = 0; /* if so, what line? */
int searchflag; /* Do we need to search at start? */
int saveflag; /* temp store for lastflag */
int errflag; /* C error processing? */
bname_t bname ; /* buffer name of file to read */
#if CRYPT
int cryptflag; /* encrypting on the way in? */
ekey_t ekey ; /* startup encryption key */
#endif
int newc;
#if PKCODE & VMS
(void) umask(-1); /* Use old protection (this is at wrong place). */
@@ -190,8 +175,7 @@ int main(int argc, char **argv)
/* Initialize the editor. */
vtinit(); /* Display */
logwrite = mlwrite ;
logger = mllog ;
mloutfmt = mlwrite ;
edinit("main"); /* Buffers, windows */
varinit(); /* user variables */
@@ -201,9 +185,9 @@ int main(int argc, char **argv)
firstfile = TRUE; /* no file to edit yet */
startflag = FALSE; /* startup file not executed yet */
errflag = FALSE; /* not doing C error parsing */
#if CRYPT
cryptflag = FALSE; /* no encryption by default */
#endif
/* Insure screen is initialized before startup and goto/search */
update( FALSE) ;
/* Parse the command line */
for (carg = 1; carg < argc; ++carg) {
@@ -230,14 +214,6 @@ int main(int argc, char **argv)
gotoflag = TRUE;
gline = atoi(&argv[carg][2]);
break;
#if CRYPT
case 'k': /* -k<key> for code key */
case 'K':
cryptflag = TRUE;
strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ;
ekey[ sizeof ekey - 1] = 0 ;
break;
#endif
case 'r': /* -r restrictive use */
case 'R':
restflag = TRUE;
@@ -252,6 +228,19 @@ int main(int argc, char **argv)
case 'V':
viewflag = TRUE;
break;
case 'x':
case 'X':
if( argv[ carg][ 2]) { /* -Xfilename */
if( startup( &argv[ carg][ 2]) == TRUE)
startflag = TRUE ; /* don't execute emacs.rc */
} else if( argv[ carg + 1]) { /* -X filename */
if( startup( &argv[ carg + 1][ 0]) == TRUE)
startflag = TRUE ; /* don't execute emacs.rc */
carg += 1 ;
}
break ;
default: /* unknown switch */
/* ignore this for now */
break;
@@ -273,7 +262,12 @@ int main(int argc, char **argv)
unqname(bname);
/* set this to inactive */
bp = bfind(bname, TRUE, 0);
bp = bfind( bname, TRUE, 0) ;
if( bp == NULL) {
fputs( "Buffer creation failed!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
strncpy( bp->b_fname, argv[ carg], sizeof bp->b_fname - 1) ; /* max filename length limited to NFILEN - 1 (79) */
bp->b_fname[ sizeof bp->b_fname - 1] = 0 ;
bp->b_active = FALSE;
@@ -285,13 +279,6 @@ int main(int argc, char **argv)
/* set the modes appropriatly */
if (viewflag)
bp->b_mode |= MDVIEW;
#if CRYPT
if (cryptflag) {
bp->b_mode |= MDCRYPT;
strncpy( bp->b_key, ekey, sizeof ekey) ;
cryptbufferkey( bp) ;
}
#endif
}
}
@@ -310,162 +297,46 @@ int main(int argc, char **argv)
/* if invoked with no other startup files,
run the system startup file here */
if (startflag == FALSE) {
startup("");
startflag = TRUE;
if( startflag == FALSE) {
if( startup( "") != TRUE)
mloutstr( "Default startup failed!") ;
startflag = TRUE ;
}
discmd = TRUE; /* P.K. */
/* if there are any files to read, read the first one! */
bp = bfind("main", FALSE, 0);
if (firstfile == FALSE && (gflags & GFREAD)) {
if( bp == NULL) {
/* "main" buffer has been created during early initialisation */
fputs( "Initialisation failure!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
if (firstfile == FALSE && readfirst_f()) {
swbuffer(firstbp);
zotbuf(bp);
} else
} else {
bp->b_mode |= gmode;
upmode() ;
}
/* Deal with startup gotos and searches */
if (gotoflag && searchflag) {
update(FALSE);
mlwrite("(Can not search and goto at the same time!)");
} else if (gotoflag) {
if (gotoline(TRUE, gline) == FALSE) {
update(FALSE);
mlwrite("(Bogus goto argument)");
}
} else if (searchflag) {
if (forwhunt(FALSE, 0) == FALSE)
update(FALSE);
}
if( gotoflag && searchflag)
mloutstr( "(Can not search and goto at the same time!)") ;
else if( gotoflag) {
if( gotoline( TRUE, gline) == FALSE)
mloutstr( "(Bogus goto argument)") ;
} else if( searchflag)
if( forwhunt( FALSE, 0))
mloutfmt( "Found on line %d", getcline()) ;
/* Setup to process commands. */
lastflag = 0; /* Fake last flags. */
loop:
/* Execute the "command" macro...normally null. */
saveflag = lastflag; /* Preserve lastflag through this. */
execute(META | SPEC | 'C', FALSE, 1);
lastflag = saveflag;
#if TYPEAH && PKCODE
if (typahead()) {
newc = getcmd();
update(FALSE);
do {
fn_t execfunc;
if (c == newc && (execfunc = getbind(c)) != NULL
&& execfunc != insert_newline
&& execfunc != insert_tab)
newc = getcmd();
else
break;
} while (typahead());
c = newc;
} else {
update(FALSE);
c = getcmd();
}
#else
/* Fix up the screen */
update(FALSE);
/* get the next command from the keyboard */
c = getcmd();
#endif
/* if there is something on the command line, clear it */
if (mpresf != FALSE) {
mlerase();
update(FALSE);
#if CLRMSG
if (c == ' ') /* ITS EMACS does this */
goto loop;
#endif
}
f = FALSE;
n = 1;
/* do META-# processing if needed */
basec = c & ~META; /* strip meta char off if there */
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
f = TRUE; /* there is a # arg */
n = 0; /* start with a zero default */
mflag = 1; /* current minus flag */
c = basec; /* strip the META */
while ((c >= '0' && c <= '9') || (c == '-')) {
if (c == '-') {
/* already hit a minus or digit? */
if ((mflag == -1) || (n != 0))
break;
mflag = -1;
} else {
n = n * 10 + (c - '0');
}
if ((n == 0) && (mflag == -1)) /* lonely - */
mlwrite("Arg:");
else
mlwrite("Arg: %d", n * mflag);
c = getcmd(); /* get the next key */
}
n = n * mflag; /* figure in the sign */
}
/* do ^U repeat argument processing */
if (c == reptc) { /* ^U, start argument */
f = TRUE;
n = 4; /* with argument of 4 */
mflag = 0; /* that can be discarded. */
mlwrite("Arg: 4");
while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
|| c == '-') {
if (c == reptc)
if ((n > 0) == ((n * 4) > 0))
n = n * 4;
else
n = 1;
/*
* If dash, and start of argument string, set arg.
* to -1. Otherwise, insert it.
*/
else if (c == '-') {
if (mflag)
break;
n = 0;
mflag = -1;
}
/*
* If first digit entered, replace previous argument
* with digit and set sign. Otherwise, append to arg.
*/
else {
if (!mflag) {
n = 0;
mflag = 1;
}
n = 10 * n + c - '0';
}
mlwrite("Arg: %d",
(mflag >= 0) ? n : (n ? -n : -1));
}
/*
* Make arguments preceded by a minus sign negative and change
* the special argument "^U -" to an effective "^U -1".
*/
if (mflag == -1) {
if (n == 0)
n++;
n = -n;
}
}
/* and execute the command */
execute(c, f, n);
goto loop;
kbd_loop() ;
return EXIT_SUCCESS ; /* never reached */
}
/*
* Initialize all of the buffers and windows. The buffer name is passed down
* as an argument, because the main routine may have been told to read in a
@@ -479,8 +350,11 @@ static void edinit(char *bname)
bp = bfind(bname, TRUE, 0); /* First buffer */
blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */
wp = (struct window *)malloc(sizeof(struct window)); /* First window */
if (bp == NULL || wp == NULL || blistp == NULL)
exit(1);
if (bp == NULL || wp == NULL || blistp == NULL) {
fputs( "First initialisation failed!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
curbp = bp; /* Make this current */
wheadp = wp;
curwp = wp;
@@ -593,8 +467,7 @@ static void dspram( void)
*
* int status; return status of emacs
*/
int cexit(int status)
{
void cexit( int status) {
struct buffer *bp; /* buffer list pointer */
struct window *wp; /* window list pointer */
struct window *tp; /* temporary window pointer */

View File

@@ -1,3 +1,5 @@
/* mingw32.c -- */
#ifdef MINGW32
#include "termio.h"
#include "terminal.h"
@@ -188,4 +190,8 @@ static void ttmove( int l, int c) {
wgoxy( c, l) ;
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of mingw32.c */

15
mlout.c Normal file
View File

@@ -0,0 +1,15 @@
/* mlout.c -- implements mlout.h */
#include "mlout.h"
/* by default just use a stub */
static void mloutdump( const char *buf, ...) {
}
void (*mloutfmt)( const char *, ...) = mloutdump ;
void mloutstr( const char *str) {
mloutfmt( (*str) ? "%s" : "", str) ;
}
/* end of mlout.c */

12
mlout.h Normal file
View File

@@ -0,0 +1,12 @@
/* mlout.h -- message line output interface */
#ifndef __MLOUT_H__
#define __MLOUT_H__
extern void (*mloutfmt)( const char *, ...) ;
void mloutstr( const char *str) ;
#endif /* __MLOUT_H__ */
/* end of mlout.h */

View File

@@ -205,9 +205,6 @@ struct name_bind names[] = {
{"search-reverse", backsearch},
{"select-buffer", usebuffer},
{"set", setvar},
#if CRYPT
{"set-encryption-key", set_encryption_key},
#endif
{"set-fill-column", setfillcol},
{"set-mark", setmark},
{"shell-command", spawn},

View File

@@ -20,7 +20,8 @@
#endif
#include <errno.h>
#define MAXLOCK 512
/* Maximum file length name 255 */
#define MAXLOCK 256
#define MAXNAME 128
#if defined(SVR4) && ! defined(__linux__)
@@ -44,11 +45,14 @@ int gethostname(char *name, int namelen)
char *dolock( const char *fname)
{
int fd, n;
static char lname[MAXLOCK], locker[MAXNAME + 1];
char lname[ MAXLOCK] ;
static char locker[ MAXNAME + 1] ;
int mask;
struct stat sbuf;
strcat(strcpy(lname, fname), ".lock~");
strncpy( lname, fname, sizeof lname - 1 - 6) ;
lname[ sizeof lname - 1 - 6] = 0 ;
strcat( lname, ".lock~") ;
/* check that we are not being cheated, qname must point to */
/* a regular file - even this code leaves a small window of */
@@ -84,7 +88,16 @@ char *dolock( const char *fname)
cuserid(locker);
strcat(locker + strlen(locker), "@");
gethostname(locker + strlen(locker), 64);
write(fd, locker, strlen(locker));
{
int ret, locker_size ;
locker_size = strlen( locker) ;
ret = write( fd, locker, locker_size) ;
if( ret != locker_size) {
/* some error handling here */
}
}
close(fd);
return NULL;
}
@@ -102,11 +115,12 @@ char *dolock( const char *fname)
*
*********************/
char *undolock( const char *fname)
{
static char lname[MAXLOCK];
char *undolock( const char *fname) {
char lname[ MAXLOCK] ;
strcat(strcpy(lname, fname), ".lock~");
strncpy( lname, fname, sizeof lname - 1 - 6) ;
lname[ sizeof lname - 1 - 6] = 0 ;
strcat( lname, ".lock~") ;
if (unlink(lname) != 0) {
if (errno == EACCES || errno == ENOENT)
return NULL;
@@ -118,4 +132,9 @@ char *undolock( const char *fname)
}
return NULL;
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of pklock.c */

12
posix.c
View File

@@ -1,4 +1,6 @@
/* posix.c -- implements termio.h */
/* posix.c -- posix implementation of termio.h */
#ifdef POSIX
#include "termio.h"
/* posix.c
@@ -13,8 +15,6 @@
* fixed for termios rather than the old termio.. Linus Torvalds
*/
#ifdef POSIX
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -250,4 +250,8 @@ int typahead(void)
return x;
}
#endif /* POSIX */
#else
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */
/* end of posix.c */

591
random.c
View File

@@ -1,8 +1,6 @@
/* random.c -- implements random.h */
#include "random.h"
#define NBRACE 1 /* new style brace matching command */
/* random.c
*
* This file contains the command processing functions for a number of
@@ -12,6 +10,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic.h"
@@ -21,7 +20,6 @@
#include "execute.h"
#include "input.h"
#include "line.h"
#include "log.h"
#include "search.h"
#include "terminal.h"
#include "window.h"
@@ -40,7 +38,7 @@ static const char *cname[] = { /* names of colors */
int gfcolor = NCOLORS - 1 ; /* global forgrnd color (white) */
int gbcolor = 0 ; /* global backgrnd color (black) */
static int tabsize ; /* Tab size (0: use real tabs) */
boolean hardtab = TRUE ; /* use hard tab instead of soft tab */
int fillcol = 72 ; /* Current fill column */
/* uninitialized global definitions */
@@ -49,6 +47,9 @@ int thisflag ; /* Flags, this command */
int lastflag ; /* Flags, last command */
static int adjustmode( int kind, int global) ;
static int cinsert( void) ;
/*
* Set fill column to n.
*/
@@ -73,7 +74,8 @@ int showcpos(int f, int n)
int numlines; /* # of lines in file */
long predchars; /* # chars preceding point */
int predlines; /* # lines preceding point */
int curchar; /* character under cursor */
unicode_t curchar ; /* character under cursor */
unsigned bytes ; /* length of unicode sequence */
int ratio;
int col;
int savepos; /* temp save for current offset */
@@ -88,19 +90,23 @@ int showcpos(int f, int n)
predchars = 0;
predlines = 0;
curchar = 0;
bytes = 1 ;
while (lp != curbp->b_linep) {
/* if we are on the current line, record it */
if (lp == curwp->w_dotp) {
int len ;
predlines = numlines;
predchars = numchars + curwp->w_doto;
if ((curwp->w_doto) == llength(lp))
curchar = '\n';
len = llength( lp) ;
if( (curwp->w_doto) == len)
curchar = (curbp->b_mode & MDDOS) ? '\r' : '\n' ;
else
curchar = lgetc(lp, curwp->w_doto);
bytes = utf8_to_unicode( lp->l_text, curwp->w_doto, len, &curchar) ;
}
/* on to the next line */
++numlines;
numchars += llength(lp) + 1;
numchars += llength( lp) + ((curbp->b_mode & MDDOS) ? 2 : 1) ;
lp = lforw(lp);
}
@@ -125,9 +131,9 @@ int showcpos(int f, int n)
ratio = (100L * predchars) / numchars;
/* summarize and report the info */
mlwrite("Line %d/%d Col %d/%d Char %D/%D (%d%%) char = 0x%x",
mlwrite("Line %d/%d Col %d/%d Char %D/%D (%d%%) char = %s%x",
predlines + 1, numlines + 1, col, ecol,
predchars, numchars, ratio, curchar);
predchars, numchars, ratio, (bytes > 1) ? "\\u" : "0x", curchar);
return TRUE;
}
@@ -168,15 +174,16 @@ int getccol(int bflg)
unicode_t c;
i += utf8_to_unicode(dlp->l_text, i, len, &c);
if (c != ' ' && c != '\t' && bflg)
if( bflg && c != ' ' && c != '\t') /* Request Stop at first non-blank */
break;
if (c == '\t')
col |= tabmask;
else if (c < 0x20 || c == 0x7F)
++col;
else if (c >= 0xc0 && c <= 0xa0)
col += 2;
++col;
col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F) /* displayed as ^c */
col += 2 ;
else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */
col += 3 ;
else
col += 1 ;
}
return col;
}
@@ -205,10 +212,11 @@ int setccol(int pos)
/* advance one character */
c = lgetc(curwp->w_dotp, i);
if (c == '\t')
col |= tabmask;
col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F)
++col;
++col;
col += 2 ;
else
col += 1 ;
}
/* set us at the new position */
@@ -282,17 +290,21 @@ int quote(int f, int n)
* done in this slightly funny way because the tab (in ASCII) has been turned
* into "C-I" (in 10 bit code) already. Bound to "C-I".
*/
int insert_tab(int f, int n)
{
if (n < 0)
return FALSE;
if (n == 0 || n > 1) {
tabsize = n;
return TRUE;
}
if (!tabsize)
return linsert(1, '\t');
return linsert(tabsize - (getccol(FALSE) % tabsize), ' ');
int insert_tab( int f, int n) {
int status ;
if( n < 0)
status = FALSE ;
else if( n == 0)
status = TRUE ;
else if( hardtab == TRUE)
status = linsert( n, '\t') ;
else /* softtab */
do {
status = linsert( tabwidth - getccol( FALSE) % tabwidth, ' ') ;
} while( status != FALSE && --n) ;
return status ;
}
#if AEDIT
@@ -321,10 +333,9 @@ int detab(int f, int n)
/* if we have a tab */
if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') {
ldelchar(1, FALSE);
insspace(TRUE,
(tabmask + 1) -
(curwp->w_doto & tabmask));
insspace( TRUE, tabwidth - curwp->w_doto % tabwidth);
}
forwchar(FALSE, 1);
}
@@ -345,7 +356,7 @@ int detab(int f, int n)
*/
int entab(int f, int n)
{
#define nextab(a) (a & ~tabmask) + (tabmask+1)
#define nextab(a) (a + tabwidth - a % tabwidth)
int inc; /* increment to next line [sgn(n)] */
int fspace; /* pointer to first space if in a run */
@@ -489,8 +500,6 @@ int openline(int f, int n)
*/
int insert_newline(int f, int n)
{
int s;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
@@ -513,6 +522,8 @@ int insert_newline(int f, int n)
/* insert some lines */
while (n--) {
int s ;
if ((s = lnewline()) != TRUE)
return s;
#if SCROLLCODE
@@ -522,202 +533,64 @@ int insert_newline(int f, int n)
return TRUE;
}
int cinsert(void)
static int cinsert(void)
{ /* insert a newline and indentation for C */
char *cptr; /* string pointer into text to copy */
int tptr; /* index to scan into line */
int bracef; /* was there a brace at the end of line? */
int i;
char ichar[NSTRING]; /* buffer to hold indent of last line */
int i, nicol ;
/* grab a pointer to text to copy indentation from */
cptr = &curwp->w_dotp->l_text[0];
/* check for a brace */
tptr = curwp->w_doto - 1;
bracef = (cptr[tptr] == '{');
tptr = curwp->w_doto ;
bracef = (tptr > 0) && (cptr[ tptr - 1] == '{') ;
/* save the indent of the previous line */
i = 0;
while ((i < tptr) && (cptr[i] == ' ' || cptr[i] == '\t')
&& (i < NSTRING - 1)) {
ichar[i] = cptr[i];
++i;
nicol = 0 ;
for( i = 0 ; i < tptr ; i += 1) {
int ch ;
ch = cptr[ i] ;
if( ch == ' ')
nicol += 1 ;
else if( ch == '\t')
nicol += tabwidth - nicol % tabwidth ;
else
break ;
}
ichar[i] = 0; /* terminate it */
if( i == tptr) { /* all line is blank */
curwp->w_doto = 0 ; /* gotobol */
lnewline() ;
curwp->w_doto = tptr ; /* gotoeol */
} else {
/* put in the newline */
if (lnewline() == FALSE)
return FALSE;
if (lnewline() == FALSE)
return FALSE;
/* and the saved indentation */
linstr(ichar);
i = nicol % tabwidth ; /* spaces */
nicol /= tabwidth ; /* tabs */
if( bracef) {
/* and one more tab for a brace */
nicol += 1 ;
i = 0 ;
}
/* and one more tab for a brace */
if (bracef)
insert_tab(FALSE, 1);
if( nicol > 0)
insert_tab( FALSE, nicol) ;
if( i > 0)
linsert( i, ' ') ;
}
#if SCROLLCODE
curwp->w_flag |= WFINS;
#endif
return TRUE;
}
#if NBRACE
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (always } for now)
*/
int insbrace(int n, int c)
{
int ch; /* last character before input */
int oc; /* caractere oppose a c */
int i, count;
int target; /* column brace should go after */
struct line *oldlp;
int oldoff;
/* if we aren't at the beginning of the line... */
if (curwp->w_doto != 0)
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(n, c);
}
/* chercher le caractere oppose correspondant */
switch (c) {
case '}':
oc = '{';
break;
case ']':
oc = '[';
break;
case ')':
oc = '(';
break;
default:
return FALSE;
}
oldlp = curwp->w_dotp;
oldoff = curwp->w_doto;
count = 1;
backchar(FALSE, 1);
while (count > 0) {
if (curwp->w_doto == llength(curwp->w_dotp))
ch = '\n';
else
ch = lgetc(curwp->w_dotp, curwp->w_doto);
if (ch == c)
++count;
if (ch == oc)
--count;
backchar(FALSE, 1);
if (boundry(curwp->w_dotp, curwp->w_doto, REVERSE))
break;
}
if (count != 0) { /* no match */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
return linsert(n, c);
}
curwp->w_doto = 0; /* debut de ligne */
/* aller au debut de la ligne apres la tabulation */
while ((ch = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
|| ch == '\t')
forwchar(FALSE, 1);
/* delete back first */
target = getccol(FALSE); /* c'est l'indent que l'on doit avoir */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
while (target != getccol(FALSE)) {
if (target < getccol(FALSE)) /* on doit detruire des caracteres */
while (getccol(FALSE) > target)
backdel(FALSE, 1);
else { /* on doit en inserer */
while (target - getccol(FALSE) >= 8)
linsert(1, '\t');
linsert(target - getccol(FALSE), ' ');
}
}
/* and insert the required brace(s) */
return linsert(n, c);
}
#else
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (always { for now)
*/
int insbrace(int n, int c)
{
int ch; /* last character before input */
int i;
int target; /* column brace should go after */
/* if we are at the beginning of the line, no go */
if (curwp->w_doto == 0)
return linsert(n, c);
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(n, c);
}
/* delete back first */
target = getccol(FALSE); /* calc where we will delete to */
target -= 1;
target -= target % (tabsize == 0 ? 8 : tabsize);
while (getccol(FALSE) > target)
backdel(FALSE, 1);
/* and insert the required brace(s) */
return linsert(n, c);
}
#endif
int inspound(void)
{ /* insert a # into the text here...we are in CMODE */
int ch; /* last character before input */
int i;
/* if we are at the beginning of the line, no go */
if (curwp->w_doto == 0)
return linsert(1, '#');
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(1, '#');
}
/* delete back first */
while (getccol(FALSE) >= 1)
backdel(FALSE, 1);
/* and insert the required pound */
return linsert(1, '#');
}
/*
* Delete blank lines around dot. What this command does depends if dot is
@@ -751,38 +624,45 @@ int deblank(int f, int n)
/*
* Insert a newline, then enough tabs and spaces to duplicate the indentation
* of the previous line. Assumes tabs are every eight characters. Quite simple.
* of the previous line. Assumes tabs are every tabwidth characters.
* Figure out the indentation of the current line. Insert a newline by calling
* the standard routine. Insert the indentation by inserting the right number
* of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
* subcomands failed. Normally bound to "C-J".
*/
int indent(int f, int n)
{
int nicol;
int c;
int i;
int indent( int f, int n) {
int nicol ;
int i ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return FALSE;
while (n--) {
nicol = 0;
for (i = 0; i < llength(curwp->w_dotp); ++i) {
c = lgetc(curwp->w_dotp, i);
if (c != ' ' && c != '\t')
break;
if (c == '\t')
nicol |= tabmask;
++nicol;
}
if (lnewline() == FALSE
|| ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE)
|| ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE))
return FALSE;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n < 0)
return FALSE ;
/* number of columns to indent */
nicol = 0 ;
for( i = 0 ; i < llength( curwp->w_dotp) ; i += 1) {
int c ;
c = lgetc( curwp->w_dotp, i) ;
if( c == '\t')
nicol += tabwidth - nicol % tabwidth ;
else if( c == ' ')
nicol += 1 ;
else
break ;
}
return TRUE;
i = nicol / tabwidth ; /* # of tab to insert */
nicol %= tabwidth ; /* # of space to insert */
while( n--)
if( lnewline() == FALSE
|| ( i != 0 && insert_tab( FALSE, i) == FALSE)
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
return FALSE ;
return TRUE ;
}
/*
@@ -932,12 +812,11 @@ int delgmode(int f, int n)
* int kind; true = set, false = delete
* int global; true = global flag, false = current buffer flag
*/
int adjustmode(int kind, int global)
{
int i; /* loop index */
static int adjustmode( int kind, int global) {
unsigned i ; /* loop index */
int status; /* error return on input */
char prompt[50]; /* string to prompt user with */
char cbuf[ NSTRING] ; /* buffer to recieve mode name into */
char *cbuf ; /* buffer to recieve mode name into */
/* build the proper prompt string */
if (global)
@@ -952,7 +831,7 @@ int adjustmode(int kind, int global)
/* prompt the user and get an answer */
status = mlreply( prompt, cbuf, sizeof cbuf - 1) ;
status = newmlarg( &cbuf, prompt, 0) ;
if (status != TRUE)
return status;
@@ -980,6 +859,7 @@ int adjustmode(int kind, int global)
curwp->w_flag |= WFCOLR;
#endif
mlerase();
free( cbuf) ;
return TRUE;
}
}
@@ -1002,59 +882,16 @@ int adjustmode(int kind, int global)
if (global == 0)
upmode();
mlerase(); /* erase the junk */
free( cbuf) ;
return TRUE;
}
}
mlwrite("No such mode!");
free( cbuf) ;
return FALSE;
}
/*
* This function simply clears the message line,
* mainly for macro usage
*
* int f, n; arguments ignored
*/
int clrmes(int f, int n)
{
mlforce("");
return TRUE;
}
/*
* This function writes a string on the message line
* mainly for macro usage
*
* int f, n; arguments ignored
*/
int writemsg(int f, int n)
{
char *sp; /* pointer into buf to expand %s */
char *np; /* ptr into nbuf */
int status;
char buf[ NSTRING] ; /* buffer to recieve message into */
char nbuf[ NSTRING * 2] ; /* buffer to expand string into */
if ((status =
mlreply("Message to write: ", buf, sizeof buf - 1)) != TRUE)
return status;
/* expand all '%' to "%%" so mlwrite won't expect arguments */
sp = buf;
np = nbuf;
while (*sp) {
*np++ = *sp;
if (*sp++ == '%')
*np++ = '%';
}
*np = '\0';
/* write the message out */
mlforce(nbuf);
return TRUE;
}
#if CFENCE
/*
* the cursor is moved to a matching fence
@@ -1112,114 +949,60 @@ int getfence(int f, int n)
return FALSE;
}
/* set up for scan */
count = 1;
if (sdir == REVERSE)
backchar(FALSE, 1);
else
forwchar(FALSE, 1);
/* scan until we find a match, or reach the end of file */
count = 1 ;
do {
if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) {
/* at buffer limit, no match to be found */
/* restore the current position */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
TTbeep() ;
return FALSE ;
}
/* scan until we find it, or reach the end of file */
while (count > 0) {
if (curwp->w_doto == llength(curwp->w_dotp))
c = '\n';
if( sdir == FORWARD)
forwchar( FALSE, 1) ;
else
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (c == ch)
++count;
if (c == ofence)
--count;
if (sdir == FORWARD)
forwchar(FALSE, 1);
else
backchar(FALSE, 1);
if (boundry(curwp->w_dotp, curwp->w_doto, sdir))
break;
}
backchar( FALSE, 1) ;
/* if count is zero, we have a match, move the sucker */
if (count == 0) {
if (sdir == FORWARD)
backchar(FALSE, 1);
else
forwchar(FALSE, 1);
curwp->w_flag |= WFMOVE;
return TRUE;
}
/* if no eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
if( c == ch)
++count ;
else if( c == ofence)
--count ;
}
} while( count > 0) ;
/* restore the current position */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
TTbeep();
return FALSE;
/* we have a match, move the sucker */
curwp->w_flag |= WFMOVE ;
return TRUE ;
}
#endif
/*
* Close fences are matched against their partners, and if
* on screen the cursor briefly lights there
*
* char ch; fence type to match against
*/
int fmatch(int ch)
{
struct line *oldlp; /* original line pointer */
int oldoff; /* and offset */
struct line *toplp; /* top line in current window */
int count; /* current fence level count */
char opench; /* open fence */
char c; /* current character in scan */
int i;
/* first get the display update out there */
update(FALSE);
static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
int status ; /* status return code */
char *tstring ; /* string to add */
/* save the original cursor position */
oldlp = curwp->w_dotp;
oldoff = curwp->w_doto;
/* ask for string to insert */
status = newmlargt( &tstring, prompt, 0) ; /* grab as big a token as screen allow */
if( tstring == NULL)
return status ;
/* setup proper open fence for passed close fence */
if (ch == ')')
opench = '(';
else if (ch == '}')
opench = '{';
else
opench = '[';
if( f == FALSE)
n = 1 ;
else if( n < 0)
n = -n ;
/* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp;
count = 1;
backchar(FALSE, 2);
/* insert it */
while( n-- && status == TRUE)
status = fun( tstring) ;
/* scan back until we find it, or reach past the top of the window */
while (count > 0 && curwp->w_dotp != toplp) {
if (curwp->w_doto == llength(curwp->w_dotp))
c = '\n';
else
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (c == ch)
++count;
if (c == opench)
--count;
backchar(FALSE, 1);
if (curwp->w_dotp == curwp->w_bufp->b_linep->l_fp &&
curwp->w_doto == 0)
break;
}
/* if count is zero, we have a match, display the sucker */
/* there is a real machine dependant timing problem here we have
yet to solve......... */
if (count == 0) {
forwchar(FALSE, 1);
for (i = 0; i < term.t_pause; i++)
update(FALSE);
}
/* restore the current position */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
return TRUE;
free( tstring) ;
return status ;
}
/*
@@ -1228,26 +1011,8 @@ int fmatch(int ch)
*
* int f, n; ignored arguments
*/
int istring(int f, int n)
{
int status; /* status return code */
char tstring[ 512] ; /* string to add */
/* ask for string to insert */
status =
mlreplyt("String to insert<META>: ", tstring, sizeof tstring - 1, metac) ;
if (status != TRUE)
return status;
if (f == FALSE)
n = 1;
if (n < 0)
n = -n;
/* insert it */
while (n-- && (status = linstr(tstring)));
return status;
int istring( int f, int n) {
return iovstring( f, n, "String to insert<META>: ", linstr) ;
}
/*
@@ -1256,24 +1021,8 @@ int istring(int f, int n)
*
* int f, n; ignored arguments
*/
int ovstring(int f, int n)
{
int status; /* status return code */
char tstring[ NSTRING + 1] ; /* string to add */
/* ask for string to insert */
status =
mlreplyt( "String to overwrite<META>: ", tstring, NSTRING, metac) ;
if (status != TRUE)
return status;
if (f == FALSE)
n = 1;
if (n < 0)
n = -n;
/* insert it */
while (n-- && (status = lover(tstring)));
return status;
int ovstring( int f, int n) {
return iovstring( f, n, "String to overwrite<META>: ", lover) ;
}
/* end of random.c */

View File

@@ -1,9 +1,14 @@
#ifndef _RANDOM_H_
#define _RANDOM_H_
#include "retcode.h"
#define AEDIT 1
extern int fillcol ; /* Fill column */
extern boolean hardtab ; /* Use hard tab instead of soft tab */
/* Uninitialized global external declarations. */
@@ -29,9 +34,6 @@ int trim( int f, int n) ;
#endif
int openline( int f, int n) ;
int insert_newline( int f, int n) ;
int cinsert( void) ;
int insbrace( int n, int c) ;
int inspound( void) ;
int deblank( int f, int n) ;
int indent( int f, int n) ;
int forwdel( int f, int n) ;
@@ -41,11 +43,7 @@ int setemode( int f, int n) ;
int delmode( int f, int n) ;
int setgmode( int f, int n) ;
int delgmode( int f, int n) ;
int adjustmode( int kind, int global) ;
int clrmes( int f, int n) ;
int writemsg( int f, int n) ;
int getfence( int f, int n) ;
int fmatch( int ch) ;
int istring( int f, int n) ;
int ovstring( int f, int n) ;

View File

@@ -15,7 +15,7 @@
#include "buffer.h"
#include "estruct.h"
#include "line.h"
#include "log.h"
#include "mlout.h"
#include "random.h"
#include "window.h"
@@ -74,7 +74,7 @@ int copyregion(int f, int n)
++loffs;
}
}
logwrite("(region copied)");
mloutstr( "(region copied)") ;
return TRUE;
}
@@ -171,7 +171,7 @@ int getregion(struct region *rp)
long bsize;
if (curwp->w_markp == NULL) {
logwrite("No mark set in this window");
mloutstr( "No mark set in this window") ;
return FALSE;
}
if (curwp->w_dotp == curwp->w_markp) {
@@ -213,6 +213,6 @@ int getregion(struct region *rp)
}
}
}
logwrite("Bug: lost mark");
mloutstr( "Bug: lost mark") ;
return FALSE;
}

100
search.c
View File

@@ -70,7 +70,7 @@
#include "estruct.h"
#include "input.h"
#include "line.h"
#include "log.h"
#include "mlout.h"
#include "terminal.h"
#include "window.h"
@@ -93,6 +93,9 @@ spat_t rpat ; /* replacement pattern */
#if defined(MAGIC)
#define BELL 0x07 /* a bell character */
/*
* Defines for the metacharacters in the regular expression
* search routines.
@@ -213,7 +216,7 @@ int forwsearch(int f, int n)
if (status == TRUE)
savematch();
else
mlwrite("Not found");
mloutstr( "Not found") ;
}
return status;
}
@@ -236,7 +239,7 @@ int forwhunt(int f, int n)
* into MAGIC mode until after we entered the pattern.
*/
if (pat[0] == '\0') {
mlwrite("No pattern set");
mloutstr( "No pattern set") ;
return FALSE;
}
#if MAGIC
@@ -266,7 +269,7 @@ int forwhunt(int f, int n)
if (status == TRUE)
savematch();
else
mlwrite("Not found");
mloutstr( "Not found") ;
return status;
}
@@ -314,7 +317,7 @@ int backsearch(int f, int n)
if (status == TRUE)
savematch();
else
mlwrite("Not found");
mloutstr( "Not found") ;
}
return status;
}
@@ -338,7 +341,7 @@ int backhunt(int f, int n)
* into MAGIC mode until after we entered the pattern.
*/
if (tap[0] == '\0') {
mlwrite("No pattern set");
mloutstr( "No pattern set") ;
return FALSE;
}
#if MAGIC
@@ -368,7 +371,7 @@ int backhunt(int f, int n)
if (status == TRUE)
savematch();
else
mlwrite("Not found");
mloutstr( "Not found") ;
return status;
}
@@ -510,8 +513,7 @@ static int amatch(struct magic *mcptr, int direct, struct line **pcwline, int *p
mcptr++;
for (;;) {
c = nextch(&curline, &curoff,
direct ^ REVERSE);
(void) nextch( &curline, &curoff, direct ^ REVERSE) ;
if (amatch
(mcptr, direct, &curline, &curoff)) {
@@ -680,6 +682,14 @@ int eq(unsigned char bc, unsigned char pc)
return bc == pc;
}
void setprompt( char *tpat, unsigned tpat_size, char *prompt, char *apat) {
strncpy( tpat, prompt, 14) ; /* copy prompt to output string */
tpat[ 14] = '\0' ; /* longest prompt is "Reverse Search" */
strcat( tpat, " (") ; /* build new prompt string */
expandp( apat, &tpat[ strlen( tpat)], tpat_size) ; /* add old pattern */
strcat( tpat, ")<Meta>: ") ;
}
/*
* readpattern -- Read a pattern. Stash it in apat. If it is the
* search string, create the reverse pattern and the magic
@@ -695,19 +705,20 @@ static int readpattern(char *prompt, char *apat, int srch)
{
int status;
char tpat[NPAT + 20];
char *dynpat ; /* dynamically allocated pattern buffer */
strcpy(tpat, prompt); /* copy prompt to output string */
strcat(tpat, " ("); /* build new prompt string */
expandp(&apat[0], &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
setprompt( tpat, NPAT / 2, prompt, apat) ;
/* Read a pattern. Either we get one,
* or we just get the META charater, and use the previous pattern.
* Then, if it's the search string, make a reversed pattern.
* *Then*, make the meta-pattern, if we are defined that way.
*/
if ((status = mlreplyt(tpat, tpat, NPAT, metac)) == TRUE) {
strcpy(apat, tpat);
status = newmlargt( &dynpat, tpat, NPAT) ;
if( status == TRUE) {
strncpy( apat, dynpat, NPAT - 1) ;
apat[ NPAT - 1] = 0 ;
free( dynpat) ;
if (srch) { /* If we are doing the search string. */
/* Reverse string copy, and remember
* the length for substitution purposes.
@@ -738,7 +749,6 @@ static int readpattern(char *prompt, char *apat, int srch)
void savematch(void)
{
char *ptr; /* pointer to last match string */
int j;
struct line *curline; /* line of last match */
int curoff; /* offset " " */
@@ -751,6 +761,8 @@ void savematch(void)
ptr = patmatch = malloc(matchlen + 1);
if (ptr != NULL) {
unsigned j ;
curoff = matchoff;
curline = matchline;
@@ -906,12 +918,12 @@ static int replaces(int kind, int f, int n)
if (kind) {
/* Get the query.
*/
pprompt:mlwrite(&tpat[0], &pat[0],
&rpat[0]);
qprompt:
pprompt:
mloutstr( tpat) ;
qprompt:
update(TRUE); /* show the proposed place to change */
c = tgetc(); /* and input */
mlwrite(""); /* and clear it */
mloutstr( "") ; /* and clear it */
/* And respond appropriately.
*/
@@ -979,17 +991,17 @@ static int replaces(int kind, int f, int n)
curwp->w_dotp = origline;
curwp->w_doto = origoff;
curwp->w_flag |= WFMOVE;
/* fallthrough */
case BELL: /* abort! and stay */
mlwrite("Aborted!");
return FALSE;
mloutstr( "Aborted!") ;
return FALSE ;
default: /* bitch and beep */
TTbeep();
/* fallthrough */
case '?': /* help me */
mlwrite
("(Y)es, (N)o, (!)Do rest, (U)ndo last, (^G)Abort, (.)Abort back, (?)Help: ");
mloutstr(
"(Y)es, (N)o, (!)Do rest, (U)ndo last, (^G)Abort, (.)Abort back, (?)Help: ") ;
goto qprompt;
} /* end of switch */
@@ -1017,7 +1029,7 @@ static int replaces(int kind, int f, int n)
/* And report the results.
*/
mlwrite("%d substitutions", numsub);
mloutfmt( "%d substitutions", numsub) ;
return TRUE;
}
@@ -1037,7 +1049,7 @@ int delins(int dlength, char *instr, int use_meta)
* and insert its replacement.
*/
if ((status = ldelete((long) dlength, FALSE)) != TRUE)
mlwrite("%%ERROR while deleting");
mloutstr( "%ERROR while deleting") ;
else
#if MAGIC
if ((rmagical && use_meta) &&
@@ -1087,12 +1099,7 @@ int expandp(char *srcstr, char *deststr, int maxlength)
*deststr++ = '^';
*deststr++ = c ^ 0x40;
maxlength -= 2;
} else if (c == '%') {
*deststr++ = '%';
*deststr++ = '%';
maxlength -= 2;
} else { /* any other character */
*deststr++ = c;
maxlength--;
}
@@ -1252,6 +1259,8 @@ static int mcstr(void)
pchr = *++patptr;
magical = TRUE;
}
/* fallthrough */
default:
litcase:mcptr->mc_type =
LITCHAR;
@@ -1324,7 +1333,7 @@ static int rmcstr(void)
rmcptr->mc_type = LITCHAR;
if ((rmcptr->rstr =
malloc(mj + 1)) == NULL) {
mlwrite("%%Out of memory");
mloutstr( "%Out of memory") ;
status = FALSE;
break;
}
@@ -1345,7 +1354,7 @@ static int rmcstr(void)
* current character.
*/
if ((rmcptr->rstr = malloc(mj + 2)) == NULL) {
mlwrite("%%Out of memory");
mloutstr( "%Out of memory") ;
status = FALSE;
break;
}
@@ -1374,11 +1383,12 @@ static int rmcstr(void)
if (rmagical && mj > 0) {
rmcptr->mc_type = LITCHAR;
if ((rmcptr->rstr = malloc(mj + 1)) == NULL) {
mlwrite("%%Out of memory.");
mloutstr( "%Out of memory") ;
status = FALSE;
} else {
strncpy(rmcptr->rstr, patptr - mj, mj);
rmcptr++;
}
strncpy(rmcptr->rstr, patptr - mj, mj);
rmcptr++;
}
rmcptr->mc_type = MCNIL;
@@ -1461,7 +1471,7 @@ static int mceq(int bc, struct magic *mt)
break;
default:
mlwrite("mceq: what is %d?", mt->mc_type);
mloutfmt( "mceq: what is %d?", mt->mc_type) ;
result = FALSE;
break;
@@ -1483,7 +1493,7 @@ static int cclmake(char **ppatptr, struct magic *mcptr)
int pchr, ochr;
if ((bmap = clearbits()) == NULL) {
mlwrite("%%Out of memory");
mloutstr( "%Out of memory") ;
return FALSE;
}
@@ -1503,7 +1513,7 @@ static int cclmake(char **ppatptr, struct magic *mcptr)
mcptr->mc_type = CCL;
if ((ochr = *patptr) == MC_ECCL) {
mlwrite("%%No characters in character class");
mloutstr( "%No characters in character class") ;
return FALSE;
} else {
if (ochr == MC_ESC)
@@ -1533,6 +1543,7 @@ static int cclmake(char **ppatptr, struct magic *mcptr)
*/
case MC_ESC:
pchr = *++patptr;
/* falltrhough */
default:
setbit(pchr, bmap);
break;
@@ -1544,7 +1555,7 @@ static int cclmake(char **ppatptr, struct magic *mcptr)
*ppatptr = patptr;
if (ochr == '\0') {
mlwrite("%%Character class not ended");
mloutstr( "%Character class not ended") ;
free(bmap);
return FALSE;
}
@@ -1557,10 +1568,11 @@ static int cclmake(char **ppatptr, struct magic *mcptr)
static int biteq(int bc, char *cclmap)
{
#if PKCODE
bc = bc & 0xFF;
#endif
bc &= 0xFF ;
#else
if (bc >= HICHAR)
return FALSE;
#endif
return (*(cclmap + (bc >> 3)) & BIT(bc & 7)) ? TRUE : FALSE;
}

View File

@@ -5,8 +5,6 @@
#include "line.h"
#define BELL 0x07 /* a bell character */
typedef char spat_t[ 128] ; /* search pattern type */
#define NPAT sizeof( spat_t) /* # of bytes, pattern */
@@ -41,6 +39,8 @@ int delins( int dlength, char *instr, int use_meta) ;
int expandp( char *srcstr, char *deststr, int maxlength) ;
int boundry( struct line *curline, int curoff, int dir) ;
void setprompt( char *tpat, unsigned tpat_size, char *prompt, char *apat) ;
#if MAGIC
void mcclear( void) ;
void rmcclear( void) ;

272
spawn.c
View File

@@ -22,7 +22,6 @@
#include "file.h"
#include "flook.h"
#include "input.h"
#include "log.h"
#include "terminal.h"
#include "window.h"
@@ -42,8 +41,6 @@ extern short iochan; /* In "termio.c" */
#if V7 | USG | BSD
#include <signal.h>
#ifdef SIGWINCH
extern int chg_width, chg_height;
extern void sizesignal(int);
#endif
#endif
@@ -51,6 +48,7 @@ extern void sizesignal(int);
#include <process.h>
#endif
/*
* Create a subjob with a copy of the command intrepreter in it. When the
* command interpreter exits, mark the screen as garbage so that you do a full
@@ -69,12 +67,12 @@ int spawncli(int f, int n)
#if VMS
movecursor(term.t_nrow, 0); /* In last line. */
mlputs("(Starting DCL)\r\n");
mlwrite("(Starting DCL)\r\n");
TTflush(); /* Ignore "ttcol". */
sgarbf = TRUE;
sys(NULL);
sleep(1);
mlputs("\r\n(Returning from DCL)\r\n");
mlwrite("\r\n(Returning from DCL)\r\n");
TTflush();
sleep(1);
return TRUE;
@@ -94,12 +92,12 @@ int spawncli(int f, int n)
TTclose(); /* stty to old settings */
TTkclose(); /* Close "keyboard" */
if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
system(cp);
ue_system( cp) ;
else
#if BSD
system("exec /bin/csh");
#else
system("exec /bin/sh");
ue_system( "exec /bin/sh") ;
#endif
sgarbf = TRUE;
usleep( 2000000L) ;
@@ -147,59 +145,32 @@ void rtfrmshell(void)
* character to be typed, then mark the screen as garbage so a full repaint is
* done. Bound to "C-X !".
*/
int spawn(int f, int n)
{
int s;
char line[NLINE];
int spawn( int f, int n) {
int s ;
char *line ;
/* don't allow this command if restricted */
if (restflag)
if( restflag)
return resterr();
#if VMS
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
movecursor(term.t_nrow, 0);
TTflush();
s = sys(line); /* Run the command. */
if (clexec == FALSE) {
mlputs("\r\n\n(End)"); /* Pause. */
TTflush();
tgetc();
}
sgarbf = TRUE;
return s;
#endif
#if MSDOS
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
movecursor(term.t_nrow, 0);
TTkclose();
shellprog(line);
TTkopen();
/* if we are interactive, pause here */
if (clexec == FALSE) {
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return TRUE;
#endif
#if V7 | USG | BSD
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
s = newmlarg( &line, "!", 0) ;
if( s != TRUE)
return s ;
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
system(line);
ue_system( line) ;
free( line) ;
fflush(stdout); /* to be sure P.K. */
TTopen();
if (clexec == FALSE) {
mlputs("(End)"); /* Pause. */
mlwrite( "(End)") ; /* Pause. */
TTflush();
while ((s = tgetc()) != '\r' && s != ' ');
mlputs("\r\n");
mlwrite( "\r\n") ;
}
TTkopen();
sgarbf = TRUE;
@@ -213,54 +184,28 @@ int spawn(int f, int n)
* done. Bound to "C-X $".
*/
int execprg(int f, int n)
{
int s;
char line[NLINE];
int execprg( int f, int n) {
int s ;
char *line ;
/* don't allow this command if restricted */
if (restflag)
return resterr();
#if VMS
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
TTflush();
s = sys(line); /* Run the command. */
mlputs("\r\n\n(End)"); /* Pause. */
TTflush();
tgetc();
sgarbf = TRUE;
return s;
#endif
#if MSDOS
if ((s = mlreply("$", line, NLINE)) != TRUE)
return s;
movecursor(term.t_nrow, 0);
TTkclose();
execprog(line);
TTkopen();
/* if we are interactive, pause here */
if (clexec == FALSE) {
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return TRUE;
#endif
if( restflag)
return resterr() ;
#if V7 | USG | BSD
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
s = newmlarg( &line, "$", 0) ;
if( s != TRUE)
return s ;
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
system(line);
ue_system( line) ;
free( line) ;
fflush(stdout); /* to be sure P.K. */
TTopen();
mlputs("(End)"); /* Pause. */
mlwrite( "(End)") ; /* Pause. */
TTflush();
while ((s = tgetc()) != '\r' && s != ' ');
sgarbf = TRUE;
@@ -272,48 +217,32 @@ int execprg(int f, int n)
* Pipe a one line command into a window
* Bound to ^X @
*/
int pipecmd(int f, int n)
{
int s; /* return status from CLI */
struct window *wp; /* pointer to new window */
struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */
static char bname[] = "command";
static char filnam[NSTRING] = "command";
#if MSDOS
char *tmp;
FILE *fp;
int len;
#endif
int pipecmd( int f, int n) {
int s ; /* return status from CLI */
struct window *wp ; /* pointer to new window */
struct buffer *bp ; /* pointer to buffer to zot */
char *mlarg ;
char *line ; /* command line send to shell */
static char bname[] = "command" ;
static char filnam[ NSTRING] = "command" ;
/* don't allow this command if restricted */
if (restflag)
return resterr();
#if MSDOS
if ((tmp = getenv("TMP")) == NULL
&& (tmp = getenv("TEMP")) == NULL)
strcpy(filnam, "command");
else {
strcpy(filnam, tmp);
len = strlen(tmp);
if (len <= 0 || filnam[len - 1] != '\\'
&& filnam[len - 1] != '/')
strcat(filnam, "\\");
strcat(filnam, "command");
}
#endif
#if VMS
mlwrite("Not available under VMS");
return FALSE;
#endif
if( restflag)
return resterr() ;
/* get the command to pipe in */
if ((s = mlreply("@", line, NLINE)) != TRUE)
return s;
s = newmlarg( &mlarg, "@", 0) ;
if( s != TRUE)
return s ;
line = malloc( strlen( mlarg) + strlen( filnam) + 2) ;
if( line == NULL) {
free( mlarg) ;
return FALSE ;
}
strcpy( line, mlarg) ;
free( mlarg) ;
/* get rid of the command output buffer if it exists */
if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
@@ -334,42 +263,29 @@ int pipecmd(int f, int n)
}
wp = wp->w_wndp;
}
if (zotbuf(bp) != TRUE)
return FALSE;
if( zotbuf( bp) != TRUE) {
free( line) ;
return FALSE ;
}
}
#if MSDOS
strcat(line, " >>");
strcat(line, filnam);
movecursor(term.t_nrow, 0);
TTkclose();
shellprog(line);
TTkopen();
sgarbf = TRUE;
if ((fp = fopen(filnam, "r")) == NULL) {
s = FALSE;
} else {
fclose(fp);
s = TRUE;
}
#endif
#if V7 | USG | BSD
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
strcat(line, ">");
strcat(line, filnam);
system(line);
strcat( line, ">") ;
strcat( line, filnam) ;
ue_system( line) ;
free( line) ;
TTopen();
TTkopen();
TTflush();
sgarbf = TRUE;
s = TRUE;
#endif
#else
if (s != TRUE)
return s;
#endif
/* split the current window to make room for the command output */
if (splitwind(FALSE, 1) == FALSE)
@@ -396,32 +312,37 @@ int pipecmd(int f, int n)
* filter a buffer through an external DOS program
* Bound to ^X #
*/
int filter_buffer(int f, int n)
{
int s; /* return status from CLI */
struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */
int filter_buffer( int f, int n) {
int s ; /* return status from CLI */
struct buffer *bp ; /* pointer to buffer to zot */
char *mlarg ;
char *line ; /* command line send to shell */
fname_t tmpnam ; /* place to store real file name */
static char bname1[] = "fltinp";
static char bname1[] = "fltinp" ;
static char filnam1[] = "fltinp";
static char filnam2[] = "fltout";
static char filnam1[] = "fltinp" ;
static char filnam2[] = "fltout" ;
/* don't allow this command if restricted */
if (restflag)
return resterr();
if( restflag)
return resterr() ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
#if VMS
mlwrite("Not available under VMS");
return FALSE;
#endif
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
/* get the filter name and its args */
if ((s = mlreply("#", line, NLINE)) != TRUE)
return s;
s = newmlarg( &mlarg, "#", 0) ;
if( s != TRUE)
return s ;
line = malloc( strlen( mlarg) + 16 + 1) ;
if( line == NULL) {
free( mlarg) ;
return FALSE ;
}
strcpy( line, mlarg) ;
free( mlarg) ;
/* setup the proper file names */
bp = curbp;
@@ -429,20 +350,12 @@ int filter_buffer(int f, int n)
strcpy(bp->b_fname, bname1); /* set it to our new one */
/* write it out, checking for errors */
if (writeout(filnam1) != TRUE) {
mlwrite("(Cannot write filter file)");
strcpy(bp->b_fname, tmpnam);
return FALSE;
if( writeout( filnam1) != TRUE) {
mlwrite( "(Cannot write filter file)") ;
strcpy( bp->b_fname, tmpnam) ;
free( line) ;
return FALSE ;
}
#if MSDOS
strcat(line, " <fltinp >fltout");
movecursor(term.t_nrow - 1, 0);
TTkclose();
shellprog(line);
TTkopen();
sgarbf = TRUE;
s = TRUE;
#endif
#if V7 | USG | BSD
TTputc('\n'); /* Already have '\r' */
@@ -450,7 +363,8 @@ int filter_buffer(int f, int n)
TTclose(); /* stty to old modes */
TTkclose();
strcat(line, " <fltinp >fltout");
system(line);
ue_system( line) ;
free( line) ;
TTopen();
TTkopen();
TTflush();
@@ -460,7 +374,7 @@ int filter_buffer(int f, int n)
/* on failure, escape gracefully */
if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
mlwrite("(Execution failed)");
mlwrite( "(Execution failed)") ;
strcpy(bp->b_fname, tmpnam);
unlink(filnam1);
unlink(filnam2);

39
tcap.c
View File

@@ -126,22 +126,21 @@ static void tcapopen(void)
char *t, *p;
char tcbuf[1024];
char *tv_stype;
char err_str[72];
int int_col, int_row;
#if PKCODE && USE_BROKEN_OPTIMIZATION
if (!term_init_ok) {
#endif
if ((tv_stype = getenv("TERM")) == NULL) {
puts("Environment variable TERM not defined!");
exit(1);
fputs( "Environment variable TERM not defined!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
if ((tgetent(tcbuf, tv_stype)) != 1) {
sprintf(err_str, "Unknown terminal type %s!",
tv_stype);
puts(err_str);
exit(1);
fputs( "Unknown terminal type ", stderr) ;
fputs( tv_stype, stderr) ;
fputs( "!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
/* Get screen size from system, or else from termcap. */
@@ -151,18 +150,24 @@ static void tcapopen(void)
if ((term.t_nrow <= 0)
&& (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
puts("termcap entry incomplete (lines)");
exit(1);
fputs( "termcap entry incomplete (lines)\n", stderr) ;
exit( EXIT_FAILURE) ;
}
if ((term.t_ncol <= 0)
&& (term.t_ncol = (short) tgetnum("co")) == -1) {
puts("Termcap entry incomplete (columns)");
exit(1);
fputs( "Termcap entry incomplete (columns)\n", stderr) ;
exit( EXIT_FAILURE) ;
}
#ifdef SIGWINCH
term.t_mrow = MAXROW;
term.t_mcol = MAXCOL;
/* At initialization we use maximum size even if current OS window is smaller */
term.t_mrow = MAXROW ;
term.t_mcol = MAXCOL ;
if( term.t_nrow >= term.t_mrow)
term.t_nrow = term.t_mrow - 1 ;
if( term.t_ncol > term.t_mcol)
term.t_ncol = term.t_mcol ;
#else
term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;
@@ -193,8 +198,8 @@ static void tcapopen(void)
#endif
if (CL == NULL || CM == NULL || UP == NULL) {
puts("Incomplete termcap entry\n");
exit(1);
fputs( "Incomplete termcap entry\n", stderr) ;
exit( EXIT_FAILURE) ;
}
if (CE == NULL) /* will we be able to use clear to EOL? */
@@ -218,8 +223,8 @@ static void tcapopen(void)
#endif
if (p >= &tcapbuf[TCAPSLEN]) {
puts("Terminal description too big!\n");
exit(1);
fputs( "Terminal description too big!\n", stderr) ;
exit( EXIT_FAILURE) ;
}
#if PKCODE && USE_BROKEN_OPTIMIZATION
term_init_ok = 1;

View File

@@ -1,3 +1,6 @@
/* termio.c -- implements termio.h */
#if !defined( POSIX) && !defined( MINGW32)
#include "termio.h"
/* TERMIO.C
@@ -9,8 +12,6 @@
* modified by Petri Kutvonen
*/
#if !defined( POSIX) && !defined( MINGW32)
#include <stdio.h>
#include <stdlib.h>
@@ -19,7 +20,6 @@
#include "utf8.h"
/* rfi */
#include <unistd.h>
#include <sys/ioctl.h>
@@ -57,12 +57,12 @@ int nxtchar = -1; /* character held from type ahead */
#include <signal.h>
#include <termio.h>
#include <fcntl.h>
int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */
struct termio otermio; /* original terminal characteristics */
struct termio ntermio; /* charactoristics to use inside */
static int kbdflgs ; /* saved keyboard fd flags */
static int kbdpoll ; /* in O_NDELAY mode */
static int kbdqp ; /* there is a char in kbdq */
static char kbdq ; /* char we've already read */
static struct termio otermio ; /* original terminal characteristics */
static struct termio ntermio ; /* characteristics to use inside */
#if XONXOFF
#define XXMASK 0016000
#endif
@@ -463,4 +463,8 @@ int typahead( void)
}
#endif
#else
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */
/* end of termio.c */

View File

@@ -10,6 +10,7 @@ insert-string %mypath
newline
insert-string &cat "Length of $PATH: " &len $PATH
newline
insert-string &cat "Length of %mypath: " &cat &len %mypath ~n
; Insert string with escaped characters
insert-string "hello, world~n"
newline
@@ -27,10 +28,10 @@ insert-string 123456789012345678901234567890123456789012345678901234567890123456
next-line
insert-string _________1_________2_________3_________4_________5_________6_________7_________8_________9_________0_________1_________2_________3
next-line
; Create and insert string variable until size exceed string limit [will be truncated to NSTRING - 1 (127)
; Create and insert string variable until size exceed 1024 characters or variable get truncated
set %nam 123
set %expect &len %nam
!while &equ &len %nam %expect
!while &and &les %expect 1024 &equ &len %nam %expect
insert-string %nam
newline
set %nam &cat %nam %nam
@@ -43,6 +44,7 @@ newline
insert-string &cat "Expected: " %expect
newline
; Use the variable as filename [will be truncated to NFILEN - 1 (79)]
set %nam &mid %nam 1 255
write-file %nam
insert-string &cat "Filename: " $cfname
newline
@@ -67,3 +69,4 @@ set-mark
end-of-file
copy-region
insert-string $kill
redraw-display

133
utf8.c
View File

@@ -1,5 +1,9 @@
/* utf8.c -- implements utf8.h, converts between unicode and UTF-8 */
#include "utf8.h"
#include <assert.h>
/*
* utf8_to_unicode()
*
@@ -15,55 +19,60 @@
*/
unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res)
{
unsigned value;
unsigned char c = line[index];
unsigned bytes, mask, i;
unicode_t value ;
unsigned c = line[ index] & 0xFFU ;
unsigned bytes, mask, i;
*res = c;
line += index;
len -= index;
*res = c;
/*
* 0xxxxxxx is valid utf8
* 10xxxxxx is invalid UTF-8, we assume it is Latin1
*/
if (c < 0xc0)
return 1;
/*
* 0xxxxxxx is valid one byte utf8
* 10xxxxxx is invalid UTF-8 start byte, we assume it is Latin1
* 1100000x is start of overlong encoding sequence
* Sequence longer than 4 bytes are invalid
* Last valid code is 0x10FFFF, encoding start with 0xF4
*/
if( c <= 0xC1 || c > 0xF4)
return 1;
/* Ok, it's 11xxxxxx, do a stupid decode */
mask = 0x20;
bytes = 2;
while (c & mask) {
bytes++;
mask >>= 1;
}
/* Ok, it's 11xxxxxx, do a stupid decode */
mask = 0x20;
bytes = 2;
while( (c & mask) != 0) {
bytes++;
mask >>= 1;
}
/* Invalid? Do it as a single byte Latin1 */
if (bytes > 6)
return 1;
if (bytes > len)
return 1;
/* bytes is in range [2..4] as c was in range [C2..F4] */
len -= index;
if (bytes > len)
return 1;
value = c & (mask-1);
value = c & (mask-1);
/* Ok, do the bytes */
for (i = 1; i < bytes; i++) {
c = line[i];
if ((c & 0xc0) != 0x80)
return 1;
value = (value << 6) | (c & 0x3f);
}
*res = value;
return bytes;
/* Ok, do the bytes */
line += index;
for (i = 1; i < bytes; i++) {
c = line[i] & 0xFFU ;
if ((c & 0xc0) != 0x80)
return 1;
value = (value << 6) | (c & 0x3f);
}
if( value > 0x10FFFF) /* Avoid 110000 - 13FFFF */
return 1 ;
*res = value;
return bytes;
}
static void reverse_string(char *begin, char *end)
{
do {
char a = *begin, b = *end;
*end = a; *begin = b;
begin++; end--;
} while (begin < end);
do {
char a = *begin, b = *end;
*end = a; *begin = b;
begin++; end--;
} while (begin < end);
}
/*
@@ -77,22 +86,34 @@ static void reverse_string(char *begin, char *end)
* possible sequence, while utf8_to_unicode() accepts both Latin1 and
* overlong utf-8 sequences.
*/
unsigned unicode_to_utf8(unsigned int c, char *utf8)
{
int bytes = 1;
unsigned unicode_to_utf8( unicode_t c, char *utf8) {
unsigned bytes = 1 ;
*utf8 = c;
if (c > 0x7f) {
int prefix = 0x40;
char *p = utf8;
do {
*p++ = 0x80 + (c & 0x3f);
bytes++;
prefix >>= 1;
c >>= 6;
} while (c > prefix);
*p = c - 2*prefix;
reverse_string(utf8, p);
}
return bytes;
assert( c <= 0x10FFFF) ;
#ifdef NDEBUG
if( c > 0x10FFFF) /* Let's assume this is due to sign extension */
c &= 0xFF ;
#endif
if( c <= 0x7f)
*utf8 = (char) c ;
else {
unsigned prefix = 0x40 ;
char *p = utf8 ;
do {
*p++ = (char) (0x80 + (c & 0x3f)) ;
bytes++ ;
prefix >>= 1 ;
c >>= 6 ;
} while( c >= prefix) ;
*p = (char) (c - 2 * prefix) ;
reverse_string( utf8, p) ;
}
return bytes ;
}
/* end of utf8.c */

11
utf8.h
View File

@@ -1,15 +1,10 @@
#ifndef UTF8_H
#define UTF8_H
typedef unsigned int unicode_t;
typedef unsigned int unicode_t ;
unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
unicode_t *res) ;
unsigned unicode_to_utf8( unsigned int c, char *utf8) ;
static inline int is_beginning_utf8( unsigned char c)
{
return (c & 0xc0) != 0x80;
}
unicode_t *res) ;
unsigned unicode_to_utf8( unicode_t c, char *utf8) ;
#endif

View File

@@ -9,8 +9,9 @@
# define PROGRAM_NAME "em"
#endif
#define PROGRAM_NAME_LONG "uEMACS"
# define PROGRAM_NAME_PFX "\xC2"
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
#define VERSION "4.1.1"
# define VERSION "4.2.2"
#endif /* VERSION_H_ */

View File

@@ -599,10 +599,10 @@ int newsize(int f, int n)
/* if the command defaults, assume the largest */
if (f == FALSE)
n = term.t_mrow + 1;
n = term.t_mrow ;
/* make sure it's in range */
if (n < 3 || n > term.t_mrow + 1) {
if (n < 3 || n > term.t_mrow) {
mlwrite("%%Screen size out of range");
return FALSE;
}

View File

@@ -21,8 +21,8 @@ struct window {
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
int w_toprow ; /* Origin 0 top row of window */
int w_ntrows ; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR

12
word.c
View File

@@ -16,7 +16,7 @@
#include "buffer.h"
#include "estruct.h"
#include "line.h"
#include "log.h"
#include "mlout.h"
#include "random.h"
#include "region.h"
#include "window.h"
@@ -428,7 +428,7 @@ int fillpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
logwrite("No fill column set");
mloutstr( "No fill column set") ;
return FALSE;
}
#if PKCODE
@@ -527,14 +527,14 @@ int justpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
logwrite("No fill column set");
mloutstr( "No fill column set") ;
return FALSE;
}
justflag = TRUE;
leftmarg = curwp->w_doto;
if (leftmarg + 10 > fillcol) {
leftmarg = 0;
logwrite("Column too narrow");
mloutstr( "Column too narrow") ;
return FALSE;
}
@@ -719,8 +719,8 @@ int wordcount(int f, int n)
else
avgch = 0;
logwrite("Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch);
mloutfmt( "Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch) ;
return TRUE;
}
#endif

View File

@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef MINGW32
@@ -20,11 +21,14 @@ static void die( const char *err) {
/* Function copyright: git */
void xmkstemp( char *template) {
int fd ;
mode_t o_mask ;
o_mask = umask( 0177) ;
fd = mkstemp( template) ;
if( fd < 0)
die( "Unable to create temporary file") ;
umask( o_mask) ;
close( fd) ;
}

2
wrapper.h Executable file → Normal file
View File

@@ -3,7 +3,7 @@
#include <stdlib.h>
void xmkstemp( char *template) ;
void xmkstemp( char *fname_template) ;
void *xmalloc( size_t size) ;

View File

@@ -1,4 +1,4 @@
/* wscreen.c -- windows screen console */
/* wscreen.c -- windows screen console for MINGW32 */
#include "wscreen.h"
#ifdef MINGW32
@@ -112,6 +112,6 @@ void wtitle( const char *title) {
SetConsoleTitle( title) ;
}
#endif
#endif /* MINGW32 */
/* end of wscreen.c */