static MRESULT APIENTRY InitDlg ( HWND Window, ULONG msg, MPARAM mp1, MPARAM mp2 ) {

  /**************************************************************************
   * Get parameters from initialization message.                            *
   **************************************************************************/

   PDATEFMT_PARMS Parms = PDATEFMT_PARMS ( PVOIDFROMMP ( mp2 ) ) ;

   Sys_SetWindowData ( Window, Parms ) ;

  /**************************************************************************
   * Fill the entry field.                                                  *
   **************************************************************************/

   Sys_SendMessage ( CHILD(Window,IDD_DATEFMT_ENTRY), EM_SETTEXTLIMIT, MPFROMLONG(sizeof(Parms->Format)-1), 0 ) ;

   char Local [sizeof(Parms->Format)] ;
   LocalDateFormat ( Local, Parms->Format ) ;
   Sys_SetWindowText ( CHILD(Window,IDD_DATEFMT_ENTRY), Local ) ;

  /**************************************************************************
   * Return no error.                                                       *
   **************************************************************************/

   return ( Dialog_Processor ( Window, msg, mp1, mp2 ) ) ;
}
示例#2
0
static int
parser_compare_nodes(node *left, node *right)
{
    int j;

    if (TYPE(left) < TYPE(right))
        return (-1);

    if (TYPE(right) < TYPE(left))
        return (1);

    if (ISTERMINAL(TYPE(left)))
        return (strcmp(STR(left), STR(right)));

    if (NCH(left) < NCH(right))
        return (-1);

    if (NCH(right) < NCH(left))
        return (1);

    for (j = 0; j < NCH(left); ++j) {
        int v = parser_compare_nodes(CHILD(left, j), CHILD(right, j));

        if (v != 0)
            return (v);
    }
    return (0);
}
示例#3
0
int run_prompt() {

    Node *ptree;
    AstNode *stree;
    EmCodeObject *co;
    Environment *env;
    EmObject *retval;

    env = newenv(vm->topenv);

    while (1) {
        ptree = parse();
        if (ptree) {

            if (ptree->type != MAGIC_COMMAND) {
                // printtree(ptree);

                stree = ast_from_ptree(ptree);

                // printstree(stree);

                co = compile_ast_tree(stree);

                INCREF(&nulobj);
                retval = run_codeobject(co, env, &nulobj);

                if (retval)
                    DECREF(retval);

                vm_reset_for_prompt();

                freetree(ptree);
                freestree(stree);

            } else { // MAGIC_COMMAND
                printf("got magic command %d\n", CHILD(ptree,0)->type);
                if (NCH(ptree) == 2) {
                    printf("magic command arg = %s\n",
                    CHILD(ptree,1)->lexeme);
                }
                if (CHILD(ptree,0)->type == MCA_EXIT) {
                    freetree(ptree); // release memory before exit
                    break;
                }
                // Always release memory of parse tree
                freetree(ptree);
            }
        }
    }
    env_free(env);

    return 1;
}
示例#4
0
文件: Fsanity.c 项目: 8l/csolve
int
SanityCheck1(Heap * h, Item * i)
{
  Heap * h1;

  if(h == NULL_HEAP)
  {
     return(TRUE);
  }

  h1 = h;
  do
  {
    if(LessThan(ITEM(h1), i))
    {
      return(FALSE);
    }
    if(!SanityCheck1(CHILD(h1), ITEM(h1)))
    {
      return(FALSE);
    }

    h1 = FORWARD(h1);
  }
  while(h1 != h);

  return(TRUE);
}
示例#5
0
文件: delaunay.cpp 项目: omco/geode
GEODE_UNUSED static void check_bsp(const TriangleTopology& mesh, RawArray<const Node> bsp, RawField<const Vector<int,2>,FaceId> face_to_bsp, RawField<const Perturbed2,VertexId> X_) {
  if (self_check) {
    cout << "bsp:\n";
    #define CHILD(c) format("%c%d",(c<0?'f':'n'),(c<0?~c:c))
    for (const int n : range(bsp.size()))
      cout << "  "<<n<<" : test "<<bsp[n].test<<", children "<<CHILD(bsp[n].children[0])<<" "<<CHILD(bsp[n].children[1])<<endl;
    cout << "tris = "<<mesh.elements()<<endl;
    cout << "X = "<<X_.flat<<endl;
  }
  for (const int n : range(bsp.size()))
    for (const int i : range(2))
      if (bsp[n].children[i]<0)
        GEODE_ASSERT(face_to_bsp[FaceId(~bsp[n].children[i])].contains(2*n+i));
  auto X = X_.copy();
  for (const auto f : mesh.faces()) {
    int i0,i1;
    face_to_bsp[f].get(i0,i1);
    if (bsp.size())
      GEODE_ASSERT(bsp[i0/2].children[i0&1]==~f.id);
    if (i1>=0)
      GEODE_ASSERT(bsp[i1/2].children[i1&1]==~f.id);
    const auto v = mesh.vertices(f);
    if (!is_sentinel(X[v.x]) && !is_sentinel(X[v.y]) && !is_sentinel(X[v.z])) {
      const auto center = X.append(Perturbed2(X.size(),(X[v.x].value()+X[v.y].value()+X[v.z].value())/3));
      const auto found = bsp_search(bsp,X,center);
      if (found!=f) {
        cout << "bsp search failed: f "<<f<<", v "<<v<<", found "<<found<<endl;
        GEODE_ASSERT(false);
      }
      X.flat.pop();
    }
  }
}
示例#6
0
static void remove_obj(uint16_t object)
{
  uint16_t parent = PARENT(object);

  if(parent != 0)
  {
    uint16_t child = CHILD(parent);

    /* Direct child */
    if(child == object)
    {
      /* parent->child = parent->child->sibling */
      SET_CHILD(parent, SIBLING(child));
    }
    else
    {
      while(SIBLING(child) != object)
      {
        /* child = child->sibling */
        child = SIBLING(child);
      }

      /* Now the sibling of child is the object to remove. */

      /* child->sibling = child->sibling->sibling */
      SET_SIBLING(child, SIBLING(SIBLING(child)));
    }

    /* object->parent = 0 */
    SET_PARENT(object, 0);

    /* object->sibling = 0 */
    SET_SIBLING(object, 0);
  }
}
示例#7
0
文件: Fsanity.c 项目: 8l/csolve
void
PrettyPrint(Heap * h)
{
  Heap * h1;

  if(h == NULL_HEAP)
  {
    printf(" nil ");
    return;
  }

  printf("(");

  h1 = h;
  do
  {
    PrintItem(ITEM(h1));
    printf("[%u] ", RANK(h1));
    PrettyPrint(CHILD(h1));
    h1 = FORWARD(h1);
  }
  while(h1 != h);

  printf(")");
}
示例#8
0
/*     For testing(?) - prints out tree     */
void printnode(struct treenode *node_p,int flag,FILE *fp){
  int n;

  n=flag;
  while(n<DOODAH && CHILD(node)!=NULL){
    fprintf(fp,"# %s\tConnected to %15s by Length %e\n",node_p->name
                ,CHILD(node)->name,CHILD(length));

/*  When calling parent from child - be careful of
 * infinite recursion!
 *  The first branch always the parent, except for
 * the tree root, in which case, the first branch
 * is also a child.*/ 
    printnode(CHILD(node),1,fp);
    n++;
  }
}
示例#9
0
int add_lengths_to_tree (TREE * tree, double *lengths)
{
  int a, b;

  CheckIsTree (tree);
  assert (NULL != lengths);

  for (a = 0; a < tree->n_br; a++) {
    (tree->branches[a])->blength[0] = lengths[a];
    b = find_connection (CHILD (tree->branches[a], 0), tree->branches[a]);

    CHILD (tree->branches[a], 0)->blength[b] = lengths[a];
  }

  CheckIsTree (tree);

  return 0;
}
示例#10
0
文件: Fsanity.c 项目: 8l/csolve
int
SanityCheck2(Heap * h)
{
  int   sum;
  Heap * h1;
  Heap * h2;

  if(h == NULL_HEAP)
  {
     return(TRUE);
  }

  h1 = h;
  do
  {
    if(CHILD(h1) != NULL_HEAP)
    {
      sum = 0;
      h2 = CHILD(h1);
      do
      {
         sum += RANK(h2) + 1;

         h2 = FORWARD(h2);
      }
      while(h2 != CHILD(h1));
      if(sum != RANK(h1))
      {
        return(FALSE);
      }

      if(!SanityCheck2(CHILD(h1)))
      {
        return(FALSE);
      }
    }

    h1 = FORWARD(h1);
  }
  while(h1 != h);

  return(TRUE);
}
static MRESULT APIENTRY Control ( HWND Window, ULONG, MPARAM mp1, MPARAM ) {

  /**************************************************************************
   * Find the instance data.                                                *
   **************************************************************************/

   PDATEFMT_PARMS Parms = PDATEFMT_PARMS ( Sys_GetWindowData ( Window ) ) ;

  /**************************************************************************
   * Decode the message.  Find out what control sent it, and what the       *
   *   control had to say.                                                  *
   **************************************************************************/

   USHORT id = SHORT1FROMMP ( mp1 ) ;
   USHORT Message = SHORT2FROMMP ( mp1 ) ;

  /**************************************************************************
   * Handle changes according to which control reported them.               *
   **************************************************************************/

   switch ( id ) {

      case IDD_DATEFMT_ENTRY: {
         if ( Message == EN_CHANGE ) {
            char Local [sizeof(Parms->Format)] ;
            Sys_GetWindowText ( CHILD(Window,id), Local, sizeof(Local) ) ;
            GeneralDateFormat ( Parms->Format, Local ) ;
            char Result [100] ;
            if ( FormatDate ( time(0), Parms->Format, Result, sizeof(Result) ) ) {
               Sys_SetWindowText ( CHILD(Window,IDD_DATEFMT_SAMPLE), Result ) ;
               Sys_SetWindowText ( CHILD(Window,IDD_DATEFMT_ERR), "" ) ;
            } else {
               ResourceString Message ( Parms->Library, IDS_DATEFMT_ERROR1 ) ;
               Sys_SetWindowText ( CHILD(Window,IDD_DATEFMT_ERR), PSZ(Message) ) ;
            } /* endif */
         } /* endif */
         return ( 0 ) ;
      } /* endcase */
   } /* endswitch */

   return ( 0 ) ;
}
示例#12
0
static void
freechildren(node *n)
{
    int i;
    for (i = NCH(n); --i >= 0; )
        freechildren(CHILD(n, i));
    if (n->n_child != NULL)
        PyObject_FREE(n->n_child);
    if (STR(n) != NULL)
        PyObject_FREE(STR(n));
}
示例#13
0
void print_tree (FILE * out, const NODE * node, const NODE * parent,
		 const TREE * tree)
{
  int a, leaf_flag = 0;

  if (NULL == out)
    out = stdout;
  if (parent == NULL)
    CheckIsTree (tree);

  fprintf (out, "(");

  if (parent == NULL)
    a = -1;
  else
    a = 0;

  while (node->branch[++a] != NULL) {
    if (ISLEAF (CHILD (node, a))) {
      if (leaf_flag == 1){
	fprintf (out, ", ");
      }
      fprintf (out, "%s", CHILD(node,a)->name);
      leaf_flag = 1;
    }
    else {
      if (leaf_flag == 1)
	fprintf (out, ", ");
      print_tree (out, CHILD (node, a), node, tree);
      leaf_flag = 1;
    }
    if (node->blength[a]>=0.){
      fprintf (out, ":%f", node->blength[a]);
    }
  }
  fprintf (out, " )");

  if (parent == NULL)
    fprintf (out, "\n");
}
示例#14
0
文件: parser.c 项目: 10sr/cpython
static int
push(stack *s, int type, dfa *d, int newstate, int lineno, int col_offset)
{
    int err;
    node *n;
    n = s->s_top->s_parent;
    assert(!s_empty(s));
    err = PyNode_AddChild(n, type, (char *)NULL, lineno, col_offset);
    if (err)
        return err;
    s->s_top->s_state = newstate;
    return s_push(s, d, CHILD(n, NCH(n)-1));
}
示例#15
0
文件: parser.c 项目: 10sr/cpython
/* Leaving this in as an example */
static void
future_hack(parser_state *ps)
{
    node *n = ps->p_stack.s_top->s_parent;
    node *ch, *cch;
    int i;

    /* from __future__ import ..., must have at least 4 children */
    n = CHILD(n, 0);
    if (NCH(n) < 4)
        return;
    ch = CHILD(n, 0);
    if (STR(ch) == NULL || strcmp(STR(ch), "from") != 0)
        return;
    ch = CHILD(n, 1);
    if (NCH(ch) == 1 && STR(CHILD(ch, 0)) &&
        strcmp(STR(CHILD(ch, 0)), "__future__") != 0)
        return;
    ch = CHILD(n, 3);
    /* ch can be a star, a parenthesis or import_as_names */
    if (TYPE(ch) == STAR)
        return;
    if (TYPE(ch) == LPAR)
        ch = CHILD(n, 4);

    for (i = 0; i < NCH(ch); i += 2) {
        cch = CHILD(ch, i);
        if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME) {
            char *str_ch = STR(CHILD(cch, 0));
            if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) {
                ps->p_flags |= CO_FUTURE_WITH_STATEMENT;
            } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) {
                ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;
            } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) {
                ps->p_flags |= CO_FUTURE_UNICODE_LITERALS;
            }
        }
    }
}
static MRESULT APIENTRY Apply ( HWND Window, ULONG, MPARAM, MPARAM ) {

  /**************************************************************************
   * Find the instance data.                                                *
   **************************************************************************/

   PDATEFMT_PARMS Parms = PDATEFMT_PARMS ( Sys_GetWindowData ( Window ) ) ;

  /**************************************************************************
   * Verify the date format.                                                *
   **************************************************************************/

   if ( !VerifyDateFormat ( CHILD(Window,IDD_DATEFMT_ENTRY), CHILD(Window,IDD_DATEFMT_ERR), CHILD(Window,IDD_DATEFMT_SAMPLE), Parms->Format ) )
      return ( 0 ) ;

  /**************************************************************************
   * Send the new text back to the parent window.                           *
   **************************************************************************/

   Sys_SendMessage ( OWNER(Window), WM_SET_DATEFMT, MPFROMP(Parms->Format), 0 ) ;

   return ( 0 ) ;
}
static MRESULT APIENTRY OK ( HWND Window, ULONG, MPARAM, MPARAM ) {

  /**************************************************************************
   * Find the instance data.                                                *
   **************************************************************************/

   PDATEFMT_PARMS Parms = PDATEFMT_PARMS ( Sys_GetWindowData ( Window ) ) ;

  /**************************************************************************
   * Verify the date format.                                                *
   **************************************************************************/

   if ( !VerifyDateFormat ( CHILD(Window,IDD_DATEFMT_ENTRY), CHILD(Window,IDD_DATEFMT_ERR), CHILD(Window,IDD_DATEFMT_SAMPLE), Parms->Format ) )
      return ( 0 ) ;

  /**************************************************************************
   * Dismiss the dialog with a TRUE status.                                 *
   **************************************************************************/

   Sys_EndDialog ( Window, TRUE ) ;

   return ( 0 ) ;
}
示例#18
0
static Py_ssize_t
sizeofchildren(node *n)
{
    Py_ssize_t res = 0;
    int i;
    for (i = NCH(n); --i >= 0; )
        res += sizeofchildren(CHILD(n, i));
    if (n->n_child != NULL)
        /* allocated size of n->n_child array */
        res += XXXROUNDUP(NCH(n)) * sizeof(node);
    if (STR(n) != NULL)
        res += strlen(STR(n)) + 1;
    return res;
}
/*=================================================*
 * create_node allocates enough space for the node *
 *=================================================*/
