* New version 2.21.999
[alpine.git] / pith / margin.c
blobbcaeccb3928e6b25a05e717e6378db143c8a116a
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: margin.c 1032 2008-04-11 00:30:04Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2018 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 /*======================================================================
21 margin.c
22 Implements message data gathering and formatting
24 ====*/
27 #include "../pith/headers.h"
28 #include "../pith/string.h"
29 #include "../pith/state.h"
30 #include "../pith/conf.h"
34 * Internal prototypes
39 * format_view_margin - return sane value for vertical margins
41 int *
42 format_view_margin(void)
44 static int margin[2];
45 char tmp[100], e[200], *err, lastchar = 0;
46 int left = 0, right = 0, leftm = 0, rightm = 0;
47 size_t l;
49 memset(margin, 0, sizeof(margin));
52 * We initially tried to make sure that the user didn't shoot themselves
53 * in the foot by setting this too small. People seem to want to do some
54 * strange stuff, so we're going to relax the wild shot detection and
55 * let people set what they want, until we get to the point of totally
56 * absurd. We've also added the possibility of appending the letter c
57 * onto the width. That means treat the value as an absolute column
58 * instead of a width. That is, a right margin of 76c means wrap at
59 * column 76, whereas right margin of 4 means to wrap at column
60 * screen width - 4.
62 if(ps_global->VAR_VIEW_MARGIN_LEFT){
63 strncpy(tmp, ps_global->VAR_VIEW_MARGIN_LEFT, sizeof(tmp)-1);
64 tmp[sizeof(tmp)-1] = '\0';
65 removing_leading_and_trailing_white_space(tmp);
66 if(tmp[0]){
67 l = strlen(tmp);
68 if(l > 0)
69 lastchar = tmp[l-1];
71 if(lastchar == 'c')
72 tmp[l-1] = '\0';
74 if((err = strtoval(tmp, &left, 0, 0, 0, e, sizeof(e), "Viewer-margin-left")) != NULL){
75 leftm = 0;
76 dprint((2, "%s\n", err));
78 else{
79 if(lastchar == 'c')
80 leftm = left-1;
81 else
82 leftm = left;
84 leftm = MIN(MAX(0, leftm), ps_global->ttyo->screen_cols);
89 if(ps_global->VAR_VIEW_MARGIN_RIGHT){
90 strncpy(tmp, ps_global->VAR_VIEW_MARGIN_RIGHT, sizeof(tmp)-1);
91 tmp[sizeof(tmp)-1] = '\0';
92 removing_leading_and_trailing_white_space(tmp);
93 if(tmp[0]){
94 l = strlen(tmp);
95 if(l > 0)
96 lastchar = tmp[l-1];
98 if(lastchar == 'c')
99 tmp[l-1] = '\0';
101 if((err = strtoval(tmp, &right, 0, 0, 0, e, sizeof(e), "Viewer-margin-right")) != NULL){
102 rightm = 0;
103 dprint((2, "%s\n", err));
105 else{
106 if(lastchar == 'c')
107 rightm = ps_global->ttyo->screen_cols - right;
108 else
109 rightm = right;
111 rightm = MIN(MAX(0, rightm), ps_global->ttyo->screen_cols);
116 if((rightm > 0 || leftm > 0) && rightm >= 0 && leftm >= 0
117 && ps_global->ttyo->screen_cols - rightm - leftm >= 8){
118 margin[0] = leftm;
119 margin[1] = rightm;
122 return(margin);
127 * Give a margin for help and such
129 int *
130 non_messageview_margin(void)
132 static int margin[2];
134 margin[0] = 0;
135 margin[1] = 4;
137 return(margin);