/* This file is part of mailfrom filter. -*- c -*- Copyright (C) 2006 Sergey Poznyakoff 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; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ MF_DEFUN(toupper, NUMBER, STRING string) { char *p; for (p = string; *p; p++) *p = toupper(*p); push(env, string); } END MF_DEFUN(tolower, NUMBER, STRING string) { char *p; for (p = string; *p; p++) *p = tolower(*p); push(env, string); } END MF_DEFUN(length, NUMBER, STRING string) { push(env, (STKVAL) strlen(string)); } END MF_DEFUN(substring, STRING, STRING string, NUMBER start, NUMBER end) { long len = strlen(string); char *s; if (end < 0) end = len - 1; if (end < start) { long t = end; end = start; start = t; } if (start >= len || end >= len) { if (env_catch(env, mf_range) == 0) return; else runtime_error(env, "substring: argument out of range"); } len = end - start + 1; s = heap_reserve(env, len + 1); memcpy(s, string + start, len); s[len] = 0; push(env, (STKVAL)s); } END MF_INIT(string)