Ejemplo n.º 1
0
t_op		get_options(int argc, char **argv)
{
	int			i;
	int			j;
	t_op		options;

	i = 1;
	initialize_options(&options);
	while (argv[i])
	{
		j = -1;
		if (argv[i][0] != '-')
		{
			get_files(i, &options, argc, argv);
			return (options);
		}
		j++;
		while (argv[i][++j])
		{
			if (ft_strchr("lrRatucg1p", argv[i][j]) == NULL)
				error_option(argv[i][j]);
			flag_options(&options, argv[i][j]);
		}
		i++;
	}
	get_files(i, &options, argc, argv);
	return (options);
}
Ejemplo n.º 2
0
void
get_files (command_t cmd, file_tree *head)
{
  char **word;
  switch (cmd->type)
    {
      case AND_COMMAND:
      case SEQUENCE_COMMAND:
      case OR_COMMAND:
      case PIPE_COMMAND:
        get_files (cmd->u.command[0], head);
        get_files (cmd->u.command[1], head);
        break;
      case SIMPLE_COMMAND:
        if (cmd->input)
          insert_file_tree (head, cmd->input, 0);
        if (cmd->output)
          insert_file_tree (head, cmd->output, 1);
        word = cmd->u.word;
        while (*word)
          {
            insert_file_tree (head, *word, 0);
            word++;
          }
        break;
      case SUBSHELL_COMMAND:
        if (cmd->input)
          insert_file_tree (head, cmd->input, 0);
        if (cmd->output)
          insert_file_tree (head, cmd->output, 1);
        get_files (cmd->u.subshell_command, head);
        break;
    }
}
Ejemplo n.º 3
0
void
get_files(command_t cmd, char ***ip_array, char ***op_array, int *input_size, int *output_size)
{
	if(cmd == NULL) {
		return;
	}
	
	switch(cmd->type) {
		case AND_COMMAND:
		case SEQUENCE_COMMAND:
		case OR_COMMAND:
		case PIPE_COMMAND:
			get_files(cmd->u.command[0],ip_array,op_array,input_size,output_size);
			get_files(cmd->u.command[1],ip_array,op_array,input_size,output_size);
			break;
		case SUBSHELL_COMMAND:
			if(cmd->input != NULL) {
				*ip_array = (char**)checked_realloc(*ip_array,(*input_size+1)*sizeof(char*));
				copy_file(*ip_array,cmd->input,input_size);
			}
			if(cmd->output != NULL) {
				*op_array = (char**)checked_realloc(*op_array,(*output_size+1)*sizeof(char*));
				copy_file(*op_array,cmd->output,output_size);
			}
			get_files(cmd->u.subshell_command,ip_array,op_array,input_size,output_size);
			break;
		case SIMPLE_COMMAND:
			if(cmd->input != NULL) {
				*ip_array = (char**)checked_realloc(*ip_array,(*input_size+1)*sizeof(char*));
				copy_file(*ip_array,cmd->input,input_size);
			}
			if(cmd->output != NULL) {
				*op_array = (char**)checked_realloc(*op_array,(*output_size+1)*sizeof(char*));
				copy_file(*op_array,cmd->output,output_size);
			}
			char **w = cmd->u.word;
			
			/*start at the second word, first word is the command */
			w++;
			while(*w) {
				*ip_array = (char**)checked_realloc(*ip_array,(*input_size+1)*sizeof(char*));
				copy_file(*ip_array,*w,input_size);
				w++;
			}
			break;
		default:
			return;
	}
	return;
}
Ejemplo n.º 4
0
DELETE_ADMIN( logs )( cr_connection& conn )
{
	auto files = get_files( g_path_log );
	for( string& file : files )
	{
		if( file != "slite.log" )
		{
			string log_path = g_path_log + file;
			if( remove( log_path.c_str() ) )
			{
				conn.respond( CR_HTTP_INTERNAL_ERROR, "Unable to delete file: " + file );
				return;
			}
		}
	}
	
/*	if( gLogFile )
	{
		fclose( gLogFile );
		gLogFile = fopen( gPathLogFile.c_str(), "wt" );
		gLogSize = cr_file_size( gPathLogFile );
	}*/
	
	conn.respond( CR_HTTP_OK, to_string( files.size() ) + " files were deleted" );
}
Ejemplo n.º 5
0
void retrieve_rt_vars(void)
{
    gchar **files = NULL;
    GArray *classes = NULL;
    Rtv_Data *rtv_data = NULL;
    gint i = 0;
    /*printf("retrieve rt_vars from mtx realtime maps\n");*/

    files = get_files(NULL,REALTIME_MAPS_DATA_DIR,"xml",&classes);
    if (!files)
        return;
    while(files[i])
        i++;
    rtv_data = g_new0(Rtv_Data, 1);
    rtv_data->persona_hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,info_free);
    rtv_data->persona_array = g_array_new(FALSE,TRUE,sizeof(Persona_Info *));
    rtv_data->total_files = i;
    load_rtvars(files,rtv_data);
    g_array_free(classes,TRUE);
    g_strfreev(files);
    g_hash_table_destroy(rtv_data->persona_hash);
    g_array_free(rtv_data->persona_array,TRUE);
    g_free(rtv_data);

}
Ejemplo n.º 6
0
Archivo: sized.c Proyecto: Tolchi/misc
int do_attrition(void) {
  int rc = -1, nfiles=0;
  UT_array *files;
  UT_array *stats; 
  utarray_new(files,&ut_str_icd);
  utarray_new(stats,&stats_icd);
  if (get_files(files,stats) == -1) goto done;

  /* tally up their sizes */
  int64_t total_sz=0;
  file_stat_t *fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) total_sz += fs->sb.st_size;
  if (total_sz < cf.sz_bytes) { rc = 0; goto done; }

  /* we're oversize. sort the files oldest first and delete til under max size*/
  utarray_sort(stats,attrition_sort);
  fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) {
    char *file = *(char**)utarray_eltptr(files, fs->file_idx);
    if (cf.verbose) syslog(LOG_INFO,"removing %s (size %ld)", file, (long)fs->sb.st_size);
    if (cf.dry_run || (unlink(file) == 0)) {
      total_sz -= fs->sb.st_size;
      nfiles++;
      if (total_sz < cf.sz_bytes) { rc = 0; goto done; }
    } else {
      syslog(LOG_ERR,"can't unlink %s: %s", file, strerror(errno));
    }
  }

 done:
  if (cf.verbose) syslog(LOG_INFO,"%d files removed", nfiles);
  utarray_free(files);
  utarray_free(stats);
  return rc;
}
Ejemplo n.º 7
0
/********************************************************
 *	print_dir
 *
 * Takes the a directory's ID and prints the child
 * directories and files within.
 ********************************************************/
