Xaw3_1AsciiSrc.c revision 749
749N/A * Copyright 1989 Massachusetts Institute of Technology 749N/A * Permission to use, copy, modify, distribute, and sell this software and its 749N/A * documentation for any purpose is hereby granted without fee, provided that 749N/A * the above copyright notice appear in all copies and that both that 749N/A * copyright notice and this permission notice appear in supporting 749N/A * documentation, and that the name of M.I.T. not be used in advertising or 749N/A * publicity pertaining to distribution of the software without specific, 749N/A * written prior permission. M.I.T. makes no representations about the 749N/A * suitability of this software for any purpose. It is provided "as is" 749N/A * without express or implied warranty. 749N/A * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 749N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 749N/A * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 749N/A * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 749N/A * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 749N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 749N/A * Author: Chris Peterson, MIT X Consortium. 749N/A * Much code taken from X11R3 String and Disk Sources. 749N/A/**************************************************************** 749N/A * Full class record constant 749N/A ****************************************************************/ 749N/A /* class_name */ "AsciiSrc",
749N/A/* textSrc_class fields */ 749N/A/* asciiSrc_class fields */ 749N/A/************************************************************ 749N/A * Semi-Public Interfaces. 749N/A ************************************************************/ 749N/A/* Function Name: ClassInitialize 749N/A * Description: Class Initialize routine, called only once. 749N/A/* Function Name: Initialize 749N/A * Description: Initializes the simple menu widget 749N/A * Arguments: request - the widget requested by the argument list. 749N/A * new - the new widget with both resource and non 749N/A * Set correct flags (override resources) depending upon widget class. 749N/A/* Function Name: ReadText 749N/A * Description: This function reads the source. 749N/A * Arguments: w - the AsciiSource widget. 749N/A * pos - position of the text to retreive. 749N/A * RETURNED text - text block that will contain returned text. 749N/A * length - maximum number of characters to read. 749N/A * Returns: The number of characters read into the buffer. 749N/A/* Function Name: ReplaceText. 749N/A * Description: Replaces a block of text with new text. 749N/A * Arguments: w - the AsciiSource widget. 749N/A * startPos, endPos - ends of text that will be removed. 749N/A * text - new text to be inserted into buffer at startPos. 749N/A * Returns: XawEditError or XawEditDone. 749N/A * Editing a read only source is not allowed. 749N/A * If empty and not the only piece then remove it. 749N/A else {
/* We are fully in one piece. */ 749N/A * Put in the New Stuff. 749N/A * If we are in ascii string emulation mode. Then the 749N/A * string is not allowed to grow. 749N/A * Description: Scans the text source for the number and type 749N/A * Arguments: w - the AsciiSource widget. 749N/A * position - the position to start scanning. 749N/A * type - type of thing to scan for. 749N/A * dir - direction to scan. 749N/A * count - which occurance if this thing to search for. 749N/A * include - whether or not to include the character found in 749N/A * the position that is returned. 749N/A * Returns: the position of the item found. 749N/A * Note: While there are only 'n' characters in the file there are n+1 749N/A * possible cursor positions (one before the first character and 749N/A * one after the last character. 749N/A * Scanning right from src->ascii_src.length??? 749N/A return(0);
/* Scanning left from 0??? */ 749N/A * If the buffer is empty then return 0. 749N/A else {
/* XawstParagraph */ 749N/A/* case XawstAll: ---- handled in special code above */ 749N/A/* Function Name: Search 749N/A * Description: Searchs the text source for the text block passed 749N/A * Arguments: w - the AsciiSource Widget. 749N/A * position - the position to start scanning. 749N/A * dir - direction to scan. 749N/A * text - the text block to search for. 749N/A * Returns: the position of the item found. 749N/A/* Function Name: SetValues 749N/A * Description: Sets the values for the AsciiSource. 749N/A * Arguments: current - current state of the widget. 749N/A * request - what was requested. 749N/A * new - what the widget will become. 749N/A * Returns: True if redisplay is needed. 749N/A "AsciiSrc: The XtNuseStrinInPlace resources may not be changed.");
749N/A /* Fool it into not freeing the string */ 749N/A/* Function Name: GetValuesHook 749N/A * Description: This is a get values hook routine that sets the 749N/A * values specific to the ascii source. 749N/A * Arguments: w - the AsciiSource Widget. 749N/A * args - the argument list. 749N/A * num_args - the number of args. 749N/A/* Function Name: Destroy 749N/A * Description: Destroys an ascii source (frees all data) 749N/A * Arguments: src - the Ascii source Widget to free. 749N/A/************************************************************ 749N/A ************************************************************/ 749N/A/* Function Name: XawAsciiSourceFreeString 749N/A * Description: Frees the string returned by a get values call 749N/A * on the string when the source is of type string. 749N/A * Arguments: w - the AsciiSrc widget. 749N/A/* Function Name: XawAsciiSave 749N/A * Description: Saves all the pieces into a file or string as required. 749N/A * Arguments: w - the asciiSrc Widget. 749N/A * Returns: TRUE if the save was successful. 749N/A * If using the string in place then there is no need to play games 749N/A * to get the internal info into a readable string. 749N/A else {
/* This is a string widget. */ 749N/A/* Function Name: XawAsciiSaveAsFile 749N/A * Description: Save the current buffer as a file. 749N/A * Arguments: w - the AsciiSrc widget. 749N/A * name - name of the file to save this file into. 749N/A * Returns: True if the save was sucessful. 749N/A/* Function Name: XawAsciiSourceChanged 749N/A * Description: Returns true if the source has changed since last saved. 749N/A * Arguments: w - the ascii source widget. 749N/A * Returns: a Boolean (see description). 749N/A/************************************************************ 749N/A ************************************************************/ 749N/A/* Function Name: WriteToFile 749N/A * Description: Write the string specified to the begining of the file 749N/A * Arguments: w - the widget. (for error messages only) 749N/A * string - string to write. 749N/A * name - the name of the file 749N/A * file - file to write it to. 749N/A * Returns: returns TRUE if sucessful, FALSE otherwise. 749N/A/* Function Name: StorePiecesInString 749N/A * Description: store the pieces in memory into a standard ascii string. 749N/A * Arguments: data - the ascii pointer data. 749N/A * This will refill all pieces to capacity. 749N/A/* Function Name: InitStringOrFile. 749N/A * Description: Initializes the string or file. 749N/A * Arguments: src - the AsciiSource. 749N/A * Returns: none - May exit though. 749N/A * type is XawAsciiFile. 749N/A "Creating a read only disk widget and no file specified.",
749N/A "Bad editMode for ascii source; must be Read, Append or Edit.",
749N/A * If we are using teh string in place then set the other fields as follows: 749N/A * piece->used = src->ascii_src.length; 749N/A/* Function Name: AllocNewPiece 749N/A * Description: Allocates a new piece of memory. 749N/A * Arguments: src - The AsciiSrc Widget. 749N/A * prev - the piece just before this one, or NULL. 749N/A * Returns: the allocated piece. 749N/A/* Function Name: FreeAllPieces 749N/A * Description: Frees all the pieces 749N/A * Arguments: src - The AsciiSrc Widget. 749N/A printf(
"Programmer Botch in FreeAllPieces, there may be a memory leak.\n");
749N/A/* Function Name: RemovePiece 749N/A * Description: Removes a piece from the list. 749N/A * piece - the piece to remove. 749N/A/* Function Name: FindPiece 749N/A * Description: Finds the piece containing the position indicated. 749N/A * Arguments: src - The AsciiSrc Widget. 749N/A * position - the position that we are searching for. 749N/A * RETURNED first - the position of the first character in this piece. 749N/A * Returns: piece - the piece that contains this position. 749N/A return(
old_piece);
/* if we run off the end the return the last piece */ 749N/A/* Function Name: MyStrncpy 749N/A * Description: Just like string copy, but slower and will always 749N/A * work on overlapping strings. 749N/A * Arguments: (same as strncpy) - s1, s2 - strings to copy (2->1). 749N/A * n - the number of chars to copy. 749N/A/* Function Name: BreakPiece 749N/A * Description: Breaks a full piece into two new pieces. 749N/A * Arguments: src - The AsciiSrc Widget. 749N/A * piece - the piece to break. 749N/A/************************************************************ 749N/A * Compatability functions. 749N/A ************************************************************/ 749N/A/* Function Name: AsciiStringSourceCreate 749N/A * Description: Creates a string source. 749N/A * Arguments: parent - the widget that will own this source. 749N/A * args, num_args - the argument list. 749N/A * Returns: a pointer to the new text source. 749N/A * This is hacked up to try to emulate old functionality, it 749N/A * may not work, as I have not old code to test it on. 749N/A * Chris D. Peterson 8/31/89. 749N/A#
endif /* ASCII_STRING */ 749N/A/* Function Name: AsciiDiskSourceCreate 749N/A * Description: Creates a disk source. 749N/A * Arguments: parent - the widget that will own this source. 749N/A * args, num_args - the argument list. 749N/A * Returns: a pointer to the new text source.