#include <X11/IntrinsicP.h>#include <stdio.h>#include <ctype.h>#include <errno.h>#include <X11/StringDefs.h>#include <X11/Xos.h>#include <stdlib.h>#include <X11/Xfuncs.h>#include <X11/Xaw3d/XawInit.h>#include <X11/Xaw3d/AsciiSrcP.h>#include <X11/Xmu/Misc.h>#include <X11/Xmu/CharSet.h>#include <X11/Xaw3d/MultiSrcP.h>Include dependency graph for AsciiSrc.c:

Go to the source code of this file.
Defines | |
| #define | offset(field) XtOffsetOf(AsciiSrcRec, ascii_src.field) |
| #define | Off_t off_t |
| #define | Size_t size_t |
| #define | superclass (&textSrcClassRec) |
| #define | HALF_PIECE (src->ascii_src.piece_size/2) |
Functions | |
| static XawTextPosition | Scan () |
| static XawTextPosition | Search () |
| static XawTextPosition | ReadText () |
| static int | ReplaceText () |
| static Piece * | FindPiece () |
| static Piece ** | AllocNewPiece () |
| static FILE * | InitStringOrFile () |
| static void | FreeAllPieces () |
| static void | RemovePiece () |
| static void | BreakPiece () |
| static void | LoadPieces () |
| static void | RemoveOldStringOrFile () |
| static void | CvtStringToAsciiType () |
| static void | ClassInitialize () |
| static void | Initialize () |
| static void | Destroy () |
| static void | GetValuesHook () |
| static String | MyStrncpy () |
| static String | StorePiecesInString () |
| static Boolean | SetValues () |
| static Boolean | WriteToFile () |
| static void | Initialize (Widget request, Widget new, ArgList args, Cardinal *num_args) |
| static XawTextPosition | ReadText (Widget w, XawTextPosition pos, XawTextBlock *text, int length) |
| static int | ReplaceText (Widget w, XawTextPosition startPos, XawTextPosition endPos, XawTextBlock *text) |
| static XawTextPosition | Scan (Widget w, XawTextPosition position, XawTextScanType type, XawTextScanDirection dir, int count, Boolean include) |
| static XawTextPosition | Search (Widget w, XawTextPosition position, XawTextScanDirection dir, XawTextBlock *text) |
| static Boolean | SetValues (Widget current, Widget request, Widget new, ArgList args, Cardinal *num_args) |
| static void | GetValuesHook (Widget w, ArgList args, Cardinal *num_args) |
| static void | Destroy (Widget w) |
| void | XawAsciiSourceFreeString (Widget w) |
| Boolean | XawAsciiSave (Widget w) |
| Boolean | XawAsciiSaveAsFile (Widget w, String name) |
| Boolean | XawAsciiSourceChanged (Widget w) |
| static void | RemoveOldStringOrFile (AsciiSrcObject src, Boolean checkString) |
| static Boolean | WriteToFile (String string, String name) |
| static String | StorePiecesInString (AsciiSrcObject src) |
| static FILE * | InitStringOrFile (AsciiSrcObject src, Boolean newString) |
| static void | LoadPieces (AsciiSrcObject src, FILE *file, char *string) |
| static Piece * | AllocNewPiece (AsciiSrcObject src, Piece *prev) |
| static void | FreeAllPieces (AsciiSrcObject src) |
| static void | RemovePiece (AsciiSrcObject src, Piece *piece) |
| static Piece * | FindPiece (AsciiSrcObject src, XawTextPosition position, XawTextPosition *first) |
| static String | MyStrncpy (char *s1, char *s2, int n) |
| static void | BreakPiece (AsciiSrcObject src, Piece *piece) |
| static void | CvtStringToAsciiType (XrmValuePtr args, Cardinal *num_args, XrmValuePtr fromVal, XrmValuePtr toVal) |
Variables | |
| static int | magic_value = MAGIC_VALUE |
| static XtResource | resources [] |
| AsciiSrcClassRec | asciiSrcClassRec |
| WidgetClass | asciiSrcObjectClass = (WidgetClass)&asciiSrcClassRec |
| #define HALF_PIECE (src->ascii_src.piece_size/2) |
| #define Off_t off_t |
| #define offset | ( | field | ) | XtOffsetOf(AsciiSrcRec, ascii_src.field) |
Definition at line 67 of file AsciiSrc.c.
| #define Size_t size_t |
| #define superclass (&textSrcClassRec) |
Definition at line 113 of file AsciiSrc.c.
Referenced by ChangeManaged(), Realize(), and XmuWnInitializeNodes().
| static Piece* AllocNewPiece | ( | AsciiSrcObject | src, | |
| Piece * | prev | |||
| ) | [static] |
Definition at line 1138 of file AsciiSrc.c.
References _Piece::next, and _Piece::prev.
01141 { 01142 Piece * piece = XtNew(Piece); 01143 01144 if (prev == NULL) { 01145 src->ascii_src.first_piece = piece; 01146 piece->next = NULL; 01147 } 01148 else { 01149 if (prev->next != NULL) 01150 (prev->next)->prev = piece; 01151 piece->next = prev->next; 01152 prev->next = piece; 01153 } 01154 01155 piece->prev = prev; 01156 01157 return(piece); 01158 }
| static Piece* * AllocNewPiece | ( | ) |
| static void BreakPiece | ( | AsciiSrcObject | src, | |
| Piece * | piece | |||
| ) | [static] |
Definition at line 1271 of file AsciiSrc.c.
References AllocNewPiece(), HALF_PIECE, _Piece::text, and _Piece::used.
01274 { 01275 Piece * new = AllocNewPiece(src, piece); 01276 01277 new->text = XtMalloc(src->ascii_src.piece_size * sizeof(unsigned char)); 01278 strncpy(new->text, piece->text + HALF_PIECE, 01279 src->ascii_src.piece_size - HALF_PIECE); 01280 piece->used = HALF_PIECE; 01281 new->used = src->ascii_src.piece_size - HALF_PIECE; 01282 }
Here is the call graph for this function:

