Back to index

lightning-sunbird  0.9+nobinonly
mac_console.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "mac_console.h"
00038 
00039 #ifndef __CONSOLE__
00040 #include <console.h>
00041 #endif
00042 
00043 extern CWPluginContext gPluginContext;
00044 
00045 UInt32 mac_console_count = 0;
00046 CWMemHandle mac_console_handle = NULL;
00047 
00048 /*
00049  *     The following four functions provide the UI for the console package.
00050  *     Users wishing to replace SIOUX with their own console package need
00051  *     only provide the four functions below in a library.
00052  */
00053 
00054 /*
00055  *     extern short InstallConsole(short fd);
00056  *
00057  *     Installs the Console package, this function will be called right
00058  *     before any read or write to one of the standard streams.
00059  *
00060  *     short fd:            The stream which we are reading/writing to/from.
00061  *     returns short:       0 no error occurred, anything else error.
00062  */
00063 
00064 short InstallConsole(short fd)
00065 {
00066 #pragma unused (fd)
00067        mac_console_count = 0;
00068        CWAllocMemHandle(gPluginContext, 8192, false, &mac_console_handle);
00069        return 0;
00070 }
00071 
00072 /*
00073  *     extern void RemoveConsole(void);
00074  *
00075  *     Removes the console package.  It is called after all other streams
00076  *     are closed and exit functions (installed by either atexit or _atexit)
00077  *     have been called.  Since there is no way to recover from an error,
00078  *     this function doesn't need to return any.
00079  */
00080 
00081 void RemoveConsole(void)
00082 {
00083        if (mac_console_handle != NULL) {
00084               CWFreeMemHandle(gPluginContext, mac_console_handle);
00085               mac_console_handle = NULL;
00086        }
00087 }
00088 
00089 /*
00090  *     extern long WriteCharsToConsole(char *buffer, long n);
00091  *
00092  *     Writes a stream of output to the Console window.  This function is
00093  *     called by write.
00094  *
00095  *     char *buffer: Pointer to the buffer to be written.
00096  *     long n:                     The length of the buffer to be written.
00097  *     returns short:       Actual number of characters written to the stream,
00098  *                                 -1 if an error occurred.
00099  */
00100 
00101 long WriteCharsToConsole(char *buffer, long n)
00102 {
00103        long size = 0;
00104        void* ptr = NULL;
00105 
00106        if (CWGetMemHandleSize(gPluginContext, mac_console_handle, &size) == noErr) {
00107               if (mac_console_count + n >= size) {
00108                      size += 8192;
00109                      if (CWResizeMemHandle(gPluginContext, mac_console_handle, size) != noErr)
00110                             return -1;
00111               }
00112        }
00113 
00114        if (CWLockMemHandle(gPluginContext, mac_console_handle, false, &ptr) == noErr) {
00115               BlockMoveData(buffer, (char *)ptr + mac_console_count, n);
00116               mac_console_count += n;
00117               CWUnlockMemHandle(gPluginContext, mac_console_handle);
00118        }
00119        
00120        return 0;
00121 }
00122 
00123 /*
00124  *     extern long ReadCharsFromConsole(char *buffer, long n);
00125  *
00126  *     Reads from the Console into a buffer.  This function is called by
00127  *     read.
00128  *
00129  *     char *buffer: Pointer to the buffer which will recieve the input.
00130  *     long n:                     The maximum amount of characters to be read (size of
00131  *                                 buffer).
00132  *     returns short:       Actual number of characters read from the stream,
00133  *                                 -1 if an error occurred.
00134  */
00135 
00136 long ReadCharsFromConsole(char *buffer, long n)
00137 {
00138        return 0;
00139 }