NODE *create_node()
        {
                NODE *ndp=(NODE *)malloc(sizeof(NODE));

                if(ndp==NULL)
                        fatal_error("no more room for NODE");

                PARENT(ndp)=NULL;
                SIBLING(ndp)=NULL;
                CHILD(ndp)=NULL;
                INFO(ndp)=create_data_info();
                LEVEL(ndp)=0;

                return(ndp);
        }
示例#20
0
static MRESULT APIENTRY InitDlg ( HWND Window, MESG msg, MPARAM1 mp1, MPARAM2 mp2 ) {

  /**************************************************************************
   * Get parameters from initialization message.                            *
   **************************************************************************/

   PTABS_PARMS Parms = PTABS_PARMS ( PVOIDFROMMP ( mp2 ) ) ;

   Sys_SetWindowData ( Window, Parms ) ;

  /**************************************************************************
   * Set the current measurement units.                                     *
   **************************************************************************/

   ResourceString English ( Parms->Library, IDS_UNITS_ENGLISH ) ;
   ResourceString Metric ( Parms->Library, IDS_UNITS_METRIC ) ;

   Sys_SetWindowText ( CHILD(Window,IDD_TABS_UNITS), Parms->Metric ? PSZ(Metric) : PSZ(English) ) ;

  /**************************************************************************
   * Set the page size.                                                     *
   **************************************************************************/

   ResourceString Margins ( Parms->Library, IDS_TABS_MARGINS ) ;
   char String1 [20] ;  FormatDecimal ( String1, Parms->LeftMargin, 1000, 3 ) ;
   char String2 [20] ;  FormatDecimal ( String2, Parms->RightMargin, 1000, 3 ) ;
   char Text [100] ;
   sprintf ( Text, PCHAR(Margins), String1, String2 ) ;
   Sys_SetWindowText ( CHILD(Window,IDD_TABS_SIZE), Text ) ;

  /**************************************************************************
   * Return no error.                                                       *
   **************************************************************************/

   return ( Dialog_Processor ( Window, msg, mp1, mp2 ) ) ;
}
示例#21
0
static void
freechildren(node *n)
{
    int i;
    for (i = NCH(n); --i >= 0; )
        freechildren(CHILD(n, i));
    if (n->n_child != NULL)
        PyObject_FREE(n->n_child);
	/*
		Print statement modification :
		Free all nodes except those marked modified.
		Those are virtual nodes in the parse three that don't actually reside in the statement's memory,
		Freeing them is dangerous.
	*/
    if (STR(n) != NULL && (!n->n_wasModified))
        PyObject_FREE(STR(n));
}
示例#22
0
/* create_block_tree:
 * Construct block tree by peeling nodes from block list in state.
 * When done, return root. The block list is empty
 * FIX: use largest block as root
 */
