示例#1
0
void InteractiveScanner::ErrorMessage(const char* msg, fint l, fint c) {
  if (suppress)
    return;
  for (fint i = 1; i < c; i ++) putchar(' ');
  lprintf("^\n");
  error3("%s on line %ld, character %ld", msg, l, c);
}
示例#2
0
int cmd_exec(struct command_t* command){
	if(error1(command))
		return -1;
	if(error2(command))
		return -2;
	if(error3(command))
		return -3;
	if(error4(command))
		return -4;
	if(error5(command))
		return -5;

	if(isNum(command->token[0])){
		command->arg1 = atoi(command->token[0]);
		strcpy(command->operation, command->token[1]);
		command->arg2 = atoi(command->token[2]);
	}
	else{
		strcpy(command->operation, command->token[0]);
		command->arg1 = atoi(command->token[1]);
	}

	DoOperation(command);
	return 0;
}
示例#3
0
int open_archive(char *name, int mode)
{
  unsigned short magic = 0;
  int fd;

  if (mode == CREATE) {
	if ((fd = creat(name, 0666)) < 0)
		error2(TRUE, "cannot creat %s\n", name);
	magic = MAGIC_NUMBER;
	wr_int2(fd, magic);
	return fd;
  }

  if ((fd = open(name, mode)) < 0) {
	if (mode == APPEND) {
		close(open_archive(name, CREATE));
		if (!nocr_fl) error3(FALSE, "%s: creating %s\n", progname, name);
		return open_archive(name, APPEND);
	}
	error2(TRUE, "cannot open %s\n", name);
  }
  lseek(fd, 0L, 0);
  magic = rd_unsigned2(fd);
  if (magic != AALMAG && magic != ARMAG)
	error2(TRUE, "%s is not in ar format\n", name);
  
  return fd;
}
示例#4
0
/*
 * m4open
 *
 * Continue processing files when unable to open the given file argument.
 */
FILE *
m4open(char ***argvec, char *mode, int *argcnt)
{
	FILE	*fp;
	char *arg;

	while (*argcnt > 0) {
		arg = (*argvec)[0]; /* point arg to current file name */
		if (arg[0] == '-' && arg[1] == EOS)
			return (stdin);
		else {
			if ((fp = fopen(arg, mode)) == NULL) {
				(void) fprintf(stderr, gettext(
				"m4: cannot open %s: "), arg);
				perror("");
				if (*argcnt == 1) {
					/* last arg therefore exit */
					error3();
				} else {
					exitstat = 1;
					(*argvec)++; /* try next arg */
					(*argcnt)--;
				}
			} else
				break;
		}
	}
	return (fp);
}
示例#5
0
/* Routine was patched by Hiroaki Morimoto, revised 2003/08/15.
   Rewritten by DPL 2004/05/16 to be more understandable.
   octaveCode returns octave adjustments in the order
   [absolute or =],[relative] */
