Exemplo n.º 1
0
void fmt(char *line_full, ssize_t line_remaining_len, int width) {
  char *line = line_full;
  ssize_t line_len;
  int i;
  bool split_on_space = false;

  while (line_remaining_len > width) {
    line_len = width;
    for (i = 1; i < line_len; i++) {
      if (line[line_len - i] == ' ') {
        line_len = line_len - i;
        split_on_space = true;
        break;
      }
    }
    write_line(line, line_len);
    if (split_on_space) {
      line_remaining_len--;
      line++;
    }
    line_remaining_len -= line_len;
    line += line_len;
  }
  if (line_remaining_len > 0) {
    write_line(line, line_remaining_len);
  }
}
int main()
{
    write_line("Calling test function");
    TestFunc();
    write_line("After test function");
    return 0;
}
Exemplo n.º 3
0
/**
 * im_write_imask_name:
 * @in: mask to write
 * @filename: filename to write to
 *
 * Write an imask to a file. See im_read_dmask() for a description of the mask
 * file format.
 *
 * See also: im_write_imask().
 *
 * Returns: 0 on success, or -1 on error.
 */
int 
im_write_imask_name( INTMASK *in, const char *filename )
{
	FILE *fp;
	int x, y, i;

	if( im_check_imask( "im_write_imask_name", in ) ||
		!(fp = im__file_open_write( filename, TRUE )) )
		return( -1 );

	if( write_line( fp, "%d %d", in->xsize, in->ysize ) ) {
		fclose( fp ); 
		return( -1 );
	}
	if( in->scale != 1 || in->offset != 0 ) 
		write_line( fp, " %d %d", in->scale, in->offset );
	write_line( fp, "\n" );

	for( i = 0, y = 0; y < in->ysize; y++ ) {
		for( x = 0; x < in->xsize; x++, i++ ) 
			write_line( fp, "%d ", in->coeff[i] );

		if( write_line( fp, "\n" ) ) {
			fclose( fp ); 
			return( -1 );
		}
	}
	fclose( fp );

	return( 0 );
}
Exemplo n.º 4
0
static int		end_line(char **rest, char **line, int const fd, char *buf)
{
	int		ret_read;
	char	*end;
	char	*tmp;

	while (1)
	{
		if (ft_strchr(*rest, '\n') != NULL)
		{
			tmp = ft_strdup(*rest);
			end = ft_strchr(tmp, '\n');
			end = end + 1;
			write_line(rest, end, line);
			ft_memdel((void**)&tmp);
			return (1);
		}
		ft_bzero(buf, BUFF_SIZE);
		if ((ret_read = read(fd, buf, BUFF_SIZE)) == 0)
		{
			if (ft_strlen(*rest) > 0)
				write_line(rest, NULL, line);
			return (0);
		}
		join_rest(rest, buf);
	}
}
void TestFunc()
{
    write_line("Before first notification");
    __annotation_mark(loc1);
    write_line("Before second notification");
    __annotation_mark(loc2);
    write_line("After second notification");
}
Exemplo n.º 6
0
void write_store(item_t *dst_item, item_t *src_item)
{
  if (!dst_item || !src_item) return;
  // Se o item de origem já estiver em um registrador, a função “write_load” não mudará nada
  write_load(src_item);
  if (dst_item->addressing == addressing_indirect)
    write_line("STORE [R%d], R%d", dst_item->index, src_item->index);
  else
    write_line("STORE [%.4X], R%d", dst_item->address, src_item->index);
  dst_item->addressing = addressing_register;
  dst_item->index = src_item->index;
  // TODO: Se for reaproveitar o destino para as próximas contas, é necessário reduzir o índice de registradores?
  dec_index(1);
}
Exemplo n.º 7
0
void print_shell_use() {
    write_line("Comandos disponibles:");
    write_line("help                muestra esta ayuda");
    write_line("ls                  muestra la lista de programas disponibles");
    write_line("ps                  muestra datos sobre los procesos del sistema");
    write_line("run <programa>      ejecuta un programa en foreground");
    write_line("bg <programa>       ejecuta un programa en background");
    write_line("nice <pid> <valor>  cambia la prioridad de un proceso");
    write_line("kill <pid>          mata un proceso");
    write_line("echo <palabra>      imprime una palabra");
}
Exemplo n.º 8
0
void write_branch_link(item_t *item, bool forward)
{
  if (forward) {
    fpos_t position;
    fgetpos(output_file, &position);
    add_link(create_link(position), &item->links);
    write_line(BACKEND_FORWARD_LABEL);
  }
  else {
    if (item->label)
      write_line(item->label);
    else
      write_line("GOD_KNOWS_WHERE!");
  }
}
Exemplo n.º 9
0
void write_index_offset(item_t *item, item_t *index_item)
{
  if (!item || !index_item) return;
  // TODO: Adicionar rotina “trap” para índices fora do limite
  write_load(index_item);
  write_line("MUL R%d, %d", index_item->index, item->type->base->size);
  if (item->addressing == addressing_direct) {
    write_line("ADD R%d, %d", index_item->index, item->address);
    item->index = index_item->index;
    item->addressing = addressing_indirect;
  }
  else if (item->addressing == addressing_indirect) {
    write_line("ADD R%d, R%d", item->index, index_item->index);
    dec_index(1);
  }
}
Exemplo n.º 10
0
// writes changes to a writable book to the bok file.		
void cBooks::readbook_writeable(UOXSOCKET s, P_ITEM pBook, int p, int l)
{
	int ii=0,lines_processed=0,lin=0;
	char line[34],ch;
	unsigned long loopexit=0;
	
	if (a_t) write_title(pBook,s); // if title was changed by writer write the changes "down"
	if (a_t) write_author(pBook,s); // if author was changed by writer write the changes "down" to the bok-file
	
	while (lines_processed<l && (++loopexit < MAXLOOPS) )
	{
		if (ii>511) lines_processed=l; // avoid crash if client sends out inconsitent data
		ch=pagebuffer[s][ii];
		if (lin<33) line[lin]=ch; else line[33]=ch;
		ii++;
		lin++;
		if (ch==0) 
		{
			lines_processed++;
			lin=0;
			
			write_line(pBook, p, lines_processed, line,s);
		}
	}
	
	a_t=0; // dont re-write author and title if not necassairy
}
Exemplo n.º 11
0
bool
VMGahpServer::command_async_mode_on(void)
{
    static const char* command = "ASYNC_MODE_ON";

    if( m_is_initialized == false ) {
        return false;
    }

    if( isSupportedCommand(command) == FALSE ) {
        return false;
    }

    if(write_line(command) == false) {
        return false;
    }

    // give some time to gahp server
    sleep(1);

    Gahp_Args result;
    if( read_argv(result) == false ) {
        return false;
    }

    if( result.argc == 0 || result.argv[0][0] != 'S' ) {
        dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command);
        return false;
    }

    return true;
}
Exemplo n.º 12
0
int main(int argc, char ** argv) 
{   
               
        // initialize and watch the entire directory tree from the current working
        // directory downwards for all events
        if ( !inotifytools_initialize() || !inotifytools_watch_recursively( "/proc/acpi/ac_adapter/AC/", IN_ALL_EVENTS ) )
        {
                fprintf(stderr, "%s\n", strerror( inotifytools_error() ) );
                return -1;
        }
        // set time format to 24 hour time, HH:MM:SS
        inotifytools_set_printf_timefmt( "%T" );
        // Output all events as "<timestamp> <path> <events>"
        struct inotify_event * event = inotifytools_next_event( -1 );
        if ( event ) 
        {
                inotifytools_printf( event, "%T %w%f %e\n" );
                event = inotifytools_next_event( -1 );
        }        
        // Configure userspace as the scaling governor in ACPI 
        write_line(ACPI_GOVERNOR_FILE, "userspace");       
        
        
        // Start past/mdp/avgn/maxperf/maxlife 
       
        // Start phoronix-test-suite benchmark mdp 
    
        start_pts(argv[2]);
        start_dvs_program(argv[1]); 
}
Exemplo n.º 13
0
static struct COOR *end_line(struct COOR *ptr, int node)
{
    ptr->row = row;
    ptr->col = col - 1;
    ptr->node = node;

