예제 #1
0
파일: files.c 프로젝트: doomglue/aleph
// store scene to sdcard at name
void files_store_scene_name(const char* name, u8 ext) {
  //u32 i;
  void* fp;
  char namebuf[64] = SCENES_PATH;
  u8* pScene;

  app_pause();

  strcat(namebuf, name);

  if(ext) {
    // weird..
    strip_space(namebuf, 32);
    strcat(namebuf, ".scn");
  }

  print_dbg("\r\n opening scene file for writing: ");
  print_dbg(namebuf);

  // fill the scene RAM buffer from current state of system
  scene_write_buf(); 
  // open FP for writing
  fp = fl_fopen(namebuf, "wb");
  pScene = (u8*)sceneData;
  fl_fwrite((const void*)pScene, sizeof(sceneData_t), 1, fp);
  fl_fclose(fp);
  // rescan
  list_scan(&sceneList, SCENES_PATH);
  delay_ms(10);

  app_resume();
}
int fl_remove( const char * filename )
{
	FL_FILE* file;
	int res = 0;

	FL_LOCK(&_fs);

	// Use read_file as this will check if the file is already open!
	file = fl_fopen((char*)filename, "r");
	if (file)
	{
		// Delete allocated space
		if (fatfs_free_cluster_chain(&_fs, file->startcluster))
		{
			// Remove directory entries
			if (fatfs_mark_file_deleted(&_fs, file->parentcluster, (char*)file->shortfilename))
			{
				// Close the file handle (this should not write anything to the file
				// as we have not changed the file since opening it!)
				fl_fclose(file);

				res = 1;
			}
		}
	}

	FL_UNLOCK(&_fs);

	return res;
}
예제 #3
0
void DerivedShared_Image::reload ()
{
    int i;
    FILE * fp;
    uchar header[64];
    Fl_Image * img;

    if (!name_)
        return;

    if ((fp = fl_fopen (name_, "rb")) != NULL)
    {
        if (fread (header, 1, sizeof (header), fp) == 0)
        { /* ignore */
        }
        fclose (fp);
    }
    else
    {
        return;
    }

    if (memcmp (header, "#define", 7) == 0) // XBM file
        img = new Fl_XBM_Image (name_);
    else if (memcmp (header, "/* XPM */", 9) == 0) // XPM file
        img = new Fl_XPM_Image (name_);
    else
    {
        for (i = 0, img = 0; i < num_handlers_; i++)
        {
            // The only difference is the cast
            img = (static_cast<Fl_Image *> (
                (fl_handlers_[i]) (name_, header, sizeof (header))));

            if (img)
                break;
        }
    }

    if (img)
    {
        if (alloc_image_)
            delete image_;

        alloc_image_ = 1;

        if ((img->w () != w () && w ()) || (img->h () != h () && h ()))
        {
            Fl_Image * temp = img->copy (w (), h ());
            delete img;
            image_ = temp;
        }
        else
        {
            image_ = img;
        }

        update ();
    }
};
예제 #4
0
파일: files.c 프로젝트: Someone101/aleph
// search for named .dsc file and load into network param desc memory
extern u8 files_load_desc(const char* name) {
  char path[64] = DSP_PATH;
  void * fp;
  int nparams = -1;
  // word buffer for 4-byte unpickling
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  int i;
  u8 ret = 0;

  app_pause();

  strcat(path, name);
  strip_ext(path);
  strcat(path, ".dsc");

  print_dbg("\r\n  opening .dsc file at path: ");
  print_dbg(path);

  fp = fl_fopen(path, "r");
  if(fp == NULL) {
    print_dbg("... error opening .dsc file.");
    print_dbg(path);
    ret = 1;
  } else {

    // get number of parameters
    fake_fread(nbuf, 4, fp);
    unpickle_32(nbuf, (u32*)&nparams); 

    /// loop over params
    if(nparams > 0) {
      net_clear_params();
      //    net->numParams = nparams;

      for(i=0; i<nparams; i++) {
	//  FIXME: a little gross,
	// to be interleaving network and file manipulation like this...
	///....
	// read into desc buffer
	fake_fread(dbuf, PARAM_DESC_PICKLE_BYTES, fp);
	// unpickle directly into network descriptor memory
	pdesc_unpickle( &desc, dbuf );
	// copy descriptor to network and increment count
	net_add_param(i, (const ParamDesc*)(&desc));     
 
      }
    } else {
      print_dbg("\r\n error: crazy parameter count from descriptor file.");
      ret = 1;
    }
  }
  fl_fclose(fp);
  app_resume();
  return ret;
}
예제 #5
0
void songfile_timer(void*)
{
    int len;
    char song[501];
    char msg[100];
    float repeat_time = 1;

    struct stat s;
    static time_t old_t;


    if(cfg.main.song_path == NULL)
        goto exit;

    if(stat(cfg.main.song_path, &s) != 0)
    {

        // File was probably locked by another application
        // retry in 5 seconds
        repeat_time = 5;
        goto exit;
    }

    if(old_t == s.st_mtime) //file hasn't changed
        goto exit;

   if((cfg.main.song_fd = fl_fopen(cfg.main.song_path, "rb")) == NULL)
   {
	   snprintf(msg, sizeof(msg), "Warning\nCould not open: %s.\nWill retry in 5 seconds", 
					   cfg.main.song_path); 

       print_info(msg, 1);
       repeat_time = 5;
       goto exit;
   }

    old_t = s.st_mtime;

   if(fgets(song, 500, cfg.main.song_fd) != NULL)
   {
       len = strlen(song);
       //remove newline character
       if(song[len-1] == '\n' || song[len-1] == '\r')
           song[len-1] = '\0';

       cfg.main.song = (char*) realloc(cfg.main.song, strlen(song) +1);
       strcpy(cfg.main.song, song);
       button_cfg_song_go_cb();
   }

   fclose(cfg.main.song_fd);

exit:
    Fl::repeat_timeout(repeat_time, &songfile_timer);
}
예제 #6
0
파일: files.c 프로젝트: Someone101/aleph
// store scene to sdcard at name
void files_store_scene_name(const char* name, u8 ext) {
  //u32 i;
  void* fp;
  char namebuf[64] = SCENES_PATH;
  u8* pScene;

  app_pause();

  strcat(namebuf, name);

  if(ext) {
    // weird..
    strip_space(namebuf, 32);
    strcat(namebuf, ".scn");
  }

  print_dbg("\r\n opening scene file for writing: ");
  print_dbg(namebuf);

  // fill the scene RAM buffer from current state of system
  scene_write_buf(); 
  print_dbg("\r\n filled scene binary buffer");

  // open FP for writing
  fp = fl_fopen(namebuf, "wb");
  print_dbg("\r\n opened file for binary write at 0x");
  print_dbg_hex((u32)fp);

  pScene = (u8*)sceneData;
  print_dbg("\r\n writing data from scene buffer at 0x");
  print_dbg_hex((u32)pScene);
  print_dbg(", size : ");
  print_dbg_hex(sizeof(sceneData_t));
  

  // dump the scene data to debug output...

  fl_fwrite((const void*)pScene, sizeof(sceneData_t), 1, fp);
  fl_fclose(fp);

  print_dbg("\r\n ... finished writing, closed file pointer");

  // rescan
  list_scan(&sceneList, SCENES_PATH);
  delay_ms(10);

  print_dbg("\r\n re-scanned scene file list and waited.");

  app_resume();
}
예제 #7
0
파일: ottos.c 프로젝트: ottos/ottos
void fs_test() {
  file_t* file;
  char buffer[512];
  //char text[] = { 't', 'e', 's', 't', '\n', '\r' };
  char text[] = "new file\n\r\0";

  devices_init();
  mmchs_init();
  fs_init();
  fl_listdirectory("/");

  file = (file_t*) fl_fopen("/test/thenewest.txt", "a");
  fl_fwrite(text, sizeof(text), sizeof(text), file);
  fl_fclose(file);

  fl_listdirectory("/test/");

  file = (file_t*) fl_fopen("/test/thenewest.txt", "r");
  fl_fread(buffer, 512, sizeof(text), file);
  kernel_print(buffer);
  fl_fclose(file);


}
예제 #8
0
파일: files.c 프로젝트: Someone101/aleph
// search for a given filename in a listed directory. set size by pointer
void* list_open_file_name(dirList_t* list, const char* name, const char* mode, u32* size) {
  FL_DIR dirstat;
  struct fs_dir_ent dirent;
  char path[64];
  void* fp;

  print_dbg("\r\n *list_open_file_name: "); 
  print_dbg(path); 
  print_dbg(" at ");
  print_dbg(list->path);
  print_dbg(" request: ");
  print_dbg(name);


  strcpy(path, list->path);

  if(fl_opendir(path, &dirstat)) {
    
    while (fl_readdir(&dirstat, &dirent) == 0) {
      print_dbg("\r\n ... checking against "); 
      print_dbg(dirent.filename);

      if (strcmp(dirent.filename, name) == 0) {
	strncat(path, dirent.filename, 58);
	
	print_dbg("\r\n ... found, opening at:  "); 
	print_dbg(path);
      
	fp = fl_fopen(path, mode);
	*size = dirent.size;
	break;
      } else { // no match on this entry
	*size = 0;
	fp = NULL;
      }
    } // end loop
  } else { // dir error
    print_dbg("\r\n directory error.");
    *size = 0;
    fp = NULL;
  }
  return fp;
}
예제 #9
0
파일: dd.c 프로젝트: everslick/piratos
int
cmd_dd_exec(CLI *cli, char *argv[]) {
	int verbose = 0, seek = 0, skip = 0, count = -1, block = 32;
	int size, rc, err = 0, argc = cli_num_args(argv);
	char infile[PATH_MAX], outfile[PATH_MAX];
	char *inname = NULL, *outname = NULL;
	FL_FILE *in = NULL, *out = NULL;
	int c, opt_ind;
	//char *buffer = NULL;

	for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
		c = getopt_long(argc, argv, "vi:o:b:c:s:k:", long_options, &opt_ind);

		switch (c) {
			case 'v': verbose =           1;  break;
			case 'i': inname  =      optarg;  break;
			case 'o': outname =      optarg;  break;
			case 'b': block   = atoi(optarg); break;
			case 's': skip    = atoi(optarg); break;
			case 'c': count   = atoi(optarg); break;
			case 'k': seek    = atoi(optarg); break;
		}
	}

	if (verbose) {
		printf("inname  = %s\n", inname);
		printf("outname = %s\n", outname);
		printf("block   = %i\n", block);
		printf("skip    = %i\n", skip);
		printf("seek    = %i\n", seek);
		printf("count   = %i\n", count);
	}

	//buff = (char *)mall c(block);
	char buffer[block];

	if (argc - optind != 1) {
		printf("dd - incorrect number of arguments. Try 'man dd'\n");
		err++; goto cleanup;
	}

	if (buffer == NULL) {
		printf("dd: out of memory.\n");
		err++; goto cleanup;
	}

	if (inname) {
		cli_clean_path(cli, inname, infile);

		if (fl_is_dir(infile)) {
			printf("dd: '%s' is a directory\n", infile);
			err++; goto cleanup;
		}

		in = (FL_FILE *)fl_fopen(infile, "r");

		if (!in) {
			printf("dd: could not open '%s' for reading\n", infile);
			err++; goto cleanup;
		}

		fl_fseek(in, skip * block, SEEK_SET);
	} else {
		printf("dd: no input file specified - dumping zeros\n");
		memset(buffer, 0, block);
	}

	if (outname) {
		cli_clean_path(cli, outname, outfile);

		if (fl_is_dir(outfile)) {
			printf("dd: '%s' is a directory\n", outfile);
			err++; goto cleanup;
		}

		out = (FL_FILE *)fl_fopen(outfile, "r+");

		if (out) {
			rc = fl_fseek(out, seek * block, SEEK_SET);
			printf("WARNING: seeking in outfile beyond EOF is unsupported!\n");
		} else {
			out = (FL_FILE *)fl_fopen(outfile, "w");
		}

		if (!out) {
			printf("dd: could not open '%s' for writeing\n", outfile);
			err++; goto cleanup;
		}
	} else {
		printf("dd: no output file specified - using stdout\n");
	}

	if (count >= 0) {
		size = count;
	} else {
		// TODO size of (infile - skip) / block
	}

	while (size > 0) {
		int blk = count - size;

		if (verbose) printf("dd:  reading block %i\n", blk);

		if (in) {
			rc = fl_fread(buffer, block, 1, in);

			if (rc < 0) {
				printf("dd: Error reading block %i\n", blk);
				err++; goto cleanup;
			} else {
				// short read -> set block size to number of bytes read
				block = rc;
			}
		}

		if (verbose) printf("dd: writeing block %i\n", blk);

		if (out) {
			rc = fl_fwrite(buffer, block, 1, out);

			if (rc < 0) {
				printf("dd: Error writeing block %i\n", blk);
				err++; goto cleanup;
			}
		} else {
			printf("%s\n", buffer);
		}

		size--;
	}

	// TODO print summary

