Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filename extension detection on relative paths #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions efunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ extern char *mklower(char *str);
extern int abs(int x);
extern int ernd(void);
extern int sindex(char *source, char *pattern);
extern int rsindex(char *source, char *pattern);
extern char *xlat(char *source, char *lookup, char *trans);

/* crypt.c */
Expand Down
2 changes: 1 addition & 1 deletion emacs.rc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bind-to-key execute-macro-40 M-?
add-mode "wrap"
!return
!endif
set %rctmp &sin $cfname "."
set %rctmp &sir $cfname "."
!if &equ %rctmp 0
!return
!endif
Expand Down
44 changes: 44 additions & 0 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ char *gtfun(char *fname)
return itoa(~atoi(arg1));
case UFXLATE:
return xlat(arg1, arg2, arg3);
case UFRSINDEX:
return itoa(rsindex(arg1, arg2));
}

exit(-11); /* never should get here */
Expand Down Expand Up @@ -972,6 +974,48 @@ int sindex(char *source, char *pattern)
return 0;
}

/*
* reverse find pattern within source
*
* char *source; source string to search
* char *pattern; string to look for
*/
int rsindex(char *source, char *pattern)
{
char *sp; /* ptr to current position to scan */
char *csp; /* ptr to source string during comparison */
char *cp; /* ptr to place to check for equality */
int lp;
int ls;

ls = strlen(source);
lp = strlen(pattern);
if (ls == 0 || lp == 0 || ls < lp)
return 0;

/* scanning through the source string */
sp = source + ls - lp;
while (sp >= source) {
/* scan through the pattern */
cp = pattern;
csp = sp;
while (*cp) {
if (!eq(*cp, *csp))
break;
++cp;
++csp;
}

/* was it a match? */
if (*cp == 0)
return (int) (sp - source) + 1;
--sp;
}

/* no match at all.. */
return 0;
}

/*
* Filter a string through a translation table
*
Expand Down
2 changes: 2 additions & 0 deletions evar.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static struct user_function funcs[] = {
{ "bxo", DYNAMIC }, /* bitwise xor 9-10-87 jwm */
{ "bno", MONAMIC }, /* bitwise not */
{ "xla", TRINAMIC }, /* XLATE character string translation */
{ "sir", DYNAMIC } /* reverse find the index of one string in another */
};

/* And its preprocesor definitions. */
Expand Down Expand Up @@ -205,5 +206,6 @@ static struct user_function funcs[] = {
#define UFBXOR 36
#define UFBNOT 37
#define UFXLATE 38
#define UFRSINDEX 39

#endif /* EVAR_H_ */