summaryrefslogtreecommitdiff
path: root/pico/browse.c
diff options
context:
space:
mode:
Diffstat (limited to 'pico/browse.c')
-rw-r--r--pico/browse.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/pico/browse.c b/pico/browse.c
index 8113e4dc..08054e37 100644
--- a/pico/browse.c
+++ b/pico/browse.c
@@ -1,11 +1,8 @@
-#if !defined(lint) && !defined(DOS)
-static char rcsid[] = "$Id: browse.c 942 2008-03-04 18:21:33Z hubert@u.washington.edu $";
-#endif
/*
* ========================================================================
* Copyright 2006-2008 University of Washington
- * Copyright 2013-2021 Eduardo Chappa
+ * Copyright 2013-2022 Eduardo Chappa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -333,7 +330,7 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
int row, col, crow, ccol;
int flags;
int add_file;
- char *p, *envp, child[NLINE], tmp[NLINE];
+ char *p, *envp, child[2*NLINE+2], tmp[2*NLINE+1];
struct bmaster *mp;
struct fcell *tp;
EML eml;
@@ -721,25 +718,31 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
case 'e': /* exit or edit */
case 'E':
if(gmode&MDBRONLY){ /* run "pico" */
- snprintf(child, sizeof(child), "%s%c%s", gmp->dname, C_FILESEP,
- gmp->current->fname);
+ char *t;
+ snprintf(child, sizeof(child), "%.*s%c%.*s", NLINE, gmp->dname, C_FILESEP,
+ NLINE, gmp->current->fname);
/* make sure selected isn't a directory or executable */
if(!LikelyASCII(child)){
emlwrite(_("Can't edit non-text file. Try Launch."), NULL);
break;
}
- if((envp = (char *) getenv("EDITOR")) != NULL)
- snprintf(tmp, sizeof(tmp), "%s \'%s\'", envp, child);
- else
- snprintf(tmp, sizeof(tmp), "pico%s%s%s \'%s\'",
+ if((envp = (char *) getenv("EDITOR")) != NULL){
+ t = fs_get(strlen(envp) + strlen(child) + 3 + 1);
+ sprintf(t, "%s \'%s\'", envp, child);
+ }
+ else{
+ t = fs_get(strlen(child) + 16 + 1);
+ sprintf(t, "pico%s%s%s \'%s\'",
(gmode & MDFKEY) ? " -f" : "",
(gmode & MDSHOCUR) ? " -g" : "",
(gmode & MDMOUSE) ? " -m" : "",
child);
+ }
- BrowserRunChild(tmp, gmp->dname); /* spawn pico */
+ BrowserRunChild(t, gmp->dname); /* spawn pico */
PaintBrowser(gmp, 0, &crow, &ccol); /* redraw browser */
+ if(t) fs_give((void **) &t);
}
else{
zotmaster(&gmp);
@@ -812,8 +815,8 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
tmp[0] = '\0';
i = 0;
- snprintf(child, sizeof(child), "%s%c%s", gmp->dname, C_FILESEP,
- gmp->current->fname);
+ snprintf(child, sizeof(child), "%.*s%c%.*s", NLINE, gmp->dname, C_FILESEP,
+ NLINE, gmp->current->fname);
while(!i){
static EXTRAKEYS opts[] = {
{"^X", N_("Add Name"), CTRL|'X', KS_NONE},
@@ -1306,8 +1309,8 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
break;
}
- snprintf(tmp, sizeof(tmp), "%s%c%s", gmp->dname, C_FILESEP,
- gmp->current->fname);
+ snprintf(tmp, sizeof(tmp), "%.*s%c%.*s", NLINE, gmp->dname, C_FILESEP,
+ NLINE, gmp->current->fname);
if(copy(tmp, child) < 0){
/* copy() will report any error messages */
@@ -1424,8 +1427,8 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
}
}
- snprintf(tmp, sizeof(tmp), "%s%c%s", gmp->dname, C_FILESEP,
- gmp->current->fname);
+ snprintf(tmp, sizeof(tmp), "%.*s%c%.*s", NLINE, gmp->dname, C_FILESEP,
+ NLINE, gmp->current->fname);
if(our_rename(tmp, child) < 0){
eml.s = errstr(errno);
@@ -1581,15 +1584,18 @@ FileBrowse(char *dir, size_t dirlen, char *fn, size_t fnlen,
break;
}
else if(gmode&MDBRONLY){
- snprintf(child, sizeof(child), "%s%c%s", gmp->dname, C_FILESEP,
- gmp->current->fname);
+ snprintf(child, sizeof(child), "%.*s%c%.*s", NLINE, gmp->dname, C_FILESEP,
+ NLINE, gmp->current->fname);
if(LikelyASCII(child)){
- snprintf(tmp, sizeof(tmp), "%s \'%s\'",
- (envp = (char *) getenv("PAGER"))
- ? envp : BROWSER_PAGER, child);
- BrowserRunChild(tmp, gmp->dname);
+ char *t;
+ envp = (char *) getenv("PAGER");
+ t = fs_get((envp ? strlen(envp) : strlen(BROWSER_PAGER))
+ + strlen(child) + 3 + 1);
+ sprintf(t, "%s \'%s\'", envp ? envp : BROWSER_PAGER, child);
+ BrowserRunChild(t, gmp->dname);
PaintBrowser(gmp, 0, &crow, &ccol);
+ if(t) fs_give((void **) &t);
}
break;
@@ -1823,7 +1829,7 @@ getfcells(char *dname, int fb_flags)
**filtnames, /* array filtered names */
errbuf[NLINE];
struct fcell *ncp, /* new cell pointer */
- *tcp; /* trailing cell ptr */
+ *tcp = NULL; /* trailing cell ptr */
struct bmaster *mp;
EML eml;