cleanup:
	fl_fclose(in);
	fl_fclose(out);
	//free(buffer);

	return (err ? -1 : 0);
}
예제 #10
0
//-----------------------------------------------------------------
// Main: Test bench file to create 5 files with psuedo random
// sequences in of varying lengths - read them back and complete
// then remove them.
//-----------------------------------------------------------------
void main()
{
	int i,j,x;

	FL_FILE * files[5];
	FL_FILE *readFile;
	char filenames[5][260];
	BYTE fileData[5][10000];
	BYTE readBuffer[10000];
	int fileLengths[5];
	BYTE *massiveData;
	time_t timeStart, timeEnd;

#define TESTFILES 6
	char *testfile[] = { "X:\\1", "X:\\1.bin", "X:\\12345678.321",
						 "X:\\mylongfilename", "X:\\mylongfilename.bin",
						 "X:\\the Quick Brown Fox jumped over the lazy dog.elf.binfile.jar"	};

	srand(time(NULL));

	// Initialise
	FAT32_InitDrive();

	fl_init();

	if (fl_attach_media(FAT_ReadSector, FAT_WriteSector) != FAT_INIT_OK)
		return;

	// List directory
	fl_listdirectory("C:\\");
//	return ;

test_start:

	// Generate 5 random files
	memset(filenames, 0x00, 260*5);
	for (j=0;j<5;j++)
	{
		// Length
		fileLengths[j] = GetRandom(9999);

		// Data
		for (x=0;x<fileLengths[j];x++)
			fileData[j][x] = (BYTE)GetRandom(255);

		// Names
		sprintf(filenames[j], "X:\\Auto Generated Filename Number %d", j+1);
	}

	// Create some files
	for (j=0;j<5;j++)
	{
		printf("Creating File: %s [%d bytes]\n", filenames[j], fileLengths[j]);

		// Create File
		files[j] = fl_fopen(filenames[j], "w");
		if (files[j]!=NULL)
		{
			if (fl_fwrite(fileData[j], 1, fileLengths[j], files[j])!=fileLengths[j])
			{
				printf("ERROR: File Write Block Failed File %s Length %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}
		}
		else
		{
			printf("ERROR: Error Creating File %s\n", filenames[j]);
			fl_assert(0);
		}

		fl_fclose(files[j]);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fread whole file) [%d bytes]\n", filenames[j], fileLengths[j]);

			if (fl_fread(readBuffer, 1, fileLengths[j], readFile)!=fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
					failed = TRUE;

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed\n", filenames[j]);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File using fgetc
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fgetc) [%d bytes]\n", filenames[j], fileLengths[j]);

			i = 0;
			while (i < fileLengths[j])
			{
				int res = fl_fgetc(readFile);
				if (res == -1)
					break;

				readBuffer[i++] = (BYTE)res;
			}

			if (i != fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
					failed = TRUE;

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed\n", filenames[j]);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File chunks
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fread chunks) [%d bytes]\n", filenames[j], fileLengths[j]);

			i = 0;
			while (i < fileLengths[j])
			{
				int read_length = GetRandom(1025);

				if (read_length > (fileLengths[j] - i))
					read_length = fileLengths[j] - i;

				if (fl_fread(readBuffer + i, 1, read_length, readFile) != read_length)
				{
					printf("ERROR: File %s fread error\n", filenames[j]);
					fl_assert(0);
					break;
				}

				i += read_length;
			}

			if (i != fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
				{
					failed = TRUE;
					break;
				}

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed at %d\n", filenames[j], i);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Delete File
		if (fl_remove(filenames[j])<0)
			printf("ERROR: Delete File %s Failed\n", filenames[j]);

		// Verify file is no longer present!
		readFile = fl_fopen(filenames[j], "r");
		if (readFile != NULL)
		{
			printf("ERROR: File %s still present after delete!\n", filenames[j]);
			fl_assert(0);
			fl_fclose(readFile);
		}
	}

	// Create folder
	fl_createdirectory("C:\\folder1");

#if 0

	// Create massive file
#define MASSIVE_FILE_LEN (1024 * 1024)
	printf("Creating Massive File [%d bytes]\n", MASSIVE_FILE_LEN);

	massiveData = malloc(MASSIVE_FILE_LEN);
	if (!massiveData)
	{
		printf("ERROR: Could not allocate memory for massive array!\n");
		fl_assert(0);
		fl_shutdown();
		return ;
	}

	// Create random data for file
	for (x=0;x<MASSIVE_FILE_LEN;x++)
		massiveData[x] = (BYTE)GetRandom(255);

	// Remove if it already exists!
	fl_remove("X:\\folder1\\massive file.bin");

	timeStart = time(NULL);

	// Create Large File
	readFile = fl_fopen("X:\\folder1\\massive file.bin", "w");
	if (readFile != NULL)
	{
		if (fl_fwrite(massiveData, 1, MASSIVE_FILE_LEN, readFile) != MASSIVE_FILE_LEN)
		{
			printf("ERROR: File Write Block Failed for massive file (Length %d)\n", MASSIVE_FILE_LEN);
			fl_assert(0);
		}
	}
	else
	{
		printf("ERROR: Error Creating massive file\n");
		fl_assert(0);
	}

	fl_fclose(readFile);

	// Verify Massive File
	readFile = fl_fopen("X:\\folder1\\massive file.bin", "r");
	if (readFile!=NULL)
	{
		int failed = FALSE;

		printf("File Massive File Read Check (fread whole file) [%d bytes]\n", MASSIVE_FILE_LEN);

		i = 0;
		while (i < MASSIVE_FILE_LEN)
		{
			int read_length = GetRandom(2048) + 128;

			if (read_length > (MASSIVE_FILE_LEN - i))
				read_length = MASSIVE_FILE_LEN - i;

			if (fl_fread(readBuffer, 1, read_length, readFile) != read_length)
			{
				printf("ERROR: File massive file fread error\n");
				fl_assert(0);
				break;
			}

			for (j=0;j<read_length;j++)
				if ( massiveData[i+j] != (BYTE)readBuffer[j] )
				{
					printf("ERROR: File Massive File Data Verify Failed at %d\n", i+j);
					fl_assert(0);
					break;
				}

			i += read_length;
		}

		if (i != MASSIVE_FILE_LEN)
		{
			printf("ERROR: File massive file Read Length Error %d\n", MASSIVE_FILE_LEN);
			fl_assert(0);
		}
	}
	fl_fclose(readFile);

	timeEnd = time(NULL);
	printf("Time taken %d seconds\n", (int)(timeEnd-timeStart));

	free(massiveData);
#endif

	// Filename test
	for (i=0;i<TESTFILES;i++)
	{
		// Create File
		readFile = fl_fopen(testfile[i], "w");
		if (readFile != NULL)
			;
		else
		{
			printf("ERROR: Error Creating File %s\n", testfile[i]);
			fl_assert(0);
		}

		fl_fputc(0, readFile);
		fl_fclose(readFile);

		readFile = fl_fopen(testfile[i], "r");
		assert(readFile);
		fl_fclose(readFile);
	}

	// List directory
	fl_listdirectory("C:\\");

	for (i=0;i<TESTFILES;i++)
	{
		// Delete File
		if (fl_remove(testfile[i])<0)
		{
			printf("ERROR: Delete File %s Failed\n", testfile[i]);
			fl_assert(0);
		}
	}

	fl_shutdown();

	printf("\r\nCompleted\r\n");

	// List directory
	fl_listdirectory("C:\\");
}
예제 #11
0
file_handle_t file_open(mountpoint_t* mountpoint, const char* path, const char* mode)
{
    return fl_fopen(path, mode);
}
예제 #12
0
void split_recording_timer(void *initial_call)
{
    int zero = 0;
    char *insert_pos;
    char *path;
    char *ext;
    char file_num_str[10];
    static int file_num;
    struct tm *local_time;
    const time_t t = time(NULL);

    if(*((int*)initial_call) == 1)
        file_num = 2;

    // Values < 0 are not allowed
    if(fl_g->input_rec_split_time->value() < 0)
    {
        fl_g->input_rec_split_time->value(0);
        return;
    }

    path = strdup(cfg.rec.path);
    ext = util_get_file_extension(cfg.rec.filename);
    if(ext == NULL)
    {
        print_info("Could not find a file extension in current filename\n"
                "Automatic file splitting is deactivated", 0);
        free(path);
        return;
    }


    snprintf(file_num_str, sizeof(file_num_str), "-%d", file_num);

    insert_pos = strrstr(path, ext);
    strinsrt(&path, file_num_str, insert_pos-1);


    if((next_fd = fl_fopen(path, "rb")) != NULL)
    {
        print_info("Next file ", 0);
        print_info(path, 0);
        print_info("already exists\nbutt keeps recording to current file", 0);
        fclose(next_fd);
        free(path);
        return;
    }

    if((next_fd = fl_fopen(path, "wb")) == NULL)
    {
        fl_alert("Could not open:\n%s", path);
        free(path);
        return;
    }

    print_info("Recording to:", 0);
    print_info(path, 0);

    file_num++;


    next_file = 1;
    free(path);

    local_time = localtime(&t);

    // Make sure that the 60 minutes boundary is not violated in case sync_to_hour == 1
    if((cfg.rec.sync_to_hour == 1) && ((local_time->tm_min + cfg.rec.split_time) > 60))
        Fl::repeat_timeout(60*(60 - local_time->tm_min), &split_recording_timer, &zero);
    else
        Fl::repeat_timeout(60*cfg.rec.split_time, &split_recording_timer, &zero);

}
예제 #13
0
파일: hd.c 프로젝트: everslick/piratos
int
cmd_hd_exec(CLI *cli, char *argv[]) {
	int argc = cli_num_args(argv);
	char buffer[16], path[PATH_MAX];
	int eof = 0, rc, line = 0, i;
	FL_FILE *file;

	if (argc != 2) {
		printf("hd - incorrect number of arguments. Try 'man hd'\n");

		return (-1);
	}

	cli_clean_path(cli, argv[1], path);

	if (fl_is_dir(path)) {
		printf("hd: '%s' is a directory\n", path);

		return (-1);
	}

	file = (FL_FILE *)fl_fopen(path, "r");

	if (!file) {
		printf("hd: Could not open '%s'\n", path);

		return (-1);
	}

	while (rc != EOF) {
		rc = fl_fread(buffer, 16, 1, file);

		printf("%04hhx:%04hhx  ", line * 16, line * 16 + rc -1);

		for (i=0; i<rc; i++) {
			printf("%02hhx ", buffer[i]);
			if (i == 7) printf(" ");
		}

		for (i=rc; i<16; i++) {
			printf("   ");
			if (i == 7) printf(" ");
		}

		printf(" |");
		for (i=0; i<rc; i++) {
			if ((buffer[i] < 32) || (buffer[i] > 127)) {
				printf(".");
			} else {
				printf("%c", buffer[i]);
			}
		}
		printf("|\n");

		if (rc < 16) break;

		line++;
	}

	fl_fclose(file);

	return (0);
}
예제 #14
0
void LOS_proc(unsigned char tid, void* msg)
{
    //static int file_num = 0;
	//static int size;
	static LOS_state_t last_st;
	int i;
    
#ifndef __LOCAL_STORE_ACCEL_MODE__
	if (LOS_queue.numBytes > 0)
#else
    if (LS_num_accel_queue > 0)
#endif
	{
		switch (st)
		{
		case LOS_NONE:
			//probe_high();
			last_st = st;
			st = LOS_CREATE_START;
		case LOS_CREATE_START:
			i = fl_fopen("/file.txt", "w", (void**)&mFile[LOS_open_file_index], TRUE);
			switch (i)
			{
			case 0:
				st = LOS_OPEN_START;
				break;
			case -1:
				return;
			default:
				if (mFile[LOS_open_file_index])
				{
					last_st = st;
					st = LOS_CREATE_DONE;
				}
				else
				{
					st = LOS_OPEN_START;
				}
			}
		case LOS_OPEN_START:
			if (st == LOS_OPEN_START)
			{
#ifdef PROBE_ENABLED
				probe_low();
#endif
				i = fl_fopen("/file.txt", "w", (void**)mFile[LOS_open_file_index], TRUE);
				switch (i)
				{
				case 0:
					st = LOS_NONE;
					return;
				case -1:
					return;
				default:
					if (mFile[LOS_open_file_index])
					{
						last_st = st;
						st = LOS_OPEN_DONE;
					}
					else
					{
						st = LOS_NONE;
						return;
					}
				}
			}
		case LOS_CREATE_DONE:
		case LOS_OPEN_DONE:
			//probe_low();
			last_st = st;
#ifndef __LOCAL_STORE_ACCEL_MODE__
			if (LOS_queue.outCount == LOS_queue.inCount)
			{
				st = LOS_WRITE_HEAD;
			}
			else if (LOS_queue.outCount > LOS_queue.inCount)
			{
				size = LOS_queue.maxBytes - LOS_queue.outCount;
				st = LOS_WRITE_HEAD;
			}
			else
			{
				size = LOS_queue.numBytes;
				st = LOS_WRITE_ALL;
			}
		case LOS_WRITE_HEAD:
			if (st == LOS_WRITE_HEAD)
			{
				i = fl_fwrite(&LOS_queue.buffer[LOS_queue.outCount], 1, size, mFile[LOS_open_file_index]);
				switch (i)
				{
				case -1:
					printf("ERROR: Write file failed\n");
					st = last_st;
					return;
				case -2:
					return;
				}
				st = last_st;
				if (i == size)
				{
					LOS_queue.numBytes -= size;
					LOS_queue.outCount = 0;
				}
				else
				{
					printf("ERROR: Write file failed\n");
				}
				return;
			}
		case LOS_WRITE_ALL:
			if (st == LOS_WRITE_ALL)
			{
				i = fl_fwrite(&LOS_queue.buffer[LOS_queue.outCount], 1, size, mFile[LOS_open_file_index]);
				switch (i)
				{
				case -1:
					printf("ERROR: Write file failed\n");
					st = last_st;
					return;
				case -2:
					return;
				default:
					if (i == size)
					{
						LOS_queue.numBytes -= size;
						LOS_queue.outCount += size;
#ifdef PROBE_ENABLED
						probe2_change(0);
#endif
						if (mFile[LOS_open_file_index]->filelength > MAX_FILE_SIZE)
						{
							st = LOS_CLOSE_START;
						}
						else
						{
							st = last_st;
							return;
						}
					}
					else
					{
						printf("ERROR: Write file failed\n");
						st = last_st;
						return;
					}
				}
			}
#else 
            if (LS_get_accel_string())
            {
                st = LOS_WRITE;
            }
            else
            {
                st = last_st;
                return;
            }
        case LOS_WRITE:
            if (st == LOS_WRITE)
            {
                i = fl_fwrite(LS_accel_string, 1, LS_accel_string_size, mFile[LOS_open_file_index]);
                switch (i)
                {
                case -1:
                    printf("ERROR: Write file failed\n");
                    st = last_st;
                    return;
                case -2:
                    return;
                }
                st = last_st;
                if (i == LS_accel_string_size)
                {
                    LS_accel_queue_out_count = (LS_accel_queue_out_count + 1) % MAX_LS_ACCEL_ITEMS;
                    --LS_num_accel_queue;
#ifdef PROBE_ENABLED
                    probe2_change(0);
#endif
					if (mFile[LOS_open_file_index]->filelength > MAX_FILE_SIZE)
					{
						st = LOS_CLOSE_START;
					}
					else
					{
						st = last_st;
						return;
					}
                }
                else
                {
                    st = last_st;
                    return;
                }
            }
#endif
		case LOS_CLOSE_START:
			i = fl_fclose(mFile[LOS_open_file_index]);
			switch (i)
			{
			case 0:
				printf("ERROR: Close file failed\n");
				return;
			case -1:
				i = 0;
				return;
			}
			st = LOS_NONE;
		}
	}
}
예제 #15
0
// 'Fl_FileBrowser::load()' - Load a directory into the browser.
int                                         // O - Number of files loaded
    Fl_File_Browser::load(const Fl_String &dir) // I - Directory to load
{   
    Fl_String old_dir(directory());
    m_dir_ds.directory(dir);

    clear();
    clear_columns();
    sort_col(1);
    m_up_item = 0;

    if(dir.empty()) {
        header()->add_column("", 20);

        // No directory specified:
        //  - For UNIX list all mount points.
        //  - For Win32 list all valid drive letters.

        //icon      = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE);
        //if (icon == (Fl_FileIcon *)0)
        //  icon = Fl_FileIcon::find("any", Fl_FileIcon::DIR);

        begin();
        char filename[FL_PATH_MAX];
#ifdef _WIN32
        header()->add_column(_("File"), 100);
        header()->add_column(_("Type"), 100);
        header()->add_column(_("Capacity"), 100);
        header()->add_column(_("Free Space"), 100);

        // Drive available bits
        DWORD drives = GetLogicalDrives();
        for(int i = 'A'; i <= 'Z'; i ++, drives >>= 1) {
            if (drives & 1) {
                Fl_ListView_Item *item = new Fl_ListView_Item();
                item->image(&hd_pix);
                snprintf(filename, sizeof(filename)-1, "%c:\\", i);
                item->label(1, filename);

                Fl_File_Attr *attr = fl_file_attr(filename);
                if(attr->flags & Fl_File_Attr::DEVICE)
                {
                    uint type = GetDriveTypeA(filename);
                    const char *typestr=_(types[0]);

                    if (type==DRIVE_CDROM)      { typestr=_(types[4]); item->image(&cd_pix); }
                    else if (type==DRIVE_REMOVABLE) { typestr=_(types[5]); item->image(&floppy_pix); }
                    else if (type==DRIVE_FIXED)     typestr=_(types[6]);
                    else if (type==DRIVE_REMOTE)        typestr=_(types[7]);
                    else if (type==DRIVE_RAMDISK)   typestr=_(types[8]);

                    item->label(2, typestr);

                    uint s = 0;
                    Fl_String suffix;
                    if((s = get_dev_size(attr->capacity, suffix))>0) {
                        item->label(3, Fl_String(s)+" "+suffix);
                    }
                    if((s = get_dev_size(attr->free, suffix))>0) {
                        item->label(4, Fl_String(s)+" "+suffix);
                    }

                    /*
                     //TOO SLOW!!!
                     char drivename[255];
                     if(GetVolumeInformation(
                     filename, drivename, sizeof(drivename)-1,
                     NULL, NULL, NULL, NULL, 0))
                     {
                     if(drivename[0])
                     snprintf(fname, sizeof(fname)-1, "%s (%s)", filename, drivename);
                     }
                     */
                }

            }
        }
#else
        header()->add_column(_("File"), 100);
        header()->add_column(_("Device"), 100);
        header()->add_column(_("Type"), 100);

        FILE    *mtab = 0;      // /etc/mtab or /etc/mnttab file
        char    line[1024];     // Input line
        char    dev[256];       // Device name
        char    fstype[256];    // Filesystem type

        // Open the file that contains a list of mounted filesystems...
#  if defined(__hpux) || defined(__sun)
        // Fairly standard
        mtab = fl_fopen("/etc/mnttab", "r");
#  elif defined(__sgi) || defined(linux)
        // More standard
        mtab = fl_fopen("/etc/mtab", "r");
#  endif
        // Otherwise fallback to full list
        if(mtab == NULL) mtab = fl_fopen("/etc/fstab", "r");
        if(mtab == NULL) mtab = fl_fopen("/etc/vfstab", "r");

        if (mtab != NULL)
        {
            while (fgets(line, sizeof(line), mtab) != NULL)
            {
                if (line[0] == '#' || line[0] == '\n')
                    continue;
                if (sscanf(line, "%255s%4095s%255s", dev, filename, fstype) != 3)
                    continue;
                if(!strcasecmp(dev, "none"))
                    continue;

                Fl_ListView_Item *item = new Fl_ListView_Item();
                item->image(&hd_pix);
                item->label(1, filename);
                item->label(2, dev);
                item->label(3, fstype);
            }
            fclose(mtab);
        }
#endif // _WIN32
        end();
        resizable_col(0, false);
        return children();

    } else {