Esempio n. 1
0
File: cli.c Progetto: Godzil/sd2snes
void cli_loop(void) {
  while (1) {
    curchar = getline(">");
    printf("\n");

    /* Process medium changes before executing the command */
    if (disk_state != DISK_OK && disk_state != DISK_REMOVED) {
      FRESULT res;

      printf("Medium changed... ");
      res = f_mount(0,&fatfs);
      if (res != FR_OK) {
        printf("Failed to mount new medium, result %d\n",res);
      } else {
        printf("Ok\n");
      }

    }

    /* Remove whitespace */
    while (*curchar == ' ') curchar++;
    while (strlen(curchar) > 0 && curchar[strlen(curchar)-1] == ' ')
      curchar[strlen(curchar)-1] = 0;

    /* Ignore empty lines */
    if (strlen(curchar) == 0)
      continue;

    /* Parse command */
    int8_t command = parse_wordlist(command_words);
    if (command < 0)
      continue;


    FRESULT res;
    switch (command) {
    case CMD_CD:
#if _FS_RPATH
      if (strlen(curchar) == 0) {
        f_getcwd((TCHAR*)file_lfn, 255);
        printf("%s\n",file_lfn);
        break;
      }

      res = f_chdir((const TCHAR *)curchar);
      if (res != FR_OK) {
        printf("chdir %s failed with result %d\n",curchar,res);
      } else {
        printf("Ok.\n");
      }
#else
      printf("cd not supported.\n");
      res;
#endif
    break;
    case CMD_RESET:
      cmd_reset();
      break;

    case CMD_SRESET:
      cmd_sreset();
      break;

    case CMD_DIR:
    case CMD_LS:
      cmd_show_directory();
      break;

    case CMD_RESUME:
      return;
      break;

    case CMD_LOADROM:
      cmd_loadrom();
      break;

    case CMD_LOADRAW:
      cmd_loadraw();
      break;

    case CMD_SAVERAW:
      cmd_saveraw();
      break;

    case CMD_RM:
      cmd_rm();
      break;

    case CMD_D4:
      cmd_d4();
      break;

    case CMD_VMODE:
      cmd_vmode();
      break;

    case CMD_PUT:
      cmd_put();
      break;

    case CMD_MAPPER:
      cmd_mapper();
      break;

    case CMD_SETTIME:
      cmd_settime();
      break;

    case CMD_TIME:
      cmd_time();
      break;

    case CMD_TEST:
      testbattery();
      break;

    case CMD_SETFEATURE:
      cmd_setfeature();
      break;

    case CMD_HEXDUMP:
      cmd_hexdump();
      break;

    case CMD_W8:
      cmd_w8();
      break;

    case CMD_W16:
      cmd_w16();
      break;
    }

  }
}
static void prvCreateDemoFileUsing_f_putc( void )
{
unsigned char ucReturn;
int iByte, iReturned;
F_FILE *pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ];

	/* Obtain and print out the working directory. */
	f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
	printf( "In directory %s\r\n", cRAMBuffer );

	/* Create a sub directory. */
	ucReturn = f_mkdir( pcDirectory1 );
	configASSERT( ucReturn == F_NO_ERROR );

	/* Move into the created sub-directory. */
	ucReturn = f_chdir( pcDirectory1 );
	configASSERT( ucReturn == F_NO_ERROR );

	/* Obtain and print out the working directory. */
	f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
	printf( "In directory %s\r\n", cRAMBuffer );

	/* Create a subdirectory in the new directory. */
	ucReturn = f_mkdir( pcDirectory2 );
	configASSERT( ucReturn == F_NO_ERROR );

	/* Move into the directory just created - now two directories down from
	the root. */
	ucReturn = f_chdir( pcDirectory2 );
	configASSERT( ucReturn == F_NO_ERROR );

	/* Obtain and print out the working directory. */
	f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
	printf( "In directory %s\r\n", cRAMBuffer );
	configASSERT( strcmp( ( const char * ) cRAMBuffer, pcFullPath ) == 0 );

	/* Generate the file name. */
	sprintf( cFileName, "%s.txt", pcDirectory2 );

	/* Print out the file name and the directory into which the file is being
	written. */
	printf( "Writing file %s in %s\r\n", cFileName, cRAMBuffer );

	pxFile = f_open( cFileName, "w" );

	/* Create a file 1 byte at a time.  The file is filled with incrementing
	ascii characters starting from '0'. */
	for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
	{
		iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
		configASSERT( iReturned ==  ( ( int ) '0' + iByte ) );
	}

	/* Finished so close the file. */
	f_close( pxFile );

	/* Move back to the root directory. */
	ucReturn = f_chdir( "../.." );
	configASSERT( ucReturn == F_NO_ERROR );

	/* Obtain and print out the working directory. */
	f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
	printf( "Back in root directory %s\r\n", cRAMBuffer );
	configASSERT( strcmp( ( const char * ) cRAMBuffer, pcRoot ) == 0 );
}
Esempio n. 3
0
bool TestExtFile::test_getcwd() {
  VERIFY(!f_getcwd().toString().empty());
  return Count(true);
}