Starmap image generator, preview 1

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2254 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2006-02-23 21:40:07 +00:00
parent 8c0c87d878
commit 52e061325e
21 changed files with 8761 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
########################################################################
# This is a GNU makefile - tested on CYGWIN and Linux
#
# You may need to compile or install libpng and/or zlib before
# compiling this.
#
TARGET = mapgen
# These flags are needed to get it to compile with libpngX.dll on CYGWIN
CYGWINFLAGS = -DPNG_USE_DLL
#CYGWINFLAGS =
PNGFLAGS = -I.
SDLFLAGS = $(shell sdl-config --cflags)
CC = gcc
CFLAGS = -W -Wall -O0 # -g
LIBS = -L/usr/local/lib -lpng -lm -lSDL_ttf -lSDL_image
LDFLAGS = $(shell sdl-config --libs)
BINS = $(TARGET) $(TARGET).exe
OBJS = mapgen.o alist.o scriptlib.o stringbank.o unicode.o sdlpngdrv.o SDL_gfxPrimitives.o
.SUFFIXES: .c .o
.c.o:
$(CC) -c $(CFLAGS) -o $@ $*.c $(PNGFLAGS) $(SDLFLAGS) $(CYGWINFLAGS)
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(LIBS) $(LDFLAGS)
clean:
rm -f $(BINS) *.o
+3513
View File
File diff suppressed because it is too large Load Diff
+191
View File
@@ -0,0 +1,191 @@
/*
SDL_gfxPrimitives: graphics primitives for SDL
LGPL (c) A. Schiffler
2006-02-01 - Alex Volkov
Disabled dll linkage
*/
#ifndef _SDL_gfxPrimitives_h
#define _SDL_gfxPrimitives_h
#include <math.h>
#ifndef M_PI
#define M_PI 3.141592654
#endif
#include "SDL.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* ----- Versioning */
#define SDL_GFXPRIMITIVES_MAJOR 2
#define SDL_GFXPRIMITIVES_MINOR 0
#define SDL_GFXPRIMITIVES_MICRO 13
/* ----- W32 DLL interface */
#if 0
#ifdef WIN32
#ifdef BUILD_DLL
#define DLLINTERFACE __declspec(dllexport)
#else
#define DLLINTERFACE __declspec(dllimport)
#endif
#else
#define DLLINTERFACE
#endif
#else
#define DLLINTERFACE
#endif
/* ----- Prototypes */
/* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
/* Pixel */
DLLINTERFACE int pixelColor(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color);
DLLINTERFACE int pixelRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Horizontal line */
DLLINTERFACE int hlineColor(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
DLLINTERFACE int hlineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Vertical line */
DLLINTERFACE int vlineColor(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
DLLINTERFACE int vlineRGBA(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rectangle */
DLLINTERFACE int rectangleColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
DLLINTERFACE int rectangleRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled rectangle (Box) */
DLLINTERFACE int boxColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
DLLINTERFACE int boxRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2,
Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Line */
DLLINTERFACE int lineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
DLLINTERFACE int lineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Line */
DLLINTERFACE int aalineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
DLLINTERFACE int aalineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Circle */
DLLINTERFACE int circleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
DLLINTERFACE int circleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Circle */
DLLINTERFACE int aacircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
DLLINTERFACE int aacircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Circle */
DLLINTERFACE int filledCircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
DLLINTERFACE int filledCircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ellipse */
DLLINTERFACE int ellipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
DLLINTERFACE int ellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Ellipse */
DLLINTERFACE int aaellipseColor(SDL_Surface * dst, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color);
DLLINTERFACE int aaellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Ellipse */
DLLINTERFACE int filledEllipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
DLLINTERFACE int filledEllipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#define CLOCKWISE
/* Pie */
DLLINTERFACE int pieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
DLLINTERFACE int pieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Pie */
DLLINTERFACE int filledPieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
DLLINTERFACE int filledPieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Trigon */
DLLINTERFACE int trigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
DLLINTERFACE int trigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Trigon */
DLLINTERFACE int aatrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
DLLINTERFACE int aatrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Trigon */
DLLINTERFACE int filledTrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
DLLINTERFACE int filledTrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Polygon */
DLLINTERFACE int polygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
DLLINTERFACE int polygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Polygon */
DLLINTERFACE int aapolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
DLLINTERFACE int aapolygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Polygon */
DLLINTERFACE int filledPolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
DLLINTERFACE int filledPolygonRGBA(SDL_Surface * dst, const Sint16 * vx,
const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Bezier */
/* s = number of steps */
DLLINTERFACE int bezierColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
DLLINTERFACE int bezierRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
};
#endif
#endif /* _SDL_gfxPrimitives_h */
+228
View File
@@ -0,0 +1,228 @@
/* alist.c, Copyright (c) 2005 Michael C. Martin */
/*
* 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 thta it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//#include "libs/reslib.h"
#include "alist.h"
#include "stringbank.h"
alist_entry *
AlistEntry_New (const char *key, const char *value)
{
alist_entry *e;
e = malloc (sizeof(alist_entry));
e->key = key;
e->value = value;
e->next = NULL;
return e;
}
void
AlistEntry_Free (alist_entry *e)
{
if (e == NULL)
return;
AlistEntry_Free (e->next);
free (e);
}
alist *
Alist_New (void)
{
alist *result = malloc (sizeof(alist));
result->first = NULL;
return result;
}
void
Alist_Free (alist *m) {
if (m == NULL) return;
AlistEntry_Free (m->first);
free (m);
}
alist_entry *
Alist_GetEntry (alist *m, const char *key)
{
alist_entry *x = m->first;
while (x != NULL) {
if (!strcmp (x->key, key))
return x;
x = x->next;
}
return NULL;
}
const char *
Alist_GetString (alist *m, const char *key)
{
alist_entry *x = Alist_GetEntry (m, key);
return x ? x->value : NULL;
}
void
Alist_PutString (alist *m, const char *key, const char *value)
{
alist_entry *e = Alist_GetEntry (m, key);
if (e == NULL) {
e = AlistEntry_New(key, value);
e->next = m->first;
m->first = e;
} else {
e->value = value;
}
}
void
Alist_PutAll (alist *dst, alist *src)
{
alist_entry *e = src->first;
while (e) {
Alist_PutString (dst, e->key, e->value);
e = e->next;
}
}
alist *
Alist_New_FromFile (FILE *f)
{
long flen;
alist *m;
char *data;
fseek (f, 0, SEEK_END);
flen = ftell (f);
fseek (f, 0, SEEK_SET);
data = malloc (flen + 1);
if (!data) {
return NULL;
}
fread (data, 1, flen, f);
data[flen] = '\0';
m = Alist_New_FromString (data);
free (data);
return m;
}
alist *
Alist_New_FromFilename (const char *fname)
{
alist *result;
FILE *f = fopen (fname, "rt");
if (!f) {
return NULL;
}
result = Alist_New_FromFile (f);
fclose(f);
return result;
}
alist *
Alist_New_FromString (char *d)
{
alist *m = Alist_New ();
int len, i;
if (!m) return NULL;
len = strlen(d);
i = 0;
while (i < len) {
int key_start, key_end, value_start, value_end;
/* Starting a line: search for non-whitespace */
while ((i < len) && isspace (d[i])) i++;
if (i >= len) break; /* Done parsing! */
/* If it was a comment, skip to end of comment/file */
if (d[i] == '#') {
while ((i < len) && (d[i] != '\n')) i++;
if (i >= len) break;
continue; /* Back to keyword search */
}
key_start = i;
/* Find the = on this line */
while ((i < len) && (d[i] != '=') &&
(d[i] != '\n') && (d[i] != '#')) i++;
if (i >= len) { /* Bare key at EOF */
fprintf (stderr, "Warning: Bare keyword at EOF");
break;
}
/* Comments here mean incomplete line too */
if (d[i] != '=') {
fprintf (stderr, "Warning: Key without value");
while ((i < len) && (d[i] != '\n')) i++;
if (i >= len) break;
continue; /* Back to keyword search */
}
/* Key ends at first whitespace before = , or at key_start*/
key_end = i;
while ((key_end > key_start) && isspace (d[key_end-1]))
key_end--;
/* Consume the = */
i++;
/* Value starts at first non-whitespace after = on line... */
while ((i < len) && (d[i] != '#') && (d[i] != '\n') &&
isspace (d[i]))
i++;
value_start = i;
/* Until first non-whitespace before terminator */
while ((i < len) && (d[i] != '#') && (d[i] != '\n'))
i++;
value_end = i;
while ((value_end > value_start) && isspace (d[value_end-1]))
value_end--;
/* Skip past EOL or EOF */
while ((i < len) && (d[i] != '\n'))
i++;
i++;
/* We now have start and end values for key and value.
We terminate the strings for both by writing \0s, then
make a new map entry. */
d[key_end] = '\0';
d[value_end] = '\0';
Alist_PutString (m, StringBank_AddOrFindString(d+key_start),
StringBank_AddOrFindString(d+value_start));
}
return m;
}
void
Alist_Dump (alist *m, FILE *s, const char *prefix)
{
alist_entry *e = m->first;
int prefix_len = 0;
if (prefix)
prefix_len = strlen (prefix);
while (e) {
if (!prefix || !strncmp (prefix, e->key, prefix_len)) {
fwrite (e->key, 1, strlen (e->key), s);
fputc (' ', s);
fputc ('=', s);
fputc (' ', s);
fwrite (e->value, 1, strlen (e->value), s);
fputc ('\n', s);
}
e = e->next;
}
return;
}
+65
View File
@@ -0,0 +1,65 @@
/* alist.h, Copyright (c) 2005 Michael C. Martin */
/*
* 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 thta it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _ALIST_H_
#define _ALIST_H_
#include <stdio.h>
/* Associative List types. */
typedef struct _alist_entry {
const char *key, *value;
struct _alist_entry *next;
} alist_entry;
typedef struct _alist_map {
alist_entry *first;
} alist;
/* ***** alist_entry operations ***** */
/* Constructor and destructor */
alist_entry *AlistEntry_New (const char *key, const char *value);
void AlistEntry_Free (alist_entry *e);
/* ***** alist operations ***** */
/* Standard constructor and destructor */
alist *Alist_New (void);
void Alist_Free (alist *m);
/* Specialized constructors: Parse an alist out of a stream, file, or
string. It expects a bunch of key=value statements, one per
line. */
alist *Alist_New_FromFile (FILE *f);
alist *Alist_New_FromFilename (const char *fname);
alist *Alist_New_FromString (char *d);
/* Getting and Setting operations */
alist_entry *Alist_GetEntry (alist *m, const char *key);
const char *Alist_GetString (alist *m, const char *key);
void Alist_PutString (alist *m, const char *key, const char *value);
void Alist_PutAll (alist *dest, alist *src);
/* Dump the alist to the specified stream in a form that could be
read later by the Alist_New_From* routines. Dump only keys
that begin with the prefix; NULL means all keys. */
void Alist_Dump (alist *m, FILE *s, const char *prefix);
#endif /* _ALIST_H_ */
+102
View File
@@ -0,0 +1,102 @@
Andromedae,s,AB
Antliae,ne,AB,BC,BE,CD,EF,FA
Apodis,w,AB,BC,CD,DA
Aquarii,ne,AG,AC,CD,DB,BE,EF,FA
Aquilae,se,AB,AC,AD,AE
Arae,nw,AB,AC,AD,DE,EA
Arianni,ne,AB,BC,CA
Arietis,nw,AB,BC,CD,DE
Aurigae,s,AB,BC,CD
Bootis,e,AD,AB,BC,CG,CF,FE,EA
Brahe,w,AB,BF,FE,ED,DC,CE
Caeli,n,AB,BC,CD,DE
Camelopardalis,e,AB,BH,HE,EA,AF,FG,AC,CD,DI
Cancri,e,AC,CB,BD,DC
Capricorni,w,AB,BC,CA
Carinae,nw,AC,CB
Cassiopeiae,s,AB,BD,DE,DC,CA
Centauri,w,CA,AE,EF,FB,BD
Cephei,n,AB
Cerenkov,n,AB
Ceti,e,EF,FA,AD,DC,CB,BG,GD
Chamaeleonis,e,AB,BC,CD,DE,EF,FG,GH,HI,IJ
Chandrasekhar,n,AC,CB,BE,EC,CD,DA
Circini,se,AB,BC,CD,DE,EF,FA
Columbae,e,BA,AC
Copernicus,n,CA,AB
Corvi,e,DG,GB,BF,FC,CE
Crateris,ne,AB,BD,DC,DH,DE,EG,GF
Crucis,nw,AB,BC,CD,DA
Cygnus,n,AB,BD,DC,CA,BE
Delphini,s,AB
Doradus,n,AB
Draconis,s,JM,ML,LJ,JN,NF,FB,BA,AD,DK,KC,CE,EH,HG,GI,IH
Equulei,n,AB
Eridani,s,AB,BC,CA
Fornacis,n,AB,BC,CD,DE,EG,DF
Geminorum,w,AB,BC,CD,DA
Giclas,ne,AB,BE,EH,AC,CG,AD,DF
Gorno,e,AB,BC,CD,DE,EA
Gruis,ne,BA,AC,CD,DE,EF,FG,GD
Herculis,w,AB
Horologii,ne,AB,BC,CD,DE,EF,FA,AG,GH,HI,IJ,JK,KA
Hyades,e,CB,BA,AD,DC,CE,EF,FG,GH,HI,IJ,JK
Hydrae,,AB,BC
Hyginus,ne,AB
Illuminati,,DA,AB,BC,CE,EF,FG,GH
Indi,n,AB
Kepler,nw,AB,BC,CA
Klystron,w,AB
Krueger,,FA,AC,CB,BD,DE,EA
Lacaille,ne,AB,BC,CA
Lacertae,s,AB
Lalande,w,CA,AB,BC,CD
Lentilis,se,AB,BD,DA,AC
Leonis,w,AB,BC
Leporis,s,AB,BC
Librae,s,AB,BC,CD,DE,EG,GF,FD
Lipi,ne,DC,CA,AB,BE
Luyten,e,AB,BC,CA
Lyncis,sw,AB,BC,CD,DA,AE,EF,BG,GH
Lyrae,e,AB
Maksutov,se,AB
Mensae,n,AB,BC
Mersenne,e,AB
Mira,,AB,BC,CA,AD
Monocerotis,w,AB
Muscae,nw,CB,BA,AD,DE,EF,FD
Normae,se,AB,BC,CD,DE,EF
Octantis,nw,AB
Olber,s,AB,BC,CA
Ophiuchi,e,AB,BC,CA
Orionis,nw,AB,BC,CD,DA,DE,DF,AH,HG,HI,BK,KL,KJ
Pavonis,n,AB
Pegasi,e,AB
Persei,nw,AB,BF,FA,AC,CD,AH,AE,EG,EI
Phoenicis,ne,AB,BC
Pictoris,s,CA,AB,BC,CD
Piscium,nw,AC,CD,DB,BC
Ptolemae,nw,AB,BC,CD,DB,AF,FE,FG
Puppis,sw,AB,BC,CA
Pyxidis,nw,AB,BC
Raynet,nw,CA,AB
Reticuli,sw,AB,BD,DA,AC
Sagittae,s,AB,BC,CA
Sagittarii,n,AB,BC,CD
Saurus,ne,AB,BC,CA
Scorpii,sw,AB,BC,CF,FE,ED
Sculptoris,,AC,AD,AE
Scuti,e,BA,AD,DF,FE,EC
Serpentis,nw,FA,AC,CE,EB,BD,DG,GH,HI
Sextantis,n,AB,BF,FE,ED,DC
Squidi,nw,AB,BC,CA
Tauri,ne,DA,AF,FE,EC,CA,CB
Telescopii,n,AB,BC,CA
Trianguli,n,AB,BC,CA
Tucanae,ne,AB,BC,CA
Velorum,ne,AB
Virginis,se,AB,BC,CD
Vitalis,w,AB,AC,CD,DA
Volantis,s,CA,AB,BC,CD,DF,FE,EG,GF
Vulpeculae,e,AB,AC,AD,AE,AF,AG
Wolf,nw,AB
+15
View File
@@ -0,0 +1,15 @@
/* Dummy compile-time configuration options
* Only used when compiling in MS VC++ using UQM's getopt.c
*/
#ifndef _CONFIG_H
#define _CONFIG_H
/* Define if words are stored with the most significant byte first */
#undef WORDS_BIGENDIAN
/* Defined if your system has getopt.h */
#undef HAVE_GETOPT_H
#endif /* _CONFIG_H */
+1
View File
@@ -0,0 +1 @@
αβγδεζηθικλμνξοπρστυφχψω
+213
View File
@@ -0,0 +1,213 @@
#####################################################################
# Starmap image generation script
#
# 300 dpi, clipped A3 size
#####################################################################
# General image definition
image.dpi.x=300
image.dpi.y=300
# width and height in inches; v-trimmed A3
image.width=11.69
image.height=14.56
image.backcolor=200020
# layer Order
image.layers=sois,grid,soinames,clusters,stars,starnums,cnames
grid.extent.x=1000
grid.extent.y=1000
grid.step.1=100
grid.step.2=50
grid.step.3=10
# origins and dimensions in inches
grid.origin.x=0.6
grid.origin.y=0.6
grid.width=10.49
grid.height=10.49
grid.color=9566cb
# font: Arial Bold
grid.font.name=arialbd.ttf
# font point size is in 1/64th of an inch
grid.font.size=8
# weight is in 1/64th of an inch
grid.box.weight=1
grid.lines.weight=0.75
grid.marks.color=8771b6
# Stars
stars.definition=stars.map
stars.numcolor=989898
# font: Times New Roman
stars.desig.font.name=times.ttf
stars.desig.font.size=4
# designation letters/symbols in utf8 for the specified font
# using Greek letters
stars.desig.table=greek.map
# star images and/or colors
# radius in 1/64 of an inch
stars.colors=RGBOYW
stars.sizes=3
stars.R.1.image=stars/fca_027_red.png
stars.R.1.radius=1.5
stars.R.1.color=980000
stars.R.2.image=stars/fca_037_red.png
stars.R.2.radius=2.8
stars.R.2.color=b80000
stars.R.3.image=stars/fca_070_red.png
stars.R.3.radius=3.8
stars.R.3.color=d00000
stars.G.1.image=stars/fca_027_green.png
stars.G.1.radius=1.5
stars.G.1.color=009800
stars.G.2.image=stars/fca_037_green.png
stars.G.2.radius=2.8
stars.G.2.color=00b800
stars.G.3.image=stars/fca_070_green.png
stars.G.3.radius=3.8
stars.G.3.color=00d000
stars.B.1.image=stars/fca_027_blue.png
stars.B.1.radius=1.5
stars.B.1.color=000098
stars.B.2.image=stars/fca_037_blue.png
stars.B.2.radius=2.8
stars.B.2.color=0000b8
stars.B.3.image=stars/fca_070_blue.png
stars.B.3.radius=3.8
stars.B.3.color=0000d0
stars.O.1.image=stars/fca_027_orange.png
stars.O.1.radius=1.5
stars.O.1.color=b86000
stars.O.2.image=stars/fca_037_orange.png
stars.O.2.radius=2.8
stars.O.2.color=d06800
stars.O.3.image=stars/fca_070_orange.png
stars.O.3.radius=3.8
stars.O.3.color=e8700
stars.Y.1.image=stars/fca_027_yellow.png
stars.Y.1.radius=1.5
stars.Y.1.color=b8b420
stars.Y.2.image=stars/fca_037_yellow.png
stars.Y.2.radius=2.8
stars.Y.2.color=d0ca28
stars.Y.3.image=stars/fca_070_yellow.png
stars.Y.3.radius=3.8
stars.Y.3.color=e8e430
stars.W.1.image=stars/fca_027_white.png
stars.W.1.radius=1.5
stars.W.1.color=c8c8c8
stars.W.2.image=stars/fca_037_white.png
stars.W.2.radius=2.8
stars.W.2.color=d8d8d8
stars.W.3.image=stars/fca_070_white.png
stars.W.3.radius=3.8
stars.W.3.color=f0f0f0
# Star Clusters
clusters.definition=clusters.map
# font: Arial Narrow Bold
clusters.names.font.name=arialnb.ttf
clusters.names.font.size=7
clusters.names.color=7aa2ef
clusters.lines.color=8181a9
clusters.lines.weight=0.75
# Spheres of Influence
sois.font.name=arialbd.ttf
sois.font.size=16
sois.count=14
sois.1.name=EARTHLING
sois.1.color=f05015
sois.1.font.size=9
sois.1.center.x=177
sois.1.center.y=144.5
sois.1.radius=44
sois.2.name=CHENJESU
sois.2.color=6090e0
sois.2.font.size=14
sois.2.center.x=70
sois.2.center.y=218
sois.2.radius=64
sois.3.name=MMRNMHRM
sois.3.color=e0e0e0
sois.3.font.size=9
sois.3.center.x=68
sois.3.center.y=294
sois.3.radius=48
sois.4.name=ILWRATH
sois.4.color=E00040
sois.4.font.size=5
sois.4.center.x=-10
sois.4.center.y=355
sois.4.radius=53
sois.5.name=SPATHI
sois.5.color=f0f000
sois.5.center.x=245
sois.5.center.y=365
sois.5.radius=100
sois.6.name=ANDROSYNTH
sois.6.color=e000f0
sois.6.font.size=8
sois.6.center.x=370
sois.6.center.y=261
sois.6.radius=49
sois.7.name=SHOFIXTI
sois.7.color=e07038
sois.7.font.size=9
sois.7.center.x=288
sois.7.center.y=20
sois.7.radius=37
sois.8.name=VUX
sois.8.color=00f060
sois.8.center.x=431
sois.8.center.y=153
sois.8.radius=58
sois.9.name=YEHAT
sois.9.color=f0c010
sois.9.center.x=495
sois.9.center.y=5
sois.9.radius=105
sois.10.name=MYCON
sois.10.color=c0a810
sois.10.center.x=624
sois.10.center.y=235
sois.10.radius=56
sois.11.name=UMGAH
sois.11.color=30d0a0
sois.11.center.x=185
sois.11.center.y=608
sois.11.radius=49
sois.12.name=UNKNOWN
sois.12.color=80b050
sois.12.font.size=8
sois.12.center.x=58
sois.12.center.y=46
sois.12.radius=35
sois.13.name=UNKNOWN
sois.13.color=80b050
sois.13.font.size=14
sois.13.center.x=945
sois.13.center.y=275
sois.13.radius=74
sois.14.name=UNKNOWN
sois.14.color=80b050
sois.14.center.x=282
sois.14.center.y=850
sois.14.radius=73
+84
View File
@@ -0,0 +1,84 @@
/*
* UQM Starmap image generator
* Output Driver decl
*
* The GPL applies
*
*/
#include <sys/types.h>
#include <stdlib.h>
#include <stdint.h>
#include "port.h"
typedef struct
{
uint8_t r, g, b, a;
} mg_color_t;
typedef struct
{
int x;
int y;
} mg_point_t;
typedef struct
{
double x;
double y;
} mg_pointf_t;
typedef struct
{
int x;
int y;
int w;
int h;
} mg_rect_t;
typedef struct
{
double x;
double y;
double w;
double h;
} mg_rectf_t;
typedef struct mg_font *mg_font_t;
typedef struct mg_image *mg_image_t;
typedef struct
{
const char* name;
const char* description;
// func ptrs
int (* init)(int argc, char *argv[]);
int (* term)(void);
void (* usage)(void);
int (* setResolution)(int dpi_x, int dpi_y);
int (* begin)(double w, double h);
int (* write)(void);
int (* end)(void);
mg_font_t (* loadFont)(const char* name, double size, const char* filename /* optional */);
void (* freeFont)(mg_font_t);
mg_image_t (* loadImage)(const char* filename);
void (* freeImage)(mg_image_t);
int (* getImageSize)(mg_image_t, mg_rectf_t* r);
// draw func ptrs
void (* setClipRect)(const mg_rectf_t*);
void (* drawPixel)(double x, double y, mg_color_t, double weight);
void (* drawLine)(double x0, double y0, double x1, double y1, mg_color_t color, double weight);
void (* drawRect)(const mg_rectf_t* r, mg_color_t color, double weight);
void (* drawFilledRect)(const mg_rectf_t* r, mg_color_t color);
void (* drawEllipse)(double xc, double yc, double xr, double yr, mg_color_t color, double weight);
void (* drawFilledEllipse)(double xc, double yc, double xr, double yr, mg_color_t color);
void (* drawImage)(double x, double y, mg_image_t image);
void (* drawText)(mg_font_t, double x, double y, const unsigned char* utf8str, mg_color_t);
void (* getTextSize)(mg_font_t, const unsigned char* utf8str, mg_rectf_t* r);
} mg_driver_t;
extern void mg_verbose(int level, const char* fmt, ...);
+2034
View File
File diff suppressed because it is too large Load Diff
+178
View File
@@ -0,0 +1,178 @@
# Microsoft Developer Studio Project File - Name="mapgen" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=mapgen - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "mapgen.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "mapgen.mak" CFG="mapgen - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "mapgen - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "mapgen - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=xicl6.exe
RSC=rc.exe
!IF "$(CFG)" == "mapgen - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\src\getopt" /I "." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "PNG_USE_DLL" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng.lib SDLmain.lib SDL.lib SDL_image.lib SDL_ttf.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "mapgen - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "..\..\src\getopt" /I "." /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "PNG_USE_DLL" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng.lib SDLmain.lib SDL.lib SDL_image.lib SDL_ttf.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "mapgen - Win32 Release"
# Name "mapgen - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\alist.c
# End Source File
# Begin Source File
SOURCE=.\alist.h
# End Source File
# Begin Source File
SOURCE=.\config.h
# End Source File
# Begin Source File
SOURCE=..\..\src\getopt\getopt.c
# End Source File
# Begin Source File
SOURCE=..\..\src\getopt\getopt.h
# End Source File
# Begin Source File
SOURCE=.\mapdrv.h
# End Source File
# Begin Source File
SOURCE=.\mapgen.c
# End Source File
# Begin Source File
SOURCE=.\port.h
# End Source File
# Begin Source File
SOURCE=.\scriptlib.c
# End Source File
# Begin Source File
SOURCE=.\scriptlib.h
# End Source File
# Begin Source File
SOURCE=.\SDL_gfxPrimitives.c
# End Source File
# Begin Source File
SOURCE=.\SDL_gfxPrimitives.h
# End Source File
# Begin Source File
SOURCE=.\sdlpngdrv.c
# End Source File
# Begin Source File
SOURCE=.\stringbank.c
# End Source File
# Begin Source File
SOURCE=.\stringbank.h
# End Source File
# Begin Source File
SOURCE=.\unicode.c
# End Source File
# Begin Source File
SOURCE=.\unicode.h
# End Source File
# End Group
# Begin Group "Map Files"
# PROP Default_Filter "*.map"
# Begin Source File
SOURCE=.\clusters.map
# End Source File
# Begin Source File
SOURCE=.\greek.map
# End Source File
# Begin Source File
SOURCE=.\large300.map
# End Source File
# Begin Source File
SOURCE=.\stars.map
# End Source File
# End Group
# End Target
# End Project
+18
View File
@@ -0,0 +1,18 @@
#ifndef _PORT_H
#define _PORT_H
#if defined(WIN32) && defined(_MSC_VER)
# include <direct.h>
# include <getopt.h>
# define inline __inline
#else
# include <unistd.h>
#endif
#if defined(__GNUC__)
# define inline __inline__
#endif
#define countof(a) ( sizeof(a)/sizeof(*a) )
#endif /* _PORT_H */
+253
View File
@@ -0,0 +1,253 @@
/* Copyright (c) 2005 Michael C. Martin */
/*
* 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 thta it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "scriptlib.h"
#include "alist.h"
#include "stringbank.h"
static alist *map = NULL;
static void
check_map_init (void)
{
if (map == NULL) {
map = Alist_New ();
}
}
void
scr_ClearTables (void)
{
if (map != NULL) {
Alist_Free (map);
map = NULL;
}
}
/* Type conversion routines. */
static const char *
bool2str (bool b)
{
return b ? "yes" : "no";
}
static const char *
int2str (int i) {
char buf[20];
sprintf (buf, "%d", i);
return StringBank_AddOrFindString (buf);
}
static int
str2int (const char *s) {
return atoi(s);
}
static float
str2float (const char *s) {
return (float) atof(s);
}
static bool
str2bool (const char *s) {
if (!stricmp (s, "yes") ||
!stricmp (s, "true") ||
!stricmp (s, "1") )
return true;
return false;
}
void
scr_LoadFile (FILE *s)
{
alist *d;
check_map_init ();
d = Alist_New_FromFile (s);
if (d) {
Alist_PutAll (map, d);
Alist_Free (d);
}
}
void
scr_LoadFilename (const char *fname)
{
alist *d;
check_map_init ();
d = Alist_New_FromFilename (fname);
if (d) {
Alist_PutAll (map, d);
Alist_Free (d);
}
}
void
scr_SaveFile (FILE *f, const char *root)
{
check_map_init ();
Alist_Dump (map, f, root);
}
void
scr_SaveFilename (const char *fname, const char *root)
{
FILE *f;
check_map_init ();
f = fopen (fname, "wt");
if (f) {
scr_SaveFile (f, root);
fclose (f);
}
}
bool
scr_IsBoolean (const char *key)
{
const char *d;
check_map_init ();
d = scr_GetString (key);
if (!d) return 0;
return !stricmp (d, "yes") ||
!stricmp (d, "no") ||
!stricmp (d, "true") ||
!stricmp (d, "false") ||
!stricmp (d, "0") ||
!stricmp (d, "1") ||
!stricmp (d, "");
}
bool
scr_IsInteger (const char *key)
{
const char *d;
check_map_init ();
d = scr_GetString (key);
while (*d) {
if (!isdigit (*d))
return 0;
d++;
}
return 1;
}
const char *
scr_GetString (const char *key)
{
check_map_init ();
return Alist_GetString (map, key);
}
const char *
scr_GetStringDef (const char *key, const char *def)
{
const char *v;
check_map_init ();
v = scr_GetString (key);
if (!v)
v = def;
return v;
}
void
scr_PutString (const char *key, const char *value)
{
check_map_init ();
Alist_PutString (map, key, value);
}
int
scr_GetInteger (const char *key)
{
check_map_init ();
return str2int (scr_GetString (key));
}
int
scr_GetIntegerDef (const char *key, int def)
{
const char *v;
check_map_init ();
v = scr_GetString (key);
return v ? str2int (v) : def;
}
void
scr_PutInteger (const char *key, int value)
{
check_map_init ();
scr_PutString (key, int2str(value));
}
float
scr_GetFloat (const char *key)
{
check_map_init ();
return str2float (scr_GetString (key));
}
float
scr_GetFloatDef (const char *key, float def)
{
const char *v;
check_map_init ();
v = scr_GetString (key);
return v ? str2float (v) : def;
}
bool
scr_GetBoolean (const char *key)
{
check_map_init ();
return str2bool (scr_GetString (key));
}
bool
scr_GetBooleanDef (const char *key, bool def)
{
const char *v;
check_map_init ();
v = scr_GetString (key);
return v ? str2bool (v) : def;
}
void
scr_PutBoolean (const char *key, bool value)
{
check_map_init ();
scr_PutString (key, bool2str(value));
}
bool
scr_HasKey (const char *key)
{
check_map_init ();
return (scr_GetString (key) != NULL);
}
+57
View File
@@ -0,0 +1,57 @@
/* Copyright (c) 2005 Michael C. Martin */
/*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _SCRIPTLIB_H
#define _SCRIPTLIB_H
#include <stdio.h>
#ifndef __cpluspluc
typedef enum { false, true } bool;
#endif
/* Key-Value resources */
void scr_ClearTables (void);
void scr_LoadFilename (const char *fname);
void scr_SaveFilename (const char *fname, const char *root);
void scr_LoadFile (FILE *fname);
void scr_SaveFile (FILE *fname, const char *root);
bool scr_HasKey (const char *key);
const char *scr_GetString (const char *key);
const char *scr_GetStringDef (const char *key, const char *def);
void scr_PutString (const char *key, const char *value);
bool scr_IsInteger (const char *key);
int scr_GetInteger (const char *key);
int scr_GetIntegerDef (const char *key, int def);
void scr_PutInteger (const char *key, int value);
float scr_GetFloat (const char *key);
float scr_GetFloatDef (const char *key, float def);
bool scr_IsBoolean (const char *key);
bool scr_GetBoolean (const char *key);
bool scr_GetBooleanDef (const char *key, bool def);
void scr_PutBoolean (const char *key, bool value);
#endif /* _RESLIB_H */
+861
View File
@@ -0,0 +1,861 @@
/*
* UQM Starmap image generator
* SDL/PNG driver implementation
*
* Uses: SDL, SDL_image, SDL_ttf, parts of SDL_gfx, and libpng
*
*
* The GPL applies
*
*/
#include "mapdrv.h"
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "SDL_gfxPrimitives.h"
#include <png.h>
struct mg_font
{
char* name;
TTF_Font* font;
int size;
};
struct mg_image
{
SDL_Surface* img;
double width;
double height;
};
static int drv_init(int argc, char *argv[]);
static int drv_term(void);
static void drv_usage(void);
static int drv_setResolution(int dpi_x, int dpi_y);
static int drv_begin(double w, double h);
static int drv_write(void);
static int drv_end(void);
static mg_font_t drv_loadFont(const char* name, double size, const char*);
static void drv_freeFont(mg_font_t);
static mg_image_t drv_loadImage(const char*);
static void drv_freeImage(mg_image_t);
static int drv_getImageSize(mg_image_t, mg_rectf_t*);
static void drv_setClipRect(const mg_rectf_t*);
static void drv_drawPixel(double x, double y, mg_color_t, double weight);
static void drv_drawLine(double x0, double y0, double x1, double y1, mg_color_t, double weight);
static void drv_drawRect(const mg_rectf_t*, mg_color_t color, double weight);
static void drv_drawFilledRect(const mg_rectf_t*, mg_color_t color);
static void drv_drawEllipse(double xc, double yc, double xr, double yr, mg_color_t, double weight);
static void drv_drawFilledEllipse(double xc, double yc, double xr, double yr, mg_color_t);
static void drv_drawImage(double x, double y, mg_image_t);
static void drv_drawText(mg_font_t, double x, double y, const unsigned char* utf8str, mg_color_t);
static void drv_getTextSize(mg_font_t, const unsigned char* utf8str, mg_rectf_t*);
const mg_driver_t sdlpng_drv =
{
"sdlpng", // name
"SDL/PNG image writer", // description
// func ptrs
drv_init,
drv_term,
drv_usage,
drv_setResolution,
drv_begin,
drv_write,
drv_end,
drv_loadFont,
drv_freeFont,
drv_loadImage,
drv_freeImage,
drv_getImageSize,
// draw func ptrs
drv_setClipRect,
drv_drawPixel,
drv_drawLine,
drv_drawRect,
drv_drawFilledRect,
drv_drawEllipse,
drv_drawFilledEllipse,
drv_drawImage,
drv_drawText,
drv_getTextSize,
};
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
# define R_MASK 0xff000000
# define G_MASK 0x00ff0000
# define B_MASK 0x0000ff00
# define A_MASK 0x000000ff
# define PNG_R_MASK 0x00ff0000
# define PNG_G_MASK 0x0000ff00
# define PNG_B_MASK 0x000000ff
# define PNG_A_MASK 0xff000000
#else
# define R_MASK 0x00ff0000
# define G_MASK 0x0000ff00
# define B_MASK 0x000000ff
# define A_MASK 0xff000000
# define PNG_R_MASK 0x000000ff
# define PNG_G_MASK 0x0000ff00
# define PNG_B_MASK 0x00ff0000
# define PNG_A_MASK 0xff000000
#endif
static int parseArguments(int argc, char* argv[]);
static SDL_PixelFormat* imgfmt;
static SDL_Surface* fmtimg;
static SDL_Surface* outimg;
static int use32bpp;
static const char* fontdir = ".";
static const char* outdev = "starmap.png";
static FILE* fout;
static int dpix, dpiy;
static char* strcopy(const char* str)
{
int l;
char* s;
if (!str)
return 0;
l = strlen(str);
s = malloc(l + 1);
if (!s)
return 0;
memcpy(s, str, l + 1);
return s;
}
static int drv_init(int argc, char *argv[])
{
int ret;
ret = parseArguments(argc, argv);
if (ret)
return ret;
if (SDL_Init(SDL_INIT_NOPARACHUTE))
{
mg_verbose(1, "Cannot init SDL\n");
return EXIT_FAILURE;
}
if (TTF_Init())
{
mg_verbose(1, "Cannot init SDL_ttf\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
static int drv_term(void)
{
imgfmt = 0;
if (fmtimg)
SDL_FreeSurface(fmtimg);
fmtimg = 0;
if (outimg)
SDL_FreeSurface(outimg);
outimg = 0;
if (fout)
fclose(fout);
fout = 0;
TTF_Quit();
SDL_Quit();
return EXIT_SUCCESS;
}
static void drv_usage(void)
{
mg_verbose(0,
"sdlpng driver : [-f <fontdir>] [-n] [-o <outfile>]\n"
"Options:\n"
"\t-f dir where font files are located\n"
"\t-n use native 32bpp surface for rendering\n"
"\t doubles memory requirement but may increase quality in some cases\n"
"\t-o save image as <outfile> (default is 'starmap.png')\n"
);
}
static int parseArguments(int argc, char* argv[])
{
char ch;
while (-1 != (ch = getopt(argc, argv, "-f:no:")))
{
switch (ch)
{
case 'f':
fontdir = optarg;
break;
case 'n':
use32bpp = 1;
break;
case 'o':
outdev = optarg;
break;
default:
// non-option -- probably an arg to unknown option
;
}
}
return EXIT_SUCCESS;
}
static int drv_setResolution(int dpi_x, int dpi_y)
{
dpix = dpi_x;
dpiy = dpi_y;
return EXIT_SUCCESS;
}
static inline int inchToPixelsX(double inch)
{
int v = (int)(inch * dpix);
// make sure it's at least 1 pixel wide if present
if (!v && inch)
v = 1;
return v;
}
static inline int inchToPixelsY(double inch)
{
int v = (int)(inch * dpiy);
// make sure it's at least 1 pixel wide if present
if (!v && inch)
v = 1;
return v;
}
static inline double pixelsToInchX(int pixels)
{
return (double)pixels / dpix;
}
static inline double pixelsToInchY(int pixels)
{
return (double)pixels / dpiy;
}
static int drv_begin(double w, double h)
{
int targetbpp;
fout = fopen(outdev, "wb");
if (!fout)
{
mg_verbose(1, "Cannot open file '%s' -- %s\n", outdev, strerror(errno));
return EXIT_FAILURE;
}
if (use32bpp)
{ // SDL-native channel order; allows exact accelerated blits
fmtimg = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
R_MASK, G_MASK, B_MASK, A_MASK);
targetbpp = 32;
}
else
{ // PNG-native channel order; saves memory
fmtimg = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
PNG_R_MASK, PNG_G_MASK, PNG_B_MASK, PNG_A_MASK);
targetbpp = 24;
}
if (!fmtimg)
{
mg_verbose(1, "Cannot create format image\n");
return EXIT_FAILURE;
}
imgfmt = fmtimg->format;
outimg = SDL_CreateRGBSurface(SDL_SWSURFACE, inchToPixelsX(w), inchToPixelsY(h),
targetbpp, imgfmt->Rmask, imgfmt->Gmask, imgfmt->Bmask, 0);
if (!outimg)
{
mg_verbose(1, "Cannot create work image\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
static int drv_end(void)
{
imgfmt = 0;
if (fmtimg)
SDL_FreeSurface(fmtimg);
fmtimg = 0;
if (outimg)
SDL_FreeSurface(outimg);
outimg = 0;
if (fout)
fclose(fout);
fout = 0;
return EXIT_SUCCESS;
}
static int drv_write(void)
{
png_structp png_ptr;
png_infop info_ptr;
SDL_Surface* cimg = NULL;
SDL_PixelFormat* fmt = outimg->format;
png_bytep* lines = NULL;
int i;
if (!outimg || !fout)
return EXIT_FAILURE;
mg_verbose(2, "Writing image to '%s'\n", outdev);
if (fmt->BytesPerPixel != 3 ||
fmt->Rmask != PNG_R_MASK ||
fmt->Gmask != PNG_G_MASK ||
fmt->Bmask != PNG_B_MASK)
{
cimg = SDL_CreateRGBSurface(SDL_SWSURFACE, outimg->w, outimg->h, 24,
PNG_R_MASK, PNG_G_MASK, PNG_B_MASK, 0);
if (!cimg)
return EXIT_FAILURE;
SDL_BlitSurface(outimg, NULL, cimg, NULL);
outimg = cimg;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (!png_ptr)
{
mg_verbose(1, "png_create_write_struct failed.\n");
return EXIT_FAILURE;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
mg_verbose(1, "png_create_info_struct failed.\n");
return EXIT_FAILURE;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
mg_verbose(1, "png error.\n");
png_destroy_write_struct(&png_ptr, &info_ptr);
return EXIT_FAILURE;
}
lines = calloc(outimg->h, sizeof(png_bytep));
if (!lines)
return EXIT_FAILURE;
for (i = 0; i < outimg->h; ++i)
lines[i] = (Uint8*)outimg->pixels + i * outimg->pitch;
png_init_io(png_ptr, fout);
png_set_IHDR(png_ptr, info_ptr, outimg->w, outimg->h, 8,
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_BASE);
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
png_set_pHYs(png_ptr, info_ptr, dpix * 10000 / 254, dpiy * 10000 / 254,
PNG_RESOLUTION_METER);
png_write_info(png_ptr, info_ptr);
png_set_packing(png_ptr);
png_write_image(png_ptr, lines);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
if (cimg)
SDL_FreeSurface(cimg);
if (lines)
free(lines);
return EXIT_SUCCESS;
}
static mg_font_t drv_loadFont(const char* name, double size, const char* filename)
{
char buf[512];
struct mg_font* fnt;
fnt = calloc(1, sizeof(*fnt));
if (!fnt)
return 0;
fnt->size = inchToPixelsY(size);
fnt->name = strcopy(name);
sprintf(buf, "%s/%s", fontdir, filename);
fnt->font = TTF_OpenFont(buf, fnt->size);
if (!fnt->font)
{
free(fnt);
return 0;
}
return fnt;
}
static void drv_freeFont(mg_font_t fnt)
{
if (!fnt)
return;
if (fnt->name)
free(fnt->name);
if (fnt->font)
TTF_CloseFont(fnt->font);
free(fnt);
}
static mg_image_t drv_loadImage(const char* filename)
{
struct mg_image* img;
img = calloc(1, sizeof(*img));
if (!img)
return 0;
img->img = IMG_Load(filename);
if (!img->img)
{
free(img);
return 0;
}
img->width = pixelsToInchX(img->img->w);
img->height = pixelsToInchY(img->img->h);
return img;
}
static void drv_freeImage(mg_image_t img)
{
if (!img)
return;
if (img->img)
SDL_FreeSurface(img->img);
free(img);
}
static int drv_getImageSize(mg_image_t img, mg_rectf_t* r)
{
if (!r)
return EXIT_FAILURE;
r->x = r->y = 0;
if (img)
{
r->w = img->width;
r->h = img->height;
}
else
{
r->w = 0;
r->h = 0;
}
return EXIT_SUCCESS;
}
static void drv_setClipRect(const mg_rectf_t* r)
{
if (!r)
{
SDL_SetClipRect(outimg, 0);
}
else
{
SDL_Rect dr;
dr.x = (int)(r->x * dpix);
dr.y = (int)(r->y * dpiy);
dr.w = (int)(r->w * dpix);
dr.h = (int)(r->h * dpiy);
SDL_SetClipRect(outimg, &dr);
}
}
static inline Uint32 colorToGfx(mg_color_t clr)
{
return (clr.r << 24) | (clr.g << 16) | (clr.b << 8) | (clr.a);
}
static inline Uint32 colorToSDL(mg_color_t clr)
{
return SDL_MapRGBA(imgfmt, clr.r, clr.g, clr.b, clr.a);
}
static void drv_drawPixel(double xf, double yf, mg_color_t color, double weightf)
{
// weight is ignored here
const int x0 = (int)(xf * dpix);
const int y0 = (int)(yf * dpiy);
const Uint32 clr = colorToGfx(color);
pixelColor(outimg, x0, y0, clr);
(void)weightf; // hush little compiler
}
static void drawHLine(int x0, int x1, int y, mg_color_t color, int weight)
{
int i;
int y0 = y - weight / 2;
const Uint32 clr = colorToGfx(color);
Uint32 aaclr;
Uint32 c;
color.a = 0xb0;
aaclr = colorToGfx(color);
for (i = 0; i < weight; ++i, ++y0)
{
if (weight > 2 && (i == 0 || i == weight - 1))
c = aaclr;
else
c = clr;
hlineColor(outimg, x0, x1, y0, c);
}
}
static void drawVLine(int x, int y0, int y1, mg_color_t color, int weight)
{
int i;
int x0 = x - weight / 2;
const Uint32 clr = colorToGfx(color);
Uint32 aaclr;
Uint32 c;
color.a = 0xb0;
aaclr = colorToGfx(color);
for (i = 0; i < weight; ++i, ++x0)
{
if (weight > 2 && (i == 0 || i == weight - 1))
c = aaclr;
else
c = clr;
vlineColor(outimg, x0, y0, y1, c);
}
}
// This is a pretty crude floating point algorithm
// for drawing thick anti-aliased lines with rounded end-points
// Not optimized at all, but we do not need speed here
static void drv_drawLine(double x0f, double y0f, double x1f, double y1f, mg_color_t color, double weightf)
{
int x0 = (int)(x0f * dpix);
int y0 = (int)(y0f * dpiy);
int x1 = (int)(x1f * dpix);
int y1 = (int)(y1f * dpiy);
int dx, dy;
double length;
double sinl, cosl;
double hw, thres;
int x, y;
const Uint32 clr = colorToGfx(color);
const Uint32 clrna = clr & 0xffffff00;
int weight;
if (x0 == x1)
{
drawVLine(x0, y0, y1, color, inchToPixelsX(weightf));
return;
}
if (y0 == y1)
{
drawHLine(x0, x1, y0, color, inchToPixelsY(weightf));
return;
}
weight = (int)((weightf * dpix + weightf * dpiy) / 2);
if (weight <= 1)
{ // 1-pixel wide
aalineColor(outimg, x0, y0, x1, y1, clr);
return;
}
if (x1 < x0)
{ // swap line endpoints
int t;
t = x0;
x0 = x1;
x1 = t;
t = y0;
y0 = y1;
y1 = t;
}
dx = x1 - x0;
dy = y1 - y0;
length = sqrt(dx*dx + dy*dy);
sinl = (double)dy / length;
cosl = (double)dx / length;
hw = (double)weight / 2;
thres = hw - 0.6;
if (thres < 0)
thres = 0;
for (x = x0 - weight; x < x1 + weight; ++x)
{
double py = (double)(x - x0) / dx * dy;
double ly = y0 + py;
int iy;
int sy;
if (x < x0)
sy = y0;
else if (x > x1)
sy = y1;
else
sy = (int)ly;
for (iy = -1; iy <= 1; ++iy)
{
if (iy == 0)
{
++iy;
++sy;
}
for (y = sy; ; y += iy)
{
double oy = py + (y - ly) * fabs(sinl);
double dist;
if (y1 < y0)
oy = -oy;
// distance from ideal line point dictates opacity
if (oy < 0)
{
dist = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
}
else if (oy > abs(dy))
{
dist = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
else
{
dist = fabs((double)y - ly) * fabs(cosl);
}
if (dist <= thres)
{
pixelColor(outimg, x, y, clr);
}
else
{ // anti-alias the pixel
int a = (int)((1 - (dist - thres)) * 255);
if (a <= 0)
break;
pixelColor(outimg, x, y, clrna | ((color.a * a) >> 8));
}
}
}
}
}
static void drv_drawRect(const mg_rectf_t* r, mg_color_t color, double weightf)
{
// draw the box
drv_drawLine(r->x, r->y, r->x + r->w, r->y, color, weightf);
drv_drawLine(r->x, r->y + r->h, r->x + r->w, r->y + r->h, color, weightf);
drv_drawLine(r->x, r->y, r->x, r->y + r->h, color, weightf);
drv_drawLine(r->x + r->w, r->y, r->x + r->w, r->y + r->h, color, weightf);
}
static void drv_drawFilledRect(const mg_rectf_t* r, mg_color_t color)
{
const Uint32 clr = colorToSDL(color);
if (!r)
{ // whole surface
SDL_FillRect(outimg, NULL, clr);
}
else
{
SDL_Rect dr;
dr.x = (int)(r->x * dpix);
dr.y = (int)(r->y * dpiy);
dr.w = (int)(r->w * dpix);
dr.h = (int)(r->h * dpiy);
SDL_FillRect(outimg, &dr, clr);
}
}
static void drv_drawEllipse(double xcf, double ycf, double xrf, double yrf, mg_color_t color, double weight)
{
// weight currently ignored
int xc = (int)(xcf * dpix);
int yc = (int)(ycf * dpiy);
int xr = (int)(xrf * dpix);
int yr = (int)(yrf * dpiy);
const Uint32 clr = colorToGfx(color);
aaellipseColor(outimg, xc, yc, xr, yr, clr);
(void)weight; // hush little compiler
}
// This is a pretty crude floating point algorithm
// for drawing anti-aliased filled ellipse
// Not really optimized at all, but we do not need speed here
static void drv_drawFilledEllipse(double xcf, double ycf, double xrf, double yrf, mg_color_t color)
{
const int xc = (int)(xcf * dpix);
const int yc = (int)(ycf * dpiy);
const int xr = (int)(xrf * dpix);
const int yr = (int)(yrf * dpiy);
const Uint32 clr = colorToGfx(color);
const Uint32 clrna = clr & 0xffffff00;
int x, y;
double radius, radius_2, rad_thres;
double fx_2, fy_2;
// the (more or less) classic elliptic equation is
// (fx*x)^2 + (fy*y)^2 = r^2 (classic: fx=r/a, fy=r/b)
// we'll take a=r (or b=r) and transform
// x^2 + (fy*y)^2 = r^2
// or more precisely, along the major axis
if (xr >= yr)
radius = xr;
else
radius = yr;
radius_2 = radius * radius;
fx_2 = radius / xr;
fx_2 = fx_2 * fx_2;
fy_2 = radius / yr;
fy_2 = fy_2 * fy_2;
rad_thres = (radius + 1) * (radius + 1);
for (y = -yr; y <= yr; y++)
{
double y_2 = y * y * fy_2;
for (x = -xr; x <= xr; x++)
{
double r_2 = y_2 + x * x * fx_2;
if (r_2 >= rad_thres)
{ // outside bounds
continue;
}
if (r_2 <= radius_2)
{ // solid pixels inside the ellipse
pixelColor(outimg, xc + x, yc + y, clr);
}
else
{ // anti-aliased edge
int a = (int) ((1 - (sqrt(r_2) - radius)) * 255);
if (a < 0)
continue; // should never happen
pixelColor(outimg, xc + x, yc + y, clrna | ((color.a * a) >> 8));
}
}
}
}
static void setImageAlpha(SDL_Surface* img, int alpha)
{
SDL_PixelFormat* fmt = img->format;
int x, y;
if (!fmt->Amask)
{
SDL_SetAlpha(img, SDL_SRCALPHA, alpha);
return;
}
if (fmt->BytesPerPixel != 4)
{
mg_verbose(1, "Unsuppoted surface format for alpha -- %d bytes/pixel\n", (int)fmt->BytesPerPixel);
return;
}
// adjust the alpha channel accordingly
for (y = 0; y < img->h; ++y)
{
Uint32* dst = (Uint32*)((Uint8*)img->pixels + img->pitch * y);
for (x = 0; x < img->w; ++x, ++dst)
{
Uint32 p = *dst;
Uint32 a = (p & fmt->Amask) >> fmt->Ashift;
p &= ~fmt->Amask;
a = a * alpha / 255;
*dst = p | (a << fmt->Ashift);
}
}
}
static void drv_drawImage(double xf, double yf, struct mg_image* img)
{
SDL_Rect dr;
dr.x = (int)(xf * dpix);
dr.y = (int)(yf * dpiy);
SDL_BlitSurface(img->img, NULL, outimg, &dr);
}
static void drv_drawText(struct mg_font* fnt, double xf, double yf, const unsigned char* utf8str, mg_color_t color)
{
SDL_Rect dr;
SDL_Color clr = {color.r, color.g, color.b, 0};
SDL_Surface* text;
if (!fnt || !utf8str)
return;
dr.x = (int)(xf * dpix);
dr.y = (int)(yf * dpiy);
text = TTF_RenderUTF8_Blended(fnt->font, utf8str, clr);
if (!text)
return;
if (color.a != 0xff)
setImageAlpha(text, color.a);
SDL_BlitSurface(text, NULL, outimg, &dr);
SDL_FreeSurface(text);
}
static void drv_getTextSize(struct mg_font* fnt, const unsigned char* utf8str, mg_rectf_t* r)
{
int w = 0;
int h = 0;
if (!r)
return;
if (!fnt || !utf8str)
{
r->w = 0;
r->h = 0;
return;
}
TTF_SizeUTF8(fnt->font, utf8str, &w, &h);
r->w = (double)w / dpix;
r->h = (double)h / dpiy;
}
+502
View File
@@ -0,0 +1,502 @@
Achernar,*,537.5,272.9,B,1
Alcor,*,970.8,025.0,B,1
Aldebaran,*,737.5,356.2,B,1
Algol,*,900.0,325.0,R,1
Almagest,*,990.9,235.9,B,1
Altair,*,450.0,650.0,B,1
Andromedae,A,862.5,700.0,G,1
Andromedae,B,866.6,710.4,G,1
Antares,*,647.9,754.1,O,1
Antliae,A,268.7,900.0,B,1
Antliae,B,270.6,891.0,Y,1
Antliae,C,283.1,885.4,G,1
Antliae,D,305.0,883.3,B,1
Antliae,E,253.5,891.7,W,1
Antliae,F,258.1,910.5,R,1
Apodis,A,258.2,850.7,Y,3
Apodis,B,259.3,856.9,R,1
Apodis,C,256.2,857.2,O,1
Apodis,D,253.6,850.4,G,1
Aquarii,A,856.0,863.8,G,1
Aquarii,B,863.0,869.3,G,1
Aquarii,C,853.4,879.7,O,1
Aquarii,D,858.8,881.2,B,1
Aquarii,E,875.0,864.5,B,1
Aquarii,F,862.5,856.2,O,1
Aquarii,G,849.2,857.8,W,1
Aquilae,A,915.9,974.5,B,3
Aquilae,B,918.6,974.1,R,1
Aquilae,C,912.0,974.1,R,1
Aquilae,D,914.4,968.6,Y,1
Aquilae,E,914.7,979.0,O,1
Arae,A,933.9,084.3,W,1
Arae,B,933.3,093.7,Y,3
Arae,C,941.9,094.2,B,1
Arae,D,929.2,075.0,Y,1
Arae,E,923.7,082.1,B,1
Arcturus,*,964.5,579.1,O,1
Arianni,A,739.5,175.0,B,1
Arianni,B,718.7,183.3,Y,1
Arianni,C,739.5,168.7,Y,1
Arietis,A,937.5,158.3,G,1
Arietis,B,946.9,154.8,G,1
Arietis,C,947.7,167.0,Y,1
Arietis,D,954.1,168.7,R,2
Arietis,E,955.9,173.5,O,1
Aurigae,A,806.2,208.3,W,1
Aurigae,B,808.0,201.1,O,1
Aurigae,C,816.3,200.9,W,1
Aurigae,D,818.7,193.7,W,1
Bellatrix,*,545.8,191.6,Y,1
Betelgeuse,*,412.5,377.0,B,1
Bootis,A,022.9,266.6,G,1
Bootis,B,035.1,275.8,Y,1
Bootis,C,038.4,290.0,O,1
Bootis,D,021.7,250.9,O,1
Bootis,E,013.8,269.6,R,1
Bootis,F,016.7,287.5,R,1
Bootis,G,067.2,286.3,O,1
Brahe,A,620.8,233.3,O,1
Brahe,B,639.5,231.2,G,1
Brahe,C,635.4,272.9,W,1
Brahe,D,645.8,275.0,G,1
Brahe,E,641.6,262.5,O,1
Brahe,F,650.0,245.8,R,1
Caeli,A,241.1,071.8,R,1
Caeli,B,258.9,074.1,R,1
Caeli,C,285.4,078.7,R,1
Caeli,D,308.9,078.2,R,1
Caeli,E,333.3,080.1,R,1
Camelopardalis,A,606.2,404.1,Y,2
Camelopardalis,B,595.8,408.3,G,1
Camelopardalis,C,612.5,393.7,G,1
Camelopardalis,D,627.0,383.3,G,1
Camelopardalis,E,593.7,393.7,O,1
Camelopardalis,F,616.6,412.5,O,1
Camelopardalis,G,620.8,422.9,O,1
Camelopardalis,H,589.5,402.0,R,1
Camelopardalis,I,629.1,393.7,R,1
Cancri,A,493.7,514.5,G,1
Cancri,B,515.5,512.2,G,1
Cancri,C,500.6,501.1,O,1
Cancri,D,509.4,493.1,R,1
Canopus,*,218.7,150.0,B,1
Capella,*,424.4,009.1,B,1
Capricorni,A,297.9,516.6,O,2
Capricorni,B,303.5,517.8,O,1
Capricorni,C,299.3,531.8,R,1
Carinae,A,362.5,543.7,G,2
Carinae,B,341.6,543.7,B,1
Carinae,C,358.3,547.9,G,1
Cassiopeiae,A,354.1,518.7,B,1
Cassiopeiae,B,377.0,525.0,G,1
Cassiopeiae,C,367.9,506.8,Y,1
Cassiopeiae,D,387.5,514.5,Y,1
Cassiopeiae,E,399.4,518.5,R,1
Centauri,A,155.9,099.3,R,3
Centauri,B,141.2,090.5,G,1
Centauri,C,157.9,111.5,G,1
Centauri,D,131.2,126.0,Y,1
Centauri,E,151.5,086.6,G,1
Centauri,F,146.3,077.9,R,2
Cephei,A,375.0,583.3,G,2
Cephei,B,362.5,575.0,R,2
Cerenkov,A,422.1,198.6,B,1
Cerenkov,B,450.0,200.0,O,1
Ceti,A,287.5,447.9,W,2
Ceti,B,287.5,404.1,B,1
Ceti,C,303.8,408.3,B,1
Ceti,D,293.7,430.6,B,1
Ceti,E,270.8,470.8,B,1
Ceti,F,289.5,468.7,G,1
Ceti,G,281.2,425.0,O,1
Chamaeleonis,A,497.1,710.4,W,1
Chamaeleonis,B,495.5,703.4,O,1
Chamaeleonis,C,489.5,704.1,G,1
Chamaeleonis,D,485.4,712.5,O,1
Chamaeleonis,E,487.9,720.1,Y,1
Chamaeleonis,F,495.8,722.9,G,1
Chamaeleonis,G,508.3,714.5,B,1
Chamaeleonis,H,514.5,695.8,B,1
Chamaeleonis,I,514.5,687.5,G,1
Chamaeleonis,J,506.2,675.0,B,1
Chandrasekhar,A,012.5,654.1,R,2
Chandrasekhar,B,037.5,671.6,W,1
Chandrasekhar,C,020.8,662.5,G,1
Chandrasekhar,D,018.7,652.0,O,1
Chandrasekhar,E,031.2,672.8,O,1
Circini,A,039.5,597.9,G,2
Circini,B,036.5,609.3,B,1
Circini,C,043.7,627.0,B,1
Circini,D,054.1,614.5,O,1
Circini,E,056.3,598.0,O,1
Circini,F,045.6,598.9,O,1
Columbae,A,075.0,645.8,W,2
Columbae,B,077.0,660.2,R,1
Columbae,C,072.9,620.8,G,1
Copernicus,A,579.1,262.5,G,1
Copernicus,B,600.8,263.1,Y,1
Copernicus,C,562.5,252.0,R,1
Corvi,B,033.3,981.2,G,1
Corvi,C,006.2,947.9,G,1
Corvi,D,100.0,939.5,O,1
Corvi,E,010.4,912.5,R,1
Corvi,F,008.3,997.9,R,1
Corvi,G,102.0,993.7,R,1
Crateris,A,601.4,563.2,B,2
Crateris,B,610.7,578.5,Y,1
Crateris,C,616.6,600.0,W,1
Crateris,D,620.0,593.5,Y,1
Crateris,E,630.1,587.5,Y,1
Crateris,F,649.6,603.2,O,1
Crateris,G,642.9,595.8,R,1
Crateris,H,621.5,625.5,R,1
Crucis,A,558.3,629.1,W,1
Crucis,B,547.9,668.7,G,1
Crucis,C,525.0,622.9,Y,1
Crucis,D,543.7,591.6,Y,1
Cygnus,A,047.9,458.3,B,1
Cygnus,B,047.9,464.5,G,1
Cygnus,C,056.2,470.8,G,1
Cygnus,D,041.6,471.7,R,1
Cygnus,E,025.0,458.3,R,1
Delphini,A,371.6,645.8,R,1
Delphini,B,377.0,650.0,G,1
Deneb,*,218.7,008.3,O,1
Doradus,A,420.8,685.4,O,1
Doradus,B,429.1,693.7,O,1
Draconis,A,277.1,835.1,B,1
Draconis,B,282.2,839.5,R,1
Draconis,C,251.8,805.6,W,1
Draconis,D,253.5,835.8,Y,1
Draconis,E,283.6,785.7,W,1
Draconis,F,277.6,867.3,O,1
Draconis,G,315.1,839.0,R,1
Draconis,H,327.0,800.0,Y,1
Draconis,I,356.2,825.0,Y,1
Draconis,J,245.8,866.6,W,1
Draconis,K,236.2,839.5,G,1
Draconis,L,231.0,870.2,R,1
Draconis,M,230.0,886.1,R,1
Draconis,N,258.8,865.3,R,1
Equulei,A,591.0,662.4,B,1
Equulei,B,602.0,672.9,B,1
Eridani,A,587.5,772.9,Y,3
Eridani,B,595.8,764.5,W,1
Eridani,C,579.1,758.3,W,1
Fomalhaut,*,437.5,856.2,R,1
Fornacis,A,537.5,787.5,W,1
Fornacis,B,564.5,802.0,B,1
Fornacis,C,587.5,806.2,B,1
Fornacis,D,597.9,797.9,G,1
Fornacis,E,604.1,791.6,O,1
Fornacis,F,610.4,800.0,O,1
Fornacis,G,618.7,787.5,R,1
Geminorum,A,495.8,779.1,W,2
Geminorum,B,497.9,779.1,W,1
Geminorum,C,489.5,745.8,O,1
Geminorum,D,464.5,747.9,R,1
Giclas,A,084.3,038.0,O,2
Giclas,B,084.3,043.1,Y,1
Giclas,C,080.3,033.7,Y,1
Giclas,D,087.7,034.0,Y,1
Giclas,E,095.8,046.8,B,1
Giclas,F,111.6,033.4,G,1
Giclas,G,070.8,004.1,W,1
Giclas,H,067.5,074.2,O,1
Gorno,A,277.1,014.6,B,1
Gorno,B,281.4,008.9,O,1
Gorno,C,293.9,011.6,O,1
Gorno,D,290.8,026.9,B,1
Gorno,E,282.0,030.1,G,1
Groombridge,*,996.0,904.2,W,2
Gruis,A,227.4,366.3,W,1
Gruis,B,214.8,355.1,W,1
Gruis,C,225.0,370.8,W,1
Gruis,D,235.4,374.1,R,1
Gruis,E,241.6,368.7,O,2
Gruis,F,258.3,375.0,W,1
Gruis,G,247.9,395.8,O,1
Herculis,A,160.4,364.5,W,1
Herculis,B,175.8,341.8,B,1
Horologii,A,720.8,754.1,Y,1
Horologii,B,712.5,725.0,R,1
Horologii,C,720.8,700.0,R,1
Horologii,D,736.0,718.4,R,1
Horologii,E,753.2,725.8,R,1
Horologii,F,744.3,753.8,R,1
Horologii,G,739.5,785.4,R,1
Horologii,H,720.0,784.9,R,1
Horologii,I,708.3,799.3,R,1
Horologii,J,688.9,780.3,R,1
Horologii,K,694.0,751.4,R,1
Hyades,A,832.2,893.4,W,1
Hyades,B,837.5,895.8,B,1
Hyades,C,837.5,904.1,O,1
Hyades,D,824.9,895.8,O,1
Hyades,E,850.0,912.5,O,1
Hyades,F,850.0,937.2,Y,1
Hyades,G,845.8,939.3,Y,1
Hyades,H,829.6,954.8,G,1
Hyades,I,800.0,950.5,W,1
Hyades,J,766.4,958.9,G,1
Hyades,K,725.5,937.4,G,1
Hydrae,A,733.3,650.0,W,1
Hydrae,B,781.2,656.2,O,1
Hydrae,C,816.6,625.0,R,1
Hyginus,A,852.0,416.6,R,1
Hyginus,B,864.5,406.2,R,1
Hyperion,*,656.2,127.0,O,1
Illuminati,A,235.4,329.1,R,3
Illuminati,B,252.0,343.7,O,1
Illuminati,C,268.7,333.3,B,1
Illuminati,D,235.4,316.6,Y,2
Illuminati,E,272.7,295.1,G,1
Illuminati,F,245.8,275.0,G,1
Illuminati,G,220.8,285.4,O,1
Illuminati,H,201.1,304.3,O,1
Indi,A,400.0,136.3,O,1
Indi,B,395.8,135.4,B,1
Kepler,A,581.2,320.8,Y,1
Kepler,B,562.5,295.8,B,1
Kepler,C,602.0,297.9,O,1
Klystron,A,193.7,997.9,R,1
Klystron,B,291.6,954.1,R,1
Krueger,A,030.4,047.7,Y,1
Krueger,B,053.0,044.2,W,1
Krueger,C,052.2,052.5,Y,1
Krueger,D,057.0,028.9,G,1
Krueger,E,026.5,015.6,O,1
Krueger,F,013.4,056.5,G,1
Lacaille,A,014.6,095.5,R,1
Lacaille,B,023.0,095.2,Y,1
Lacaille,C,024.2,085.7,O,2
Lacertae,A,841.6,808.3,B,1
Lacertae,B,822.9,804.1,R,1
Lalande,A,349.9,264.8,B,1
Lalande,B,340.0,280.4,W,1
Lalande,C,361.9,283.0,O,1
Lalande,D,375.9,277.8,O,1
Lentilis,A,462.5,600.0,B,1
Lentilis,B,462.5,589.5,G,1
Lentilis,C,458.3,604.1,O,1
Lentilis,D,472.9,595.8,O,1
Leonis,A,900.0,822.9,G,1
Leonis,B,943.7,785.4,R,1
Leonis,C,968.7,733.3,W,1
Leporis,A,807.3,858.8,O,1
Leporis,B,766.6,866.6,O,1
Leporis,C,718.7,881.2,B,1
Librae,A,735.4,906.2,B,1
Librae,B,741.4,912.4,G,1
Librae,C,754.5,910.7,O,1
Librae,D,779.1,918.7,O,1
Librae,E,779.1,922.9,W,1
Librae,F,783.3,908.3,W,1
Librae,G,788.9,918.1,G,1
Lipi,A,556.2,864.5,G,1
Lipi,B,550.0,839.5,O,1
Lipi,C,547.5,882.3,O,1
Lipi,D,564.5,897.9,R,1
Lipi,E,543.7,827.0,R,1
Luyten,A,425.0,164.5,R,1
Luyten,B,433.3,168.7,O,1
Luyten,C,433.3,156.2,R,1
Lyncis,A,560.0,955.2,O,1
Lyncis,B,571.1,947.5,O,1
Lyncis,C,578.1,971.1,Y,1
Lyncis,D,570.4,979.5,Y,1
Lyncis,E,532.9,953.8,Y,1
Lyncis,F,522.9,972.9,R,1
Lyncis,G,598.9,949.6,O,1
Lyncis,H,612.5,960.4,R,1
Lyrae,A,191.6,127.0,R,1
Lyrae,B,189.5,104.1,R,1
Maksutov,A,597.7,524.6,G,1
Maksutov,B,627.0,547.9,R,1
Menkar,*,481.2,927.0,O,1
Mensae,A,383.3,318.7,R,1
Mensae,B,403.0,288.7,R,1
Mensae,C,464.5,295.8,R,1
Mersenne,A,260.4,664.5,R,1
Mersenne,B,241.6,729.1,R,1
Metis,*,570.8,460.4,R,1
Microscopii,*,439.5,997.9,G,1
Mira,A,355.1,232.0,R,1
Mira,B,367.8,192.6,B,1
Mira,C,388.4,226.2,Y,1
Mira,D,335.4,235.4,O,1
Mizar,*,041.6,130.1,R,1
Monocerotis,A,387.5,718.7,O,1
Monocerotis,B,385.4,729.1,G,1
Muscae,A,112.5,779.1,B,2
Muscae,B,104.1,770.8,O,1
Muscae,C,102.0,718.7,R,1
Muscae,D,139.5,804.1,R,1
Muscae,E,152.0,833.3,O,1
Muscae,F,112.5,858.3,O,1
Normae,A,142.5,540.4,B,1
Normae,B,141.6,531.5,W,1
Normae,C,152.0,526.1,R,1
Normae,D,161.3,527.9,G,1
Normae,E,185.4,541.6,W,1
Normae,F,215.9,561.4,O,1
Octantis,A,157.8,666.8,G,3
Octantis,B,136.0,648.9,G,1
Olber,A,027.0,218.7,B,1
Olber,B,012.5,222.9,B,1
Olber,C,031.2,225.0,B,1
Ophiuchi,A,043.7,877.0,R,1
Ophiuchi,B,047.9,887.5,R,1
Ophiuchi,C,033.3,891.6,G,1
Organon,*,685.8,057.7,G,1
Orionis,A,190.2,606.5,G,1
Orionis,B,197.8,596.8,G,1
Orionis,C,192.3,587.8,O,1
Orionis,D,171.4,592.6,Y,1
Orionis,E,154.5,581.8,O,1
Orionis,F,155.8,605.8,Y,1
Orionis,G,179.5,632.9,Y,1
Orionis,H,188.1,630.8,G,1
Orionis,I,211.8,637.9,B,1
Orionis,J,220.0,617.6,B,1
Orionis,K,215.9,607.3,Y,1
Orionis,L,222.8,603.8,B,1
Pavonis,A,056.2,800.0,G,2
Pavonis,B,068.7,800.0,O,1
Pegasi,A,033.3,762.5,B,1
Pegasi,B,039.5,745.8,B,1
Persei,A,929.1,258.3,B,1
Persei,B,947.9,266.6,W,1
Persei,C,933.3,279.1,R,1
Persei,D,925.0,285.4,W,1
Persei,E,903.8,240.7,R,1
Persei,F,946.9,280.6,O,1
Persei,G,889.5,268.7,O,1
Persei,H,937.5,241.6,G,1
Persei,I,887.5,231.2,G,1
Phoenicis,A,941.6,439.5,B,1
Phoenicis,B,957.3,418.2,R,1
Phoenicis,C,981.2,414.5,B,1
Pictoris,A,933.3,370.8,G,1
Pictoris,B,931.2,356.2,B,1
Pictoris,C,937.5,360.4,Y,1
Pictoris,D,959.9,358.3,G,1
Piscium,A,843.7,345.8,G,1
Piscium,B,879.1,354.1,O,1
Piscium,C,870.8,362.5,O,1
Piscium,D,877.0,345.8,G,1
Pollux,*,565.2,009.8,W,1
Procyon,*,074.2,226.8,O,1
Ptolemae,A,200.4,044.1,B,1
Ptolemae,B,205.8,047.5,Y,1
Ptolemae,C,210.0,055.4,Y,1
Ptolemae,D,215.6,044.0,O,1
Ptolemae,E,185.5,027.0,G,1
Ptolemae,F,178.7,033.8,G,1
Ptolemae,G,174.0,042.3,B,1
Puppis,A,812.5,308.3,O,1
Puppis,B,829.1,297.9,O,1
Puppis,C,827.0,295.8,G,1
Pyxidis,A,895.8,500.0,B,2
Pyxidis,B,900.0,500.0,R,1
Pyxidis,C,906.2,508.3,O,1
Raynet,A,284.0,167.6,G,1
Raynet,B,288.1,161.4,G,1
Raynet,C,279.1,189.5,R,1
Regulus,*,373.2,106.7,G,1
Reticuli,A,731.2,506.2,O,1
Reticuli,B,702.0,529.1,B,1
Reticuli,C,741.6,508.3,G,1
Reticuli,D,725.0,458.3,G,1
Rigel,*,210.4,208.3,O,1
Sagittae,A,025.0,568.7,G,1
Sagittae,B,037.1,577.2,R,1
Sagittae,C,015.2,590.0,R,1
Sagittarii,A,683.3,200.0,B,1
Sagittarii,B,702.0,239.5,Y,1
Sagittarii,C,708.3,277.0,R,1
Sagittarii,D,656.2,302.0,B,1
Saurus,A,230.6,228.5,O,1
Saurus,B,240.2,230.9,R,1
Saurus,C,229.8,238.5,R,1
Scorpii,A,646.7,187.8,B,1
Scorpii,B,650.0,191.6,W,1
Scorpii,C,647.9,206.2,G,1
Scorpii,D,603.6,203.5,B,1
Scorpii,E,629.1,220.8,G,1
Scorpii,F,650.0,220.8,B,1
Sculptoris,A,604.1,156.2,B,1
Sculptoris,C,608.3,162.5,G,1
Sculptoris,D,581.2,120.8,O,1
Sculptoris,E,570.8,152.0,O,1
Scuti,A,503.9,037.3,O,1
Scuti,B,501.4,058.4,R,1
Scuti,C,525.6,060.8,G,1
Scuti,D,516.0,028.0,Y,1
Scuti,E,533.8,035.5,W,1
Scuti,F,531.3,015.0,W,1
Serpentis,A,491.1,018.0,O,2
Serpentis,B,486.1,026.2,W,1
Serpentis,C,492.3,029.4,Y,1
Serpentis,D,474.7,022.1,O,1
Serpentis,E,487.2,040.8,R,1
Serpentis,F,500.7,003.5,G,1
Serpentis,G,471.4,007.8,G,1
Serpentis,H,452.9,016.9,B,1
Serpentis,I,459.6,042.9,W,1
Sextantis,A,433.7,106.6,B,1
Sextantis,B,460.4,118.7,O,1
Sextantis,C,487.5,114.5,O,1
Sextantis,D,487.3,096.8,G,1
Sextantis,E,477.0,089.5,B,1
Sextantis,F,468.1,091.6,O,1
Sirius,*,180.6,150.7,W,2
Sol,*,175.2,145.0,Y,1
Squidi,A,214.5,391.6,G,1
Squidi,B,206.2,399.1,O,1
Squidi,C,214.5,420.8,R,1
Tauri,A,022.9,366.6,G,1
Tauri,B,028.8,373.5,W,1
Tauri,C,026.7,364.5,B,1
Tauri,D,016.6,377.0,W,1
Tauri,E,014.9,351.9,R,1
Tauri,F,009.0,361.4,B,1
Telescopii,A,028.5,402.0,W,1
Telescopii,B,029.1,410.4,O,1
Telescopii,C,050.0,418.7,B,1
Trianguli,A,793.4,031.8,B,1
Trianguli,B,795.8,027.0,B,1
Trianguli,C,806.2,031.8,R,1
Tucanae,A,400.0,543.7,G,1
Tucanae,B,393.7,562.5,O,1
Tucanae,C,408.3,551.3,R,1
Vega,*,033.3,975.0,R,1
Vela,*,334.5,193.1,Y,1
Velorum,A,086.0,406.5,B,1
Velorum,B,092.6,397.2,R,1
Virginis,A,029.1,325.0,G,1
Virginis,B,050.1,325.9,G,1
Virginis,C,079.1,327.0,R,1
Virginis,D,110.4,333.3,W,1
Vitalis,A,300.0,350.0,B,1
Vitalis,B,318.7,337.5,B,1
Vitalis,C,308.3,367.4,R,1
Vitalis,D,277.0,362.5,R,1
Volantis,A,095.1,177.0,Y,1
Volantis,B,114.0,184.7,W,1
Volantis,C,104.8,191.9,G,1
Volantis,D,097.7,195.3,Y,1
Volantis,E,070.5,183.8,G,1
Volantis,F,073.6,173.7,B,2
Volantis,G,065.0,164.6,G,1
Vulpeculae,A,365.4,258.7,G,3
Vulpeculae,B,364.1,251.2,G,1
Vulpeculae,C,371.3,253.7,G,1
Vulpeculae,D,372.1,261.9,G,1
Vulpeculae,E,366.8,266.6,G,1
Vulpeculae,F,360.8,263.7,G,1
Vulpeculae,G,358.7,256.6,G,1
Wolf,A,160.1,174.6,R,1
Wolf,B,166.6,181.2,Y,1
Zeeman,*,335.2,194.0,W,3
+106
View File
@@ -0,0 +1,106 @@
/* stringbank.c, Copyright (c) 2005 Michael C. Martin */
/*
* 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 thta it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stringbank.h"
#define CHUNK_SIZE (1024 - sizeof (void *) - sizeof (int))
typedef struct _stringbank_chunk {
char data[CHUNK_SIZE];
int len;
struct _stringbank_chunk *next;
} chunk;
static chunk *bank = NULL;
static void
add_chunk (void)
{
chunk *n = malloc (sizeof (chunk));
n->len = 0;
n->next = bank;
bank = n;
}
const char *
StringBank_AddString (const char *str)
{
int len = strlen (str);
chunk *x = bank;
if (len > CHUNK_SIZE)
return NULL;
while (x) {
int remaining = CHUNK_SIZE - x->len;
if (len < remaining) {
char *result = x->data + x->len;
strcpy (result, str);
x->len += len + 1;
return result;
}
x = x->next;
}
/* No room in any currently existing chunk */
add_chunk ();
strcpy (bank->data, str);
bank->len += len + 1;
return bank->data;
}
const char *
StringBank_AddOrFindString (const char *str)
{
int len = strlen (str);
chunk *x = bank;
if (len > CHUNK_SIZE)
return NULL;
while (x) {
int i = 0;
while (i < x->len) {
if (!strcmp (x->data + i, str))
return x->data + i;
while (x->data[i]) i++;
i++;
}
x = x->next;
}
/* We didn't find it, so add it */
return StringBank_AddString (str);
}
#ifdef DEBUG
void
StringBank_Dump (FILE *s)
{
chunk *x = bank;
while (x) {
int i = 0;
while (i < x->len) {
fprintf (s, "\"%s\"\n", x->data + i);
while (x->data[i]) i++;
i++;
}
x = x->next;
}
}
#endif
+37
View File
@@ -0,0 +1,37 @@
/* stringbank.h, Copyright (c) 2005 Michael C. Martin */
/*
* 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 thta it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Se 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _STRINGBANK_H_
#define _STRINGBANK_H_
#ifdef DEBUG
#include <stdio.h>
#endif
/* Put str into the string bank. */
const char *StringBank_AddString (const char *str);
/* Put str into the string bank if it's not already there. Much slower. */
const char *StringBank_AddOrFindString (const char *str);
#ifdef DEBUG
/* Print out a list of the contents of the string bank to the named stream. */
void StringBank_Dump (FILE *s);
#endif /* DEBUG */
#endif /* _STRINGBANK_H_ */
+232
View File
@@ -0,0 +1,232 @@
/* Portions Copyright (C) 2005 Serge van den Boom */
/*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "unicode.h"
#include "port.h"
// Resynchronise (skip everything starting with 0x10xxxxxx):
static inline void
resyncUTF8(const unsigned char **ptr) {
while ((**ptr & 0xc0) == 0x80)
*ptr++;
}
// Get one character from a UTF-8 encoded string.
// *ptr will point to the start of the next character.
// Returns 0 if the encoding is bad. This can be distinguished from the
// '\0' character by checking whether **ptr == '\0' before calling this
// function.
wchar_t
getCharFromString(const unsigned char **ptr) {
wchar_t result;
if (**ptr < 0x80) {
// 0xxxxxxx, regular ASCII
result = **ptr;
(*ptr)++;
return result;
}
if ((**ptr & 0xe0) == 0xc0) {
// 110xxxxx; 10xxxxxx must follow
// Value between 0x00000080 and 0x000007ff (inclusive)
result = **ptr & 0x1f;
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if (result < 0x00000080) {
// invalid encoding - must reject
goto err;
}
return result;
}
if ((**ptr & 0xf0) == 0xe0) {
// 1110xxxx; 10xxxxxx 10xxxxxx must follow
// Value between 0x00000800 and 0x0000ffff (inclusive)
result = **ptr & 0x0f;
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if (result < 0x00000800) {
// invalid encoding - must reject
goto err;
}
return result;
}
if ((**ptr & 0xf8) == 0xf0) {
// 11110xxx; 10xxxxxx 10xxxxxx 10xxxxxx must follow
// Value between 0x00010000 and 0x0010ffff (inclusive)
result = **ptr & 0x07;
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if ((**ptr & 0xc0) != 0x80)
goto err;
result = (result << 6) | ((**ptr) & 0x3f);
(*ptr)++;
if (result < 0x00010000) {
// invalid encoding - must reject
goto err;
}
return result;
}
err:
fprintf(stderr, "Warning: Invalid UTF8 sequence.\n");
// Resynchronise (skip everything starting with 0x10xxxxxx):
resyncUTF8(ptr);
return 0;
}
size_t
utf8StringCount(const unsigned char *start) {
size_t count = 0;
wchar_t ch;
for (;;) {
ch = getCharFromString(&start);
if (ch == '\0')
return count;
count++;
}
}
// Locates a wide char (ch) in a UTF-8 string (pStr)
// returns the char positions when found
// -1 when not found
int
utf8StringPos (const unsigned char *pStr, wchar_t ch)
{
int pos;
for (pos = 0; *pStr != '\0'; ++pos)
{
if (getCharFromString (&pStr) == ch)
return pos;
}
if (ch == '\0' && *pStr == '\0')
return pos;
return -1;
}
// Safe version of strcpy(), somewhat analogous to strncpy()
// except it guarantees a 0-term when size > 0
// when size == 0, returns NULL
unsigned char *
utf8StringCopy (unsigned char *dst, size_t size, const unsigned char *src)
{
if (size == 0)
return 0;
strncpy (dst, src, size);
dst[size - 1] = '\0';
return dst;
}
// Decodes a UTF-8 string (start) into a wide char string (wstr)
// returns number of chars decoded and stored, not counting 0-term
// any chars that do not fit are truncated
// wide string term 0 is always appended, unless the destination
// buffer is 0 chars long
size_t
getWideFromString(wchar_t *wstr, size_t maxcount, const unsigned char *start)
{
wchar_t *next;
if (maxcount == 0)
return 0;
// always leave room for 0-term
--maxcount;
for (next = wstr; maxcount > 0; ++next, --maxcount)
{
*next = getCharFromString(&start);
if (*next == 0)
break;
}
*next = 0; // term
return next - wstr;
}
int
isWideGraphChar(wchar_t ch)
{ // this is not technically sufficient, but close enough for us
// we'll consider all non-control (CO and C1) chars in 'graph' class
return (ch > 0xa0) || (ch > 0x20 && ch < 0x7f);
}
int
isWidePrintChar(wchar_t ch)
{ // this is not technically sufficient, but close enough for us
// chars in 'print' class are 'graph' + 'space' classes
// the only space we currently have defined is 0x20
return (ch == 0x20) || isWideGraphChar(ch);
}
wchar_t
toWideUpper(wchar_t ch)
{ // this is a very basic Latin-1 implementation
// just to get things going
return (ch < 0x100) ? toupper(ch) : ch;
}
wchar_t
toWideLower(wchar_t ch)
{ // this is a very basic Latin-1 implementation
// just to get things going
return (ch < 0x100) ? tolower(ch) : ch;
}
+37
View File
@@ -0,0 +1,37 @@
/* Portions Copyright (C) 2005 Serge van den Boom */
/*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _UNICODE_H
#define _UNICODE_H
#include <stddef.h>
wchar_t getCharFromString(const unsigned char **ptr);
size_t utf8StringCount(const unsigned char *start);
int utf8StringPos (const unsigned char *pStr, wchar_t ch);
unsigned char *utf8StringCopy (unsigned char *dst, size_t size,
const unsigned char *src);
size_t getWideFromString(wchar_t *wstr, size_t maxcount,
const unsigned char *start);
int isWideGraphChar(wchar_t ch);
int isWidePrintChar(wchar_t ch);
wchar_t toWideUpper(wchar_t ch);
wchar_t toWideLower(wchar_t ch);
#endif /* _UNICODE_H */