Exemplo n.º 1
0
int autoconnect(fd_set *master, int *fdmax, servlist *serv) // XXX broken in the face of asynch nl [I have forgotten what was meant by this; I'm not aware of anything broken about this function]
{
	servlist *curr=serv;
	if(!curr) return(0);
	#if ASYNCH_NL
	char cstr[36+strlen(serv->name)+strlen(serv->portno)];
	sprintf(cstr, "Connecting to %s on port %s...", serv->name, serv->portno);
	nl_list *list=irc_connect(serv->name, serv->portno);
	if(!list) return(autoconnect(master, fdmax, serv->next));
	add_to_buffer(0, STA, QUIET, 0, false, cstr, "auto: ");
	list->reconn_b=0;
	list->autoent=serv;
	#else /* ASYNCH_NL */
	char cstr[36+strlen(serv->name)+strlen(serv->portno)];
	sprintf(cstr, "Connecting to %s on port %s...", serv->name, serv->portno);
	add_to_buffer(0, STA, QUIET, 0, false, cstr, "auto: ");
	int serverhandle=irc_connect(serv->name, serv->portno, master, fdmax);
	if(serverhandle)
	{
		bufs=(buffer *)realloc(bufs, ++nbufs*sizeof(buffer));
		cbuf=nbufs-1;
		init_buffer(cbuf, SERVER, serv->name, buflines);
		bufs[cbuf].handle=serverhandle;
		bufs[cbuf].nick=strdup(serv->nick);
		bufs[cbuf].autoent=serv;
		if(serv) bufs[cbuf].ilist=n_dup(serv->igns);
		bufs[cbuf].server=cbuf;
		bufs[cbuf].conninpr=true;
		add_to_buffer(cbuf, STA, QUIET, 0, false, cstr, "auto: ");
		redraw_buffer();
	}
	#endif /* ASYNCH_NL */
	autoconnect(master, fdmax, serv->next);
	return(1);
}
Exemplo n.º 2
0
lexeme *st_backslash_in_quotes(lexer_info *linfo, buffer *buf)
{
#ifdef LEXER_DEBUG
    print_state("ST_BACKSLASH_IN_QUOTES", linfo->c);
#endif

    switch (linfo->c) {
    case EOF:
        linfo->state = ST_ERROR;
        break;
    case '\"':
        add_to_buffer(buf, linfo->c);
        break;
    case '\n':
        print_prompt2();
        /* fallthrough */
    default:
        add_to_buffer(buf, '\\');
        add_to_buffer(buf, linfo->c);
        break;
    }
    deferred_get_char(linfo);
    linfo->state = ST_IN_QUOTES;

    return NULL;
}
Exemplo n.º 3
0
nl_list *irc_connect(char *server, const char *portno)
{
	// Look up server
	struct addrinfo *hints=malloc(sizeof(struct addrinfo));
	if(!hints)
	{
		add_to_buffer(0, ERR, NORMAL, 0, false, strerror(errno), "malloc: ");
		return(NULL);
	}
	memset(hints, 0, sizeof(*hints));
	hints->ai_family=AF_INET;
	hints->ai_socktype = SOCK_STREAM; // TCP stream sockets
	struct gaicb *nl_details=malloc(sizeof(struct gaicb));
	if(!nl_details)
	{
		add_to_buffer(0, ERR, NORMAL, 0, false, strerror(errno), "malloc: ");
		return(NULL);
	}
	nl_list *nl=malloc(sizeof(nl_list));
	if(!nl)
	{
		add_to_buffer(0, ERR, NORMAL, 0, false, strerror(errno), "malloc: ");
		free(nl_details);
		return(NULL);
	}
	*nl=(nl_list){.nl_details=nl_details, .autoent=NULL, .reconn_b=0, .pass=NULL, .next=nl_active, .prev=NULL};
	*nl_details=(struct gaicb){.ar_name=strdup(server), .ar_service=strdup(portno), .ar_request=hints};
	if(nl_active) nl_active->prev=nl;
	nl_active=nl;
	getaddrinfo_a(GAI_NOWAIT, &nl->nl_details, 1, &(struct sigevent){.sigev_notify=SIGEV_SIGNAL, .sigev_signo=SIGUSR1});
	return(nl_active);
}
Exemplo n.º 4
0
// TODO Check it!
int result_iterate (void* json_v, int col_count, char** cols, char** col_names) {
  int i;
  long size, count;
  char** json = (char**)json_v;

  // Format string
  if (add_to_buffer (json, "{") != 0)
    return 1;
  
  for (i = 0; i < col_count; i++) {
    if (cols[i] == NULL)
      continue;
    
    size = buffer_est_size (*json) - 1;
    count = snprintf (*json, (size_t)size, "%s: '%s'", col_names[i], cols[i]);
    if (count >= size)
      return 1;
    (*json) += count;
    
    if (i != col_count - 1)
      if (add_to_buffer (json, ", ") != 0)
	return 1;
  }

  if (add_to_buffer (json, "}, ") != 0)
    return 1;

  return 0;
}
Exemplo n.º 5
0
int irc_rx(int fd, char ** data, fd_set *master)
{
	sigpipe=0;
	char buf[512];
	unsigned long int l=0;
	bool cr=false;
	while(!(cr||sigpipe))
	{
		long bytes=recv(fd, buf+l, 1, 0);
		if(bytes>0)
		{
			char c=buf[l];
			if((strchr("\n\r", c)!=NULL) || (l>510))
			{
				cr=true;
				buf[l]=0;
			}
			l++;
		}
		else // bytes<=0
		{
			if(errno==EINTR)
				continue;
			int b;
			for(b=0;b<nbufs;b++)
			{
				if((fd==bufs[b].handle) && (bufs[b].type==SERVER))
				{
					add_to_buffer(b, ERR, NORMAL, 0, false, strerror(errno), "irc_rx: recv:");
					bufs[b].live=false;
					close(bufs[b].handle);
					bufs[b].handle=0; // de-bind fd
				}
			}
			FD_CLR(fd, master);
			cr=true; // just crash out with a partial message
			buf[l]=0;
		}
	}
	*data=strdup(buf);
	if(*buf)
	{
		char rmsg[32+strlen(buf)];
		sprintf(rmsg, "%d, %lu bytes: %s", fd, l, buf);
		add_to_buffer(0, STA, DEBUG, 0, false, rmsg, sigpipe?"DBG SIGPIPE rx: ":"DBG rx: ");
	}
	if(sigpipe)
	{
		sigpipe=0;
		return(-1);
	}
	if(!*data)
		return(1);
	return(0);
}
Exemplo n.º 6
0
int
create_sig (BUFFER * data, BUFFER * signature)
{
#ifdef USE_RSAREF
  R_RSA_PRIVATE_KEY sigKey;
  R_SIGNATURE_CTX context;
  unsigned char sig[MAX_SIGNATURE_LEN];
  unsigned int sigLen;

  if (get_priv_key (NULL, &sigKey) != 0)
    return -1;
  R_SignInit (&context, DA_MD5);
  R_SignUpdate (&context, data->message, data->length);
  if (R_SignFinal (&context, sig, &sigLen, &sigKey) != 0)
    {
      fprintf (errlog, "Error: Cannot create signature.\n");
      return (-1);
    }
  add_to_buffer (signature, sig, sigLen);
  return 0;
#else
  /* not implemented */
  return (-1);
#endif
}
Exemplo n.º 7
0
static void		handle_search(t_htable *table, char *key, char *print_buf)
{
	char		*value;

	if (!(value = get_hash(table, key)))
	{
		add_to_buffer(print_buf, key);
		add_to_buffer(print_buf, ": Not found.\n");
	}
	else
	{
		add_to_buffer(print_buf, value);
		add_to_buffer(print_buf, "\n");
	}
	free(key);
}
Exemplo n.º 8
0
static PmError winmm_write_short(PmInternal *midi, PmEvent *event)
{
    midiwinmm_type m = (midiwinmm_type) midi->descriptor;
    PmError rslt = pmNoError;
    assert(m);

    if (midi->latency == 0) { /* use midiOut interface, ignore timestamps */
        m->error = midiOutShortMsg(m->handle.out, event->message);
        if (m->error) rslt = pmHostError;
    } else {  /* use midiStream interface -- pass data through buffers */
        unsigned long when = event->timestamp;
        unsigned long delta;
        int full;
        if (when == 0) when = midi->now;
        /* when is in real_time; translate to intended stream time */
        when = when + m->delta + midi->latency;
        /* make sure we don't go backward in time */
        if (when < m->last_time) when = m->last_time;
        delta = when - m->last_time;
        m->last_time = when;
        /* before we insert any data, we must have a buffer */
        if (m->hdr == NULL) {
            /* stream interface: buffers allocated when stream is opened */
            m->hdr = get_free_output_buffer(midi);
        }
        full = add_to_buffer(m, m->hdr, delta, event->message);
        if (full) rslt = winmm_write_flush(midi, when);
    }
    return rslt;
}
Exemplo n.º 9
0
/*
 Producer thread function.
 producer producers the set of integers
 that satisfy i%num_producers = p_id;

 Produer first waits till the buffer is not full.
 Producer locks the buffer.
 Producer inserts a value into a buffer.
 Producer unlocks the buffer.
 Producer notifies the buffer is not empty, by calling
 sem_post(&count).
 */
