Example #1
0
//insert at given position, if gtr than length, insert at end
void in(int val,int pos)
{
  p=newnode();
  p->val=val;
  t=h;
  int i=1;
  while(i<pos && t!=NULL)
    {
      if(t->next==NULL)
        break;
      t=t->next;
      i++;
    }
  if(t!=NULL)
    {
      if(pos==0)
	{
	  p->next=h;
	  h->last=p;
	  h=p;
	  length++;
	  return;
	}
      p->next=t->next;
      p->last=t;
      if(t->next!=NULL)
         t->next->last=p;
      t->next=p;
    }
  else
    {
      p->next=t;
      h=p;
    }
  length++;
}
Example #2
0
int newscene(lua_State *L, scene_t *scene)
/* recursively creates the userdata for the scene,
 * the root node and its children, and all other nested objects */
    {
    unsigned int i;
    TRACE_CREATE(scene, "scene");
    if(scene->mRootNode)
        {
        newnode(L, scene, scene->mRootNode);
        lua_pop(L, 1);
        }
#define New(what, newfunc) do {                     \
    for(i=0; i< scene->mNum##what; i++)             \
        { newfunc(L, scene, scene->m##what[i]); lua_pop(L, 1);  } } while(0)
    New(Meshes, newmesh);
    New(Materials, newmaterial);
    New(Lights, newlight);
    New(Textures, newtexture);
    New(Cameras, newcamera);
    New(Animations, newanimation);
#undef New
    newuserdata(L, (void*)scene, SCENE_MT);
    return 1;   
    }
Example #3
0
EORB_CPP_node *read_expr_ (void)
{
   EORB_CPP_node *l;
   EORB_CPP_node *r;
   char c;

#ifdef DEBUG_EXPR

   if (debugging)
   {
      outputs("~E");
   }
#endif
   l = read_expr_0();
   while (1)
   {
      c = getnhsexpand();
      switch (c)
      {
         case '\n':
         case ')':
            Push(c);
            return (l);
            break;
         case ',':
            r = read_expr_0();
            l = newnode(l, c, r);
            break;
         default:
            err_head();
            fprintf(stderr, "expression syntax error -- bad operator `%c'\n", c);
            return (l);
            break;
      }
   }
}
Example #4
0
/*
 * This implements the 'x' option.
 * Request that new entries be extracted.
 */
long
addfile(const char *name, ino_t ino, int type)
{
	struct entry *ep;
	long descend = hflag ? GOOD : FAIL;
	char buf[100];

	if (TSTINO(ino, dumpmap) == 0) {
		dprintf(stdout, "%s: not on the tape\n", name);
		return (descend);
	}
	if (ino == UFS_WINO && command == 'i' && !vflag)
		return (descend);
	if (!mflag) {
		(void) snprintf(buf, sizeof(buf), "./%llu",
		    (unsigned long long)ino);
		name = buf;
		if (type == NODE) {
			(void) genliteraldir(name, ino);
			return (descend);
		}
	}
	ep = lookupino(ino);
	if (ep != NULL) {
		if (strcmp(name, myname(ep)) == 0) {
			ep->e_flags |= NEW;
			return (descend);
		}
		type |= LINK;
	}
	ep = addentry(name, ino, type);
	if (type == NODE)
		newnode(ep);
	ep->e_flags |= NEW;
	return (descend);
}
Example #5
0
File: stmt.c Project: 0culus/ioq3
void definelab(int lab) {
	Code cp;
	Symbol p = findlabel(lab);

	assert(lab);
	walk(NULL, 0, 0);
	code(Label)->u.forest = newnode(LABEL+V, NULL, NULL, p);
	for (cp = codelist->prev; cp->kind <= Label; )
		cp = cp->prev;
	while (   cp->kind == Jump
	       && cp->u.forest->kids[0]
	       && specific(cp->u.forest->kids[0]->op) == ADDRG+P
	       && cp->u.forest->kids[0]->syms[0] == p) {
		assert(cp->u.forest->kids[0]->syms[0]->u.l.label == lab);
		p->ref--;
		assert(cp->next);
		assert(cp->prev);
		cp->prev->next = cp->next;
		cp->next->prev = cp->prev;
		cp = cp->prev;
		while (cp->kind <= Label)
			cp = cp->prev;
	}
}
Example #6
0
int main()
{
  int o,i,ans,x;
  o=0;
  tot=0;
  newnode(0,-1);
  scanf("%s",s);
  while (s[0]!='#')
  {
    i=0;
    tot=1;
    a[1].s=0;
    height=0;
    ans=0;
    x=1;
    s2=0;
    while (s[i])
    {
      if (s[i]=='d')
      {
        height++;
        if (height>ans) ans=height;
        x=add(x);
      }
      else
      {
        height--;
        x=a[x].fa;
      }
      i++;
    }
    printf("Tree %d: %d => %d\n",++o,ans,s2);
    scanf("%s",s);
  }
  return 0;
}
Example #7
0
/*
 * Insure that all the components of a pathname exist.
 */
void
pathcheck(char *name)
{
	char *cp;
	struct entry *ep;
	char *start;

	start = strchr(name, '/');
	if (start == 0)
		return;
	for (cp = start; *cp != '\0'; cp++) {
		if (*cp != '/')
			continue;
		*cp = '\0';
		ep = lookupname(name);
		if (ep == NULL) {
			/* Safe; we know the pathname exists in the dump. */
			ep = addentry(name, pathsearch(name)->d_ino, NODE);
			newnode(ep);
		}
		ep->e_flags |= NEW|KEEP;
		*cp = '/';
	}
}
int main()
{
    node* a[SIZE];
    int front = -1,rear = -1;
    node* root = newnode(2);
    insert(root,4);
    insert(root,5);
    insert(root,1);
    insert(root,3);
    insert(root,10);
    insert(root,7);
    enqueue(a,root,&front,&rear);
    while(!is_empty(front,rear)){
        node* temp = dequeue(a,&front,&rear);
        if(temp->left!=NULL){
            enqueue(a,temp->left,&front,&rear);
        }
        if(temp->right!=NULL){
            enqueue(a,temp->right,&front,&rear);
        }
        printf("%d\n",temp->value);
    }
    return 0;
}
Example #9
0
int main(){
int i,j=0,k;

struct node *root = newnode(8);
 /* root->left        = newnode(-1);
  root->right       = newnode(56);
  root->left->left  = newnode(11);
  root->left->right = newnode(89);
                                      //the above tree is not a binary search tree
  */
  root->left        = newnode(4);
  root->right       = newnode(12);
  root->left->left  = newnode(3);
  root->left->right = newnode(5);
  root->right->left=newnode(10);
   root->right->right=newnode(14);
 
 inorder(root);
 
 printf("inorder traversal of the tree is:\n");
 for(i=0;i<arr_l;i++){printf("%d ",arr[i]);} 
 
 for(i=1;i<arr_l;i++){
 
 if(arr[i]<arr[i-1]) {j=1; break;}
 }
 
 if(j==1) printf("\nthis is not a binary search tree");
 else printf("\nthis is a binary search tree");
  getchar();
  return 0;



 


}
Example #10
0
void main(){

	 root = newnode(10);
	 root->left = newnode(-2);
	 root->right = newnode(6);
	 root->left->left  = newnode(8);
	 root->left->right = newnode(-4);
	 root->right->left=newnode(7);
	 root->right->right=newnode(5);

	 inorder(root);
	 printf("\n");
	 convert_to_sum_tree(root);
	  inorder(root);








}
Example #11
0
/* Driver program to test above functions*/
int main()
{

    /* Constructed binary tree is
              10
            /   \
          8      12
        /
      3
    */
    struct node *root = newnode(22);
    root->left        = newnode(8);
    root->right       = newnode(22);
    root->left->left  = newnode(4);
    root->left->right  = newnode(12);
     root->left->right->left  = newnode(10);   
      root->left->right->right  = newnode(14);   
    // Populates nextRight pointer in all nodes
    connectRecur(root);
    print(root);

    getchar();
    return 0;
}
Example #12
0
/* Driver program to test above functions*/
int main()
{
  
  /* Constructed binary tree is
            10
          /   \
        8      2
      /  \    /
    3     5  2
  */
  struct node *root = newnode(10);
  root->left        = newnode(8);
  root->right       = newnode(2);
  root->left->left  = newnode(3);
  root->left->right = newnode(5);
  root->right->left = newnode(2);
  int sum=0;
  printPaths(root, &sum);
  printf("Total Sum is %d\n",sum);
  printf("Total sum is %d\n",Sum(root, 0));
  getchar();
  return 0;
}
Example #13
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* comp_atom (comp_t* com)
{
	qse_rex_node_t* atom;

	if (!IS_ESC(com))
	{
		switch (com->c.value)
		{
			case QSE_T('('):
				atom = comp_group (com);
				if (atom == QSE_NULL) return QSE_NULL;
				break;
			
			case QSE_T('.'):
				atom = newnode (com, QSE_REX_NODE_ANY);
				if (atom == QSE_NULL) return QSE_NULL;
				if (getc_esc(com) <= -1) return QSE_NULL;
				break;

			case QSE_T('^'):
				atom = newnode (com, QSE_REX_NODE_BOL);
				if (atom == QSE_NULL) return QSE_NULL;
				if (getc_esc(com) <= -1) return QSE_NULL;
				break;
	
			case QSE_T('$'):
				atom = newnode (com, QSE_REX_NODE_EOL);
				if (atom == QSE_NULL) return QSE_NULL;
				if (getc_esc(com) <= -1) return QSE_NULL;
				break;

			case QSE_T('['):
				atom = newnode (com, QSE_REX_NODE_CSET);
				if (atom == QSE_NULL) return QSE_NULL;
				if (getc_esc(com) <= -1) return QSE_NULL;
				if (charset(com, atom) <= -1) return QSE_NULL;
				break;

			default:
				if (com->rex->option & QSE_REX_STRICT)
				{
					/* check if a special charcter is at the 
					 * position that requires a normal character. */
					switch (com->c.value)
					{
						case QSE_T('{'):
							/* { is a normal charcter when bound is disabled */
							if (com->rex->option & QSE_REX_NOBOUND) break;

						case QSE_T(')'):
						case QSE_T('?'):
						case QSE_T('*'):
						case QSE_T('+'):
							/* it's at the wrong postion */
							com->rex->errnum = QSE_REX_ESPCAWP;
							return QSE_NULL;
					}
				}

				goto normal_char;
		}
	}
	else
	{
	normal_char:
		/* normal character */
		atom = newcharnode (com, com->c.value);
		if (atom == QSE_NULL) return QSE_NULL;
		if (getc_esc(com) <= -1) return QSE_NULL;
	}

	atom->occ.min = 1;
	atom->occ.max = 1;

	if (!IS_ESC(com))
	{
		/* handle the occurrence specifier, if any */
		if (comp_occ (com, atom) == QSE_NULL) return QSE_NULL;
	}

	return atom;
}
Example #14
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* newcharnode (comp_t* c, qse_char_t ch)
{
	qse_rex_node_t* n = newnode (c, QSE_REX_NODE_CHAR);
	if (n != QSE_NULL) n->u.c = ch;
	return n;
}
Example #15
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* newgroupendnode (comp_t* c, qse_rex_node_t* group)
{
	qse_rex_node_t* n = newnode (c, QSE_REX_NODE_GROUPEND);
	if (n != QSE_NULL) n->u.ge.group = group;
	return n;
}
Example #16
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* newgroupnode (comp_t* c)
{
	return newnode (c, QSE_REX_NODE_GROUP);
}
Example #17
0
File: SAM.cpp Project: xyiyy/icpc
void init_sam() {
	n_node = 0;
	last = root = newnode();
}
Example #18
0
int main()
{

    struct node *T        = newnode(26);
    T->right              = newnode(3);
    T->right->right       = newnode(3);
    T->left               = newnode(10);
    T->left->left         = newnode(4);
    T->left->left->right  = newnode(30);
    T->left->right        = newnode(6);


    struct node *S    = newnode(610);
    S->right          = newnode(68);
    S->left           = newnode(41);
    S->left->right    = newnode(360);

    if(is_subtree(T,S)==1)
        printf("sub tree found");
    if(is_subtree(T,S)==0)
        printf("sub tree not found");
    return 0;
}
Example #19
0
node integer(int n){
     node q = newnode(INT_CONST,int_const_tag);
     q->body.int_const.contents = strperm(intToString(n));
     return q;
     }
Example #20
0
/*
 *	For each directory entry on the incremental tape, determine which
 *	category it falls into as follows:
 *	KEEP - entries that are to be left alone.
 *	NEW - new entries to be added.
 *	EXTRACT - files that must be updated with new contents.
 *	LINK - new links to be added.
 *	Renames are done at the same time.
 */
long
nodeupdates(char *name, ino_t ino, int type)
{
	struct entry *ep, *np, *ip;
	long descend = GOOD;
	int lookuptype = 0;
	int key = 0;
		/* key values */
#		define ONTAPE	0x1	/* inode is on the tape */
#		define INOFND	0x2	/* inode already exists */
#		define NAMEFND	0x4	/* name already exists */
#		define MODECHG	0x8	/* mode of inode changed */

	/*
	 * This routine is called once for each element in the
	 * directory hierarchy, with a full path name.
	 * The "type" value is incorrectly specified as LEAF for
	 * directories that are not on the dump tape.
	 *
	 * Check to see if the file is on the tape.
	 */
	if (TSTINO(ino, dumpmap))
		key |= ONTAPE;
	/*
	 * Check to see if the name exists, and if the name is a link.
	 */
	np = lookupname(name);
	if (np != NULL) {
		key |= NAMEFND;
		ip = lookupino(np->e_ino);
		if (ip == NULL)
			panic("corrupted symbol table\n");
		if (ip != np)
			lookuptype = LINK;
	}
	/*
	 * Check to see if the inode exists, and if one of its links
	 * corresponds to the name (if one was found).
	 */
	ip = lookupino(ino);
	if (ip != NULL) {
		key |= INOFND;
		for (ep = ip->e_links; ep != NULL; ep = ep->e_links) {
			if (ep == np) {
				ip = ep;
				break;
			}
		}
	}
	/*
	 * If both a name and an inode are found, but they do not
	 * correspond to the same file, then both the inode that has
	 * been found and the inode corresponding to the name that
	 * has been found need to be renamed. The current pathname
	 * is the new name for the inode that has been found. Since
	 * all files to be deleted have already been removed, the
	 * named file is either a now unneeded link, or it must live
	 * under a new name in this dump level. If it is a link, it
	 * can be removed. If it is not a link, it is given a
	 * temporary name in anticipation that it will be renamed
	 * when it is later found by inode number.
	 */
	if (((key & (INOFND|NAMEFND)) == (INOFND|NAMEFND)) && ip != np) {
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
		} else {
			dprintf(stdout, "name/inode conflict, mktempname %s\n",
				myname(np));
			mktempname(np);
		}
		np = NULL;
		key &= ~NAMEFND;
	}
	if ((key & ONTAPE) &&
	  (((key & INOFND) && ip->e_type != type) ||
	   ((key & NAMEFND) && np->e_type != type)))
		key |= MODECHG;

	/*
	 * Decide on the disposition of the file based on its flags.
	 * Note that we have already handled the case in which
	 * a name and inode are found that correspond to different files.
	 * Thus if both NAMEFND and INOFND are set then ip == np.
	 */
	switch (key) {

	/*
	 * A previously existing file has been found.
	 * Mark it as KEEP so that other links to the inode can be
	 * detected, and so that it will not be reclaimed by the search
	 * for unreferenced names.
	 */
	case INOFND|NAMEFND:
		ip->e_flags |= KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ip));
		break;

	/*
	 * A file on the tape has a name which is the same as a name
	 * corresponding to a different file in the previous dump.
	 * Since all files to be deleted have already been removed,
	 * this file is either a now unneeded link, or it must live
	 * under a new name in this dump level. If it is a link, it
	 * can simply be removed. If it is not a link, it is given a
	 * temporary name in anticipation that it will be renamed
	 * when it is later found by inode number (see INOFND case
	 * below). The entry is then treated as a new file.
	 */
	case ONTAPE|NAMEFND:
	case ONTAPE|NAMEFND|MODECHG:
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
		} else {
			mktempname(np);
		}
		/* FALLTHROUGH */

	/*
	 * A previously non-existent file.
	 * Add it to the file system, and request its extraction.
	 * If it is a directory, create it immediately.
	 * (Since the name is unused there can be no conflict)
	 */
	case ONTAPE:
		ep = addentry(name, ino, type);
		if (type == NODE)
			newnode(ep);
		ep->e_flags |= NEW|KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ep));
		break;

	/*
	 * A file with the same inode number, but a different
	 * name has been found. If the other name has not already
	 * been found (indicated by the KEEP flag, see above) then
	 * this must be a new name for the file, and it is renamed.
	 * If the other name has been found then this must be a
	 * link to the file. Hard links to directories are not
	 * permitted, and are either deleted or converted to
	 * symbolic links. Finally, if the file is on the tape,
	 * a request is made to extract it.
	 */
	case ONTAPE|INOFND:
		if (type == LEAF && (ip->e_flags & KEEP) == 0)
			ip->e_flags |= EXTRACT;
		/* FALLTHROUGH */
	case INOFND:
		if ((ip->e_flags & KEEP) == 0) {
			renameit(myname(ip), name);
			moveentry(ip, name);
			ip->e_flags |= KEEP;
			dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
				flagvalues(ip));
			break;
		}
		if (ip->e_type == NODE) {
			descend = FAIL;
			fprintf(stderr,
				"deleted hard link %s to directory %s\n",
				name, myname(ip));
			break;
		}
		ep = addentry(name, ino, type|LINK);
		ep->e_flags |= NEW;
		dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
			flagvalues(ep));
		break;

	/*
	 * A previously known file which is to be updated. If it is a link,
	 * then all names referring to the previous file must be removed
	 * so that the subset of them that remain can be recreated.
	 */
	case ONTAPE|INOFND|NAMEFND:
		if (lookuptype == LINK) {
			removeleaf(np);
			freeentry(np);
			ep = addentry(name, ino, type|LINK);
			if (type == NODE)
			        newnode(ep);
			ep->e_flags |= NEW|KEEP;
			dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name,
				flagvalues(ep));
			break;
		}
		if (type == LEAF && lookuptype != LINK)
			np->e_flags |= EXTRACT;
		np->e_flags |= KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(np));
		break;

	/*
	 * An inode is being reused in a completely different way.
	 * Normally an extract can simply do an "unlink" followed
	 * by a "creat". Here we must do effectively the same
	 * thing. The complications arise because we cannot really
	 * delete a directory since it may still contain files
	 * that we need to rename, so we delete it from the symbol
	 * table, and put it on the list to be deleted eventually.
	 * Conversely if a directory is to be created, it must be
	 * done immediately, rather than waiting until the
	 * extraction phase.
	 */
	case ONTAPE|INOFND|MODECHG:
	case ONTAPE|INOFND|NAMEFND|MODECHG:
		if (ip->e_flags & KEEP) {
			badentry(ip, "cannot KEEP and change modes");
			break;
		}
		if (ip->e_type == LEAF) {
			/* changing from leaf to node */
			for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) {
				if (ip->e_type != LEAF)
					badentry(ip, "NODE and LEAF links to same inode");
				removeleaf(ip);
				freeentry(ip);
			}
			ip = addentry(name, ino, type);
			newnode(ip);
		} else {
			/* changing from node to leaf */
			if ((ip->e_flags & TMPNAME) == 0)
				mktempname(ip);
			deleteino(ip->e_ino);
			ip->e_next = removelist;
			removelist = ip;
			ip = addentry(name, ino, type);
		}
		ip->e_flags |= NEW|KEEP;
		dprintf(stdout, "[%s] %s: %s\n", keyval(key), name,
			flagvalues(ip));
		break;

	/*
	 * A hard link to a directory that has been removed.
	 * Ignore it.
	 */
	case NAMEFND:
		dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key),
			name);
		descend = FAIL;
		break;

	/*
	 * If we find a directory entry for a file that is not on
	 * the tape, then we must have found a file that was created
	 * while the dump was in progress. Since we have no contents
	 * for it, we discard the name knowing that it will be on the
	 * next incremental tape.
	 */
	case 0:
		fprintf(stderr, "%s: (inode %ju) not found on tape\n",
		    name, (uintmax_t)ino);
		break;

	/*
	 * If any of these arise, something is grievously wrong with
	 * the current state of the symbol table.
	 */
	case INOFND|NAMEFND|MODECHG:
	case NAMEFND|MODECHG:
	case INOFND|MODECHG:
		fprintf(stderr, "[%s] %s: inconsistent state\n", keyval(key),
			name);
		break;

	/*
	 * These states "cannot" arise for any state of the symbol table.
	 */
	case ONTAPE|MODECHG:
	case MODECHG:
	default:
		panic("[%s] %s: impossible state\n", keyval(key), name);
		break;
	}
	return (descend);
}
Example #21
0
/* xlapply - apply a function to arguments (already on the stack) */
LVAL xlapply(int argc)
{
    LVAL *oldargv,fun,val;
    LVAL funname;
    LVAL old_profile_fixnum = profile_fixnum;
    FIXTYPE *old_profile_count_ptr = profile_count_ptr;
    int oldargc;

    /* get the function */
    fun = xlfp[1];

    /* get the functional value of symbols */
    if (symbolp(fun)) {
        funname = fun;  /* save it */
        while ((val = getfunction(fun)) == s_unbound)
            xlfunbound(fun);
        fun = xlfp[1] = val;

        if (profile_flag && atomp(funname)) {
            LVAL profile_prop = findprop(funname, s_profile);
            if (null(profile_prop)) {
                /* make a new fixnum, don't use cvfixnum because
                   it would return shared pointer to zero, but we
                   are going to modify this integer in place --
                   dangerous but efficient.
                 */
                profile_fixnum = newnode(FIXNUM);
                profile_fixnum->n_fixnum = 0;
                setplist(funname, cons(s_profile,
                                       cons(profile_fixnum,
                                            getplist(funname))));
                setvalue(s_profile, cons(funname, getvalue(s_profile)));
            } else profile_fixnum = car(profile_prop);
            profile_count_ptr = &getfixnum(profile_fixnum);
        }
    }

    /* check for nil */
    if (null(fun))
        xlerror("bad function",fun);

    /* dispatch on node type */
    switch (ntype(fun)) {
    case SUBR:
        oldargc = xlargc;
        oldargv = xlargv;
        xlargc = argc;
        xlargv = xlfp + 3;
        val = (*getsubr(fun))();
        xlargc = oldargc;
        xlargv = oldargv;
        break;
    case CONS:
        if (!consp(cdr(fun)))
            xlerror("bad function",fun);
        if (car(fun) == s_lambda) {
            fun = xlclose(NIL,
                          s_lambda,
                          car(cdr(fun)),
                          cdr(cdr(fun)),
                          xlenv,xlfenv);
        } else
            xlerror("bad function",fun);
        /**** fall through into the next case ****/
    case CLOSURE:
        if (gettype(fun) != s_lambda)
            xlerror("bad function",fun);
        val = evfun(fun,argc,xlfp+3);
        break;
    default:
        xlerror("bad function",fun);
    }

    /* restore original profile counting state */
    profile_fixnum = old_profile_fixnum;
    profile_count_ptr = old_profile_count_ptr;

    /* remove the call frame */
    xlsp = xlfp;
    xlfp = xlfp - (int)getfixnum(*xlfp);

    /* return the function value */
    return (val);
}
Example #22
0
/* evform - evaluate a form */
LOCAL LVAL evform(LVAL form)
{
    LVAL fun,args,val,type;
    LVAL tracing=NIL;
    LVAL *argv;
    LVAL old_profile_fixnum = profile_fixnum;
    FIXTYPE *old_profile_count_ptr = profile_count_ptr;
    LVAL funname;
    int argc;

    /* protect some pointers */
    xlstkcheck(2);
    xlsave(fun);
    xlsave(args);

    (*profile_count_ptr)++; /* increment profile counter */

    /* get the function and the argument list */
    fun = car(form);
    args = cdr(form);

    funname = fun;

    /* get the functional value of symbols */
    if (symbolp(fun)) {
        if (getvalue(s_tracelist) && member(fun,getvalue(s_tracelist)))
            tracing = fun;
        fun = xlgetfunction(fun);
    }

    /* check for nil */
    if (null(fun))
        xlerror("bad function",NIL);

    /* dispatch on node type */
    switch (ntype(fun)) {
    case SUBR:
        argv = xlargv;
        argc = xlargc;
        xlargc = evpushargs(fun,args);
        xlargv = xlfp + 3;
        trenter(tracing,xlargc,xlargv);
        val = (*getsubr(fun))();
        trexit(tracing,val);
        xlsp = xlfp;
        xlfp = xlfp - (int)getfixnum(*xlfp);
        xlargv = argv;
        xlargc = argc;
        break;
    case FSUBR:
        argv = xlargv;
        argc = xlargc;
        xlargc = pushargs(fun,args);
        xlargv = xlfp + 3;
        val = (*getsubr(fun))();
        xlsp = xlfp;
        xlfp = xlfp - (int)getfixnum(*xlfp);
        xlargv = argv;
        xlargc = argc;
        break;
    case CONS:
        if (!consp(cdr(fun)))
            xlerror("bad function",fun);
        if ((type = car(fun)) == s_lambda)
             fun = xlclose(NIL,
                           s_lambda,
                           car(cdr(fun)),
                           cdr(cdr(fun)),
                           xlenv,xlfenv);
        else
            xlerror("bad function",fun);
        /**** fall through into the next case ****/
    case CLOSURE:
        /* do profiling */
        if (profile_flag && atomp(funname)) {
            LVAL profile_prop = findprop(funname, s_profile);
            if (null(profile_prop)) {
                /* make a new fixnum, don't use cvfixnum because
                   it would return shared pointer to zero, but we
                   are going to modify this integer in place --
                   dangerous but efficient.
                 */
                profile_fixnum = newnode(FIXNUM);
                profile_fixnum->n_fixnum = 0;
                setplist(funname, cons(s_profile,
                                       cons(profile_fixnum,
                                            getplist(funname))));
                setvalue(s_profile, cons(funname, getvalue(s_profile)));
            } else profile_fixnum = car(profile_prop);
            profile_count_ptr = &getfixnum(profile_fixnum);
        }

        if (gettype(fun) == s_lambda) {
            argc = evpushargs(fun,args);
            argv = xlfp + 3;
            trenter(tracing,argc,argv);
            val = evfun(fun,argc,argv);
            trexit(tracing,val);
            xlsp = xlfp;
            xlfp = xlfp - (int)getfixnum(*xlfp);
        }
        else {
            macroexpand(fun,args,&fun);
            val = xleval(fun);
        }
        profile_fixnum = old_profile_fixnum;
        profile_count_ptr = old_profile_count_ptr;
        break;
    default:
        xlerror("bad function",fun);
    }

    /* restore the stack */
    xlpopn(2);

    /* return the result value */
    return (val);
}
Example #23
0
node String(char *s){
     node q = newnode(STRING,string_tag);
     q->body.unique_string.characters = s;
     return q;
     }
