home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / complete.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  4KB  |  144 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  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.
  11.  
  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.
  16.  
  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.
  20.  
  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.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32.  
  33. void do_path_completion(win,qual)
  34. int win;
  35. USHORT qual;
  36. {
  37.     char path[256],match[32],*ptr;
  38.     BPTR lock;
  39.     struct FileInfoBlock __aligned finfo;
  40.     struct complete_entry *entry,*curentry,*addpos;
  41.     int new=0,a;
  42.  
  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,31);
  48.         match[31]=0;
  49.         *ptr=0;
  50.     }
  51.     else {
  52.         DisplayBeep(NULL);    
  53.         return;
  54.     }
  55.  
  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 (LStrCmpI(match,entry->name)==0) break;
  61.             entry=entry->next;
  62.         }
  63.         if (!entry) new=1;
  64.         else if (entry!=completion[win].currententry) {
  65.             completion[win].currententry=entry;
  66.             goto docomplete;
  67.         }
  68.     }
  69.  
  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;
  76.  
  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 (LStrCmpI(addpos->name,entry->name)>0) break;
  93.                                 addpos=addpos->next;
  94.                             }
  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;
  102.                             }
  103.                             else {
  104.                                 if (curentry) {
  105.                                     curentry->next=entry;
  106.                                     entry->last=curentry;
  107.                                 }
  108.                                 else completion[win].firstentry=entry;
  109.                             }
  110.                         }
  111.                     }
  112.                 }
  113.             }
  114.             UnLock(lock);
  115.         }
  116.         unbusy();
  117.     }
  118.  
  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;
  123.     }
  124.  
  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;
  130.         }
  131.         else completion[win].currententry=completion[win].firstentry;
  132.         if (!completion[win].currententry) {
  133.             DisplayBeep(NULL);
  134.             ActivateStrGad(&path_strgadget[win],Window);
  135.             return;
  136.         }
  137.     }
  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);
  143. }
  144.