double dangle( LWDVector a, LWDVector b ) { LWDVector na, nb; dcopyv( na, a ); dnormalize( na ); dcopyv( nb, b ); dnormalize( nb ); return acos( ddot( na, nb )); }
void dpolynorm( LWDVector v1, LWDVector v2, LWDVector vlast, LWDVector norm ) { LWDVector a, b; dsub( v2, v1, a ); dsub( vlast, v1, b ); dcross( a, b, norm ); dnormalize( norm ); }
/* * dfollow - change to arg directory; fall back on cdpath if not valid */ static Char * dfollow(Char *cp) { Char *dp; struct varent *c; char ebuf[PATH_MAX]; int serrno; cp = globone(cp, G_ERROR); /* * if we are ignoring symlinks, try to fix relatives now. */ dp = dnormalize(cp); if (chdir(short2str(dp)) >= 0) { free(cp); return dgoto(dp); } else { free(dp); if (chdir(short2str(cp)) >= 0) return dgoto(cp); serrno = errno; } if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp) && (c = adrof(STRcdpath))) { Char **cdp; Char *p; Char buf[PATH_MAX]; for (cdp = c->vec; *cdp; cdp++) { for (dp = buf, p = *cdp; (*dp++ = *p++) != '\0';) continue; dp[-1] = '/'; for (p = cp; (*dp++ = *p++) != '\0';) continue; if (chdir(short2str(buf)) >= 0) { printd = 1; free(cp); cp = Strsave(buf); return dgoto(cp); } } } dp = value(cp); if ((dp[0] == '/' || dp[0] == '.') && chdir(short2str(dp)) >= 0) { free(cp); cp = Strsave(dp); printd = 1; return dgoto(cp); } (void) strlcpy(ebuf, short2str(cp), sizeof ebuf); free(cp); stderror(ERR_SYSTEM, ebuf, strerror(serrno)); return (NULL); }
void dvec_hp( LWDVector a, double *h, double *p ) { LWDVector n; dcopyv( n, a ); dnormalize( n ); *p = ( double ) asin( -n[ 1 ] ); if ( 1.0 - fabs( n[ 1 ] ) > EPSILON_D ) { *h = acos( n[ 2 ] / cos( *p )); if ( n[ 0 ] < 0.0 ) *h = 2 * PI - *h; } else *h = 0.0; }
/*ARGSUSED*/ void dolist(Char **v, struct command *c) { Char **globbed; int i, k, ret = 0; struct stat st; USE(c); if (*++v == NULL) { struct Strbuf word = Strbuf_INIT; Strbuf_terminate(&word); cleanup_push(&word, Strbuf_cleanup); (void) t_search(&word, LIST, TW_ZERO, 0, STRNULL, 0); cleanup_until(&word); return; } v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); for (k = 0; v[k] != NULL && v[k][0] != '-'; k++) continue; if (v[k]) { /* * We cannot process a flag therefore we let ls do it right. */ Char *lspath; struct command *t; struct wordent cmd, *nextword, *lastword; Char *cp; struct varent *vp; if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } if (seterr) { xfree(seterr); seterr = NULL; } lspath = STRls; STRmCF[1] = 'C'; STRmCF[3] = '\0'; /* Look at listflags, to add -A to the flags, to get a path of ls if necessary */ if ((vp = adrof(STRlistflags)) != NULL && vp->vec != NULL && vp->vec[0] != STRNULL) { if (vp->vec[1] != NULL && vp->vec[1][0] != '\0') lspath = vp->vec[1]; for (cp = vp->vec[0]; *cp; cp++) switch (*cp) { case 'x': STRmCF[1] = 'x'; break; case 'a': STRmCF[3] = 'a'; break; case 'A': STRmCF[3] = 'A'; break; default: break; } } cmd.word = STRNULL; lastword = &cmd; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(lspath); lastword->next = nextword; nextword->prev = lastword; lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmCF); lastword->next = nextword; nextword->prev = lastword; #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) if (dspmbyte_ls) { lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmmliteral); lastword->next = nextword; nextword->prev = lastword; } #endif #ifdef COLOR_LS_F if (color_context_ls) { lastword = nextword; nextword = xcalloc(1, sizeof cmd); nextword->word = Strsave(STRmmcolormauto); lastword->next = nextword; nextword->prev = lastword; } #endif /* COLOR_LS_F */ lastword = nextword; for (cp = *v; cp; cp = *++v) { nextword = xcalloc(1, sizeof cmd); nextword->word = quote(Strsave(cp)); lastword->next = nextword; nextword->prev = lastword; lastword = nextword; } lastword->next = &cmd; cmd.prev = lastword; cleanup_push(&cmd, lex_cleanup); /* build a syntax tree for the command. */ t = syntax(cmd.next, &cmd, 0); cleanup_push(t, syntax_cleanup); if (seterr) stderror(ERR_OLD); /* expand aliases like process() does */ /* alias(&cmd); */ /* execute the parse tree. */ execute(t, tpgrp > 0 ? tpgrp : -1, NULL, NULL, FALSE); /* done. free the lex list and parse tree. */ cleanup_until(&cmd); if (setintr) cleanup_until(&pintr_disabled); } else { Char *dp, *tmp; struct Strbuf buf = Strbuf_INIT; cleanup_push(&buf, Strbuf_cleanup); for (k = 0, i = 0; v[k] != NULL; k++) { tmp = dnormalize(v[k], symlinks == SYM_IGNORE); cleanup_push(tmp, xfree); dp = Strend(tmp) - 1; if (*dp == '/' && dp != tmp) #ifdef apollo if (dp != &tmp[1]) #endif /* apollo */ *dp = '\0'; if (stat(short2str(tmp), &st) == -1) { int err; err = errno; if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } haderr = 1; xprintf("%S: %s.\n", tmp, strerror(err)); haderr = 0; i = k + 1; ret = 1; } else if (S_ISDIR(st.st_mode)) { Char *cp; if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } if (k != 0 && v[1] != NULL) xputchar('\n'); xprintf("%S:\n", tmp); buf.len = 0; for (cp = tmp; *cp; cp++) Strbuf_append1(&buf, (*cp | QUOTE)); Strbuf_terminate(&buf); dp = &buf.s[buf.len - 1]; if ( #ifdef WINNT_NATIVE (*dp != (Char) (':' | QUOTE)) && #endif /* WINNT_NATIVE */ (*dp != (Char) ('/' | QUOTE))) { Strbuf_append1(&buf, '/'); Strbuf_terminate(&buf); } else *dp &= TRIM; (void) t_search(&buf, LIST, TW_ZERO, 0, STRNULL, 0); i = k + 1; } cleanup_until(tmp); } cleanup_until(&buf); if (k != i) { if (i != 0) xputchar('\n'); print_by_column(STRNULL, &v[i], k - i, FALSE); } if (ret) stderror(ERR_SILENT); } cleanup_until(globbed); }
/* * dfollow - change to arg directory; fall back on cdpath if not valid */ static Char * dfollow(Char *cp, int old) { Char *dp; struct varent *c; int serrno; cp = old ? Strsave(cp) : globone(cp, G_ERROR); cleanup_push(cp, xfree); #ifdef apollo if (Strchr(cp, '`')) { char *dptr; if (chdir(dptr = short2str(cp)) < 0) stderror(ERR_SYSTEM, dptr, strerror(errno)); dp = agetcwd(); cleanup_push(dp, xfree); if (dp != NULL) { cleanup_until(cp); return dgoto(dp); } else stderror(ERR_SYSTEM, dptr, strerror(errno)); } #endif /* apollo */ /* * if we are ignoring symlinks, try to fix relatives now. * if we are expading symlinks, it should be done by now. */ dp = dnormalize(cp, symlinks == SYM_IGNORE); if (chdir(short2str(dp)) >= 0) { cleanup_until(cp); return dgoto(dp); } else { xfree(dp); if (chdir(short2str(cp)) >= 0) { cleanup_ignore(cp); cleanup_until(cp); return dgoto(cp); } else if (errno != ENOENT && errno != ENOTDIR) { int err; err = errno; stderror(ERR_SYSTEM, short2str(cp), strerror(err)); } serrno = errno; } if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp) && (c = adrof(STRcdpath)) && c->vec != NULL) { struct Strbuf buf = Strbuf_INIT; Char **cdp; for (cdp = c->vec; *cdp; cdp++) { size_t len = Strlen(*cdp); buf.len = 0; if (len > 0) { Strbuf_append(&buf, *cdp); if ((*cdp)[len - 1] != '/') Strbuf_append1(&buf, '/'); } Strbuf_append(&buf, cp); Strbuf_terminate(&buf); /* * We always want to fix the directory here * If we are normalizing symlinks */ dp = dnormalize(buf.s, symlinks == SYM_IGNORE || symlinks == SYM_EXPAND); if (chdir(short2str(dp)) >= 0) { printd = 1; xfree(buf.s); cleanup_until(cp); return dgoto(dp); } else if (chdir(short2str(cp)) >= 0) { printd = 1; xfree(dp); xfree(buf.s); cleanup_ignore(cp); cleanup_until(cp); return dgoto(cp); } } xfree(buf.s); } dp = varval(cp); if ((dp[0] == '/' || dp[0] == '.') && chdir(short2str(dp)) >= 0) { cleanup_until(cp); cp = Strsave(dp); printd = 1; return dgoto(cp); } /* * on login source of ~/.cshdirs, errors are eaten. the dir stack is all * directories we could get to. */ if (!bequiet) stderror(ERR_SYSTEM, short2str(cp), strerror(serrno)); cleanup_until(cp); return (NULL); }