From 18f45619adbdf036043905961ba7342c648de497 Mon Sep 17 00:00:00 2001 From: Iain William Wiseman Date: Mon, 5 May 2025 15:40:06 +1200 Subject: [PATCH] Fixed up the hardcode audoio.mp3 --- .vscode/launch.json | 1 + README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- id3cobol.cbl | 27 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0ccc3a0..8df8c17 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,6 +6,7 @@ "type": "gdb", "preLaunchTask": "Build All", "request": "launch", + "arguments": "audio.mp3", "cobcargs": ["-free", "-x", "-g","-debug", "-Wall", "-O0"] , "group": ["id3cobol.cbl"], "env": { diff --git a/README.md b/README.md index 196a48c..ac3f137 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ This project is a COBOL-based MP3 ID3 tag reader that parses and displays metada - `id3cobol.cbl`: Main COBOL program for reading and parsing MP3 ID3 tags. - `zero-ord.cbl`: COBOL module for zero-based ordinal conversion. - `Makefile`: Build automation file for compiling and cleaning the project. +- `audio.mp3`: Sample MP3 file for testing (required for the program to run). - `.gitignore`: Specifies files and directories to be ignored by Git. ## Build Instructions @@ -43,14 +44,52 @@ This project is a COBOL-based MP3 ID3 tag reader that parses and displays metada make distclean ``` +## Environment Variables + +The following environment variables are important for proper execution: + +- **COB_LIBRARY_PATH**: Tells COBOL where to find modules + ```bash + export COB_LIBRARY_PATH=/path/to/workspace:$COB_LIBRARY_PATH + ``` + +- **COB_PRE_LOAD**: Tells COBOL to preload the zero-ord module + ```bash + export COB_PRE_LOAD=zero-ord + ``` + +- **LD_LIBRARY_PATH**: Helps the Linux dynamic linker find the module + ```bash + export LD_LIBRARY_PATH=/path/to/workspace:$LD_LIBRARY_PATH + ``` + +These variables are automatically set when using the VS Code debugger. + ## Usage -Run the compiled `id3cobol` program to parse the `audio.mp3` file: +Run the compiled `id3cobol` program to parse an MP3 file: + ```bash +# Using default audio.mp3 file: ./id3cobol + +# Using a specific MP3 file: +./id3cobol path/to/your/music.mp3 ``` -> **Note**: Ensure you have an `audio.mp3` file in the same directory as the program. This file is required for the program to function. +> **Note**: Ensure you have an MP3 file with ID3 tags. If no argument is provided, the program will look for `audio.mp3` in the current directory. + +## VS Code Integration + +This project includes VS Code configuration files: + +- **launch.json**: Configures debugging with proper environment variables +- **tasks.json**: Defines build tasks for compiling the project + +To debug in VS Code: +1. Press F5 or select "Run and Debug" from the left sidebar +2. Select "COBOL debugger" configuration +3. The debugger will automatically build and launch the program with audio.mp3 ## Debugging diff --git a/id3cobol.cbl b/id3cobol.cbl index 49df6f9..0534475 100644 --- a/id3cobol.cbl +++ b/id3cobol.cbl @@ -16,6 +16,7 @@ IDENTIFICATION DIVISION. *> Debug flag to enable/disable debug prints 01 WS-DEBUG-MODE PIC 9 VALUE 1. + *> Default filename that can be overridden with command-line argument 01 WS-FILENAME PIC X(255) VALUE "audio.mp3". 01 WS-EOF-FLAG PIC 9 VALUE 0. 88 WS-EOF VALUE 1. @@ -24,6 +25,11 @@ IDENTIFICATION DIVISION. 01 STOP-READING-FLAG PIC 9 VALUE 0. 88 STOP-READING VALUE 1. + *> Command line argument handling + 01 CMD-ARGS. + 05 CMD-ARG-COUNT PIC 9(2) COMP-5. + 05 CMD-ARG-VALUES PIC X(255) OCCURS 1 TO 10 DEPENDING ON CMD-ARG-COUNT. + *> ID3v2 Header Structure 01 ID3-HEADER. 05 ID3-TAG PIC X(3). *> Should be "ID3" @@ -81,6 +87,11 @@ IDENTIFICATION DIVISION. PROCEDURE DIVISION. MAIN-PARA. DISPLAY "Starting MP3-ID3-INFO program". + + *> Process command-line arguments + PERFORM PROCESS-COMMAND-LINE + + DISPLAY "Analyzing file: " FUNCTION TRIM(WS-FILENAME) PERFORM OPEN-FILE. @@ -298,3 +309,19 @@ IDENTIFICATION DIVISION. END-READ MOVE WS-TEMP-BYTE TO BYTES-BUFFER(WS-I:1) END-PERFORM. + + *> Process command-line arguments to get the filename + PROCESS-COMMAND-LINE. + *> Get argument count and values + ACCEPT CMD-ARG-COUNT FROM ARGUMENT-NUMBER + + *> Check if at least one argument was provided + IF CMD-ARG-COUNT > 0 + *> Get the first argument (the filename) + ACCEPT CMD-ARG-VALUES(1) FROM ARGUMENT-VALUE + + *> If argument isn't empty, use it as filename + IF CMD-ARG-VALUES(1) NOT = SPACES + MOVE CMD-ARG-VALUES(1) TO WS-FILENAME + END-IF + END-IF.