    switch (data_type) {
    case CELL_TYPE:
	ptr->val = ((CELL *) middle)[col];
	break;
    case FCELL_TYPE:
	ptr->dval = ((FCELL *) middle)[col];
	break;
    case DCELL_TYPE:
	ptr->dval = ((DCELL *) middle)[col];
	break;
    default:
	break;
    }

    G_debug(3, "end_line: node: %d; p: row:%d, col:%d",
	    node, ptr->row, ptr->col);

    ptr->fptr = ptr;
    write_line(ptr);

    return (NULL);
}
void
istream_line_splitter::
dump(std::ostream& os) const {
    os << "\tline_no: " << _line_no << "\n";
    os << "\tline: ";
    write_line(os);
}
Exemplo n.º 15
0
void			THIS::eval(std::string const & s)
{
	auto parent = getParent();

	bp::object o;
	try {
		o = bp::eval(s.c_str(), main_namespace_);

		if(!o.is_none()) {
			main_namespace_["temp_obj"] = o;
			bp::exec("print temp_obj", main_namespace_);
		}
	} catch(bp::error_already_set const &) {

		PyErr_Clear();

		//PyErr_Print();

		try {
			o = bp::exec(s.c_str(), main_namespace_, bp::object());
		} catch(bp::error_already_set const &) {
			PyErr_Print();
		}
		
		PyErr_Print();
	}

	auto output = PythonStdIoRedirect::GetOutputContainer();

	for(auto it = output.begin(); it != output.end(); ++it)
		parent->write_line(*it);//.insert(lines_.end(), output.begin(), output.end());

}
Exemplo n.º 16
0
int
write_objects(FILE *fp)
{
    F_arc	   *a;
    F_compound	   *c;
    F_ellipse	   *e;
    F_line	   *l;
    F_spline	   *s;
    F_text	   *t;

    /*
     * A 2 for the orientation means that the origin (0,0) is at the upper 
     * left corner of the screen (2nd quadrant).
     */

    if (!update_figs)
	put_msg("Writing . . .");
#ifdef I18N
    /* set the numeric locale to C so we get decimal points for numbers */
    setlocale(LC_NUMERIC, "C");
#endif  /* I18N */
    write_fig_header(fp);
    for (a = objects.arcs; a != NULL; a = a->next) {
	num_object++;
	write_arc(fp, a);
    }
    for (c = objects.compounds; c != NULL; c = c->next) {
	num_object++;
	write_compound(fp, c);
    }
    for (e = objects.ellipses; e != NULL; e = e->next) {
	num_object++;
	write_ellipse(fp, e);
    }
    for (l = objects.lines; l != NULL; l = l->next) {
	num_object++;
	write_line(fp, l);
    }
    for (s = objects.splines; s != NULL; s = s->next) {
	num_object++;
	write_spline(fp, s);
    }
    for (t = objects.texts; t != NULL; t = t->next) {
	num_object++;
	write_text(fp, t);
    }
#ifdef I18N
    /* reset to original locale */
    setlocale(LC_NUMERIC, "");
#endif  /* I18N */
    if (ferror(fp)) {
	fclose(fp);
	return (-1);
    }
    if (fclose(fp) == EOF)
	return (-1);


    return (0);
}
Exemplo n.º 17
0
bool
VMGahpServer::command_quit(void)
{
    static const char* command = "QUIT";

    if( m_is_initialized == false ) {
        return false;
    }

    if(write_line(command) == false) {
        return false;
    }

    // give some time to gahp server
    sleep(1);

    Gahp_Args result;
    if( read_argv(result) == false ) {
        return false;
    }

    if( result.argc == 0 || result.argv[0][0] != 'S' ) {
        dprintf(D_ALWAYS,"VMGAHP command '%s' failed\n",command);
        return false;
    }

    return true;
}
Exemplo n.º 18
0
void debug_print_line(byte* line, int size, byte color) {
	// Максимальная длина строки 29 символов
	const byte left = 50;
	const byte right = 79;
	const byte up = 0;
	const byte down = 24;
	const byte writex = 50;
	const byte writey = 24;
	Mouse_Hide();
	asm {
		pusha
	// Прокрутка на одну строку вверх перед печатью очередной
		mov ah, 6
		mov al, 1
		mov bx, 0000h
		mov ch, up
		mov cl, left
		mov dh, down
		mov dl, right
		int 10h
		popa
	}
	write_line(line, size, writex, writey, color);
	Mouse_Show();
}
Exemplo n.º 19
0
/* create a ppm image from the decoded raster data */
static void write_ppm(image_t* img,FILE* fp){
	int i;
	/* allocate buffers for dot statistics */
        for(i=0;i<MAX_COLORS;i++){
	  /*img->color[i].dots=calloc(1,sizeof(int)*(img->color[i].level+1));*/
	  img->color[i].dots=calloc(1,sizeof(int)*(1<<((img->color[i].bpp)+1)));
	}	
	/* allocate buffers for levels used*/
        for(i=0;i<MAX_COLORS;i++){
	  img->color[i].usedlevels=calloc(1,sizeof(int)*(1<<((img->color[i].bpp)+1)));
	}	

	/* write header */
	fputs("P6\n", fp);
	fprintf(fp, "%d\n%d\n255\n", img->width, img->height);

	/* set top most left value */
	img->image_left = img->width;

	/* write data line by line */
	for(i=0;i<img->height;i++){
		write_line(img,fp,i);
	}
	
	/* output some statistics */
	printf("statistics:\n");
	for(i=0;i<MAX_COLORS;i++){
	  int level;
	  if (img->color[i].bpp > 0) {
	    /*for(level=0;level < img->color[i].level;level++)*/
	    for(level=0;level < 1<<(img->color[i].bpp);level++)
	      printf("color %c level %i dots %i\n",img->color[i].name,level,img->color[i].dots[level]);
	  }
	}
	printf("Level values actually used:\n");
	for(i=0;i<MAX_COLORS;i++){
	  int level;
	  if (img->color[i].bpp > 0) {
	    printf("color %c bpp %i available levels %i declared levels %i --- actual level values used:\n",img->color[i].name,img->color[i].bpp,1<<(img->color[i].bpp),img->color[i].level);
	    for(level=0;level < 1<<(img->color[i].bpp);level++)
	      printf("%i",img->color[i].usedlevels[level]);
	    printf("\n");
	  }
	}
	/* translate area coordinates to 1/72 in (the gutenprint unit)*/
	img->image_top = img->image_top * 72.0 / img->yres ;
	img->image_bottom = img->image_bottom * 72.0 / img->yres ;
	img->image_left = img->image_left * 72.0 / img->xres ;
	img->image_right = img->image_right * 72.0 / img->xres ;
	printf("top %u bottom %u left %u right %u\n",img->image_top,img->image_bottom,img->image_left,img->image_right);
	printf("width %u height %u\n",img->image_right - img->image_left,img->image_bottom - img->image_top);	

	/* clean up */
        for(i=0;i<MAX_COLORS;i++){
		if(img->color[i].dots)
			free(img->color[i].dots);
	}	

}
Exemplo n.º 20
0
static void print_ls(char *mode) {
    if (strlen(mode) == 0) {
        int n = ls(0, result_buf, RESULT_BUF_LEN);
        result_buf[n] = '\0';

        write_line(result_buf);
    }
}
Exemplo n.º 21
0
void con_allexit( )
{
    char buf[MAXLINE];

    allexiting = 1;
    sprintf( buf, "src=%s bcast=true cmd=allexit\n", myid );
    write_line( rhs_idx, buf );
}
Exemplo n.º 22
0
void con_shutdown( )
{
    char buf[MAXLINE], mpd_id[IDSIZE];

    mpd_getval( "mpd_id", mpd_id );
    sprintf( buf, "src=%s dest=%s cmd=shutdown\n", myid, mpd_id );
    write_line( rhs_idx, buf );
}
Exemplo n.º 23
0
void write_load(item_t *item)
{
  if (!item) return;
  if (item->addressing == addressing_immediate)
    write_line("LOAD R%d, %d", register_index, item->value);
  else if (item->addressing == addressing_direct)
    write_line("LOAD R%d, [%.4X]", register_index, item->address);
  else if (item->addressing == addressing_indirect) {
    write_line("LOAD R%d, [R%d]", item->index, item->index);
    item->addressing = addressing_register;
    return;
  }
  else
    return; // TODO: Devo verificar e apontar erro ou deixar como está?
  item->addressing = addressing_register;
  item->index = register_index;
  inc_index(1);
}
Exemplo n.º 24
0
	bool begin_run(void)
	{
		write_line();

		// 异步从服务器读取数据
		//client_->read();
		client_->gets(10, false);

		return true;
	}
