08 June 2024, 19:49 | #1 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 729
|
Gpt4o: Write me a hexdump for the amiga
Gpt4o wrote a decent hexdump. I was testing it with SAS C on Amiga 500 Os 1.3.
I did 2 corrections on follow-up prompts. 1. "I think the compiler is C89" 2. "It doesn't have getopt" Not bad. Code:
#include <dos/dos.h> #include <exec/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stddef.h> // for size_t #ifndef SIZE_MAX #define SIZE_MAX ((size_t)-1) #endif void hexdump(const char *filename, size_t offset, size_t length) { FILE *file; unsigned char buffer[16]; size_t bytesRead; size_t totalRead; size_t i; file = fopen(filename, "rb"); // Open file in binary read mode if (!file) { printf("Failed to open file: %s\n", filename); return; } fseek(file, offset, SEEK_SET); // Set the file position to the offset totalRead = 0; // Total bytes read // Read the file and display its contents in hexadecimal format while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0 && totalRead < length) { printf("%08lx ", (unsigned long)(offset + totalRead)); // Print the offset // Print the hexadecimal values of the bytes for (i = 0; i < bytesRead; ++i) { printf("%02x ", buffer[i]); if (i == 7) printf(" "); } // If the line is not full, pad with spaces if (bytesRead < 16) { for (i = bytesRead; i < 16; ++i) { printf(" "); if (i == 7) printf(" "); } } printf(" |"); // Print the ASCII representation of the bytes for (i = 0; i < bytesRead; ++i) { if (buffer[i] >= 32 && buffer[i] <= 126) { printf("%c", buffer[i]); } else { printf("."); } } printf("|\n"); totalRead += bytesRead; // Update total bytes read } fclose(file); // Close the file } int main(int argc, char **argv) { size_t offset = 0; // Default offset is 0 size_t length = SIZE_MAX; // Default length is maximum size int i; // Manually parse command-line options for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-o") == 0) { if (i + 1 < argc) { offset = strtoul(argv[++i], NULL, 0); // Set offset } else { printf("Option -o requires an argument.\n"); return 1; } } else if (strcmp(argv[i], "-n") == 0) { if (i + 1 < argc) { length = strtoul(argv[++i], NULL, 0); // Set length } else { printf("Option -n requires an argument.\n"); return 1; } } else { // Assume the remaining argument is the filename break; } } // Ensure a filename is provided if (i >= argc) { printf("Usage: hexdump [-o offset] [-n length] <filename>\n"); return 1; } // Perform hexdump on the provided file hexdump(argv[i], offset, length); return 0; } |
09 June 2024, 12:33 | #2 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,570
|
You shouldn't need any AmigaOS headers in a completely portable source text.
|
09 June 2024, 12:39 | #3 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,844
|
My comment is the opposite. If the application is for the Amiga, why is it not using dos.library IO/ReadArgs and why is it not using exec.library RawDoFmt (or a simple custom online nybble to char conversion) and types?
|
09 June 2024, 12:46 | #4 |
Registered User
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 2,165
|
I'd guess that ChatGPT hasn't had a lot of Amiga sources trained into it?
|
09 June 2024, 14:34 | #5 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,844
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
chatGPT to write Amiga C code | JOB | Coders. C/C++ | 4 | 02 February 2023 15:44 |
Can write Amiga Bootblock PC? | Retro1234 | support.Other | 8 | 10 June 2019 18:15 |
So, I'd like to write a new Amiga game - what do you want to see? | Graham Humphrey | Amiga scene | 88 | 26 February 2012 21:50 |
How do I write curly braces on Amiga 600? { and } | e5frog | support.Other | 0 | 15 July 2011 13:44 |
Amiga disk write protection | Overdoc | Retrogaming General Discussion | 15 | 23 October 2001 01:02 |
|
|