Пример #1
0
static inline void
fetch_Lookup (int i)
{
  FT_ULong Lookup_ptr = Lookup_List[i].ptr;

  if (Lookup_ptr && !Lookup_List[i].entry)
  {
    Lookup_Item *entry = Lookup_List[i].entry = mycalloc (1, sizeof(Lookup_Item));
    Boolean is_ext = False;
    FT_UShort val;
    int j;

#ifdef  DEBUG
    warning("Lookup[%d] at 0x%04x.", i, Lookup_ptr);
#endif
    GSUB_ptr = Lookup_ptr;

    /*
     *   Read Lookup Item
     */
    need(6);
    val = get_UShort();
    if (val == 7)
      is_ext = True;
    else if (val != 1)
      oops("Lookup[%d] at 0x%04x: bad Type=%d.", i, Lookup_ptr, val);
    get_UShort(); /* Ignore Lookup Flag */
    entry->count = get_UShort();
    entry->list = mycalloc (entry->count, sizeof(Single_Item));

    need(2 * entry->count);
    for (j = 0; j < entry->count; j++)
      entry->list[j].ptr = Lookup_ptr + get_UShort();

    if (is_ext)
      for (j = 0; j < entry->count; j++)
      {
        GSUB_ptr = entry->list[j].ptr;
        need(8);
        val = get_UShort();
        if (val != 1)
          oops("Lookup[%d] Extension[%d] at 0x%04x: bad Format=%d.", i, j, entry->list[j].ptr, val);
        val = get_UShort();
        if (val != 1)
          oops("Lookup[%d] Extension[%d] at 0x%04x: bad Type=%d.", i, j, entry->list[j].ptr, val);
        entry->list[j].ptr += get_ULong();
      }

    for (j = 0; j < entry->count; j++)
      fetch_Single (&entry->list[j]);
  }
}
Пример #2
0
void process_fill()
{
    char sz = 'b';
    int64_t count;
    int64_t val;
    int64_t nn;

    if (*inptr=='.') {
        inptr++;
        if (strchr("bchwBCHW",*inptr)) {
            sz = tolower(*inptr);
            inptr++;
        }
        else
            printf("Illegal fill size.\r\n");
    }
    SkipSpaces();
    NextToken();
    count = expr();
    prevToken();
    need(',');
    NextToken();
    val = expr();
    prevToken();
    for (nn = 0; nn < count; nn++)
        switch(sz) {
        case 'b': emitByte(val); break;
        case 'c': emitChar(val); break;
        case 'h': emitHalf(val); break;
        case 'w': emitWord(val); break;
        }
}
Пример #3
0
void dirDEFPAGE(string &line, RawSource *) {
  int firstpage, lastpage, org, size, val;
  if (!ParseExpression(line,firstpage)) { error("Syntax error",ERRREP); return; }
  if (labelnotfound) error("Forward reference");
  if (firstpage<0 || firstpage>255) { error("Illegal pagenumber"); return; }
  if (need(line,"..")) {
    if (!ParseExpression(line,lastpage)) { error("Syntax error",ERRREP); return; }
    if (labelnotfound) error("Forward reference");
    if (lastpage<0 || firstpage>lastpage) { error("Illegal pagenumber"); return; }
  } else lastpage=firstpage;
  if (comma(line)) {
      if (sbcneed(line,'*')) {
        val=-1;
      } else {
        if (!ParseExpression(line,val)) { error("Syntax error",ERRREP); return; }
        if (labelnotfound) error("Forward reference");
        if (val<0) { val=0; error("Negative origin"); }
      }
    prevorg=val;
    if (comma(line)) {
      if (sbcneed(line,'*')) {
        val=-1;
      } else {
        if (!ParseExpression(line,val)) { error("Syntax error",ERRREP); return; }
        if (labelnotfound) error("Forward reference");
        if (val<0) { val=0; error("Negative size"); }
      }
      prevsize=val;
    }
  }
  org=prevorg; size=prevsize;
  for (val=firstpage;val<=lastpage;++val) output[onr]->defpage(val,org,size);
  checkjunk(line);
}
Пример #4
0
 string minWindow(string s, string t) {
     int m = s.size(), n = t.size();
     vector<int> need(128,0);
     for(char c : t) ++need[c];
     int needCnt = n;
     vector<int> have(128,0);
     int idx = 0;
     int minLen = m + 1;
     string res;
     for(int i = 0, startIdx = 0; i < m; ++i)
     {
         char c = s[i];
         ++have[c];
         if(have[c] <= need[c]) --needCnt;
         while(needCnt == 0)
         {
             if(i - startIdx + 1 < minLen)
             {
                 idx = startIdx;
                 minLen = i - startIdx + 1;
             }
             char c = s[startIdx];
             --have[c];
             if(have[c] < need[c]) ++needCnt;
             ++startIdx;
         }
     }
     return minLen == m + 1 ? "" : s.substr(idx, minLen);
 }
