rockbox/tools/rdf2binary.c
Christian Soffke 727c800c0d Don't force gcc as host compiler + fix clang warnings
On MacOS, gcc is a symlink for clang.

Patch gets rid of the warnings produced by clang,
when it is set as HOSTCC, and fixes voicetools
compilation on MacOS when calling make voicetools
from the simulator directory.

lua rb_defines_helper:
format specifies type 'int' but the argument has
type 'long'

codecs: opus / speex (LOGF):
format '%ld' expects argument of type 'long int',
but argument 7 has type 'off_t'

gigabeat:
variable 'size' set but not used

rdf2binary:
a function declaration without a prototype is
deprecated in all versions of C

rbspeexdec:
passing 'unsigned char *' to parameter of type
'char *' converts between pointers to integer
types where one is of the unique plain 'char'
type and the other is not

hmac-sha1.c
defining a type within 'offsetof' is a Clang
extension

Change-Id: I90539906698868f9589650585d865aee9f7e8539
2024-12-20 05:29:18 +01:00

115 lines
3 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Miika Pekkarinen
*
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/*
This tool converts the rdf file to the binary data used in the dict plugin.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
/* maximum word lenght, has to be the same in dict.c */
#define WORDLEN 32
/* struckt packing */
#ifdef __GNUC__
#define STRUCT_PACKED __attribute__((packed))
#else
#define STRUCT_PACKED
#pragma pack (push, 2)
#endif
struct word
{
char word[WORDLEN];
long offset;
} STRUCT_PACKED;
/* convert offsets here, not on device. */
long reverse (long N) {
unsigned char B[4];
B[0] = (N & 0x000000FF) >> 0;
B[1] = (N & 0x0000FF00) >> 8;
B[2] = (N & 0x00FF0000) >> 16;
B[3] = (N & 0xFF000000) >> 24;
return ((B[0] << 24) | (B[1] << 16) | (B[2] << 8) | (B[3] << 0));
}
int main(void)
{
FILE *in, *idx_out, *desc_out;
struct word w;
char buf[10000];
long cur_offset = 0;
in = fopen("dict.preparsed", "r");
idx_out = fopen("dict.index", "wb");
desc_out = fopen("dict.desc", "wb");
if (in == NULL || idx_out == NULL || desc_out == NULL)
{
fprintf(stderr, "Error: Some files couldn't be opened\n");
return 1;
}
while (fgets(buf, sizeof buf, in) != NULL)
{
/* It is safe to use strtok here */
const char *word = strtok(buf, "\t");
const char *desc = strtok(NULL, "\t");
if (word == NULL || desc == NULL)
{
fprintf(stderr, "Parse error!\n");
fprintf(stderr, "word: %s\ndesc: %s\n", word, desc);
return 2;
}
/* We will null-terminate the words */
strncpy(w.word, word, WORDLEN - 1);
w.offset = reverse(cur_offset);
fwrite(&w, sizeof(struct word), 1, idx_out);
while (1)
{
int len = strlen(desc);
cur_offset += len;
fwrite(desc, len, 1, desc_out);
desc = strtok(NULL, "\t");
if (desc == NULL)
break ;
cur_offset++;
fwrite("\n", 1, 1, desc_out);
}
}
return 0;
}