Skip to content

Commit

Permalink
align total formats
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Aug 3, 2021
1 parent c5b2298 commit 814f40d
Show file tree
Hide file tree
Showing 54 changed files with 126 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Bash/swapview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ getSwap(){
printf '%7s %9s %s\n' "$pid" "$(filesize $((swap*1024)))" "$command"
fi || continue
done; printf '%s\n' $((sum * 1024)) > $sumfile) | sort -k2 -h
printf "Total: %8s\n" "$(filesize "$(<$sumfile)")"
printf "Total: %10s\n" "$(filesize "$(<$sumfile)")"
rm "$sumfile"
}

Expand Down
2 changes: 1 addition & 1 deletion Bash_parallel/swapview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getSwap(){
sumsize=0
fi
total=$(filesize $(( $(echo "$sumsize" | bc) *1024)))
printf "Total: %8s\n" "$total"
printf "Total: %10s\n" "$total"
rm "$sumfile"
}

Expand Down
2 changes: 1 addition & 1 deletion C++11/swapview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ int main(){
total += x.size;
}
auto size = output_size(total);
std::printf("Total: %8s\n", size.c_str());
std::printf("Total: %10s\n", size.c_str());
return 0;
}
2 changes: 1 addition & 1 deletion C++14/swapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ int main(int argc, char * argv[]){
<< "\n";
t+=get<1>(item);
}
cout<<"Total:"<<setw(9)<<filesize(t)<<"\n";
cout<<"Total: "<<setw(10)<<filesize(t)<<"\n";
return 0;
}
2 changes: 1 addition & 1 deletion C++14_boost/swapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ int main(int argc, char * argv[]){
cout << format % get<0>(item) % filesize(get<1>(item)) % get<2>(item) << "\n";
t+=get<1>(item);
}
cout<< boost::format("Total:%|9|") % filesize(t)<<"\n";
cout<< boost::format("Total: %|10|") % filesize(t)<<"\n";
return 0;
}
2 changes: 1 addition & 1 deletion C++17/swapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ int main() {
<< std::setw(0) << cmd << '\n';
total += swp;
}
std::cout << "Total:" << std::setw(9) << filesize(total) << std::endl;
std::cout << "Total: " << std::setw(10) << filesize(total) << std::endl;
}
2 changes: 1 addition & 1 deletion C++98/swapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ int main(int argc, char * argv[]){
format_print(*itr);
t += itr->size;
}
cout<<"Total:"<<setw(9)<<filesize(t)<<"\n";
cout<<"Total: "<<setw(10)<<filesize(t)<<"\n";
return 0;
}
2 changes: 1 addition & 1 deletion C/swapview.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int main() {
}
free(infos);
char *stotal = filesize(total);
printf("Total: %8s\n", stotal);
printf("Total: %10s\n", stotal);
free(stotal);
return 0;
}
2 changes: 1 addition & 1 deletion CSharp/SwapView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void Main (string[] args)
Console.WriteLine ("{0,7:D} {1,9} {2}", s.pid, filesize (s.size), s.comm);
t += s.size;
}
Console.WriteLine ("Total: {0,8}", filesize (t));
Console.WriteLine ("Total: {0,10}", filesize (t));
}
}
}
2 changes: 1 addition & 1 deletion ChezScheme/swapview.ss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@
(filesize (process-info-swap-usage item))
(process-info-command-line item))))
(getSwap))
(format #t "Total: ~8@a~%" (filesize total))))
(format #t "Total: ~10@a~%" (filesize total))))

(main)
2 changes: 1 addition & 1 deletion Chicken/swapview.scm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
(filesize (process-info-swap-usage swapped-process-info))
(process-info-command-line swapped-process-info)))
results)
(format #t "Total: ~8@a~%" (filesize total-swap))))
(format #t "Total: ~10@a~%" (filesize total-swap))))

(main)
4 changes: 2 additions & 2 deletions CoffeeScript/swapview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ prettyPrint = (res) ->
console.log str

console.log [
'Total:'
fillLength 9, (formatSize0 (res.reduce addSecond, 0))
'Total: '
fillLength 10, (formatSize0 (res.reduce addSecond, 0))
].join('')
4 changes: 2 additions & 2 deletions CoffeeScript_parallel/swapview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ prettyPrint = (res) ->
console.log str

console.log [
'Total:'
fillLength 9, (formatSize0 (res.reduce addSecond, 0))
'Total: '
fillLength 10, (formatSize0 (res.reduce addSecond, 0))
].join('')
4 changes: 2 additions & 2 deletions CommonLisp_old/swapview.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

(defun print-result (list)
"Print the result in list, which item: (id swap cmdline)"
(let ((format-string "~7@A~7T~8@A~8T~A~%"))
(let ((format-string "~7@A~7T~9@A~9T~A~%"))
(progn
(format t format-string "PID" "SWAP" "COMMAND")
(loop for item in list
summing (second item) into total
do (format t format-string (first item) (convert-size (second item)) (third item))
finally (format t "Total: ~A~%" (convert-size total))))))
finally (format t "Total: ~10@A~%" (convert-size total))))))

