Exemple #1
0
static Void local drawClassRelations(HDC hDC)
{
  Class cls;
  for(cls=CLASSMIN; cls<classMax(); cls++) {
    List supers;
    for(supers=cclass(cls).supers; nonNull(supers); supers=tl(supers)) {
      Class parent = getHead(hd(supers));
      if (isClass(parent)) {
	if (parent == cls) {     /* child of itself - draw an arc */
	  Class source = findClassInNodes(cls);
	  Arc(hDC, Nodes[source].Pos.right-5,  Nodes[source].Pos.bottom-5,
		   Nodes[source].Pos.right+15, Nodes[source].Pos.bottom+20,
		   Nodes[source].Pos.right-5,  Nodes[source].Pos.bottom-5,
		   Nodes[source].Pos.right-4,  Nodes[source].Pos.bottom-4);
	} else { 	               /* Join the two classes with a line */
	  Class source = findClassInNodes(parent);
	  Class target = findClassInNodes(cls);

	  INT sx = Nodes[source].Pos.right + 4;
	  INT sy = Nodes[source].Pos.top
		   + (Nodes[source].Pos.bottom - Nodes[source].Pos.top)/2;
	  INT tx = Nodes[target].Pos.left  - 4;
	  INT ty = Nodes[target].Pos.top
		   + (Nodes[target].Pos.bottom - Nodes[target].Pos.top)/2;

	  MoveToEx(hDC, sx, sy,NULL);
	  LineTo(hDC, tx, ty);
	}
      }
    }
  }
}
Exemple #2
0
static Bool local isParentOf(Class parent, Class child)
{
  List supers;
  for(supers=cclass(child).supers; nonNull(supers); supers=tl(supers)) {
    if (getHead(hd(supers)) == parent) {
      return TRUE;
    }
  }
  return FALSE;
}
Exemple #3
0
static Void local drawNode( HDC hDC, Node n )
{
  /* frame */
  Rectangle(hDC, Nodes[n].Pos.left-4, Nodes[n].Pos.top-2,
		 Nodes[n].Pos.right+4,Nodes[n].Pos.bottom+2);

  /* frame shadow */
  MoveToEx(hDC, Nodes[n].Pos.right+4, Nodes[n].Pos.top, NULL);
  LineTo(hDC,   Nodes[n].Pos.right+4, Nodes[n].Pos.bottom+2);
  LineTo(hDC,   Nodes[n].Pos.left-2,  Nodes[n].Pos.bottom+2);

  /* class text */
  fprintf(stdstr, "%s\n",textToStr(cclass(Nodes[n].Class).text));
  TextOut(hDC, Nodes[n].Pos.left, Nodes[n].Pos.top, 
	       (LPSTR)stdstrbuff, (INT)strlen(stdstrbuff));
}
Exemple #4
0
Node* RJParser::atom() {
   // printf("atom %c\n", buffer[pos]);
	Node* a;
        Node* b;
	if(cur == '(') {
		accept('(');
		a = altexp();
		accept(')');
		return a;
        } else if(cur == '[') {
            return cclass();
	} else if(cur == '.') {
		accept('.');
		return node(ANY, 0,0);
        } else if(cur == '\\') {
            accept('\\');
            a = node(ATOM,0,0);
            switch(cur) {
                case '\\': a->val = '\\'; break;
                case 'n': a->val = '\n'; break;
                case 't': a->val = '\t'; break;
                case 'd':
                    a->val = '0';
                    b = node(ATOM,0,0);
                    b->val = '9';
                    accept(cur);
                    return node(RAN,a,b);
                default:
                    a->val = cur;
            }
            accept(cur);
            return a;
	} else if(!is_special(cur)) {
		a = node(ATOM,0,0);
		a->val = cur;
		accept(cur);
		return a;
        } else if(cur == 0) {
            return node(NONE,0,0);
	} else {
            //TODO error
            throw "bad atom";
            return a;
        }
}
Exemple #5
0
static Void local buildClassGraph( HDC hDC )
{
  INT   row = INIT_ROW;
  Class cls;
  for (cls=CLASSMIN; cls<classMax(); cls++) {
    if (cclass(cls).numSupers == 0) {
      row = addClassToGraph(hDC, INIT_COLUMN, row, cls) + VERTICAL_SEPARATION;
    }
  }
  /* Since Haskell has acyclic class dependencies, we should be done by now;
   * but it does no harm to make sure.
   */
  for(cls=CLASSMIN; cls<classMax(); cls++) {
    if (-1 == findClassInNodes(cls)) { /* Not added yet */
      row = addClassToGraph(hDC, INIT_COLUMN, row, cls) + VERTICAL_SEPARATION;
    }
  }
}
Exemple #6
0
/* members and contexts for the new class                       */
static local VOID SetClass(HWND hDlg, Class currClass)
{
  INT   i;
  List  instances, members;

  /* Update list of instances */
  SendDlgItemMessage(hDlg, LB_INSTANCES ,LB_RESETCONTENT, 0, 0L);

  /* Clear the redraw flag */
  SendDlgItemMessage(hDlg, LB_INSTANCES ,WM_SETREDRAW, FALSE, 0L);

  for(instances=cclass(currClass).instances; !isNull(instances); instances=tl(instances)) {
    if(!isNull(instances)) {
     SendDlgItemMessage(hDlg, LB_INSTANCES ,LB_ADDSTRING, 0, (LONG)(LPSTR) hd(instances));
    }
    SendDlgItemMessage(hDlg, LB_INSTANCES, LB_SETCURSEL, 0, 0L);
  }

 /* Set the redraw flag and force repaint. */
 SendDlgItemMessage(hDlg, LB_INSTANCES ,WM_SETREDRAW, TRUE, 0L);
 InvalidateRect(GetDlgItem(hDlg, LB_INSTANCES), NULL, TRUE);


  /* Update list of members */

  /* Clear the redraw flag */
  SendDlgItemMessage(hDlg, LB_MEMBERS ,WM_SETREDRAW, FALSE, 0L);

  SendDlgItemMessage(hDlg, LB_MEMBERS ,LB_RESETCONTENT, 0, 0L);
  if (cclass(currClass).numMembers > 0) {
    for(members=cclass(currClass).members, i=0 ;i < cclass(currClass).numMembers; members=tl(members), i++) {
     SendDlgItemMessage(hDlg, LB_MEMBERS ,LB_ADDSTRING, 0, (LONG)(LPSTR) hd(members));
    }
    SendDlgItemMessage(hDlg, LB_MEMBERS, LB_SETCURSEL, 0, 0L);
  }

 /* Set the redraw flag and force repaint. */
 SendDlgItemMessage(hDlg, LB_MEMBERS ,WM_SETREDRAW, TRUE, 0L);
 InvalidateRect(GetDlgItem(hDlg, LB_MEMBERS), NULL, TRUE);


  /* Update context */
  SendDlgItemMessage(hDlg, LB_CONTEXT ,LB_RESETCONTENT, 0, 0L);
  if(nonNull(cclass(currClass).supers)) {
    printContext(stdstr, cclass(currClass).supers);
    fprintf     (stdstr,"\n");
    SendDlgItemMessage(hDlg, LB_CONTEXT ,LB_ADDSTRING, 0, (LONG)(LPSTR) stdstrbuff);
  }
}
Exemple #7
0
/* returns the row for placing next node      */
static INT local addClassToGraph(HDC hDC, INT Column, INT startRow, Class ThisClass)
{
  Node newNode = LastNode++;
  SIZE Size;
  INT  row = startRow;

  /* Get size of class name on the screen */
  fprintf(stdstr, "%s\n",textToStr(cclass(ThisClass).text));
  GetTextExtentPoint(hDC,(LPSTR)stdstrbuff, (INT)strlen(stdstrbuff), &Size);

  Nodes[newNode].Class      = ThisClass;
  Nodes[newNode].Pos.left   = Column;
  Nodes[newNode].Pos.top    = startRow;
  Nodes[newNode].Pos.right  = Nodes[newNode].Pos.left + Size.cx;
  Nodes[newNode].Pos.bottom = Nodes[newNode].Pos.top  + Size.cy;

  /* Add subclasses of ThisClass */
  { Class cls;
    INT   col   = Nodes[newNode].Pos.right+HORIZONTAL_SEPARATION;
    INT   child = 0;
    for(cls=CLASSMIN; cls<classMax(); cls++) {
      if (-1 == findClassInNodes(cls) /* Check for cycles in graph */
	  && isParentOf(ThisClass, cls)) {
	if (child++ > 0) {
	  row += VERTICAL_SEPARATION;
	}
	row = addClassToGraph(hDC, col, row, cls);
      }
    }
  }
  /* Set to average position of children */
  { INT height = row-startRow;
    Nodes[newNode].Pos.top    += height/2;
    Nodes[newNode].Pos.bottom += height/2;
  }
  return row;
}
Exemple #8
0
static int
_advance(char *lp, char *ep)
{
    char 	*rp;
    char 	*curlp;
    wchar_t	c, d;
    int 	n;
    wchar_t cl;
    int 	neg;
    char 	*bbeg;
    int 	ct;

    for (;;) {
        neg = 0;
        switch (*ep++) {

        case CCHR:
            if (*ep++ == *lp++)
                continue;
            return (0);

        case MCCHR:
            ep += Popwchar(ep, cl);
            c = cl;
            if ((n = Popwchar(lp, cl)) <= 0 || c !=  cl)
                return (0);
            lp += n;
            continue;

        case CDOT:
            /*
             * match any characters except NULL
             */
            if ((n = Popwchar(lp, cl)) > 0) {
                lp += n;
                continue;
            } else if (n < 0) {
                lp++;
                continue;
            } else {
                return (0);
            }
        case CDOL:
            if (*lp == 0)
                continue;
            return (0);

        case CCEOF:
            loc2 = lp;
            return (1);

        case CCL:
            c = (unsigned char)*lp++;
            if (ISTHERE(c)) {
                ep += 32;
                continue;
            }
            return (0);

        case NMCCL:
            neg = 1;
        /* FALLTHRU */

        case MCCL:
            rp = lp;
            if (cclass(ep, &rp, neg) != 1)
                return (0);
            ep += *(ep + 32) + 32;
            lp = rp;
            continue;

        case CBRA:
            braslist[*ep++] = lp;
            continue;

        case CKET:
            braelist[*ep++] = lp;
            continue;

        case MCCHR | RNGE:
            ep += Popwchar(ep, cl);
            c = cl;
            getrnge(ep);
            while (low--) {
                if ((n = Popwchar(lp, cl)) <= 0 || cl != c)
                    return (0);
                lp += n;
            }
            curlp = lp;
            while (size--) {
                if ((n = Popwchar(lp, cl)) <= 0 || cl != c)
                    break;
                lp += n;
            }
            if (size < 0)
                n = Popwchar(lp, cl);
            if (n == -1)
                return (0);
            lp += (n ? n : 1);
            ep += 2;
            goto mstar;

        case CCHR | RNGE:
            c = *ep++;
            getrnge(ep);
            while (low--)
                if (*lp++ != c)
                    return (0);
            curlp = lp;
            while (size--)
                if (*lp++ != c)
                    break;
            if (size < 0)
                lp++;
            ep += 2;
            goto star;

        case CDOT | RNGE:
            getrnge(ep);
            while (low--) {
                if ((n = Popwchar(lp, cl)) > 0) {
                    lp += n;
                } else if (n < 0) {
                    lp++;
                } else {
                    return (0);
                }
            }
            curlp = lp;
            while (size--) {
                if ((n = Popwchar(lp, cl)) > 0) {
                    lp += n;
                } else if (n < 0) {
                    lp++;
                } else {
                    break;
                }
            }
            if (size < 0)
                n = Popwchar(lp, cl);
            if (n > 0) {
                lp += n;
            } else {
                lp++;
            }
            ep += 2;
            goto mstar;

        case NMCCL | RNGE:
            neg = 1;
        /* FALLTHRU */

        case MCCL | RNGE:
            getrnge(ep + *(ep + 32) + 32);
            rp = lp;
            while (low--) {
                if (cclass(ep, &rp, neg) != 1)
                    return (0);
            }
            curlp = rp;
            while (size-- && (c = (cclass(ep, &rp, neg))) == 1)
                ;
            if (c == -1)
                return (0);
            lp = rp;
            if (size < 0) {
                if ((n = Popwchar(lp, cl)) == -1)
                    return (0);
                lp += (n ? n : 1);
            }
            ep += *(ep + 32) + 34;
            goto mstar;

        case CCL | RNGE:
            getrnge(ep + 32);
            while (low--) {
                c = (unsigned char)*lp++;
                if (!ISTHERE(c))
                    return (0);
            }
            curlp = lp;
            while (size--) {
                c = (unsigned char)*lp++;
                if (!ISTHERE(c))
                    break;
            }
            if (size < 0)
                lp++;
            ep += 34;		/* 32 + 2 */
            goto star;

        case CBACK:
            bbeg = braslist[*ep];
            ct = (int)(braelist[*ep++] - bbeg);

            if (ecmp(bbeg, lp, ct)) {
                lp += ct;
                continue;
            }
            return (0);

        case CBACK | STAR:
            bbeg = braslist[*ep];
            ct = (int)(braelist[*ep++] - bbeg);
            curlp = lp;
            while (ecmp(bbeg, lp, ct))
                lp += ct;

            while (lp >= curlp) {
                if (_advance(lp, ep))
                    return (1);
                lp -= ct;
            }
            return (0);

        case CDOT | STAR:
            curlp = lp;
            if (!multibyte)
                while (*lp++)
                    ;
            else {
                for (;;) {
                    n = Popwchar(lp, cl);
                    if (n > 0) {
                        lp += n;
                    } else if (n < 0) {
                        lp++;
                    } else {
                        lp++;
                        break;
                    }
                }
            }
            goto mstar;

        case CCHR | STAR:
            curlp = lp;
            while (*lp++ == *ep)
                ;
            ep++;
            goto star;

        case MCCHR | STAR:
            curlp = lp;
            ep += Popwchar(ep, cl);
            c = cl;
            while ((n = Popwchar(lp, cl))  > 0 && cl == c)
                lp += n;
            if (n == -1)
                return (0);
            lp += (n ? n : 1);
            goto mstar;

        case NMCCL | STAR:
            neg = 1;
        /* FALLTHRU */

        case MCCL | STAR:
            curlp = rp = lp;
            while ((d = cclass(ep, &rp, neg)) == 1)
                ;
            if (d == -1)
                return (0);
            lp = rp;
            ep += *(ep + 32) + 32;
            goto mstar;

        case CCL | STAR:
            curlp = lp;
            do {
                c = (unsigned char)*lp++;
            } while (ISTHERE(c));
            ep += 32;
            goto star;

        case CBRC:
            if (lp == start && locs == (char *)0)
                continue;
            c = (unsigned char)*lp;
            d = (unsigned char)*(lp-1);
            if ((isdigit((int)c) || uletter((int)c) || c >= 0200 &&
                    MB_CUR_MAX > 1) && !isdigit((int)d) &&
                    !uletter((int)d) &&
                    (d < 0200 || MB_CUR_MAX == 1))
                continue;
            return (0);

        case CLET:
            d = (unsigned char)*lp;
            if (!isdigit((int)d) && !uletter((int)d) && (d < 0200 ||
                    MB_CUR_MAX == 1))
                continue;
            return (0);

        default:
            return (0);
        }
    }

mstar:
    if (multibyte) {
        /* MB_CUR_MAX > 1 */
        if ((eucw1 != 0) || (eucw2 != 0) || (eucw3 != 0)) {
            /* EUC locale */
            do {
                char *p1, *p2;
                lp--;
                p1 = lp - eucw2;
                p2 = lp - eucw3;
                /* check if previous character is from    */
                /* supplementary code sets 1, 2, or 3 and */
                /* back up appropriate number of bytes    */
                if ((unsigned char)*lp >= 0200) {
                    if (p1 >= curlp &&
                            (unsigned char)*p1 == SS2)
                        lp = p1;
                    else if (p2 >= curlp &&
                             (unsigned char)*p2 == SS3)
                        lp = p2;
                    else
                        lp = lp - eucw1 + 1;
                }
                if (lp == locs)
                    break;
                if (_advance(lp, ep))
                    return (1);
            } while (lp > curlp);
            return (0);
        } else {
            /* Anything else */
            do {
                int	len;
                char	*p1, *p2;

                p2 = curlp;
                do {
                    p1 = p2;
                    if (isascii(*p1)) {
                        p2 = p1 + 1;
                    } else {
                        len = mblen(p1, MB_CUR_MAX);
                        if (len == -1) {
                            len = 1;
                        }
                        p2 = p1 + len;
                    }
                    if (p2 > lp) {
                        /* something is wrong */
                        return (0);
                    }
                } while (p2 != lp);
                lp = p1;
                if (lp == locs)
                    break;
                if (_advance(lp, ep))
                    return (1);
            } while (lp > curlp);
            return (0);
        }
    }
star:
    do {
        if (--lp == locs)
            break;
        if (_advance(lp, ep))
            return (1);
    } while (lp > curlp);
    return (0);
}
Exemple #9
0
/*
 * try to match the next thing in the dfa
 */
