Blame view

scripts/get_feat.pl 14.3 KB
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
1
2
3
4
5
6
7
8
  #!/usr/bin/perl
  # SPDX-License-Identifier: GPL-2.0
  
  use strict;
  use Pod::Usage;
  use Getopt::Long;
  use File::Find;
  use Fcntl ':mode';
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
9
  use Cwd 'abs_path';
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
10
11
12
13
14
15
  
  my $help;
  my $man;
  my $debug;
  my $arch;
  my $feat;
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
16
17
18
19
20
  
  my $basename = abs_path($0);
  $basename =~ s,/[^/]+$,/,;
  
  my $prefix=$basename . "../Documentation/features";
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
21

f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
22
23
24
25
  # Used only at for full features output. The script will auto-adjust
  # such values for the minimal possible values
  my $status_size = 1;
  my $description_size = 1;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
26
27
28
29
30
31
  GetOptions(
  	"debug|d+" => \$debug,
  	"dir=s" => \$prefix,
  	'help|?' => \$help,
  	'arch=s' => \$arch,
  	'feat=s' => \$feat,
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
32
  	'feature=s' => \$feat,
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
33
34
35
36
37
  	man => \$man
  ) or pod2usage(2);
  
  pod2usage(1) if $help;
  pod2usage(-exitstatus => 0, -verbose => 2) if $man;
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
38
  pod2usage(1) if (scalar @ARGV < 1 || @ARGV > 2);
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
39
40
  
  my ($cmd, $arg) = @ARGV;
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
41
42
  pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate"
  		&& $cmd ne "ls" && $cmd ne "list");
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
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
  
  require Data::Dumper if ($debug);
  
  my %data;
  my %archs;
  
  #
  # Displays an error message, printing file name and line
  #
  sub parse_error($$$$) {
  	my ($file, $ln, $msg, $data) = @_;
  
  	$data =~ s/\s+$/
  /;
  
  	print STDERR "Warning: file $file#$ln:
  \t$msg";
  
  	if ($data ne "") {
  		print STDERR ". Line
  \t\t$data";
  	} else {
  	    print STDERR "
  ";
  	}
  }
  
  #
  # Parse a features file, storing its contents at %data
  #
  
  my $h_name = "Feature";
  my $h_kconfig = "Kconfig";
  my $h_description = "Description";
  my $h_subsys = "Subsystem";
  my $h_status = "Status";
  my $h_arch = "Architecture";
  
  my $max_size_name = length($h_name);
  my $max_size_kconfig = length($h_kconfig);
  my $max_size_description = length($h_description);
  my $max_size_subsys = length($h_subsys);
  my $max_size_status = length($h_status);
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
86
87
88
89
  
  my $max_size_arch = 0;
  my $max_size_arch_with_header;
  my $max_description_word = 0;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
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
  
  sub parse_feat {
  	my $file = $File::Find::name;
  
  	my $mode = (stat($file))[2];
  	return if ($mode & S_IFDIR);
  	return if ($file =~ m,($prefix)/arch-support.txt,);
  	return if (!($file =~ m,arch-support.txt$,));
  
  	my $subsys = "";
  	$subsys = $2 if ( m,.*($prefix)/([^/]+).*,);
  
  	if (length($subsys) > $max_size_subsys) {
  		$max_size_subsys = length($subsys);
  	}
  
  	my $name;
  	my $kconfig;
  	my $description;
  	my $comments = "";
  	my $last_status;
  	my $ln;
  	my %arch_table;
  
  	print STDERR "Opening $file
  " if ($debug > 1);
  	open IN, $file;
  
  	while(<IN>) {
  		$ln++;
  
  		if (m/^\#\s+Feature\s+name:\s*(.*\S)/) {
  			$name = $1;
  			if (length($name) > $max_size_name) {
  				$max_size_name = length($name);
  			}
  			next;
  		}
  		if (m/^\#\s+Kconfig:\s*(.*\S)/) {
  			$kconfig = $1;
  			if (length($kconfig) > $max_size_kconfig) {
  				$max_size_kconfig = length($kconfig);
  			}
  			next;
  		}
  		if (m/^\#\s+description:\s*(.*\S)/) {
  			$description = $1;
  			if (length($description) > $max_size_description) {
  				$max_size_description = length($description);
  			}
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
140
141
142
143
144
145
  
  			foreach my $word (split /\s+/, $description) {
  				if (length($word) > $max_description_word) {
  					$max_description_word = length($word);
  				}
  			}
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  			next;
  		}
  		next if (m/^\\s*$/);
  		next if (m/^\s*\-+\s*$/);
  		next if (m/^\s*\|\s*arch\s*\|\s*status\s*\|\s*$/);
  
  		if (m/^\#\s*(.*)/) {
  			$comments .= "$1
  ";
  			next;
  		}
  		if (m/^\s*\|\s*(\S+):\s*\|\s*(\S+)\s*\|\s*$/) {
  			my $a = $1;
  			my $status = $2;
  
  			if (length($status) > $max_size_status) {
  				$max_size_status = length($status);
  			}
  			if (length($a) > $max_size_arch) {
  				$max_size_arch = length($a);
  			}
  
  			$status = "---" if ($status =~ m/^\.\.$/);
  
  			$archs{$a} = 1;
  			$arch_table{$a} = $status;
  			next;
  		}
  
  		#Everything else is an error
  		parse_error($file, $ln, "line is invalid", $_);
  	}
  	close IN;
  
  	if (!$name) {
  		parse_error($file, $ln, "Feature name not found", "");
  		return;
  	}
  
  	parse_error($file, $ln, "Subsystem not found", "") if (!$subsys);
  	parse_error($file, $ln, "Kconfig not found", "") if (!$kconfig);
  	parse_error($file, $ln, "Description not found", "") if (!$description);
  
  	if (!%arch_table) {
  		parse_error($file, $ln, "Architecture table not found", "");
  		return;
  	}
  
  	$data{$name}->{where} = $file;
  	$data{$name}->{subsys} = $subsys;
  	$data{$name}->{kconfig} = $kconfig;
  	$data{$name}->{description} = $description;
  	$data{$name}->{comments} = $comments;
  	$data{$name}->{table} = \%arch_table;
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
200
201
  
  	$max_size_arch_with_header = $max_size_arch + length($h_arch);
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  }
  
  #
  # Output feature(s) for a given architecture
  #
  sub output_arch_table {
  	my $title = "Feature status on $arch architecture";
  
  	print "=" x length($title) . "
  ";
  	print "$title
  ";
  	print "=" x length($title) . "
  
  ";
  
  	print "=" x $max_size_subsys;
  	print "  ";
  	print "=" x $max_size_name;
  	print "  ";
  	print "=" x $max_size_kconfig;
  	print "  ";
  	print "=" x $max_size_status;
  	print "  ";
  	print "=" x $max_size_description;
  	print "
  ";
  	printf "%-${max_size_subsys}s  ", $h_subsys;
  	printf "%-${max_size_name}s  ", $h_name;
  	printf "%-${max_size_kconfig}s  ", $h_kconfig;
  	printf "%-${max_size_status}s  ", $h_status;
  	printf "%-${max_size_description}s
  ", $h_description;
  	print "=" x $max_size_subsys;
  	print "  ";
  	print "=" x $max_size_name;
  	print "  ";
  	print "=" x $max_size_kconfig;
  	print "  ";
  	print "=" x $max_size_status;
  	print "  ";
  	print "=" x $max_size_description;
  	print "
  ";
  
  	foreach my $name (sort {
  				($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
249
  				("\L$a" cmp "\L$b")
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
250
251
252
253
254
255
256
257
  			       } keys %data) {
  		next if ($feat && $name ne $feat);
  
  		my %arch_table = %{$data{$name}->{table}};
  		printf "%-${max_size_subsys}s  ", $data{$name}->{subsys};
  		printf "%-${max_size_name}s  ", $name;
  		printf "%-${max_size_kconfig}s  ", $data{$name}->{kconfig};
  		printf "%-${max_size_status}s  ", $arch_table{$arch};
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
258
259
  		printf "%-s
  ", $data{$name}->{description};
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
  	}
  
  	print "=" x $max_size_subsys;
  	print "  ";
  	print "=" x $max_size_name;
  	print "  ";
  	print "=" x $max_size_kconfig;
  	print "  ";
  	print "=" x $max_size_status;
  	print "  ";
  	print "=" x $max_size_description;
  	print "
  ";
  }
  
  #
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  # list feature(s) for a given architecture
  #
  sub list_arch_features {
  	print "#
  # Kernel feature support matrix of the '$arch' architecture:
  #
  ";
  
  	foreach my $name (sort {
  				($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
  				("\L$a" cmp "\L$b")
  			       } keys %data) {
  		next if ($feat && $name ne $feat);
  
  		my %arch_table = %{$data{$name}->{table}};
  
  		my $status = $arch_table{$arch};
  		$status = " " x ((4 - length($status)) / 2) . $status;
  
  		printf " %${max_size_subsys}s/ ", $data{$name}->{subsys};
  		printf "%-${max_size_name}s: ", $name;
  		printf "%-5s|   ", $status;
  		printf "%${max_size_kconfig}s # ", $data{$name}->{kconfig};
  		printf " %s
  ", $data{$name}->{description};
  	}
  }
  
  #
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
  # Output a feature on all architectures
  #
  sub output_feature {
  	my $title = "Feature $feat";
  
  	print "=" x length($title) . "
  ";
  	print "$title
  ";
  	print "=" x length($title) . "
  
  ";
  
  	print ":Subsystem: $data{$feat}->{subsys} 
  " if ($data{$feat}->{subsys});
  	print ":Kconfig: $data{$feat}->{kconfig} 
  " if ($data{$feat}->{kconfig});
  
  	my $desc = $data{$feat}->{description};
  	$desc =~ s/^([a-z])/\U$1/;
  	$desc =~ s/\.?\s*//;
  	print "
  $desc.
  
  ";
  
  	my $com = $data{$feat}->{comments};
  	$com =~ s/^\s+//;
  	$com =~ s/\s+$//;
  	if ($com) {
  		print "Comments
  ";
  		print "--------
  
  ";
  		print "$com
  
  ";
  	}
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
344
  	print "=" x $max_size_arch_with_header;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
345
346
347
348
349
350
351
352
  	print "  ";
  	print "=" x $max_size_status;
  	print "
  ";
  
  	printf "%-${max_size_arch}s  ", $h_arch;
  	printf "%-${max_size_status}s", $h_status . "
  ";
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
353
  	print "=" x $max_size_arch_with_header;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
354
355
356
357
358
359
360
361
362
363
364
  	print "  ";
  	print "=" x $max_size_status;
  	print "
  ";
  
  	my %arch_table = %{$data{$feat}->{table}};
  	foreach my $arch (sort keys %arch_table) {
  		printf "%-${max_size_arch}s  ", $arch;
  		printf "%-${max_size_status}s
  ", $arch_table{$arch};
  	}
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
365
  	print "=" x $max_size_arch_with_header;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
366
367
368
369
370
371
372
373
374
  	print "  ";
  	print "=" x $max_size_status;
  	print "
  ";
  }
  
  #
  # Output all features for all architectures
  #
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
375
376
377
  sub matrix_lines($$$) {
  	my $desc_size = shift;
  	my $status_size = shift;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
378
  	my $header = shift;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
379
380
381
382
383
384
385
386
  	my $fill;
  	my $ln_marker;
  
  	if ($header) {
  		$ln_marker = "=";
  	} else {
  		$ln_marker = "-";
  	}
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
387

dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
388
  	$fill = $ln_marker;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
389

dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
390
  	print "+";
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
391
  	print $fill x $max_size_name;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
392
  	print "+";
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
393
  	print $fill x $desc_size;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
394
  	print "+";
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
395
  	print $ln_marker x $status_size;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
396
397
  	print "+
  ";
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
398
399
400
  }
  
  sub output_matrix {
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
401
  	my $title = "Feature status on all architectures";
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
402
  	my $notcompat = "Not compatible";
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
403
404
405
406
407
408
409
410
  
  	print "=" x length($title) . "
  ";
  	print "$title
  ";
  	print "=" x length($title) . "
  
  ";
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
411
412
413
  	my $desc_title = "$h_kconfig / $h_description";
  
  	my $desc_size = $max_size_kconfig + 4;
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
414
415
416
417
418
419
  	if (!$description_size) {
  		$desc_size = $max_size_description if ($max_size_description > $desc_size);
  	} else {
  		$desc_size = $description_size if ($description_size > $desc_size);
  	}
  	$desc_size = $max_description_word if ($max_description_word > $desc_size);
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
420
  	$desc_size = length($desc_title) if (length($desc_title) > $desc_size);
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
421
422
423
424
425
  	$max_size_status = length($notcompat) if (length($notcompat) > $max_size_status);
  
  	# Ensure that the status will fit
  	my $min_status_size = $max_size_status + $max_size_arch + 6;
  	$status_size = $min_status_size if ($status_size < $min_status_size);
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
426

ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
427
428
429
  	my $cur_subsys = "";
  	foreach my $name (sort {
  				($data{$a}->{subsys} cmp $data{$b}->{subsys}) or
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
430
  				("\L$a" cmp "\L$b")
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
431
  			       } keys %data) {
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
432

ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
433
434
435
436
437
  		if ($cur_subsys ne $data{$name}->{subsys}) {
  			if ($cur_subsys ne "") {
  				printf "
  ";
  			}
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
438

ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
439
  			$cur_subsys = $data{$name}->{subsys};
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
440

ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
441
442
443
444
445
446
  			my $title = "Subsystem: $cur_subsys";
  			print "$title
  ";
  			print "=" x length($title) . "
  
  ";
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
447

52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
448

dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
449
450
451
452
  			matrix_lines($desc_size, $status_size, 0);
  
  			printf "|%-${max_size_name}s", $h_name;
  			printf "|%-${desc_size}s", $desc_title;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
453

dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
454
455
456
  			printf "|%-${status_size}s|
  ", "Status per architecture";
  			matrix_lines($desc_size, $status_size, 1);
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
457
  		}
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
458

ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
459
  		my %arch_table = %{$data{$name}->{table}};
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
460
  		my $cur_status = "";
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
461
  		my (@lines, @descs);
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
462
463
  		my $line = "";
  		foreach my $arch (sort {
4fa32f870   Mauro Carvalho Chehab   scripts: get_feat...
464
  					($arch_table{$b} cmp $arch_table{$a}) or
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
465
466
467
468
469
470
  					("\L$a" cmp "\L$b")
  				       } keys %arch_table) {
  
  			my $status = $arch_table{$arch};
  
  			if ($status eq "---") {
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
471
  				$status = $notcompat;
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
472
473
474
475
476
477
478
479
480
481
  			}
  
  			if ($status ne $cur_status) {
  				if ($line ne "") {
  					push @lines, $line;
  					$line = "";
  				}
  				$line = "- **" . $status . "**: " . $arch;
  			} elsif (length($line) + length ($arch) + 2 < $status_size) {
  				$line .= ", " . $arch;
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
482
  			} else {
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
483
484
485
486
487
488
  				push @lines, $line;
  				$line = "  " . $arch;
  			}
  			$cur_status = $status;
  		}
  		push @lines, $line if ($line ne "");
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  		my $description = $data{$name}->{description};
  		while (length($description) > $desc_size) {
  			my $d = substr $description, 0, $desc_size;
  
  			# Ensure that it will end on a space
  			# if it can't, it means that the size is too small
  			# Instead of aborting it, let's print what we have
  			if (!($d =~ s/^(.*)\s+.*/$1/)) {
  				$d = substr $d, 0, -1;
  				push @descs, "$d\\";
  				$description =~ s/^\Q$d\E//;
  			} else {
  				push @descs, $d;
  				$description =~ s/^\Q$d\E\s+//;
  			}
  		}
  		push @descs, $description;
  
  		# Ensure that the full description will be printed
  		push @lines, "" while (scalar(@lines) < 2 + scalar(@descs));
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
509

dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
510
511
512
513
514
  		my $ln = 0;
  		for my $line(@lines) {
  			if (!$ln) {
  				printf "|%-${max_size_name}s", $name;
  				printf "|%-${desc_size}s", "``" . $data{$name}->{kconfig} . "``";
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
515
  			} elsif ($ln >= 2 && scalar(@descs)) {
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
516
  				printf "|%-${max_size_name}s", "";
f5889e70b   Mauro Carvalho Chehab   scripts: get_feat...
517
  				printf "|%-${desc_size}s", shift @descs;
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
518
  			} else {
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
519
  				printf "|%-${max_size_name}s", "";
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
520
  				printf "|%-${desc_size}s", "";
ba813f7c2   Mauro Carvalho Chehab   scripts: get_feat...
521
  			}
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
522
523
524
525
526
  
  			printf "|%-${status_size}s|
  ", $line;
  
  			$ln++;
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
527
  		}
dbb909023   Mauro Carvalho Chehab   scripts: get_feat...
528
  		matrix_lines($desc_size, $status_size, 0);
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
529
  	}
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  }
  
  
  #
  # Parses all feature files located at $prefix dir
  #
  find({wanted =>\&parse_feat, no_chdir => 1}, $prefix);
  
  print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug);
  
  #
  # Handles the command
  #
  if ($cmd eq "current") {
  	$arch = qx(uname -m | sed 's/x86_64/x86/' | sed 's/i386/x86/');
  	$arch =~s/\s+$//;
  }
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
547
548
549
550
551
552
553
554
555
556
  if ($cmd eq "ls" or $cmd eq "list") {
  	if (!$arch) {
  		$arch = qx(uname -m | sed 's/x86_64/x86/' | sed 's/i386/x86/');
  		$arch =~s/\s+$//;
  	}
  
  	list_arch_features;
  
  	exit;
  }
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  if ($cmd ne "validate") {
  	if ($arch) {
  		output_arch_table;
  	} elsif ($feat) {
  		output_feature;
  	} else {
  		output_matrix;
  	}
  }
  
  __END__
  
  =head1 NAME
  
  get_feat.pl - parse the Linux Feature files and produce a ReST book.
  
  =head1 SYNOPSIS
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
574
575
  B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>] [--arch=<arch>]
  	       [--feature=<feature>|--feat=<feature>] <COMAND> [<ARGUMENT>]
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
576
577
578
579
  
  Where <COMMAND> can be:
  
  =over 8
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
580
581
582
583
584
585
  B<current>               - output table in ReST compatible ASCII format
  			   with features for this machine's architecture
  
  B<rest>                  - output table(s)  in ReST compatible ASCII format
  			   with features in ReST markup language. The output
  			   is affected by --arch or --feat/--feature flags.
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
586

ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
587
588
  B<validate>              - validate the contents of the files under
  			   Documentation/features.
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
589

ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
590
591
592
  B<ls> or B<list>         - list features for this machine's architecture,
  			   using an easier to parse format.
  			   The output is affected by --arch flag.
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
593
594
595
596
597
598
599
600
601
602
603
  
  =back
  
  =head1 OPTIONS
  
  =over 8
  
  =item B<--arch>
  
  Output features for an specific architecture, optionally filtering for
  a single specific feature.
ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
604
  =item B<--feat> or B<--feature>
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
605

