jcs
/amend
/amendments
/61
repo: Exclude repo file itself when showing 'add file' dialog
jcs made amendment 61 over 2 years ago
--- browser.c Thu Feb 3 16:39:41 2022
+++ browser.c Thu Feb 3 17:36:42 2022
@@ -83,7 +83,7 @@ browser_idle(struct browser *browser)
struct browser *
browser_init(struct repo *repo)
{
- char title[256], filename[256];
+ char title[256], filename[256], *justfilename;
struct browser *browser;
Rect bounds = { 0 }, te_bounds = { 0 };
Rect data_bounds = { 0, 0, 0, 1 }; /* tlbr */
@@ -106,12 +106,12 @@ browser_init(struct repo *repo)
memcpy(filename, browser->repo->bile->filename, sizeof(filename));
PtoCstr(filename);
- for (n = 0, colonpos = 0; n < browser->repo->bile->filename[0]; n++) {
- if (filename[n] == ':')
- colonpos = n + 1;
- }
- snprintf(title, sizeof(title), "%s: %s", PROGRAM_NAME,
- filename + colonpos);
+ justfilename = strrchr(filename, ':');
+ if (justfilename == NULL)
+ justfilename = (char *)&filename;
+ else
+ justfilename++;
+ snprintf(title, sizeof(title), "%s: %s", PROGRAM_NAME, justfilename);
CtoPstr(title);
browser->win = NewWindow(0L, &bounds, title, false, noGrowDocProc,
(WindowPtr)-1L, true, 0);
--- repo.c Mon Jan 24 17:17:15 2022
+++ repo.c Thu Feb 3 17:40:39 2022
@@ -426,8 +426,9 @@ static struct repo *repo_add_file_filter_repo;
pascal Boolean
repo_add_file_filter(struct FileParam *pbp)
{
- static Str255 file_filter_fname;
+ static Str255 file_filter_fname, file_filter_repo_fname;
short n;
+ char *justfilename;
if (CurDirStore != repo_add_file_filter_repo_dir)
/* not in same dir as repo, filter out */
@@ -436,6 +437,19 @@ repo_add_file_filter(struct FileParam *pbp)
memcpy(file_filter_fname, pbp->ioNamePtr, pbp->ioNamePtr[0] + 1);
PtoCstr(file_filter_fname);
+ /* exclude the repo itself */
+ memcpy(file_filter_repo_fname,
+ repo_add_file_filter_repo->bile->filename,
+ sizeof(file_filter_repo_fname));
+ PtoCstr(file_filter_repo_fname);
+ justfilename = strrchr((char *)&file_filter_repo_fname, ':');
+ if (justfilename == NULL)
+ justfilename = (char *)&file_filter_repo_fname;
+ else
+ justfilename++;
+ if (strcmp(justfilename, (char *)&file_filter_fname) == 0)
+ return true;
+
for (n = 0; n < repo_add_file_filter_repo->nfiles; n++) {
if (strcmp(repo_add_file_filter_repo->files[n]->filename,
(char *)file_filter_fname) == 0)
@@ -453,7 +467,7 @@ repo_add_file(struct repo *repo)
CInfoPBRec pb;
WDPBRec wdir = { 0 };
SFReply reply;
- Str255 repofname, repopath, newpath;
+ Str255 fname, repofname, repopath, newpath;
Handle new_fileh;
struct repo_file *file;
struct repo_file_attrs attrs;
@@ -463,7 +477,8 @@ repo_add_file(struct repo *repo)
/* tell SFGetFile we only want to accept files from this dir */
wdir.ioVRefNum = wdir.ioWDVRefNum = repo->bile->vrefnum;
- wdir.ioNamePtr = (StringPtr)&repo->bile->filename;
+ memcpy(fname, repo->bile->filename, sizeof(fname));
+ wdir.ioNamePtr = (StringPtr)&fname;
if (PBGetWDInfo(&wdir, 0) != noErr) {
warn("Failed looking up repo directory");
return NULL;