1 /*
2 * $Id: funcs.c,v 1.5 2000/08/10 21:02:50 danny Exp $
3 *
4 * Copyright � 1993 Free Software Foundation, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this software; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * This file contains descriptions of all the interactive functions
23 * built into oleo.
24 */
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #ifdef WITH_DMALLOC
30 #include <dmalloc.h>
31 #endif
32
33 #include "global.h"
34 #include "cmd.h"
35 #include "key.h"
36 #include "io-term.h"
37 #include "basic.h"
38 #include "format.h"
39 #include "print.h"
40 #include "font.h"
41 #include "io-x11.h"
42 #include "io-edit.h"
43 #include "regions.h"
44 #include "help.h"
45 #include "window.h"
46 #include "font.h"
47 #include "graph.h"
48 #include "lists.h"
49
50
51 /* This include builds the function table, doc strings, and FUNC_ARGS strings.
52 */
53 #include "defuns.h"
54
55
56 /* Returns 0 if the function is found.
57 * Also returns (through parameters) the vector and cmd_func.
58 * The output parameters can be NULL.
59 */
60
find_function(int * vec_out,struct cmd_func ** cmd_out,char * name,int len)61 int find_function (int * vec_out, struct cmd_func ** cmd_out, char * name, int len)
62 {
63 int vector;
64 struct cmd_func * cmd;
65 for (vector = 0; vector < num_funcs; vector++)
66 for (cmd = &the_funcs[vector][0]; cmd->func_name; cmd++)
67 if (!(strincmp (name, cmd->func_name, len) || cmd->func_name[len]))
68 {
69 if (vec_out)
70 *vec_out = vector;
71 if (cmd_out)
72 *cmd_out = cmd;
73 return 0;
74 }
75 return 1;
76 }
77
78 static struct cmd_func * named_macro_strings = 0;
79 static int num_named_macro_strings = 0;
80 static int named_macro_vec;
81
init_named_macro_strings(void)82 void init_named_macro_strings (void)
83 {
84 named_macro_strings =
85 (struct cmd_func *) ck_malloc (sizeof (struct cmd_func));
86 bzero (named_macro_strings, sizeof (struct cmd_func));
87 named_macro_vec = add_usr_cmds (named_macro_strings);
88 }
89
90
name_macro_string(char * name,char * str)91 void name_macro_string (char * name, char * str)
92 {
93 int i = num_named_macro_strings;
94 ++num_named_macro_strings;
95 named_macro_strings =
96 ((struct cmd_func *)
97 ck_realloc (named_macro_strings,
98 ((1 + num_named_macro_strings) * sizeof (struct cmd_func))));
99 the_funcs [named_macro_vec] = named_macro_strings;
100 bzero (named_macro_strings + num_named_macro_strings,
101 sizeof (struct cmd_func));
102 {
103 struct cmd_func * cf = &named_macro_strings [i];
104 cf->func_name = ck_savestr (name);
105 cf->func_func = run_string_as_macro;
106 cf->init_code = 0;
107 {
108 struct info_buffer * ib = find_or_make_info (name);
109 clear_info (ib);
110 print_info (ib, "Equivalent to %s.", str);
111 cf->func_doc = ib->text;
112 }
113 {
114 int i = 0;
115 cf->func_args = (char **)ck_malloc (3 * sizeof (char *));
116 cf->func_args [i++] = mk_sprintf ("=%s", str);
117 cf->func_args [i++] = "p";
118 cf->func_args [i++] = 0;
119 }
120 }
121 }
122
123