block_t *createBlocktree(Agraph_t * g, circ_state * state)
{
    block_t *bp;
    block_t *next;
    block_t *root;
    int min;
    /* int        ordercnt; */

    find_blocks(g, state);

    bp = state->bl.first;	/* if root chosen, will be first */
    /* Otherwise, just pick first as root */
    root = bp;

    /* Find node with minimum VAL value to find parent block */
    /* FIX: Should be some way to avoid search below.               */
    /* ordercnt = state->orderCount;  */
    for (bp = bp->next; bp; bp = next) {
	Agnode_t *n;
	Agnode_t *parent;
	Agnode_t *child;
	Agraph_t *subg = bp->sub_graph;

	child = n = agfstnode(subg);
	min = VAL(n);
	parent = PARENT(n);
	for (n = agnxtnode(subg, n); n; n = agnxtnode(subg, n)) {
	    if (VAL(n) < min) {
		child = n;
		min = VAL(n);
		parent = PARENT(n);
	    }
	}
	SET_PARENT(parent);
	CHILD(bp) = child;
	next = bp->next;	/* save next since list insertion destroys it */
	appendBlock(&(BLOCK(parent)->children), bp);
    }
    initBlocklist(&state->bl);	/* zero out list */
    return root;
}
示例#23
0
文件: nodes.c 项目: yoanlcq/FATE
void fst_anynode_dealloc(fst_node *n, uint8_t depth) {
    switch(n->type) {
        /* Nothing here for typeless node. We just free its name and itself and the end. */
        case FST_LNODE: fst_lnode_dealloc_extras(n); break;
        case FST_KNODE: fst_knode_dealloc_extras(n); break;
        case FST_DNODE: fst_dnode_dealloc_extras(n); break;
        case FST_ENODE: fst_enode_dealloc_extras(n); break;
        case FST_VNODE: fst_vnode_dealloc_extras(n); break;
    }
#define CNT (((fst_hardlink*)n)->children.count)
#define CHILD(__i__) ((fst_hardlink*)n)->children.nodes[__i__]
    if(depth && n->entry_type == FST_HARDLINK && CNT > 0) {
        for(--CNT ; ; --CNT) {
            fst_anynode_dealloc(CHILD(CNT), depth-1);
            if(!CNT) break;
        }
    }
#undef CNT
#undef CHILD
    free(n->name);
    free(n);
}
示例#24
0
文件: listnode.c 项目: 1st1/cpython
static void
list1node(FILE *fp, node *n)
{
    if (n == NULL)
        return;
    if (ISNONTERMINAL(TYPE(n))) {
        int i;
        for (i = 0; i < NCH(n); i++)
            list1node(fp, CHILD(n, i));
    }
    else if (ISTERMINAL(TYPE(n))) {
        switch (TYPE(n)) {
        case INDENT:
            ++level;
            break;
        case DEDENT:
            --level;
            break;
        default:
            if (atbol) {
                int i;
                for (i = 0; i < level; ++i)
                    fprintf(fp, "\t");
                atbol = 0;
            }
            if (TYPE(n) == NEWLINE) {
                if (STR(n) != NULL)
                    fprintf(fp, "%s", STR(n));
                fprintf(fp, "\n");
                atbol = 1;
            }
            else
                fprintf(fp, "%s ", STR(n));
            break;
        }
    }
    else
        fprintf(fp, "? ");
}
示例#25
0
void delay_heap_sort_down(void) {
	uint32_t l,r,m;
	uint32_t pos = 0;
	heapelem x;
	while (pos<heapelements) {
		l = CHILD(pos);
		r = l+1;
		if (l>=heapelements) {
			return;
		}
		m = l;
		if (r<heapelements && heap[r].firetime < heap[l].firetime) {
			m = r;
		}
		if (heap[pos].firetime <= heap[m].firetime) {
			return;
		}
		x = heap[pos];
		heap[pos] = heap[m];
		heap[m] = x;
		pos = m;
	}
}
示例#26
0
文件: merger.c 项目: bhohbaum/moosefs
void merger_heap_sort_down(void) {
	uint32_t l,r,m;
	uint32_t pos=0;
	hentry x;
	while (pos<heapsize) {
		l = CHILD(pos);
		r = l+1;
		if (l>=heapsize) {
			return;
		}
		m = l;
		if (r<heapsize && heap[r].nextid < heap[l].nextid) {
			m = r;
		}
		if (heap[pos].nextid <= heap[m].nextid) {
			return;
		}
		x = heap[pos];
		heap[pos] = heap[m];
		heap[m] = x;
		pos = m;
	}
}
示例#27
0
文件: Fsanity.c 项目: 8l/csolve
int
SanityCheck3(Heap * h, int rank)
{
  int   sum;
  Heap * h1;
  Heap * h2;

  if((h == NULL_HEAP) && (rank == 0))
  {
     return(TRUE);
  }

  sum = 0;
  h1 = h;
  do
  {
    sum += RANK(h1) + 1;

    if(!SanityCheck3(CHILD(h1), RANK(h1)))
    {
      return(FALSE);
    }

    h1 = FORWARD(h1);
  }
  while(h1 != h);

  if(sum == rank)
  {
    return(TRUE);
  }
  else
  {
    return(FALSE);
  }
}
示例#28
0
static void
future_hack(parser_state *ps)
{
	node *n = ps->p_stack.s_top->s_parent;
	node *ch;
	int i;

	if (strcmp(STR(CHILD(n, 0)), "from") != 0)
		return;
	ch = CHILD(n, 1);
	if (strcmp(STR(CHILD(ch, 0)), "__future__") != 0)
		return;
	for (i = 3; i < NCH(n); i += 2) {
		ch = CHILD(n, i);
		if (NCH(ch) >= 1 && TYPE(CHILD(ch, 0)) == NAME &&
		    strcmp(STR(CHILD(ch, 0)), "generators") == 0) {
			ps->p_generators = 1;
			break;
		}
	}
}
示例#29
0
static int
future_check_features(PyFutureFeatures *ff, node *n, const char *filename)
{
	int i;
	char *feature;
	node *ch, *nn;

	REQ(n, import_from);
	nn = CHILD(n, 3 + (TYPE(CHILD(n, 3)) == LPAR));
	if (TYPE(nn) == STAR) {
		PyErr_SetString(PyExc_SyntaxError, FUTURE_IMPORT_STAR);
		PyErr_SyntaxLocation(filename, nn->n_lineno);
		return -1;
	}
	REQ(nn, import_as_names);
	for (i = 0; i < NCH(nn); i += 2) {
		ch = CHILD(nn, i);
		REQ(ch, import_as_name);
		feature = STR(CHILD(ch, 0));
		if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
			continue;
		} else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
			continue;
		} else if (strcmp(feature, FUTURE_DIVISION) == 0) {
			ff->ff_features |= CO_FUTURE_DIVISION;
		} else if (strcmp(feature, "braces") == 0) {
			PyErr_SetString(PyExc_SyntaxError,
					"not a chance");
			PyErr_SyntaxLocation(filename, CHILD(ch, 0)->n_lineno);
			return -1;
		} else {
			PyErr_Format(PyExc_SyntaxError,
				     UNDEFINED_FUTURE_FEATURE, feature);
			PyErr_SyntaxLocation(filename, CHILD(ch, 0)->n_lineno);
			return -1;
		}
	}
	return 0;
}
示例#30
0
/* getRotation:
 * The function determines how much the block should be rotated
 * for best positioning with parent, assuming its center is at x and y
 * relative to the parent.
 * angle gives the angle of the new position, i.e., tan(angle) = y/x.
 * If sn has 2 nodes, we arrange the line of the 2 normal to angle.
 * If sn has 1 node, parent_pos has already been set to the 
 * correct angle assuming no rotation.
 * Otherwise, we find the node in sn connected to the parent and rotate
 * the block so that it is closer or at least visible to its node in the
 * parent.
 *
 * For COALESCED blocks, if neighbor is in left half plane, 
 * use unCOALESCED case.
 * Else let theta be angle, R = LEN(x,y), pho the radius of actual 
 * child block, phi be angle of neighbor in actual child block,
 * and r the distance from center of coalesced block to center of 
 * actual block. Then, the angle to rotate the coalesced block to
 * that the edge from the parent is tangent to the neighbor on the
 * actual child block circle is
 *    alpha = theta + M_PI/2 - phi - arcsin((l/R)*(sin B))
 * where l = r - rho/(cos phi) and beta = M_PI/2 + phi.
 * Thus, 
 *    alpha = theta + M_PI/2 - phi - arcsin((l/R)*(cos phi))
 */
