Deleted Added
sdiff udiff text old ( 195941 ) new ( 221715 )
full compact
1/*
2 * Copyright (C) 1984-2009 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 234 unchanged lines hidden (view full) ---

245 p = "cannot open";
246#endif
247 len = strlen(filename) + strlen(p) + 3;
248 m = (char *) ecalloc(len, sizeof(char));
249 SNPRINTF2(m, len, "%s: %s", filename, p);
250 return (m);
251}
252
253/*
254 * Return the ratio of two POSITIONS, as a percentage.
255 * {{ Assumes a POSITION is a long int. }}
256 */
257 public int
258percentage(num, den)
259 POSITION num, den;
260{
261 POSITION num100 = num * 100;
262
263 if (num100 / 100 == num)
264 return (num100 / den);
265 else
266 return (num / (den / 100));
267}
268
269/*
270 * Return the specified percentage of a POSITION.
271 */
272 public POSITION
273percent_pos(pos, percent, fraction)
274 POSITION pos;
275 int percent;
276 long fraction;
277{
278 /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */
279 long perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100);
280 POSITION temp;
281
282 if (perden == 0)
283 return (0);
284 temp = pos * perden; /* This might overflow. */
285 if (temp / perden == pos)
286 /* No overflow */
287 return (temp / NUM_FRAC_DENOM);
288 else
289 /* Above calculation overflows;
290 * use a method that is less precise but won't overflow. */
291 return (perden * (pos / NUM_FRAC_DENOM));
292}
293
294#if !HAVE_STRCHR
295/*
296 * strchr is used by regexp.c.
297 */
298 char *
299strchr(s, c)

--- 56 unchanged lines hidden ---