duanev@kauai.ACA.MCC.COM (Duane Voth) (02/17/89)
ok, I give up. Does anyone have an example of how to use XtDiskSourceCreate, XtStringSourceCreate, et. al. for a textWidget? I want to be able to change the displayed file in a asciiDiskWidget at will (can be a readonly file) and send strings to an asciiStringWidget. duane
jlf@earth.cray.COM (John Freeman) (02/18/89)
> ok, I give up. Does anyone have an example of how to > use XtDiskSourceCreate, XtStringSourceCreate, et. al. > for a textWidget? I want to be able to change the displayed > file in a asciiDiskWidget at will (can be a readonly file) > and send strings to an asciiStringWidget. Here is a fragment of code from a program of mine that does what you ask for, hopefully complete enough. --------------------------------------------------------------- Widget source_box; XtTextSource xtsp = NULL; Arg file_arg[] = {XtNfile,(XtArgVal) source_filename}; /* * If XtDiskSourceCreate can't open source_filename, the whole * program will exit, so check first. */ ret = open(source_filename, O_RDONLY); if (ret < 0) { sprintf(carray, "Can't open source file %s\n", source_filename); return; } if (xtsp) { /* close old */ XtDiskSourceDestroy(xtsp); } /* Change file in source_box */ xtsp = XtDiskSourceCreate(source_box, file_arg, XtNumber(file_arg)); XtTextSetSource(source_box, xtsp, 0);
jlf@earth.cray.COM (John Freeman) (02/24/89)
> still, the DiskWidget wants a valid > file name at widget creation time - something I don't > want to specify. if the file name is null, > XtDiskSourceCreate constructs a temp file name and > proceeds to try to open it read only, which of course > fails, and then exits via XtError. do you know any > way around this? i hacked lib/Xaw/DiskSrc.c to create > and close the temp file name, which produces spurious > files, but at least it doesn't exit. You are entirely correct about temporary file names in the Disk Widget. I did exactly as you - modified DiskSrc.c to creat() the file, then unlink() in immediately. This works just fine. I also submitted a bug report to MIT about it. Context diffs for DiskSrc.c: *** DiskSrc.c Tue Oct 18 11:29:58 1988 --- DiskSrc.c.new Tue Feb 14 11:08:36 1989 *************** *** 389,394 **** --- 394,400 ---- if (data->fileName == NULL) { data->fileName = tmpnam (XtMalloc((unsigned)TMPSIZ)); data->is_tempfile = TRUE; + creat(data->fileName, 0600); } else data->is_tempfile = FALSE; *************** *** 408,413 **** --- 414,422 ---- XtError("Cannot open source file in XtDiskSourceCreate"); src->Replace = DummyReplaceText; } + if (data->is_tempfile) { + unlink(data->fileName); /* temp file won't be left around */ + } (void) fseek(data->file, topPosition, 2); data->length = ftell (data->file); data->buffer = (char *) XtMalloc((unsigned)bufSize); *************** *** 421,431 **** { DiskSourcePtr data; data = (DiskSourcePtr) src->data; XtFree((char *) data->buffer); - if (data->is_tempfile) { - unlink(data->fileName); - XtFree((char *) data->fileName); - } XtFree((char *) src->data); XtFree((char *) src); } --- 430,437 ---- { DiskSourcePtr data; data = (DiskSourcePtr) src->data; + XtFree((char *) data->fileName); XtFree((char *) data->buffer); XtFree((char *) src->data); XtFree((char *) src); }