| 774 | static hashtable<char *, completeval *> completions; |
| 775 | |
| 776 | void addcomplete(char *command, int type, char *dir, char *ext) |
| 777 | { |
| 778 | if(type==COMPLETE_FILE) |
| 779 | { |
| 780 | int dirlen = (int)strlen(dir); |
| 781 | while(dirlen > 0 && (dir[dirlen-1] == '/' || dir[dirlen-1] == '\\')) |
| 782 | dir[--dirlen] = '\0'; |
| 783 | if(ext) |
| 784 | { |
| 785 | if(strchr(ext, '*')) ext[0] = '\0'; |
| 786 | if(!ext[0]) ext = NULL; |
| 787 | } |
| 788 | } |
| 789 | completekey key(type, dir, ext); |
| 790 | completeval **val = completedata.access(key); |
| 791 | if(!val) |
| 792 | { |
| 793 | completeval *f = new completeval(type, dir, ext); |
| 794 | if(type==COMPLETE_LIST) explodelist(dir, f->list); |
| 795 | if(type==COMPLETE_FILE) |
| 796 | { |
| 797 | explodelist(dir, f->dirlist); |
| 798 | loopv(f->dirlist) |
| 799 | { |
| 800 | char *dir = f->dirlist[i]; |
| 801 | int dirlen = (int)strlen(dir); |
| 802 | while(dirlen > 0 && (dir[dirlen-1] == '/' || dir[dirlen-1] == '\\')) |
| 803 | dir[--dirlen] = '\0'; |
| 804 | } |
| 805 | } |
| 806 | val = &completedata[completekey(type, f->dir, f->ext)]; |
| 807 | *val = f; |
| 808 | } |
| 809 | completeval **hascomplete = completions.access(command); |
| 810 | if(hascomplete) *hascomplete = *val; |
| 811 | else completions[newstring(command)] = *val; |
| 812 | } |
| 813 | |
| 814 | void addfilecomplete(char *command, char *dir, char *ext) |
| 815 | { |
no test coverage detected