| static void BreakPiece | ( | ) |
| static void ClassInitialize | ( | ) | [static] |
Definition at line 180 of file AsciiSrc.c.
References XawInitializeWidgetSet().
00181 { 00182 XawInitializeWidgetSet(); 00183 XtAddConverter( XtRString, XtRAsciiType, CvtStringToAsciiType, 00184 NULL, (Cardinal) 0); 00185 }
Here is the call graph for this function:

| static void CvtStringToAsciiType | ( | XrmValuePtr | args, | |
| Cardinal * | num_args, | |||
| XrmValuePtr | fromVal, | |||
| XrmValuePtr | toVal | |||
| ) | [static] |
Definition at line 1286 of file AsciiSrc.c.
References type, XawAsciiFile, XawAsciiString, XmuCopyISOLatin1Lowered(), XtEfile, and XtEstring.
01291 { 01292 static XawAsciiType type; 01293 static XrmQuark XtQEstring = NULLQUARK; 01294 static XrmQuark XtQEfile; 01295 XrmQuark q; 01296 char lowerName[40]; 01297 01298 if (XtQEstring == NULLQUARK) { 01299 XtQEstring = XrmPermStringToQuark(XtEstring); 01300 XtQEfile = XrmPermStringToQuark(XtEfile); 01301 } 01302 01303 if (strlen ((char*)fromVal->addr) < sizeof lowerName) { 01304 XmuCopyISOLatin1Lowered(lowerName, (char *) fromVal->addr); 01305 q = XrmStringToQuark(lowerName); 01306 01307 if (q == XtQEstring) type = XawAsciiString; 01308 else if (q == XtQEfile) type = XawAsciiFile; 01309 else { 01310 toVal->size = 0; 01311 toVal->addr = NULL; 01312 return; 01313 } 01314 toVal->size = sizeof type; 01315 toVal->addr = (XPointer) &type; 01316 return; 01317 } 01318 toVal->size = 0; 01319 toVal->addr = NULL; 01320 }
Here is the call graph for this function:

| static void CvtStringToAsciiType | ( | ) |
| static void Destroy | ( | Widget | w | ) | [static] |
Definition at line 718 of file AsciiSrc.c.
References RemoveOldStringOrFile().
00720 { 00721 RemoveOldStringOrFile((AsciiSrcObject) w, True); 00722 }
Here is the call graph for this function:

| static void Destroy | ( | ) |
| static Piece* FindPiece | ( | AsciiSrcObject | src, | |
| XawTextPosition | position, | |||
| XawTextPosition * | first | |||
| ) | [static] |
Definition at line 1216 of file AsciiSrc.c.
01219 { 01220 Piece * old_piece = NULL, * piece = src->ascii_src.first_piece; 01221 XawTextPosition temp; 01222 01223 for ( temp = 0 ; piece != NULL ; temp += piece->used, piece = piece->next ) { 01224 *first = temp; 01225 old_piece = piece; 01226 01227 if ((temp + piece->used) > position) 01228 return(piece); 01229 } 01230 return(old_piece); /* if we run off the end the return the last piece */ 01231 }
| static Piece* FindPiece | ( | ) | [static] |
Referenced by ReadText(), ReplaceText(), Scan(), and Search().
Here is the caller graph for this function:

| static void FreeAllPieces | ( | AsciiSrcObject | src | ) | [static] |
Definition at line 1167 of file AsciiSrc.c.
References first, RemovePiece(), and void().
01169 { 01170 Piece * next, * first = src->ascii_src.first_piece; 01171 01172 if (first->prev != NULL) 01173 (void) printf("Xaw AsciiSrc Object: possible memory leak in FreeAllPieces().\n"); 01174 01175 for ( ; first != NULL ; first = next ) { 01176 next = first->next; 01177 RemovePiece(src, first); 01178 } 01179 }
Here is the call graph for this function:

| static void FreeAllPieces | ( | ) | [static] |
Referenced by RemoveOldStringOrFile(), and StorePiecesInString().
Here is the caller graph for this function:

| static void GetValuesHook | ( | Widget | w, | |
| ArgList | args, | |||
| Cardinal * | num_args | |||
| ) | [static] |
Definition at line 688 of file AsciiSrc.c.
References _AsciiSrcRec::ascii_src, _AsciiSrcPart::first_piece, i, name, streq, _AsciiSrcPart::string, _Piece::text, _AsciiSrcPart::type, _AsciiSrcPart::use_string_in_place, value, XawAsciiSave(), and XawAsciiString.
00692 { 00693 AsciiSrcObject src = (AsciiSrcObject) w; 00694 int i; 00695 00696 if (src->ascii_src.type == XawAsciiString) { 00697 for (i = 0; i < *num_args ; i++ ) 00698 if (streq(args[i].name, XtNstring)) { 00699 if (src->ascii_src.use_string_in_place) { 00700 *((char **) args[i].value) = src->ascii_src.first_piece->text; 00701 } 00702 else { 00703 if (XawAsciiSave(w)) /* If save sucessful. */ 00704 *((char **) args[i].value) = src->ascii_src.string; 00705 } 00706 break; 00707 } 00708 } 00709 }
Here is the call graph for this function:

