Esempio n. 1
0
int ftdi_context_release(ftdi_context_t* context) {
  int i;

  error_clear(&context->error);
  
  if (context == ftdi_default_context) {
    if (context->num_references)
      context->num_references--;
    else {
      error_set(&context->error, FTDI_ERROR_CONTEXT_RELEASE);
      return error_get(&context->error);
    }
  }
  else
    context->num_references = 0;

  if (!context->num_references && context->num_devices) {
    for (i = 0; i < context->num_devices; ++i)
      ftdi_device_destroy(&context->devices[i]);
    
    free(context->devices);
    context->devices = 0;
    context->num_devices = 0;
  }
  
  return error_get(&context->error);
}
Esempio n. 2
0
/* battery_on_timeout */
static gboolean _battery_on_timeout(gpointer data)
{
	const gdouble error = 0.0 / 0.0;
	Battery * battery = data;
	PanelAppletHelper * helper = battery->helper;
	gdouble level;
	gboolean charging;
	int timeout;

	if(_battery_get(battery, &level, &charging) == FALSE)
	{
		helper->error(NULL, error_get(NULL), 1);
		timeout = 0;
	}
	else if(level == error || level < 0.0)
	{
		helper->error(NULL, error_get(NULL), 1);
		timeout = 30000;
	}
	else
		timeout = 5000;
	_battery_set(battery, level, charging);
	battery->timeout = (timeout > 0)
		? g_timeout_add(timeout, _battery_on_timeout, battery) : 0;
	return FALSE;
}
Esempio n. 3
0
int ftdi_device_read(ftdi_device_t* dev, unsigned char* data, size_t num) {
  ssize_t result = 0, num_read = 0;
  double time, period = 0.0;

  error_clear(&dev->error);
  
  timer_start(&time);
  while ((num_read < num) &&
    ((period = timer_stop(time)) <= dev->timeout) &&
    ((result = ftdi_read_data(dev->libftdi_context, &data[num_read],
      num-num_read)) >= 0)) {
    if (result)
      timer_start(&time);
    num_read += result;
  }
  dev->num_read += num_read;
    
  if (result < 0) {
    error_setf(&dev->error, FTDI_ERROR_READ, "%03:%03", dev->bus,
      dev->address);
    return -error_get(&dev->error);
  }
  else if (!num_read && (period > dev->timeout)) {
    error_setf(&dev->error, FTDI_ERROR_TIMEOUT, "%03:%03", dev->bus,
      dev->address);
    return -error_get(&dev->error);
  }

  return num_read;
}
Esempio n. 4
0
static void draw_text_error(void)
{
	int x = 0;
	int y = 0;
	int dx = text_size_x();
	int dy = text_size_y();
	
	text_clear();

	draw_text_center(x, y, dx,
"ERROR! An error occurred in your last action!"
	, COLOR_REVERSE);
	++y;

	++y;
	y = draw_text_para(x, y, dx, dy,
"Your action has generated an error. Probably you have requested an "
"unsupported feature by your hardware or software."
	, COLOR_NORMAL);

	if (*error_get()) {
		y = draw_text_para(x, y, dx, dy-y, "\nThe video software reports this error:", COLOR_NORMAL);
		log_std(("v: error \"%s\"\n", error_get()));
		y = draw_text_para(x, y, dx, dy-y, error_get(), COLOR_ERROR);
	}

	y = draw_text_para(x, y, dx, dy-y, "\nPress ESC", COLOR_NORMAL);

	video_wait_vsync();

	do {
		target_idle();
		os_poll();
	} while (inputb_get()==INPUTB_NONE);
}
Esempio n. 5
0
static int _settings_browse(Settings * settings)
{
	int ret = 0;
	Config * config;
	GtkTreeModel * model;
	char const * path;
	char * p;
	size_t i;
	size_t j;
	int datadir = 1;

	if((config = config_new()) == NULL)
		return -_settings_error(error_get(NULL), 1);
	model = _settings_get_model(settings);
	gtk_list_store_clear(GTK_LIST_STORE(model));
	/* read through every XDG application folder */
	if((path = getenv("XDG_DATA_DIRS")) == NULL || strlen(path) == 0)
	{
		path = "/usr/local/share:/usr/share";
		datadir = 0;
	}
	if((p = strdup(path)) == NULL)
		_settings_error(error_get(NULL), 1);
	else
		for(i = 0, j = 0;; i++)
			if(p[i] == '\0')
			{
				string_rtrim(&p[j], "/");
				_settings_browse_folder(settings, config,
						&p[j]);
				datadir |= (strcmp(&p[j], DATADIR) == 0);
				break;
			}
			else if(p[i] == ':')
			{
				p[i] = '\0';
				string_rtrim(&p[j], "/");
				_settings_browse_folder(settings, config,
						&p[j]);
				datadir |= (strcmp(&p[j], DATADIR) == 0);
				j = i + 1;
			}
	free(p);
	if(datadir == 0)
		ret = _settings_browse_folder(settings, config, DATADIR);
	ret |= _settings_browse_home(settings, config);
	config_delete(config);
	return ret;
}
Esempio n. 6
0
/* parser_string */
int parser_string(AsmPrefs * ap, AsmCode * code, char const * string)
{
	CppPrefs prefs;
	State state;
	size_t i;

	memset(&prefs, 0, sizeof(prefs));
#if 0
	prefs.filename = infile;
#endif
	prefs.filters = CPP_FILTER_COMMENT;
	memset(&state, 0, sizeof(state));
	state.code = code;
	if((state.cpp = cpp_new(&prefs)) == NULL)
		return -1;
	if(ap != NULL)
		for(i = 0; i < ap->defines_cnt; i++)
			/* FIXME check errors */
			cpp_define_add(state.cpp, ap->defines[i], NULL);
	if(_parser_scan(&state) != 0)
		return _parser_error(&state, "%s", error_get());
	if(_program(&state) != 0)
		error_set_code(1, "%s%u%s%u%s", "Compilation failed with ",
				state.error_cnt, " error(s) and ",
				state.warning_cnt, " warning(s)");
	if(state.token != NULL)
		token_delete(state.token);
	return state.error_cnt;
}
Esempio n. 7
0
/* notes_note_add */
Note * notes_note_add(Notes * notes, Note * note)
{
	GtkTreeIter iter;
	char * filename;

	if(note == NULL)
	{
		if((note = note_new()) == NULL)
			return NULL;
		if((filename = _notes_note_get_new_filename()) == NULL)
		{
			notes_error(notes, error_get(NULL), 0);
			note_delete(note);
			return NULL;
		}
		note_set_filename(note, filename);
		free(filename);
		note_set_title(note, _("New note"));
		note_save(note);
	}
	gtk_list_store_insert(notes->store, &iter, 0);
	gtk_list_store_set(notes->store, &iter, ND_COL_NOTE, note,
			ND_COL_TITLE, note_get_title(note), -1);
	return note;
}
Esempio n. 8
0
static void _idle_load(Panel * panel, PanelPosition position)
{
	char const * plugins;
	char * p;
	char * q;
	size_t i;

	if((plugins = _panel_get_plugins(panel, position)) == NULL
			|| strlen(plugins) == 0)
		return;
	if((p = string_new(plugins)) == NULL)
	{
		panel_error(panel, error_get(), FALSE);
		return;
	}
	for(q = p, i = 0;;)
	{
		if(q[i] == '\0')
		{
			if(panel_load(panel, position, q) != 0)
				error_print(PACKAGE); /* we can ignore errors */
			break;
		}
		if(q[i++] != ',')
			continue;
		q[i - 1] = '\0';
		if(panel_load(panel, position, q) != 0)
			error_print(PACKAGE); /* we can ignore errors */
		q += i;
		i = 0;
	}
	free(p);
}
Esempio n. 9
0
/* clock_on_timeout */
static gboolean _clock_on_timeout(gpointer data)
{
	Clock * clock = data;
	PanelAppletHelper * helper = clock->helper;
	struct timeval tv;
	time_t t;
	struct tm tm;
	char buf[32];

	if(gettimeofday(&tv, NULL) != 0)
	{
		error_set("%s: %s: %s", applet.name, "gettimeofday",
				strerror(errno));
		helper->error(NULL, error_get(NULL), 1);
		return TRUE;
	}
	t = tv.tv_sec;
	localtime_r(&t, &tm);
	strftime(buf, sizeof(buf), clock->format, &tm);
	gtk_label_set_text(GTK_LABEL(clock->label), buf);
#ifndef EMBEDDED
	if(clock->iconsize != GTK_ICON_SIZE_LARGE_TOOLBAR)
	{
		strftime(buf, sizeof(buf), _("%H:%M:%S\n%d/%m/%Y"), &tm);
		gtk_widget_set_tooltip_text(clock->label, buf);
	}
#endif
	return TRUE;
}
Esempio n. 10
0
/* instruction */
static int _instruction(State * state)
	/* instruction_name [ space [ operand_list ] ] */
{
	int ret;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	/* reset the current instruction */
	memset(&state->call, 0, sizeof(state->call));
	/* instruction_name */
	ret = _instruction_name(state);
	if(!_parser_in_set(state, TS_SPACE))
		return ret;
	/* [ space ] */
	ret |= _space(state);
	/* [ operand_list ] */
	if(_parser_in_set(state, TS_OPERAND_LIST))
		ret |= _operand_list(state);
	/* call the current instruction */
	if(state->call.name != NULL)
	{
		if(asmcode_instruction(state->code, &state->call) != 0)
			ret |= _parser_error(state, "%s", error_get());
		free(state->call.name);
	}
	/* FIXME memory leak (register names...) */
	memset(&state->call, 0, sizeof(state->call));
	return ret;
}
Esempio n. 11
0
/* section_name */
static int _section_name(State * state)
	/* WORD */
{
	int ret = 0;
	char const * string = NULL;
	size_t len;
	char * section = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	if(state->token == NULL
			|| (string = token_get_string(state->token)) == NULL
			|| (len = strlen(token_get_string(state->token))) == 0)
		return error_set_code(1, "%s",
				"Sections with empty names are not allowed");
	if((section = malloc(len + 2)) == NULL)
		return ret | error_set_code(1, "%s", strerror(errno));
	snprintf(section, len + 2, ".%s", string);
	ret |= _parser_scan(state);
#ifdef DEBUG
	fprintf(stderr, "%s\"%s\"\n", "DEBUG: section ", section);
#endif
	if(asmcode_section(state->code, section) != 0)
		ret |= _parser_error(state, "%s", error_get());
	free(section);
	return ret;
}
Esempio n. 12
0
/* parser */
int parser(AsmPrefs * ap, AsmCode * code, char const * infile)
{
	CppPrefs prefs;
	State state;

	memset(&prefs, 0, sizeof(prefs));
	prefs.filename = infile;
	prefs.filters = CPP_FILTER_COMMENT;
	memset(&state, 0, sizeof(state));
	state.code = code;
	if((state.cpp = cpp_new(&prefs)) == NULL)
		return -1;
	if(_parser_defines(&state, ap) != 0)
	{
		cpp_delete(state.cpp);
		return -1;
	}
	if(_parser_scan(&state) != 0)
	{
		cpp_delete(state.cpp);
		return _parser_error(&state, "%s", error_get());
	}
	if(_program(&state) != 0)
		error_set_code(1, "%s%s%u%s%u%s", infile,
				": Compilation failed with ", state.error_cnt,
				" error(s) and ", state.warning_cnt,
				" warning(s)");
	if(state.token != NULL)
		token_delete(state.token);
	return state.error_cnt;
}
Esempio n. 13
0
/* panel_error */
int panel_error(Panel * panel, char const * message, int ret)
{
	(void) panel;

	fprintf(stderr, "%s: %s\n", PROGNAME, (message != NULL) ? message
			: error_get(NULL));
	return ret;
}
Esempio n. 14
0
/* notes_note_reload_all */
int notes_note_reload_all(Notes * notes)
{
	int ret = 0;
	char * filename;
	DIR * dir;
	struct dirent * de;
	Note * note;

	if((filename = _notes_note_get_directory()) == NULL)
		return notes_error(notes, error_get(NULL), 1);
	if((dir = opendir(filename)) == NULL)
	{
		if(errno != ENOENT)
		{
			error_set("%s: %s", filename, strerror(errno));
			ret = notes_error(notes, error_get(NULL), 1);
		}
	}
	else
	{
		notes_note_remove_all(notes);
		while((de = readdir(dir)) != NULL)
		{
			if(strncmp(de->d_name, "note.", 5) != 0)
				continue;
			free(filename);
			if((filename = _notes_note_get_filename(de->d_name))
					== NULL)
				continue; /* XXX report error */
			if((note = note_new_from_file(filename)) == NULL)
			{
				notes_error(NULL, error_get(NULL), 1);
				continue;
			}
			if(notes_note_add(notes, note) == NULL)
			{
				note_delete(note);
				continue; /* XXX report error */
			}
		}
	}
	free(filename);
	return ret;
}
Esempio n. 15
0
int ftdi_device_open(ftdi_device_t* dev, ftdi_interface_t interface) {
  error_clear(&dev->error);
  
  if (ftdi_set_interface(dev->libftdi_context, interface))
    error_set(&dev->error, FTDI_ERROR_INVALID_INTERFACE);
  else if (ftdi_usb_open_dev(dev->libftdi_context, dev->libusb_device))
    error_setf(&dev->error, FTDI_ERROR_OPEN, "%03:%03", dev->bus,
      dev->address);
    
  return error_get(&dev->error);
}
Esempio n. 16
0
int ftdi_device_close(ftdi_device_t* dev) {
  error_clear(&dev->error);
  
  if (ftdi_usb_purge_buffers(dev->libftdi_context))
    error_setf(&dev->error, FTDI_ERROR_PURGE, "%03:%03", dev->bus,
      dev->address);
  else if (ftdi_usb_close(dev->libftdi_context))
    error_setf(&dev->error, FTDI_ERROR_CLOSE, "%03:%03", dev->bus,
      dev->address);
  
  return error_get(&dev->error);
}
Esempio n. 17
0
int ftdi_context_refresh(ftdi_context_t* context) {
  struct usb_bus* libusb_bus;
  struct usb_device* libusb_device;
  struct ftdi_context* libftdi_context;
  int i = 0;

  error_clear(&context->error);
  
  if (context->num_references) {
    if (context->num_devices) {
      for (i = 0; i < context->num_devices; ++i)
        ftdi_device_destroy(&context->devices[i]);
      
      free(context->devices);
      context->devices = 0;
      context->num_devices = 0;
    }

    usb_init();
    if ((usb_find_busses() > 0) && (usb_find_devices() > 0)) {
      for (libusb_bus = usb_get_busses(); libusb_bus;
          libusb_bus = libusb_bus->next)
        for (libusb_device = libusb_bus->devices; libusb_device;
            libusb_device = libusb_device->next)
          if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID)
            context->num_devices++;
    }
    
    if (context->num_devices) {
      context->devices = malloc(context->num_devices*sizeof(ftdi_device_t));
      
      i = 0;
      for (libusb_bus = usb_get_busses(); libusb_bus;
          libusb_bus = libusb_bus->next)
        for (libusb_device = libusb_bus->devices; libusb_device;
            libusb_device = libusb_device->next)
          if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID) {
        libftdi_context = ftdi_new();
        ftdi_init(libftdi_context);
      
        ftdi_device_init(&context->devices[i], libftdi_context, libusb_bus,
          libusb_device);
        i++;
      }
    }
  }
  else
    error_set(&context->error, FTDI_ERROR_INVALID_CONTEXT);
  
  return error_get(&context->error);
}
Esempio n. 18
0
static gboolean _video_on_open(gpointer data)
{
	const int timeout = 10000;
	VideoPhonePlugin * video = data;
	PhonePluginHelper * helper = video->helper;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, video->device);
#endif
	if((video->fd = open(video->device, O_RDWR)) < 0)
	{
		error_set_code(1, "%s: %s (%s)", video->device,
				"Could not open the video capture device",
				strerror(errno));
		helper->error(helper->phone, error_get(NULL), 1);
		video->source = g_timeout_add(timeout, _video_on_open, video);
		return FALSE;
	}
	if(_open_setup(video) != 0)
	{
		helper->error(helper->phone, error_get(NULL), 1);
		close(video->fd);
		video->fd = -1;
		video->source = g_timeout_add(timeout, _video_on_open, video);
		return FALSE;
	}
	video->source = 0;
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %dx%d\n", __func__,
			video->format.fmt.pix.width,
			video->format.fmt.pix.height);
#endif
	/* FIXME allow the window to be smaller */
	gtk_widget_set_size_request(video->area, video->format.fmt.pix.width,
			video->format.fmt.pix.height);
	return FALSE;
}
Esempio n. 19
0
static gboolean _camera_on_open(gpointer data)
{
	Camera * camera = data;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, camera->device);
#endif
	camera->source = 0;
	if((camera->fd = open(camera->device, O_RDWR)) < 0)
	{
		error_set_code(1, "%s: %s (%s)", camera->device,
				_("Could not open the video capture device"),
				strerror(errno));
		_camera_error(camera, error_get(), 1);
		return FALSE;
	}
	if(_open_setup(camera) != 0)
	{
		_camera_error(camera, error_get(), 1);
		close(camera->fd);
		camera->fd = -1;
		/* FIXME also free camera->buffers */
		return FALSE;
	}
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %dx%d\n", __func__,
			camera->format.fmt.pix.width,
			camera->format.fmt.pix.height);
#endif
	gtk_widget_set_sensitive(GTK_WIDGET(_camera_toolbar[0].widget), TRUE);
	gtk_widget_set_sensitive(GTK_WIDGET(_camera_toolbar[2].widget), TRUE);
	gtk_widget_set_sensitive(GTK_WIDGET(_camera_toolbar[4].widget), TRUE);
	/* FIXME allow the window to be smaller */
	gtk_widget_set_size_request(camera->area, camera->format.fmt.pix.width,
			camera->format.fmt.pix.height);
	return FALSE;
}
Esempio n. 20
0
static SSLTransport * _ssl_init(AppTransportPluginHelper * helper,
		AppTransportMode mode, char const * name)
{
	SSLTransport * ssl;
	int res;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%u, \"%s\")\n", __func__, mode, name);
#endif
	if((ssl = object_new(sizeof(*ssl))) == NULL)
		return NULL;
	memset(ssl, 0, sizeof(*ssl));
	ssl->helper = helper;
	if((ssl->ssl_ctx = SSL_CTX_new(TLSv1_method())) == NULL
			|| SSL_CTX_set_cipher_list(ssl->ssl_ctx,
				SSL_DEFAULT_CIPHER_LIST) != 1
			|| SSL_CTX_load_verify_locations(ssl->ssl_ctx, NULL,
				"/etc/openssl/certs") != 1)
		/* FIXME report the underlying error */
		res = -error_set_code(1, "Could not initialize SSL");
	else
		switch((ssl->mode = mode))
		{
			case ATM_CLIENT:
				res = _init_client(ssl, name);
				break;
			case ATM_SERVER:
				res = _init_server(ssl, name);
				break;
			default:
				res = -error_set_code(1,
						"Unknown transport mode");
				break;
		}
	/* check for errors */
	if(res != 0)
	{
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() => %d (%s)\n", __func__, res,
				error_get(NULL));
#endif
		_ssl_destroy(ssl);
		return NULL;
	}
#if 0 /* XXX may be useful */
	SSL_CTX_set_mode(ssl->ssl_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
#endif
	return ssl;
}
Esempio n. 21
0
int ftdi_device_write(ftdi_device_t* dev, unsigned char* data, size_t num) {
  ssize_t result;
  
  error_clear(&dev->error);
  
  result = ftdi_write_data(dev->libftdi_context, data, num);
  if (result >= 0)
    dev->num_written += result;
  else {
    error_setf(&dev->error, FTDI_ERROR_WRITE, "%03:%03", dev->bus,
      dev->address);
    return -error_get(&dev->error);
  }
  
  return result;
}
Esempio n. 22
0
static int _snapshot_dcim(Camera * camera, char const * homedir,
		char const * dcim)
{
	char * path;

	if((path = g_build_filename(homedir, dcim, NULL)) == NULL)
		return -_camera_error(camera, _("Could not save picture"), 1);
	if(mkdir(path, 0777) != 0 && errno != EEXIST)
	{
		error_set_code(1, "%s: %s: %s", _("Could not save picture"),
				path, strerror(errno));
		free(path);
		return -_camera_error(camera, error_get(), 1);
	}
	free(path);
	return 0;
}
Esempio n. 23
0
static unsigned int _reset_baudrate(ModemPlugin * modem, unsigned int baudrate)
{
	switch(baudrate)
	{
		case 1200:
			return B1200;
		case 2400:
			return B2400;
		case 4800:
			return B4800;
		case 9600:
			return B9600;
		case 19200:
			return B19200;
		case 38400:
			return B38400;
#ifdef B76800
		case 76800:
			return B76800;
#endif
#ifdef B14400
		case 14400:
			return B14400;
#endif
#ifdef B28800
		case 28800:
			return B28800;
#endif
		case 57600:
			return B57600;
		case 115200:
			return B115200;
		case 230400:
			return B230400;
		case 460800:
			return B460800;
		case 921600:
			return B921600;
		default:
			error_set("%u%s", baudrate,
					"Unsupported baudrate (using 115200)");
			modem->helper->error(NULL, error_get(), 1);
			return B115200;
	}
}
Esempio n. 24
0
/* ussd_init */
static USSD * _ussd_init(PhonePluginHelper * helper)
{
	USSD * ussd;

	if((ussd = object_new(sizeof(*ussd))) == NULL)
		return NULL;
	ussd->config = config_new();
	ussd->_operator = NULL;
	ussd->helper = helper;
	ussd->window = NULL;
	ussd->operators = NULL;
	ussd->codes = NULL;
	/* check for errors */
	if(ussd->config == NULL || config_load(ussd->config,
				SYSCONFDIR "/" PACKAGE "/ussd.conf") != 0)
		helper->error(helper->phone, error_get(NULL), 1);
	return ussd;
}
Esempio n. 25
0
static char * _snapshot_path(Camera * camera, char const * homedir,
		char const * dcim, char const * extension)
{
	struct timeval tv;
	struct tm tm;
	unsigned int i;
	char * filename;
	char * path;

	if(gettimeofday(&tv, NULL) != 0 || gmtime_r(&tv.tv_sec, &tm) == NULL)
	{
		error_set_code(1, "%s: %s", _("Could not save picture"),
				strerror(errno));
		_camera_error(camera, error_get(), 1);
		return NULL;
	}
	for(i = 0; i < 64; i++)
	{
		if((filename = g_strdup_printf("%u%02u%02u-%02u%02u%02u-%03u%s",
						tm.tm_year + 1900,
						tm.tm_mon + 1, tm.tm_mday,
						tm.tm_hour, tm.tm_min,
						tm.tm_sec, i + 1, extension))
				== NULL)
			/* XXX report error */
			return NULL;
		path = g_build_filename(homedir, dcim, filename, NULL);
		g_free(filename);
		if(path == NULL)
		{
			_camera_error(camera, _("Could not save picture"), 1);
			return NULL;
		}
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() %s\n", __func__, path);
#endif
		if(access(path, R_OK) != 0 && errno == ENOENT)
			return path;
		g_free(path);
	}
	return NULL;
}
Esempio n. 26
0
static int _settings_browse_home(Settings * settings, Config * config)
{
	int ret;
	char const fallback[] = ".local/share";
	char const * path;
	char const * homedir;
	String * p;

	/* use $XDG_DATA_HOME if set and not empty */
	if((path = getenv("XDG_DATA_HOME")) != NULL && strlen(path) > 0)
		return _settings_browse_folder(settings, config, path);
	/* fallback to "$HOME/.local/share" */
	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	if((p = string_new_append(homedir, "/", fallback, NULL)) == NULL)
		return -_settings_error(error_get(NULL), 1);
	ret = _settings_browse_folder(settings, config, p);
	free(p);
	return ret;
}
Esempio n. 27
0
static int _snapshot_save(Camera * camera, char const * path,
		CameraSnapshotFormat format)
{
	struct v4l2_pix_format * pix = &camera->format.fmt.pix;
	GdkPixbuf * pixbuf;
	char buf[16];
	gboolean res;
	GError * error = NULL;

	if((pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer,
					GDK_COLORSPACE_RGB, FALSE, 8,
					pix->width, pix->height, pix->width * 3,
					NULL, NULL)) == NULL)
		return -_camera_error(camera, _("Could not save picture"), 1);
	switch(format)
	{
		case CSF_JPEG:
			snprintf(buf, sizeof(buf), "%d",
					camera->snapshot_quality);
			res = gdk_pixbuf_save(pixbuf, path, "jpeg", &error,
					"quality", buf, NULL);
			break;
		case CSF_PNG:
			res = gdk_pixbuf_save(pixbuf, path, "png", &error,
					NULL);
			break;
		default:
			res = FALSE;
			break;
	}
	g_object_unref(pixbuf);
	if(res != TRUE)
	{
		error_set_code(1, "%s: %s", _("Could not save picture"),
				(error != NULL) ? error->message
				: _("Unknown error"));
		g_error_free(error);
		return -_camera_error(camera, error_get(), 1);
	}
	return 0;
}
Esempio n. 28
0
/* function_name */
static int _function_name(State * state)
	/* WORD */
{
	int ret;
	char const * string;
	char * function = NULL;

	if((string = token_get_string(state->token)) == NULL)
		return _parser_error(state, "%s", "Empty function names are"
				" not allowed");
	if((function = strdup(string)) == NULL)
		return error_set_code(1, "%s", strerror(errno));
	ret = _parser_check(state, AS_CODE_WORD);
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s \"%s\"\n", "function", function);
#endif
	if(asmcode_function(state->code, function) != 0)
		ret |= _parser_error(state, "%s", error_get());
	free(function);
	return ret;
}
Esempio n. 29
0
/* cpufreq_on_timeout */
static gboolean _cpufreq_on_timeout(gpointer data)
{
	Cpufreq * cpufreq = data;
	PanelAppletHelper * helper = cpufreq->helper;
	uint64_t freq;
	size_t freqsize = sizeof(freq);
	char buf[256];

	if(sysctlbyname(cpufreq->name, &freq, &freqsize, NULL, 0) < 0)
	{
		error_set("%s: %s: %s", applet.name, cpufreq->name,
				strerror(errno));
		helper->error(NULL, error_get(NULL), 1);
		return TRUE;
	}
	snprintf(buf, sizeof(buf), "%4u", (unsigned int)freq);
	gtk_label_set_text(GTK_LABEL(cpufreq->label), buf);
# if GTK_CHECK_VERSION(2, 12, 0)
	snprintf(buf, sizeof(buf), "%s%u %s", _("CPU frequency: "),
			(unsigned int)freq, _("MHz"));
	gtk_widget_set_tooltip_text(cpufreq->hbox, buf);
# endif
	return TRUE;
}
Esempio n. 30
0
/* main */
int main(int argc, char * argv[])
{
	Clock * clock;
	int o;

	if(setlocale(LC_ALL, "") == NULL)
		_error("setlocale", 1);
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	gtk_init(&argc, &argv);
	while((o = getopt(argc, argv, "")) != -1)
		switch(o)
		{
			default:
				return _usage();
		}
	if(optind != argc)
		return _usage();
	if((clock = clock_new()) == NULL)
		return _error(error_get(NULL), 2);
	gtk_main();
	clock_delete(clock);
	return 0;
}