Exemple #1
0
Fichier : ls.c Projet : narupo/cap
int
lscmd_run(lscmd_t *self) {
    if (self->opts.ishelp) {
        lscmd_usage(self);
        return 0;
    }

    char cd[FILE_NPATH];
    if (!file_readline(cd, sizeof cd, self->config->var_cd_path)) {
        err_error("failed to read line from cd of variable");
        return 1;
    }

    char home[FILE_NPATH];
    if (!file_readline(home, sizeof home, self->config->var_home_path)) {
        err_error("failed to read line from home of variable");
        return 2;
    }

    if (optind - self->argc == 0) {
        return lscmd_ls(self, cd);
    } else {
        char path[FILE_NPATH];

        for (int i = optind; i < self->argc; ++i) {
            const char *arg = self->argv[i];
            const char *org = (arg[0] == '/' ? home : cd);
            file_solvefmt(path, sizeof path, "%s/%s", org, arg);
            lscmd_ls(self, path);
        }
    }

    return 0;
}
Exemple #2
0
int execute_script(t_hydra_console *con, char *filename)
{
	FIL fp;
	int i;
	if (!is_fs_ready()) {
		if(mount() != 0) {
			return FALSE;
		}
	}

	if (!file_open(&fp, filename, 'r')) {
		cprintf(con, "Failed to open file %s\r\n", filename);
		return FALSE;
	}

	/* Clear any input in tokenline buffer */
	tl_input(con->tl, 0x03);

	while(file_readline(&fp, inbuf, IN_OUT_BUF_SIZE)) {
		i=0;
		if(inbuf[0] == '#') {
			continue;
		}
		while(inbuf[i] != '\0') {
			tl_input(con->tl, inbuf[i]);
			i++;
		}
	}
	file_close(&fp);
	return TRUE;
}
Exemple #3
0
int MIDI_SetMimpiMap(char *filename) {

	BYTE		b;
	FILEH		fh;
	char		buf[128];

	LOADED_TONEMAP = 0;
	ZeroMemory(TONE_CH, sizeof(TONE_CH));
	ZeroMemory(TONEBANK[0], sizeof(TONEBANK));
	for (b=0; b<128; b++) {
		TONEMAP[0][b] = b;
		TONEMAP[1][b] = b;
		TONEMAP[2][b] = b;
	}
	TONE_CH[9] = MIMPI_RHYTHM;

	if ((filename == NULL) || (!filename[0])) {
		ENABLE_TONEMAP = 0;
		return(FALSE);
	}
	fh = File_Open(filename);
	if (fh == (FILEH)-1) {
		ENABLE_TONEMAP = 0;
		return(FALSE);
	}
	while(file_readline(fh, buf, sizeof(buf)) >= 0) {
		mimpidefline_analaize(buf);
	}
	File_Close(fh);

	LOADED_TONEMAP = 1;
	return(TRUE);
}
bool test_file_readline_f1 (Test *test)
{
	Directory *directory;
	File *file;
	char *path;
	char *line;
	size_t bytes_read;

	TITLE ();
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/readline"));
        /*
                d stage/readline
                f f2
                f f3 \
                         \
                        0 \
                        AB \
                        012 \
                        ABCD \
                        01234 \
                        ABCD \
                        012 \
                        AB \
                        0
                f f1
         */
	CATCH (!(directory = directory_open (path)));
	string_destroy (path);
	CATCH (!directory_read (directory));
	CATCH (!(file = directory_find_file (directory, "f1")));
	CATCH (file_readline (NULL, NULL, NULL));
	CATCH (file_readline (file, NULL, NULL));
	CATCH (!(line = string_create_with_size (1)));
	CATCH (file_readline (file, line, NULL));
	CATCH (file_readline (file, line, &bytes_read));
	directory_close (directory);
	string_destroy (line);
	PASS ();
}
Exemple #5
0
int event_load(event_t * event, const char * file)
{
	FILE * fp = fopen(file, "rb");
	char mbuf[2048];
	int  line_num = 0;

	if(fp == 0)
		return -1;

	line_num = 0;
	while(!feof(fp))
	{
		line_num++;
		file_readline(fp, mbuf, 2048);
		if(event_analise(event, mbuf) != 0)
			printf("配置错误 第 %3d 行 %s\n", line_num, mbuf);
	}
	fclose(fp);
	return 0;
}
Exemple #6
0
int
main (int argc, char **argv)
{
  struct file f;
  char *line;
  int i;
  int n;

  n = 0;
  for (i = 1; i < argc; i++) {
    file_open (&f, argv[i]);
    while ((line = file_readline (&f))) {
      check_parse (line);
      n++;
    }
    file_close (&f);
  }
  url_free (&url);

  printf ("Tested %d urls.\n", n);
}
bool test_file_readline_f3 (Test *test)
{
	Directory *directory;
	File *file;
	char *path;
	char *line;
	size_t bytes_read;
	char *check[] = { 
		"",
		"0",
		"AB",
		"012",
		"ABCD",
		"01234",
		"ABCD",
		"012",
		"AB",
		"0",
	};

	TITLE ();
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/readline"));
        /*
                d stage/readline
                f f2
                f f3 \
                         \
                        0 \
                        AB \
                        012 \
                        ABCD \
                        01234 \
                        ABCD \
                        012 \
                        AB \
                        0
                f f1
         */
	CATCH (!(directory = directory_open (path)));
	string_destroy (path);
	directory_read (directory);
	CATCH (!(file = directory_find_file (directory, "f3")));
	CATCH (!file_open (file));
	CATCH (!(line = string_create_with_size (5)));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 1);
	CATCH (!string_equals (line, check[0]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 2);
	CATCH (!string_equals (line, check[1]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 3);
	CATCH (!string_equals (line, check[2]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 4);
	CATCH (!string_equals (line, check[3]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 5);
	CATCH (!string_equals (line, check[4]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 5);
	CATCH (!string_equals (line, "0123"));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 5);
	CATCH (!string_equals (line, check[6]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 4);
	CATCH (!string_equals (line, check[7]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 3);
	CATCH (!string_equals (line, check[8]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 2);
	CATCH (!string_equals (line, check[9]));
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 0);
	CATCH (!file_readline (file, line, &bytes_read));
	CATCH (bytes_read != 0);
	directory_close (directory);
	string_destroy (line);
	PASS ();
}
Exemple #8
0
int main(int argc, char *argv){
  eeprom_recover();  
  filesys_init();
  

  /* general file manipulation calls */
  file_t * foo = file_open("output.csv", 'a');
  file_write(foo, "hello world",11); 
  file_write(foo, "heres some more stuff", 21); 
  file_close(foo);


  foo =  file_open("vim", 'w');
  char buf[2048] = "Vim has some intelligence about what to do if the swap file is corrupt in  some way.  If Vim has doubt about what it found, it will give an error  message and insert lines with ??? in the text.  If you see an error message  while recovering, search in the file for ??? to see what is wrong.  You may  want to cut and paste to get the text you need.    The most common remark is ???LINES MISSING.  This means that Vim cannot read  the text from the original file.  This can happen if the system crashed and  parts of the original file were not written to disk.    Be sure that the recovery was successful before overwriting the original  file or deleting the swap file.  It is good practice to write the recovered  file elsewhere and run diff to find out if the changes you want are in the  recovered file.  Or use |:DiffOrig|.    Once you are sure the recovery is ok delete the swap file.  Otherwise, you  will continue to get warning messages that the .swp file already exists.    {Vi: recovers in another way and sends mail if there is something to recover}\0";
  file_write(foo, buf, strlen(buf));
  file_close(foo);


  
  printf("--------------------------------------\n");

  foo = file_open("output.csv", 'w');
  file_write(foo, "***************************************|", 40);
  file_close(foo);

  foo = file_open("another.test", 'w');
  file_close(foo);

  foo = file_open("vim", 'a');
  char wiki[1024] = "Using universal hashing (in a randomized algorithm or data structure) refers to selecting a hash function at random from a family of hash functions with a certain mathematical property (see definition below). This guarantees a low number of collisions in expectation, even if the data is chosen by an adversary. Many universal families are known (for hashing integers, vectors, strings), and their evaluation is often very efficient. Universal hashing has numerous uses in computer science, for example in implementations of hash tables, randomized algorithms, and cryptography.";
  file_write(foo, wiki, strlen(wiki));
  file_close(foo);
  

  foo = file_open("lines.txt", 'a');
  file_writeline(foo, "this is the first line", 22);
  file_write(foo, "some more stuff", 15);
  file_close(foo);

  foo = file_open("lines.txt", 'r');
  char in[256];
  file_readline(foo, in, 256);
  printf("|%s|", in);

  file_rewind(foo);

  memset(in, 0, 256);

  file_read(foo, in, 10);
  printf("|%s|", in);
  file_close(foo);

  eeprom_print();
  //char buf[256] = "**********************************************************************************************************************************************************************************************************************************************************ABC|";
  //file_write(foo, buf, strlen(buf));
  


  
  /*
  foo = file_open("test.foo",'a');
  file_print(foo); 

  file_write(foo, "$$$",3); 
  */
  //eeprom_print();

  /*
  foo = file_open("test.foo", 'r');
  file_print(foo);
  
  char read[128];
  int b = file_read(foo, read, 11);
  printf("%d %s\n", b, read);
  
  file_print(foo);
  eeprom_print();
  
  memset(read, 0, 128);
  b = file_read(foo, read, 29);
  printf("%d %s\n", b, read);
  file_close(foo);
*/
  /* write test:
  foo = file_open("test.foo", 'w');
  file_print(foo); 
  file_write(foo, buf, 256);
  file_print(foo); 
  eeprom_print();
  */

  /*=== PAGE tests ===
  page_t *page_1 = page_create(DATA_P);
  page_t *page_2 = page_create(DATA_P);
  page_t *page_3 = page_create(DATA_P);
  page_t *page_4 = page_create(DATA_P);

  
  char text[256];
  memset(text, 0, 256);

  int16_t a;

  sprintf(text, "%s %d", "hello world", 1);
  a = page_write(page_1, 2, text, 100);
  printf("bytes written: %d\n", a);
  
  sprintf(text, "%s %d", "hello world", 2);
  a = page_write(page_2, 2, text, 100);
  printf("bytes written: %d\n", a);
  
  sprintf(text, "%s %d", "hello world", 3);
  a = page_write(page_3, 2, text, 100);
  printf("bytes written: %d\n", a);
  

  int i;
  for(i = 0; i < 256; ++i)
    text[i] = i % 0x80;

  a = page_write(page_4, 2, text, 256);
  printf("bytes written: %d\n", a);
  
  //eeprom_print();
  memset(text, 0, 256);
  page_read(page_4, 5, text, 5);
  
  page_erase(page_4, 64, 32);
  page_write(page_4, 64, "this is erased data", 19);
 
  //will fail due to open pages
  pagesys_qwipe();
  
  //eeprom_print();

  printf("\n"); 
  page_close(page_1);
  page_close(page_2);
  page_close(page_3);
  page_close(page_4);

  pagesys_qwipe();

  //eeprom_print();

  
  memset(text, 0, 256);
  page_1 = page_create(DATA_P);
  sprintf(text, "%s %d", "goodbye", 5);
  page_write(page_1, 2, text, 9);

  //eeprom_print();
  
  page_close(page_1);
  
  //full wipe
  pagesys_wipe();
  
  
  eeprom_print();
  
  //printf("%s\n", text);
  */


  /* === EEPROM tests === 
  uint8_t x = 0xFF;
  printf("0x%X\n", x);
  
  int i = 0;
  for(; i < 8; ++i){
    x &= (0xFF ^ (1 << i)) ;
    printf("0x%X\n", x);
    x = 0xFF;
  }
  */


  /*
  char buf[256] = "hello world";
  eeprom_write_page(0x0, buf, sizeof(buf));

  sprintf(buf, "%s", "this is a test sentence. here are some numbers 100 20123 1i12 DFASDFADSf");
  eeprom_write_page(0x100, buf, sizeof(buf));



  //full aligned page write
  int i;
  for(i = 0; i < 256; ++i)
    buf[i] = i % 0x80;
  
  eeprom_write_page(0x300, buf, sizeof(buf));
  //eeprom_erase_page(0x3f1);


  eeprom_write(0x290, buf, sizeof(buf));
  
  
  eeprom_print();
  eeprom_backup();
  */
/*  
  eeprom_read_page(0x0, buf, sizeof(buf));
  memview(buf, sizeof(buf));


  eeprom_read_page(0x290, buf, sizeof(buf));
  memview(buf, sizeof(buf));


  eeprom_read_page(0x300, buf, sizeof(buf));
  memview(buf, sizeof(buf));
  
  //eeprom_erase(0x300, 129);
  eeprom_wipe();

  eeprom_write(0x000, "A", 1);
  eeprom_write(0x100, "B", 1);
  eeprom_write(0x200, "C", 1);
  eeprom_write(0x300, "D", 1);
  eeprom_print();
  //eeprom_wipe();
*/
    
}