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   
C/C++ Source or Header  |  1988-01-28  |  2KB  |  105 lines

  1. #include "conv.h"    /* contains the ebcdic/ascii tables */
  2. #include <sys/file.h>
  3. #define DEVICE "/dev/rmt4"
  4. #define BUF_SIZE 512
  5.  
  6. static char put_buffer[BUF_SIZE], *put_ptr = put_buffer;
  7. static int put_count = BUF_SIZE;
  8. static int tape_drive = -1;
  9.  
  10. extern int debug;
  11.  
  12. #define CONV(c) ( debug ? (c) : atoe[(int) (c)] )
  13.  
  14. #define put_char(ch)\
  15.     (*put_ptr++ = CONV(ch), --put_count > 0 ? 0 : put_record())
  16.  
  17. put_record()
  18. {
  19.     if (put_count == BUF_SIZE) {
  20.     /* empty buffer */
  21.     return;
  22.     }
  23.  
  24.     while (--put_count >= 0) {
  25.     *put_ptr++ = CONV(' ');
  26.     }
  27.  
  28.     if (write(tape_drive, put_buffer, BUF_SIZE) != BUF_SIZE) {
  29.     perror("M36gen, Can't write on the tape drive");
  30.     exit(-1);
  31.     }
  32.  
  33.     put_count = BUF_SIZE ; put_ptr = put_buffer;
  34. }
  35.  
  36. put_int(num)
  37. int num;
  38. {
  39.     register int digit, val;
  40.     register char *ptr;
  41.     char buffer[100];
  42.     int negative = 0;
  43.  
  44.     val = num;
  45.  
  46.     if (val == 0) {
  47.     put_char('0');
  48.     return;
  49.     } else if (val < 0) {
  50.     val = -val;
  51.     negative = 1;
  52.     }
  53.  
  54.     ptr = buffer;
  55.  
  56.     digit = val % 10;
  57.  
  58.     while (val > 0) {
  59.     *ptr++ = digit + '0';
  60.     val /= 10;
  61.     digit = val%10;
  62.     }
  63.  
  64.     if (negative) {
  65.     *ptr++ = '-';
  66.     }
  67.  
  68.     while (--ptr >= buffer) {
  69.     put_char(*ptr);
  70.     }
  71. }
  72.  
  73. put_string(str)
  74. char *str;
  75. {
  76.     while (*str != '\0') {
  77.     put_char(*str++);
  78.     }
  79. }
  80.  
  81. start_write()
  82. {
  83.     if (debug) {
  84.     tape_drive = 1;
  85.     } else {
  86.     tape_drive = open(DEVICE, O_WRONLY, 0666);
  87.     }
  88.  
  89.     if (tape_drive < 0) {
  90.     perror(DEVICE);
  91.     exit(-1);
  92.     }
  93.  
  94.     return;
  95. }
  96.  
  97. stop_write()
  98. {
  99.     put_record();
  100.  
  101.     if (!debug && tape_drive != -1) {
  102.     close(tape_drive);
  103.     }
  104. }
  105.