예제 #1
0
/* @brief Draw a line of text to a cairo context.
 *
 * @param cr A cairo context for drawing to the screen.
 * @param text The text to be drawn.
 * @param line The index of the line to be drawn (counting from the top).
 * @param foreground The color of the text.
 * @param background The color of the background.
 * @return Void.
 */
static void draw_line(cairo_t *cr, const char *text, uint32_t line, color_t *foreground, color_t *background) {
  pthread_mutex_lock(&global.draw_mutex);

  cairo_set_source_rgb(cr, background->r, background->g, background->b);
  /* Add 2 to fix a weird offsetting bug. TODO: Fix the bug properly. */
  cairo_rectangle(cr, 0, line * settings.height + 2, settings.width, settings.height);
  cairo_stroke_preserve(cr);
  cairo_fill(cr);
  offset_t offset = calculate_line_offset(line);

  /* Parse the response line as we draw it. */
  char *c = (char *)text;
  while (c && *c != '\0') {
    draw_t d = parse_response_line(&c);
    char saved = *c;
    *c = '\0';
    switch (d.type) {
      case DRAW_IMAGE:
        offset.x += draw_image(cr, d.data, offset) + settings.height / 10;
        break;
      case DRAW_TEXT:
      default:
        offset.x += draw_text(cr, d.data, offset, foreground);
        break;
    }
    *c = saved;
  }

  pthread_mutex_unlock(&global.draw_mutex);
}
예제 #2
0
파일: nntp-latest.c 프로젝트: ivartj/nntp
int processline(io *s)
{
	int code;
	int m;
	ssize_t sz;
	char line[512], msgid[512];

	sz = parse_response_line(s, &code, line);
	if(sz == -1)
		msg_fail("parse_response_line: %s", msg_get());
	switch(code) {
	case 223:
		break;
	case 422:
		exit(EXIT_SUCCESS);
	default:
		msg_fail("Received unexpected response code %d", code);
	}

	m = sscanf(line, "%*d %*d %s", msgid);
	if(m == 0)
		msg_fail("Failed to parse message-id from response");
	printf("%s\n", msgid);

	return 0;
}
예제 #3
0
파일: nntp-latest.c 프로젝트: ivartj/nntp
void greeting(io *s)
{
	size_t sz;
	int code;

	sz = parse_response_line(s, &code, NULL);
	if(sz == -1)
		msg_fail("parse_response_line: %s", msg_get());

	switch(code) {
	case 200:
	case 201:
		break;
	default:
		msg_fail("Received unexpected response code %d", code);
	}
}
예제 #4
0
파일: nntp-latest.c 프로젝트: ivartj/nntp
void getlatest(io *s)
{
	ssize_t sz;
	int code;
	int high;
	int i;
	char line[512], msgid[512];
	int m;
	int n;

	io_printf(s, "GROUP %s\r\n", group);

	sz = parse_response_line(s, &code, line);
	if(sz == -1)
		msg_fail("parse_response_line: %s", msg_get());

	switch(code) {
	case 211:
		break;
	case 411:
		msg_fail("No such newsgroup");
	default:
		msg_fail("Received unexpected response code %d", code);
	}

	m = sscanf(line, "%*d %*d %*d %d", &high);
	if(m == 0)
		msg_fail("Failed to parse latest article number from response line");

	io_printf(s, "STAT %d\r\n", high);
	processline(s);
	for(i = 1; i < max; i++)
		io_printf(s, "LAST\r\n");
	for(i = 1; i < max; i++)
		processline(s);
}