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

« back to all changes in this revision

Viewing changes to prim/general/src/logviewer.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) 1995-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 Massachusetts Ave, Cambridge,
 
17
  MA 02139, USA.
 
18
 
 
19
  Correspondence 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
                                         all rights reserved
 
30
.IDENTIFIER  logviewer
 
31
.LANGUAGE    C
 
32
.AUTHOR      K. Banse   DMD-ESO Garching
 
33
.KEYWORDS    logging, display
 
34
.PURPOSE     this module is executed via
 
35
                $ xterm -e logviewer.exe ...
 
36
             thus at termination the xterm window disappears, 
 
37
             => we need to put sleep() into the code, to be
 
38
             able to read any error message
 
39
 
 
40
             display info in separate xterm, parallel to application
 
41
             by displaying the contents of a given file
 
42
 
 
43
.VERSION     1.00       030121
 
44
 
 
45
 090120         last modif
 
46
 
 
47
------------------------------------------------------------*/
 
48
 
 
49
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
50
 
 
51
#define  _POSIX_SOURCE 1
 
52
 
 
53
#define  LIMIT_LINES  100
 
54
 
 
55
 
 
56
#include <stdio.h>
 
57
#include <stdlib.h>
 
58
#include <string.h>
 
59
#include <sys/types.h>
 
60
#include <sys/stat.h>
 
61
#include <unistd.h>
 
62
#include <fcntl.h>
 
63
 
 
64
/*
 
65
 
 
66
*/
 
67
 
 
68
int main(argc,argv)
 
69
int argc;
 
70
char *argv[];
 
71
 
 
72
{
 
73
int fd, mm;
 
74
static int baselen, count, swindx;
 
75
 
 
76
char   cbuf[104];
 
77
static char  filename[168], switchy[4] = "AB ";
 
78
 
 
79
 
 
80
 
 
81
/* a pair of ASCII infofiles is used to display 
 
82
  (lots of) information
 
83
   written to the infofiles by the application 
 
84
   after LIMIT_LINES lines of text, the infofiles are switched
 
85
   from blablaA to blablaB and vice versa
 
86
   this limit must be synchronized with `logview_init()'
 
87
   in .../prim/general/libsrc/logview.c   */
 
88
 
 
89
 
 
90
baselen = (int)strlen(argv[1]);
 
91
if (baselen > 160)
 
92
   {
 
93
   printf(">>> file:\n%s\n>>> way to long for us...\n",argv[1]);
 
94
   sleep(5);
 
95
   exit(1);
 
96
   }
 
97
 
 
98
(void) strcpy(filename,argv[1]);
 
99
swindx = 0;
 
100
 
 
101
filename[baselen] = switchy[swindx]; filename[baselen+1] = '\0';
 
102
count = 5;
 
103
 
 
104
 
 
105
try_again:
 
106
fd = open(filename,O_RDONLY);   /* open for reading */
 
107
if (fd < 1)
 
108
   {
 
109
   if (--count > 0)
 
110
      {
 
111
      sleep(2);
 
112
      goto try_again;
 
113
      }
 
114
   printf("could not open infofile %s ...\n",filename);
 
115
   sleep(3);
 
116
   exit(1);
 
117
   }
 
118
 
 
119
count = 0;
 
120
 
 
121
input_loop:                             /* use 100 bytes buffer */
 
122
mm = read(fd,cbuf,100);                 /* in sync with logview.c */
 
123
if (mm >0)
 
124
      {
 
125
      if (strncmp(cbuf,"EOF",3) == 0)           /* check for end of program */
 
126
         {
 
127
         printf("\n... terminating parallel log ...\n");
 
128
         sleep(3);
 
129
         exit(0);
 
130
         }
 
131
      printf("%s\n",cbuf); 
 
132
      count ++;
 
133
 
 
134
      if (count == LIMIT_LINES)
 
135
         {
 
136
         close(fd);
 
137
         mm = unlink(filename);
 
138
         if (mm != 0)
 
139
            {
 
140
            printf("we could not delete: %s\n",filename);
 
141
            sleep(5);
 
142
            exit(1);
 
143
            }
 
144
 
 
145
         swindx  = 1 - swindx;                  /* 0 -> 1, 1 -> 0 */
 
146
         filename[baselen] = switchy[swindx];
 
147
         count = 5;
 
148
         goto try_again;
 
149
         }
 
150
      }
 
151
else
 
152
   {
 
153
   sleep(1);
 
154
   }
 
155
 
 
156
goto input_loop;
 
157
 
 
158
}