1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
|
/***********************************************************************/
/* EDIT.C - The body of the program. */
/***********************************************************************/
/*
* THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
* Copyright (C) 1991-1999 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave,
* Cambridge, MA 02139 USA.
*
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling, M.Hessling@qut.edu.au http://www.lightlink.com/hessling/
* PO Box 203, Bellara, QLD 4507, AUSTRALIA
* Author of THE, a Free XEDIT/KEDIT editor and, Rexx/SQL
* Maintainer of PDCurses: Public Domain Curses and, Regina Rexx interpreter
* Use Rexx ? join the Rexx Language Association: http://www.rexxla.org
*/
static char RCSid[] = "$Id: edit.c,v 1.7 2001/04/21 05:30:11 mark Exp $";
#include <the.h>
#include <proto.h>
bool prefix_changed=FALSE;
#ifdef HAVE_PROTO
void editor(void)
#else
void editor()
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short y=0,x=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("edit.c: editor");
/*
* Reset any command line positioning parameters so only those files
* edited from the command line take on the line/col, command line
* position.
*/
startup_line = startup_column = 0;
if (display_screens > 1)
display_screen(other_screen);
getyx(CURRENT_WINDOW,y,x);
wmove(CURRENT_WINDOW,y,x);
wrefresh(CURRENT_WINDOW);
if (error_on_screen)
{
if (error_window != NULL)
{
touchwin(error_window);
wrefresh(error_window);
wmove(CURRENT_WINDOW,y,x);
wrefresh(CURRENT_WINDOW);
}
}
#ifdef MSWIN
draw_cursor(TRUE);
#endif
while (1)
{
if (process_key(-1,FALSE) != RC_OK)
break;
}
TRACE_RETURN();
return;
}
#ifdef THE_SINGLE_INSTANCE_ENABLED
/***********************************************************************/
#ifdef HAVE_PROTO
int process_fifo_input( int key )
#else
int process_fifo_input( key )
int key;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
int length,s;
fd_set readfds;
CHARTYPE *str;
int curses_fd;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("edit.c: process_fifo_input");
if ( key == -1
&& single_instance_server )
{
/*
*
* Add curses input and the input fifo
*/
#ifdef XCURSES
curses_fd = PDC_get_input_fd();
#else
curses_fd = stdin; /* doesn't work */
#endif
FD_ZERO ( &readfds );
FD_SET ( curses_fd, &readfds );
FD_SET ( fifo_fd, &readfds );
if ( ( s = select ( FD_SETSIZE, &readfds, NULL, NULL, NULL ) ) < 0 )
{
TRACE_RETURN();
return key;
}
if ( s == 0 ) /* no requests pending - should never happen!*/
{
TRACE_RETURN();
return key;
}
if ( FD_ISSET ( fifo_fd, &readfds ) )
{
if ( read( fifo_fd, (char *)&length, sizeof(int) ) < 0 )
{
TRACE_RETURN();
return key;
}
/*
* Sleep for 100 milliseconds to ensure the remainder of the
* data is in the fifo. Yuck!
*/
napms( 100 );
str = (*the_malloc)( ( length+1) * sizeof( CHARTYPE ) );
if ( read( fifo_fd, str, length*sizeof(CHARTYPE) ) < 0 )
{
TRACE_RETURN();
return key;
}
str[length] = '\0';
(void)command_line( str, TRUE );
(*the_free)( str );
key = 0;
}
}
TRACE_RETURN();
return key;
}
#endif
/***********************************************************************/
#ifdef HAVE_PROTO
int process_key(int key, bool mouse_details_present)
#else
int process_key(key, mouse_details_present)
int key;
bool mouse_details_present;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
unsigned short x=0,y=0;
short rc=RC_OK;
CHARTYPE string_key[2];
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("edit.c: process_key");
#if defined(USE_EXTCURSES)
getyx(CURRENT_WINDOW,y,x);
wmove(CURRENT_WINDOW,y,x);
wrefresh(CURRENT_WINDOW);
#endif
string_key[1] = '\0';
#ifdef CAN_RESIZE
if (is_termresized())
{
(void)THE_Resize(0,0);
(void)THERefresh((CHARTYPE *)"");
}
#endif
#ifdef THE_SINGLE_INSTANCE_ENABLED
key = process_fifo_input( key );
#endif
if (key == (-1))
{
key = my_getch(stdscr);
}
#if defined(PDCURSES_MOUSE_ENABLED) || defined(NCURSES_MOUSE_VERSION)
if (key == KEY_MOUSE)
{
int b,ba,bm;
if (get_mouse_info(&b,&ba,&bm) != RC_OK)
{
TRACE_RETURN();
return(RC_OK);
}
}
else
{
if (!mouse_details_present)
reset_saved_mouse_pos();
}
#endif
#ifdef CAN_RESIZE
if (is_termresized())
{
TRACE_RETURN();
return(RC_OK);
}
#endif
initial = FALSE; /* set first time a key is requested */
if (error_on_screen)
clear_msgline(key);
if (current_key == -1)
current_key = 0;
else
current_key = (current_key == 7) ? 0 : current_key++;
lastkeys[current_key] = key;
rc = function_key(key,OPTION_NORMAL,mouse_details_present);
if (number_of_files == 0)
{
TRACE_RETURN();
return(RC_INVALID_ENVIRON);
}
if (rc >= RAW_KEY)
{
if (rc > RAW_KEY)
key = rc - (RAW_KEY*2);
if (key < 256 && key >= 0)
{
string_key[0] = (CHARTYPE)key;
/*
* If operating in CUA mode, and a CUA block exists, check
* if the block should be reset or deleted before executing
* the command.
*/
if ( INTERFACEx == INTERFACE_CUA
&& CURRENT_VIEW->mark_type == M_CUA )
{
ResetOrDeleteCUABlock( CUA_DELETE_BLOCK );
}
(void)Text(string_key);
}
}
show_statarea();
if (display_screens > 1
&& SCREEN_FILE(0) == SCREEN_FILE(1))
{
build_screen(other_screen);
display_screen(other_screen);
/* refresh_screen(other_screen);*/
show_heading(other_screen);
}
refresh_screen(current_screen);
if (error_on_screen)
{
getyx(CURRENT_WINDOW,y,x);
if (error_window != NULL)
{
touchwin(error_window);
wnoutrefresh(error_window);
}
wmove(CURRENT_WINDOW,y,x);
wnoutrefresh(CURRENT_WINDOW);
}
#ifdef HAVE_BROKEN_SYSVR4_CURSES
getyx(CURRENT_WINDOW,y,x);
wmove(CURRENT_WINDOW,y,x);
wrefresh(CURRENT_WINDOW);
#else
doupdate();
#endif
TRACE_RETURN();
return(RC_OK);
}
/***********************************************************************/
#ifdef HAVE_PROTO
short EditFile(CHARTYPE *fn, bool external_command_line)
#else
short EditFile(fn, external_command_line)
CHARTYPE *fn;
bool external_command_line;
#endif
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
short rc=RC_OK,y=0,x=0;
VIEW_DETAILS *save_current_view=NULL;
VIEW_DETAILS *previous_current_view=NULL;
CHARTYPE save_prefix=0;
short save_gap=0;
ROWTYPE save_cmd_line=0;
bool save_id_line=0;
/*--------------------------- processing ------------------------------*/
TRACE_FUNCTION("edit.c: EditFile");
/*
* With no arguments, edit the next file in the ring...
*/
if (strcmp((DEFCHAR *)fn,"") == 0)
{
rc = advance_view(NULL,DIRECTION_FORWARD);
TRACE_RETURN();
return(rc);
}
/*
* With "-" as argument, edit the previous file in the ring...
*/
if (strcmp((DEFCHAR *)fn,"-") == 0)
{
rc = advance_view(NULL,DIRECTION_BACKWARD);
TRACE_RETURN();
return(rc);
}
/*
* If there are still file(s) in the ring, clear the command line and
* save any changes to the focus line.
*/
if (number_of_files > 0)
{
post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
memset(cmd_rec,' ',max_line_length);
cmd_rec_len = 0;
}
previous_current_view = CURRENT_VIEW;
/*
* Save the position of the cursor for the current view before getting
* the contents of the new file...
*/
if (curses_started
&& number_of_files > 0)
{
if (CURRENT_WINDOW_COMMAND != NULL)
{
wmove(CURRENT_WINDOW_COMMAND,0,0);
my_wclrtoeol(CURRENT_WINDOW_COMMAND);
}
getyx(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->y[WINDOW_FILEAREA],CURRENT_VIEW->x[WINDOW_FILEAREA]);
if (CURRENT_WINDOW_PREFIX != NULL)
getyx(CURRENT_WINDOW_PREFIX,CURRENT_VIEW->y[WINDOW_PREFIX],CURRENT_VIEW->x[WINDOW_PREFIX]);
}
if (number_of_files > 0)
{
save_prefix=CURRENT_VIEW->prefix;
save_gap=CURRENT_VIEW->prefix_gap;
save_cmd_line=CURRENT_VIEW->cmd_line;
save_id_line=CURRENT_VIEW->id_line;
}
/*
* Read the contents of the new file into memory...
*/
if ((rc = get_file(strrmdup(strtrans(fn,OSLASH,ISLASH),ISLASH,TRUE))) != RC_OK)
{
TRACE_RETURN();
return(rc);
}
/*
* If more than one screen is displayed, sort out which view is to be
* displayed...
*/
if (display_screens > 1)
{
save_current_view = CURRENT_VIEW;
CURRENT_SCREEN.screen_view = CURRENT_VIEW = previous_current_view;
advance_view(save_current_view,DIRECTION_FORWARD);
}
else
{
if (number_of_files > 0)
{
/*
* If the position of the prefix or command line for the new view is
* different from the previous view, rebuild the windows...
*/
if ((save_prefix&PREFIX_LOCATION_MASK) != (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK)
|| save_gap != CURRENT_VIEW->prefix_gap
|| save_cmd_line != CURRENT_VIEW->cmd_line
|| save_id_line != CURRENT_VIEW->id_line)
{
set_screen_defaults();
if (curses_started)
{
if (set_up_windows(current_screen) != RC_OK)
{
TRACE_RETURN();
return(RC_OK);
}
}
}
}
/*
* Re-calculate CURLINE for the new view in case the CURLINE is no
* longer in the display area.
*/
prepare_view(current_screen);
}
pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
build_screen(current_screen);
/*
* Position the cursor in the main window depending on the type of file
*/
if (curses_started)
{
if (CURRENT_VIEW->in_ring)
{
wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->y[WINDOW_FILEAREA],CURRENT_VIEW->x[WINDOW_FILEAREA]);
if (CURRENT_WINDOW_PREFIX != NULL)
wmove(CURRENT_WINDOW_PREFIX,CURRENT_VIEW->y[WINDOW_PREFIX],CURRENT_VIEW->x[WINDOW_PREFIX]);
getyx(CURRENT_WINDOW,y,x);
wmove(CURRENT_WINDOW,y,x);
}
else
{
if (CURRENT_FILE->pseudo_file == PSEUDO_DIR)
wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->current_row,file_start-1);
else
wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->current_row,0);
}
}
/*
* Execute any profile file...
*/
if ((REPROFILEx && CURRENT_VIEW->in_ring == FALSE)
|| (in_profile && external_command_line))
{
profile_file_executions++;
in_reprofile = TRUE;
if (execute_profile)
{
if (local_prf != (CHARTYPE *)NULL)
rc = get_profile(local_prf,prf_arg);
}
in_reprofile = FALSE;
}
/*
* If the result of processing the profile file results in no files
* in the ring, we need to get out NOW.
*/
if (number_of_files == 0)
{
TRACE_RETURN();
return(rc);
}
/* pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);*/
build_screen(current_screen);
/*
* If startup values were specified on the command, line, move cursor
* there...
*/
if (startup_line != 0
|| startup_column != 0)
{
THEcursor_goto( startup_line, startup_column );
}
/*
* If curses hasn't started, don't try to use curses functions...
*/
if (curses_started)
{
display_screen(current_screen);
if (CURRENT_WINDOW_COMMAND != NULL)
wmove(CURRENT_WINDOW_COMMAND,0,0);
if (CURRENT_WINDOW_PREFIX != NULL)
touchwin(CURRENT_WINDOW_PREFIX);
if (CURRENT_WINDOW_GAP != NULL)
touchwin(CURRENT_WINDOW_GAP);
if (CURRENT_WINDOW_COMMAND != NULL)
touchwin(CURRENT_WINDOW_COMMAND);
if (CURRENT_WINDOW_IDLINE != NULL)
touchwin(CURRENT_WINDOW_IDLINE);
touchwin(CURRENT_WINDOW_FILEAREA);
show_statarea();
}
/*
* If we have a Rexx interpreter, register a handler for ring.x where
* x is the number of files in the ring.
*/
if (rexx_support)
{
CHARTYPE tmp[20];
sprintf(tmp,"ring.%d",number_of_files+(compatible_feel==COMPAT_XEDIT) ? 1 : 0 );
MyRexxRegisterFunctionExe(tmp);
}
TRACE_RETURN();
return(rc);
}
|