示例#1
0
int SetSysVar(char const *name, Value *value)
{
    SysVar *v = FindSysVar(name);
    if (!v) return E_NOSUCH_VAR;
    if (v->type != SPECIAL_TYPE &&
	v->type != value->type) return E_BAD_TYPE;
    if (!v->modifiable) {
	Eprint("%s: `$%s'", ErrMsg[E_CANT_MODIFY], name);
	return E_CANT_MODIFY;
    }

    if (v->type == SPECIAL_TYPE) {
	SysVarFunc f = (SysVarFunc) v->value;
	return f(1, value);
    } else if (v->type == STR_TYPE) {
        /* If it's a string variable, special measures must be taken */
	if (v->been_malloced) free(*((char **)(v->value)));
	v->been_malloced = 1;
	*((char **) v->value) = value->v.str;
	value->type = ERR_TYPE;  /* So that it's not accidentally freed */
    } else {
	if (v->max != ANY && value->v.val > v->max) return E_2HIGH;
	if (v->min != ANY && value->v.val < v->min) return E_2LOW;
	*((int *)v->value) = value->v.val;
    }
    return OK;
}
示例#2
0
int GetSysVar(char const *name, Value *val)
{
    SysVar *v = FindSysVar(name);

    val->type = ERR_TYPE;
    if (!v) return E_NOSUCH_VAR;
    if (v->type == SPECIAL_TYPE) {
	SysVarFunc f = (SysVarFunc) v->value;
	return f(0, val);
    } else if (v->type == STR_TYPE) {
	val->v.str = StrDup(*((char **) v->value));
	if (!val->v.str) return E_NO_MEM;
    } else {
	val->v.val = *((int *) v->value);
    }
    val->type = v->type;

    /* In "verbose" mode, print attempts to test $RunOff */
    if (DebugFlag & DB_PRTLINE) {
	if (v->value == (void *) &RunDisabled) {
	    Eprint("(Security note: $RunOff variable tested.)\n");
	    /* Allow further messages from this line */
	    FreshLine = 1;
	}
    }
    return OK;
}
示例#3
0
文件: files.c 项目: Yomin/remind
static int NextChainedFile(IncludeStruct *i)
{
    while(i->chain) {
	FilenameChain *cur = i->chain;
	i->chain = i->chain->next;
	if (OpenFile(cur->filename) == OK) {
	    return OK;
	} else {
	    Eprint("%s: %s", ErrMsg[E_CANT_OPEN], cur->filename);
	}
    }
    return E_EOF;
}
示例#4
0
文件: files.c 项目: Yomin/remind
static int PopFile(void)
{
    IncludeStruct *i;

    /* Assume we own the file for now */
    RunDisabled &= ~RUN_NOTOWNER;

    if (!Hush && NumIfs) Eprint("%s", ErrMsg[E_MISS_ENDIF]);
    if (!IStackPtr) return E_EOF;
    i = &IStack[IStackPtr-1];

    if (i->chain) {
	int oldRunDisabled = RunDisabled;
	if (NextChainedFile(i) == OK) {
	    return OK;
	}
	RunDisabled = oldRunDisabled;
    }

    if (IStackPtr <= 1) {
	return E_EOF;
    }

    IStackPtr--;

    LineNo = i->LineNo;
    IfFlags = i->IfFlags;
    NumIfs = i->NumIfs;
    CLine = i->CLine;
    fp = NULL;
    STRSET(FileName, i->filename);
    if (!i->ownedByMe) {
	RunDisabled |= RUN_NOTOWNER;
    }
    if (!CLine && (i->offset != -1L)) {
	/* We must open the file, then seek to specified position */
	if (strcmp(i->filename, "-")) {
	    fp = fopen(i->filename, "r");
	    if (!fp || !CheckSafety()) return E_CANT_OPEN;
	    if (PurgeMode) OpenPurgeFile(i->filename, "a");
	} else {
	    fp = stdin;
	    if (PurgeMode) PurgeFP = stdout;
	}
	if (fp != stdin)
	    (void) fseek(fp, i->offset, 0);  /* Trust that it works... */
    }
    free((char *) i->filename);
    return OK;
}
示例#5
0
文件: files.c 项目: Yomin/remind
int DoInclude(ParsePtr p)
{
    DynamicBuffer buf;
    int r, e;

    DBufInit(&buf);
    if ( (r=ParseToken(p, &buf)) ) return r;
    e = VerifyEoln(p);
    if (e) Eprint("%s", ErrMsg[e]);
    if ( (r=IncludeFile(DBufValue(&buf))) ) {
	DBufFree(&buf);
	return r;
    }
    DBufFree(&buf);
    NumIfs = 0;
    IfFlags = 0;
    return OK;
}
示例#6
0
int GetVarValue(char const *str, Value *val, Var *locals, ParsePtr p)
{
    Var *v;

    /* Try searching local variables first */
    v = locals;
    while (v) {
	if (! StrinCmp(str, v->name, VAR_NAME_LEN))
	    return CopyValue(val, &v->v);
	v = v->next;
    }

    /* Global variable... mark expression as non-constant */
    if (p) p->nonconst_expr = 1;
    v=FindVar(str, 0);

    if (!v) {
	Eprint("%s: %s", ErrMsg[E_NOSUCH_VAR], str);
	return E_NOSUCH_VAR;
    }
    return CopyValue(val, &v->v);
}
示例#7
0
static int NextSimpleTrig(int startdate, Trigger *trig, int *err)
{
    int typ = 0;
    int d, m, y, j, d2, m2, y2;

    *err = 0;
    FromJulian(startdate, &y, &m, &d);
    d2 = d;
    m2 = m;
    y2 = y;

    if (trig->d != NO_DAY) typ |= GOT_DAY;
    if (trig->m != NO_MON) typ |= GOT_MON;
    if (trig->y != NO_YR) typ |= GOT_YR;
    if (trig->wd != NO_WD) typ |= GOT_WD;
    switch(typ) {
    case 0:
    case GOT_WD:
	if (trig->wd != NO_WD)
	    while(! (trig->wd & (1 << (startdate%7)))) startdate++;
	return startdate;

    case GOT_DAY:
	if (d > trig->d) {
	    m++;
	    if (m == 12) { m = 0; y++; }
	}
	while (trig->d > DaysInMonth(m, trig->y)) m++;
	j = Julian(y, m, trig->d);
	return j;

    case GOT_MON:
	if (m == trig->m) return startdate;
	else if (m > trig->m) return Julian(y+1, trig->m, 1);
	else return Julian(y, trig->m, 1);

    case GOT_YR:
	if (y == trig->y) return startdate;
	else if (y < trig->y) return Julian(trig->y, 0, 1);
	else return -1;

    case GOT_DAY+GOT_MON:
	if (m > trig->m || (m == trig->m && d > trig->d)) y++;
	if (trig->d > MonthDays[trig->m]) {
	    *err = E_BAD_DATE;
	    return -1;
	}

	/* Take care of Feb. 29 */
	while (trig->d > DaysInMonth(trig->m, y)) y++;
	return Julian(y, trig->m, trig->d);

    case GOT_DAY+GOT_YR:
	if (y < trig->y) return Julian(trig->y, 0, trig->d);
	else if (y > trig->y) return -1;

	if (d > trig->d) {
	    m++;
	    if (m == 12) return -1;
	}
	while (trig->d > DaysInMonth(m, trig->y)) m++;
	return Julian(trig->y, m, trig->d);

    case GOT_MON+GOT_YR:
	if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
	if (y < trig->y) return Julian(trig->y, trig->m, 1);
	if (m == trig->m) return startdate;
	return Julian(trig->y, trig->m, 1);

    case GOT_DAY+GOT_MON+GOT_YR:
	if (trig->d > DaysInMonth(trig->m, trig->y)) {
	    *err = E_BAD_DATE;
	    return -1;
	}
	return Julian(trig->y, trig->m, trig->d);

    case GOT_YR+GOT_WD:
	if (y > trig->y) return -1;
	if (y < trig->y) j = Julian(trig->y, 0, 1);
	else j = startdate;
	while(! (trig->wd & (1 << (j%7)))) j++;
	if (JYear(j) > trig->y) return -1;
	return j;

    case GOT_MON+GOT_WD:
	if (m == trig->m) {
	    j = startdate;
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    if (JMonth(j) == trig->m) return j;
	}
	if (m >= trig->m) j = Julian(y+1, trig->m, 1);
	else j = Julian(y, trig->m, 1);
	while(! (trig->wd & (1 << (j%7)))) j++;
	return j; /* Guaranteed to be within the month */

    case GOT_DAY+GOT_WD:
	if (m !=0 || y > BASE) {
	    m2 = m-1;
	    if (m2 < 0) { y2 = y-1; m2 = 11; }

	    /* If there are fewer days in previous month, no match */
	    if (trig->d <= DaysInMonth(m2, y2)) {
		j = Julian(y2, m2, trig->d);
		while(! (trig->wd & (1 << (j%7)))) j++;
		if (j >= startdate) return j;

	    }
	}

	/* Try this month */
	if (trig->d <= DaysInMonth(m, y)) {
	    j = Julian(y, m, trig->d);
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    if (j >= startdate) return j;
	}

	/* Argh!  Try next avail. month */
	m2 = m+1;
	if (m2 > 11) { m2 = 0; y++; }
	while (trig->d > DaysInMonth(m2, y)) m2++;
	j = Julian(y, m2, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	return j;

    case GOT_WD+GOT_YR+GOT_DAY:
	if (y > trig->y+1 || (y > trig->y && m>0)) return -1;
	if (y > trig->y) {
	    j = Julian(trig->y, 11, trig->d);
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    if (j >= startdate) return j;
	} else if (y < trig->y) {
	    j = Julian(trig->y, 0, trig->d);
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    return j;
	} else {
	    /* Try last month */
	    if (m > 0) {
		m2 = m-1;
		while (trig->d > DaysInMonth(m2, trig->y)) m2--;
		j = Julian(trig->y, m2, trig->d);
		while(! (trig->wd & (1 << (j%7)))) j++;
		if (j >= startdate) return j;
	    }
	}
	/* Try this month */
	if (trig->d <= DaysInMonth(m, trig->y)) {
	    j = Julian(trig->y, m, trig->d);
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    if (j >= startdate) return j;
	}

	/* Must be next month */
	if (m == 11) return -1;
	m++;
	while (trig->d > DaysInMonth(m, trig->d)) m++;
	j = Julian(trig->y, m, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	return j;

    case GOT_DAY+GOT_MON+GOT_WD:
	if (trig->d > MonthDays[trig->m]) {
	    *err = E_BAD_DATE;
	    return -1;
	}
	/* Back up a year in case we'll cross a year boundary*/
	if (y > BASE) {
	    y--;
	}

	/* Move up to the first valid year */
	while (trig->d > DaysInMonth(trig->m, y)) y++;

	/* Try last year */
	j = Julian(y, trig->m, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	if (j >= startdate) return j;

	/* Try this year */
	y++;
	j = Julian(y, trig->m, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	if (j >= startdate) return j;

	/* Must be next year */
	y++;
	while (trig->d > DaysInMonth(trig->m, y)) y++;
	j = Julian(y, trig->m, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	return j;

    case GOT_WD+GOT_MON+GOT_YR:
	if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
	if (trig->y > y || (trig->y == y && trig->m > m)) {
	    j = Julian(trig->y, trig->m, 1);
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    return j;
	} else {
	    j = startdate;
	    while(! (trig->wd & (1 << (j%7)))) j++;
	    FromJulian(j, &y2, &m2, &d2);
	    if (m2 == trig->m) return j; else return -1;
	}

    case GOT_WD+GOT_DAY+GOT_MON+GOT_YR:
	if (trig->d > DaysInMonth(trig->m, trig->y)) {
	    *err = E_BAD_DATE;
	    return -1;
	}
	j = Julian(trig->y, trig->m, trig->d);
	while(! (trig->wd & (1 << (j%7)))) j++;
	return j;

    default:
	Eprint("NextSimpleTrig %s %d", ErrMsg[E_SWERR], typ);
	*err = E_SWERR;
	return -1;
    }
}
示例#8
0
int ComputeTrigger(int today, Trigger *trig, int *err, int save_in_globals)
{
    int nattempts = 0,
	start = today,
	nextstart = 0,
	y, m, d, omit,
	result;

    trig->expired = 0;
    if (save_in_globals) {
	LastTrigValid = 0;
    }

/* Assume everything works */
    *err = OK;

/* But check for obvious problems... */
    if (trig->localomit == 1 + 2 + 4 + 8 + 16 + 32 + 64) {
	*err = E_2MANY_LOCALOMIT;
	return -1;
    }

    if (trig->rep != NO_REP &&
	(trig->d == NO_DAY ||
	 trig->m == NO_MON ||
	 trig->y == NO_YR)) {
	Eprint("%s", ErrMsg[E_REP_FULSPEC]);
	*err = E_REP_FULSPEC;
	return -1;
    }


    while (nattempts++ < TRIG_ATTEMPTS) {
	result = GetNextTriggerDate(trig, start, err, &nextstart);

	/* If there's an error, die immediately */
	if (*err) return -1;
	if (result == -1) {
	    trig->expired = 1;
	    if (DebugFlag & DB_PRTTRIG) {
		fprintf(ErrFp, "%s(%d): %s\n",
			FileName, LineNo, ErrMsg[E_EXPIRED]);
	    }
	    return -1;
	}

	/* If result is >= today, great! */
	if (trig->skip == SKIP_SKIP) {
	    *err = IsOmitted(result, trig->localomit, trig->omitfunc, &omit);
	    if (*err) return -1;
	} else {
	    omit = 0;
	}
	if (result >= today &&
	    (trig->skip != SKIP_SKIP || !omit)) {
	    if (save_in_globals) {
		LastTriggerDate = result;  /* Save in global var */
		LastTrigValid = 1;
	    }
	    if (DebugFlag & DB_PRTTRIG) {
		FromJulian(result, &y, &m, &d);
		fprintf(ErrFp, "%s(%d): Trig = %s, %d %s, %d\n",
			FileName, LineNo,
			DayName[result % 7],
			d,
			MonthName[m],
			y);
	    }
	    return result;
	}

	/* If it's a simple trigger, no point in rescanning */
	if (trig->back == NO_BACK &&
	    trig->skip == NO_SKIP &&
	    trig->rep == NO_REP) {
	    trig->expired = 1;
	    if (DebugFlag & DB_PRTTRIG) {
		fprintf(ErrFp, "%s(%d): %s\n",
			FileName, LineNo, ErrMsg[E_EXPIRED]);
	    }
	    if (result != -1) {
		if (save_in_globals) {
		    LastTriggerDate = result;
		    LastTrigValid = 1;
		}
	    }
	    return -1;
	}

	if (trig->skip == SKIP_SKIP &&
	    omit &&
	    nextstart <= start &&
	    result >= start) {
	    nextstart = result + 1;
	}

	/* Keep scanning... unless there's no point in doing it.*/
	if (nextstart <= start) {
	    if (result != -1) {
		if (save_in_globals) {
		    LastTriggerDate = result;
		    LastTrigValid = 1;
		}
	    }
	    trig->expired = 1;
	    if (DebugFlag & DB_PRTTRIG) {
		fprintf(ErrFp, "%s(%d): %s\n",
			FileName, LineNo, ErrMsg[E_EXPIRED]);
	    }
	    return -1;
	}
	else start = nextstart;

    }

    /* We failed - too many attempts or trigger has expired*/
    *err = E_CANT_TRIG;
    return -1;
}
示例#9
0
文件: files.c 项目: Yomin/remind
int IncludeFile(char const *fname)
{
    IncludeStruct *i;
    int oldRunDisabled;
    struct stat statbuf;

    FreshLine = 1;
    if (IStackPtr+1 >= INCLUDE_NEST) return E_NESTED_INCLUDE;
    i = &IStack[IStackPtr];

    if (FileName) {
	i->filename = StrDup(FileName);
	if (!i->filename) return E_NO_MEM;
    } else {
	i->filename = NULL;
    }
    i->LineNo = LineNo;
    i->NumIfs = NumIfs;
    i->IfFlags = IfFlags;
    i->CLine = CLine;
    i->offset = -1L;
    i->chain = NULL;
    if (RunDisabled & RUN_NOTOWNER) {
	i->ownedByMe = 0;
    } else {
	i->ownedByMe = 1;
    }
    if (fp) {
	i->offset = ftell(fp);
	FCLOSE(fp);
    }

    IStackPtr++;

#ifdef HAVE_GLOB
    /* If it's a directory, set up the glob chain here. */
    if (stat(fname, &statbuf) == 0) {
	FilenameChain *fc;
	if (S_ISDIR(statbuf.st_mode)) {
	    if (SetupGlobChain(fname, i) == OK) { /* Glob succeeded */
		if (!i->chain) { /* Oops... no matching files */
		    if (!Hush) {
			Eprint("%s: %s", fname, ErrMsg[E_NO_MATCHING_REMS]);
		    }
		    PopFile();
		    return E_NO_MATCHING_REMS;
		}
		while(i->chain) {
		    fc = i->chain;
		    i->chain = i->chain->next;

		    /* Munch first file */
		    oldRunDisabled = RunDisabled;
		    if (!OpenFile(fc->filename)) {
			return OK;
		    }
		    Eprint("%s: %s", ErrMsg[E_CANT_OPEN], fc->filename);
		    RunDisabled = oldRunDisabled;
		}
		/* Couldn't open anything... bail */
		return PopFile();
	    } else {
		if (!Hush) {
		    Eprint("%s: %s", fname, ErrMsg[E_NO_MATCHING_REMS]);
		}
	    }
	    return E_NO_MATCHING_REMS;
	}
    }
#endif

    oldRunDisabled = RunDisabled;
    /* Try to open the new file */
    if (!OpenFile(fname)) {
	return OK;
    }
    RunDisabled = oldRunDisabled;
    Eprint("%s: %s", ErrMsg[E_CANT_OPEN], fname);
    /* Ugh!  We failed!  */
    PopFile();
    return E_CANT_OPEN;
}
示例#10
0
int
PLP_page( )
{
int lvp, first;
char attr[NAMEMAXLEN], *line, *lineval;

char buf[512], devval[20];
char *outfilename, *mapfilename, *titledet, *pagetitle, *url;
int stat, nt, align, nlines, maxlen, landscapemode, dobackground, dopagebox, pagesizegiven, clickmap_enabled_here, tight, map;
double adjx, adjy, scalex, scaley, sx, sy;

TDH_errprog( "pl proc page" );

/* initialize */
landscapemode = PLS.landscape; /* from command line */
titledet = "";
outfilename = "";
mapfilename = "";
pagetitle = "";
dobackground = 1;
dopagebox = 1;
if( GL_member( PLS.device, "gesf" )) dopagebox = 0; /* bounding box shouldn't include entire page for gif , eps */
if( PLS.device == 'e' ) dobackground = 0; 
pagesizegiven = 0;
strcpy( devval, "" );
scalex = scaley = 1.0;
clickmap_enabled_here = 0;

/* get attributes.. */
first = 1;
while( 1 ) {
        line = getnextattr( first, attr, &lvp );
        if( line == NULL ) break;
        first = 0;
        lineval = &line[lvp];


	/* if an attribute is given on command line, it overrides anything here.. */
	if( GL_slmember( attr, PLS.cmdlineparms )) continue;
	if( strcmp( attr, "landscape" )==0 && GL_slmember( "portrait", PLS.cmdlineparms )) continue;
	if( strcmp( attr, "outfilename" )==0 && GL_slmember( "o", PLS.cmdlineparms )) continue;

	if( strcmp( attr, "landscape" )==0 ) landscapemode = getyn( lineval );
	else if( strcmp( attr, "title" )==0 ) pagetitle = getmultiline( lineval, "get" ); 
	else if( strcmp( attr, "titledetails" )==0 ) titledet = lineval;
	else if( strcmp( attr, "color" )==0 ) tokncpy( Estandard_color, lineval, COLORLEN );
	else if( strcmp( attr, "scale" )==0 ) { 
		nt = sscanf( lineval, "%lf %lf", &scalex, &scaley ); 
		if( nt == 1 ) scaley = scalex; 
		}
	else if( strcmp( attr, "backgroundcolor" )==0 ) {
		tokncpy( Estandard_bkcolor, lineval, COLORLEN );
		Ebackcolor( Estandard_bkcolor );
		dobackground = 1; /* added scg 9/27/99 */
		}
	else if( strcmp( attr, "linewidth" )==0 ) Estandard_lwscale = ftokncpy( lineval );
	else if( strcmp( attr, "textsize" )==0 ) Estandard_textsize = itokncpy( lineval );
	else if( strcmp( attr, "font" )==0 ) tokncpy( Estandard_font, lineval, FONTLEN );
	else if( strcmp( attr, "dobackground" )==0 ) dobackground = getyn( lineval );
	else if( strcmp( attr, "dopagebox" )==0 ) dopagebox = getyn( lineval );
	else if( strcmp( attr, "tightcrop" )==0 ) { tight = getyn( lineval ); Etightbb( tight ); }
	else if( strncmp( attr, "crop", 4 )==0 ) {
		double cropx1, cropy1, cropx2, cropy2;
		nt = sscanf( lineval, "%lf %lf %lf %lf", &cropx1, &cropy1, &cropx2, &cropy2 );
		if( nt != 4 ) Eerr( 2707, "usage: crop x1 y1 x2 y2 OR croprel left bottom right top", "" );
		else {
			if( PLS.usingcm ) { cropx1 /= 2.54; cropy1 /= 2.54; cropx2 /= 2.54; cropy2 /= 2.54; }
			if( strcmp( attr, "croprel" )==0 ) Especifycrop( 2, cropx1, cropy1, cropx2, cropy2 ); /* relative to tight */
			else Especifycrop( 1, cropx1, cropy1, cropx2, cropy2 ); /* absolute */
			}
		}

	else if( strcmp( attr, "pixsize" ) ==0 ) {  /* added scg 1/9/08 */
		int reqwidth, reqheight;
		nt = sscanf( lineval, "%d %d", &reqwidth, &reqheight );
		if( nt != 2 ) Eerr( 57233, "pixsize ignored.. it requires width and height (in pixels)", "" );
#ifndef NOGD
        	PLGG_setimpixsize( reqwidth, reqheight );
#endif
        	if( PLS.device != 'g' ) Eerr( 24795, "pixsize ignored.. it's only applicable when generating png/gif/jpeg images", "" ); 
		}

	else if( strcmp( attr, "pagesize" )==0 ) {
		getcoords( "pagesize", lineval, &(PLS.winw), &(PLS.winh) );
		pagesizegiven = 1;
		}
	else if( strcmp( attr, "outfilename" )==0 ) {
		outfilename = lineval;
		if( strlen( outfilename ) > MAXPATH-1 ) { PLS.skipout = 1; return( Eerr( 57932, "outfilename too long", "" ) ); }  
		}
	else if( strncmp( attr, "mapfile", 7 )==0 ) {
		mapfilename = lineval;
		if( strlen( mapfilename ) > MAXPATH-1 ) { Eerr( 57932, "mapfile name too long", "" ); mapfilename = ""; }
		}

	else if( strcmp( attr, "clickmapdefault" )==0 ) { 
		url = lineval;
		if( strlen( url ) > MAXURL-1 ) Eerr( 57933, "clickmapdefault url too long", "" );
		else clickmap_setdefaulturl( url ); 
		}

	else if( strcmp( attr, "map" )==0 ) { map = getyn( lineval ); if( map ) { PLS.clickmap = 1; clickmap_enabled_here = 1; }}
	else if( strcmp( attr, "csmap" )==0 ){ map = getyn( lineval ); if( map ) { PLS.clickmap = 2; clickmap_enabled_here = 1; }} 
	else if( strcmp( attr, "outlabel" )==0 ) Esetoutlabel( lineval );
	else Eerr( 1, "page attribute not recognized", attr );
	}



/* -------------------------- */
/* Page break logic.. */
/* -------------------------- */
if( PLS.npages == 0 ) {

	/* following 3 lines moved here from above - also replicated below.  scg 10/31/00 */
	if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley );
	Egetglobalscale( &sx, &sy );
	if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy );
	else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */

	/* clickmap (must come before init for eg. svg - scg 2/7/05) */
	if( clickmap_enabled_here ) {
		if( mapfilename[0] == '\0' ) {
        		if( PLS.clickmap == 2 ) strcpy( PLS.mapfile, "stdout" );  /* csmap defaults to stdout..  scg 8/26/04  */
        		else if( PLS.outfile[0] != '\0' ) makeoutfilename( PLS.outfile, PLS.mapfile, 'm', 1);
        		else strcpy( PLS.mapfile, "unnamed.map" );
        		}
		PL_clickmap_init();
#ifndef NOSVG
		/* must update this now too.. scg 2/7/05  */
		if( PLS.device == 's' ) PLGS_setparms( PLS.debug, PLS.tmpname, PLS.clickmap );
#endif
		}
	else if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename ); /* PPP */

	/* initialize and give specified output file name .. */
	if( outfilename[0] != '\0' ) Esetoutfilename( outfilename );
	stat = Einit( PLS.device );
	if( stat ) { PLS.skipout = 1; return( stat ); }

	/* set paper orientation */
	if( landscapemode ) Epaper( 1 );

	}


else if( PLS.npages > 0 ) {

	if( GL_member( PLS.device, "gesf" )) {

		/* finish up current page before moving on to next one.. */
		Eshow();
		stat = Eendoffile();
		if( stat ) return( stat );

		/* now set file name for next page.. */
		if( outfilename[0] != '\0' ) Esetoutfilename( outfilename );
		else	{
			makeoutfilename( PLS.outfile, buf, PLS.device, (PLS.npages)+1 );
			if( PLS.debug ) fprintf( PLS.diagfp, "Setting output file name to %s\n", PLS.outfile );
			Esetoutfilename( buf );
			}

		if( PLS.clickmap ) {
			/* initialize a new click map file.. */
			if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename );
			else makeoutfilename( PLS.outfile, PLS.mapfile, 'm', (PLS.npages)+1 );
			PL_clickmap_init();

			}


		/* perhaps set global scaling and/or page size for next page.. */
		/* following 3 lines copied here from above - scg 10/31/00 */
		if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley );
		Egetglobalscale( &sx, &sy ); 
		if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy );
		else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */

		/* initialize next page.. */
		stat = Einit( PLS.device );
		if( stat ) return( stat );
		}

	else if ( PLS.device == 'x' ) PL_do_x_button( "More.." );

	else if ( GL_member( PLS.device, "pc" ) ) {
		Eprint();
		if( landscapemode ) Epaper( 1 ); /* added scg 2/29/00 */
		Elinetype( 0, 0.6, 1.0 );   /* added scg 9/20/99 */
		}
	}
