1
/*===========================================================================
2
Copyright (C) 1985-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
19
Corresponding concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
30
.AUTHOR Francois Ochsenbein [ESO]
32
.CATEGORY String transformations
35
Replacement of tabs by the correct amount of spaces.
37
.VERSION 1.0 19-Dec-1985: Creation
38
.VERSION 2.0 05-Jul-1988: All functions return int.
41
--------------------------------------------*/
43
#define PM_LEVEL LEVEL_STR
45
#include <midas_def.h>
50
extern int pm_enter(), eh_ed_str2(), pm_iexit();
54
/*===========================================================================
56
*===========================================================================*/
57
int ed_tab (dest, size, source, ls, tab_len)
59
.PURPOSE Perform transformations of tabs by the correct amount of blanks
60
.RETURNS Length of transformed text. The NUL byte is appended if there is space.
61
.REMARKS An error is passed to the Error Handler if the destination buffer is
63
Strange results if strings overlap !!!
65
char *dest; /* OUT: destination string */
66
int size; /* IN: size of destination string */
67
char *source; /* IN: source string */
68
int ls; /* IN: length of source string */
69
int tab_len; /* IN: Column adjustment (8 is zero) */
71
char *p1, *p2, *p1e, *p2e, truncated;
79
if (tab_len <= 0) tab_len = 8;
80
/* Perform transformations */
81
for (p1=source, p2=dest; (p1<p1e) && (truncated == 0) ; )
82
{ if (p2 >= p2e) { truncated = 1; continue; }
84
{ i = tab_len - ((p2 - dest)%tab_len);
85
if ((p2+i) >= p2e) { truncated = 1; continue; }
86
p2 += oscfill(p2, i, ' ');
90
len = MIN(p2e-p2, p1e-p1);
91
i = oscopuc(p2, p1, len, '\t');
95
if (truncated) ERR_ED_STR2("Truncated: ",dest, size);
96
else if (p2 < p2e) *p2 = EOS;