]> git.lyx.org Git - lyx.git/blob - src/BufferView2.C
Added a preliminary NOT working insettabular. Lot's of fixes for the text
[lyx.git] / src / BufferView2.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #include <fstream>
15
16 #include "BufferView.h"
17 #include "buffer.h"
18 #include "lyxcursor.h"
19 #include "lyxtext.h"
20 #include "insets/inseterror.h"
21 #include "insets/insetinfo.h"
22 #include "insets/insetspecialchar.h"
23 #include "LyXView.h"
24 #include "minibuffer.h"
25 #include "bufferlist.h"
26 #include "support/FileInfo.h"
27 #include "lyxscreen.h"
28 #include "support/filetools.h"
29 #include "lyx_gui_misc.h"
30 #include "LaTeX.h"
31 #include "BufferView_pimpl.h"
32
33 extern BufferList bufferlist;
34
35 using std::pair;
36 using std::endl;
37 using std::ifstream;
38
39 // Inserts a file into current document
40 bool BufferView::insertLyXFile(string const & filen)
41         //
42         // Copyright CHT Software Service GmbH
43         // Uwe C. Schroeder
44         //
45         // Insert a Lyxformat - file into current buffer
46         //
47         // Moved from lyx_cb.C (Lgb)
48 {
49         if (filen.empty()) return false;
50
51         string fname = MakeAbsPath(filen);
52
53         // check if file exist
54         FileInfo fi(fname);
55
56         if (!fi.readable()) {
57                 WriteAlert(_("Error!"),
58                            _("Specified file is unreadable: "),
59                            MakeDisplayPath(fname, 50));
60                 return false;
61         }
62         
63         beforeChange();
64
65         ifstream ifs(fname.c_str());
66         if (!ifs) {
67                 WriteAlert(_("Error!"),
68                            _("Cannot open specified file: "),
69                            MakeDisplayPath(fname, 50));
70                 return false;
71         }
72         LyXLex lex(0, 0);
73         lex.setStream(ifs);
74         char c; ifs.get(c);
75         ifs.putback(c);
76
77         bool res = true;
78
79         if (c == '#') {
80                 lyxerr.debug() << "Will insert file with header" << endl;
81                 res = buffer()->readFile(lex, text->cursor.par);
82         } else {
83                 lyxerr.debug() << "Will insert file without header" << endl;
84                 res = buffer()->readLyXformat2(lex, text->cursor.par);
85         }
86
87         resize();
88         return res;
89 }
90
91 bool BufferView::removeAutoInsets()
92 {
93         LyXParagraph * par = buffer()->paragraph;
94
95         LyXCursor cursor = text->cursor;
96         LyXCursor tmpcursor = cursor;
97         cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
98         cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
99
100         bool a = false;
101         while (par) {
102                 if (par->AutoDeleteInsets()){
103                         a = true;
104                         if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
105                                 // this is possible now, since SetCursor takes
106                                 // care about footnotes
107                                 text->SetCursorIntern(par, 0);
108                                 text->RedoParagraphs(text->cursor,
109                                                      text->cursor.par->Next());
110                                 text->FullRebreak();
111                         }
112                 }
113                 par = par->next;
114         }
115         // avoid forbidden cursor positions caused by error removing
116         if (cursor.pos > cursor.par->Last())
117                 cursor.pos = cursor.par->Last();
118         text->SetCursorIntern(cursor.par, cursor.pos);
119
120         return a;
121 }
122
123
124 void BufferView::insertErrors(TeXErrors & terr)
125 {
126         // Save the cursor position
127         LyXCursor cursor = text->cursor;
128
129         // This is drastic, but it's the only fix, I could find. (Asger)
130         allFloats(1, 0);
131         allFloats(1, 1);
132
133         for (TeXErrors::Errors::const_iterator cit = terr.begin();
134              cit != terr.end();
135              ++cit) {
136                 string desctext((*cit).error_desc);
137                 string errortext((*cit).error_text);
138                 string msgtxt = desctext + '\n' + errortext;
139                 int errorrow = (*cit).error_in_line;
140
141                 // Insert error string for row number
142                 int tmpid = -1; 
143                 int tmppos = -1;
144
145                 buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos);
146
147                 LyXParagraph * texrowpar = 0;
148
149                 if (tmpid == -1) {
150                         texrowpar = text->FirstParagraph();
151                         tmppos = 0;
152                 } else {
153                         texrowpar = text->GetParFromID(tmpid);
154                 }
155
156                 if (texrowpar == 0)
157                         continue;
158
159                 InsetError * new_inset = new InsetError(msgtxt);
160                 text->SetCursorIntern(texrowpar, tmppos);
161                 text->InsertInset(new_inset);
162                 text->FullRebreak();
163         }
164         // Restore the cursor position
165         text->SetCursorIntern(cursor.par, cursor.pos);
166 }
167
168
169 void BufferView::setCursorFromRow(int row)
170 {
171         int tmpid = -1; 
172         int tmppos = -1;
173
174         buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
175
176         LyXParagraph * texrowpar;
177
178         if (tmpid == -1) {
179                 texrowpar = text->FirstParagraph();
180                 tmppos = 0;
181         } else {
182                 texrowpar = text->GetParFromID(tmpid);
183         }
184         text->SetCursor(texrowpar, tmppos);
185 }
186
187 void BufferView::insertInset(Inset * inset, string const & lout,
188                          bool no_table)
189 {
190         // check for table/list in tables
191         if (no_table && text->cursor.par->table){
192                 WriteAlert(_("Impossible Operation!"),
193                            _("Cannot insert table/list in table."),
194                            _("Sorry."));
195                 return;
196         }
197         // not quite sure if we want this...
198         text->SetCursorParUndo();
199         text->FreezeUndo();
200         
201         beforeChange();
202         if (!lout.empty()) {
203                 update(-2);
204                 text->BreakParagraph();
205                 update(-1);
206                 
207                 if (text->cursor.par->Last()) {
208                         text->CursorLeft();
209                         
210                         text->BreakParagraph();
211                         update(-1);
212                 }
213
214                 pair<bool, LyXTextClass::size_type> lres =
215                         textclasslist.NumberOfLayout(buffer()->params
216                                                      .textclass, lout);
217                 LyXTextClass::size_type lay;
218                 if (lres.first != false) {
219                         // layout found
220                         lay = lres.second;
221                 } else {
222                         // layout not fount using default "Standard" (0)
223                         lay = 0;
224                 }
225                  
226                 text->SetLayout(lay);
227                 
228                 text->SetParagraph(0, 0,
229                                    0, 0,
230                                    VSpace(VSpace::NONE), VSpace(VSpace::NONE),
231                                    LYX_ALIGN_LAYOUT, 
232                                    string(),
233                                    0);
234                 update(-1);
235                 
236                 text->current_font.setLatex(LyXFont::OFF);
237         }
238         
239         text->InsertInset(inset);
240 #if 1
241         // if we enter a text-inset the cursor should be to the left side
242         // of it! This couldn't happen before as Undo was not handled inside
243         // inset now after the Undo LyX tries to call inset->Edit(...) again
244         // and cannot do this as the cursor is behind the inset and GetInset
245         // does not return the inset!
246         if (inset->IsTextInset()) {
247                 if (text->cursor.par->isRightToLeftPar())
248                         text->CursorRight();
249                 else
250                         text->CursorLeft();
251         }
252 #endif
253         update(-1);
254
255         text->UnFreezeUndo();   
256 }
257
258
259 // Open and lock an updatable inset
260 void BufferView::open_new_inset(UpdatableInset * new_inset)
261 {
262         beforeChange();
263         text->FinishUndo();
264         insertInset(new_inset);
265         text->CursorLeft();
266         update(1);
267         new_inset->Edit(this, 0, 0, 0);
268 }
269
270 /* This is also a buffer property (ale) */
271 // Not so sure about that. a goto Label function can not be buffer local, just
272 // think how this will work in a multiwindo/buffer environment, all the
273 // cursors in all the views showing this buffer will move. (Lgb)
274 // OK, then no cursor action should be allowed in buffer. (ale)
275 bool BufferView::gotoLabel(string const & label)
276
277 {
278         LyXParagraph * par = buffer()->paragraph;
279         LyXParagraph::size_type pos;
280         Inset * inset;
281         while (par) {
282                 pos = -1;
283                 while ((inset = par->ReturnNextInsetPointer(pos))){     
284                         for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
285                                 if (label == inset->getLabel(i)) {
286                                         beforeChange();
287                                         text->SetCursor(par, pos);
288                                         text->sel_cursor = text->cursor;
289                                         update(0);
290                                         return true;
291                                 }
292                         }
293                         ++pos;
294                 } 
295                 par = par->next;
296         }
297         return false;
298 }
299
300 void BufferView::allFloats(char flag, char figmar)
301 {
302         if (!available()) return;
303
304         LyXCursor cursor = text->cursor;
305
306         if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
307             && ((figmar 
308                  && cursor.par->footnotekind != LyXParagraph::FOOTNOTE 
309                  && cursor.par->footnotekind != LyXParagraph::MARGIN)
310                 || (!figmar
311                     && cursor.par->footnotekind != LyXParagraph::FIG 
312                     && cursor.par->footnotekind != LyXParagraph::TAB
313                     && cursor.par->footnotekind != LyXParagraph::WIDE_FIG 
314                     && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
315                     && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
316                 toggleFloat();
317         else
318                 beforeChange();
319
320         LyXCursor tmpcursor = cursor;
321         cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
322         cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
323
324         LyXParagraph *par = buffer()->paragraph;
325         while (par) {
326                 if (flag) {
327                         if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
328                             && ((figmar 
329                                  && par->footnotekind != LyXParagraph::FOOTNOTE 
330                                  && par->footnotekind !=  LyXParagraph::MARGIN)
331                                 || (!figmar
332                                     && par->footnotekind != LyXParagraph::FIG 
333                                     && par->footnotekind != LyXParagraph::TAB
334                                     && par->footnotekind != LyXParagraph::WIDE_FIG 
335                                     && par->footnotekind != LyXParagraph::WIDE_TAB
336                                     && par->footnotekind != LyXParagraph::ALGORITHM
337                                         )
338                                     )
339                                 ) {
340                                 if (par->previous
341                                     && par->previous->footnoteflag != 
342                                     LyXParagraph::CLOSED_FOOTNOTE){ /* should be */ 
343                                         text->SetCursorIntern(par->previous,
344                                                               0);
345                                         text->OpenFootnote();
346                                 }
347                         }
348                 } else {
349                         if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
350                             && (
351                                     (figmar 
352                                      &&
353                                      par->footnotekind != LyXParagraph::FOOTNOTE 
354                                      &&
355                                      par->footnotekind !=  LyXParagraph::MARGIN
356                                             )
357                                     ||
358                                     (!figmar
359                                      &&
360                                      par->footnotekind != LyXParagraph::FIG 
361                                      &&
362                                      par->footnotekind != LyXParagraph::TAB
363                                      &&
364                                      par->footnotekind != LyXParagraph::WIDE_FIG 
365                                      &&
366                                      par->footnotekind != LyXParagraph::WIDE_TAB
367                                      &&
368                                      par->footnotekind != LyXParagraph::ALGORITHM
369                                             )
370                                     )
371                                 ) {
372                                 text->SetCursorIntern(par, 0);
373                                 text->CloseFootnote();
374                         }
375                 }
376                 par = par->next;
377         }
378
379         text->SetCursorIntern(cursor.par, cursor.pos);
380         redraw();
381         fitCursor();
382         updateScrollbar();
383 }
384
385
386 void BufferView::insertNote()
387 {
388         InsetInfo * new_inset = new InsetInfo();
389         insertInset(new_inset);
390         new_inset->Edit(this, 0, 0, 0);
391 }
392
393
394 void BufferView::openStuff()
395 {
396         if (available()) {
397                 owner()->getMiniBuffer()->Set(_("Open/Close..."));
398                 hideCursor();
399                 beforeChange();
400                 update(-2);
401                 text->OpenStuff();
402                 update(0);
403                 setState();
404         }
405 }
406
407
408 void BufferView::toggleFloat()
409 {
410         if (available()) {
411                 owner()->getMiniBuffer()->Set(_("Open/Close..."));
412                 hideCursor();
413                 beforeChange();
414                 update(-2);
415                 text->ToggleFootnote();
416                 update(0);
417                 setState();
418         }
419 }
420
421 void BufferView::menuUndo()
422 {
423         if (available()) {
424                 owner()->getMiniBuffer()->Set(_("Undo"));
425                 hideCursor();
426                 beforeChange();
427                 update(-2);
428                 if (!text->TextUndo())
429                         owner()->getMiniBuffer()->Set(_("No further undo information"));
430                 else
431                         update(-1);
432                 setState();
433         }
434 }
435
436
437 void BufferView::menuRedo()
438 {
439         if (the_locking_inset) {
440                 owner()->getMiniBuffer()->Set(_("Redo not yet supported in math mode"));
441                 return;
442         }    
443    
444         if (available()) {
445                 owner()->getMiniBuffer()->Set(_("Redo"));
446                 hideCursor();
447                 beforeChange();
448                 update(-2);
449                 if (!text->TextRedo())
450                         owner()->getMiniBuffer()->Set(_("No further redo information"));
451                 else
452                         update(-1);
453                 setState();
454         }
455 }
456
457
458 void BufferView::hyphenationPoint()
459 {
460         if (available()) {
461                 hideCursor();
462                 update(-2);
463                 InsetSpecialChar * new_inset = 
464                         new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
465                 insertInset(new_inset);
466         }
467 }
468
469
470 void BufferView::ldots()
471 {
472         if (available())  {
473                 hideCursor();
474                 update(-2);
475                 InsetSpecialChar * new_inset = 
476                         new InsetSpecialChar(InsetSpecialChar::LDOTS);
477                 insertInset(new_inset);
478         }
479 }
480
481
482 void BufferView::endOfSentenceDot()
483 {
484         if (available()) {
485                 hideCursor();
486                 update(-2);
487                 InsetSpecialChar * new_inset = 
488                         new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
489                 insertInset(new_inset);
490         }
491 }
492
493
494 void BufferView::menuSeparator()
495 {
496         if (available()) {
497                 hideCursor();
498                 update(-2);
499                 InsetSpecialChar * new_inset = 
500                         new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
501                 insertInset(new_inset);
502         }
503 }
504
505
506 void BufferView::newline()
507 {
508         if (available()) {
509                 hideCursor();
510                 update(-2);
511 #if 0
512                 InsetSpecialChar * new_inset =
513                         new InsetSpecialChar(InsetSpecialChar::NEWLINE);
514                 insertInset(new_inset);
515 #else
516                 text->InsertChar(LyXParagraph::META_NEWLINE);
517                 update(-1);
518 #endif
519         }
520 }
521
522
523 void BufferView::protectedBlank()
524 {
525         if (available()) {
526                 hideCursor();
527                 update(-2);
528 #if 1
529                 InsetSpecialChar * new_inset =
530                         new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
531                 insertInset(new_inset);
532 #else
533                 text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
534                 update(-1);
535 #endif
536         }
537 }
538
539
540 void BufferView::hfill()
541 {
542         if (available()) {
543                 hideCursor();
544                 update(-2);
545                 text->InsertChar(LyXParagraph::META_HFILL);
546                 update(-1);
547         }
548 }
549
550 void BufferView::copyEnvironment()
551 {
552         if (available()) {
553                 text->copyEnvironmentType();
554                 // clear the selection, even if mark_set
555                 toggleSelection();
556                 text->ClearSelection();
557                 update(-2);
558                 owner()->getMiniBuffer()->Set(_("Paragraph environment type copied"));
559         }
560 }
561
562
563 void BufferView::pasteEnvironment()
564 {
565         if (available()) {
566                 text->pasteEnvironmentType();
567                 owner()->getMiniBuffer()->Set(_("Paragraph environment type set"));
568                 update(1);
569         }
570 }
571
572
573 void BufferView::copy()
574 {
575         if (available()) {
576                 text->CopySelection();
577                 // clear the selection, even if mark_set
578                 toggleSelection();
579                 text->ClearSelection();
580                 update(-2);
581                 owner()->getMiniBuffer()->Set(_("Copy"));
582         }
583 }
584
585 void BufferView::cut()
586 {
587         if (available()) {
588                 hideCursor();
589                 update(-2);
590                 text->CutSelection();
591                 update(1);
592                 owner()->getMiniBuffer()->Set(_("Cut"));
593         }
594 }
595
596
597 void BufferView::paste()
598 {
599         if (!available()) return;
600         
601         owner()->getMiniBuffer()->Set(_("Paste"));
602         hideCursor();
603         // clear the selection
604         toggleSelection();
605         text->ClearSelection();
606         update(-2);
607         
608         // paste
609         text->PasteSelection();
610         update(1);
611         
612         // clear the selection 
613         toggleSelection();
614         text->ClearSelection();
615         update(-2);
616 }
617
618
619 void BufferView::gotoNote()
620 {
621         if (!available()) return;
622    
623         hideCursor();
624         beforeChange();
625         update(-2);
626         LyXCursor tmp;
627    
628         if (!text->GotoNextNote()) {
629                 if (text->cursor.pos 
630                     || text->cursor.par != text->FirstParagraph()) {
631                                 tmp = text->cursor;
632                                 text->cursor.par = text->FirstParagraph();
633                                 text->cursor.pos = 0;
634                                 if (!text->GotoNextNote()) {
635                                         text->cursor = tmp;
636                                         owner()->getMiniBuffer()->Set(_("No more notes"));
637                                         LyXBell();
638                                 }
639                         } else {
640                                 owner()->getMiniBuffer()->Set(_("No more notes"));
641                                 LyXBell();
642                         }
643         }
644         update(0);
645         text->sel_cursor = text->cursor;
646 }
647
648
649 void BufferView::insertCorrectQuote()
650 {
651         char c;
652
653         if (text->cursor.pos)
654                 c = text->cursor.par->GetChar(text->cursor.pos - 1);
655         else 
656                 c = ' ';
657
658         insertInset(new InsetQuotes(c, buffer()->params));
659 }
660
661
662 /* these functions are for the spellchecker */ 
663 char * BufferView::nextWord(float & value)
664 {
665         if (!available()) {
666                 value = 1;
667                 return 0;
668         }
669
670         char * string = text->SelectNextWord(value);
671
672         return string;
673 }
674
675   
676 void BufferView::selectLastWord()
677 {
678         if (!available()) return;
679    
680         hideCursor();
681         beforeChange();
682         text->SelectSelectedWord();
683         toggleSelection(false);
684         update(0);
685 }
686
687
688 void BufferView::endOfSpellCheck()
689 {
690         if (!available()) return;
691    
692         hideCursor();
693         beforeChange();
694         text->SelectSelectedWord();
695         text->ClearSelection();
696         update(0);
697 }
698
699
700 void BufferView::replaceWord(string const & replacestring)
701 {
702         if (!available()) return;
703
704         hideCursor();
705         update(-2);
706    
707         /* clear the selection (if there is any) */ 
708         toggleSelection(false);
709         update(-2);
710    
711         /* clear the selection (if there is any) */ 
712         toggleSelection(false);
713         text->ReplaceSelectionWithString(replacestring.c_str());
714    
715         text->SetSelectionOverString(replacestring.c_str());
716
717         // Go back so that replacement string is also spellchecked
718         for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
719                 text->CursorLeftIntern();
720         }
721         update(1);
722 }
723 // End of spellchecker stuff
724
725
726 bool BufferView::lockInset(UpdatableInset * inset)
727 {
728         if (!the_locking_inset && inset) {
729                 the_locking_inset = inset;
730                 return true;
731         } else if (inset) {
732             return the_locking_inset->LockInsetInInset(this, inset);
733         }
734         return false;
735 }
736
737
738 void BufferView::showLockedInsetCursor(long x, long y, int asc, int desc)
739 {
740         if (the_locking_inset && available()) {
741                 LyXCursor cursor = text->cursor;
742                 if ((cursor.pos - 1 >= 0) &&
743                     (cursor.par->GetChar(cursor.pos-1) ==
744                      LyXParagraph::META_INSET) &&
745                     (cursor.par->GetInset(cursor.pos - 1) ==
746                      the_locking_inset->GetLockingInset()))
747                         text->SetCursor(cursor, cursor.par, cursor.pos-1);
748                 y += cursor.y + the_locking_inset->InsetInInsetY();
749                 pimpl_->screen->ShowManualCursor(x, y, asc, desc,
750                                          LyXScreen::BAR_SHAPE);
751         }
752 }
753
754
755 void BufferView::hideLockedInsetCursor()
756 {
757         if (the_locking_inset && available()) {
758                 pimpl_->screen->HideCursor();
759         }
760 }
761
762
763 void BufferView::fitLockedInsetCursor(long x, long y, int asc, int desc)
764 {
765         if (the_locking_inset && available()){
766                 y += text->cursor.y + the_locking_inset->InsetInInsetY();
767                 if (pimpl_->screen->FitManualCursor(x, y, asc, desc))
768                         updateScrollbar();
769         }
770 }
771
772
773 int BufferView::unlockInset(UpdatableInset * inset)
774 {
775         if (inset && the_locking_inset == inset) {
776                 inset->InsetUnlock(this);
777                 the_locking_inset = 0;
778                 text->FinishUndo();
779                 return 0;
780         } else if (inset && the_locking_inset &&
781                    the_locking_inset->UnlockInsetInInset(this, inset)) {
782                 text->FinishUndo();
783                 return 0;
784         }
785         return bufferlist.unlockInset(inset);
786 }
787
788
789 void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
790 {
791         if (!the_locking_inset)
792                 return; // shouldn't happen
793         if (kind == Undo::EDIT) // in this case insets would not be stored!
794                 kind = Undo::FINISH;
795         text->SetUndo(kind,
796                       text->cursor.par->
797                       ParFromPos(text->cursor.pos)->previous, 
798                       text->cursor.par->
799                       ParFromPos(text->cursor.pos)->next);
800 }
801
802
803 void BufferView::updateInset(Inset * inset, bool mark_dirty)
804 {
805         if (!inset)
806                 return;
807
808         // first check for locking insets
809         if (the_locking_inset) {
810                 if (the_locking_inset == inset) {
811                         if (text->UpdateInset(inset)){
812                                 update();
813                                 if (mark_dirty){
814                                         if (buffer()->isLyxClean())
815                                                 owner()->getMiniBuffer()->
816                                                         setTimer(4);
817                                         buffer()->markDirty();
818                                 }
819                                 updateScrollbar();
820                                 return;
821                         }
822                 } else if (the_locking_inset->UpdateInsetInInset(this,inset)) {
823                         if (text->UpdateInset(the_locking_inset)) {
824                                 update();
825                                 if (mark_dirty){
826                                         if (buffer()->isLyxClean())
827                                                 owner()->getMiniBuffer()->
828                                                         setTimer(4);
829                                         buffer()->markDirty();
830                                 }
831                                 updateScrollbar();
832                                 return;
833                         }
834                 }
835         }
836   
837         // then check the current buffer
838         if (available()) {
839                 hideCursor();
840                 update(-3);
841                 if (text->UpdateInset(inset)){
842                         if (mark_dirty)
843                                 update(1);
844                         else 
845                                 update(3);
846                         return;
847                 }
848         }
849 }