Esempio n. 1
0
static int strncmpcanon(const char *a, const char *b, int n)
{
	Rune ra, rb;
	int c;
	while (n--) {
		if (!*a) return -1;
		if (!*b) return 1;
		a += chartorune(&ra, a);
		b += chartorune(&rb, b);
		c = canon(ra) - canon(rb);
		if (c)
			return c;
	}
	return 0;
}
Esempio n. 2
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const string &sourceRoot,
                         const string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  // Fast path for files that exist unless VirtualHost option StaticFastPath is false, in
  // which case rewrite rules are applied even if the original path points to an existing static file.

  String canon(Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
               AttachString);


  if ( vhost->staticfastpath() )
    {
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }


  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Esempio n. 3
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const string &sourceRoot,
                         const string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  // Fast path for files that exist
  if (vhost->checkExistenceBeforeRewrite()) {
    String canon(
      Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
      AttachString);
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Esempio n. 4
0
ripple()
{
	register Point p1, p2;
	register Point inc;
	register Point p;

	while (kbdchar() != 'q') {
		if (P->state & MOVED) {
			P->state &= ~(MOVED|RESHAPED);
			p = sub (Drect.origin, p);
			p1 = add (p1, p);
			p2 = add (p2, p);
			p = Drect.origin;
		}
		else if (P->state & RESHAPED) {
			P->state &= ~RESHAPED;
			p1.x=p2.x=avg(Drect.origin.x, Drect.corner.x);
			p1.y=p2.y=avg(Drect.origin.y, Drect.corner.y);
			inc.x=1;
			inc.y=1;
			rectf(&display, Drect, F_XOR);
			p = Drect.origin;
		}
		rectf(&display, canon(p1, p2), F_XOR);
		if (p1.x==Drect.origin.x || p1.x==Drect.corner.x) {
			inc.x= -inc.x;
		}
		if (p1.y==Drect.origin.y || p1.y==Drect.corner.y) {
			inc.y= -inc.y;
		}
		p1 = sub (p1, inc);
		p2 = add (p2, inc);
		wait (CPU);
	}
}
Esempio n. 5
0
/*
 *   os_exfld - load in an external function from an open file, given the
 *   size of the function (in bytes).  Returns a pointer to the newly
 *   allocated memory block containing the function in memory.  
 */
int (*os_exfld(osfildef *fp, unsigned len))(void *)
{
    void      *extfn;
    unsigned   alo;

#ifdef MSOS2
    /* for OS/2, don't load anything, but seek past the resource */
# ifdef MICROSOFT
    if (_osmode == OS2_MODE)
# endif /* MICROSOFT */
    {
        osfseek(fp, (long)len, OSFSK_SET);
        return((int (*)(void))0);
    }
#endif /* MSOS2 */

#ifdef __DPMI16__

    HANDLE selector;

    selector = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, len);
    if (!selector || !(extfn = GlobalLock(selector)))
        return 0;

    /* read the file */
    osfrb(fp, extfn, len);

    /* change the selector to a code segment */
    _asm
    {
        mov   bx, selector                                  /* get selector */
            lar   ax, bx                       /* get current access rights */
            mov   cl, ah
            or    cl, 8               /* set the CODE bit in the descriptor */
            mov   ax, 9                 /* function = set descriptor rights */
            mov   ch, 0
            int   31h
    }

    /* close the file and return the pointer to the function in memory */
    return((int (*)(void *))extfn);

#else /* __DPMI16 __ */

    /* figure out how much memory is needed and allocate it */
    alo = ((len + 0xf) & ~0xf) + 16;    /* round to mult of 16, plus 1 page */
    extfn = canon(malloc(alo));/* allocate the memory, canonicalize pointer */
    if (!extfn)
        return((int (*)(void *))0 );

    /* read the file */
    osfrb(fp, extfn, len);

    /* close the file and return the pointer to the function in memory */
    return((int (*)(void *))extfn);

#endif /* __DPMI16__ */
}
Esempio n. 6
0
static int incclasscanon(Reclass *cc, Rune c)
{
	Rune *p, r;
	for (p = cc->spans; p < cc->end; p += 2)
		for (r = p[0]; r <= p[1]; ++r)
			if (c == canon(r))
				return 1;
	return 0;
}
Esempio n. 7
0
int
canon_sort(char *dst, char *str, int expectlen)
{
  int len = canon(dst, str, 0);
  if (expectlen >= 0 && len != expectlen)
    return 1;

  qsort(dst, len, 1, cmp_char);
  return 0;
}
Esempio n. 8
0
static void writenodeandport(FILE * f, node_t * node, char *port)
{
    char *name;
    if (IS_CLUST_NODE(node))
	name = canon (agraphof(node), strchr(agnameof(node), ':') + 1);
    else
	name = agcanonStr (agnameof(node));
    printstring(f, " ", name); /* slimey i know */
    if (port && *port)
	printstring(f, ":", agcanonStr(port));
}
Esempio n. 9
0
/* numeric constant */
Expr *
numConst(double v, pmUnits u)
{
    Expr    *x;

    x = newExpr(NOP, NULL, NULL, -1, -1, -1, 1, SEM_NUMCONST);
    newRingBfr(x);
    x->units = canon(u);
    x->valid = 1;
    *(double *) x->ring = scale(u) * v;
    return x;
}
Esempio n. 10
0
/* _write_plain:
 */
void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend)
{
    int i, j, splinePoints;
    char *tport, *hport;
    node_t *n;
    edge_t *e;
    bezier bz;
    pointf pt;
    char *lbl;
    char* fillcolor;

#ifdef WITH_CGRAPH
    putstr = g->clos->disc.io->putstr;
#endif
//    setup_graph(job, g);
    setYInvert(g);
    pt = GD_bb(g).UR;
    printdouble(f, "graph ", job->zoom);
    printdouble(f, " ", PS2INCH(pt.x));
    printdouble(f, " ", PS2INCH(pt.y));
    agputc('\n', f);
    for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	if (IS_CLUST_NODE(n))
	    continue;
	printstring(f, "node ", agcanonStr(agnameof(n)));
	printpoint(f, ND_coord(n));
	if (ND_label(n)->html)   /* if html, get original text */
#ifndef WITH_CGRAPH
	    lbl = agcanonStr (agxget(n, N_label->index));
#else
	    lbl = agcanonStr (agxget(n, N_label));
#endif
	else
	    lbl = canon(agraphof(n),ND_label(n)->text);
        printdouble(f, " ", ND_width(n));
        printdouble(f, " ", ND_height(n));
        printstring(f, " ", lbl);
	printstring(f, " ", late_nnstring(n, N_style, "solid"));
	printstring(f, " ", ND_shape(n)->name);
	printstring(f, " ", late_nnstring(n, N_color, DEFAULT_COLOR));
	fillcolor = late_nnstring(n, N_fillcolor, "");
        if (fillcolor[0] == '\0')
	    fillcolor = late_nnstring(n, N_color, DEFAULT_FILL);
	printstring(f, " ", fillcolor);
	agputc('\n', f);
    }