Пример #5
0
static inline FT_UShort
fetch_Coverage (Coverage_Item *coverage)
{
  FT_UShort res = 0;
  GSUB_ptr = coverage->ptr;
  need(4);
  coverage->format = get_UShort();
  coverage->count = res = get_UShort();
  switch (coverage->format)
  {
    case 1:
      coverage->data.glyphs = mymalloc (res * sizeof(FT_UShort));
#ifdef  DEBUG
      warning("Coverage Format=1 with %d Glyphs at 0x%04x.", res, coverage->ptr);
#endif
      fetch_Glyphs (res, coverage->data.glyphs);
      break;
    case 2:
      coverage->data.ranges = mymalloc (res * sizeof(Range_Record));
#ifdef  DEBUG
      warning("Coverage Format=1 with %d Ranges at 0x%04x.", res, coverage->ptr);
#endif
      res = fetch_Ranges (res, coverage->data.ranges);
      break;
    default:
      oops("Coverage at 0x%04x: bad Format=%d.", coverage->ptr, coverage->format);
  }
  return res;
}
Пример #6
0
/*
 * addbcf() adds a bytecoded font control character to a rendered page
 */
void
addbcf(char c)
{
    linestart();
    need(2);
    PAGE[PAGELEN++] = bcfID;
    PAGE[PAGELEN++] = c;
}
Пример #7
0
void
fmt_build(stringvec_t *v, int len, char *fmt, ...) {
	va_list ap;
	need(v, len);
	va_start(ap, fmt);
	v->off += fmt_vsfmt(&(v->base)[v->off], len, fmt, ap);
	va_end(ap);
}
Пример #8
0
/*
**  READ_ARG -- Read a single argument from pipe
**
**	An argument can be as simple as an integer, or as complex
**	as a query tree.
**
**	Parameters:
**		ppb -- the pipe block to read from.
**		pparm -- the parameter descripter to put the
**			argument in.
**
**	Returns:
**		none.
**
**	Side Effects:
**		May allocate space from Qbuf for trees, etc.
**
**	Called By:
**		readinput
**
**	Trace Flags:
**		10.6 - 10.7
*/
int
read_arg(register pb_t *ppb, register paramv_t *pparm)
{
	char	ptype;
	short	plen;
	register int	i;
	register char	*p;
	qtree_t		*q;

	/* get the parameter type */
	i = pb_get(ppb, &ptype, 1);
	if (i == 0) {
		pparm->pv_type = PV_EOF;
		pparm->pv_val.pv_str = NULL;
		return (PV_EOF);
	}
	i = pb_get(ppb, (char *) &plen, 2);
	if (i < 2)
		syserr("readarg: pb_get %d", i);

	/* figure out the type */
	switch (ptype) {
	  case PV_INT:
#ifdef xCM_DEBUG
		if (plen != sizeof(pparm->pv_val.pv_int))
			syserr("readinput: PV_INT %d", plen);
#endif
		pb_get(ppb, (char *) &pparm->pv_val.pv_int, plen);
		break;

	  case PV_STR:
	  case PV_TUPLE:
		p = need(Qbuf, plen);
		pb_get(ppb, p, plen);
		pparm->pv_val.pv_str = p;
		break;

	  case PV_QTREE:
		q = readqry(pb_get, (int) ppb, TRUE);
		pparm->pv_val.pv_qtree = q;
		break;

	  case PV_EOF:
		/* this case is allowed for the mon-par interface */
		break;

	  default:
		syserr("readinput: type %d len %d", ptype, plen);
	}

	/* save the type & length */
	pparm->pv_type = ptype;
	pparm->pv_len = plen;

	return (ptype);
}
Пример #9
0
static inline void
fetch_Single (Single_Item *item)
{
  int i;
  FT_UShort val;

  item->coverage = mycalloc (1, sizeof(Coverage_Item));
  GSUB_ptr = item->ptr;
  need(6);
  item->format = get_UShort();
  item->coverage->ptr = item->ptr + get_UShort();
  switch (item->format)
  {
    case 1:
      val = get_Short();
      item->data.delta = mycalloc (1, sizeof(FT_UShort));
      *item->data.delta = val;
#ifdef  DEBUG
      warning("Single Substitution Format=1 with Delta=%d at 0x%04x.", val, item->ptr);
#endif
      fetch_Coverage (item->coverage);
      break;
    case 2:
      val = get_UShort();
      need(2 * val);
      item->data.array = mycalloc (1, sizeof(Glyph_Array));
      item->data.array->count = val;
      item->data.array->glyphs = mycalloc (val, sizeof(FT_UShort));
      for (i = 0; i < val; i++)
        item->data.array->glyphs[i] = get_UShort();
#ifdef  DEBUG
      warning("Single Substitution Format=2 with %d Glyphs at 0x%04x.", val, item->ptr);
#endif
      val = fetch_Coverage (item->coverage);
      if (val != item->data.array->count)
        oops("Coverage at 0x%04x: covers %d glyphs (should be %d).", item->ptr, val, item->data.array->count);
      break;
    default:
      oops("Single Substitution at 0x%04x: bad Format=%d.", item->ptr, item->format);
  }
  
  add_Single (item);
}
Пример #10
0
void BioStruct3DSettingsDialog::setGlassesColorScheme(int num)
{
    if (num<=0 || num>glassesColorSchemes.size())
        return;

    GlassesColorScheme need(glassesColorSchemes.at(num));

    setLeftEyeColor(need.leftEyeColor);
    setRightEyeColor(need.rightEyeColor);
}
Пример #11
0
 int calculateMinimumHP(vector<vector<int>>& dungeon) {
     int row = dungeon.size(), col = dungeon[0].size();
     vector<int> need(col+1, INT_MAX);
     need[col-1] = 1;
     for (int i = row - 1; i >= 0; i--) {
         for (int j = col - 1; j >= 0; j--) {
             need[j] = max(1, min(need[j], need[j+1]) - dungeon[i][j]);
         }
     }
     return need[0];
 }
