home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
dev
/
misc
/
flexcat
/
src
/
flexcat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-21
|
32KB
|
1,540 lines
/*
FlexCat.c: The flexible catalog creator V 1.01
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Ok, this is nothing special. It grabs a catalog translation and a
catalog description file and produces catalogs and the source to
handle 'em. What is it else than lots of other programs?
The difference is, that YOU determine what source FlexCat produces.
Another file is scanned by FlexCat to produce code. This file contains
some c-string like special characters (%v for version for example)
You can edit this file and modify it as you want. So FlexCat can produce
C source as well as Assembler, Oberon, Modula 2, E, ...
Command line syntax:
FlexCat CDFILE/A,CTFILE,NEWCTFILE/K,CATALOG/K,ASSEMBLER/S,SOURCES/M
CDFILE - the name of the catalog description file; see CatComp for
syntax
CTFILE - the name of a catalog translation file; see CatComp for
syntax
NEWCTFILE - the name of a catalog transcription file to be created
(will be a copy of CDFILE except that the strings remain
empty and will be put as comments behind the string
definition)
CATALOG - the name of the catalog to be created; default is the
basename of the CDFILE and .catalog appended
SOURCES - the sourcefiles to be created. These arguments take a special
form: sourcefile=templatefile where sourcefile is the
name of the file to create and templatefile is the name of
a template file containing some special patterns. The
template file will be scanned and written to the source
file with these special patterns replaced by certain
strings. Possible patterns are:
%b basename of CDFILE (for example "file", if
CDFILE is "file.cd")
%v version
%l language (of CDFILE)
%n number of catalog strings
%% the percent sign itself
The following patterns indicate, that the line should be
repeated for each catalog string.
%i the string's ID descriptor
%d the string's ID
%s the string itself
%(...) indicates that anything between the brackets
should appear for any line except the last
(Oberon and Modula need a "," to separate array
entries, but the last entry must not be
terminated by a ",". So you would terminate an
array entry by a %(,).)
Example: Let the string description be
MSG_HELLO (5//)
Hello!
Then the special characters produce
%i = MSG_HELLO
%d = 5
%s = "Hello!"
Additionally the following characters may appear (as well as in the
catalog description and catalog translation file)
\b = Backspace (Ascii 8)
\c = Control sequence introducer (Ascii 155)
\e = Escape (Ascii 27)
\f = Form feed (Ascii 12)
\g = Display beep (Ascii 7)
\n = line feed, newline (Ascii 10)
\r = carriage return (Ascii 13)
\t = Tab (Ascii 9)
\v = Vertical tab (Ascii 11)
\) = the character ')' (Needed inside %(..))
\\ = the backslash itself
\xHH = Ascii code HH (where HH are hex digits)
\OOO = Ascii code OOO (where OOO are octal digits)
A backslash at the end of a line indicates that the line should be
concatenated with the next one.
Computer: Amiga 1200 Compiler: Dice, 2.07.54R
Author: V 1.0 31.06.1993 Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Tel. 07123 / 14881
Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
V1.01 Fixed a bug: The length of the source string
was used to check for the stringlen instead of
the real stringlen.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef AMIGA
#include <exec/types.h>
#include <clib/exec_protos.h>
#include "FlexCat_cat.h"
#ifdef AZTEC_C
#include <pragmas/exec_lib.h>
#endif
#endif
#ifdef _DCC
#define index strchr
#define rindex strrchr
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#define TYPE_C 0 /* Produce C strings */
#define TYPE_ASSEMBLER 1 /* Produce Assembler strings */
#define TYPE_OBERON 2 /* Produce Oberon strings */
#define TYPE_NONE 3 /* Simple strings */
#define OutputMode_None 0 /* Nothing written yet */
#define OutputMode_Bin 1 /* Last character written was binary */
#define OutputMode_Ascii 2 /* Last character written was Ascii */
struct CatString
{ struct CatString *Next;
char *CD_Str;
char *CT_Str;
char *ID_Str;
int MinLen, MaxLen, ID;
};
struct CDLine
{ struct CDLine *Next;
char *Line;
};
struct CatString *FirstCatString = NULL; /* First catalog string */
struct CDLine *FirstCDLine = NULL; /* First catalog description line */
char *BaseName = ""; /* Basename of catalog description */
char *Language = "english"; /* Language of catalog description */
int CatVersion = 0; /* Version of catalog to be opened */
int LengthBytes = 0; /* Number of bytes to preceed a */
/* created string and containing */
/* its length. */
char *CatLanguage = NULL; /* Language of catalog translation */
char *CatVersionString = NULL; /* version string of catalog */
/* translation */
int CodeSet = 0; /* Codeset of catalog translation */
int NumStrings = 0; /* Number of catalog strings */
int LongStrings = TRUE; /* Generate long or short strings */
char *ScanFile; /* File currently scanned */
int ScanLine; /* Line currently scanned */
struct Library *LocaleBase = NULL;
/*
This terminates the program.
*/
void Cleanup(int result)
{
#ifdef AMIGA
CloseFlexCatCatalog();
if (LocaleBase)
{ CloseLibrary(LocaleBase);
}
#endif
exit(result);
}
/*
This shows an error message and terminates
*/
struct RDArgs *Args;
void ShowError(const STRPTR msg, ...)
{ fprintf(stderr, (char *) msg, (&msg)[1], (&msg)[2], (&msg)[3], (&msg)[4]);
putc('\n', stderr);
Cleanup(10);
}
/*
This shows the message: Memory error.
*/
void MemError(void)
{ ShowError(GetFlexCatString(msgMemoryError), NULL);
}
/*
This shows a warning
*/
void ShowWarn(STRPTR msg, ...)
{ fprintf(stderr, (char *) GetFlexCatString(msgWarning), ScanFile, ScanLine);
fprintf(stderr, (char *) msg, (&msg)[1], (&msg)[2], (&msg)[3], (&msg)[4]);
putc('\n', stderr);
}
/*
This allocates a string
*/
char *AllocString(const char *str)
{ char *ptr;
if (!(ptr = malloc(strlen(str)+1)))
{ MemError();
}
strcpy(ptr, str);
return(ptr);
}
/*
This translates a hex character.
*/
int gethex(int c)
{
if (c >= '0' && c <= '9')
{ return(c - '0');
}
else if (c >= 'a' && c <= 'f')
{ return(c - 'a' + 10);
}
else if (c >= 'A' && c <= 'F')
{ return(c - 'A' + 10);
}
ShowWarn(GetFlexCatString(msgExpectedHex));
return(0);
}
/*
This translates an octal digit.
*/
int getoctal(int c)
{
if (c >= '0' && c <= '7')
{ return(c - '0');
}
ShowWarn(GetFlexCatString(msgExpectedOctal));
return(0);
}
/*
Reading a line is somewhat compicated in order to allow lines of any
length.
Inputs: fp - the file, where the input comes from
AllowComment - TRUE, if a leading semicolon should force to
interpret the line as a comment line
*/
#define BUFSIZE 4096
char *ReadLine(FILE *fp, int AllowComment)
{ char *OldLine, *NewLine = NULL;
int c = '\0';
int Len = 0, LineLen = 0;
int CommentLine = FALSE, FirstChar = TRUE;
int BackslashSeen = FALSE;
while (c != EOF)
{ if (Len+10 > LineLen)