annotate src/c-client/flstring.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: File string routines
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * Networks and Distributed Computing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * Computing & Communications
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Administration Building, AG-44
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Internet: MRC@CAC.Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 * Date: 15 April 1997
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 * Last Edited: 6 December 2006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 #include <stdio.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 #include "mail.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 #include "flstring.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 /* String driver for stdio file strings */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 static void file_string_init (STRING *s,void *data,unsigned long size);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 static char file_string_next (STRING *s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 static void file_string_setpos (STRING *s,unsigned long i);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 STRINGDRIVER file_string = {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41 file_string_init, /* initialize string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 file_string_next, /* get next byte in string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 file_string_setpos /* set position in string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 };
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 /* Initialize mail string structure for file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 * pointer to string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 * size of string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 static void file_string_init (STRING *s,void *data,unsigned long size)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 s->data = data; /* note file descriptor */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 /* big enough for one byte */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 s->chunk = s->curpos = (char *) &s->data1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 s->size = size; /* data size */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 s->cursize = s->chunksize = 1;/* always call stdio */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 file_string_setpos (s,0); /* initial offset is 0 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 /* Get next character from string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 * Returns: character, string structure chunk refreshed
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 static char file_string_next (STRING *s)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 char ret = *s->curpos;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 s->offset++; /* advance position */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 s->cursize = 1; /* reset size */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 *s->curpos = (char) getc ((FILE *) s->data);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 return ret;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 /* Set string pointer position
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 * new position
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 static void file_string_setpos (STRING *s,unsigned long i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 s->offset = i; /* note new offset */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87 fseek ((FILE *) s->data,i,SEEK_SET);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 /* in case using returnstringstruct hack */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 s->chunk = s->curpos = (char *) &s->data1;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90 *s->curpos = (char) getc ((FILE *) s->data);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 }

yatex.org