Esempio n. 11
0
void interface(int interactive) {
	if(interactive) {
		int key, result;
		char customkey[8] = { 0 }, * marked = NULL;
		
		canon(0);
		fflush(stderr);
		if((key = fetchkey(1000000)) == -1)
			return;

		if(key == 27) {
			int ch;
			while((ch = fetchkey(100000)) != -1 && !strchr("ABCDEFGHMPQRSZojmk~", ch));
			return;
		}

		switch(key) {
			case 'l':
				puts(rate("L") ? "Loved." : "Sorry, failed.");
				break;

			case 'U':
				puts(rate("U") ? "Unloved." : "Sorry, failed.");
				break;

			case 'B':
				puts(rate("B") ? "Banned." : "Sorry, failed.");
				kill(playfork, SIGUSR1);
				break;

			case 'n':
				rate("S");
				break;

			case 'Q':
				unlink(rcpath("session"));
				exit(EXIT_SUCCESS);

			case 'i':
				if(playfork) {
					const char * path = rcpath("i-template");
					if(path && !access(path, R_OK)) {
						char ** template = slurp(path);
						if(template != NULL) {
Esempio n. 12
0
bool RequestURI::virtualFileExists(const VirtualHost *vhost,
                                   const std::string &sourceRoot,
                                   const std::string &pathTranslation,
                                   const String& filename) {
  if (filename.empty() || filename.charAt(filename.length() - 1) == '/') {
    return false;
  }
  String canon(Util::canonicalize(filename.c_str(), filename.size()),
               AttachString);
  if (!vhost->getDocumentRoot().empty()) {
    std::string fullname = canon.data();
    int i = 0;
    while (i < fullname.size() && fullname[i] == '/') ++i;
    if (i) {
      fullname = fullname.substr(i);
    }
    if (!i || !m_rewritten) {
      fullname = pathTranslation + fullname;
    }
    m_path = fullname;
    m_absolutePath = String(sourceRoot) + m_path;
    processExt();
    if (RuntimeOption::PathDebug) {
      m_triedURLs.push_back(m_absolutePath.toCppString());
    }

    if (StaticContentCache::TheFileCache && !fullname.empty() &&
        StaticContentCache::TheFileCache->fileExists(fullname.c_str())) {
      return true;
    }

    struct stat st;
    return RuntimeOption::AllowedFiles.find(fullname.c_str()) !=
      RuntimeOption::AllowedFiles.end() ||
      (stat(m_absolutePath.c_str(), &st) == 0 &&
       (st.st_mode & S_IFMT) == S_IFREG);
  }
  m_path = canon;
  m_absolutePath = String(sourceRoot) + canon;
  processExt();
  return true;
}
Esempio n. 13
0
File: line.c Progetto: kahrs/cda
slashbox(Line *l,Rectangle r)
{
	int m;
	for (m = 0; l; l = l->next)
		switch(l->type) {
		case LINE:
			if (WITHIN(l->P,r)) {
				l->sel |= 3;
				m |= (l->mod |= LINEBOX);
			}
			if (WITHIN(l->Q,r)) {
				l->sel |= 12;
				m |= (l->mod |= LINEBOX);
			}
			if (l->sel != 0 && l->sel != 15
				&& (l->X == l->U || l->Y == l->V)) {	/* clip */
				Line *n = newline(l->Q,l->next);
				l->next = n;
				l->Q = n->P = rclipl(r,canon(l->r));
				n->sel = l->sel&12;
				n->sel |= n->sel>>2;
				l->sel &= 3;
				l->sel |= l->sel<<2;
				l = l->next;
			}
			break;
		case BOX:
		case MACRO:
		case DOTS:
		case INST:
			if (WITHIN(l->P,r) && WITHIN(l->Q,r)) {
				l->sel |= 15;
				m |= (l->mod |= BOXBOX);
			}
			break;
		case STRING:
			if (WITHIN(l->P,r)) {
				l->sel = 3;
				m |= (l->mod |= STRBOX);
			}
			break;
		}
Esempio n. 14
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const std::string &sourceRoot,
                         const std::string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  auto pathTranslated = transport->getPathTranslated();
  if (!pathTranslated.empty()) {
    // The transport is overriding everything and just handing us the filename
    m_path = m_absolutePath = pathTranslated;
    processExt();
    return true;
  }

  // Fast path for files that exist
  if (vhost->checkExistenceBeforeRewrite()) {
    String canon(
      Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
      AttachString);
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Esempio n. 15
0
int
main(int argc, char *argv[])
{
	int ch;
	ino_t ino;
	char *inputdev;
	char *symtbl = "./restoresymtable";
	char *p, name[MAXPATHLEN];

	/* Temp files should *not* be readable.  We set permissions later. */
	(void) umask(077);

	if (argc < 2)
		usage();

	(void)setlocale(LC_ALL, "");

	inputdev = NULL;
	obsolete(&argc, &argv);
	while ((ch = getopt(argc, argv, "b:dDf:himNP:Rrs:tuvxy")) != -1)
		switch(ch) {
		case 'b':
			/* Change default tape blocksize. */
			bflag = 1;
			ntrec = strtol(optarg, &p, 10);
			if (*p)
				errx(1, "illegal blocksize -- %s", optarg);
			if (ntrec <= 0)
				errx(1, "block size must be greater than 0");
			break;
		case 'd':
			dflag = 1;
			break;
		case 'D':
			Dflag = 1;
			break;
		case 'f':
			if (pipecmd)
				errx(1,
				    "-P and -f options are mutually exclusive");
			inputdev = optarg;
			break;
		case 'P':
			if (!pipecmd && inputdev)
				errx(1,
				    "-P and -f options are mutually exclusive");
			inputdev = optarg;
			pipecmd = 1;
			break;
		case 'h':
			hflag = 0;
			break;
		case 'i':
		case 'R':
		case 'r':
		case 't':
		case 'x':
			if (command != '\0')
				errx(1,
				    "%c and %c options are mutually exclusive",
				    ch, command);
			command = ch;
			break;
		case 'm':
			mflag = 0;
			break;
		case 'N':
			Nflag = 1;
			break;
		case 's':
			/* Dumpnum (skip to) for multifile dump tapes. */
			dumpnum = strtol(optarg, &p, 10);
			if (*p)
				errx(1, "illegal dump number -- %s", optarg);
			if (dumpnum <= 0)
				errx(1, "dump number must be greater than 0");
			break;
		case 'u':
			uflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		case 'y':
			yflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (command == '\0')
		errx(1, "none of i, R, r, t or x options specified");

	if (signal(SIGINT, onintr) == SIG_IGN)
		(void) signal(SIGINT, SIG_IGN);
	if (signal(SIGTERM, onintr) == SIG_IGN)
		(void) signal(SIGTERM, SIG_IGN);
	setlinebuf(stderr);

	if (inputdev == NULL && (inputdev = getenv("TAPE")) == NULL)
		inputdev = _PATH_DEFTAPE;
	setinput(inputdev, pipecmd);

	if (argc == 0) {
		argc = 1;
		*--argv = ".";
	}

	switch (command) {
	/*
	 * Interactive mode.
	 */
	case 'i':
		setup();
		extractdirs(1);
		initsymtable(NULL);
		runcmdshell();
		break;
	/*
	 * Incremental restoration of a file system.
	 */
	case 'r':
		setup();
		if (dumptime > 0) {
			/*
			 * This is an incremental dump tape.
			 */
			vprintf(stdout, "Begin incremental restore\n");
			initsymtable(symtbl);
			extractdirs(1);
			removeoldleaves();
			vprintf(stdout, "Calculate node updates.\n");
			treescan(".", ROOTINO, nodeupdates);
			findunreflinks();
			removeoldnodes();
		} else {
			/*
			 * This is a level zero dump tape.
			 */
			vprintf(stdout, "Begin level 0 restore\n");
			initsymtable((char *)0);
			extractdirs(1);
			vprintf(stdout, "Calculate extraction list.\n");
			treescan(".", ROOTINO, nodeupdates);
		}
		createleaves(symtbl);
		createlinks();
		setdirmodes(FORCE);
		checkrestore();
		if (dflag) {
			vprintf(stdout, "Verify the directory structure\n");
			treescan(".", ROOTINO, verifyfile);
		}
		dumpsymtable(symtbl, (long)1);
		break;
	/*
	 * Resume an incremental file system restoration.
	 */
	case 'R':
		initsymtable(symtbl);
		skipmaps();
		skipdirs();
		createleaves(symtbl);
		createlinks();
		setdirmodes(FORCE);
		checkrestore();
		dumpsymtable(symtbl, (long)1);
		break;
	/*
	 * List contents of tape.
	 */
	case 't':
		setup();
		extractdirs(0);
		initsymtable((char *)0);
		while (argc--) {
			canon(*argv++, name, sizeof(name));
			ino = dirlookup(name);
			if (ino == 0)
				continue;
			treescan(name, ino, listfile);
		}
		break;
	/*
	 * Batch extraction of tape contents.
	 */
	case 'x':
		setup();
		extractdirs(1);
		initsymtable((char *)0);
		while (argc--) {
			canon(*argv++, name, sizeof(name));
			ino = dirlookup(name);
			if (ino == 0)
				continue;
			if (mflag)
				pathcheck(name);
			treescan(name, ino, addfile);
		}
		createfiles();
		createlinks();
		setdirmodes(0);
		if (dflag)
			checkrestore();
		break;
	}
	done(0);
	/* NOTREACHED */
}
Esempio n. 16
0
void
main(int argc, char *argv[])
{
	int i, fd, n, aflag, vflag;
	char body[Bodysize+2], *raw, *ret;
	Biobuf *bp;

	sprint(patfile, "%s/patterns", UPASLIB);
	aflag = -1;
	vflag = 0;
	ARGBEGIN {
	case 'a':
		aflag = 1;
		break;
	case 'v':
		vflag = 1;
		break;
	case 'd':
		debug++;
		break;
	case 'p':
		strcpy(patfile,ARGF());
		break;
	} ARGEND

	bp = Bopen(patfile, OREAD);
	if(bp){
		parsepats(bp);
		Bterm(bp);
	}

	if(argc >= 1){
		fd = open(*argv, OREAD);
		if(fd < 0){
			fprint(2, "can't open %s\n", *argv);
			exits("open");
		}
		Binit(&bin, fd, OREAD);
	} else 
		Binit(&bin, 0, OREAD);

	*body = 0;
	*header = 0;
	ret = 0;
	for(;;){
		raw = canon(&bin, header+1, body+1, &n);
		if(raw == 0)
			break;
		if(aflag == 0)
			continue;
		if(aflag < 0)
			aflag = 0;
		if(vflag){
			if(header[1]) {
				fprint(2, "\t**** Header ****\n\n");
				write(2, header+1, strlen(header+1));
				fprint(2, "\n");
			}
			fprint(2, "\t**** Body ****\n\n");
			if(body[1])
				write(2, body+1, strlen(body+1));
			fprint(2, "\n");
		}

		for(i = 0; patterns[i].action; i++){
			if(matchaction(&patterns[i], header+1))
				ret = patterns[i].action;
			if(i == HoldHeader)
				continue;
			if(matchaction(&patterns[i], body+1))
				ret = patterns[i].action;
		}
	}
	exits(ret);
}
Esempio n. 17
0
static inline int chartocanon(int *c, const char *s)
{
	int n = fz_chartorune(c, s);
	*c = canon(*c);
	return n;
}
Esempio n. 18
0
int
waitchar(void)
{
	Event e;
	int c;
	char c2;
	int newmouse;
	int wasblocked;
	int kbdchar = -1;
	char echobuf[3*BSIZE];
	static int lastc = -1;


	for(;;) {
		if(resize_flag)
			resize();
		wasblocked = blocked;
		if(backp)
			return(0);
		if(ecanmouse() && (button2() || button3()))
			readmenu();
		if(snarffp) {
			if((c = Bgetc(snarffp)) < 0) {
				if(lastc != '\n')
					write(outfd,"\n",1);
				Bterm(snarffp);
				snarffp = 0;
				if(lastc != '\n') {
					lastc = -1;
					return('\n');
				}
				lastc = -1;
				continue;
			}
			lastc = c;
			c2 = c;
			write(outfd, &c2, 1);
			return(c);
		}
		if(!blocked && host_avail())
			return(rcvchar());
		if(kbdchar > 0) {
			if(blocked)
				resize();
			if(cs->raw) {
				switch(kbdchar){
				case Kup:
					sendfk("up key");
					break;
				case Kdown:
					sendfk("down key");
					break;
				case Kleft:
					sendfk("left key");
					break;
				case Kright:
					sendfk("right key");
					break;
				case Kpgup:
					sendfk("page up");
					break;
				case Kpgdown:
					sendfk("page down");
					break;
				case KF|1:
					sendfk("F1");
					break;
				case KF|2:
					sendfk("F2");
					break;
				case KF|3:
					sendfk("F3");
					break;
				case KF|4:
					sendfk("F4");
					break;
				case KF|5:
					sendfk("F5");
					break;
				case KF|6:
					sendfk("F6");
					break;
				case KF|7:
					sendfk("F7");
					break;
				case KF|8:
					sendfk("F8");
					break;
				case KF|9:
					sendfk("F9");
					break;
				case KF|10:
					sendfk("F10");
					break;
				case KF|11:
					sendfk("F11");
					break;
				case KF|12:
					sendfk("F12");
					break;
				case '\n':
					echobuf[0] = '\r';
					sendnchars(1, echobuf);
					break;
				case '\r':
					echobuf[0] = '\n';
					sendnchars(1, echobuf);
					break;
				default:
					echobuf[0] = kbdchar;
					sendnchars(1, echobuf);
					break;
				}
			} else if(canon(echobuf,kbdchar) == SCROLL) {
				if(!blocked)
					bigscroll();
			} else
				strcat(echo_input,echobuf);
			blocked = 0;
			kbdchar = -1;
			continue;
		}
		curson(wasblocked);	/* turn on cursor while we're waiting */
		do {
			newmouse = 0;
			switch(eread(blocked ? Emouse|Ekeyboard :
					       Emouse|Ekeyboard|Ehost, &e)) {
			case Emouse:
				mouse = e.mouse;
				if(button2() || button3())
					readmenu();
				else if(resize_flag == 0) {
					/* eresized() is triggered by special mouse event */
					newmouse = 1;
				}
				break;
			case Ekeyboard:
				kbdchar = e.kbdc;
				break;
			case Ehost:
				set_host(&e);
				break;
			default:
				perror("protocol violation");
				exits("protocol violation");
			}
		} while(newmouse == 1);
		cursoff();	/* turn cursor back off */
	}
}
Esempio n. 19
0
void
main(int argc, char *argv[])
{
    int i, n, nolines, optout;
    char **args, **a, *cp, *buf;
    char body[Bodysize+2];
    Resub match[1];
    Biobuf *bp;

    optout = 1;
    a = args = Malloc((argc+1)*sizeof(char*));
    sprint(patfile, "%s/patterns", UPASLIB);
    sprint(linefile, "%s/lines", UPASLOG);
    sprint(holdqueue, "%s/queue.hold", SPOOL);
    sprint(copydir, "%s/copy", SPOOL);

    *a++ = argv[0];
    for(argc--, argv++; argv[0] && argv[0][0] == '-'; argc--, argv++) {
        switch(argv[0][1]) {
        case 'c':			/* save copy of message */
            cflag = 1;
            break;
        case 'd':			/* debug */
            debug++;
            *a++ = argv[0];
            break;
        case 'h':			/* queue held messages by sender domain */
            hflag = 1;		/* -q flag must be set also */
            break;
        case 'n':			/* NOHOLD mode */
            nflag = 1;
            break;
        case 'p':			/* pattern file */
            if(argv[0][2] || argv[1] == 0)
                usage();
            argc--;
            argv++;
            strecpy(patfile, patfile+sizeof patfile, *argv);
            break;
        case 'q':			/* queue name */
            if(argv[0][2] ||  argv[1] == 0)
                usage();
            *a++ = argv[0];
            argc--;
            argv++;
            qname = a;
            *a++ = argv[0];
            break;
        case 's':			/* save copy of dumped message */
            sflag = 1;
            break;
        case 't':			/* test mode - don't log match
						 * and write message to /dev/null
						 */
            tflag = 1;
            break;
        case 'v':			/* vebose - print matches */
            vflag = 1;
            break;
        default:
            *a++ = argv[0];
            break;
        }
    }

    if(argc < 3)
        usage();

    Binit(&bin, 0, OREAD);
    bp = Bopen(patfile, OREAD);
    if(bp) {
        parsepats(bp);
        Bterm(bp);
    }
    qdir = a;
    sender = argv[2];

    /* copy the rest of argv, acummulating the recipients as we go */
    for(i = 0; argv[i]; i++) {
        *a++ = argv[i];
        if(i < 4)	/* skip queue, 'mail', sender, dest sys */
            continue;
        /* recipients and smtp flags - skip the latter*/
        if(strcmp(argv[i], "-g") == 0) {
            *a++ = argv[++i];
            continue;
        }
        if(recips)
            s_append(recips, ", ");
        else
            recips = s_new();
        s_append(recips, argv[i]);
        if(optout && !optoutofspamfilter(argv[i]))
            optout = 0;
    }
    *a = 0;
    /* construct a command string for matching */
    snprint(cmd, sizeof(cmd)-1, "%s %s", sender, s_to_c(recips));
    cmd[sizeof(cmd)-1] = 0;
    for(cp = cmd; *cp; cp++)
        *cp = tolower(*cp);

    /* canonicalize a copy of the header and body.
     * buf points to orginal message and n contains
     * number of bytes of original message read during
     * canonicalization.
     */
    *body = 0;
    *header = 0;
    buf = canon(&bin, header+1, body+1, &n);
    if (buf == 0)
        exits("read");

    /* if all users opt out, don't try matches */
    if(optout) {
        if(cflag)
            cout = opencopy(sender);
        exits(qmail(args, buf, n, cout));
    }

    /* Turn off line logging, if command line matches */
    nolines = matchaction(Lineoff, cmd, match);

    for(i = 0; patterns[i].action; i++) {
        /* Lineoff patterns were already done above */
        if(i == Lineoff)
            continue;
        /* don't apply "Line" patterns if excluded above */
        if(nolines && i == SaveLine)
            continue;
        /* apply patterns to the sender/recips, header and body */
        if(matchaction(i, cmd, match))
            break;
        if(matchaction(i, header+1, match))
            break;
        if(i == HoldHeader)
            continue;
        if(matchaction(i, body+1, match))
            break;
    }
    if(cflag && patterns[i].action == 0)	/* no match found - save msg */
        cout = opencopy(sender);

    exits(qmail(args, buf, n, cout));
}
Esempio n. 20
0
void track :: synth(SampleBuf *out,
                    long writePos,
                    int c,
                    long synthtime,
                    int steps,
                    real fScale0,
                    real fScale1,
                    real mScale) {
  if(point.size()==0) return;
  long k = synthtime - start;
  if(k>=(long)point.size()-1) return;
  currtime = synthtime;
  if(k<0) return;
  int k1 = k + 1;  

  tpoint *tp0 = point[k];
  tpoint *tp1 = point[k1];

  real w0 = tp0->f;
  real w1 = tp1->f;
  real ph0 = tp0->ph;
  real ph1 = tp1->ph;
  real h = tp0->h;
 
  real dp = ph1 - ph0;
  if(dp>PI) dp-=TWOPI;
  else if(dp<-PI) dp+=TWOPI;
  real dp0 = 0.5f*h*(w0 + w1);
  real dw = canon(dp - dp0)/h;

  if(k==0) {
    if(precursor) {
      m_p = precursor->m_pDescendant;
    }  else {    
      dw = 0;
    }
  }
  
  real dt = (real)steps;
  w0 = (w0+dw);
  w1 = (w1+dw);
  w0 = w0*fScale0;
  w1 = w1*fScale1;
  dp = dt*0.5f*(w0 + w1);
  real b = (w1 - w0)/(2.0f*dt);

  bool bEnd = (k1==(long)point.size()-1);
  bool bStart = (k==0);

  if(bStart && tailStart) {
    if(w0 < PI && w0 > -PI) {
      real ph = m_p;
      int rise = round2int(this->rise * (real)steps);
      real dm = mScale*tp1->y/(real)rise;
      real m = mScale*tp1->y - dm;
      for(int i=steps-1;i>=steps-rise+1;i--) {
        ph -= w0;     
        if(ph<-PI) ph += TWOPI;
        else if(ph>PI) ph -= TWOPI;
        out->buf[writePos+i][c] += m * COS(ph);
        m -= dm;
      }
    }
  } else if(bEnd && tailEnd) {
    if(w0 < PI && w0 > -PI) {
      real ph = m_p;
      int fall = round2int(this->fall * (real)steps);
      real dm = mScale*tp0->y/(real)fall;
      real m = mScale*tp0->y;
      for(int i=0;i<fall;i++) {
        out->buf[writePos+i][c] += m * COS(ph); 
        ph += w0;
        if(ph<-PI) ph += TWOPI;
        else if(ph>PI) ph -= TWOPI;
        m -= dm;
      }
    }
  } else  {
    real m = mScale*tp0->y;
    real dm = mScale*(tp1->y0 - tp0->y)/dt;
    real ph = m_p;
    real b2tt1 = b;
    real b2 = 2.0f*b;
    real dph;

    audio *o = &(out->buf[writePos]);
    for(int i=0;i<steps;i++) {
      dph = w0 + b2tt1;      
      if(dph < PI && dph > -PI) (*o)[c] += m * COS(ph);
      ph += dph;
      if(ph<-PI) ph += TWOPI;
      else if(ph>PI) ph -= TWOPI;
      b2tt1 += b2;
      m += dm;
      o++;
    }
  }

  if(bEnd) {
    if(descendant && descendant->back()->M < tp0->M) {
      m_pDescendant = canon(m_p + dp/dt*(real)(descendant->owner->samplePos - owner->samplePos));
    }
  } else if(bStart && tailStart) {
  } else {
    m_p = canon(m_p + dp);
    if(descendant && descendant->back()->M > tp0->M && (k1+res==(long)point.size()-1)) {
      m_pDescendant = canon(m_p + dp/dt*(real)(descendant->owner->samplePos - (owner->samplePos+steps)));
    }
  }
}
Esempio n. 21
0
File: line.c Progetto: kahrs/cda
selpt(Line *dl,Point p)
{
	int s,m,prop;
	Rectangle r;
	Line *l=dl;
	for (m = 0; l; l = l->next) {
		r = l->r;
		prop = 0;
		switch (l->type) {
		case LINE:
			if (EQ(p,P))
				l->sel = 3;
			else if (EQ(p,Q))
				l->sel = 12;
			else if (Y == p.y && Y == V && (p.x-X)*(U-p.x) > 0)
				prop = 1;
			else if (X == p.x && X == U && (p.y-Y)*(V-p.y) > 0)
				prop = 1;
			else
				continue;
			m |= (l->mod |= LINEHIT);
			if (prop) {
				l->sel = 15;
				m |= selbox(dl,canon(r));
			}
			break;
		case BOX:
		case MACRO:
			if (EQ(p,ul(r)))
				selborder(dl,l->sel=3,r);
			else if (EQ(p,lr(r)))
				selborder(dl,l->sel=12,r);
			else if (EQ(p,ll(r)))
				selborder(dl,l->sel=9,r);
			else if (EQ(p,ur(r)))
				selborder(dl,l->sel=6,r);
			else if (l->type == BOX && IN(p,r)) {
				l->sel = 15;
				m |= selbox(dl,r);
			}
			else
				continue;
			m |= (l->mod |= BOXHIT);
			break;
		case INST:
			if (WITHIN(p,r)) {
				l->sel = 15;
				m |= (l->mod |= BOXHIT) | selbox(dl,r);
			}
			break;	
		case DOTS:
			if (EQ(p,ul(r)))
				l->sel=3;
			else if (EQ(p,lr(r)))
				l->sel=12;
			else if (EQ(p,ll(r)))
				l->sel=9;
			else if (EQ(p,ur(r)))
				l->sel=6;
			else if (IN(p,r))
				l->sel = 15;
			else
				continue;
			m |= (l->mod |= DOTHIT);
			break;
		case STRING:
			if (EQ(p,P)) {
				l->sel = 3;
				m |= (l->mod |= STRHIT);
			}
			break;
		}
	}
	return m;
}
Esempio n. 22
0
static int match(Reinst *pc, const char *sp, const char *bol, int flags, Resub *out)
{
	Rethread ready[MAXTHREAD];
	Resub scratch;
	Resub sub;
	Rune c;
	int nready;
	int i;

	/* queue initial thread */
	spawn(ready + 0, pc, sp, out);
	nready = 1;

	/* run threads in stack order */
	while (nready > 0) {
		--nready;
		pc = ready[nready].pc;
		sp = ready[nready].sp;
		memcpy(&sub, &ready[nready].sub, sizeof sub);
		for (;;) {
			switch (pc->opcode) {
			case I_END:
				for (i = 0; i < MAXSUB; ++i) {
					out->sub[i].sp = sub.sub[i].sp;
					out->sub[i].ep = sub.sub[i].ep;
				}
				return 1;
			case I_JUMP:
				pc = pc->x;
				continue;
			case I_SPLIT:
				if (nready >= MAXTHREAD) {
					fprintf(stderr, "regexec: backtrack overflow!\n");
					return 0;
				}
				spawn(&ready[nready++], pc->y, sp, &sub);
				pc = pc->x;
				continue;

			case I_PLA:
				if (!match(pc->x, sp, bol, flags, &sub))
					goto dead;
				pc = pc->y;
				continue;
			case I_NLA:
				memcpy(&scratch, &sub, sizeof scratch);
				if (match(pc->x, sp, bol, flags, &scratch))
					goto dead;
				pc = pc->y;
				continue;

			case I_ANYNL:
				sp += chartorune(&c, sp);
				if (c == 0)
					goto dead;
				break;
			case I_ANY:
				sp += chartorune(&c, sp);
				if (c == 0)
					goto dead;
				if (isnewline(c))
					goto dead;
				break;
			case I_CHAR:
				sp += chartorune(&c, sp);
				if (c == 0)
					goto dead;
				if (flags & REG_ICASE)
					c = canon(c);
				if (c != pc->c)
					goto dead;
				break;
			case I_CCLASS:
				sp += chartorune(&c, sp);
				if (c == 0)
					goto dead;
				if (flags & REG_ICASE) {
					if (!incclasscanon(pc->cc, canon(c)))
						goto dead;
				} else {
					if (!incclass(pc->cc, c))
						goto dead;
				}
				break;
			case I_NCCLASS:
				sp += chartorune(&c, sp);
				if (c == 0)
					goto dead;
				if (flags & REG_ICASE) {
					if (incclasscanon(pc->cc, canon(c)))
						goto dead;
				} else {
					if (incclass(pc->cc, c))
						goto dead;
				}
				break;
			case I_REF:
				i = sub.sub[pc->n].ep - sub.sub[pc->n].sp;
				if (flags & REG_ICASE) {
					if (strncmpcanon(sp, sub.sub[pc->n].sp, i))
						goto dead;
				} else {
					if (strncmp(sp, sub.sub[pc->n].sp, i))
						goto dead;
				}
				if (i > 0)
					sp += i;
				break;

			case I_BOL:
				if (sp == bol && !(flags & REG_NOTBOL))
					break;
				if (flags & REG_NEWLINE)
					if (sp > bol && isnewline(sp[-1]))
						break;
				goto dead;
			case I_EOL:
				if (*sp == 0)
					break;
				if (flags & REG_NEWLINE)
					if (isnewline(*sp))
						break;
				goto dead;
			case I_WORD:
				i = sp > bol && iswordchar(sp[-1]);
				i ^= iswordchar(sp[0]);
				if (i)
					break;
				goto dead;
			case I_NWORD:
				i = sp > bol && iswordchar(sp[-1]);
				i ^= iswordchar(sp[0]);
				if (!i)
					break;
				goto dead;

			case I_LPAR:
				sub.sub[pc->n].sp = sp;
				break;
			case I_RPAR:
				sub.sub[pc->n].ep = sp;
				break;
			default:
				goto dead;
			}
			pc = pc + 1;
		}
dead: ;
	}
	return 0;
}
Esempio n. 23
0
static PyObject *riscos_getcwd(PyObject *self,PyObject *args)
{ if(!PyArg_NoArgs(args)) return NULL;
  return canon("@");
}
Esempio n. 24
0
/*
 * Read and parse an interactive command.
 * The first word on the line is assigned to "cmd". If
 * there are no arguments on the command line, then "curdir"
 * is returned as the argument. If there are arguments
 * on the line they are returned one at a time on each
 * successive call to getcmd. Each argument is first assigned
 * to "name". If it does not start with "/" the pathname in
 * "curdir" is prepended to it. Finally "canon" is called to
 * eliminate any embedded ".." components.
 */
static void
getcmd(char *curdir, char *cmd, size_t cmdlen, char *name, size_t namelen,
       struct arglist *ap)
{
	char *cp;
	static char input[BUFSIZ];
	char output[BUFSIZ];
#	define rawname input	/* save space by reusing input buffer */
	int globretval;

	/*
	 * Check to see if still processing arguments.
	 */
	if (ap->argcnt > 0)
		goto retnext;
	if (nextarg != NULL)
		goto getnext;
	/*
	 * Read a command line and trim off trailing white space.
	 */
	do {
		(void)fprintf(stderr, "%s > ", __progname);
		(void)fflush(stderr);
		if (fgets(input, sizeof input, terminal) == NULL) {
			(void)strlcpy(cmd, "quit", cmdlen);
			return;
		}
	} while (input[0] == '\n' || input[0] == '\0');
	for (cp = &input[strlen(input) - 1];
	     cp >= input && (*cp == ' ' || *cp == '\t' || *cp == '\n'); cp--)
		/* trim off trailing white space and newline */;
	*++cp = '\0';
	/*
	 * Copy the command into "cmd".
	 */
	cp = copynext(input, cmd);
	ap->cmd = cmd;
	/*
	 * If no argument, use curdir as the default.
	 */
	if (*cp == '\0') {
		(void)strlcpy(name, curdir, MAXPATHLEN);
		return;
	}
	nextarg = cp;
	/*
	 * Find the next argument.
	 */
getnext:
	cp = copynext(nextarg, rawname);
	if (*cp == '\0')
		nextarg = NULL;
	else
		nextarg = cp;
	/*
	 * If it is an absolute pathname, canonicalize it and return it.
	 */
	if (rawname[0] == '/') {
		canon(rawname, name, namelen);
	} else {
		/*
		 * For relative pathnames, prepend the current directory to
		 * it then canonicalize and return it.
		 */
		snprintf(output, sizeof(output), "%s/%s", curdir, rawname);
		canon(output, name, namelen);
	}
	if ((globretval = glob(name, GLOB_ALTDIRFUNC | GLOB_NOESCAPE,
	    NULL, &ap->glob)) < 0) {
		fprintf(stderr, "%s: %s: ", ap->cmd, name);
		switch (globretval) {
		case GLOB_NOSPACE:
			fprintf(stderr, "out of memory\n");
			break;
		case GLOB_NOMATCH:
			fprintf(stderr, "no filename match.\n");
			break;
		case GLOB_ABORTED:
			fprintf(stderr, "glob() aborted.\n");
			break;
		default:
			fprintf(stderr, "unknown error!\n");
			break;
		}
	}

	if (ap->glob.gl_pathc == 0)
		return;
	ap->freeglob = 1;
	ap->argcnt = ap->glob.gl_pathc;

retnext:
	strlcpy(name, ap->glob.gl_pathv[ap->glob.gl_pathc - ap->argcnt],
	    MAXPATHLEN);
	if (--ap->argcnt == 0) {
		ap->freeglob = 0;
		globfree(&ap->glob);
	}
#	undef rawname
}
Esempio n. 25
0
static PyObject *riscos_expand(PyObject *self,PyObject *args)
{	char *path;
	if (!PyArg_Parse(args, "s", &path)) return NULL;
        return canon(path);
}
Esempio n. 26
0
static void compile(Reprog *prog, Renode *node)
{
	Reinst *inst, *split, *jump;
	int i;

	if (!node)
		return;

	switch (node->type) {
	case P_CAT:
		compile(prog, node->x);
		compile(prog, node->y);
		break;

	case P_ALT:
		split = emit(prog, I_SPLIT);
		compile(prog, node->x);
		jump = emit(prog, I_JUMP);
		compile(prog, node->y);
		split->x = split + 1;
		split->y = jump + 1;
		jump->x = prog->end;
		break;

	case P_REP:
		for (i = 0; i < node->m; ++i) {
			inst = prog->end;
			compile(prog, node->x);
		}
		if (node->m == node->n)
			break;
		if (node->n < REPINF) {
			for (i = node->m; i < node->n; ++i) {
				split = emit(prog, I_SPLIT);
				compile(prog, node->x);
				if (node->ng) {
					split->y = split + 1;
					split->x = prog->end;
				} else {
					split->x = split + 1;
					split->y = prog->end;
				}
			}
		} else if (node->m == 0) {
			split = emit(prog, I_SPLIT);
			compile(prog, node->x);
			jump = emit(prog, I_JUMP);
			if (node->ng) {
				split->y = split + 1;
				split->x = prog->end;
			} else {
				split->x = split + 1;
				split->y = prog->end;
			}
			jump->x = split;
		} else {
			split = emit(prog, I_SPLIT);
			if (node->ng) {
				split->y = inst;
				split->x = prog->end;
			} else {
				split->x = inst;
				split->y = prog->end;
			}
		}
		break;

	case P_BOL: emit(prog, I_BOL); break;
	case P_EOL: emit(prog, I_EOL); break;
	case P_WORD: emit(prog, I_WORD); break;
	case P_NWORD: emit(prog, I_NWORD); break;

	case P_PAR:
		inst = emit(prog, I_LPAR);
		inst->n = node->n;
		compile(prog, node->x);
		inst = emit(prog, I_RPAR);
		inst->n = node->n;
		break;
	case P_PLA:
		split = emit(prog, I_PLA);
		compile(prog, node->x);
		emit(prog, I_END);
		split->x = split + 1;
		split->y = prog->end;
		break;
	case P_NLA:
		split = emit(prog, I_NLA);
		compile(prog, node->x);
		emit(prog, I_END);
		split->x = split + 1;
		split->y = prog->end;
		break;

	case P_ANY:
		emit(prog, I_ANY);
		break;
	case P_CHAR:
		inst = emit(prog, I_CHAR);
		inst->c = (prog->flags & REG_ICASE) ? canon(node->c) : node->c;
		break;
	case P_CCLASS:
		inst = emit(prog, I_CCLASS);
		inst->cc = node->cc;
		break;
	case P_NCCLASS:
		inst = emit(prog, I_NCCLASS);
		inst->cc = node->cc;
		break;
	case P_REF:
		inst = emit(prog, I_REF);
		inst->n = node->n;
		break;
	}
}
Esempio n. 27
0
/*
 * Read and execute commands from the terminal.
 */
void
runcmdshell(void)
{
	struct entry *np;
	ufs1_ino_t ino;
	struct arglist arglist;
	char curdir[MAXPATHLEN];
	char name[MAXPATHLEN];
	char cmd[BUFSIZ];

	arglist.freeglob = 0;
	arglist.argcnt = 0;
	arglist.glob.gl_flags = GLOB_ALTDIRFUNC;
	arglist.glob.gl_opendir = (void *)rst_opendir;
	arglist.glob.gl_readdir = (void *)glob_readdir;
	arglist.glob.gl_closedir = (void *)rst_closedir;
	arglist.glob.gl_lstat = glob_stat;
	arglist.glob.gl_stat = glob_stat;
	canon("/", curdir, sizeof(curdir));
loop:
	if (setjmp(reset) != 0) {
		if (arglist.freeglob != 0) {
			arglist.freeglob = 0;
			arglist.argcnt = 0;
			globfree(&arglist.glob);
		}
		nextarg = NULL;
		volno = 0;
	}
	runshell = 1;
	getcmd(curdir, cmd, name, sizeof(name), &arglist);
	switch (cmd[0]) {
	/*
	 * Add elements to the extraction list.
	 */
	case 'a':
		if (strncmp(cmd, "add", strlen(cmd)) != 0)
			goto bad;
		ino = dirlookup(name);
		if (ino == 0)
			break;
		if (mflag)
			pathcheck(name);
		treescan(name, ino, addfile);
		break;
	/*
	 * Change working directory.
	 */
	case 'c':
		if (strncmp(cmd, "cd", strlen(cmd)) != 0)
			goto bad;
		ino = dirlookup(name);
		if (ino == 0)
			break;
		if (inodetype(ino) == LEAF) {
			fprintf(stderr, "%s: not a directory\n", name);
			break;
		}
		strcpy(curdir, name);
		break;
	/*
	 * Delete elements from the extraction list.
	 */
	case 'd':
		if (strncmp(cmd, "delete", strlen(cmd)) != 0)
			goto bad;
		np = lookupname(name);
		if (np == NULL || (np->e_flags & NEW) == 0) {
			fprintf(stderr, "%s: not on extraction list\n", name);
			break;
		}
		treescan(name, np->e_ino, deletefile);
		break;
	/*
	 * Extract the requested list.
	 */
	case 'e':
		if (strncmp(cmd, "extract", strlen(cmd)) != 0)
			goto bad;
		createfiles();
		createlinks();
		setdirmodes(0);
		if (dflag)
			checkrestore();
		volno = 0;
		break;
	/*
	 * List available commands.
	 */
	case 'h':
		if (strncmp(cmd, "help", strlen(cmd)) != 0)
			goto bad;
		/* FALLTHROUGH */
	case '?':
		fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
			"Available commands are:\n",
			"\tls [arg] - list directory\n",
			"\tcd arg - change directory\n",
			"\tpwd - print current directory\n",
			"\tadd [arg] - add `arg' to list of",
			" files to be extracted\n",
			"\tdelete [arg] - delete `arg' from",
			" list of files to be extracted\n",
			"\textract - extract requested files\n",
			"\tsetmodes - set modes of requested directories\n",
			"\tquit - immediately exit program\n",
			"\twhat - list dump header information\n",
			"\tverbose - toggle verbose flag",
			" (useful with ``ls'')\n",
			"\thelp or `?' - print this list\n",
			"If no `arg' is supplied, the current",
			" directory is used\n");
		break;
	/*
	 * List a directory.
	 */
	case 'l':
		if (strncmp(cmd, "ls", strlen(cmd)) != 0)
			goto bad;
		printlist(name, curdir);
		break;
	/*
	 * Print current directory.
	 */
	case 'p':
		if (strncmp(cmd, "pwd", strlen(cmd)) != 0)
			goto bad;
		if (curdir[1] == '\0')
			fprintf(stderr, "/\n");
		else
			fprintf(stderr, "%s\n", &curdir[1]);
		break;
	/*
	 * Quit.
	 */
	case 'q':
		if (strncmp(cmd, "quit", strlen(cmd)) != 0)
			goto bad;
		return;
	case 'x':
		if (strncmp(cmd, "xit", strlen(cmd)) != 0)
			goto bad;
		return;
	/*
	 * Toggle verbose mode.
	 */
	case 'v':
		if (strncmp(cmd, "verbose", strlen(cmd)) != 0)
			goto bad;
		if (vflag) {
			fprintf(stderr, "verbose mode off\n");
			vflag = 0;
			break;
		}
		fprintf(stderr, "verbose mode on\n");
		vflag++;
		break;
	/*
	 * Just restore requested directory modes.
	 */
	case 's':
		if (strncmp(cmd, "setmodes", strlen(cmd)) != 0)
			goto bad;
		setdirmodes(FORCE);
		break;
	/*
	 * Print out dump header information.
	 */
	case 'w':
		if (strncmp(cmd, "what", strlen(cmd)) != 0)
			goto bad;
		printdumpinfo();
		break;
	/*
	 * Turn on debugging.
	 */
	case 'D':
		if (strncmp(cmd, "Debug", strlen(cmd)) != 0)
			goto bad;
		if (dflag) {
			fprintf(stderr, "debugging mode off\n");
			dflag = 0;
			break;
		}
		fprintf(stderr, "debugging mode on\n");
		dflag++;
		break;
	/*
	 * Unknown command.
	 */
	default:
	bad:
		fprintf(stderr, "%s: unknown command; type ? for help\n", cmd);
		break;
	}
	goto loop;
}
Esempio n. 28
0
/*
 * Read and parse an interactive command.
 * The first word on the line is assigned to "cmd". If
 * there are no arguments on the command line, then "curdir"
 * is returned as the argument. If there are arguments
 * on the line they are returned one at a time on each
 * successive call to getcmd. Each argument is first assigned
 * to "name". If it does not start with "/" the pathname in
 * "curdir" is prepended to it. Finally "canon" is called to
 * eliminate any embedded ".." components.
 */
static void
getcmd(char *curdir, char *cmd, char *name, size_t size, struct arglist *ap)
{
	char *cp;
	static char input[BUFSIZ];
	char output[BUFSIZ];
#	define rawname input	/* save space by reusing input buffer */

	/*
	 * Check to see if still processing arguments.
	 */
	if (ap->argcnt > 0)
		goto retnext;
	if (nextarg != NULL)
		goto getnext;
	/*
	 * Read a command line and trim off trailing white space.
	 */
	do	{
		fprintf(stderr, "restore > ");
		fflush(stderr);
		if (fgets(input, BUFSIZ, terminal) == NULL) {
			strcpy(cmd, "quit");
			return;
		}
	} while (input[0] == '\n');
	for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--)
		/* trim off trailing white space and newline */;
	*++cp = '\0';
	/*
	 * Copy the command into "cmd".
	 */
	cp = copynext(input, cmd);
	ap->cmd = cmd;
	/*
	 * If no argument, use curdir as the default.
	 */
	if (*cp == '\0') {
		strncpy(name, curdir, size);
		name[size - 1] = '\0';
		return;
	}
	nextarg = cp;
	/*
	 * Find the next argument.
	 */
getnext:
	cp = copynext(nextarg, rawname);
	if (*cp == '\0')
		nextarg = NULL;
	else
		nextarg = cp;
	/*
	 * If it is an absolute pathname, canonicalize it and return it.
	 */
	if (rawname[0] == '/') {
		canon(rawname, name, size);
	} else {
		/*
		 * For relative pathnames, prepend the current directory to
		 * it then canonicalize and return it.
		 */
		snprintf(output, sizeof(output), "%s/%s", curdir, rawname);
		canon(output, name, size);
	}
	if (glob(name, GLOB_ALTDIRFUNC, NULL, &ap->glob) < 0)
		fprintf(stderr, "%s: out of memory\n", ap->cmd);
	if (ap->glob.gl_pathc == 0)
		return;
	ap->freeglob = 1;
	ap->argcnt = ap->glob.gl_pathc;

retnext:
	strncpy(name, ap->glob.gl_pathv[ap->glob.gl_pathc - ap->argcnt], size);
	name[size - 1] = '\0';
	if (--ap->argcnt == 0) {
		ap->freeglob = 0;
		globfree(&ap->glob);
	}
#	undef rawname
}
Esempio n. 29
0
char * readline(struct prompt * setup) {
	int eoln = 0, seq = 0, histsize = 0, index = -1, changed = !0;
	static char line[1024];
	unsigned length = 0;

	assert(setup != NULL);

	/* Print prompt if present. */
	if(setup->prompt)
		fputs(setup->prompt, stderr);

	/* Initialize line (empty or with preset text if given). */
	memset(line, 0, sizeof(line));
	if(setup->line) {
		strncpy(line, setup->line, sizeof(line) - 1);
		length = strlen(line);
		fputs(line, stderr);
	}

	/* Count items in history. */
	for(histsize = 0; setup->history && setup->history[histsize]; ++histsize);
	index = histsize;

	canon(0);

	while(!eoln) {
		int key = fgetc(stdin);

		switch(key) {
			case 8: /* Backspace. */
			case 127: /* Delete. */
				/* We don't support moving the cursor from the end of the line
				 * so handle these the same. */
				if(length > 0) {
					delete(1);
					line[--length] = 0;
					changed = !0;
				}
				break;

			case 9: /* Tab. */
				/* Call the callback function for completion if present. */
				if(setup->callback != NULL) {
					if(setup->callback(line, sizeof(line), changed)) {
						delete(length);
						length = strlen(line);
						memset(line + length, 0, sizeof(line) - length);
						fprintf(stderr, "\r%s%s", setup->prompt, line);
					}
					changed = 0;
				}
				break;

			case 4: /* EOF (^D) */
			case 10: /* Line break. */
			case 13: /* Carriage return (who knows...) */
				eoln = !0;
				break;

			case 23: /* ^W */
				if(length > 0) {
					int alpha = isalpha(line[length - 1]);
					while(length > 0 && isalpha(line[length - 1]) == alpha) {
						line[--length] = 0;
						delete(1);
					}
					changed = !0;
				}

				break;

			case 27: /* Escape. */
				++seq;
				changed = !0;
				break;

			default:
				changed = !0;
				if(seq > 0) {
					if(seq < 2)
						++seq;
					else {
						seq = 0;
						switch(key) {
							case 65: /* Up. */
							case 66: /* Down. */
								if(histsize) {
									if(key == 66 && index < histsize - 1)
										++index;

									if(key == 65 && index > -1)
										--index;

									delete(length);
									memset(line, 0, length);
									length = 0;

									if(index > -1 && index < histsize) {
										strncpy(
											line,
											setup->history[index],
											sizeof(line) - 1
										);

										length = strlen(line);
										fputs(line, stderr);
									}
								}

								break;
						}
					}
				}
				else {
					if(length < sizeof(line)) {
						line[length++] = key;
						fputc(key, stderr);
					}
				}
		}
	}

	canon(!0);
	fputc(10, stderr);

	return line;
}
Esempio n. 30
0
/* _write_plain:
 */
void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend)
{
    int i, j, splinePoints;
    char *tport, *hport;
    node_t *n;
    edge_t *e;
    bezier bz;
    pointf pt;
    char *lbl;
    char* fillcolor;

    putstr = g->clos->disc.io->putstr;
//    setup_graph(job, g);
    setYInvert(g);
    pt = GD_bb(g).UR;
    printdouble(f, "graph ", job->zoom);
    printdouble(f, " ", PS2INCH(pt.x));
    printdouble(f, " ", PS2INCH(pt.y));
    agputc('\n', f);
    for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	if (IS_CLUST_NODE(n))
	    continue;
	printstring(f, "node ", agcanonStr(agnameof(n)));
	printpoint(f, ND_coord(n));
	if (ND_label(n)->html)   /* if html, get original text */
	    lbl = agcanonStr (agxget(n, N_label));
	else
	    lbl = canon(agraphof(n),ND_label(n)->text);
        printdouble(f, " ", ND_width(n));
        printdouble(f, " ", ND_height(n));
        printstring(f, " ", lbl);
	printstring(f, " ", late_nnstring(n, N_style, "solid"));
	printstring(f, " ", ND_shape(n)->name);
	printstring(f, " ", late_nnstring(n, N_color, DEFAULT_COLOR));
	fillcolor = late_nnstring(n, N_fillcolor, "");
        if (fillcolor[0] == '\0')
	    fillcolor = late_nnstring(n, N_color, DEFAULT_FILL);
	printstring(f, " ", fillcolor);
	agputc('\n', f);
    }
    for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	for (e = agfstout(g, n); e; e = agnxtout(g, e)) {

	    if (extend) {		//assuming these two attrs have already been created by cgraph
		if (!(tport = agget(e,"tailport")))
		    tport = "";
		if (!(hport = agget(e,"headport")))
		    hport = "";
	    }
	    else
		tport = hport = "";
	    if (ED_spl(e)) {
		splinePoints = 0;
		for (i = 0; i < ED_spl(e)->size; i++) {
		    bz = ED_spl(e)->list[i];
		    splinePoints += bz.size;
		}
		printstring(f, NULL, "edge");
		writenodeandport(f, agtail(e), tport);
		writenodeandport(f, aghead(e), hport);
		printint(f, " ", splinePoints);
		for (i = 0; i < ED_spl(e)->size; i++) {
		    bz = ED_spl(e)->list[i];
		    for (j = 0; j < bz.size; j++)
			printpoint(f, bz.list[j]);
		}
	    }
	    if (ED_label(e)) {
		printstring(f, " ", canon(agraphof(agtail(e)),ED_label(e)->text));
		printpoint(f, ED_label(e)->pos);
	    }
	    printstring(f, " ", late_nnstring(e, E_style, "solid"));
	    printstring(f, " ", late_nnstring(e, E_color, DEFAULT_COLOR));
	    agputc('\n', f);
	}
    }
    agputs("stop\n", f);
}