static void colon_process(void) { int keypress; /* Clear the current line and print a prompt */ print_statusline(" :"); keypress = less_getch(2); switch (keypress) { case 'd': remove_current_file(); break; case 'e': examine_file(); break; #if ENABLE_FEATURE_LESS_FLAGS case 'f': m_status_print(); break; #endif case 'n': change_file(1); break; case 'p': change_file(-1); break; case 'q': less_exit(EXIT_SUCCESS); break; case 'x': change_file(0); break; } }
/* Examines a directory, treating it as a bundle, and determines whether it has an executable. * Examines the executable as a regular file to determine which architectures it matches. * Prints out the results. */ static void examine_bundle(const uint8_t *bundle_path) { CFURLRef bundleURL = CFURLCreateFromFileSystemRepresentation(NULL, bundle_path, strlen((const char *)bundle_path), true), executableURL = NULL; CFBundleRef bundle = NULL; uint8_t path[PATH_MAX]; struct stat statBuf; if (bundleURL && (bundle = CFBundleCreate(NULL, bundleURL))) { // Try to obtain a path to an executable within the bundle. executableURL = CFBundleCopyExecutableURL(bundle); if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, path, PATH_MAX) && stat((const char *)path, &statBuf) == 0) { // Make sure it is a regular file, and if so examine it as a regular file. if ((statBuf.st_mode & S_IFMT) == S_IFREG) { examine_file(path); } else { printf("Unsupported file type for file %s.\n", path); } } else { printf("No executable located for %s.\n", bundle_path); } } else { printf("Cannot read %s.\n", bundle_path); } if (executableURL) CFRelease(executableURL); if (bundle) CFRelease(bundle); if (bundleURL) CFRelease(bundleURL); }
/* Examines each argument, determining whether it represents a directory or a regular file. * Treats directories as bundles and regular files as standalone executables. * Examines bundle or standalone executables to determine which architectures they match. * Prints out the results. */ main(int argc, char **argv) { int i; struct stat statBuf; for (i = 1; i < argc; i++) { uint8_t *path = (uint8_t *)(argv[i]); if (stat((const char *)path, &statBuf) == 0) { // Check to see whether it is a regular file or a directory. if ((statBuf.st_mode & S_IFMT) == S_IFREG) { examine_file(path); } else if ((statBuf.st_mode & S_IFMT) == S_IFDIR) { examine_bundle(path); } else { printf("Unsupported file type for file %s.\n", path); } } else { printf("Cannot find %s.\n", path); } } }
static void colon_process(void) { int keypress; /* Clear the current line and print a prompt */ clear_line(); printf(" :"); keypress = tless_getch(); switch (keypress) { case 'd': remove_current_file(); break; case 'e': examine_file(); break; #ifdef CONFIG_FEATURE_LESS_FLAGS case 'f': clear_line(); m_status_print(); break; #endif case 'n': change_file(1); break; case 'p': change_file(-1); break; case 'q': tless_exit(0); break; case 'x': change_file(0); break; default: break; } }
static void keypress_process(int keypress) { switch (keypress) { case KEYCODE_DOWN: case 'e': case 'j': case 0x0d: buffer_down(1); break; case KEYCODE_UP: case 'y': case 'k': buffer_up(1); break; case KEYCODE_PAGEDOWN: case ' ': case 'z': case 'f': buffer_down(max_displayed_line + 1); break; case KEYCODE_PAGEUP: case 'w': case 'b': buffer_up(max_displayed_line + 1); break; case 'd': buffer_down((max_displayed_line + 1) / 2); break; case 'u': buffer_up((max_displayed_line + 1) / 2); break; case KEYCODE_HOME: case 'g': case 'p': case '<': case '%': buffer_line(0); break; case KEYCODE_END: case 'G': case '>': cur_fline = MAXLINES; read_lines(); buffer_line(cur_fline); break; case 'q': case 'Q': less_exit(EXIT_SUCCESS); break; #if ENABLE_FEATURE_LESS_MARKS case 'm': add_mark(); buffer_print(); break; case '\'': goto_mark(); buffer_print(); break; #endif case 'r': case 'R': buffer_print(); break; /*case 'R': full_repaint(); break;*/ case 's': save_input_to_file(); break; case 'E': examine_file(); break; #if ENABLE_FEATURE_LESS_FLAGS case '=': m_status_print(); break; #endif #if ENABLE_FEATURE_LESS_REGEXP case '/': option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS; regex_process(); break; case 'n': goto_match(match_pos + 1); break; case 'N': goto_match(match_pos - 1); break; case '?': option_mask32 |= LESS_STATE_MATCH_BACKWARDS; regex_process(); break; #endif #if ENABLE_FEATURE_LESS_DASHCMD case '-': flag_change(); buffer_print(); break; #ifdef BLOAT case '_': show_flag_status(); break; #endif #endif #if ENABLE_FEATURE_LESS_BRACKETS case '{': case '(': case '[': match_right_bracket(keypress); break; case '}': case ')': case ']': match_left_bracket(keypress); break; #endif case ':': colon_process(); break; } if (isdigit(keypress)) number_process(keypress); }
static void keypress_process(int keypress) { switch (keypress) { case KEY_DOWN: case 'e': case 'j': case '\015': buffer_down(1); buffer_print(); break; case KEY_UP: case 'y': case 'k': buffer_up(1); buffer_print(); break; case PAGE_DOWN: case ' ': case 'z': buffer_down(height - 1); buffer_print(); break; case PAGE_UP: case 'w': case 'b': buffer_up(height - 1); buffer_print(); break; case 'd': buffer_down((height - 1) / 2); buffer_print(); break; case 'u': buffer_up((height - 1) / 2); buffer_print(); break; case 'g': case 'p': case '<': case '%': buffer_line(0); break; case 'G': case '>': buffer_line(num_flines - height + 2); break; case 'q': case 'Q': tless_exit(0); break; #ifdef CONFIG_FEATURE_LESS_MARKS case 'm': add_mark(); buffer_print(); break; case '\'': goto_mark(); buffer_print(); break; #endif case 'r': buffer_print(); break; case 'R': full_repaint(); break; case 's': if (inp_stdin) save_input_to_file(); break; case 'E': examine_file(); break; #ifdef CONFIG_FEATURE_LESS_FLAGS case '=': clear_line(); m_status_print(); break; #endif #ifdef CONFIG_FEATURE_LESS_REGEXP case '/': match_backwards = 0; regex_process(); break; case 'n': goto_match(match_pos + 1); break; case 'N': goto_match(match_pos - 1); break; case '?': match_backwards = 1; regex_process(); break; #endif #ifdef CONFIG_FEATURE_LESS_FLAGCS case '-': flag_change(); buffer_print(); break; case '_': show_flag_status(); break; #endif #ifdef CONFIG_FEATURE_LESS_BRACKETS case '{': case '(': case '[': match_right_bracket(keypress); break; case '}': case ')': case ']': match_left_bracket(keypress); break; #endif case ':': colon_process(); break; default: break; } if (isdigit(keypress)) number_process(keypress); }