(PLS.npages)++;


/* -------------------------- */
/* now do other work.. */
/* -------------------------- */


/* do background.. */
/* if( dopagebox ) Ecblock( 0.0, 0.0, EWinx, EWiny, Ecurbkcolor, 0 ); */ /* does update bb */
if( dopagebox ) Ecblock( 0.0, 0.0, PLS.winw, PLS.winh, Ecurbkcolor, 0 ); /* does update bb */
else if( dobackground ) {
	/* EPS color=transparent - best to do nothing.. */
        if( PLS.device == 'e' && strcmp( Ecurbkcolor, "transparent" )==0 ) ;

        else Eclr(); /* doesn't update bb */
	}

if( pagetitle[0] != '\0' ) {
	textdet( "titledetails", titledet, &align, &adjx, &adjy, 3, "B", 1.0 );
	if( align == '?' ) align = 'C';
	measuretext( pagetitle, &nlines, &maxlen );
	if( align == 'L' ) Emov( 1.0 + adjx, (PLS.winh-0.8) + adjy );
	else if ( align == 'C' ) Emov( (PLS.winw / 2.0 ) + adjx, (PLS.winh-0.8) + adjy );
	else if( align == 'R' ) Emov( (PLS.winw-1.0) + adjx, (PLS.winh-0.8) + adjy );
	Edotext( pagetitle, align );
	}

