Example #1
0
vector processZeros(vector data)
{
    bool needProcess = false;
    int start = 0;
    int end = 0;
    for (int i=0; i<data.x; i++)
    {
        end = i - 1;
        if (getv(data, i) != 0 && needProcess)
        {
            needProcess = false;
            for (int j=end; j>=start; j--)
            {
                setv(data, j, getv(data, i));
            }
        }
        else if (getv(data, i) == 0 && !needProcess)
        {
            start = i;
            needProcess = true;
        }
    }
    if (needProcess)
    {
        end++;
        for (int i=start; i<=end; i++)
        {
            setv(data, i, getv(data, start-1));
        }
    }
    return data;
}
Example #2
0
void setv(int i, int value, int node = 1, int left = 0, int right = maxn-1) {
	if (left > i || right < i)
		return;
	if (left == right) {
		t[left] = value;
		return;
	}
	int mid = (left + right) >> 1;
	setv(i, value, node * 2, left, mid);
	setv(i, value, node * 2 + 1, mid + 1, right);
	tminPos[node] = t[tminPos[node * 2]] <= t[tminPos[node * 2 + 1]] ? tminPos[node * 2] : tminPos[node * 2 + 1];
}
Example #3
0
File: vararg4.c Project: Justme0/dg
int main(void)
{
	int a = 0;
	setv(1, foo, &a);
	test_assert(a == 17);
	return 0;
}
Example #4
0
int main()
{
	int n;
	
	while(scanf("%d",&n),n)
	{
		memset(map,' ',sizeof(map));
		len=4*n+2;
		h=4*n-2;
		init();
		for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			scanf("%d",&str[i][j]);	
			if(str[i][j]==1)
			{
				setl(1+4*i,3+4*j);
			}
			else if(str[i][j]==-1)
			{
				setv(1+4*i,3+4*j);
			}
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(str[i][j]==0)
			{
				set(1+4*i,3+4*j);
			}
		}
		print();
	}
	return 0;	
}
Example #5
0
void SchoolFish::applyLayer(int layer)
{
	switch (layer)
	{
	case -3:
		setv(EV_LOOKAT, 0);
	break;
	}
}
Example #6
0
File: Par.hpp Project: hust220/nsp
	void setv(T &&t, K &&k, V && ...rest) const {
		if (_pars.find(k) != _pars.end()) {
			auto && l = _pars.at(k);
			t.resize(l.size());
			std::copy(l.begin(), l.end(), t.begin());
		}
		else {
			setv(t, rest...);
		}
	}
Example #7
0
void
setcopy(const Char *var, const Char *val, int flags)
{
    Char *copy;

    copy = Strsave(val);
    cleanup_push(copy, xfree);
    setv(var, copy, flags);
    cleanup_ignore(copy);
    cleanup_until(copy);
}
Example #8
0
    void stash::end_draw()
    {
        if( !drawing )
            return;

        // Debug dump.
        if( debug )
        {
            if( nverts+6 < VERT_COUNT )
            {
                float x = 0, y = 0, *v = &verts[ nverts*4 ];

                v = setv(v, x, y, 0, 0);
                v = setv(v, x+tw, y, 1, 0);
                v = setv(v, x+tw, y+th, 1, 1);

                v = setv(v, x, y, 0, 0);
                v = setv(v, x+tw, y+th, 1, 1);
                v = setv(v, x, y+th, 0, 1);

                nverts += 6;
            }
        }

        flush_draw();
        drawing = 0;
    }
Example #9
0
    void stash::draw_text( size_t idx, float size, float x, float y, const char* s, float* dx )
    {
        if( tex && idx < fonts.size() && fonts[idx].data.size() )
        {
            short isize = (short)(size*10.0f);
            sth_quad q;

            for ( unsigned int codepoint, state = 0; *s; ++s)
            {
                if (decutf8(&state, &codepoint, *(unsigned char*)s)) continue;

                if (nverts+6 >= VERT_COUNT)
                    flush_draw();

                if (!get_quad(&fonts[idx], codepoint, isize, &x, &y, &q)) continue;

                float *v = &verts[nverts*4];

                v = setv(v, q.x0, q.y0, q.s0, q.t0);
                v = setv(v, q.x1, q.y0, q.s1, q.t0);
                v = setv(v, q.x1, q.y1, q.s1, q.t1);

                v = setv(v, q.x0, q.y0, q.s0, q.t0);
                v = setv(v, q.x1, q.y1, q.s1, q.t1);
                v = setv(v, q.x0, q.y1, q.s0, q.t1);

                nverts += 6;
            }

            if (dx) *dx = x;
        }
    }
