File: globals.h

package info (click to toggle)
casio 2.2-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 704 kB
  • ctags: 417
  • sloc: ansic: 3,452; makefile: 90
file content (328 lines) | stat: -rw-r--r-- 6,453 bytes parent folder | download | duplicates (4)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 *
 *              This program is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation;
 * 		Look at the file LICENSE for details
 *
*/
#ifndef     CASIO_H
#define	    CASIO_H 1
#ifdef      IN_CAS
#define	    Cext
#else
#define	    Cext  extern
#endif

#include    <stdio.h>
#include    <string.h>
#include    <errno.h>
#include    <sys/time.h>
#include    <sys/types.h>
#include    <sys/stat.h>
#include    <unistd.h>
#include    <termios.h>
#include    <fcntl.h>
#include    <signal.h>
#include    <time.h>
#include    <string.h>
#include    <stdlib.h>

#ifndef __i386__
#define swapl(x)	\
        ((x & 0xff000000U) >> 24) | \
        ((x & 0x00ff0000U) >>  8) | \
        ((x & 0x0000ff00U) <<  8) | \
        ((x & 0x000000ffU) << 24)
#define swaps(x)	\
        ((x & 0xff00) >> 8) | \
        ((x & 0x00ff) << 8)

#define ntohl(x)	swapl(x)
#define ntohs(x)	swaps(x)
#define htonl(x)	swapl(x)
#define htons(x)	swaps(x)

#define NTOHL(x)        (x) = ntohl((u_long)x)
#define NTOHS(x)        (x) = ntohs((u_short)x)
#define HTONL(x)        (x) = htonl((u_long)x)
#define HTONS(x)        (x) = htons((u_short)x)

#endif

/*
 * defines:
 */
#define READ    1
#define WRITE   0
#define WAIT    1
#define NOWAIT  0
#define TIMEOUT  60500L
#define MAXTYPE 16

/*
 * Control codes for handshake
 */
#if defined(Solaris2)
#define CR              '\r'
#define LF              '\n'
#else
#define CR              0x0d
#define LF              0x0a
#endif /* defined(Solaris2) */
#define XON             0x11
#define XOFF            0x13
#define ACK             0x23
#define NACK            0x3f
#define STOP            0x21
#define IACK		0xBD	/* Ack for Illuminator */
#define ILLH		0x8A	/* recor header for Illuminator */

#define RCLINELEN       80
#define RCFNAME         "~/.casiorc"

#define DEFAULTDB       "~/.casiodb"

#define NELEM(a)        ((int)(sizeof(a) / sizeof((a)[0])))


typedef unsigned char   byte ;
typedef unsigned short  word ;
/*
 * Structure of a record header as it is
 * exhanged with the CASIO
 */
typedef struct
{
        byte    marker ;        /* ':' marks the start of a record              */
        word    nbytes ;        /* 2 digit ASCII, # databytes                   */
        word    type ;          /* 2 digit ASCII, record type                   */
        word    low ;           /* 2 digit ASCII, low memory address            */
        word    high ;          /* 2 digit ASCII, high memory address           */
} CasioHeader ;

/*
 * Internal representation of such a header
 */
typedef struct
{
       byte    ourhead ;        /* always 0x8A */
        byte    type ;        /* type*/
        byte    nbytes ;        /* number of databytes in the record  */

} Header ;

int     bytelen,
        tflag ,
        debugmode;


/*
 * variables for getopt
 */
extern char *optarg;
extern int optind;
int ch;

char *tilde_expand_filename(const char *filename, uid_t my_uid);

FILE *dbg;
FILE *data;
FILE *casiofile;
time_t now;
struct tm *tmstruct;
char tbuff[256];
char deb[256];
char dat[256];





typedef struct
{
byte type;
byte length;
byte data[256];
byte cksum;
struct casiorec *next;
} casiorec;


typedef struct
{
byte text;
byte data[254];
} tel1;

typedef struct
{
byte day;
byte month;
byte year;
byte text;
byte data[251];
} memot;

typedef struct
{
byte day;
byte month;
byte year;
byte text;
byte priority;
byte text2;
byte data[249];
} todot;

typedef struct
{
byte day;
byte month;
byte year;
byte unused;
byte sctype;
byte text;
byte data[249];
} schd2;

typedef struct
{
byte day;
byte month;
byte year;
byte smin;
byte shour;
byte emin;
byte ehour;
byte amin;
byte ahour;
byte unused;
byte sctype;
byte text;
byte data[246];
} schd3;

typedef struct
{
byte day;
byte month;
byte year;
byte day2;
byte month2;
byte year2;
byte unused;
byte sctype;
byte text;
byte data[246];
} schd1;

typedef struct
{
byte day;
byte month;
byte year;
byte unused;
byte paytype;
byte exptype;
byte receipt;
byte amount[5];
byte text;
byte data[249];
} expense;

typedef struct
{
byte day;
byte month;
byte year;  /* always hex FC */
byte day2;
byte month2;
byte year2;
byte unused;
byte amin;
byte ahour;   /* FF if alarm has expired */
byte icon;
byte unused2;
byte text;
byte data[244];
} remind;

/*
 * global variables:
 */
byte nbytes;

byte Stopped;

byte LastRead, WriteStatus;
time_t now;
struct tm *tmstruct;
char tbuff[256];
char deb[256];
char dat[256];

CasioHeader CHeader;
static struct termios term;
static struct termios save_stdin;
static struct termios oldterm;

Header MHeader;
casiorec ourdata;

unsigned int Record;
int blkflg;
byte DataBuffer[512], WBuffer[1024];
byte Direction ;
int firstheader;



/*
byte Direction = WRITE;
byte Direction = WRITE;
byte Direction = READ;
*/


int NOCHECK = 0;
byte ourheader = 0x8A;
int displayed[17]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};


char rectypes[MAXTYPE][10]={"Tel1","Tel2","Tel3","Memo1","Memo2","Memo3","Todo1","Todo2","Todo3","Expense1","Expense2","Expense3","schedule1","schedule2","schedule3","Reminder"};

#ifdef jamal
char rectypes[MAXTYPE][10]={"Tel1","Tel2","Tel3","Memo1","Memo2","Memo3","Todo1","Todo2","Todo3","Expense1","Expense2","Expense3","schedule1","schedule2","schedule3","Reminder"};
int displayed[17]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

char tels[8][32]={"Name","Phone #1","Phone #2","Phone #3","Company","Address","Email","Note/Position"};
char expt[8][32]={"Meals","Hotel","Car","Phone","Fares","Entertainment","Tips","Misc."};
char payt[8][32]={"Cash","Check","Credit Card","other","other1","other2","other3","other4"};
#endif
/*
 * function prototypes:
 */
void UpperCase (char *s);
byte ReadByte (int secs,int usecs,int mode );
void ReadHeader (void);
void WriteByte (byte d);
void WaitForCasio (void);
int WriteLine (FILE * infile);
void WriteBuffer (casiorec *ourdata);
byte ReadHex (void);
byte atoh (char c);
void ReadLine (void);
char htoa (byte c);
void DisplayStatus (void);
int kbhit (void);
int tty_cbreak (int fd);	/* put stdin into a raw mode */
int tty_reset (int fd);		/* restore stdins's mode */
static void sig_catch (int);	/*signal catcher  */
void terminate ();		/* terminator */
int cas_cksum();   /* computes checksum for illuminator */
int (*displayers[16])();
casiorec *therecs[16];
extern int waitforchar (int fd , unsigned int secs, unsigned int usecs);

#endif