1 /*******************************************************************************
2  * Copyright (c) 2013-2021, Andrés Martinelli <andmarti@gmail.com>             *
3  * All rights reserved.                                                        *
4  *                                                                             *
5  * This file is a part of SC-IM                                                *
6  *                                                                             *
7  * SC-IM is a spreadsheet program that is based on SC. The original authors    *
8  * of SC are James Gosling and Mark Weiser, and mods were later added by       *
9  * Chuck Martin.                                                               *
10  *                                                                             *
11  * Redistribution and use in source and binary forms, with or without          *
12  * modification, are permitted provided that the following conditions are met: *
13  * 1. Redistributions of source code must retain the above copyright           *
14  *    notice, this list of conditions and the following disclaimer.            *
15  * 2. Redistributions in binary form must reproduce the above copyright        *
16  *    notice, this list of conditions and the following disclaimer in the      *
17  *    documentation and/or other materials provided with the distribution.     *
18  * 3. All advertising materials mentioning features or use of this software    *
19  *    must display the following acknowledgement:                              *
20  *    This product includes software developed by Andrés Martinelli            *
21  *    <andmarti@gmail.com>.                                                    *
22  * 4. Neither the name of the Andrés Martinelli nor the                        *
23  *   names of other contributors may be used to endorse or promote products    *
24  *   derived from this software without specific prior written permission.     *
25  *                                                                             *
26  * THIS SOFTWARE IS PROVIDED BY ANDRES MARTINELLI ''AS IS'' AND ANY            *
27  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED   *
28  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE      *
29  * DISCLAIMED. IN NO EVENT SHALL ANDRES MARTINELLI BE LIABLE FOR ANY           *
30  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  *
31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;*
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
33  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  *
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE       *
35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           *
36  *******************************************************************************/
37 
38 /**
39  * \file macros.h
40  * \author Andrés Martinelli <andmarti@gmail.com>
41  * \date 2017-07-18
42  * \brief Header file for cros.c
43  */
44 
45 #define BUFFERSIZE      1024   // must be higher than MAX_IB_LEN
46 #define MAX_IB_LEN       512   // max input bar length
47 
48 #define MAX_MULTIPLIER   100
49 #define MAXSC            15    // MAXSC is the max length of a special key expressed as a string. ex. <C-a>
50 #define MAXMAPITEM       (MAXSC * 20) // max length of mapping part (in / out)
51 
52 #define TIMEOUT_CURSES   300   // ms  curses input timeout
53 #define COMPLETECMDTIMEOUT     (get_conf_int("command_timeout")/4)     // used for goto cell
54 #define ESC_DELAY        25    // Escape timeout
55 #define RESCOL           4     // columns reserved for row numbers
56 #define RESROW           2     // rows reserved for prompt, error, and column numbers
57 #define RESCOLHEADER     1     // number of row to show column header. always 1. just to make code cleaner
58 
59 #define NORMAL_MODE      0x01
60 #define INSERT_MODE      0x02
61 #define EDIT_MODE        0x04
62 #define COMMAND_MODE     0x08
63 #define VISUAL_MODE      0x16
64 
65 #define ctl(x)           ((x) & 0x1f)
66 #define uncl(x)           (0x60 | ((x) & 0x1f))
67 #define OKEY_ESC         '\033'
68 #define OKEY_TAB         '\011'
69 #define OKEY_ENTER       10
70 #define OKEY_SPACE       L' '
71 #define OKEY_LEFT        0x104
72 #define OKEY_RIGHT       0x105
73 #define OKEY_DOWN        0x102
74 #define OKEY_UP          0x103
75 #define OKEY_DEL         0x14a
76 #define OKEY_BS          0x107
77 #define OKEY_BS2         0x7f   // some BSDs, Linux distros, SSH/tmux configs
78 #define OKEY_HOME        0x106
79 #define OKEY_END         0x168
80 #define OKEY_PGUP        0x153
81 #define OKEY_PGDOWN      0x152
82 #define OKEY_F(x)        KEY_F(x)
83 
84 //#define metak(x) ((x) | 0x80)
85 #define LEFT             0
86 #define RIGHT            1
87 
88 // used for is_single_command function
89 #define NO_CMD           0
90 #define EDITION_CMD      1
91 #define MOVEMENT_CMD     2
92 
93 #define HEADINGS          0
94 #define WELCOME           1
95 #define CELL_SELECTION    2
96 #define CELL_SELECTION_SC 3
97 #define NUMB              4
98 #define STRG              5
99 #define DATEF             6
100 #define EXPRESSION        7
101 #define INFO_MSG          8
102 #define ERROR_MSG         9
103 #define MODE              10
104 #define CELL_ID           11
105 #define CELL_FORMAT       12
106 #define CELL_CONTENT      13
107 #define INPUT             14
108 #define NORMAL            15
109 #define CELL_ERROR        16
110 #define CELL_NEGATIVE     17
111 #define DEFAULT           18
112 #define DEBUG_MSG         19
113 #define VALUE_MSG         20
114 #define GRID_EVEN         21
115 #define GRID_ODD          22
116 #define HEADINGS_ODD      23
117 #define HELP_HIGHLIGHT    24
118 
119 void ui_sc_msg(char * s, int type, ...);
120 #define sc_error(x, ...)     ui_sc_msg(x, ERROR_MSG, ##__VA_ARGS__)
121 #define sc_debug(x, ...)     ui_sc_msg(x, DEBUG_MSG, ##__VA_ARGS__)
122 #define sc_info(x, ...)      ui_sc_msg(x, INFO_MSG, ##__VA_ARGS__)
123 #define sc_value(x, ...)     ui_sc_msg(x, VALUE_MSG, ##__VA_ARGS__)
124 
125 #define RUNTIME ((current_tv.tv_sec - startup_tv.tv_sec) * 1000L + (current_tv.tv_usec - startup_tv.tv_usec) / 1000L)
126