Example #10
0
/*-------------------------------------------------------------------------
 * evalcoord2f - evaluate a point on a surface
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::evalcoord2f( long, REAL u, REAL v )
{
    REAL domain[2];
    domain[0] = u;
    domain[1] = v;
    if( equal(v,vvals[0]) ) {
  mapeval( domain, 0, 0 );
    } else if( equal(v,vvals[1]) ) {
  mapeval( domain, 1, 0 );
    } else if( equal(v,vvals[2]) ) {
  mapeval( domain, 2, 0 );
    } else {
  // approximately 20-30% of the time this branch is taken
  int index = nextlru();
  setv( v, index );
  mapeval( domain, index, 0 );
    }
}
Example #11
0
    /**
     * MANDATORY, decompose rectangle
     *
     * @param s set, representing rectangle to decompose
     *
     * @param sv resulting two (or more) rectangles
     * 
     * @param record the incumbent value
     *
     */
    virtual void  branch (Set & s, GVector < Set > & sv, GVector < Solution > & solv, Solution & incumbent, BNBBranchInfo * info, InfiniInt ql)
    {
      bool rv;
      Set asetv[MAX_BNB_CHILDREN];
      FixedVector < Set > setv(asetv, MAX_BNB_CHILDREN);
      rv = false;
      sv.push_back(s);
      if(!mDiscarders.empty()) {
	int sz = mDiscarders.size();
	for(int i = 0; i < sz; i++){
	  if(sv.empty())
	    break;
	  while(!sv.empty()) {
	    Set s = sv.back();
	    sv.pop_back();
	    mDiscarders[i]->discard(s, setv, solv, incumbent, info);
	  }
	  int sz = setv.size();
	  for(int i = 0; i < sz; i ++) {
	    sv.push_back(setv[i]);
	  }
	  setv.clear();
	  //sv.insert(sv.end(), setv.begin(), setv.end());
	}
      }
      //TODO make selection of sets to produce solutions
      int sz = sv.size();
      for(int i = 0; i < sz; i ++) {
	Solution sol;
	if(makeSolution(sv[i], sol)) 
	  solv.push_back(sol);
      }
      /*
      if(mOptions & Options::DO_LOCAL_SEARCH) {
	int sz = solv.size();
	for(int i = 0; i <  sz; i++){
	  improveSolution(solv[i]);
	}
      }
      */
    }