Пример #12
0
static inline void
fetch_Glyphs (FT_UShort count, FT_UShort *glyphs)
{
  int i;

  need(2 * count);
  for (i = 0; i < count; i++)
    glyphs[i]  = get_UShort();
  for (i = 1; i < count; i++)
    if (glyphs[i] <= glyphs[i - 1])
      oops("Glyph[%d]=%d and Glyph[%d]=%d: out of order.", i - 1, glyphs[i - 1], i, glyphs[i]);
}
Пример #13
0
double cRooms::getSpHeating(void)
{
	// Update dMaxDiff and dMaxSp
	need();
	
	double t1 = (TempOutside.get()/(320-4*TempOutside.get()));
	double t2 = pow(dMaxSp,t1);
	double swhk = 0.55*dsteil*t2*(-TempOutside.get()+20)*2+dMaxSp+dkh+dMaxDiff*dverst;
	double swhkLimit = min(max(swhk,dminvl),dmaxvl);
	
	return swhkLimit;
}
Пример #14
0
/*
 * addbct() is a local that actually adds a bct to a rendered page
 */
static void
addbct(char c, char *s)
{
    linestart();
    need(strlen(s)+3);

    PAGE[PAGELEN++] = bctID;
    PAGE[PAGELEN++] = c;

    while (*s)
	PAGE[PAGELEN++] = *s++;
    PAGE[PAGELEN++] = bctID;
}
Пример #15
0
static inline void
fetch_Feature (int i)
{
  FT_ULong Feature_ptr = Feature_List[i].ptr;

  if (Feature_ptr && !Feature_List[i].entry)
  {
    Feature_Item *entry = Feature_List[i].entry = mycalloc (1, sizeof(Feature_Item));  
    FT_UShort val;
    int j;

#ifdef  DEBUG
    warning("Feature[%d] '%c%c%c%c' at 0x%04x.", i, print_Tag(Feature_List[i].tag), Feature_ptr);
#endif
    GSUB_ptr = Feature_ptr;

    /*
     *   Read Feature Item
     */
    need(4);
    val = get_UShort();
    if (val)
      oops("Feature[%d] at 0x%04x: bad FeaturParams 0x%04x.", Feature_ptr, i, val);
    entry->count = get_UShort();
    entry->list = mycalloc (entry->count, sizeof(FT_UShort));

    need(2*entry->count);
    for (j = 0; j < entry->count; j++) {
      entry->list[j] = get_UShort();
      if (entry->list[j] >= Lookup_Count)
        oops("Feature[%d] at 0x%04x: bad Lookup Index[%d]=%d.", i, Feature_ptr, j, entry->list[j]);
    }

    for (j = 0; j < entry->count; j++)
      fetch_Lookup (entry->list[j]);
  }
}
Пример #16
0
 bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) {
     vector<set<int>> need(numCourses);
     vector<set<int>> go(numCourses);
     set<int>::iterator it;
     set<int>::iterator j;
     queue<int> ha;
     int size=prerequisites.size();
     for(int i=0;i<size;i++)
     {
         //go to go list check which class can be finish;
         int a=prerequisites[i].second,b=prerequisites[i].first;
         go[a].insert(b);
         need[b].insert(a);
     }
     for(int i=0;i<numCourses;i++)
     {
         if(need[i].size()==0)
         {
             ha.push(i);
         }
     }
     while(!ha.empty())
     {
         int index=ha.front();
         for(j=go[index].begin();j!=go[index].end();j++)
         {
             int classes=*j;
             it=need[classes].find(index);
             if(it!=need[classes].end())
                 need[classes].erase(it);
             if(need[classes].size()==0)
             {
                 ha.push(classes);
             }
         }
         ha.pop();
     }
     for(int i=0;i<numCourses;i++)
     {
         if(need[i].size()!=0)
         {
             return false;
         }
     }
     return true;
 }