Example #24
0
static Renode *parseatom(struct cstate *g)
{
	Renode *atom;
	if (g->lookahead == L_CHAR) {
		atom = newnode(g, P_CHAR);
		atom->c = g->yychar;
		next(g);
		return atom;
	}
	if (g->lookahead == L_CCLASS) {
		atom = newnode(g, P_CCLASS);
		atom->cc = g->yycc;
		next(g);
		return atom;
	}
	if (g->lookahead == L_NCCLASS) {
		atom = newnode(g, P_NCCLASS);
		atom->cc = g->yycc;
		next(g);
		return atom;
	}
	if (g->lookahead == L_REF) {
		atom = newnode(g, P_REF);
		if (g->yychar == 0 || g->yychar > g->nsub || !g->sub[g->yychar])
			die(g, "invalid back-reference");
		atom->n = g->yychar;
		atom->x = g->sub[g->yychar];
		next(g);
		return atom;
	}
	if (accept(g, '.'))
		return newnode(g, P_ANY);
	if (accept(g, '(')) {
		atom = newnode(g, P_PAR);
		if (g->nsub == MAXSUB)
			die(g, "too many captures");
		atom->n = g->nsub++;
		atom->x = parsealt(g);
		g->sub[atom->n] = atom;
		if (!accept(g, ')'))
			die(g, "unmatched '('");
		return atom;
	}
	if (accept(g, L_NC)) {
		atom = parsealt(g);
		if (!accept(g, ')'))
			die(g, "unmatched '('");
		return atom;
	}
	if (accept(g, L_PLA)) {
		atom = newnode(g, P_PLA);
		atom->x = parsealt(g);
		if (!accept(g, ')'))
			die(g, "unmatched '('");
		return atom;
	}
	if (accept(g, L_NLA)) {
		atom = newnode(g, P_NLA);
		atom->x = parsealt(g);
		if (!accept(g, ')'))
			die(g, "unmatched '('");
		return atom;
	}
	die(g, "syntax error");
	return NULL;
}
Example #25
0
node IntegerN(char *s, unsigned int len) {
     node q = newnode(INT_CONST,int_const_tag);
     q->body.int_const.contents = strnperm(s,len);
     return q;
     }
