home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / imap / src / c-client / flstring.c < prev    next >
C/C++ Source or Header  |  1998-09-16  |  3KB  |  95 lines

  1. /*
  2.  * Program:    File string routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    15 April 1997
  13.  * Last Edited:    15 April 1997
  14.  *
  15.  * Copyright 1997 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <stdio.h>
  38. #include "mail.h"
  39. #include "osdep.h"
  40. #include "misc.h"
  41. #include "flstring.h"
  42.  
  43. /* String driver for stdio file strings */
  44.  
  45. STRINGDRIVER file_string = {
  46.   file_string_init,        /* initialize string structure */
  47.   file_string_next,        /* get next byte in string structure */
  48.   file_string_setpos        /* set position in string structure */
  49. };
  50.  
  51.  
  52. /* Initialize mail string structure for file
  53.  * Accepts: string structure
  54.  *        pointer to string
  55.  *        size of string
  56.  */
  57.  
  58. void file_string_init (STRING *s,void *data,unsigned long size)
  59. {
  60.   s->data = data;        /* note file descriptor */
  61.                 /* big enough for one byte */
  62.   s->chunk = s->curpos = (char *) &s->data1;
  63.   s->size = size;        /* data size */
  64.   s->cursize = s->chunksize = 1;/* always call stdio */
  65.   file_string_setpos (s,0);    /* initial offset is 0 */
  66. }
  67.  
  68.  
  69. /* Get next character from string
  70.  * Accepts: string structure
  71.  * Returns: character, string structure chunk refreshed
  72.  */
  73.  
  74. char file_string_next (STRING *s)
  75. {
  76.   char ret = *s->curpos;
  77.   s->offset++;            /* advance position */
  78.   s->cursize = 1;        /* reset size */
  79.   *s->curpos = (char) getc ((FILE *) s->data);
  80.   return ret;
  81. }
  82.  
  83.  
  84. /* Set string pointer position
  85.  * Accepts: string structure
  86.  *        new position
  87.  */
  88.  
  89. void file_string_setpos (STRING *s,unsigned long i)
  90. {
  91.   s->offset = i;        /* note new offset */
  92.   fseek ((FILE *) s->data,i,L_SET);
  93.   *s->curpos = (char) getc ((FILE *) s->data);
  94. }
  95.