void* producer(void* producer_params) {

	struct thread_params *params = (struct thread_params*) producer_params;
	int p_id = params->id;

	int i;
	for (i = p_id; i < production_count; i += producer_count) {

		//wait until buffer is not full
		sem_wait(&buff_size);

		//toggle the lock
		sem_wait(&buff_lock);

		//add item to buffer
		add_to_buffer(i);

		//release the lock
		sem_post(&buff_lock);

		//notify that the buffer is not empty.
		sem_post(&count);

	}
	return NULL;
}
Exemplo n.º 10
0
static int run_scan_word(lua_State * L) /* HH */
{
    saved_tex_scanner texstate;
    save_tex_scanner(texstate);
    do {
        get_x_token();
    } while ((cur_cmd == spacer_cmd) || (cur_cmd == relax_cmd));
    if (cur_cmd == 11 || cur_cmd == 12 ) {
        declare_buffer;
        while (1) {
            add_to_buffer(cur_chr);
            get_x_token();
            if (cur_cmd != 11 && cur_cmd != 12 ) {
                break ;
            }
        }
        back_input();
        push_buffer;
    } else {
        back_input();
        lua_pushnil(L);
    }
    unsave_tex_scanner(texstate);
    return 1;
}
Exemplo n.º 11
0
static void sensorResponded(char response, int time) {
    if (!IGNORE_RESULT) {
      for (int i = 0; i < 8; i++) {
          int mask = 1 << i;
          int offset = 0;
          if (CURR_HIGH_BITS) {
              offset += 8;
          }
          if ((mask & response) != 0 && SENSOR_VALUE[CURR_SENSOR_BOX][7-i+offset] == 0) {
            Sensor s;
            s.box = CURR_SENSOR_BOX;
            s.val = 8 -i + offset;
            s.time = time;

            add_to_buffer(s);
          }
          SENSOR_VALUE[CURR_SENSOR_BOX][7-i+offset] = ((mask & response) !=0);
      }
    }
    if (CURR_HIGH_BITS) {
        CURR_HIGH_BITS = 0;
        ++CURR_SENSOR_BOX;
    } else {
        CURR_HIGH_BITS = 1;
    }
    if (CURR_SENSOR_BOX >= NUM_SENSOR_BOX) {
        CURR_SENSOR_BOX = 0;
        IGNORE_RESULT = 0;
    }
}
Exemplo n.º 12
0
int irc_conn_rest(int b, char *nick, char *username, char *passwd, char *fullname)
{
	add_to_buffer(0, STA, DEBUG, 0, false, "", "DBG connect rest");
	bufs[b].live=true; // mark it as live
	bufs[b].conninpr=false;
	bufs[b].ping=0;
	bufs[b].last=time(NULL);
	if(bufs[b].autoent && bufs[b].autoent->nick)
		nick=bufs[b].autoent->nick;
	if(bufs[b].autoent && bufs[b].autoent->pass)
		passwd=bufs[b].autoent->pass;
	if(passwd) // Optionally send a PASS message before the NICK/USER
	{
		char passmsg[6+strlen(passwd)];
		sprintf(passmsg, "PASS %s", passwd); // PASS <password>
		irc_tx(bufs[b].handle, passmsg);
	}
	char nickmsg[6+strlen(nick)];
	sprintf(nickmsg, "NICK %s", nick); // NICK <nickname>
	irc_tx(bufs[b].handle, nickmsg);
	struct utsname arch;
	uname(&arch);
	char usermsg[16+strlen(username)+strlen(arch.nodename)+strlen(fullname)];
	sprintf(usermsg, "USER %s 0 %s :%s", username, arch.nodename, fullname); // USER <user> <mode> <unused> <realname>
	irc_tx(bufs[b].handle, usermsg);
	return(0);
}
Exemplo n.º 13
0
void init(char *yaffs_test_dir,char *yaffs_mount_dir,int argc, char *argv[]){
	char output=0;
	int x=0;
	int seed=-1;
	FILE *log_handle;
	/*these variables are already set to zero, but it is better not to take chances*/
	message_buffer.head=0;				 
	message_buffer.tail=0;


	log_handle=fopen(LOG_FILE,"w");
	if (log_handle!=NULL){
		fputs("log file for yaffs tester\n",log_handle);
		fclose(log_handle);
	}
	add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	
	yaffs_start_up();
    	yaffs_mount(yaffs_mount_dir);
	for (x=0;x<argc;x++){
//		add_to_buffer(&message_buffer,"argv ",MESSAGE_LEVEL_BASIC_TASKS,PRINT);
//		add_to_buffer(&message_buffer,argv[x],MESSAGE_LEVEL_BASIC_TASKS,PRINT);
		if (strcmp("-seed",argv[x])==0){			/*warning only compares the length of the strings, quick fix*/
			seed= atoi(argv[x+1]);
			/*add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
			append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);			
			append_to_buffer(&message_buffer,"\n",MESSAGE_LEVEL_BASIC_TASKS,PRINT);*/
		}
	}
	if (seed==-1){
		seed=time(NULL);
		srand(seed); 
	}
	else {
	srand(seed);
	}
	add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	

	if (yaffs_access(yaffs_test_dir,0))	/* if the test folder does not exist then create it */
	{
		add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
		append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);	
		output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
		yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
	}
	
}
Exemplo n.º 14
0
int
compress_buf2buf (BUFFER * in, BUFFER * out, long offset)
{
  z_stream s;
  int err;
  char outbuf[4096];

  if (compressed_buf (in, offset))
    {
      /* is already compressed */
      add_to_buffer (out, in->message, in->length);
      return 0;
    }

  add_to_buffer (out, in->message, offset);

  s.zalloc = (alloc_func) 0;
  s.zfree = (free_func) 0;
  s.opaque = (voidpf) 0;
  s.next_in = NULL;

  sprintf (outbuf, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
	   Z_DEFLATED, 0 /*flags */ , 0, 0, 0, 0 /*time */ , 0 /*xflags */ ,
	   3 /* Unix */ );
  add_to_buffer (out, outbuf, 10);

  if (deflateInit2 (&s, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS,
		    8, 0) != Z_OK)
    return 0;

  s.next_in = in->message + offset;
  s.avail_in = in->length - offset;
  s.next_out = outbuf;
  s.avail_out = sizeof (outbuf);

  while ((err = deflate (&s, Z_FINISH)) == Z_OK)
    {
      add_to_buffer (out, outbuf, sizeof (outbuf) - s.avail_out);
      s.next_out = outbuf;
      s.avail_out = sizeof (outbuf);
    }
  add_to_buffer (out, outbuf, sizeof (outbuf) - s.avail_out);
  if (deflateEnd (&s) != Z_OK || err != Z_STREAM_END)
    return 0;
  return 1;
}
Exemplo n.º 15
0
ssize_t
read_buffer(int fd, struct buffer_s * buffptr)
{
	ssize_t bytesin;
	unsigned char *buffer;

	assert(fd >= 0);
	assert(buffptr != NULL);

	/*
	 * Don't allow the buffer to grow larger than MAXBUFFSIZE
	 */
	if (buffptr->size >= MAXBUFFSIZE)
		return 0;

	buffer = safemalloc(READ_BUFFER_SIZE);
	if (!buffer) {
		return -ENOMEM;
	}

	bytesin = read(fd, buffer, READ_BUFFER_SIZE);

	if (bytesin > 0) {
		if (add_to_buffer(buffptr, buffer, bytesin) < 0) {
			log_message(LOG_ERR,
				    "readbuff: add_to_buffer() error.");
			bytesin = -1;
		}
	} else {
		if (bytesin == 0) {
			/* connection was closed by client */
			bytesin = -1;
		} else {
			switch (errno) {
#ifdef EWOULDBLOCK
			case EWOULDBLOCK:
#else
#  ifdef EAGAIN
			case EAGAIN:
#  endif
#endif
			case EINTR:
				bytesin = 0;
				break;
			default:
				log_message(LOG_ERR,
					    "readbuff: recv() error \"%s\" on file descriptor %d",
					    strerror(errno), fd);
				bytesin = -1;
				break;
			}
		}
	}

	safefree(buffer);
	return bytesin;
}
Exemplo n.º 16
0
int
uncompress_buf2buf (BUFFER * in, BUFFER * out, long offset)
{
  z_stream s;
  char outbuf[4096];
  byte *p;
  int err;

  if (!compressed_buf (in, offset))
    return 0;			/* not compressed */

  add_to_buffer (out, in->message, offset);

  s.zalloc = (alloc_func) 0;
  s.zfree = (free_func) 0;
  s.opaque = (voidpf) 0;

  p = gzheader (in->message + offset, in->length);
  if (p == NULL)
    return -1;
  s.next_in = p;
  s.avail_in = in->length - (p - in->message);
  s.next_out = NULL;

  if (inflateInit2 (&s, -MAX_WBITS) != Z_OK)
    return (-1);

  s.next_out = outbuf;
  s.avail_out = sizeof (outbuf);

  while ((err = inflate (&s, Z_PARTIAL_FLUSH)) == Z_OK)
    {
      add_to_buffer (out, outbuf, sizeof (outbuf) - s.avail_out);
      s.next_out = outbuf;
      s.avail_out = sizeof (outbuf);
    }
  add_to_buffer (out, outbuf, sizeof (outbuf) - s.avail_out);
  if ((err=inflateEnd (&s) != Z_OK))
    {
      fprintf (errlog, "Decompression error. %d\n",err);
      return (-1);
    }
  return 1;			/* compressed */
}
Exemplo n.º 17
0
/* The message is returned in a static buffer, so don't call this
   again until you're done with the previous response or it will be overwritten. */