void print_dir( uint32_t id )
{
	uint32_t i, num_children, num_files;
	struct FS_Directory *children;
	struct FS_File *dir_files;

	num_children = get_num_children( id );
	if ( num_children )
	{
		children = get_children( id );
		for ( i = 0; i < num_children; i++ )
			printf("%s\n", children[i].name );
		free( children );
	}
	

	num_files = get_num_files( id );
	if ( num_files )
	{
		dir_files = get_files( id );
		for ( i = 0; i < num_files; i++ )
			printf("%s\n", dir_files[i].name );
		free( dir_files );
	}
		
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
	if (argc != 3)
		fail("usage: cospkg cos.pkg dir");

	get_files(argv[2]);
	build_hdr();
	write_pkg(argv[1]);

	return 0;
}
Ejemplo n.º 9
0
static void
test_valid_suite ()
{
    GSList *list, *l;

    list = get_files ("valid");
    for (l = list; l; l = l->next) {
        test_parser_with_file ((const gchar *) l->data, TRUE);
        g_free (l->data);
    }
    g_slist_free (list);
}
Ejemplo n.º 10
0
script_vec System::get_removed_scripts()
{
	script_vec vp;

	string_vec files = get_files(PATH_REMOVED_SCRIPTS);

	for (string_vec::iterator i = files.begin(); i != files.end(); i++)
	{
		vp.push_back(*i);
	}

	return vp;
}
Ejemplo n.º 11
0
package_vec System::get_removed_packages()
{
	package_vec vp;

	string_vec files = get_files(PATH_REMOVED_PACKAGES);

	for (string_vec::iterator i = files.begin(); i != files.end(); i++)
	{
		vp.push_back(Package(*i));
	}

	return vp;
}
Ejemplo n.º 12
0
script_vec System::get_installed_scripts()
{
	script_vec vp;

	string_vec files = get_files(PATH_INSTALLED_SCRIPTS);

	for (string_vec::iterator i = files.begin(); i != files.end(); i++)
	{
		vp.push_back(Script(*i));
	}

	return vp;
}
Ejemplo n.º 13
0
package_vec System::get_installed_packages()
{
	package_vec vp;

	string_vec files = get_files(PATH_INSTALLED_PACKAGES);

	for (string_vec::iterator i = files.begin(); i != files.end(); i++)
	{
		vp.push_back(Package(*i)); /* BOOM */
	}

	return vp;
}
Ejemplo n.º 14
0
static PTR get_file_struct_ptr(CPUState *env, PTR task_struct, int fd) {
	PTR files = get_files(env, task_struct);
	PTR fds = get_files_fds(env, files);
	PTR fd_file_ptr, fd_file;

	// fds is a flat array with struct file pointers.
	// Calculate the address of the nth pointer and read it.
	fd_file_ptr = fds + fd*sizeof(PTR);
	if (-1 == panda_virtual_memory_rw(env, fd_file_ptr, (uint8_t *)&fd_file, sizeof(PTR), 0)) {
		return (PTR)NULL;
	}
	if (fd_file == (PTR)NULL) {
		return (PTR)NULL;
	}
	return fd_file;
}
Ejemplo n.º 15
0
static int cmd(string str, object me, string verb)
{
  string file, *filename, text;
  int range, lineas;
  string content, err;

  content = "";

  if (!strlen(str))
  {
    notify_fail("Syntax: tail [-<number of lines>] <files>\n");
    return 0;
  }

  if (sscanf(str, "-%d %s", range, file) == 2)
  {
    filename = get_files(file);

    if (!sizeof(filename))
    {
      notify_fail("That file does not exist.\n");
      return 0;
    }

    if (range < 0)
    {
      notify_fail("Invalid range: "+range+"\n");
      return 0;
    }

    if (!range)
      range = 20;

    err = catch(content = read_file(filename[0]));

    if (err || !content)
    {
      notify_fail("Unable to read the file... maybe too long?\n");
      return 0;
    }

    lineas = sizeof(explode(content,"\n"));
    text = read_file_line(filename[0], lineas-range, lineas);

    write(text);
    return 1;
  }
Ejemplo n.º 16
0
static Suite *
create_lm_parser_invalid_suite ()
{
	Suite  *suite;
	GSList *list, *l;

	suite = suite_create ("LmParser");

	list = get_files ("invalid");
	for (l = list; l; l = l->next) {
		g_print ("INVALID: %s\n", (const gchar *) l->data);
		g_free (l->data);
	}
	g_slist_free (list);

	return suite;
}
Ejemplo n.º 17
0
	incr_depth_t(std::size_t* _depth, std::ostream& stream, const span_t& span) :
		depth(_depth),
		stream(stream),
		span(span)
	{
		char tmp[64];
		const char* fname = get_files().at(span.first.file_id).c_str();
		const char* last_slash = strrchr(fname, '/');
		snprintf(tmp, 64, "%32s (l%4d c%4d) (l%4d c%4d) ",
			last_slash ? 1+last_slash : fname,
			span.first.line,
			span.first.col, span.second.line, span.second.col);
		stream << tmp;
		for(std::size_t i = 0; i < *depth; ++i)
		 stream << "  ";
		++*depth;
	}
Ejemplo n.º 18
0
gboolean
on_expand_cb (GtkExpander *expander, GString *str)
{
    GString *mystr2;
    int i;
    GtkWidget *vbox = g_list_first (gtk_container_get_children (GTK_CONTAINER (expander)))->data;
    int numofchilds = g_list_length (gtk_container_get_children (GTK_CONTAINER (vbox)));
    if (numofchilds == 0)
    {
        GArray *subdir = get_files (str->str, TRUE, FALSE);
        for (i=0; i<subdir->len; i++)
        {
            mystr2 = g_array_index (subdir, GString*, i);
            doodle_add_dir_images (mystr2->str, vbox);
        }
        free_gstring_array (subdir);
        g_string_free (str, TRUE);
    }
Ejemplo n.º 19
0
int*
create_dependencygraph(command_stream_t stream)
{
	
	int i, j;
	
	int *dependency_array = (int*) checked_malloc(stream->size * sizeof(int*));
	

	fstruct_t* files_array = (fstruct_t*) checked_malloc(stream->size * sizeof(fstruct_t));
	
	/*initially there are no dependencies */
	for (i = 0; i < stream->size; i++)
	{
		dependency_array[i] = 0;
	}
	
	/*first get all the files for each command in the command stream and store them in a fstruct array */
	for (i = 0; i < stream->size; i++)
	{
		files_array[i]= create_fstruct();
		get_files(stream->command_array[i], &files_array[i]->ip_array, &files_array[i]->op_array, &files_array[i]->input_size, &files_array[i]->output_size);
	}

	/*check the files array and set the dependencies accordingly 
	we start at 1 since the first command never has any dependencies*/
	for (i = 1; i < stream->size; i++)
	{
		for (j = 0; j < i; j++)
		{
			if (check_dependency(files_array[j], files_array[i]))
			{
				if ((dependency_array[j] + 1)> dependency_array[i])
				{
					dependency_array[i] = dependency_array[j] +1;
				}
			}
		}
	}
	return dependency_array;
}
Ejemplo n.º 20
0
void retrieve_rt_vars(void)
{
	gchar **files = NULL;
	GArray *classes = NULL;
	struct Rtv_Data *rtv_data = NULL;
	gint i = 0;
	/*printf("retrieve rt_vars from mtx realtime maps\n");*/
	files = get_files(g_strconcat(REALTIME_MAPS_DATA_DIR,PSEP,NULL),g_strdup("rtv_map"),&classes);
	if (!files)
		return;
	while(files[i])
		i++;
	rtv_data = g_new0(struct Rtv_Data, 1);
	rtv_data->rtv_hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
	rtv_data->int_ext_hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
	rtv_data->rtv_list = NULL;
	rtv_data->total_files = i;
	load_rtvars(files,rtv_data);
	g_array_free(classes,TRUE);

}
Ejemplo n.º 21
0
void File::get_files(std::vector<std::string>& file_vector,
		const std::string& directory, bool recursive,
		const std::string& extension) {
	if (!boost::filesystem::exists(directory)) {
		return;
	}
	boost::filesystem::directory_iterator end_itr;
	for (boost::filesystem::directory_iterator itr(directory); itr != end_itr;
			++itr) {
		if (recursive && boost::filesystem::is_directory(itr->status())) {
			get_files(file_vector, itr->path().string(), recursive);
		} else {
			if (extension.empty()
					|| itr->path().extension().string() == extension) {
				if (get_name(itr->path().string())[0] != '.') { // ignore hidden files
					file_vector.push_back(itr->path().string());
				}
			}
		}
	}
}
Ejemplo n.º 22
0
GET_ADMIN( logs )( cr_connection& conn )
{
	cr_result r( conn );
	r.set_record_fields( g_log_fields );
	r.set_record_name( g_log_name );
	
	auto files = get_files( g_path_log );
	for( auto& file : files )
	{
		size_t len = file.length();
		if( len > 3 && !strcmp( &file[ len - 4 ], ".log" ) )
		{
			int64_t size = cr_file_size( g_path_log + file );
			file.resize( len - 4 );
			
			r.add_text( file );
			r.add_int( size );
		}
	}
	
	conn.respond( CR_HTTP_OK, r );
}
Ejemplo n.º 23
0
// Adds a command to the list of processes, ranked by parallelizability
void
add_command_t (command_t cmd, command_array **cmd_arr,  
          size_t *arr_size, size_t *arr_capacity)
{
  command_array cmd_info;

  cmd_info.command_tree = cmd;

  // Make the File Tree
  file_tree head = 0;
  get_files (cmd_info.command_tree, &head);
  cmd_info.files = head;

  // Check Size of the array, allocate more memory if needed
  if (*arr_capacity <= *arr_size)
    {
      size_t new_capacity = (*arr_capacity) * (sizeof (command_array));
      *cmd_arr = checked_grow_alloc (*cmd_arr, &new_capacity);
      *arr_capacity = new_capacity / (sizeof (command_array));
    }

  // Initialize new command_array element's command tree
  if (*arr_size != 0)
    {
      cmd_info.ranking = find_ranking (&cmd_info, cmd_arr, *arr_size);
      place_command_by_ranking (&cmd_info, cmd_arr, *arr_size);
    }
  else // The first command is always independent
    {
      cmd_info.ranking = 0;
      (*cmd_arr)[*arr_size] = cmd_info;
    }

  // Change Array Size
  (*arr_size)++;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
	FILE *fp;

	if (argc != 5)
		fail("usage: makepkg [key suffix] [version] filename.pkg dir_with_files");

	get_keys(argv[1]);
	get_files(argv[4]);
	get_version(argv[2]);

	build_pkg_hdr();
	compress_pkg();

	build_info_hdr();
	build_meta_hdr();
	build_sce_hdr();
	build_pkg();

	calculate_hashes();
	sign_hdr();

	sce_encrypt_data(pkg);
	sce_encrypt_header(pkg, &k);

	fp = fopen(argv[3], "wb");
	if (fp == NULL)
		fail("fopen(%s) failed", argv[3]);

	if (fwrite(pkg, pkg_size, 1, fp) != 1)
		fail("fwrite failed");

	fclose(fp);

	return 0;
}
Ejemplo n.º 25
0
Archivo: sized.c Proyecto: Tolchi/misc
int do_query(void) {
  int rc = -1;
  UT_array *files;
  UT_array *stats; 
  utarray_new(files,&ut_str_icd);
  utarray_new(stats,&stats_icd);
  if (get_files(files,stats) == -1) goto done;

  /* tally up their sizes */
  int64_t total_sz=0;
  file_stat_t *fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) total_sz += fs->sb.st_size;

  char tsz[100],csz[100];
  syslog(LOG_INFO,"directory size: %s (limit %s)", hsz(total_sz, tsz, sizeof(tsz)), 
                                      hsz(cf.sz_bytes, csz, sizeof(csz)));

  rc = 0;

 done:
  utarray_free(files);
  utarray_free(stats);
  return rc;
}
Ejemplo n.º 26
0
GtkWidget *
doodle_add_images (gchar *dir)
{
    int i;
    gchar *dirname;
    GtkWidget *table;
    GtkWidget *image;
    GtkWidget *ebox;
    GdkPixbuf *pixbuf;
    int r, c=2;
    int left, top;
    int w=50, h;

    dirname = dir;

    GArray *arr = get_files (dirname, FALSE, FALSE);

    r = (arr->len / c) + 1;
    table = gtk_table_new (r, c, TRUE);

    GString *mystr;
    for (i=0; i<arr->len; i++)
    {
        top = i / 2;
        left = i % 2;

        mystr = g_array_index (arr, GString*, i);
        image = gtk_image_new_from_file (mystr->str);
        pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (image));

        h = gdk_pixbuf_get_height (pixbuf) * 50 / (float)gdk_pixbuf_get_width (pixbuf);
        pixbuf = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR);

        gtk_widget_destroy (GTK_WIDGET (image));
        image = gtk_image_new_from_pixbuf (pixbuf);
        ebox = gtk_event_box_new ();
        gtk_widget_add_events (ebox, GDK_BUTTON_PRESS_MASK |
                                     GDK_BUTTON_RELEASE_MASK |
                                     GDK_POINTER_MOTION_MASK);

        //g_signal_connect (ebox, "button_press_event", G_CALLBACK (on_doodle_click_cb), mystr->str);

        // dnd
        gtk_drag_source_set (ebox,
                             GDK_BUTTON1_MASK,
                             TARGET_LIST,
                             N_TARGETS,
                             GDK_ACTION_COPY);
        g_signal_connect (ebox, "drag-data-get", G_CALLBACK (drag_data_get_handl),
                                                mystr->str + tbo_files_prefix_len (mystr->str));
        g_signal_connect (ebox, "drag-begin", G_CALLBACK (drag_begin_handl), mystr->str);
        g_signal_connect (ebox, "drag-end", G_CALLBACK (drag_end_handl), mystr->str);

        gtk_container_add (GTK_CONTAINER (ebox), image);
        gtk_table_attach_defaults (GTK_TABLE (table), ebox, left, left + 1, top, top + 1);
    }

    doodle_add_to_free (arr);

    gtk_widget_show_all (GTK_WIDGET (table));
    return table;
}
Ejemplo n.º 27
0
G_MODULE_EXPORT gboolean determine_ecu(GArray *tests, GHashTable *tests_hash)
{
	gboolean retval = TRUE;
	gint i = 0;
	Detection_Test *test = NULL;
	gint num_tests = tests->len;
	gboolean match = FALSE;
	gchar * filename = NULL;
	gchar ** filenames = NULL;
	GArray *classes = NULL;
	Firmware_Details *firmware = NULL;
	extern gconstpointer *global_data;

	filenames = get_files(g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),NULL),g_strdup("prof"),&classes);
	if (!filenames)
	{
		dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__": determine_ecu()\n\t NO Interrogation profiles found,  was MegaTunix installed properly?\n\n"));
		return FALSE;
	}

	i = 0;
	while (filenames[i])
	{
		if (check_for_match(tests_hash,filenames[i]))
		{
			match = TRUE;
			filename = g_strdup(filenames[i]);
			break;
		}
		i++;
	}
	g_strfreev(filenames);
	g_array_free(classes,TRUE);
	/* Update the screen with the data... */
	for (i=0;i<num_tests;i++)
	{
		test = g_array_index(tests,Detection_Test *,i);
		if (test->result_type == RESULT_DATA)
		{
			dbg_func_f(INTERROGATOR,g_strdup_printf("\tCommand (%s), returned %i byts\n",test->test_desc,test->num_bytes));
			thread_update_logbar_f("interr_view","info",g_strdup_printf("\tCommand (%s), returned %i bytes)\n",test->test_desc,test->num_bytes),FALSE,FALSE);
		}
		if (test->result_type == RESULT_TEXT)
		{
			dbg_func_f(INTERROGATOR,g_strdup_printf("\tCommand (%s), returned (%s)\n",test->test_desc,test->result_str));
			thread_update_logbar_f("interr_view","info",g_strdup_printf("\tCommand (%s), returned (%s)\n",test->test_desc,test->result_str),FALSE,FALSE);
		}
		else if (test->result_type == RESULT_LIST)
		{
			dbg_func_f(INTERROGATOR,g_strdup_printf("\tCommand (%s), returned %i elements\n",test->test_desc,g_list_length((GList *)test->result)));
			thread_update_logbar_f("interr_view","info",g_strdup_printf("\tCommand (%s), returned %i elements\n",test->test_desc,g_list_length((GList *)test->result)),FALSE,FALSE);
		}
	}
	if (match == FALSE) /* (we DID NOT find one) */
	{
		dbg_func_f(INTERROGATOR|CRITICAL,g_strdup(__FILE__":\n\tdetermine_ecu()\n\tFirmware NOT DETECTED, Enable Interrogation debugging, retry interrogation,\nclose megatunix, and send ~/MTXlog.txt to the author for analysis with a note\ndescribing which firmware you are attempting to talk to.\n"));
		update_logbar_f("interr_view","warning",g_strdup("Firmware NOT DETECTED, Enable Interrogation debugging, retry interrogation,\nclose megatunix, and send ~/MTXlog.txt to the author for analysis with a note\ndescribing which firmware you are attempting to talk to.\n"),FALSE,FALSE,TRUE);
		retval = FALSE;
	}
	else
	{
		if (!firmware)
		{
			firmware = g_new0(Firmware_Details,1);
			DATA_SET(global_data,"firmware",firmware);
		}

		if (!load_firmware_details(firmware,filename))
			retval = FALSE;
	}
	g_free(filename);
	return(retval);
}
Ejemplo n.º 28
0
EXPORT gboolean lookuptables_configurator(GtkWidget *widget, gpointer data)
{
	static gboolean ltc_created = FALSE;
	static GtkWidget * lookuptables_config_window = NULL;
	extern Firmware_Details *firmware;
	GtkListStore *store = NULL;
	GtkTreeStore *combostore = NULL;
	GtkTreeIter iter;
	GtkTreeIter per_iter;
	GtkTreeIter sys_iter;
	GtkCellRenderer *renderer = NULL;
	GtkTreeViewColumn *column = NULL;
	GtkWidget * vbox = NULL;
	GtkWidget * tree = NULL;
	GtkWidget * frame = NULL;
	ListElement *element = NULL;
	ConfigFile *cfgfile = NULL;
	GArray *classes = NULL;
	GList *p_list = NULL;
	GList *s_list = NULL;
	guint i = 0;
	gchar * tmpbuf = NULL;
	gchar ** vector = NULL;
	gchar ** tmpvector = NULL;

	if ((ltc_created) && (ltc_visible))
		return TRUE;
	if ((ltc_created) && (!ltc_visible))
	{
		gtk_widget_show_all(lookuptables_config_window);
		return TRUE;
	}
	else	/* i.e.  NOT created,  build it */
	{
		lookuptables_config_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
		gtk_window_set_title(GTK_WINDOW(lookuptables_config_window),_("MegaTunix LookupTables"));
		gtk_window_set_default_size(GTK_WINDOW(lookuptables_config_window),300,200);
		vbox = gtk_vbox_new(FALSE,0);
		gtk_container_add(GTK_CONTAINER(lookuptables_config_window),vbox);
		gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
		g_signal_connect(G_OBJECT(lookuptables_config_window),"delete_event", G_CALLBACK(lookuptables_configurator_hide),NULL);

		ltc_created = TRUE;
		ltc_visible = TRUE;
		frame = gtk_frame_new("MegaTunix LookupTables");
		gtk_box_pack_start (GTK_BOX(vbox),frame,FALSE,TRUE,5);
		vbox = gtk_vbox_new(FALSE,0);
		gtk_container_add(GTK_CONTAINER(frame),vbox);

		store = gtk_list_store_new(N_COLS,	/* total cols */
				G_TYPE_STRING, /* int name */
				G_TYPE_STRING, /* filename  combo*/
				G_TYPE_BOOLEAN,/* View/Edit */
				G_TYPE_BOOLEAN); /* change */

		combostore = gtk_tree_store_new(1,G_TYPE_STRING);/* lookuptable filename */
				
		gtk_tree_store_append(combostore,&per_iter,NULL);
		gtk_tree_store_append(combostore,&sys_iter,NULL);
		gtk_tree_store_set(combostore,&per_iter,
				0,"Personal", -1);
		gtk_tree_store_set(combostore,&sys_iter,
				0,"System", -1);
		vector = get_files(g_strdup(LOOKUPTABLES_DATA_DIR),g_strdup("inc"),&classes);
		for (i=0;i<g_strv_length(vector);i++)
		{
			tmpvector = g_strsplit(vector[i],PSEP,-1);
			if (g_array_index(classes,FileClass,i) == PERSONAL)
			{
				element = g_new0(ListElement, 1);
				element->name = g_strdup(tmpvector[g_strv_length(tmpvector)-1]);
				p_list = g_list_append(p_list,element);
			}
			if (g_array_index(classes,FileClass,i) == SYSTEM)
			{
				element = g_new0(ListElement, 1);
				element->name = g_strdup(tmpvector[g_strv_length(tmpvector)-1]);
				s_list = g_list_append(s_list,element);
			}
			g_strfreev(tmpvector);
		}
		g_strfreev(vector);
		g_array_free(classes,TRUE);
		p_list = g_list_sort(p_list,list_sort);
		s_list = g_list_sort(s_list,list_sort);
		for (i=0;i<g_list_length(p_list);i++)
		{
			gtk_tree_store_append(combostore,&iter,&per_iter);
			element = g_list_nth_data(p_list,i);
			gtk_tree_store_set(combostore,&iter,
					0,element->name,
					-1);
		}
		for (i=0;i<g_list_length(s_list);i++)
		{
			gtk_tree_store_append(combostore,&iter,&sys_iter);
			element = g_list_nth_data(s_list,i);
			gtk_tree_store_set(combostore,&iter,
					0,element->name,
					-1);
		}
		g_list_foreach(p_list,free_element,NULL);
		g_list_foreach(s_list,free_element,NULL);
		g_list_free(p_list);
		g_list_free(s_list);

		cfgfile = cfg_open_file(firmware->profile_filename);
		if (!cfgfile)
			return FALSE;
		cfg_read_string(cfgfile,"lookuptables","tables",&tmpbuf);
		vector = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
		for (i=0;i<g_strv_length(vector);i++)
		{
			cfg_read_string(cfgfile,"lookuptables",vector[i],&tmpbuf);
			gtk_list_store_append(store,&iter);
			gtk_list_store_set(store,&iter,
					INTERNAL_NAME_COL,vector[i],
					FILENAME_COL,tmpbuf,
					VIEW_EDIT_COL,FALSE,
					-1);
			g_free(tmpbuf);
		}
		g_strfreev(vector);

		tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
		gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree),TRUE);
		gtk_box_pack_start(GTK_BOX(vbox),tree,TRUE,TRUE,0);
		renderer = gtk_cell_renderer_text_new();
		column = gtk_tree_view_column_new_with_attributes("Internal Name",renderer,"text",INTERNAL_NAME_COL,NULL);
		gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);
		renderer = gtk_cell_renderer_combo_new();
		g_object_set(G_OBJECT(renderer),"editable",TRUE,"model",combostore,"text-column",0,"style",PANGO_STYLE_ITALIC,NULL);
		g_signal_connect(G_OBJECT(renderer),"edited", G_CALLBACK(lookuptable_change),store);
		column = gtk_tree_view_column_new_with_attributes("Table Filename",renderer,"text",FILENAME_COL,NULL);
		gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);