(defun get-process-id (path)
"Return process id from the path"
Expand Down
4 changes: 2 additions & 2 deletions CommonLisp_opt/swapview.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

(defun print-result (lis)
"Print the result in list, which item: (id swap cmdline)"
(let ((format-string "~7@A~7T~8@A~8T~A~%"))
(let ((format-string "~7@A~7T~9@A~9T~A~%"))
(format t format-string "PID" "SWAP" "COMMAND")
(loop for item in lis
summing (second item) into total
do (format t format-string (first item) (convert-size (second item)) (third item))
finally (format t "Total: ~A~%" (convert-size total)))))
finally (format t "Total: ~10@A~%" (convert-size total)))))

(defun get-process-id (path)
"Return process id from the path"
Expand Down
2 changes: 1 addition & 1 deletion Crystal/common.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SwapView
extend self

FORMAT = "%7s %9s %s"
TOTALFMT = "Total: %8s"
TOTALFMT = "Total: %10s"
SWAP = "Swap: "

def filesize(size)
Expand Down
2 changes: 1 addition & 1 deletion Cython/swapview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from libc.string cimport strncmp, memmove
import os

format = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"

cdef int find_size(char *s):
cdef char *s_tmp = s + 5
Expand Down
2 changes: 1 addition & 1 deletion D/swapview.d
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ void main(){
total += item.size;
writeln(format(m , item.pid, filesize(item.size), item.comm));
}
writeln(format("Total: %8s", filesize(total)));
writeln(format("Total: %10s", filesize(total)));
}
2 changes: 1 addition & 1 deletion D_parallel/swapview.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main(){
total += item.size;
writeln(format(m, item.pid, filesize(item.size), item.comm));
}
writeln(format("Total: %8s", filesize(total)));
writeln(format("Total: %10s", filesize(total)));
}

// vim: set et ts=4 sw=4
2 changes: 1 addition & 1 deletion Dart/swapview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ main() {
print(
"${result.pid.padLeft(7)} ${toHumanReadable(result.swap).padLeft(9)} ${result.cmdline}");
}
print("Total: ${toHumanReadable(total).padLeft(8)}");
print("Total: ${toHumanReadable(total).padLeft(10)}");
}
2 changes: 1 addition & 1 deletion Elixir/swapview.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule SwapView do
format {pid, size |> filesize, comm}
end)
total = result |> Enum.map(fn {_, size, _} -> size end) |> Enum.sum |> filesize
IO.puts "Total: #{total |> String.pad_leading(8)}"
IO.puts "Total: #{total |> String.pad_leading(10)}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion Erlang/swapview.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ swap_print() ->
io:format("~7s ~9s ~s~n", ["PID", "SWAP", "COMMAND"]),
[io:format("~7s ~9s ~s~n", [Pid, filesize(Size), Cmd]) || {Pid, Cmd, Size} <- Ret],
Total = lists:sum([Size || {_,_,Size} <- Ret]),
io:format("Total: ~8s~n", [filesize(Total)]).
io:format("Total: ~10s~n", [filesize(Total)]).

