shellhooks.c

Go to the documentation of this file.
00001 
00002 /*  $Id: shellhooks.c 355 2005-01-11 22:48:55Z andreradke $    */
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 "shell.h"
00032 #include "shellhooks.h"
00033 
00034 
00035 
00036 
00037 #define maxkeyboardhooks 2
00038 
00039 static short ctkeyboardhooks = 0;
00040 
00041 callback keyboardhooks [maxkeyboardhooks];
00042 
00043 
00044 boolean shellpushkeyboardhook (callback routine) {
00045     
00046     if (ctkeyboardhooks >= maxkeyboardhooks) {
00047     
00048         shellinternalerror (idtoomanykeyboardhooks, STR_increase_maxkeyboardhooks);
00049         
00050         return (false);
00051         }
00052         
00053     keyboardhooks [ctkeyboardhooks++] = routine;
00054     
00055     return (true);
00056     } /*shellpushkeyboardhook*/
00057 
00058 
00059 boolean shellcallkeyboardhooks (void) {
00060     
00061     /*
00062     we call all the routines that are hooked into the keyboard.
00063     
00064     kb.h global keyboardstatus is filled with information about the keystroke.
00065     
00066     if any of the hooks return false, we execute no more -- and we return false.
00067     the caller is expected to return, thereby giving a hook a way of consuming
00068     a keystroke.
00069     
00070     note -- the hook routine can assume absolutely nothing about its environment.
00071     */
00072     
00073     register short i;
00074     
00075     for (i = 0; i < ctkeyboardhooks; i++) {
00076         
00077         register callback cb;
00078         
00079         cb = keyboardhooks [i];
00080         
00081         if (!(*cb) ())
00082             return (false);
00083         } /*for*/
00084         
00085     return (true);
00086     } /*shellcallkeyboardhooks*/
00087 
00088 
00089 
00090 #define maxdirtyhooks 2
00091 
00092 static short ctdirtyhooks = 0;
00093 
00094 callback dirtyhooks [maxdirtyhooks];
00095 
00096 
00097 boolean shellpushdirtyhook (callback routine) {
00098     
00099     if (ctdirtyhooks >= maxdirtyhooks) {
00100     
00101         shellinternalerror (idtoomanydirtyhooks, STR_increase_maxdirtyhooks);
00102         
00103         return (false);
00104         }
00105         
00106     dirtyhooks [ctdirtyhooks++] = routine;
00107     
00108     return (true);
00109     } /*shellpushdirtyhook*/
00110 
00111 
00112 boolean shellcalldirtyhooks (void) {
00113     
00114     /*
00115     we call all the routines that are hooked into the dirty event.  that is, 
00116     if a user action resulted in **anything** becoming dirty, we call all 
00117     the routines in the dirtyhooks array.
00118     
00119     if any of the hooks return false, we execute no more -- and we return false.
00120     
00121     note -- the hook routine can assume absolutely nothing about its environment.
00122     */
00123     
00124     register short i;
00125     
00126     for (i = 0; i < ctdirtyhooks; i++) {
00127         
00128         register callback cb;
00129         
00130         cb = dirtyhooks [i];
00131         
00132         if (!(*cb) ())
00133             return (false);
00134         } /*for*/
00135         
00136     return (true);
00137     } /*shellcalldirtyhooks*/
00138 
00139 
00140 
00141 #define maxmenuhooks 3
00142 
00143 static short ctmenuhooks = 0;
00144 
00145 menuhookcallback menuhooks [maxmenuhooks];
00146 
00147 
00148 boolean shellpushmenuhook (menuhookcallback routine) {
00149     
00150     if (ctmenuhooks >= maxmenuhooks) {
00151     
00152         shellinternalerror (idtoomanymenuhooks, STR_increase_maxmenuhooks);
00153         
00154         return (false);
00155         }
00156         
00157     menuhooks [ctmenuhooks++] = routine;
00158     
00159     return (true);
00160     } /*shellpushmenuhook*/
00161 
00162 
00163 boolean shellcallmenuhooks (short idmenu, short iditem) {
00164     
00165     /*
00166     when the user selects a menu command, we call all the routines in
00167     the menuhooks array.  if none of the hooks handle the command, 
00168     the shell will attempt to handle it.
00169     
00170     if any of the hooks return false, we execute no more -- and we return false.
00171     
00172     note -- the hook routine can assume absolutely nothing about its environment.
00173     */
00174     
00175     register short i;
00176     
00177     for (i = 0; i < ctmenuhooks; i++) {
00178         
00179         register menuhookcallback cb;
00180         
00181         cb = menuhooks [i];
00182         
00183         if (!(*cb) (idmenu, iditem))
00184             return (false);
00185         } /*for*/
00186         
00187     return (true);
00188     } /*shellcallmenuhooks*/
00189 
00190 
00191 
00192 #define maxeventhooks 5
00193 
00194 static short cteventhooks = 0;
00195 
00196 eventhookcallback eventhooks [maxeventhooks];
00197 
00198 
00199 boolean shellpusheventhook (eventhookcallback routine) {
00200     
00201     if (cteventhooks >= maxeventhooks) {
00202     
00203         shellinternalerror (idtoomanyeventhooks, STR_increase_maxeventhooks);
00204         
00205         return (false);
00206         }
00207         
00208     eventhooks [cteventhooks++] = routine;
00209     
00210     return (true);
00211     } /*shellpusheventhook*/
00212 
00213 
00214 boolean shellpopeventhook (void) {
00215     
00216     assert (cteventhooks > 0);
00217     
00218     --cteventhooks;
00219     
00220     return (true);
00221     } /*shellpopeventhook*/
00222 
00223 
00224 boolean shellcalleventhooks (EventRecord *ev, WindowPtr w) {
00225     
00226     /*
00227     when any event is processed that could affect a window owned by the 
00228     application, we give the event hooks a chance to intercept the event
00229     before normal processing occurs.  in some cases, such as a suspend or 
00230     resume event, normal processing will occur whether or not any hook 
00231     returns false.
00232     
00233     if any of the hooks return false, we execute no more -- and we return false.
00234     
00235     note -- the hook routine can assume absolutely nothing about its environment.
00236     */
00237     
00238     register short i;
00239     
00240     for (i = 0; i < cteventhooks; i++) {
00241         
00242         register eventhookcallback cb;
00243         
00244         cb = eventhooks [i];
00245         
00246         if (!(*cb) (ev, w))
00247             return (false);
00248         } /*for*/
00249         
00250     return (true);
00251     } /*shellcalleventhooks*/
00252 
00253 
00254 
00255 short cterrorhooks = 0;
00256 
00257 errorhookcallback errorhooks [maxerrorhooks];
00258 
00259 
00260 boolean shellpusherrorhook (errorhookcallback routine) {
00261     
00262     if (cterrorhooks >= maxerrorhooks) {
00263     
00264         shellinternalerror (idtoomanyerrorhooks, STR_increase_maxerrorhooks);       
00265         return (false);
00266         }
00267         
00268     errorhooks [cterrorhooks++] = routine;
00269     
00270     return (true);
00271     } /*shellpusherrorhook*/
00272 
00273 
00274 boolean shellpoperrorhook (void) {
00275     
00276     assert (cterrorhooks > 0);
00277     
00278     --cterrorhooks;
00279     
00280     return (true);
00281     } /*shellpoperrorhook*/
00282 
00283 
00284 boolean shellcallerrorhooks (bigstring bs) {
00285     
00286     /*
00287     we call all the routines that are hooked into the error event.  that is, 
00288     if a user action resulted in any error, we call all the routines in the 
00289     errorhooks array.
00290     
00291     if any of the hooks return false, we execute no more -- and we return false.
00292     
00293     note -- the hook routine can assume absolutely nothing about its environment.
00294     
00295     1/31/91: we call the most recently pushed hooks first
00296     */
00297     
00298     register short i = cterrorhooks;
00299     
00300     while (--i >= 0) {
00301         
00302         register errorhookcallback cb;
00303         
00304         cb = errorhooks [i];
00305         
00306         if (!(*cb) (bs))
00307             return (false);
00308         } /*for*/
00309         
00310     return (true);
00311     } /*shellcallerrorhooks*/
00312 
00313 
00314 
00315 #define maxscraphooks 7
00316 
00317 static short ctscraphooks = 0;
00318 
00319 scraphookcallback scraphooks [maxscraphooks];
00320 
00321 
00322 boolean shellpushscraphook (scraphookcallback routine) {
00323     
00324     if (ctscraphooks >= maxscraphooks) {
00325     
00326         shellinternalerror (idtoomanyscraphooks, STR_increase_maxscraphooks);
00327         
00328         return (false);
00329         }
00330         
00331     scraphooks [ctscraphooks++] = routine;
00332     
00333     return (true);
00334     } /*shellpushscraphook*/
00335 
00336 
00337 boolean shellcallscraphooks (Handle hscrap) {
00338     
00339     /*
00340     we call all the routines that are hooked into the readscrap event.  that is, 
00341     if we're about it import the scrap, we call all the routines in the 
00342     scraphooks array so that they can look for their own type.
00343     
00344     if any of the hooks return false, we execute no more -- and we return false.
00345     
00346     note -- the hook routine can assume absolutely nothing about its environment.
00347     
00348     1/31/91: we call the most recently pushed hooks first
00349     */
00350     
00351     register short i = ctscraphooks;
00352     
00353     while (--i >= 0) {
00354         
00355         register scraphookcallback cb;
00356         
00357         cb = scraphooks [i];
00358         
00359         if (!(*cb) (hscrap))
00360             return (false);
00361         } /*for*/
00362         
00363     return (true);
00364     } /*shellcallscraphooks*/
00365 
00366 
00367 #define maxmemoryhooks 3
00368 
00369 static short ctmemoryhooks = 0;
00370 
00371 memoryhookcallback memoryhooks [maxmemoryhooks];
00372 
00373 
00374 boolean shellpushmemoryhook (memoryhookcallback routine) {
00375     
00376     if (ctmemoryhooks >= maxmemoryhooks) {
00377     
00378         shellinternalerror (idtoomanymemoryhooks, STR_increase_maxmemoryhooks);
00379         
00380         return (false);
00381         }
00382     
00383     memoryhooks [ctmemoryhooks++] = routine;
00384     
00385     return (true);
00386     } /*shellpushmemoryhook*/
00387 
00388 
00389 boolean shellcallmemoryhooks (long *ctbytesneeded) {
00390     
00391     /*
00392     we call all the routines that are hooked into the low memory mechanism.
00393     
00394     each hook has the opportunity to release some memory, and reduce the 
00395     ctbytesneeded value accordingly.  any hook is free to release more or 
00396     less than the amound needed.
00397     
00398     if any of the hooks return false, we execute no more -- and we return false.
00399     
00400     note -- the hook routine can assume absolutely nothing about its environment.
00401     */
00402     
00403     register short i;
00404     
00405     for (i = 0; i < ctmemoryhooks; i++) {
00406         
00407         register memoryhookcallback cb;
00408         
00409         cb = memoryhooks [i];
00410         
00411         if (!(*cb) (ctbytesneeded))
00412             return (false);
00413         } /*for*/
00414     
00415     return (true);
00416     } /*shellcallmemoryhooks*/
00417 
00418 
00419 #define maxfilehooks 1
00420 
00421 static short ctfilehooks = 0;
00422 
00423 static callback filehooks [maxfilehooks];
00424 
00425 
00426 boolean shellpushfilehook (callback routine) {
00427     
00428     if (ctfilehooks >= maxfilehooks) {
00429     
00430         shellinternalerror (idtoomanyfilehooks, STR_increase_maxfilehooks);
00431         
00432         return (false);
00433         }
00434         
00435     filehooks [ctfilehooks++] = routine;
00436     
00437     return (true);
00438     } /*shellpushfilehook*/
00439 
00440 
00441 boolean shellcallfilehooks (void) {
00442     
00443     /*
00444     we call all the routines that are hooked into file opening & closing.
00445     
00446     note -- the hook routine can assume absolutely nothing about its environment.
00447     */
00448     
00449     register short i;
00450     
00451     for (i = 0; i < ctfilehooks; i++) {
00452         
00453         register callback cb;
00454         
00455         cb = filehooks [i];
00456         
00457         (*cb) ();
00458         } /*for*/
00459     
00460     return (true);
00461     } /*shellcallfilehooks*/
00462 
00463 
00464 
00465 #define maxwakeuphooks 2
00466 
00467 static short ctwakeuphooks = 0;
00468 
00469 static wakeuphookcallback wakeuphooks [maxwakeuphooks];
00470 
00471 
00472 boolean shellpushwakeuphook (wakeuphookcallback routine) {
00473     
00474     if (ctwakeuphooks >= maxwakeuphooks) {
00475     
00476         shellinternalerror (idtoomanyfilehooks, STR_increase_maxfilehooks);
00477         
00478         return (false);
00479         }
00480         
00481     wakeuphooks [ctwakeuphooks++] = routine;
00482     
00483     return (true);
00484     } /*shellpushwakeuphook*/
00485 
00486 
00487 boolean shellcallwakeuphooks (hdlprocessthread hthread) {
00488     
00489     /*
00490     we call all the routines that are hooked into wakeup opening & closing.
00491     
00492     note -- the hook routine can assume absolutely nothing about its environment.
00493     */
00494     
00495     register short i;
00496     
00497     for (i = 0; i < ctwakeuphooks; i++) {
00498         
00499         register wakeuphookcallback cb;
00500         
00501         cb = wakeuphooks [i];
00502         
00503         if (!(*cb) (hthread))
00504             return (false);
00505         } /*for*/
00506     
00507     return (true);
00508     } /*shellcallwakeuphooks*/
00509 
00510 
00511 
00512 
00513 

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