home *** CD-ROM | disk | FTP | other *** search
- /**---------------------------------------------------------------------
- ***
- *** file: xmemisc.c
- ***
- *** project: jetedit - Motif Widgets text editor
- ***
- ***-------------------------------------------------------------------*/
-
- #define BUFFER 20 /* The number of commands that can be undone. */
- #define BUFSIZE 40 /* The default storage size for the undo data. */
- #include "xme.h"
-
- struct UndoRecord {
- XmTextPosition start_pos;
- XmTextPosition end_pos;
- XmTextPosition cursor_pos;
- char *delete_string;
- } UndoRecordPtr[BUFFER];
-
- int head, tail;
-
- /*--------------------------------------------------------------
- ** OpenUndoBuffer
- ** Initialize an array of UndoRecord structures.
- */
- void OpenUndoBuffer()
- {
- int i;
-
- for (i=0; i<BUFFER; i++) {
- UndoRecordPtr[i].delete_string = XtMalloc (BUFSIZE);
- (UndoRecordPtr[i].delete_string)[0] = '\0';
- UndoRecordPtr[i].start_pos = 0;
- UndoRecordPtr[i].end_pos = 0;
- UndoRecordPtr[i].cursor_pos = 0;
- }
- head = 0;
- tail = 0;
- }
-
-
- /*--------------------------------------------------------------
- ** InitUndoBuffer
- ** Reinitialize the array of UndoRecord structures.
- */
- void InitUndoBuffer()
- {
- int i;
-
- for (i=0; i<BUFFER; i++) {
- UndoRecordPtr[i].delete_string =
- XtRealloc (UndoRecordPtr[i].delete_string, BUFSIZE);
- (UndoRecordPtr[i].delete_string)[0] = '\0';
- UndoRecordPtr[i].start_pos = 0;
- UndoRecordPtr[i].end_pos = 0;
- UndoRecordPtr[i].cursor_pos = 0;
- }
- head = 0;
- tail = 0;
- }
-
-
- /*--------------------------------------------------------------
- ** CloseUndoBuffer
- ** Deallocate the string arrays.
- */
- void CloseUndoBuffer()
- {
- int i;
-
- XtSetSensitive(undo_button, False);
- for (i=0; i<BUFFER; i++)
- XtFree (UndoRecordPtr[i].delete_string);
- }
-
-
- /*--------------------------------------------------------------
- ** UndoStoreCB
- ** Store an UndoRecord structure.
- */
- void UndoStoreCB (w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- XmTextVerifyCallbackStruct *cb = (XmTextVerifyCallbackStruct *) call_data;
- XmTextPosition startpos, endpos;
- char *deltext; /* text being deleted */
- char *thestring; /* the complete text in the text widget */
- int textl; /* the length of the text to be inserted */
- long i, j;
- Arg al[1];
- int newlines;
-
- if (no_undo) return; /* a flag indicating to not store an undo record */
-
- if (file_saved) {
- file_saved = False;
- XtSetSensitive(save_button, True);
- sprintf (message_string, " Editing: %s", thefile);
- XtSetArg(al[0], XmNlabelString,
- XmStringCreateLtoR(message_string, charset));
- XtSetValues(message, al, 1);
- }
- XtSetSensitive(undo_button, True);
- head++;
- if (head >= BUFFER)
- head = 0;
- if (head == tail) {
- tail++;
- if (tail >= BUFFER)
- tail = 0;
- }
-
- startpos = cb->startPos;
- endpos = cb->endPos;
- textl = cb->text->length;
- thestring = cb->text->ptr;
- deltext = UndoRecordPtr[head].delete_string;
- deltext[0] = '\0';
- UndoRecordPtr[head].cursor_pos = cb->currInsert;
- UndoRecordPtr[head].start_pos = startpos;
- UndoRecordPtr[head].end_pos = startpos + textl;
-
- newlines = 0;
- if (textl) { /* text is being inserted */
- for (i=0; i<textl; i++)
- if (thestring[i] == '\n')
- newlines++;
- }
- if (endpos != startpos) { /* text is being deleted */
- if (endpos - startpos + 1 > BUFSIZE) {
- deltext = XtRealloc
- (UndoRecordPtr[head].delete_string, endpos - startpos +1);
- UndoRecordPtr[head].delete_string = deltext;
- }
- thestring = XmTextGetString(w);
- j=0;
- for (i=startpos; i<endpos; i++,j++) {
- deltext[j] = thestring[i];
- if (deltext[j] == '\n')
- newlines--;
- }
- deltext[j] = '\0';
- XtFree(thestring);
- }
-
- if (newlines) {
- /* update the line number message */
- lines += newlines;
- sprintf (message_string, " Line: %4d", lines);
- XtSetArg(al[0], XmNlabelString,
- XmStringCreateLtoR(message_string, charset));
- XtSetValues(line, al, 1);
- }
- }
-
-
- /*--------------------------------------------------------------
- ** Undo
- ** Restore previous condition from an UndoRecord Structure.
- */
- void Undo(event)
- XKeyEvent *event;
- {
- XmTextPosition startpos;
- XmTextPosition endpos;
- char *thestring;
- int length, j, newlines;
- char *file_string;
- char line_string[15];
- Arg al[1];
-
- if (head == tail) return;
- no_undo = True;
- startpos = UndoRecordPtr[head].start_pos;
- endpos = UndoRecordPtr[head].end_pos;
- thestring = UndoRecordPtr[head].delete_string;
- length = strlen(thestring);
-
- XmTextReplace (text, startpos, endpos, thestring);
- if (length > 1)
- XmTextSetSelection(text, startpos, startpos+length, event->time+1);
- MoveTo(UndoRecordPtr[head].cursor_pos);
-
- file_string = (char *)XmTextGetString(text);
- newlines = 1;
- for (j=0; j<UndoRecordPtr[head].cursor_pos; j++)
- if(file_string[j] == '\n')
- newlines++;
-
- if (lines != newlines) {
- lines = newlines;
- /* update the line number message */
- sprintf (line_string, " Line:%5d", lines);
- XtSetArg(al[0], XmNlabelString,
- XmStringCreateLtoR(line_string, charset));
- XtSetValues(line, al, 1);
- }
- XtFree (file_string);
-
- head--;
- if (head < 0)
- head = BUFFER - 1;
- if (head == tail)
- XtSetSensitive(undo_button, False);
- no_undo = False;
- }
-
-
- /*--------------------------------------------------------------
- ** Indent
- ** Insert tab stop or spaces as appropriate.
- ** Return the number of characters inserted.
- */
- int Indent(file_string, cursorPos, fixCursor)
- char *file_string;
- XmTextPosition cursorPos;
- Boolean fixCursor;
- {
- XmTextPosition linePos;
- int i,j;
- char theChar;
- int numSpaces;
- char insertionText[MAX_TAB_SPACES+1];
- Boolean leading; /* leading or trailing flag */
-
- /* if real tabs are selected, just insert and return */
- if (leading_tabs && trailing_tabs) {
- XmTextReplace(text, cursorPos, cursorPos, "\t");
- return(1);
- }
-
- /* FixCursor is a flag indicating this routine was called from
- the auto indenting routines in NewLine. NewLine sends only
- single lines of text in file_string rather than the entire
- file. */
- if (fixCursor)
- linePos = strlen (file_string);
- else linePos = cursorPos;
-
- /* We now figure out where to tab to. The first step is to move back
- to the first non-space character, counting spaces as we go. */
- numSpaces = 0;
- while (linePos-- > 0) {
- if (file_string[linePos] != ' ')
- break;
- numSpaces++;
- }
-
- /* If the first none space character is a newline, or we reach the
- beginning of the string without finding anything but spaces,
- we are inserting a leading tab stop. */
- theChar = file_string[linePos];
- if ((theChar == '\n') || (linePos < 0))
- leading = True;
-
- /* else if the character was anything but '\t', we are
- inserting a trailing tab. Determine the total number of
- characters on the line (stop counting if '\t' is encountered) */
- else if (theChar != '\t') {
- leading = False;
- numSpaces++;
- while (linePos-- > 0) {
- if ((file_string[linePos] == '\n') || (file_string[linePos] == '\t'))
- break;
- numSpaces++;
- }
- }
-
- /* else the character must have been '\t'. We check to see if there is anything
- but spaces or tabs back on the line. If there are, it's a trailing tab.
- If not, it's a leading tab. */
- else {
- while (linePos >= 0) {
- if ((file_string[linePos] != ' ') && (file_string[linePos] != '\t'))
- break;
- linePos--;
- }
- if ((file_string[linePos] == '\n') || (linePos < 0))
- leading = True;
- else leading = False;
- }
-
- if ((leading && leading_tabs) || (!leading && trailing_tabs)) {
- XmTextReplace(text, cursorPos, cursorPos, "\t");
- return(1);
- }
-
- /* Insert enough spaces to fill out to the next tab_spaces stop. */
- i = tab_spaces - (numSpaces % tab_spaces);
- for (j=0; j<i; j++)
- insertionText[j] = ' ';
- insertionText[i] = '\0';
- XmTextReplace(text, cursorPos, cursorPos, insertionText);
- return (i);
- }
-
-
-
- /*--------------------------------------------------------------
- ** Outdent
- ** Delete to previous tab stop.
- */
- int Outdent(file_string, cursorPos, fixCursor)
- char *file_string;
- XmTextPosition cursorPos;
- Boolean fixCursor;
- {
- XmTextPosition linePos;
- int i;
- int numSpaces;
- int numNotabs;
-
- numSpaces=0;
- /* FixCursor is a flag indicating this routine was called from
- the auto indenting routines in NewLine. NewLine sends only
- single lines of text in file_string rather than the entire
- file. */
- if (fixCursor)
- linePos = strlen (file_string);
- else linePos = cursorPos;
- /* find previous none space */
- while (linePos > 0) {
- linePos--;
- if (file_string[linePos] != ' ')
- break;
- numSpaces++;
- }
- /* Now we determine the total number of characters in the line.
- We stop counting if we find a '\n' or '\t'. */
- numNotabs = numSpaces;
- if (file_string[linePos] != ' ') {
- while (linePos > 0) {
- if ((file_string[linePos] == '\n') || (file_string[linePos] == '\t'))
- break;
- numNotabs++;
- linePos--;
- }
- }
-
- if (numNotabs) {
- i = numNotabs % tab_spaces;
- if (i == 0)
- i = tab_spaces;
- if (i > numSpaces)
- i = numSpaces;
- }
- else {
- if (file_string[linePos] == '\t')
- i=1;
- else i=0;
- }
-
- if (i)
- XmTextReplace(text, cursorPos-i, cursorPos, "");
- return (i);
- }
-
-
- /*--------------------------------------------------------------
- ** IndentText
- ** Indent each line in a block of selected text
- ** or at the cursor if no text selected.
- */
- void IndentText(w,event)
- Widget w;
- XKeyEvent *event;
- {
- XmTextPosition cursorPos;
- XmTextPosition linePos;
- XmTextPosition endPos;
- XmTextPosition startPos;
- Arg al[2];
- char *selString; /* the selected block of text */
- char *file_string;
- int i;
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- /* get cursor position */
- XtSetArg(al[0], XmNcursorPosition, &cursorPos);
- XtGetValues(text, al, 1);
-
- /* The cursor may be located at either the start or end of the
- selected block of text. */
- selString = NULL;
- if ((selString = XmTextGetSelection (text)) && strlen(selString)) {
- if (!strncmp (selString, file_string+cursorPos, strlen(selString))) {
- startPos = cursorPos;
- endPos = cursorPos + strlen (selString);
- }
- else {
- startPos = cursorPos - strlen (selString);
- endPos = cursorPos;
- }
- cursorPos = endPos;
-
- if (file_string[--cursorPos] == '\n')
- cursorPos--; /* if last character is newline,
- move back one character */
- while (cursorPos >= startPos) {
- /* find start of line */
- while (file_string[cursorPos] != '\n' && cursorPos >= startPos)
- cursorPos--;
- linePos = cursorPos + 1;
- while (linePos < endPos) {
- if ((file_string[linePos] != ' ') && (file_string[linePos] != '\t'))
- break;
- linePos++;
- }
- i = Indent (file_string, linePos, False);
- endPos += i;
- cursorPos --;
- }
- /* the widget apparently clears the selection at event->time,
- so we need to add one to get it to set a new selection */
- XmTextSetSelection (text, startPos, endPos, event->time+1);
- MoveTo(endPos);
- }
- else {
- Indent(file_string, cursorPos, False);
- }
-
- if (selString)
- XtFree(selString);
- XtFree (file_string);
- }
-
-
- /*--------------------------------------------------------------
- ** OutdentText
- ** Outdent each line in a block of selected text
- ** or at the cursor if no text selected.
- */
- void OutdentText(w,event)
- Widget w;
- XKeyEvent *event;
- {
- XmTextPosition cursorPos; /* text cursor position */
- XmTextPosition endPos;
- XmTextPosition startPos;
- XmTextPosition oldPos;
- Arg al[2];
- char *selString; /* the selected block of text */
- char *file_string;
- char theChar;
-
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- /* get cursor position */
- XtSetArg(al[0], XmNcursorPosition, &cursorPos);
- XtGetValues(text, al, 1);
-
- selString = NULL;
- if ((selString = XmTextGetSelection (text)) && strlen(selString)) {
- /*determine if cursor is at the beginning or end of selected block */
- if (!strncmp (selString, file_string+cursorPos, strlen(selString))) {
- startPos = cursorPos;
- endPos = cursorPos + strlen (selString);
- }
- else {
- startPos = cursorPos - strlen (selString);
- endPos = cursorPos;
- }
- cursorPos = endPos;
-
- if (file_string[--cursorPos] == '\n')
- cursorPos--; /* if last character is \n, skip */
- while (cursorPos >= startPos) {
- /* find start of line */
- while (file_string[cursorPos] != '\n' && cursorPos >= startPos)
- cursorPos--;
- /* find first non space or tab */
- oldPos = cursorPos;
- while ((theChar = file_string[++cursorPos]) == '\t' || theChar == ' ')
- ;
- endPos -= Outdent(file_string, cursorPos, False);
- cursorPos = oldPos-1;
- }
- /* the widget apparently clears the selection at event->time,
- so we need to add one to get it to set a new selection */
- XmTextSetSelection (text, startPos, endPos, event->time+1);
- }
- else Outdent(file_string, cursorPos, False);
-
- if (selString)
- XtFree(selString);
- XtFree (file_string);
- }
-
-
- /*--------------------------------------------------------------
- ** GetPrevLine
- ** Get the previous line minus leading and trailing
- ** spaces and tabs.
- **
- ** This routine alters the contents of file_string.
- ** It returns a pointer to the
- ** position in file_string of the first non whitespace
- ** character of the first line before old_pos which is
- ** not a comment line. This can be the line containing
- ** old_pos. '\0's are put at the starting value of
- ** old_pos and at the end of the returned line but
- ** before trailing comments or whitespace.
- **
- ** On entry, old_pos points to the current insert point.
- ** On exit, it points to the '\n' immediately preceding
- ** the returned line. If there is no '\n', old_pos returns
- ** -1.
- **
- ** text_pos returns the offset from
- ** the beginning of file_string of the beginning of
- ** the returned string.
- **
- ** spacetab will contain a '\n' followed by the leading
- ** whitespace and terminated with '\0'. This is for use
- ** in indenting the next line to the same position as the
- ** previous one.
- */
- char *GetPrevLine(file_string, old_pos, text_pos, spacetab)
- char *file_string;
- long *old_pos;
- long *text_pos;
- char *spacetab;
- {
- char *trailing;
- long i;
- char theChar;
- char *theLine;
-
- /* the while loop eliminates lines of only tabs, spaces & comments */
- i=0;
- while (*old_pos > 0) {
- /* get the line */
- file_string[*old_pos] = '\0';
- while (file_string[--(*old_pos)] != '\n')
- if (*old_pos < 0) break;
- *text_pos = *old_pos;
- (*text_pos)++;
- /* save leading spaces and tabs */
- i=0;
- spacetab[i++] = '\n';
- while ((file_string[*text_pos] == ' ') || (file_string[*text_pos] == '\t')) {
- spacetab[i++] = file_string[*text_pos];
- (*text_pos)++;
- }
- /* strip the returned line of leading tabs & spaces */
- theLine = (char *)(file_string + *text_pos);
- /* if the line contains any characters, check for a comment line */
- if (theLine[0] != '\0') {
- /* break if this line is not a comment */
- if (theLine[0] != '*' && strncmp (theLine, "/*", 2))
- break;
- }
- }
- spacetab[i] = '\0';
- spacetab[i+1] = '\0'; /* used by NewLine */
-
- /* delete trailing comments */
- if (trailing = strchr (theLine, '/'))
- if (trailing[1] == '*')
- trailing[0] = '\0';
-
- /* delete trailing spaces & tabs */
- i = strlen (theLine);
- while (((theChar = theLine[--i]) == ' ') || (theChar == '\t'))
- ;
- theLine[i+1] = '\0';
- return (theLine);
- }
-
- /*--------------------------------------------------------------
- ** InSwitch
- ** Determine whether text_pos is in a switch.
- */
- Boolean InSwitch(file_string, text_pos)
- char *file_string;
- long text_pos;
- {
- int close_brackets;
- char *theLine;
-
- close_brackets = 0;
- while (text_pos-- > 0) {
- if (file_string[text_pos] == '}')
- close_brackets++;
- else if (file_string[text_pos] == '{')
- if (close_brackets >= 0)
- close_brackets--;
- else
- return False;
- else if (file_string[text_pos] == 's') {
- theLine = (char *)(file_string + text_pos);
- if (!strncmp (theLine, "switch", 6))
- return True;
- }
- }
- return False;
- }
-
- /*--------------------------------------------------------------
- ** NewLine
- ** Indent new line to appropriate syntax sensitive
- ** position.
- */
- void NewLine(w,event)
- Widget w;
- XKeyEvent *event;
- {
- XmTextPosition cursorPos; /* text cursor position */
- Arg al[1];
- char *file_string;
- long textPos;
- long oldPos;
- char spacetab[100];
- char garbage[100];
- char *theLine;
- char *oldLine;
- char theChar;
- int i;
- Boolean inFlag;
- char line_string[15];
-
- /* get the cursor position */
- XtSetArg(al[0], XmNcursorPosition, &cursorPos);
- XtGetValues(text, al, 1);
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- if ((indent_style==NONE) || (file_string[cursorPos-1] == '\n') || (cursorPos == 0)) {
- XmTextReplace(text, cursorPos, cursorPos, "\n");
- MoveTo(cursorPos+1);
- return;
- }
-
- oldPos = (long)cursorPos;
- theLine = GetPrevLine(file_string, &oldPos, &textPos, &spacetab[0]);
-
- /* indent new line to position of previous line - smart indenting */
- XmTextReplace(text, cursorPos, cursorPos, spacetab);
- cursorPos += strlen (spacetab);
- if (indent_style == SMART) {
- MoveTo(cursorPos);
- return;
- }
-
- /* C syntax sensitive indenting. */
- /* if theLine is not empty, check whether to indent or outdent */
- if (i = strlen(theLine)) {
- if (theLine[i-1] != ';') {
- inFlag = False;
- switch (theLine[0]) {
- case 'c':
- if (!strncmp (theLine, "case", 4))
- inFlag = True;
- break;
- case 'd':
- if (!strncmp (theLine, "do", 2))
- inFlag = True;
- break;
- case 'e':
- if (!strncmp (theLine, "else", 4))
- inFlag = True;
- break;
- case 'f':
- if (!strncmp (theLine, "for", 3))
- inFlag = True;
- break;
- case 'i':
- if (!strncmp (theLine, "if", 2))
- inFlag = True;
- break;
- case 's':
- if (!strncmp (theLine, "struct", 6))
- inFlag = True;
- else if (!strncmp (theLine, "static", 6))
- inFlag = True;
- else if (!strncmp (theLine, "switch", 6))
- if (indent_case || open_brace != 2)
- inFlag = True;
- break;
- case 't':
- if (!strncmp (theLine, "typedef", 7))
- inFlag = True;
- break;
- case 'w':
- if (!strncmp (theLine, "while", 5))
- inFlag = True;
- break;
- case '{':
- if (open_brace != 1 && theLine[1] == '\0') {
- if (oldPos>0) {
- theLine = GetPrevLine(file_string, &oldPos, &textPos, &garbage[0]);
- if (indent_case || strncmp(theLine, "switch", 6))
- inFlag = True;
- }
- }
- break;
- case '}':
- if (close_brace == 1)
- Outdent(spacetab, cursorPos, True);
- break;
- }
- if (inFlag)
- Indent (spacetab, cursorPos, True);
- }
- /* Else the previous line ends in a ';'. We need to check the line
- ** before it to decide whether to outdent.
- */
- else {
- /* outdent after a break when in a switch */
- if (!strncmp (theLine, "break", 5)) {
- if (InSwitch(file_string, oldPos))
- Outdent (spacetab, cursorPos, True);
- }
- else if (oldPos>0) {
- theLine = GetPrevLine(file_string, &oldPos, &textPos, &garbage[0]);
- if (i = strlen(theLine))
- switch (theLine[i-1]) {
- case ';':
- case ':':
- case '{':
- case '}':
- break;
- default:
- Outdent (spacetab, cursorPos, True);
- break;
- }
- }
- }
- }
- XtFree (file_string);
- }
-
- /*--------------------------------------------------------------
- ** LeftBrace
- ** Outdent when a left brace is typed when using
- ** syntax sensitive indenting and open_brace==0.
- */
- void LeftBrace(w,event)
- Widget w;
- XKeyEvent *event;
- {
- XmTextPosition cursorPos; /* text cursor position */
- XmTextPosition thePos;
- long textPos;
- Arg al[10];
- char *file_string;
- char spacetab[100];
- char *theLine;
- char theChar;
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- /* get cursor position */
- XtSetArg(al[0], XmNcursorPosition, &cursorPos);
- XtGetValues(text, al, 1);
- XmTextReplace(text, cursorPos, cursorPos, "{");
- if ((indent_style==SYNTAX) && (open_brace == 0)) {
- /* we need to make sure this is the first character on the line to
- prevent outdenting { typed in comments */
- thePos = cursorPos;
- while (thePos > 0) {
- thePos--;
- if ((theChar = file_string[thePos]) == '\n') {
- Outdent (file_string, cursorPos, False);
- break;
- }
- else if (theChar != ' ' && theChar != '\t')
- break;
- }
- }
- XtFree (file_string);
- }
-
- /*--------------------------------------------------------------
- ** RightBrace
- ** Outdent when a right brace is typed when using
- ** syntax sensitive indenting and close_brace==0.
- ** It's a little more complex if the right brace follows
- ** a break.
- */
- void RightBrace(w,event)
- Widget w;
- XKeyEvent *event;
- {
- XmTextPosition cursorPos; /* text cursor position */
- XmTextPosition thePos;
- long textPos;
- Arg al[10];
- char *file_string;
- char spacetab[100];
- char *theLine;
- char theChar;
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- /* get cursor position */
- XtSetArg(al[0], XmNcursorPosition, &cursorPos);
- XtGetValues(text, al, 1);
- XmTextReplace(text, cursorPos, cursorPos, "}");
- if ((close_brace==0) && (indent_style==SYNTAX)) {
- thePos = cursorPos;
- while (thePos > 0) {
- thePos--;
- if ((theChar = file_string[thePos]) == '\n') {
- thePos = cursorPos;
- theLine = GetPrevLine(file_string, &thePos, &textPos, &spacetab[0]);
- if (strncmp(theLine, "break", 5)) {
- XtFree (file_string);
- file_string = (char *)XmTextGetString(text);
- Outdent (file_string, cursorPos, False);
- }
- else {
- if (indent_case || !InSwitch(file_string, thePos)) {
- XtFree (file_string);
- file_string = (char *)XmTextGetString(text);
- Outdent (file_string, cursorPos, False);
- }
- }
- break;
- }
- else if (theChar != ' ' && theChar != '\t')
- break;
- }
- }
- XtFree (file_string);
- }
-
- /*-------------------------------------------------------------
- ** Goto Line
- */
- void GotoString(goto_string)
- char *goto_string;
- {
- char *file_string;
- XmTextPosition cursorPos;
- Arg al[1];
- int line_number;
- int i;
- long j;
- long string_length;
-
- /* get the text string */
- file_string = (char *)XmTextGetString(text);
- j=0;
- string_length = strlen (file_string);
- sscanf (goto_string, "%d", &line_number);
-
- for (i=0; i<(line_number-1); i++) {
- while (file_string[j++] != '\n') {
- if (j >= string_length) {
- fprintf (stderr, "\7"); /* beep if at end of file */
- break;
- }
- }
- if (j >= string_length) break;
- }
-
- if (j < string_length) {
- MoveTo((XmTextPosition)j);
- }
- XtFree (file_string);
- }
-
- /*-------------------------------------------------------------
- ** MoveTo
- ** We needed this function because Motif1.1 seems to
- ** have real problems with:
- ** XtSetArg (al[0], XmNcursorPosition, position);
- ** XtSetValues (text, al, 1);
- ** The function:
- ** XmTextSetCursorPosition(text, position);
- ** works fine, but is unavailable in Motif1.0
- */
- void MoveTo(position)
- XmTextPosition position;
- {
- Arg al[1];
-
- #ifdef Motif1.0
- XtSetArg (al[0], XmNcursorPosition, position);
- XtSetValues (text, al, 1);
- #else
- XmTextSetCursorPosition(text, position);
- #endif
- }
-
-