Example #1
0
static void
num_arg(char *arg, int md)
{
	offset_t repeat, toline;
	char rep[21];
	char *ptr;
	int		len;

	ptr = rep;
	for (++arg; *arg != '}'; arg += len) {
		if (*arg == NULL)
			fatal("%s: missing '}'\n", targ);
		if ((len = mblen(arg, MB_LEN_MAX)) <= 0)
			len = 1;
		if ((ptr + len) >= &rep[20])
			fatal("%s: Repeat count too large\n", targ);
		(void) memcpy(ptr, arg, len);
		ptr += len;
	}
	*ptr = NULL;
	if ((asc_to_ll(rep, &repeat) == ERR) || repeat < 0L)
		fatal("Illegal repeat count: %s\n", targ);
	if (md == LINMODE) {
		toline = offset = curline;
		for (; repeat > 0LL; repeat--) {
			toline += offset;
			to_line(toline);
		}
	} else	if (md == EXPMODE)
			for (; repeat > 0LL; repeat--)
				to_line(findline(expbuf, offset));
		else
			fatal("No operation for %s\n", targ);
}
Example #2
0
static void
line_arg(char *line)
{
	long long to;

	if (asc_to_ll(line, &to) == ERR)
		fatal("%s: bad line number\n", line);
	to_line(to);
}
Example #3
0
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    if ( isSelected() )
    {
        QPen pen(color_selected,2);
        pen.setCosmetic(true);
        painter->setPen(pen);
        QLineF nv = to_line().normalVector();
        nv.setLength((Node::external_radius()-2)/painter->matrix().m11());
        painter->drawLine(to_line().translated(nv.dx(),nv.dy()));
        painter->drawLine(to_line().translated(-nv.dx(),-nv.dy()));
    }

    if ( visible && highlighted )
        m_style.edge_type->paint_highlighted(painter,*this);
    else if ( visible || highlighted )
        m_style.edge_type->paint_regular(painter,*this);

}
Example #4
0
static void
re_arg(char *string)
{
	char *ptr;
	char ch;
	int		len;

	ch = *string;
	ptr = string;
	ptr++;
	while (*ptr != ch) {
		if (*ptr == '\\')
			++ptr;

		if (*ptr == NULL)
			fatal("%s: missing delimiter\n", targ);

		if ((len = mblen(ptr, MB_LEN_MAX)) <= 0)
			len = 1;
		ptr += len;
	}

	/*
	 * The line below was added because compile no longer supports
	 * the fourth argument being passed.  The fourth argument used
	 * to be '/' or '%'.
	 */

	*ptr = NULL;
	if (asc_to_ll(++ptr, &offset) == ERR)
		fatal("%s: illegal offset\n", string);

	/*
	 * The line below was added because INIT which did this for us
	 * was removed from compile in regexp.h
	 */

	string++;
	expbuf = compile(string, (char *)0, (char *)0);
	if (regerrno)
		PERROR(regerrno);
	to_line(findline(expbuf, offset));
}
Example #5
0
int
main(int argc, char **argv)
{
	int ch, mode;
	char *ptr;

	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
#define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	while ((ch = getopt(argc, argv, "skf:n:")) != EOF) {
		switch (ch) {
			case 'f':
				(void) strcpy(file, optarg);
				if ((ptr = strrchr(optarg, '/')) == NULL)
					ptr = optarg;
				else
					ptr++;

				break;
			case 'n':		/* POSIX.2 */
				for (ptr = optarg; *ptr != NULL; ptr++)
					if (!isdigit((int)*ptr))
						fatal("-n num\n", NULL);
				fiwidth = atoi(optarg);
				break;
			case 'k':
				keep++;
				break;
			case 's':
				silent++;
				break;
			case '?':
				errflg++;
		}
	}

	argv = &argv[optind];
	argc -= optind;
	if (argc <= 1 || errflg)
		usage();

	if (strcmp(*argv, "-") == 0) {
		infile = tmpfile();

		while (fread(tmpbuf, 1, BUFSIZ, stdin) != 0) {
			if (fwrite(tmpbuf, 1, BUFSIZ, infile) == 0)
				if (errno == ENOSPC) {
					(void) fprintf(stderr, "csplit: ");
					(void) fprintf(stderr, gettext(
					    "No space left on device\n"));
					exit(1);
				} else {
					(void) fprintf(stderr, "csplit: ");
					(void) fprintf(stderr, gettext(
					    "Bad write to temporary "
					    "file\n"));
					exit(1);
				}

	/* clear the buffer to get correct size when writing buffer */

			(void) memset(tmpbuf, '\0', sizeof (tmpbuf));
		}
		rewind(infile);
	} else if ((infile = fopen(*argv, "r")) == NULL)
		fatal("Cannot open %s\n", *argv);
	++argv;
	curline = (offset_t)1;
	(void) signal(SIGINT, sig);

	/*
	 * The following for loop handles the different argument types.
	 * A switch is performed on the first character of the argument
	 * and each case calls the appropriate argument handling routine.
	 */

	for (; *argv; ++argv) {
		targ = *argv;
		switch (**argv) {
		case '/':
			mode = EXPMODE;
			create = TRUE;
			re_arg(*argv);
			break;
		case '%':
			mode = EXPMODE;
			create = FALSE;
			re_arg(*argv);
			break;
		case '{':
			num_arg(*argv, mode);
			mode = FALSE;
			break;
		default:
			mode = LINMODE;
			create = TRUE;
			line_arg(*argv);
			break;
		}
	}
	create = TRUE;
	to_line(LAST);
	return (0);
}
Example #6
0
void line_listener(void * cvoid, zctx_t * context, void * pipe) {
  lineconfig_t * config = (lineconfig_t*)  cvoid;
  // atm, topic == outpipe, but this is coincidental...
  zmsg_t * msg;
  dump_lineconfig(config);
  channel_memory_t channel_memory = { strdup("unknown"),
                                      strdup("unknown"),
                                      0 };
  // void * monitor_controller = zsocket_new(config->context, ZMQ_PUB);
  //  zsocket_bind(monitor_controller, "inproc://monitor_controller");
  //  int trigger_capacity = 1;
  
  void * lineout = zsocket_new(context, ZMQ_PUB);
  char * outpipe = to_linesocket(config->line_id);
  zclock_log("binding line |%s|", outpipe);
  zsocket_bind(lineout, outpipe);

  void * subscriber = zsocket_new(context, ZMQ_SUB);
  zclock_log("subscribing to line |%d|", config->line_id);
  zsockopt_set_unsubscribe(subscriber, "");

  char * topic = to_line(config->line_id);
  // 
  zsockopt_set_subscribe(subscriber, topic);
  zclock_log("subscribing to literal line |%s|", topic);
  zsocket_connect(subscriber, "inproc://line");

  child_handshake(pipe);
  zsocket_destroy(context, pipe);

  while(1) {
    msg = zmsg_recv(subscriber);
    if(!msg) {
      zclock_log("line quitting!");
      return;
    }
        
    // zmsg_dump(msg);
    char * recv_topic = zmsg_popstr(msg);
    // zclock_log("line got topic\nreceived: %s\nexpected: %s\n", recv_topic, config->topic);
    //fflush(stdout);
    assert(strcmp(recv_topic, topic)==0);
    free(recv_topic);
    assert(zmsg_size(msg) == 2);
      
    char * channel = zmsg_popstr(msg);
    zmsg_t * out = zmsg_new();
    // originally, I thought it was a neat trick to not mention the
    // channel in every message. unfortunately, this screws up the
    // case where a new trigger gets introduced: at the beginning, it
    // has no idea what the channel currently is.

    // rather than trying to micro-optimise, let's just keep repeating
    // the channel in the value update too.

    if (port_changed(channel, &channel_memory)) {
      zmsg_pushstr(out, channel_memory.current_channel);
      zmsg_pushstr(out, "CHANNEL_CHANGE");
      zmsg_send(&out, lineout);
    }
    // only send a value if we're all settled down
    if(strcmp(channel, channel_memory.current_channel)==0) {
      out = zmsg_new();
      zmsg_pushstr(out, channel_memory.current_channel);
      zmsg_push(out, zmsg_pop(msg));
      zmsg_pushstr(out, "VALUE");
      zmsg_send(&out, lineout);
    }
    free(channel);
    zmsg_destroy(&msg);
    
  }
  free(config);
}