~ubuntu-branches/ubuntu/vivid/macutils/vivid

« back to all changes in this revision

Viewing changes to comm/xm_to.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Sharkey
  • Date: 2001-10-27 15:22:18 UTC
  • Revision ID: james.westby@ubuntu.com-20011027152218-oikhfgiaja3hjf5f
Tags: upstream-2.0b3
ImportĀ upstreamĀ versionĀ 2.0b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "comm.h"
 
2
#ifdef XM
 
3
#include "../fileio/machdr.h"
 
4
#include "../fileio/rdfile.h"
 
5
#include "../util/masks.h"
 
6
#include "globals.h"
 
7
#include "protocol.h"
 
8
 
 
9
extern int tgetc();
 
10
extern void tputc();
 
11
extern void tputrec();
 
12
 
 
13
static void send_part();
 
14
static int send_sync();
 
15
static void send_rec();
 
16
 
 
17
void xm_to()
 
18
{
 
19
    if(send_sync() == ACK) {
 
20
        send_part(file_info, DATABYTES, 1);
 
21
        send_part(data_fork, data_size, 1);
 
22
        send_part(rsrc_fork, rsrc_size, 0);
 
23
    }
 
24
}
 
25
 
 
26
static void send_part(info, size, more)
 
27
char *info;
 
28
int size, more;
 
29
{
 
30
int recno = 1, i, status;
 
31
 
 
32
    while(size > 0) {
 
33
        for(i = 0; i < RETRIES; i++) {
 
34
            send_rec(info, DATABYTES, recno);
 
35
            status = tgetc(ACKTIMO);
 
36
            if(status != NAK) {
 
37
                break;
 
38
            }
 
39
        }
 
40
        if(status == NAK || status == CAN) {
 
41
            cleanup(-1);
 
42
        }
 
43
        size -= DATABYTES;
 
44
        info += DATABYTES;
 
45
        recno = (recno + 1) & MAXRECNO;
 
46
    }
 
47
    tputc(EOT);
 
48
    if(!pre_beta) {
 
49
        status = tgetc(ACKTIMO);
 
50
    }
 
51
    if(more) {
 
52
        status = tgetc(ACKTIMO);
 
53
    }
 
54
}
 
55
 
 
56
static int send_sync()
 
57
{
 
58
int c, i;
 
59
 
 
60
    for(i = 0; i < 3; i++) {
 
61
        tputc(ESC);
 
62
        tputc('a');
 
63
        while((c = tgetc(ACKTIMO)) != TMO) {
 
64
            switch(c) {
 
65
            case CAN:
 
66
            case EOT:
 
67
            case ACK:
 
68
                return c;
 
69
            default:
 
70
                continue;
 
71
            }
 
72
        }
 
73
    }
 
74
    return CAN;
 
75
}
 
76
 
 
77
static void send_rec(buf, bufsize, recno)
 
78
char *buf;
 
79
int bufsize, recno;
 
80
{
 
81
int i, cksum;
 
82
char *bp;
 
83
 
 
84
    cksum = 0;
 
85
    bp = buf;
 
86
    for(i = 0; i < bufsize; i++) {
 
87
        cksum += *bp++ & BYTEMASK;
 
88
    }
 
89
    tputc(SOH);
 
90
    tputc((unsigned char)recno);
 
91
    tputc((unsigned char)(MAXRECNO - recno));
 
92
    tputrec(buf, bufsize);
 
93
    tputc((char)(cksum & BYTEMASK));
 
94
}
 
95
 
 
96
#else /* XM */
 
97
int xm_to; /* Keep lint and some compilers happy */
 
98
#endif /* XM */