Beispiel #1
0
/*
* increment counter value in circular manner, call changestate()
* which turns on one LED and turns off others depending upon
* counter value.
*/
void rotate()
{
	const unsigned long int delayCount = 0x7ffff;
	int counter = 0;
	changestate(counter);
	while(1) 
	{
		if(sw1In()) 
		{
			counter = ((counter + 1) % 4);//move to next led
			changestate(counter);
			delay(delayCount);//wait for switch to be depressed
		}
	}
}
OZ_Thread *oz_knl_thread_setcurstate (OZ_Thread_state state, uLong nevents, OZ_Eventlist *eventlist)

{
  OZ_Thread *thread;
  uLong tc;

  if ((state != OZ_THREAD_STATE_RUN) && (state != OZ_THREAD_STATE_WEV)) {
    oz_crash ("oz_knl_thread_setcurstate: new state %d unsupported", thread -> state);
  }

  tc = oz_hw_smplock_wait (&smplock_tc);
  thread = curthread;
  OZ_KNL_CHKOBJTYPE (thread, OZ_OBJTYPE_THREAD);
  switch (thread -> state) {
    case OZ_THREAD_STATE_COM: {
      break;
    }
    case OZ_THREAD_STATE_RUN:
    case OZ_THREAD_STATE_WEV:
    case OZ_THREAD_STATE_ZOM: {
      changestate (thread, state);
      thread -> nevents   = nevents;
      thread -> eventlist = eventlist;
      break;
    }
    default: oz_crash ("oz_knl_thread_setcurstate: old state %d unsupported", thread -> state);
  }
  oz_hw_smplock_clr (&smplock_tc, tc);
  return (thread);
}
Beispiel #3
0
void builtincont(struct cmdline_tokens *tok, int state){
  if (tok->argc < 2){
    // app_error("Usage: %s [%jid/pid]\n", tok->argv[0]);
    return;
  }
  pid_t pid;

  /* JID */
  if (tok->argv[1][0]=='%'){
    int jid = atoi((char *)(tok->argv[1] + sizeof(char)));
    pid = jid2pid(jid);
    if (!pid)
      app_error("No such jid \n");
  }
  else{
    /* PID case */
    pid = atoi(tok->argv[1]);
    if (!pid2jid(pid))
      app_error("No such pid \n");
  }
  /* Common to both JID & PID */
  Kill(-pid, SIGCONT);
  changestate(job_list, pid, state);
  if (state==BG){
    printf("[%d] (%d) %s\n", pid2jid(pid), pid,
	   getjobpid(job_list,pid)->cmdline);
  }

  if (state==FG){
    wait_for_fg(pid);
  }
}
void MCButton::SetVisited(MCExecContext& ctxt, bool setting)
{
	bool t_dirty;
	t_dirty = changestate(setting, CS_VISITED);

	reseticon();

	if (t_dirty)
		Redraw();
}
void oz_knl_thread_wakewev (OZ_Thread *thread, uLong wakests)

{
  uLong tc;

  OZ_KNL_CHKOBJTYPE (thread, OZ_OBJTYPE_THREAD);
  tc = oz_hw_smplock_wait (&smplock_tc);
  if (thread -> state == OZ_THREAD_STATE_WEV) {
    thread -> waitsts = wakests;
    changestate (thread, OZ_THREAD_STATE_COM);
  }
  oz_hw_smplock_clr (&smplock_tc, tc);
}
void oz_knl_thread_exit (uLong status)

