//! @brief Minimalist file editor to append char to a file //! //! @verbatim //! hit ^q to exit and save file //! @endverbatim //! void ushell_cmd_append_file( void ) { int c_key; if( g_s_arg[0][0] == 0 ) return; // Select file or directory if( !nav_setcwd( (FS_STRING)g_s_arg[0], true, false ) ) { fputs(MSG_ER_UNKNOWN_FILE, stdout); return; } // Open file if( !file_open(FOPEN_MODE_APPEND) ) { fputs(MSG_KO, stdout); return; } // Append file fputs(MSG_APPEND_WELCOME, stdout); while( 1 ) { usart_reset_status(SHL_USART); while(usart_read_char(SHL_USART, &c_key) != USART_SUCCESS); if( c_key == ASCII_CTRL_Q ) break; // ^q to quit putchar( c_key ); file_putc( c_key ); if( c_key == ASCII_CR ) { putchar(ASCII_LF); file_putc(ASCII_LF); } } // Close file file_close(); putchar(ASCII_CR);putchar(ASCII_LF); }
/** * If the lookup name matches one of the built-in transformations, generate * that and return 1. Otherwise, return 0. */ int generate_lookup_builtin(Pool *pool, FILE *out, AstLookup *p) { if (string_equal(p->name, string_from_k("quote"))) { CHECK(file_putc(out, '"')); CHECK(file_write(out, p->item->name.p, p->item->name.end)); CHECK(file_putc(out, '"')); return 1; } else if (string_equal(p->name, string_from_k("lower"))) { return generate_lower(out, p->item->name); } else if (string_equal(p->name, string_from_k("upper"))) { return generate_upper(out, p->item->name); } else if (string_equal(p->name, string_from_k("camel"))) { return generate_camel(out, p->item->name); } else if (string_equal(p->name, string_from_k("mixed"))) { return generate_mixed(out, p->item->name); } return 0; }
/*! \brief Minimalist file editor to append char to a file. * * \note Hit ^q to exit and save file. */ static void fat_example_append_file(void) { int c; print(SHL_USART, MSG_APPEND_WELCOME); // Wait for ^q to quit. while (TRUE) { // If something new in the USART usart_reset_status(SHL_USART); if (usart_read_char(SHL_USART, &c) == USART_SUCCESS) { // if this is not the quit char if (c != QUIT_APPEND) { // Echo the char. print_char(SHL_USART, c); // Add it to the file. file_putc(c); // if it is a carriage return. if (c == CR) { // Echo line feed. print_char(SHL_USART, LF); // Add line feed to the file. file_putc(LF); } } // Quit char received. else { // Exit the append function. break; } } } }
int generate_for_item(Pool *pool, FILE *out, AstFor *p, ListNode *item, int *need_comma) { Scope *scope = scope_new(pool, p->scope); ListBuilder code = list_builder_init(pool); if (dynamic_ok(p->filter) && !test_filter(p->filter, ast_to_outline_item(item->d))) return 1; if (p->list && *need_comma) CHECK(file_putc(out, ',')); *need_comma = 1; scope_add(scope, pool, p->item, item->d); CHECK(parse_code(pool, &p->code, scope, out_list_builder(&code))); CHECK(generate_code(pool, out, code.first)); return 1; }
//! This function removes the selected file in the list //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! bool pl_rem_sel( void ) { uint8_t nav_id_save; bool b_status = false; if( !pl_main_modify() ) return false; if( 0 == pl_g_u16_list_sel ) { fs_g_status = FS_ERR_PL_OUT_LST; return false; } nav_id_save = nav_get(); nav_select( FS_NAV_ID_PLAYLIST ); // Jump at the beginning of the current path #if( PL_UNICODE == true) file_string_unicode(); if( !file_seek( pl_g_u16_path_size*2 , FS_SEEK_CUR_RE )) goto pl_rem_sys_err; #else if( !file_seek( pl_g_u16_path_size , FS_SEEK_CUR_RE )) goto pl_rem_sys_err; #endif // Comment the line if( !file_putc('#')) goto pl_rem_sys_err; b_status = true; pl_g_u16_list_size--; pl_rem_sys_err: #if( PL_UNICODE == true) file_string_ascii(); #endif // Go to beginning of file AND no file selected file_seek( 0 , FS_SEEK_SET ); pl_g_u16_list_sel = 0; nav_select( nav_id_save ); return b_status; }
//! This function adds files in play list //! //! @param sz_filterext add file only corresponding to the extension filter //! @param u8_mode PL_ADD_FILE, PL_ADD_DIR, PL_ADD_SUBDIR //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! //! @verbatim //! It is possible to select a file or all files in a directory //! @endverbatim //! bool pl_add( const FS_STRING sz_filterext , uint8_t u8_mode ) { uint8_t nav_id_save; uint8_t u8_folder_level; if( !pl_main_modify() ) return false; nav_id_save = nav_get(); // Check last character of file nav_select( FS_NAV_ID_PLAYLIST ); if( 0!=nav_file_lgt() ) { #if( PL_UNICODE == true) file_string_unicode(); file_seek( 2, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 2, FS_SEEK_END); file_putc('\n'); } file_string_ascii(); #else file_seek( 1, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 1, FS_SEEK_END); file_putc('\n'); } #endif } nav_select( nav_id_save ); // Get path of play list file and check with current to create a relative path if( PL_ADD_FILE == u8_mode ) goto pl_add_file; // Add all files valid in current dir u8_folder_level = 0; nav_filelist_reset(); while(1) { while(1) { if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) break; // a next file and directory is found // No other dir or file in current dir then go to parent dir if( 0 == u8_folder_level ) goto pl_add_end; // end of ADD // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list u8_folder_level--; if( !nav_dir_gotoparent() ) return false; } if( nav_file_isdir()) { if( PL_ADD_SUBDIR == u8_mode ) { // Enter in sub dir if( !nav_dir_cd()) return false; u8_folder_level++; } } else { pl_add_file: if( nav_file_checkext( sz_filterext ) ) { // It is a valid file // Get name of current file #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_ascii(); #endif nav_getcwd( (FS_STRING)pl_cache_path, PL_CACHE_PATH_MAX_SIZE, true ); #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_unicode(); #endif // Write path in file list nav_select( FS_NAV_ID_PLAYLIST ); #if( PL_UNICODE == true) file_string_unicode(); #endif if( file_puts(pl_cache_path)) file_putc('\n'); #if( PL_UNICODE == true) file_string_ascii(); #endif nav_select( nav_id_save ); pl_g_u16_list_size++; } if( PL_ADD_FILE == u8_mode ) goto pl_add_end; } // if dir OR file } // end of first while(1) pl_add_end: // Go to beginning of file AND no file selected nav_select( FS_NAV_ID_PLAYLIST ); file_seek( 0 , FS_SEEK_SET ); pl_g_u16_list_sel = 0; nav_select( nav_id_save ); return true; }