~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Frontier Kernel
Frontier/Common/source/command.c

Version: ~ [ 10.0 ] ~

** Warning: Cannot open xref database.

1 2 /* $Id: command.c,v 1.5 2005/01/11 22:48:05 andreradke Exp $ */ 3 4 /****************************************************************************** 5 6 UserLand Frontier(tm) -- High performance Web content management, 7 object database, system-level and Internet scripting environment, 8 including source code editing and debugging. 9 10 Copyright (C) 1992-2004 UserLand Software, Inc. 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 26 ******************************************************************************/ 27 28 #include "frontier.h" 29 #include "standard.h" 30 31 #include "kb.h" 32 #include "memory.h" 33 #include "mouse.h" 34 #include "strings.h" 35 #include "resources.h" 36 #include "shell.rsrc.h" 37 #include "lang.h" 38 #include "langsystem7.h" 39 #include "miniwindow.h" 40 #include "process.h" 41 #include "cancoon.h" 42 #include "scripts.h" 43 #include "command.h" 44 45 46 47 #define cmdtextitem 1 48 49 50 51 static hdlprocessrecord quickscriptprocess = nil; 52 53 54 55 static boolean cmdsavestring (short stringnumber, Handle htext) { 56 57 /* 58 the cmd dialog only has one string, so we ignore the stringnumber param. 59 60 set the script string in the cancoondata record, for saving -- so we have 61 a permanent copy of the last script he wrote across invocations of the 62 program. 63 64 1/21/93 dmb: don't set superglobals manually anymore 65 66 5.0d14 dmb: hscriptstring is now a text handle, not a hdlstring. 67 */ 68 69 Handle h; /* 2004-12-03 creedon - temporary handle */ 70 register hdlcancoonrecord hc; 71 72 assert (cancoonglobals != nil); 73 74 hc = cancoonglobals; /*copy into register*/ 75 76 if (!equalhandles (htext, (**hc).hscriptstring)) { 77 78 if ((**hc).hscriptstring == nil) { /* 2004-12-03 creedon, aradke */ 79 copyhandle (htext, &h); 80 (**hc).hscriptstring = h; 81 } 82 else 83 copyhandlecontents (htext, (**hc).hscriptstring); 84 85 (**hc).fldirty = true; 86 } 87 88 return (true); 89 } /*cmdsavestring*/ 90 91 92 static boolean cmdloadstring (short stringnumber, Handle *h) { 93 94 /* 95 1/21/93 dmb: don't set superglobals manually anymore 96 97 5.0d14 dmb: hscriptstring is now a text handle, not a hdlstring. 98 */ 99 100 assert (cancoonglobals != nil); 101 102 return (copyhandle ((**cancoonglobals).hscriptstring, h)); 103 } /*cmdloadstring*/ 104 105 106 static boolean cmderrorroutine (long refcon, long lnum, short charnum, hdlhashtable *htable, bigstring bsname) { 107 108 /* 109 a lang error occurred; select the offending text in the quickscript window 110 */ 111 112 #ifdef flnewfeatures 113 114 if (bsname != nil) { /*request is for name*/ 115 116 getstringlist (commandlistnumber, commandtitlestring, bsname); 117 118 return (true); 119 } 120 121 #endif 122 123 if (!startcmddialog ()) 124 return (false); 125 126 if (!shellpushglobals (miniwindow)) 127 return (false); 128 129 charnum = langgetsourceoffset (lnum, charnum); 130 131 minisetselect (charnum, charnum); 132 133 shellpopglobals (); 134 135 return (true); 136 } /*cmderrorroutine*/ 137 138 139 static boolean cmdtexthit (Point pt) { 140 141 /* 142 2.1b6 dmb: use debugging context for zooming, if available 143 */ 144 145 if (keyboardstatus.ctmodifiers && mousestatus.fldoubleclick) { 146 147 bigstring bs; 148 hdlhashtable hcontext = nil; 149 150 minigetselstring (0, bs); 151 152 if (scriptgetdebuggingcontext (&hcontext)) /*gauranteed to be non-nil*/ 153 pushhashtable (hcontext); 154 155 langzoomobject (bs); 156 157 if (hcontext != nil) { 158 159 pophashtable (); 160 161 scriptunlockdebuggingcontext (); 162 } 163 } 164 165 return (true); 166 } /*cmdtexthit*/ 167 168 169 static boolean cmdprocesscallback (void) { 170 171 miniinvalicon (idcommandconfig); 172 173 return (true); 174 } /*cmdprocesscallback*/ 175 176 177 static pascal void *cmdthreadmain (tythreadmainparams hprocess) { 178 179 /* 180 2.1b2 dmb: use getobjectmodeldisplaystring to diplay result 181 182 2.1b4 dmb: use the debugger context, if available (i.e. a script 183 is currently suspended). 184 185 4.0.1b1 dmb: pass name of thread to initprocessthread; call exitprocessthread 186 */ 187 188 register hdlprocessrecord hp = (hdlprocessrecord) hprocess; 189 tyvaluerecord val; 190 bigstring bsresult; 191 hdlhashtable hcontext = nil; 192 boolean fl; 193 194 initprocessthread ("\x0c" "quick script"); /*must call from every thread main*/ 195 196 if ((**hp).fldisposewhenidle) 197 fl = false; 198 else { 199 200 if (scriptgetdebuggingcontext (&hcontext)) 201 (**hp).hcontext = hcontext; 202 203 fl = processruncode (hp, &val); 204 205 if (hcontext != nil) 206 scriptunlockdebuggingcontext (); 207 } 208 209 disposeprocess (hp); 210 211 if (!fl) 212 setbooleanvalue (false, &val); 213 214 getobjectmodeldisplaystring (&val, bsresult); /*hashgetvaluestring (val, bsresult)*/ 215 216 disposetmpvalue (&val); 217 218 minisetwindowmessage (idcommandconfig, bsresult); /*can't assume miniwindow is around anymore*/ 219 220 quickscriptprocess = nil; /*clear "semaphore"*/ 221 222 exitprocessthread (); 223 224 return (nil); 225 } /*cmdthreadmain*/ 226 227 228 static boolean cmdiconhit (void) { 229 230 /* 231 5/21/91 dmb: run the string as a process so we can handle errors nicely. 232 233 8/20/91 dmb: when the process completes, we're in another thread and can't 234 assume that the window is around anymore, let alone that its globals are 235 set. to handle this (crashing) situation, use new minisetwindowmessage 236 to display the result. 237 238 10/25/91 dmb: check new process's disposewhenidleflag before running it. 239 240 10/27/91 dmb: don't dispose result value if processruncode returns false 241 242 12/12/91 dmb: extract the text handle from the dialog record's TE record to 243 overcome the miniwindow's string-oriented architecture. Unfortunately, the 244 text also saved in the database as a string, to this is just a band-aid, not 245 a real fix. 246 247 2.1a6 dmb: reworked threading for thread mgr 1.1 248 249 2.1b2 dmb: pass -1 for errorrefcon instead of zero to prevent top level 250 lexical scope from being transparent (i.e. visible to subroutines) 251 252 5.0d14 dmb: minidialog now uses full text handles, not bigstrings 253 254 5.0b17 dmb: minigetstring result is ours to consume 255 */ 256 257 Handle hscript; 258 hdltreenode hcode; 259 boolean fl; 260 hdlprocessrecord hprocess; 261 register hdlprocessrecord hp; 262 hdlprocessthread hthread; 263 264 if (quickscriptprocess != nil) { 265 266 sysbeep (); 267 268 return (false); 269 } 270 271 if (!langpusherrorcallback (&cmderrorroutine, (long) -1)) 272 return (false); 273 274 minigetstring (0, &hscript); 275 276 fl = langbuildtree (hscript, false, &hcode); /*consumes htext*/ 277 278 langpoperrorcallback (); 279 280 if (!fl) /*syntax error*/ 281 return (false); 282 283 langerrorclear (); /*compilation produced no error, be sure error window is empty*/ 284 285 if (!newprocess (hcode, true, &cmderrorroutine, (long) -1, &hprocess)) { 286 287 langdisposetree (hcode); 288 289 return (false); 290 } 291 292 hp = hprocess; /*copy into register*/ 293 294 (**hp).processstartedroutine = &cmdprocesscallback; 295 296 (**hp).processkilledroutine = &cmdprocesscallback; 297 298 #ifndef oldthreads 299 300 if (!newprocessthread (&cmdthreadmain, (tythreadmainparams) hp, &hthread)) { 301 302 disposeprocess (hp); 303 304 return (false); 305 } 306 307 quickscriptprocess = hp; /*can only run one of these at a time*/ 308 309 return (true); 310 311 #else 312 313 quickscriptprocess = hp; /*can only run one of these at a time*/ 314 315 if (!innewprocessthread (&hthread)) /*not in new thread -- we're done with synchonous stuff*/ 316 return (true); 317 318 if ((hthread == nil) || (**hp).fldisposewhenidle) 319 fl = false; 320 else 321 fl = processruncode (hp, &val); 322 323 disposeprocess (hp); 324 325 if (!fl) 326 setbooleanvalue (false, &val); 327 328 hashgetvaluestring (val, bsresult); 329 330 disposetmpvalue (val); 331 332 minisetwindowmessage (idcommandconfig, bsresult); /*can't assume miniwindow is around anymore*/ 333 334 quickscriptprocess = nil; /*clear "semaphore"*/ 335 336 endprocessthread (hthread); 337 338 return (false); /*if we got here, hthread was nil*/ 339 340 #endif 341 } /*cmdiconhit*/ 342 343 344 static boolean cmdgettargetdata (short id) { 345 346 /* 347 we don't want our script to operate on our window 348 349 2.1b14 dmb: make sure that the current process and our process aren't 350 both nil before rejecting targetship. 351 352 5.0b6 dmb: allow wp verbs to target QuickScript 353 */ 354 355 if ((currentprocess != nil) && (currentprocess == quickscriptprocess)) 356 return (false); 357 358 return (id == -1) || (id == idwordprocessor); 359 } /*cmdgettargetdata*/ 360 361 362 static void cmdcheckrunbutton (void) { 363 364 /* 365 boolean fl = debuggingcurrentprocess () || !processisoneshot (false); 366 */ 367 368 boolean fl = (quickscriptprocess == nil) /*&& !processbusy ()*/ ; 369 370 (**minidata).fliconenabled = fl; 371 } /*cmdcheckrunbutton*/ 372 373 374 static boolean cmdsetfields (void) { 375 376 register hdlminirecord hm = minidata; 377 bigstring bs; 378 379 (**hm).idconfig = idcommandconfig; 380 381 (**hm).windowtype = ixcommandinfo; 382 383 getstringlist (commandlistnumber, runiconstring, bs); 384 385 copystring (bs, (**hm).iconlabel); 386 387 getstringlist (commandlistnumber, commandtitlestring, bs); 388 389 copystring (bs, (**hm).windowtitle); 390 391 (**hm).savestringroutine = &cmdsavestring; 392 393 (**hm).loadstringroutine = &cmdloadstring; 394 395 (**hm).texthitroutine = &cmdtexthit; 396 397 (**hm).iconenableroutine = &cmdcheckrunbutton; 398 399 (**hm).iconhitroutine = &cmdiconhit; 400 401 (**hm).gettargetdataroutine = &cmdgettargetdata; 402 403 (**hm).cttextitems = 1; 404 405 (**hm).textitems [0] = cmdtextitem; 406 407 return (true); 408 } /*cmdsetfields*/ 409 410 411 boolean startcmddialog (void) { 412 413 return (startminidialog (idcommandconfig, &cmdsetfields)); 414 } /*startcmddialog*/ 415 416 417 boolean cmdstart (void) { 418 419 return (ministart (idcommandconfig)); 420 } /*cmdstart*/ 421 422 423 424 425

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.