rtf 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #------------------------------------------------------------------------------
  2. # $File: rtf,v 1.9 2020/12/12 20:01:47 christos Exp $
  3. # rtf: file(1) magic for Rich Text Format (RTF)
  4. #
  5. # Duncan P. Simpson, D.P.Simpson@dcs.warwick.ac.uk
  6. # Update: Joerg Jenderek
  7. # URL: https://en.wikipedia.org/wiki/Rich_Text_Format
  8. # Reference: http://www.snake.net/software/RTF/RTF-Spec-1.7.rtf
  9. # http://www.kleinlercher.at/tools/Windows_Protocols/Word2007RTFSpec9.pdf
  10. 0 string {\\rtf
  11. # skip DROID fmt-355-signature-id-522.rtf by looking for valid version
  12. >5 ubyte !0xAB
  13. # skip also \ in DROID fmt-50-signature-id-158.rtf by looking for valid version
  14. >>5 ubyte !0x5C Rich Text Format data
  15. !:mime text/rtf
  16. !:apple ????RTF
  17. !:ext rtf
  18. >>>0 use rtf-info
  19. # display information like version, language and code page of RTF
  20. 0 name rtf-info
  21. # 1 mostly, 2 for newer Pocket Word documents, space for test like fdo78502.rtf, { for some urtf
  22. >5 ubyte !0x7b \b, version %c
  23. # The word for character set must precede any text or most other control words
  24. >6 string \\mac \b, Apple Macintosh
  25. >6 string \\pc
  26. # control word \pca
  27. >>9 ubyte =0x61 \b, IBM PS/2, code page 850
  28. >>9 ubyte !0x61 \b, IBM PC, code page 437
  29. # unknown character set or ANSI later after control words like
  30. # \adeflang1025 \info \title \author \category \manager
  31. # "Burow, Steffanie - Im Tal des Schneeleoparden.rtf"
  32. #>6 search/105 \\ansi \b, ANSI
  33. >6 search/502 \\ansi \b, ANSI
  34. >6 default x \b, unknown character set
  35. # look for explicit codepage keyword
  36. # "Burow, Steffanie - Im Tal des Schneeleoparden.rtf"
  37. #>5 search/110 \\ansicpg
  38. >5 search/500 \\ansicpg
  39. # skip unknown or buggy codepage string 0 like in fdo78502.rtf
  40. >>&0 ubyte !0x30 \b, code page
  41. # codepage string: 437~United States IBM, ..., 1252~WesternEuropean, ..., 57011~Punjabi
  42. >>>&-1 string x %-.3s
  43. # skip space or \ and display possible 4th digit of code page string
  44. >>>&2 ubyte >0x2F
  45. >>>>&-1 ubyte <0x3A \b%c
  46. # possible 5th digit of code page string
  47. >>>>>&0 ubyte >0x2F
  48. >>>>>>&-1 ubyte <0x3A \b%c
  49. # look again at version byte to use default clause
  50. >5 ubyte x
  51. # Default language ID for South Asian/Middle Eastern text
  52. # language ID: 1025, ..., 1065~Persian, ..., 2057~English_UnitedKingdom, ..., 58380~French_NorthAfrica
  53. # Readme-0.72-Persian.rtf
  54. #>6 search/1 \\adeflang \b, default middle east language ID
  55. >>6 search/497 \\adeflang \b, default middle east language ID
  56. # https://docs.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a
  57. >>>&0 string x %.4s
  58. # skip \ and NL and show possible 5th digit of language string
  59. >>>&4 ubyte >0x2F
  60. >>>>&-1 ubyte <0x3A \b%c
  61. # else look for default language to be used when the \plain control word is encountered
  62. >>6 default x
  63. # "Burow, Steffanie - Im Tal des Schneeleoparden.rtf"
  64. #>>>6 search/127 \\deflang
  65. >>>6 search/505 \\deflang
  66. >>>>&0 string >0 \b, default language ID %-.4s
  67. # possible 5th digit of language string
  68. >>>>&4 ubyte >0x2F
  69. >>>>>&-1 ubyte <0x3A \b%c
  70. # Reference: http://latex2rtf.sourceforge.net/rtfspec_63.html
  71. # Note: no real world example found
  72. 0 string {\\urtf Rich Text Format unicoded data
  73. !:mime text/rtf
  74. #!:apple ????RTF
  75. !:ext rtf
  76. >1 use rtf-info
  77. # URL: https://en.wikipedia.org/wiki/Microsoft_Word
  78. # Reference: http://fileformats.archiveteam.org/wiki/Microsoft_Word
  79. # Note: called by TrID "Pocket Word document"
  80. # by PlanMaker "Pocket Word-Handheld PC" for pwd
  81. # by PlanMaker "Pocket Word-Pocket PC" for psw
  82. 0 string {\\pwd Pocket Word document or template
  83. # by SoftMaker Office http://extension.nirsoft.net/pwd
  84. #!:mime application/msword
  85. # https://reposcope.com/mimetype/application/x-pocket-word
  86. !:mime application/x-pocket-word
  87. # PWD for Handheld PC variant and PSW for Pocket PC variant
  88. # PWT for template
  89. !:ext pwd/psw/pwt
  90. >0 use rtf-info