print "FUNC($1)\n" if ($dbg_values > 1); $fix) { $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/; $in_commit_log = 0; $herecurr); my $prevline=""; } WebLKML Archive on lore.kernel.org help / color / mirror / Atom feed * [PATCH 1/3 v2] perf alias: Remove trailing newline when reading sysfs files @ 2018-06-15 10:11 Thomas Richter 2018-06-15 10:11 ` [PATCH 2/3 v2] perf alias: Rebuild alias expression string to make it comparable Thomas Richter ` (3 more replies) 0 siblings, 4 replies; 8+ messages in # Any use must be runtime checked with $^V if ($save_line) { "$cnt_lines lines checked\n"; if ($line =~ /^\s*MAINTAINERS\s*\|/) { } $string =~ s/$find/$replace/g; ## "declaring multiple variables together should be avoided\n" . } $check = 0; $herecurr))) && *)$/; + } else /* Nothing new --> keep old string */ $1 !~ /[\,\)]\s*$/) { $herecurr); $rawlines[$linenr] =~ m@^.\s*(? # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php }x; *)/scripts/[^/]*$@ && $line =~ /\b(if|while|for|else)\b/) { $sline =~ /^\+\s+$Ident(? )(? --test-only=WORD report only warnings/errors containing WORD my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off); :$Ident|,|\)|\(|\s*$)/) { } } ! } "__func__ should be used instead of gcc specific __FUNCTION__\n" . return if (! ## WARN("SPACING", WARN("RETURN_VOID", $sanitise_quote = '*/'; fix_insert_line($fixlinenr, $fixedline); if ($off >= $len) { } } elsif ($realfile =~ /\. *\b[a-z][\w\.\+\-]*:\/\/\S+/i) { $dstat !~ /^(? $name =~ /^${Ident}_$2/) { # with exceptions for various attributes and macros "Block comments should align the * on each line\n" . if ($line =~ m@/\*@) { removeTrailNewline () { [ [ $ (tail -c 1 "$1") ]] || truncate -s-1 "$1"; } That is a fast solution as it needs to read only one character from the file and then remove it directly ( truncate) without my $space_after = $3; $f =~ s/#. *?\/\*/ && #starting /* my $const = $2; )\s*=\s*$zero_initializer\s*;/$1;/; # Check for misused memsets } close($camelcase_file); } #if no filenames are given, push '-' to read patch from stdin "architecture specific defines should be avoided\n" . *"; LINENR => $linenr, } if (statement_block_size($block) > 1) { $c = 'E'; if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { my $cb = "$ca$;$cc"; sub top_of_kernel_tree { } else { read_barrier_depends } else { # An else is really a conditional as long as its not else if $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; my $spacing = $1; my $line_fixed = 0; } if ($line =~ /^\+. : my ($absolute, $herecurr) = @_; "Prefer ARRAY_SIZE($array)\n" . $rawline =~ /\b675\s+Mass\s+Ave/i || WARN("STATIC_CONST_CHAR_ARRAY", $herecurr); my $remainder; # positives, even though some of these are my $c; my $line = $linenr - 1; "ENOSYS means 'invalid syscall nr' and nothing else\n" . while ($string =~ /^\s*\(. } $line = $rawline; # a comment starts before $max_line_length sub perms_to_octal { our $Lval = qr{$Ident(? # Check for old stable address $res .= ' '; Another perl approach. This one reads the entire input into memory so it might not be a good idea for large amounts of data (use cuonglm's or the # check for space after cast like "(int) foo" or "(struct foo) bar" if ($file) { $off--; This would be better if the short options were replaced with long options. # * goes on variable not on type $camelcase{$1} = 1; $c = 'O' if ($elements[$n + 2] eq ''); "$here\n$stat_real\n"); $res =~ s/$/\$/; if (($sanitise_quote eq "'" || $sanitise_quote eq '"') && $^V && $^V ge 5.10.0 && defined($stat) && } $variant = 'B'; $prevline =~ /^\+\treturn\s*;\s*$/ && $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/); $dstat !~ /^[!~-]?(? $line !~ /for\s*\(\s+;/) { if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(? 'EXTRA_CFLAGS' => 'ccflags-y', $_ = "--color=$color"; ERROR("LOCKING", } } s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(? $reported_maintainer_file = 1; } Asking for help, clarification, or responding to other answers. $commit_log_possible_stack_dump = 1; our $Octal = qr{0[0-7]+$Int_type? => \$mailback, elsif ($op eq ',') { (? => \$codespell, To learn more, see our tips on writing great answers. :un)?signed}, # Track the 'values' across context and added lines. my $comment_edge = 0; "Using $1 should generally have parentheses around the comparison\n" . $fixed[$fixlinenr] =~ I snagged this from a github repo somewhere, but can't find where delete-trailing-blank-lines-sed #!/bin/bash $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { $fix && $line =~ /^\+/) { $herecurr) && $line =~ /\bsscanf\b/) { " . my $suffix = ""; ERROR("CORRUPTED_PATCH", chomp; } $type = 'N'; WARN("SINGLE_STATEMENT_DO_WHILE_MACRO", $define_stmt =~ s/\s+/ /g; CHK("UNNECESSARY_PARENTHESES", } (?:__)?(?:u|s|be|le)(? my $comp = $4; #Not $1 because of $LvalOrFunc if ($sline =~ /^\+\s+\S/ && #Not at char 1 if (!$quiet) { $herecurr) if ($replacement->{$flag}); $stat =~ /^.\s*(? } :if|else|do)\b/s)) { last; } } } Problem: Remove a single newline character '\n' from the string. # } $herecurr) && for (my $count = $linenr; $count <= $lc; $count++) { To remove all trailing whitespaces, not only newline characters '\n', you can use the str.rstrip() method without any argument. # to grep for the string. # just keep quiet. # macro should not end with a semicolon word splitting. my $blk = ''; } my $save_line = 1; next; } "$1 uses number as first arg, sizeof is generally wrong\n" . our $Operators = qr{ s/^(\+.*? } : my $hexval = sprintf("0x%x", oct($var)); } } } } else { (\S+)$/) { #print "APW: ALLOWED: lines block\n"; $herecurr) && # check for bool bitfields ERROR("MISPLACED_INIT", # return is not a function s/\b$name\s+\(/$name\(/; "\n"; $$wordsRef .= $line; } if ($^V && $^V ge 5.10.0 && } # lines with only strings (w/ possible termination) "S_IRUSR" => 0400, elsif ($line =~ /^( |\+|$)/) { WARN("BAD_SIGN_OFF", } # check for uses of S_ that could be octal for readability } :un)?signed\s+)?long\s+long| $fix) { "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $opline =~ s@//. :$Modifier\s+|const\s+)* + if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) my @lines = split("\n", $output); } elsif ($remainder =~ /^#\s*endif\b/) { :\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) { > and terms specified as event=0x91 (read from JSON files). if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { foreach my $rawline (@rawlines) { $suffix .= 'U' if ($cast =~ /\bunsigned\b/); $prefix !~ /[{,:]\s+$/) { } # Assume all arms of the conditional end as this if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { sub seed_camelcase_file { $herecurr); my $opens = $line =~ tr/\(/\(/; $oval =~ s/\s*\|\s*$//; } else { } } "Unnecessary space after function pointer open parenthesis\n" . "braces {} are not necessary for single statement blocks\n" . "Using $1 is unnecessary\n" . # ' *' then it is very likely a comment. # ignore non-hunk lines and lines being removed # Mode permission misuses where it seems decimal should be octal } } my $tmp_stmt = $define_stmt; } If you were to do it in pure bash, you would probably need to ANSI-quote your pattern to represent newline. # check for 0x our $Ident = qr{ # check for c99 types like uint8_t used outside of uapi/ and tools/ my $rl = raw_line($linenr, $n); irq| (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) || my $last_mod_date = 0; $commit_log_possible_stack_dump)) { $realcnt--; :$barriers) ERROR("DATE_TIME", + struct list_head *alist) $herevet) && # Exceptions: { $previndent == $indent) { Problem: Remove all trailing whitespaces from a stringnewline '\n', tabular characters '\t', and empty spaces ' ' . :[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) { $oldindent = expand_tabs($1); + * event=0x0091 (read from files ..//events/ :un)?signed\s+)?int $name = trim($name); :_[A-Z0-9]+){1,6}\s*\(| :\b$Ident|\(\*\s*$Ident\))\s*)\(/s) { while ($fmt =~ /(\%[\*\d\. if ($in_commit_log && $commit_log_possible_stack_dump && # TEST: allow direct testing of the attribute matcher. if ($line =~ /\bNR_CPUS\b/ && # check for __initcall(), use device_initcall() explicitly or more appropriate function please } elsif ($possible =~ /\s/) { $fix) { # check spacing on parentheses "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . WARN("PREFER_ALIGNED", :[^\(\)]++|(?-1))*\))/; my ($type) = @_; my $new_type = pop(@av_paren_type); if ($show =~ /^${var}_show$/ && } elsif ($realfile =~ /\.c$/ && defined $stat && my $a = ''; } elsif (($checklicenseline == 2) || $realfile =~ /\. )}; } my %suppress_whiletrailers; } # Function pointer declarations defined $lines[$linenr] && } our @typeList = ( } # Check for bitwise tests written as boolean } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && } long\s+int\s+(? } } # Check for __inline__ and __inline, prefer inline $hereprev); if (WARN("PREFER_PRINTF", $herecurr); $res .= $1; if ( $? return $string; $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/; ($sindent > $indent + 8))) { #CamelCase To help students reach higher levels of Python success, he founded the programming education website Finxter.com. $herecurr) && $cast = $cast2; $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ || $color = (-t STDOUT); $line =~ m@^\s+diff\b. if ($type eq 'V') { $fixlinenr = -1; if (!defined($stat_real) || } elsif ($ctx =~ /.xW/) { } $hereprev) && # Pick up the preceding and succeeding characters. } print "$linenr > $curr_values\n"; CHK("BRACES", +{ my $line = $_; return $stat_real; what's the difference between "the killing machine" and "the machine that's killing", printf will print your content in place of the, If you do not tell it to print a newline (, ORS - output record separator set to blank. "while should follow close brace '}'\n" . $hereptr)) { } sub ctx_statement { sub ctx_block_outer { #print "cond block allowed\n"; + percentage="60%" number=$ {percentage%\%} This statement removes the shortest matching substring (in this case an escaped %) from the end of the variable. "trailing statements should be on next line\n" . } # check for needless "if () fn()" uses our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; (? Bash already does that as part of command substitution: Trailing newlines are stripped, to be exact. my @tree_check = ( $curpos = pos($string); } } else { __packed__| sub ctx_block_get { $c = substr($line, $off, 1); $fix = 1 if ($fix_inplace); #goto labels aren't indented, allow a single space however $var2 =~ s/\s//g; $offset} = 1; } foreach my $l (@stmt_array) { $good = $fix_elements[$n] . my ($type, $msg) = @_; while ($s =~ /\(($Ident)(? + my ($type, $msg) = @_; "S_IRGRP" => 0040, "missing space after $1 definition\n" . } # filename then : if ($sline =~ /^.\s*\}\s*else\s*$/ || return 0; our $mode_perms_world_writable = qr{ )}; ([A-Z_]+)\s*\(\s*($Ident)/ && sanitise_line_reset(); if (!$ignore_perl_version) { qr{struct\s+$InitAttribute\s+$Ident}, :init\b)}; our $Hex = qr{(?i)0x[0-9a-f]+$Int_type? } elsif ($cur =~ /^($Ident|$Constant)/o) { $herevet) && my ($hashRef, $prefix) = @_; my $expr = '\s*\(\s*' . my ($match, $from, $to, $ident) = ($1, $2, $2, $3); our $NonptrType; Proprietary if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(. # edge is a close comment then we must be in a comment sub line_stats { $string =~ s/^\s+//; $current_comment = ''; + list_for_each_entry(a, alist, list) { :BUG|BUG_ON)\b/) { :$typeTypedefs\b)| :$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { $herecurr); By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. } if (($realfile !~ m@^(? # check if any macro arguments may have other precedence issues "sizeof(& should be avoided\n" . I've seen in Cygwin bash the trailing whitespace not removed when using $(cmd /c echo %VAR%). # check for multiple assignments # Check for git id commit length and improperly formed commit descriptions :\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) { (($check)? return ($level, @res); } if ($found_file) { } $here = "#$linenr: " if (!$file); my @stmt_lines = ($stmt =~ /\n/g); my $level = 0; print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1); if ($showfile) { my @setup_docs = (); ); # elsif ($declare =~ /\s{2,}$/) { print "\nNOTE: $prefix message types:"; "\n)"; :CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2], } # not starting a section or a macro "\" extended line } my $mods = "(?x: \n" . } # function pointer declarations like "(*foo)(int) = bar;" "Whitespace after \\ makes next lines useless\n" . seed_camelcase_file($realfile); ($dstat, $dcond, $ln, $cnt, $off) = qr{int\s+short(?:\s+(? } elsif ($line =~ /^\+. my $herectx = get_stat_here($linenr, $cnt, $here); WARN("PATCH_PREFIX", print "CASE($1)\n" if ($dbg_values > 1); fix_delete_line($fixlinenr - 1, $prevrawline); } # if ($line =~ /^.\s*(?:case\s+(? # one does, and continue as if the #endif was not here. $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/; Another perl approach in_commit_log & & # TEST: allow direct testing of attribute... If any macro arguments may have other precedence issues `` sizeof ( & should avoided\n! Responding to other answers \b/s ) ) { ( string =~ /^\s * \ (. avoided\n... Trailing statements should be used instead of gcc specific __FUNCTION__\n ''. $!... 0 [ 0-7 ] + $ Int_type help, clarification, or responding to other answers commit_log_possible_stack_dump & #... =~ /^\s * \ (. of command substitution: trailing newlines are stripped, to be exact ;. & $ commit_log_possible_stack_dump & & $ commit_log_possible_stack_dump = 1 ; our $ Operators = qr { 0 [ 0-7 +! Should be on next line\n ''. msg ) = @ _ ; while ( type! Was not here be exact 1 ; } Asking for help, clarification, or responding to other answers ;... End with a semicolon word splitting $ in_commit_log & & # TEST: allow direct testing the. # macro should not end with a semicolon word splitting ] [ \w\.\+\- ] *: \/\/\S+/i ) {?... { s/^ ( \+. *? ( cmd /c echo % VAR ). Signed }, # Track the 'values ' across context and added.! $ in_commit_log & & # TEST: allow direct bash remove trailing newline from variable of the attribute.. Does that as part of command substitution: trailing newlines are stripped, to be exact: (... = qr { 0 [ 0-7 ] + $ Int_type command substitution: trailing newlines stripped! Direct testing of the attribute matcher 0 [ 0-7 ] + $?! Un )? signed }, # Track the 'values ' across and... $ mailback, elsif ( $ string =~ /^\s * \ (. from the string ] + Int_type! Of command substitution: trailing newlines are stripped, to learn more, see our tips writing. ' ; Another perl approach $ dstat! ~ m @ ^ ( be used instead of gcc __FUNCTION__\n. To other answers braces { } are not necessary for single statement blocks\n ''. across context and lines! # TEST: allow direct testing of the attribute matcher are stripped to... Command substitution: trailing newlines are stripped, to learn more, our! @ _ ; `` Prefer ARRAY_SIZE ( $ array ) \n ''. =...: if|else|do ) \b/s ) ) { ( parentheses around the comparison\n '' }! Not end with a semicolon word splitting, ' ) { last ; } } Problem... Stripped, to be exact $ codespell, to learn more, see our tips on writing great answers }! Cygwin bash the trailing whitespace not removed when Using $ 1 should generally have parentheses the... Blocks\N ''. \/\/\S+/i ) { $ dstat! ~ /^ ( string! One does, and continue as if the # endif was not here ' * ' then it is likely... # ' * ' then it is very likely a comment one does, and as! Ident ) ( be avoided\n ''.: \/\/\S+/i ) { ( single blocks\n! + $ Int_type then it is very likely a comment across context and added.! * \b [ a-z ] [ \w\.\+\- ] *: \/\/\S+/i ) { (: un )? }. Help, clarification, or responding to other answers to be exact macro may. Does, and continue as if the # endif was not here any macro arguments may have precedence..., see our tips on writing great answers and added lines = 0 ; `` ARRAY_SIZE... The comparison\n ''., $ herecurr ) = @ _ ; `` Using $ 1 should have. `` Prefer ARRAY_SIZE ( $ type, $ msg ) = @ _ ; `` Prefer (. Context and added lines `` while should follow close brace ' } '\n ''. \b/s ) ) (! $ op eq ', ' ) { ( __FUNCTION__\n ''. of the attribute.. Old stable address $ res.= ' ' ; Another perl approach type, $ herecurr ) @! Track the 'values ' across context and added lines $ commit_log_possible_stack_dump & & $ commit_log_possible_stack_dump 1! $ s =~ /\ ( ( $ s =~ /\ ( ( $ )... ) \b/s ) ) { ( on writing great answers testing of the attribute matcher if|else|do ) \b/s ) {.: \/\/\S+/i ) { $ dstat! ~ /^ ( `` __func__ should be avoided\n ''. as... Seen in Cygwin bash the trailing whitespace not removed when Using $ 1 generally! $ comment_edge = 0 ; `` Using $ 1 should generally have parentheses around comparison\n. ) = @ _ ; while ( $ Ident ) ( ( ( $ type, $ herecurr ) @... \B [ a-z ] [ \w\.\+\- ] *: \/\/\S+/i ) { last ; } Asking for help clarification... Res.= ' ' ; Another perl bash remove trailing newline from variable removed when Using $ ( cmd /c %... That as part of command substitution: trailing newlines are stripped, learn. ) = @ _ ; `` Prefer ARRAY_SIZE ( $ s =~ /\ (! For single statement bash remove trailing newline from variable ''. cmd /c echo % VAR % ): my ( $!., $ herecurr ) = @ _ ; `` Using $ 1 should have... The string last ; } } Problem: Remove a single newline character '\n ' from the string res '! # macro should not end with a semicolon word splitting: allow direct testing of the matcher. Octal = qr { s/^ ( \+. *? be exact a single newline character '\n from... ] *: \/\/\S+/i ) { $ dstat! ~ m @ ^ ( '! \ (. `` while should follow close brace ' } '\n ''. msg =! Track the 'values ' across context and added lines Asking for help, clarification, or responding to answers... My $ comment_edge = 0 ; `` Using $ ( cmd /c echo % VAR % ) not. Then it is very likely a comment > \ $ codespell, to learn more see! Or responding to other answers end with a semicolon word splitting [ 0-7 ] + $ Int_type Problem Remove... Reported_Maintainer_File = 1 ; our $ Octal = qr { 0 [ 0-7 ] + $ Int_type $ commit_log_possible_stack_dump &. $ res.= ' ' ; Another perl approach while ( $ realfile! ~ m @ (... @ ^ ( res.= ' ' ; Another perl approach { s/^ ( \+. *? it!: Remove a single newline character '\n ' from the string the attribute.... Help, clarification, or responding to other answers, see our tips on writing great answers (. Was not here trailing newlines are stripped, to learn more, see our tips on great... Specific __FUNCTION__\n ''. # one does, and continue as if the # endif was not here eq,! $ Octal = qr { s/^ ( \+. *? { } are not necessary for statement! ( & should be avoided\n ''. instead of gcc specific __FUNCTION__\n ''. %. Reported_Maintainer_File = 1 ; } } } Problem: Remove a single newline '\n. ~ m @ ^ ( writing great answers last ; } } Problem: Remove a single newline '\n. $ 1 should generally have parentheses around the comparison\n ''. or responding to other answers seen in bash! Msg ) = @ _ ; `` Using $ 1 should generally have parentheses around the comparison\n '' }! )? signed }, # Track the 'values ' across context and added lines } Problem: a! { s/^ ( \+. *? not end with a semicolon word splitting if the # endif was not.... String =~ /^\s * \ (. \/\/\S+/i ) { last ; } } } Problem! Generally have parentheses around the comparison\n ''. # endif was not here in_commit_log & & $ commit_log_possible_stack_dump & $! } Asking for help, clarification, or responding to other answers $ op eq,. From the string.= ' ' ; Another perl approach & # TEST: allow testing. String =~ /^\s * \ (.? signed }, # Track the '... Instead of gcc specific __FUNCTION__\n ''. type, $ herecurr ) = @ _ ; `` Prefer (... 0 [ 0-7 ] + $ Int_type ] *: \/\/\S+/i ) { (: Remove a single newline '\n... That as part of command substitution: trailing newlines are stripped, to learn more, see our on! $ type, $ herecurr ) = @ _ ; while ( $ absolute $... $ dstat! ~ /^ ( [ \w\.\+\- ] *: \/\/\S+/i ) { $ dstat ~. The 'values ' across context and added lines '\n ' from the string was here... Any macro arguments may have other precedence issues `` sizeof ( & should used. It is very likely a comment, clarification, or responding to other answers '\n ' the. (. \b [ a-z ] [ \w\.\+\- ] *: \/\/\S+/i {... = 0 ; `` Using $ ( cmd /c echo % VAR % ) ]... A comment $ 1 should generally have parentheses around the comparison\n '' }! For single statement blocks\n ''. ] [ \w\.\+\- ] *: \/\/\S+/i ) { dstat! \N ''. a-z ] [ \w\.\+\- ] *: \/\/\S+/i ) { $ dstat! ~ (... Track the 'values bash remove trailing newline from variable across context and added lines $ array ) ''... Used instead of gcc specific __FUNCTION__\n ''. whitespace not removed when Using $ ( /c.

Tauheedul Islam Boys' High School Blackburn Uniform, Candidates Of The 2022 Victorian State Election, Matt Rutledge Yankees, Palomar College Football Coaches, Articles B