Changes by Franco Bez <franco.bez@augsburg.baynet.de>:

* gtkedit/edit.c: Workarround for the CR/LF Translation problem.
        This is vital, because otherwise CoolEdit corrupts files -
        they keep growing each time you save the file.

        * pc/key_nt.c: fixed the problem with the AltGr Key and the
        Gray Keys. Still not optimal, but usable.
        Especially usefull for international keyboard

        * pc/util_nt.c: Provide a mc_doublepopen and mc_doublepclose
        function. If one has an egrep.exe installed it's now possible
        to search for files containing a search pattern.
This commit is contained in:
Pavel Roskin 1998-10-14 14:09:47 +00:00
parent 0a024abfb5
commit 853c179690
4 changed files with 190 additions and 17 deletions

View File

@ -24,6 +24,7 @@
#if defined(OS2_NT)
# include <io.h>
# include <fcntl.h>
# define CR_LF_TRANSLATION
#endif
#include "edit.h"
@ -104,6 +105,14 @@ char *edit_get_buffer_as_text (WEdit * e)
/* cursor set to start of file */
int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *text)
{
#if defined CR_LF_TRANSLATION
/* Variables needed for safe handling of Translation from Microsoft CR/LF EOL to
Unix Style LF EOL - Franco */
long bytes_wanted,bytes_read,bytes_missing;
char *p;
#endif
long buf;
int j, file = 0, buf2;
@ -124,8 +133,35 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
edit->buffers2[buf2] = CMalloc (EDIT_BUF_SIZE);
if (filename)
/*
_read returns the number of bytes read,
which may be less than count if there are fewer than count bytes left in the file
or if the file was opened in text mode,
in which case each carriage returnlinefeed (CR-LF) pair is replaced
with a single linefeed character. Only the single linefeed character is counted
in the return value. The replacement does not affect the file pointer.
_eof returns 1 if the current position is end of file, or 0 if it is not.
A return value of -1 indicates an error; in this case, errno is set to EBADF,
which indicates an invalid file handle.
*/
if (filename){
#if defined CR_LF_TRANSLATION
bytes_wanted=edit->curs2 & M_EDIT_BUF_SIZE;
p = (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE);
bytes_read = read (file, p , edit->curs2 & M_EDIT_BUF_SIZE);
bytes_missing = bytes_wanted - bytes_read ;
while(bytes_missing ){
p += bytes_read;
bytes_read = read(file,p,bytes_missing);
if(bytes_read <= 0) break;
bytes_missing -= bytes_read ;
}
#else
read (file, (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE);
#endif
}
else {
memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), text, edit->curs2 & M_EDIT_BUF_SIZE);
text += edit->curs2 & M_EDIT_BUF_SIZE;
@ -133,8 +169,22 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
for (buf = buf2 - 1; buf >= 0; buf--) {
edit->buffers2[buf] = CMalloc (EDIT_BUF_SIZE);
if (filename)
if (filename){
#if defined CR_LF_TRANSLATION
bytes_wanted = EDIT_BUF_SIZE;
p = (char *) edit->buffers2[buf];
bytes_read = read (file, p, EDIT_BUF_SIZE);
bytes_missing = bytes_wanted - bytes_read ;
while(bytes_missing ){
p += bytes_read;
bytes_read = read(file,p,bytes_missing);
if(bytes_read <= 0) break;
bytes_missing -= bytes_read ;
}
#else
read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
#endif
}
else {
memcpy (edit->buffers2[buf], text, EDIT_BUF_SIZE);
text += EDIT_BUF_SIZE;
@ -154,15 +204,21 @@ int edit_load_file (WEdit * edit, const char *filename, const char *text, unsign
struct stat s;
int file;
/* VARS for Lastbyte calculation in TEXT mode FRANCO */
#if defined CR_LF_TRANSLATION
char tmp_buf[1024];
long real_size,bytes_read;
#endif
if (text) {
edit->last_byte = text_size;
filename = NULL;
} else {
#if defined(MIDNIGHT) || defined(GTK)
if ((file = open ((char *) filename, O_RDONLY)) < 0)
if ((file = open ((char *) filename, O_RDONLY | MY_O_TEXT )) < 0)
{
close(creat((char *) filename, 0666));
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
if ((file = open ((char *) filename, O_RDONLY | MY_O_TEXT )) < 0) {
edit_error_dialog (_(" Error "), get_sys_error (catstrs (" Fail trying to open the file, ", filename, ", for reading ", 0)));
return 1;
}
@ -194,6 +250,20 @@ int edit_load_file (WEdit * edit, const char *filename, const char *text, unsign
filename, _(" \n Increase edit.h:MAXBUF and recompile the editor. "), 0));
return 1;
}
/* Lastbyte calculation in TEXT mode FRANCO */
#if defined CR_LF_TRANSLATION
if(file && (!text)){
real_size=0;
tmp_buf[1024]=0;
while((bytes_read = read(file,tmp_buf,1024)) > 0){
real_size += bytes_read;
}
s.st_size = real_size;
}
#endif
close (file);
edit->last_byte = s.st_size;
edit->stat = s;

View File

@ -1,3 +1,17 @@
Wed Oct 14 14:51:23 1998 Franco Bez <franco.bez@augsburg.baynet.de>
* gtkedit/edit.c: Workarround for the CR/LF Translation problem.
This is vital, because otherwise CoolEdit corrupts files -
they keep growing each time you save the file.
* pc/key_nt.c: fixed the problem with the AltGr Key and the
Gray Keys. Still not optimal, but usable.
Especially usefull for international keyboard
* pc/util_nt.c: Provide a mc_doublepopen and mc_doublepclose
function. If one has an egrep.exe installed it's now possible
to search for files containing a search pattern.
Tue May 12 17:16:43 1998 Pavel Roskin <pavel_roskin@geocities.com>
* Makefile.RSX, mc.rc: Resources support for RSX

View File

@ -85,6 +85,7 @@ struct {
{ ALT('*'), VK_MULTIPLY },
{ ALT('+'), VK_ADD },
{ ALT('-'), VK_SUBTRACT },
{ ALT('\t'), VK_PAUSE }, /* Added to make Complete work press Pause */
{ ESC_CHAR, VK_ESCAPE },
@ -101,6 +102,8 @@ void init_key (void)
int ctrl_pressed ()
{
if(dwSaved_ControlState & RIGHT_ALT_PRESSED) return 0;
/* The line above fixes the BUG with the AltGr Keys*/
return dwSaved_ControlState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED);
}
@ -111,7 +114,7 @@ int shift_pressed ()
int alt_pressed ()
{
return dwSaved_ControlState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED);
return dwSaved_ControlState & (/* RIGHT_ALT_PRESSED |*/ LEFT_ALT_PRESSED );
}
static int VKtoCurses (int a_vkc)
@ -128,12 +131,20 @@ static int VKtoCurses (int a_vkc)
static int translate_key_code(int asc, int scan)
{
int c;
switch(scan){
case 106: /* KP_MULT*/
return ALT('*');
case 107: /* KP_PLUS*/
return ALT('+');
case 109: /* KP_MINUS*/
return ALT('-');
}
c = VKtoCurses (scan);
if (!asc && !c)
return 0;
if (asc && c)
return c;
if (!asc)
if (!asc || asc=='\t' )
{
if (shift_pressed() && (c >= KEY_F(1)) && (c <= KEY_F(10)))
c += 10;
@ -141,8 +152,10 @@ static int translate_key_code(int asc, int scan)
c += 10;
if (alt_pressed() && (c == KEY_F(7)))
c = ALT('?');
if (ctrl_pressed() && c == '\t')
c = ALT('\t');
if (asc == '\t'){
if(ctrl_pressed())c = ALT('\t');
else c=asc;
}
return c;
}
if (ctrl_pressed())
@ -176,11 +189,11 @@ int get_key_code (int no_delay)
break;
vkcode = ir.Event.KeyEvent.wVirtualKeyCode;
#ifndef __MINGW32__
//#ifndef __MINGW32__
ch = ir.Event.KeyEvent.uChar.AsciiChar;
#else
ch = ir.Event.KeyEvent.AsciiChar;
#endif
//#else
// ch = ir.Event.KeyEvent.AsciiChar;
//#endif
dwSaved_ControlState = ir.Event.KeyEvent.dwControlKeyState;
j = translate_key_code (ch, vkcode);
if (j)

View File

@ -118,10 +118,10 @@ void check_error_pipe (void)
{
int rvalue;
rvalue = read (error_pipe[0], error + len, 1);
len ++;
rvalue = -1; // read (error_pipe[0], error + len, 1);
if (rvalue <= 0)
break;
len ++;
}
error[len] = 0;
close (error_pipe[0]);
@ -579,17 +579,93 @@ void init_uid_gid_cache (void)
return;
}
/* INHANDLE is a result of some mc_open call to any vfs, this function
returns a normal handle (to be used with read) of a pipe for reading
of the output of COMMAND with arguments ... (must include argv[0] as
well) which gets as its input at most INLEN bytes from the INHANDLE
using mc_read. You have to call mc_doublepclose to close the returned
handle afterwards. If INLEN is -1, we read as much as we can :) */
int mc_doublepopen (int inhandle, int inlen, pid_t *the_pid, char *command, ...)
{
return 0;
int pipe0 [2], pipe1 [2], std_sav [2];
#define MAXARGS 16
int argno;
char *args[MAXARGS];
char buffer [8192];
int i;
va_list ap;
pid_t pid;
// Create the pipes
if(_pipe(pipe0, 8192, O_BINARY | O_NOINHERIT) == -1)
exit (1);
if(_pipe(pipe1, 8192, O_BINARY | O_NOINHERIT) == -1)
exit (1);
// Duplicate stdin/stdout handles (next line will close original)
std_sav[0] = _dup(_fileno(stdin));
std_sav[1] = _dup(_fileno(stdout));
// Duplicate read end of pipe0 to stdin handle
if(_dup2(pipe0[0], _fileno(stdin)) != 0)
exit (1);
// Duplicate write end of pipe1 to stdout handle
if(_dup2(pipe1[1], _fileno(stdout)) != 0)
exit (1);
// Close original read end of pipe0
close(pipe0[0]);
// Close original write end of pipe1
close(pipe1[1]);
va_start (ap, command);
argno = 0;
while ((args[argno++] = va_arg(ap, char *)) != NULL)
if (argno == (MAXARGS - 1)) {
args[argno] = NULL;
break;
}
va_end (ap);
// Spawn process
pid = spawnvp(P_NOWAIT,command, args);// argv[1], (const char* const*)&argv[1]);
if(!pid)
exit (1);
// Duplicate copy of original stdin back into stdin
if(_dup2(std_sav[0], _fileno(stdin)) != 0)
exit (1);
// Duplicate copy of original stdout back into stdout
if(_dup2(std_sav[1], _fileno(stdout)) != 0)
exit (1);
// Close duplicate copy of original stdout and stdin
close(std_sav[0]);
close(std_sav[1]);
while ((i = _read (inhandle, buffer,
(inlen == -1 || inlen > 8192)
? 8192 : inlen)) > 0) {
write (pipe0 [1], buffer, i);
if (inlen != -1) {
inlen -= i;
if (!inlen)
break;
}
}
close (pipe0 [1]);
*the_pid = pid;
return pipe1 [0];
}
int mc_doublepclose (int pipe, pid_t pid)
{
/* win32Trace(("mc_doublepclose called")); */
return 0;
int status = 0;
close (pipe);
_cwait ( &status, pid, 0);
return status;
}
/*hacks to get it compile, remove these after vfs works */
/*hacks to get it compile, remove these after vfs works */
#ifndef USE_VFS
char *vfs_get_current_dir (void)