summaryrefslogtreecommitdiff
path: root/corebinutils/ls/ls.h
blob: 9668bdce4cbb53c6807172824eea219dca36a6c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*-
 * SPDX-License-Identifier: BSD-3-Clause
 *
 * Copyright (c) 1989, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Copyright (c) 2026
 *  Project Tick. All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Michael Fischbein.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef LS_H
#define LS_H

#include <sys/stat.h>
#include <sys/types.h>

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>

enum layout_mode {
	LAYOUT_SINGLE = 0,
	LAYOUT_COLUMNS,
	LAYOUT_LONG,
	LAYOUT_STREAM,
};

enum sort_mode {
	SORT_NAME = 0,
	SORT_TIME,
	SORT_SIZE,
	SORT_VERSION,
};

enum time_field {
	TIME_MTIME = 0,
	TIME_ATIME,
	TIME_BTIME,
	TIME_CTIME,
};

enum follow_mode {
	FOLLOW_DEFAULT = 0,
	FOLLOW_COMMAND_LINE,
	FOLLOW_ALL,
	FOLLOW_NEVER,
};

enum group_mode {
	GROUP_NONE = 0,
	GROUP_DIRS_FIRST,
	GROUP_DIRS_LAST,
};

enum name_mode {
	NAME_LITERAL = 0,
	NAME_PRINTABLE,
	NAME_OCTAL,
	NAME_ESCAPE,
};

enum color_mode {
	COLOR_DEFAULT = 0,
	COLOR_NEVER,
	COLOR_AUTO,
	COLOR_ALWAYS,
};

struct file_time {
	struct timespec ts;
	bool available;
};

struct options {
	enum layout_mode layout;
	enum sort_mode sort;
	enum time_field time_field;
	enum follow_mode follow;
	enum group_mode group_dirs;
	enum name_mode name_mode;
	enum color_mode color_mode;
	long block_units;
	size_t terminal_width;
	const char *time_format;
	bool stdout_is_tty;
	bool show_all;
	bool show_almost_all;
	bool disable_root_almost_all;
	bool list_directory_itself;
	bool recursive;
	bool show_full_time;
	bool human_readable;
	bool show_inode;
	bool show_blocks;
	bool show_type;
	bool slash_only;
	bool numeric_ids;
	bool suppress_owner;
	bool reverse_sort;
	bool same_sort_direction;
	bool no_sort;
	bool sort_across;
	bool thousands;
	bool colorize;
};

struct entry {
	char *name;
	char *path;
	struct stat st;
	struct file_time btime;
	char *user;
	char *group;
	char *link_target;
	int stat_errno;
	bool stat_ok;
	bool is_dir;
	bool is_symlink;
	bool followed;
};

struct entry_list {
	struct entry *items;
	size_t len;
	size_t cap;
};

struct display_info {
	uintmax_t total_blocks;
	size_t max_name_width;
	size_t inode_width;
	size_t block_width;
	size_t links_width;
	size_t user_width;
	size_t group_width;
	size_t size_width;
};

struct context {
	struct options opt;
	time_t now;
	int exit_status;
	bool wrote_output;
};

struct visit_stack {
	dev_t dev;
	ino_t ino;
	const struct visit_stack *parent;
};

#endif