void importpath(Char *cp) { Char *dp, **pv; int c, i; i = 0; for (dp = cp; *dp; dp++) if (*dp == ':') i++; /* * i+2 where i is the number of colons in the path. There are i+1 * directories in the path plus we need room for a zero terminator. */ pv = (Char **)xcalloc((size_t) (i + 2), sizeof(Char **)); dp = cp; i = 0; if (*dp) for (;;) { if ((c = *dp) == ':' || c == 0) { *dp = 0; pv[i++] = Strsave(*cp ? cp : STRdot); if (c) { cp = dp + 1; *dp = ':'; } else break; } dp++; } pv[i] = 0; setq(STRpath, pv, &shvhed); }
int main(int argc, char **argv){ FILE *f = fopen("output.txt","w"); //intialize PERFL variables double* q = calloc(2, sizeof(double)); q[0] = 1.0; q[1] = 0.0; //intialize rk4 variables ODE rk4 = new_ODE(2); setq(rk4,0,1.0); setq(rk4,1,0.0); set_func(rk4, derivatives); double h = .02*PERIOD; double step_limit; double energy_rk,energy_lf,max_dev_lf,max_dev_rk ; energy_rk = energy_lf = max_dev_lf = max_dev_rk = 0.0; printf("How many periods: "); scanf("%lf",&step_limit); step_limit = step_limit*50; fprintf(f,"t/T \t E_L \t E_K \n"); for (int i = 0;i<=step_limit;i++){ runge_kutta_4_update(rk4, h); energy_rk = pow(getq(rk4,0),4)/4.0 + pow(getq(rk4,1),2)/2.0; position_verlet(q,force,h); energy_lf= pow(q[0],4)/4.0 + pow(q[1],2)/2.0; double dev_lf =fabs(energy_lf-0.25); double dev_rk =fabs(energy_rk-0.25); if(dev_rk > max_dev_rk){max_dev_rk=dev_rk;} if(dev_lf > max_dev_lf){max_dev_lf=dev_lf;} fprintf(f,"%f \t %.12f \t %.12f \n",(i*h),dev_lf,dev_rk); } printf("Maximum deviation for PEFRL = %f\n",max_dev_lf); printf("Maximum deviation for runge-kutta = %f\n",max_dev_rk) ; return 0; }
void CosmoWindowDecoder::reset(int inq, int inw, int inh) { /* * Make sure all outstanding putimage's finish. * Syncing with the first window, syncs the server, * and hence all of them. */ window_->sync(); /*XXX*/ if (inq == 0) return; inq_ = inq; setq(inq); int w = window_->width(); int h = window_->height(); /*XXX*/ if (w < 300) return; shutdown(); startup(); int options[10]; int* p = options; *p++ = CL_IMAGE_WIDTH; *p++ = w; *p++ = CL_INTERNAL_IMAGE_WIDTH; *p++ = inw; *p++ = CL_IMAGE_HEIGHT; *p++ = h; *p++ = CL_INTERNAL_IMAGE_HEIGHT; *p++ = inh; /*XXX*/ *p++ = CL_STREAM_HEADERS; *p++ = 0; #ifdef notdef *p++ = CL_ORIGINAL_FORMAT; *p++ = ?; #endif int s = clSetParams(ch_, options, 10); if (s != 0) { printf("clSetParams failed\n"); exit(1); } if (vbx_ == 0 || vbx_->width() != w || vbx_->height() != h) vbx_ = new SharedVideoImage(window_->tkwin(), w, h); }
static void dset(Char *dp) { /* * Don't call set() directly cause if the directory contains ` or * other junk characters glob will fail. */ Char **vec = xreallocarray(NULL, 2, sizeof(*vec)); vec[0] = Strsave(dp); vec[1] = 0; setq(STRcwd, vec, &shvhed); Setenv(STRPWD, dp); }
static void dset(Char *dp) { /* * Don't call set() directly cause if the directory contains ` or * other junk characters glob will fail. */ Char **vec = (Char **) xmalloc((size_t) (2 * sizeof(Char **))); vec[0] = Strsave(dp); vec[1] = 0; setq(STRcwd, vec, &shvhed); Setenv(STRPWD, dp); }
//When loading, increase degree if number of parameters exceed qlen bool Algebraic::readImplicit(std::ifstream &file,bool verbose) { std::vector<double> params; readParameters(file,params); if(params.size() != qlen()) { //params doesn't match qlen, change degree int newdegree = 0; while (Algebraic::coefficients(newdegree) < (int)params.size()) newdegree++; degree(newdegree); } setq(params); return true; }
static void FFN(Fpsetq)(object arg) { object *old_top = vs_top; object *top; object argsv = arg; for (top = old_top; !endp(arg); arg = MMcddr(arg), top++) { if(endp(MMcdr(arg))) FEinvalid_form("No value for ~S.", arg->c.c_car); top[0] = Ieval1(MMcadr(arg)); vs_top = top + 1; } for (arg = argsv, top = old_top; !endp(arg); arg = MMcddr(arg), top++) setq(MMcar(arg),top[0]); vs_base = vs_top = old_top; vs_push(Cnil); }
void set1(Char *var, Char **vec, struct varent *head) { Char **oldv = vec; gflag = 0; tglob(oldv); if (gflag) { vec = globall(oldv); if (vec == 0) { blkfree(oldv); stderror(ERR_NAME | ERR_NOMATCH); return; } blkfree(oldv); gargv = 0; } setq(var, vec, head); }
void set_transition_callback(TransitionRule rule, int dur1, int dur2, TransitionCallback cb, void *arg) { static bool initialized = false; if(!rule) { return; } setq(rule, dur1, dur2, cb, arg); if(!initialized) { popq(); initialized = true; transition.rule2 = NULL; } if(transition.state == TRANS_IDLE || rule == transition.rule) { popq(); } }
static void FFN(Fsetq)(object form) { object ans; if (endp(form)) { vs_base = vs_top; vs_push(Cnil); } else { object *top = vs_top; do { vs_top = top; if (endp(MMcdr(form))) FEinvalid_form("No value for ~S.", form->c.c_car); setq(MMcar(form),ans=Ieval1(MMcadr(form))); form = MMcddr(form); } while (!endp(form)); top[0]=ans; vs_base=top; vs_top= top+1; } }
static void dgetstack(void) { int i = 0; Char **dblk, **dbp; struct directory *dn; if (adrof(STRdirstack) == NULL) return; for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev, i++) continue; dbp = dblk = xmalloc((i + 1) * sizeof(Char *)); for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev, dbp++) *dbp = Strsave(dn->di_name); *dbp = NULL; cleanup_push(dblk, blk_cleanup); setq(STRdirstack, dblk, &shvhed, VAR_READWRITE); cleanup_ignore(dblk); cleanup_until(dblk); }
PvhEncoder::PvhEncoder() : TransmitterModule(FT_PVH), sh_(0), pt_(RTP_PT_PVH) { // bind("pt_", &pt_); memset(&cntr_, 0, sizeof(cntr_)); memset(shs_, 0, sizeof(shs_)); int i; for (i = 0; i < NLAYER; ++i) channels_[i].pb = 0; /* * Set the DC quantizer to 1, since we want to do this * coefficient differently (i.e., the DC is rounded while * the AC terms are truncated). */ int qt[64]; for (i = 0; i < 64; ++i) qt[i] = 1; fdct_fold_q(qt, qt_); setq(); }
//overload the display method to include variances void soc::SocSystem_Ors::displayState(const arr& q,const arr *invQ,const char *text){ setq(q); if(text) gl->text.clr() <<text; if(invQ){ arr Q; inverse_SymPosDef(Q,*invQ); if(gl->drawers.last().classP!=&plotModule) gl->add(glDrawPlot,&plotModule); plotClear(); TaskVariable *v; uint i; for_list(i,v,vars){ if(v->type==posTVT){ arr X(3,3); X = v->J * Q * v->tJ; plotCovariance(v->y,X); break; } } } gl->update(); //gl->watch(); //gl->timedupdate(getTau()*(T-1)/(display-1)); //if(invQ) gl->drawers.popLast(); }
void set1(const Char *var, Char **vec, struct varent *head, int flags) { Char **oldv = vec; if ((flags & VAR_NOGLOB) == 0) { int gflag; gflag = tglob(oldv); if (gflag) { vec = globall(oldv, gflag); if (vec == 0) { blkfree(oldv); stderror(ERR_NAME | ERR_NOMATCH); } blkfree(oldv); } } /* * Uniqueness addition from: Michael Veksler <*****@*****.**> */ if ( flags & (VAR_FIRST | VAR_LAST) ) { /* * Code for -f (VAR_FIRST) and -l (VAR_LAST) options. * Method: * Delete all duplicate words leaving "holes" in the word array (vec). * Then remove the "holes", keeping the order of the words unchanged. */ if (vec && vec[0] && vec[1]) { /* more than one word ? */ int i, j; int num_items; for (num_items = 0; vec[num_items]; num_items++) continue; if (flags & VAR_FIRST) { /* delete duplications, keeping first occurance */ for (i = 1; i < num_items; i++) for (j = 0; j < i; j++) /* If have earlier identical item, remove i'th item */ if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) { xfree(vec[i]); vec[i] = NULL; break; } } else if (flags & VAR_LAST) { /* delete duplications, keeping last occurance */ for (i = 0; i < num_items - 1; i++) for (j = i + 1; j < num_items; j++) /* If have later identical item, remove i'th item */ if (vec[i] && vec[j] && Strcmp(vec[j], vec[i]) == 0) { /* remove identical item (the first) */ xfree(vec[i]); vec[i] = NULL; } } /* Compress items - remove empty items */ for (j = i = 0; i < num_items; i++) if (vec[i]) vec[j++] = vec[i]; /* NULL-fy remaining items */ for (; j < num_items; j++) vec[j] = NULL; } /* don't let the attribute propagate */ flags &= ~(VAR_FIRST|VAR_LAST); } setq(var, vec, head, flags); }
void FILEOutputAssistor::reset(int inq, int w, int h) { Module::size(w, h); setq(inq); }
int main(int argc, char *argv[]) { struct sigaction oact; Char *cp; char *tcp, **tempv; const char *ecp; sigset_t nsigset; int f; cshin = stdin; cshout = stdout; csherr = stderr; setprogname(argv[0]); settimes(); /* Immed. estab. timing base */ /* * Initialize non constant strings */ #ifdef _PATH_BSHELL STR_BSHELL = SAVE(_PATH_BSHELL); #endif #ifdef _PATH_CSHELL STR_SHELLPATH = SAVE(_PATH_CSHELL); #endif STR_environ = blk2short(environ); environ = short2blk(STR_environ); /* So that we can free it */ STR_WORD_CHARS = SAVE(WORD_CHARS); HIST = '!'; HISTSUB = '^'; word_chars = STR_WORD_CHARS; tempv = argv; if (eq(str2short(tempv[0]), STRaout)) /* A.out's are quittable */ quitit = 1; uid = getuid(); gid = getgid(); euid = geteuid(); egid = getegid(); /* * We are a login shell if: 1. we were invoked as -<something> and we had * no arguments 2. or we were invoked only with the -l flag */ loginsh = (**tempv == '-' && argc == 1) || (argc == 2 && tempv[1][0] == '-' && tempv[1][1] == 'l' && tempv[1][2] == '\0'); if (loginsh && **tempv != '-') { /* * Mangle the argv space */ tempv[1][0] = '\0'; tempv[1][1] = '\0'; tempv[1] = NULL; for (tcp = *tempv; *tcp++;) continue; for (tcp--; tcp >= *tempv; tcp--) tcp[1] = tcp[0]; *++tcp = '-'; argc--; } if (loginsh) (void)time(&chktim); AsciiOnly = 1; #ifdef NLS (void)setlocale(LC_ALL, ""); { int k; for (k = 0200; k <= 0377 && !Isprint(k); k++) continue; AsciiOnly = k > 0377; } #else AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL; #endif /* NLS */ /* * Move the descriptors to safe places. The variable didfds is 0 while we * have only FSH* to work with. When didfds is true, we have 0,1,2 and * prefer to use these. */ initdesc(); /* * XXX: This is to keep programs that use stdio happy. * what we really want is freunopen() .... * Closing cshin cshout and csherr (which are really stdin stdout * and stderr at this point and then reopening them in the same order * gives us again stdin == cshin stdout == cshout and stderr == csherr. * If that was not the case builtins like printf that use stdio * would break. But in any case we could fix that with memcpy and * a bit of pointer manipulation... * Fortunately this is not needed under the current implementation * of stdio. */ (void)fclose(cshin); (void)fclose(cshout); (void)fclose(csherr); if (!(cshin = funopen2((void *) &SHIN, readf, writef, seekf, NULL, closef))) exit(1); if (!(cshout = funopen2((void *) &SHOUT, readf, writef, seekf, NULL, closef))) exit(1); if (!(csherr = funopen2((void *) &SHERR, readf, writef, seekf, NULL, closef))) exit(1); (void)setvbuf(cshin, NULL, _IOLBF, 0); (void)setvbuf(cshout, NULL, _IOLBF, 0); (void)setvbuf(csherr, NULL, _IOLBF, 0); /* * Initialize the shell variables. ARGV and PROMPT are initialized later. * STATUS is also munged in several places. CHILD is munged when * forking/waiting */ set(STRstatus, Strsave(STR0)); if ((ecp = getenv("HOME")) != NULL) cp = quote(SAVE(ecp)); else cp = NULL; if (cp == NULL) fast = 1; /* No home -> can't read scripts */ else set(STRhome, cp); dinit(cp); /* dinit thinks that HOME == cwd in a login * shell */ /* * Grab other useful things from the environment. Should we grab * everything?? */ if ((ecp = getenv("LOGNAME")) != NULL || (ecp = getenv("USER")) != NULL) set(STRuser, quote(SAVE(ecp))); if ((ecp = getenv("TERM")) != NULL) set(STRterm, quote(SAVE(ecp))); /* * Re-initialize path if set in environment */ if ((ecp = getenv("PATH")) == NULL) { #ifdef _PATH_DEFPATH importpath(str2short(_PATH_DEFPATH)); #else setq(STRpath, defaultpath(), &shvhed); #endif } else { importpath(str2short(ecp)); } set(STRshell, Strsave(STR_SHELLPATH)); doldol = putn((int) getpid()); /* For $$ */ shtemp = Strspl(STRtmpsh, doldol); /* For << */ /* * Record the interrupt states from the parent process. If the parent is * non-interruptible our hand must be forced or we (and our children) won't * be either. Our children inherit termination from our parent. We catch it * only if we are the login shell. */ /* parents interruptibility */ (void)sigaction(SIGINT, NULL, &oact); parintr = oact.sa_handler; (void)sigaction(SIGTERM, NULL, &oact); parterm = oact.sa_handler; /* catch these all, login shell or not */ (void)signal(SIGHUP, phup); /* exit processing on HUP */ (void)signal(SIGXCPU, phup); /* ...and on XCPU */ (void)signal(SIGXFSZ, phup); /* ...and on XFSZ */ /* * Process the arguments. * * Note that processing of -v/-x is actually delayed till after script * processing. * * We set the first character of our name to be '-' if we are a shell * running interruptible commands. Many programs which examine ps'es * use this to filter such shells out. */ argc--, tempv++; while (argc > 0 && (tcp = tempv[0])[0] == '-' && *++tcp != '\0' && !batch) { do switch (*tcp++) { case 0: /* - Interruptible, no prompt */ prompt = 0; setintr = 1; nofile = 1; break; case 'b': /* -b Next arg is input file */ batch = 1; break; case 'c': /* -c Command input from arg */ if (argc == 1) xexit(0); argc--, tempv++; arginp = SAVE(tempv[0]); prompt = 0; nofile = 1; break; case 'e': /* -e Exit on any error */ exiterr = 1; break; case 'f': /* -f Fast start */ fast = 1; break; case 'i': /* -i Interactive, even if !intty */ intact = 1; nofile = 1; break; case 'm': /* -m read .cshrc (from su) */ mflag = 1; break; case 'n': /* -n Don't execute */ noexec = 1; break; case 'q': /* -q (Undoc'd) ... die on quit */ quitit = 1; break; case 's': /* -s Read from std input */ nofile = 1; break; case 't': /* -t Read one line from input */ onelflg = 2; prompt = 0; nofile = 1; break; case 'v': /* -v Echo hist expanded input */ nverbose = 1; /* ... later */ break; case 'x': /* -x Echo just before execution */ nexececho = 1; /* ... later */ break; case 'V': /* -V Echo hist expanded input */ setNS(STRverbose); /* NOW! */ break; case 'X': /* -X Echo just before execution */ setNS(STRecho); /* NOW! */ break; } while (*tcp); tempv++, argc--; } if (quitit) /* With all due haste, for debugging */ (void)signal(SIGQUIT, SIG_DFL); /* * Unless prevented by -, -c, -i, -s, or -t, if there are remaining * arguments the first of them is the name of a shell file from which to * read commands. */ if (nofile == 0 && argc > 0) { nofile = open(tempv[0], O_RDONLY); if (nofile < 0) { child = 1; /* So this doesn't return */ stderror(ERR_SYSTEM, tempv[0], strerror(errno)); } ffile = SAVE(tempv[0]); /* * Replace FSHIN. Handle /dev/std{in,out,err} specially * since once they are closed we cannot open them again. * In that case we use our own saved descriptors */ if ((SHIN = dmove(nofile, FSHIN)) < 0) switch(nofile) { case 0: SHIN = FSHIN; break; case 1: SHIN = FSHOUT; break; case 2: SHIN = FSHERR; break; default: stderror(ERR_SYSTEM, tempv[0], strerror(errno)); /* NOTREACHED */ } (void)ioctl(SHIN, FIOCLEX, NULL); prompt = 0; /* argc not used any more */ tempv++; } intty = isatty(SHIN); intty |= intact; if (intty || (intact && isatty(SHOUT))) { if (!batch && (uid != euid || gid != egid)) { errno = EACCES; child = 1; /* So this doesn't return */ stderror(ERR_SYSTEM, "csh", strerror(errno)); } } /* * Decide whether we should play with signals or not. If we are explicitly * told (via -i, or -) or we are a login shell (arg0 starts with -) or the * input and output are both the ttys("csh", or "csh</dev/ttyx>/dev/ttyx") * Note that in only the login shell is it likely that parent may have set * signals to be ignored */ if (loginsh || intact || (intty && isatty(SHOUT))) setintr = 1; settell(); /* * Save the remaining arguments in argv. */ setq(STRargv, blk2short(tempv), &shvhed); /* * Set up the prompt. */ if (prompt) { set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent)); /* that's a meta-questionmark */ set(STRprompt2, Strsave(STRmquestion)); } /* * If we are an interactive shell, then start fiddling with the signals; * this is a tricky game. */ shpgrp = getpgrp(); opgrp = tpgrp = -1; if (setintr) { **argv = '-'; if (!quitit) /* Wary! */ (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGINT, pintr); sigemptyset(&nsigset); (void)sigaddset(&nsigset, SIGINT); (void)sigprocmask(SIG_BLOCK, &nsigset, NULL); (void)signal(SIGTERM, SIG_IGN); if (quitit == 0 && arginp == 0) { (void)signal(SIGTSTP, SIG_IGN); (void)signal(SIGTTIN, SIG_IGN); (void)signal(SIGTTOU, SIG_IGN); /* * Wait till in foreground, in case someone stupidly runs csh & * dont want to try to grab away the tty. */ if (isatty(FSHERR)) f = FSHERR; else if (isatty(FSHOUT)) f = FSHOUT; else if (isatty(OLDSTD)) f = OLDSTD; else f = -1; retry: if ((tpgrp = tcgetpgrp(f)) != -1) { if (tpgrp != shpgrp) { sig_t old = signal(SIGTTIN, SIG_DFL); (void)kill(0, SIGTTIN); (void)signal(SIGTTIN, old); goto retry; } opgrp = shpgrp; shpgrp = getpid(); tpgrp = shpgrp; /* * Setpgid will fail if we are a session leader and * mypid == mypgrp (POSIX 4.3.3) */ if (opgrp != shpgrp) if (setpgid(0, shpgrp) == -1) goto notty; /* * We do that after we set our process group, to make sure * that the process group belongs to a process in the same * session as the tty (our process and our group) (POSIX 7.2.4) */ if (tcsetpgrp(f, shpgrp) == -1) goto notty; (void)ioctl(dcopy(f, FSHTTY), FIOCLEX, NULL); } if (tpgrp == -1) { notty: (void)fprintf(csherr, "Warning: no access to tty (%s).\n", strerror(errno)); (void)fprintf(csherr, "Thus no job control in this shell.\n"); } } } if ((setintr == 0) && (parintr == SIG_DFL)) setintr = 1; (void)signal(SIGCHLD, pchild); /* while signals not ready */ /* * Set an exit here in case of an interrupt or error reading the shell * start-up scripts. */ reenter = setexit(); /* PWP */ haderr = 0; /* In case second time through */ if (!fast && reenter == 0) { /* Will have value(STRhome) here because set fast if don't */ { sig_t oparintr; sigset_t osigset; int osetintr; oparintr = parintr; osetintr = setintr; sigemptyset(&nsigset); (void)sigaddset(&nsigset, SIGINT); (void)sigprocmask(SIG_BLOCK, &nsigset, &osigset); setintr = 0; parintr = SIG_IGN; /* Disable onintr */ #ifdef _PATH_DOTCSHRC (void)srcfile(_PATH_DOTCSHRC, 0, 0); #endif if (!fast && !arginp && !onelflg) dohash(NULL, NULL); #ifdef _PATH_DOTLOGIN if (loginsh) (void)srcfile(_PATH_DOTLOGIN, 0, 0); #endif (void)sigprocmask(SIG_SETMASK, &osigset, NULL); setintr = osetintr; parintr = oparintr; } (void)srccat(value(STRhome), STRsldotcshrc); if (!fast && !arginp && !onelflg && !havhash) dohash(NULL, NULL); /* * Source history before .login so that it is available in .login */ if ((cp = value(STRhistfile)) != STRNULL) tildehist[2] = cp; dosource(tildehist, NULL); if (loginsh) (void)srccat(value(STRhome), STRsldotlogin); } /* * Now are ready for the -v and -x flags */ if (nverbose) setNS(STRverbose); if (nexececho) setNS(STRecho); /* * All the rest of the world is inside this call. The argument to process * indicates whether it should catch "error unwinds". Thus if we are a * interactive shell our call here will never return by being blown past on * an error. */ process(setintr); /* * Mop-up. */ if (intty) { if (loginsh) { (void)fprintf(cshout, "logout\n"); (void)close(SHIN); child = 1; goodbye(); } else { (void)fprintf(cshout, "exit\n"); } } rechist(); exitstat(); /* NOTREACHED */ }
void XILOutputAssistor::reset(int inq, int w, int h) { //fprintf(stderr,"XILOutputAssistor(%s)::"__FUNCTION__"\n",filename_); Module::size(w, h); setq(inq); }