void checkOctave(voice_index voice, Char *note)
{
  Char code;

  code = octaveCode(note);
  if (code == '=') {
    setOctave(voice);
    removeOctaveCode(code, note);
  }
  if (octave(voice) == blank)
    return;
  code = octaveCode(note);
  if (isdigit(code)) {
    resetOctave(voice);
    return;
  }
  while (code == '+' || code == '-') {
    newOctave(voice, code);
    removeOctaveCode(code, note);
    code = octaveCode(note);
  }
  if (code != ' ')
    error3(voice, "You may have only one absolute octave assignment");
  insertOctaveCode(octave(voice), note);
  checkRange(voice, note);
  resetOctave(voice);
}
示例#6
0
void
error(char *str)
{
	(void) fprintf(stderr, "\n%s:", procnam);
	fpath(stderr);
	(void) fprintf(stderr, ":%d %s\n", fline[ifx], str);
	error3();
}
示例#7
0
Local void adjustUptext(struct LOC_addUptext *LINK)
{
  Char letter;
  boolean force = false;
  uptext_info *WITH1;

  delete1(LINK->w, 1);
  while (*LINK->w != '\0') {
/* p2c: uptext.pas: Note: Eliminated unused assignment statement [338] */
    letter = LINK->w[0];
    delete1(LINK->w, 1);
    WITH1 = &U[LINK->voice-1];
    switch (letter) {

    case '<':
      if (WITH1->uptext_lcz > 1)
	WITH1->uptext_lcz--;
      break;

    case '>':
      if (WITH1->uptext_lcz < 3)
	WITH1->uptext_lcz++;
      break;

    case '^':
      WITH1->uptext_adjust = 0;
      break;

    case 'v':
      WITH1->uptext_adjust = under;
      break;

    case '=':
      force = true;
      break;

    case '+':
    case '-':
      if (*LINK->w != '\0')
	getNum(LINK->w, &LINK->adj);
      else
	LINK->adj = 0;
      if (letter == '-')
	LINK->adj = -LINK->adj;
      if (force)
	WITH1->uptext_adjust = LINK->adj;
      else
	WITH1->uptext_adjust += LINK->adj;
      *LINK->w = '\0';
      break;

    default:
      error3(LINK->voice, "Unknown uptext adjustment");
      break;
    }
  }
  strcpy(LINK->w, "!");
}
示例#8
0
文件: main.c 项目: bruceg/bglibs
static int cli_option_parse_long_eq(cli_option* o, const char* arg)
{
  if(o->type == CLI_FLAG || o->type == CLI_COUNTER) {
    error3("Option --", o->name, " does not take a value.");
    return -1;
  }
  else
    return cli_option_set(o, arg) - 1;
}
示例#9
0
文件: main.c 项目: bruceg/bglibs
static int cli_option_parse_long_noeq(cli_option* o, const char* arg)
{
  if(o->type == CLI_FLAG || o->type == CLI_COUNTER)
    return cli_option_set(o, 0);
  else if(arg)
    return cli_option_set(o, arg);
  else {
    error3("Option --", o->name, " requires a value.");
    return -1;
  }
}
示例#10
0
void usage()
{
	error3(TRUE, "usage: %s %s archive [file] ...\n",
		progname,
#ifdef AAL
		"[acdrtxvlu]"
#else
		"[acdprtxvlu]"
#endif
		);
}
示例#11
0
文件: Sound.cpp 项目: alekstorm/tala
Sound Sound_extractChannel (Sound me, long ichan) {
	Sound thee = NULL;
//start:
	if (ichan <= 0 || ichan > my ny) error3 (L"Cannot extract channel ", Melder_integer (ichan), L".");
	thee = Sound_create (1, my xmin, my xmax, my nx, my dx, my x1); cherror
	for (long isamp = 1; isamp <= my nx; isamp ++) {
		thy z [1] [isamp] = my z [ichan] [isamp];
	}
end:
	iferror forget (thee);
	return thee;
}
示例#12
0
文件: ncode.cpp 项目: AdamSpitz/self
bool NCodeBase::verify2(const char* name) {
  bool r = true;
  if ((int32)this & (oopSize - 1)) {
    error2("alignment error in %s at %#lx", name, this);
    r = false;
  }
  if (instsLen() > 256 * K) {
    error3("instr length of %s at %#lx seems too big (%ld)", name, this, instsLen());
    r = false;
  }
  return r;
}
示例#13
0
inline void subMonomial::length(int newlength) {
#ifdef CAREFUL
   if(newlength<0) {
     error3(newlength);
   } else if (_start+newlength-1 > _mono.numberOfFactors()) {
     error4(newlength);
   } else 
#endif
   {
     _length = newlength;
   }
};
示例#14
0
Local void examineMacro(struct LOC_scanMusic *LINK)
{
  if (!countMacro())
    return;
  if (debugMode())
    printf("%s: ", LINK->note);
  if (strlen(LINK->note) == 1) {
    LINK->mlen = LINK->bar_length - LINK->old_length;
    if (LINK->macroID < 1 || LINK->macroID > 20)
      error3(LINK->voice, "Invalid macro ID");
    macro_length[LINK->macroID-1] = LINK->mlen;
    if (debugMode())
      printf("Ending macro %d of type %c, length=%d\n",
	     LINK->macroID, LINK->macro_type, LINK->mlen);
    if (LINK->macro_type == 'S')
      LINK->bar_length = LINK->old_length;
    LINK->store_macro = false;
    return;
  }
  LINK->playID = identifyMacro(LINK->note, LINK);
  if (LINK->playID < 1 || LINK->playID > 20)
    error3(LINK->voice, "Invalid macro ID");
  if (LINK->note[1] == 'P') {
    if (debugMode())
      printf("Playing macro %d of length %d\n",
	     LINK->playID, macro_length[LINK->playID-1]);
    LINK->bar_length += macro_length[LINK->playID-1];
    return;
  }
  if (pos1(LINK->note[1], "SR") <= 0)
    return;
  LINK->old_length = LINK->bar_length;
  LINK->macro_type = LINK->note[1];
  LINK->macroID = LINK->playID;
  LINK->store_macro = true;
  if (debugMode())
    printf("Defining macro %d of type %c\n", LINK->macroID, LINK->note[1]);
}
示例#15
0
文件: win32_net.c 项目: 5py/libmpg123
static int win32_net_open_connection(mpg123_string *host, mpg123_string *port)
{
	struct addrinfo hints;
	struct addrinfo *addr, *addrlist;
	SOCKET addrcount;
	ws.local_socket = SOCKET_ERROR;

	if(param.verbose>1) fprintf(stderr, "Note: Attempting new-style connection to %s\n", host->p);
	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family   = AF_UNSPEC; /* We accept both IPv4 and IPv6 ... and perhaps IPv8;-) */
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	debug2("Atempt resolve/connect to %s:%s", host->p, port->p);
	msgme(addrcount = getaddrinfo(host->p, port->p, &hints, &addrlist));

	if(addrcount == INVALID_SOCKET)
	{
		error3("Resolving %s:%s: %s", host->p, port->p, gai_strerror(addrcount));
		return -1;
	}

	addr = addrlist;
	while(addr != NULL)
	{
		ws.local_socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
		if (ws.local_socket == INVALID_SOCKET)
		{
			msgme1;
		}
		else
		{
			if(win32_net_timeout_connect(ws.local_socket, addr->ai_addr, addr->ai_addrlen) == 0)
			break;
			debug("win32_net_timeout_connect error, closing socket");
			win32_net_close(ws.local_socket);
			ws.local_socket=SOCKET_ERROR;
		}
		addr=addr->ai_next;
	}
	if(ws.local_socket == SOCKET_ERROR) {error2("Cannot resolve/connect to %s:%s!", host->p, port->p);}
	else
	{
	  ws.inited = 2;
	}

	freeaddrinfo(addrlist);
	return 1;
}
示例#16
0
文件: module.c 项目: jmscott/blobio
void
module_leave()
{
    int i;
    static char nm[] = "module_leave";

    for (i = 0;  i < module_count;  i++) {
        struct digest_module *mp = modules[i];

        if (mp->shutdown) {
            if ((*mp->shutdown)())
                error3(nm, mp->name, "callback failed");
        } else
            warn3(nm, mp->name, "no shutdown() callback");
    }
}
示例#17
0
文件: prepmx.c 项目: MiKTeX/miktex
Static void getMeterChange(voice_index voice, Char *new_meter)
{
  short pn1, pn2;
  Char w[256], new_command[256];

  if (nextNote(voice) != mword)
    return;
  getMusicWord(w, voice);
  getMeter(w, &meternum, &meterdenom, &pn1, &pn2);
  full_bar = meternum * (64 / meterdenom);
  /* CMO: process denominator value with function PMXmeterdenom */
  meterWord(new_command, meternum, PMXmeterdenom(meterdenom), pn1, pn2);
  if (*new_meter != '\0' && strcmp(new_meter, new_command))
    error3(voice, "The same meter change must appear in all voices");
  strcpy(new_meter, new_command);
}
示例#18
0
文件: Ltas.cpp 项目: alekstorm/tala
Ltas Spectrum_to_Ltas (Spectrum me, double bandWidth) {
	Ltas thee = NULL;
	long numberOfBands = ceil ((my xmax - my xmin) / bandWidth), iband;
	if (bandWidth <= my dx) error3 (L"Bandwidth must be greater than ", Melder_double (my dx), L".")
	thee = Thing_new (Ltas); cherror
	Matrix_init (thee, my xmin, my xmax, numberOfBands, bandWidth, my xmin + 0.5 * bandWidth, 1, 1, 1, 1, 1); cherror
	for (iband = 1; iband <= numberOfBands; iband ++) {
		double fmin = thy xmin + (iband - 1) * bandWidth;
		double meanEnergyDensity = Sampled_getMean (me, fmin, fmin + bandWidth, 0, 1, FALSE);
		double meanPowerDensity = meanEnergyDensity * my dx;   /* As an approximation for a division by the original duration. */
		thy z [1] [iband] = meanPowerDensity == 0.0 ? -300.0 : 10 * log10 (meanPowerDensity / 4.0e-10);
	}
end:
	iferror forget (thee);
	return thee;
}
示例#19
0
文件: main.c 项目: bruceg/bglibs
static int parse_long(char* argv[])
{
  unsigned j;
  const char* arg = argv[0]+2;
  for(j = 0; j < cli_option_count; j++) {
    cli_option* o = cli_full_options[j];
    if(o->name) {
      size_t len = strlen(o->name);
      if(!memcmp(arg, o->name, len)) {
	if(arg[len] == '\0')
	  return cli_option_parse_long_noeq(o, argv[1]);
	else if(arg[len] == '=')
	  return cli_option_parse_long_eq(o, arg+len+1);
      }
    }
  }
  error3("Unknown option string: '--", arg, "'");
  return -1;
}
示例#20
0
int TCPconnect0(char *bindAddress,int bindPort,int block)
{
	struct in_addr iaddr;
	struct sockaddr_in saddr;
	int sd,j;
	int nodelay;

	if (!getAddress(bindAddress, &iaddr)) {
		error2("Host %s could not be resolved\n",bindAddress);
		return -1;
	}
	sd = socket(PF_INET, SOCK_STREAM, 0);
	if (sd < 0) {
		error("Couldn't create server socket!\n");
		return -1;
	}
	saddr.sin_family = AF_INET;
        memcpy(&saddr.sin_addr, &iaddr, sizeof(iaddr));
        saddr.sin_port = htons(bindPort);

	if (setsockopt(sd,IPPROTO_TCP,TCP_NODELAY,&nodelay,sizeof(nodelay))<0)
		error("TCP_NODELAY failed\n");
		
	if (block==0) {
		j=0;
		setsockopt(sd, SOL_SOCKET, SO_LINGER, &j, sizeof(j));
		fcntl(sd, F_SETFL, O_NONBLOCK);
	}

    if (connect(sd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
        	error3("Couldn't connect to address %s port %d\n",
	        bindAddress, bindPort);
	        return -1;
	}
	return(sd);
}
示例#21
0
static int initialize_device(out123_handle *ao)
{
	mpg123_tinyalsa_t* ta = (mpg123_tinyalsa_t*)ao->userptr;

	ta->config.channels = ao->channels;
	ta->config.rate = ao->rate;
    	ta->config.period_size = 1024;
    	ta->config.period_count = 4;
       	ta->config.format = PCM_FORMAT_S16_LE;
    	ta->config.start_threshold = 0;
    	ta->config.stop_threshold = 0;
	ta->config.silence_threshold = 0;

	ta->pcm = pcm_open(ta->card, ta->device, PCM_OUT, &ta->config);
	if (!ta->pcm || !pcm_is_ready(ta->pcm))
	{
		if(!AOQUIET)
			error3( "(open) Unable to open card %u PCM device %u (%s)\n"
			,	ta->card, ta->device, pcm_get_error(ta->pcm) );
		return -1;
	}

	return 0;
}
示例#22
0
文件: analyze.c 项目: MiKTeX/miktex
void testParagraph(void)
{
  voice_index0 voice;
  voice_index0 leader = 0, nv = 0;
  paragraph_index0 mus;
  short extra, l, nbar;
  voice_index0 FORLIM;
  Char STR2[256];
  Char STR4[256];

  nbars = 0;
  pickup = 0;
  nleft = 0;
  if (top > bottom)
    return;
  pickup = 0;
  *multi_bar_rest = '\0';
  FORLIM = bottom;
  for (voice = top; voice <= FORLIM; voice++) {
    mus = musicLineNo(voice);
    if (mus > 0) {   /** -------------- Voice is present  ---- */
      nv++;
      line_no = orig_line_no[mus-1];
      scanMusic(voice, &l);
      if (*multi_bar_rest != '\0' && nv > 1)
	error("Multi-bar rest allows only one voice", print);
      if (!pmx_preamble_done) {
	if (voice == top)
	  pickup = l;
	else if (pickup != l)
	  error3(voice, "The same pickup must appear in all voices");
      }
      nbar = numberOfBars(voice);
      extra = ExtraLength(voice);
      if (*multi_bar_rest != '\0' && (nbar > 0 || extra > 0))
	error3(voice, "Multi-bar rest allows no other rests or notes");
      if (nbar > nbars || nbar == nbars && extra > nleft) {
	nbars = nbar;
	nleft = extra;
	leader = voice;
      }
      if (!final_paragraph && meternum > 0 && extra > 0) {
	printf("Line has %s\n", describe(STR2, nbar, extra));
	error("   Line does not end at complete bar", print);
      }
      if (pmx_preamble_done && l > 0 && meternum > 0) {
	printf("l=%d meternum=%d\n", l, meternum);
	error3(voice, "Short bar with no meter change");
      }
    }
  }
  if (!pmx_preamble_done) {
    xmtrnum0 = (double)pickup / one_beat;   /* Don't want an integer result */
    if (beVerbose())
      printf("Pickup = %d/64\n", pickup);
  }
  if (leader <= 0)
    return;
  FORLIM = bottom;
  for (voice = top; voice <= FORLIM; voice++) {
    if (musicLineNo(voice) > 0) {
      if (voice != leader) {
	mus = musicLineNo(voice);
	line_no = orig_line_no[mus-1];
	if (numberOfBars(voice) != numberOfBars(leader) ||
	    ExtraLength(voice) != ExtraLength(leader)) {
	  printf("Following line has %s\n",
		 describe(STR4, numberOfBars(voice), ExtraLength(voice)));
	  puts(musicLine(STR4, voice));
	  printf("Longest line has %s\n",
		 describe(STR2, numberOfBars(leader), ExtraLength(leader)));
	  puts(musicLine(STR2, leader));
	  error("Line duration anomaly", print);
	}
      }
    }
  }
}
示例#23
0
文件: audio.c 项目: retsyx/slapstick
/*
 * c=num of channels of stream
 * r=rate of stream
 * return 0 on error
 */
int audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
{
	int rn;
	int f0=0;
	
	if(param.force_8bit) f0 = 2; /* skip the 16bit encodings */

	c--; /* stereo=1 ,mono=0 */

	/* force stereo is stronger */
	if(param.force_mono) c = 0;
	if(param.force_stereo) c = 1;

	if(param.force_rate) {
		rn = rate2num(param.force_rate);
		/* 16bit encodings */
		if(audio_fit_cap_helper(ai,rn,f0,2,c)) return 1;
		/* 8bit encodings */
		if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c)) return 1;

		/* try again with different stereoness */
		if(c == 1 && !param.force_stereo)	c = 0;
		else if(c == 0 && !param.force_mono) c = 1;

		/* 16bit encodings */
		if(audio_fit_cap_helper(ai,rn,f0,2,c)) return 1;
		/* 8bit encodings */
		if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c)) return 1;

		error3("Unable to set up output device! Constraints: %s%s%liHz.",
		      (param.force_stereo ? "stereo, " :
		       (param.force_mono ? "mono, " : "")),
		      (param.force_8bit ? "8bit, " : ""),
		      param.force_rate);
		if(param.verbose <= 1) print_capabilities(ai);
		return 0;
	}

	/* try different rates with 16bit */
	rn = rate2num(r>>0);
	if(audio_fit_cap_helper(ai,rn,f0,2,c))
		return 1;
	rn = rate2num(r>>1);
	if(audio_fit_cap_helper(ai,rn,f0,2,c))
		return 1;
	rn = rate2num(r>>2);
	if(audio_fit_cap_helper(ai,rn,f0,2,c))
		return 1;

	/* try different rates with 8bit */
	rn = rate2num(r>>0);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
		return 1;
	rn = rate2num(r>>1);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
		return 1;
	rn = rate2num(r>>2);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
		return 1;

	/* try again with different stereoness */
	if(c == 1 && !param.force_stereo)	c = 0;
	else if(c == 0 && !param.force_mono) c = 1;

	/* 16bit */
	rn = rate2num(r>>0);
	if(audio_fit_cap_helper(ai,rn,f0,2,c)) return 1;
	rn = rate2num(r>>1);
	if(audio_fit_cap_helper(ai,rn,f0,2,c)) return 1;
	rn = rate2num(r>>2);
	if(audio_fit_cap_helper(ai,rn,f0,2,c)) return 1;

	/* 8bit */
	rn = rate2num(r>>0);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c)) return 1;
	rn = rate2num(r>>1);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c)) return 1;
	rn = rate2num(r>>2);
	if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c)) return 1;

	error5("Unable to set up output device! Constraints: %s%s%i, %i or %iHz.",
	      (param.force_stereo ? "stereo, " :
	       (param.force_mono ? "mono, " : "")),
	      (param.force_8bit ? "8bit, " : ""),
	      r, r>>1, r>>2);
	if(param.verbose <= 1) print_capabilities(ai);
	return 0;
}
int
main_program(int num_channels, int num_connections, const char *server_hostname, int server_port, int timeout)
{
    struct sockaddr_in server_address;
    int main_sd = -1, num_events = 0, i, j, event_mask, channels_per_connection, num, start_time = 0, iters_to_next_summary = 0;
    Connection *connections = NULL, *connection;
    Statistics stats = {0,0,0,0,0};
    int exitcode = EXIT_SUCCESS;
    struct epoll_event events[MAX_EVENTS];
    char buffer[BIG_BUFFER_SIZE];

    info("Subscriber starting up\n");
    info("Subscriber: %d connections to %d channels on server: %s:%d\n", num_connections, num_channels, server_hostname, server_port);

    if ((fill_server_address(server_hostname, server_port, &server_address)) != 0) {
        error2("ERROR host name not found\n");
    }

    if ((main_sd = epoll_create(200 /* this size is not used on Linux kernel 2.6.8+ */)) < 0) {
        error3("Failed %d creating main epoll socket\n", errno);
    }

    if ((connections = init_connections(num_connections, &server_address, main_sd)) == NULL) {
        error2("Failed to create to connections\n");
    }

    stats.requested_connections = num_connections;

    for (i = 0; i < num_connections; i++) {
        connections[i].channel_start = 0;
        connections[i].channel_end = num_channels - 1;
    }

    // infinite loop
    debug("Entering Infinite Loop\n");

    iters_to_next_summary = ITERATIONS_TILL_SUMMARY_PER_TIMEOUT/timeout;

    for(;;) {
        if ((num_events = epoll_wait(main_sd, events, MAX_EVENTS, timeout)) < 0) {
            error3("epoll_wait failed\n");
        }

        for (i = 0; i < num_events; i++) {
            event_mask = events[i].events;
            connection = (Connection *)(events[i].data.ptr);

            if (event_mask & EPOLLHUP) { // SERVER HUNG UP
                debug("EPOLLHUP\n");
                info("Server hung up on conncetion %d. Reconecting...\n", connection->index);
                sleep(1);
                stats.connections--;
                reopen_connection(connection);

                continue;
            }

            if (event_mask & EPOLLERR) {
                debug("EPOLLERR\n");
                info("Server returned an error on connection %d. Reconecting...\n", connection->index);
                stats.connections--;
                reopen_connection(connection);

                continue;
            }

            if (event_mask & EPOLLIN) { // READ
                debug("----------READ AVAILABLE-------\n");

                if (connection->state == CONNECTED) {
                    read_response(connection, &stats, buffer, BIG_BUFFER_SIZE);
                }
            }

            if (event_mask & EPOLLOUT) { // WRITE
                debug("----------WRITE AVAILABLE-------\n");

                if (start_time == 0) {
                    start_time = time(NULL);
                }

                if (connection->state == CONNECTING) {
                    connection->state = CONNECTED;
                    stats.connections++;
                    debug("Connection opened for index=%d\n", connection->index);

                    subscribe_channels(connection, &stats);

                    // remove write flag from event
                    if (change_connection(connection, EPOLLIN | EPOLLHUP) < 0) {
                        error2("Failed creating socket for connection = %d\n", connection->index);
                    }
                }
            }
        }

        if ((iters_to_next_summary-- <= 0)) {
            iters_to_next_summary = ITERATIONS_TILL_SUMMARY_PER_TIMEOUT/timeout;
            summary("Connections=%ld, Messages=%ld BytesRead=%ld Msg/Sec=%0.2f\n", stats.connections, stats.messages, stats.bytes_read, calc_message_per_second(stats.messages, start_time));
        }

        if (stats.connections == 0) {
            num = 0;
            for (j = 0; j < num_connections; j++) {
                if (connections[i].state != CLOSED) {
                    num++;
                    break;
                }
            }

            if (num == 0) {
                exitcode = EXIT_SUCCESS;
                goto exit;
            }
        }
    }

exit:
    if (connections != NULL) free(connections);

    return exitcode;
}
示例#25
0
文件: net.c 项目: jmscott/blobio
/*
 *  Do a timed read of some bytes on the network.
 *
 *	>= 0	=> read some bytes
 *	-1	=> read() error
 *	-2	=> timeout
 */
