Exemple #1
0
static void push(UScriptRun *scriptRun, int32_t pairIndex, UScriptCode scriptCode)
{
    scriptRun->pushCount  = LIMIT_INC(scriptRun->pushCount);
    scriptRun->fixupCount = LIMIT_INC(scriptRun->fixupCount);
    
    scriptRun->parenSP = INC1(scriptRun->parenSP);
    scriptRun->parenStack[scriptRun->parenSP].pairIndex  = pairIndex;
    scriptRun->parenStack[scriptRun->parenSP].scriptCode = scriptCode;
}
Exemple #2
0
static void fixup(UScriptRun *scriptRun, UScriptCode scriptCode)
{
    int32_t fixupSP = DEC(scriptRun->parenSP, scriptRun->fixupCount);
    
    while (scriptRun->fixupCount-- > 0) {
        fixupSP = INC1(fixupSP);
        scriptRun->parenStack[fixupSP].scriptCode = scriptCode;
    }
}
void
gfxScriptItemizer::fixup(PRInt32 scriptCode)
{
    PRInt32 fixupSP = DEC(parenSP, fixupCount);

    while (fixupCount-- > 0) {
        fixupSP = INC1(fixupSP);
        parenStack[fixupSP].scriptCode = scriptCode;
    }
}
void
gfxScriptItemizer::push(PRInt32 pairIndex, PRInt32 scriptCode)
{
    pushCount  = LIMIT_INC(pushCount);
    fixupCount = LIMIT_INC(fixupCount);

    parenSP = INC1(parenSP);
    parenStack[parenSP].pairIndex  = pairIndex;
    parenStack[parenSP].scriptCode = scriptCode;
}
void
gfxScriptItemizer::fixup(int32_t newScriptCode)
{
    int32_t fixupSP = DEC(parenSP, fixupCount);

    while (fixupCount-- > 0) {
        fixupSP = INC1(fixupSP);
        parenStack[fixupSP].scriptCode = newScriptCode;
    }
}
void
gfxScriptItemizer::push(uint32_t endPairChar, int32_t newScriptCode)
{
    pushCount  = LIMIT_INC(pushCount);
    fixupCount = LIMIT_INC(fixupCount);

    parenSP = INC1(parenSP);
    parenStack[parenSP].endPairChar = endPairChar;
    parenStack[parenSP].scriptCode = newScriptCode;
}
Exemple #7
0
static int
resp_print_bulk_string(netdissect_options *ndo, register const u_char *bp, int length) {
    int length_cur = length, string_len;
    long strtol_ret;
    char *p;

    ND_TCHECK(*bp);

    /* opcode: '$' */
    INC1(bp, length_cur);
    ND_TCHECK(*bp);

    /* <length> */
    errno = 0;
    strtol_ret = strtol((const char *)bp, &p, 10);
    if (errno != 0 || p == (const char *)bp || strtol_ret < -1 ||
        strtol_ret > INT_MAX)
        string_len = -2; /* invalid */
    else
        string_len = (int)strtol_ret;

    /* move to \r\n */
    MOVE_FORWARD(bp, length_cur);

    /* \r\n */
    INC2(bp, length_cur);

    if (string_len > 0) {
        /* Byte string of length string_len */
        ND_TCHECK2(*bp, string_len);
        RESP_PRINT_SEGMENT(ndo, bp, string_len);
    } else {
        switch(string_len) {
            case 0: resp_print_empty(ndo); break;
            case (-1): {
                /* This is the NULL response. It follows a different pattern: $-1\r\n */
                resp_print_null(ndo);
                TEST_RET_LEN(length - length_cur);
                /* returned ret_len or jumped to trunc */
            }
            default: resp_print_invalid(ndo); break;
        }
    }

    /* <string> */
    INCBY(bp, string_len, length_cur);

    /* \r\n */
    INC2(bp, length_cur);

    TEST_RET_LEN(length - length_cur);

trunc:
    return (-1);
}
Exemple #8
0
static int
resp_print_bulk_array(netdissect_options *ndo, register const u_char *bp, int length) {
    int length_cur = length, array_len, i, ret_len = 0;
    long strtol_ret;
    char *p;

    ND_TCHECK(*bp);

    /* opcode: '*' */
    INC1(bp, length_cur);
    ND_TCHECK(*bp);

    /* <array_length> */
    errno = 0;
    strtol_ret = strtol((const char *)bp, &p, 10);
    if (errno != 0 || p == (const char *)bp || strtol_ret < -1 ||
        strtol_ret > INT_MAX)
        array_len = -2; /* invalid */
    else
        array_len = (int)strtol_ret;

    /* move to \r\n */
    MOVE_FORWARD(bp, length_cur);

    /* \r\n */
    INC2(bp, length_cur);

    if (array_len > 0) {
        /* non empty array */
        for (i = 0; i < array_len; i++) {
            ret_len = resp_parse(ndo, bp, length_cur);

            TEST_RET_LEN_NORETURN(ret_len);

            bp += ret_len;
            length_cur -= ret_len;

            TEST_RET_LEN_NORETURN(length - length_cur);
        }
    } else {
        /* empty, null, or invalid */
        switch(array_len) {
            case 0:     resp_print_empty(ndo);   break;
            case (-1):  resp_print_null(ndo);    break;
            default:    resp_print_invalid(ndo); break;
        }
    }

    TEST_RET_LEN(length - length_cur);

trunc:
    return (-1);
}
Exemple #9
0
int igraph_i_merge(igraph_t *res, int mode, 
		   const igraph_t *left, const igraph_t *right, 
		   igraph_vector_t *edge_map1, igraph_vector_t *edge_map2) {
  
  long int no_of_nodes_left=igraph_vcount(left);
  long int no_of_nodes_right=igraph_vcount(right);
  long int no_of_nodes;
  long int no_edges_left=igraph_ecount(left);
  long int no_edges_right=igraph_ecount(right);
  igraph_bool_t directed=igraph_is_directed(left);
  igraph_vector_t edges;
  igraph_vector_t edges1, edges2;
  igraph_vector_long_t order1, order2;
  long int i, j, eptr=0;
  long int idx1, idx2, edge1=-1, edge2=-1, from1=-1, from2=-1, to1=-1, to2=-1;
  igraph_bool_t l;

  if (directed != igraph_is_directed(right)) {
    IGRAPH_ERROR("Cannot make union or intersection of directed "
		 "and undirected graph", IGRAPH_EINVAL);
  }
  
  IGRAPH_VECTOR_INIT_FINALLY(&edges, 0);
  IGRAPH_VECTOR_INIT_FINALLY(&edges1, no_edges_left*2);
  IGRAPH_VECTOR_INIT_FINALLY(&edges2, no_edges_right*2);
  IGRAPH_CHECK(igraph_vector_long_init(&order1, no_edges_left));
  IGRAPH_FINALLY(igraph_vector_long_destroy, &order1);
  IGRAPH_CHECK(igraph_vector_long_init(&order2, no_edges_right));
  IGRAPH_FINALLY(igraph_vector_long_destroy, &order2);
  
  if (edge_map1) { 
    switch (mode) {
    case IGRAPH_MODE_UNION:
      IGRAPH_CHECK(igraph_vector_resize(edge_map1, no_edges_left));
      break;
    case IGRAPH_MODE_INTERSECTION:
      igraph_vector_clear(edge_map1);
      break;
    }
  }
  if (edge_map2) { 
    switch (mode) {
    case IGRAPH_MODE_UNION:
      IGRAPH_CHECK(igraph_vector_resize(edge_map2, no_edges_right));
      break;
    case IGRAPH_MODE_INTERSECTION:
      igraph_vector_clear(edge_map2);
      break;
    }
  }

  no_of_nodes=no_of_nodes_left > no_of_nodes_right ?
    no_of_nodes_left : no_of_nodes_right;

  /* We merge the two edge lists. We need to sort them first.
     For undirected graphs, we also need to make sure that 
     for every edge, that larger (non-smaller) vertex id is in the
     second column. */

  IGRAPH_CHECK(igraph_get_edgelist(left, &edges1, /*bycol=*/ 0));
  IGRAPH_CHECK(igraph_get_edgelist(right, &edges2, /*bycol=*/ 0));
  if (!directed) {
    for (i=0, j=0; i<no_edges_left; i++, j+=2) {
      if (VECTOR(edges1)[j] > VECTOR(edges1)[j+1]) {
	long int tmp=VECTOR(edges1)[j];
	VECTOR(edges1)[j]=VECTOR(edges1)[j+1];
	VECTOR(edges1)[j+1]=tmp;
      }
    }
    for (i=0, j=0; i<no_edges_right; i++, j+=2) {
      if (VECTOR(edges2)[j] > VECTOR(edges2)[j+1]) {
	long int tmp=VECTOR(edges2)[j];
	VECTOR(edges2)[j]=VECTOR(edges2)[j+1];
	VECTOR(edges2)[j+1]=tmp;
      }
    }
  }

  for (i=0; i<no_edges_left; i++) {
    VECTOR(order1)[i]=i;
  }
  for (i=0; i<no_edges_right; i++) {
    VECTOR(order2)[i]=i;
  }

  igraph_qsort_r(VECTOR(order1), no_edges_left, sizeof(VECTOR(order1)[0]),
		 &edges1, igraph_i_order_edgelist_cmp);
  igraph_qsort_r(VECTOR(order2), no_edges_right, sizeof(VECTOR(order2)[0]),
		 &edges2, igraph_i_order_edgelist_cmp);

#define INC1() if ( (++idx1) < no_edges_left) {			 \
    edge1 = VECTOR(order1)[idx1];				 \
    from1 = VECTOR(edges1)[2*edge1];				 \
    to1 = VECTOR(edges1)[2*edge1+1];				 \
  }
