pch.c (c44f94d0cde8b9cc3ce4947f4f732c1078e64669) | pch.c (c1a08643e3f6c6af2672fc7fd50251465f580489) |
---|---|
1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 42 unchanged lines hidden (view full) --- 51static LINENUM p_newfirst; /* 1st line number of replacement */ 52static LINENUM p_ptrn_lines; /* # lines in pattern */ 53static LINENUM p_repl_lines; /* # lines in replacement text */ 54static LINENUM p_end = -1; /* last line in hunk */ 55static LINENUM p_max; /* max allowed value of p_end */ 56static LINENUM p_context = 3; /* # of context lines */ 57static LINENUM p_input_line = 0; /* current line # from patch file */ 58static char **p_line = NULL;/* the text of the hunk */ | 1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 42 unchanged lines hidden (view full) --- 51static LINENUM p_newfirst; /* 1st line number of replacement */ 52static LINENUM p_ptrn_lines; /* # lines in pattern */ 53static LINENUM p_repl_lines; /* # lines in replacement text */ 54static LINENUM p_end = -1; /* last line in hunk */ 55static LINENUM p_max; /* max allowed value of p_end */ 56static LINENUM p_context = 3; /* # of context lines */ 57static LINENUM p_input_line = 0; /* current line # from patch file */ 58static char **p_line = NULL;/* the text of the hunk */ |
59static short *p_len = NULL; /* length of each line */ | 59static unsigned short *p_len = NULL; /* length of each line */ |
60static char *p_char = NULL; /* +, -, and ! */ 61static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ 62static int p_indent; /* indent to patch */ 63static LINENUM p_base; /* where to intuit this time */ 64static LINENUM p_bline; /* line # of p_base */ 65static LINENUM p_start; /* where intuit found a patch */ 66static LINENUM p_sline; /* and the line number for it */ 67static LINENUM p_hunk_beg; /* line number of current hunk */ --- 61 unchanged lines hidden (view full) --- 129 * Make sure our dynamically realloced tables are malloced to begin with. 130 */ 131void 132set_hunkmax(void) 133{ 134 if (p_line == NULL) 135 p_line = malloc(hunkmax * sizeof(char *)); 136 if (p_len == NULL) | 60static char *p_char = NULL; /* +, -, and ! */ 61static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ 62static int p_indent; /* indent to patch */ 63static LINENUM p_base; /* where to intuit this time */ 64static LINENUM p_bline; /* line # of p_base */ 65static LINENUM p_start; /* where intuit found a patch */ 66static LINENUM p_sline; /* and the line number for it */ 67static LINENUM p_hunk_beg; /* line number of current hunk */ --- 61 unchanged lines hidden (view full) --- 129 * Make sure our dynamically realloced tables are malloced to begin with. 130 */ 131void 132set_hunkmax(void) 133{ 134 if (p_line == NULL) 135 p_line = malloc(hunkmax * sizeof(char *)); 136 if (p_len == NULL) |
137 p_len = malloc(hunkmax * sizeof(short)); | 137 p_len = malloc(hunkmax * sizeof(unsigned short)); |
138 if (p_char == NULL) 139 p_char = malloc(hunkmax * sizeof(char)); 140} 141 142/* 143 * Enlarge the arrays containing the current hunk of patch. 144 */ 145static void 146grow_hunkmax(void) 147{ 148 int new_hunkmax = hunkmax * 2; 149 150 if (p_line == NULL || p_len == NULL || p_char == NULL) 151 fatal("Internal memory allocation error\n"); 152 153 p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); | 138 if (p_char == NULL) 139 p_char = malloc(hunkmax * sizeof(char)); 140} 141 142/* 143 * Enlarge the arrays containing the current hunk of patch. 144 */ 145static void 146grow_hunkmax(void) 147{ 148 int new_hunkmax = hunkmax * 2; 149 150 if (p_line == NULL || p_len == NULL || p_char == NULL) 151 fatal("Internal memory allocation error\n"); 152 153 p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); |
154 p_len = reallocf(p_len, new_hunkmax * sizeof(short)); | 154 p_len = reallocf(p_len, new_hunkmax * sizeof(unsigned short)); |
155 p_char = reallocf(p_char, new_hunkmax * sizeof(char)); 156 157 if (p_line != NULL && p_len != NULL && p_char != NULL) { 158 hunkmax = new_hunkmax; 159 return; 160 } 161 162 if (!using_plan_a) --- 1033 unchanged lines hidden (view full) --- 1196 1197/* 1198 * Reverse the old and new portions of the current hunk. 1199 */ 1200bool 1201pch_swap(void) 1202{ 1203 char **tp_line; /* the text of the hunk */ | 155 p_char = reallocf(p_char, new_hunkmax * sizeof(char)); 156 157 if (p_line != NULL && p_len != NULL && p_char != NULL) { 158 hunkmax = new_hunkmax; 159 return; 160 } 161 162 if (!using_plan_a) --- 1033 unchanged lines hidden (view full) --- 1196 1197/* 1198 * Reverse the old and new portions of the current hunk. 1199 */ 1200bool 1201pch_swap(void) 1202{ 1203 char **tp_line; /* the text of the hunk */ |
1204 short *tp_len; /* length of each line */ | 1204 unsigned short *tp_len;/* length of each line */ |
1205 char *tp_char; /* +, -, and ! */ 1206 LINENUM i; 1207 LINENUM n; 1208 bool blankline = false; 1209 char *s; 1210 1211 i = p_first; 1212 p_first = p_newfirst; --- 140 unchanged lines hidden (view full) --- 1353pch_context(void) 1354{ 1355 return p_context; 1356} 1357 1358/* 1359 * Return the length of a particular patch line. 1360 */ | 1205 char *tp_char; /* +, -, and ! */ 1206 LINENUM i; 1207 LINENUM n; 1208 bool blankline = false; 1209 char *s; 1210 1211 i = p_first; 1212 p_first = p_newfirst; --- 140 unchanged lines hidden (view full) --- 1353pch_context(void) 1354{ 1355 return p_context; 1356} 1357 1358/* 1359 * Return the length of a particular patch line. 1360 */ |
1361short | 1361unsigned short |
1362pch_line_len(LINENUM line) 1363{ 1364 return p_len[line]; 1365} 1366 1367/* 1368 * Return the control character (+, -, *, !, etc) for a patch line. 1369 */ --- 210 unchanged lines hidden --- | 1362pch_line_len(LINENUM line) 1363{ 1364 return p_len[line]; 1365} 1366 1367/* 1368 * Return the control character (+, -, *, !, etc) for a patch line. 1369 */ --- 210 unchanged lines hidden --- |