ssize_t
net_read(int fd, void *buf, size_t buf_size, unsigned timeout)
{
	static char n[] = "net_read";

	ssize_t nread;
	int e;
	struct sigaction a;
	struct itimerval t;

	/*
	 *  Set the timeout alarm handler.
	 */
	memset(&a, 0, sizeof a);
	alarm_caught = 0;
	a.sa_handler = catch_SIGALRM;
	a.sa_flags = 0;
	sigemptyset(&a.sa_mask);
	t.it_interval.tv_sec = 0;
	t.it_interval.tv_usec = 0;
	t.it_value.tv_sec = timeout;
	t.it_value.tv_usec = 0;
again:
	/*
	 *  Set the alarm handler.
	 */
	if (sigaction(SIGALRM, &a, (struct sigaction *)0))
		panic3(n, "sigaction(ALRM) failed", strerror(errno));
	/*
	 *  Set the interval time.
	 */
	if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0))
		panic3(n, "setitimer(REAL) failed", strerror(errno));

	nread = read(fd, (void *)buf, buf_size);
	e = errno;

	/*
	 *  Disable timer.
	 *
	 *  Note:
	 *	Does setitimer(t.it_interval.tv_sec == 0) above imply
	 *	timer never refires?
	 */
	t.it_value.tv_sec = 0;
	if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0))
		panic3(n, "setitimer(REAL) reset failed", strerror(errno));

	if (nread < 0) {
		char tbuf[27];

		if (e != EINTR && e != EAGAIN) {
			error3(n, "read() failed", strerror(e));
			errno = e;
			return -1;
		}
		if (!alarm_caught)
			goto again;

		alarm_caught = 0;
		snprintf(tbuf, sizeof tbuf, "timed out after %d secs", timeout);
		error3(n, "alarm caught", tbuf);
		return -2;
	}
	return nread;
}
示例#26
0
void scanMusic(voice_index voice_, short *left_over)
{
  struct LOC_scanMusic V;
  Char buf[256], enote[256], xnote[256];
  boolean has_next = false, done = false;
  Char dur1, lastdur;
  music_word nscan;
  Char STR1[256];

  V.voice = voice_;
  strcpy(terminators, "d.x");
  resetInfo(V.voice, buf);
  *left_over = 0;
  V.store_macro = false;
  V.bar = full_bar;
  V.bar_length = 0;
  V.ngrace = 0;
  V.nmulti = 0;
  if (meternum == 0)
    V.bar = 32000;
  dur1 = duration(V.voice);
  lastdur = dur1;
  do {
    getNextMusWord(buf, V.note, &nscan);
    if (*V.note == '\0')
      break;
    V.count = 0;
    /*    if isNoteOrRest(note) and not (isPause(note) or isMultibarRest(note))
          then note:=toStandard(note); */
    V.doublex = (pos1('D', V.note) > 0);
    if (nscan == mword) {
      if (*V.note == '\0')
	error3(V.voice, "You may not end a line with a meter change");
      if (V.bar_length > 0)
	error3(V.voice, "Meter change only allowed at start of bar");
      else
	V.bar = barLength(V.note);
    } else if (nscan == rword) {
      if (!(isPause(V.note) || isMultiBarRest(V.note))) {
	processNote(V.note, xnote, dur1, &lastdur, &V.count);
	checkSticky(V.note, rest_attrib[V.voice-1]);
      }
    }
    if (*V.note != '\0')
      appendNote(V.voice, nscan);
    strcpy(enote, V.note);
    if (nscan == macro || nscan == endmacro)
      examineMacro(&V);
    if (nscan == abcdefg) {
      if (!multi_bar_rest && V.ngrace + V.nmulti == 0) {
	processNote(enote, xnote, dur1, &lastdur, &V.count);
	if (*xnote != '\0') {
	  checkSticky(enote, note_attrib[V.voice-1]);
	  appendToLine(V.voice, enote);
	  appendNote(V.voice, nscan);
	  strcpy(enote, xnote);
	}
	checkSticky(enote, note_attrib[V.voice-1]);
      }
    }
    appendToLine(V.voice, enote);
    if (*V.note == '\0')   /* !!! else word_bound[here]:=length(line); */
      done = true;
    sprintf(STR1, "%c", barsym);
    if (!strcmp(V.note, STR1)) {
      if (meternum == 0)
	error3(V.voice, "You may not use bar lines in barless music");
      else if (V.bar_length == 0)
	markBar(V.voice);
      else if (numberOfBars(V.voice) == 0 && V.bar_length < V.bar) {
	if (has_next)
	  has_next = false;   /*Should check whether pickups are equal*/
	else if (*left_over > 0)
	  error3(V.voice, "Bar is too short");
	*left_over = V.bar_length;
	V.bar_length = 0;
      }
    }
    if (nscan == nextvoice) {
      if (V.bar_length > 0)
	error3(V.voice, "Next voice before bar is full");
      else
	barForward(V.voice, -1);
      has_next = true;
    } else if (isPause(V.note))
      V.bar_length += V.bar;
    else if (!multi_bar_rest) {   /*do nothing*/
      if (!done && isNoteOrRest(V.note))
	countIt(&V);
      else
	maybeGroup(&V);
    }
    dur1 = lastdur;
    if (V.bar_length >= V.bar && V.ngrace + V.nmulti == 0 && !V.store_macro) {
      if (debugMode())
	printf("%d %d\n", V.voice, V.bar_length);
      barForward(V.voice, V.bar_length / V.bar);
      V.bar_length %= V.bar;
/* p2c: mtx.pas, line 268:
 * Note: Using % for possibly-negative arguments [317] */
    }
  } while (!done);
  setExtraLength(V.voice, V.bar_length);
  resetDuration(V.voice, dur1);
  regroup(V.voice);
}
示例#27
0
文件: net.c 项目: jmscott/blobio
/*
 *  Do a timed write() of an entire buffer.
 *  Returns
 *
 *	0	=> entire buffer written without error
 *	1	=> write() timed out
 *	-1	=> write() error
 */
