ChatGPT and IRIX devlopment
Curious if anyone had begun to leverage GenAI/prompt engineering for IRIX development. Could be a good way to get some apps updated. So far I've had great success in my spare time:
Prompts:
write a small program to compile in IRIX 6.5.22 that includes a motif window
add a log viewer window to the motif example code above
add the ability to open a log file to the program above
add a scroll bar to the log viewer widget
How to resize the window?
Prompts-debug:
there is a compile error in line 31 in this example. A declaration cannot appear after an executable statement in a block. please fix this error.
line 31 is also a declaration after an executable statement and causes a compile error
Code that compiles and runs:
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/MainW.h>
#include <Xm/Text.h>
#include <Xm/FileSB.h>
#include <Xm/ScrolledW.h>
#include <stdio.h>
#include <stdlib.h>
/* Global log widget */
Widget log_text;
/* Function to append log text */
void append_log(const char *message) {
XmTextPosition pos = XmTextGetLastPosition(log_text);
XmTextInsert(log_text, pos, message);
XmTextInsert(log_text, pos + strlen(message), "\n");
}
/* Function to read a log file and display its contents */
void load_log_file(const char *filename) {
char buffer[256];
FILE *file = fopen(filename, "r");
if (!file) {
append_log("Error: Could not open the file.");
return;
}
/* Clear the current text in the log viewer */
XmTextSetString(log_text, "");
/* Read the file line by line and append it to the log text */
while (fgets(buffer, sizeof(buffer), file)) {
append_log(buffer);
}
fclose(file);
}
/* Callback function for the file selection dialog */
void file_ok_callback(Widget widget, XtPointer client_data, XtPointer call_data) {
XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *) call_data;
char *filename;
/* Convert the selected file name to a string */
if (XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &filename)) {
append_log("Loading log file...");
load_log_file(filename);
XtFree(filename);
}
}
/* Callback function for the open file button */
void open_file_callback(Widget widget, XtPointer client_data, XtPointer call_data) {
Widget file_dialog;
file_dialog = XmCreateFileSelectionDialog(widget, "file_dialog", NULL, 0);
XtAddCallback(file_dialog, XmNokCallback, file_ok_callback, NULL);
XtManageChild(file_dialog);
}
/* Exit button callback */
void exit_callback(Widget widget, XtPointer client_data, XtPointer call_data) {
append_log("Exit button clicked, exiting application.");
exit(0);
}
int main(int argc, char *argv[]) {
XtAppContext app;
Widget top_wid, main_window, button, open_button, row_col, scrolled_window;
/* Initialize the X Toolkit */
top_wid = XtVaAppInitialize(&app, "MotifApp", NULL, 0, &argc, argv, NULL, NULL);
/* Create a Main Window widget */
main_window = XtVaCreateManagedWidget("main_window", xmMainWindowWidgetClass, top_wid,
XmNwidth, 600, /* Set initial width */
XmNheight, 400, /* Set initial height */
NULL);
/* Create a RowColumn widget to hold other widgets */
row_col = XtVaCreateManagedWidget("row_col", xmRowColumnWidgetClass, main_window,
XmNorientation, XmVERTICAL,
XmNpacking, XmPACK_TIGHT,
XmNresizeWidth, True,
XmNresizeHeight, True,
NULL);
/* Create a Scrolled Window widget for the log viewer */
scrolled_window = XtVaCreateManagedWidget("scrolled_window", xmScrolledWindowWidgetClass, row_col,
XmNscrollingPolicy, XmAUTOMATIC,
XmNwidth, 500, /* Optional, for better initial sizing */
XmNheight, 300, /* Optional, for better initial sizing */
XmNresizeWidth, True,
XmNresizeHeight, True,
NULL);
/* Create the log viewer (XmText widget) */
log_text = XtVaCreateManagedWidget("log_text", xmTextWidgetClass, scrolled_window,
XmNrows, 10,
XmNcolumns, 50,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNscrollHorizontal, False,
XmNeditable, False,
XmNwordWrap, True,
XmNresizeWidth, True,
XmNresizeHeight, True,
NULL);
/* Add some initial log message */
append_log("Application started.");
/* Create an Open File button */
open_button = XtVaCreateManagedWidget("Open Log File", xmPushButtonWidgetClass, row_col, NULL);
XtAddCallback(open_button, XmNactivateCallback, open_file_callback, NULL);
/* Create an Exit button */
button = XtVaCreateManagedWidget("Exit", xmPushButtonWidgetClass, row_col, NULL);
XtAddCallback(button, XmNactivateCallback, exit_callback, NULL);
/* Realize the widgets (create the window) */
XtRealizeWidget(top_wid);
/* Enter the event processing loop */
XtAppMainLoop(app);
return 0;
}
(This post was last modified: 10-07-2024, 05:06 PM by jgunnoe.)
|