const char* recv_msg(char *buf, int bufsize) {
  int val;
  fd_set read_fdset;
  fd_set except_fdset;
  struct timeval tv;
  char readbuf[bufsize];
  unsigned int totalbytes;

  /* Is there already a reply in the buffer from before? (can happen if
     we get multiple lines in one read) */
  const char *reply_msg = extract_reply(buf);
  if (reply_msg != NULL)
    return reply_msg;

  while (1) {
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    FD_ZERO(&read_fdset);
    FD_ZERO(&except_fdset);
    FD_SET(sock, &read_fdset);
    FD_SET(sock, &except_fdset);
    if (select(sock+1, &read_fdset, NULL, &except_fdset, &tv) == 0) {
      /* we've waited 2 seconds and got no response - too long - conclude
	 the socket is dead */
      printf("timed out waiting response\n");
      //connect_to_robot();
      //initialize_robot();
      return 0;
    }
    if (FD_ISSET(sock, &except_fdset)) {
      connect_to_robot();
      re_initialize_robot();
      return 0;
    }
  
    assert(FD_ISSET(sock, &read_fdset));
    val = read(sock, readbuf, bufsize-1);
    if (val > 0) {
    } else {
      /* the write failed - likely the robot was switched off - attempt
	 to reconnect and reinitialize */
      connect_to_robot();
      re_initialize_robot();
      buf[0]='\0';
      return 0;
    }
    /* ensure readbuf is null terminated */
    readbuf[val] = '\0';
    totalbytes = strlen(buf);
    add_to_buffer(buf, &totalbytes, readbuf);
    reply_msg = extract_reply(buf);
    if (reply_msg != NULL)
      return reply_msg;
  }
}
Exemplo n.º 18
0
EXPORT void CALL
AiLenChanged( void )
{
	// FIXME: We may need near full speed before this is going to work
	if(!audioEnabled) return;

	short* stream = (short*)(AudioInfo.RDRAM +
		         (*AudioInfo.AI_DRAM_ADDR_REG & 0xFFFFFF));
	unsigned int length = *AudioInfo.AI_LEN_REG;

	add_to_buffer(stream, length);
}
Exemplo n.º 19
0
void join_paths(char *path1,char *path2,char *new_path ){

/*	printf("strlen path1:%d\n",strlen(path1));
	printf("strlen path2:%d\n",strlen(path2));
	printf("path1; %s\n",path1);
*/
	add_to_buffer(&message_buffer, "joining paths:",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_to_buffer(&message_buffer, " and ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
	if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
		/*paths are compatiable. concatanate them. note -2 is because of \0*/  
		strcat(new_path,path1);
		strcat(new_path,path2);		
		//char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
		//strcpy(new_path,strcat(path1,path2)); 
		//return new_path;
	}	
	else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
		/*paths are compatiable. concatanate them*/  
		strcat(new_path,path1);
		strcat(new_path,path2);		
		//char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
		//strcpy(new_path,strcat(path1,path2)); 
		//return new_path;
	}
	else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
			/*need to add a "/". */  
		strcat(new_path,path1);
		strcat(new_path,"/");
		strcat(new_path,path2);
		//strcpy(new_path,strcat(path1,strcat("/\0",path2)));

#if 0
		copy_array(path1,new_path,0,0);
		copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
		copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
 old method now trying to use copy_array
		//char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
		for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){ 
			new_path[x]=path1[x];
		}
		new_path[x+1]='/';
		for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){ 
			new_path[x]=path2[i]; 
		}
