wpverbs.c

Go to the documentation of this file.
00001 
00002 /*  $Id: wpverbs.c 1206 2006-04-05 23:21:19Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "PAIGE.H"
00032 
00033 #include "frontierconfig.h"
00034 #include "cursor.h"
00035 #include "file.h"
00036 #include "kb.h"
00037 #include "memory.h"
00038 #include "mouse.h"
00039 #include "ops.h"
00040 #include "quickdraw.h"
00041 #include "resources.h"
00042 #include "strings.h"
00043 #include "search.h"
00044 #include "zoom.h"
00045 #include "shell.h"
00046 #include "shellhooks.h"
00047 #include "shellprint.h"
00048 #include "shellundo.h"
00049 #include "lang.h"
00050 #include "langexternal.h"
00051 #include "tablestructure.h"
00052 #include "cancoon.h"
00053 #include "wpengine.h"
00054 #include "wpinternal.h"
00055 #include "wpverbs.h"
00056 #include "kernelverbdefs.h"
00057 
00058 
00059 
00060 #define wperrorlist 264 
00061 #define nowperror 1
00062 #define namenotwperror 2
00063 
00064 #define wpstringlist 164
00065 #define wptypestring 1
00066 #define wpsizestring 2
00067 
00068 
00069 typedef enum tywptoken { /*verbs that are processed by wp.c*/
00070     
00071     intextmodefunc,
00072     
00073     settextmodefunc,
00074     
00075     gettextfunc,
00076     
00077     settextfunc,
00078     
00079     getseltextfunc,
00080     
00081     getdisplayfunc,
00082     
00083     setdisplayfunc,
00084     
00085     getrulerfunc,
00086     
00087     setrulerfunc,
00088     
00089     getindentfunc,
00090     
00091     setindentfunc,
00092     
00093     getleftmarginfunc,
00094     
00095     setleftmarginfunc,
00096     
00097     getrightmarginfunc,
00098     
00099     setrightmarginfunc,
00100     
00101     setspacingfunc,
00102     
00103     setjustificationfunc,
00104     
00105     settabfunc,
00106     
00107     cleartabsfunc,
00108     
00109     getselectfunc,
00110     
00111     setselectfunc,
00112     
00113     insertfunc,
00114     
00115     #ifdef flvariables
00116     
00117     newvariablefunc,
00118     
00119     deletevariablefunc,
00120     
00121     getnthvariablefunc,
00122     
00123     setvariablevaluefunc,
00124     
00125     getvariablevaluefunc,
00126     
00127     insertvariablefunc,
00128     
00129     getevalfunc,
00130     
00131     setevalfunc,
00132     
00133     hilitevariablesfunc,
00134     
00135     #endif
00136     
00137     rulerlengthfunc,
00138     
00139     gofunc,
00140     
00141     selectwordfunc,
00142     
00143     selectlinefunc,
00144     
00145     selectparafunc,
00146     
00147     ctwpverbs
00148     
00149     } tywptoken;
00150 
00151 
00152 
00153 #if langexternalfind_optimization
00154 
00155     typedef tyexternalvariable tywpvariable, *ptrwpvariable, **hdlwpvariable;
00156 
00157 #else
00158     
00159 typedef struct tywpvariable {
00160     
00161     unsigned short id; /*tyexternalid: managed by langexternal.c*/
00162     
00163     unsigned short flinmemory: 1; /*if true, variabledata is an hdlwprecord, else a dbaddress*/
00164     
00165     unsigned short flmayaffectdisplay: 1; /*not in memory, but being displayed in a table window*/
00166     
00167     unsigned short flpacked: 1; /*the wp doc isn't being edited, so we store it packed*/
00168     
00169     long variabledata; /*either a hdlwprecord or a dbaddress*/
00170     
00171     hdldatabaserecord hdatabase; // 5.0a18 dmb
00172 
00173     dbaddress oldaddress; /*last place this wp doc was stored in db*/
00174     } tywpvariable, *ptrwpvariable, **hdlwpvariable;
00175 
00176 #endif
00177 
00178 static short errornum = 0; /*error number exclusively for wp routines*/
00179 
00180 
00181 #if !flruntime
00182 
00183 static void wpverbsetscrollbarsroutine (void) {
00184 
00185     register ptrwindowinfo pw = *wpwindowinfo;
00186     register ptrwprecord pwp = *wpdata;
00187     
00188     (*pw).vertscrollinfo = (*pwp).vertscrollinfo; /*copy from wp record to window record*/
00189     
00190     (*pw).horizscrollinfo = (*pwp).horizscrollinfo;
00191     
00192     (*pw).fldirtyscrollbars = true; /*force a refresh of scrollbars by the shell*/
00193     } /*wpverbsetscrollbarsroutine*/
00194 
00195 
00196 static void wplinkwindowinfo (void) {
00197     
00198     /*
00199     link wpdata to wpwindowinfo, and make sure that the content rect of 
00200     the WS handle is up to date.
00201     
00202     5.0a2 dmb: use paperrect, not contentrect, as bounds
00203     */
00204     
00205     register hdlwindowinfo hw = wpwindowinfo;
00206     Rect rbounds;
00207     
00208     wpsetupwindow ();
00209     
00210     rbounds = (**hw).contentrect;
00211     
00212     insetrect (&rbounds, 3, 3);
00213     
00214     rbounds.right = rbounds.left + shellprintinfo.paperrect.right - shellprintinfo.paperrect.left;
00215     
00216     rbounds.bottom = rbounds.top + shellprintinfo.paperrect.bottom - shellprintinfo.paperrect.top;
00217     
00218     wpsetbufferrect ((**hw).contentrect, rbounds);
00219     
00220     (**wpdata).setscrollbarsroutine = &wpverbsetscrollbarsroutine;
00221     } /*wplinkwindowinfo*/
00222 
00223 
00224 boolean wpverbgettypestring (hdlexternalvariable hvariable, bigstring bs) {
00225 #pragma unused (hvariable)
00226 
00227     getstringlist (wpstringlist, wptypestring, bs);
00228     
00229     return (true);
00230     } /*wpverbgettypestring*/
00231 
00232 
00233 #endif // !flruntime
00234 
00235 static boolean newwpvariable (boolean flinmemory, boolean flpacked, long variabledata, hdlwpvariable *h) {
00236 
00237     if (!langnewexternalvariable (flinmemory, variabledata, (hdlexternalvariable *) h))
00238         return (false);
00239     
00240     (***h).flpacked = flpacked;
00241 
00242     return (true);
00243     } /*newwpvariable*/
00244 
00245 
00246 static boolean wpdisposevariable (hdlexternalvariable hvariable, boolean fldisk) {
00247 #pragma unused (fldisk)
00248     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00249     register long vdata = (**hv).variabledata;
00250     
00251     if ((**hv).flpacked) 
00252         disposehandle ((Handle) vdata);
00253     else
00254         wpdisposerecord ((hdlwprecord) vdata);
00255         
00256     return (true);
00257     } /*wpdisposevariable*/
00258 
00259 
00260 boolean wpverbdispose (hdlexternalvariable hvariable, boolean fldisk) {
00261     
00262     return (langexternaldisposevariable (hvariable, fldisk, &wpdisposevariable));
00263     } /*wpverbdispose*/
00264 
00265 
00266 #if !flruntime
00267 
00268 static void wpverbcheckwindowrect (register hdlwprecord hwp) {
00269     
00270     hdlwindowinfo hinfo;
00271     
00272     if ((**hwp).flwindowopen) { /*make windowrect reflect current window size & position*/
00273         
00274         if (shellfinddatawindow ((Handle) hwp, &hinfo)) {
00275             
00276             Rect r;
00277             
00278             shellgetglobalwindowrect (hinfo, &r);
00279             
00280             if (!equalrects (r, (**hwp).windowrect)) {
00281             
00282                 (**hwp).windowrect = r;
00283                 
00284                 (**hwp).fldirty = true;
00285                 }
00286             }
00287         }
00288     } /*wpverbcheckwindowrect*/
00289 
00290 #else
00291     
00292     #define wpverbcheckwindowrect(hwp)  ((void *) 0)
00293 
00294 #endif
00295 
00296 #if !flruntime
00297 
00298 boolean wpverbisdirty (hdlexternalvariable hvariable) {
00299     
00300     /*
00301     8/11/92 dmb: check windowrect now to ensure consistent results
00302     */
00303     
00304     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00305     register hdlwprecord hwp;
00306     
00307     if (!(**hv).flinmemory)
00308         return (false);
00309     
00310     if ((**hv).flpacked) /*if it's packed and in memory, it must be dirty*/
00311         return (true);
00312     
00313     hwp = (hdlwprecord) (**hv).variabledata;
00314     
00315     wpverbcheckwindowrect (hwp);
00316     
00317     return ((**hwp).fldirty || (**hwp).fldirtyview);
00318     } /*wpverbisdirty*/
00319 
00320 
00321 boolean wpverbsetdirty (hdlexternalvariable hvariable, boolean fldirty) {
00322     
00323     /*
00324     4/15/92 dmb: see comments in langexternalsetdirty
00325     */
00326     
00327     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00328     register hdlwprecord hwp;
00329     
00330     if (!wpverbinmemory ((hdlexternalvariable) hv))
00331         return (false);
00332     
00333     hwp = (hdlwprecord) (**hv).variabledata;
00334     
00335     (**hwp).fldirty = (**hwp).fldirtyview = fldirty;
00336     
00337     return (true);
00338     } /*wpverbsetdirty*/
00339 
00340 #endif // !flruntime
00341 
00342 
00343 static void wpverblinkvariable (hdlwprecord hwp, hdlwpvariable hv) {
00344     
00345     (**hv).variabledata = (long) hwp; /*link the wp rec into the variable rec*/
00346     
00347     (**hwp).wprefcon = (long) hv; /*the pointing is mutual*/
00348     } /*wpverblinkvariable*/
00349 
00350 
00351 boolean wpverbnew (Handle hdata, hdlexternalvariable *hvariable) {
00352     
00353     /*
00354     9/11/91 dmb: now take hdata parameter.  note: for now, we're assuming 
00355     that only tablescrap calls us with non-nil hdata.  to allow it to be 
00356     either WS text or plain text, we actually ignore hdata and let 
00357     wppaste to the interpretation.
00358     */
00359     
00360     register hdlwpvariable hv;
00361     hdlwprecord hwp;
00362     Rect r;
00363     
00364     if (!newwpvariable (true, false, 0L, (hdlwpvariable *) hvariable))
00365         return (false);
00366     
00367     hv = (hdlwpvariable) *hvariable; /*copy into register*/
00368     
00369     setrect (&r, 0, 0, infinity, infinity); /*very large clip & bounds area*/
00370     
00371     if (!wpnewrecord (r, &hwp)) {
00372         
00373         disposehandle ((Handle) hv);
00374         
00375         return (false);
00376         }
00377     
00378     if (hdata != nil) { /*we've been given intial text*/
00379         
00380         shellpushglobals (nil); /*preserve our globals*/
00381         
00382         wppushdata (hwp);
00383         
00384         /*
00385         wpsettexthandle (hdata);
00386         */
00387         
00388         wppaste (true); /*we're assuming that only tablescrap calls us with data*/
00389         
00390         wppopdata ();
00391         
00392         shellpopglobals ();
00393         }
00394     
00395     wpverblinkvariable (hwp, hv); /*set up pointers to each other*/
00396     
00397     return (true);
00398     } /*wpverbnew*/
00399 
00400 
00401 static boolean wpverbpackrecord (hdlwprecord hwp, Handle *hpacked) {
00402     
00403     register boolean fl;
00404     register hdlwprecord hwporig = wpdata;
00405     
00406     wpdata = hwp;
00407     
00408     fl = wppack (hpacked);
00409     
00410     wpdata = hwporig;
00411     
00412     return (fl);
00413     } /*wpverbpackrecord*/
00414 
00415 
00416 boolean wpverbmemorypack (hdlexternalvariable h, Handle *hpacked) {
00417     
00418     /*
00419     a special entrypoint for the language's pack and upack verbs.
00420     */
00421     
00422     register hdlwpvariable hv = (hdlwpvariable) h;
00423     register hdlwprecord hwp;
00424     register boolean fl;
00425     Handle hpush = nil;
00426     
00427     if (!(**hv).flinmemory) {
00428     
00429         if (!langexternalrefdata ((hdlexternalvariable) hv, &hpush))
00430             return (false);
00431             
00432         goto pushandexit;
00433         }
00434         
00435     if ((**hv).flpacked) {
00436         
00437         if (!copyhandle ((Handle) (**hv).variabledata, &hpush))
00438             return (false);
00439         
00440         goto pushandexit;
00441         }
00442     
00443     /*it's in memory and not packed*/
00444     
00445     hwp = (hdlwprecord) (**hv).variabledata;
00446     
00447     wpverbcheckwindowrect (hwp);
00448     
00449     if (!wpverbpackrecord (hwp, &hpush))
00450         return (false);
00451     
00452     pushandexit:
00453     
00454     if (hpush == nil)
00455         return (false);
00456     
00457     fl = pushhandle (hpush, *hpacked);
00458     
00459     disposehandle (hpush);
00460     
00461     return (fl);
00462     } /*wpverbmemorypack*/
00463     
00464     
00465 boolean wpverbmemoryunpack (Handle hpacked, long *ixload, hdlexternalvariable *h) {
00466     
00467     /*
00468     create a new variable -- in memory, packed, with hpacked as the data handle.
00469     
00470     this is a special entrypoint for the pack and unpack verbs.
00471     */
00472     
00473     Handle hpackedwp;
00474     
00475     if (!loadhandleremains (*ixload, hpacked, &hpackedwp))
00476         return (false);
00477     
00478     return (newwpvariable (true, true, (long) hpackedwp, (hdlwpvariable *) h)); 
00479     } /*wpverbmemoryunpack*/
00480 
00481 
00482 static void wpverbondisk (hdlwpvariable hv, dbaddress adr) {
00483 
00484     (**hv).flinmemory = false;
00485     
00486     (**hv).flpacked = false;
00487     
00488     (**hv).variabledata = (long) adr;
00489     } /*wpverbondisk*/
00490 
00491 
00492 static void wpverbunload (hdlwpvariable hv) {
00493     
00494     /*
00495     5.0.2b20 dmb: corrected disposal of loaded variable
00496     */
00497     
00498     long variabledata = (**hv).variabledata;
00499     
00500     assert ((**hv).flinmemory);
00501     
00502     if ((**hv).flpacked)
00503         disposehandle ((Handle) variabledata);
00504     else
00505         wpdisposerecord ((hdlwprecord) variabledata);
00506     
00507     if ((**hv).oldaddress == nil) // 5.0d3 dmb
00508         disposehandle ((Handle) hv);
00509     else
00510         wpverbondisk (hv, (**hv).oldaddress);
00511     } /*wpverbunload*/
00512 
00513 
00514 boolean wpverbpack (hdlexternalvariable h, Handle *hpacked, boolean *flnewdbaddress) {
00515 
00516     /*
00517     6.2a15 AR: added flnewdbaddress parameter
00518     */
00519 
00520     register hdlwpvariable hv = (hdlwpvariable) h;
00521     register hdlwprecord hwp;
00522     register boolean fl;
00523     Handle hpackedwp;
00524     dbaddress adr;
00525     hdlwindowinfo hinfo;
00526     boolean fltempload = false;
00527     
00528     if (!(**hv).flinmemory) { /*simple case, wp doc is resident in the db*/
00529         
00530         if (flconvertingolddatabase) {
00531             
00532             if (!wpverbinmemory (h))
00533                 return (false);
00534             
00535             fltempload = true;
00536             }
00537         else {
00538         
00539             adr = (dbaddress) (**hv).variabledata;
00540             
00541             if (fldatabasesaveas)
00542                 if (!dbcopy (adr, &adr))
00543                     return (false);
00544             
00545             goto pushaddress;
00546             }
00547         }
00548     
00549     /*the doc is in memory, either as a WP-Engine structure or a packed handle*/
00550     
00551     adr = (**hv).oldaddress; /*place where this wp doc used to be stored*/
00552     
00553     if ((**hv).flpacked) { /*no window open, but changes were made*/
00554         
00555         hpackedwp = (Handle) (**hv).variabledata;
00556         
00557         if (!dbassignhandle (hpackedwp, &adr))
00558             return (false);
00559         
00560         if (fldatabasesaveas)
00561             goto pushaddress;
00562         
00563         wpverbondisk (hv, adr);
00564         
00565         disposehandle (hpackedwp); /*reclaim memory used by packed doc*/
00566         
00567         goto pushaddress;
00568         }
00569     
00570     /*the wpdoc is in memory and it's not packed*/
00571     
00572     hwp = (hdlwprecord) (**hv).variabledata;
00573     
00574     wpverbcheckwindowrect (hwp);
00575     
00576     if (!fldatabasesaveas && !(**hwp).fldirty && !(**hwp).fldirtyview) /*don't need to update the db version of the wpdoc*/
00577         goto pushaddress;
00578     
00579     if (!wpverbpackrecord (hwp, &hpackedwp))
00580         return (false);
00581     
00582     fl = dbassignhandle (hpackedwp, &adr);
00583     
00584     disposehandle (hpackedwp);
00585     
00586     if (!fl)
00587         return (false);
00588     
00589     if (fldatabasesaveas)
00590         goto pushaddress;
00591     
00592     if (!wpwindowopen ((hdlexternalvariable) hv, &hinfo)) { /*it's been saved, we can reclaim some memory*/
00593         
00594         wpverbondisk (hv, adr);
00595         
00596         wpdisposerecord (hwp); /*reclaim memory used by doc*/
00597         }
00598     else {
00599         
00600         assert (!fltempload);
00601         
00602         (**hwp).fldirty = false; /*we just saved off a new db version*/
00603         
00604         (**hwp).fldirtyview = false;
00605         
00606         shellsetwindowchanges (hinfo, false);
00607         }
00608     
00609     pushaddress:
00610     
00611     if (!fldatabasesaveas) {
00612     
00613         *flnewdbaddress = ((**hv).oldaddress != adr);
00614             
00615         (**hv).oldaddress = adr;
00616         }
00617     else
00618         *flnewdbaddress = true; 
00619     
00620     return (pushlongondiskhandle (adr, *hpacked));
00621     } /*wpverbpack*/
00622 
00623 
00624 boolean wpverbunpack (Handle hpacked, long *ixload, hdlexternalvariable *h) {
00625 
00626     dbaddress adr;
00627     
00628     if (!loadlongfromdiskhandle (hpacked, ixload, &adr)) 
00629         return (false);
00630 
00631     return (newwpvariable (false, false, adr, (hdlwpvariable *) h));
00632     } /*wpverbunpack*/
00633 
00634 
00635 boolean wpverbinmemory (hdlexternalvariable h) {
00636     
00637     /*
00638     6/6/91 dmb: after loading, set dirty bit if value has never been 
00639     saved to disk
00640     
00641     11/14/01 dmb: always marked as dirty when expanding from in-memory packed state
00642     
00643     5.0a18 dmb: support database linking
00644     */
00645     
00646     register hdlwpvariable hv = (hdlwpvariable) h;
00647     hdlwprecord hwp;
00648     boolean flinmemory = (**hv).flinmemory;
00649     boolean fl;
00650     dbaddress adr;
00651     Handle hpackedwp;
00652     boolean fldirty;
00653     
00654     if (flinmemory && !(**hv).flpacked) /*nothing to do, it's already unpacked & in memory*/
00655         return (true);
00656     
00657     if (flinmemory) { /*don't need to read packed wp from database*/
00658         
00659         adr = (**hv).oldaddress;
00660         
00661         hpackedwp = (Handle) (**hv).variabledata;
00662         
00663         fldirty = true; /*otherwise, wouldn't have been kept in memory*/
00664         }
00665     else {
00666         adr = (dbaddress) (**hv).variabledata;
00667         
00668         if (!langexternalrefdata ((hdlexternalvariable) hv, &hpackedwp))
00669             return (false);
00670         
00671         fldirty = false; /*clean version from disk*/
00672         }
00673 
00674     fl = wpunpack (hpackedwp, &hwp);
00675     
00676     if (fl || !flinmemory) /*on failure, don't dispose packed version if in memory*/
00677         disposehandle (hpackedwp);
00678     
00679     if (!fl)
00680         return (false);
00681     
00682     (**hv).flinmemory = true;
00683     
00684     (**hv).flpacked = false;
00685     
00686     (**hv).oldaddress = adr; /*last place this wp was stored*/
00687     
00688     (**hwp).fldirty = fldirty;
00689     
00690     wpverblinkvariable (hwp, hv); /*set up pointers to each other*/
00691     
00692     return (true);
00693     } /*wpverbinmemory*/
00694 
00695 
00696 #if !flruntime
00697 
00698 boolean wpverbgetsize (hdlexternalvariable hvariable, long *size) {
00699     
00700     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00701     
00702     if ((**hv).flpacked)
00703         wpgetpackedmaxpos ((Handle) (**hv).variabledata, size);
00704         
00705     else {
00706         
00707         if (!wpverbinmemory ((hdlexternalvariable) hv))
00708             return (false);
00709         
00710         wppushdata ((hdlwprecord) (**hv).variabledata);
00711         
00712         wpgetmaxpos (size);
00713         
00714         wppopdata ();
00715         }
00716     
00717     return (true);
00718     } /*wpverbgetsize*/
00719 
00720 
00721 boolean wpverbgetdisplaystring (hdlexternalvariable h, bigstring bs) {
00722     
00723     /*
00724     get string for table display.  variable is in memory
00725     */
00726     
00727     long ctchars;
00728     
00729     if (!wpverbgetsize (h, &ctchars))
00730         return (false);
00731     
00732     parsenumberstring (wpstringlist, wpsizestring, ctchars, bs);
00733     
00734     return (true);
00735     } /*wpverbgetdisplaystring*/
00736 
00737 
00738 boolean wpverbpacktotext (hdlexternalvariable h, Handle htext) {
00739     
00740     /*
00741     5.0.2b20 dmb: unload if just loaded
00742     */
00743     
00744     register hdlwpvariable hv = (hdlwpvariable) h;
00745     register hdlwprecord hwp;
00746     register boolean fl;
00747     register hdlwprecord hwporig = wpdata;
00748     Handle hwptext;
00749     boolean fltempload = !(**hv).flinmemory;
00750     
00751     if (!wpverbinmemory ((hdlexternalvariable) hv))
00752         return (false);
00753     
00754     hwp = (hdlwprecord) (**hv).variabledata;
00755     
00756     wpdata = hwp;
00757     
00758     fl = wpgettexthandle (&hwptext);
00759     
00760     wpdata = hwporig;
00761     
00762     if (fl)
00763         fl = pushhandle (hwptext, htext);
00764     
00765     disposehandle (hwptext);
00766     
00767     if (fltempload)
00768         wpverbunload (hv);
00769     
00770     return (fl);
00771     } /*wpverbpacktotext*/
00772 
00773 
00774 boolean wpverbgettimes (hdlexternalvariable h, long *timecreated, long *timemodified) {
00775     
00776     register hdlexternalvariable hv = h;
00777     register hdlwprecord hwp;
00778     
00779     if (!wpverbinmemory (hv))
00780         return (false);
00781     
00782     hwp = (hdlwprecord) (**hv).variabledata;
00783     
00784     *timecreated = (**hwp).timecreated;
00785     
00786     *timemodified = (**hwp).timelastsave;
00787     
00788     return (true);
00789     } /*wpverbgettimes*/
00790 
00791 
00792 boolean wpverbsettimes (hdlexternalvariable h, long timecreated, long timemodified) {
00793     
00794     register hdlexternalvariable hv = h;
00795     register hdlwprecord hwp;
00796     
00797     if (!wpverbinmemory (hv))
00798         return (false);
00799     
00800     hwp = (hdlwprecord) (**hv).variabledata;
00801     
00802     (**hwp).timecreated = timecreated;
00803     
00804     (**hwp).timelastsave = timemodified;
00805     
00806     return (true);
00807     } /*wpverbsettimes*/
00808 
00809 
00810 #if 0
00811 
00812 static boolean getwpparam (hdltreenode hfirst, short pnum, hdlwpvariable *hv) {
00813     
00814     /*
00815     the caller wants an wp doc parameter.  we only accept them as "var"
00816     parameters, we just want the name of a variable that holds an wpdoc.
00817     
00818     this keeps lang.c from having to know too much about wpdocs, but 
00819     more importantly, keeps them from being automatically copied!  could
00820     be very wasteful of memory because these things can get very large.
00821     
00822     we return a handle to the wp record and the identifier we 
00823     referenced to get the wp doc.  the string may used to name a window,
00824     for example.
00825     */
00826     
00827     short id;
00828     
00829     if (!langexternalgetexternalparam (hfirst, pnum, &id, (hdlexternalvariable *) hv)) {
00830         
00831         errornum = namenotwperror;
00832         
00833         return (false);
00834         }
00835     
00836     if (id != idwordprocessor) {
00837         
00838         errornum = namenotwperror;
00839         
00840         return (false);
00841         }
00842     
00843     return (true);
00844     } /*getwpparam*/
00845 
00846 #endif
00847 
00848 
00849 boolean wpwindowopen (hdlexternalvariable hvariable, hdlwindowinfo *hinfo) {
00850     
00851     /*
00852     1/1/92 dmb: check flpacked!
00853     
00854     5.0b9 dmb: for clipboard operations, must test hwp for nil
00855     */
00856     
00857     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00858     register hdlwprecord hwp;
00859     
00860     if (!(**hv).flinmemory)
00861         return (false);
00862     
00863     if ((**hv).flpacked) /*if it's packed, window can't be open*/
00864         return (false);
00865     
00866     hwp = (hdlwprecord) (**hv).variabledata;
00867     
00868     if (hwp == nil)
00869         return (false);
00870     
00871     shellfinddatawindow ((Handle) hwp, hinfo); /*3/19/91 DW*/
00872     
00873     return ((**hwp).flwindowopen);
00874     } /*wpwindowopen*/
00875 
00876 
00877 boolean wpedit (hdlexternalvariable hvariable, hdlwindowinfo hparent, ptrfilespec fs, bigstring bstitle, rectparam rzoom) {
00878 
00879     /*
00880     4.17.97 dmb: protect against globals smashing under Windows
00881 
00882     5.0b18 dmb: further protection: set flwindowopen bit before 
00883     newchildwindow, which will yield
00884 
00885     5.0.2b6 dmb: added flwindowopen loop to handle Windows async overlap
00886     */
00887     
00888     register hdlwpvariable hv = (hdlwpvariable) hvariable;
00889     register hdlwprecord hwp;
00890     Rect rwindow;
00891     WindowPtr w;
00892     hdlwindowinfo hi;
00893     
00894     if (!wpverbinmemory ((hdlexternalvariable) hv)) /*couldn't swap it into memory*/
00895         return (false);
00896     
00897     hwp = (hdlwprecord) (**hv).variabledata; /*it's in memory*/
00898     
00899     while ((**hwp).flwindowopen) { /*bring to front, return true*/
00900         
00901         if (shellfinddatawindow ((Handle) hwp, &hi)) {
00902             
00903             if ((*rzoom).top > -2)
00904                 shellbringtofront (hi);
00905             
00906             return (true);
00907             }
00908 
00909         #ifdef MACVERSION
00910             break;
00911         #else
00912             if (!shellyield (false))
00913                 return (false);
00914         #endif
00915         }
00916     
00917     rwindow = (**hwp).windowrect; /*window comes up where it was last time*/
00918     
00919     (**hwp).flwindowopen = true;
00920 
00921     if (!newchildwindow (idwpconfig, hparent, &rwindow, rzoom, bstitle, &w)) {
00922         
00923         (**hwp).flwindowopen = false;
00924 
00925         return (false);
00926         }
00927     
00928     wpdata = hwp; /*copy into global*/
00929     
00930     getwindowinfo (w, &hi);
00931     
00932     (**hi).hdata = (Handle) hwp;
00933     
00934     if (fs != nil)
00935         (**hi).fspec = *fs;
00936     
00937     shellpushglobals (w);
00938 
00939     wplinkwindowinfo ();
00940     
00941     shellpopglobals ();
00942     
00943     //(**hwp).flwindowopen = true;
00944     
00945     if ((**hwp).fldirty)
00946         shellsetwindowchanges (hi, true);
00947 
00948     windowzoom (w); /*show the window to the user. do last, or we'd have to push globals*/
00949     
00950     return (true);
00951     } /*wpedit*/
00952 
00953 
00954 static boolean wpfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
00955     
00956     /*
00957     bridges wp.c with the language.  the name of the verb is bs, its first parameter
00958     is hparam1, and we return a value in vreturned.
00959     
00960     we use a limited number of support routines from lang.c to get parameters and
00961     to return values. 
00962     
00963     return false only if the error is serious enough to halt the running of the script
00964     that called us, otherwise error values are returned through the valuerecord, which
00965     is available to the script.
00966     
00967     if we return false, we try to provide a descriptive error message in the 
00968     returned string bserror.
00969     
00970     12/30/91 dmb: use wpinserthandle for insertfunc
00971     
00972     5/17/92 dmb: setselectfunc now uses longs, as it should always have
00973     
00974     6/1/93 dmb: when vreturned is nil, return whether or not verb token must 
00975     be run in the Frontier process
00976     
00977     5.0.2b17 dmb: insert, settext get readonly handles
00978     */
00979     
00980     register tyvaluerecord *v = vreturned;
00981     register boolean fl;
00982     WindowPtr targetwindow;
00983     short idprocessor = idwordprocessor;
00984     
00985     if (v == nil)
00986         return (true);
00987     
00988     errornum = 0;
00989     
00990     setbooleanvalue (false, v); /*by default, wp functions return true*/
00991     
00992     switch (token) {
00993         
00994         /*
00995         case packtextfunc:
00996             if (!wppacktextverb (hparam1, v))
00997                 goto error;
00998             
00999             return (true);
01000         
01001         case unpacktextfunc:
01002             if (!wpunpacktextverb (hparam1, v))
01003                 goto error;
01004             
01005             return (true);
01006         */
01007         
01008         case intextmodefunc: /*verb that don't require wp-specific target*/
01009         case settextmodefunc:
01010             idprocessor = -1;
01011             
01012             break;
01013         }
01014     
01015     /*all other verbs require a wp window in front -- set wpengine.c globals*/
01016     
01017     if (!langfindtargetwindow (idprocessor, &targetwindow)) {
01018         
01019         errornum = nowperror;
01020         
01021         goto error;
01022         }
01023     
01024     shellpushglobals (targetwindow);
01025     
01026     (*shellglobals.gettargetdataroutine) (idprocessor); /*set wp globals*/
01027     
01028     fl = false; /*default return value*/
01029     
01030     switch (token) {
01031         
01032         case intextmodefunc: {
01033             WindowPtr textwindow;
01034             
01035             if (!langcheckparamcount (hparam1, 0))
01036                 break;
01037             
01038             fl = setbooleanvalue (langfindtargetwindow (idwordprocessor, &textwindow), v);
01039             
01040             break;
01041             }
01042         
01043         case settextmodefunc: {
01044             boolean flenter;
01045             
01046             flnextparamislast = true;
01047             
01048             if (!getbooleanvalue (hparam1, 1, &flenter))
01049                 break;
01050             
01051             fl = setbooleanvalue ((*shellglobals.settextmoderoutine) (flenter), v);
01052             
01053             break;
01054             }
01055         
01056         case gettextfunc: {
01057             Handle htext;
01058             
01059             if (!langcheckparamcount (hparam1, 0))
01060                 break;
01061             
01062             if (!wpgettexthandle (&htext))
01063                 break;
01064             
01065             fl = setheapvalue (htext, stringvaluetype, v);
01066             
01067             break;
01068             }
01069         
01070         case settextfunc: {
01071             Handle htext;
01072             
01073             flnextparamislast = true;
01074             
01075             if (!getreadonlytextvalue (hparam1, 1, &htext))
01076                 break;
01077             
01078             if (!wpsettexthandle (htext))
01079                 break;
01080             
01081             fl = setbooleanvalue (true, v);
01082             
01083             break;
01084             }
01085         
01086         case getseltextfunc: {
01087             /*
01088             bigstring bs;
01089             */
01090             Handle htext;
01091             
01092             if (!langcheckparamcount (hparam1, 0))
01093                 break;
01094             
01095             if (!wpgetseltexthandle (&htext))
01096                 break;
01097             
01098             fl = setheapvalue (htext, stringvaluetype, v);
01099             
01100             /*
01101             wpgetseltext (bs);
01102             
01103             fl = setstringvalue (bs, v);
01104             */
01105             
01106             break;
01107             }
01108         
01109         case getdisplayfunc:
01110             
01111             if (!langcheckparamcount (hparam1, 0)) /*too many parameters were passed*/
01112                 break;
01113             
01114             (*v).data.flvalue = !(**wpdata).flinhibitdisplay;
01115             
01116             fl = true;
01117             
01118             break;
01119         
01120         case setdisplayfunc: {
01121             boolean fldisplay;
01122             
01123             flnextparamislast = true;
01124             
01125             if (!getbooleanvalue (hparam1, 1, &fldisplay))
01126                 break;
01127             
01128             (*v).data.flvalue = wpsetdisplay (fldisplay);
01129             
01130             fl = true;
01131             
01132             break;
01133             }
01134         
01135         case getrulerfunc:
01136             
01137             if (!langcheckparamcount (hparam1, 0))
01138                 break;
01139             
01140             (*v).data.flvalue = wpgetruler ();
01141             
01142             fl = true;
01143             
01144             break;
01145         
01146         case setrulerfunc: {
01147             boolean flruler;
01148             
01149             flnextparamislast = true;
01150             
01151             if (!getbooleanvalue (hparam1, 1, &flruler))
01152                 break;
01153             
01154             (*v).data.flvalue = wpsetruler (flruler);
01155             
01156             fl = true;
01157             
01158             break;
01159             }
01160         
01161         case getindentfunc: {
01162             short indent;
01163             
01164             if (!langcheckparamcount (hparam1, 0))
01165                 break;
01166             
01167             wpgetindent (&indent);
01168             
01169             fl = setlongvalue (indent, v);
01170             
01171             break;
01172             }
01173             
01174         case setindentfunc: {
01175             short indent;
01176             
01177             flnextparamislast = true;
01178             
01179             if (!getintvalue (hparam1, 1, &indent))
01180                 break;
01181             
01182             (*v).data.flvalue = wpsetindent (indent);
01183             
01184             fl = true;
01185             
01186             break;
01187             }
01188             
01189         case getleftmarginfunc: {
01190             short leftmargin;
01191             
01192             if (!langcheckparamcount (hparam1, 0))
01193                 break;
01194             
01195             wpgetleftmargin (&leftmargin);
01196             
01197             fl = setlongvalue (leftmargin, v);
01198             
01199             break;
01200             }
01201             
01202         case setleftmarginfunc: {
01203             short leftmargin;
01204             
01205             flnextparamislast = true;
01206             
01207             if (!getintvalue (hparam1, 1, &leftmargin))
01208                 break;
01209             
01210             (*v).data.flvalue = wpsetleftmargin (leftmargin);
01211             
01212             fl = true;
01213             
01214             break;
01215             }
01216             
01217         case getrightmarginfunc: {
01218             short rightmargin;
01219             
01220             if (!langcheckparamcount (hparam1, 0))
01221                 break;
01222             
01223             wpgetrightmargin (&rightmargin);
01224             
01225             fl = setlongvalue (rightmargin, v);
01226             
01227             break;
01228             }
01229             
01230         case setrightmarginfunc: {
01231             short rightmargin;
01232             
01233             flnextparamislast = true;
01234             
01235             if (!getintvalue (hparam1, 1, &rightmargin))
01236                 break;
01237             
01238             (*v).data.flvalue = wpsetrightmargin (rightmargin);
01239             
01240             fl = true;
01241             
01242             break;
01243             }
01244         
01245         case setspacingfunc: {
01246             short spacing;
01247             
01248             flnextparamislast = true;
01249             
01250             if (!getintvalue (hparam1, 1, &spacing))
01251                 break;
01252             
01253             (**wpwindowinfo).selectioninfo.leading = spacing;
01254             
01255             fl = setbooleanvalue (wpsetleading (), v);
01256             
01257             break;
01258             }
01259         
01260         case setjustificationfunc: {
01261             short justification;
01262             
01263             flnextparamislast = true;
01264             
01265             if (!getintvalue (hparam1, 1, &justification))
01266                 break;
01267             
01268             (**wpwindowinfo).selectioninfo.justification = (tyjustification) (justification - 1);
01269             
01270             fl = setbooleanvalue (wpsetjustify (), v);
01271             
01272             break;
01273             }
01274         
01275         case settabfunc: {
01276             short pos;
01277             short type;
01278             char fill;
01279             
01280             if (!getintvalue (hparam1, 1, &pos))
01281                 break;
01282             
01283             if (!getintvalue (hparam1, 2, &type)) /*1 for left tab; 2 center; etc.*/
01284                 break;
01285             
01286             flnextparamislast = true;
01287             
01288             if (!getcharvalue (hparam1, 3, &fill))
01289                 break;
01290             
01291             fl = setbooleanvalue (wpsettab (pos, type - 1, fill), v);
01292             
01293             break;
01294             }
01295         
01296         case cleartabsfunc: {
01297             if (!langcheckparamcount (hparam1, 0))
01298                 break;
01299             
01300             fl = setbooleanvalue (wpcleartabs (), v);
01301             
01302             break;
01303             }
01304         
01305         case getselectfunc: {
01306             long startsel, endsel;
01307             
01308             wpgetselection (&startsel, &endsel);
01309             
01310             if (!langsetlongvarparam (hparam1, 1, startsel))
01311                 return (false);
01312             
01313             flnextparamislast = true;
01314             
01315             if (!langsetlongvarparam (hparam1, 2, endsel))
01316                 return (false);
01317             
01318             (*v).data.flvalue= true;
01319             
01320             fl = true;
01321             
01322             break;
01323             }
01324         
01325         case setselectfunc: {
01326             long startsel, endsel;
01327             
01328             if (!getlongvalue (hparam1, 1, &startsel))
01329                 break;
01330             
01331             flnextparamislast = true;
01332             
01333             if (!getlongvalue (hparam1, 2, &endsel))
01334                 break;
01335             
01336             wpsetselection (startsel, endsel);
01337             
01338             (*v).data.flvalue= true;
01339             
01340             fl = true;
01341             
01342             break;
01343             }
01344         
01345         case insertfunc: {
01346             Handle x;
01347 
01348             flnextparamislast = true;
01349             
01350             if (!getreadonlytextvalue (hparam1, 1, &x))
01351                 break;
01352             
01353             wptrimhiddentext ();
01354             
01355             if (!wpinserthandle (x))
01356                 break;
01357             
01358             (*v).data.flvalue = true;
01359             
01360             fl = true;
01361             
01362             break;
01363             }
01364         
01365         /*
01366         case findfunc: {
01367             bigstring bs;
01368             
01369             flnextparamislast = true;
01370             
01371             if (!getstringvalue (hparam1, 1, bs))
01372                 break;
01373             
01374             (*v).data.flvalue = wpsearch (bs, false, false, false, false);
01375             
01376             fl = true;
01377             
01378             break;
01379             }
01380         
01381         case replacefunc:
01382             if (!langcheckparamcount (hparam1, 0))
01383                 break;
01384             
01385             (*v).data.flvalue = wpinsert (searchparams.bsreplace);
01386             
01387             fl = true;
01388             
01389             break;
01390         */
01391         
01392         #if false
01393         
01394         case writetofilefunc: {
01395             bigstring bs;
01396             
01397             flnextparamislast = true;
01398             
01399             if (!getstringvalue (hparam1, 1, bs))
01400                 break;
01401             
01402             (*v).data.flvalue = wpwritetofile (bs);
01403             
01404             fl = true;
01405             
01406             break;
01407             }
01408             
01409         case readfromfilefunc: {
01410             bigstring bs;
01411             
01412             flnextparamislast = true;
01413             
01414             if (!getstringvalue (hparam1, 1, bs))
01415                 break;
01416             
01417             (*v).data.flvalue = wpreadfromfile (bs);
01418             
01419             fl = true;
01420             
01421             break;
01422             }
01423         
01424         case readfromtextfilefunc: {
01425             bigstring bs;
01426             
01427             flnextparamislast = true;
01428             
01429             if (!getstringvalue (hparam1, 1, bs))
01430                 break;
01431             
01432             (*v).data.flvalue = wpreadfromtextfile (bs);
01433             
01434             fl = true;
01435             
01436             break;
01437             }
01438         
01439         case writetotextfilefunc: {
01440             bigstring bs;
01441             
01442             flnextparamislast = true;
01443             
01444             if (!getstringvalue (hparam1, 1, bs))
01445                 break;
01446             
01447             (*v).data.flvalue = wpwritetotextfile (bs);
01448             
01449             fl = true;
01450             
01451             break;
01452             }
01453         
01454         #endif
01455         
01456         #ifdef flvariables
01457         
01458         case newvariablefunc: {
01459             bigstring bs, bsvalue;
01460             
01461             if (!getstringvalue (hparam1, 1, bs))
01462                 break;
01463             
01464             flnextparamislast = true;
01465             
01466             if (!getstringvalue (hparam1, 2, bsvalue))
01467                 break;
01468             
01469             (*v).data.flvalue = wpnewvariable (bs, bsvalue);
01470             
01471             fl = true;
01472             
01473             break;
01474             }
01475         
01476         case deletevariablefunc: {
01477             bigstring bs;
01478             
01479             flnextparamislast = true;
01480             
01481             if (!getstringvalue (hparam1, 1, bs))
01482                 break;
01483             
01484             (*v).data.flvalue = wpdeletevariable (bs);
01485             
01486             fl = true;
01487             
01488             break;
01489             }
01490         
01491         case getnthvariablefunc: {
01492             short ix;
01493             bigstring bs;
01494             
01495             flnextparamislast = true;
01496             
01497             if (!getintvalue (hparam1, 1, &ix))
01498                 break;
01499             
01500             if (!wpgetnthvariable (ix, bs))
01501                 setemptystring (bs);
01502             
01503             fl = setstringvalue (bs, v);
01504             
01505             break;
01506             }
01507         
01508         case setvariablevaluefunc: {
01509             bigstring bs, bsvalue;
01510             
01511             if (!getstringvalue (hparam1, 1, bs))
01512                 break;
01513             
01514             flnextparamislast = true;
01515             
01516             if (!getstringvalue (hparam1, 2, bsvalue))
01517                 break;
01518             
01519             (*v).data.flvalue = wpsetvariablevalue (bs, bsvalue);
01520             
01521             fl = true;
01522             
01523             break;
01524             }
01525         
01526         case getvariablevaluefunc: {
01527             bigstring bs, bsvalue;
01528             
01529             flnextparamislast = true;
01530             
01531             if (!getstringvalue (hparam1, 1, bs))
01532                 break;
01533             
01534             if (!wpgetvariablevalue (bs, bsvalue))
01535                 setemptystring (bsvalue);
01536             
01537             fl = setstringvalue (bsvalue, v);
01538             
01539             break;
01540             }
01541         
01542         case insertvariablefunc: {
01543             bigstring bs;
01544             
01545             flnextparamislast = true;
01546             
01547             if (!getstringvalue (hparam1, 1, bs))
01548                 break;
01549             
01550             (*v).data.flvalue = wpinsertvariable (bs);
01551             
01552             fl = true;
01553             
01554             break;
01555             }
01556         
01557         case getevalfunc:
01558             if (!langcheckparamcount (hparam1, 0))
01559                 break;
01560             
01561             (*v).data.flvalue = wpgetevaluate ();
01562             
01563             fl = true;
01564             
01565             break;
01566         
01567         case setevalfunc: {
01568             boolean flexpand;
01569             
01570             flnextparamislast = true;
01571             
01572             if (!getbooleanvalue (hparam1, 1, &flexpand))
01573                 break;
01574             
01575             (*v).data.flvalue = wpsetevaluate (flexpand);
01576             
01577             fl = true;
01578             
01579             break;
01580             }
01581         
01582         case hilitevariablesfunc: {
01583             boolean flhilite;
01584             
01585             flnextparamislast = true;
01586             
01587             if (!getbooleanvalue (hparam1, 1, &flhilite))
01588                 break;
01589             
01590             (*v).data.flvalue = wphilitevariables (flhilite);
01591             
01592             fl = true;
01593             
01594             break;
01595             }
01596         
01597         #endif
01598         
01599         case rulerlengthfunc:
01600             if (!langcheckparamcount (hparam1, 0))
01601                 break;
01602             
01603             fl = setlongvalue (wpavailwidth (), v);
01604             
01605             break;
01606         
01607         case gofunc: {
01608             tydirection dir;
01609             long dist;
01610             
01611             if (!getdirectionvalue (hparam1, 1, &dir))
01612                 break;
01613             
01614             flnextparamislast = true;
01615             
01616             if (!getlongvalue (hparam1, 2, &dist))
01617                 break;
01618             
01619             fl = setbooleanvalue (wpgo (dir, dist), v);
01620             
01621             break;
01622             }
01623         
01624         case selectwordfunc:
01625             if (!langcheckparamcount (hparam1, 0))
01626                 break;
01627             
01628             fl = setbooleanvalue (wpselectword (), v);
01629             
01630             break;
01631         
01632         case selectlinefunc:
01633             if (!langcheckparamcount (hparam1, 0))
01634                 break;
01635             
01636             fl = setbooleanvalue (wpselectline (), v);
01637             
01638             break;
01639         
01640         case selectparafunc:
01641             if (!langcheckparamcount (hparam1, 0))
01642                 break;
01643             
01644             fl = setbooleanvalue (wpselectpara (), v);
01645             
01646             break;
01647         
01648         } /*switch*/
01649     
01650     shellupdatescrollbars (shellwindowinfo);
01651     
01652     shellsetselectioninfo (); /*force ruler update*/
01653     
01654     shellpopglobals ();
01655     
01656     return (fl);
01657     
01658     error:
01659     
01660     if (errornum != 0) /*get error string*/
01661         getstringlist (wperrorlist, errornum, bserror);
01662     
01663     return (false);
01664     } /*wpfunctionvalue*/
01665 
01666 
01667 static boolean wpclose (void) {
01668     
01669     /*
01670     6.18.97 dmb: no more in-memory packed state. doesn't work well 
01671     with file based objects.
01672     */
01673     
01674     register hdlwprecord hwp = wpdata;
01675     register hdlwpvariable hv;
01676     // Handle hpackedwp;
01677     
01678     if (hwp == nil) //already closed & disposed?
01679         return (true);
01680     
01681     hv = (hdlwpvariable) (**hwp).wprefcon;
01682     
01683     langexternalwindowclosed ((hdlexternalvariable) hv);
01684     
01685     killundo (); /*must toss undos before they're stranded*/
01686     
01687     wpverbcheckwindowrect (hwp);
01688     
01689     if ((**hwp).fldirty || isfilewindow (shellwindow)) {
01690         
01691         /*
01692         if (wppack (&hpackedwp)) { // pack wp doc. the window is going away.
01693             
01694             wpdispose (); // no longer need the unpacked version
01695             
01696             (**hv).flpacked = true;
01697             
01698             (**hv).variabledata = (long) hpackedwp;
01699             }
01700         else
01701         */
01702         (**hwp).flwindowopen = false; /*not in a window anymore*/
01703         }
01704     else {
01705         // assert ((**hv).oldaddress != nildbaddress);
01706         
01707         wpverbunload (hv);
01708         
01709         wpdata = nil;
01710         
01711         return (true);
01712         }
01713     
01714     return (true);
01715     } /*wpclose*/
01716 
01717 
01718 static boolean wpinitverbs (void) {
01719     
01720     return (loadfunctionprocessor (idwpverbs, &wpfunctionvalue));
01721     } /*wpinitverbs*/
01722 
01723 
01724 static boolean dosearch (boolean flfromtop, boolean flwrap, boolean *fltempload) {
01725     
01726     /*
01727     4.1b12 dmb: handle replaceall wraparound when replacement string contains 
01728     search string. also, check for cmd-period
01729     
01730     5.0.2b18 dmb: fixed flwrap case when matches were close together.
01731     */
01732     
01733     register boolean fl;
01734     long startsel, endsel;
01735     long origendsel = 0, searchstart;
01736     short diff;
01737     boolean flwrapped = false;
01738     
01739     if (searchparams.flreplaceall && flwrap) {/*4.1b12*/
01740     
01741         wpgetselection (&startsel, &endsel);
01742         
01743         origendsel = endsel;
01744         
01745         if (searchparams.ctreplaced > 0) /*there was a selection, already replaced*/
01746             origendsel -= stringlength (searchparams.bsreplace);
01747         }
01748     
01749     while (true) {
01750         
01751         searchstart = endsel; /*4.1b12*/
01752         
01753         fl = wpsearch (flfromtop, !searchparams.flunicase, searchparams.flwholewords, flwrap);
01754         
01755         if (!fl)
01756             break;
01757         
01758         *fltempload = false;
01759         
01760         if (!searchparams.flreplaceall)
01761             break;
01762         
01763         if (flwrap) { /*4.1b12*/
01764         
01765             wpgetselection (&startsel, &endsel);
01766             
01767             if (startsel < searchstart) { /*wrapped*/
01768                 
01769                 if (flwrapped) /*wrapped before; we must be done*/
01770                     goto overlapped;
01771                 
01772                 flwrapped = true;
01773                 }
01774             
01775             if (flwrapped) {
01776                 
01777                 if (endsel > origendsel) /*wrapped beyond original search start*/
01778                     goto overlapped;
01779                 
01780                 diff = stringlength (searchparams.bsreplace) - (endsel - startsel);
01781                 
01782                 endsel += diff; /*adjust current sel end for next searchstart*/
01783                 
01784                 origendsel += diff; /*adjust orig start*/
01785                 }
01786             }
01787         
01788         if (!wpinsert (searchparams.bsreplace))
01789             break;
01790         
01791         endsel = startsel + stringlength (searchparams.bsreplace); //keep in synch
01792         
01793         ++searchparams.ctreplaced;
01794         
01795         if (keyboardescape ()) /*user pressed cmd-period -- stop visiting*/
01796             return (false);
01797     
01798         flfromtop = false;
01799         }
01800     
01801     return (fl);
01802     
01803     overlapped: {
01804         
01805         wpsetselection (searchstart, searchstart); /*go back to last replacement*/
01806         
01807         return (false);
01808         }
01809     } /*dosearch*/
01810 
01811 
01812 boolean wpverbfind (hdlexternalvariable hvariable, boolean *flzoom) {
01813 #pragma unused(flzoom)
01814 
01815     register hdlwpvariable hv = (hdlwpvariable) hvariable;
01816     register hdlwprecord hwp;
01817     register boolean fl;
01818     boolean fltempload;
01819     boolean flwindowopen;
01820     hdlwindowinfo hinfo;
01821     
01822     fltempload = !(**hv).flinmemory;
01823     
01824     if (!wpverbinmemory ((hdlexternalvariable) hv))
01825         return (false);
01826     
01827     hwp = (hdlwprecord) (**hv).variabledata;
01828     
01829     flwindowopen = wpwindowopen ((hdlexternalvariable) hv, &hinfo);
01830     
01831     if (flwindowopen)
01832         shellpushglobals ((**hinfo).macwindow);
01833     
01834     else {
01835         shellpushglobals (nil);
01836         
01837         wppushdata (hwp);
01838         }
01839     
01840     fl = dosearch (true, false, &fltempload);
01841     
01842     if (fltempload && !fl && !(**hwp).fldirty)
01843         wpverbunload (hv);
01844     
01845     if (!flwindowopen)
01846         wppopdata ();
01847     
01848     shellpopglobals ();
01849     
01850     return (fl);
01851     } /*wpverbfind*/
01852 
01853 
01854 static boolean wpverbsearch (void) {
01855     
01856     /*
01857     2/13/92 dmb: use new dosearch to handle replace all
01858     */
01859     
01860     long wprefcon = (**wpdata).wprefcon;
01861     boolean fltempload = false;
01862     
01863     startingtosearch (wprefcon);
01864     
01865     /*
01866     if (wpsearch (searchparams.bsfind, false, !searchparams.flunicase, searchparams.flwholewords, searchshouldwrap (wprefcon)))
01867         return (true);
01868     */
01869     
01870     if (dosearch (false, searchshouldwrap (wprefcon), &fltempload))
01871         return (true);
01872     
01873     if (!searchshouldcontinue (wprefcon))
01874         return (false);
01875     
01876     return (langexternalcontinuesearch ((hdlexternalvariable) wprefcon));
01877     } /*wpverbsearch*/
01878 
01879 
01880 static boolean wpverbruncursor (void) {
01881     
01882     /*
01883     9/26/91 dmb: work with handles, not strings
01884     */
01885     
01886     bigstring bsresult;
01887     long startsel, endsel;
01888     Handle htext;
01889     
01890     wpgetselection (&startsel, &endsel);
01891     
01892     if (startsel == endsel)
01893         wpselectline ();
01894     
01895     if (!wpgetseltexthandle (&htext))
01896         return (false);
01897     
01898     return (langrunhandle (htext, bsresult)); /*consumes htext*/
01899     
01900     /*
01901     if (startsel == endsel)
01902         wpsetselection (0, 255);
01903     
01904     wpgetseltext (bs);
01905     
01906     return (langrunstring (bs, bsresult));
01907     */
01908     
01909     } /*wpverbruncursor*/
01910 
01911 
01912 static boolean wpverbtitleclick (Point pt) {
01913     
01914     return (langexternaltitleclick (pt, (hdlexternalvariable) (**wpdata).wprefcon));
01915     } /*wpverbtitleclick*/
01916 
01917 
01918 static boolean wpverbgetvariable (void *hvariable) {
01919     
01920     hdlexternalvariable *hv = (hdlexternalvariable *) hvariable;
01921     
01922     if (wpdata == nil)
01923         return (false);
01924     
01925     *hv = (hdlexternalvariable) (**wpdata).wprefcon;
01926     
01927     return (true);
01928     } /*wpverbgetvariable*/
01929 
01930 
01931 static boolean wpverbgettargetdata (short id) {
01932     
01933     /*
01934     a verb is about to be executed that acts on the indicated external type, or 
01935     on any shell window if id == -1.
01936     
01937     return true if we can handle verbs of that type and are able to set the 
01938     relevant globals
01939     */
01940     
01941     switch (id) {
01942         
01943         case -1:
01944             return (true);
01945         
01946         case idwordprocessor: /*don't need to do anything -- our wp globals are pushed*/
01947             return (true);
01948         
01949         default:
01950             return (false);
01951         }
01952     } /*wpverbgettargetdata*/
01953 
01954 
01955 static boolean wpverbclick (Point pt, tyclickflags flags) {
01956     
01957     wpclick (pt, flags);
01958     
01959     if (keyboardstatus.ctmodifiers && mousestatus.fldoubleclick) {
01960         
01961         bigstring bs;
01962         
01963         wpgetseltext (bs);
01964         
01965         langzoomobject (bs);
01966         }
01967     
01968     return (true);
01969     } /*wpverbclick*/
01970 
01971 
01972 static boolean wpverbkeystroke (void) {
01973     
01974     if (langexternalsurfacekey ((hdlexternalvariable) (**wpdata).wprefcon))
01975         return (true);
01976     
01977     return (wpkeystroke ());
01978     } /*wpverbkeystroke*/
01979 
01980 
01981 static boolean wpverbpaste (void) {
01982     
01983     /*
01984     6.0b3 dmb: had to add this layer as wppaste gained the flstyles parameter
01985     */
01986     
01987     return (wppaste (true));
01988     } /*wpverbpaste*/
01989 
01990 
01991 boolean wpstart (void) {
01992     
01993     /*
01994     set up callback routines record, and link our data into the shell's 
01995     data structure.
01996     */
01997     
01998     ptrcallbacks wpcallbacks;
01999     register ptrcallbacks cb;
02000     
02001     assert (sizeof (tyexternalvariable) == sizeof (tywpvariable));
02002     
02003     wpinitverbs ();
02004     
02005     shellpushscraphook (&wpscraphook);
02006     
02007     shellnewcallbacks (&wpcallbacks);
02008     
02009     cb = wpcallbacks; /*copy into register*/
02010     
02011     loadconfigresource (idwpconfig, &(*cb).config);
02012         
02013     (*cb).configresnum = idwpconfig;
02014         
02015     (*cb).windowholder = &wpwindow;
02016     
02017     (*cb).dataholder = (Handle *) &wpdata;
02018     
02019     (*cb).infoholder = &wpwindowinfo; 
02020     
02021     (*cb).initroutine = &wpinit;
02022     
02023     (*cb).quitroutine = &wpshutdown;
02024     
02025 #ifdef version42orgreater
02026     
02027     (*cb).disposerecordroutine = ccdisposefilerecord;
02028     
02029     (*cb).saveroutine = ccsavespecialfile;
02030 
02031 #endif
02032     
02033     (*cb).closeroutine = &wpclose;
02034     
02035     (*cb).titleclickroutine = &wpverbtitleclick;
02036     
02037     (*cb).searchroutine = &wpverbsearch;
02038     
02039     (*cb).executeroutine = &wpverbruncursor;
02040     
02041     (*cb).getvariableroutine = &wpverbgetvariable;
02042     
02043     (*cb).updateroutine = &wpupdate;
02044     
02045     (*cb).activateroutine = &wpactivate;
02046     
02047     (*cb).getcontentsizeroutine = &wpgetcontentsize;
02048     
02049     (*cb).resizeroutine = &wpresize;
02050     
02051     (*cb).scrollroutine = &wpscroll;
02052     
02053     (*cb).setscrollbarroutine = &wpresetscrollbars;
02054     
02055     (*cb).mouseroutine = &wpverbclick;
02056     
02057     (*cb).keystrokeroutine = &wpverbkeystroke;
02058     
02059     /*
02060     (*cb).undoroutine = &wpundo;
02061     */
02062     
02063     (*cb).cutroutine = &wpcut;
02064     
02065     (*cb).copyroutine = &wpcopy;
02066     
02067     (*cb).pasteroutine = &wpverbpaste;
02068     
02069     (*cb).clearroutine = &wpclear;
02070     
02071     (*cb).selectallroutine = &wpselectall;
02072     
02073     (*cb).fontroutine = &wpsetfont;
02074     
02075     (*cb).sizeroutine = &wpsetsize;
02076     
02077     (*cb).styleroutine = &wpsetstyle;
02078     
02079     (*cb).leadingroutine = &wpsetleading;
02080     
02081     (*cb).justifyroutine = &wpsetjustify;
02082     
02083     (*cb).setselectioninforoutine = &wpsetselectioninfo;
02084     
02085     (*cb).pagesetuproutine = &wppagesetup;
02086     
02087     (*cb).beginprintroutine = &wpbeginprint;
02088     
02089     (*cb).endprintroutine = &wpendprint;
02090     
02091     (*cb).printroutine = &wpprint;
02092     
02093     (*cb).setprintinfoproutine = &wpsetprintinfo;
02094     
02095     (*cb).idleroutine = &wpidle;
02096     
02097     (*cb).adjustcursorroutine = &wpadjustcursor;
02098     
02099     (*cb).gettargetdataroutine = &wpverbgettargetdata;
02100     
02101     return (true);
02102     } /*wpstart*/
02103 
02104 #endif // !flruntime
02105 
02106 
02107 

Generated on Wed May 31 18:20:04 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6