forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / dopus / Program / complete.c
blob74a79f1b1e374abf7805f0805f13555d574d97b3
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
33 void do_path_completion(win,qual)
34 int win;
35 UWORD qual;
37 struct FileInfoBlock __aligned finfo;
38 char path[256],match[FILEBUF_SIZE],*ptr;
39 BPTR lock;
40 struct complete_entry *entry,*curentry,*addpos;
41 int new=0,a;
43 strcpy(path,str_pathbuffer[win]);
44 a=strlen(path);
45 if (a>0 && (path[a-1]=='/' || path[a-1]==':')) match[0]=0;
46 else if (ptr=BaseName(path)) {
47 LStrnCpy(match,ptr,FILEBUF_SIZE-1);
48 match[FILEBUF_SIZE-1]=0;
49 *ptr=0;
51 else {
52 DisplayBeep(NULL);
53 return;
56 if (LStrCmp(completion[win].path,path)!=0) new=1;
57 else if (LStrCmp(completion[win].match,match)!=0) {
58 entry=completion[win].firstentry;
59 while (entry) {
60 if (Stricmp(match,entry->name)==0) break;
61 entry=entry->next;
63 if (!entry) new=1;
64 else if (entry!=completion[win].currententry) {
65 completion[win].currententry=entry;
66 goto docomplete;
70 if (new) {
71 strcpy(completion[win].match,match);
72 strcpy(completion[win].path,path);
73 LFreeRemember(&completion[win].memory);
74 completion[win].firstentry=NULL;
75 completion[win].currententry=NULL;
77 busy();
78 if (lock=Lock(path,ACCESS_READ)) {
79 Examine(lock,&finfo);
80 if (finfo.fib_DirEntryType>0) {
81 while (ExNext(lock,&finfo)) {
82 if (status_haveaborted) break;
83 if (finfo.fib_DirEntryType>0 &&
84 (!match[0] || LStrnCmpI(finfo.fib_FileName,match,strlen(match))==0)) {
85 if (entry=LAllocRemember(&completion[win].memory,
86 sizeof(struct complete_entry),MEMF_CLEAR)) {
87 strcpy(entry->name,finfo.fib_FileName);
88 addpos=completion[win].firstentry;
89 curentry=NULL;
90 while (addpos) {
91 curentry=addpos;
92 if (Stricmp(addpos->name,entry->name)>0) break;
93 addpos=addpos->next;
95 if (addpos) {
96 entry->next=addpos;
97 entry->last=addpos->last;
98 addpos->last=entry;
99 if (entry->last) entry->last->next=entry;
100 if (addpos==completion[win].firstentry)
101 completion[win].firstentry=entry;
103 else {
104 if (curentry) {
105 curentry->next=entry;
106 entry->last=curentry;
108 else completion[win].firstentry=entry;
114 UnLock(lock);
116 unbusy();
119 if (completion[win].currententry) {
120 if (qual&IEQUALIFIER_ANYSHIFT)
121 completion[win].currententry=completion[win].currententry->last;
122 else completion[win].currententry=completion[win].currententry->next;
125 if (!completion[win].currententry) {
126 if (qual&IEQUALIFIER_ANYSHIFT) {
127 entry=completion[win].firstentry;
128 while (entry && entry->next) entry=entry->next;
129 completion[win].currententry=entry;
131 else completion[win].currententry=completion[win].firstentry;
132 if (!completion[win].currententry) {
133 DisplayBeep(NULL);
134 ActivateStrGad(&path_strgadget[win],Window);
135 return;
138 docomplete:
139 strcpy(str_pathbuffer[win],path);
140 TackOn(str_pathbuffer[win],completion[win].currententry->name,256);
141 RefreshStrGad(&path_strgadget[win],Window);
142 ActivateStrGad(&path_strgadget[win],Window);