Annotation of researchv9/X11/src/X.V11R1/clients/xedit/ap.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char rcs_id[] = "$Header: ap.c,v 1.6 87/09/11 08:22:04 toddb Exp $";
                      3: #endif
                      4: 
                      5: /*
                      6:  *                       COPYRIGHT 1987
                      7:  *                DIGITAL EQUIPMENT CORPORATION
                      8:  *                    MAYNARD, MASSACHUSETTS
                      9:  *                     ALL RIGHTS RESERVED.
                     10:  *
                     11:  * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
                     12:  * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
                     13:  * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
                     14:  * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
                     15:  *
                     16:  * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT RIGHTS,
                     17:  * APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN ADDITION TO THAT
                     18:  * SET FORTH ABOVE.
                     19:  *
                     20:  *
                     21:  * Permission to use, copy, modify, and distribute this software and its
                     22:  * documentation for any purpose and without fee is hereby granted, provided
                     23:  * that the above copyright notice appear in all copies and that both that
                     24:  * copyright notice and this permission notice appear in supporting documentation,
                     25:  * and that the name of Digital Equipment Corporation not be used in advertising
                     26:  * or publicity pertaining to distribution of the software without specific, 
                     27:  * written prior permission.
                     28:  */
                     29: 
                     30: #include <sys/types.h>
                     31: #include <sys/stat.h>
                     32: #include <sys/file.h>
                     33: #include "xedit.h"
                     34: 
                     35: #define chunk 2048
                     36: 
                     37: typedef struct {
                     38:     char *buf;
                     39:     int size;
                     40:     XtTextPosition pos;
                     41:     XtTextSource *strSrc;
                     42: } ApAsSourceData;
                     43: 
                     44: /* Private Routines */
                     45: 
                     46: static XtTextPosition ApAsGetLastPos(src)
                     47:   XtTextSource *src;
                     48: {
                     49:   ApAsSourceData *data;
                     50:     data = (ApAsSourceData *)src->data;
                     51:     return ((*data->strSrc->getLastPos)(data->strSrc));
                     52: }
                     53: 
                     54: static ApAsSetLastPos(src, lastPos)
                     55:   XtTextSource *src;
                     56:   XtTextPosition lastPos;
                     57: {
                     58: }
                     59: 
                     60: static int ApAsRead(src, pos, text, maxRead)
                     61:   XtTextSource *src;
                     62:   int pos;
                     63:   XtTextBlock *text;
                     64:   int maxRead;
                     65: {
                     66:   ApAsSourceData *data;
                     67:     data = (ApAsSourceData *)src->data;
                     68:     return ((*data->strSrc->read)(data->strSrc, pos, text, maxRead));
                     69: }
                     70: 
                     71: 
                     72: static int ApAsReplace(src, startPos, endPos, text, delta)
                     73:   XtTextSource *src;
                     74:   XtTextPosition startPos, endPos;
                     75:   XtTextBlock *text;
                     76:   int *delta;
                     77: {
                     78:   ApAsSourceData *data;
                     79:   int i;
                     80:     data = (ApAsSourceData *)src->data;
                     81:     if((startPos!=endPos) || (startPos!=data->pos))
                     82:         return 0;
                     83:     if((data->pos + text->length) >= data->size){
                     84:         while((data->pos + text->length) >= data->size){
                     85:             data->size += chunk;
                     86:             data->buf = realloc(data->buf, data->size);  /* optimize this!!! */
                     87:         } 
                     88:         XtStringSourceDestroy(data->strSrc);
                     89:         data->strSrc = (XtTextSource *)XtStringSourceCreate(data->buf, 
                     90:                                                data->size, XttextEdit);
                     91:     }
                     92:     i = (*data->strSrc->replace)(data->strSrc, startPos, endPos, text, delta);
                     93:     data->pos += *delta;
                     94:     return (i);
                     95: }
                     96: 
                     97: static XtTextPosition ApAsScan (src, pos, sType, dir, count, include)
                     98:   XtTextSource *src;
                     99:   XtTextPosition pos;
                    100:   ScanType sType;
                    101:   ScanDirection dir;
                    102:   int count, include;
                    103: {
                    104:   ApAsSourceData *data;
                    105:     data = (ApAsSourceData *)src->data;
                    106:     return 
                    107:      ((*data->strSrc->scan)(data->strSrc, pos, sType, dir, count, include));
                    108: }
                    109: static XtEditType ApAsGetEditType(src)
                    110:   XtTextSource *src;
                    111: {
                    112: /*
                    113:     StringSourcePtr data;
                    114:     data = (StringSourcePtr) src->data;
                    115:     return(data->editMode);
                    116: */
                    117:     return(XttextAppend);
                    118: }
                    119: 
                    120: 
                    121: /* Public routines */
                    122: 
                    123: XtTextSource *TCreateApAsSource ()
                    124: {
                    125:   XtTextSource *src;
                    126:   ApAsSourceData *data;
                    127:     src = (XtTextSource *) malloc(sizeof(XtTextSource));
                    128:     src->read = ApAsRead;
                    129:     src->replace = ApAsReplace; 
                    130:     src->getLastPos = ApAsGetLastPos;
                    131:     src->setLastPos = ApAsSetLastPos;
                    132:     src->scan = ApAsScan;
                    133:     src->editType = ApAsGetEditType;
                    134:     data = (ApAsSourceData *)(malloc(sizeof(ApAsSourceData)));
                    135:     data->buf = calloc(chunk,1);
                    136:     data->pos = 0;
                    137:     data->size = chunk;
                    138:     data->strSrc = (XtTextSource *) XtStringSourceCreate (data->buf, data->size,XttextEdit);
                    139:     src->data = (int *)data;
                    140:     return src;
                    141: }
                    142: 
                    143: TDestroyApAsSource(src)
                    144:   XtTextSource *src;
                    145: {
                    146:   ApAsSourceData *data;
                    147:     data = (ApAsSourceData *)src->data;
                    148:     free(data->buf);
                    149:     free(data);
                    150:     free(src);
                    151: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.