home *** CD-ROM | disk | FTP | other *** search
- /* Systems Sciences Laboratory, Webster Research Center */
-
- static char *PROGRAM_information[] =
- {
- "Copyright (c) 1988 Xerox Corporation. All rights reserved.",
- "$Header$",
- "$Locker$"
- }
- ;
-
- /*
- * Copyright protection claimed includes all forms and matters of copyrightable
- * material and information now allowed by statutory or judicial lay or
- * herinafter granted, including without limitation, material generated from
- * the software programs which are displayed on the screen such as icons,
- * screen display looks, etc.
- */
-
-
- #include "xfilebrowser.h"
-
- #define chunk 2048
-
- typedef struct {
- char *buf;
- int size;
- XtTextPosition pos;
- XtTextSource strSrc;
- } ApAsSourceData;
-
- /* Private Routines */
-
-
- static XtTextPosition ApAsGetLastPos(src)
- XtTextSource src;
- {
- ApAsSourceData *data;
- data = (ApAsSourceData *)src->data;
- return (XtTextPosition)(*data->strSrc->GetLastPos)(data->strSrc);
- }
-
- static ApAsSetLastPos(src, lastPos)
- XtTextSource src;
- XtTextPosition lastPos;
- {
- }
-
- static int ApAsRead(src, pos, text, maxRead)
- XtTextSource src;
- int pos;
- XtTextBlock *text;
- int maxRead;
- {
- ApAsSourceData *data;
- data = (ApAsSourceData *)src->data;
- return ((*data->strSrc->Read)(data->strSrc, pos, text, maxRead));
- }
-
-
- static Arg stringargs[] = {
- {XtNstring, (XtArgVal) NULL},
- {XtNlength, (XtArgVal) NULL},
- {XtNeditType, (XtArgVal) XttextEdit},
- };
-
- static int ApAsReplace(src, startPos, endPos, text)
- XtTextSource src;
- XtTextPosition startPos, endPos;
- XtTextBlock *text;
- {
- ApAsSourceData *data;
- int i;
-
- if (!allowedit) return 0;
- data = (ApAsSourceData *)src->data;
-
- if((data->pos + text->length) >= data->size){
- while((data->pos + text->length) >= data->size){
- data->size += chunk;
- data->buf = XtRealloc(data->buf, data->size); /* optimize this!!! */
- }
- XtStringSourceDestroy(data->strSrc);
- stringargs[0].value = (XtArgVal)data->buf ;
- stringargs[1].value = (XtArgVal)data->size ;
- data->strSrc = (XtTextSource)
- XtStringSourceCreate(toplevel,stringargs,XtNumber(stringargs));
- }
- i = (*data->strSrc->Replace)(data->strSrc, startPos, endPos, text);
- data->pos += text->length;
- return (i);
- }
-
- static XtTextPosition ApAsScan (src, pos, sType, dir, count, include)
- XtTextSource src;
- XtTextPosition pos;
- XtTextScanType sType;
- XtTextScanDirection dir;
- int count, include;
- {
- ApAsSourceData *data;
- data = (ApAsSourceData *)src->data;
- return
- ((*data->strSrc->Scan)(data->strSrc, pos, sType, dir, count, include));
- }
-
-
- /* Public routines */
-
- XtTextSource TCreateApAsSource ()
- {
- XtTextSource src;
- ApAsSourceData *data;
- src = (XtTextSource) XtMalloc(sizeof(XtTextSourceRec));
- src->Read = ApAsRead;
- src->Replace = ApAsReplace;
- src->GetLastPos = ApAsGetLastPos;
- src->SetLastPos = ApAsSetLastPos;
- src->Scan = ApAsScan;
- src->edit_mode = XttextEdit;
- data = (ApAsSourceData *)(XtMalloc(sizeof(ApAsSourceData)));
- data->buf = XtCalloc(chunk,1);
- data->pos = 0;
- data->size = chunk;
- stringargs[0].value = (XtArgVal)data->buf ;
- stringargs[1].value = (XtArgVal)data->size ;
- data->strSrc = (XtTextSource) XtStringSourceCreate (toplevel,stringargs,
- XtNumber(stringargs));
- src->data = (caddr_t)data;
- return src;
- }
-
- TDestroyApAsSource(src)
- XtTextSource src;
- {
- ApAsSourceData *data;
- data = (ApAsSourceData *)src->data;
- XtStringSourceDestroy(data->strSrc);
- XtFree(data->buf);
- XtFree(data);
- XtFree(src);
- }
-