LPCTSTR FileTypeManager::set_type(Entry* entry, bool dont_hide_ext) { LPCTSTR ext = _tcsrchr(entry->_data.cFileName, TEXT('.')); if (ext) { const FileTypeInfo& type = (*this)[ext]; if (!type._displayname.empty()) entry->_type_name = _tcsdup(type._displayname); // hide some file extensions if (type._neverShowExt && !dont_hide_ext) { int len = ext - entry->_data.cFileName; if (entry->_display_name != entry->_data.cFileName) free(entry->_display_name); entry->_display_name = (LPTSTR) malloc((len+1)*sizeof(TCHAR)); lstrcpyn(entry->_display_name, entry->_data.cFileName, len + 1); } if (is_exe_file(ext)) entry->_data.dwFileAttributes |= ATTRIBUTE_EXECUTABLE; } return ext; }
// Main function int main(int argc, char const *argv[]) { char input[MAX_LINE]; // input string char **cmd_argv; // parsed arguments int cmd_argc; // arguments number bool cmd_found; // flag to indicate if command is found // Print initial help message cmd_help.execute(1,&(cmd_help.cmd)); update_current_dir(); // Main superloop while(true) { // Read command from input stream printf("[%s]%c ", current_dir, INVITE_CHAR); gets(input); // Parse input stream cmd_argv = parse(input, ARG_SEPARATOR, &cmd_argc); remove_empty_or_whitespace(&cmd_argv, &cmd_argc); if (cmd_argc == 0) continue; // Search for appropriate built-in command and execute it cmd_found = false; for (int i = 0; i < commands_count; ++i) { if (strcmp(cmd_argv[0],commands[i]->cmd) == 0) { cmd_found = true; commands[i]->execute(cmd_argc, cmd_argv); break; } } // Search for appropriate executable file and execute it if (!cmd_found) { if (is_exe_file(cmd_argv[0])) { cmd_found = true; execute_file(cmd_argc, cmd_argv); } } // Error message, if command not found if (!cmd_found) { fprintf(stderr, "Error: \"%s\" command not found!\n", cmd_argv[0]); } // Release resources free_strs(cmd_argv, cmd_argc); } return EXIT_SUCCESS; }