int
net_write(int fd, void *buf, size_t buf_size, unsigned timeout)
{
	static char n[] = "net_write";

	int nwrite;
	unsigned char *b, *b_end;
	struct sigaction a;
	struct itimerval t;
	int e;

	b = buf;
	b_end = buf + buf_size;

	/*
	 *  Set the timeout alarm handler.
	 */
	memset(&a, 0, sizeof a);

	alarm_caught = 0;
	a.sa_handler = catch_SIGALRM;
	a.sa_flags = 0;
	sigemptyset(&a.sa_mask);
	t.it_interval.tv_sec = 0;
	t.it_interval.tv_usec = 0;
	t.it_value.tv_sec = timeout;
	t.it_value.tv_usec = 0;
again:
	/*
	 *  Set the ALRM handler.
	 */
	if (sigaction(SIGALRM, &a, (struct sigaction *)0))
		panic3(n, "sigaction(ALRM) failed", strerror(errno));
	/*
	 *  Set the timer
	 */
	if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0))
		panic3(n, "write_buf: setitimer(REAL) failed", strerror(errno));
	nwrite = write(fd, (void *)b, b_end - b);
	e = errno;

	/*
	 *  Disable timer.
	 *
	 *  Note:
	 *	Does setitimer(t.it_interval.tv_sec == 0) above imply
	 *	timer never refires?
	 */
	t.it_value.tv_sec = 0;
	t.it_value.tv_usec = 0;
	if (setitimer(ITIMER_REAL, &t, (struct itimerval *)0))
		panic3(n, "setitimer(REAL, 0) failed", strerror(errno));

	if (nwrite < 0) {
		char tbuf[20];

		if (e != EINTR && e != EAGAIN) {
			error3(n, "write() failed", strerror(errno));
			errno = e;
			return -1;
		}
		if (!alarm_caught)
			goto again;

		alarm_caught = 0;
		snprintf(tbuf, sizeof tbuf, "timed out after %d secs", timeout);
		error3(n, "alarm caught", tbuf);
		return 1;
	}
	b += nwrite;
	if (b < b_end)
		goto again;
	return 0;
}
示例#28
0
Local void incbar(short nl, struct LOC_countIt *LINK)
{
  LINK->LINK->bar_length += nl;
  if (LINK->LINK->bar_length > LINK->LINK->bar && meternum > 0)
    error3(LINK->LINK->voice, "Bar end occurs in mid-note");
}
示例#29
0
文件: prepmx.c 项目: MiKTeX/miktex
Local Char *processOther(Char *Result, Char *note_,
			 struct LOC_processLine *LINK)
{
  Char note[256];

