Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

75 lignes
1.3 KiB

  1. #!/bin/sh
  2. fname=$(mktemp foobar.XXXXX)
  3. cat > "$fname"
  4. awk '
  5. maxline == 1 {
  6. if (maxlength < length)
  7. maxlength = length
  8. }
  9. function printtop () {
  10. blank = sprintf("%*s", maxlength + 4, "")
  11. gsub(" ", "*", blank)
  12. printf("%s\n", blank)
  13. }
  14. function printline(a)
  15. {
  16. printf("* %s%*s *\n", a, maxlength - length(a), "")
  17. }
  18. # return the string a, with the character at pos, replaced with chr
  19. function replace(a, pos, chr)
  20. {
  21. return substr(a, 1, pos - 1) chr substr(a, pos + 1)
  22. }
  23. output == 1 && FNR == 1 {
  24. printtop()
  25. printf("* %*s *\n", maxlength, "")
  26. prevline = $0
  27. next
  28. }
  29. output == 1 {
  30. # fix up horizontal issues
  31. gsub("\\|-", "+-", prevline)
  32. gsub("\\| -", "+--", prevline)
  33. gsub("-\\|", "-+", prevline)
  34. gsub("- \\|", "--+", prevline)
  35. # Fix up vertical issues
  36. # first fix edges from below
  37. r = split($0, a, "|")
  38. pos = 0
  39. for (i = 2; i <= r; i++) {
  40. pos += length(a[i - 1]) + 1
  41. if (substr(prevline, pos, 1) == "-")
  42. prevline = replace(prevline, pos, "+")
  43. }
  44. # fix edges from above
  45. r = split(prevline, a, "|")
  46. pos = 0
  47. for (i = 2; i <= r; i++) {
  48. pos += length(a[i - 1]) + 1
  49. if (substr($0, pos, 1) == "-")
  50. $0 = replace($0, pos, "+")
  51. }
  52. printline(prevline)
  53. prevline = $0
  54. }
  55. END {
  56. printline(prevline)
  57. printf("* %*s *\n", maxlength, "")
  58. printtop()
  59. }
  60. ' maxline=1 "$fname" maxline=0 output=1 "$fname"
  61. rm "$fname"