Пример #17
0
void cRooms::getData( JsonObject& root )
{
	JsonArray& RoomsIsTemps = root.createNestedArray("RTi");
	JsonArray& RoomsSPTemps = root.createNestedArray("RTs");
	
	for (int i = 0; i<nRooms;i++){
		RoomsIsTemps.add(Room[i].IsTemp.get());
		RoomsSPTemps.add(Room[i].getSpTemp());
	}
	
	root["Toutside"] = TempOutside.get();
	root["Rn"] = need();
	root["RTsHeating"] = getSpHeating();
	
	root["RTitoR"] = IsTempHeatingLead.get();
	root["RTitoSys"] = IsTempHeatingReturn.get();
	root["RP"] = Pump.get();
	root["RM"] = Mixer.get();
}
Пример #18
0
qtree_t *
makezero(int typ)
{
	register int		l;
	register qtree_t	*s;
	int			symbuf[(sizeof(*s)) / sizeof(l)];
				/*word aligned*/

	l = 0;
	s = (qtree_t *) symbuf;
	s->sym.type = typ;

	switch (typ) {
	  case INT_CONST:
		s->sym.len = l = 2;
		s->sym.value.sym_data.i2type = 0;
		break;

	  case FLOAT_CONST:
		s->sym.len = l = 4;
		s->sym.value.sym_data.f4type = 0.0;
		break;

	  case CHAR_CONST:
		s->sym.len = l = 2;
		memset(&s->sym.value.sym_data.i2type, ' ', 2);	/* (2 spaces) */
		break;

	  default:
		syserr("makezero: typ %d", typ);
	}

	/* duplicate the node into Qbuf */
	l += 2 + 2 * QT_HDR_SIZ;	/* size of type + len + left + right */
	s = (qtree_t *) need(Qbuf, l);
	bmove(symbuf, s, l);
	return (s);
}
Пример #19
0
void
runout(void)
{
int i;
if (boxflg || allflg || dboxflg) need();
if (ctrflg)
	{
	fprintf(tabout, ".nr #I \\n(.i\n");
	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
	}
fprintf(tabout, ".fc %c %c\n", F1, F2);
fprintf(tabout, ".nr #T 0-1\n");
deftail();
for(i=0; i<nlin; i++)
	putline(i,i);
if (leftover)
	yetmore();
fprintf(tabout, ".fc\n");
fprintf(tabout, ".nr T. 1\n");
fprintf(tabout, ".T# 1\n");
if (ctrflg)
	fprintf(tabout, ".in \\n(#Iu\n");
}
 string minWindow(string s, string t) {
     int m=s.length(), n=t.length();
     if(m<n) return "";
     vector<int> need(256, 0);   
     vector<int> has(256,0);
     for(int i=0; i<n;i++)
         need[t[i]]++;
     
     int start=0, end= 0;
     int count=0;
     int minLen=INT_MAX, minStart=0;
     for(; end< m; end++){
         if(need[s[end]] ==0 )   continue;
         if(has[s[end]]< need[s[end]])
             count++;
         has[s[end]] ++;
         if(count == n){
             while(start <= end){
                 if(need[s[start]] ==0)
                     start++;
                 else if(has[s[start]] > need[s[start]]){
                     has[s[start]]--;
                     start++;
                 }
                 else
                     break;
             }
             if(minLen > end-start+1){
                 minLen= end-start +1;
                 minStart = start;
             }
         }
     }
     if(minLen ==INT_MAX)    return "";
     return s.substr(minStart, minLen);
 }
Пример #21
0
static inline FT_UShort
fetch_Ranges (FT_UShort count, Range_Record *ranges)
{
  int i;
  FT_UShort ndx = 0;

      need(6 * count);
      for (i = 0; i < count; i++)
      {
        ranges[i].start = get_UShort();
        ranges[i].end = get_UShort();
        if (ranges[i].start > ranges[i].end)
          oops("Range[%d]: bad range=%d..%d.", i, ranges[i].start, ranges[i].end);
        ranges[i].start_Index = get_UShort();
        if (ranges[i].start_Index != ndx)
          oops("Range[%d]: bad start_Index=%d (should be %d).", i, ranges[i].start_Index, ndx);
        ndx += (ranges[i].end - ranges[i].start) + 1;
      }
      for (i = 1; i < count; i++)
        if (ranges[i].start <= ranges[i-1].end)
          oops("Range[%d]=%d..%d and Range[%d]=%d..%d: out of order.",
               i - 1, ranges[i - 1].start, ranges[i - 1].end, i, ranges[i].start, ranges[i].end);
      return ndx;
}
Пример #22
0
/*
 * addchar() adds a single character to a rendered page
 */