#endif

		//return new_path;
	}
Exemplo n.º 20
0
lexeme *st_backslash(lexer_info *linfo, buffer *buf)
{
#ifdef LEXER_DEBUG
    print_state("ST_BACKSLASH", linfo->c);
#endif

    switch (linfo->c) {
    case EOF:
        linfo->state = ST_ERROR;
        return NULL;
    case '\n':
        /* Ignore newline symbol */
        print_prompt2();
        break;
/* Non bash-like behaviour. In bash substitution
 * makes in $'string' costruction. */
    case 'a':
        add_to_buffer(buf, '\a');
        break;
    case 'b':
        add_to_buffer(buf, '\b');
        break;
    case 'f':
        add_to_buffer(buf, '\f');
        break;
    case 'n':
        add_to_buffer(buf, '\n');
        break;
    case 'r':
        add_to_buffer(buf, '\r');
        break;
    case 't':
        add_to_buffer(buf, '\t');
        break;
    case 'v':
        add_to_buffer(buf, '\v');
        break;
    default:
        add_to_buffer(buf, linfo->c);
        break;
    }

    deferred_get_char(linfo);
    linfo->state = ST_WORD;

    return NULL;
}
Exemplo n.º 21
0
int irc_tx(int fd, char * packet)
{
	sigpipe=0;
    char pq[512];
	low_quote(packet, pq);
	unsigned long l=min(strlen(pq), 511);
	unsigned long p=0;
	while((p<l)&&!sigpipe)
	{
		signed long j=send(fd, pq+p, l-p, 0);
		if(j<1)
		{
			if(errno==EINTR)
				continue;
			return(p); // Something went wrong with send()!
		}
		p+=j;
	}
	if(sigpipe)
	{
		char tmsg[32+strlen(pq)];
		sprintf(tmsg, "%d, %lu bytes: %s", fd, p, pq);
		add_to_buffer(0, STA, DEBUG, 0, false, tmsg, "DBG SIGPIPE tx: ");
		sigpipe=0;
		return(-1);
	}
	send(fd, "\n", 1, 0);
	char tmsg[32+strlen(pq)];
	sprintf(tmsg, "%d, %lu bytes: %s", fd, l, pq);
	add_to_buffer(0, STA, DEBUG, 0, false, tmsg, "DBG tx: ");
	if(sigpipe)
	{
		sigpipe=0;
		return(-1);
	}
	return(l); // Return the number of bytes sent
}
Exemplo n.º 22
0
lexeme *st_one_two_sym_lex(lexer_info *linfo, buffer *buf)
{
    lexeme *lex = NULL;

#ifdef LEXER_DEBUG
    print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
#endif

    if (buf->count_sym == 0) {
        add_to_buffer(buf, linfo->c);
        deferred_get_char(linfo);
    } else if (buf->count_sym == 1) {
        /* TODO: make it more pretty */
        char prev_c = get_last_from_buffer(buf);
        clear_buffer(buf);
        switch (prev_c) {
        case '>':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_APPEND) :
                make_lex(LEX_OUTPUT);
            break;
        case '|':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_OR) :
                make_lex(LEX_PIPE);
            break;
        case '&':
            lex = (prev_c == linfo->c) ?
                make_lex(LEX_AND) :
                make_lex(LEX_BACKGROUND);
            break;
        default:
            fprintf(stderr, "Lexer: error (type 1) in ST_ONE_TWO_SYM_LEX;");
            print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
            exit(ES_LEXER_INCURABLE_ERROR);
        }
        if (prev_c == linfo->c)
            deferred_get_char(linfo);
        linfo->state = ST_START;
        return lex;
    } else {
        fprintf(stderr, "Lexer: error (type 2) in ST_ONE_TWO_SYM_LEX;");
        print_state("ST_ONE_TWO_SYM_LEX", linfo->c);
        exit(ES_LEXER_INCURABLE_ERROR);
    }

    return lex;
}
Exemplo n.º 23
0
static int run_scan_argument(lua_State * L) /* HH */
{   /* can be simplified, no need for intermediate list */
    saved_tex_scanner texstate;
    halfword t, saved_defref;
    save_tex_scanner(texstate);
    do {
        get_token();
    } while ((cur_cmd == spacer_cmd) || (cur_cmd == relax_cmd));
    if (cur_cmd == left_brace_cmd) {
        back_input();
        saved_defref = def_ref;
        (void) scan_toks(false, true);
        t = def_ref;
        def_ref = saved_defref;
        tokenlist_to_luastring(L,t);
        flush_list(t);
    } else if (cur_cmd == call_cmd) {
        halfword saved_cur_tok = cur_tok;
        cur_tok = right_brace_token + '}';
        back_input();
        cur_tok = saved_cur_tok;
        back_input();
        cur_tok = left_brace_token + '{';
        back_input();
        saved_defref = def_ref;
        (void) scan_toks(false, true);
        t = def_ref;
        def_ref = saved_defref;
        tokenlist_to_luastring(L,t);
        flush_list(t);
    } else if (cur_cmd == 11 || cur_cmd == 12 ) {
        declare_buffer;
        while (1) {
            add_to_buffer(cur_chr);
            get_x_token();
            if (cur_cmd != 11 && cur_cmd != 12 ) {
                break ;
            }
        }
        back_input();
        push_buffer;
    } else {
        back_input();
        lua_pushnil(L);
    }
    unsave_tex_scanner(texstate);
    return 1;
}
Exemplo n.º 24
0
Arquivo: buffer.c Projeto: ec429/quIRC
int initialise_buffers(int buflines)
{
	bufs=malloc(sizeof(buffer));
	if(!bufs)
		return(1);
	init_buffer(0, STATUS, "status", buflines); // buf 0 is always STATUS
	nbufs=1;
	cbuf=0;
	bufs[0].live=true; // STATUS is never dead
	bufs[0].nick=nick;
	nick=NULL;
	bufs[0].ilist=igns;
	add_to_buffer(0, STA, QUIET, 0, false, GPL_TAIL, "quirc -- ");
	init_ring(&d_buf);
	d_buf.loop=true;
	return(0);
}
Exemplo n.º 25
0
int
readbuf (int fd, BUFFER * b)
{
  int len;
  char *p;

  if (readn (fd, (char *) &len, sizeof (len)) != sizeof (len))
    return (0);
  len = ntohs (len);
  if (len > 32 * 1024)
    return (0);
  p = malloc (len);
  if (readn (fd, p, len) != len)
    return (0);
  add_to_buffer (b, p, len);
  free (p);
  return (1);
}
Exemplo n.º 26
0
static 
PT_THREAD(producer(struct pt *pt))
{
  static int produced;
  
  PT_BEGIN(pt);
  
  for(produced = 0; produced < NUM_ITEMS; ++produced) {
  
    PT_SEM_WAIT(pt, &full);
    
    add_to_buffer(produce_item());
    
    PT_SEM_SIGNAL(pt, &empty);
  }

  PT_END(pt);
}
Exemplo n.º 27
0
int main(void)
{
	setlocale(LC_ALL, "Russian");
	char buffer[MAX_STR_LENGTH];
	init_buffer();
	FILE* file;
	fopen_s(&file, "prog.pas", "r");
	while (!feof(file))
	{
		fgets(buffer, MAX_STR_LENGTH, file);
		add_to_buffer(buffer);
	}
	fclose(file);

	process_program();
	getchar();
	return 0;
}
Exemplo n.º 28
0
lexeme *st_word(lexer_info *linfo, buffer *buf)
{
    lexeme *lex = NULL;

#ifdef LEXER_DEBUG
    print_state("ST_WORD", linfo->c);
#endif

    switch (linfo->c) {
    case EOF:
    case '\n':
    case ' ':
    case '\t':
    case '<':
    case ';':
    case '(':
    case ')':
    case '>':
    case '|':
    case '&':
    case '`':
        linfo->state = ST_START;
        lex = make_lex(LEX_WORD);
        lex->str = convert_to_string(buf, 1);
        return lex;
    case '\\':
        deferred_get_char(linfo);
        linfo->state = ST_BACKSLASH;
        break;
    case '\"':
        deferred_get_char(linfo);
        linfo->state = ST_IN_QUOTES;
        break;
    default:
        add_to_buffer(buf, linfo->c);
        deferred_get_char(linfo);
    }

    return lex;
}
Exemplo n.º 29
0
/**
 *  Free stack buffer.
 *
 *	\param b					pointer to buffer
 *
 */
