コード例 #1
0
ファイル: print_recursive.c プロジェクト: w0dm4n/ft_ls
void		print_recursive(char **files, char *flags, char *folder, int i)
{
	char			**path;
	struct stat		*file_stat;
	int				boolean;

	if (!files || !files[0] || !ft_strlen(files[0]))
		return ;
	boolean = 0;
	if (!(path = malloc(sizeof(char*) * ALL_RECURSIVE_POSSIBILITY)))
		return ;
	path = ft_set_null(path);
	print_total(files, flags, folder);
	while (files[i])
	{
		if (!(file_stat = get_file_stat(files[i], file_stat, folder)))
			return ;
		print_by_flags(file_stat, flags, files, i);
		if (S_ISDIR(file_stat->st_mode) && files[i][0] != '.' && (boolean += 1))
			path = new_dir(path, files[i]);
		free(file_stat);
		i++;
	}
	ft_putstr("\n");
	free_files(files);
	(boolean) ? recursive_if(path, folder, flags) : free_files(path);
}
コード例 #2
0
ファイル: ft_earth.c プロジェクト: Probin42/ft_ls
void		ft_ls_dir2(t_flag flag, t_item *list, int multidir, char *tmp)
{
	DIR		*dir;
	t_item	*files;
	int		start;

	start = 0;
	files = NULL;
	while (list)
	{
		dir = opendir(list->name);
		while (ft_get_item(&files, readdir(dir),
					ft_strjoin(list->path, "/"), flag) != 0)
			;
		closedir(dir);
		if (files)
		{
			start == 1 ? ft_putchar('\n') : NULL;
			tmp = ft_strjoin(list->name, ":");
			multidir ? ft_putendl(tmp) : NULL;
			ft_strdel(&tmp);
			start = 1;
			ft_displayfile(flag, files, 1);
		}
		free_files(&files);
		list = list->next;
	}
}
コード例 #3
0
ファイル: print_recursive.c プロジェクト: w0dm4n/ft_ls
void		recursive_if(char **path, char *folder, char *flags)
{
	int				i;
	char			*rl;
	struct stat		*file_stat;

	i = 0;
	rl = ft_strnew(DEFAULT_BUFFER);
	while (path[i])
	{
		ft_bzero(rl, DEFAULT_BUFFER);
		rl = realpath(folder, rl);
		rl = ft_strcat(rl, "/");
		rl = ft_strcat(rl, path[i]);
		rl = ft_strcat(rl, "/");
		if (!(file_stat = get_file_stat(path[i], file_stat, folder)))
			return ;
		ft_putstr(rl);
		ft_putstr(":\n");
		print_recursive(get_specified_dir(rl, flags), flags, rl, 0);
		free(file_stat);
		i++;
	}
	free(rl);
	free_files(path);
}
コード例 #4
0
ファイル: task.c プロジェクト: ezc/elinks
/** If @a loaded_in_frame is set, this was called just to indicate a move inside
 * a frameset, and we basically just reset the appropriate frame's view_state in
 * that case. When clicking on a link inside a frame, the frame URI is somehow
 * updated and added to the files-to-load queue, then ses_forward() is called
 * with @a loaded_in_frame unset, duplicating the whole frameset's location,
 * then later the file-to-load callback calls it for the particular frame with
 * @a loaded_in_frame set. */