/*		renderer = gtk_cell_renderer_toggle_new();
		column = gtk_tree_view_column_new_with_attributes("View/Edit",renderer,"active",VIEW_EDIT_COL,NULL);
		gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);
		*/
		gtk_widget_show_all (lookuptables_config_window);
		gtk_tree_view_columns_autosize( GTK_TREE_VIEW(tree));
		return TRUE;
	}

}
Ejemplo n.º 29
0
/* The main function */
int main ( int argc, char *argv[] )
{
    int serverSock;				/* Server Socket */
    int clientSock;				/* Client Socket */
    struct sockaddr_in changeServAddr;		/* Local address */
    struct sockaddr_in changeClntAddr;		/* Client address */
    unsigned short changeServPort;		/* Server port */
    unsigned int clntLen;			/* Length of address data struct */
    DIR *dir;
    struct dirent *ent;
    char filepath[FILENAME_MAX];
    char filename[FILENAME_MAX];
    char rcvBuf[RCVBUFSIZE];
    char sndBuf[SNDBUFSIZE];
    char fileBuf[FILEBUFSIZE];
    char serverFiles[4096];
    char *curFile;
    MusicInfo rcvInfo;
    memset(&rcvInfo, 0, sizeof(rcvInfo));
    MusicInfo sndInfo;
    memset(&sndInfo, 0, sizeof(sndInfo));

    /* Create new TCP Socket for incoming requests*/
    if ( ( serverSock = socket ( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) < 0 )
    {
        exit ( 1 );
    }

    int on = 1;
    setsockopt ( serverSock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof ( on ) );
    memset ( &changeServAddr, 0, sizeof ( changeServAddr ) );
    changeServAddr.sin_family = AF_INET;
    changeServAddr.sin_addr.s_addr = htonl ( INADDR_ANY );
    changeServAddr.sin_port = htons ( 12003 );

    /* Bind to local address structure */
    if ( bind ( serverSock, ( struct sockaddr * ) &changeServAddr, sizeof ( changeServAddr ) ) < 0 )
    {
        perror ( "bind() failed." );
        exit ( 1 );
    }

    /* Listen for incoming connections */
    if ( listen ( serverSock, MAXPENDING ) < 0 )
    {
        perror ( "listen() failed." );
        exit ( 1 );
    }

    //char *rcvBuf = ( char * ) malloc ( RCVBUFSIZE );
    //char *sndBuf = ( char * ) malloc ( SNDBUFSIZE );

    /* Loop server forever*/
    while ( 1 )
    {
        /* Accept incoming connection */
        clientSock = accept ( serverSock, ( struct sockaddr * ) &changeClntAddr, &clntLen );
        if ( clientSock < 0 )
        {
            perror ( "accept() failed." );
            exit ( 1 );
        }

        int test = 0;
        while ( 1 )
        {
            memset ( rcvBuf, 0, RCVBUFSIZE );
            memset ( sndBuf, 0, SNDBUFSIZE );
	    memset(fileBuf, 0, FILEBUFSIZE);
            recv ( clientSock, rcvBuf, RCVBUFSIZE, 0 );

            /* Case list */

    	    if(Decode(rcvBuf, RCVBUFSIZE, &rcvInfo)) {
		printf("Request Type: %s\n", rcvInfo.requestType);
	    }
	    printf("Strcmp with list: %d\n", strcmp(rcvInfo.requestType, "list"));
	    printf("Strcmp with diff: %d\n", strcmp(rcvInfo.requestType, "diff"));
	    printf("Strcmp with pull: %d\n", strcmp(rcvInfo.requestType, "pull"));
	    printf("Request Type: %s\n", rcvInfo.requestType);
	    printf("Song Names: %s\n", rcvInfo.songNames);
	    printf("Song IDs: %s\n", rcvInfo.songIDs);
	    printf("End of file? %c\n", rcvInfo.eof);
	    printf("Terminate? %c\n", rcvInfo.terminate);

            if ( strcmp ( rcvInfo.requestType, "list" ) == 0 )
            {
		printf("Inside if statement\n");
                if ( ( dir= opendir ( "./repo" ) ) != NULL )
                {
                    while ( ( ent = readdir ( dir ) ) != NULL )
                    {

                        char *d_name = ent->d_name;
                        if ( *d_name != '.' && strcmp ( d_name, ".." ) != 0 )
                        {
                            strcat ( sndInfo.songNames, d_name );
                            strcat ( sndInfo.songNames, "|" );
                        }
                    }

                    closedir ( dir );
                }

                //strcat ( sndBuf, "\0" );
		strcpy(sndInfo.requestType, rcvInfo.requestType);
	        strcpy(sndInfo.songIDs, " ");
	        strcpy(sndInfo.fileData, " ");
		sndInfo.eof = 1;
		sndInfo.terminate = 1;
		size_t responseSize = Encode(&sndInfo, sndBuf, SNDBUFSIZE);
		printf("sndBuf: %s\n", sndBuf);
                send ( clientSock, sndBuf, SNDBUFSIZE, 0 );
            }	// end of list


	    else if ( strcmp ( rcvInfo.requestType, "diff" ) == 0 )
            {
                if ( ( dir= opendir ( "./repo" ) ) != NULL )
                {
                    while ( ( ent = readdir ( dir ) ) != NULL )
                    {

                        char *d_name = ent->d_name;
                        if ( *d_name != '.' && strcmp ( d_name, ".." ) != 0 )
                        {
                            strcat ( sndInfo.songNames, d_name );
                            strcat ( sndInfo.songNames, "|" );
                        }
                    }

                    closedir ( dir );
                }

                //strcat ( sndBuf, "\0" );
		strcpy(sndInfo.requestType, rcvInfo.requestType);
	        strcpy(sndInfo.songIDs, " ");
	        strcpy(sndInfo.fileData, " ");
		sndInfo.eof = 1;
		sndInfo.terminate = 1;
		size_t responseSize = Encode(&sndInfo, sndBuf, SNDBUFSIZE);
		printf("sndBuf: %s\n", sndBuf);
                send ( clientSock, sndBuf, SNDBUFSIZE, 0 );
            }	// end of list
	    /*else if ( strcmp ( rcvInfo.requestType, "diff" ) == 0 ) {
		printf("Diff requested\n");
		fflush(stdout);
		get_files(dir, ent, serverFiles);
		
	    }*/

            /* Case pull */
            else if ( strcmp ( rcvInfo.requestType, "pull" ) == 0 )
            {
                /* Get array of file names */
                get_files ( dir, ent, serverFiles );

                curFile = strtok ( serverFiles, "\n" );
                while ( curFile != NULL )
                {
                    printf ( "curFile = %s\n", curFile );
                    memset ( sndBuf, 0, SNDBUFSIZE );
                    memset ( filename, 0, FILENAME_MAX );
                    memset ( filepath, 0, FILENAME_MAX );

                    strcat ( filename, curFile );
                    strcat ( filepath, SERVER_DIR );
                    strcat ( filepath, filename );
                    FILE *fp = fopen ( filepath, "r" );

                    /* Send file name first */
                    strcat ( sndBuf, filename );
                    send ( clientSock, sndBuf, SNDBUFSIZE, 0 );

                    if ( fp != NULL )
                    {
                        /* Read the file into sndBuf */
                        while ( fread ( sndBuf, sizeof ( char ), SNDBUFSIZE, fp ) > 0 )
                        {
                            send ( clientSock, sndBuf, SNDBUFSIZE, 0 );
                            memset ( sndBuf, 0, SNDBUFSIZE );
                        }

                        /* Designate end of file */
                        send ( clientSock, "\0", 1, 0 );

                        fclose ( fp );
                    }

                    /* Get next one */
                    curFile = strtok ( NULL, "\n" );
                }
                printf ( "Done sending files.\n" );

            }	// end of pull
        }

        close ( clientSock );
    }

    free ( rcvBuf );
    free ( sndBuf );

}
Ejemplo n.º 30
0
int main (int argc, char **argv) 
{
FILE	*imagefile, *ldrfile;
FILE	*rawfile[11], *prmfile[11];
char	prmfilename[128];
int	nPRF;
long	byte_offset;
int     nsub = 3, burst_skip = 0, num_burst = 1000 ;
struct PRM prm;
struct ALOS_ORB orb;

	if (argc < 3) die (USAGE,"");

	/* set flags  */
	dopp = 0;
	debug = verbose = swap = quiet_flag = 0;

	nPRF = 0;

	null_sio_struct(&prm);
	set_ALOS_defaults(&prm);

	/* read command line */
	parse_ALOS_commands(argc, argv, USAGE, &prm, &nsub, &burst_skip, &num_burst);

	if (verbose) print_ALOS_defaults(&prm);
	if (is_big_endian_() == -1) {swap = 1;fprintf(stderr,".... swapping bytes\n");} else {swap = 0;} 

	/* IMG and LED files should exist already */
	if ((imagefile = fopen(argv[1], "r")) == NULL) die ("couldn't open Level 1.0 IMG file \n",argv[1]);
	if ((ldrfile = fopen(argv[2], "r")) == NULL) die ("couldn't open LED file \n",argv[2]); 

	/* if it exists, copy to prm structure */
	strcpy(prm.led_file,argv[2]);

	/* name and open output files and header files for raw data (but input for later processing) */
	get_files(&prm, &rawfile[nPRF], &prmfile[nPRF], prmfilename, argv[1], nPRF, nsub+1);

	/* read sarleader; put info into prm; write log file if specified 		*/
	read_ALOS_sarleader(ldrfile, &prm, &orb);

	/* read Level 1.0 file;  put info into prm; convert to *.raw format 		*/
	/* if PRF changes halfway through, create new set of header and data files      */
	/* byte_offset is non-zero only if the prf changes				*/
	/* byte_offset gets set to point in file at prf change				*/

	byte_offset = -1;

	/* set the chirp extension to 500 if FBD  or WB1 fs = 16000000 */
       	if (prm.fs < 17000000.) prm.chirp_ext = 500;

	/* check to be sure the burst_skip*1559 lines does not exceed the file size */
        if (burst_skip*1559 > 100000) fprintf(stderr," warning skip could exceed the length of the file \n");

	/* read_ALOS_data returns 0 if all data file is read;
	returns byte offset if the PRF changes  */
	byte_offset = read_ALOS_data_SS(imagefile, rawfile[nPRF], &prm, &byte_offset, &nsub, &burst_skip, &num_burst);

	/* calculate parameters from orbit */
	ALOS_ldr_orbit(&orb, &prm);

	/* calculate doppler from raw file */
	if (dopp == 1) calc_dop(&prm);

	/* write ascii output, SIO format */
	put_sio_struct(prm, prmfile[nPRF]);

	return(EXIT_SUCCESS);
}