getswap() ->
{ok, F} = file:list_dir_all("/proc"),
Expand Down
2 changes: 1 addition & 1 deletion FreePascal/swapview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@
t := t + results[i].size;
WriteLn(Format('%7D %9S %S', [results[i].pid, filesize(results[i].size), results[i].comm]));
End;
WriteLn(Format('Total: %8S', [filesize(t)]));
WriteLn(Format('Total: %10S', [filesize(t)]));
End.
2 changes: 1 addition & 1 deletion Go/swapview.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
fmt.Printf("%7d %9s %s\n", v.Pid, FormatSize(v.Size), v.Comm)
total += v.Size
}
fmt.Printf("Total: %8s\n", FormatSize(total))
fmt.Printf("Total: %10s\n", FormatSize(total))
}

func GetInfos() (list []Info) {
Expand Down
2 changes: 1 addition & 1 deletion Go_goroutine/swapview.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
fmt.Printf("%7d %9s %s\n", v.Pid, FormatSize(v.Size), v.Comm)
total += v.Size
}
fmt.Printf("Total: %8s\n", FormatSize(total))
fmt.Printf("Total: %10s\n", FormatSize(total))
}

func GetInfos() (list []Info) {
Expand Down
2 changes: 1 addition & 1 deletion Guile/swapview.scm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(format #t FORMATSTR "PID" "SWAP" "COMMAND")
(let lp((next results) (total 0))
(cond
((null? next) (format #t "Total: ~8@a~%" (filesize total)))
((null? next) (format #t "Total: ~10@a~%" (filesize total)))
(else
(let ((item (car next)))
(format #t FORMATSTR
Expand Down
2 changes: 1 addition & 1 deletion Haskell/swapview.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Pid = Int

format = "%7d %9s %s"
formatHead = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"
firstLine = printf formatHead ("PID" :: Text) ("SWAP" :: Text) ("COMMAND" :: Text)

main = do
Expand Down
2 changes: 1 addition & 1 deletion Haskell_parallel/swapview.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Pid = Int

format = "%7d %9s %s"
formatHead = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"
firstLine = printf formatHead ("PID" :: Text) ("SWAP" :: Text) ("COMMAND" :: Text)

main = do
Expand Down
2 changes: 1 addition & 1 deletion Java/SwapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public static void main (String [] argv){
System.out.printf("%7d %9s %s\n", s.pid, filesize(s.size), s.comm);
t += s.size;
}
System.out.printf("Total: %8s\n", filesize(t));
System.out.printf("Total: %10s\n", filesize(t));
}
}
2 changes: 1 addition & 1 deletion Julia/swapview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function main()
@inbounds for (pid, swap, comm) in results
@printf("%7s %9s %s\n", pid, filesizeKB(swap), comm)
end
@printf("Total: %8s\n", isempty(results) ? "0B" :
@printf("Total: %10s\n", isempty(results) ? "0B" :
filesizeKB(sum((x) -> x[2], results)))
end

Expand Down
2 changes: 1 addition & 1 deletion Lua/swapview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function getSwap()
end

local fmt = "%7s %9s %s"
local totalFmt = "Total: %8s"
local totalFmt = "Total: %10s"
local results = getSwap()
local sum = 0
print(format(fmt, 'PID', 'SWAP', 'COMMAND'))
Expand Down
2 changes: 1 addition & 1 deletion Nim/swapview.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ for i in infos:
echo i
t += i.swap
var total = filesize(t)
echo "Total: " & spaces(max(0, 8 - total.len)) & total
echo "Total: " & spaces(max(0, 10 - total.len)) & total
2 changes: 1 addition & 1 deletion NodeJS/swapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ results.forEach(s => {
t += s[1]
})

console.log(sprintf("Total: %8s", filesize(t)))
console.log(sprintf("Total: %10s", filesize(t)))
2 changes: 1 addition & 1 deletion NodeJS_async/swapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ getSwap(function(err, results){
console.log(sprintf("%7s %9s %s", s[0], filesize(s[1]), s[2]));
t += s[1];
});
console.log(sprintf("Total: %8s", filesize(t)));
console.log(sprintf("Total: %10s", filesize(t)));
});
2 changes: 1 addition & 1 deletion NodeJS_cluster/swapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if (cluster.isMaster) {
console.log(sprintf('%7s %9s %s', s[0], filesize(s[1]), s[2]));
t += s[1];
});
console.log(sprintf('Total: %8s', filesize(t)));
console.log(sprintf('Total: %10s', filesize(t)));
}

// fork workers
Expand Down
2 changes: 1 addition & 1 deletion OCaml/swapview.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let get_swaps () : swap_t list =
let main =
let print' = Printf.printf "%7s %9s %s\n" in
let print_swap (pid, swap, comm) = print' pid (filesize swap) comm in
let print_total total = Printf.printf "Total: %8s\n" (filesize total) in
let print_total total = Printf.printf "Total: %10s\n" (filesize total) in

let swaps = get_swaps () in
let total = List.fold_left (fun acc (_, x, _) -> acc + x) 0 swaps in
Expand Down
2 changes: 1 addition & 1 deletion PHP/swapview.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ function getSwap()
$totalSize += $result[1];
}

printf("Total: %8s" . PHP_EOL, renderSize($totalSize));
printf("Total: %10s" . PHP_EOL, renderSize($totalSize));
2 changes: 1 addition & 1 deletion POSIX_shell/swapview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ main() {
printf(printf_format, $1, convert_file_size_from_kB($2), join_field(3, NF, " "))
}
END{
printf("Total: %s\n", convert_file_size_from_kB(total))
printf("Total: %10s\n", convert_file_size_from_kB(total))
}'
}

Expand Down
2 changes: 1 addition & 1 deletion Perl/swapview.pl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sub main {
$total_swap_size += $result->{'swap'};
printf $printf_format, $result->{'pid'}, convert_file_size_from_kB( $result->{'swap'} ), $result->{'cmd'};
}
printf qq{Total: %8s\n}, convert_file_size_from_kB( $total_swap_size );
printf qq{Total: %10s\n}, convert_file_size_from_kB( $total_swap_size );
}

main
2 changes: 1 addition & 1 deletion PowerShell/swapview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Get-ChildItem /proc | Where-Object { $_.Name -match '^[0-9]+$' } | ForEach-Objec
Write-Output ("{0,7} {1,9} {2}" -f $_.Pid, (FileSize $_.Size), $_.Cmd)
}

Write-Output ("Total: {0,8}" -f (FileSize $total))
Write-Output ("Total: {0,10}" -f (FileSize $total))
2 changes: 1 addition & 1 deletion Python/swapview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re

format = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"

def filesize(size):
units = 'KMGT'
Expand Down
2 changes: 1 addition & 1 deletion Python3_bytes/swapview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

format = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"

def filesize(size):
units = 'KMGT'
Expand Down
2 changes: 1 addition & 1 deletion Python_mp/swapview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os

format = "%7s %9s %s"
totalFmt = "Total: %8s"
totalFmt = "Total: %10s"

def filesize(size):
units = 'KMGT'
Expand Down
2 changes: 1 addition & 1 deletion R/swapview.r
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ for(i in 1:nrow(result)){
t = t + size
}
}
write(sprintf("Total: %8s", filesize(t)), stdout())
write(sprintf("Total: %10s", filesize(t)), stdout())
2 changes: 1 addition & 1 deletion Racket/swapview.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(define (total n)
(begin
(display "Total: ")
(display (~a n #:min-width 8))
(display (~a n #:min-width 10))
(newline)))

(define (strinit s)
Expand Down
2 changes: 1 addition & 1 deletion Ruby/swapview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# for Ruby 2.4+

FORMAT = '%7s %9s %s'
TOTALFMT = 'Total: %8s'
TOTALFMT = 'Total: %10s'

UNITS = %w[B KiB MiB GiB TiB].freeze
def filesize(size)
Expand Down
Loading

0 comments on commit 814f40d

Please sign in to comment.