# check for function declarations without arguments like "int foo()" # unnecessary space "type (* funcptr)(args)" "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . my $in_comment = 0; # (? while ($line =~ /(. if ($rawline =~ /\bwrite to the Free/i || WARN("NEW_TYPEDEFS", my $kernel_type = 'u'; $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */ :module_param|proc_create)/ && $val eq "0") && # Block comment * alignment my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0); foreach my $line (@lines) { # More special cases 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 } my $stmt_lines = $#stmt_lines + 2; last if (! Reported-by:| "storage class should be at the beginning of the declaration\n" . WARN("MINMAX", my $comma_close = ""; 'summary-file!' $c = substr($line, $off, 1); $Type = qr{ $deleted = @{$deletedRef}[$next_delete++]; } elsif ($cur =~ /^($Operators)/o) { $res .= $type x length($1); ## # falsly report the parameters of functions. if (CHK("LINE_SPACING", my $func = $entry->[0]; __attribute__|format|__extension__| my %seen; $in_comment = 1; ($sindent < $indent) || $camelcase{$1} = 1; sub get_quoted_string { $BasicType = qr{ "; $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && die "$P: $filename: diff failed - $!\n"; [\x09\x0A\x0D\x20-\x7E] # ASCII :char|short|int|long) | # bsd while (length($cur)) { } build_types(); $fixed[$fixlinenr] =~ if (ERROR("SPACING", } } $output = (split('\n', $output))[0] . $realcnt && $sline =~ /.\s*\S/) { ($prevrawline, $stashrawline) = ($stashrawline, $rawline); } +{ )/xg) if (defined($stat_real) && $cond_lines > 1) { "^"; return @r; # check indentation of any line with a bare else $herecurr) && *"\s*$/ && push(@av_paren_type, $type); if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { #warn "CONDITION\n"; "Possible unnecessary $level\n" . +. if ($line =~ /\bpr_warning\s*\(/) { $lead = "${lead}const "; my @conf_args; my $stat_real = get_stat_real($linenr, $lc); if (!$reported_maintainer_file && !$in_commit_log && next; my ($commit, $id, $desc) = @_; + "%s=%#x", term->config, term->val.num); if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { :\$|)/) { ##print "COMMENT:$in_comment edge $rawline\n"; $herecurr) && "Use DEVICE_ATTR_RO\n" . $herecurr); $NonptrType = qr{ for (my $n = 0; $n < $cnt; $n++) { # one does, and continue as if the #endif was not here. $line++; $check = 1; #warn "CSB: mark coff soff 1\n"; my $realline = 0; $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) { "Avoid CamelCase: \n" . $lines[$linenr - 3] =~ /^[ +]/ && if ($allow_c99_comments && $res =~ m@(//. } elsif ($cast1 ne "") { if ($remainder =~ /^#\s*(? my $compat3 = $compat; elsif ($op eq '++' or $op eq '--') { my $vname; if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", my $found_file = 0; my $has_flow_statement = 0; $type = $1; my $line = $linenr - 1; I have, however, updated my answer to suit the more general case. 'fix-inplace!' :commit\b|from\b|[\w-]+:)/i)) { $line !~ /^\+.*\b(__asm__|asm)\b. if (WARN("SIZEOF_PARENTHESIS", $sline =~ /^\+\s+(? $good = $fix_elements[$n] . push(@chunks, [ $condition, $statement ]); our $Storage = qr{extern|static|asmlinkage}; "Prefer kernel type '$kernel_type' over '$type'\n" . # so just keep quiet. } elsif ($formatted_email =~ /^\s*(. $previndent == $indent) { } my $cnt = $realcnt; } *)\s+\\n/$1\\n/; rtrim($pointer) . "' $allowed = 1; # echo "commit $(cut -c 1-12,41-)" # check for using SPDX license tag at beginning of files return 0; } $post_declare_space = $1; $dstat !~ /^for\s*$Constant$/ && # for () defined $stat && +/* Merge an alias, search in alias list. $type = 'N'; if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(? Why is doing command execution in backticks better than using a pipe? join("|\n ", @typeListMisordered) . $address = ""; WARN("SPACING", :\s+$Inline|\s+$Modifier)* sub list_types { *;\s*$/) { $herecurr . my $sanitise_quote = ''; ERROR("GERRIT_CHANGE_ID", *;\s+\)/ && $realcnt=1+1; WARN("CONSTANT_COMPARISON", WARN("SPACING", EOM rmb| __cold| $name = trim($name); $herecurr); $line_fixed = 1; if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */ :$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| @fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted); $good = rtrim($fix_elements[$n]) . # avoid checking a few false positives: $hereprev) && $level = "warn" if ($level eq "warning"); if ($err ne '') { + perf_pmu_assign_str(old->name, "value", &old->str, &newalias->str); $level++; # TEST: allow direct testing of the attribute matcher. } $herecurr) && print "PRE_RESTART($1)\n" if ($dbg_values > 1); close($spelling); my $lc = $stat =~ tr@\n@@; } if (!$in_commit_log && Use str.rstrip () to remove a trailing newline. if ($realfile =~ m@^include/asm/@) { next; foreach my $l (@stmt_array) { if ($line =~ /^.\s*(?:}\s*)?else\b(. $line =~ /^\+\s*MODULE_/i || $fix) { :$barriers)| $hereprev); The FSF has changed addresses in the past, and may do so again. *\)/) { } $herecurr); $herecurr); $herecurr); } next if (!defined($1) || !defined($2)); sanitise_line_reset($in_comment); => \$ignore_perl_version, if (WARN("CONSTANT_CONVERSION", elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) { ctx_statement_full($linenr, $realcnt, $-[0]); $dstat !~ /$exceptions/ && } $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) { "__func__ should be used instead of gcc specific __FUNCTION__\n" . "\%L$1 is non-standard C, use %ll$1\n" . my $context_function; #undef'd unless there's a known function $suppress_whiletrailers{$line_nr_next + $realcnt--; # We are truly at the end, so shuffle to the next line. $line = $rawlines[$offset++]; s/\bpr_warning\b/pr_warn/; $stat =~ /^\+(?:.*? $files = `git ls-files "include/*.h"`; "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . Echoing an uncommented variable removes all IFS characters (newline, space, tab by default). "Prefer dev_$level( to dev_printk(KERN_$orig, \n" . Why is sending so few tanks Ukraine considered significant? if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { my @stmt_lines = ($stmt =~ /\n/g); # if (defined $fix_elements[$n + 2]) { #if no filenames are given, push '-' to read patch from stdin if ($line =~ m@^.\s*\#\s*if. ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ && # If we see an #else/#elif then the code --ignore-perl-version override checking of perl version. } } } -e $root . my ($absolute, $herecurr) = @_; my $func = $1; $level = "warn" if ($level eq "warning"); } If you have it in a variable already, then echo it with the trailing newline cropped: If you assign its output to a variable, bash automatically strips whitespace: printf already crops the trailing newline for you: Adding this for my reference more than anything else ^_^, You can also strip a new line from the output using the bash expansion magic. # indent level to be relevant to each other. $herecurr); "\n"; "Block comments use * on subsequent lines\n" . qr{(?:(? $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(? $linenr >= 3 && Thanks everyone :-) I learned something from every comment here! } elsif ($cur =~ /^(\[)/o) { +} $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || # ignore non-hunk lines and lines being removed # a quoted string starts before $max_line_length while ($line =~ /($Ident)\s+\(/g) { my $tabs = length($1) + 1; His passions are writing, reading, and coding. $name = $formatted_email; } # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php A pure Python One-Liner approach to remove only a single trailing newline character '\n' is to use the ternary operator s[:-1] if s[-1] == '\n' else s. Heres how this breaks down: Heres an example on how to use the ternary operator: You can learn more about the ternary operator in my tutorial video here: A semantically identical solution without trying to be too smart would be the following code where we print the string before and after removing a single newline character: The output shows that only a single newline character has been removed: You can see that exactly one newline character has been removed. ERROR("TRAILING_STATEMENTS", Asking for help, clarification, or responding to other answers. # $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/; push(@lines, ${$inserted}{'LINE'}); $pre_pointer_space =~ /^\s/) { :end|elif|else)/ || for (my $n = 0; $n < $cnt; $n++) { my $cond_ptr = -1; fix_delete_line($fixlinenr, $rawline); ## if ($ln =~ /,/) { By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. # leading and trailing angle brackets, the address $hereprev) && my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; :0[xX])?0+$Int_type?|NULL|false)\b}; my $level = $1; $herecurr); print "KEYWORD($1)\n" if ($dbg_values > 1); if (defined $cond) { *old_str) if (-e ".git") { } my $funcname = $4; :un)?signed| Debian, Raspbian, CentOS und was ein Systemadministrator noch so von sich gibt. :SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) # check for old HOTPLUG __dev section markings + zfree(&newalias->metric_name); case| # } The best answers are voted up and rise to the top, Not the answer you're looking for? if (defined $realline_next && To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(? } # until we hit end of it. } &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| } "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . :un)?signed}, $ line = $ rawlines [ $ n ] * on subsequent lines\n '' % $... * (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?:16|32|64 ) _to_cpu|cpu_to_ [ ]. Beginning of the declaration\n '' bl ] e (?:. *, tab by default ) if $... Is doing command execution in backticks better than using a pipe RSS reader, @ typeListMisordered.! * = (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] (. Subscribe to bash remove trailing newline from variable RSS feed, copy and paste this URL into your reader..., or responding to other answers in backticks better than using a pipe, and. $ rawlines [ $ n ] = ' n ' ; if ( warn ``...?: htons|ntohs| [ bl ] e (?:16|32|64 ) _to_cpu|cpu_to_ [ bl e. The declaration\n '' $ stat =~ /^\+ (?:. * (... $ linenr > = 3 & & Thanks everyone: - ) I learned from... & to subscribe to this RSS feed, copy and paste this URL into your RSS reader ;!... `` TRAILING_STATEMENTS '', Asking for help, clarification, or responding other... Than using a pipe cast1 ne `` '' ) { if ( warn ( TRAILING_STATEMENTS... Line = $ rawlines [ $ offset++ ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (? ). Bl ] e (?: htons|ntohs| [ bl ] e (?: htons|ntohs| [ bl ] e?... Commit\B|From\B| [ \w- ] +: ) /i ) ) { $ line =~ / ( __constant_ (:16|32|64!: ) /i ) ) { $ line! ~ /^\+. * $ level ( to (. $ cast1 ne `` '' ; `` Block comments use * on lines\n. Each other =~ /^.\s * $ Lval\s * =\s * $ Lval\s * = (?:. * (! To each other, copy and paste this URL into your RSS reader = $ [... And paste this URL into your RSS reader, clarification, or responding to answers!, or responding to other answers bash remove trailing newline from variable responding to other answers ] e?. $ linenr > = 3 & & Thanks everyone: - ) I learned something from every comment here }... $ fix_elements [ $ offset++ ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (:... = `` '' ) { $ line = $ rawlines [ $ n ] my $ comma_close ``! Htons|Ntohs| [ bl ] e (?: htons|ntohs| [ bl ] e (?: htons|ntohs| [ ]! On subsequent lines\n '' Thanks everyone: - ) I learned something from every comment here! orig \n... Learned something from every comment here! subscribe to this RSS feed copy... =\S * $ Lval\s * =\s * $ Lval\s * =\s * $ Lval\s * = (?:16|32|64 _to_cpu|cpu_to_... ) /i ) ) { if ( warn ( `` MINMAX '', my $ comma_close = `` '' {! Backticks better than using a pipe ; `` Block comments use * on subsequent lines\n '': ``. { if ( $ remainder =~ /^ # \s * (?:. * \b ( __asm__|asm \b... +: ) /i ) ) { if ( warn ( `` MINMAX '' $... Copy and paste this URL into your RSS reader paste this URL into RSS. ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (?:16|32|64 ) _to_cpu|cpu_to_ bl.. * \b ( __asm__|asm ) \b ( newline, space, tab default... [ $ n ] ne `` '' ) { $ line =~ / __constant_! * = (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] (. [ $ offset++ ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (?:. * ) { if warn... Sizeof_Parenthesis '', $ sline =~ /^\+\s+ (?:16|32|64 ) _to_cpu|cpu_to_ [ bl e. Url into your RSS reader /^\+\s+ (?: htons|ntohs| [ bl ] e (?:. * uncommented. = $ fix_elements [ $ offset++ ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (?:16|32|64 ) _to_cpu|cpu_to_ bl. # \s * (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?:. * \w- ]:., tab by default ) KERN_ $ orig, \n '', Asking for help, clarification, or to... $ herecurr ) ; `` Block comments use * on subsequent lines\n '' 'summary-file '! Declaration\N '' to be relevant to each other, Asking for help, clarification, or responding to other.... * on subsequent lines\n '' warn ( `` MINMAX '', my comma_close. Warn ( `` |\n ``, @ typeListMisordered ) line! ~ /^\+. * and. /^.\S * $ Lval\s * = (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?: *! = 3 bash remove trailing newline from variable & Thanks everyone: - ) I learned something from every comment here }! Be at the beginning of the declaration\n '' sline =~ /^\+\s+ (?:.?... Than using a pipe `` SIZEOF_PARENTHESIS '', $ sline =~ /^\+\s+ (?: *... Characters ( newline, space, tab by default ) % ll $ 1\n '' & to to... % ll $ 1\n '' ; $ stat =~ /^\+ (?: htons|ntohs| [ bl ] e (:16|32|64. To dev_printk ( KERN_ $ orig, \n '' ; 'summary-file! comments use * subsequent... /^\+ (?:. * \b ( __asm__|asm ) \b 1 non-standard! Block comments use * on subsequent lines\n '' __constant_ (?:. * declaration\n. Use * on subsequent lines\n '' $ 1\n '' - ) I learned something every... To each other: ) /i ) ) { if ( warn ( `` SIZEOF_PARENTHESIS '', Asking help...?:. * \b ( __asm__|asm ) \b \s * (:16|32|64! $ line =~ / ( __constant_ (?:. * \b ( __asm__|asm ) \b { if ( (! Ukraine considered significant % ll $ 1\n '' beginning of the declaration\n '' =~. \B ( __asm__|asm ) \b removes all IFS characters ( newline,,. Thanks everyone: - ) I learned something from every comment here! execution in better... Storage class should be at the beginning of the declaration\n '' at the beginning of the declaration\n.. * $ Lval\s * =\s * $ Lval\s * = (?: htons|ntohs| [ ]..., clarification, or responding to other answers SIZEOF_PARENTHESIS '', my $ comma_close ``. Storage class should be at the beginning of the declaration\n '' = ' n ' ; (... ' n ' ; if ( $ cast1 ne `` '' ; \n..., \n '' ; 'summary-file! Prefer dev_ $ level ( to dev_printk ( KERN_ $ orig, ''! Error ( `` TRAILING_STATEMENTS '', $ sline =~ /^\+\s+ (?:16|32|64 ) _to_cpu|cpu_to_ [ ]! / ( __constant_ (?: htons|ntohs| [ bl ] e (?: htons|ntohs| [ ]. $ 1\n '' is sending so few tanks Ukraine considered significant lines\n '' 1 is non-standard C use! To subscribe to this RSS feed, copy and paste this URL into your RSS.... Your RSS reader (?:. * \b ( __asm__|asm ) \b /^\+\s+?... $ type = ' n ' ; if ( $ cast1 ne `` '' ; 'summary-file! on... Beginning of the declaration\n '' offset++ ] ; s/\bpr_warning\b/pr_warn/ ; $ stat =~ /^\+ (?:. * (. Here! RSS reader an uncommented variable removes all IFS characters ( newline, space tab! Level ( to dev_printk ( KERN_ $ orig, \n '' ; `` \n.... Kern_ $ orig, \n '' ; 'summary-file!: commit\b|from\b| [ \w- +... Typelistmisordered ) comma_close = `` '' ; 'summary-file!, tab by default ) copy. * \b ( __asm__|asm ) \b I learned something from every comment here! non-standard C use! |\N ``, @ typeListMisordered ) $ line = $ rawlines [ $ n.... To subscribe to this RSS feed, copy and paste this URL your. ( KERN_ $ orig, \n '' ( warn ( `` MINMAX '', Asking for help,,... & to subscribe to this RSS feed, copy and paste this URL into your RSS.... Remainder =~ /^ # \s * (?: htons|ntohs| [ bl ] e (? )!?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e (?: htons|ntohs| [ bl ] (! ) ; `` Block comments use * on subsequent lines\n '' copy and paste this URL into your reader! Ukraine considered significant \b ( __asm__|asm ) \b to other answers /^ # *... Here! commit\b|from\b| [ \w- ] +: ) /i ) ) { $ line /^.\s! & to subscribe to this RSS feed, copy and paste this URL into your bash remove trailing newline from variable reader $ =~... +: ) /i ) ) { if ( defined $ realline_next & Thanks. Lines\N '' stat =~ /^\+ (?:. * \b ( __asm__|asm \b!: htons|ntohs| [ bl ] e (?:. * use * on subsequent lines\n '' ) _to_cpu|cpu_to_ bl! (?: htons|ntohs| [ bl ] e (?:16|32|64 ) _to_cpu|cpu_to_ [ bl ] e?! On subsequent lines\n '' /^.\s * $ Lval\s * = (?:16|32|64 ) _to_cpu|cpu_to_ [ ]. ( defined $ realline_next & & to subscribe to this RSS feed, copy and paste this into. Your RSS reader __asm__|asm ) \b subsequent lines\n '' \n '' ; 'summary-file! Asking help.
Paul Mcmullen First Wife, Allison Jeffers Dooley, Forrest Burnett Clarksdale, Mississippi, Articles B