Utils 6.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
15 16 17 18 19 20 21 22 23
/***************************************************/
/* File   : Utils.h                                */
/*                                                 */
/* Purpose: Infrequently altered utilities.        */
/*                                                 */
/* Author : A.D.Hodgkinson                         */
/*                                                 */
/* History: 18-Oct-96: Created.                    */
/***************************************************/
24

25 26 27 28 29 30 31
/* Known error numbers */

#define Utils_Error_OS_Escape      17              /* Offers only 'Continue'      */
#define Utils_Error_Custom_Normal  (1u<<30)        /* Offers 'Continue' and 'Quit */
#define Utils_Error_Custom_Fatal   ((1u<<30) + 1)  /* Offers only 'Quit'          */
#define Utils_Error_Custom_Message ((1u<<30) + 2)  /* Offers only 'Continue'      */

32 33 34
/* Useful macros */

#define Beep          (_swi(0x107,0))
35
#define Swap(a,b)     { (a) ^= (b); (b) ^= (a); (a) ^= (b); }
36 37 38 39
#define StrNCpy0(x,y) {strncpy(x,y,sizeof(x)-1); x[sizeof(x)-1]=0;}
#define WordAlign(a)  (void *) ((((unsigned int) (a)) + (sizeof(int) - 1)) & (~(sizeof(int) - 1)))

#define ChkError(e)   (show_error_cont(e))
40
#define RetError(fn)  {_kernel_oserror * e = (fn); if (e) return e;}
41
#define RetLastE      {erb = *_kernel_last_oserror(); return &erb;}
42
#define RetWarnE(e)   {if (&erb != (e)) erb = *(e); erb.errnum = Utils_Error_Custom_Message; return &erb;}
43

44
/* Function prototypes */
45 46 47

char            * lookup_token                     (char * s, int flag, char * arg);
char            * lookup_choice                    (char * s, int flag, char * arg);
48
char            * lookup_control                   (char * s, int flag, char * arg);
49 50 51 52 53 54

void              show_error                       (_kernel_oserror * e);
void              show_error_cont                  (_kernel_oserror * e);
void              show_error_ret                   (_kernel_oserror * e);
int               report_toolbox_error             (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);

55 56 57 58
_kernel_oserror * make_no_fetch_memory_error       (int stage);
_kernel_oserror * make_no_cont_memory_error        (int stage);
_kernel_oserror * make_no_table_memory_error       (int stage);
_kernel_oserror * make_no_memory_error             (int stage);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

void              show_centred                     (ObjectId o);
_kernel_oserror * set_corrected_extent             (unsigned int f, ObjectId o, BBox * w);
int               find_behind                      (int w);
_kernel_oserror * find_tool_sizes                  (int * theight, int * hheight, int * vwidth);

void              register_null_claimant           (int eventcode, WimpEventHandler * handler, browser_data * handle);
void              deregister_null_claimant         (int eventcode, WimpEventHandler * handler, browser_data * handle);

BBox            * intersection                     (BBox * a, BBox * b);
BBox            * set_graphics_intersection        (BBox * rbox, BBox * cbox);
void              restore_graphics_intersection    (BBox * cbox);

void              read_os_to_points                (void);
void              convert_pair_to_os               (int x, int y, int * osx, int * osy);
void              convert_pair_to_points           (int x, int y, int * mpx, int * mpy);
void              convert_to_os                    (int x, int * osx);
void              convert_to_points                (int x, int * mpx);
void              convert_box_to_os                (const BBox * mp, BBox * os);
void              convert_box_to_points            (const BBox * os, BBox * mp);

_kernel_oserror * read_sprite_size                 (char * name, int * width, int * height);
81
_kernel_oserror * utils_text_width                 (char * text, int * width, int scan);
82 83 84 85 86 87 88 89 90 91 92 93 94
_kernel_oserror * set_gadget_state                 (ObjectId o, ComponentId c, int grey_state);

void              anti_twitter                     (WimpRedrawWindowBlock * r);

int               adjust                           (void);

int               hide_gadget                      (ObjectId o, ComponentId c);
int               show_gadget                      (ObjectId o, ComponentId c);
int               gadget_hidden                    (ObjectId o, ComponentId c);
void              slab_gadget                      (ObjectId o, ComponentId c);
void              slab_gadget_in                   (ObjectId o, ComponentId c);
void              slab_gadget_out                  (ObjectId o, ComponentId c);

95 96 97
ObjectId          utils_check_caret_restoration    (ObjectId window_id);
_kernel_oserror * utils_restore_caret              (ObjectId window_id);

98 99 100 101 102 103
_kernel_oserror * copy_toolaction_info             (ObjectId src_o, ComponentId src_c, ObjectId dst_o, ComponentId dst_c);
_kernel_oserror * set_window_flags                 (int window_handle, unsigned int clear_word, unsigned int eor_word);

int               debounce_keypress                (void);

int               task_from_window                 (int window_handle);
104
_kernel_oserror * utils_browser_from_window        (int window_handle, browser_data ** browser);
105
int               is_known_browser                 (browser_data * b);
106 107

browser_data    * utils_parent                     (browser_data * b);
108
browser_data    * utils_ancestor                   (browser_data * b);
109 110

int               encode_base64                    (const char * in, int len, char * out);
111
int               utils_strcasecmp                 (const char * a, const char * b);
112
int               utils_strncasecmp                (const char * a, const char * b, unsigned int n);
113
int               utils_len_printf                 (const char * format, ...);
114
int               utils_number_length              (int number);
115
unsigned int      utils_return_hash                (const char * s);
116

117 118
_kernel_oserror * utils_get_task_handle            (const char * task_to_get, unsigned int * found_handle);
_kernel_oserror * utils_stop_proxy                 (void);
119
void              utils_build_user_agent_string    (int netscape, char * buffer, int buffer_size);
120 121

int               utils_check_scrap                (void);
122 123
_kernel_oserror * utils_canonicalise_path          (const char * in, char ** out);
_kernel_oserror * utils_build_tree                 (const char * path);