static void print_args(t_info *info, t_dlst *headdir) { t_node *tmp; t_dlst *it; it = info->headfile.next; if (GET(info->opt, OPT_L) || GET(info->opt, OPT_1)) { while (it != &info->headfile) { tmp = C_NODE(t_node, it); if (!GET(info->opt, OPT_A) && tmp->namtyp.d_name[0] == '.') { it = it->next; continue ; } if (GET(info->opt, OPT_L)) print_stat(tmp, info); else print_filename(tmp, info); it = it->next; } } else test_col_file(info); if (!dlst_empty(headdir)) ft_putchar('\n'); }
int main(int argc, char** argv) { int fan_fd, len; char buf[sizeof(struct fanotify_event_metadata)*1024]; struct fanotify_event_metadata *metadata; if (argc != 3) { printf("Usage: %s <root-dir> <procfs>\n", argv[0]); return 1; } procfs = argv[2]; fan_fd = fanotify_init(0, 0); if (fan_fd == -1) { perror("fanotify_init"); return 1; } fanotify_mark(fan_fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_ACCESS, AT_FDCWD, argv[1]); if (fan_fd == -1) { perror("fanotify_mark"); return 1; } while (1) { len = read(fan_fd, buf, sizeof(buf)); metadata = (struct fanotify_event_metadata*)&buf; while (FAN_EVENT_OK(metadata, len)) { print_filename(metadata->fd); close(metadata->fd); metadata = FAN_EVENT_NEXT(metadata, len); } } }
void print_files(t_info *info) { t_node *tmp; t_dlst *it; it = info->headfile.next; if (GET(info->opt, OPT_L) && !dlst_empty(&info->headfile)) ft_printf("total %d\n", info->total); if (GET(info->opt, OPT_L) || GET(info->opt, OPT_1)) { while (it != &info->headfile) { tmp = C_NODE(t_node, it); if (!GET(info->opt, OPT_A) && tmp->namtyp.d_name[0] == '.') { it = it->next; continue ; } if (GET(info->opt, OPT_L)) print_stat(tmp, info); else print_filename(tmp, info); it = it->next; } } else test_col_file(info); }
void print_files_stream(t_ll *files) { int term_width; int line_width; t_bool last; term_width = get_window_columns(); if (g_opts->oneentperline) { print_filenames_nocols(files); return ; } line_width = 0; ll_iter(files) { last = files->next == NULL; line_width += my_strlen(FINFO_LL_FILENAME(files)) + (!last * 4) + g_opts->filetypesymb; if (line_width > term_width) { my_putstr("\n"); line_width = 0; } print_filename(files->data); my_putstr(last ? "\n" : ", "); } }
int main (int argc, char *argv[]) { if (argc < 1) { return -1; } else if (argc == 1) { print_fd (STDIN); } else { int i; for (i = 1; i < argc; i++) { int status = print_filename (argv[i]); if (status == -1) { printf ("error opening file %d\n", i); return status; } } } return 0; }
/* A convenience function for displaying a list of strings in columnar format on readline's output stream. MATCHES is the list of strings, in argv format, LEN is the number of strings in MATCHES, and MAX is the length of the longest string in MATCHES. Comes from readline/complete.c and modified to write in the TUI command window using tui_putc/tui_puts. */ static void tui_rl_display_match_list(char **matches, int len, int max) { typedef int QSFUNC(const void *, const void *); int count, limit, printed_len; int i, j, k, l; char *temp; /* Screen dimension correspond to the TUI command window: */ int screenwidth = TUI_CMD_WIN->generic.width; /* If there are many items, then ask the user if she really wants to see them all. */ if (len >= rl_completion_query_items) { char msg[256]; snprintf(msg, sizeof(msg), "\nDisplay all %d possibilities? (y or n)", len); tui_puts(msg); if (get_y_or_n() == 0) { tui_puts("\n"); return; } } /* How many items of MAX length can we fit in the screen window? */ max += 2; limit = (screenwidth / max); if ((limit != 1) && ((limit * max) == screenwidth)) limit--; /* Avoid a possible floating exception. If max > screenwidth, limit will be 0 and a divide-by-zero fault will result. */ if (limit == 0) limit = 1; /* How many iterations of the printing loop? */ count = ((len + (limit - 1)) / limit); /* FIXME: sanity-check result */ /* Watch out for special case. If LEN is less than LIMIT, then just do the inner printing loop. 0 < len <= limit implies count = 1. */ /* Sort the items if they are not already sorted. */ if (rl_ignore_completion_duplicates == 0) qsort(matches + 1, len, sizeof(char *), (QSFUNC *)_rl_qsort_string_compare); tui_putc('\n'); if (_rl_print_completions_horizontally == 0) { /* Print the sorted items, up-and-down alphabetically, like ls. */ for (i = 1; i <= count; i++) { for (j = 0, l = i; j < limit; j++) { if ((l > len) || (matches[l] == 0)) break; else { temp = printable_part(matches[l]); printed_len = print_filename(temp, matches[l]); if ((j + 1) < limit) for (k = 0; k < (max - printed_len); k++) tui_putc(' '); } l += count; } tui_putc('\n'); } } else { /* Print the sorted items, across alphabetically, like ls -x. */ for (i = 1; matches[i]; i++) { temp = printable_part(matches[i]); printed_len = print_filename(temp, matches[i]); /* Have we reached the end of this line? */ if (matches[i + 1]) { if (i && (limit > 1) && ((i % limit) == 0)) tui_putc('\n'); else for (k = 0; k < max - printed_len; k++) tui_putc(' '); } } tui_putc('\n'); } }