cleanup: remove unused tagutils code, and switch to standard int types

This commit is contained in:
Justin Maggard 2014-03-06 17:08:21 -08:00
parent cb95ca6e06
commit b9404d1847
9 changed files with 271 additions and 648 deletions

View File

@ -27,8 +27,8 @@ minidlnad_SOURCES = minidlna.c upnphttp.c upnpdescgen.c upnpsoap.c \
options.c minissdp.c uuid.c upnpevents.c \
sql.c utils.c metadata.c scanner.c inotify.c \
tivo_utils.c tivo_beacon.c tivo_commands.c \
tagutils/textutils.c tagutils/misc.c tagutils/tagutils.c \
playlist.c image_utils.c albumart.c log.c
playlist.c image_utils.c albumart.c log.c \
tagutils/tagutils.c
#if NEED_VORBIS
vorbisflag = -lvorbis

View File

@ -1,125 +0,0 @@
//=========================================================================
// FILENAME : misc.c
// DESCRIPTION : Miscelleneous funcs
//=========================================================================
// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
//=========================================================================
/* 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 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h>
#else
#include <endian.h>
#endif
#include "misc.h"
inline __u16
le16_to_cpu(__u16 le16)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le16;
#else
__u16 be16 = ((le16 << 8) & 0xff00) | ((le16 >> 8) & 0x00ff);
return be16;
#endif
}
inline __u32
le32_to_cpu(__u32 le32)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le32;
#else
__u32 be32 =
((le32 << 24) & 0xff000000) |
((le32 << 8) & 0x00ff0000) |
((le32 >> 8) & 0x0000ff00) |
((le32 >> 24) & 0x000000ff);
return be32;
#endif
}
inline __u64
le64_to_cpu(__u64 le64)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le64;
#else
__u64 be64;
__u8 *le64p = (__u8*)&le64;
__u8 *be64p = (__u8*)&be64;
be64p[0] = le64p[7];
be64p[1] = le64p[6];
be64p[2] = le64p[5];
be64p[3] = le64p[4];
be64p[4] = le64p[3];
be64p[5] = le64p[2];
be64p[6] = le64p[1];
be64p[7] = le64p[0];
return be64;
#endif
}
inline __u8
fget_byte(FILE *fp)
{
__u8 d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
return d;
}
inline __u16
fget_le16(FILE *fp)
{
__u16 d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le16_to_cpu(d);
return d;
}
inline __u32
fget_le32(FILE *fp)
{
__u32 d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le32_to_cpu(d);
return d;
}
inline __u32
cpu_to_be32(__u32 cpu32)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
__u32 be32 =
((cpu32 << 24) & 0xff000000) |
((cpu32 << 8) & 0x00ff0000) |
((cpu32 >> 8) & 0x0000ff00) |
((cpu32 >> 24) & 0x000000ff);
return be32;
#else
return cpu32;
#endif
}

View File

@ -1,51 +0,0 @@
//=========================================================================
// FILENAME : misc.h
// DESCRIPTION : Header for misc.c
//=========================================================================
// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
//=========================================================================
/* 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 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SCANNER_MISC_H
#define _SCANNER_MISC_H
typedef unsigned char __u8;
typedef signed char __s8;
typedef unsigned short __u16;
typedef signed short __s16;
typedef unsigned int __u32;
typedef signed int __s32;
#if __WORDSIZE == 64
typedef unsigned long __u64;
typedef signed long __s64;
#else
typedef unsigned long long __u64;
typedef signed long long __s64;
#endif
inline __u16 le16_to_cpu(__u16 le16);
inline __u32 le32_to_cpu(__u32 le32);
inline __u64 le64_to_cpu(__u64 le64);
inline __u8 fget_byte(FILE *fp);
inline __u16 fget_le16(FILE *fp);
inline __u32 fget_le32(FILE *fp);
inline __u32 cpu_to_be32(__u32 cpu32);
extern char * sha1_hex(char *key);
#endif

View File

@ -19,9 +19,139 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h>
#else
#include <endian.h>
#endif
static inline uint16_t
le16_to_cpu(uint16_t le16)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le16;
#else
uint16_t be16 = ((le16 << 8) & 0xff00) | ((le16 >> 8) & 0x00ff);
return be16;
#endif
}
static inline uint32_t
le32_to_cpu(uint32_t le32)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le32;
#else
uint32_t be32 =
((le32 << 24) & 0xff000000) |
((le32 << 8) & 0x00ff0000) |
((le32 >> 8) & 0x0000ff00) |
((le32 >> 24) & 0x000000ff);
return be32;
#endif
}
static inline uint64_t
le64_to_cpu(uint64_t le64)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
return le64;
#else
uint64_t be64;
uint8_t *le64p = (uint8_t*)&le64;
uint8_t *be64p = (uint8_t*)&be64;
be64p[0] = le64p[7];
be64p[1] = le64p[6];
be64p[2] = le64p[5];
be64p[3] = le64p[4];
be64p[4] = le64p[3];
be64p[5] = le64p[2];
be64p[6] = le64p[1];
be64p[7] = le64p[0];
return be64;
#endif
}
static inline uint32_t
cpu_to_be32(uint32_t cpu32)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint32_t be32 =
((cpu32 << 24) & 0xff000000) |
((cpu32 << 8) & 0x00ff0000) |
((cpu32 >> 8) & 0x0000ff00) |
((cpu32 >> 24) & 0x000000ff);
return be32;
#else
return cpu32;
#endif
}
static inline uint8_t
fget_byte(FILE *fp)
{
uint8_t d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
return d;
}
static inline uint16_t
fget_le16(FILE *fp)
{
uint16_t d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le16_to_cpu(d);
return d;
}
static inline uint32_t
fget_le32(FILE *fp)
{
uint32_t d;
if (!fread(&d, sizeof(d), 1, fp))
return 0;
d = le32_to_cpu(d);
return d;
}
// NOTE: support U+0000 ~ U+FFFF only.
static int
utf16le_to_utf8(char *dst, int n, uint16_t utf16le)
{
uint16_t wc = le16_to_cpu(utf16le);
if (wc < 0x80)
{
if (n < 1)
return 0;
*dst++ = wc & 0xff;
return 1;
}
else if (wc < 0x800)
{
if (n < 2)
return 0;
*dst++ = 0xc0 | (wc>>6);
*dst++ = 0x80 | (wc & 0x3f);
return 2;
}
else
{
if (n < 3)
return 0;
*dst++ = 0xe0 | (wc>>12);
*dst++ = 0x80 | ((wc>>6) & 0x3f);
*dst++ = 0x80 | (wc & 0x3f);
return 3;
}
}
static int
_asf_read_file_properties(FILE *fp, asf_file_properties_t *p, __u32 size)
_asf_read_file_properties(FILE *fp, asf_file_properties_t *p, uint32_t size)
{
int len;
@ -86,7 +216,7 @@ _asf_read_audio_stream(FILE *fp, struct song_metadata *psong, int size)
}
static int
_asf_read_media_stream(FILE *fp, struct song_metadata *psong, __u32 size)
_asf_read_media_stream(FILE *fp, struct song_metadata *psong, uint32_t size)
{
asf_media_stream_t s;
avi_audio_format_t wfx;
@ -118,7 +248,7 @@ _asf_read_media_stream(FILE *fp, struct song_metadata *psong, __u32 size)
}
static int
_asf_read_stream_object(FILE *fp, struct song_metadata *psong, __u32 size)
_asf_read_stream_object(FILE *fp, struct song_metadata *psong, uint32_t size)
{
asf_stream_object_t s;
int len;
@ -143,7 +273,7 @@ _asf_read_stream_object(FILE *fp, struct song_metadata *psong, __u32 size)
}
static int
_asf_read_extended_stream_object(FILE *fp, struct song_metadata *psong, __u32 size)
_asf_read_extended_stream_object(FILE *fp, struct song_metadata *psong, uint32_t size)
{
int i, len;
long off;
@ -198,7 +328,7 @@ _asf_read_extended_stream_object(FILE *fp, struct song_metadata *psong, __u32 si
}
static int
_asf_read_header_extension(FILE *fp, struct song_metadata *psong, __u32 size)
_asf_read_header_extension(FILE *fp, struct song_metadata *psong, uint32_t size)
{
off_t pos;
long off;
@ -237,11 +367,11 @@ static int
_asf_load_string(FILE *fp, int type, int size, char *buf, int len)
{
unsigned char data[2048];
__u16 wc;
uint16_t wc;
int i, j;
__s32 *wd32;
__s64 *wd64;
__s16 *wd16;
int32_t *wd32;
int64_t *wd64;
int16_t *wd16;
i = 0;
if(size && (size <= sizeof(data)) && (size == fread(data, 1, size, fp)))
@ -252,8 +382,8 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len)
case ASF_VT_UNICODE:
for(j = 0; j < size; j += 2)
{
wd16 = (__s16 *) &data[j];
wc = (__u16)*wd16;
wd16 = (int16_t *) &data[j];
wc = (uint16_t)*wd16;
i += utf16le_to_utf8(&buf[i], len - i, wc);
}
break;
@ -269,14 +399,14 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len)
case ASF_VT_DWORD:
if(size >= 4)
{
wd32 = (__s32 *) &data[0];
wd32 = (int32_t *) &data[0];
i = snprintf(buf, len, "%d", le32_to_cpu(*wd32));
}
break;
case ASF_VT_QWORD:
if(size >= 8)
{
wd64 = (__s64 *) &data[0];
wd64 = (int64_t *) &data[0];
#if __WORDSIZE == 64
i = snprintf(buf, len, "%ld", le64_to_cpu(*wd64));
#else
@ -287,7 +417,7 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len)
case ASF_VT_WORD:
if(size >= 2)
{
wd16 = (__s16 *) &data[0];
wd16 = (int16_t *) &data[0];
i = snprintf(buf, len, "%d", le16_to_cpu(*wd16));
}
break;

View File

@ -30,9 +30,9 @@
#endif
typedef struct _GUID {
__u32 l;
__u16 w[2];
__u8 b[8];
uint32_t l;
uint16_t w[2];
uint8_t b[8];
} __PACKED__ GUID;
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
@ -117,166 +117,166 @@ DEFINE_GUID(ASF_StreamBufferStream, SWAP32(0x3AFB65E2), SWAP16(0x47EF), SWAP16(0
0xAC, 0x2C, 0x70, 0xA9, 0x0D, 0x71, 0xD3, 0x43);
typedef struct _BITMAPINFOHEADER {
__u32 biSize;
__s32 biWidth;
__s32 biHeight;
__u16 biPlanes;
__u16 biBitCount;
__u32 biCompression;
__u32 biSizeImage;
__s32 biXPelsPerMeter;
__s32 biYPelsPerMeter;
__u32 biClrUsed;
__u32 biClrImportant;
uint32_t biSize;
int32_t biWidth;
int32_t biHeight;
uint16_t biPlanes;
uint16_t biBitCount;
uint32_t biCompression;
uint32_t biSizeImage;
int32_t biXPelsPerMeter;
int32_t biYPelsPerMeter;
uint32_t biClrUsed;
uint32_t biClrImportant;
} __PACKED__ BITMAPINFOHEADER;
typedef struct _WAVEFORMATEX {
__u16 wFormatTag;
__u16 nChannels;
__u32 nSamplesPerSec;
__u32 nAvgBytesPerSec;
__u16 nBlockAlign;
__u16 wBitsPerSample;
__u16 cbSize;
uint16_t wFormatTag;
uint16_t nChannels;
uint32_t nSamplesPerSec;
uint32_t nAvgBytesPerSec;
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
uint16_t cbSize;
} __PACKED__ WAVEFORMATEX;
typedef struct _asf_stream_object_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID StreamType;
GUID ErrorCorrectionType;
__u64 TimeOffset;
__u32 TypeSpecificSize;
__u32 ErrorCorrectionSize;
__u16 StreamNumber;
__u32 Reserved;
uint64_t TimeOffset;
uint32_t TypeSpecificSize;
uint32_t ErrorCorrectionSize;
uint16_t StreamNumber;
uint32_t Reserved;
} __PACKED__ asf_stream_object_t;
typedef struct _asf_media_stream_t {
asf_stream_object_t Hdr;
GUID MajorType;
GUID SubType;
__u32 FixedSizeSamples;
__u32 TemporalCompression;
__u32 SampleSize;
uint32_t FixedSizeSamples;
uint32_t TemporalCompression;
uint32_t SampleSize;
GUID FormatType;
__u32 FormatSize;
uint32_t FormatSize;
} __PACKED__ asf_media_stream_t;
typedef struct _avi_audio_format_t {
__u16 wFormatTag;
__u16 nChannels;
__u32 nSamplesPerSec;
__u32 nAvgBytesPerSec;
__u16 nBlockAlign;
__u16 wBitsPerSample;
__u16 cbSize;
uint16_t wFormatTag;
uint16_t nChannels;
uint32_t nSamplesPerSec;
uint32_t nAvgBytesPerSec;
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
uint16_t cbSize;
} __PACKED__ avi_audio_format_t;
typedef struct _asf_extended_stream_object_t {
GUID ID;
__u64 Size;
__u64 StartTime;
__u64 EndTime;
__u32 DataBitrate;
__u32 BufferSize;
__u32 InitialBufferFullness;
__u32 AltDataBitrate;
__u32 AltBufferSize;
__u32 AltInitialBufferFullness;
__u32 MaximumObjectSize;
__u32 Flags;
__u16 StreamNumber;
__u16 LanguageIDIndex;
__u64 AvgTimePerFrame;
__u16 StreamNameCount;
__u16 PayloadExtensionSystemCount;
uint64_t Size;
uint64_t StartTime;
uint64_t EndTime;
uint32_t DataBitrate;
uint32_t BufferSize;
uint32_t InitialBufferFullness;
uint32_t AltDataBitrate;
uint32_t AltBufferSize;
uint32_t AltInitialBufferFullness;
uint32_t MaximumObjectSize;
uint32_t Flags;
uint16_t StreamNumber;
uint16_t LanguageIDIndex;
uint64_t AvgTimePerFrame;
uint16_t StreamNameCount;
uint16_t PayloadExtensionSystemCount;
} __PACKED__ asf_extended_stream_object_t;
typedef struct _asf_stream_name_t {
__u16 ID;
__u16 Length;
uint16_t ID;
uint16_t Length;
} __PACKED__ asf_stream_name_t;
typedef struct _asf_payload_extension_t {
GUID ID;
__u16 Size;
__u32 InfoLength;
uint16_t Size;
uint32_t InfoLength;
} __PACKED__ asf_payload_extension_t;
typedef struct _asf_object_t {
GUID ID;
__u64 Size;
uint64_t Size;
} __PACKED__ asf_object_t;
typedef struct _asf_codec_entry_t {
__u16 Type;
__u16 NameLen;
__u32 Name;
__u16 DescLen;
__u32 Desc;
__u16 InfoLen;
__u32 Info;
uint16_t Type;
uint16_t NameLen;
uint32_t Name;
uint16_t DescLen;
uint32_t Desc;
uint16_t InfoLen;
uint32_t Info;
} __PACKED__ asf_codec_entry_t;
typedef struct _asf_codec_list_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID Reserved;
__u64 NumEntries;
uint64_t NumEntries;
asf_codec_entry_t Entries[2];
asf_codec_entry_t VideoCodec;
} __PACKED__ asf_codec_list_t;
typedef struct _asf_content_description_t {
GUID ID;
__u64 Size;
__u16 TitleLength;
__u16 AuthorLength;
__u16 CopyrightLength;
__u16 DescriptionLength;
__u16 RatingLength;
__u32 Title;
__u32 Author;
__u32 Copyright;
__u32 Description;
__u32 Rating;
uint64_t Size;
uint16_t TitleLength;
uint16_t AuthorLength;
uint16_t CopyrightLength;
uint16_t DescriptionLength;
uint16_t RatingLength;
uint32_t Title;
uint32_t Author;
uint32_t Copyright;
uint32_t Description;
uint32_t Rating;
} __PACKED__ asf_content_description_t;
typedef struct _asf_file_properties_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID FileID;
__u64 FileSize;
__u64 CreationTime;
__u64 TotalPackets;
__u64 PlayDuration;
__u64 SendDuration;
__u64 Preroll;
__u32 Flags;
__u32 MinPacketSize;
__u32 MaxPacketSize;
__u32 MaxBitrate;
uint64_t FileSize;
uint64_t CreationTime;
uint64_t TotalPackets;
uint64_t PlayDuration;
uint64_t SendDuration;
uint64_t Preroll;
uint32_t Flags;
uint32_t MinPacketSize;
uint32_t MaxPacketSize;
uint32_t MaxBitrate;
} __PACKED__ asf_file_properties_t;
typedef struct _asf_header_extension_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID Reserved1;
__u16 Reserved2;
__u32 DataSize;
uint16_t Reserved2;
uint32_t DataSize;
} __PACKED__ asf_header_extension_t;
typedef struct _asf_video_stream_t {
asf_stream_object_t Hdr;
__u32 Width;
__u32 Height;
__u8 ReservedFlags;
__u16 FormatSize;
uint32_t Width;
uint32_t Height;
uint8_t ReservedFlags;
uint16_t FormatSize;
BITMAPINFOHEADER bmi;
__u8 ebih[1];
uint8_t ebih[1];
} __PACKED__ asf_video_stream_t;
typedef struct _asf_audio_stream_t {
@ -285,56 +285,56 @@ typedef struct _asf_audio_stream_t {
} __PACKED__ asf_audio_stream_t;
typedef struct _asf_payload_t {
__u8 StreamNumber;
__u8 MediaObjectNumber;
__u32 MediaObjectOffset;
__u8 ReplicatedDataLength;
__u32 ReplicatedData[2];
__u32 PayloadLength;
uint8_t StreamNumber;
uint8_t MediaObjectNumber;
uint32_t MediaObjectOffset;
uint8_t ReplicatedDataLength;
uint32_t ReplicatedData[2];
uint32_t PayloadLength;
} __PACKED__ asf_payload_t;
typedef struct _asf_packet_t {
__u8 TypeFlags;
__u8 ECFlags;
__u8 ECType;
__u8 ECCycle;
__u8 PropertyFlags;
__u32 PacketLength;
__u32 Sequence;
__u32 PaddingLength;
__u32 SendTime;
__u16 Duration;
__u8 PayloadFlags;
uint8_t TypeFlags;
uint8_t ECFlags;
uint8_t ECType;
uint8_t ECCycle;
uint8_t PropertyFlags;
uint32_t PacketLength;
uint32_t Sequence;
uint32_t PaddingLength;
uint32_t SendTime;
uint16_t Duration;
uint8_t PayloadFlags;
asf_payload_t Payload;
} __PACKED__ asf_packet_t;
typedef struct _asf_data_object_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID FileID;
__u64 TotalPackets;
uint64_t TotalPackets;
unsigned short Reserved;
} __PACKED__ asf_data_object_t;
typedef struct _asf_padding_object_t {
GUID ID;
__u64 Size;
uint64_t Size;
} __PACKED__ asf_padding_object_t;
typedef struct _asf_simple_index_object_t {
GUID ID;
__u64 Size;
uint64_t Size;
GUID FileID;
__u32 IndexEntryTimeInterval;
__u32 MaximumPacketCount;
__u32 IndexEntriesCount;
uint32_t IndexEntryTimeInterval;
uint32_t MaximumPacketCount;
uint32_t IndexEntriesCount;
} __PACKED__ asf_simple_index_object_t;
typedef struct _asf_header_object_t {
GUID ID;
__u64 Size;
__u32 NumObjects;
__u16 Reserved;
uint64_t Size;
uint32_t NumObjects;
uint16_t Reserved;
asf_header_extension_t HeaderExtension;
asf_content_description_t ContentDescription;
asf_file_properties_t FileProperties;

View File

@ -24,9 +24,7 @@
#include <string.h>
#include <ctype.h>
#include "misc.h"
#include "tagutils.h"
#include "textutils.h"
#include "log.h"

View File

@ -40,11 +40,8 @@
#ifdef HAVE_ICONV
#include <iconv.h>
#endif
#include <sqlite3.h>
#include "tagutils.h"
#include "misc.h"
#include "textutils.h"
#include "../metadata.h"
#include "../utils.h"
#include "../log.h"

View File

@ -1,298 +0,0 @@
//=========================================================================
// FILENAME : textutils.c
// DESCRIPTION : Misc. text utilities
//=========================================================================
// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
//=========================================================================
/* 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 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "misc.h"
#include "textutils.h"
#include "../log.h"
static unsigned int
_char_htoi(char h)
{
if (h<'0')
return 0;
if (h<='9')
return h-'0';
if (h<'A')
return 0;
if (h<='F')
return h-'A'+10;
if (h<'a')
return 0;
if (h<='f')
return h-'a'+10;
return 0;
}
void
urldecode(char *src)
{
char c, *s, *d;
for (d=s=src; *s; s++, d++) {
c = *s;
if (c=='%') {
c = *++s;
if (c=='%')
c = '%';
else {
c = _char_htoi(c)<<4 | _char_htoi(*++s);
}
*d = c;
}
else {
*d = c;
}
}
*d = '\0';
}
#if 0
static int
is_ignoredword(const char *str)
{
int i;
if (!prefs.ignoredwords)
return 0;
for (i=0; prefs.ignoredwords[i].n; i++) {
if (!(strncasecmp(prefs.ignoredwords[i].word, str, prefs.ignoredwords[i].n))) {
char next_char = str[prefs.ignoredwords[i].n];
if (isalnum(next_char))
continue;
return prefs.ignoredwords[i].n;
}
}
return 0;
}
#endif
char *
skipspaces(const char *str)
{
while (isspace(*str)) str++;
return (char*) str;
}
/*
U+0040 (40): @ A B C D E F G H I J K L M N O
U+0050 (50): P Q R S T U V W X Y Z [ \ ] ^ _
U+0060 (60): ` a b c d e f g h i j k l m n o
U+0070 (70): p q r s t u v w x y z { | } ~
U+00c0 (c3 80): À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï
U+00d0 (c3 90): Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß
U+00e0 (c3 a0): à á â ã ä å æ ç è é ê ë ì í î ï
U+00f0 (c3 b0): ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
U+0100 (c4 80): Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď
U+0110 (c4 90): Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ
U+0120 (c4 a0): Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ Ī ī Ĭ ĭ Į į
U+0130 (c4 b0): İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ
U+0140 (c5 80): ŀ Ł ł Ń ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ
U+0150 (c5 90): Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ Ş ş
U+0160 (c5 a0): Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů
U+0170 (c5 b0): Ű ű Ų ų Ŵ ŵ Ŷ ŷ Ÿ Ź ź Ż ż Ž ž ſ
*/
// conversion table for latin diacritical char to ascii one char or two chars.
unsigned short UtoAscii[] = {
// U+00c0
0x0041,0x0041,0x0041,0x0041, 0x0041,0x0041,0x4145,0x0043, 0x0045,0x0045,0x0045,0x0045, 0x0049,0x0049,0x0049,0x0049,
0x0044,0x004e,0x004f,0x004f, 0x004f,0x004f,0x004f,0xc397, 0xc398,0x0055,0x0055,0x0055, 0x0055,0x0059,0x0050,0x5353,
// U+00e0
0x0041,0x0041,0x0041,0x0041, 0x0041,0x0041,0x4145,0x0043, 0x0045,0x0045,0x0045,0x0045, 0x0049,0x0049,0x0049,0x0049,
0x0044,0x004e,0x004f,0x004f, 0x004f,0x004f,0x004f,0xc397, 0xc398,0x0055,0x0055,0x0055, 0x0055,0x0059,0x0050,0x5353,
// U+0100
0x0041,0x0041,0x0041,0x0041, 0x0041,0x0041,0x0043,0x0043, 0x0043,0x0043,0x0043,0x0043, 0x0043,0x0043,0x0044,0x0044,
0x0044,0x0044,0x0045,0x0045, 0x0045,0x0045,0x0045,0x0045, 0x0045,0x0045,0x0045,0x0045, 0x0047,0x0047,0x0047,0x0047,
// U+0120
0x0047,0x0047,0x0047,0x0047, 0x0048,0x0048,0x0048,0x0048, 0x0049,0x0049,0x0049,0x0049, 0x0049,0x0049,0x0049,0x0049,
0x0049,0x0049,0x494a,0x494a, 0x004a,0x004a,0x004b,0x004b, 0x004b,0x004c,0x004c,0x004c, 0x004c,0x004c,0x004c,0x004c,
// U+0140
0x004c,0x004c,0x004c,0x004e, 0x004e,0x004e,0x004e,0x004e, 0x004e,0x004e,0x004e,0x004e, 0x004f,0x004f,0x004f,0x004f,
0x004f,0x004f,0x4f45,0x4f45, 0x0052,0x0052,0x0052,0x0052, 0x0052,0x0052,0x0053,0x0053, 0x0053,0x0053,0x0053,0x0053,
// U+0160
0x0053,0x0053,0x0054,0x0054, 0x0054,0x0054,0x0054,0x0054, 0x0055,0x0055,0x0055,0x0055, 0x0055,0x0055,0x0055,0x0055,
0x0055,0x0055,0x0055,0x0055, 0x0057,0x0057,0x0059,0x0059, 0x0059,0x005a,0x005a,0x005a, 0x005a,0x005a,0x005a,0xc5bf
};
// conversion table for toupper() function for latin diacritical char
unsigned short UtoUpper[] = {
// U+00c0
0xc380,0xc381,0xc382,0xc383, 0xc384,0xc385,0xc386,0xc387, 0xc388,0xc389,0xc38a,0xc38b, 0xc38c,0xc38d,0xc38e,0xc38f,
0xc390,0xc391,0xc392,0xc393, 0xc394,0xc395,0xc396,0xc397, 0xc398,0xc399,0xc39a,0xc39b, 0xc39c,0xc39d,0xc39e,0x5353,
// U+00e0
0xc380,0xc381,0xc382,0xc383, 0xc384,0xc385,0xc386,0xc387, 0xc388,0xc389,0xc38a,0xc38b, 0xc38c,0xc38d,0xc38e,0xc38f,
0xc390,0xc391,0xc392,0xc393, 0xc394,0xc395,0xc396,0xc397, 0xc398,0xc399,0xc39a,0xc39b, 0xc39c,0xc39d,0xc39e,0xc39f,
// U+0100
0xc480,0xc480,0xc482,0xc482, 0xc484,0xc484,0xc486,0xc486, 0xc488,0xc488,0xc48a,0xc48a, 0xc48c,0xc48c,0xc48e,0xc48e,
0xc490,0xc490,0xc492,0xc492, 0xc494,0xc494,0xc496,0xc496, 0xc498,0xc498,0xc49a,0xc49a, 0xc49c,0xc49c,0xc49e,0xc49e,
// U+0120
0xc4a0,0xc4a0,0xc4a2,0xc4a2, 0xc4a4,0xc4a4,0xc4a6,0xc4a6, 0xc4a8,0xc4a8,0xc4aa,0xc4aa, 0xc4ac,0xc4ac,0xc4ae,0xc4ae,
0xc4b0,0xc4b0,0xc4b2,0xc4b2, 0xc4b4,0xc4b4,0xc4b6,0xc4b6, 0xc4b8,0xc4b9,0xc4b9,0xc4bb, 0xc4bb,0xc4bd,0xc4bd,0xc4bf,
// U+0140
0xc4bf,0xc581,0xc581,0xc583, 0xc583,0xc585,0xc585,0xc587, 0xc587,0xc589,0xc58a,0xc58a, 0xc58c,0xc58c,0xc58e,0xc58e,
0xc590,0xc591,0xc592,0xc593, 0xc594,0xc595,0xc596,0xc597, 0xc598,0xc599,0xc59a,0xc59b, 0xc59c,0xc59d,0xc59e,0xc59f,
// U+0160
0xc5a0,0xc5a0,0xc5a2,0xc5a2, 0xc5a4,0xc5a4,0xc5a6,0xc5a6, 0xc5a8,0xc5a8,0xc5aa,0xc5aa, 0xc5ac,0xc5ac,0xc5ae,0xc5ae,
0xc5b0,0xc5b1,0xc5b2,0xc5b3, 0xc5b4,0xc5b5,0xc5b6,0xc5b7, 0xc5b8,0xc5b9,0xc5b9,0xc5bb, 0xc5bc,0xc5bd,0xc5bd,0xc5bf,
};
int
safe_atoi(char *s)
{
if (!s)
return 0;
if ((s[0]>='0' && s[0]<='9') || s[0]=='-' || s[0]=='+')
return atoi(s);
return 0;
}
// NOTE: support U+0000 ~ U+FFFF only.
int
utf16le_to_utf8(char *dst, int n, __u16 utf16le)
{
__u16 wc = le16_to_cpu(utf16le);
if (wc < 0x80) {
if (n<1) return 0;
*dst++ = wc & 0xff;
return 1;
}
else if (wc < 0x800) {
if (n<2) return 0;
*dst++ = 0xc0 | (wc>>6);
*dst++ = 0x80 | (wc & 0x3f);
return 2;
}
else {
if (n<3) return 0;
*dst++ = 0xe0 | (wc>>12);
*dst++ = 0x80 | ((wc>>6) & 0x3f);
*dst++ = 0x80 | (wc & 0x3f);
return 3;
}
}
void
fetch_string_txt(char *fname, char *lang, int n, ...)
{
va_list args;
char **keys;
char ***strs;
char **defstr;
int i;
FILE *fp;
char buf[4096];
int state;
char *p;
char *langid;
const char *lang_en = "EN";
if (!(keys = malloc(sizeof(keys) * n))) {
DPRINTF(E_FATAL, L_SCANNER, "Out of memory\n");
}
if (!(strs = malloc(sizeof(strs) * n))) {
DPRINTF(E_FATAL, L_SCANNER, "Out of memory\n");
}
if (!(defstr = malloc(sizeof(defstr) * n))) {
DPRINTF(E_FATAL, L_SCANNER, "Out of memory\n");
}
va_start(args, n);
for (i=0; i<n; i++) {
keys[i] = va_arg(args, char *);
strs[i] = va_arg(args, char **);
defstr[i] = va_arg(args, char *);
}
va_end(args);
if (!(fp = fopen(fname, "rb"))) {
DPRINTF(E_ERROR, L_SCANNER, "Cannot open <%s>\n", fname);
goto _exit;
}
state = -1;
while (fgets(buf, sizeof(buf), fp)) {
int len = strlen(buf);
if (buf[len-1]=='\n') buf[len-1] = '\0';
if (state<0) {
if (isalpha(buf[0])) {
for (i=0; i<n; i++) {
if (!(strcmp(keys[i], buf))) {
state = i;
break;
}
}
}
}
else {
int found = 0;
if (isalpha(buf[0]) || buf[0]=='\0') {
state = -1;
continue;
}
p = buf;
while (isspace(*p)) p++;
if (*p == '\0') {
state = -1;
continue;
}
langid = p;
while (!isspace(*p)) p++;
*p++ = '\0';
if (!strcmp(lang, langid))
found = 1;
else if (strcmp(lang_en, langid))
continue;
while (isspace(*p)) p++;
if (*strs[state])
free(*strs[state]);
*strs[state] = strdup(p);
if (found)
state = -1;
}
}
for (i=0; i<n; i++) {
if (!*strs[i])
*strs[i] = defstr[i];
}
fclose(fp);
_exit:
free(keys);
free(strs);
free(defstr);
}

View File

@ -1,28 +0,0 @@
//=========================================================================
// FILENAME : textutils.h
// DESCRIPTION : Header for textutils.c
//=========================================================================
// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
//=========================================================================
/* 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 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
extern void urldecode(char *src);
extern char * skipspaces(const char *src);
extern int safe_atoi(char *s);
extern int utf16le_to_utf8(char *dst, int n, __u16 utf16le);
extern void fetch_string_txt(char *fname, char *lang, int n, ...);