~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/tc3/libsrc/edtab.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1985-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++  
 
29
.MODULE    edtab.c
 
30
.AUTHOR    Francois Ochsenbein [ESO]
 
31
.LANGUAGE  C
 
32
.CATEGORY  String transformations
 
33
 
 
34
.COMMENTS
 
35
Replacement of tabs by the correct amount of spaces.
 
36
 
 
37
.VERSION 1.0    19-Dec-1985: Creation 
 
38
.VERSION 2.0    05-Jul-1988: All functions return int.
 
39
 
 
40
 090831         last modif
 
41
--------------------------------------------*/
 
42
 
 
43
#define PM_LEVEL        LEVEL_STR
 
44
 
 
45
#include <midas_def.h>
 
46
#include <te.h>
 
47
#include <str.h>
 
48
 
 
49
 
 
50
extern int pm_enter(), eh_ed_str2(), pm_iexit();
 
51
 
 
52
 
 
53
 
 
54
/*===========================================================================
 
55
 *                   ed_tab
 
56
 *===========================================================================*/
 
57
int ed_tab (dest, size, source, ls, tab_len)
 
58
/*++++++
 
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
 
62
        too small.
 
63
        Strange results if strings overlap !!!
 
64
----------*/
 
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)    */
 
70
{
 
71
        char    *p1, *p2, *p1e, *p2e, truncated;
 
72
        int     len, i;
 
73
 
 
74
  ENTER("+ed_tab");
 
75
 
 
76
  p1e = source + ls; 
 
77
  p2e = dest + size;
 
78
  truncated = 0;
 
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; }
 
83
        if (*p1 == '\t')
 
84
        {       i = tab_len - ((p2 - dest)%tab_len);
 
85
                if ((p2+i) >= p2e)      { truncated = 1; continue; }
 
86
                p2 += oscfill(p2, i, ' ');
 
87
                p1++;
 
88
                continue;
 
89
        }
 
90
        len = MIN(p2e-p2, p1e-p1);
 
91
        i = oscopuc(p2, p1, len, '\t');
 
92
        p1 += i, p2 += i;
 
93
  }
 
94
 
 
95
  if (truncated) ERR_ED_STR2("Truncated: ",dest, size);
 
96
  else  if (p2 < p2e)   *p2 = EOS;
 
97
 
 
98
  EXIT(p2 - dest);       
 
99
}
 
100