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 504 505 506 507 508 509 510 511 512 513 514 515 516
|
/* $Id: dired.c,v 1.8 2001/02/18 19:29:29 amura Exp $ */
/* dired module for mg 2a */
/* by Robert A. Larson */
/*
* $Log: dired.c,v $
* Revision 1.8 2001/02/18 19:29:29 amura
* split dir.c to port depend/independ
*
* Revision 1.7 2001/02/18 17:07:24 amura
* append AUTOSAVE feature (but NOW not work)
*
* Revision 1.6 2000/12/27 16:56:01 amura
* change d_makename() params for conservative reason, and bugfix in dires_()
*
* Revision 1.5 2000/12/14 18:06:24 amura
* filename length become flexible
*
* Revision 1.4 2000/09/21 17:28:29 amura
* replace macro _WIN32 to WIN32 for Cygwin
*
* Revision 1.3 2000/07/22 17:54:09 amura
* fix typo bug
*
* Revision 1.2 2000/06/27 01:49:42 amura
* import to CVS
*
* Revision 1.1 1999/05/21 02:45:06 amura
* Initial revision
*
*/
#include "config.h" /* 90.12.20 by S.Yoshida */
#include "def.h"
#ifndef NO_DIRED
BUFFER *dired_();
#ifndef strncpy
extern char* strncpy();
#endif
#ifdef CHGMISC /* 99.8.11 by M.Suzuki */
static int SearchDir(dirname)
char* dirname;
{
LINE *llp;
for (llp=curbp->b_linep; lforw(llp)!=curbp->b_linep; llp=lforw(llp)){
#ifndef max
#define max(a,b) (((a)<(b))?(b):(a))
#endif
if (strncmp(dirname, llp->l_text, max(strlen(dirname),llength(llp)))
== 0 ){
curwp->w_dotp = llp;
curwp->w_flag |= WFEDIT | WFMOVE;
curwp->w_doto = llength(llp);
return TRUE;
}
}
return FALSE;
}
#endif /* CHGMISC */
/*ARGSUSED*/
int
dired(f, n)
int f, n;
{
char dirname[NFILEN];
BUFFER *bp;
#ifdef CHGMISC /* 1999.8.17 by M.Suzuki */
char *fname;
#endif /* CHGMISC */
#ifdef EXTD_DIR
int i;
ensurecwd();
edefset(curbp->b_cwd);
#endif
dirname[0] = '\0';
#ifndef NO_FILECOMP /* 90.04.04 by K.Maeda */
if(eread("Dired: ", dirname, NFILEN, EFNEW | EFCR | EFFILE) == ABORT)
#else /* NO_FILECOMP */
if(eread("Dired: ", dirname, NFILEN, EFNEW | EFCR) == ABORT)
#endif /* NO_FILECOMP */
return ABORT;
#ifdef CHGMISC /* 1999.8.17 by M.Suzuki */
if((fname = adjustname(dirname)) == NULL) {
ewprintf("Bad directory name");
return FALSE;
}
if( !ffisdir(fname) ){
return filevisit_(fname,f,n);
}
if((bp = dired_(fname)) == NULL) return FALSE;
#else
if((bp = dired_(dirname)) == NULL) return FALSE;
#endif /* CHGMISC */
curbp = bp;
#ifdef EXTD_DIR
i = strlen(dirname);
if (curbp->b_cwd != NULL)
free(curbp->b_cwd);
if ((curbp->b_cwd=malloc(i 2)) == NULL)
return FALSE;
strcpy(curbp->b_cwd, dirname);
if (i >= 1) {
if (curbp->b_cwd[i-1] != BDC1
#ifdef BDC2
&& curbp->b_cwd[i-1] != BDC2
#endif
) {
curbp->b_cwd[i] = BDC1;
curbp->b_cwd[i 1] = '\0';
}
}
#endif /* EXTD_DIR */
#ifdef READONLY /* 91.01.15 by K.Maeda */
curbp->b_flag |= BFRONLY;
#endif /* READONLY */
#ifdef FEPCTRL
/* The following fepmode_off() is only effective if the provided
fepcontrol supports a doubled fepmode_off() feature. That is,
the second call for the fepmode_off() is expected to change the
previous fep mode as off, without doing any actual fep control
since the fep mode has been already turned off by the first
call of the function. So, the succeeding fepmode_on() will not
turn on the fep mode even if the previous fep mode was on
before the first call of fepmode_off().
If this feature is not provided, entering dired does not affect
the fep mode.
By Tillanosoft, Mar 21, 1999 */
fepmode_off();
#endif
return showbuffer(bp, curwp, WFHARD | WFMODE);
}
/*ARGSUSED*/
int
d_otherwindow(f, n)
int f, n;
{
char dirname[NFILEN];
BUFFER *bp;
WINDOW *wp;
#ifdef EXTD_DIR
ensurecwd();
edefset(curbp->b_cwd);
#endif
dirname[0] = '\0';
#ifndef NO_FILECOMP /* 90.04.04 by K.Maeda */
if(eread("Dired other window: ", dirname, NFILEN, EFNEW | EFCR | EFFILE) == ABORT)
#else /* NO_FILECOMP */
if(eread("Dired other window: ", dirname, NFILEN, EFNEW | EFCR) == ABORT)
#endif /* NO_FILECOMP */
return ABORT;
#ifdef CHGMISC /* 99.6.18 by M.Suzuki */
if((bp = dired_(dirname)) == NULL) return FALSE;
#else
if((bp = dired_(dirname)) == NULL) return FALSE;
#endif /* CHGMISC */
#ifdef READONLY /* 91.01.15 by K.Maeda */
bp->b_flag |= BFRONLY;
#endif /* READONLY */
if((wp = popbuf(bp)) == NULL) return FALSE;
curbp = bp;
curwp = wp;
return TRUE;
}
/*ARGSUSED*/
int
d_del(f, n)
int f, n;
{
if(n < 0) return FALSE;
while(n--) {
if(llength(curwp->w_dotp) > 0)
#ifdef CHGMISC /* 99.6.18 by M.Suzuki */
if(lgetc(curwp->w_dotp,0) != '/' &&
strncmp(curwp->w_dotp->l_text, " total", 7) )
#endif /* CHGMISC */
lputc(curwp->w_dotp, 0, 'D');
if(lforw(curwp->w_dotp) != curbp->b_linep)
curwp->w_dotp = lforw(curwp->w_dotp);
}
curwp->w_flag |= WFEDIT | WFMOVE;
curwp->w_doto = 0;
return TRUE;
}
/*ARGSUSED*/
int
d_undel(f, n)
int f, n;
{
if(n < 0) return d_undelbak(f, -n);
while(n--) {
if(llength(curwp->w_dotp) > 0)
#ifdef CHGMISC /* 99.6.18 by M.Suzuki */
if( lgetc(curwp->w_dotp,0) != '/' &&
strncmp(curwp->w_dotp->l_text," total",7) )
#endif /* CHGMISC */
lputc(curwp->w_dotp, 0, ' ');
if(lforw(curwp->w_dotp) != curbp->b_linep)
curwp->w_dotp = lforw(curwp->w_dotp);
}
curwp->w_flag |= WFEDIT | WFMOVE;
curwp->w_doto = 0;
return TRUE;
}
/*ARGSUSED*/
int
d_undelbak(f, n)
int f, n;
{
if(n < 0) return d_undel(f, -n);
while(n--) {
if(llength(curwp->w_dotp) > 0)
lputc(curwp->w_dotp, 0, ' ');
if(lback(curwp->w_dotp) != curbp->b_linep)
curwp->w_dotp = lback(curwp->w_dotp);
}
curwp->w_doto = 0;
curwp->w_flag |= WFEDIT | WFMOVE;
return TRUE;
}
/*ARGSUSED*/
int
d_flag(f, n)
int f, n;
{
struct LINE *lp;
char flag = (f & FFARG) ? ' ' : 'D';
int nflags = 0, len;
lp = curbp->b_linep;
do {
len = llength(lp);
if (len > 0 && lgetc(lp, len - 1) == '~') {
lputc(lp, 0, flag);
nflags ;
}
lp = lforw(lp);
} while (lp != curbp->b_linep);
curwp->w_flag |= WFEDIT | WFMOVE;
ewprintf(flag == 'D' ?
"%d backup file%s flagged." : "%d backup file%s unmarked.",
nflags, nflags == 1 ? "" : "s");
return TRUE;
}
/*
* unified routine for d_findfile and d_ffotherwindow
*/
static
int
d_fileopen(f, n, popup)
int f, n, popup;
{
char fname[NFILEN];
register BUFFER *bp;
register int s;
register WINDOW *wp;
BUFFER *findbuffer();
if ((s = d_makename(curwp->w_dotp, fname, sizeof(fname))) == ABORT)
return FALSE;
if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL)
return FALSE;
#ifdef READONLY /* 91.01.16 by S.Yoshida */
if (s) { /* If dired buffer, */
bp->b_flag |= BFRONLY; /* mark as read-only. */
}
#endif /* READONLY */
if (popup) {
if ((wp = popbuf(bp)) == NULL)
return FALSE;
curbp = bp;
curwp = wp;
}
else {
curbp = bp;
if (showbuffer(bp, curwp, WFHARD) != TRUE)
return FALSE;
}
if (bp->b_fname != NULL)
return TRUE;
s = readin(fname);
#ifdef READONLY /* 91.01.16 by S.Yoshida */
if (fchkreadonly(bp->b_fname)) { /* If no write permission, */
bp->b_flag |= BFRONLY; /* mark as read-only. */
ewprintf("File is write protected");
}
#endif /* READONLY */
return s;
}
/*ARGSUSED*/
int
d_findfile(f, n)
int f, n;
{
return d_fileopen(f, n, FALSE);
}
#ifdef READONLY
/*ARGSUSED*/
int
d_viewfile(f, n)
int f, n;
{
int res;
res = d_findfile(f, n);
if (res) {
curbp->b_flag |= BFRONLY; /* set read-only bit. */
}
return res;
}
#endif
/*ARGSUSED*/
int
d_ffotherwindow(f, n)
int f, n;
{
return d_fileopen(f, n, TRUE);
}
/*ARGSUSED*/
int
d_expunge(f, n)
int f, n;
{
register LINE *lp, *nlp;
char fname[NFILEN];
VOID lfree();
#ifdef EXTD_DIR
ensurecwd();
#endif
for(lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) {
nlp = lforw(lp);
if(llength(lp) && lgetc(lp, 0) == 'D') {
switch(d_makename(lp, fname, sizeof(fname))) {
case ABORT:
ewprintf("Bad line in dired buffer");
return FALSE;
case FALSE:
if(unlink(fname) < 0) {
ewprintf("Could not delete '%s'", fname);
return FALSE;
}
break;
case TRUE:
if(unlinkdir(fname) < 0) {
ewprintf("Could not delete directory '%s'", fname);
return FALSE;
}
break;
}
lfree(lp);
curwp->w_flag |= WFHARD;
}
}
return TRUE;
}
static char *
filename(path)
char *path;
{
char *cp1;
cp1 = path;
while (*cp1 != 0) {
cp1;
}
--cp1; /* insure at least 1 character ! */
while (cp1!= path && cp1[-1] != BDC1
#ifdef BDC2
&& cp1[-1] != BDC2
#endif
) {
--cp1;
}
return cp1;
}
/*ARGSUSED*/
int
d_copy(f, n)
int f, n;
{
char frname[NFILEN], toname[NFILEN], *fr;
int stat;
#ifdef EXTD_DIR
ensurecwd();
#endif
switch (d_makename(curwp->w_dotp, frname, sizeof(frname))) {
case TRUE:
ewprintf("Not a file");
return FALSE;
case ABORT:
return FALSE;
case FALSE:
/* nothing to do */
break;
}
fr = filename(frname);
#ifdef EXTD_DIR
edefset(curbp->b_cwd);
#endif
#ifndef NO_FILECOMP /* 90.04.04 by K.Maeda */
if((stat = eread("Copy %s to: ", toname, NFILEN, EFNEW | EFCR | EFFILE, fr))
#else /* NO_FILECOMP */
if((stat = eread("Copy %s to: ", toname, NFILEN, EFNEW | EFCR, fr))
#endif /* NO_FILECOMP */
!= TRUE) {
return stat;
}
stat = (copy(frname, toname) >= 0);
return stat;
}
/*ARGSUSED*/
int
d_rename(f, n)
int f, n;
{
char frname[NFILEN], toname[NFILEN], *fr;
int stat;
#ifdef EXTD_DIR
ensurecwd();
#endif
switch (d_makename(curwp->w_dotp, frname, sizeof(frname))) {
case TRUE:
ewprintf("Not a file");
return FALSE;
case ABORT:
return FALSE;
case FALSE:
/* nothing to do */
break;
}
fr = filename(frname);
#ifdef EXTD_DIR
edefset(curbp->b_cwd);
#endif
#ifndef NO_FILECOMP /* 90.04.04 by K.Maeda */
if((stat = eread("Rename %s to: ", toname, NFILEN, EFNEW | EFCR | EFFILE,
fr))
#else /* NO_FILECOMP */
if((stat = eread("Rename %s to: ", toname, NFILEN, EFNEW | EFCR, fr))
#endif /* NO_FILECOMP */
!= TRUE) {
return stat;
}
stat = (rename(frname, toname) >= 0);
return stat;
}
/*ARGSUSED*/
int
d_execute(f, n)
int f, n;
{
#ifdef WIN32
char fname[NFILEN];
register int s;
extern void WinExecute(char *);
s = d_makename(curwp->w_dotp, fname, sizeof(fname));
if (s == ABORT) {
return FALSE;
}
else if (s) { /* that is, fname points to a directory */
#if !defined(_WIN32_WCE) || 200 <= _WIN32_WCE
goto noproblem;
#endif
return FALSE;
}
else {
noproblem:
WinExecute(fname);
return TRUE;
}
#else /* not WIN32 */
return TRUE;
#endif /* WIN32 */
}
#endif /* NO_DIRED */
|