struct view_state *
ses_forward(struct session *ses, int loaded_in_frame)
{
	struct location *loc = NULL;
	struct view_state *vs;

	if (!loaded_in_frame) {
		free_files(ses);
		mem_free_set(&ses->search_word, NULL);
	}

x:
	if (!loaded_in_frame) {
		loc = mem_calloc(1, sizeof(*loc));
		if (!loc) return NULL;
		copy_struct(&loc->download, &ses->loading);
	}

	if (ses->task.target.frame && *ses->task.target.frame) {
		struct frame *frame;

		assertm(have_location(ses), "no location yet");
		if_assert_failed return NULL;

		if (!loaded_in_frame) {
			copy_location(loc, cur_loc(ses));
			add_to_history(&ses->history, loc);
		}

		frame = ses_find_frame(ses, ses->task.target.frame);
		if (!frame) {
			if (!loaded_in_frame) {
				del_from_history(&ses->history, loc);
				destroy_location(loc);
			}
			mem_free_set(&ses->task.target.frame, NULL);
			goto x;
		}

		vs = &frame->vs;
		if (!loaded_in_frame) {
			destroy_vs(vs, 1);
			init_vs(vs, ses->loading_uri, vs->plain);
		} else {
			done_uri(vs->uri);
			vs->uri = get_uri_reference(ses->loading_uri);
			if (vs->doc_view) {
				/* vs->doc_view itself will get detached in
				 * render_document_frames(), but that's too
				 * late for us. */
				vs->doc_view->vs = NULL;
				vs->doc_view = NULL;
			}
#ifdef CONFIG_ECMASCRIPT
			vs->ecmascript_fragile = 1;
#endif
		}

	} else {
コード例 #5
0
ファイル: ls.c プロジェクト: 2014-class/freerouter
static int
list_dir(FILE *out, const char *directory, int flags)
{
    DIR *d = opendir(directory);
    struct dirent *ent;
    char **files = NULL;
    int n_files = 0;
    int ret;

    if(d == NULL) {
	syslog(LOG_ERR, "%s: %m", directory);
	return -1;
    }
    while((ent = readdir(d)) != NULL) {
	void *tmp;

	if(hide_file(ent->d_name, flags))
	    continue;
	tmp = realloc(files, (n_files + 1) * sizeof(*files));
	if (tmp == NULL) {
	    syslog(LOG_ERR, "%s: out of memory", directory);
	    free_files (files, n_files);
	    closedir (d);
	    return -1;
	}
	files = tmp;
	ret = asprintf(&files[n_files], "%s/%s", directory, ent->d_name);
	if (ret == -1) {
	    syslog(LOG_ERR, "%s: out of memory", directory);
	    free_files (files, n_files);
	    closedir (d);
	    return -1;
	}
	++n_files;
    }
    closedir(d);
    return list_files(out, (const char**)files, n_files, flags | LS_DIR_FLAG);
}
コード例 #6
0
void reload_button_clicked( GtkWidget *widget, gpointer data) {

  pthread_mutex_lock(&loading_mutex);

  if( !loading ) {
    loading = TRUE;
    pthread_mutex_unlock(&loading_mutex);

    free_folders();
    free_files();

    read_config(auto_clear_tags);

    /* load the folders, and clear the tags database */
    load_folders_threaded(TRUE);
  } else
    pthread_mutex_unlock(&loading_mutex);
}
コード例 #7
0
ファイル: spca50x-flash.c プロジェクト: ryanstout/libgphoto2
/*
 * Deinit camera
 */
int
spca50x_flash_close (CameraPrivateLibrary *pl, GPContext *context)
{
	if (pl->fw_rev == 1) {
		CHECK (gp_port_usb_msg_write (pl->gpdev, 0x00, 0x01, 0x2306,
					NULL, 0x00));
		CHECK (gp_port_usb_msg_write (pl->gpdev, 0x00, 0x00, 0x0d04,
					NULL, 0x00));
	} else {
		/* Anything we need to do? */

	}

	if (!pl->dirty_flash && pl->bridge == BRIDGE_SPCA500) {
		/* check if we need to free the file info buffers */
		free_files(pl);
	}
	pl->dirty_flash = 1;
	return GP_OK;
}
コード例 #8
0
ファイル: gpasm.c プロジェクト: jdelgadoalfonso/gputils
int main( int argc, char *argv[] )
{
  extern char *optarg;
  extern int optind;
  int c;
  int usage = 0;
  int memory_dump = 0;
  int dos_newlines = 0;
  char *pc;
  int  cmd_processor = 0;
  char *processor_name = NULL;

  state.i_memory = i_memory_create();
  
  state.pass = 0;
  state.quiet = 0;

  #ifdef PARSE_DEBUG
  {
    extern int yydebug;
    yydebug = 1; /* enable parse debug */
  }
  #endif

  #ifdef USE_GPASM_HEADER_PATH
    /* add the header path to the include paths list */
    #ifndef __MSDOS__
      include_paths[n_include_paths++] = GPASM_HEADER_PATH;
    #else
      include_paths[n_include_paths++] = "c:\\gputils\\header";    
    #endif
  #endif

  while ((c = GETOPT_FUNC) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = 1;
      break;
    case 'a':
      select_hexformat(optarg);
      state.cmd_line.hex_format = 1;
      break;
    case 'c':
      state.case_insensitive = 1;
      if (state.stDefines != NULL) {
        printf("Warning: The -c option must be called before the -d option.\n");
      }
      break;
    case 'D':
    case 'd':
      if ((optarg != NULL) && (strlen(optarg) > 0)) {
	struct symbol *sym;
	char *lhs, *rhs;

        /* the Defines symbol table is not yet defined*/
        if (state.stDefines == NULL) {
          state.stDefines = push_symbol_table(NULL, state.case_insensitive);
        }

	lhs = strdup(optarg);
	rhs = strchr(lhs, '=');
	if (rhs != NULL) {
	  *rhs = '\0';	/* Terminate the left-hand side */
	  rhs++;	/* right-hand side begins after the '=' */
	}

	sym = get_symbol(state.stDefines, lhs);
	if (sym == NULL)
	  sym = add_symbol(state.stDefines, lhs);
	if (rhs)
	  annotate_symbol(sym, rhs);
      }
      break;
    case 'e':
      select_expand(optarg);
      state.cmd_line.macro_expand = 1;
      break;
    case 'I':
       if(n_include_paths < MAX_INCLUDE_PATHS) {
 	 include_paths[n_include_paths++] = optarg;
       } else {
 	 fprintf(stderr, "too many -I paths\n");
 	 exit(1);
       }
       break;    
 
    case 'l':
      dump_processor_list();
      exit(0);
      break;
    case 'm':
      memory_dump = 1;
      break;
    case 'n':
      #ifndef __MSDOS__
        dos_newlines = 1;
      #endif
      break;
    case 'o':
	    strcpy(state.hexfilename, optarg);
	    strcpy(state.basefilename, optarg);
	    pc = strrchr(state.basefilename, '.');
	    if (pc)
		   *pc = 0;
      break;
    case 'p':
      cmd_processor = 1;
      processor_name = optarg;
      break;
    case 'q':
      state.quiet = 1;
      break;
    case 'r':
      select_radix(optarg);
      state.cmd_line.radix = 1;
      break;
    case 'w':
      select_errorlevel(atoi(optarg));
      state.cmd_line.error_level = 1;
      break;
    case 'v':
      fprintf(stderr, "%s\n", GPASM_VERSION_STRING);
      exit(0);
      
    }
    if (usage)
      break;
  }
  
  if (optind < argc)
    state.srcfilename = argv[optind];
  else
    usage = 1;

  if (usage) {
    show_usage();
  }

  if(state.basefilename[0] == '\0') {
	  strcpy(state.basefilename, state.srcfilename);
	  pc = strrchr(state.basefilename, '.');
	  if (pc)
		  *pc = 0;
  }

  /* the Defines symbol table is not yet defined*/
  if (state.stDefines == NULL) {
    state.stDefines = push_symbol_table(NULL, state.case_insensitive);
  }

  /* Builtins are always case insensitive */
  state.stBuiltin = push_symbol_table(NULL, 1);
  state.stDirective = state.stBuiltin;
  state.stMacros = push_symbol_table(NULL, state.case_insensitive);
  state.stTop = 
    state.stGlobal = push_symbol_table(NULL, state.case_insensitive);

  opcode_init(0);

  /* the tables are built, select the processor if -p was used */
  if (cmd_processor) {
    select_processor(processor_name);
    state.cmd_line.processor = 1;
  }

  state.maxram = (MAX_RAM - 1);

  open_src(state.srcfilename, 0);
  state.pass = 1;
  yyparse();
 
  open_src(state.srcfilename, 0);
  state.pass++;
  state.org = 0;
  state.cblock = 0;
  if (state.cmd_line.radix != 1)
    state.radix = 16;
  cod_init();
  lst_init();
  yyparse();

  assert(state.pass == 2);
  
  pop_symbol_table(state.stBuiltin);
  
  if (check_writehex(state.i_memory, state.hex_format)) {
    gperror(GPE_IHEX,NULL); 
  } else {
    int byte_words;
    
    if (state.device.core_size > 0xff) {
      byte_words = 0;
    } else {
      byte_words = 1;
      if (state.hex_format != inhx8m) {
        gpwarning(GPW_UNKNOWN,"Must use inhx8m format for EEPROM8");
        state.hex_format = inhx8m;
      }
    }
    
    if (writehex(state.basefilename, state.i_memory, 
                 state.hex_format, state.num.errors,
                 byte_words, dos_newlines)) {
      gperror(GPE_UNKNOWN,"Error generating hex file");
    }
  }

  if(memory_dump)
    print_i_memory(state.i_memory);

  /* Maybe produce a symbol table */
  if (state.lst.symboltable) {
    lst_throw(); /* Start symbol table on a fresh page */
    lst_symbol_table(state.stGlobal);
    lst_defines_table(state.stDefines);
  }

  /* Maybe produce a memory map */
  if (state.lst.memorymap) {
    lst_memory_map(state.i_memory);
  }
  
  /* Finish off the listing and symbol files*/
  lst_close();
  if (state.processor_info)
    cod_close_file();
  free_files();

  if (state.num.errors > 0)
    return 1;
  else
    return 0;
}
コード例 #9
0
ファイル: main.c プロジェクト: KirovAir/swiss-gc
void main_loop()
{ 	
	while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); }
	// We don't care if a subsequent device is "default"
	if(needsDeviceChange) {
		free_files();
		if(deviceHandler_deinit) {
			deviceHandler_deinit(deviceHandler_initial);
		}
		if (forceSlot) {
			deviceHandler_FAT_deinit(&initial_SD1);
		}
		curDevice = -1;
		needsDeviceChange = 0;
		deviceHandler_initial = NULL;
		needsRefresh = 1;
		curMenuLocation = ON_FILLIST;
		select_device(0);
		if (curDevice == WKF)  {
			trySlotB();
		}
		curMenuLocation = ON_OPTIONS;
	}
	
	if(deviceHandler_initial) {
		// If the user selected a device, make sure it's ready before we browse the filesystem
		deviceHandler_deinit( deviceHandler_initial );
		sdgecko_setSpeed(EXI_SPEED32MHZ);
		if(!deviceHandler_init( deviceHandler_initial )) {
			if(((deviceHandler_initial->name[0] == 's')&&(deviceHandler_initial->name[1] == 'd'))||(deviceHandler_initial->name[0] == 'i')) {
				print_gecko("SD/IDE-EXI Device Failed to initialize @ 32MHz!\r\nTrying again once @ 16MHz...\r\n");
				sdgecko_setSpeed(EXI_SPEED16MHZ);
				if(!deviceHandler_init(deviceHandler_initial)) {
				// Try the alternate slot for SDGecko or IDE-EXI
					if(deviceHandler_initial->name[0] == 's')
						deviceHandler_initial = (deviceHandler_initial == &initial_SD0) ?
												&initial_SD1:&initial_SD0;
					else
						deviceHandler_initial = (deviceHandler_initial == &initial_IDE0) ?
												&initial_IDE1:&initial_IDE0;
					memcpy(&curFile, deviceHandler_initial, sizeof(file_handle));
				}
				print_gecko("Trying alternate slot @ 32MHz...\r\n");
				sdgecko_setSpeed(EXI_SPEED32MHZ);
				if(!deviceHandler_init( deviceHandler_initial )) {
					print_gecko("Alternate slot failed once @ 16MHz... \r\n");
					sdgecko_setSpeed(EXI_SPEED16MHZ);
					if(!deviceHandler_init( deviceHandler_initial )) {
						print_gecko("Both slots failed twice\r\n");
						needsDeviceChange = 1;
						return;
					}
				}
			}
		}
		if(curDevice==SD_CARD || curDevice==WKF || curDevice==IDEEXI) { 
			load_config(forceSlot);
		}
	}
	else {
		curMenuLocation=ON_OPTIONS;
	}
	// If a previously undetected device has been successfully init'd, mark it as available from now on
	if(!deviceHandler_getDeviceAvailable(curDevice)) {
		deviceHandler_setDeviceAvailable(curDevice, 1);
	}
  
	while(1) {
		if(deviceHandler_initial && needsRefresh) {
			curMenuLocation=ON_OPTIONS;
			free_files();
			curSelection=0; files=0; curMenuSelection=0;
			// Read the directory/device TOC
			if(allFiles){ free(allFiles); allFiles = NULL; }
			print_gecko("Reading directory: %s\r\n",curFile.name);
			files = deviceHandler_readDir(&curFile, &allFiles, -1);
			memcpy(&curDir, &curFile, sizeof(file_handle));
			sortFiles(allFiles, files);
			print_gecko("Found %i entries\r\n",files);
			if(files<1) { deviceHandler_deinit(deviceHandler_initial); needsDeviceChange=1; break;}
			needsRefresh = 0;
			curMenuLocation=ON_FILLIST;
		}
		while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); }
		drawFiles(&allFiles, files);

		u16 btns = PAD_ButtonsHeld(0);
		if(curMenuLocation==ON_OPTIONS) {
			if(btns & PAD_BUTTON_LEFT){	curMenuSelection = (--curMenuSelection < 0) ? (MENU_MAX-1) : curMenuSelection;}
			else if(btns & PAD_BUTTON_RIGHT){curMenuSelection = (curMenuSelection + 1) % MENU_MAX;	}
		}
		if(deviceHandler_initial && ((btns & PAD_BUTTON_B)||(curMenuLocation==ON_FILLIST)))	{
			while(PAD_ButtonsHeld(0) & PAD_BUTTON_B){ VIDEO_WaitVSync (); }
			curMenuLocation=ON_FILLIST;
			renderFileBrowser(&allFiles, files);
		}
		else if(btns & PAD_BUTTON_A) {
			//handle menu event
			switch(curMenuSelection) {
				case 0:		// Device change
					needsDeviceChange = 1;  //Change from SD->DVD or vice versa
					break;
				case 1:		// Settings
					show_settings(NULL, NULL);
					break;
				case 2:		// Credits
					show_info();
					break;
				case 3:
					if(deviceHandler_initial) {
						memcpy(&curFile, deviceHandler_initial, sizeof(file_handle));
						if(curDevice == WKF) { 
							wkfReinit(); deviceHandler_deinit(deviceHandler_initial);
						}
					}
					needsRefresh=1;
					break;
				case 4:
					__libogc_exit(0);
					break;
			}
			
		}
		while (!(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_A) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT))) {
			VIDEO_WaitVSync();
		}
		if(needsDeviceChange) {
			break;
		}
	}
}
コード例 #10
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
stormfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
    off_t offset, struct fuse_file_info *fi)
{
  int result;
  struct file *dir;
  GList *files = NULL, *head = NULL, *next = NULL;

  DEBUG("readdir: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  filler(buf, ".",  0, 0);
  filler(buf, "..", 0, 0);

  dir = cache_get(path);
  if(cache_valid(dir) && dir->dir != NULL) {
    pthread_mutex_lock(&dir->lock);
    head = g_list_first(dir->dir);
    while(head != NULL) {
      next = head->next;
      struct file *f = head->data;
      filler(buf, (char *) f->name, f->st, 0);
      head = next;
    }
    pthread_mutex_unlock(&dir->lock);
    return 0;
  }

  if((result = proxy_readdir(path, &files)) != 0)
    return result;

  result = proxy_getattr_multi(path, files);

  pthread_mutex_lock(&dir->lock);
  head = g_list_first(files);
  while(head != NULL) {
    next = head->next;
    // FIXME: list_bucket is using the same structure (file) as
    // the cache which makes the code below confusing.
    struct file *file = head->data;
    char *fullpath = get_path(path, file->name);
    struct file *f = cache_get(fullpath);
    free(fullpath);

    pthread_mutex_lock(&f->lock);
    if(f->st == NULL)
      f->st = g_new0(struct stat, 1);
    memcpy(f->st, file->st, sizeof(struct stat));
    f->st->st_nlink = 1;
    cache_touch(f);
    pthread_mutex_unlock(&f->lock);

    filler(buf, (char *) f->name, f->st, 0);
    dir->dir = g_list_append(dir->dir, f);

    head = next;
  }
  pthread_mutex_unlock(&dir->lock);

  free_files(files);

  return result;
}
コード例 #11
0
ファイル: gpasm.c プロジェクト: jdelgadoalfonso/gputils
int
assemble(void)
{
  char *pc; 
  struct symbol_table *cmd_defines;

  /* store the command line defines to restore on second pass */
  cmd_defines = state.stDefines;
  state.c_memory = state.i_memory = i_memory_create();

  if(state.basefilename[0] == '\0') {
    strcpy(state.basefilename, state.srcfilename);
    pc = strrchr(state.basefilename, '.');
    if (pc)
      *pc = 0;
  }

  /* Builtins are always case insensitive */
  state.stBuiltin = push_symbol_table(NULL, 1);
  state.stDirective = state.stBuiltin;
  state.stMacros = push_symbol_table(NULL, state.case_insensitive);
  state.stTop = 
    state.stGlobal = push_symbol_table(NULL, state.case_insensitive);
  state.stTopDefines = 
    state.stDefines = push_symbol_table(cmd_defines, state.case_insensitive);

  opcode_init(0);

  /* the tables are built, select the processor if -p was used */
  if (cmd_processor) {
    select_processor(processor_name);
    state.cmd_line.processor = 1;
  }

  state.pass = 1;
  open_src(state.srcfilename, 0);
  yyparse();
 
  state.pass++;
  state.org = 0;
  state.cblock = 0;
  /* clean out defines for second pass */
  state.stTopDefines = 
    state.stDefines = push_symbol_table(cmd_defines, state.case_insensitive);
  if (state.cmd_line.radix != 1)
    state.radix = 16;
  state.obj.symbol_num = 0;
  state.obj.section_num = 0;
  state.obj.org_num = 0;
  state.found_config = 0;
  state.found_devid = 0;
  state.found_idlocs = 0;
  coff_init();
  cod_init();
  lst_init();
  open_src(state.srcfilename, 0);
  yyparse();

  assert(state.pass == 2);
  
  pop_symbol_table(state.stBuiltin);
  
  hex_init();

  if(state.memory_dump)
    print_i_memory(state.i_memory, 
                   state.device.class == PROC_CLASS_PIC16E ? 1 : 0);

  /* Maybe produce a symbol table */
  if (state.lst.symboltable) {
    lst_throw(); /* Start symbol table on a fresh page */
    lst_symbol_table(state.stGlobal);
    lst_defines_table(state.stDefines);
  }

  /* Maybe produce a memory map */
  if ((state.mode == absolute) && (state.lst.memorymap)) {
    lst_memory_map(state.i_memory);
  }
  
  /* Finish off the object, listing, and symbol files*/
  coff_close_file();
  lst_close();
  if (state.processor_info)
    cod_close_file();
  free_files();

  if ((state.num.errors > 0) ||
      (gp_num_errors > 0))
    return EXIT_FAILURE;
  else
    return EXIT_SUCCESS;
}
コード例 #12
0
ファイル: tardiffmerge.c プロジェクト: maksverver/tardiff
int tardiffmerge(int argc, char *argv[], char *flags)
{
    int n, num_diffs;
    struct File *files, *file;
    bool input_ok, output_ok, order_files;

    num_diffs = argc - 1;
    input_ok = output_ok = false;
    order_files = (strchr(flags, 'f') == NULL);

    /* Verify arguments are all diff files: */
    input_ok = identify_files((const char**)argv, num_diffs, NULL, &files);
    for (file = files; file != NULL; file = file->next)
    {
        if (file->type == FILE_INVALID)
        {
            fprintf(stderr, "%s: %s\n", file->path, file->invalid.error);
        }
        else
        if (file->type != FILE_DIFF)
        {
            fprintf(stderr, "%s: not a differences file\n", file->path);
            input_ok = false;
        }
        else  /* file->type == FILE_DIFF */
        {
            static uint8_t zero_digest[DS];
            if (order_files &&
                memcmp(file->diff.digest1, zero_digest, DS) == 0)
            {
                fprintf(stderr, "Input contains version 1.0 difference files; "
                                "merge order cannot be determined.\n");
                input_ok = false;
            }
        }
    }

    if (input_ok && order_files)
    {
        mark_usable(files);
        if (!order_input(&files))
        {
            fprintf(stderr, "Input files could not be ordered!\n");
            input_ok = false;
        }
    }

    if (input_ok)
    {
        /* Redirect output (if necessary) */
        if (strcmp(argv[argc - 1], "-") != 0) redirect_stdout(argv[argc - 1]);

        n = 0;
        for (file = files; file != NULL; file = file->next)
        {
            InputStream *is;
            char magic[MAGIC_LEN];

            /* Try to open again */
            is = OpenFileInputStream(file->path);
            if (is == NULL)
            {
                fprintf(stderr, "%s: could not be opened.\n", file->path);
                break;
            }

            /* Save pointer here, so we can close it later. */
            is_diff[n++] = is;

            /* Verify magic again */
            read_data(is, magic, MAGIC_LEN);
            if (memcmp(magic, MAGIC_STR, MAGIC_LEN) != 0)
            {
                fprintf(stderr, "%s: not a differences file\n", file->path);
                break;
            }

            /* Process entire file */
            process_input(is);
        }

        if (file == NULL)
        {
            output_ok = generate_output();
        }

        /* Close open streams: */
        while (n-- > 0) is_diff[n]->close(is_diff[n]);

        munmap(last_blocks, last_num_blocks*sizeof(BlockRef));
    }
    free_files(files);

    return (input_ok && output_ok) ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #13
0
ファイル: spca50x-flash.c プロジェクト: ryanstout/libgphoto2
int
spca50x_flash_get_TOC(CameraPrivateLibrary *pl, int *filecount)
{
	uint16_t n_toc_entries;
	int toc_size = 0;
	if (pl->dirty_flash == 0){
		/* TOC has been read already, and stored in the pl,
		   so let's not read it again unless "dirty" gets set,
		   e.g. by a reset, delete or capture action... */
		*filecount = pl->num_files_on_flash;
		return GP_OK;
	}
	pl->num_files_on_flash = 0;

	if (pl->bridge == BRIDGE_SPCA500) { /* for dsc350 type cams */
				/* command mode */
		CHECK (gp_port_usb_msg_write (pl->gpdev,
					0x00, 0x0080, 0x0100,
					NULL, 0x00));
		/* trigger TOC upload */
		CHECK (gp_port_usb_msg_write (pl->gpdev,
					0x05, 0x0000, 0x000d,
					NULL, 0x00));
		toc_size = 0x100; /* always 256 for the dsc-350 cams */
	} else {

		if (pl->fw_rev == 1) {
			CHECK (gp_port_usb_msg_read (pl->gpdev,
						0x0b, 0x0000, 0x0000,
						(char*)&n_toc_entries, 0x02));
			/* Each file gets two toc entries, one for the image,
			   one for the thumbnail */
			LE16TOH (n_toc_entries);
			*filecount = n_toc_entries/2;
		} else {
			CHECK (gp_port_usb_msg_read (pl->gpdev,
						0x54, 0x0000, 0x0000,
						(char*)&n_toc_entries, 0x02));
			LE16TOH (n_toc_entries);
			*filecount = n_toc_entries;
		}
		/* If empty, return now */
		if (n_toc_entries == 0)
			return GP_OK;

		/* Request the TOC */
		if (pl->fw_rev == 1) {
			CHECK (gp_port_usb_msg_read (pl->gpdev, 0x0a,
						n_toc_entries, 0x000c,
						NULL, 0x00));
		} else {
			CHECK (gp_port_usb_msg_read (pl->gpdev, 0x54,
						n_toc_entries, 0x0001,
						NULL, 0x00));
		}
		/* slurp it in. Supposedly there's 32 bytes in each entry. */
		toc_size = n_toc_entries * 32;

		/* align */
		if (toc_size % 512 != 0)
			toc_size = ((toc_size / 512) + 1) * 512;
	}
	if (pl->flash_toc)
		free (pl->flash_toc);
	pl->flash_toc = malloc(toc_size);
	if (!pl->flash_toc)
		return GP_ERROR_NO_MEMORY;

	CHECK (spca50x_flash_wait_for_ready(pl));

	if (pl->bridge == BRIDGE_SPCA500) { /* For dsc350 type cams */
		/* read the TOC from the cam */
		CHECK (gp_port_read (pl->gpdev, (char *)pl->flash_toc, toc_size));
		/* reset to idle */
		CHECK (gp_port_usb_msg_write(pl->gpdev, 0x00, 0x0000, 0x0100, NULL, 0x0));
		*filecount = (int)pl->flash_toc[10];
		/* Now, create the files info buffer */
		free_files(pl);
		/* NOTE: using calloc to ensure new block is "empty" */
		pl->files = calloc (1, *filecount * sizeof (struct SPCA50xFile));
		if (!pl->files)
			return GP_ERROR_NO_MEMORY;
	} else { /* all other cams with flash... */
		/* read the TOC from the cam */
		CHECK (gp_port_read (pl->gpdev, (char *)pl->flash_toc, toc_size));
	}
	/* record that TOC has been updated - clear the "dirty" flag */
	pl->num_files_on_flash = *filecount;
	pl->dirty_flash = 0;

	return GP_OK;
}