static char rcsid[] = "@(#)$Id: strings.c,v 1.18 2006/04/09 07:37:19 hurtta Exp $";
/******************************************************************************
* The Elm (ME+) Mail System - $Revision: 1.18 $ $State: Exp $
*
* Modified by: Kari Hurtta <hurtta+elm@posti.FMI.FI>
* (was hurtta+elm@ozone.FMI.FI)
******************************************************************************
* The Elm Mail System
*
* Copyright (c) 1986, 1987 Dave Taylor
* Copyright (c) 1988, 1989, 1990, 1991 USENET Community Trust
*****************************************************************************/
/** This file contains all the string oriented functions for the
ELM Mailer, and lots of other generally useful string functions!
For BSD systems, this file also includes the function "tolower"
to translate the given character from upper case to lower case.
**/
#include "def_elm.h"
#include "s_elm.h"
DEBUG_VAR(Debug,__FILE__,"misc");
/** forward declarations **/
char **argv_from_to(to)
char *to;
{
int count=1;
int idx = 0, q = 0, i;
char *ptr=to;
char *last;
char **res;
DPRINT(Debug,8, (&Debug, "argv_from_to: to=%s\n",to));
while (*ptr) {
int len = rfc822_toklen(ptr);
if (len == 1 && *ptr == COMMA)
count++;
ptr += len;
}
DPRINT(Debug,8, (&Debug, " count=%d\n",count));
res = safe_malloc((count + 1) * sizeof (char *));
ptr = to;
last = ptr;
while (*ptr) {
int len = rfc822_toklen(ptr);
DPRINT(Debug,20, (&Debug, " token: %.*s\n",len,ptr));
if (len == 1 && *ptr == ',' && last && !q) {
int k;
*ptr = '\0';
rfc822_reap_comments(last,NULL,0);
k = strlen(last);
while(k > 0 && last[k-1] == ' ')
k--;
last[k] = '\0';
res[idx++] = last;
DPRINT(Debug,20, (&Debug, " addr: %s\n",last));
last = NULL;
} else if (len == 1 && *ptr == '<')
q = 1;
else if (len == 1 && *ptr == '>')
q = 0;
if (*ptr && !last && *ptr != ' ')
last = ptr;
ptr += len;
}
if (last) {
int k;
*ptr = '\0';
rfc822_reap_comments(last,NULL,0);
k = strlen(last);
while(k > 0 && last[k-1] == ' ')
k--;
last[k] = '\0';
res[idx++] = last;
DPRINT(Debug,20, (&Debug,
" addr: %s\n",last));
last = NULL;
}
res[idx] = 0;
DPRINT(Debug,8, (&Debug, " idx=%d\n",idx));
for (i = 0; i < idx; i++)
DPRINT(Debug,8, (&Debug, " [%d]=%s\n",i,res[i]));
return res;
}
void split_word(buffer, first, rest)
char *buffer, *first, *rest;
{
int len;
/** Rip the buffer into first word and rest of word, translating it
all to lower case as we go along..
**/
/** skip leading white space, just in case.. **/
while(whitespace(*buffer)) buffer++;
/** now copy into 'first' until we hit white space or EOLN **/
while (*buffer) {
len = len_next_part(buffer);
if (len == 1 && isspace(*buffer))
break;
while (--len >= 0) {
#ifdef ASCII_CTYPE
if (!isascii(*buffer))
*first = *buffer;
else
#endif
*first = tolower((unsigned char)*buffer);
buffer++;
first++;
}
}
*first = '\0';
while (whitespace(*buffer)) buffer++;
/*
* no need to check rest of buffer for quoted strings, we are taking
* it all anyway.
*/
for (; *buffer; buffer++, rest++)
#ifdef ASCII_CTYPE
if (!isascii(*buffer))
*rest = *buffer;
else
#endif
*rest = tolower((unsigned char)*buffer);
*rest = '\0';
return;
}
void Centerline(line, string, page)
int line;
char *string;
struct menu_context *page;
{
/** Output 'string' on the given line, centered. **/
int length, col;
int LINES, COLUMNS;
menu_get_sizes(page, &LINES, &COLUMNS);
length = strlen(string);
if (length > COLUMNS)
col = 0;
else
col = (COLUMNS - length) / 2;
menu_PutLine0(page,line, col, string);
}
char *argv_zero(string)
CONST char *string;
{
/** given a string of the form "/something/name" return a
string of the form "name"... **/
static char buffer[NLEN];
int i, j=0;
for (i=strlen(string)-1; string[i] != '/'; i--)
buffer[j++] = string[i];
buffer[j] = '\0';
reverse(buffer);
return( (char *) buffer);
}
/*
* Local Variables:
* mode:c
* c-basic-offset:4
* buffer-file-coding-system: iso-8859-1
* End:
*/
syntax highlighted by Code2HTML, v. 0.9.1