2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2008 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 /*======================================================================
18 Implements message data gathering and formatting
23 #include "../pith/headers.h"
24 #include "../pith/string.h"
25 #include "../pith/state.h"
26 #include "../pith/conf.h"
35 * format_view_margin - return sane value for vertical margins
38 format_view_margin(void)
41 char tmp
[100], e
[200], *err
, lastchar
= 0;
42 int left
= 0, right
= 0, leftm
= 0, rightm
= 0;
45 memset(margin
, 0, sizeof(margin
));
48 * We initially tried to make sure that the user didn't shoot themselves
49 * in the foot by setting this too small. People seem to want to do some
50 * strange stuff, so we're going to relax the wild shot detection and
51 * let people set what they want, until we get to the point of totally
52 * absurd. We've also added the possibility of appending the letter c
53 * onto the width. That means treat the value as an absolute column
54 * instead of a width. That is, a right margin of 76c means wrap at
55 * column 76, whereas right margin of 4 means to wrap at column
58 if(ps_global
->VAR_VIEW_MARGIN_LEFT
){
59 strncpy(tmp
, ps_global
->VAR_VIEW_MARGIN_LEFT
, sizeof(tmp
)-1);
60 tmp
[sizeof(tmp
)-1] = '\0';
61 removing_leading_and_trailing_white_space(tmp
);
70 if((err
= strtoval(tmp
, &left
, 0, 0, 0, e
, sizeof(e
), "Viewer-margin-left")) != NULL
){
72 dprint((2, "%s\n", err
));
80 leftm
= MIN(MAX(0, leftm
), ps_global
->ttyo
->screen_cols
);
85 if(ps_global
->VAR_VIEW_MARGIN_RIGHT
){
86 strncpy(tmp
, ps_global
->VAR_VIEW_MARGIN_RIGHT
, sizeof(tmp
)-1);
87 tmp
[sizeof(tmp
)-1] = '\0';
88 removing_leading_and_trailing_white_space(tmp
);
97 if((err
= strtoval(tmp
, &right
, 0, 0, 0, e
, sizeof(e
), "Viewer-margin-right")) != NULL
){
99 dprint((2, "%s\n", err
));
103 rightm
= ps_global
->ttyo
->screen_cols
- right
;
107 rightm
= MIN(MAX(0, rightm
), ps_global
->ttyo
->screen_cols
);
112 if((rightm
> 0 || leftm
> 0) && rightm
>= 0 && leftm
>= 0
113 && ps_global
->ttyo
->screen_cols
- rightm
- leftm
>= 8){
123 * Give a margin for help and such
126 non_messageview_margin(void)
128 static int margin
[2];