Example #12
0
/*-------------------------------------------------------------------------
 * evalpoint2i - evaluate a grid point
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::evalpoint2i( long u, long v )
{
    int gridi = 1 + (int) u;
    REAL domain[2];
    domain[0] = u * dus + us;
    domain[1] = v * dvs + vs;

    if( equal(domain[1], vvals[1]) ) {
  compute( domain, 1, gridi );
    } else if( equal(domain[1], vvals[0]) ) {
  compute( domain, 0, gridi );
    } else if( equal(domain[1], vvals[2]) ) {
  mapeval( domain, 2, 0 );
    } else {
  // this branch is executed less than 20% of the time
  int index = nextlru();
  setv( domain[1], index );
  mapeval( domain, index, 0 );
    }
}
Example #13
0
void deriveNSfractions(bool data, int mode, bool bjet = false)
{
  if (mode==0) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1);
    return;
  }
  if (mode==2) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(0.7);
    return;
  }
  if (mode==4) {
    for (unsigned i=0;i<binbounds.size()-1;i++)
      NSfrac.push_back(1.3);
    return;
  }

  TString fnpp;
  if (bjet)
    fnpp = data ? "dtppjpf" : "mcppbfa";
  else
    fnpp = data ? "dtppjpf" : "mcppqcd";
  auto filepp = config.getfile_djt(fnpp);

  seth(1,0,PI);
  auto hppNS = geth("hppNS");
  auto hppAS = geth("hppAS");

  Fill(filepp,[&] (dict &d) {
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hppNS->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hppAS->Fill(d["dphi21"],d["weight"]);
  });

  float a_pp = hppNS->Integral()/hppAS->Integral();
  cout<<"a_pp "<<a_pp<<endl;


  TString fnPbPb;
  if (bjet)
    fnPbPb = data ? "dtPbbjt" : "mcPbbfa";
  else
    fnPbPb = data ? "dtPbjcl" : "mcPbqcd";
  auto file = config.getfile_djt(fnPbPb);
  vector<TString> histn;
  for (unsigned i=0;i<binbounds.size()-1;i++)
    histn.push_back(Form("PbPb%d%d",binbounds[i],binbounds[i+1]));
  setv(histn);

  auto hPbPbNS = getv("hPbPbNS");
  auto hPbPbAS = getv("hPbPbAS");

  auto hPbPbNSsig = getv("hPbPbNSsig");

  Fill(file,[&] (dict &d) {
    int b = getbin(d["bin"]);
    float w = d["weight"];
    if (bjet && !(d["discr_csvV1_1"]>0.9 && d["discr_csvV1_2"]>0.9)) return;  
    if (bjet && d["pairCode21"]==0) w*=processweight((int)d["bProdCode"]);
    if (!data && d["pthat"]<50) return;  
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13) hPbPbNS[b]->Fill(d["dphi21"],d["weight"]);
    if (d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]>PI23) hPbPbAS[b]->Fill(d["dphi21"],d["weight"]);

    if (!data && d["jtpt1"]>pt1cut && d["jtpt2"]>pt2cut && d["dphi21"]<PI13 && (d["subid2"]==0 && d["refpt2"]>20))
      hPbPbNSsig[b]->Fill(d["dphi21"],d["weight"]);

  });

  vector<double> binmean;
  vector<double> nsfractrue;
  vector<double> nsfracest;

  for (unsigned i=0;i<binbounds.size()-1;i++) {
    float a_PbPb = hPbPbNS[i]->Integral()/hPbPbAS[i]->Integral();
    float x = (1-a_pp/a_PbPb)/(1-a_pp);
    NSfrac.push_back(mode==1 ? x : -1);// = old stupid adding of the signal : 2-x);
    // cout<<binbounds[i]<<" - "<<binbounds[i+1]<<" = "<<NSfrac[i]<<endl;

    nsfractrue.push_back(1-hPbPbNSsig[i]->Integral()/hPbPbNS[i]->Integral());
    nsfracest.push_back(NSfrac[NSfrac.size()-1]);
    binmean.push_back((binbounds[i]+binbounds[i+1])/2);
  }

  auto c = getc();
  TGraph *g = new TGraph(binbounds.size()-1,&binmean[0],&nsfractrue[0]);
  g->Draw();
  SavePlot(c,bjet ? "bjetfractionofNS" : "incfractionofNS");

  auto c2 = getc();
  TGraph *g2 = new TGraph(binbounds.size()-1,&binmean[0],&nsfracest[0]);
  g2->Draw();
  SavePlot(c2,bjet ? "bjetfractionofNSdata" : "incfractionofNSdata");



///////////////////////////// DATA:
// bin<20 : 0.93
// bin>=20 && bin<60 : 0.84
// bin>=60 : 0.39
////////////////////////////


}
Example #14
0
/*ARGSUSED*/
void
dolet(Char **v, struct command *dummy)
{
    Char *p;
    Char   *vp, c, op;
    int    hadsub;
    int     subscr;

    USE(dummy);
    v++;
    p = *v++;
    if (p == 0) {
	prvars();
	return;
    }
    do {
	hadsub = 0;
	vp = p;
	if (letter(*p))
	    for (; alnum(*p); p++)
		continue;
	if (vp == p || !letter(*vp))
	    stderror(ERR_NAME | ERR_VARBEGIN);
	if (*p == '[') {
	    hadsub++;
	    p = getinx(p, &subscr);
	}
	if (*p == 0 && *v)
	    p = *v++;
	if ((op = *p) != 0)
	    *p++ = 0;
	else
	    stderror(ERR_NAME | ERR_ASSIGN);

	/*
	 * if there is no expression after the '=' then print a "Syntax Error"
	 * message - strike
	 */
	if (*p == '\0' && *v == NULL)
	    stderror(ERR_NAME | ERR_ASSIGN);

	vp = Strsave(vp);
	cleanup_push(vp, xfree);
	if (op == '=') {
	    c = '=';
	    p = xset(p, &v);
	}
	else {
	    c = *p++;
	    if (any("+-", c)) {
		if (c != op || *p)
		    stderror(ERR_NAME | ERR_UNKNOWNOP);
		p = Strsave(STR1);
	    }
	    else {
		if (any("<>", op)) {
		    if (c != op)
			stderror(ERR_NAME | ERR_UNKNOWNOP);
		    stderror(ERR_NAME | ERR_SYNTAX);
		}
		if (c != '=')
		    stderror(ERR_NAME | ERR_UNKNOWNOP);
		p = xset(p, &v);
	    }
	}
	cleanup_push(p, xfree);
	if (op == '=') {
	    if (hadsub)
		asx(vp, subscr, p);
	    else
		setv(vp, p, VAR_READWRITE);
	    cleanup_ignore(p);
	}
	else if (hadsub) {
	    struct varent *gv = getvx(vp, subscr);
	    Char *val;

	    val = operate(op, gv->vec[subscr - 1], p);
	    cleanup_push(val, xfree);
	    asx(vp, subscr, val);
	    cleanup_ignore(val);
	    cleanup_until(val);
	}
	else {
	    Char *val;

	    val = operate(op, varval(vp), p);
	    cleanup_push(val, xfree);
	    setv(vp, val, VAR_READWRITE);
	    cleanup_ignore(val);
	    cleanup_until(val);
	}
	update_vars(vp);
	cleanup_until(vp);
    } while ((p = *v++) != NULL);
}
Example #15
0
/*ARGSUSED*/
void
doset(Char **v, struct command *c)
{
    Char *p;
    Char   *vp;
    Char  **vecp;
    int    hadsub;
    int     subscr;
    int	    flags = VAR_READWRITE;
    int    first_match = 0;
    int    last_match = 0;
    int    changed = 0;

    USE(c);
    v++;
    do {
	changed = 0;
	/*
	 * Readonly addition From: Tim P. Starrin <*****@*****.**>
	 */
	if (*v && eq(*v, STRmr)) {
	    flags = VAR_READONLY;
	    v++;
	    changed = 1;
	}
	if (*v && eq(*v, STRmf) && !last_match) {
	    first_match = 1;
	    v++;
	    changed = 1;
	}
	if (*v && eq(*v, STRml) && !first_match) {
	    last_match = 1;
	    v++;
	    changed = 1;
	}
    } while(changed);
    p = *v++;
    if (p == 0) {
	plist(&shvhed, flags);
	return;
    }
    do {
	hadsub = 0;
	vp = p;
	if (!letter(*p))
	    stderror(ERR_NAME | ERR_VARBEGIN);
	do {
	    p++;
	} while (alnum(*p));
	if (*p == '[') {
	    hadsub++;
	    p = getinx(p, &subscr);
	}
	if (*p != '\0' && *p != '=')
	    stderror(ERR_NAME | ERR_VARALNUM);
	if (*p == '=') {
	    *p++ = '\0';
	    if (*p == '\0' && *v != NULL && **v == '(')
		p = *v++;
	}
	else if (*v && eq(*v, STRequal)) {
	    if (*++v != NULL)
		p = *v++;
	}
	if (eq(p, STRLparen)) {
	    Char **e = v;

	    if (hadsub)
		stderror(ERR_NAME | ERR_SYNTAX);
	    for (;;) {
		if (!*e)
		    stderror(ERR_NAME | ERR_MISSING, ')');
		if (**e == ')')
		    break;
		e++;
	    }
	    p = *e;
	    *e = 0;
	    vecp = saveblk(v);
	    if (first_match)
	       flags |= VAR_FIRST;
	    else if (last_match)
	       flags |= VAR_LAST;

	    set1(vp, vecp, &shvhed, flags);
	    *e = p;
	    v = e + 1;
	}
	else if (hadsub) {
	    Char *copy;

	    copy = Strsave(p);
	    cleanup_push(copy, xfree);
	    asx(vp, subscr, copy);
	    cleanup_ignore(copy);
	    cleanup_until(copy);
	}
	else
	    setv(vp, Strsave(p), flags);
	update_vars(vp);
    } while ((p = *v++) != NULL);
}
Example #16
0
/*
 * Karl Kleinpaste, 21oct1983.
 * Set up a one-word alias command, for use for special things.
 * This code is based on the mainline of process().
 */