int main(int argc, char *argv[])
{
        srand(time(NULL));
        
        int fp = open("/dev/mypipe", O_WRONLY);//open the character device to put the strings produced 
                write_line(fp);
		
        close(fp);
	return 0;
}
Exemplo n.º 26
0
void con_exit( )
{
    char buf[MAXLINE], mpd_id[IDSIZE];

    mpd_getval( "mpd_id", mpd_id );
    if ( strcmp( mpd_id, "self" ) == 0 )
	strncpy( mpd_id, myid, IDSIZE );
    sprintf( buf, "src=%s dest=%s cmd=exit\n", myid, mpd_id );
    write_line( rhs_idx, buf );
}
Exemplo n.º 27
0
void con_killjob( )
{
    char buf[MAXLINE];
    int  jobid;

    jobid = atoi( mpd_getval( "jobid", buf) );
    sprintf( buf, "src=%s bcast=true cmd=killjob jobid=%d\n", myid, jobid );
    write_line( rhs_idx, buf );
    mpdprintf( debug, "con_killjob: sending killjob jobid=%d\n", jobid );
}
Exemplo n.º 28
0
static void matrix_int(void) {
    ++index;

    if(index >= 3) {
        ++cycle;
        index = 0;
    }

    move_line(index);
    write_line(pixels + (index * 3), cycle & 3);
}
Exemplo n.º 29
0
static void send_cmd(const char *format, ...)
{
	char buf[512];
	va_list ap;

	va_start(ap, format);
	vsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);

	write_line(buf);
}
Exemplo n.º 30
0
void matrix_show(void) {
    for(uint8_t n = 0; n < 4; ++n) {
        uint8_t i;

        for(i = 0; i < 3; ++i) {
            move_line(i);
            write_line(pixels + (i * 3), n);
            wait_ms(1);
        }
    }
}