Blame libmisc/unquote.c

rpm-build 0a0c83
/*
rpm-build 0a0c83
  File: unquote.c
rpm-build 0a0c83
rpm-build 0a0c83
  Copyright (C) 2003 Andreas Gruenbacher <a.gruenbacher@bestbits.at>
rpm-build 0a0c83
rpm-build 0a0c83
  This program is free software; you can redistribute it and/or modify it under
rpm-build 0a0c83
  the terms of the GNU Lesser General Public License as published by the
rpm-build 0a0c83
  Free Software Foundation; either version 2.1 of the License, or (at
rpm-build 0a0c83
  your option) any later version.
rpm-build 0a0c83
rpm-build 0a0c83
  This program is distributed in the hope that it will be useful, but WITHOUT
rpm-build 0a0c83
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rpm-build 0a0c83
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
rpm-build 0a0c83
  License for more details.
rpm-build 0a0c83
rpm-build 0a0c83
  You should have received a copy of the GNU Lesser General Public
rpm-build 0a0c83
  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
rpm-build 0a0c83
*/
rpm-build 0a0c83
rpm-build 0a0c83
#include "config.h"
rpm-build 0a0c83
#include <stdio.h>
rpm-build 0a0c83
#include <stdlib.h>
rpm-build 0a0c83
#include <ctype.h>
rpm-build 0a0c83
#include "misc.h"
rpm-build 0a0c83
rpm-build 0a0c83
char *__acl_unquote(char *str)
rpm-build 0a0c83
{
rpm-build 0a0c83
	unsigned char *s, *t;
rpm-build 0a0c83
rpm-build 0a0c83
	if (!str)
rpm-build 0a0c83
		return str;
rpm-build 0a0c83
rpm-build 0a0c83
	for (s = (unsigned char *)str; *s != '\0'; s++)
rpm-build 0a0c83
		if (*s == '\\')
rpm-build 0a0c83
			break;
rpm-build 0a0c83
	if (*s == '\0')
rpm-build 0a0c83
		return str;
rpm-build 0a0c83
rpm-build 0a0c83
#define isoctal(c) \
rpm-build 0a0c83
	((c) >= '0' && (c) <= '7')
rpm-build 0a0c83
rpm-build 0a0c83
	t = s;
rpm-build 0a0c83
	do {
rpm-build 0a0c83
		if (*s == '\\' &&
rpm-build 0a0c83
		    isoctal(*(s+1)) && isoctal(*(s+2)) && isoctal(*(s+3))) {
rpm-build 0a0c83
			*t++ = ((*(s+1) - '0') << 6) +
rpm-build 0a0c83
			       ((*(s+2) - '0') << 3) +
rpm-build 0a0c83
			       ((*(s+3) - '0')     );
rpm-build 0a0c83
			s += 3;
rpm-build 0a0c83
		} else if (*s == '\\' && *(s+1) == '\\') {
rpm-build 0a0c83
			*t++ = *s++;
rpm-build 0a0c83
		} else
rpm-build 0a0c83
			*t++ = *s;
rpm-build 0a0c83
	} while (*s++ != '\0');
rpm-build 0a0c83
rpm-build 0a0c83
	return str;
rpm-build 0a0c83
}