static double
getRotation(block_t * sn, Agraph_t * g, double x, double y, double theta)
{
    double mindist2;
    Agraph_t *subg;
    /* Agedge_t* e; */
    Agnode_t *n, *closest_node, *neighbor;
    nodelist_t *list;
    double len2, newX, newY;
    int count;

    subg = sn->sub_graph;
#ifdef OLD
    parent = sn->parent;
#endif

    list = sn->circle_list;

    if (sn->parent_pos >= 0) {
	theta += M_PI - sn->parent_pos;
	if (theta < 0)
	    theta += 2 * M_PI;

	return theta;
    }

    count = sizeNodelist(list);
    if (count == 2) {
	return (theta - M_PI / 2.0);
    }

    /* Find node in block connected to block's parent */
    neighbor = CHILD(sn);
#ifdef OLD
    for (e = agfstedge(g, parent); e; e = agnxtedge(g, e, parent)) {
	n = e->head;
	if (n == parent)
	    n = e->tail;

	if ((BLOCK(n) == sn) && (PARENT(n) == parent)) {
	    neighbor = n;
	    break;
	}
    }
#endif
    newX = ND_pos(neighbor)[0] + x;
    newY = ND_pos(neighbor)[1] + y;
    mindist2 = LEN2(newX, newY);    /* save sqrts by using sqr of dist to find min */
    closest_node = neighbor;

    for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) {
	if (n == neighbor)
	    continue;

	newX = ND_pos(n)[0] + x;
	newY = ND_pos(n)[1] + y;

	len2 = LEN2(newX, newY);
	if (len2 < mindist2) {
	    mindist2 = len2;
	    closest_node = n;
	}
    }

    /* if((neighbor != closest_node) && !ISPARENT(neighbor)) { */
    if (neighbor != closest_node) {
	double rho = sn->rad0;
	double r = sn->radius - rho;
	double n_x = ND_pos(neighbor)[0];
	if (COALESCED(sn) && (-r < n_x)) {
	    double R = LEN(x, y);
	    double n_y = ND_pos(neighbor)[1];
	    double phi = atan2(n_y, n_x + r);
	    double l = r - rho / (cos(phi));

	    theta += M_PI / 2.0 - phi - asin((l / R) * (cos(phi)));
	} else {		/* Origin still at center of this block */
	    double phi = atan2(ND_pos(neighbor)[1], ND_pos(neighbor)[0]);
	    theta += M_PI - phi - PSI(neighbor);
	    if (theta > 2 * M_PI)
		theta -= 2 * M_PI;
	}
    } else
	theta = 0;
    return theta;
}