void
aliasrun(int cnt, Char *s1, Char *s2)
{
    struct wordent w, *new1, *new2;	/* for holding alias name */
    struct command *t = NULL;
    jmp_buf_t osetexit;
    int status;
    size_t omark;

    getexit(osetexit);
    if (seterr) {
	xfree(seterr);
	seterr = NULL;	/* don't repeatedly print err msg. */
    }
    w.word = STRNULL;
    new1 = xcalloc(1, sizeof w);
    new1->word = Strsave(s1);
    if (cnt == 1) {
	/* build a lex list with one word. */
	w.next = w.prev = new1;
	new1->next = new1->prev = &w;
    }
    else {
	/* build a lex list with two words. */
	new2 = xcalloc(1, sizeof w);
	new2->word = Strsave(s2);
	w.next = new2->prev = new1;
	new1->next = w.prev = new2;
	new1->prev = new2->next = &w;
    }
    cleanup_push(&w, lex_cleanup);

    /* Save the old status */
    status = getn(varval(STRstatus));

    /* expand aliases like process() does. */
    alias(&w);
    /* build a syntax tree for the command. */
    t = syntax(w.next, &w, 0);
    cleanup_push(t, syntax_cleanup);
    if (seterr)
	stderror(ERR_OLD);

    psavejob();
    cleanup_push(&cnt, psavejob_cleanup); /* cnt is used only as a marker */

    /* catch any errors here */
    omark = cleanup_push_mark();
    if (setexit() == 0)
	/* execute the parse tree. */
	/*
	 * From: Michael Schroeder <*****@*****.**>
	 * was execute(t, tpgrp);
	 */
	execute(t, tpgrp > 0 ? tpgrp : -1, NULL, NULL, TRUE);
    /* reset the error catcher to the old place */
    cleanup_pop_mark(omark);
    resexit(osetexit);
    if (haderr) {
	haderr = 0;
	/*
	 * Either precmd, or cwdcmd, or periodic had an error. Call it again so
	 * that it is removed
	 */
	if (precmd_active)
	    precmd();
	if (postcmd_active)
	    postcmd();
#ifdef notdef
	/*
	 * XXX: On the other hand, just interrupting them causes an error too.
	 * So if we hit ^C in the middle of cwdcmd or periodic the alias gets
	 * removed. We don't want that. Note that we want to remove precmd
	 * though, cause that could lead into an infinite loop. This should be
	 * fixed correctly, but then haderr should give us the whole exit
	 * status not just true or false.
	 */
	else if (cwdcmd_active)
	    cwd_cmd();
	else if (beepcmd_active)
	    beep_cmd();
	else if (periodic_active)
	    period_cmd();
#endif /* notdef */
    }
    cleanup_until(&w);
    pendjob();
    /* Restore status */
    setv(STRstatus, putn((tcsh_number_t)status), VAR_READWRITE);
}
Example #17
0
/*-------------------------------------------------------------------------
 * makeMesh - make the mesh of points on lattice
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::makeMesh( long umin, long umax, long vmin, long vmax )
{
    assert( umax - umin >= 0 );
    assert( vmax - vmin >= 0 );

    REAL domain[2];
    REAL v0;
    int vstart;

    REAL v1 = vs + dvs * vmin;

    int lastv = (int) (vmax + 1);
    for( int gridv1 = (int) (vmin)+1; gridv1 != lastv; gridv1++ ) {

  v0 = v1;
  /* strength reduction == roundoff error */
  v1 = vs + dvs * gridv1;  

  if( equal(v0, vvals[1]) ) {
      if( ! equal( v1, vvals[0]) ) {
    setv( v1, 0 );
      }
      vstart = 1;
  } else if( equal(v0, vvals[0]) ) {
      if( ! equal(v1, vvals[1]) ) {
          setv( v1, 1 );
      }
      vstart = 0;
  } else if( equal(v1, vvals[1]) ) {
      setv( v0, 0 );
      vstart = 0;
  } else {
      setv( v0, 1 );
      setv( v1, 0 );
      vstart = 1;
  }

  assert( equal(vvals[vstart],v0) );
  assert( equal(vvals[1-vstart],v1) );

  bgnqstrip();
  if( vstart == 1 ) {
      int lastu = (int) (umax + 1);
      int gridi = (int) umin;
      for( int gridu = gridi++; gridu != lastu; gridu = gridi++ ) {

    /* strength reduction == roundoff error */
    domain[0] = us + dus * gridu;

    domain[1] = vvals[1];
    compute( domain, 1, gridi );

    domain[1] = vvals[0];
    compute( domain, 0, gridi );
      }
  } else {
      int lastu = (int) (umax + 1);
      int gridi = (int) umin;
      for( int gridu = gridi++; gridu != lastu; gridu = gridi++ ) {
    /* strength reduction == roundoff error */
    domain[0] = us + dus * gridu;

    domain[1] = vvals[0];
    compute( domain, 0, gridi );

    domain[1] = vvals[1];
    compute( domain, 1, gridi );
      }
  }
  endqstrip();
    }
}
Example #18
0
File: ntfunc.c Project: phase/tcsh
int nt_texec(char *prog, char**args ) {

	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	HANDLE htemp;
	DWORD type=0;
	DWORD dwCreationflags;
	unsigned int priority;
	char *argv0 = NULL, *savepath = NULL;
	char *cmdstr,*cmdend ;
	char *originalPtr = NULL;
	unsigned int cmdsize,cmdlen;
	char *p2;
	char **savedargs;
	int retries=0;
	int hasdot =0;
	int is_winnt=0;
	int retval = 1;

	memset(&si,0,sizeof(si));
	savedargs = args;

	/* MUST FREE !! */
	originalPtr = cmdstr= heap_alloc(MAX_PATH<<2);
	cmdsize = MAX_PATH<<2;

	is_winnt = (gdwPlatform != VER_PLATFORM_WIN32_WINDOWS);


	p2 = cmdstr;

	cmdlen = 0;
	cmdlen += copy_quote_and_fix_slashes(prog,cmdstr,&hasdot);
	p2 += cmdlen;

	if (*cmdstr != '"') {
		// If not quoted, skip initial character we left for quote
		*cmdstr = 'A';
		cmdstr++; 
		cmdsize--;
	}
	*p2 = 0; 
	cmdend = p2;

	if (!is_winnt) {
		argv0 = NULL;
	}
	else {
		argv0= heap_alloc(MAX_PATH);
		(void)StringCbPrintf(argv0,MAX_PATH,"%s",prog);
	}

	si.cb = sizeof(STARTUPINFO);
	si.dwFlags = STARTF_USESTDHANDLES;
	htemp= (HANDLE)_get_osfhandle(SHIN);
	DuplicateHandle(GetCurrentProcess(),htemp,GetCurrentProcess(),
			&si.hStdInput,0,TRUE,DUPLICATE_SAME_ACCESS);
	htemp= (HANDLE)_get_osfhandle(SHOUT);
	DuplicateHandle(GetCurrentProcess(),htemp,GetCurrentProcess(),
			&si.hStdOutput,0,TRUE,DUPLICATE_SAME_ACCESS);
	htemp= (HANDLE)_get_osfhandle(SHDIAG);
	DuplicateHandle(GetCurrentProcess(),htemp,GetCurrentProcess(),
			&si.hStdError,0,TRUE,DUPLICATE_SAME_ACCESS);


	/* 
	   quotespace hack needed since execv() would have separated args, but
	   createproces doesnt
	   -amol 9/14/96
	 */

	args++; // the first arg is the command

	dprintf("nt_texec calling c_a_a_q");
	if(concat_args_and_quote(args,&originalPtr,&cmdstr,&cmdlen,&cmdend,&cmdsize) == NULL)
	{
		retval = 1;
		errno  = ENOMEM;
		heap_free(originalPtr);
		goto free_mem;
	}

	*cmdend = 0;

	dwCreationflags = GetPriorityClass(GetCurrentProcess());
	priority = GetThreadPriority(GetCurrentThread());

	if (is_winnt) {
		retries = 0;
		// For NT, try ShellExecuteEx first
		do {
			if (GetBinaryType(argv0,&type)) 
				break;
			if (GetLastError() == ERROR_BAD_EXE_FORMAT){
				errno = ENOEXEC;
				if (!__nt_only_start_exes)
					try_shell_ex(savedargs,0,FALSE);
				if (errno) {
					retval = 1; 
					goto free_mem;
				}
				else {
					retval = 0;
					goto free_mem;
				}
			}
			// only try shellex again after appending ".exe fails
			else if ( retries > 1 ){
				if (
						( (argv0[0] == '\\') ||(argv0[0] == '/') ) &&
						( (argv0[1] == '\\') ||(argv0[1] == '/') ) &&
						(!args[1])
				   )
					if (!__nt_only_start_exes)
						try_shell_ex(savedargs,0,FALSE);
				errno  = ENOENT;
			}
			if (retries == 0)
				(void)StringCbPrintf(argv0,MAX_PATH,"%s.exe",prog);
			else if (retries == 1) {
				(void)StringCbPrintf(argv0,MAX_PATH,"%s.EXE",prog);
			}
			retries++;
		}while(retries < 3);
	}
	savepath = fix_path_for_child();
re_cp:
	dprintf("nt_texec cmdstr %s\n",cmdstr);


	if (!CreateProcess(argv0,
				cmdstr,
				NULL,
				NULL,
				TRUE, // need this for redirecting std handles
				dwCreationflags,
				NULL,//envcrap,
				NULL,
				&si,
				&pi) ){

		if (GetLastError() == ERROR_BAD_EXE_FORMAT) {
			errno  = ENOEXEC;
		}
		else if (GetLastError() == ERROR_INVALID_PARAMETER) {
			errno = ENAMETOOLONG;
		}else {
			errno  = ENOENT;
		}
		if (!is_winnt && !hasdot) { //append '.' to the end if needed
			StringCbCat(cmdstr,cmdsize,".");
			hasdot=1;
			goto re_cp;
		}
		retval = 1;
	}
	else{
		int gui_app ;
		DWORD exitcode;
		char guivar[50];


		if (GetEnvironmentVariable("TCSH_NOASYNCGUI",guivar,50))
			gui_app=0;
		else
			gui_app= is_gui(argv0);

		if(!gui_app) {
			WaitForSingleObject(pi.hProcess,INFINITE);
			(void)GetExitCodeProcess(pi.hProcess,&exitcode);
			setv(STRstatus, putn(exitcode), VAR_READWRITE);/*FIXRESET*/
		}
		retval = 0;
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
	}
free_mem:
	CloseHandle(si.hStdInput);
	CloseHandle(si.hStdOutput);
	CloseHandle(si.hStdError);

	if(savepath)
		restore_path(savepath);

	heap_free(originalPtr);
	if (argv0)
		heap_free(argv0);
	return retval;
}
Example #19
0
GraphData * ProcWave2Data(QString fname)
{
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    QFile file(fname);
    file.open(QIODevice::ReadOnly);
    WaveFile * waveFile = waveOpenHFile(file.handle());
    qDebug() << "waveOpenFile" << LOG_DATA;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "chunkDataSize" << LOG_DATA;
    short int bits = littleEndianBytesToUInt16(waveFile->formatChunk->significantBitsPerSample);
    qDebug() << "significantBitsPerSample" << LOG_DATA;

    vector wave = sptk_v2v(waveFile->dataChunk->waveformData, size, bits);
    qDebug() << "wave" << LOG_DATA;

    vector frame = sptk_frame(wave, sptk_settings->frame);
    qDebug() << "frame" << LOG_DATA;

    vector intensive = vector_intensive(frame, sptk_settings->frame->leng, sptk_settings->frame->shift);
    qDebug() << "intensive" << LOG_DATA;

    vector window = sptk_window(frame, sptk_settings->window);
    qDebug() << "window" << LOG_DATA;

    vector lpc = sptk_lpc(frame, sptk_settings->lpc);
    qDebug() << "lpc" << LOG_DATA;

    vector spec = sptk_spec(lpc, sptk_settings->spec);
    qDebug() << "spec " << maxv(spec) << LOG_DATA;

    vector spec_proc;
    if (sptk_settings->spec->proc == 0){
        spec_proc = vector_pow_log(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_log" << LOG_DATA;
    } else if (sptk_settings->spec->proc == 1){
        spec_proc = vector_pow_exp(spec, sptk_settings->spec->factor, sptk_settings->spec->min);
        qDebug() << "spec_exp" << LOG_DATA;
    }
    qDebug() << "spec_proc " << maxv(spec_proc) << LOG_DATA;

    vector pitch = processZeros(sptk_pitch_spec(wave, sptk_settings->pitch, intensive.x));
    qDebug() << "pitch" << LOG_DATA;

    vector mask = getFileMask(waveFile, wave, pitch.x);
    qDebug() << "mask" << LOG_DATA;

    vector pitch_cutted = processZeros(vector_cut_by_mask(pitch, mask));
    qDebug() << "pitch_cutted" << LOG_DATA;
    double pitch_min = getv(pitch_cutted, minv(pitch_cutted));
    double pitch_max = getv(pitch_cutted, maxv(pitch_cutted));

    vector intensive_cutted = vector_cut_by_mask(intensive, mask);
    qDebug() << "intensive_cutted" << LOG_DATA;

    vector inverted_mask = vector_invert_mask(mask);
    qDebug() << "inverted_mask" << LOG_DATA;

    vector pitch_interpolate = vector_interpolate_by_mask(
                pitch_cutted,
                inverted_mask,
                0,
                sptk_settings->plotF0->interpolation_type
                );
    qDebug() << "pitch_interpolate" << LOG_DATA;

    vector intensive_interpolate = vector_interpolate_by_mask(
                intensive_cutted,
                inverted_mask,
                0,
                sptk_settings->plotEnergy->interpolation_type
                );
    qDebug() << "intensive_interpolate" << LOG_DATA;

    vector pitch_mid = vector_smooth_mid(pitch_interpolate, sptk_settings->plotF0->frame);
    qDebug() << "pitch_mid" << LOG_DATA;

    vector intensive_mid = vector_smooth_lin(intensive_interpolate, sptk_settings->plotEnergy->frame);
    qDebug() << "intensive_mid" << LOG_DATA;

    vector norm_wave = normalizev(wave, 0.0, 1.0);

    MaskData md_p = getLabelsFromFile(waveFile, MARK_PRE_NUCLEUS);
    MaskData md_n = getLabelsFromFile(waveFile, MARK_NUCLEUS);
    MaskData md_t = getLabelsFromFile(waveFile, MARK_POST_NUCLEUS);

    vector p_mask = readMaskFromFile(waveFile, wave.x, MARK_PRE_NUCLEUS);
    qDebug() << "p_mask" << LOG_DATA;

    vector n_mask = readMaskFromFile(waveFile, wave.x, MARK_NUCLEUS);
    qDebug() << "n_mask" << LOG_DATA;

    vector t_mask = readMaskFromFile(waveFile, wave.x, MARK_POST_NUCLEUS);
    qDebug() << "t_mask" << LOG_DATA;

    vector p_wave = zero_to_nan(vector_cut_by_mask(norm_wave, p_mask));
    qDebug() << "p_mask" << LOG_DATA;

    vector n_wave = zero_to_nan(vector_cut_by_mask(norm_wave, n_mask));
    qDebug() << "n_mask" << LOG_DATA;

    vector t_wave = zero_to_nan(vector_cut_by_mask(norm_wave, t_mask));
    qDebug() << "t_mask" << LOG_DATA;

    vector pnt_mask = onesv(norm_wave.x);
    for (int i=0; i<p_mask.x && i<n_mask.x && i<t_mask.x && i<norm_wave.x; i++) {
        if (getv(p_mask, i) == 1 || getv(n_mask, i) == 1 || getv(t_mask, i) == 1)
        {
            setv(pnt_mask, i, 0);
        } else {
            setv(pnt_mask, i, 1);
        }
    }

    vector display_wave = zero_to_nan(vector_cut_by_mask(norm_wave, pnt_mask));

    freev(frame);
    freev(window);
    freev(lpc);
    freev(pitch_cutted);
    freev(intensive_cutted);
    freev(inverted_mask);
    freev(pitch_interpolate);
    freev(intensive_interpolate);
    freev(wave);
    qDebug() << "freev" << LOG_DATA;

    file.close();
    waveCloseFile(waveFile);
    qDebug() << "waveCloseFile" << LOG_DATA;

    GraphData * data = new GraphData();

    data->d_full_wave = norm_wave;
    data->d_wave = display_wave;
    data->d_p_wave = p_wave;
    data->d_n_wave = n_wave;
    data->d_t_wave = t_wave;
    data->d_pitch_original = pitch;
    data->d_pitch = pitch_mid;
    data->pitch_max = pitch_max;
    data->pitch_min = pitch_min;
    data->d_intensive_original = intensive;
    data->d_intensive = intensive_mid;
    data->d_spec_proc = spec_proc;
    data->d_spec = spec;
    data->d_mask = mask;
    data->p_mask = p_mask;
    data->n_mask = n_mask;
    data->t_mask = t_mask;
    data->pnt_mask = pnt_mask;

    data->md_p = md_p;
    data->md_t = md_t;
    data->md_n = md_n;

    return data;
}
Example #20
0
File: sh.dir.c Project: lukem/tcsh
/*
 * dcanon - canonicalize the pathname, removing excess ./ and ../ etc.
 *	we are of course assuming that the file system is standardly
 *	constructed (always have ..'s, directories have links)
 */
Char   *
dcanon(Char *cp, Char *p)
{
    Char *sp;
    Char *p1, *p2;	/* general purpose */
    int    slash;
#ifdef HAVE_SLASHSLASH
    int    slashslash;
#endif /* HAVE_SLASHSLASH */
    size_t  clen;

#ifdef S_IFLNK			/* if we have symlinks */
    Char *mlink, *newcp;
    char *tlink;
    size_t cc;
#endif /* S_IFLNK */

    clen = Strlen(cp);

    /*
     * christos: if the path given does not start with a slash prepend cwd. If
     * cwd does not start with a slash or the result would be too long try to
     * correct it.
     */
    if (!ABSOLUTEP(cp)) {
	Char *tmpdir;
	size_t	len;

	p1 = varval(STRcwd);
	if (p1 == STRNULL || !ABSOLUTEP(p1)) {
	    Char *new_cwd = agetcwd();

	    if (new_cwd == NULL) {
		xprintf("%s: %s\n", progname, strerror(errno));
		setcopy(STRcwd, str2short("/"), VAR_READWRITE|VAR_NOGLOB);
	    }
	    else
		setv(STRcwd, new_cwd, VAR_READWRITE|VAR_NOGLOB);
	    p1 = varval(STRcwd);
	}
	len = Strlen(p1);
	tmpdir = xmalloc((len + clen + 2) * sizeof (*tmpdir));
	(void) Strcpy(tmpdir, p1);
	(void) Strcat(tmpdir, STRslash);
	(void) Strcat(tmpdir, cp);
	xfree(cp);
	cp = p = tmpdir;
    }

#ifdef HAVE_SLASHSLASH
    slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */

    while (*p) {		/* for each component */
	sp = p;			/* save slash address */
	while (*++p == '/')	/* flush extra slashes */
	    continue;
	if (p != ++sp)
	    for (p1 = sp, p2 = p; (*p1++ = *p2++) != '\0';)
		continue;
	p = sp;			/* save start of component */
	slash = 0;
	if (*p) 
	    while (*++p)	/* find next slash or end of path */
		if (*p == '/') {
		    slash = 1;
		    *p = 0;
		    break;
		}

#ifdef HAVE_SLASHSLASH
	if (&cp[1] == sp && sp[0] == '.' && sp[1] == '.' && sp[2] == '\0')
	    slashslash = 1;
#endif /* HAVE_SLASHSLASH */
	if (*sp == '\0') {	/* if component is null */
	    if (--sp == cp)	/* if path is one char (i.e. /) */ 
		break;
	    else
		*sp = '\0';
	}
	else if (sp[0] == '.' && sp[1] == 0) {
	    if (slash) {
		for (p1 = sp, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = --sp;
	    }
	    else if (--sp != cp)
		*sp = '\0';
	    else
		sp[1] = '\0';
	}
	else if (sp[0] == '.' && sp[1] == '.' && sp[2] == 0) {
	    /*
	     * We have something like "yyy/xxx/..", where "yyy" can be null or
	     * a path starting at /, and "xxx" is a single component. Before
	     * compressing "xxx/..", we want to expand "yyy/xxx", if it is a
	     * symbolic link.
	     */
	    *--sp = 0;		/* form the pathname for readlink */
#ifdef S_IFLNK			/* if we have symlinks */
	    if (sp != cp && /* symlinks != SYM_IGNORE && */
		(tlink = areadlink(short2str(cp))) != NULL) {
		mlink = str2short(tlink);
		xfree(tlink);

		if (slash)
		    *p = '/';
		/*
		 * Point p to the '/' in "/..", and restore the '/'.
		 */
		*(p = sp) = '/';
		if (*mlink != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * "/..". First, back sp up to the character past "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + mlink + "/.." and rest
		     */
		    p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) +
					  Strlen(p) + 1) * sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    newcp = Strspl(mlink, p);
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		xfree(cp);
		cp = newcp;
#ifdef HAVE_SLASHSLASH
                slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */
		continue;	/* canonicalize the link */
	    }
#endif /* S_IFLNK */
	    *sp = '/';
	    if (sp != cp)
		while (*--sp != '/')
		    continue;
	    if (slash) {
		for (p1 = sp + 1, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = sp;
	    }
	    else if (cp == sp)
		*++sp = '\0';
	    else
		*sp = '\0';
	}
	else {			/* normal dir name (not . or .. or nothing) */

#ifdef S_IFLNK			/* if we have symlinks */
	    if (sp != cp && symlinks == SYM_CHASE &&
		(tlink = areadlink(short2str(cp))) != NULL) {
		mlink = str2short(tlink);
		xfree(tlink);

		/*
		 * restore the '/'.
		 */
		if (slash)
		    *p = '/';

		/*
		 * point sp to p (rather than backing up).
		 */
		sp = p;

		if (*mlink != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * remainder. First, back sp up to the character past
		     * "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + mlink + "/.." and rest
		     */
		    p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) +
					  Strlen(p) + 1) * sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    newcp = Strspl(mlink, p);
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		xfree(cp);
		cp = newcp;
#ifdef HAVE_SLASHSLASH
                slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */
		continue;	/* canonicalize the mlink */
	    }
#endif /* S_IFLNK */
	    if (slash)
		*p = '/';
	}
    }

    /*
     * fix home...
     */
#ifdef S_IFLNK
    p1 = varval(STRhome);
    cc = Strlen(p1);
    /*
     * See if we're not in a subdir of STRhome
     */
    if (p1 && *p1 == '/' && (Strncmp(p1, cp, cc) != 0 ||
	(cp[cc] != '/' && cp[cc] != '\0'))) {
	static ino_t home_ino = (ino_t) -1;
	static dev_t home_dev = (dev_t) -1;
	static Char *home_ptr = NULL;
	struct stat statbuf;
	int found;
	Char *copy;

	/*
	 * Get dev and ino of STRhome
	 */
	if (home_ptr != p1 &&
	    stat(short2str(p1), &statbuf) != -1) {
	    home_dev = statbuf.st_dev;
	    home_ino = statbuf.st_ino;
	    home_ptr = p1;
	}
	/*
	 * Start comparing dev & ino backwards
	 */
	p2 = copy = Strsave(cp);
	found = 0;
	while (*p2 && stat(short2str(p2), &statbuf) != -1) {
	    if (DEV_DEV_COMPARE(statbuf.st_dev, home_dev) &&
			statbuf.st_ino == home_ino) {
			found = 1;
			break;
	    }
	    if ((sp = Strrchr(p2, '/')) != NULL)
		*sp = '\0';
	}
	/*
	 * See if we found it
	 */
	if (*p2 && found) {
	    /*
	     * Use STRhome to make '~' work
	     */
	    newcp = Strspl(p1, cp + Strlen(p2));
	    xfree(cp);
	    cp = newcp;
	}
	xfree(copy);
    }
#endif /* S_IFLNK */

#ifdef HAVE_SLASHSLASH
    if (slashslash) {
	if (cp[1] != '/') {
	    p = xmalloc((Strlen(cp) + 2) * sizeof(Char));
	    *p = '/';
	    (void) Strcpy(&p[1], cp);
	    xfree(cp);
	    cp = p;
	}
    }
    if (cp[1] == '/' && cp[2] == '/') {
	for (p1 = &cp[1], p2 = &cp[2]; (*p1++ = *p2++) != '\0';)
	    continue;
    }
#endif /* HAVE_SLASHSLASH */
    return cp;
}