#define INC2() if ( (++idx2) < no_edges_right) {		 \
    edge2 = VECTOR(order2)[idx2];				 \
    from2 = VECTOR(edges2)[2*edge2];				 \
    to2 = VECTOR(edges2)[2*edge2+1];				 \
  }

  idx1 = idx2 = -1;
  INC1();
  INC2();
  
#define CONT() switch (mode) {				\
 case IGRAPH_MODE_UNION:				\
   l = idx1 < no_edges_left || idx2 < no_edges_right;	\
   break;						\
 case IGRAPH_MODE_INTERSECTION:				\
   l = idx1 < no_edges_left && idx2 < no_edges_right;	\
   break;						\
  }

  CONT();
  while (l) {
    if (idx2 >= no_edges_right || 
	(idx1 < no_edges_left && from1 < from2) || 
	(idx1 < no_edges_left && from1 == from2 && to1 < to2)) {
      /* Edge from first graph */
      if (mode==IGRAPH_MODE_UNION) {
	IGRAPH_CHECK(igraph_vector_push_back(&edges, from1));
	IGRAPH_CHECK(igraph_vector_push_back(&edges, to1));
	if (edge_map1) { VECTOR(*edge_map1)[edge1]=eptr; }
	eptr++;
      }
      INC1();
    } else if (idx1 >= no_edges_left ||
	       (idx2 < no_edges_right && from2 < from1) ||
	       (idx2 < no_edges_right && from1 == from2 && to2 < to1)) {
      /* Edge from second graph */
      if (mode==IGRAPH_MODE_UNION) {
	IGRAPH_CHECK(igraph_vector_push_back(&edges, from2));
	IGRAPH_CHECK(igraph_vector_push_back(&edges, to2));
	if (edge_map2) { VECTOR(*edge_map2)[edge2]=eptr; }
	eptr++;
      }
      INC2();
    } else {
      /* Edge from both */
      IGRAPH_CHECK(igraph_vector_push_back(&edges, from1));
      IGRAPH_CHECK(igraph_vector_push_back(&edges, to1));
      if (mode==IGRAPH_MODE_UNION) {
	if (edge_map1) { VECTOR(*edge_map1)[edge1]=eptr; }
	if (edge_map2) { VECTOR(*edge_map2)[edge2]=eptr; }
      } else if (mode==IGRAPH_MODE_INTERSECTION) {
	if (edge_map1) { 
	  IGRAPH_CHECK(igraph_vector_push_back(edge_map1, edge1));
	}
	if (edge_map2) {
	  IGRAPH_CHECK(igraph_vector_push_back(edge_map2, edge2));
	}
      }
      eptr++;
      INC1();
      INC2();
    }
    CONT();
  }
  
#undef INC1
#undef INC2

  igraph_vector_long_destroy(&order2);
  igraph_vector_long_destroy(&order1);
  igraph_vector_destroy(&edges2);
  igraph_vector_destroy(&edges1);
  IGRAPH_FINALLY_CLEAN(4);
  
  IGRAPH_CHECK(igraph_create(res, &edges, no_of_nodes, directed));
  igraph_vector_destroy(&edges);
  IGRAPH_FINALLY_CLEAN(1);
  return 0;
}