{
  OZ_KNL_CHKOBJTYPE (curthread, OZ_OBJTYPE_THREAD);
  oz_knl_iorundown (curthread, OZ_PROCMODE_KNL);	// do I/O rundown
  OZ_KNL_CHKOBJTYPE (curthread, OZ_OBJTYPE_THREAD);
  curthread -> waitsts = status;			// save its exit status
  while (1) {
    changestate (curthread, OZ_THREAD_STATE_ZOM);	// kill it off
    if (curthread -> exitevent != NULL) {		// maybe someone wants to know that we've exited
      oz_knl_event_inc (curthread -> exitevent, 1);
    }
    oz_knl_thread_wait ();				// loop in case some lowipl routine puts it in run state
  }
}
Beispiel #7
0
void sigchld_handler (int sig){
  pid_t pid;
  int status;

  while((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
    if(WIFSTOPPED(status)) {
      safe_printf("Job [%d] (%d) stopped by signal %d\n",
	     pid2jid(pid), pid, WSTOPSIG(status));
      changestate(job_list, pid, ST);
    }
    else {
      if(WIFSIGNALED(status)) {
	safe_printf("Job [%d] (%d) terminated by signal %d\n",
	       pid2jid(pid), pid, WTERMSIG(status));
      }
      deletejob(job_list, pid);
    }
  }
  return;
}
Beispiel #8
0
int *pop(chess *q, stack *s) {
	stacknode *p;
	int *loc, i;
	loc = (int *)malloc(sizeof(int) * 13);
	if(loc == NULL) {
		printw("Malloc failed");
		getch();
		exit(1);
	}
	if(empty(s) == 1) {
		mvprintw(25, 110, "Empty Stack");
		getch();
		changestate(q);
		return NULL;
	}
	p = s->tail;
	for(i = 0; i < 4; i++) {
		loc[i] = p->prloc[i];
		loc[i + 4] = p->locinput[i];
	}
	if(p->loc3) {/* If killed then restoring the piece */
		for(i = 8; i < 13; i++) {
			loc[i] = p->loc3[i-8];
		}
		if(p->loc3[0] != PAWN) {
			append(q, p->loc3, p->loc3[4]);
		}
	}
	if(p->previous) {
		s->tail = p->previous;
		s->tail->next = NULL;
	}
	else {
		s->head = NULL;	
		s->tail = NULL;
	}
	free(p);
	s->count--;
	return loc;
}
uLong oz_knl_thread_wait (void)

{
  int si;
  OZ_Thread **lthread, *thread;
  uLong tc;

get_something:
  tc = oz_hw_smplock_wait (&smplock_tc);
  if (tc != OZ_SMPLOCK_SOFTINT) oz_crash ("oz_knl_thread_wait: called at smplevel %u", tc);

  /* Do any pending lowipls */

  if (oz_knl_lowipl_lowipls != NULL) {
    oz_hw_smplock_clr (&smplock_tc, OZ_SMPLOCK_SOFTINT);
    oz_knl_lowipl_handleint ();
    goto get_something;
  }

  /* the original thread might have been put */
  /* in run state by an lowipl routine that */
  /* waited for an event flag and was */
  /* subsequently resumed, then it returned */
  /* to the wait loop here, well the thread */
  /* state will now be 'RUN' */

  OZ_KNL_CHKOBJTYPE (curthread, OZ_OBJTYPE_THREAD);
  if (curthread -> state == OZ_THREAD_STATE_RUN) {
    oz_hw_smplock_clr (&smplock_tc, OZ_SMPLOCK_SOFTINT);
    return;
  }

  /* Find a computable thread and start it */

  for (lthread = &allthreads; (thread = *lthread) != NULL; lthread = &(thread -> next)) {
    OZ_KNL_CHKOBJTYPE (thread, OZ_OBJTYPE_THREAD);
    if (thread -> state == OZ_THREAD_STATE_COM) break;
  }

  /* No thread is computable, wait for an interrupt then check again */

  if (thread == NULL) {
    oz_hw_smplock_clr (&smplock_tc, OZ_SMPLOCK_SOFTINT);
    oz_hw_cpu_waitint (NULL);
    goto get_something;
  }

  /* Have a computable thread, make it current and move to end of 'allthreads' list */

  newthread = thread;							/* save pointer in static variable */
  thread = thread -> next;						/* unlink from 'allthreads' list */
  *lthread = thread;
  while ((thread = *lthread) != NULL) lthread = &(thread -> next);	/* skip to end of 'allthreads' list */
  *lthread = newthread;							/* put new current thread on end of 'allthreads' list */
  newthread -> next  = NULL;
  changestate (newthread, OZ_THREAD_STATE_RUN);				/* set new state to 'running' */
  oldthread = curthread;						/* save old thread pointer */
  curthread = newthread;						/* set up new current thread */
  oz_hw_thread_switchctx (oldthread -> hwctx, newthread -> hwctx);	/* switch stacks */
  if (oldthread -> state == OZ_THREAD_STATE_ZOM) oz_knl_thread_increfc (oldthread, -1); /* if old one was zombie, get rid of it now */
  oz_hw_smplock_clr (&smplock_tc, OZ_SMPLOCK_SOFTINT);
}
Beispiel #10
0
main(int argc, char *argv[])
{
  int ch,err,notdone,vowflag,initflag;
  errorcount=0;
  switcher='~';
  true=1;
  false=0;
  tamilflag=false;
  tdelim=1;  /* i.e. control-a ::: if yah don't like it, change it */
  tspace[0]=tdelim;
  tspace[1]=' ';
  haccbox();
  vowflag=0;
  if (argc > 1) input = fopen(argv[1],"rb");
  if (input == (FILE *) NULL) {
	/* prompt for and open input file */
	for ( ; input == (FILE *) NULL ; input=get_file("rb","Enter name of input file: ")) ;
        }
        /* we are making these binary, as we have no guarantee what kind */
        /* of character may be in the transcription: we don't care about */
        /* ends of lines, as we are reading character by character */
   if (argc > 2) output = fopen(argv[2],"wb");
   if (output == (FILE *) NULL) {
	for ( ; output == (FILE *) NULL ; output=get_file("wb","Enter name of output file: ")) ;
	/* prompt for and open output file */
        }
   while ((ch = getc(input)) != EOF) {
	if (ch == switcher) changestate();
	else {
		if (ch == '|') {
                  vowflag=1;
		  notdone=1;
		  initflag=2;
		  while (notdone) {
		  ch=getc(input);
                  if (isalnum(ch)) {
                    initflag--;
                    if (vowflag==0) {
		       if (! isvowel(ch)) stringout("\\-");
                       }
		    if (isvowel(ch)) vowflag=1;
                    else vowflag=0;
                    }
                  else {
                     vowflag=1;
                     initflag=2;
                     }
		  if (ch==EOF) notdone=0;
		  else {
		    switch(ch) {
		      case '2': stringout("\\ndot{}");
		      	break;
		      case '3': stringout("\\nndot{}");
		      	break;
		      case '4': stringout("\\skts{}");
			break;
		      case '5': stringout("\\paln{}");
		      	break;
		      case '6': stringout("\\rdot{}");
		      	break;
		      case '7': stringout("\\rdotdot{}");
			break;
		      case 'T': stringout("\\tdot{}");
			 break;
		      case 'D': stringout("\\dotd{}");
			 break;
		      case '8':
		                 if ( initflag > 0 ) stringout("\\tdot{}");
		                 else {
		                      err=getc(input);
		                      if (err == '8') stringout("\\tdot{}\\tdot{}");
				      else {
					  stringout("\\dotd{}");
					  pushback(err);
					  }
		                      }
		      	break;
		      case '9': stringout("\\dotl{}");
		      	break;
		      case '|': notdone=0;
		        break;
		      default: putc(ch,output);
			} /* endcase */
		  } /* end else */
		} /* endwhile */
		} /* endif */
		else putc(ch,output);
	}  /* endelse */
	} /* endwhile */
   fclose(input);
   fclose(output);
   puts("Tamilize is done.");
}
Beispiel #11
0
void processtamil()
{
  char ch;
  int  newsyl;
  newsyl=true;
  for (tamilflag=true; tamilflag==true; ) {
    ch = getc(input);
    if (ch == EOF) abort();
    if (ch == switcher) changestate();
    else if (isspace(ch)) {
            stringout(tspace);
            charout(ch);            
            for ( ch=getc(input); isspace(ch); ch=getc(input)) charout(ch);
            pushback(ch);
            newsyl=true;
	    }
    else if (ispunct(ch) ) {
             if (ch == 125) printf("\nCharacter } encountered while scanning tamil -- probable error.\n");
             romanout(ch);
             newsyl=true;
             }
    else {
            switch (ch) {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u': if (newsyl==true) {
			      charout(tdelim);
			      newsyl=false;
			      }
                          charout(ch);
                          break;
                case 'c':
                case 't':
                case 'p':
                case 'm':
                case 'y':
                case 'r':
                case 'l':
                case 'v':
                case 's':
                case 'j':
                case 'x':
                case 'h': charout(tdelim);
                          charout(ch);
                          newsyl=false;
                          break;
                case 'k': charout(tdelim);
                          ch=getc(input);
                          if (ch=='4') charout('X');
                          else {
                              charout('k');
                              pushback(ch);
                              }
                          newsyl=false;
                          break;
                case '2': charout(tdelim);
                          charout('N');
                          newsyl=false;
                          break;
                case '3': charout(tdelim);
                          stringout("NN");
                          newsyl=false;
                          break;
                case '4': charout(tdelim);
                          charout('S');
                          newsyl=false;
                          break;
                case '5': charout(tdelim);
                          stringout("NY");
                          newsyl=false;
                          break;
                case '6': charout(tdelim);
                          charout('R');
                          newsyl=false;
                          break;
                case '7': charout(tdelim);
                          charout('Z');
                          newsyl=false;
                          break;
                case '8': charout(tdelim);
                          charout('T');
                          newsyl=false;
                          break;
                case '9': charout(tdelim);
                          charout('L');
                          newsyl=false;
                          break;
                case 'n': charout(tdelim);
                          ch=getc(input);
                          if (ch=='g') stringout("ng");
                          else {
                              charout('n');
                              pushback(ch);
                              }
                          newsyl=false;
                          break;
                default : transcribe_err(ch);
                          newsyl=true;
                } /* endcase */
    }  /* endif */
  }  /* endfor*/
}
Beispiel #12
0
/*
 * cmd_changestate()
 *
 *	Implements the door command to initate a state change operation.
 *
 *	NOTE: requires 'modify' authorization.
 */