  strcpy(note, note_);
  switch (thisNote(LINK->voice)) {

  case other:
    if (note[0] == grace_group) {
      if (strlen(note) == 1)
	LINK->ngrace = 1;
      else
	LINK->ngrace = pos1(note[1], digits);
      if (LINK->ngrace > 0)
	LINK->ngrace--;
    }
    break;

  /* For a zword, take note of pitch but do not change the contents */
  /* Add spurious duration because repitch expects duration to be present */
  case zword:
    strcpy(LINK->cutnote, note);
    predelete(LINK->cutnote, 1);
    insertChar('4', LINK->cutnote, 2);
    checkOctave(LINK->voice, LINK->cutnote);
    renewPitch(LINK->voice, LINK->cutnote);
    break;

  case lyrtag:
    extractLyrtag(LINK->voice, note);
    break;

  case rbrac:
    endBeam(LINK->voice);
    break;

  case rparen:
  case rlparen:
    endSlur(LINK->voice, note);
    break;

  case lbrac:
    beginBeam(LINK->voice, note);
    break;

  case lparen:
    maybeDotted(note, LINK);
    beginSlur(LINK->voice, note);
    break;

  case mword:
    error3(LINK->voice, "Meter change must be the first word of its bar");
    break;

  case atword:
    lyricsAdjust(LINK->voice, note);
    break;
  }
  return strcpy(Result, note);
}