This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-complete file names and redo undo
- Loading branch information
1 parent
28cab7a
commit 66691df
Showing
6 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* complete.c, editor, Morgan Peterson, Public Domain, 2021 | ||
* complete.c, Atto Emacs, Hugh Barney, Public Domain, 2016 | ||
*/ | ||
|
||
#include "header.h" | ||
|
||
/* basic filename completion, based on code in uemacs/PK */ | ||
int32_t | ||
getfilename(char *prompt, char_t *buf, int32_t nbuf) | ||
{ | ||
static char temp_file[] = TEMPFILE; | ||
int32_t cpos = 0; /* current character position in string */ | ||
int32_t k = 0, c, fd, didtry, iswild = 0; | ||
|
||
char sys_command[255]; | ||
FILE *fp = NULL; | ||
buf[0] ='\0'; | ||
|
||
for (;;) { | ||
didtry = (k == 0x09); /* Was last command tab-completion? */ | ||
display_prompt_and_response(prompt, (char*)buf); | ||
k = getch(); /* get a character from the user */ | ||
|
||
switch(k) { | ||
case 0x07: /* ctrl-g, abort */ | ||
case 0x0a: /* cr, lf */ | ||
case 0x0d: | ||
if (fp != NULL) fclose(fp); | ||
return (k != 0x07 && cpos > 0); | ||
|
||
case 0x7f: /* del, erase */ | ||
case 0x08: /* backspace */ | ||
if (cpos == 0) continue; | ||
buf[--cpos] = '\0'; | ||
break; | ||
|
||
case 0x15: /* C-u kill */ | ||
cpos = 0; | ||
buf[0] = '\0'; | ||
break; | ||
|
||
case 0x09: /* TAB, complete file name */ | ||
/* scan backwards for a wild card and set */ | ||
iswild=0; | ||
while (cpos > 0) { | ||
cpos--; | ||
if (buf[cpos] == '*' || buf[cpos] == '?') | ||
iswild = 1; | ||
} | ||
|
||
/* first time retrieval */ | ||
if (! didtry) { | ||
if (fp != NULL) fclose(fp); | ||
strcpy(temp_file, TEMPFILE); | ||
if (-1 == (fd = mkstemp(temp_file))) | ||
fatal("%s: Failed to create temp file\n"); | ||
strcpy(sys_command, "echo "); | ||
strcat(sys_command, (char*)buf); | ||
if (!iswild) strcat(sys_command, "*"); | ||
strcat(sys_command, " >"); | ||
strcat(sys_command, temp_file); | ||
strcat(sys_command, " 2>&1"); | ||
(void) ! system(sys_command); /* stop compiler unused result warning */ | ||
fp = fdopen(fd, "r"); | ||
unlink(temp_file); | ||
} | ||
|
||
/* copy next filename into buf */ | ||
while ((c = getc(fp)) != EOF && c != '\n' && c != ' ') | ||
if (cpos < nbuf - 1 && c != '*') | ||
buf[cpos++] = c; | ||
|
||
buf[cpos] = '\0'; | ||
if (c != ' ') rewind(fp); | ||
didtry = 1; | ||
break; | ||
|
||
default: | ||
if (cpos < nbuf - 1) { | ||
buf[cpos++] = k; | ||
buf[cpos] = '\0'; | ||
} | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters