Beispiel #1
0
struct s_list *f_keys_initialize(struct s_list *supplied, const char *file, char separator) {
	struct s_list *result = supplied;
	struct s_keys_entry *entry;
	char buffer[d_string_buffer_size], *pointer;
	FILE *stream;
	if (!result)
		f_list_init(&result);
	if ((stream = fopen(file, "r"))) {
		while (!feof(stream)) {
			memset(buffer, 0, d_string_buffer_size);
			if (fgets(buffer, d_string_buffer_size, stream))
				if ((pointer = strchr(buffer, separator))) {
					*pointer = '\0';
					pointer++;
					f_string_trim(buffer);
					f_string_trim(pointer);
					if ((f_string_strlen(buffer) > 0) && (f_string_strlen(pointer) > 0))
						if ((entry = (struct s_keys_entry *) d_malloc(sizeof(struct s_keys_entry)))) {
							strncpy(entry->key, buffer, d_string_buffer_size);
							strncpy(entry->value, pointer, d_string_buffer_size);
							f_list_append(result, (struct s_list_node *)entry, e_list_insert_head);
						}
				}
		}
		fclose(stream);
	}
	return result;
}
Beispiel #2
0
int main (int argc, char *argv[]) {
	struct s_interface *main_interface = (struct s_interface *) malloc(sizeof(struct s_interface));
	char *current_pointer, *next_pointer, csv_file[d_string_buffer_size], default_calibration[d_string_buffer_size], buffer[d_string_buffer_size] = {'\0'};
	int index = 0, ladder, local_selection[d_calibrations_ladders];
	size_t length;
	f_memory_init();
	if (argc >= 2) {
		if ((current_pointer = strstr(argv[1], d_compare_postfix))) {
			length = f_string_strlen(argv[1]);
			while ((current_pointer < (length+argv[1])) && (!isdigit(*current_pointer)))
				current_pointer++;
			while ((current_pointer < (length+argv[1])) && (isdigit(*current_pointer))) {
				buffer[index++] = *current_pointer;
				current_pointer++;
			}
		}
		environment.selected_trb = atoi(buffer);
		snprintf(default_calibration, d_string_buffer_size, "%s%02d", d_compare_default, environment.selected_trb);
		if (argc >= 3)
			strncpy(default_calibration, argv[2], d_string_buffer_size);
		for (ladder = 0; ladder < d_calibrations_ladders; ++ladder)
			local_selection[ladder] = d_false;
		if (f_analyze_calibration(&environment, argv[1], default_calibration)) {
			snprintf(csv_file, d_string_buffer_size, "%s.csv", argv[1]);
			f_analyze_values(&environment);
			f_analyze_values_write(&environment, stdout);
			gtk_init(&argc, &argv);
			if (f_compare_initialize(main_interface, "UI/UI_main.glade")) {
				if (argc == 4) {
					current_pointer = argv[3];
					while ((next_pointer = strchr(current_pointer, ','))) {
						ladder = atoi(current_pointer);
						local_selection[ladder] = d_true;
						p_compare_loop_toggle(main_interface, ladder, d_true);
						current_pointer = (next_pointer+1);
					}
					if (f_string_strlen(current_pointer) > 0) {
						ladder = atoi(current_pointer);
						local_selection[ladder] = d_true;
						p_compare_loop_toggle(main_interface, ladder, d_true);
					}
				} else
					for (ladder = 0; ladder < d_calibrations_ladders; ++ladder) {
						local_selection[ladder] = d_true;
						p_compare_loop_toggle(main_interface, ladder, d_true);
					}
				f_analyze_export(&environment, csv_file, local_selection);
				gtk_idle_add((GSourceFunc)f_compare_loop, main_interface);
				gtk_main();
			}
		} else
			fprintf(stderr, "one of these directories doesn't contains calibration files\n");
	} else
		fprintf(stderr, "usage:\n%s <calibration> {reference calibration} {list of masked ladders CSV}\n", argv[0]);
	f_memory_destroy();
	return 0;
}
Beispiel #3
0
int main (int argc, char *argv[]) {
	char buffer[d_string_buffer_size] = {0};
	int index;
	/* ./ localhost port {command} */
	if (argc >= 4) {
		for (index = 3; index < argc; ++index) {
			strncat(buffer, argv[index], (d_string_buffer_size-f_string_strlen(buffer)));
			strncat(buffer, d_remote_separator, (d_string_buffer_size-f_string_strlen(buffer)));
		}
		strncat(buffer, d_remote_final, (d_string_buffer_size-f_string_strlen(buffer)));
		if (!f_remote_inject(argv[1], argv[2], buffer))
			d_err(e_log_level_ever, "error, unable to communicate with %s:%s", argv[1], argv[2]);
	} else
		fprintf(stderr, "magrathea_remote usage:\n%s <IP> <port> {command ...}\n", argv[0]);
	return 0;
}
Beispiel #4
0
void p_telnet_device_refresh_readout(int client, struct s_console *console) {
	fd_set sockets;
	struct timeval timeout = {0, d_telnet_device_timeout};
	char character;
	if (v_telnet_device.clients[client].socket.initialized) {
		FD_ZERO(&sockets);
		FD_SET(v_telnet_device.clients[client].socket.socket, &sockets);
		if (select(v_telnet_device.clients[client].socket.socket+1, &sockets, NULL, NULL, &timeout) > 0)
			while (read(v_telnet_device.clients[client].socket.socket, &character, 1) > 0) {
				if (character == '\n') {
					if (f_string_strlen(v_telnet_device.clients[client].buffer) > 0) {
						if (f_string_strcmp(v_telnet_device.clients[client].buffer, d_magrathea_exit_command) != 0) {
#ifdef d_telnet_echoing
							fprintf(stdout, "[<<] %s\n", v_telnet_device.clients[client].buffer);
							fflush(stdout);
#endif
							p_console_execute(console, v_telnet_device.clients[client].buffer,
									v_telnet_device.clients[client].socket.socket);
							p_telnet_device_refresh_command(client);
						} else {
							p_telnet_device_destroy_client(client);
							break;
						}
					}
					memset(v_telnet_device.clients[client].buffer, 0, d_string_buffer_size);
					v_telnet_device.clients[client].data_pointer = 0;
					break;
				} else if (character == '\b') {
					if (v_telnet_device.clients[client].data_pointer > 0)
						v_telnet_device.clients[client].buffer[--(v_telnet_device.clients[client].data_pointer)] = '\0';
				} else if ((character != '\r') && (v_telnet_device.clients[client].data_pointer < (d_string_buffer_size-1)))
					v_telnet_device.clients[client].buffer[v_telnet_device.clients[client].data_pointer++] = character;
			}
	}
}
Beispiel #5
0
d_define_method(label, update_texture)(struct s_object *self, TTF_Font *font, struct s_object *environment) {
    d_using(label);
    char buffer[d_string_buffer_size];
    int width, height;
    struct s_drawable_attributes *drawable_attributes = d_cast(self, drawable);
    struct s_uiable_attributes *uiable_attributes = d_cast(self, uiable);
    struct s_environment_attributes *environment_attributes = d_cast(environment, environment);
    TTF_Font *current_font;
    SDL_Surface *unoptimized_surface;
    SDL_Color white = {
        255,
        255,
        255,
        255
    };
    if (label_attributes->image) {
        SDL_DestroyTexture(label_attributes->image);
        label_attributes->image = NULL;
    }
    if ((current_font = font) || (current_font = label_attributes->last_font)) {
        label_attributes->last_font = current_font;
        if (f_string_strlen(label_attributes->string_content) > 0) {
            if ((unoptimized_surface = TTF_RenderText_Blended(current_font, label_attributes->string_content, white))) {
                label_attributes->image = SDL_CreateTextureFromSurface(environment_attributes->renderer, unoptimized_surface);
                if (SDL_QueryTexture(label_attributes->image, NULL, NULL, &width, &height) == 0) {
                    label_attributes->string_width = width;
                    label_attributes->string_height = height;
                    if (label_attributes->format == e_label_background_format_adaptable) {
                        label_attributes->last_width = width + (uiable_attributes->border_w * 2.0);
                        label_attributes->last_height = height + (uiable_attributes->border_h * 2.0);
                    }
                    d_call(&(drawable_attributes->point_dimension), m_point_set_x, (double)label_attributes->last_width);
                    d_call(&(drawable_attributes->point_dimension), m_point_set_y, (double)label_attributes->last_height);
                    if (label_attributes->last_blend != e_drawable_blend_undefined)
                        d_call(self, m_drawable_set_blend, label_attributes->last_blend);
                    d_call(self, m_drawable_set_maskRGB, (unsigned int)label_attributes->last_mask_R, (unsigned int)label_attributes->last_mask_G, 
                            (unsigned int)label_attributes->last_mask_B);
                    d_call(self, m_drawable_set_maskA, (unsigned int)label_attributes->last_mask_A);
                } else {
                    snprintf(buffer, d_string_buffer_size, "unable to retrieve informations for label \"%s\" exception",
                            label_attributes->string_content);
                    d_throw(v_exception_texture, buffer);
                }
                SDL_FreeSurface(unoptimized_surface);
            } else {
                snprintf(buffer, d_string_buffer_size, "ungenerable texture for label \"%s\" exception",
                        label_attributes->string_content);
                d_throw(v_exception_texture, buffer);
            }
        }
    } else {
        snprintf(buffer, d_string_buffer_size, "ungenerable texture for label \"%s\" with missing font exception", label_attributes->string_content);
        d_throw(v_exception_texture, buffer);
    }
    d_call(self, m_emitter_raise, v_uiable_signals[e_uiable_signal_content_changed]);
    return self;
}
Beispiel #6
0
int f_trigger_device_trigger(unsigned char code, char **tokens, size_t elements, int output) {
	char buffer[d_string_buffer_size];
	enum e_adlink_trigger trigger = e_adlink_trigger_50;
	int argument, result = d_false, speed = 0;
	if (f_console_parameter("-off", tokens, elements, d_true) != d_console_parameter_null)
		trigger = e_adlink_trigger_disabled;
	else if (f_console_parameter("-ext", tokens, elements, d_true) != d_console_parameter_null)
		trigger = e_adlink_trigger_external;
	else if ((argument = f_console_parameter("-s", tokens, elements, d_false)) != d_console_parameter_null)
		switch ((speed = atoi(tokens[argument]))) {
			case 20:
				trigger = e_adlink_trigger_20;
				break;
			case 100:
				trigger = e_adlink_trigger_100;
				break;
			case 200:
				trigger = e_adlink_trigger_200;
				break;
			case 300:
				trigger = e_adlink_trigger_300;
				break;
			case 50:
			default:
				trigger = e_adlink_trigger_50;
		}
	if ((result = f_adlink_trigger_setup(trigger)))
		v_trigger_current = trigger;
	if (output != d_console_descriptor_null) {
		if (result) {
			switch (trigger) {
				case e_adlink_trigger_disabled:
					strncpy(buffer, "trigger has been disabled\n", d_string_buffer_size);
					break;
				case e_adlink_trigger_external:
					strncpy(buffer, "running external trigger\n", d_string_buffer_size);
					break;
				case e_adlink_trigger_100:
				case e_adlink_trigger_200:
				case e_adlink_trigger_300:
				case e_adlink_trigger_50:
				case e_adlink_trigger_20:
				default:
					snprintf(buffer, d_string_buffer_size, "running trigger @ %dHz\n", trigger);
			}
		}
		else
			snprintf(buffer, d_string_buffer_size, "%sYEK!%s 404 of trigger board\n", v_console_styles[e_console_style_red],
					v_console_styles[e_console_style_reset]);
		write(output, buffer, f_string_strlen(buffer));
		fsync(output);
	}
	return result;
}
Beispiel #7
0
int f_remote_inject(const char *ip, const char *port, const char *command) {
	struct addrinfo hints = {AI_PASSIVE, AF_INET, SOCK_STREAM}, *response = NULL;
	int client_socket, result = d_false, flags;
	if (getaddrinfo(ip, port, &hints, &response) == 0) {
		if ((client_socket = socket(response->ai_family, response->ai_socktype, response->ai_protocol))) {
			if (connect(client_socket, response->ai_addr, response->ai_addrlen) == 0) {
				if ((flags = fcntl(client_socket, F_GETFL)) != -1) {
					fcntl(client_socket, F_SETFL, flags|O_NONBLOCK);
					write(client_socket, command, f_string_strlen(command));
					usleep(d_remote_hard_delay);
					write(client_socket, d_remote_exit_command, f_string_strlen(d_remote_exit_command));
					usleep(d_remote_hard_delay);
					result = d_true;
				}
				shutdown(client_socket, SHUT_RDWR);
			}
			close(client_socket);
		}
		freeaddrinfo(response);
	}
	return result;
}
Beispiel #8
0
int p_analyze_directory(char *directory, struct s_analyzer_action *actions, const char *directory_ignore_list) {
	DIR *stream;
	struct dirent *descriptor;
	char next_directory[PATH_MAX];
	int result = d_true;
	size_t length;
	if ((stream = opendir(directory))) {
		while ((descriptor = readdir(stream)))
			if ((descriptor->d_name[0] != '.') && (!(strstr(directory_ignore_list, descriptor->d_name)))) {
				length = f_string_strlen(directory);
				if (directory[length-1] == '/')
					directory[length-1] = '\0';
				snprintf(next_directory, PATH_MAX, "%s/%s", directory, descriptor->d_name);
				if (!(result = p_analyze_directory(next_directory, actions, directory_ignore_list)))
					break;
			}
		closedir(stream);
	} else
		result = p_analyze_directory_file(directory, actions);
	return result;
}
Beispiel #9
0
d_define_method(label, set_content_char)(struct s_object *self, char *string_content, TTF_Font *font, struct s_object *environment) {
    d_using(label);
    size_t string_length = f_string_strlen(string_content);
    if (string_length > 0) {
        if (label_attributes->string_content) {
            /* realloc only if really needed */
            if (label_attributes->size < (string_length+1)) {
                if ((label_attributes->string_content = (char *)d_realloc(label_attributes->string_content, (string_length+1))))
                    label_attributes->size = (string_length+1);
                else
                    d_die(d_error_malloc);
            }
        } else if ((label_attributes->string_content = (char *)d_malloc(string_length+1)))
            label_attributes->size = (string_length+1);
        else
            d_die(d_error_malloc);
        strncpy(label_attributes->string_content, string_content, string_length);
        label_attributes->string_content[string_length] = '\0';
    } else if (label_attributes->string_content)
        memset(label_attributes->string_content, '\0', label_attributes->size);
    p_label_update_texture(self, font, environment);
    return self;
}
Beispiel #10
0
void p_telnet_device_refresh_command(int client) {
	char buffer[d_string_buffer_size];
	snprintf(buffer, d_string_buffer_size, "[magrathea %s]>", d_magrathea_version);
	write(v_telnet_device.clients[client].socket.socket, buffer, f_string_strlen(buffer));
	fsync(v_telnet_device.clients[client].socket.socket);
}