| 1 |
/* @(#)osttest.c 19.1 (ES0-DMD) 02/25/03 13:56:14 */ |
| 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 |
/*+++++++++++ |
| 30 |
.TYPE Program |
| 31 |
.LANGUAGE C |
| 32 |
.IDENTIFICATION ostTEST |
| 33 |
.VERSION 1.0 06-Oct-1987: Creation |
| 34 |
.AUTHOR Francois Ochsenbein [ESO-IPG] |
| 35 |
.KEYWORDS Test of ost routines |
| 36 |
.ENVIRONMENT |
| 37 |
.COMMENTS |
| 38 |
-------------------*/ |
| 39 |
|
| 40 |
#include <osterm.h> |
| 41 |
#include <atype.h> |
| 42 |
#include <macrogen.h> |
| 43 |
#include <osdefos.h> |
| 44 |
|
| 45 |
static char msg[132]; |
| 46 |
static char output[] = |
| 47 |
"Use Interrupt (^C) to stop... Use Interrupt (^C) to stop..."; |
| 48 |
static char flag = 0; |
| 49 |
static struct termstatus tst = {0}; |
| 50 |
|
| 51 |
main() |
| 52 |
{ long int st, n; |
| 53 |
int i, l, k; |
| 54 |
char c; char *p; |
| 55 |
int ctrlc(), oststop(); |
| 56 |
|
| 57 |
puts("==== Testing OST (Terminal access) routines ====\n"); |
| 58 |
|
| 59 |
/* Get info about the Terminal, and display it */ |
| 60 |
if (ostinfo(&tst) < 0) |
| 61 |
printf("Can't get terminal info: ", osmsg()); |
| 62 |
printf("Terminal "); |
| 63 |
if (tst.termname) printf("%s ", tst.termname); |
| 64 |
printf("Baud=%d, Lines=%d, Cols=%d\r\n", |
| 65 |
tst.baud_rate, tst.lines, tst.columns); |
| 66 |
printf("\tControls: INT=^%c, QUIT=^%c\r\n", |
| 67 |
tst.cc_INT+'@', |
| 68 |
tst.cc_QUIT+'@'); |
| 69 |
|
| 70 |
|
| 71 |
printf("\nInterrupt char redefined as ^C, Stop as ^Y\n"); |
| 72 |
tst.cc_INT = Control_('C'), |
| 73 |
tst.cc_QUIT = Control_('Y'); |
| 74 |
|
| 75 |
printf("\n\n Hit <Return> to start"); |
| 76 |
if (!gets(msg)) return; |
| 77 |
|
| 78 |
if (ostopen() < 0) { printf("Can't open Terminal: %s\n", osmsg()); return;} |
| 79 |
ostset(&tst); |
| 80 |
|
| 81 |
while(1) |
| 82 |
{ flag = 0; |
| 83 |
ostput("\r\nYour choice: "); |
| 84 |
k = ostread(msg,1,30); /* 30s of time-out */ |
| 85 |
if (k < 0) /* There was an error */ |
| 86 |
err(); |
| 87 |
if (k == 0) /* Nothing */ |
| 88 |
{ ostput("\07 Are you sleeping ???\r\n"); |
| 89 |
continue; |
| 90 |
} |
| 91 |
ostwrite(msg,k); |
| 92 |
switch(toupper(msg[0])) |
| 93 |
{ default: ostput("*** Uknown Command!\r\n"); |
| 94 |
case 'H': case '?': help(); continue; |
| 95 |
|
| 96 |
case 'I': /* Cancel */ |
| 97 |
if (ostint(ctrlc) != 0) err(); /* `>' changed to `!=' tm 07.09.89 */ |
| 98 |
break; |
| 99 |
|
| 100 |
case 'C': /* Cancel */ /* `>' changed to `!=' tm 07.09.89 */ |
| 101 |
if (ostint(oststop) != 0) err(); |
| 102 |
break; |
| 103 |
|
| 104 |
case 'R': /* Input */ |
| 105 |
ostput("\r\nText [no echo!] : "); |
| 106 |
for (i=0, c = 0; c != '\r'; ) |
| 107 |
{ if (i >= sizeof(msg)) break; |
| 108 |
k = ostread(&msg[i], sizeof(msg)-i, 30); |
| 109 |
if (k < 0) err(); |
| 110 |
i += k; |
| 111 |
if (k == 0) ostput("\07"); |
| 112 |
else c = msg[i-1]; |
| 113 |
} |
| 114 |
ostwrite(msg, i); |
| 115 |
ostput("\r\n"); |
| 116 |
continue; |
| 117 |
|
| 118 |
case 'W': /* Output */ |
| 119 |
ostput("\r\n"); |
| 120 |
for (i=0;i < 1000 ; i++) |
| 121 |
{ if (flag) break; |
| 122 |
sprintf(msg,"[%d] %s [%d]\r\n",i,output,i); |
| 123 |
if (flag) break; |
| 124 |
ostput(msg); |
| 125 |
} |
| 126 |
continue; |
| 127 |
|
| 128 |
case 'Q': /* Quit */ |
| 129 |
ostclose(); |
| 130 |
return; |
| 131 |
|
| 132 |
case 'T': /* Tell */ |
| 133 |
if (ostinfo(&tst) < 0) |
| 134 |
printf("Can't get terminal info: ", osmsg()); |
| 135 |
printf("\r\nTerminal "); |
| 136 |
if (tst.termname) printf("%s ", tst.termname); |
| 137 |
printf("Baud=%d, Lines=%d, Cols=%d\r\n", |
| 138 |
tst.baud_rate, tst.lines, tst.columns); |
| 139 |
printf("\tControls: INT=^%c, QUIT=^%c\r\n", |
| 140 |
tst.cc_INT+'@', |
| 141 |
tst.cc_QUIT+'@'); |
| 142 |
} |
| 143 |
} |
| 144 |
ospexit(0); |
| 145 |
} |
| 146 |
|
| 147 |
ctrlc() |
| 148 |
{ |
| 149 |
int oststop(); |
| 150 |
flag = 1; |
| 151 |
ostput("\n\r***INTERRUPT\r\n"); |
| 152 |
ostint(oststop); |
| 153 |
return(0); |
| 154 |
} |
| 155 |
|
| 156 |
help() |
| 157 |
{ |
| 158 |
ostput("\r\nPossibilities are ? Help"); |
| 159 |
ostput("\r\n C Define Interrupt = Cancel"); |
| 160 |
ostput("\r\n I Define Interrupt"); |
| 161 |
ostput("\r\n Q Quit"); |
| 162 |
ostput("\r\n R Read until CR"); |
| 163 |
ostput("\r\n T Tell terminal info"); |
| 164 |
ostput("\r\n W Write until Interrupt"); |
| 165 |
return(0); |
| 166 |
} |
| 167 |
err() |
| 168 |
{ printf("\n****Error: %s\r\n", osmsg()); |
| 169 |
return; |
| 170 |
} |