static void
addchar(char c)
{
    need(1);
    PAGE[PAGELEN++] = c;
}
Пример #23
0
/*******************************************************************************
This function evaluates an expression.  It is passed a pointer to an expression
node to evaluate (results are also put here), and it evaluates the expression
tree.
Note: the argument stack is used for user function calls.  Even though it looks
cumbersome, indices have been used instead of stack pointers.  This is because
this is a recursive function, and it is neccessary to save previous stack
information AND the stack is dynamically resizable - that is - it can move at
any time.  Hence, any pointers saved on previous invocations of this function
would be pointing to where the stack USED to be, not where it NOW is.
*******************************************************************************/
void
evalexpr(Exprnode *exprptr)
{
    extern Field *aggrfldtbl, *fldtbl;
    extern Opmode opmode;		/* report or selrej mode */
    extern Statsinfofld *statsinfofldtbl;
    Exprnode lresult, rresult;
    Exprptrlistnode *exprptrlistptr;
    int tmpidx, argctr, intval, savebotargstkidx;
    float floatval;

    switch (exprptr->typ) {
	case INTEGER: case FLOAT: case STRING:
	    break;
	case FIELD:
	    if (opmode == REPORTMODE) {
		if (curfldvalptrtbl[exprptr->arg.ival] == NULL) {
		    fprintf(stderr, "field `%s'", 
					    aggrfldtbl[exprptr->arg.ival].name);
		    fatalerrlin(" is referenced outside a foreach loop");
		}
		exprptr->typ = aggrfldtbl[exprptr->arg.ival].typ;
		switch (exprptr->typ) {
		    case STRING:
			exprptr->arg.sval =
				curfldvalptrtbl[exprptr->arg.ival]->arg.sval;
			break;
		    case INTEGER:
			exprptr->arg.ival =
				curfldvalptrtbl[exprptr->arg.ival]->arg.ival;
			break;
		    case FLOAT:
			exprptr->arg.fval =
				curfldvalptrtbl[exprptr->arg.ival]->arg.fval;
			break;
		    default: fatalerror("evalexpr: SNARK!");
			break;
		}
	    } else {	/* selrej mode */
		evalselrejfld(exprptr);
	    }
	    break;
	case UFNCCALLEXPR:
	    argctr = exprptr->arg.ufnc.argctr;
	    if (argstkctr + argctr > maxargstkctr) {   /* enlarge stk if nec */
		maxargstkctr = MAX(maxargstkctr*ARGSTKMULTFACTOR,
							    argstkctr+argctr);
		argstk = (Exprnode*)realloc((void*)argstk,
				    (size_t)maxargstkctr*sizeof(Exprnode));
	    }
				    /* eval all args & push them on the stk */
	    exprptrlistptr = exprptr->arg.ufnc.exprptrlistptr;
	    while (exprptrlistptr != NULL) {		/* eval all args */
		lresult = *exprptrlistptr->exprptr;
		evalexpr(&lresult);
		*(argstk+argstkctr++) = lresult;	/* & push on stk */
		exprptrlistptr = exprptrlistptr->next;
	    }

	    savebotargstkidx = botargstkidx;
	    botargstkidx = argstkctr-argctr;
	    tmpidx = exprptr->arg.ufnc.begstmtidx;	/* call user func */
	    *exprptr = doblock(tmpidx+1, stmts[tmpidx].s.ufncdef.endstmtidx);
	    argstkctr -= argctr;
	    botargstkidx = savebotargstkidx;
	    break;
	case UFNCPARAMEXPR:
	    if (botargstkidx+exprptr->arg.ival >= argstkctr)
		fatalerror(STKERRMSG);
	    *exprptr = *(&argstk[botargstkidx]+exprptr->arg.ival);
	    break;
	case UNARYOPEXPR:
	    lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    switch (lresult.typ) {
		case INTEGER:
		    exprptr->arg.ival =
				iunaryop(exprptr->arg.optyp, lresult.arg.ival);
		    break;
		case FLOAT:
		    exprptr->arg.fval =
				funaryop(exprptr->arg.optyp, lresult.arg.fval);
		    break;
		default:
		    fatalerrlin("evalexpr: unary operation on illegal type");
		    break;
	    }
	    exprptr->typ = lresult.typ;
	    break;
	case BINARYOPEXPR:
	    lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    rresult = *(exprptr->rightptr); evalexpr(&rresult);
	    if ((lresult.typ == INTEGER)&&(rresult.typ == INTEGER)) {
		exprptr->arg.ival = ibinop(lresult.arg.ival,
				    exprptr->arg.optyp, rresult.arg.ival);
		exprptr->typ = INTEGER;
	    } else if (lresult.typ == INTEGER && rresult.typ == FLOAT) {
		    if ((exprptr->typ=fbinop((float)lresult.arg.ival,
				exprptr->arg.optyp, rresult.arg.fval,
				&floatval, &intval)) == FLOAT)
		    exprptr->arg.fval = floatval;
		else
		    exprptr->arg.ival = intval;
	    } else if (lresult.typ == FLOAT && rresult.typ == INTEGER) {
		    if ((exprptr->typ=fbinop(lresult.arg.fval,
				exprptr->arg.optyp, (float)rresult.arg.ival,
				&floatval, &intval)) == FLOAT)
		    exprptr->arg.fval = floatval;
		else
		    exprptr->arg.ival = intval;
	    } else if (lresult.typ == FLOAT && rresult.typ == FLOAT) {
		    if ((exprptr->typ=fbinop(lresult.arg.fval,
				exprptr->arg.optyp, rresult.arg.fval,
				&floatval, &intval)) == FLOAT)
		    exprptr->arg.fval = floatval;
		else
		    exprptr->arg.ival = intval;
	    } else if (lresult.typ == STRING && rresult.typ == STRING) {
		sbinop(lresult.arg.sval, rresult.arg.sval, exprptr);
	    } else {
		fatalerrlin( "evalexpr: illegal binary op argument type(s)");
	    }
	    break;
	case COUNT:
	    if (exprptr->arg.tdbfnc.maxdepth != INVALIDFLDIDX) {
		chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
		exprptr->arg.ival = getcount(datarootptr,
					    exprptr->arg.tdbfnc.fldbits, 0,
					    exprptr->arg.tdbfnc.maxdepth);
	    } else {
		exprptr->arg.ival = getcount(datarootptr,
					    exprptr->arg.tdbfnc.fldbits, 0, 0);
	    }
	    exprptr->typ = INTEGER;
	    break;
	case NUMBER:
	    chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
	    exprptr->arg.ival = getnumber(datarootptr,
		    exprptr->arg.tdbfnc.fldbits,
		    exprptr->arg.tdbfnc.depth, exprptr->arg.tdbfnc.maxdepth);
	    exprptr->typ = INTEGER;
	    break;
	case SUM:
	    intval = statsinfofldtbl[exprptr->arg.tdbfnc.depth].typ;
	    switch (intval) {
		case INTEGER:
		    if (exprptr->arg.tdbfnc.maxdepth != INVALIDFLDIDX) {
			chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
			exprptr->arg.ival = getintsum(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						exprptr->arg.tdbfnc.maxdepth,
						exprptr->arg.tdbfnc.depth);
		    } else {
			exprptr->arg.ival = getintsum(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						0, exprptr->arg.tdbfnc.depth);
		    }
		    break;
		case FLOAT:
		    if (exprptr->arg.tdbfnc.maxdepth != INVALIDFLDIDX) {
			chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
			exprptr->arg.fval = getfltsum(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						exprptr->arg.tdbfnc.maxdepth,
						exprptr->arg.tdbfnc.depth);
		    } else {
			exprptr->arg.fval = getfltsum(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						0, exprptr->arg.tdbfnc.depth);
		    }
		    break;
		default:
		    fatalerrlin("evalexpr: illegal SUM field type");
		    break;
	    }
	    exprptr->typ = intval;


	    break;
	case SUMSQRD:
	    intval = statsinfofldtbl[exprptr->arg.tdbfnc.depth].typ;
	    switch (intval) {
		case INTEGER:
		    if (exprptr->arg.tdbfnc.maxdepth != INVALIDFLDIDX) {
			chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
			exprptr->arg.ival = getintsumsqrd(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						exprptr->arg.tdbfnc.maxdepth,
						exprptr->arg.tdbfnc.depth);
		    } else {
			exprptr->arg.ival = getintsumsqrd(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						0, exprptr->arg.tdbfnc.depth);
		    }
		    break;
		case FLOAT:
		    if (exprptr->arg.tdbfnc.maxdepth != INVALIDFLDIDX) {
			chk4badflds(exprptr->arg.tdbfnc.fldbits,
						exprptr->arg.tdbfnc.maxdepth);
			exprptr->arg.fval = getfltsumsqrd(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						exprptr->arg.tdbfnc.maxdepth,
						exprptr->arg.tdbfnc.depth);
		    } else {
			exprptr->arg.fval = getfltsumsqrd(datarootptr,
						exprptr->arg.tdbfnc.fldbits, 0,
						0, exprptr->arg.tdbfnc.depth);
		    }
		    break;
		default:
		    fatalerrlin("evalexpr: illegal SUM field type");
		    break;
	    }
	    exprptr->typ = intval;


	    break;
	case TYPE:
	    lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    switch (lresult.typ) {
		case INTEGER:		/* we've got an integer, make a ... */
		    if (exprptr->arg.casttyp == FLOAT) {
			exprptr->arg.fval = (float)lresult.arg.ival;
			exprptr->typ = FLOAT;
		    } else {		/* an integer */
			exprptr->arg.ival = lresult.arg.ival;
			exprptr->typ = INTEGER;
		    }
		    break;
		case FLOAT:		/* we've got a float, make an ... */
		    if (exprptr->arg.casttyp == FLOAT) {
			exprptr->arg.fval = lresult.arg.fval;
			exprptr->typ = FLOAT;
		    } else {		/* an integer */
			exprptr->arg.ival = (int)lresult.arg.fval;
			exprptr->typ = INTEGER;
		    }
		    break;
		default:
		    fatalerrlin("evalexpr: illegal type cast");
		    break;
	    }
	    break;
	case REPORTDT:			/* get the report date or time */
            exprptr->arg.ival = getreportdt(exprptr->arg.ival);
            exprptr->typ = INTEGER;
	    break;
	case FORMATDT:			/* format a date or time */
            lresult = *(exprptr->leftptr);  evalexpr(&lresult);
            rresult = *(exprptr->rightptr); evalexpr(&rresult);
            exprptr->arg.sval = formatdt(exprptr->arg.ival, &lresult, &rresult);
            exprptr->typ = STRING;
	    break;
        case STRFUNCEXPR:
            strfunc(exprptr);
	    break;
	case ATOI:
            lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    if (lresult.typ != STRING)
		fatalerrlin("evalexpr: atoi of non-string expression");
            exprptr->arg.ival = atoi(lresult.arg.sval);
            exprptr->typ = INTEGER;
	    break;
	case ATOF:
            lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    if (lresult.typ != STRING)
		fatalerrlin("evalexpr: atof of non-string expression");
            exprptr->arg.fval = (float) atof(lresult.arg.sval);
            exprptr->typ = FLOAT;
	    break;
	case MATHFUNC:
	    lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    switch (lresult.typ) {
		case INTEGER:
		    exprptr->arg.fval =
			mathfunc(exprptr->arg.optyp, (double)lresult.arg.ival);
		    break;
		case FLOAT:
		    exprptr->arg.fval =
			mathfunc(exprptr->arg.optyp, (double)lresult.arg.fval);
		    break;
		default:
		    fatalerrlin("evalexpr: math function on illegal type");
		    break;
	    }
	    exprptr->typ = FLOAT;
	    break;
	case ARRAYVAREXPR:
	    evalarrvar(exprptr);
	    break;
	case NEED:
	    lresult = *(exprptr->leftptr);  evalexpr(&lresult);
	    exprptr->typ = INTEGER;
	    exprptr->arg.ival = need(&lresult);
	    break;
	case UNDEFVAREXPR:
	    fprintf(stderr, "evalexpr: variable `%s'",exprptr->varptr->name);
	    fatalerrlin(" is undefined");
	    break;
	case NORETVALEXPR:
	    fatalerrlin("function returns no value (one is required)");
	    break;
	default:
	    fatalerrlin("evalexpr: illegal expr type");
	    break;
    }
}
Пример #24
0
int pregetmacro(string &line, bool icase, RawSource *rs, bool list, bool recursive) {
    Macro mac;
    mac._list=list;
    mac._recursive=recursive;
    string d,name=getid(line);
    if (name.empty()) {
        error1("Illegal macroname");
        return 0;
    }
    while('>') {
        skipblanks(line);
        if (!line[0]) break;
        if (isalpha(line[0])) {
            d=getid(line);
            mac._namParam.push_back(d);
            if (sbcneed(line,'+')) mac._greedy=true;
            if (sbcneed(line,':')) {
                d=getargument(line,mac._greedy);
            } else d="\01";
            mac._namDefaults.push_back(d);
            if (mac._greedy) break;
            if (comma(line)) continue;
            break;
        }
        if (isdigit(line[0])) {
            if (!getConstant(line,mac._minnum)) {
                error1("constant expected");
                return 0;
            }
            if (need(line,"..")) {
                skipblanks(line);
                if (sbcneed(line,'*'))
                    mac._maxnum=BIGVALUE;
                else {
                    if (!getConstant(line,mac._maxnum)) {
                        error1("constant expected");
                        return 0;
                    }
                }
            } else mac._maxnum=mac._minnum;
            if (mac._minnum<0 || mac._maxnum<mac._minnum) {
                error1("Illegal parameter");
                return 0;
            }
            if (sbcneed(line,'+'))
                if (mac._maxnum<BIGVALUE) mac._greedy=true;
                else error1("No greedy stars allowed!");
            break;
        }
        if (sbcneed(line,'*')) {
            mac._minnum=0;
            mac._maxnum=BIGVALUE;
            if (sbcneed(line,'+')) error1("No greedy stars allowed!");
            break;
        }
        error1("Syntax error");
        break;
    }
    if (mac._maxnum>mac._minnum && line[0]) {
        int i=mac._maxnum-mac._minnum;
        bool gr=false;
        while (i--) {
            if (!line[0]) break;
            if (!i) gr=mac._greedy;
            d=getargument(line,gr);
            mac._numDefaults.push_back(d);
        }
    }
    if (mac._minnum)
        mac._minparam=(int)mac._namParam.size()+mac._minnum;
    else {
        int i=(int)mac._namParam.size();
        mac._minparam=0;
        while (i--) if (mac._namDefaults[i]=="\01") {
                mac._minparam=i+1;
                break;
            }
    }
    if (mac._greedy || mac._maxnum==BIGVALUE) mac._maxparam=BIGVALUE;
    else mac._maxparam=(int)mac._namParam.size()+mac._maxnum;
    if (listopt._macroname.empty()) mac._line=curlin;
    else mac._line=listopt._macrocurlin;
    mac._filename=listopt._filename;
    mac._body=rs->ReadUntil(macronl,macroel,"macro");
    if (!listopt._macroname.empty()) listopt._macrocurlin+=(int)mac._body.size()+1;
    mactab.add(name,icase,mac);
    return 1;
}
Пример #25
0
static inline void
fetch_GSUB (void)
{
  FT_Error error;
  int i, j;

  FT_ULong Script_List_ptr, Feature_List_ptr, Lookup_List_ptr;

  /*
   *   Fetch GSUB table
   */
  if ((error = FT_Load_Sfnt_Table(face, TTAG_GSUB, 0, NULL, &GSUB_length)))
  {
#ifdef  DEBUG
    warning("No GSUB data available for vertical glyph presentation forms.");
#endif
    return;
  }
  GSUB_table = mymalloc(GSUB_length);
  if ((error = FT_Load_Sfnt_Table(face, TTAG_GSUB, 0, GSUB_table, &GSUB_length)))
  {
    warning("Cannot load GSUB table (error code = 0x%x).", error);
    return;
  }

  /*
   *   Read GSUB header
   */
  need(10);
  if (get_ULong() != 0x00010000)
    oops("GSUB: Bad version.");
  Script_List_ptr = get_UShort();
  Feature_List_ptr = get_UShort();
  Lookup_List_ptr = get_UShort();

  /*
   *   Read Script_List
   */
  GSUB_ptr = Script_List_ptr;
  need(2);
  Script_Count = get_UShort();
#ifdef  DEBUG
  warning("GSUB: Script List with %d entries at 0x%04x.", Script_Count, Script_List_ptr);
#endif
  Script_List = mycalloc (Script_Count, sizeof(Script_Record));

  need (6 * Script_Count);
  for (i = 0; i < Script_Count; i++)
  {
    FT_Tag tag = get_ULong();
    FT_ULong ptr = Script_List_ptr + get_UShort();
    for (j = 0; j < num_Script_Lang; j++)
      if (tag == Script_Lang[j].script)
      {
        Script_List[i].tag = tag;
        Script_List[i].ltag = Script_Lang[j].language;
        Script_List[i].ptr = ptr;
      }
  }

  /*
   *   Read Feature_List
   */
  GSUB_ptr = Feature_List_ptr;
  need(2);
  Feature_Count = get_UShort();
#ifdef  DEBUG
  warning("GSUB: Feature List with %d entries at 0x%04x.", Feature_Count, Feature_List_ptr);
#endif
  Feature_List = mycalloc (Feature_Count, sizeof(Feature_Record));

  need (6 * Feature_Count);
  for (i = 0; i < Feature_Count; i++)
  {
    FT_Tag tag = get_ULong();
    FT_ULong ptr = Feature_List_ptr + get_UShort();
    if (tag == FEATURE_vert || tag == FEATURE_vrt2)
    {
      Feature_List[i].tag = tag;
      Feature_List[i].ptr = ptr;
    }
  }

  /*
   *   Read Lookup_List
   */
  GSUB_ptr = Lookup_List_ptr;
  need(2);
  Lookup_Count = get_UShort();
#ifdef  DEBUG
  warning("GSUB: Lookup List with %d entries at 0x%04x.", Lookup_Count, Lookup_List_ptr);
#endif
  Lookup_List = mycalloc (Lookup_Count, sizeof(Lookup_Record));

  need (2 * Lookup_Count);
  for (i = 0; i < Lookup_Count; i++)
    Lookup_List[i].ptr = Lookup_List_ptr + get_UShort();

  /*
   *   Read Script_List entries
   */
  for (i = 0; i < Script_Count && !has_gsub; i++)
    fetch_Script (i);
}