home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
ciftomann.tar
/
pggen_dir
/
put.c
< prev
Wrap
C/C++ Source or Header
|
1988-01-28
|
2KB
|
105 lines
#include "conv.h" /* contains the ebcdic/ascii tables */
#include <sys/file.h>
#define DEVICE "/dev/rmt4"
#define BUF_SIZE 512
static char put_buffer[BUF_SIZE], *put_ptr = put_buffer;
static int put_count = BUF_SIZE;
static int tape_drive = -1;
extern int debug;
#define CONV(c) ( debug ? (c) : atoe[(int) (c)] )
#define put_char(ch)\
(*put_ptr++ = CONV(ch), --put_count > 0 ? 0 : put_record())
put_record()
{
if (put_count == BUF_SIZE) {
/* empty buffer */
return;
}
while (--put_count >= 0) {
*put_ptr++ = CONV(' ');
}
if (write(tape_drive, put_buffer, BUF_SIZE) != BUF_SIZE) {
perror("M36gen, Can't write on the tape drive");
exit(-1);
}
put_count = BUF_SIZE ; put_ptr = put_buffer;
}
put_int(num)
int num;
{
register int digit, val;
register char *ptr;
char buffer[100];
int negative = 0;
val = num;
if (val == 0) {
put_char('0');
return;
} else if (val < 0) {
val = -val;
negative = 1;
}
ptr = buffer;
digit = val % 10;
while (val > 0) {
*ptr++ = digit + '0';
val /= 10;
digit = val%10;
}
if (negative) {
*ptr++ = '-';
}
while (--ptr >= buffer) {
put_char(*ptr);
}
}
put_string(str)
char *str;
{
while (*str != '\0') {
put_char(*str++);
}
}
start_write()
{
if (debug) {
tape_drive = 1;
} else {
tape_drive = open(DEVICE, O_WRONLY, 0666);
}
if (tape_drive < 0) {
perror(DEVICE);
exit(-1);
}
return;
}
stop_write()
{
put_record();
if (!debug && tape_drive != -1) {
close(tape_drive);
}
}