return( 0 );
}
示例#11
0
文件: calendar.c 项目: hoijui/Remind
static void GenerateCalEntries(int col)
{
    int r;
    Token tok;
    char const *s;
    Parser p;

/* Do some initialization first... */
    ClearGlobalOmits();
    DestroyOmitContexts();
    DestroyVars(0);
    NumTriggered = 0;

    r=IncludeFile(InitialFile);
    if (r) {
	fprintf(ErrFp, "%s %s: %s\n", ErrMsg[E_ERR_READING], InitialFile, ErrMsg[r]);
	exit(1);
    }

    while(1) {
	r = ReadLine();
	if (r == E_EOF) return;
	if (r) {
	    Eprint("%s: %s", ErrMsg[E_ERR_READING], ErrMsg[r]);
	    exit(1);
	}
	s = FindInitialToken(&tok, CurLine);

	/* Should we ignore it? */
	if (NumIfs &&
	    tok.type != T_If &&
	    tok.type != T_Else &&
	    tok.type != T_EndIf &&
	    tok.type != T_IfTrig &&
	    ShouldIgnoreLine())
	{
	    /* DO NOTHING */
	}
	else {
	    /* Create a parser to parse the line */
	    CreateParser(s, &p);

	    switch(tok.type) {

	    case T_Empty:
	    case T_Comment:
		break;

	    case T_ErrMsg:  r=DoErrMsg(&p);  break;
	    case T_Rem:     r=DoCalRem(&p, col); break;
	    case T_If:      r=DoIf(&p);      break;
	    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_Exit:    DoExit(&p);	     break;
	    case T_Set:     r=DoSet(&p);     break;
	    case T_Fset:    r=DoFset(&p);    break;
	    case T_UnSet:   r=DoUnset(&p);   break;
	    case T_Clr:     r=DoClear(&p);   break;
	    case T_Flush:   r=DoFlush(&p);   break;
	    case T_Debug:   break;  /* IGNORE DEBUG CMD */
	    case T_Dumpvars: break; /* IGNORE DUMPVARS CMD */
	    case T_Banner:  break;  /* IGNORE BANNER CMD */
	    case T_Omit:    r=DoOmit(&p);
		if (r == E_PARSE_AS_REM) {
		    DestroyParser(&p);
		    CreateParser(s, &p);
		    r=DoCalRem(&p, col);
		}
		break;
	    case T_Pop:     r=PopOmitContext(&p);     break;
	    case T_Push:    r=PushOmitContext(&p);    break;
	    case T_Preserve: r=DoPreserve(&p);        break;
	    case T_RemType: if (tok.val == RUN_TYPE) {
		r=DoRun(&p);
		break;
	    } else {
		CreateParser(CurLine, &p);
		r=DoCalRem(&p, col);
		break;
	    }

	    /* If we don't recognize the command, do a REM by default */
	    /* Note:  Since the parser hasn't been used yet, we don't */
	    /* need to destroy it here. */

	    default:        CreateParser(CurLine, &p);
		r=DoCalRem(&p, col);
		break;
	    }
	    if (r && (!Hush || r != E_RUN_DISABLED)) Eprint("%s", ErrMsg[r]);

	    /* Destroy the parser - free up resources it may be tying up */
	    DestroyParser(&p);
	}
    }
}