mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Add "DO file" command which is equivalent to "INCLUDE [filedir()]/file"
This commit is contained in:
@@ -1238,7 +1238,10 @@ static void GenerateCalEntries(int col)
|
||||
case T_IfTrig: r=DoIfTrig(&p); break;
|
||||
case T_Else: r=DoElse(&p); break;
|
||||
case T_EndIf: r=DoEndif(&p); break;
|
||||
case T_Include: r=DoInclude(&p); break;
|
||||
|
||||
case T_Include:
|
||||
case T_IncludeR: r=DoInclude(&p, tok.type); break;
|
||||
|
||||
case T_IncludeCmd: r=DoIncludeCmd(&p); break;
|
||||
case T_Exit: DoExit(&p); break;
|
||||
case T_Set: r=DoSet(&p); break;
|
||||
|
||||
36
src/files.c
36
src/files.c
@@ -557,20 +557,52 @@ static int PopFile(void)
|
||||
/* The INCLUDE command. */
|
||||
/* */
|
||||
/***************************************************************/
|
||||
int DoInclude(ParsePtr p)
|
||||
int DoInclude(ParsePtr p, enum TokTypes tok)
|
||||
{
|
||||
DynamicBuffer buf;
|
||||
DynamicBuffer fullname;
|
||||
DynamicBuffer path;
|
||||
int r, e;
|
||||
|
||||
char const *s;
|
||||
DBufInit(&buf);
|
||||
DBufInit(&fullname);
|
||||
DBufInit(&path);
|
||||
if ( (r=ParseToken(p, &buf)) ) return r;
|
||||
e = VerifyEoln(p);
|
||||
if (e) Eprint("%s", ErrMsg[e]);
|
||||
if ( (r=IncludeFile(DBufValue(&buf))) ) {
|
||||
|
||||
if (tok == T_IncludeR) {
|
||||
/* Relative include: Include relative to dir
|
||||
containing current file */
|
||||
if (DBufPuts(&path, FileName) != OK) return E_NO_MEM;
|
||||
if (DBufLen(&path) == 0) {
|
||||
s = DBufValue(&buf);
|
||||
} else {
|
||||
char *t = DBufValue(&path) + DBufLen(&path) - 1;
|
||||
while (t > DBufValue(&path) && *t != '/') t--;
|
||||
if (*t == '/') {
|
||||
*t = 0;
|
||||
if (DBufPuts(&fullname, DBufValue(&path)) != OK) return E_NO_MEM;
|
||||
if (DBufPuts(&fullname, "/") != OK) return E_NO_MEM;
|
||||
if (DBufPuts(&fullname, DBufValue(&buf)) != OK) return E_NO_MEM;
|
||||
s = DBufValue(&fullname);
|
||||
} else {
|
||||
s = DBufValue(&buf);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s = DBufValue(&buf);
|
||||
}
|
||||
if ( (r=IncludeFile(s)) ) {
|
||||
DBufFree(&buf);
|
||||
DBufFree(&path);
|
||||
DBufFree(&fullname);
|
||||
return r;
|
||||
}
|
||||
DBufFree(&buf);
|
||||
DBufFree(&path);
|
||||
DBufFree(&fullname);
|
||||
NumIfs = 0;
|
||||
IfFlags = 0;
|
||||
return OK;
|
||||
|
||||
@@ -235,12 +235,13 @@ static void DoReminders(void)
|
||||
case T_Else: r=DoElse(&p); break;
|
||||
case T_EndIf: r=DoEndif(&p); break;
|
||||
case T_Include:
|
||||
case T_IncludeR:
|
||||
/* In purge mode, include closes file, so we
|
||||
need to echo it here! */
|
||||
if (PurgeMode) {
|
||||
PurgeEchoLine("%s\n", CurLine);
|
||||
}
|
||||
r=DoInclude(&p);
|
||||
r=DoInclude(&p, tok.type);
|
||||
purge_handled = 1;
|
||||
break;
|
||||
case T_IncludeCmd:
|
||||
|
||||
@@ -44,7 +44,7 @@ void PrintValue (Value *v, FILE *fp);
|
||||
int CopyValue (Value *dest, const Value *src);
|
||||
int ReadLine (void);
|
||||
int OpenFile (char const *fname);
|
||||
int DoInclude (ParsePtr p);
|
||||
int DoInclude (ParsePtr p, enum TokTypes tok);
|
||||
int DoIncludeCmd (ParsePtr p);
|
||||
int IncludeFile (char const *fname);
|
||||
int GetAccessDate (char const *file);
|
||||
|
||||
@@ -48,6 +48,7 @@ Token TokArray[] = {
|
||||
{ "clear-omit-context", 5, T_Clr, 0 },
|
||||
{ "debug", 5, T_Debug, 0 },
|
||||
{ "december", 3, T_Month, 11 },
|
||||
{ "do", 2, T_IncludeR, 0 },
|
||||
{ "dumpvars", 4, T_Dumpvars, 0 },
|
||||
{ "duration", 3, T_Duration, 0 },
|
||||
{ "else", 4, T_Else, 0 },
|
||||
|
||||
@@ -151,7 +151,7 @@ typedef Parser *ParsePtr; /* Pointer to parser structure */
|
||||
enum TokTypes
|
||||
{ T_Illegal,
|
||||
/* Commands first */
|
||||
T_Rem, T_Push, T_Pop, T_Preserve, T_Include, T_IncludeCmd, T_If, T_Else, T_EndIf,
|
||||
T_Rem, T_Push, T_Pop, T_Preserve, T_Include, T_IncludeR, T_IncludeCmd, T_If, T_Else, T_EndIf,
|
||||
T_IfTrig, T_ErrMsg,
|
||||
T_Set, T_UnSet, T_Fset, T_Omit, T_Banner, T_Exit,
|
||||
T_AddOmit,
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
REM 15 MSG 02
|
||||
DO subdir/04.rem
|
||||
INCLUDE subdir/04.rem
|
||||
|
||||
1
tests/include_dir/subdir/04.rem
Normal file
1
tests/include_dir/subdir/04.rem
Normal file
@@ -0,0 +1 @@
|
||||
REM 16 MSG Should be included by 02.rem
|
||||
Reference in New Issue
Block a user