#ifdef CHECK_BUFFERS
void stack_buffer_free ( buffer_t *b, uint8_t which_from  )
#else /* !CHECK_BUFFERS */
void stack_buffer_free ( buffer_t *b)
// which from : which code part sends the command
#endif /* CHECK_BUFFERS */
{

	if (b !=0 )
	{
		debug("fre\r\n");
#ifdef CHECK_BUFFERS
		if (add_to_buffer(b, avail_buffers, "avail_buf") == pdFALSE) {
			debug_printf("from: %d\r\n", which_from);
		}
#endif /* CHECK_BUFFERS */
		if ((b != last_buffer_pushed) || (b->options.last_buffer_when_pulled == 1) /*means b is the last buffer available all other are in the stack*/)
		{
			b->from = MODULE_NONE;
			b->to = MODULE_NONE;
			memset(b, 0, sizeof(buffer_t));
			if(safe_xQueueSend( buffers, ( void * ) &b, ( portTickType ) 5 ) != pdTRUE)
			{
				stack_mac_check_buffers = pdTRUE;
#ifdef CHECK_BUFFERS
				debug_printf("S: Buf queue error from: %d\r\n", which_from);
#else /* !CHECK_BUFFERS */
				debug("S: Buf queue error\r\n");
#endif /* CHECK_BUFFERS */
	
			}
			else
			{
				buffer_left++;
				last_buffer_pushed = b;
				b = 0;

			}
		}
	}
}
Exemplo n.º 30
0
void static write(int fd, byte data)
{
	char spc_chr = special_char_behaviour(data);
	
	if (spc_chr && spc_chr != '\b')
		return;
	
	if (fd == WRITE)
	{
		if (!spc_chr) 
		{
			if (current_shell->lbuf_offset < MAX_LINE - 1) 
			{
				add_to_buffer(data);
			}	else {
					return;
			}
		} else {
			if (current_shell->lbuf_offset)
			{
				current_shell->
					line_buffer[--current_shell->lbuf_offset] = 0;
			}
			return;
		}
	}
	
	if (current_shell->cursor >= 4000) 
	{
		jump_line();
		current_shell->cursor -= 160;
	}
		
	out_video(current_shell->cursor, data);
		
	current_shell->cursor+=2;
}