ca9085777   Mauro Carvalho Chehab   scripts: get_feat...
606
  Output features for a single specific feature.
52a4be3ff   Mauro Carvalho Chehab   scripts: get_feat...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
  
  =item B<--dir>
  
  Changes the location of the Feature files. By default, it uses
  the Documentation/features directory.
  
  =item B<--debug>
  
  Put the script in verbose mode, useful for debugging. Can be called multiple
  times, to increase verbosity.
  
  =item B<--help>
  
  Prints a brief help message and exits.
  
  =item B<--man>
  
  Prints the manual page and exits.
  
  =back
  
  =head1 DESCRIPTION
  
  Parse the Linux feature files from Documentation/features (by default),
  optionally producing results at ReST format.
  
  It supports output data per architecture, per feature or a
  feature x arch matrix.
  
  When used with B<rest> command, it will use either one of the tree formats:
  
  If neither B<--arch> or B<--feature> arguments are used, it will output a
  matrix with features per architecture.
  
  If B<--arch> argument is used, it will output the features availability for
  a given architecture.
  
  If B<--feat> argument is used, it will output the content of the feature
  file using ReStructured Text markup.
  
  =head1 BUGS
  
  Report bugs to Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
  
  =head1 COPYRIGHT
  
  Copyright (c) 2019 by Mauro Carvalho Chehab <mchehab+samsung@kernel.org>.
  
  License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
  
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  
  =cut