File: task.h

package info (click to toggle)
dnprogs 2.52
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,644 kB
  • ctags: 4,021
  • sloc: ansic: 26,737; cpp: 10,666; makefile: 832; sh: 537; awk: 13
file content (146 lines) | stat: -rw-r--r-- 3,882 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146


#ifndef METAFILE_DIR
#define METAFILE_DIR ".fal"
#endif

// Base class for FAL tasks
// It incorporates the messaging base and also the wherewithall
// to parse VMS filenames and calculate CRCs
class fal_task
{
  public:
    fal_task(dap_connection &c, int v, fal_params &p):
	conn(c),
	verbose(v),
	crc(DAPPOLY, DAPINICRC),
	params(p),
	record_lengths(NULL)
	{}
    virtual bool process_message(dap_message *m)=0;
    virtual ~fal_task()
	{
	    if (record_lengths)
		delete[] record_lengths;
	}
    void set_crc(bool);
    void calculate_crc(unsigned char *, int);

  protected:
    dap_connection &conn;
    int             verbose;
    bool            vms_format;
    bool            need_crc;
    vaxcrc          crc;
    fal_params     &params;

    // Bits for dealing with variable-length records.
    unsigned int    current_record;
    unsigned short *record_lengths;
    unsigned int    num_records;

    // Whether we send the DEV part of the attributes message
    typedef enum { SEND_DEV, DONT_SEND_DEV, DEV_DEPENDS_ON_TYPE} dev_option;

    virtual bool send_file_attributes(char *, int, dev_option);
    virtual bool send_file_attributes(unsigned int &, bool &, char *, int,
				      dev_option);

    void return_error();
    void return_error(int);
    void split_filespec(char *, char *, char *);
    void make_vms_filespec(const char *, char *, bool);
    void parse_vms_filespec(char *, char *, char *);
    void make_unix_filespec(char *, char *);
    void convert_vms_wildcards(char *);
    void add_vroot(char *);
    void remove_vroot(char *);
    bool is_vms_name(char *);
    bool send_ack_and_unblock();

    void open_auto_types_file();
    int  unlink(char *);
    int rename(char *, char *);
    bool check_file_type(unsigned int &block_size, bool &send_records,
			 const char *name,
			 dap_attrib_message *attrib_msg);
    bool guess_file_type(unsigned int &block_size, bool &send_records,
			 const char *name,
			 dap_attrib_message *attrib_msg);
    bool fake_file_type(unsigned int &block_size, bool &send_records,
			const char *name,
			dap_attrib_message *attrib_msg);
    bool read_metafile(unsigned int &block_size, bool &send_records,
		       const char *name,
		       dap_attrib_message *attrib_msg);
    bool read_adf(unsigned int &block_size, bool &send_records,
		  const char *name,
		  dap_attrib_message *attrib_msg);
    bool fake_file_type(const char *name, dap_attrib_message *attrib_msg);
    void create_metafile(char *name, dap_attrib_message *attrib_msg);

    // The pseudo device name we use
    static const char *sysdisk_name;

 private:
    void meta_filename(const char *file, char *metafile);
    bool adf_filename(const char *file, char *metafile);

    // auto_types structure
    class auto_types
    {
    public:
	auto_types(char *_ext, bool _records, unsigned int _block)
	{
	    strcpy(ext, _ext);
	    send_records = _records;
	    block_size = _block;
	    len = strlen(ext);
	    next = NULL;
	}

	char ext[40];
	unsigned int  block_size;
	int len;
	bool send_records;
	auto_types *next;
    };

    // Structure of the metafile
    class metafile_data
    {
    public:
	unsigned short version;
	unsigned short rfm;
	unsigned int   rat;
	unsigned short mrs;
	unsigned short lrl;

	// For variable-length records with no carriage control:
	unsigned int  num_records;
	unsigned short *records; // This is really written after the structure

	static const int METAFILE_VERSION = 2;
    };

    // This is reverse-engineered so there's loads missing.
    class adf_struct
    {
    public:
	char  unknown1[6];
	short revn;         // Revision count
	char  unknown2[4];
	char  rfm;
	char  rat;
	short rsz;
	char  unknown3[10];
	short bks;
	short mrs;
	short ext; // Extend size
	// The rest is a mystery to me.
    };

    static auto_types *auto_types_list;
    static const char *default_types_file;
};