Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * global.c * |
| 3 | * * |
| 4 | * Copyright (C) 1999 Chris Allegretta * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 1, or (at your option) * |
| 8 | * any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the Free Software * |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 18 | * * |
| 19 | **************************************************************************/ |
| 20 | |
| 21 | #include <sys/stat.h> |
| 22 | #include "config.h" |
| 23 | #include "nano.h" |
| 24 | #include "proto.h" |
| 25 | |
| 26 | #ifndef NANO_SMALL |
| 27 | #include <libintl.h> |
| 28 | #define _(string) gettext(string) |
| 29 | #else |
| 30 | #define _(string) (string) |
| 31 | #endif |
| 32 | |
| 33 | /* |
| 34 | * Global variables |
| 35 | */ |
| 36 | int flags = 0; /* Our new flag containig many options */ |
| 37 | int center_x = 0, center_y = 0; /* Center of screen */ |
| 38 | WINDOW *edit; /* The file portion of the editor */ |
| 39 | WINDOW *topwin; /* Top line of screen */ |
| 40 | WINDOW *bottomwin; /* Bottom buffer */ |
| 41 | char *filename; /* Name of the file */ |
| 42 | int editwinrows = 0; /* How many rows long is the edit |
| 43 | window? */ |
| 44 | filestruct *current; /* Current buffer pointer */ |
| 45 | int current_x = 0, current_y = 0; /* Current position of X and Y in |
| 46 | the editor - relative to edit |
| 47 | window (0,0) */ |
| 48 | filestruct *fileage = NULL; /* Our file buffer */ |
| 49 | filestruct *edittop = NULL; /* Pointer to the top of the edit |
| 50 | buffer with respect to the |
| 51 | file struct */ |
| 52 | filestruct *editbot = NULL; /* Same for the bottom */ |
| 53 | filestruct *filebot = NULL; /* Last node in the file struct */ |
| 54 | filestruct *cutbuffer = NULL; /* A place to store cut text */ |
| 55 | |
| 56 | char *answer; /* Answer str to many questions */ |
| 57 | int totlines = 0; /* Total number of lines in the file */ |
| 58 | int totsize = 0; /* Total number of bytes in the file */ |
| 59 | int placewewant = 0; /* The collum we'd like the cursor |
| 60 | to jump to when we go to the |
| 61 | next or previous line */ |
| 62 | |
| 63 | char *hblank; /* A horizontal blank line */ |
| 64 | char *help_text; /* The text in the help window */ |
| 65 | |
| 66 | /* More stuff for the marker select */ |
| 67 | |
| 68 | filestruct *mark_beginbuf; /* the begin marker buffer */ |
| 69 | int mark_beginx; /* X value in the string to start */ |
| 70 | |
| 71 | shortcut main_list[MAIN_LIST_LEN]; |
| 72 | shortcut whereis_list[WHEREIS_LIST_LEN]; |
| 73 | shortcut replace_list[REPLACE_LIST_LEN]; |
| 74 | shortcut goto_list[GOTO_LIST_LEN]; |
| 75 | shortcut writefile_list[WRITEFILE_LIST_LEN]; |
| 76 | shortcut help_list[HELP_LIST_LEN]; |
| 77 | shortcut spell_list[SPELL_LIST_LEN]; |
| 78 | |
Chris Allegretta | 9fc8d43 | 2000-07-07 01:49:52 +0000 | [diff] [blame^] | 79 | /* Regular expressions */ |
| 80 | |
| 81 | regex_t search_regexp; /* Global to store compiled search regexp */ |
| 82 | regmatch_t regmatches[10]; /* Match positions for parenthetical |
| 83 | subexpressions, max of 10 */ |
| 84 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 85 | /* Initialize a struct *without* our lovely braces =( */ |
| 86 | void sc_init_one(shortcut * s, int key, char *desc, char *help, int alt, |
| 87 | int misc1, int misc2, int view, int (*func) (void)) |
| 88 | { |
| 89 | s->val = key; |
| 90 | s->desc = desc; |
| 91 | s->help = help; |
| 92 | s->altval = alt; |
| 93 | s->misc1 = misc1; |
| 94 | s->misc2 = misc2; |
| 95 | s->viewok = view; |
| 96 | s->func = func; |
| 97 | } |
| 98 | |
| 99 | void shortcut_init(void) |
| 100 | { |
| 101 | char *nano_help_msg = "", *nano_writeout_msg = "", *nano_exit_msg = "", |
| 102 | *nano_goto_msg = "", *nano_justify_msg = "", *nano_replace_msg = |
| 103 | "", *nano_insert_msg = "", *nano_whereis_msg = |
| 104 | "", *nano_prevpage_msg = "", *nano_nextpage_msg = |
| 105 | "", *nano_cut_msg = "", *nano_uncut_msg = "", *nano_cursorpos_msg = |
| 106 | "", *nano_spell_msg = "", *nano_up_msg = "", *nano_down_msg = |
| 107 | "", *nano_forward_msg = "", *nano_back_msg = "", *nano_home_msg = |
| 108 | "", *nano_end_msg = "", *nano_firstline_msg = |
| 109 | "", *nano_lastline_msg = "", *nano_refresh_msg = |
| 110 | "", *nano_mark_msg = "", *nano_delete_msg = |
| 111 | "", *nano_backspace_msg = "", *nano_tab_msg = |
| 112 | "", *nano_enter_msg = "", *nano_case_msg = |
| 113 | "", *nano_cancel_msg = ""; |
| 114 | |
| 115 | #ifndef NANO_SMALL |
| 116 | nano_help_msg = _("Invoke the help menu"); |
| 117 | nano_writeout_msg = _("Write the current file to disk"); |
| 118 | nano_exit_msg = _("Exit from nano"); |
| 119 | nano_goto_msg = _("Goto a specific line number"); |
| 120 | nano_justify_msg = _("Justify the current paragraph"); |
| 121 | nano_replace_msg = _("Replace text within the editor"); |
| 122 | nano_insert_msg = _("Insert another file into the current one"); |
| 123 | nano_whereis_msg = _("Search for text within the editor"); |
| 124 | nano_prevpage_msg = _("Move to the previous screen"); |
| 125 | nano_nextpage_msg = _("Move to the next screen"); |
| 126 | nano_cut_msg = _("Cut the current line and store it in the cutbuffer"); |
| 127 | nano_uncut_msg = _("Uncut from the cutbuffer into the current line"); |
| 128 | nano_cursorpos_msg = _("Show the posititon of the cursor"); |
| 129 | nano_spell_msg = _("Invoke the spell checker (if available)"); |
| 130 | nano_up_msg = _("Move up one line"); |
| 131 | nano_down_msg = _("Move down one line"); |
| 132 | nano_forward_msg = _("Move forward one character"); |
| 133 | nano_back_msg = _("Move back one character"); |
| 134 | nano_home_msg = _("Move to the beginning of the current line"); |
| 135 | nano_end_msg = _("Move to the end of the current line"); |
| 136 | nano_firstline_msg = _("Go to the first line of the file"); |
| 137 | nano_lastline_msg = _("Go to the last line of the file"); |
| 138 | nano_refresh_msg = _("Refresh (redraw) the current screen"); |
| 139 | nano_mark_msg = _("Mark text at the current cursor location"); |
| 140 | nano_delete_msg = _("Delete the character under the cursor"); |
| 141 | nano_backspace_msg = |
| 142 | _("Delete the character to the left of the cursor"); |
| 143 | nano_tab_msg = _("Insert a tab character"); |
| 144 | nano_enter_msg = _("Insert a carriage return at the cursor position"); |
| 145 | nano_case_msg = |
| 146 | _("Make the current search or replace case (in)sensitive"); |
| 147 | nano_cancel_msg = _("Cancel the current function"); |
| 148 | #endif |
| 149 | |
| 150 | |
| 151 | if (ISSET(PICO_MSGS)) |
| 152 | sc_init_one(&main_list[0], NANO_HELP_KEY, _("Get Help"), |
| 153 | nano_help_msg, 0, 0, 0, VIEW, do_help); |
| 154 | else |
| 155 | sc_init_one(&main_list[0], NANO_WRITEOUT_KEY, _("WriteOut"), |
| 156 | nano_writeout_msg, |
| 157 | 0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void); |
| 158 | |
| 159 | sc_init_one(&main_list[1], NANO_EXIT_KEY, _("Exit"), |
| 160 | nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit); |
| 161 | |
| 162 | if (ISSET(PICO_MSGS)) |
| 163 | sc_init_one(&main_list[2], NANO_WRITEOUT_KEY, _("WriteOut"), |
| 164 | nano_writeout_msg, |
| 165 | 0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void); |
| 166 | else |
| 167 | sc_init_one(&main_list[2], NANO_GOTO_KEY, _("Goto Line"), |
| 168 | nano_goto_msg, |
| 169 | NANO_ALT_G, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void); |
| 170 | |
| 171 | if (ISSET(PICO_MSGS)) |
| 172 | sc_init_one(&main_list[3], NANO_JUSTIFY_KEY, _("Justify"), |
| 173 | nano_justify_msg, 0, 0, 0, NOVIEW, do_justify); |
| 174 | else |
| 175 | sc_init_one(&main_list[3], NANO_REPLACE_KEY, _("Replace"), |
| 176 | nano_replace_msg, |
| 177 | NANO_ALT_R, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace); |
| 178 | |
| 179 | sc_init_one(&main_list[4], NANO_INSERTFILE_KEY, _("Read File"), |
| 180 | nano_insert_msg, |
| 181 | 0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile); |
| 182 | |
| 183 | sc_init_one(&main_list[5], NANO_WHEREIS_KEY, _("Where Is"), |
| 184 | nano_whereis_msg, |
| 185 | 0, NANO_WHEREIS_FKEY, 0, VIEW, do_search); |
| 186 | |
| 187 | sc_init_one(&main_list[6], NANO_PREVPAGE_KEY, _("Prev Page"), |
| 188 | nano_prevpage_msg, |
| 189 | 0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, page_up); |
| 190 | |
| 191 | sc_init_one(&main_list[7], NANO_NEXTPAGE_KEY, _("Next Page"), |
| 192 | nano_nextpage_msg, |
| 193 | 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, page_down); |
| 194 | |
| 195 | sc_init_one(&main_list[8], NANO_CUT_KEY, _("Cut Text"), |
| 196 | nano_cut_msg, 0, NANO_CUT_FKEY, 0, NOVIEW, do_cut_text); |
| 197 | |
| 198 | sc_init_one(&main_list[9], NANO_UNCUT_KEY, _("UnCut Txt"), |
| 199 | nano_uncut_msg, |
| 200 | 0, NANO_UNCUT_FKEY, 0, NOVIEW, do_uncut_text); |
| 201 | |
| 202 | sc_init_one(&main_list[10], NANO_CURSORPOS_KEY, _("Cur Pos"), |
| 203 | nano_cursorpos_msg, |
| 204 | 0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos); |
| 205 | |
| 206 | sc_init_one(&main_list[11], NANO_SPELL_KEY, _("To Spell"), |
| 207 | nano_spell_msg, 0, NANO_SPELL_FKEY, 0, NOVIEW, do_spell); |
| 208 | |
| 209 | |
| 210 | sc_init_one(&main_list[12], NANO_UP_KEY, _("Up"), |
| 211 | nano_up_msg, 0, KEY_UP, 0, VIEW, do_up); |
| 212 | |
| 213 | sc_init_one(&main_list[13], NANO_DOWN_KEY, _("Down"), |
| 214 | nano_down_msg, 0, KEY_DOWN, 0, VIEW, do_down); |
| 215 | |
| 216 | sc_init_one(&main_list[14], NANO_FORWARD_KEY, _("Forward"), |
| 217 | nano_forward_msg, 0, KEY_RIGHT, 0, VIEW, do_right); |
| 218 | |
| 219 | sc_init_one(&main_list[15], NANO_BACK_KEY, _("Back"), |
| 220 | nano_back_msg, 0, KEY_LEFT, 0, VIEW, do_left); |
| 221 | |
| 222 | sc_init_one(&main_list[16], NANO_HOME_KEY, _("Home"), |
| 223 | nano_home_msg, 0, KEY_HOME, 362, VIEW, do_home); |
| 224 | |
| 225 | sc_init_one(&main_list[17], NANO_END_KEY, _("End"), |
| 226 | nano_end_msg, 0, KEY_END, 385, VIEW, do_end); |
| 227 | |
| 228 | sc_init_one(&main_list[18], NANO_REFRESH_KEY, _("Refresh"), |
| 229 | nano_refresh_msg, 0, 0, 0, VIEW, total_refresh); |
| 230 | |
| 231 | sc_init_one(&main_list[19], NANO_MARK_KEY, _("Mark Text"), |
| 232 | nano_mark_msg, 0, 0, 0, NOVIEW, do_mark); |
| 233 | |
| 234 | sc_init_one(&main_list[20], NANO_DELETE_KEY, _("Delete"), |
| 235 | nano_delete_msg, 0, KEY_DC, |
| 236 | NANO_CONTROL_D, NOVIEW, do_delete); |
| 237 | |
| 238 | sc_init_one(&main_list[21], NANO_BACKSPACE_KEY, _("Backspace"), |
| 239 | nano_backspace_msg, 0, |
| 240 | KEY_BACKSPACE, 127, NOVIEW, do_backspace); |
| 241 | |
| 242 | sc_init_one(&main_list[22], NANO_TAB_KEY, _("Tab"), |
| 243 | nano_tab_msg, 0, 0, 0, NOVIEW, do_tab); |
| 244 | |
| 245 | if (ISSET(PICO_MSGS)) |
| 246 | sc_init_one(&main_list[23], NANO_REPLACE_KEY, _("Replace"), |
| 247 | nano_replace_msg, |
| 248 | NANO_ALT_R, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace); |
| 249 | else |
| 250 | sc_init_one(&main_list[23], NANO_JUSTIFY_KEY, _("Justify"), |
| 251 | nano_justify_msg, 0, 0, 0, NOVIEW, do_justify); |
| 252 | |
| 253 | sc_init_one(&main_list[24], NANO_ENTER_KEY, _("Enter"), |
| 254 | nano_enter_msg, |
| 255 | 0, KEY_ENTER, NANO_CONTROL_M, NOVIEW, do_enter_void); |
| 256 | |
| 257 | if (ISSET(PICO_MSGS)) |
| 258 | sc_init_one(&main_list[25], NANO_GOTO_KEY, _("Goto Line"), |
| 259 | nano_goto_msg, |
| 260 | NANO_ALT_G, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void); |
| 261 | else |
| 262 | sc_init_one(&main_list[25], NANO_HELP_KEY, _("Get Help"), |
| 263 | nano_help_msg, 0, 0, 0, VIEW, do_help); |
| 264 | |
| 265 | |
| 266 | sc_init_one(&whereis_list[0], NANO_FIRSTLINE_KEY, _("First Line"), |
| 267 | nano_firstline_msg, 0, 0, 0, VIEW, do_first_line); |
| 268 | |
| 269 | sc_init_one(&whereis_list[1], NANO_LASTLINE_KEY, _("Last Line"), |
| 270 | nano_lastline_msg, 0, 0, 0, VIEW, do_last_line); |
| 271 | |
| 272 | sc_init_one(&whereis_list[2], NANO_CASE_KEY, _("Case Sens"), |
| 273 | nano_case_msg, 0, 0, 0, VIEW, 0); |
| 274 | |
| 275 | |
Chris Allegretta | 715e7dd | 2000-06-30 20:35:26 +0000 | [diff] [blame] | 276 | sc_init_one(&whereis_list[3], NANO_OTHERSEARCH_KEY, _("Replace"), |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 277 | nano_replace_msg, 0, 0, 0, VIEW, do_replace); |
| 278 | |
Chris Allegretta | 8c2b40f | 2000-06-29 01:30:04 +0000 | [diff] [blame] | 279 | sc_init_one(&whereis_list[4], NANO_FROMSEARCHTOGOTO_KEY, _("Goto Line"), |
| 280 | nano_goto_msg, 0, 0, 0, VIEW, do_gotoline_void); |
| 281 | |
| 282 | sc_init_one(&whereis_list[5], NANO_CANCEL_KEY, _("Cancel"), |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 283 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 284 | |
| 285 | |
| 286 | sc_init_one(&replace_list[0], NANO_FIRSTLINE_KEY, _("First Line"), |
| 287 | nano_firstline_msg, 0, 0, 0, VIEW, do_first_line); |
| 288 | |
| 289 | sc_init_one(&replace_list[1], NANO_LASTLINE_KEY, _("Last Line"), |
| 290 | nano_lastline_msg, 0, 0, 0, VIEW, do_last_line); |
| 291 | |
| 292 | sc_init_one(&replace_list[2], NANO_CASE_KEY, _("Case Sens"), |
| 293 | nano_case_msg, 0, 0, 0, VIEW, 0); |
| 294 | |
Chris Allegretta | 8c2b40f | 2000-06-29 01:30:04 +0000 | [diff] [blame] | 295 | sc_init_one(&replace_list[3], NANO_OTHERSEARCH_KEY, _("No Replace"), |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 296 | nano_whereis_msg, 0, 0, 0, VIEW, do_search); |
| 297 | |
Chris Allegretta | 8c2b40f | 2000-06-29 01:30:04 +0000 | [diff] [blame] | 298 | sc_init_one(&replace_list[4], NANO_FROMSEARCHTOGOTO_KEY, _("Goto Line"), |
| 299 | nano_goto_msg, 0, 0, 0, VIEW, do_gotoline_void); |
| 300 | |
| 301 | sc_init_one(&replace_list[5], NANO_CANCEL_KEY, _("Cancel"), |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 302 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 303 | |
| 304 | |
| 305 | sc_init_one(&goto_list[0], NANO_FIRSTLINE_KEY, _("First Line"), |
| 306 | nano_firstline_msg, 0, 0, 0, VIEW, &do_first_line); |
| 307 | |
| 308 | sc_init_one(&goto_list[1], NANO_LASTLINE_KEY, _("Last Line"), |
| 309 | nano_lastline_msg, 0, 0, 0, VIEW, &do_last_line); |
| 310 | |
| 311 | sc_init_one(&goto_list[2], NANO_CANCEL_KEY, _("Cancel"), |
| 312 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 313 | |
| 314 | |
| 315 | sc_init_one(&help_list[0], NANO_PREVPAGE_KEY, _("Prev Page"), |
| 316 | nano_prevpage_msg, |
| 317 | 0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, page_up); |
| 318 | |
| 319 | sc_init_one(&help_list[1], NANO_NEXTPAGE_KEY, _("Next Page"), |
| 320 | nano_nextpage_msg, |
| 321 | 0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, page_down); |
| 322 | |
| 323 | sc_init_one(&help_list[2], NANO_EXIT_KEY, _("Exit"), |
| 324 | nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit); |
| 325 | |
| 326 | |
| 327 | sc_init_one(&writefile_list[0], NANO_CANCEL_KEY, _("Cancel"), |
| 328 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 329 | |
| 330 | |
| 331 | sc_init_one(&writefile_list[0], NANO_CANCEL_KEY, _("Cancel"), |
| 332 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 333 | |
| 334 | sc_init_one(&spell_list[0], NANO_HELP_KEY, _("Get Help"), |
| 335 | nano_help_msg, 0, 0, 0, VIEW, do_help); |
| 336 | |
| 337 | sc_init_one(&spell_list[1], NANO_CANCEL_KEY, _("Cancel"), |
| 338 | nano_cancel_msg, 0, 0, 0, VIEW, 0); |
| 339 | |
| 340 | } |