static int
cmd_changestate(nvlist_t *args, nvlist_t **resultsp)
{
    hp_node_t	root = NULL;
    nvlist_t	*results = NULL;
    char		*path, *connection;
    ucred_t		*uc = NULL;
    uint_t		flags;
    int		rv, state, old_state, status;

    dprintf("cmd_changestate:\n");

    /* Get arguments */
    if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
            (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
            (nvlist_lookup_int32(args, HPD_STATE, &state) != 0)) {
        dprintf("cmd_changestate: invalid arguments.\n");
        return (EINVAL);
    }
    if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
        flags = 0;

    /* Get caller's credentials */
    if (door_ucred(&uc) != 0) {
        log_err("Cannot get door credentials (%s)\n", strerror(errno));
        return (EACCES);
    }

    /* Check authorization */
    if (check_auth(uc, HP_MODIFY_AUTH) != 0) {
        dprintf("cmd_changestate: access denied.\n");
        audit_changestate(uc, HP_MODIFY_AUTH, path, connection,
                          state, -1, ADT_FAIL_VALUE_AUTH);
        ucred_free(uc);
        return (EACCES);
    }

    /* Perform the state change operation */
    status = changestate(path, connection, state, flags, &old_state, &root);
    dprintf("cmd_changestate: changestate() == %d\n", status);

    /* Audit the operation */
    audit_changestate(uc, HP_MODIFY_AUTH, path, connection, state,
                      old_state, status);

    /* Caller's credentials no longer needed */
    ucred_free(uc);

    /*
     * Pack the results into an nvlist if there is an error snapshot.
     *
     * If any error occurs while packing the results, the original
     * error code from changestate() above is still returned.
     */
    if (root != NULL) {
        char	*buf = NULL;
        size_t	len = 0;

        dprintf("cmd_changestate: results nvlist required.\n");

        /* Pack and discard the error snapshot */
        rv = hp_pack(root, &buf, &len);
        hp_fini(root);
        if (rv != 0) {
            dprintf("cmd_changestate: hp_pack() failed (%s).\n",
                    strerror(rv));
            return (status);
        }

        /* Allocate nvlist for results */
        if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
            dprintf("cmd_changestate: nvlist_alloc() failed.\n");
            free(buf);
            return (status);
        }

        /* Add the results into the nvlist */
        if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
                (nvlist_add_byte_array(results, HPD_INFO, (uchar_t *)buf,
                                       len) != 0)) {
            dprintf("cmd_changestate: nvlist add failed.\n");
            nvlist_free(results);
            free(buf);
            return (status);
        }

        *resultsp = results;
    }

    return (status);
}
Beispiel #13
0
// check local path - if !localname, localpath is relative to l, with l == NULL
// being the root of the sync
// if localname is set, localpath is absolute and localname its last component
// path references a new FOLDERNODE: returns created node
// path references a existing FILENODE: returns node
// otherwise, returns NULL
LocalNode* Sync::checkpath(LocalNode* l, string* localpath, string* localname)
{
    LocalNode* ll = l;
    FileAccess* fa;
    bool newnode = false, changed = false;
    bool isroot;

    LocalNode* parent;
    string path;        // UTF-8 representation of tmppath
    string tmppath;     // full path represented by l + localpath
    string newname;     // portion of tmppath not covered by the existing
                        // LocalNode structure (always the last path component
                        // that does not have a corresponding LocalNode yet)

    if (localname)
    {
        // shortcut case (from within syncdown())
        isroot = false;
        parent = l;
        l = NULL;

        client->fsaccess->local2path(localpath, &path);
    }
    else
    {
        // construct full filesystem path in tmppath
        if (l)
        {
            l->getlocalpath(&tmppath);
        }

        if (localpath->size())
        {
            if (tmppath.size())
            {
                tmppath.append(client->fsaccess->localseparator);
            }

            tmppath.append(*localpath);
        }

        // look up deepest existing LocalNode by path, store remainder (if any)
        // in newname
        l = localnodebypath(l, localpath, &parent, &newname);

        // path invalid?
        if (!l && !newname.size())
        {
            return NULL;
        }

        string name = newname;
        client->fsaccess->local2name(&name);

        if (!client->app->sync_syncable(name.c_str(), &tmppath, &newname))
        {
            return NULL;
        }

        isroot = (l == &localroot && !newname.size());

        client->fsaccess->local2path(&tmppath, &path);
    }

    // postpone moving nodes into nonexistent parents
    if (parent && !parent->node)
    {
        return (LocalNode*)~0;
    }

    // attempt to open/type this file
    fa = client->fsaccess->newfileaccess();

    if (fa->fopen(localname ? localpath : &tmppath, true, false))
    {
        // match cached LocalNode state during initial/rescan to prevent costly re-fingerprinting
        // (just compare the fsids, sizes and mtimes to detect changes)
        if (fullscan)
        {
            // find corresponding LocalNode by file-/foldername
            int lastpart = client->fsaccess->lastpartlocal(localname ? localpath : &tmppath);

            string fname(localname ? *localpath : tmppath,
                                   lastpart,
                                   (localname ? *localpath : tmppath).size()-lastpart);

            LocalNode* cl = (parent ? parent : &localroot)->childbyname(&fname);

            if (cl && fa->fsid == cl->fsid)
            {
                // node found and same file
                l = cl;
                l->deleted = false;
                l->setnotseen(0);

                // if it's a file, size and mtime must match to qualify
                if (l->type != FILENODE || (l->size == fa->size && l->mtime == fa->mtime))
                {
                    l->scanseqno = scanseqno;

                    if (l->type == FOLDERNODE)
                    {
                        scan(localname ? localpath : &tmppath, fa);
                    }
                    else localbytes += l->size;

                    delete fa;
                    return l;
                }
            }
        }

        if (!isroot)
        {
            if (l)
            {
                // mark as present
                l->setnotseen(0);

                if (fa->type == FILENODE)
                {
                    // has the file been overwritten or changed since the last scan?
                    // or did the size or mtime change?
                    if (fa->fsidvalid)
                    {
                        // if fsid has changed, the file was overwritten
                        // (FIXME: handle type changes)
                        if (l->fsid != fa->fsid)
                        {
                            handlelocalnode_map::iterator it;

                            // was the file overwritten by moving an existing
                            // file over it?
                            if ((it = client->fsidnode.find(fa->fsid)) != client->fsidnode.end())
                            {
                                client->app->syncupdate_local_move(this, it->second->name.c_str(), path.c_str());

                                // immediately delete existing LocalNode and
                                // replace with moved one
                                delete l;

                                // (in case of a move, this synchronously
                                // updates l->parent and l->node->parent)
                                it->second->setnameparent(parent, localname ? localpath : &tmppath);

                                // mark as seen / undo possible deletion
                                it->second->setnotseen(0);

                                statecacheadd(it->second);

                                delete fa;
                                return it->second;
                            }
                            else
                            {
                                l->mtime = -1;  // trigger change detection
                            }
                        }
                    }

                    // no fsid change detected or overwrite with unknown file:
                    if (fa->mtime != l->mtime || fa->size != l->size)
                    {
                        if (fa->fsidvalid && (l->fsid != fa->fsid))
                        {
                            l->setfsid(fa->fsid);
                        }

                        m_off_t dsize = l->size;

                        if (l->genfingerprint(fa))
                        {
                            localbytes -= dsize - l->size;
                        }

                        client->app->syncupdate_local_file_change(this, path.c_str());

                        client->stopxfer(l);
                        l->bumpnagleds();
                        l->deleted = false;

                        client->syncactivity = true;

                        statecacheadd(l);

                        delete fa;
                        return l;
                    }
                }
                else
                {
                    // (we tolerate overwritten folders, because we do a
                    // content scan anyway)
                    if (fa->fsidvalid)
                    {
                        l->setfsid(fa->fsid);
                    }
                }
            }

            // new node
            if (!l)
            {
                // rename or move of existing node?
                handlelocalnode_map::iterator it;

                if (fa->fsidvalid && ((it = client->fsidnode.find(fa->fsid)) != client->fsidnode.end()))
                {
                    client->app->syncupdate_local_move(this, it->second->name.c_str(), path.c_str());

                    // (in case of a move, this synchronously updates l->parent
                    // and l->node->parent)
                    it->second->setnameparent(parent, localname ? localpath : &tmppath);

                    // make sure that active PUTs receive their updated filenames
                    client->updateputs();

                    statecacheadd(it->second);

                    // unmark possible deletion
                    it->second->setnotseen(0);

                    // immediately scan folder to detect deviations from cached state
                    if (fullscan)
					{
                        scan(localname ? localpath : &tmppath, fa);
                    }
                }
                else
                {
                    // this is a new node: add
                    l = new LocalNode;
                    l->init(this, fa->type, parent, localname ? localpath : &tmppath);

                    if (fa->fsidvalid)
                    {
                        l->setfsid(fa->fsid);
                    }

                    newnode = true;
                }
            }
        }

        if (l)
        {
            // detect file changes or recurse into new subfolders
            if (l->type == FOLDERNODE)
            {
                if (newnode)
                {
                    scan(localname ? localpath : &tmppath, fa);
                    client->app->syncupdate_local_folder_addition(this, path.c_str());

                    if (!isroot)
                    {
                        statecacheadd(l);
                    }
                }
                else
                {
                    l = NULL;
                }
            }
            else
            {
                if (isroot)
                {
                    // root node cannot be a file
                    changestate(SYNC_FAILED);
                }
                else 
                {
                    if (l->size > 0)
                    {
                        localbytes -= l->size;
                    }

                    if (l->genfingerprint(fa))
                    {
                        changed = true;
                        l->bumpnagleds();
                        l->deleted = false;
                    }

                    if (l->size > 0)
                    {
                        localbytes += l->size;
                    }

                    if (newnode)
                    {
                        client->app->syncupdate_local_file_addition(this, path.c_str());
                    }
                    else if (changed)
                    {
                        client->app->syncupdate_local_file_change(this, path.c_str());
                    }

                    if (newnode || changed)
                    {
                        statecacheadd(l);
                    }
                }
            }
        }

        if (changed || newnode)
        {
            client->syncactivity = true;
        }
    }
    else
    {
        if (fa->retry)
        {
            // fopen() signals that the failure is potentially transient - do
            // nothing and request a recheck
            dirnotify->notify(DirNotify::RETRY, ll, localpath->data(), localpath->size());
        }
        else if (l)
        {
            // immediately stop outgoing transfer, if any
            if (l->transfer)
            {
                client->stopxfer(l);
            }

            client->syncactivity = true;

            // in fullscan mode, missing files are handled in bulk in deletemissing()
            // rather than through setnotseen()
            if (!fullscan) l->setnotseen(1);
        }

        l = NULL;
    }

    delete fa;

    return l;
}
Beispiel #14
0
int checkfromall(chess *q, int *kingloc) {
	int *loc,i;
	q->c.count = 0;
	//Changing  the state just to get the required piece
	changestate(q);
	kingloc[0] = ROOK;//Changing the name to get the previouslocation
	loc = getpreviousloc(q, kingloc, CHECK);//See if the piece can be put in the kingloc. If yes then king is in check
	loc = checkifvalid(q, kingloc, loc, CHECK);
	if(loc != NULL) {
		//Just save the location
		if(q->enable == ENABLE) {
			mvprintw(20, 110, "CHECK from ROOK");	
		}
		copyloc(&q->c, loc);
		q->c.count++;
	}
	kingloc[0] = BISHOP;
	loc = getpreviousloc(q, kingloc, CHECK);
	loc = checkifvalid(q, kingloc, loc, CHECK);
	if(loc != NULL) {
		if(q->enable == ENABLE) {
			mvprintw(20, 110, "CHECK from BISHOP");	
		}
		if(q->c.count == 1) {
			(q->c.count)++;
			changestate(q);
			return CHECK;
		}
		else {
			//Save the location
			copyloc(&q->c, loc);
			(q->c.count)++;
		}
	}
	kingloc[0] = KNIGHT;
	loc = getpreviousloc(q, kingloc, CHECK);
	loc = checkifvalid(q, kingloc, loc, CHECK);
	if(loc != NULL) {
		if(q->enable == ENABLE) {
			mvprintw(20, 110, "CHECK from KNIGHT");
		}
		if(q->c.count == 1) {
			(q->c.count)++;
			changestate(q);
			return CHECK;
		}
		else {
			//Save the location
			copyloc(&q->c, loc);
			(q->c.count)++;
		}
	}
	kingloc[0] = QUEEN;
	loc = getpreviousloc(q, kingloc, CHECK);
	loc = checkifvalid(q, kingloc, loc, CHECK);
	if(loc != NULL) {
		if(q->enable == ENABLE) {
			mvprintw(20, 110, "CHECK from QUEEN");
		}
		if(q->c.count == 1) {
			(q->c.count)++;
			changestate(q);
			return CHECK;
		}
		else {
			//Save the location
			copyloc(&q->c, loc);
			(q->c.count)++;
		}
	}
	kingloc[0] = KING;
	loc = getpreviousloc(q, kingloc, CHECK);
	loc = checkifvalid(q, kingloc, loc, CHECK);
	if(loc != NULL) {
		if(q->enable == ENABLE) {
			mvprintw(20, 110, "CHECK from KING");	
		}
		//Save the location
		copyloc(&q->c, loc);
		(q->c.count)++;
		changestate(q);
		return CHECK;
	}
	changestate(q);
	if(q->c.count == 0) {
		return NOCHECK;
	}
	return CHECK;
}
void MCButton::SetArm(MCExecContext& ctxt, bool setting)
{
	if (changestate(setting, CS_ARMED))
		Redraw();
}
Beispiel #16
0
int main()
{

	signal (SIGINT, sig_handler);

	wtpconf_preinit();

	if (!read_config("./wtp_uci.conf")) {
		return 1;
	}
//	cw_dbg_opt_level = conf_dbg_level;


	if (!wtpconf_init()){
		return 1;
	};

	cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS;

	dtls_init();


	the_conn = conn_create_noq(-1, NULL);
	struct conn *conn = the_conn;

	conn->radios = mbag_i_create();
	conn->radios_upd=mbag_i_create(); 

	mbag_i_set_mbag(conn->radios,0,mbag_create());
	mbag_i_set_mbag(conn->radios_upd,0,mbag_create());



#define CWMOD "cisco"
#define CWBIND "cisco"
//#define CWMOD "capwap"
//#define CWBIND "capwap80211"


	struct mod_wtp *mod = modload_wtp(CWMOD);
	if (!mod) {
		printf("Can't load mod capwap\n");
		exit(0);
	}
	mod->init();

	mod->register_actions(&capwap_actions,MOD_MODE_CAPWAP);
	mod = modload_wtp(CWBIND);
	if (!mod) {
		printf("Can't load mod capwap80211\n");
		exit(0);
	}

	int rc = mod->register_actions(&capwap_actions,MOD_MODE_BINDINGS);

	conn->detected = 1;
	conn->dtls_verify_peer=0;
	conn->dtls_mtu = 12000;


	conn->actions = &capwap_actions;

	conn->outgoing = mbag_create();
	conn->incomming = mbag_create();
	conn->local = mbag_create();
	conn->config = mbag_create();

	the_conn->strict_capwap = 0;

	cfg_from_json(conn);
	setup_conf(conn);

	mbag_t r;
//	r  = mbag_i_get_mbag(conn->radios,0,NULL);
	r = conn->radios;
	MAVLITER_DEFINE(it,r);
	mavliter_foreach(&it){
		struct mbag_item *i=mavliter_get(&it);
		printf("RID = %d\n",i->iid);
		printf("DATA: %p\n",i->data);
		mbag_t radio= (mbag_t)i->data;
		struct mbag_item *mri = mbag_get(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION);
		
	if (!mri){
printf("Setting to 8 %p %p\n",mri,r);
		mbag_set_dword(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION,1);
	}
	else{
		printf("MRI %p\n",mri);
	}

		
	}
	



	mod_init_config(mod,conn->config);
	cfg_to_json();

	mbag_t mb = mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, NULL);
	printf("mbag %p\n", mb);


	cw_acpriolist_t acprios = cw_acpriolist_create();
	cw_acpriolist_set(acprios, "Master AC", strlen("Master AC"), 1);
	cw_acpriolist_set(acprios, "AC8new", strlen("AC8new"), 12);



	mbag_set_byte(conn->local, CW_ITEM_WTP_MAC_TYPE, CW_WTP_MAC_TYPE_SPLIT);
	mbag_set_byte(conn->local, CW_ITEM_WTP_FRAME_TUNNEL_MODE, CW_WTP_FRAME_TUNNEL_MODE_E);
	conn->wbid=1;




//	cw_set_msg_end_callback(conn->actions,CW_STATE_RUN,CW_MSG_CONFIGURATION_UPDATE_REQUEST,handle_update_req);


	if (!discovery())
		return -1;
	if (!join())
		return -1;

	if (!configure())
		return -1;

	cw_dbg(DBG_X,"Saveing config 0");

	cfg_to_json();

	changestate();


	run();

	//image_update();

	return 0;
}