static int
advance(char *lp, char *ep)
{
	char	*curlp;
	int	i;
	ptrdiff_t	ct;
	int	rv;
	struct re_globals *_re = re_globals;

	for (;;)
		switch (*ep++) {

		case CCHR:
			if (*ep++ == *lp++)
				continue;
			return (0);

		case CDOT:
			if (*lp++)
				continue;
			return (0);

		case CDOL:
			if (*lp == '\0')
				continue;
			return (0);

		case CEOF:
			return (1);

		case CCL:
			if (cclass(ep, *lp++, 1)) {
				ep += *ep;
				continue;
			}
			return (0);

		case NCCL:
			if (cclass(ep, *lp++, 0)) {
				ep += *ep;
				continue;
			}
			return (0);

		case CBRA:
			braslist[*ep++] = lp;
			continue;

		case CKET:
			braelist[*ep++] = lp;
			continue;

		case CBACK:
			if (braelist[i = *ep++] == 0)
				return (-1);
			if (backref(i, lp)) {
				lp += braelist[i] - braslist[i];
				continue;
			}
			return (0);

		case CBACK|CSTAR:
			if (braelist[i = *ep++] == 0)
				return (-1);
			curlp = lp;
			ct = braelist[i] - braslist[i];
			while (backref(i, lp))
				lp += ct;
			while (lp >= curlp) {
				if (rv = advance(lp, ep))
					return (rv);
				lp -= ct;
			}
			continue;

		case CDOT|CSTAR:
			curlp = lp;
			while (*lp++)
				;
			goto star;

		case CCHR|CSTAR:
			curlp = lp;
			while (*lp++ == *ep)
				;
			ep++;
			goto star;

		case CCL|CSTAR:
		case NCCL|CSTAR:
			curlp = lp;
			while (cclass(ep, *lp++, ep[-1] == (CCL|CSTAR)))
				;
			ep += *ep;
			goto star;

		star:
			do {
				lp--;
				if (rv = advance(lp, ep))
					return (rv);
			} while (lp > curlp);
			return (0);

		default:
			return (-1);
		}
}
Exemple #10
0
/* Function must return either 0 or 1 (assumed by code for 0x80|'!') */
static int
do_gmatch(const unsigned char *s, const unsigned char *se,
        const unsigned char *p, const unsigned char *pe)
{
        int sc, pc;
        const unsigned char *prest, *psub, *pnext;
        const unsigned char *srest;

        if (s == NULL || p == NULL)
                return 0;
        while (p < pe) {
                pc = *p++;
                sc = s < se ? *s : '\0';
                s++;
                if (!ISMAGIC(pc)) {
                        if (sc != pc)
                                return 0;
                        continue;
                }
                switch (*p++) {
                  case '[':
                        if (sc == 0 || (p = cclass(p, sc)) == NULL)
                                return 0;
                        break;

                  case '?':
                        if (sc == 0)
                                return 0;
                        break;

                  case '*':
                        if (p == pe)
                                return 1;
                        s--;
                        do {
                                if (do_gmatch(s, se, p, pe))
                                        return 1;
                        } while (s++ < se);
                        return 0;

                  /*
                   * [*+?@!](pattern|pattern|..)
                   *
                   * Not ifdef'd KSH as this is needed for ${..%..}, etc.
                   */
                  case 0x80|'+': /* matches one or more times */
                  case 0x80|'*': /* matches zero or more times */
                        if (!(prest = pat_scan(p, pe, 0)))
                                return 0;
                        s--;
                        /* take care of zero matches */
                        if (p[-1] == (0x80 | '*') &&
                                do_gmatch(s, se, prest, pe))
                                return 1;
                        for (psub = p; ; psub = pnext) {
                                pnext = pat_scan(psub, pe, 1);
                                for (srest = s; srest <= se; srest++) {
                                        if (do_gmatch(s, srest, psub, pnext - 2) &&
                                                (do_gmatch(srest, se, prest, pe) ||
                                                (s != srest && do_gmatch(srest,
                                                        se, p - 2, pe))))
                                                return 1;
                                }
                                if (pnext == prest)
                                        break;
                        }
                        return 0;

                  case 0x80|'?': /* matches zero or once */
                  case 0x80|'@': /* matches one of the patterns */
                  case 0x80|' ': /* simile for @ */
                        if (!(prest = pat_scan(p, pe, 0)))
                                return 0;
                        s--;
                        /* Take care of zero matches */
                        if (p[-1] == (0x80 | '?') &&
                                do_gmatch(s, se, prest, pe))
                                return 1;
                        for (psub = p; ; psub = pnext) {
                                pnext = pat_scan(psub, pe, 1);
                                srest = prest == pe ? se : s;
                                for (; srest <= se; srest++) {
                                        if (do_gmatch(s, srest, psub, pnext - 2) &&
                                                do_gmatch(srest, se, prest, pe))
                                                return 1;
                                }
                                if (pnext == prest)
                                        break;
                        }
                        return 0;

                  case 0x80|'!': /* matches none of the patterns */
                        if (!(prest = pat_scan(p, pe, 0)))
                                return 0;
                        s--;
                        for (srest = s; srest <= se; srest++) {
                                int matched = 0;

                                for (psub = p; ; psub = pnext) {
                                        pnext = pat_scan(psub, pe, 1);
                                        if (do_gmatch(s, srest, psub,
                                                pnext - 2))
                                        {
                                                matched = 1;
                                                break;
                                        }
                                        if (pnext == prest)
                                                break;
                                }
                                if (!matched &&
                                        do_gmatch(srest, se, prest, pe))
                                                return 1;
                        }
                        return 0;

                  default:
                        if (sc != p[-1])
                                return 0;
                        break;
                }
        }
        return s == se;
}
Exemple #11
0
static int
advance(char *lp, char *ep)
{
	register char *curlp;

	for (;;) switch (*ep++) {

	case CCHR:
/* useless
		if (*ep & RE_QUOTE) {
			c = *ep++ & TRIM;
			sp = braslist[c];
			sp1 = braelist[c];
			while (sp < sp1) {
				if (!same(*sp, *lp))
					return (0);
				sp++, lp++;
			}
			continue;
		}
*/
		if (!same(*ep, *lp))
			return (0);
		ep++, lp++;
		continue;

	case CDOT:
		if (*lp++)
			continue;
		return (0);

	case CDOL:
		if (*lp == 0)
			continue;
		return (0);

	case EX_CEOF:
		loc2 = lp;
		return (1);

	case CCL:
		if (cclass(ep, *lp++, 1)) {
			ep += *ep;
			continue;
		}
		return (0);

	case NCCL:
		if (cclass(ep, *lp++, 0)) {
			ep += *ep;
			continue;
		}
		return (0);

	case CBRA:
		braslist[(int)*ep++] = lp;
		continue;

	case CKET:
		braelist[(int)*ep++] = lp;
		continue;

	case CDOT|STAR:
		curlp = lp;
		while (*lp++)
			continue;
		goto star;

	case CCHR|STAR:
		curlp = lp;
		while (same(*lp, *ep))
			lp++;
		lp++;
		ep++;
		goto star;

	case CCL|STAR:
	case NCCL|STAR:
		curlp = lp;
		while (cclass(ep, *lp++, ep[-1] == (CCL|STAR)))
			continue;
		ep += *ep;
		goto star;
star:
		do {
			lp--;
			if (lp == locs)
				break;
			if (advance(lp, ep))
				return (1);
		} while (lp > curlp);
		return (0);

	case CBRC:
		if (lp == expbuf)
			continue;
		if ((isdigit((int)*lp) || uletter((int)*lp)) && !uletter((int)lp[-1]) && !isdigit((int)lp[-1]))
			continue;
		return (0);

	case CLET:
		if (!uletter((int)*lp) && !isdigit((int)*lp))
			continue;
		return (0);

	default:
		error("Re internal error");
		return 0;
	}
}
Exemple #12
0
static int
advance (char *alp, char *aep)
{
    register unsigned char *lp, *ep, *curlp;

    lp = (unsigned char *)alp;
    ep = (unsigned char *)aep;
    for (;;)
	switch (*ep++) {
	    case CCHR: 
		if (*ep++ == *lp++ || ep[-1] == cc[lp[-1]])
		    continue;
		return 0;

	    case CDOT: 
		if (*lp++)
		    continue;
		return 0;

	    case CDOL: 
		if (*lp == 0)
		    continue;
		return 0;

	    case CEOF: 
		return 1;

	    case CCL: 
		if (cclass (ep, *lp++, 1)) {
		    ep += *ep + 1;
		    continue;
		}
		return 0;

	    case NCCL: 
		if (cclass (ep, *lp++, 0)) {
		    ep += *ep + 1;
		    continue;
		}
		return 0;

	    case CDOT | STAR: 
		curlp = lp;
		while (*lp++)
		    continue;
		goto star;

	    case CCHR | STAR: 
		curlp = lp;
		while (*lp++ == *ep || cc[lp[-1]] == *ep)
		    continue;
		ep++;
		goto star;

	    case CCL | STAR: 
	    case NCCL | STAR: 
		curlp = lp;
		while (cclass (ep, *lp++, ep[-1] == (CCL | STAR)))
		    continue;
		ep += *ep + 1;
		goto star;

	star: 
		do {
		    lp--;
		    if (advance (lp, ep))
			return (1);
		} while (lp > curlp);
		return 0;

	    default: 
		admonish (NULL, "advance() botch -- you lose big");
		return 0;
	}
}
int RegEx::compile( char * source)
/* ..Compile the pattern into global pbuf[].. */
{
   register char  *s;         /* Source string pointer     */
   register char  *lp;        /* Last pattern pointer      */
   register int   c;          /* Current character         */
   int            o;          /* Temp                      */
   char           *spp;       /* Save beginning of pattern */
   
   s = source;
   pp = pbuf;
   
   while (c = *s++)
   {
      /* ..STAR, PLUS and MINUS are special.. */
      if (c == '*' || c == '+' || c == '-')
      {
         if ( pp == pbuf ||
         (o=pp[-1]) == BOL ||
         o == EOL ||
         o == STAR ||
         o == PLUS ||
         o == MINUS
         ) {
            badpat("Illegal occurrance op.", source, s);
            return 0;
         }
         if(!store(ENDPAT)) return 0;
         if(!store(ENDPAT)) return 0;
         spp = pp;               /* Save pattern end     */
         while (--pp > lp)       /* Move pattern down    */
         *pp = pp[-1];        /* one byte             */
         *pp =   (c == '*') ? STAR :
         (c == '-') ? MINUS : PLUS;
         pp = spp;               /* Restore pattern end  */
         continue;
      }
      
      /* ..All the rest.. */
      lp = pp;         /* ..Remember start.. */
      switch(c)
      {
         case '^':
         if(!store(BOL)) return 0;
         break;
         case '$':
         if(!store(EOL)) return 0;
         break;
         case '.':
         if(!store(ANY)) return 0;
         break;
         case '[':
         if(!cclass(source, &s)) return 0;
         break;
         case ':':
         if (*s)
         {
            c = *s++;
            switch(tolower(c))
            {
               case 'a':
               if(!store(ALPHA)) return 0;
               break;
               case 'd':
               if(!store(DIGIT)) return 0;
               break;
               case 'n':
               if(!store(NALPHA)) return 0;
               break;
               case ' ':
               if(!store(WHITE)) return 0;
               break;
               default:
               badpat("Unknown : type", source, s);
               return 0;
            }
            break;
         }
         else {
            badpat("No : type", source, s);
            return 0;
         }
         case '\\':
         if (*s)
         c = *s++;
         default:
         if(!store(CHARAC)) return 0;
         if(!store(iflag ? tolower(c) : c)) return 0;
      }
   }
   if(!store(ENDPAT)) return 0;
   if(!store('\0')) return 0;
   return 1;
}
Exemple #14
0
int advance(char *lp, char *ep)
{
    char *curlp;
    int i;

    for (;;) switch (*ep++) {

        case CCHR:
            if (*ep++ == *lp++)
                continue;
            return(0);

        case CDOT:
            if (*lp++)
                continue;
            return(0);

        case CDOL:
            if (*lp==0)
                continue;
            return(0);

        case CEOF:
            loc2 = lp;
            return(1);

        case CCL:
            if (cclass(ep, *lp++, 1)) {
                ep += *ep;
                continue;
            }
            return(0);

        case NCCL:
            if (cclass(ep, *lp++, 0)) {
                ep += *ep;
                continue;
            }
            return(0);

        case CBRA:
            braslist[*ep++] = lp;
            continue;

        case CKET:
            braelist[*ep++] = lp;
            continue;

        case CBACK:
            if (braelist[i = *ep++]==0)
                error(Q);
            if (backref(i, lp)) {
                lp += braelist[i] - braslist[i];
                continue;
            }
            return(0);

        case CBACK|STAR:
            if (braelist[i = *ep++] == 0)
                error(Q);
            curlp = lp;
            while (backref(i, lp))
                lp += braelist[i] - braslist[i];
            while (lp >= curlp) {
                if (advance(lp, ep))
                    return(1);
                lp -= braelist[i] - braslist[i];
            }
            continue;

        case CDOT|STAR:
            curlp = lp;
            while (*lp++)
                ;
            goto star;

        case CCHR|STAR:
            curlp = lp;
            while (*lp++ == *ep)
                ;
            ep++;
            goto star;

        case CCL|STAR:
        case NCCL|STAR:
            curlp = lp;
            while (cclass(ep, *lp++, ep[-1]==(CCL|STAR)))
                ;
            ep += *ep;
            goto star;

star:
            do {
                lp--;
                if (advance(lp, ep))
                    return(1);
            } while (lp > curlp);
            return(0);

        default:
            error(Q);
        }
}
Exemple #15
0
/* Handles browse classes dialog box */
LRESULT CALLBACK BrowseClassesDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
  INT           	i;
  static Class 	     	currClass;
  Class	       	     	theClass;
  Inst	       	     	theInst;
  Name	       	     	theMember;
  WORD                	NotifyCode, wId;
  HBITMAP             	hBitmap;
  RECT                	aRect, DlgRect;
  HBITMAP             	hBmp;
  BITMAP	      	bm;
  DRAWITEMSTRUCT FAR   *lpdis;
  LPMEASUREITEMSTRUCT 	lpmis;
  LPCOMPAREITEMSTRUCT 	lpcis;
  BOOL                	Selected = FALSE;
  static HBITMAP      	hCBm, hCSelBm, hIBm, hISelBm, hMBm, hMSelBm;
  String		string;
  CHAR			string1[256];

  NotifyCode = HIWORD (wParam);
  wId        = LOWORD (wParam);

  switch (msg) {
    case WM_INITDIALOG:
      CenterDialogInParent(hDlg);
      SetDialogFont (hDlg, hDialogFont);

      SendDlgItemMessage(hDlg, LB_CLASS,   LB_SETHORIZONTALEXTENT, (WPARAM)300, 0L);
      SendDlgItemMessage(hDlg, LB_MEMBERS, LB_SETHORIZONTALEXTENT, (WPARAM)400, 0L);

      /* Create list of classes and set current class */
      for(i=CLASSMIN; i<classMax(); i++) {
	SendDlgItemMessage(hDlg, LB_CLASS ,LB_ADDSTRING, 0, (LPARAM)(LPSTR) i);
      }
      SendDlgItemMessage(hDlg, LB_CLASS, LB_SETCURSEL, 0, 0L);
      currClass = (Class) SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETITEMDATA, (WPARAM) SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETCURSEL, 0, 0L), 0L);
      SetClass(hDlg, currClass);

      /* Create Bitmaps */
      hCBm = LoadBitmap (hThisInstance, "CLASSBMP");
      MapBitmap (hCBm, RGB(0,128,128), GetSysColor(COLOR_WINDOW));
      hCSelBm = LoadBitmap (hThisInstance, "CLASSBMP");
      MapBitmap (hCSelBm, RGB(0,128,128), GetSysColor(COLOR_HIGHLIGHT));
      hIBm = LoadBitmap (hThisInstance, "INSTANCEBMP");
      MapBitmap (hIBm, RGB(0,128,128), GetSysColor(COLOR_WINDOW));
      hISelBm = LoadBitmap (hThisInstance, "INSTANCEBMP");
      MapBitmap (hISelBm, RGB(0,128,128), GetSysColor(COLOR_HIGHLIGHT));
      hMBm = LoadBitmap (hThisInstance, "MEMBERBMP");
      MapBitmap (hMBm, RGB(0,128,128), GetSysColor(COLOR_WINDOW));
      hMSelBm = LoadBitmap (hThisInstance, "MEMBERBMP");
      MapBitmap (hMSelBm, RGB(0,128,128), GetSysColor(COLOR_HIGHLIGHT));
      return TRUE;

    case WM_DESTROY:
      /* Destroy Bitmaps */
      DeleteObject (hCBm);
      DeleteObject (hCSelBm);
      DeleteObject (hIBm);
      DeleteObject (hISelBm);
      DeleteObject (hMBm);
      DeleteObject (hMSelBm);
      break;

    case WM_CTLCOLORBTN:
    case WM_CTLCOLORDLG:
    case WM_CTLCOLOREDIT:
    case WM_CTLCOLORLISTBOX:
    case WM_CTLCOLORMSGBOX:
    case WM_CTLCOLORSCROLLBAR:
    case WM_CTLCOLORSTATIC:
      break;

    case WM_PAINT: {
      HDC 	   hDC;
      PAINTSTRUCT  Ps;

      BeginPaint(hDlg, &Ps);
      hDC = Ps.hdc;

      /* Paint classes Bitmap */
      GetWindowRect(hDlg, &DlgRect);
      GetWindowRect(GetDlgItem(hDlg, ID_PLACEBITMAP), &aRect);

      hBitmap = LoadMappedBitmap(hThisInstance, "CLASSESDLGBMP");
      DrawBitmap(hDC, hBitmap,
		 aRect.left-DlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),
		 aRect.top-DlgRect.top-GetSystemMetrics(SM_CYDLGFRAME)-GetSystemMetrics(SM_CYCAPTION));
      DeleteObject(hBitmap);
      EndPaint(hDlg, &Ps);
    }
    break;

    case WM_COMPAREITEM: {

      lpcis = (COMPAREITEMSTRUCT FAR *) lParam;

      switch (wParam) {
	case LB_CLASS:	    return strcmp (textToStr(cclass(lpcis->itemData1).text),
					   textToStr(cclass(lpcis->itemData2).text));

	case LB_INSTANCES:  if (nonNull(inst(lpcis->itemData1).specifics)) {
                        	printContext(stdstr,inst(lpcis->itemData1).specifics);
                        	fprintf(stdstr," => ");
                            }
                            printPred(stdstr,inst(lpcis->itemData1).head);
			    fprintf(stdstr,"\n");
			    strcpy (string1, stdstrbuff);
			    if (nonNull(inst(lpcis->itemData2).specifics)) {
                        	printContext(stdstr,inst(lpcis->itemData2).specifics);
                        	fprintf(stdstr," => ");
                            }
			    printPred(stdstr,inst(lpcis->itemData2).head);
			    fprintf(stdstr,"\n");
			    return strcmp (string1, stdstrbuff);

	case LB_MEMBERS:    printExp (stdstr, lpcis->itemData1);
			    fprintf(stdstr,"\n");
			    strcpy (string1, stdstrbuff);
			    printExp (stdstr, lpcis->itemData2);
			    fprintf(stdstr,"\n");
			    return strcmp (string1, stdstrbuff);

	}
      }
      break;

    case WM_MEASUREITEM:

      lpdis = (DRAWITEMSTRUCT FAR *) lParam;

      if (lpdis->CtlID == LB_CLASS ||
	  lpdis->CtlID == LB_INSTANCES ||
	  lpdis->CtlID == LB_MEMBERS ) {

	lpmis = (LPMEASUREITEMSTRUCT) lParam;

	/* Set the height of the list box items to Bitmap height */
	hBmp = LoadBitmap(hThisInstance, "CLASSBMP");
	GetObject(hBmp, sizeof(BITMAP), &bm);
	DeleteObject(hBmp);
	lpmis->itemHeight = bm.bmHeight+1;
	lpmis->itemWidth = 50000;

	return TRUE;
      }
      break;

    case WM_DRAWITEM:

      lpdis = (DRAWITEMSTRUCT FAR *) lParam;

      if (lpdis->CtlID == LB_CLASS ||
	  lpdis->CtlID == LB_INSTANCES ||
	  lpdis->CtlID == LB_MEMBERS ) {

	if (lpdis->itemID == (UINT)-1) {
	  return TRUE;
	}

	switch (lpdis->itemAction) {
	  case ODA_DRAWENTIRE:
	  case ODA_SELECT:
	  case ODA_FOCUS:
	    if ((lpdis->itemState & ODS_SELECTED) /*&& (lpdis->itemState & ODS_FOCUS)*/) {
	      SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
	      SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
	      Selected = TRUE;
	    }
	    else {
	      SetBkColor(lpdis->hDC, GetSysColor(COLOR_WINDOW));
	      SetTextColor(lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT));
	    }
	    break;
	  default:
	    return FALSE;
	}

	switch (lpdis->CtlID) {
	  case LB_CLASS:     theClass = (Class) SendDlgItemMessage(hDlg, lpdis->CtlID, LB_GETITEMDATA, lpdis->itemID, 0);
			     printPred(stdstr,cclass(theClass).head);
			     fprintf (stdstr, "   -- in %s\n", textToStr(module(cclass(theClass).mod).text));
			     ExtTextOut(lpdis->hDC, lpdis->rcItem.left+21, lpdis->rcItem.top, ETO_OPAQUE, &(lpdis->rcItem), stdstrbuff, strlen(stdstrbuff), NULL);
			     hBmp = Selected ? hCSelBm : hCBm;

			     break;

	  case LB_INSTANCES: theInst = (Inst) SendDlgItemMessage(hDlg, lpdis->CtlID, LB_GETITEMDATA, lpdis->itemID, 0);
                 	     if (nonNull(inst(theInst).specifics)) {
                        	printContext(stdstr,inst(theInst).specifics);
                        	fprintf(stdstr," => ");
                             }
      			     printPred(stdstr,inst(theInst).head);
			     fprintf  (stdstr, "   -- in %s \n", textToStr(module(moduleOfScript(scriptThisInst(theInst))).text));
			     ExtTextOut(lpdis->hDC, lpdis->rcItem.left+21, lpdis->rcItem.top, ETO_OPAQUE, &(lpdis->rcItem), stdstrbuff, strlen(stdstrbuff), NULL);
			     hBmp = Selected ? hISelBm : hIBm;
			     break;


	  case LB_MEMBERS:   theMember = (Name) SendDlgItemMessage(hDlg, lpdis->CtlID, LB_GETITEMDATA, lpdis->itemID, 0);
			     printExp(stdstr,theMember);
			     fprintf(stdstr, " :: ");
			     printType(stdstr,name(theMember).type);
			     fprintf(stdstr,"\n");
			     ExtTextOut(lpdis->hDC, lpdis->rcItem.left+21, lpdis->rcItem.top, ETO_OPAQUE, &(lpdis->rcItem), stdstrbuff, strlen(stdstrbuff), NULL);
			     hBmp = Selected ? hMSelBm : hMBm;
			     break;
	}
	DrawBitmap (lpdis->hDC, hBmp, (lpdis->rcItem.left)+4, lpdis->rcItem.top);

	/* If selected draw rectangle */
	if ((lpdis->itemState & ODS_SELECTED)&&(lpdis->itemState & ODS_FOCUS)) {
	  DrawFocusRect(lpdis->hDC, &(lpdis->rcItem));
	}

	return TRUE;
      }

    case WM_COMMAND:
      switch (wId) {
        case LB_CLASS:
	  switch(NotifyCode) {
	    case LBN_SELCHANGE: /* select a new class */
	      currClass = (Class) SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETITEMDATA, SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETCURSEL, 0, 0L), 0L);
	      SetClass(hDlg, currClass);
	      break;

	    case LBN_DBLCLK: { /* Open in text editor script file with class definition */
	      currClass = (Class) SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETITEMDATA, SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETCURSEL, 0, 0L), 0L);

	      currClass = (Class) SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETITEMDATA, SendDlgItemMessage(hDlg, LB_CLASS ,LB_GETCURSEL, 0, 0L), 0L);
	      setLastEdit(getScriptName(scriptThisClass(currClass)), cclass(currClass).line);
	      runEditor();
	      
	      
	    }
	    break;
	  }
	  break;

	case LB_MEMBERS:
	case LB_INSTANCES:
	  switch(NotifyCode) {/* Open in text editor script file with instance definition */
	    case LBN_DBLCLK: {
	      Inst  currInst;

	      currInst = (Inst) SendDlgItemMessage(hDlg, LB_INSTANCES, LB_GETITEMDATA, SendDlgItemMessage(hDlg, LB_INSTANCES ,LB_GETCURSEL, 0, 0L), 0L);

	      /* Find instance module */
	      setLastEdit(getScriptName(scriptThisInst(currInst)), inst(currInst).line);
	      runEditor();
	      
	    }
	    break;
	  }
	  break;

	case ID_HIERARCHY: /* Draw classes hierarchy */
	  DrawClassesHierarchy();
	  break;

	case ID_EDITCLASS: /* Pushed on Edit class button */
	  if (SendDlgItemMessage(hDlg, LB_CLASS, LB_GETCURSEL, 0, 0L) != LB_ERR)
	    DlgSendMessage(hDlg, WM_COMMAND, LB_CLASS, MAKELONG(0, LBN_DBLCLK));
	  break;

	case ID_EDITINSTANCE: /* Pushed on Edit instance button */
	  if (SendDlgItemMessage(hDlg, LB_INSTANCES, LB_GETCURSEL, 0, 0L) != LB_ERR)
	    DlgSendMessage(hDlg, WM_COMMAND, LB_INSTANCES, MAKELONG(0, LBN_DBLCLK));
	  break;

	case IDCANCEL: /* Close dialog */
	case IDOK:
	  EndDialog(hDlg, TRUE);
	  return TRUE;

	default:
	  return TRUE;
      }
  }
  return FALSE;
}