| 1 |
/* @(#)misc.c 19.1 (ES0-DMD) 02/25/03 13:39:46 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/* @(#)misc.c 1.0.0.0 (ESO-La Silla) 10/08/91 12:00:00 */ |
| 30 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 31 |
.IDENT misc.c |
| 32 |
.MODULE subroutines |
| 33 |
.LANGUAGE C |
| 34 |
.AUTHOR Cristian Levin - ESO La Silla |
| 35 |
.PURPOSE Miscelaneous functions: |
| 36 |
- Checking of the existence of a Unix file. |
| 37 |
- Checking of the Midas graphics window. |
| 38 |
.KEYWORDS file checking, graphics window |
| 39 |
.VERSION 1.0 1-Apr-1991 Implementation |
| 40 |
.ENVIRONMENT UNIX |
| 41 |
------------------------------------------------------------*/ |
| 42 |
|
| 43 |
#include <stdio.h> |
| 44 |
#include <string.h> |
| 45 |
#include <sys/types.h> |
| 46 |
#include <sys/stat.h> |
| 47 |
#include <gl_defs.h> |
| 48 |
#include <proto_os.h> |
| 49 |
|
| 50 |
/* check for the existence of 'file' with the extension 'ext' (incl. dot) */ |
| 51 |
int file_exists( file, ext ) |
| 52 |
char *file, *ext; |
| 53 |
{ |
| 54 |
char fileext[MAXLINE]; |
| 55 |
int i; |
| 56 |
struct stat statbuf; |
| 57 |
|
| 58 |
if ( file[0] == '\0' ) |
| 59 |
return(FALSE); |
| 60 |
|
| 61 |
for ( i = 0; file[i] != '\0'; i++ ) |
| 62 |
if ( file[i] == ' ' ) { |
| 63 |
file[i] = '\0'; |
| 64 |
break; |
| 65 |
} |
| 66 |
|
| 67 |
if ( strstrs(file, ext) == (char *)NULL ) |
| 68 |
sprintf( fileext, "%s%s", file, ext ); |
| 69 |
else |
| 70 |
strcpy( fileext, file ); |
| 71 |
|
| 72 |
if ( stat(fileext, &statbuf) == -1 ) |
| 73 |
return(FALSE); |
| 74 |
|
| 75 |
return(TRUE); |
| 76 |
} |
| 77 |
|
| 78 |
int graphwin_exists() |
| 79 |
{ |
| 80 |
char unit[10]; |
| 81 |
char file_old[MAXLINE], file[MAXLINE]; |
| 82 |
char midwork[MAXLINE]; |
| 83 |
|
| 84 |
osfphname("MID_WORK", midwork); |
| 85 |
osfphname("DAZUNIT", unit); |
| 86 |
unit[3] = '\0'; |
| 87 |
|
| 88 |
sprintf(file_old, "%s%sXW", midwork, unit); |
| 89 |
sprintf(file, "%smidas_xw%s", midwork, unit); |
| 90 |
return(file_exists(file_old, ".soc") || file_exists(file_old, ".soc=") || |
| 91 |
file_exists(file, "") || file_exists(file, "=") ); |
| 92 |
} |
| 93 |
|
| 94 |
void DropTrailingBlanks(str) |
| 95 |
char *str; |
| 96 |
{ |
| 97 |
int i; |
| 98 |
|
| 99 |
for ( i = 0; str[i] != '\0'; i++ ) |
| 100 |
if ( str[i] == ' ' ) { |
| 101 |
str[i] = '\0'; |
| 102 |
break; |
| 103 |
} |
| 104 |
} |