imapext-2007
diff src/osdep/vms/nl_vms.c @ 0:ada5e610ab86
imap-2007e
author | yuuji@gentei.org |
---|---|
date | Mon, 14 Sep 2009 15:17:45 +0900 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/vms/nl_vms.c Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,92 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: UNIX/VMS newline routines 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 1 August 1988 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 +/* Copy string with CRLF newlines 1.33 + * Accepts: destination string 1.34 + * pointer to size of destination string buffer 1.35 + * source string 1.36 + * length of source string 1.37 + * Returns: length of copied string 1.38 + */ 1.39 + 1.40 +unsigned long strcrlfcpy (unsigned char **dst,unsigned long *dstl, 1.41 + unsigned char *src,unsigned long srcl) 1.42 +{ 1.43 + long i = srcl * 2,j; 1.44 + unsigned char c,*d = src; 1.45 + if (*dst) { /* candidate destination provided? */ 1.46 + /* count NLs if doesn't fit worst-case */ 1.47 + if (i > *dstl) for (i = j = srcl; j; --j) if (*d++ == '\012') i++; 1.48 + /* still too small, must reset destination */ 1.49 + if (i > *dstl) fs_give ((void **) dst); 1.50 + } 1.51 + /* make a new buffer if needed */ 1.52 + if (!*dst) *dst = (char *) fs_get ((*dstl = i) + 1); 1.53 + d = *dst; /* destination string */ 1.54 + if (srcl) do { /* main copy loop */ 1.55 + if ((c = *src++) < '\016') { 1.56 + /* prepend CR to LF */ 1.57 + if (c == '\012') *d++ = '\015'; 1.58 + /* unlikely CR */ 1.59 + else if ((c == '\015') && (srcl > 1) && (*src == '\012')) { 1.60 + *d++ = c; /* copy the CR */ 1.61 + c = *src++; /* grab the LF */ 1.62 + --srcl; /* adjust the count */ 1.63 + } 1.64 + } 1.65 + *d++ = c; /* copy character */ 1.66 + } while (--srcl); 1.67 + *d = '\0'; /* tie off destination */ 1.68 + return d - *dst; /* return length */ 1.69 +} 1.70 + 1.71 +/* Length of string after strcrlfcpy applied 1.72 + * Accepts: source string 1.73 + * Returns: length of string 1.74 + */ 1.75 + 1.76 +unsigned long strcrlflen (STRING *s) 1.77 +{ 1.78 + unsigned long pos = GETPOS (s); 1.79 + unsigned long i = SIZE (s); 1.80 + unsigned long j = i; 1.81 + while (j--) switch (SNX (s)) {/* search for newlines */ 1.82 + case '\015': /* unlikely carriage return */ 1.83 + if (j && (CHR (s) == '\012')) { 1.84 + SNX (s); /* eat the line feed */ 1.85 + j--; 1.86 + } 1.87 + break; 1.88 + case '\012': /* line feed? */ 1.89 + i++; 1.90 + default: /* ordinary chararacter */ 1.91 + break; 1.92 + } 1.93 + SETPOS (s,pos); /* restore old position */ 1.94 + return i; 1.95 +}