fork download
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. WriteHTML.
  3.  
  4. ENVIRONMENT DIVISION.
  5. INPUT-OUTPUT SECTION.
  6. FILE-CONTROL.
  7. SELECT OutputFile ASSIGN TO "output.html"
  8. ORGANIZATION IS LINE SEQUENTIAL.
  9.  
  10. DATA DIVISION.
  11. FILE SECTION.
  12. FD OutputFile.
  13. 01 HTML-LINE PIC X(80).
  14.  
  15. WORKING-STORAGE SECTION.
  16. 01 IDX PIC 9(2) VALUE 1.
  17. 01 HTML-CONTENT OCCURS 10 TIMES.
  18. 05 LINE-ITEM PIC X(80).
  19. 01 BROWSER-TABLE.
  20. 05 BROWSERS OCCURS 3 TIMES INDEXED BY BROWSER-ID.
  21. 10 BROWSER-NAME PIC X(20).
  22. 10 BROWSER-COMMAND PIC X(255).
  23. 01 USER-INPUT PIC X(20) VALUE SPACES.
  24. 01 SELECTED-BROWSER-COMMAND PIC X(255) VALUE SPACES.
  25. 01 SYSTEM-RETURN-CODE PIC S9(4) COMP VALUE 0.
  26.  
  27. PROCEDURE DIVISION.
  28. MAIN-PROCEDURE.
  29. PERFORM INIT-HTML-CONTENT
  30. PERFORM INIT-BROWSER-TABLE
  31. OPEN OUTPUT OutputFile
  32. PERFORM WRITE-LINES
  33. CLOSE OutputFile
  34. DISPLAY "HTML file 'output.html' has been written successfully."
  35.  
  36. *> コマンドライン引数を取得
  37. ACCEPT USER-INPUT FROM COMMAND-LINE
  38.  
  39. *> 入力に応じたブラウザを選択
  40. PERFORM SEARCH-BROWSER
  41.  
  42. *> ブラウザコマンドが見つからない場合
  43. IF SELECTED-BROWSER-COMMAND = SPACES
  44. DISPLAY "Invalid browser specified. Using 'w3m' as default."
  45. MOVE "w3m output.html" TO SELECTED-BROWSER-COMMAND
  46. END-IF
  47.  
  48. *> システムコマンド実行
  49. CALL "SYSTEM" USING BY CONTENT SELECTED-BROWSER-COMMAND
  50. RETURNING SYSTEM-RETURN-CODE
  51. IF SYSTEM-RETURN-CODE NOT = 0
  52. DISPLAY "Failed to launch browser with return code: " SYSTEM-RETURN-CODE
  53. END-IF
  54.  
  55. STOP RUN.
  56.  
  57. INIT-HTML-CONTENT.
  58. MOVE "<!DOCTYPE html>" TO LINE-ITEM(1).
  59. MOVE "<html lang=""ja"">" TO LINE-ITEM(2).
  60. MOVE " <head>" TO LINE-ITEM(3).
  61. MOVE " <meta charset=""UTF-8"">" TO LINE-ITEM(4).
  62. MOVE " <title>タイトル</title>" TO LINE-ITEM(5).
  63. MOVE " </head>" TO LINE-ITEM(6).
  64. MOVE " <body>" TO LINE-ITEM(7).
  65. MOVE " Hello HTML!" TO LINE-ITEM(8).
  66. MOVE " </body>" TO LINE-ITEM(9).
  67. MOVE "</html>" TO LINE-ITEM(10).
  68.  
  69. INIT-BROWSER-TABLE.
  70. MOVE "w3m" TO BROWSER-NAME(1)
  71. MOVE "w3m output.html" TO BROWSER-COMMAND(1)
  72. MOVE "firefox" TO BROWSER-NAME(2)
  73. MOVE "firefox output.html" TO BROWSER-COMMAND(2)
  74. MOVE "vivaldi" TO BROWSER-NAME(3)
  75. MOVE "vivaldi output.html" TO BROWSER-COMMAND(3).
  76.  
  77. SEARCH-BROWSER.
  78. SET BROWSER-ID TO 1
  79. PERFORM VARYING BROWSER-ID FROM 1 BY 1 UNTIL BROWSER-ID > 3
  80. IF USER-INPUT = BROWSER-NAME(BROWSER-ID)
  81. MOVE BROWSER-COMMAND(BROWSER-ID) TO SELECTED-BROWSER-COMMAND
  82. EXIT PERFORM
  83. END-IF
  84. END-PERFORM.
  85.  
  86. WRITE-LINES.
  87. PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 10
  88. MOVE LINE-ITEM(IDX) TO HTML-LINE
  89. WRITE HTML-LINE
  90. END-PERFORM.
  91.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cob: 37: error: continuation character expected
prog.cob: 45: error: continuation character expected
prog.cob: in paragraph 'MAIN-PROCEDURE':
prog.cob: 34: error: syntax error, unexpected INVALID KEY
prog.cob: 34: error: syntax error, unexpected USING
prog.cob: 36: error: syntax error, unexpected END-IF
prog.cob: 42: error: 'SYS' is not defined
prog.cob: in paragraph 'SEARCH-BROWSER':
prog.cob: 71: error: 'SELECTED-BROWSER' is not defined
prog.cob: 71: error: syntax error, unexpected -
stdout
Standard output is empty