buffer.c (most-5.1.0) | : | buffer.c (most-5.2.0) | ||
---|---|---|---|---|
/* | /* | |||
This file is part of MOST. | This file is part of MOST. | |||
Copyright (c) 1991, 1999, 2002, 2005-2018, 2019 John E. Davis | Copyright (c) 1991, 1999, 2002, 2005-2021, 2022 John E. Davis | |||
This program is free software; you can redistribute it and/or modify it | This program is free software; you can redistribute it and/or modify it | |||
under the terms of the GNU General Public License as published by the Free | under the terms of the GNU General Public License as published by the Free | |||
Software Foundation; either version 2 of the License, or (at your option) | Software Foundation; either version 2 of the License, or (at your option) | |||
any later version. | any later version. | |||
This program is distributed in the hope that it will be useful, but WITHOUT | This program is distributed in the hope that it will be useful, but WITHOUT | |||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |||
more details. | more details. | |||
skipping to change at line 39 | skipping to change at line 39 | |||
#include <slang.h> | #include <slang.h> | |||
#include "jdmacros.h" | #include "jdmacros.h" | |||
#include "most.h" | #include "most.h" | |||
#include "buffer.h" | #include "buffer.h" | |||
#include "display.h" | #include "display.h" | |||
#include "window.h" | #include "window.h" | |||
#include "line.h" | #include "line.h" | |||
#include "file.h" | #include "file.h" | |||
#include "color.h" | ||||
int Most_W_Opt = 0; | int Most_W_Opt = 0; | |||
unsigned char *Most_Beg; /* beginning of current buffer */ | unsigned char *Most_Beg; /* beginning of current buffer */ | |||
unsigned char *Most_Eob; /* end of current buffer */ | unsigned char *Most_Eob; /* end of current buffer */ | |||
Most_Buffer_Type *Most_Buf; | Most_Buffer_Type *Most_Buf; | |||
MOST_INT Most_Num_Lines; | MOST_INT Most_Num_Lines; | |||
skipping to change at line 105 | skipping to change at line 106 | |||
while ((pos > Most_Beg) | while ((pos > Most_Beg) | |||
&& (*pos == '\n')) pos--; | && (*pos == '\n')) pos--; | |||
pos += 2; | pos += 2; | |||
if (pos > cpos) pos = cpos; | if (pos > cpos) pos = cpos; | |||
return pos; | return pos; | |||
} | } | |||
/* does not move point */ | /* does not move point */ | |||
static unsigned char *end_of_line1(void) | static unsigned char *end_of_line1(void) | |||
{ | { | |||
register unsigned char *pos, *pmax; | unsigned char *pos, *pmax; | |||
int n, n2; | MOST_INT n, n2; | |||
pos = Most_Beg + Most_C_Offset; | pos = Most_Beg + Most_C_Offset; | |||
pmax = Most_Eob; | pmax = Most_Eob; | |||
if (pos >= pmax) return pmax; | if (pos >= pmax) return pmax; | |||
/* find the first '\n'. If we are wrapping lines, then do not go more | /* find the first '\n'. If we are wrapping lines, then do not go more | |||
* than 3 times the display width. | * than 3 times the display width. | |||
*/ | */ | |||
if (Most_W_Opt && SLtt_Screen_Cols) | if (Most_W_Opt && SLtt_Screen_Cols) | |||
{ | { | |||
skipping to change at line 168 | skipping to change at line 169 | |||
if (pos == Most_Eob) return pos; | if (pos == Most_Eob) return pos; | |||
if (pos != Most_Beg) pos--; | if (pos != Most_Beg) pos--; | |||
return pos; | return pos; | |||
/* if (pos == Most_Eob) return (pos - 1); | /* if (pos == Most_Eob) return (pos - 1); | |||
return pos; */ | return pos; */ | |||
} | } | |||
unsigned char *most_beg_of_line(void) | unsigned char *most_beg_of_line(void) | |||
{ | { | |||
unsigned char *b; | unsigned char *b; | |||
unsigned int ncols; | ||||
unsigned char *e; | unsigned char *e; | |||
MOST_UINT ncols; | ||||
if (Most_W_Opt == 0) return beg_of_line1(); | if (Most_W_Opt == 0) return beg_of_line1(); | |||
b = beg_of_line1 (); | b = beg_of_line1 (); | |||
e = end_of_line1 (); | e = end_of_line1 (); | |||
ncols = SLtt_Screen_Cols; | ncols = SLtt_Screen_Cols; | |||
if (Most_Show_Wrap_Marker) | if (Most_Show_Wrap_Marker) | |||
ncols--; | ncols--; | |||
while (1) | while (1) | |||
{ | { | |||
skipping to change at line 196 | skipping to change at line 197 | |||
b = next_b; | b = next_b; | |||
} | } | |||
return b; | return b; | |||
} | } | |||
static unsigned char *end_of_line (unsigned char *b) | static unsigned char *end_of_line (unsigned char *b) | |||
{ | { | |||
unsigned char *e, *b1; | unsigned char *e, *b1; | |||
int ncols; | MOST_UINT ncols; | |||
e = end_of_line1(); | e = end_of_line1(); | |||
if (Most_W_Opt == 0) | if (Most_W_Opt == 0) | |||
return e; | return e; | |||
if (b == NULL) b = most_beg_of_line (); | if (b == NULL) b = most_beg_of_line (); | |||
ncols = SLtt_Screen_Cols; | ncols = SLtt_Screen_Cols; | |||
if (Most_Show_Wrap_Marker) | if (Most_Show_Wrap_Marker) | |||
ncols--; | ncols--; | |||
skipping to change at line 230 | skipping to change at line 231 | |||
if ((b1 <= e) | if ((b1 <= e) | |||
&& (b1 < Most_Eob)) | && (b1 < Most_Eob)) | |||
{ | { | |||
if (*b1 == '\n') | if (*b1 == '\n') | |||
b = b1; | b = b1; | |||
else if ((*b1 == 033) && (Most_V_Opt == 0)) | else if ((*b1 == 033) && (Most_V_Opt == 0)) | |||
{ | { | |||
unsigned char ch = 033; | unsigned char ch = 033; | |||
b1++; | b1++; | |||
while ((ch == 033) && (b1 < e) && (b1 < Most_Eob) | while ((ch == 033) && (b1 < e) && (b1 < Most_Eob) | |||
&& (0 == most_parse_color_escape (&b1, e, NULL))) | && (0 == most_parse_color_escape (&b1, e, NULL, NULL))) | |||
{ | { | |||
b = b1; | b = b1; | |||
ch = *b1++; | ch = *b1++; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
return b; | return b; | |||
} | } | |||
skipping to change at line 422 | skipping to change at line 423 | |||
int most_extract_line(unsigned char **beg, unsigned char **end) | int most_extract_line(unsigned char **beg, unsigned char **end) | |||
{ | { | |||
*beg = most_beg_of_line(); | *beg = most_beg_of_line(); | |||
*end = end_of_line (*beg); | *end = end_of_line (*beg); | |||
return 0; | return 0; | |||
} | } | |||
MOST_INT most_what_line(unsigned char *pos) | MOST_INT most_what_line(unsigned char *pos) | |||
{ | { | |||
unsigned int save_pos; | MOST_UINT save_pos; | |||
MOST_INT save_line, dir; | MOST_INT save_line, dir; | |||
MOST_INT dif_c, dif_b,dif_t; | MOST_INT dif_c, dif_b,dif_t; | |||
int ret; | MOST_INT ret; | |||
if (Most_B_Opt) | if (Most_B_Opt) | |||
{ | { | |||
return (1 + (pos - Most_Beg)/16); | return (1 + (pos - Most_Beg)/16); | |||
} | } | |||
if (Most_Selective_Display) | if (Most_Selective_Display) | |||
{ | { | |||
return most_count_lines (Most_Beg, pos); | return most_count_lines (Most_Beg, pos); | |||
} | } | |||
skipping to change at line 511 | skipping to change at line 512 | |||
ret = Most_C_Line; | ret = Most_C_Line; | |||
Most_C_Offset = save_pos; | Most_C_Offset = save_pos; | |||
Most_C_Line = save_line; | Most_C_Line = save_line; | |||
return(ret); | return(ret); | |||
} | } | |||
/* given a buffer position, find the line and column */ | /* given a buffer position, find the line and column */ | |||
void most_find_row_column(unsigned char *pos, MOST_INT *r, MOST_INT *c) | void most_find_row_column(unsigned char *pos, MOST_INT *r, MOST_INT *c) | |||
{ | { | |||
unsigned int save_offset; | MOST_UINT save_offset; | |||
MOST_INT save_line; | MOST_INT save_line; | |||
if (pos <= Most_Beg) | if (pos <= Most_Beg) | |||
{ | { | |||
*r = 1; | *r = 1; | |||
*c = 1; | *c = 1; | |||
return; | return; | |||
} | } | |||
save_line = Most_C_Line; | save_line = Most_C_Line; | |||
save_offset = Most_C_Offset; | save_offset = Most_C_Offset; | |||
*r = most_what_line(pos); | *r = most_what_line(pos); | |||
if (Most_B_Opt) | if (Most_B_Opt) | |||
{ | { | |||
*c = (int) (pos - Most_Beg) - (*r - 1) * 16 + 1; | *c = (MOST_INT) (pos - Most_Beg) - (*r - 1) * 16 + 1; | |||
return; | return; | |||
} | } | |||
Most_C_Line = *r; | Most_C_Line = *r; | |||
Most_C_Offset = pos - Most_Beg; | Most_C_Offset = pos - Most_Beg; | |||
/* Now we have found the line it is on so.... */ | /* Now we have found the line it is on so.... */ | |||
(void) most_beg_of_line(); | (void) most_beg_of_line(); | |||
*c = 1 + most_apparant_distance (pos); | *c = 1 + most_apparant_distance (pos); | |||
Most_C_Line = save_line; | Most_C_Line = save_line; | |||
skipping to change at line 551 | skipping to change at line 552 | |||
Most_Buffer_Type *most_switch_to_buffer(Most_Buffer_Type *nnew) | Most_Buffer_Type *most_switch_to_buffer(Most_Buffer_Type *nnew) | |||
{ | { | |||
Most_Buffer_Type *old; | Most_Buffer_Type *old; | |||
old = Most_Buf; | old = Most_Buf; | |||
Most_Buf = nnew; | Most_Buf = nnew; | |||
Most_Beg = Most_Buf->beg; | Most_Beg = Most_Buf->beg; | |||
Most_Eob = Most_Buf->end; | Most_Eob = Most_Buf->end; | |||
return old; | return old; | |||
} | } | |||
/* If file is NULL, then buffer is for stdin */ | ||||
Most_Buffer_Type *most_create_buffer(char *file) | Most_Buffer_Type *most_create_buffer(char *file) | |||
{ | { | |||
Most_Buffer_Type *buf; | Most_Buffer_Type *buf; | |||
if (file == NULL) file = "*stdin*"; | ||||
buf = (Most_Buffer_Type *) MOSTMALLOC(sizeof(Most_Buffer_Type)); | buf = (Most_Buffer_Type *) MOSTMALLOC(sizeof(Most_Buffer_Type)); | |||
memset ((char *) buf, 0, sizeof(Most_Buffer_Type)); | memset ((char *) buf, 0, sizeof(Most_Buffer_Type)); | |||
strcpy(buf->file,file); | strcpy(buf->file,file); | |||
return(buf); | return(buf); | |||
} | } | |||
unsigned char *most_malloc(unsigned int n) | unsigned char *most_malloc(size_t n) | |||
{ | { | |||
unsigned char *b = (unsigned char *) SLMALLOC(n); | unsigned char *b; | |||
if (n == 0) n = 1; | ||||
b = (unsigned char *) malloc (n); | ||||
if (b == NULL) | if (b == NULL) | |||
{ | { | |||
most_exit_error("malloc: Memory Allocation Error."); | most_exit_error("malloc: Memory Allocation Error."); | |||
} | } | |||
return b; | return b; | |||
} | } | |||
unsigned char *most_realloc(unsigned char *p, unsigned int n) | unsigned char *most_realloc(unsigned char *p, size_t n) | |||
{ | { | |||
unsigned char *b = (unsigned char *) SLREALLOC(p, n); | unsigned char *b; | |||
if (p == NULL) return most_malloc (n); | ||||
if (n == 0) n = 1; | ||||
b = (unsigned char *) realloc (p, n); | ||||
if (b == NULL) | if (b == NULL) | |||
{ | { | |||
most_exit_error("malloc: Memory Allocation Error."); | most_exit_error("malloc: Memory Allocation Error."); | |||
} | } | |||
return b; | return b; | |||
} | } | |||
End of changes. 17 change blocks. | ||||
14 lines changed or deleted | 25 lines changed or added |