📄 rc.c
字号:
/*
Copyright 1997, 1998 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
And David Lindauer, LADSoft.
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.
------
DAL 2001-2003 This file extensively modified and only resembles
the original
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "cmdline.h"
#include "umem.h"
#include "preproc.h"
#include "xrc.h"
extern int basestyle;
extern int laststrlen;
extern char *prm_searchpath;
extern enum e_sym lastst;
extern char lastid[];
extern char laststr[];
extern int lastch;
extern int ival;
extern FILE *inputFile;
extern char *infile;
extern int lineno;
extern int incconst;
int base_language = 0;
/* We read the directory entries in a cursor or icon file into
instances of this structure. */
struct icondir
{
unsigned char width;
unsigned char height;
unsigned char colorcount;
union
{
struct
{
unsigned short planes;
unsigned short bits;
} icon;
struct
{
unsigned short xhotspot;
unsigned short yhotspot;
} cursor;
}
u;
unsigned long bytes;
unsigned long offset;
};
int rc_lineno;
static RES_DIR *resources;
static int cursors;
static int fonts;
struct fontdir *fontdirs;
RES_INFO fontdirs_resinfo;
static int icons;
static int get_word(FILE *e)
{
int b1, b2;
b1 = getc(e);
b2 = getc(e);
return ((b2 &0xff) << 8) | (b1 &0xff);
} static unsigned long get_long(FILE *e)
{
int b1, b2, b3, b4;
b1 = getc(e);
b2 = getc(e);
b3 = getc(e);
b4 = getc(e);
return (((((((b4 &0xff) << 8) | (b3 &0xff)) << 8) | (b2 &0xff)) << 8) | (b1
&0xff));
}
//-------------------------------------------------------------------------
static void get_data(FILE *e, unsigned char *p, long c)
{
unsigned long got;
got = fread(p, 1, c, e);
if (got == c)
return ;
fatal("Data file too short");
}
//-------------------------------------------------------------------------
RES_RES *define_standard_resource(RES_DIR *resources, int type, RES_ID *name,
int language, int dupok)
{
RES_ID xtype;
RES_DIR *res;
RES_RES *r = 0;
xtype.hasname = 0;
xtype.v.id = type;
for (res = resources; res; res = res->link)
{
if (compare_type(&xtype, &res->type) && compare_type(name, &res->id) &&
language == res->language)
{
r = res->res;
if (!dupok)
return r;
break;
}
}
if (!r)
{
r = AllocateMemory(sizeof(RES_RES));
r->type = RST_UNINITIALIZED;
}
AddResource(&resources, r, &xtype, name, language, dupok);
return r;
}
//-------------------------------------------------------------------------
void define_accelerator(RES_ID *id, RES_INFO *resinfo, struct accelerator *data)
{
RES_RES *r = define_standard_resource(&resources, RT_ACCELERATOR, id,
resinfo->language, 0);
r->type = RST_ACCELERATOR;
r->u.acc = data;
r->info = *resinfo;
}
#define BITMAP_SKIP (14)
static long filesize(FILE *e)
{
long rv;
fseek(e, 0L, SEEK_END);
rv = ftell(e);
fseek(e, 0L, SEEK_SET);
return rv;
}
//-------------------------------------------------------------------------
void define_bitmap(RES_ID *id, RES_INFO *resinfo, char *filename)
{
char buf[256];
FILE *e;
char *real_filename;
unsigned char *data;
int i, size;
RES_RES *r;
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
size = filesize(e);
if (size <= BITMAP_SKIP)
fatal("%s too small", filename);
data = AllocateMemory(size - BITMAP_SKIP);
fseek(e, (long)BITMAP_SKIP, SEEK_SET);
get_data(e, data, size - BITMAP_SKIP);
fclose(e);
r = define_standard_resource(&resources, RT_BITMAP, id, resinfo->language,
0);
r->type = RST_BITMAP;
r->u.data.length = size - BITMAP_SKIP;
r->u.data.data = data;
r->info = *resinfo;
}
//-------------------------------------------------------------------------
void define_cursor(RES_ID *id, RES_INFO *resinfo, char *filename)
{
char buf[256];
FILE *e;
int type, count, i;
struct icondir *icondirs;
int first_cursor;
RES_RES *r;
struct group_cursor *first, **pp;
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
get_word(e);
type = get_word(e);
count = get_word(e);
if (type != 2)
fatal("cursor file `%s' does not contain cursor data", buf);
icondirs = AllocateMemory(count *sizeof * icondirs);
for (i = 0; i < count; i++)
{
icondirs[i].width = getc(e);
icondirs[i].height = getc(e);
icondirs[i].colorcount = getc(e);
getc(e);
icondirs[i].u.cursor.xhotspot = get_word(e);
icondirs[i].u.cursor.yhotspot = get_word(e);
icondirs[i].bytes = get_long(e);
icondirs[i].offset = get_long(e);
if (!icondirs[i].width)
icondirs[i].width = 32;
if (!icondirs[i].height)
icondirs[i].height = (icondirs[i].bytes - 0x30) / ((32 / 8) *2);
if (feof(e))
fatal("Data too short in %s", buf);
}
/* Define each cursor as a unique resource. */
first_cursor = cursors;
for (i = 0; i < count; i++)
{
unsigned char *data;
RES_ID name;
struct cursor *c;
if (fseek(e, icondirs[i].offset, SEEK_SET) != 0)
fatal("file i/o error on %s", buf);
data = AllocateMemory(icondirs[i].bytes);
get_data(e, data, icondirs[i].bytes);
c = AllocateMemory(sizeof *c);
c->xhotspot = icondirs[i].u.cursor.xhotspot;
c->yhotspot = icondirs[i].u.cursor.yhotspot;
c->length = icondirs[i].bytes;
c->data = data;
++cursors;
name.hasname = 0;
name.v.id = cursors;
r = define_standard_resource(&resources, RT_CURSOR, &name, resinfo
->language, 0);
r->type = RST_CURSOR;
r->u.cursor = c;
r->info = *resinfo;
}
fclose(e);
/* Define a cursor group resource. */
first = NULL;
pp = &first;
for (i = 0; i < count; i++)
{
struct group_cursor *cg;
cg = AllocateMemory(sizeof *cg);
cg->link = NULL;
cg->width = icondirs[i].width;
cg->height = 2 * icondirs[i].height;
/* FIXME: What should these be set to? */
cg->planes = 1;
cg->bits = 1;
cg->bytes = icondirs[i].bytes + 4;
cg->index = first_cursor + i + 1;
*pp = cg;
pp = &(*pp)->link;
}
free(icondirs);
r = define_standard_resource(&resources, RT_GROUP_CURSOR, id, resinfo
->language, 0);
r->type = RST_GROUP_CURSOR;
r->u.group_cursor = first;
r->info = *resinfo;
r->info.memflags |= MF_PURE;
}
//-------------------------------------------------------------------------
void define_dialog(RES_ID *id, RES_INFO *resinfo, struct dialog *dialog)
{
struct dialog *copy;
RES_RES *r;
copy = AllocateMemory(sizeof *copy);
*copy = *dialog;
r = define_standard_resource(&resources, RT_DIALOG, id, resinfo->language,
0);
r->type = RST_DIALOG;
r->u.dialog = copy;
r->info = *resinfo;
} int unicode_from_ascii(short **text, char *string, int len)
{
int i = 0;
*text = AllocateMemory(len *2+2);
while (*string)
{
(*text)[i++] = (short)*(unsigned char*)string++;
}
(*text)[i++] = 0;
return (i - 1);
}
//-------------------------------------------------------------------------
void string_to_id(RES_ID *val, char *string)
{
val->hasname = 1;
val->v.n.len = unicode_from_ascii(&val->v.n.name, string, strlen(string));
}
//-------------------------------------------------------------------------
struct dialog_control *define_control(char *text, long id, long x, long y, long
width, long height, long class , long style, long exstyle)
{
struct dialog_control *n = AllocateMemory(sizeof(struct dialog_control))
;
n->link = NULL;
n->id = id;
n->style = style;
n->exstyle = exstyle;
n->x = x;
n->y = y;
n->width = width;
n->height = height;
if (class < 1024)
{
n->class.hasname = 0;
n->class.v.id = class ;
}
else
string_to_id(&n->class , (void*)class );
if (text != NULL)
string_to_id(&n->text, text);
else
{
n->text.hasname = 0;
n->text.v.id = 0;
}
n->data = NULL;
n->help = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -