- else if(strncmp_P(command, PSTR("rm "), 3) == 0)
- {
- command += 3;
- if(command[0] == '\0')
- continue;
-
- struct fat_dir_entry_struct file_entry;
- if(find_file_in_dir(fs, dd, command, &file_entry))
- {
- if(fat_delete_file(fs, &file_entry))
- continue;
- }
-
- uart_puts_p(PSTR("error deleting file: "));
- uart_puts(command);
- uart_putc('\n');
- }
- else if(strncmp_P(command, PSTR("touch "), 6) == 0)
- {
- command += 6;
- if(command[0] == '\0')
- continue;
-
- struct fat_dir_entry_struct file_entry;
- if(!fat_create_file(dd, command, &file_entry))
- {
- uart_puts_p(PSTR("error creating file: "));
- uart_puts(command);
- uart_putc('\n');
- }
- }
- else if(strncmp_P(command, PSTR("mv "), 3) == 0)
- {
- command += 3;
- if(command[0] == '\0')
- continue;
-
- char* target = command;
- while(*target != ' ' && *target != '\0')
- ++target;
-
- if(*target == ' ')
- *target++ = '\0';
- else
- continue;
-
- struct fat_dir_entry_struct file_entry;
- if(find_file_in_dir(fs, dd, command, &file_entry))
- {
- if(fat_move_file(fs, &file_entry, dd, target))
- continue;
- }
-
- uart_puts_p(PSTR("error moving file: "));
- uart_puts(command);
- uart_putc('\n');
- }
- else if(strncmp_P(command, PSTR("write "), 6) == 0)
- {
- command += 6;
- if(command[0] == '\0')
- continue;
-
- char* offset_value = command;
- while(*offset_value != ' ' && *offset_value != '\0')
- ++offset_value;
-
- if(*offset_value == ' ')
- *offset_value++ = '\0';
- else
- continue;
-
- /* search file in current directory and open it */
- struct fat_file_struct* fd = open_file_in_dir(fs, dd, command);
- if(!fd)
- {
- uart_puts_p(PSTR("error opening "));
- uart_puts(command);
- uart_putc('\n');
- continue;
- }
-
- int32_t offset = strtolong(offset_value);
- if(!fat_seek_file(fd, &offset, FAT_SEEK_SET))
- {
- uart_puts_p(PSTR("error seeking on "));
- uart_puts(command);
- uart_putc('\n');
-
- fat_close_file(fd);
- continue;
- }
-
- /* read text from the shell and write it to the file */
- uint8_t data_len;
- while(1)
- {
- /* give a different prompt */
- uart_putc('<');
- uart_putc(' ');
-
- /* read one line of text */
- data_len = read_line(buffer, sizeof(buffer));
- if(!data_len)
- break;
-
- /* write text to file */
- if(fat_write_file(fd, (uint8_t*) buffer, data_len) != data_len)
- {
- uart_puts_p(PSTR("error writing to file\n"));
- break;
- }
- }
-
- fat_close_file(fd);
- }
- else if(strncmp_P(command, PSTR("mkdir "), 6) == 0)
- {
- command += 6;
- if(command[0] == '\0')
- continue;
-
- struct fat_dir_entry_struct dir_entry;
- if(!fat_create_dir(dd, command, &dir_entry))
- {
- uart_puts_p(PSTR("error creating directory: "));
- uart_puts(command);
- uart_putc('\n');
- }
- }
+ else if(strncmp_P(command, PSTR("rm "), 3) == 0)
+ {
+ command += 3;
+ if(command[0] == '\0')
+ continue;
+
+ struct fat_dir_entry_struct file_entry;
+ if(find_file_in_dir(fs, dd, command, &file_entry))
+ {
+ if(fat_delete_file(fs, &file_entry))
+ continue;
+ }
+
+ printf_P(PSTR("error deleting file: %s\n"), command);
+ }
+ else if(strncmp_P(command, PSTR("touch "), 6) == 0)
+ {
+ command += 6;
+ if(command[0] == '\0')
+ continue;
+
+ struct fat_dir_entry_struct file_entry;
+ if(!fat_create_file(dd, command, &file_entry))
+ {
+ printf_P(PSTR("error creating file: %s\n"), command);
+ }
+ }
+ else if(strncmp_P(command, PSTR("mv "), 3) == 0)
+ {
+ command += 3;
+ if(command[0] == '\0')
+ continue;
+
+ char* target = command;
+ while(*target != ' ' && *target != '\0')
+ ++target;
+
+ if(*target == ' ')
+ *target++ = '\0';
+ else
+ continue;
+
+ struct fat_dir_entry_struct file_entry;
+ if(find_file_in_dir(fs, dd, command, &file_entry))
+ {
+ if(fat_move_file(fs, &file_entry, dd, target))
+ continue;
+ }
+
+ printf_P(PSTR("error moving file: %s\n"), command);
+ }
+ else if(strncmp_P(command, PSTR("write "), 6) == 0)
+ {
+ command += 6;
+ if(command[0] == '\0')
+ continue;
+
+ char* offset_value = command;
+ while(*offset_value != ' ' && *offset_value != '\0')
+ ++offset_value;
+
+ if(*offset_value == ' ')
+ *offset_value++ = '\0';
+ else
+ continue;
+
+ /* search file in current directory and open it */
+ struct fat_file_struct* fd = open_file_in_dir(fs, dd, command);
+ if(!fd)
+ {
+ printf_P(PSTR("error opening %s\n"), command);
+ continue;
+ }
+
+ int32_t offset = strtolong(offset_value);
+ if(!fat_seek_file(fd, &offset, FAT_SEEK_SET))
+ {
+ printf_P(PSTR("error seeking on %s\n"), command);
+
+ fat_close_file(fd);
+ continue;
+ }
+
+ /* read text from the shell and write it to the file */
+ uint8_t data_len;
+ while(1)
+ {
+ /* give a different prompt */
+ printf_P(PSTR("< "));
+
+ /* read one line of text */
+ data_len = read_line(buffer, sizeof(buffer));
+ if(!data_len)
+ break;
+
+ /* write text to file */
+ if(fat_write_file(fd, (uint8_t*) buffer, data_len) != data_len)
+ {
+ printf_P(PSTR("error writing to file\n"));
+ break;
+ }
+ }
+
+ fat_close_file(fd);
+ }
+ else if(strncmp_P(command, PSTR("mkdir "), 6) == 0)
+ {
+ command += 6;
+ if(command[0] == '\0')
+ continue;
+
+ struct fat_dir_entry_struct dir_entry;
+ if(!fat_create_dir(dd, command, &dir_entry))
+ {
+ printf_P(PSTR("error creating directory: %s\n"), command);
+ }
+ }