Example #26
0
/*
 *  find out about the other side.  go to it's root if requested.  set
 *  image mode if a Plan9 system.
 */
void
preamble(char *mountroot)
{
	char *p, *ep;
	int rv;
	OS *o;

	/*
	 *  create a root directory mirror
	 */
	remroot = newnode(0, s_copy("/"));
	remroot->d->qid.type = QTDIR;
	remroot->d->mode = DMDIR|0777;
	remdir = remroot;

	/*
	 *  get system type
	 */
	sendrequest("SYST", nil);
	switch(getreply(&ctlin, msg, sizeof(msg), 1)){
	case Success:
		for(o = oslist; o->os != Unknown; o++)
			if(strncmp(msg+4, o->name, strlen(o->name)) == 0)
				break;
		os = o->os;
		if(os == NT)
			os = Unix;
		break;
	default:
		os = defos;
		break;
	}
	if(os == Unknown)
		os = defos;

	remrootpath = s_reset(remrootpath);
	switch(os){
	case NetWare:
              /*
               * Request long, rather than 8.3 filenames,
               * where the Servers & Volume support them.
               */
              sendrequest("SITE LONG", nil);
              getreply(&ctlin, msg, sizeof(msg), 0);
              /* FALL THRU */
	case Unix:
	case Plan9:
		/*
		 *  go to the remote root, if asked
		 */
		if(mountroot){
			sendrequest("CWD", mountroot);
			getreply(&ctlin, msg, sizeof(msg), 0);
		} else {
			s_append(remrootpath, "/usr/");
			s_append(remrootpath, user);
		}

		/*
		 *  get the root directory
		 */
		sendrequest("PWD", nil);
		rv = getreply(&ctlin, msg, sizeof(msg), 1);
		if(rv == PermFail){
			sendrequest("XPWD", nil);
			rv = getreply(&ctlin, msg, sizeof(msg), 1);
		}
		if(rv == Success){
			p = strchr(msg, '"');
			if(p){
				p++;
				ep = strchr(p, '"');
				if(ep){
					*ep = 0;
					s_append(s_reset(remrootpath), p);
				}
			}
		}

		break;
	case Tops:
	case VM:
		/*
		 *  top directory is a figment of our imagination.
		 *  make it permanently cached & valid.
		 */
		CACHED(remroot);
		VALID(remroot);
		remroot->d->atime = time(0) + 100000;

		/*
		 *  no initial directory.  We are in the
		 *  imaginary root.
		 */
		remdir = newtopsdir("???");
		topsdir[0] = 0;
		if(os == Tops && readdir(remdir) >= 0){
			CACHED(remdir);
			if(*topsdir)
				remdir->remname = s_copy(topsdir);
			VALID(remdir);
		}
		break;
	case VMS:
		/*
		 *  top directory is a figment of our imagination.
		 *  make it permanently cached & valid.
		 */
		CACHED(remroot);
		VALID(remroot);
		remroot->d->atime = time(0) + 100000;

		/*
		 *  get current directory
		 */
		sendrequest("PWD", nil);
		rv = getreply(&ctlin, msg, sizeof(msg), 1);
		if(rv == PermFail){
			sendrequest("XPWD", nil);
			rv = getreply(&ctlin, msg, sizeof(msg), 1);
		}
		if(rv == Success){
			p = strchr(msg, '"');
			if(p){
				p++;
				ep = strchr(p, '"');
				if(ep){
					*ep = 0;
					remroot = remdir = vmsdir(p);
				}
			}
		}
		break;
	case MVS:
		usenlst = 1;
		break;
	}

	if(os == Plan9)
		image();
}
Example #27
0
int main(int argc, char *argv[], char *envp[]) {
  char line[256];
  char ch;
  char *pwd;
  int i;
  cmd_ptr *cmdptr = NULL;

  pwd = malloc(sizeof(char) * 1024);
  jlist = jobs_init();
  //signal(SIGCHLD, SIG_DFL);
  signal(SIGINT,  SIG_IGN);
  signal(SIGTERM, SIG_IGN);
  signal(SIGQUIT, SIG_IGN);
  signal(SIGTSTP, SIG_IGN);
  signal(SIGSTOP, SIG_IGN);


  for (;;) {
    struct task *newtask;
    struct tnode *nodelist;
    strcpy(pwd, getenv("PWD"));
    printf("[CSC3150 shell:%s]$", pwd);

    line[0] = 0;
    i = 0;
    while ((ch = getchar()) != '\n')
      line[i++] = ch;
    line[i] = 0;
    if (line[0] == 0)
      continue;
    //temp=malloc(sizeof(char)*(strlen(line)+1));
    //strcpy(temp,line);
    if (!firstck(line)) {
      printf("Error: invalid input command line\n");
      continue;
    }
    //printf("Error\n");
    cmdptr = malloc(sizeof(cmd_ptr));
    initialize2(cmdptr);
    newtask = malloc(sizeof(struct task));
    newtask->cmd = malloc(sizeof(char) * (strlen(line) + 1));
    strcpy(newtask->cmd, line);
    jlist->job[jlist->n++] = newtask;

    if (start_chk(line) == 2) {
      nodelist = bnode(line);
      exec1(nodelist);
      continue;
    }
    if (start_chk(line) == 3)
      getcmd3(line, cmdptr);
    else if (start_chk(line) == 4)
      getcmd4(line, cmdptr);
    else if (start_chk(line) == 5)
      getcmd5(line, cmdptr);
    else if (start_chk(line) == 6)
      getcmd6(line, cmdptr);
    else if (start_chk(line) == 7)
      getcmd7(line, cmdptr);
    else if (start_chk(line) == 8)
      getcmd8(line, cmdptr);

    else {
      printf("Error: invalid input command line\n");
      continue;
    }


    nodelist = newnode(cmdptr);
    newtask->tids = execute(nodelist, NULL, NULL);
    if (newtask->tids != NULL) {
      jlist->job[jlist->n] = newtask;
      jlist->n++;
    }
    lwait(newtask->tids);

  }


  return 0;
}
Example #28
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* newendnode (comp_t* c)
{
	return newnode (c, QSE_REX_NODE_END);
}
Example #29
0
void xinsert(struct tnode **pn, struct tdata tn)
{
	int median, t;
	struct tnode *cur = *pn, *temp;
	/* if cur is root and null , that is cur is root */
	if(!root) {
		root = newnode();
		root->key[0] = tn.key;
		/*strcpy(&temp->name[0], tn.name);*/
		return;
	}
	/* if leaf */
	if(!cur->s && !cur->m && !cur->l) {
		/* if cur is full */
		if(cur->key[0] && cur->key[1]) {
			cur->key[2] = tn.key;
			/*strcpy(&(cur->name[2]), tn.name);*/
			/* pick up median key and 
			   push it up to the par node
			 */
			if(tn.key < cur->key[0]) {
				median = 0;
			} else if(tn.key > cur->key[1]) {
				median = 1;
			} else median = 2;

			pushup_split(cur, median);
		} else if(cur->key[0] > tn.key) {
			cur->key[1] = cur->key[0];
			/* cur->name[2] = cur->name[0] */
			cur->key[0] = tn.key;
		} else {
			cur->key[1] = tn.key;
		}
		return;
	} else if(tn.key < cur->key[0]) {
		xinsert(&cur->s, tn);
	} else if(cur->key[1] && tn.key >= cur->key[0] && tn.key < cur->key[1]) {
		xinsert(&cur->m, tn);
	} else if(cur->key[1] && tn.key >= cur->key[1]) {
		xinsert(&cur->l, tn);
	} else if(!cur->key[1]) {
		xinsert(&cur->m, tn);
	}

	/* if there is a pushup from the previous */
	if(cur->key[2]) {
		if(cur->key[1]) {
			if(cur->key[0] > cur->key[2]) {
				median = 0;
			} else if(cur->key[1] < cur->key[2]) {
				median = 1;
			} else median = 2;

			pushup_split(cur, median); 
		} else {
			if(cur->key[0] > cur->key[2]) {
				cur->key[1] = cur->key[0];
				cur->key[0] = cur->key[2];
				cur->key[2] = 0;
			} else {
				cur->key[1] = cur->key[2];
				cur->key[2] = 0;
			}
		}
	}
}
Example #30
0
File: rex.c Project: DeadZen/qse
static qse_rex_node_t* newnopnode (comp_t* c)
{
	return newnode (c, QSE_REX_NODE_NOP);
}