| static void GetValuesHook | ( | ) |
| static void Initialize | ( | Widget | request, | |
| Widget | new, | |||
| ArgList | args, | |||
| Cardinal * | num_args | |||
| ) | [static] |
Definition at line 197 of file AsciiSrc.c.
References _AsciiSrcPart::allocated_string, _AsciiSrcRec::ascii_src, _AsciiSrcPart::changes, FALSE, file, InitStringOrFile(), LoadPieces(), _AsciiSrcPart::string, TextSrcPart::text_format, _AsciiSrcRec::text_src, TRUE, _AsciiSrcPart::type, _AsciiSrcPart::use_string_in_place, XawAsciiFile, XawAsciiString, and XawFmt8Bit.
00201 { 00202 AsciiSrcObject src = (AsciiSrcObject) new; 00203 FILE * file; 00204 00205 /* 00206 * Set correct flags (override resources) depending upon widget class. 00207 */ 00208 00209 src->text_src.text_format = XawFmt8Bit; /* data format. */ 00210 00211 #ifdef ASCII_DISK 00212 if (XtIsSubclass(XtParent(new), asciiDiskWidgetClass)) { 00213 src->ascii_src.type = XawAsciiFile; 00214 src->ascii_src.string = src->ascii_src.filename; 00215 } 00216 #endif 00217 00218 #ifdef ASCII_STRING 00219 if (XtIsSubclass(XtParent(new), asciiStringWidgetClass)) { 00220 src->ascii_src.use_string_in_place = TRUE; 00221 src->ascii_src.type = XawAsciiString; 00222 } 00223 #endif 00224 00225 src->ascii_src.changes = FALSE; 00226 src->ascii_src.allocated_string = FALSE; 00227 00228 file = InitStringOrFile(src, src->ascii_src.type == XawAsciiFile); 00229 LoadPieces(src, file, NULL); 00230 00231 if (file != NULL) fclose(file); 00232 }
Here is the call graph for this function:

| static void Initialize | ( | void | ) |
Initialisation of Scilab
| static FILE* InitStringOrFile | ( | AsciiSrcObject | src, | |
| Boolean | newString | |||
| ) | [static] |
Definition at line 979 of file AsciiSrc.c.
References FALSE, file, MAGIC_VALUE, Off_t, strerror(), tmpnam(), TMPSIZ, TRUE, void(), XawAsciiString, XawtextAppend, XawtextEdit, and XawtextRead.
00982 { 00983 char * open_mode = NULL; 00984 FILE * file; 00985 char fileName[TMPSIZ]; 00986 00987 if (src->ascii_src.type == XawAsciiString) { 00988 00989 if (src->ascii_src.string == NULL) 00990 src->ascii_src.length = 0; 00991 00992 else if (! src->ascii_src.use_string_in_place) { 00993 src->ascii_src.string = XtNewString(src->ascii_src.string); 00994 src->ascii_src.allocated_string = True; 00995 src->ascii_src.length = strlen(src->ascii_src.string); 00996 } 00997 00998 if (src->ascii_src.use_string_in_place) { 00999 src->ascii_src.length = strlen(src->ascii_src.string); 01000 /* In case the length resource is incorrectly set */ 01001 if (src->ascii_src.length > src->ascii_src.ascii_length) 01002 src->ascii_src.ascii_length = src->ascii_src.length; 01003 01004 if (src->ascii_src.ascii_length == MAGIC_VALUE) 01005 src->ascii_src.piece_size = src->ascii_src.length; 01006 else 01007 src->ascii_src.piece_size = src->ascii_src.ascii_length + 1; 01008 } 01009 01010 return(NULL); 01011 } 01012 01013 /* 01014 * type is XawAsciiFile. 01015 */ 01016 01017 src->ascii_src.is_tempfile = FALSE; 01018 01019 switch (src->text_src.edit_mode) { 01020 case XawtextRead: 01021 if (src->ascii_src.string == NULL) 01022 XtErrorMsg("NoFile", "asciiSourceCreate", "XawError", 01023 "Creating a read only disk widget and no file specified.", 01024 NULL, 0); 01025 open_mode = "r"; 01026 break; 01027 case XawtextAppend: 01028 case XawtextEdit: 01029 if (src->ascii_src.string == NULL) { 01030 src->ascii_src.string = fileName; 01031 (void) tmpnam(src->ascii_src.string); 01032 src->ascii_src.is_tempfile = TRUE; 01033 open_mode = "w"; 01034 } else 01035 open_mode = "r+"; 01036 break; 01037 default: 01038 XtErrorMsg("badMode", "asciiSourceCreate", "XawError", 01039 "Bad editMode for ascii source; must be Read, Append or Edit.", 01040 NULL, NULL); 01041 } 01042 01043 /* Allocate new memory for the temp filename, because it is held in 01044 * a stack variable, not static memory. This widget does not need 01045 * to keep the private state field is_tempfile -- it is only accessed 01046 * in this routine, and its former setting is unused. 01047 */ 01048 if (newString || src->ascii_src.is_tempfile) { 01049 src->ascii_src.string = XtNewString(src->ascii_src.string); 01050 src->ascii_src.allocated_string = TRUE; 01051 } 01052 01053 if (!src->ascii_src.is_tempfile) { 01054 if ((file = fopen(src->ascii_src.string, open_mode)) != 0) { 01055 (void) fseek(file, (Off_t)0, 2); 01056 src->ascii_src.length = (XawTextPosition) ftell(file); 01057 return file; 01058 } else { 01059 String params[2]; 01060 Cardinal num_params = 2; 01061 01062 params[0] = src->ascii_src.string; 01063 params[1] = strerror(errno); 01064 XtAppWarningMsg(XtWidgetToApplicationContext((Widget)src), 01065 "openError", "asciiSourceCreate", "XawWarning", 01066 "Cannot open file %s; %s", params, &num_params); 01067 } 01068 } 01069 src->ascii_src.length = 0; 01070 return((FILE *)NULL); 01071 }
Here is the call graph for this function:

| static FILE* InitStringOrFile | ( | ) | [static] |
| static void LoadPieces | ( | AsciiSrcObject | src, | |
| FILE * | file, | |||
| char * | string | |||
| ) | [static] |
Definition at line 1074 of file AsciiSrc.c.
References AllocNewPiece(), left, Min, Off_t, Size_t, _Piece::text, _Piece::used, and XawAsciiFile.
01078 { 01079 char *local_str, *ptr; 01080 Piece * piece = NULL; 01081 XawTextPosition left; 01082 01083 if (string == NULL) { 01084 if (src->ascii_src.type == XawAsciiFile) { 01085 local_str = XtMalloc((unsigned) (src->ascii_src.length + 1) 01086 * sizeof(unsigned char)); 01087 if (src->ascii_src.length != 0) { 01088 fseek(file, (Off_t)0, 0); 01089 src->ascii_src.length = fread(local_str, (Size_t)sizeof(unsigned char), 01090 (Size_t)src->ascii_src.length, file); 01091 if (src->ascii_src.length <= 0) 01092 XtErrorMsg("readError", "asciiSourceCreate", "XawError", 01093 "fread returned error.", NULL, NULL); 01094 } 01095 local_str[src->ascii_src.length] = '\0'; 01096 } 01097 else 01098 local_str = src->ascii_src.string; 01099 } 01100 else 01101 local_str = string; 01102 01103 if (src->ascii_src.use_string_in_place) { 01104 piece = AllocNewPiece(src, piece); 01105 piece->used = Min(src->ascii_src.length, src->ascii_src.piece_size); 01106 piece->text = src->ascii_src.string; 01107 return; 01108 } 01109 01110 ptr = local_str; 01111 left = src->ascii_src.length; 01112 01113 do { 01114 piece = AllocNewPiece(src, piece); 01115 01116 piece->text = XtMalloc((unsigned)src->ascii_src.piece_size 01117 * sizeof(unsigned char)); 01118 piece->used = Min(left, src->ascii_src.piece_size); 01119 if (piece->used != 0) 01120 strncpy(piece->text, ptr, piece->used); 01121 01122 left -= piece->used; 01123 ptr += piece->used; 01124 } while (left > 0); 01125 01126 if ( (src->ascii_src.type == XawAsciiFile) && (string == NULL) ) 01127 XtFree(local_str); 01128 }
Here is the call graph for this function:

| static void LoadPieces | ( | ) |
Referenced by Initialize(), SetValues(), and StorePiecesInString().
Here is the caller graph for this function:

| static String MyStrncpy | ( | char * | s1, | |
| char * | s2, | |||
| int | n | |||
| ) | [static] |
Definition at line 1242 of file AsciiSrc.c.
References buf.
01245 { 01246 char buf[256]; 01247 char* temp; 01248 01249 if (n == 0) return s1; 01250 01251 if (n < sizeof buf) temp = buf; 01252 else temp = XtMalloc((unsigned)sizeof(unsigned char) * n); 01253 01254 strncpy(temp, s2, n); /* Saber has a bug that causes it to generate*/ 01255 strncpy(s1, temp, n); /* a bogus warning message here (CDP 6/32/89)*/ 01256 01257 if (temp != buf) XtFree(temp); 01258 return s1; 01259 }
| static String MyStrncpy | ( | ) | [static] |
| static XawTextPosition ReadText | ( | Widget | w, | |
| XawTextPosition | pos, | |||
| XawTextBlock * | text, | |||
| int | length | |||
| ) | [static] |
Definition at line 244 of file AsciiSrc.c.
References count, FindPiece(), XawTextBlock::firstPos, XawTextBlock::length, XawTextBlock::ptr, _Piece::text, and _Piece::used.
00249 { 00250 AsciiSrcObject src = (AsciiSrcObject) w; 00251 XawTextPosition count, start; 00252 Piece * piece = FindPiece(src, pos, &start); 00253 00254 text->firstPos = pos; 00255 text->ptr = piece->text + (pos - start); 00256 count = piece->used - (pos - start); 00257 text->length = (length > count) ? count : length; 00258 return(pos + text->length); 00259 }
Here is the call graph for this function:

| static XawTextPosition ReadText | ( | ) |
| static void RemoveOldStringOrFile | ( | AsciiSrcObject | src, | |
| Boolean | checkString | |||
| ) | [static] |
Definition at line 900 of file AsciiSrc.c.
References FreeAllPieces().
00903 { 00904 FreeAllPieces(src); 00905 00906 if (checkString && src->ascii_src.allocated_string) { 00907 XtFree(src->ascii_src.string); 00908 src->ascii_src.allocated_string = False; 00909 src->ascii_src.string = NULL; 00910 } 00911 }
Here is the call graph for this function:

| static void RemoveOldStringOrFile | ( | ) | [static] |
| static void RemovePiece | ( | AsciiSrcObject | src, | |
| Piece * | piece | |||
| ) | [static] |
Definition at line 1189 of file AsciiSrc.c.
References _Piece::next, _Piece::prev, and _Piece::text.
01192 { 01193 if (piece->prev == NULL) 01194 src->ascii_src.first_piece = piece->next; 01195 else 01196 (piece->prev)->next = piece->next; 01197 01198 if (piece->next != NULL) 01199 (piece->next)->prev = piece->prev; 01200 01201 if (!src->ascii_src.use_string_in_place) 01202 XtFree(piece->text); 01203 01204 XtFree((char *)piece); 01205 }
| static void RemovePiece | ( | ) |
| static int ReplaceText | ( | Widget | w, | |
| XawTextPosition | startPos, | |||
| XawTextPosition | endPos, | |||
| XawTextBlock * | text | |||
| ) | [static] |
Definition at line 271 of file AsciiSrc.c.
References _AsciiSrcRec::ascii_src, BreakPiece(), _AsciiSrcPart::changes, TextSrcPart::edit_mode, FindPiece(), XawTextBlock::firstPos, XawTextBlock::length, _AsciiSrcPart::length, Min, MyStrncpy(), _Piece::next, _AsciiSrcPart::piece_size, _Piece::prev, XawTextBlock::ptr, RemovePiece(), _Piece::text, _AsciiSrcRec::text_src, TRUE, _AsciiSrcPart::use_string_in_place, _Piece::used, XawEditDone, XawEditError, and XawtextRead.
00275 { 00276 AsciiSrcObject src = (AsciiSrcObject) w; 00277 Piece *start_piece, *end_piece, *temp_piece; 00278 XawTextPosition start_first, end_first; 00279 int length, firstPos; 00280 00281 /* 00282 * Editing a read only source is not allowed. 00283 */ 00284 00285 if (src->text_src.edit_mode == XawtextRead) 00286 return(XawEditError); 00287 00288 start_piece = FindPiece(src, startPos, &start_first); 00289 end_piece = FindPiece(src, endPos, &end_first); 00290 00291 src->ascii_src.changes = TRUE; /* We have changed the buffer. */ 00292 00293 /* 00294 * Remove Old Stuff. 00295 */ 00296 00297 if (start_piece != end_piece) { 00298 temp_piece = start_piece->next; 00299 00300 /* 00301 * If empty and not the only piece then remove it. 00302 */ 00303 00304 if ( ((start_piece->used = startPos - start_first) == 0) && 00305 !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) 00306 RemovePiece(src, start_piece); 00307 00308 while (temp_piece != end_piece) { 00309 temp_piece = temp_piece->next; 00310 RemovePiece(src, temp_piece->prev); 00311 } 00312 end_piece->used -= endPos - end_first; 00313 if (end_piece->used != 0) 00314 MyStrncpy(end_piece->text, (end_piece->text + endPos - end_first), 00315 (int) end_piece->used); 00316 } 00317 else { /* We are fully in one piece. */ 00318 if ( (start_piece->used -= endPos - startPos) == 0) { 00319 if ( !((start_piece->next == NULL) && (start_piece->prev == NULL)) ) 00320 RemovePiece(src, start_piece); 00321 } 00322 else { 00323 MyStrncpy(start_piece->text + (startPos - start_first), 00324 start_piece->text + (endPos - start_first), 00325 (int) (start_piece->used - (startPos - start_first)) ); 00326 if ( src->ascii_src.use_string_in_place && 00327 ((src->ascii_src.length - (endPos - startPos)) < 00328 (src->ascii_src.piece_size - 1)) ) 00329 start_piece->text[src->ascii_src.length - (endPos - startPos)] = '\0'; 00330 } 00331 } 00332 00333 src->ascii_src.length += -(endPos - startPos) + text->length; 00334 00335 if ( text->length != 0) { 00336 00337 /* 00338 * Put in the New Stuff. 00339 */ 00340 00341 start_piece = FindPiece(src, startPos, &start_first); 00342 00343 length = text->length; 00344 firstPos = text->firstPos; 00345 00346 while (length > 0) { 00347 char * ptr; 00348 int fill; 00349 00350 if (src->ascii_src.use_string_in_place) { 00351 if (start_piece->used == (src->ascii_src.piece_size - 1)) { 00352 /* 00353 * If we are in ascii string emulation mode. Then the 00354 * string is not allowed to grow. 00355 */ 00356 start_piece->used = src->ascii_src.length = 00357 src->ascii_src.piece_size - 1; 00358 start_piece->text[src->ascii_src.length] = '\0'; 00359 return(XawEditError); 00360 } 00361 } 00362 00363 00364 if (start_piece->used == src->ascii_src.piece_size) { 00365 BreakPiece(src, start_piece); 00366 start_piece = FindPiece(src, startPos, &start_first); 00367 } 00368 00369 fill = Min((int)(src->ascii_src.piece_size - start_piece->used), length); 00370 00371 ptr = start_piece->text + (startPos - start_first); 00372 MyStrncpy(ptr + fill, ptr, 00373 (int) start_piece->used - (startPos - start_first)); 00374 strncpy(ptr, text->ptr + firstPos, fill); 00375 00376 startPos += fill; 00377 firstPos += fill; 00378 start_piece->used += fill; 00379 length -= fill; 00380 } 00381 } 00382 00383 if (src->ascii_src.use_string_in_place) 00384 start_piece->text[start_piece->used] = '\0'; 00385 00386 XtCallCallbacks(w, XtNcallback, NULL); /* Call callbacks, we have changed 00387 the buffer. */ 00388 00389 return(XawEditDone); 00390 }
Here is the call graph for this function:

| static int ReplaceText | ( | ) | [static] |
| static XawTextPosition Scan | ( | Widget | w, | |
| XawTextPosition | position, | |||
| XawTextScanType | type, | |||
| XawTextScanDirection | dir, | |||
| int | count, | |||
| Boolean | include | |||
| ) | [static] |
Definition at line 411 of file AsciiSrc.c.
References _AsciiSrcRec::ascii_src, FALSE, FindPiece(), first, _AsciiSrcPart::length, _Piece::next, _Piece::prev, _Piece::text, TRUE, _Piece::used, XawsdRight, XawstAll, XawstEOL, XawstParagraph, XawstPositions, and XawstWhiteSpace.
00418 { 00419 AsciiSrcObject src = (AsciiSrcObject) w; 00420 int inc; 00421 Piece* piece; 00422 XawTextPosition first, first_eol_position = 0; 00423 char* ptr; 00424 00425 if (type == XawstAll) { /* Optomize this common case. */ 00426 if (dir == XawsdRight) 00427 return(src->ascii_src.length); 00428 return(0); /* else. */ 00429 } 00430 00431 if (position > src->ascii_src.length) 00432 position = src->ascii_src.length; 00433 00434 if ( dir == XawsdRight ) { 00435 if (position == src->ascii_src.length) 00436 /* 00437 * Scanning right from src->ascii_src.length??? 00438 */ 00439 return(src->ascii_src.length); 00440 inc = 1; 00441 } 00442 else { 00443 if (position == 0) 00444 return(0); /* Scanning left from 0??? */ 00445 inc = -1; 00446 position--; 00447 } 00448 00449 piece = FindPiece(src, position, &first); 00450 00451 /* 00452 * If the buffer is empty then return 0. 00453 */ 00454 00455 if ( piece->used == 0 ) return(0); 00456 00457 ptr = (position - first) + piece->text; 00458 00459 switch (type) { 00460 case XawstEOL: 00461 case XawstParagraph: 00462 case XawstWhiteSpace: 00463 for ( ; count > 0 ; count-- ) { 00464 Boolean non_space = FALSE, first_eol = TRUE; 00465 /* CONSTCOND */ 00466 while (TRUE) { 00467 unsigned char c = *ptr; 00468 00469 ptr += inc; 00470 position += inc; 00471 00472 if (type == XawstWhiteSpace) { 00473 if (isspace(c)) { 00474 if (non_space) 00475 break; 00476 } 00477 else 00478 non_space = TRUE; 00479 } 00480 else if (type == XawstEOL) { 00481 if (c == '\n') break; 00482 } 00483 else { /* XawstParagraph */ 00484 if (first_eol) { 00485 if (c == '\n') { 00486 first_eol_position = position; 00487 first_eol = FALSE; 00488 } 00489 } 00490 else 00491 if ( c == '\n') 00492 break; 00493 else if ( !isspace(c) ) 00494 first_eol = TRUE; 00495 } 00496 00497 00498 if ( ptr < piece->text ) { 00499 piece = piece->prev; 00500 if (piece == NULL) /* Begining of text. */ 00501 return(0); 00502 ptr = piece->text + piece->used - 1; 00503 } 00504 else if ( ptr >= (piece->text + piece->used) ) { 00505 piece = piece->next; 00506 if (piece == NULL) /* End of text. */ 00507 return(src->ascii_src.length); 00508 ptr = piece->text; 00509 } 00510 } 00511 } 00512 if (!include) { 00513 if ( type == XawstParagraph) 00514 position = first_eol_position; 00515 position -= inc; 00516 } 00517 break; 00518 case XawstPositions: 00519 position += count * inc; 00520 break; 00521 case XawstAll: /* handled in special code above */ 00522 default: 00523 break; 00524 } 00525 00526 if ( dir == XawsdLeft ) 00527 position++; 00528 00529 if (position >= src->ascii_src.length) 00530 return(src->ascii_src.length); 00531 if (position < 0) 00532 return(0); 00533 00534 return(position); 00535 }
Here is the call graph for this function:

| static XawTextPosition Scan | ( | ) | [static] |
| static XawTextPosition Search | ( | Widget | w, | |
| XawTextPosition | position, | |||
| XawTextScanDirection | dir, | |||
| XawTextBlock * | text | |||
| ) | [static] |
Definition at line 547 of file AsciiSrc.c.
References buf, count, FindPiece(), first, XawTextBlock::firstPos, XawTextBlock::length, _Piece::next, _Piece::prev, XawTextBlock::ptr, _Piece::text, TRUE, _Piece::used, XawsdLeft, XawsdRight, and XawTextSearchError.
00552 { 00553 AsciiSrcObject src = (AsciiSrcObject) w; 00554 int inc, count = 0; 00555 char * ptr; 00556 Piece * piece; 00557 char * buf; 00558 XawTextPosition first; 00559 00560 if ( dir == XawsdRight ) 00561 inc = 1; 00562 else { 00563 inc = -1; 00564 if (position == 0) 00565 return(XawTextSearchError); /* scanning left from 0??? */ 00566 position--; 00567 } 00568 00569 buf = XtMalloc((unsigned)sizeof(unsigned char) * text->length); 00570 strncpy(buf, (text->ptr + text->firstPos), text->length); 00571 piece = FindPiece(src, position, &first); 00572 ptr = (position - first) + piece->text; 00573 00574 /* CONSTCOND */ 00575 while (TRUE) { 00576 if (*ptr == ((dir == XawsdRight) ? *(buf + count) 00577 : *(buf + text->length - count - 1)) ) { 00578 if (count == (text->length - 1)) 00579 break; 00580 else 00581 count++; 00582 } 00583 else { 00584 if (count != 0) { 00585 position -=inc * count; 00586 ptr -= inc * count; 00587 } 00588 count = 0; 00589 } 00590 00591 ptr += inc; 00592 position += inc; 00593 00594 while ( ptr < piece->text ) { 00595 piece = piece->prev; 00596 if (piece == NULL) { /* Begining of text. */ 00597 XtFree(buf); 00598 return(XawTextSearchError); 00599 } 00600 ptr = piece->text + piece->used - 1; 00601 } 00602 00603 while ( ptr >= (piece->text + piece->used) ) { 00604 piece = piece->next; 00605 if (piece == NULL) { /* End of text. */ 00606 XtFree(buf); 00607 return(XawTextSearchError); 00608 } 00609 ptr = piece->text; 00610 } 00611 } 00612 00613 XtFree(buf); 00614 if (dir == XawsdLeft) 00615 return(position); 00616 return(position - (text->length - 1)); 00617 }
Here is the call graph for this function:

| static XawTextPosition Search | ( | ) |
| static Boolean SetValues | ( | Widget | current, | |
| Widget | request, | |||
| Widget | new, | |||
| ArgList | args, | |||
| Cardinal * | num_args | |||
| ) | [static] |
Definition at line 629 of file AsciiSrc.c.
References _AsciiSrcRec::ascii_src, FALSE, file, i, InitStringOrFile(), LoadPieces(), name, RemoveOldStringOrFile(), streq, TRUE, _AsciiSrcPart::type, _AsciiSrcPart::use_string_in_place, and XawTextSetSource().
00633 { 00634 AsciiSrcObject src = (AsciiSrcObject) new; 00635 AsciiSrcObject old_src = (AsciiSrcObject) current; 00636 Boolean total_reset = FALSE, string_set = FALSE; 00637 FILE * file; 00638 int i; 00639 00640 if ( old_src->ascii_src.use_string_in_place != 00641 src->ascii_src.use_string_in_place ) { 00642 XtAppWarning( XtWidgetToApplicationContext(new), 00643 "AsciiSrc: The XtNuseStringInPlace resource may not be changed."); 00644 src->ascii_src.use_string_in_place = 00645 old_src->ascii_src.use_string_in_place; 00646 } 00647 00648 for (i = 0; i < *num_args ; i++ ) 00649 if (streq(args[i].name, XtNstring)) { 00650 string_set = TRUE; 00651 break; 00652 } 00653 00654 if ( string_set || (old_src->ascii_src.type != src->ascii_src.type) ) { 00655 RemoveOldStringOrFile(old_src, string_set); /* remove old info. */ 00656 file = InitStringOrFile(src, string_set); /* Init new info. */ 00657 LoadPieces(src, file, NULL); /* load new info into internal buffers. */ 00658 if (file != NULL) fclose(file); 00659 XawTextSetSource( XtParent(new), new, 0); /* Tell text widget 00660 what happened. */ 00661 total_reset = TRUE; 00662 } 00663 00664 if ( old_src->ascii_src.ascii_length != src->ascii_src.ascii_length ) 00665 src->ascii_src.piece_size = src->ascii_src.ascii_length; 00666 00667 if ( !total_reset && 00668 (old_src->ascii_src.piece_size != src->ascii_src.piece_size) ) { 00669 String string = StorePiecesInString(old_src); 00670 FreeAllPieces(old_src); 00671 LoadPieces(src, NULL, string); 00672 XtFree(string); 00673 } 00674 00675 return(FALSE); 00676 }
Here is the call graph for this function:

| static Boolean SetValues | ( | ) | [static] |
| static String StorePiecesInString | ( | AsciiSrcObject | src | ) | [static] |
Definition at line 944 of file AsciiSrc.c.
References first, FreeAllPieces(), LoadPieces(), _Piece::next, string, _Piece::text, and _Piece::used.
00946 { 00947 String string; 00948 XawTextPosition first; 00949 Piece * piece; 00950 00951 string = XtMalloc((unsigned) sizeof(unsigned char) * 00952 src->ascii_src.length + 1); 00953 00954 for (first = 0, piece = src->ascii_src.first_piece ; piece != NULL; 00955 first += piece->used, piece = piece->next) 00956 strncpy(string + first, piece->text, piece->used); 00957 00958 string[src->ascii_src.length] = '\0'; /* NULL terminate this sucker. */ 00959 00960 /* 00961 * This will refill all pieces to capacity. 00962 */ 00963 00964 if (src->ascii_src.data_compression) { 00965 FreeAllPieces(src); 00966 LoadPieces(src, NULL, string); 00967 } 00968 00969 return(string); 00970 }
Here is the call graph for this function:

| static String StorePiecesInString | ( | ) |
Referenced by _XawMultiSave(), _XawMultiSaveAsFile(), XawAsciiSave(), and XawAsciiSaveAsFile().
Here is the caller graph for this function:

| static Boolean WriteToFile | ( | String | string, | |
| String | name | |||
| ) | [static] |
Definition at line 922 of file AsciiSrc.c.
References close(), FALSE, fd, TRUE, and write().
00924 { 00925 int fd; 00926 00927 if ( ((fd = creat(name, 0666)) == -1 ) || 00928 (write(fd, string, sizeof(unsigned char) * strlen(string)) == -1) ) 00929 return(FALSE); 00930 00931 if ( close(fd) == -1 ) 00932 return(FALSE); 00933 00934 return(TRUE); 00935 }
Here is the call graph for this function:

| static Boolean WriteToFile | ( | ) |
Referenced by _XawMultiSave(), _XawMultiSaveAsFile(), XawAsciiSave(), and XawAsciiSaveAsFile().
Here is the caller graph for this function:

| Boolean XawAsciiSave | ( | Widget | w | ) |
Definition at line 777 of file AsciiSrc.c.
References _XawMultiSave(), _AsciiSrcPart::allocated_string, _AsciiSrcRec::ascii_src, _AsciiSrcPart::changes, FALSE, multiSrcObjectClass, StorePiecesInString(), _AsciiSrcPart::string, string, TRUE, _AsciiSrcPart::type, _AsciiSrcPart::use_string_in_place, WriteToFile(), and XawAsciiFile.
Referenced by GetValuesHook().
00780 { 00781 AsciiSrcObject src = (AsciiSrcObject) w; 00782 00783 /* If the src is really a multi, call the multi save. */ 00784 00785 if ( XtIsSubclass( w, multiSrcObjectClass ) ) 00786 return( _XawMultiSave( w ) ); 00787 00788 else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { 00789 XtErrorMsg("bad argument", "asciiSource", "XawError", 00790 "XawAsciiSave's parameter must be an asciiSrc or multiSrc.", 00791 NULL, NULL); 00792 } 00793 00794 /* 00795 * If using the string in place then there is no need to play games 00796 * to get the internal info into a readable string. 00797 */ 00798 00799 if (src->ascii_src.use_string_in_place) 00800 return(TRUE); 00801 00802 if (src->ascii_src.type == XawAsciiFile) { 00803 char * string; 00804 00805 if (!src->ascii_src.changes) /* No changes to save. */ 00806 return(TRUE); 00807 00808 string = StorePiecesInString(src); 00809 00810 if (WriteToFile(string, src->ascii_src.string) == FALSE) { 00811 XtFree(string); 00812 return(FALSE); 00813 } 00814 XtFree(string); 00815 } 00816 else { 00817 if (src->ascii_src.allocated_string == TRUE) 00818 XtFree(src->ascii_src.string); 00819 else 00820 src->ascii_src.allocated_string = TRUE; 00821 00822 src->ascii_src.string = StorePiecesInString(src); 00823 } 00824 src->ascii_src.changes = FALSE; 00825 return(TRUE); 00826 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Boolean XawAsciiSaveAsFile | ( | Widget | w, | |
| String | name | |||
| ) |
Definition at line 839 of file AsciiSrc.c.
References _XawMultiSaveAsFile(), multiSrcObjectClass, StorePiecesInString(), string, and WriteToFile().
00843 { 00844 AsciiSrcObject src = (AsciiSrcObject) w; 00845 String string; 00846 Boolean ret; 00847 00848 /* If the src is really a multi, call the multi save. - */ 00849 00850 if ( XtIsSubclass( w, multiSrcObjectClass ) ) 00851 return( _XawMultiSaveAsFile( w, name ) ); 00852 00853 else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { 00854 XtErrorMsg("bad argument", "asciiSource", "XawError", 00855 "XawAsciiSaveAsFile's 1st parameter must be an asciiSrc or multiSrc.", 00856 NULL, NULL); 00857 } 00858 00859 string = StorePiecesInString(src); 00860 00861 ret = WriteToFile(string, name); 00862 XtFree(string); 00863 return(ret); 00864 }
Here is the call graph for this function:

| Boolean XawAsciiSourceChanged | ( | Widget | w | ) |
Definition at line 876 of file AsciiSrc.c.
References multiSrcObjectClass.
00879 { 00880 if ( XtIsSubclass( w, multiSrcObjectClass ) ) 00881 return( ( (MultiSrcObject) w )->multi_src.changes ); 00882 00883 if ( XtIsSubclass( w, asciiSrcObjectClass ) ) 00884 return( ( (AsciiSrcObject) w)->ascii_src.changes ); 00885 00886 XtErrorMsg("bad argument", "asciiSource", "XawError", 00887 "XawAsciiSourceChanged parameter must be an asciiSrc or multiSrc.", 00888 NULL, NULL); 00889 00890 return( True ); /* for gcc -Wall */ 00891 }
| void XawAsciiSourceFreeString | ( | Widget | w | ) |
Definition at line 741 of file AsciiSrc.c.
References _XawMultiSourceFreeString(), _AsciiSrcPart::allocated_string, _AsciiSrcRec::ascii_src, FALSE, multiSrcObjectClass, _AsciiSrcPart::string, _AsciiSrcPart::type, and XawAsciiFile.
00744 { 00745 AsciiSrcObject src = (AsciiSrcObject) w; 00746 00747 /* If the src is really a multi, call the multi routine.*/ 00748 00749 if ( XtIsSubclass( w, multiSrcObjectClass ) ) { 00750 _XawMultiSourceFreeString( w ); 00751 return; 00752 } 00753 00754 else if ( !XtIsSubclass( w, asciiSrcObjectClass ) ) { 00755 XtErrorMsg("bad argument", "asciiSource", "XawError", 00756 "XawAsciiSourceFreeString's parameter must be an asciiSrc or multiSrc.", 00757 NULL, NULL); 00758 } 00759 00760 if (src->ascii_src.allocated_string && src->ascii_src.type != XawAsciiFile) { 00761 src->ascii_src.allocated_string = FALSE; 00762 XtFree(src->ascii_src.string); 00763 src->ascii_src.string = NULL; 00764 } 00765 }
Here is the call graph for this function:

Definition at line 114 of file AsciiSrc.c.
| WidgetClass asciiSrcObjectClass = (WidgetClass)&asciiSrcClassRec |
Definition at line 165 of file AsciiSrc.c.
int magic_value = MAGIC_VALUE [static] |
Definition at line 65 of file AsciiSrc.c.
XtResource resources[] [static] |
Initial value:
{
{XtNstring, XtCString, XtRString, sizeof (char *),
offset(string), XtRString, NULL},
{XtNtype, XtCType, XtRAsciiType, sizeof (XawAsciiType),
offset(type), XtRImmediate, (XtPointer)XawAsciiString},
{XtNdataCompression, XtCDataCompression, XtRBoolean, sizeof (Boolean),
offset(data_compression), XtRImmediate, (XtPointer) TRUE},
{XtNpieceSize, XtCPieceSize, XtRInt, sizeof (XawTextPosition),
offset(piece_size), XtRImmediate, (XtPointer) BUFSIZ},
{XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
offset(callback), XtRCallback, (XtPointer)NULL},
{XtNuseStringInPlace, XtCUseStringInPlace, XtRBoolean, sizeof (Boolean),
offset(use_string_in_place), XtRImmediate, (XtPointer) FALSE},
{XtNlength, XtCLength, XtRInt, sizeof (int),
offset(ascii_length), XtRInt, (XtPointer) &magic_value},
}
Definition at line 69 of file AsciiSrc.c.
1.5.1