home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2001 May
/
VPR0105A.BIN
/
OLS
/
BR98211
/
br98211.lzh
/
BR98.CPP
next >
Wrap
C/C++ Source or Header
|
2001-02-05
|
147KB
|
5,568 lines
//
// Browser Returns for 9801
// Ver2.11
// Copyright (C) AsakaSoft 1999-2001
//
// Ver2.00 Release 2000/05/28
// Ver2.10 for Network Release 2000/08/12
// Ver2.11 Release 2001/02/05
//
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <jstring.h>
#include <dir.h>
#include <pc98.h>
#include <jctype.h>
#include <io.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <process.h>
#include <conio.h>
union REGS inregs, outregs;
struct SREGS segregs;
const char apname[] = "\033[32mBrowser Returns for 9801 : Ver2.11 Rev[" __DATE__ "] (C) AsakaSoft 1999-\033[36m2001\033[m";
//---------------------------------------------------------------------------
// 宣言
enum { bufmax = 200 };
// 1対1対応
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long int ulong;
uchar* nextchar ( uchar *p );
enum { pathmax = 130 };
struct fnsplit {
uchar sw;
// uchar drive[MAXDRIVE]; // X: (3)
// uchar dir[MAXDIR]; // \dir\ (66)
// uchar name[MAXFILE]; // filename (9)
uchar ext[MAXEXT]; // .ext (5)
uchar nhost[255]; // host"10.0.0.12:80" / drive"a:"
uchar npath[255]; // path"/~asaka/" / dir"/data/"
uchar nname[255]; // fname+ext"index.html"
};
int fnsplit2 ( uchar *path, struct fnsplit *fns );
void fnmerge2 ( uchar *path, struct fnsplit *fns );
void fnmerge3 ( uchar *path, struct fnsplit *fns );
void fnmerge3slash ( uchar *path );
void fnadd ( struct fnsplit *fns, uchar *fpos, uchar *name );
void fn83 ( uchar *name );
int fn_div ( uchar c );
const uint gseg[4] = { 0xe000, 0xa800, 0xb000, 0xb800 };
// ディスクエラー処理
int err_handler(int errval,int ax,int bp,int si);
FILE *fopen2(const char *filename, const char *mode);
// 設定ファイル
struct inifile {
uchar isegc;
uchar gifbmpname[pathmax];
uchar jpegconvname[pathmax];
uchar pngconvname[pathmax];
uchar paletname[pathmax];
uchar imode;
uchar bmplcd;
uchar cursorspeed;
uchar httpname[pathmax];
} ini = { 0, "gifbmp", "jpg6cdb", "pngcdb", "palet.rgb", 0, 0, 8, "httpget" };
uchar defpalet[48] = { 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,15,15 };
int in_loadini ( void );
// ディレクトリ設定
uchar apdir[pathmax], ininame[pathmax];
uchar tempdir[pathmax];
uchar tempdrive = 0;
void dr_getapdir ( void );
void dr_setapdir ( uchar *path );
void dr_gettempdir ( void );
void dr_settempdir ( uchar *path );
// USKCGM書体設定
// 1Bytes全てと2BytesのABCひらがなカタカナはキャッシュ対象
// 1Bytesの21~7Eとキャッシュ対象の2Bytesは書体読込対象
uchar ft_anfont[256][16]; // 21-7E (4096+256)
enum { ft_sw_unload = 0, ft_sw_builtin = 1, ft_sw_builtin2, ft_sw_file }; // 未読込=0 内蔵=1 別内蔵=2 ファイル=3
uchar ft_answ[256];
uchar ft_kjfont[3][94][32]; // 2321-237E, 2421-247E, 2521-257E (9024+282)
uchar ft_onpufont[32] = {
0x00, 0x00,
0x00, 0x1e,
0x00, 0xfe,
0x07, 0xf2, //
0x07, 0x02,
0x04, 0x02,
0x04, 0x02,
0x04, 0x02, //
0x04, 0x02,
0x04, 0x02,
0x04, 0x1e,
0x04, 0x3e, //
0x3c, 0x38,
0x7c, 0x00,
0x70, 0x00,
0x00, 0x00 };
uchar ft_kjsw[3][94];
void ft_init ( void );
void ft_getfont ( uint code, void *buf );
enum { ft_ef_i = 1, ft_ef_b = 2, ft_ef_u = 4, ft_ef_s = 8, ft_ef_h = 16 }; // 斜体・太字・下線・取消線・縦縮小
enum { ft_ank_1, ft_ank_2, ft_ank_1k, ft_ank_2k, ft_ank_bi1, ft_ank_bi2,
ft_kj_1an, ft_kj_2an, ft_kj_2hi, ft_kj_2ka, ft_kj_2mr, ft_kj_bi2 };
int ft_ankload ( uchar *filename, uint mode );
void ft_checkank ( uint code );
void ft_writeank ( uint code, uchar mode, uint x, uint y, uint ys, uint ye );
int ft_kjload ( uchar *filename, uint mode );
void ft_writekj ( uint code, uchar mode, uint x, uint y, uint ys, uint ye );
enum { ft_km_auto, ft_km_sjis, ft_km_eucjp };
// kmodeは参照形にしないと自動判定の結果がフィードバックされない
// ft_km_autoにして呼び出すと判定結果がkmodeに戻ってくる(JISだったらautoのまま)
uint ft_writestr ( uchar *str, uchar mode, uint x, uint y, uint ys, uint ye, uint &kmode );
void ft_writestrs ( uchar *str, uchar *modestr, uint x, uint y, uint ys, uint ye, uint s );
// BMPファイル関連
uint bm_convbmp ( uchar *convname, uchar *bmpname, uint &x, uint &y, uchar *bmpat );
uint bm_convbmp2 ( uchar *convname, uchar *bmpname, uint &x, uint &y );
void bm_setpixel ( uchar *buf, uint x, uint c, uchar dy );
uchar bm_to15 ( uchar b, uchar g, uchar r );
uint bm_writecdb ( uchar *convname, uint x, long y, uint sx, uint sy, uint ys, uint ye, uint xs, uint xe );
uchar bm_pat[4][4] = {
16, 7, 14, 5,
3, 12, 1, 10,
13, 4, 15, 6,
0, 8, 2, 11 };
// Graphic BIOS関連
void gb_init ( void );
void gb_init2 ( void );
void gb_gdcmode ( uchar m );
void gb_gdctile ( uchar t );
void gb_write ( uchar p );
void gb_view ( uchar p );
void gb_gcls ( void );
void gb_gcls2 ( uint y1, uint y2 );
void gb_gcls2 ( uint y1, uint y2, uint x1, uint x2 );
void gb_loadrgb ( uchar* pbuf );
uchar gb_sw = 0;
void gb_pstart ( void );
void gb_pend ( void );
// Add Ver2.10
void gb_waitvsync ( void );
// GDC・描画関連(EGC対応)
const uint gd_gseg[4] = { 0x0000, 0x4000, 0x8000, 0xc000 };
uchar gd_is5 = 2;
void gd_cmd ( uchar cmd );
void gd_dat ( uchar dat );
void gd_textw ( uchar dl, uchar dh );
void gd_writemode ( uchar mode );
void gd_csrw ( uchar plane, ulong ead, uchar dad );
void gd_vecte ( void );
void gd_waitdraw ( void );
void gd_gline ( uint x1, uint y1, uint x2, uint y2, uchar color );
// Graphics EGC関連
void eg_init ( void );
void eg_color ( uchar c );
uchar eg_ison = 0;
void eg_on ( void );
void eg_off ( void );
void eg_operation ( uchar ope );
// ドライブ情報関連
uchar di_daua[0x60];
uchar di_noteram[2] = { 9, 9 };
void di_initdaua ( void );
uchar di_getdaua ( uchar drive );
// HTML変換関連
uint convhtml ( uchar *cdhname, uchar *headname, uchar *htmlname, uchar &kmode, ulong &cdhx, ulong &cdhy );
void convhtml2 ( FILE *cdhtmlfp, FILE *headerfp, FILE *htmlfp, ulong length, ulong *xl, uint tdepth, uint *hx, ulong *hy, uchar istext, uchar *chname );
ulong convhtmlpt[16][2];
void convhtmlbar ( uchar ntable, ulong now, ulong size, uchar istext );
// フォルダ一覧補助
void maketop ( uchar *buf, uchar *filename, uchar *ext, uint len );
// HTML文字効果
enum { he_maxeff = 40 };
struct {
uchar tag;
uchar eff;
} htmleff[he_maxeff];
uint neffs;
void he_addeff ( uchar tag, uchar eff );
uchar he_geteff ( void );
void he_endeff ( uchar tag );
// HTMLテキストバッファ関連
// バッファそのものは再帰不要だが、
// struct txは再帰の必要がある(<li>内のtableなど)
// 出力は常に1行単位
uchar txbuf[100];
uchar txeff[100];
uchar linkto[500];
uint linksx;
enum { tx_align_l = 0, tx_align_c, tx_align_r };
struct tx {
ulong nx, sx, ex, nl, sy; // 次行開始/現在開始/終了x / 現在テキスト幅(pixel) / 現在y
ulong maxx, maxy;
uchar linkline;
uchar align;
};
void tx_init ( struct tx *tx, ulong w );
uint tx_nlcheck ( struct tx *tx, uchar sw );
void tx_return ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl );
void tx_maxreturn ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl, uchar sw );
void tx_empreturn ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl );
void tx_setlink ( struct tx *tx, FILE *headfp, uchar *href );
void tx_writelink ( struct tx *tx, FILE *headfp );
void tx_addstr ( struct tx *tx, uchar ch, uchar sw, uchar eff, FILE *cdhfp, FILE *headfp, uint yl );
// CDH・HDR表示関連
void writecdh ( uchar *filename, uint tx, uint sx, uint ty, uint s, long fy );
void loadhdr ( uchar *filename, uchar *name, ulong &starty, ulong &maxy, uchar *title, uchar *fname );
void extlink ( uchar *hdrname, uchar *hdr2name, ulong y1, ulong y2 );
void getlink ( uchar *filename, uchar *linkto, uint x, ulong y );
enum { titlemax = 200 };
// メイン処理
void draw1 ( void );
ulong tempfree = 0;
void draw2 ( uchar *cdhname, long y, ulong maxy, uchar *title, uchar *fname, uchar *hdrname, uchar *hdr2name );
void draw3 ( uchar *hdrname, uchar *linkto, long y, struct ip_joy &ipjoy );
void makename ( uint number, uchar *cdhname, uchar *hdrname );
uint inputline ( uchar *buf );
// リアルタイム処理関連
int rt_sinbuf[60];
void rt_init ( void );
int rt_sin ( int min );
int rt_cos ( int min );
void rt_clock ( void );
// 入力処理関連
uchar ip_joy = 4;
uchar ip_mouse = 3;
uint ip_joyport[4][2] = { 0, 0, 0x088, 0x08a, 0x188, 0x18a, 0x288, 0x28a };
int ip_mx = 320, ip_my = 200; // カーソル座標保存
uint ip_be = 0, ip_bb = 0; // カーソル座標保存
uchar ip_sp[3] = { 16, 8, 4 };
uchar ip_mvo = 1; // マウスカーソルがOFFになった回数
struct ip_joy {
int mx;
int my;
char jx;
char jy;
char e;
char pe;
char s;
char b;
char pb;
uchar key[16];
};
void ip_sbout ( uchar data, uchar sw );
uchar ip_sbin ( uchar sw );
void ip_init ( uchar speed );
void ip_structinit ( struct ip_joy &ipjoy );
void ip_get ( struct ip_joy &ipjoy );
void ip_mvon ( void );
void ip_mvoff ( void );
void ip_wmcursor ( struct ip_joy &ipjoy, uchar sw, uchar b );
// --------------------------------------------------------------------------
// 主要関数
int main ( void ) {
/* struct fnsplit f;
uchar buf[250] = "";
fnsplit2 ( *_argv, &f );
fnadd ( &f, buf, *(_argv+1) );
printf ( "sw%d host%s path%s name%s pos%s ext%s\n%s%s%s\n", f.sw, f.nhost, f.npath, f.nname, buf, f.ext, f.nhost, f.npath, f.nname );
return 0;
*/
printf ( "%s\n", apname );
// 各種初期化
printf ( " 動作環境確認..." );
if ( ( peekb ( 0, 0x54c ) & 2 ) == 0 ) {
printf ( "\nグラフィックチャージャ(GRCG)を搭載していない機種では動作しません。\nPC-9801/E/F/Mは非搭載・PC-9801Uではオプションです。\n" );
getch();
}
if ( ( peekb ( 0, 0x54c ) & 4 ) == 0 ) {
printf ( "\n16色表示用VRAMを搭載していない機種では動作しません\nPC-9801/E/F/Mは非搭載・一部のPC-9801VF/VMではオプションです。\n" );
getch();
}
printf ( "\r 動作環境確認...完了\n" );
printf ( " 設定読込準備..." );
harderr ( err_handler );
ft_init ();
rt_init ();
gb_init ();
di_initdaua ();
dr_getapdir ();
dr_gettempdir ();
printf ( "完了\n" );
printf ( " BR98ディレクトリ %s\n", apdir );
printf ( " 作業ディレクトリ %s\n", tempdir );
printf ( " 設定ファイル %s...\n", ininame );
in_loadini ();
// in_loadiniの後に行う初期化
if ( ini.isegc > 0 ) eg_init ();
gb_init2 ();
ip_init( ini.cursorspeed );
switch ( ip_mouse ) {
case 2:
printf ( " MS規格マウスドライバ使用\n" );
break;
case 1:
printf ( " NEC規格マウスドライバ使用\n" );
break;
default:
printf ( " マウスの使用にはMOUSE.SYSかMOUSE.COMが必要です\n" );
break;
}
long i, j, backi = 0;
ulong hx, hy;
uchar b[200], b2[200], cdhn[pathmax], hdrn[pathmax], b3[pathmax], hdrn2[pathmax];
struct fnsplit f;
uchar kmode, a;
uchar ti[titlemax] = "", fn[pathmax] = "", lt[200] = "";
ulong sy, my;
struct ip_joy joy;
struct time timep, timep2;
uint k, nowf = 0;
dfree dfr;
uchar isb = 0;
ip_structinit ( joy );
gettime ( &timep );
timep2 = timep;
strcpy ( hdrn2, "$temp.hd2" );
dr_settempdir ( hdrn2 );
b[0] = getdisk() + 'A';
b[1] = ':';
b[2] = '\\';
b[3] = '\0';
getcurdir ( 0, b + 3 );
i = strlen ( b );
if ( i > 3 ) {
b[i] = '\\';
b[i+1] = '\0';
}
fnsplit2 ( b, &f );
fnadd ( &f, b2, "./" );
fnadd ( &f, b2, *(_argv+1) );
fnmerge2 ( b, &f );
printf ( "%s : %s\n", b, b2 );
a = 2;
printf ( "\033[2J\033[>3h\033[>1h\033[>5h\r" );
kmode = ft_km_auto;
do {
if ( a == 2 ) {
gb_pstart ();
draw1 ();
gb_pend ();
gb_pstart ();
draw1 ();
gb_pend ();
makename ( nowf, cdhn, hdrn );
remove ( cdhn );
remove ( hdrn );
/* if ( convhtml ( cdhn, hdrn, b, kmode, hx, hy ) == 2 ) {
strcat ( b, "\\" );
*/
convhtml ( cdhn, hdrn, b, kmode, hx, hy );
/* }
*/
rt_clock ();
i = 0;
ti[0] = fn[0] = '\0';
loadhdr ( hdrn, b2, sy, my, ti, fn );
i = sy;
getdfree ( tempdrive, &dfr );
tempfree = (ulong)dfr.df_avail * (ulong)dfr.df_sclus * (ulong)dfr.df_bsec;
}
gb_pstart ();
draw2 ( cdhn, i, my, ti, fn, hdrn, hdrn2 );
gb_pend ();
a = 0;
// ip_mvon ();
ip_wmcursor ( joy, 1, isb );
while ( a == 0 ) {
draw3 ( hdrn2, lt, i, joy );
if ( lt[0] != '\0' ) isb = 1; else isb = 0;
ip_wmcursor ( joy, 0, isb );
if ( joy.pe > 0 ) {
if ( joy.my >= 380 ) {
// ファンクションキー
k = joy.mx & 63;
if ( ( k >= 8 ) && ( k <= 55 ) ) {
k = joy.mx / 64;
switch ( k ) {
case 0:
joy.e = joy.pe = -1;
joy.key[12] |= 4;
break;
case 1:
joy.key[12] |= 8;
break;
case 2:
joy.key[12] |= 16;
break;
case 3:
joy.key[12] |= 32;
break;
case 4:
joy.key[12] |= 64;
joy.b = joy.pb = 1;
break;
case 5:
joy.key[12] |= 128;
break;
case 6:
joy.key[13] |= 1;
break;
case 7:
joy.key[13] |= 2;
break;
case 8:
joy.key[13] |= 4;
break;
case 9:
joy.key[13] |= 8;
break;
}
}
} else if ( joy.mx < 15 ) {
if ( ( joy.my >= 42 ) && ( joy.my <= 357 ) ) {
// スクロールバー
i += ( (long)joy.my - 200 ) * 2;
a = 1;
}
} else if ( lt[0] != '\0' ) {
// リンク
fnsplit2 ( b, &f );
fnadd ( &f, b2, lt );
fnmerge2 ( b, &f );
nowf++;
backi = i;
makename ( nowf, cdhn, hdrn );
kmode = ft_km_auto;
a = 2;
}
}
if ( joy.e > 0 ) {
if ( joy.mx >= 627 ) {
if ( ( joy.my >= 42 ) && ( joy.my <= 357 ) ) {
// ゲージ
i = ( (long)joy.my - 42 ) * my / 316 - 158;
a = 1;
}
}
}
if ( joy.pb > 0 ) {
// 前ファイルに戻る
if ( nowf > 0 ) {
nowf--;
makename ( nowf, cdhn, hdrn );
ti[0] = fn[0] = '\0';
loadhdr ( hdrn, b2, sy, my, ti, fn );
strcpy ( b, fn );
b2[0] = '\0';
i = backi;
backi = 0;
if ( i == 0 ) i = sy;
a = 1;
}
}
if ( joy.key[6] & 64 ) {
// ROLL UP
if ( joy.key[14] & 1 ) i += 150; else i += 300;
a = 1;
}
if ( joy.key[6] & 128 ) {
// ROLL DOWN
if ( joy.key[14] & 1 ) i -= 150; else i -= 300;
a = 1;
}
if ( ( joy.my == 399 ) && ( joy.jy > 0 ) ) {
// 下端で↓
i += 40;
a = 1;
}
if ( ( joy.my == 0 ) && ( joy.jy < 0 ) ) {
// 上端で↑
i -= 40;
a = 1;
}
if ( joy.key[13] & 2 ) {
// F8
fnsplit2 ( b, &f );
fnadd ( &f, b2, ".\\" );
fnmerge2 ( b, &f );
nowf++;
backi = i;
makename ( nowf, cdhn, hdrn );
kmode = ft_km_auto;
a = 2;
}
if ( joy.key[13] & 1 ) {
// F7
i = my - 357 + 42;
a = 1;
}
if ( joy.key[12] & 128 ) {
// F6
i = 0;
a = 1;
}
if ( joy.key[12] & 32 ) {
// F4
// ip_mvoff ();
ip_wmcursor ( joy, 2, isb );
b3[0] = '\0';
k = inputline ( b3 );
printf ( "\033[19;1H%-79.79s\033[3;1H\r", "" );
if ( k == 0 ) {
fnsplit2 ( b, &f );
fnadd ( &f, b2, b3 );
fnmerge2 ( b, &f );
nowf++;
backi = i;
makename ( nowf, cdhn, hdrn );
kmode = ft_km_auto;
a = 2;
} else ip_be = -1;
// ip_mvon ();
ip_wmcursor ( joy, 1, isb );
}
if ( i > (long)my - 357 + 42 ) {
// 下オーバー
i = my - 357 + 42;
}
if ( i < 0 ) {
// 上オーバー
i = 0;
}
if ( joy.key[12] & 8 ) {
// F2
kmode = ft_km_sjis;
a = 2;
}
if ( joy.key[12] & 16 ) {
// F3
kmode = ft_km_eucjp;
a = 2;
}
if ( joy.pe < 0 ) a = 1;
if ( a == 0 ) {
gettime ( &timep2 );
if ( timep.ti_sec != timep2.ti_sec ) {
timep = timep2;
// ip_mvoff ();
ip_wmcursor ( joy, 2, isb );
rt_clock ();
// ip_mvon ();
ip_wmcursor ( joy, 1, isb );
}
}
}
ip_wmcursor ( joy, 2, isb );
// ip_mvoff ();
} while ( joy.e >= 0 );
gb_write ( 1 );
gb_gcls();
gb_write ( 0 );
gb_gcls();
printf ( "\033[2J\033[>3l\033[>1l\033[>5l\r" );
printf ( "%s\n作業ファイルを消去しています...\r", apname );
strcpy ( b2, "$*.*" );
dr_settempdir ( b2 );
sprintf ( b, "del %s", b2 );
system ( b );
printf ( "作業ファイルを消去しています...完了\n" );
//printf ( "gd_is5 %u\n", gd_is5 );
return ( 0 );
}
//---------------------------------------------------------------------------
// 共通関数
uchar* nextchar ( uchar *p ) {
if ( iskanji ( *p ) ) return ( p + 2 );
else return ( p + 1 );
}
int fnsplit2 ( uchar *path, struct fnsplit *fns ) {
// 相対パスでの呼び出しは誤動作の原因
/*
// フォルダ名・ファイル名ともに8.3化処理が必要
// pはpath(長いファイル名)上を動く
// p2はpathの名前開始点
// qはbuf(短いファイル名)上の書き込み点
uchar *p, *p2, *q;
uchar buf[pathmax] = "";
int i;
if ( strnicmp ( "http://", path, 7 ) == 0 ) {
fns->sw = 1;
p = path + 7;
while ( *p != '\0' ) {
switch ( *p ) {
case '/':
p2 = p + 1;
*p2 = '\0';
strcpy ( fns->nhost, path+7 );
strcpy ( fns->npath, *p2 );
*p2 = '/';
return ( 0 );
break;
}
p = nextchar ( p );
}
strcpy ( fns->nhost, path+7 );
return ( 0 );
}
fns->sw = 0;
p = p2 = path;
q = buf;
while ( *p != '\0' ) {
switch ( *p ) {
case '\\':
case '/':
*p = '\0';
strcpy ( q, p2 );
*p = '\\';
fn83 ( q );
while ( *q != '\0' ) q++;
*q = '\\';
q++;
*q = '\0';
p2 = p + 1;
break;
case ':':
*p = '\0';
strcat ( q, p2 );
*p = ':';
while ( *q != '\0' ) q++;
*q = ':';
q++;
*q = '\0';
p2 = p + 1;
break;
}
p = nextchar ( p );
}
strcpy ( q, p2 );
fn83 ( q );
*/
/*
p = buf;
q = NULL;
while ( *p != '\0' ) {
if ( ( *p == '\\' ) || ( *p == ':' ) ) q = p + 1;
p++;
}
if ( q != NULL ) {
fn83 ( q );
}
*/
/*
return ( fnsplit ( buf, fns->drive, fns->dir, fns->name, fns->ext ) );
*/
uchar buf[255] = "";
fnadd ( fns, buf, path );
return 0;
}
void fnmerge2 ( uchar *path, struct fnsplit *fns ) {
// if ( fns->sw == 0 ) fnmerge ( path, fns->drive, fns->dir, fns->name, fns->ext );
// else sprintf ( path, "http://%s%s%s%s", fns->nhost, fns->npath, fns->nname, fns->nopt );
// .extは読み取り専用として使う→getapdirは独自処理に変更
uchar buf[500];
sprintf ( buf, "%s%s%s", fns->nhost, fns->npath, fns->nname );
if ( fns->sw ) sprintf ( path, "http://%s",buf );
else strcpy ( path, buf );
}
void fnmerge3 ( uchar *path, struct fnsplit *fns ) {
// URLから作業ファイル名を作る
// table内のことを考えるとキャッシュが必要
// 画面表示があるため呼出場所に注意
enum { bufmax = 300 };
uchar buf[500], buf2[bufmax], p[pathmax], buf3[500];
FILE *tp;
int i;
ulong l;
fnmerge2 ( buf, fns );
if ( fns->sw ) {
path[0] = '\0';
l = 0;
strcpy ( p, "$temp.net" );
dr_settempdir ( p );
tp = fopen2 ( p, "r" );
if ( tp != NULL ) {
while ( !feof ( tp ) ) {
buf2[0] = '\0';
fgets ( buf2, bufmax, tp );
if ( buf2[0] == '\0' ) break;
i = strlen ( buf2 );
if ( buf2[i-1] == '\n' ) buf2[i-1] = '\0';
if ( stricmp ( buf, buf2 ) == 0 ) {
fgets ( buf2, bufmax, tp );
i = strlen ( buf2 );
if ( buf2[i-1] == '\n' ) buf2[i-1] = '\0';
strcpy ( path, buf2 );
fclose ( tp );
fnmerge3slash ( path );
return;
} else fgets ( buf2, bufmax, tp );
l++;
}
// まだキャッシュされていない場合
fclose ( tp );
}
// $temp.netがない場合も同様
if ( fns->ext[0] == '\0' ) sprintf ( buf2, "$net%lu.htm", l);
else sprintf ( buf2, "$net%lu%s", l, fns->ext );
dr_settempdir ( buf2 );
remove ( buf2 );
sprintf ( buf3, "%s %s %s", ini.httpname, buf2, buf );
system ( buf3 );
strcpy ( path, buf2 );
tp = fopen2 ( buf2, "rb" );
if ( tp != NULL ) {
fclose ( tp );
tp = fopen2 ( p, "a" );
if ( tp != NULL ) {
fprintf ( tp, "%s\n%s\n", buf, buf2 );
fclose ( tp );
}
}
} else strcpy ( path, buf );
fnmerge3slash ( path );
}
void fnmerge3slash ( uchar *path ) {
uchar *p;
p = path;
while ( *p != '\0' ) {
if ( *p == '/' ) *p = '\\';
p = nextchar ( p );
}
}
void fnadd ( struct fnsplit *fns, uchar *fpos, uchar *name ) {
/* uchar *p;
uchar *q;
uchar *q2;
uchar *r;
uchar *r2;
uchar f = 0;
uchar fn[pathmax]; // ファイル名と拡張子を一括格納
uchar p2[pathmax];
*/
/* URLも処理できるようになった
if ( strnicmp ( name, "http:", 5 ) == 0 ) {
fns->drive[0] = fns->dir[0] = fns->name[0] = fns->ext[0] = '\0';
return;
}
*/
/* fpos[0] = fn[0] = '\0'; // 現在の位置は無条件に破棄できる
p = name;
f = 0;
while ( *p != '\0' ) {
q = p;
if ( f == 0 ) {
while ( ( *q != '\0' ) && ( *q != '\\' ) && ( *q != '/' ) && ( *q != '#' ) ) {
q = nextchar ( q );
}
} else {
while ( *q != '\0' ) {
q = nextchar ( q );
}
}
if ( ( *(p+1) == ':' ) && ( p == name ) ) {
// ドライブ変更
fns->drive[0] = *p;
fns->dir[0] = '\\';
fns->dir[1] = '\0';
// ディスクが入っていないなどの場合はとりあえずrootにすべきなのかも
if ( *p <= 'Z' ) getcurdir ( *p - 'A' + 1, ( fns->dir ) + 1 );
else getcurdir ( *p - 'a' + 1, ( fns->dir ) + 1 );
fns->name[0] = fn[0] = fns->ext[0] = '\0'; // フォルダ指定ということはファイル名が消える
p += 2;
continue;
}
switch ( *q ) {
case '\0':
if ( f == 0 ) {
// ファイル名
// 8.3化処理が必要
strcpy ( fn, p );
fn83 ( fn );
} else {
// 位置
strcpy ( fpos, p );
}
break;
case '#':
// ファイル名
f = 1;
*q = '\0';
strcpy ( fn, p );
*q = '#';
break;
case '\\':
case '/':
// フォルダ名
// 8.3化処理が必要
*q = '\0';
fns->name[0] = fn[0] = fns->ext[0] = '\0'; // フォルダ指定ということはファイル名が消える
if ( *p == '\0' ) {
// root
strcpy ( fns->dir, "\\" );
*q = '\\';
break;
}
if ( *p == '.' ) {
if ( *(p+1) == '.' ) {
if ( *(p+2) == '\0' ) {
// Up dir
q2 = fns->dir, r = r2 = fns->dir;
while ( *q2 != '\0' ) {
q2 = nextchar ( q2 );
if ( *q2 == '\\' ) {
r2 = r;
r = q2;
}
}
*(r2+1) = '\0';
*q = '\\';
break;
}
} else if ( *(p+1) == '\0' ) {
// Current dir
// 移動不要
*q = '\\';
break;
}
}
// Down dir
strcpy ( p2, p );
if ( *p != '.' ) fn83 ( p2 ); // ..などは変換しない
strcat ( fns->dir, p2 );
strcat ( fns->dir, "\\" );
*q = '\\';
break;
}
p = q + 1;
if ( *q == '\0' ) break;
}
if ( fn[0] != '\0' ) {
// ファイル名と拡張子を分割
q = fn;
while ( ( *q != '\0' ) && ( *q != '.' ) ) {
q = nextchar ( q );
}
if ( *q == '\0' ) {
strncpy ( fns->name, fn, 8 );
fns->name[8] = '\0';
} else {
strncpy ( fns->ext, q, 4 ); // extは点を含む
fns->ext[4] = '\0';
*q = '\0';
strncpy ( fns->name, fn, 8 );
fns->name[8] = '\0';
}
}
// ディスクの入っていないドライブを指定すると
// DOSのエラー処理に入ってしまう
*/
// file://の記載を不許可として、\\と/を同一視すれば
// a:\data\index.htmlはa:/data/index.htmlとなり、
// host = a: / path = /data/ / name = index.html と容易に分けられる
uint np = 0; // 1=次host 0=次path
uchar *ip;
uchar *bp;
uchar *ap;
uchar *b2p;
uchar *sp;
int i;
// 初期化
fpos[0] = '\0';
// 先に#を判定
ip = name;
sp = NULL;
while ( *ip != '\0' ) {
if ( *ip == '#' ) {
sp = ip;
strcpy ( fpos, nextchar ( sp ) );
*sp = '\0';
}
ip = nextchar ( ip );
}
// 先頭特有の判定
ip = name;
if ( strnicmp ( name, "http://", 7 ) == 0 ) {
// 絶対URL
fns->sw = 1;
np = 1;
ip = name + 7;
fns->nhost[0] = fns->npath[1] = fns->nname[0] = '\0';
fns->npath[0] = '/';
} else if ( fn_div ( name[0] ) ) {
// ルート
np = 0;
ip = name + 1;
fns->npath[1] = fns->nname[0] = '\0';
fns->npath[0] = '/';
} else if ( ( name[1] == ':' ) && ( isalpha ( name[0] ) ) ) {
// ローカルドライブ(ドライブ指定は先頭でしか許容しない)
// カレントディレクトリの調査はせず、ルート基点に固定
fns->sw = 0;
fns->nhost[0] = name[0];
fns->nhost[1] = name[1];
fns->nhost[2] = '\0'; // "X:"
np = 0;
ip = name + 2;
if ( fn_div ( name[2] ) ) ip++;
fns->npath[1] = fns->nname[0] = '\0';
fns->npath[0] = '/';
}
bp = ip;
while ( *ip != '\0' ) {
if ( fn_div ( *ip ) ) {
if ( np ) {
// ここまでホスト名
*ip = '\0';
strcpy ( fns->nhost, bp );
*ip = '/';
np = 0;
} else {
// ここまでフォルダ名
*ip = '\0';
if ( strcmp ( bp, ".." ) == 0 ) {
// 親
if ( strcmp ( fns->npath, "/" ) != 0 ) {
ap = fns->npath;
bp = b2p = NULL;
while ( *ap != '\0' ) {
if ( *ap == '/' ) {
b2p = bp;
bp = ap + 1;
}
ap++;
}
if ( b2p != NULL ) *b2p = '\0';
}
} else if ( strcmp ( bp, "." ) != 0 ) {
strcat ( fns->npath, bp );
strcat ( fns->npath, "/" );
}
*ip = '/';
fns->nname[0] = '\0';
}
bp = nextchar ( ip );
}
ip = nextchar ( ip );
}
if ( bp != ip ) {
// 最後に何かあった
if ( np ) {
// ホスト名しかなかった
strcpy ( fns->nhost, bp );
} else {
// ファイル名などである
// 途中
strcpy ( fns->nname, bp );
}
}
// 最後に判定用の3文字拡張子も作る(.xxx) ?対応
ip = fns->nname;
bp = NULL;
while ( ( *ip != '\0' ) && ( *ip != '?' ) ) {
if ( *ip == '.' ) bp = ip;
ip++;
}
i = 0;
if ( bp != NULL ) {
ip = bp;
for ( i = 0 ; i < 4 ; i++ ) {
if ( ( *ip == '\0' ) && ( *ip == '?' ) ) break;
fns->ext[i] = *ip;
ip++;
}
}
fns->ext[i] = '\0';
if ( sp != NULL ) *sp = '#';
}
void fn83 ( uchar *name ) {
// 長いファイル名が入ってくる
// 前後によけいなものが来てはいけない
uchar fname[9] = "";
uchar fext[3] = "";
uchar *p = name;
uint i;
i = 0;
while ( ( *p != '\0' ) && ( *p != '.' ) ) {
if ( iskanji ( *p ) ) {
if ( i < 7 ) {
fname[i] = *p;
fname[i+1] = *(p+1);
fname[i+2] = '\0';
i+=2;
}
p+=2;
} else {
if ( ( i < 8 ) && ( *p != ' ' ) ) {
fname[i] = *p;
fname[i+1] = '\0';
i++;
}
p++;
}
}
if ( *p == '.' ) {
p++;
i = 0;
while ( *p != '\0' ) {
if ( *p == '.' ) {
// .tar.gzなどは.gzにする
i = 0;
p++;
} else if ( iskanji ( *p ) ) {
if ( i < 2 ) {
fext[i] = *p;
fext[i+1] = *(p+1);
fext[i+2] = '\0';
i+=2;
}
p+=2;
} else {
if ( ( i < 3 ) && ( *p != ' ' ) ) {
fext[i] = *p;
fext[i+1] = '\0';
i++;
}
p++;
}
}
sprintf ( name, "%s.%s", fname, fext );
} else {
strcpy ( name, fname );
}
}
int fn_div ( uchar c ) {
return ( ( c == '\\' ) || ( c == '/' ) );
}
//---------------------------------------------------------------------------
// 関数内容
#pragma warn -par
int err_handler(int errval,int ax,int bp,int si) {
hardretn ( 0 );
return ( 0 );
}
#pragma warn +par
FILE *fopen2(const char *filename, const char *mode) {
FILE *fp;
uchar c;
fp = fopen ( filename, mode );
if ( mode[0] != 'r' ) return fp; // 書き込み時は追加検査なし
if ( fp == NULL ) return NULL;
if ( fread ( ( void * )&c, 1, 1, fp ) == 0 ) {
fclose ( fp );
return NULL;
}
ungetc ( c, fp );
return fp;
}
int in_loadini ( void ) {
FILE *fp;
uchar buf[bufmax*2]; // pの場所で~展開をするため大きめに
uchar *p;
uint i;
FILE *palfp;
uchar pal[48];
fp = fopen2 ( ininame, "r" );
if ( fp == NULL ) return ( 1 );
while ( !feof ( fp ) ) {
buf[0] = '\0';
fgets ( buf, bufmax, fp );
i = strlen ( buf );
if ( i > 0 ) if ( buf[i-1] == '\n' ) buf[i-1] = '\0'; // 最後のReturnを除去
if ( ( buf[0] != '\0' ) && ( buf[0] != ';' ) ) { // ;で始まるならコメント
p = jstrchr ( buf, '=' );
if ( p != NULL ) {
*p = '\0';
p++;
if ( stricmp ( buf, "isegc" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 3 ) {
printf ( " EGC使用 : " );
switch ( i ) {
case 2:
if ( peekb ( 0, 0x54d ) & 64 ) {
printf ( "自動...検出しました\n" );
ini.isegc = 1;
} else {
printf ( "自動...検出されませんでした\n" );
ini.isegc = 0;
}
break;
case 1:
printf ( "する\n" );
ini.isegc = 1;
break;
case 0:
default:
printf ( "しない\n" );
ini.isegc = 0;
break;
}
}
}
}
if ( stricmp ( buf, "isgdc5" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 3 ) {
printf ( " GDCクロック : " );
switch ( i ) {
case 2:
printf ( "自動検出\n" );
gd_is5 = 2;
break;
case 1:
printf ( "5MHz\n" );
gd_is5 = 1;
break;
case 0:
default:
printf ( "2.5MHz\n" );
gd_is5 = 0;
break;
}
}
}
}
if ( stricmp ( buf, "ismouse" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 4 ) {
printf ( " マウスドライバ : " );
switch ( i ) {
case 3:
printf ( "自動判別\n" );
ip_mouse = 3;
break;
case 2:
printf ( "MS規格\n" );
ip_mouse = 2;
break;
case 1:
printf ( "NEC規格\n" );
ip_mouse = 1;
break;
case 0:
default:
printf ( "使用しない\n" );
ip_mouse = 0;
break;
}
}
}
}
if ( stricmp ( buf, "isjoy" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 5 ) {
printf ( " ジョイスティック : " );
switch ( i ) {
case 4:
printf ( "自動判別\n" );
ip_joy = 4;
break;
case 3:
case 2:
case 1:
printf ( "Port %03X,%03X\n", ip_joyport[i][0], ip_joyport[i][1] );
ip_joy = i;
break;
case 0:
default:
printf ( "使用しない\n" );
ip_joy = 0;
break;
}
}
}
}
if ( stricmp ( buf, "gifbmp" ) == 0 ) {
strcpy ( ini.gifbmpname, p );
dr_setapdir ( ini.gifbmpname );
printf ( " GIF→BMP画像変換 : %s\n", ini.gifbmpname );
}
if ( stricmp ( buf, "jpegconv" ) == 0 ) {
strcpy ( ini.jpegconvname, p );
dr_setapdir ( ini.jpegconvname );
printf ( " JPEG画像読み込み : %s\n", ini.jpegconvname );
}
if ( stricmp ( buf, "pngconv" ) == 0 ) {
strcpy ( ini.pngconvname, p );
dr_setapdir ( ini.pngconvname );
printf ( " PNG画像読み込み : %s\n", ini.pngconvname );
}
if ( stricmp ( buf, "palet" ) == 0 ) {
strcpy ( ini.paletname, p );
dr_setapdir ( ini.paletname );
palfp = fopen2 ( ini.paletname, "rb" );
if ( palfp != NULL ) {
fread ( pal, 48, 1, palfp );
fclose ( palfp );
gb_loadrgb ( pal );
printf ( " パレットファイル : %s\n", ini.paletname );
}
}
if ( stricmp ( buf, "imode" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 4 ) {
ini.imode = i;
printf ( " 斜体モード : Type %u\n", (uint)ini.imode );
}
}
}
if ( stricmp ( buf, "bmplcd" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 2 ) {
ini.bmplcd = i;
printf ( " LCD用BMP表示 : %s\n", ( ini.bmplcd == 0 ) ? "No" : "Yes" );
}
}
}
if ( stricmp ( buf, "cursorspeed" ) == 0 ) {
if ( sscanf ( p, "%u", &i ) > 0 ) {
if ( i < 256 ) {
ini.cursorspeed = i;
printf ( " カーソル移動速度 : %u\n", (uint)ini.cursorspeed );
}
}
}
if ( stricmp ( buf, "1bytefont" ) == 0 ) {
if ( stricmp ( p, "*normal" ) == 0 ) {
printf ( " 半角書体/半角カタカナ書体 : 1バイト内蔵\n" );
ft_ankload ( "", ft_ank_bi1 );
} else if ( stricmp ( p, "*2han" ) == 0 ) {
ft_ankload ( "", ft_ank_bi2 );
printf ( " 半角書体/半角カタカナ書体 : 2バイト半角\n" );
} else {
dr_setapdir ( p );
if ( ft_ankload ( p, ft_ank_1 ) == 0 ) {
printf ( " 半角書体 : %s(半角用)\n", p );
}
}
}
if ( stricmp ( buf, "1bytefont2" ) == 0 ) {
dr_setapdir ( p );
if ( ft_ankload ( p, ft_ank_2 ) == 0 ) {
printf ( " 半角書体 : %s(全角用)\n", p );
}
}
if ( stricmp ( buf, "1bytefontk" ) == 0 ) {
dr_setapdir ( p );
if ( ft_ankload ( p, ft_ank_1k ) == 0 ) {
printf ( " 半角カタカナ書体 : %s(半角用)\n", p );
}
}
/* if ( stricmp ( buf, "1bytefont2k" ) == 0 ) {
// 全角ひらがなカタカナ用フォントは文字のならびが違うため使用できないため、この流用スイッチは凍結
dr_setapdir ( p );
if ( ft_ankload ( p, ft_ank_2k ) == 0 ) {
printf ( " 半角カタカナ書体 : %s(全角用)\n", p );
}
}
*/
if ( stricmp ( buf, "2bytesfonta" ) == 0 ) {
if ( stricmp ( p, "*normal" ) == 0 ) {
if ( ft_kjload ( "", ft_kj_bi2 ) == 0 ) {
printf ( " 全角英数書体 : 2バイト内蔵\n" );
}
} else {
dr_setapdir ( p );
if ( ft_kjload ( p, ft_kj_2an ) == 0 ) {
printf ( " 全角英数書体 : %s(全角用)\n", p );
}
}
}
if ( stricmp ( buf, "2bytesfonta1" ) == 0 ) {
dr_setapdir ( p );
if ( ft_kjload ( p, ft_kj_1an ) == 0 ) {
printf ( " 全角英数書体 : %s(半角EXFONT用)\n", p );
}
}
if ( stricmp ( buf, "2bytesfonth" ) == 0 ) {
dr_setapdir ( p );
if ( ft_kjload ( p, ft_kj_2hi ) == 0 ) {
printf ( " 全角ひらがな書体 : %s(EXFONT用)\n", p );
}
}
if ( stricmp ( buf, "2bytesfontk" ) == 0 ) {
dr_setapdir ( p );
if ( ft_kjload ( p, ft_kj_2ka ) == 0 ) {
printf ( " 全角カタカナ書体 : %s(EXFONT用)\n", p );
}
}
if ( stricmp ( buf, "2bytesfontm" ) == 0 ) {
dr_setapdir ( p );
if ( ft_kjload ( p, ft_kj_2mr ) == 0 ) {
printf ( " 全角書体 : %s(まるこむ98用)\n", p );
}
}
if ( stricmp ( buf, "httpget" ) == 0 ) {
strcpy ( ini.httpname, p );
dr_setapdir ( ini.httpname );
printf ( " HTTP取得 : %s\n", ini.httpname );
}
}
}
}
fclose ( fp );
return ( 0 );
}
void dr_getapdir ( void ) {
// struct fnsplit ap;
uchar adrive[MAXDRIVE]; // X: (3)
uchar adir[MAXDIR]; // \dir\ (66)
uchar aname[MAXFILE]; // filename (9)
uchar aext[MAXEXT]; // .ext (5)
/* fnsplit2 ( *_argv, &ap );
// apdir
strcpy ( apdir, ap.drive );
strcat ( apdir, ap.dir );
// ininame
strcpy ( ap.ext, ".ini" );
fnmerge2 ( ininame, &ap );
*/
fnsplit ( *_argv, adrive, adir, aname, aext );
strcpy ( apdir, adrive );
strcat ( apdir, adir );
strcpy ( aext, ".ini" );
fnmerge ( ininame, adrive, adir, aname, aext );
}
void dr_setapdir ( uchar *path ) {
uchar path2[pathmax];
if ( path[0] != '~' ) return;
strcpy ( path2, path + 1 );
strcpy ( path, apdir );
strcat ( path, path2 );
}
//uchar tempdir[pathmax];
void dr_gettempdir ( void ) {
// tempdirをセットできるならする
// 上記にかかわらずtempdriveはセットする
strcpy ( tempdir, getenv ( "TEMP" ) );
if ( tempdir[0] == '\0' ) {
strcpy ( tempdir, getenv ( "TMP" ) );
}
if ( tempdir[0] == '\0' ) {
tempdrive = getdisk() + 1;
return; // 補う処理は不要
}
if ( tempdir[strlen(tempdir)-1] != '\\' ) strcat ( tempdir, "\\" );
if ( tempdir[1] == ':' ) {
if ( tempdir[0] >= 'a' ) tempdrive = tempdir[0] - 'a' + 1;
else tempdrive = tempdir[0] - 'A' + 1;
} else tempdrive = getdisk() + 1;
}
void dr_settempdir ( uchar *path ) {
uchar buf[pathmax];
if ( tempdir[0] == '\0' ) return;
strcpy ( buf, path );
strcpy ( path, tempdir );
strcat ( path, buf );
}
void ft_init ( void ) {
uint i, j;
uchar b[34];
for ( i = 0 ; i < 256 ; i++ ) {
ft_answ[i] = ft_sw_unload;
}
for ( i = 0 ; i < 94 ; i++ ) {
for ( j = 0 ; j < 3 ; j++ ) ft_kjsw[j][i] = ft_sw_unload;
}
// 2Bytes半角利用がデフォルト *normal指定で打ち消せる
ft_ankload ( "", ft_ank_bi2 );
// 音符フォントがないなら内蔵フォントを使用
ft_getfont ( 0x2276, b );
j = 0;
for ( i = 2 ; i < 34 ; i++ ) j |= b[i];
if ( j != 0 ) {
for ( i = 0 ; i < 32 ; i++ ) ft_onpufont[i] = b[i+2];
}
}
void ft_getfont ( uint code, void *buf ) {
int i;
uchar *p;
p = ( ( uchar * )buf ) + 2;
if ( code >= 0x8000 ) {
// ANK
pc98getfont ( code, buf );
} else if ( code >= 0x100 ) {
// 2Bytes
outportb ( 0xa3, ( code >> 8 ) - 0x20 );
outportb ( 0xa1, code & 255 );
outportb ( 0x68, 0x0b ); // KCG Bitmap Access
switch ( code >> 8 ) {
case 0x29:
case 0x2a:
case 0x2b:
for ( i = 0 ; i < 16 ; i++ ) {
outportb ( 0xa5, i + 32 );
*(p+i) = inportb ( 0xa9 ); // 左側だけ読めばいい
}
break;
default:
for ( i = 0 ; i < 16 ; i++ ) {
outportb ( 0xa5, i + 32 );
*(p+i*2) = inportb ( 0xa9 );
outportb ( 0xa5, i );
*(p+i*2+1) = inportb ( 0xa9 );
}
break;
}
outportb ( 0x68, 0x0a ); // KCG Code Access
} else {
// 1/4 Size ANK
pc98getfont ( code, buf );
}
}
int ft_ankload ( uchar *filename, uint mode ) {
FILE *fp;
int i, j, j2, k, je;
uchar buf[34], d, s;
// 機械内からの読み出し
switch ( mode ) {
// 内蔵フォントは条件によっては読まない
case ft_ank_bi1:
for ( i = 0 ; i < 256 ; i++ ) if ( ft_answ[i] > ft_sw_builtin ) ft_answ[i] = ft_sw_unload;
return ( 0 );
case ft_ank_bi2:
// for ( i = 0 ; i < 0x21 ; i++ ) if ( ft_answ[i] > ft_sw_builtin ) ft_answ[i] = ft_sw_unload;
for ( i = 0x21 ; i < 0x7f ; i++ ) { // Numlic, Alphabet
if ( ft_answ[i] != ft_sw_builtin2 ) {
ft_getfont ( 0x2900 + i, buf );
memcpy ( ft_anfont[i], &buf[2], 16 );
ft_answ[i] = ft_sw_builtin2;
}
}
// for ( i = 0x7f ; i < 0xa1 ; i++ ) if ( ft_answ[i] > ft_sw_builtin ) ft_answ[i] = ft_sw_unload;
for ( i = 0xa1 ; i < 0xe0 ; i++ ) { // 半角カタカナ
if ( ft_answ[i] != ft_sw_builtin2 ) {
ft_getfont ( 0x2a00 + i - ( 0xa0 - 0x20 ), buf );
memcpy ( ft_anfont[i], &buf[2], 16 );
ft_answ[i] = ft_sw_builtin2;
}
}
// for ( i = 0xe0 ; i < 256 ; i++ ) if ( ft_answ[i] > ft_sw_builtin ) ft_answ[i] = ft_sw_unload;
return ( 0 );
}
switch ( mode ) {
// j2 = 読み込み位置(AN/K) 0x21~0x7Eからいくつずれるか
// je = どこで止めるか ANなら0x777E Kなら0x775F
case ft_ank_1k:
case ft_ank_2k:
j2 = 0xa1 - 0x21;
je = 0x775f;
break;
default:
j2 = 0;
je = 0x777e;
break;
}
// ファイルからの読み出し
fp = fopen2 ( filename, "rb" );
if ( fp == NULL ) return ( 1 );
fread ( buf, 34, 1, fp );
switch ( mode ) {
// 以前に同じファイルから読んだか分からないので必ず読む
case ft_ank_1:
case ft_ank_1k:
for ( i = 0 ; i < 188 ; i++ ) {
// 左半分を抽出
fread ( buf, 34, 1, fp );
j = buf[1] * 256 + buf[0];
if ( ( j >= 0x7721 ) && ( j <= je ) ) {
j -= 0x7700;
for ( k = 0 ; k < 16 ; k++ ) ft_anfont[j+j2][k] = buf[k*2+2];
ft_answ[j+j2] = ft_sw_file;
}
}
break;
case ft_ank_2:
case ft_ank_2k:
for ( i = 0 ; i < 188 ; i++ ) {
// 横幅を半分に
fread ( buf, 34, 1, fp );
j = buf[1] * 256 + buf[0];
if ( ( j >= 0x7721 ) && ( j <= je ) ) {
j -= 0x7700;
for ( k = 0 ; k < 16 ; k++ ) {
// 思い浮かばないのでかなりいい加減である。遅そう。
d = 0;
s = buf[k*2+2];
if ( s & 0xc0 ) d += 0x80;
if ( s & 0x30 ) d += 0x40;
if ( s & 0x0c ) d += 0x20;
if ( s & 0x03 ) d += 0x10;
s = buf[k*2+3];
if ( s & 0xc0 ) d += 0x08;
if ( s & 0x30 ) d += 0x04;
if ( s & 0x0c ) d += 0x02;
if ( s & 0x03 ) d += 0x01;
ft_anfont[j+j2][k] = d;
}
ft_answ[j+j2] = ft_sw_file;
}
}
break;
default:
fclose ( fp );
return ( 1 );
}
fclose ( fp );
return ( 0 );
}
void ft_checkank ( uint code ) {
uchar buf[34], c2 = code & 255;
if ( ft_answ[c2] == ft_sw_unload ) {
ft_getfont ( 0x8000 + c2, buf );
memcpy ( ft_anfont[c2], &buf[2], 16 );
ft_answ[c2] = ft_sw_builtin;
}
}
void ft_writeank ( uint code, uchar mode, uint x, uint y, uint ys, uint ye ) {
uint i, j , sy, off;
uchar c; // ここはunsignedであること。
if ( x >= 80 ) return;
if ( y >= ye ) return;
if ( y + 18 <= ys ) return;
gd_waitdraw();
ft_checkank ( code );
for ( i = 0 ; i < 18 ; i++ ) {
sy = y + i;
off = x + sy * 80;
if ( ( sy >= ys ) && ( sy <= ye ) ) {
// 文字色は15に固定
if ( i < 16 ) {
if ( mode & ft_ef_h ) {
if ( ( i < 4 ) || ( i >= 12 ) ) continue;
else c = ft_anfont[code][(i-4)*2] | ft_anfont[code][(i-4)*2+1];
} else c = ft_anfont[code][i];
if ( mode & ft_ef_i ) { // 斜体
switch ( i ) {
case 0: case 1: case 2: case 3: case 4:
c = ( c >> 1 ) | ( c & 1 );
break;
case 5:
if ( ini.imode & 1 ) c |= c >> 1;
break;
case 10:
if ( ini.imode & 1 ) c |= c << 1;
break;
case 11: case 12: case 13: case 14: case 15:
c = ( c << 1 ) | ( c & 0x80 );
break;
default:
break;
}
}
// if ( mode & ft_ef_b ) c |= c >> 1; // 太字
if ( mode & ft_ef_b ) c |= c << 1; // 太字
if ( ( mode & ft_ef_s ) && ( ( i == 6 ) || ( i == 10 ) ) ) c = 0xff; // 取消線
if ( eg_ison ) pokeb ( gseg[0], off, c );
else for ( j = 0 ; j < 4 ; j++ ) pokeb ( gseg[j], off, c );
} else if ( i == 17 ) {
if ( mode & ft_ef_u ) {
if ( eg_ison ) pokeb ( gseg[0], off, 0xff );
else for ( j = 0 ; j < 4 ; j++ ) pokeb ( gseg[j], off, 0xff );
}
}
}
}
}
//enum { ft_kj_2bi, ft_kj_1an, ft_kj_2an, ft_kj_2hi, ft_kj_2ka, ft_kj_2mr };
int ft_kjload ( uchar *filename, uint mode ) {
FILE *fp;
uint i, j, k, d1, d2, p;
uchar buf[34], s;
switch ( mode ) {
case ft_kj_bi2:
// 内蔵フォント
for ( i = 0 ; i < 3 ; i++ ) {
for ( j = 0 ; j < 94 ; j++ ) {
if ( ft_kjsw[i][j] > ft_sw_builtin ) ft_kjsw[i][j] = ft_sw_unload;
}
}
return ( 0 );
}
fp = fopen2 ( filename, "rb" );
if ( fp == NULL ) return ( 1 );
fread ( buf, 34, 1, fp );
switch ( mode ) { // EXFONT書体の書き込み位置
case ft_kj_2hi:
p = 1;
break;
case ft_kj_2ka:
p = 2;
break;
case ft_kj_2an:
default:
p = 0;
break;
}
switch ( mode ) {
// 以前に同じファイルから読んだか分からないので必ず読む
case ft_kj_1an:
// 1byteAN書体
for ( i = 0 ; i < 188 ; i++ ) {
// 横幅を伸ばす
fread ( buf, 34, 1, fp );
j = buf[1] * 256 + buf[0];
if ( ( j >= 0x7721 ) && ( j <= 0x777e ) ) {
j -= 0x7721;
for ( k = 0 ; k < 32 ; k+=2 ) {
d1 = d2 = 0;
s = buf[k+2];
if ( s & 0x80 ) d1 += 0xc0;
if ( s & 0x40 ) d1 += 0x30;
if ( s & 0x20 ) d1 += 0x0c;
if ( s & 0x10 ) d1 += 0x03;
if ( s & 0x08 ) d2 += 0xc0;
if ( s & 0x04 ) d2 += 0x30;
if ( s & 0x02 ) d2 += 0x0c;
if ( s & 0x01 ) d2 += 0x03;
ft_kjfont[0][j][k] = d1;
ft_kjfont[0][j][k+1] = d2;
}
ft_kjsw[0][j] = ft_sw_file;
}
}
break;
case ft_kj_2an:
case ft_kj_2hi:
case ft_kj_2ka:
// 2bytesAN書体 / ひらがな書体 / カタカナ書体 EXFONT形
for ( i = 0 ; i < 188 ; i++ ) {
fread ( buf, 34, 1, fp );
j = buf[1] * 256 + buf[0];
if ( ( j >= 0x7721 ) && ( j <= 0x777e ) ) {
j -= 0x7721;
for ( k = 0 ; k < 32 ; k++ ) {
ft_kjfont[p][j][k] = buf[k+2];
}
ft_kjsw[p][j] = ft_sw_file;
}
}
break;
case ft_kj_2mr:
// 2bytesまるこむ書体
for ( i = 0 ; i < 188 ; i++ ) {
fread ( buf, 34, 1, fp );
j = buf[1] * 256 + buf[0];
if ( ( j >= 0x7621 ) && ( j <= 0x7673 ) ) {
// ひらがな
j -= 0x7621;
for ( k = 0 ; k < 32 ; k++ ) {
ft_kjfont[1][j][k] = buf[k+2];
}
ft_kjsw[1][j] = ft_sw_file;
} else if ( ( j >= 0x7675 ) && ( j <= 0x767e ) ) {
// 数字
j -= 0x7675;
j += 0x30 - 0x21;
for ( k = 0 ; k < 32 ; k++ ) {
ft_kjfont[0][j][k] = buf[k+2];
}
ft_kjsw[0][j] = ft_sw_file;
} else if ( ( j >= 0x7721 ) && ( j <= 0x7776 ) ) {
// カタカナ
j -= 0x7721;
for ( k = 0 ; k < 32 ; k++ ) {
ft_kjfont[2][j][k] = buf[k+2];
}
ft_kjsw[2][j] = ft_sw_file;
} else if ( j == 0x777b ) {
// P
j = 0x50 - 0x21;
for ( k = 0 ; k < 32 ; k++ ) {
ft_kjfont[0][j][k] = buf[k+2];
}
ft_kjsw[0][j] = ft_sw_file;
}
}
break;
}
return ( 0 );
}
void ft_writekj ( uint code, uchar mode, uint x, uint y, uint ys, uint ye ) {
uint i, sy, off, j, k, l;
uint d, d2; // unsignedであること
uchar buf[34], buf2[34];
if ( x >= 80 ) return;
if ( y >= ye ) return;
if ( y + 18 <= ys ) return;
gd_waitdraw();
for ( j = 2 ; j < 34 ; j++ ) buf[j] = 0;
k = code >> 8, l = code & 255;
if ( code == 0x2276 ) {
memcpy ( buf + 2, ft_onpufont, 32 );
} else if ( ( k >= 0x23 ) && ( k <= 0x25 ) && ( l >= 0x21 ) && ( l <= 0x7e ) ) {
k -= 0x23;
l -= 0x21;
if ( ft_kjsw[k][l] == ft_sw_unload ) {
// これでは2バイトずれる(buf先頭2バイトは使われない)→23~25が1ドットずれる
// ft_getfont ( code, ft_kjfont[k][l] );
ft_getfont ( code, buf );
memcpy ( ft_kjfont[k][l], buf + 2, 32 );
ft_kjsw[k][l] = ft_sw_builtin;
} else {
memcpy ( buf + 2, ft_kjfont[k][l], 32 );
}
} else ft_getfont ( code, buf );
if ( mode & ft_ef_h ) {
for ( i = 0 ; i < 34 ; i++ ) buf2[i] = buf[i];
for ( i = 0 ; i < 34 ; i++ ) buf[i] = 0;
for ( i = 0 ; i < 8 ; i++ ) {
buf[10+i*2] = buf2[2+i*4] | buf2[4+i*4];
buf[10+i*2+1] = buf2[3+i*4] | buf2[5+i*4];
}
}
for ( i = 0 ; i < 18 ; i++ ) {
sy = y + i;
off = x + sy * 80;
if ( ( sy >= ys ) && ( sy <= ye ) ) {
if ( i < 16 ) {
if ( mode & ( ft_ef_b | ft_ef_i ) ) {
d = ( buf[i*2+2]<<8 ) + buf[i*2+3];
if ( mode & ft_ef_i ) { // 斜体
switch ( i ) {
case 0: case 1: case 2: case 3: case 4:
d = ( d >> 1 ) | ( d & 1 );
break;
case 5:
if ( ini.imode & 2 ) d |= d >> 1;
break;
case 10:
if ( ini.imode & 2 ) d |= d << 1;
break;
case 11: case 12: case 13: case 14: case 15:
d = ( d << 1 ) | ( d & 0x8000 );
break;
default:
break;
}
}
// if ( mode & ft_ef_b ) d |= d >> 1; // 太字
if ( mode & ft_ef_b ) d |= d << 1; // 太字
d2 = ( ( d & 0xff )<<8 ) + ( d >> 8 );
} else d2 = buf[i*2+2] + (buf[i*2+3]<<8);
if ( ( mode & ft_ef_s ) && ( ( i == 6 ) || ( i == 10 ) ) ) d2 = 0xffff; // 取消線
if ( eg_ison ) poke ( gseg[0], off, d2 );
else for ( j = 0 ; j < 4 ; j++ ) poke ( gseg[j], off, d2 );
} else if ( i == 17 ) {
if ( mode & ft_ef_u ) {
if ( eg_ison ) poke ( gseg[0], off, 0xffff );
else for ( j = 0 ; j < 4 ; j++ ) poke ( gseg[j], off, 0xffff );
}
}
}
}
}
//enum { ft_km_auto, ft_km_sjis, ft_km_eucjp };
uint ft_writestr ( uchar *str, uchar mode, uint x, uint y, uint ys, uint ye, uint &kmode ) {
enum { n_ascii, n_kanji, n_kana };
uchar nowmode = n_ascii;
uchar *p = str, *q = p + 1;
uint nx = x, c;
gd_waitdraw();
if ( ini.isegc ) {
eg_on ();
eg_color ( 15 );
}
while ( *p != '\0' ) {
switch ( *p ) {
case 0x1b:
switch ( *q ) {
case 0x24:
// to Kanji
nowmode = n_kanji;
p += 2;
break;
case 0x28:
// to ASCII
if ( *(p+2) == 0x49 )
nowmode = n_kana;
else
nowmode = n_ascii;
p += 2;
break;
}
break;
case 0x1e:
// to Kana
if ( nowmode == n_ascii ) nowmode = n_kana;
break;
case 0x1f:
// to ASCII
if ( nowmode == n_kana ) nowmode = n_ascii;
break;
default:
// シフトコード以外
c = *q;
c += (*p)<<8;
switch ( nowmode ) {
case n_kanji:
// JIS漢字
ft_writekj ( c, mode, nx, y, ys, ye );
p++;
nx += 2;
break;
case n_kana:
// JIS半角カタカナ
ft_writeank ( *p + 0xa1 - 0x21, mode, nx, y, ys, ye );
nx++;
break;
default:
if ( kmode == ft_km_auto ) {
// 漢字コード判別作業中
// kmodeを変更すれば現在の文字から新コードで見る
if ( *p < 0x80 ) {
// ASCII
ft_writeank ( *p, mode, nx, y, ys, ye );
nx++;
/* } else if ( *p == 0x8e ) {
// 8E 次がA1~DFならEUCJP半角カタカナ/SJIS漢字
// 次が21~7EならSJIS確定
if ( *q < 0xa0 ) kmode = ft_km_sjis;
else kmode = ft_km_eucjp;
*/
} else if ( *p < 0xa1 ) {
kmode = ft_km_sjis; // 80~8D 8E~A0はSJIS
} else {
// A1~FF 漢字第2バイトで判断
// この範囲がもう一度来たらEUCJP 違うならSJIS
// 半角カタカナ2連続だと誤判定する(逆方向の誤判定はないかな?)
if ( *q > 0xa0 ) {
kmode = ft_km_eucjp;
} else {
kmode = ft_km_sjis;
}
}
} // ここで一旦合流することで判断直後の漢字表示が可能に
switch ( kmode ) {
case ft_km_eucjp:
if ( *p == 0x8e ) {
// EUCJP半角カタカナ
ft_writeank ( *q, mode, nx, y, ys, ye );
p++;
nx++;
} else if ( ( *p >= 0xa1 ) && ( *p <= 0xfe ) ) {
// EUCJP漢字
ft_writekj ( c & 0x7f7f, mode, nx, y, ys, ye );
nx += 2;
p++;
} else {
// EUCJP AN
ft_writeank ( *p, mode, nx, y, ys, ye );
nx++;
}
break;
case ft_km_sjis:
if ( iskanji ( *p ) ) {
// SJIS漢字
ft_writekj ( jmstojis ( c ), mode, nx, y, ys, ye );
p++;
nx += 2;
} else {
// SJIS ANK
ft_writeank ( *p, mode, nx, y, ys, ye );
nx++;
}
break;
case ft_km_auto:
break;
}
break;
}
break;
}
p++;
q = p + 1;
if ( nx >= 80 ) break;
}
if ( ini.isegc ) eg_off ();
return ( nx - x );
}
void ft_writestrs ( uchar *str, uchar *modestr, uint x, uint y, uint ys, uint ye, uint s ) {
uchar *p = str, *q;
uint nx = 0, nx2, c;
uchar mode = 0;
gd_waitdraw();
if ( ini.isegc ) {
eg_on ();
eg_color ( 15 );
}
while ( ( *p != '\0' ) && ( nx < s ) ) {
mode = *(modestr + nx);
nx2 = x + nx;
if ( iskanji ( *p ) ) {
if ( nx + 1 >= s ) break;
q = p + 1;
c = *q;
c += (*p)<<8;
ft_writekj ( jmstojis ( c ), mode, nx2, y, ys, ye );
p++;
nx++;
} else {
ft_writeank ( *p, mode, nx2, y, ys, ye );
}
p++;
nx++;
}
if ( ini.isegc ) eg_off ();
}
uint bm_convbmp ( uchar *convname, uchar *bmpname, uint &x, uint &y, uchar *bmpat ) {
FILE *pat;
FILE *tp;
uchar buf[bufmax], buf2[bufmax], bmpname2[bufmax], bmpname3[bufmax], f;
uint i, j;
ulong fx, fy, l;
struct fnsplit fns;
printf ( "\033[3;1H\033[>5l\r" );
fnsplit2 ( bmpname, &fns );
fnmerge3 ( bmpname3, &fns );
// fnsplit2 ( bmpname3, &fns );
strcpy ( bmpname2, bmpname3 );
// まずは開けるか確認→ローカルに移してから
pat = fopen2 ( bmpname3, "rb" );
if ( pat == NULL ) {
printf ( "\033[>5h\033[2J\r" );
return ( 1 );
}
fclose ( pat );
// GIFはBMPに変換する
if ( stricmp ( fns.ext, ".gif" ) == 0 ) {
strcpy ( buf, "$temp.gbc" );
dr_settempdir ( buf );
tp = fopen2 ( buf, "r" );
l = 0, f = 0;
if ( tp != NULL ) {
while ( !feof ( tp ) ) {
buf[0] = '\0';
fgets ( buf, bufmax, tp );
if ( buf[0] == '\0' ) break;
i = strlen ( buf );
if ( buf[i-1] == '\n' ) buf[i-1] = '\0';
if ( stricmp ( buf, bmpname3 ) == 0 ) {
sprintf ( buf2, "$%lu.bmp", l );
dr_settempdir ( buf2 );
pat = fopen2 ( buf2, "rb" );
if ( pat == NULL ) { // ファイルがもうないならもう一度変換
sprintf ( buf2, "$%lu", l );
dr_settempdir ( buf2 );
sprintf ( buf, "%s %s %s", ini.gifbmpname, bmpname3, buf2 );
system ( buf );
strcat ( buf2, ".bmp" );
} else fclose ( pat );
// fnsplit2 ( buf2, &fns );
strcpy ( bmpname2, buf2 );
f = 1;
break;
}
l++;
}
}
fclose ( tp );
if ( f == 0 ) {
sprintf ( buf2, "$%lu", l );
dr_settempdir ( buf2 );
remove ( buf2 );
sprintf ( buf, "%s %s %s", ini.gifbmpname, bmpname3, buf2 );
system ( buf );
strcat ( buf2, ".bmp" );
pat = fopen2 ( buf2, "rb" );
if ( pat != NULL ) {
fclose ( pat );
strcpy ( buf, "$temp.gbc" );
dr_settempdir ( buf );
tp = fopen2 ( buf, "a" );
if ( tp != NULL ) {
fprintf ( tp, "%s\n", bmpname );
fclose ( tp );
// fnsplit2 ( buf2, &fns );
strcpy ( bmpname2, buf2 );
}
}
}
printf ( "\033[>5h\r" );
}
// fnmerge2 ( bmpname2, &fns );
l = 0;
pat = fopen2 ( bmpat, "r" );
if ( pat != NULL ) {
while ( !feof ( pat ) ) {
buf[0] = '\0';
fgets ( buf, bufmax, pat );
if ( buf[0] == '\0' ) break;
i = strlen ( buf );
if ( buf[i-1] == '\n' ) buf[i-1] = '\0';
fgets ( buf2, bufmax, pat );
if ( stricmp ( buf, bmpname2 ) == 0 ) {
fclose ( pat );
sscanf ( buf2, "%lu,%lu", &fx, &fy );
x = fx, y = fy;
if ( x > 640 ) x = 640;
sprintf ( convname, "$%lu.cdb", l );
dr_settempdir ( convname );
pat = fopen2 ( convname, "rb" );
if ( pat == NULL ) { // ファイルがもうないならもう一度変換
if ( stricmp ( fns.ext, ".jpg" ) == 0 ) {
remove ( convname );
sprintf ( buf, "%s %s %s", ini.jpegconvname, bmpname2, convname );
system ( buf );
} else if ( stricmp ( fns.ext, ".png" ) == 0 ) {
remove ( convname );
sprintf ( buf, "%s %s %s", ini.pngconvname, bmpname2, convname );
system ( buf );
} else {
bm_convbmp2 ( convname, bmpname2, x, y );
}
} else fclose ( pat );
printf ( "\033[>5h\033[2J\r" );
return ( 0 );
}
l++;
}
fclose ( pat );
}
sprintf ( convname, "$%lu.cdb", l );
dr_settempdir ( convname );
pat = fopen2 ( bmpat, "a" );
if ( pat == NULL ) {
printf ( "\033[>5h\033[2J\r" );
return ( 1 );
}
if ( stricmp ( fns.ext, ".jpg" ) == 0 ) {
remove ( convname );
sprintf ( buf, "%s %s %s", ini.jpegconvname, bmpname2, convname );
system ( buf );
tp = fopen2 ( convname, "rb" );
if ( tp == NULL ) j = 1;
else {
fread ( (void *)&fx, 4, 1, tp );
/* fclose ( tp );
fclose ( pat );
x = y = 0;
printf ( "\033[>5h\033[2J\r" );
return ( 1 );
}
*/
fread ( (void *)&fy, 4, 1, tp );
x = fx;
if ( x > 640 ) x = 640;
y = fy;
j = 0;
fclose ( tp );
}
} else if ( stricmp ( fns.ext, ".png" ) == 0 ) {
remove ( convname );
sprintf ( buf, "%s %s %s", ini.pngconvname, bmpname2, convname );
system ( buf );
tp = fopen2 ( convname, "rb" );
if ( tp == NULL ) j = 1;
else {
fread ( (void *)&fx, 4, 1, tp );
/* fclose ( tp );
fclose ( pat );
x = y = 0;
printf ( "\033[>5h\033[2J\r" );
return ( 1 );
}
*/
fread ( (void *)&fy, 4, 1, tp );
x = fx;
if ( x > 640 ) x = 640;
y = fy;
j = 0;
fclose ( tp );
}
} else {
j = bm_convbmp2 ( convname, bmpname2, x, y );
}
if ( j == 0 ) fprintf ( pat, "%s\n%u,%u,%s\n", bmpname2, x, y, convname );
fclose ( pat );
printf ( "\033[>5h\033[2J\r" );
return ( j );
}
uint bm_convbmp2 ( uchar *convname, uchar *bmpname, uint &x, uint &y ) {
FILE *bfp;
FILE *cfp;
ulong i, j, k, colors, psize, rps, j2;
uchar flag = 0; // 1なら上から格納するBMP
ulong bx, by, n/*, ny*/;
uchar pal[256], pt[4];
uchar scr[320];
uchar r[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
struct bmphead { // 18 = 14 + 4
uchar bm[2];
ulong size;
uint dummy[2];
ulong start;
ulong headsize;
};
union {
uchar buf[18];
struct bmphead r;
} d;
struct winhead { // 36 = 40 - 4
long x;
long y;
uint dummy1;
uint colors;
ulong compress;
ulong size;
ulong dummy2[2];
ulong rps;
ulong dummy3;
};
struct os2head { // 8 = 12 - 4
uint x;
uint y;
uint dummy1;
uint colors;
};
union {
uchar buf[36];
struct winhead w;
struct os2head o;
} d2;
bfp = fopen2 ( bmpname, "rb" );
if ( bfp == NULL ) return ( 1 );
cfp = fopen2 ( convname, "wb" );
if ( cfp == NULL ) {
fclose ( bfp );
return ( 1 );
}
// ヘッダ読み込み
fread ( d.buf, 18, 1, bfp );
if ( ( d.r.bm[0] != 'B' ) || ( d.r.bm[1] != 'M' ) ) return ( 1 );
fread ( d2.buf , d.r.headsize - 4, 1, bfp );
switch ( d.r.headsize ) {
case 40:
// Windows Bitmap
bx = d2.w.x;
if ( d2.w.y < 0 ) {
by = -d2.w.y;
flag = 1;
} else {
by = d2.w.y;
flag = 0;
}
colors = d2.w.colors;
psize = 4;
if ( d2.w.compress != 0 ) {
// 圧縮データには対応しない
fclose ( bfp );
fclose ( cfp );
return ( 1 );
}
if ( colors >= 16 ) rps = d2.w.rps; else rps = 0;
break;
case 12:
// OS/2 Bitmap
bx = d2.o.x;
by = d2.o.y;
colors = d2.o.colors;
flag = 0;
psize = 3;
rps = 0;
break;
default:
fclose ( bfp );
fclose ( cfp );
return ( 1 );
}
// パレット読み込み
if ( colors >= 16 ) {
// 今のところはパレット読み終了時点で読み飛ばしがあるためseek不要
// fseek ( bfp, psize * rps, SEEK_CUR ); // 最適化カラーパレットを読みとばす
} else {
switch ( colors ) {
case 1:
rps = 2;
break;
case 4:
rps = 16;
break;
case 8:
rps = 256;
break;
default:
fclose ( bfp );
fclose ( cfp );
return ( 1 );
}
for ( i = 0 ; i < rps ; i++ ) {
fread ( pt, psize, 1, bfp );
pal[i] = bm_to15 ( pt[0], pt[1], pt[2] );
}
}
fseek ( bfp, d.r.start, SEEK_SET );
// サイズ書き込み
fputc ( bx & 255, cfp );
fputc ( ( bx >> 8 ) & 255, cfp );
fputc ( ( bx >> 16 ) & 255, cfp );
fputc ( bx >> 24, cfp );
fputc ( by & 255, cfp );
fputc ( ( by >> 8 ) & 255, cfp );
fputc ( ( by >> 16 ) & 255, cfp );
fputc ( by >> 24, cfp );
fputc ( flag, cfp );
// データ読み込み
j2 = ( bx + 7 ) / 8;
if ( j2 > 80 ) j2 = 80;
for ( i = 0 ; i < by ; i++ ) {
for ( j = 0 ; j < 80 ; j++ ) for ( k = 0 ; k < 4 ; k++ ) scr[k*80+j] = 0;
n = 0;
// if ( flag ) ny = i; else ny = by - 1 - i;
j = 0;
while ( j < bx ) {
switch ( colors ) {
case 1:
pt[0] = fgetc ( bfp );
for ( k = 0 ; k < 8 ; k++ ) if ( j + k < bx ) {
if ( pt[0] && r[k] ) bm_setpixel ( scr, j + k, pal[1], i&3 );
else bm_setpixel ( scr, j + k, pal[0], i&3 );
}
j += 8;
n++;
break;
case 4:
pt[0] = fgetc ( bfp );
bm_setpixel ( scr, j, pal[pt[0]>>4], i&3 );
if ( j + 1 < bx ) bm_setpixel ( scr, j + 1, pal[pt[0]&15], i&3 );
j += 2;
n++;
break;
case 8:
pt[0] = fgetc ( bfp );
bm_setpixel ( scr, j, pal[pt[0]], i&3 );
j++;
n++;
break;
case 16:
pt[0] = fgetc ( bfp );
pt[1] = fgetc ( bfp );
k = pt[1] * 256 + pt[0];
bm_setpixel ( scr, j, bm_to15 ( (k&31)*8, ((k>>5)&31)*8, ((k>>10)&31)*8 ), i&3 );
j++;
n += 2;
break;
case 24:
for ( k = 0 ; k < 3 ; k++ ) pt[k] = fgetc ( bfp );
bm_setpixel ( scr, j, bm_to15 ( pt[0], pt[1], pt[2] ), i&3 );
j++;
n += 3;
break;
case 32:
for ( k = 0 ; k < 4 ; k++ ) pt[k] = fgetc ( bfp );
bm_setpixel ( scr, j, bm_to15 ( pt[0], pt[1], pt[2] ), i&3 );
j++;
n += 4;
break;
}
}
while ( n % 4 != 0 ) {
fgetc ( bfp ); // DWORD区切りにあわせる
n++;
}
/* if ( ny < 400 ) {
for ( j = 0 ; j < 80 ; j++ ) {
for ( k = 0 ; k < 4 ; k++ ) {
pokeb ( gseg[k], j + ny * 80, scr[k*80+j] );
}
}
}
*/
for ( k = 0 ; k < 4 ; k++ ) {
fwrite ( scr + k * 80, j2, 1, cfp );
/* for ( j = 0 ; j < 80 ; j++ ) {
fputc ( scr[k*80+j], cfp );
}
*/
}
if ( ( i % 8 ) == 0 ) convhtmlbar ( 0, i, by, 4 );
}
x = bx; y = by;
fclose ( bfp );
fclose ( cfp );
return ( 0 );
}
void bm_setpixel ( uchar *buf, uint x, uint c, uchar dy ) {
uchar b[4] = { 1, 2, 4, 8 };
uchar r[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
uint i;
if ( x >= 640 ) return;
/* i = c % 17;
c /= 17;
if ( i >= bm_pat[x&3][dy] ) c++;
*/
c = ( c + bm_pat[x&3][dy] ) / 17;
// if ( ini.bmplcd ) c = 15 - c;
for ( i = 0 ; i < 4 ; i++ ) {
if ( c & b[i] ) {
*( buf + i * 80 + x / 8 ) |= r[x%8];
} else {
*( buf + i * 80 + x / 8 ) &= ~r[x%8];
}
}
}
uchar bm_to15 ( uchar b, uchar g, uchar r ) {
return ( ( 151UL * g + 28UL * b + 77UL * r ) / 256 );
}
uint bm_writecdb ( uchar *convname, uint x, long y, uint sx, uint sy, uint ys, uint ye, uint xs, uint xe ) {
FILE *fp;
uint i, j, k, s2, s, s3, s4;
uchar buf[4][80], flag;
long y2;
uchar *p;
uchar far *farp;
uchar b[8] = { 0x00, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
ulong ix;
gd_waitdraw();
fp = fopen2 ( convname, "rb" );
if ( fp == NULL ) return ( 1 );
p = ( uchar * )&ix;
for ( i = 0 ; i < 4 ; i++ ) *( p + i ) = fgetc ( fp );
for ( i = 0 ; i < 4 ; i++ ) fgetc ( fp ); // このxが画像幅 sxは表示幅
// ix→s3は読み込みサイズ(Max80) sx→s2,s4は表示サイズ(byte)
s3 = ( ix + 7 ) / 8;
s2 = ( sx + 7 ) / 8;
s4 = sx & 7;
if ( s3 > 80 ) {
s4 = 0;
s3 = 80;
}
/* s2 = ( sx + 7 ) / 8;
s4 = sx & 7;
if ( s2 > 80 ) {
s3 = 80;
s4 = 0;
} else s3 = s2;
*/
i = xe - xs + 1;
if ( s2 > i ) s2 = i;
flag = fgetc ( fp );
if ( flag ) y2 = y; else y2 = y + sy - 1;
for ( j = 0 ; j < sy ; j++ ) {
for ( k = 0 ; k < 4 ; k++ ) {
fread ( buf[k], s3, 1, fp );
// if ( ini.bmplcd ) buf[k][s3-1] |= b[s4]; // bmplcd時 画像右の余白が15になるのを防ぐ
}
if ( y2 < ys ) {
if ( !flag ) break;
} else if ( y2 > ye ) {
if ( flag ) break;
} else {
if ( ini.bmplcd ) for ( k = 0 ; k < 4 ; k++ ) {
buf[k][s3-1] |= b[s4]; // bmplcd時 画像右の余白が15になるのを防ぐ
}
/* for ( i = 0 ; i < s2 ; i++ ) {
for ( k = 0 ; k < 4 ; k++ ) {
pokeb ( gseg[k], y2 * 80 + i + xs + x / 8, buf[k][i] );
}
}
*/
s = y2 * 80 + /*xs +*/ x / 8;
for ( k = 0 ; k < 4 ; k++ ) {
farp = ( uchar far * ) MK_FP ( gseg[k], s );
p = buf[k];
for ( i = 0 ; i < s2 ; i++ ) {
if ( ini.bmplcd ) *farp = ~(*p);
else *farp = *p;
farp++;
p++;
}
}
}
if ( flag ) y2++; else y2--;
}
fclose ( fp );
return ( 0 );
}
void gb_init ( void ) {
// gd_is5を使う作業はここでは行えない
// gd_is5がiniファイルを読まないと決まらないが
// 初期化を行わないとiniでパレットを読めないため。
// Graphic BIOS
inregs.h.ah = 0x40;
int86 ( 0x18, &inregs, &outregs );
inregs.h.ah = 0x42;
inregs.h.ch = 0xc0;
int86 ( 0x18, &inregs, &outregs );
// Mode Flip Flop 1
/*
outportb ( 0x68, 2 ); // Graphic ColorMode
outportb ( 0x68, 8 ); // Graphic 400Line
outportb ( 0x68, 15 ); // Graphic/Text On
*/
// Mode Flip Flop 2
outportb ( 0x6a, 1 ); // 16 Colors
outportb ( 0x6a, 0x40 ); // CRT Mode
// Text GDC
outportb ( 0x62, 0x0d ); // Text On
// Graphic GDC
// a2 = cmd / a0 = dat
/*
// GGDC sync
gd_cmd ( 0x0e );
gd_dat ( 0x06 );
if ( gd_is5 ) {
gd_dat ( 0x4e );
gd_dat ( 0x07 );
gd_dat ( 0x25 );
gd_dat ( 0x07 );
} else {
gd_dat ( 0x26 );
gd_dat ( 0x03 );
gd_dat ( 0x11 );
gd_dat ( 0x03 );
}
gd_dat ( 0x07 );
gd_dat ( 0x90 );
gd_dat ( 0x65 );
// GGDC zoom=0
gd_cmd ( 0x46 );
gd_dat ( 0x00 );
// GGDC scrool
gd_cmd ( 0x70 );
gd_dat ( 0x00 );
gd_dat ( 0x00 );
gd_dat ( 0x00 );
if ( gd_is5 ) gd_dat ( 0x59 ); else gd_dat ( 0x19 );
// GGDC csrform=0
gd_cmd ( 0x4b );
gd_dat ( 0x00 );
// GGDC pitch
gd_cmd ( 0x47 );
if ( gd_is5 ) gd_dat ( 0x50 ); else gd_dat ( 0x28 );
*/
// GGDC start
gd_cmd ( 0x0d );
// GGDC textw
gd_textw ( 0xff, 0xff );
gb_write ( 0 );
gb_gcls ();
gb_view ( 0 );
gb_loadrgb ( defpalet );
}
void gb_init2 ( void ) {
// GDCクロック自動取得
if ( gd_is5 > 1 ) {
if ( inportb ( 0x31 ) & 0x80 ) gd_is5 = 0; else gd_is5 = 1;
if ( peekb ( 0, 0x54d ) & 4 ) gd_is5 = 1;/* else gd_is5 = 0;*/
}
}
void gb_gdcmode ( uchar m ) {
outportb ( 0x7c, m );
pokeb ( 0, 0x495, m );
}
void gb_gdctile ( uchar t ) {
uint i;
for ( i = 0 ; i < 4 ; i++ ) {
outportb ( 0x7e, t );
pokeb ( 0, 0x496 + i, t );
}
}
void gb_write ( uchar p ) {
outportb ( 0xa6, p & 1 );
}
void gb_view ( uchar p ) {
outportb ( 0xa4, p & 1 );
}
void gb_gcls ( void ) {
uint i;
gb_gdcmode ( 0x80 );
gb_gdctile ( 0 );
for ( i = 0 ; i < 0x8000; i += 2 ) poke ( 0xa800, i, 0 );
gb_gdcmode ( 0 );
}
void gb_gcls2 ( uint y1, uint y2 ) {
uint i;
gb_gdcmode ( 0x80 );
gb_gdctile ( 0 );
for ( i = y1 * 80 ; i < y2 * 80 ; i += 2 ) poke ( 0xa800, i, 0 );
gb_gdcmode ( 0 );
}
void gb_gcls2 ( uint y1, uint y2, uint x1, uint x2 ) {
uint i, j;
gb_gdcmode ( 0x80 );
gb_gdctile ( 0 );
for ( i = y1 * 80 ; i < y2 * 80 ; i += 80 ) {
for ( j = x1 ; j <= x2 ; j++ ) pokeb ( 0xa800, i+j, 0 );
}
gb_gdcmode ( 0 );
}
void gb_loadrgb ( uchar* pbuf ) {
uint i;
for ( i = 0 ; i < 8 ; i++ ) {
outportb ( 0xa8, i );
outportb ( 0xac, *( pbuf + i * 6 + 0 ) );
outportb ( 0xaa, *( pbuf + i * 6 + 1 ) );
outportb ( 0xae, *( pbuf + i * 6 + 2 ) );
outportb ( 0xa8, i + 8 );
outportb ( 0xac, *( pbuf + i * 6 + 3 ) );
outportb ( 0xaa, *( pbuf + i * 6 + 4 ) );
outportb ( 0xae, *( pbuf + i * 6 + 5 ) );
}
}
void gb_pstart ( void ) {
gb_write ( 1 - gb_sw );
}
void gb_pend ( void ) {
gb_sw = 1 - gb_sw;
gb_view ( gb_sw );
}
//void gb_endchg ( void ) {
// gb_write ( 1 - gb_sw );
//}
void gb_waitvsync ( void ) {
int i;
i = 0;
while ( ( inportb ( 0x60 ) & 0x20 ) != 0 ) {
i++;
if ( i > 1000 ) return;
if ( kbhit() ) getch();
}
while ( ( inportb ( 0x60 ) & 0x20 ) == 0 ) if ( kbhit() ) getch();
}
void gd_cmd ( uchar cmd ) {
while ( inportb ( 0xa0 ) & 2 ) outportb ( 0x5f, 0 );
outportb ( 0xa2, cmd );
}
void gd_dat ( uchar dat ) {
while ( inportb ( 0xa0 ) & 2 ) outportb ( 0x5f, 0 );
outportb ( 0xa0, dat );
}
void gd_textw ( uchar dl, uchar dh ) {
gd_cmd ( 0x78 );
gd_dat ( dl );
gd_dat ( dh );
}
void gd_writemode ( uchar mode ) {
gd_cmd ( 0x20 | ( mode & 3 ) );
}
void gd_csrw ( uchar plane, ulong ead, uchar dad ) {
gd_cmd ( 0x49 );
ead |= gd_gseg[plane%4];
gd_dat ( ead & 0xff );
gd_dat ( ( ead >> 8 ) & 0xff );
gd_dat ( ( ( ead >> 16 ) & 3 ) | ( ( dad & 15 ) << 4 ) );
}
void gd_vecte ( void ) {
gd_cmd ( 0x6c );
while ( ( inportb ( 0xa0 ) & 4 ) == 0 ) outportb ( 0x5f, 0 );
}
void gd_waitdraw ( void ) {
while ( ( inportb ( 0xa0 ) & 8 ) != 0 ) outportb ( 0x5f, 0 );
}
void gd_gline ( uint x1, uint y1, uint x2, uint y2, uchar color ) {
uint gx1, gy1, gx2, gy2, zx, zy, i, le;
int dx, dy, t;
uchar p[4] = { 1, 2, 4, 8 }, dir;
ulong l;
if ( ini.isegc ) eg_on ();
if ( x1 <= x2 ) {
gx1 = x1, gy1 = y1;
gx2 = x2, gy2 = y2;
} else {
gx1 = x2, gy1 = y2;
gx2 = x1, gy2 = y1;
}
dx = (int)gx2 - (int)gx1;
dy = (int)gy2 - (int)gy1;
l = (ulong)gx1 + gy1 * 640UL;
if ( dy > dx ) {
dir = 0;
t = dx; dx = dy; dy = t;
} else if ( dy > 0 ) dir = 1;
else if ( dy > -dx ) dir = 2;
else {
dir = 3;
t = dx; dx = dy; dy = t;
}
if ( dx < 0 ) zx = -dx; else zx = dx;
if ( dy < 0 ) zy = -dy; else zy = dy;
if ( eg_ison ) {
if ( color > 15 ) le = 1;
else le = 2;
} else le = 4;
for ( i = 0 ; i < le ; i++ ) {
// gd_waitdraw ();
if ( eg_ison ) {
gd_writemode ( 0 ); // GDCはreplaceモードを使い、重ね合せはEGCにさせる
if ( color > 15 ) {
// 反転
eg_color ( 15 );
eg_operation ( 0x3c );
} else if ( i == 0 ) {
// 描くプレーン
if ( color == 0 ) continue;
eg_color ( color );
eg_operation ( 0xfc );
} else {
// 消すプレーン
if ( color == 15 ) continue;
eg_color ( 15 - color );
eg_operation ( 0x0c );
}
} else {
if ( color > 15 ) gd_writemode ( 1 );
else if ( color & p[i] ) gd_writemode ( 3 );
else gd_writemode ( 2 );
}
// vectw
gd_cmd ( 0x4c );
gd_dat ( 0x08 | dir );
gd_dat ( zx & 255 );
t = ( zx >> 8 ) & 63;
if ( gd_is5 ) t |= 0x40;
gd_dat ( t );
t = 2 * zy - zx;
gd_dat ( t & 255 );
gd_dat ( ( t >> 8 ) & 255 );
t = 2 * zy - 2 * zx;
gd_dat ( t & 255 );
gd_dat ( ( t >> 8 ) & 255 );
t = 2 * zy;
gd_dat ( t & 255 );
gd_dat ( ( t >> 8 ) & 255 );
// csrw
gd_csrw ( i, l >> 4, l & 15 );
// vecte
gd_vecte ();
gd_waitdraw ();
}
// gd_waitdraw ();
if ( ini.isegc ) eg_off ();
else gd_waitdraw ();
}
void eg_init ( void ) {
eg_on ();
eg_color ( 15 );
outport ( 0x4a2, 0x00ff );
// outport ( 0x4a4, 0x0400 );
outport ( 0x4a8, 0xffff );
outport ( 0x4ac, 0x0000 );
outport ( 0x4ae, 0x000f );
eg_off ();
}
void eg_color ( uchar c ) {
uint c1, c2, c3;
uchar a = 0;
if ( eg_ison == 0 ) {
a = 1;
eg_on ();
}
c &= 15;
c1 = c;
c2 = ~(c1 >> 1);
c3 = ~(( c1 & 1 ) << 3);
outport ( 0x4a0, c2 & c3 );
if ( a ) eg_off ();
}
void eg_on ( void ) {
gb_gdcmode ( 0x80 );
outportb ( 0x6a, 0x07 );
outportb ( 0x6a, 0x05 );
eg_ison = 1;
}
void eg_off ( void ) {
gd_waitdraw();
outport ( 0x4a0, 0xfff0 );
outportb ( 0x6a, 0x04 );
outportb ( 0x6a, 0x06 );
gb_gdcmode ( 0 );
eg_ison = 0;
}
void eg_operation ( uchar ope ) {
// R7~R0を直接opeで受ける
uchar a = 0;
if ( eg_ison == 0 ) {
eg_on ();
a = 1;
}
outport ( 0x4a4, 0x0c00 | ope );
if ( a ) eg_off ();
}
void di_initdaua ( void ) {
uchar c;
inregs.h.cl = 0x13;
segread ( &segregs );
segregs.ds = FP_SEG ( di_daua );
inregs.x.dx = FP_OFF ( di_daua );
int86x ( 0xdc, &inregs, &outregs, &segregs );
// RAMドライブ判別
di_noteram[0] = di_noteram[1] = 9;
if ( peekb ( 0, 0x400 ) & 128 ) {
c = peekb ( 0, 0x488 );
if ( c & 128 ) di_noteram[1] = 3;
if ( c & 64 ) di_noteram[1] = 2;
if ( c & 32 ) di_noteram[1] = 1;
if ( c & 16 ) di_noteram[1] = 0;
if ( c & 8 ) di_noteram[0] = 3;
if ( c & 4 ) di_noteram[0] = 2;
if ( c & 2 ) di_noteram[0] = 1;
if ( c & 1 ) di_noteram[0] = 0;
}
}
uchar di_getdaua ( uchar drive ) {
if ( drive > 25 ) return 0;
return ( di_daua[drive*2+0x1b] );
}
uint convhtml ( uchar *cdhname, uchar *headname, uchar *htmlname, uchar &kmode, ulong &cdhx, ulong &cdhy ) {
// 無意味に長いタグへの対応が前版ではできなかった
FILE *cdhfp;
FILE *headfp;
FILE *htmlfp;
FILE *htmlfp2;
ulong flen;
ulong scrx = 640 - 8 * 4;
uchar istext = 0;
struct fnsplit fns;
uint hx;
ulong hy;
uchar ch, ch2;
uint i, j;
uchar ink = 0, inh = 0;
uchar buf[pathmax], buf2[pathmax];
ulong l, fl;
uchar vs = 0;
struct ffblk find;
uint da[6];
neffs = 0;
cdhx = cdhy = 0;
uchar localname[pathmax];
fnsplit2 ( htmlname, &fns );
printf ( "\033[3;1H\033[>5l\r" );
fnmerge3 ( localname, &fns );
printf ( "\033[>5h\033[2J\r" );
// Ver2.10N 変更
if ( ( fns.sw == 0 ) && ( fns.nname[0] == '\0' ) ) {
// フォルダ対象
cdhfp = fopen2 ( cdhname, "w" );
if ( cdhname == NULL ) return ( 1 );
headfp = fopen2 ( headname, "w" );
if ( headname == NULL ) {
fclose ( cdhfp );
return ( 1 );
}
fprintf ( headfp, "F%s\n", htmlname );
fprintf ( cdhfp, "E80,00000000000000000000000000000000000000000000000000000000000000000000000000000000\n" );
fprintf ( cdhfp, "T0,0,現在のフォルダは\n" );
fprintf ( cdhfp, "T0,20,%s\n", htmlname );
fprintf ( cdhfp, "E80,66666666666600000000000000000000000000000000000000000000000000000000000000000000\n" );
l = 60, fl = 0;
strcpy ( buf, htmlname );
strcat ( buf, "*.*" );
i = findfirst ( buf, &find, 0x37 );
while ( i == 0 ) {
if ( ( strcmp ( find.ff_name, "." ) != 0 ) && ( find.ff_name[0] != '$' ) ) {// updir..は必要だがcurdir.は要らない・$temp.cdhなどを指定されるとたいへんなことになる
fl++;
strcpy ( buf2, htmlname );
strcat ( buf2, find.ff_name );
// リンク設定
if ( find.ff_attrib & FA_DIREC ) strcpy ( buf, "\\" ); else buf[0] = '\0';
fprintf ( headfp, "A0,%lu,95,%lu,%s%s\n", l, l + 15, find.ff_name, buf );
// ファイル名・拡張子展開
if ( strcmp ( find.ff_name, ".." ) == 0 ) {
ch2 = ' ';
ch = 2;
} else {
for ( ch2 = 0 ; ch2 < 12 ; ch2++ ) {
// 2byte目が'.'になる漢字はSJISにない
if ( find.ff_name[ch2] == '.' ) {
ch = ch2 + 1;
find.ff_name[ch2] = '\0';
break;
} else if ( find.ff_name[ch2] == '\0' ) {
ch = ch2;
break;
}
}
if ( find.ff_name[ch] == '\0' ) ch2 = ' '; else ch2 = '.';
}
fprintf ( cdhfp, "T0,%lu,%-8.8s%c%-3.3s", l, find.ff_name, ch2, find.ff_name + ch );
if ( find.ff_attrib & FA_DIREC ) {
if ( strcmp ( find.ff_name, ".." ) == 0 ) fprintf ( cdhfp, " (Up Folder)" );
else fprintf ( cdhfp, " (Sub Folder)" );
} else {
sprintf ( buf, "%10ld", find.ff_fsize );
if ( find.ff_fsize >= 1000000000L ) {
buf[20] = buf[21] = buf[22] = ',';
} else if ( find.ff_fsize >= 1000000L ) {
buf[20] = ' ';
buf[21] = buf[22] = ',';
} else if ( find.ff_fsize >= 1000L ) {
buf[20] = buf[21] = ' ';
buf[22] = ',';
} else {
buf[20] = buf[21] = buf[22] = ' ';
}
fprintf ( cdhfp, " %c%c%c%c%c%c%c%c%c%c%c%c%c", buf[0], buf[20], buf[1], buf[2], buf[3], buf[21], buf[4], buf[5], buf[6], buf[22], buf[7], buf[8], buf[9] );
}
for ( j = 0 ; j < 6 ; j++ ) buf[j] = '.';
buf[6] = ' ';
if ( find.ff_attrib & FA_RDONLY ) buf[0] = 'R';
if ( find.ff_attrib & FA_HIDDEN ) buf[1] = 'H';
if ( find.ff_attrib & FA_SYSTEM ) buf[2] = 'S';
if ( find.ff_attrib & FA_ARCH ) buf[3] = 'A';
if ( find.ff_attrib & FA_LABEL ) buf[4] = 'V';
if ( find.ff_attrib & FA_DIREC ) buf[5] = 'D';
da[0] = ( find.ff_fdate >> 9 ) + 1980;
da[1] = ( find.ff_fdate >> 5 ) & 15;
da[2] = find.ff_fdate & 31;
da[3] = find.ff_ftime >> 11;
da[4] = ( find.ff_ftime >> 5 ) & 31;
da[5] = ( find.ff_ftime & 31 ) << 1;
if ( find.ff_attrib & FA_DIREC ) {
buf[7] = '\0';
} else {
maketop ( buf + 7, buf2, find.ff_name + ch, 22 );
}
fprintf ( cdhfp, " %4u/%2u/%2u %2u:%02u:%02u %s\n", da[0], da[1], da[2], da[3], da[4], da[5], buf );
l += 20;
}
i = findnext ( &find );
convhtmlbar ( 0, fl, 0, 3 );
}
l += 20;
fprintf ( cdhfp, "E80,66666666000000000000000000000000000000000000000000000000000000000000000000000000\n" );
for ( i = 0 ; i < 26 ; i++ ) {
ch = di_getdaua ( i );
fprintf ( headfp, "A0,%lu,63,%lu,%c:\\\n", l, l + 15, 'A' + i );
fprintf ( cdhfp, "T0,%lu,Drive %c: (%02X)", l, 'A' + i, ch );
ch2 = ch & 15;
switch ( ch >> 4 ) {
case 1:
if ( ch2 == di_noteram[0] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 1.2MB/640KB\n" );
break;
case 2:
fprintf ( cdhfp, " SCSI\n" );
break;
case 3:
if ( ch2 == di_noteram[0] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 1.2MB/1.44MB\n" );
break;
case 4:
fprintf ( cdhfp, " RAM\n" );
break;
case 5:
fprintf ( cdhfp, " FDD 320KB\n" );
break;
case 6:
fprintf ( cdhfp, " Net BRANCH4670\n" );
break;
case 7:
if ( ch2 == di_noteram[1] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 640KB\n" );
break;
case 8:
fprintf ( cdhfp, " SASI/IDE\n" );
break;
case 9:
if ( ch2 == di_noteram[0] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 1.2MB\n" );
break;
case 10:
fprintf ( cdhfp, " SCSI\n" );
break;
case 11:
if ( ch2 == di_noteram[0] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 1.2MB/1.44MB\n" );
break;
case 12:
fprintf ( cdhfp, " SCSI\n" );
break;
case 13:
fprintf ( cdhfp, " ROM\n" );
break;
case 14:
fprintf ( cdhfp, " RAM\n" );
break;
case 15:
if ( ch2 == di_noteram[1] ) fprintf ( cdhfp, " (RAM)" );
fprintf ( cdhfp, " FDD 640KB/1.2MB\n" );
break;
case 0:
default:
fprintf ( cdhfp, " Unknown\n" );
break;
}
l += 20;
fl++;
convhtmlbar ( 0, fl, 0, 3 );
}
fprintf ( headfp, "Y%lu\n", l );
fclose ( headfp );
fclose ( cdhfp );
cdhx = 8 * ( 80 - 5 );
cdhy = l;
return ( 0 );
}
// これ以降はファイルが対象
// 開けるか
htmlfp2 = fopen2 ( localname, "rb" );
if ( htmlfp2 == NULL ) {
cdhfp = fopen2 ( cdhname, "w" );
if ( cdhname == NULL ) return ( 1 );
headfp = fopen2 ( headname, "w" );
if ( headname == NULL ) {
fclose ( cdhfp );
return ( 1 );
}
fprintf ( headfp, "F%s\n", htmlname );
fprintf ( cdhfp, "E000000000000000000000000\n" );
fprintf ( cdhfp, "T0,0,ファイルが見つかりません\n" );
i = 13*8;
j = 20;
fprintf ( headfp, "Y%u\n", (uint)j );
fclose ( headfp );
fclose ( cdhfp );
cdhx = i, cdhy = j;
return ( 2 );
}
fclose ( htmlfp2 );
if ( ( stricmp ( fns.ext, ".bmp" ) == 0 ) || ( stricmp ( fns.ext, ".jpg" ) == 0 ) || ( stricmp ( fns.ext, ".png" ) == 0 ) || ( stricmp ( fns.ext, ".gif" ) == 0 ) ){
// 画像のネット対応はここもいじること
cdhfp = fopen2 ( cdhname, "w" );
if ( cdhname == NULL ) return ( 1 );
headfp = fopen2 ( headname, "w" );
if ( headname == NULL ) {
fclose ( cdhfp );
return ( 1 );
}
strcpy ( buf2, "$temp.pat" );
dr_settempdir ( buf2 );
if ( bm_convbmp ( buf, localname, i, j, buf2 ) != 0 ) {
fprintf ( headfp, "F%s\n", htmlname );
fprintf ( cdhfp, "E00000000000000000000\n" );
fprintf ( cdhfp, "T0,0,画像を読み込めません\n" );
j = 20;
fprintf ( headfp, "Y%u\n", (uint)j );
fclose ( headfp );
fclose ( cdhfp );
return ( 1 );
}
fprintf ( headfp, "F%s\n", htmlname );
fprintf ( cdhfp, "G0,0,%u,%u,%s\n", i, j, buf );
fprintf ( headfp, "TImage %ux%u\n", i, j );
fprintf ( headfp, "Y%u\n", j );
fclose ( headfp );
fclose ( cdhfp );
cdhx = i, cdhy = j;
return ( 0 );
}
htmlfp2 = fopen2 ( localname, "rb" );
if ( htmlfp2 == NULL ) return ( 1 );
strcpy ( buf, "$temp.htm" );
dr_settempdir ( buf );
htmlfp = fopen2 ( buf, "wb" );
if ( htmlfp == NULL ) {
fclose ( htmlfp2 );
return ( 1 );
}
// ファイルかフォルダかの判定で既にfnsに入っている
// 1文字読んでみてHTML判別
// '<'で始まるか.htmか.shtかならばHTMLとして扱う
istext = 1;
if ( stricmp ( fns.ext, ".htm" ) == 0 ) istext = 0;
if ( stricmp ( fns.ext, ".sht" ) == 0 ) istext = 0;
ch = fgetc ( htmlfp2 );
if ( ch == '<' ) istext = 0;
ungetc ( ch, htmlfp2 );
// 漢字コード切り替え(kmodeがautoでない場合はそのまま通過)
// 判定
while ( ( !feof ( htmlfp2 ) ) && ( kmode == ft_km_auto ) ) {
ch = fgetc ( htmlfp2 );
if ( ( ch >= 0x81 ) && ( ch <= 0xa0 ) ) {
ch2 = fgetc ( htmlfp2 );
switch ( ch ) {
case 0x8e:
if ( ( ch2 <= 0xa0 ) || ( ch2 >= 0xe0 ) ) kmode = ft_km_sjis;
break;
case 0x8f:
if ( ( ch2 <= 0xa0 ) || ( ch2 == 0xff ) ) kmode = ft_km_sjis;
else if ( ( ch2 == 0xfd ) || ( ch2 == 0xfe ) ) kmode = ft_km_eucjp;
break;
default:
kmode = ft_km_sjis;
break;
}
} else if ( ( ch >= 0xa1 ) && ( ch <= 0xdf ) ) {
ch2 = fgetc ( htmlfp2 );
if ( ch2 <= 0xa0 ) kmode = ft_km_sjis;
else if ( ( ( ch2 >= 0xf0 ) && ( ch2 <= 0xf9 ) ) || ( ch2 >= 0xfb ) ) kmode = ft_km_eucjp;
} else if ( ( ( ch >= 0xe0 ) && ( ch <= 0xef ) ) || ( ch == 0xfa ) ) {
ch2 = fgetc ( htmlfp2 );
if ( ch2 <= 0xa0 ) kmode = ft_km_sjis;
else if ( ch2 >= 0xfd ) kmode = ft_km_eucjp;
} else if ( ch == 0x1b ) {
kmode = ft_km_sjis; // JISはSJIS扱いに含める
}
}
/*
switch ( kmode ) {
case ft_km_auto: printf ( "Kanji : None\r" );break;
case ft_km_sjis: printf ( "Kanji : JIS or MS\r" );break;
case ft_km_eucjp: printf ( "Kanji : EUC-JP\r" );break;
}
*/
if ( kmode == ft_km_auto ) kmode = ft_km_sjis;
// 変換
fseek ( htmlfp2, 0, SEEK_SET );
fl = filelength ( fileno ( htmlfp2 ) );
l = 0, vs = 0;
while ( !feof ( htmlfp2 ) ) {
ch = fgetc ( htmlfp2 );
l++;
switch ( ch ) {
case 0x1b:
ch2 = fgetc ( htmlfp2 );
l++;
switch ( ch2 ) {
case 0x24:
ink = 1;
break;
case 0x28:
ink = 0;
break;
}
fgetc ( htmlfp2 );
l++;
break;
case 0x0e:
inh = 1;
break;
case 0x0f:
inh = 0;
break;
default:
if ( ( ch == '\n' ) || ( ch == '\r' ) ) fputc ( ch, htmlfp );
else if ( ch == '\t' ) {
if ( istext ) fputc ( ' ', htmlfp );
else fputc ( '\t', htmlfp );
} else if ( ch < ' ' ) {
fputc ( '^', htmlfp );
fputc ( ch + 0x40, htmlfp );
}
else if ( ink ) {
// JIS漢字
ch2 = fgetc ( htmlfp2 );
l++;
i = jistojms ( ch * 256U + ch2 );
if ( i != 0 ) {
fputc ( i >> 8, htmlfp );
fputc ( i & 255, htmlfp );
}
} else if ( inh ) {
// JIS半角カナ
fputc ( ( ch & 127 ) + 0xa0 - 0x20, htmlfp );
} else if ( kmode == ft_km_eucjp ) {
// EUC
if ( ch == 0x8e ) {
ch2 = fgetc ( htmlfp2 );
l++;
fputc ( ch2, htmlfp );
} else if ( ch == 0x8f ) {
// getのみ
} else if ( ch >= 0xa1 ) {
ch2 = fgetc ( htmlfp2 );
l++;
ch &= 127;
ch2 &= 127;
i = jistojms ( ch * 256U + ch2 );
if ( i != 0 ) {
fputc ( i >> 8, htmlfp );
fputc ( i & 255, htmlfp );
}
} else {
fputc ( ch, htmlfp );
}
} else {
// SJIS
if ( ( ( ch >= 0x81 ) && ( ch <= 0x9f ) ) || ( ch >= 0xe0 ) ) {
ch2 = fgetc ( htmlfp2 );
l++;
if ( iskanji2 ( ch2 ) ) {
fputc ( ch, htmlfp );
fputc ( ch2, htmlfp );
}
} else {
fputc ( ch, htmlfp );
}
}
break;
}
vs++;
if ( ( vs % 100 ) == 0 ) {
vs = 0;
convhtmlbar ( 0, l, fl, 2 );
}
}
fclose ( htmlfp );
fclose ( htmlfp2 );
strcpy ( buf, "$temp.htm" );
dr_settempdir ( buf );
htmlfp = fopen2 ( buf, "rb" );
if ( htmlfp == NULL ) return ( 1 );
flen = filelength ( fileno ( htmlfp ) );
cdhfp = fopen2 ( cdhname, "w" );
if ( cdhname == NULL ) {
fclose ( htmlfp );
return ( 1 );
}
headfp = fopen2 ( headname, "w" );
if ( headname == NULL ) {
fclose ( htmlfp );
fclose ( cdhfp );
return ( 1 );
}
fprintf ( headfp, "F%s\n", htmlname );
convhtml2 ( cdhfp, headfp, htmlfp, flen, &scrx, 0, &hx, &hy, istext, htmlname );
cdhx = hx, cdhy = hy;
fprintf ( headfp, "Y%lu\n", hy );
fclose ( headfp );
fclose ( cdhfp );
fclose ( htmlfp );
return ( 0 );
}
void convhtml2 ( FILE *cdhtmlfp, FILE *headerfp, FILE *htmlfp, ulong length, ulong *xl, uint tdepth, uint *hx, ulong *hy, uchar istext, uchar *chname ) {
uchar vsw = 0, vsw2 = 0;
ulong c = 0,/* l,*/ l2;
uint i, j[10];
uchar ch, ch2;
uchar *p;
uint f, g;
int in;
FILE *cdhfp;
FILE *headfp;
FILE *tablefp;
ulong cellx[40];
cellx[0] = xl[0];
cdhfp = cdhtmlfp, headfp = headerfp; // tableでは一旦別のfpに書いてそれを読むのでこうする
tablefp = NULL; // tableタグのないtd,thを無視できるように
// タグ処理
enum { tagpmax = 20, retl = 20 };
uchar tagbuf[1000], tagbuf2[1000], cbuf[4];
uchar *tagp[tagpmax][2];
uchar tagn = '\0';
uint ntagl = 0, ntagp = 0;
uint neff = 0; // tableタグを超えたエフェクト伝達はないのでローカルでよい
uchar tralign = tx_align_l; // trタグでのalign
uint ttx, tpx, tpx2, tbx;
ulong tty, tty2, tpy, tpy2;
uint ntd = 0, ntr = 0;
uchar taddbuf[200];
uchar *tap;
ulong sy2;
uchar inbody, inpre = istext, intitle = 0, incaption = 0, inspace = 0;
uchar title[200];
uint titlelen = 0;
uint inblock = 0, indd = 0, inlist = 0;
uint osx = 0, oex = xl[0];
struct fnsplit fns;
// テーブル再帰処理
struct tx tx;
tx.align = tx_align_l;
uchar tableborder = 0;
fpos_t fpt, tablestart, tableend, startp;
fgetpos ( htmlfp, &startp );
uint ntable; // tdepthとは別にすることで/tableを検出する 今回処理するのはntable=1の部分
if ( tdepth > 0 ) {
ntable = 0; // table処理中なら最初のtableは書式設定のため すぐにntable=0→1となるはず
inbody = 1;
} else {
ntable = 1;
// inbody = 0;
inbody = 1;
}
// タグ代替テキスト用
uchar tagtext[20];
*hx = 0;
*hy = 0;
tx_init ( &tx, xl[0] );
ch2 = '\0';
while ( c < length ) {
ch = fgetc ( htmlfp );
if ( feof ( htmlfp ) ) break;
if ( ( !istext ) && ( ch == '<' ) ) {
ntagl = 0, ntagp = 0;
fgetpos ( htmlfp, &fpt );
// >まで読んでみて、-->でなかったら-->が出るまで読み飛ばす
// <!-- <tag> <tag> -->
// ↑から ↑までさらに読み飛ばすということ
// タグ内容を読み込む
ch = fgetc ( htmlfp ); // <は読み捨てる
c++;
while ( ( c < length ) && ( ch != '>' ) && ( !feof ( htmlfp ) ) ) {
tagbuf[ntagl] = ch;
ntagl++;
ch = fgetc ( htmlfp );
c++; // >も読み捨てる
}
tagbuf[ntagl] = '\0';
// タグ内容を分割する
p = tagbuf;
f = 1 , ntagp = 0; // "内部ならf=0
while ( ( ntagp < tagpmax ) && ( *p != '\0' ) ) {
if ( iskanji ( *p ) ) {
p += 2;
if ( *( p - 1 ) == '\0' ) p--;
} else {
switch ( *p ) {
case '"':
strcpy ( tagbuf2, p + 1 );
strcpy ( p, tagbuf2 );
f = 1 - f;
p--; // "のぶんがなくなったのでpは移動しない
break;
case ' ':
case '\r':
case '\n':
if ( f ) {
*p = '\0';
tagp[ntagp][0] = p + 1;
tagp[ntagp][1] = &tagn;
ntagp++;
}
break;
case '=':
// align=left=toだと、
// 「align」=「left=to」になる
if ( ( f ) && ( tagp[ntagp-1][1] == &tagn ) ) {
*p = '\0';
tagp[ntagp-1][1] = p + 1;
}
break;
default:
break;
}
p++;
}
}
// for debug
// タグ内容の表示
//printf ( "%s\n", tagbuf );
//for ( i = 0 ; i < ntagp ; i++ ) printf ( " %s = %s\n", tagp[i][0], tagp[i][1] );
// タグ命令の判別
if ( strncmp ( tagbuf, "!--", 3 ) == 0 ) {
// コメント
// -->でなければさらに読み飛ばす
//printf ( "........comment detected.\n" );
// 最終3文字を読む
cbuf[0] = tagbuf[ntagl-2];
cbuf[1] = tagbuf[ntagl-1];
cbuf[2] = '>';
cbuf[3] = '\0';
// -->になるまで読みとばす
while ( ( c < length ) && ( stricmp ( cbuf, "-->" ) != 0 ) ) {
cbuf[0] = cbuf[1];
cbuf[1] = cbuf[2];
cbuf[2] = fgetc ( htmlfp );
c++;
}
}
// 表関連
if ( stricmp ( tagbuf, "table" ) == 0 ) {
switch ( ntable ) {
case 0:
// table処理中 現在のtableの書式
break;
case 1:
// 新規処理table 範囲開始
tx_empreturn ( &tx, cdhfp, headfp, retl ); // /tableで書き込みがあるので行の途中では困る
tablestart = fpt - 1; // tableタグ開始地点を起点にするのでfptが必要
tableborder = 0;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "border" ) == 0 ) {
if ( stricmp ( tagp[i][1], "0" ) == 0 ) tableborder = 0;
else tableborder = 1;
}
}
break;
default:
// 処理開始table内のtable 再帰内で処理
break;
}
ntable++;
}
if ( stricmp ( tagbuf, "/table" ) == 0 ) {
if ( ntable > 0 ) ntable--;
switch ( ntable ) {
case 1:
// table範囲終了・再帰
fgetpos ( htmlfp, &tableend );
// <table> </table>
//↑start ↑end
fpt = tableend - tablestart; // 再読み込み範囲となる
tdepth++;
sprintf ( tagbuf, "%s$table%02u.cdh", tempdir, tdepth );
cdhfp = fopen2 ( tagbuf, "w" );
sprintf ( tagbuf, "%s$table%02u.hdr", tempdir, tdepth );
headfp = fopen2 ( tagbuf, "w" );
if ( ( cdhfp != NULL ) && ( headfp != NULL ) ) {
// 第1回再帰呼び出し
for ( i = 0 ; i < 40 ; i++ ) cellx[i] = xl[ntd]- inblock - indd - inlist;
fsetpos ( htmlfp, &tablestart );
convhtml2 ( cdhfp, headfp, htmlfp, fpt, cellx, tdepth, &ttx, &tty, istext, chname );
fclose ( cdhfp );
fclose ( headfp );
// 幅計算
sprintf ( tagbuf, "%s$table%02u.cdh", tempdir, tdepth );
tablefp = fopen2 ( tagbuf, "r" );
for ( i = 0 ; i < 40 ; i++ ) cellx[i] = 0;
while ( !feof ( tablefp ) ) {
taddbuf[0] = '\0';
fgets ( taddbuf, 200, tablefp );
switch ( taddbuf[0] ) {
case 'C':
sscanf ( &taddbuf[1], "%u,%u,%u", &j[0], &j[1], &j[2] ); // 横幅は640を超えないのでuintでよい
if ( cellx[j[0]] < j[2] ) cellx[j[0]] = j[2];
}
}
fclose ( tablefp );
//for ( i = 1 ; i < 15 ; i++ ) printf ( "%3u ", cellx[i] );
//printf ( "\n" );
// 横幅の数をj[4]に
// 許容横幅はxl[ntd]- inblock - indd - inlist -j[4]*8-8になる
j[4] = 0;
for ( i = 1 ; i < 40 ; i++ ) if ( cellx[i] > 0 ) j[4] = i;
// 幅の合計をj[3]に
j[3] = 0;
for ( i = 1 ; i < 40 ; i++ ) j[3] += cellx[i];
// 幅の最大をj[5]に
j[5] = 0;
for ( i = 1 ; i < 40 ; i++ ) if ( cellx[i] > j[5] ) j[5] = cellx[i];
// 幅を調節する
j[6] = j[5];
while ( ( j[3] > xl[ntd] - inblock - indd - inlist- j[4] * 8 - 8 ) && ( j[6] > 16 ) ) {
for ( i = 1 ; i < 40 ; i++ ) if ( cellx[i] == j[6] ) {
cellx[i] -= 8;
j[3] -= 8;
}
j[6] -= 8;
}
//for ( i = 1 ; i < 15 ; i++ ) printf ( "%3u ", cellx[i] );
//printf ( "\n" );
// 右端のことを考えて補正する(間違ってこの追加分に入っても罫線とだぶるだけで隣には行かない)
//中止for ( i = 1 ; i < 40 ; i++ ) cellx[i] += 8;
sprintf ( tagbuf, "%s$table%02u.cdh", tempdir, tdepth );
cdhfp = fopen2 ( tagbuf, "w" );
sprintf ( tagbuf, "%s$table%02u.hdr", tempdir, tdepth );
headfp = fopen2 ( tagbuf, "w" );
// 第2回再帰呼び出し
fsetpos ( htmlfp, &tablestart );
convhtml2 ( cdhfp, headfp, htmlfp, fpt, cellx, tdepth, &ttx, &tty, istext, chname );
fclose ( cdhfp );
fclose ( headfp );
cdhfp = cdhtmlfp;
headfp = headerfp;
// cellxを幅からx座標にする(cellx[f-1]で使う)
cellx[0] = 8;
for ( i = 1 ; i < 40 ; i++ ) {
cellx[i] += cellx[i-1];
cellx[i] += 8;
}
// 表の左端x座標を決める
// 表の幅はcellx[j[4]]にある
//if ( stricmp ( tagp[i][1], "right" ) == 0 ) tx.align = tx_align_r;
//else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tx.align = tx_align_c;
//else tx.align = tx_align_l;
switch ( tx.align ) {
case tx_align_r:
if ( tx.ex < cellx[j[4]] ) tbx = 0;
else tbx = tx.ex - cellx[j[4]];
break;
case tx_align_c:
if ( tx.sx + tx.ex < cellx[j[4]] ) tbx = 0;
else tbx = ( tx.sx + tx.ex - cellx[j[4]] ) / 2;
break;
default:
tbx = tx.sx;
break;
}
// tablefpを使って書き込み 11,12,21,22,23という場合にも備えなければならない
sprintf ( tagbuf, "%s$table%02u.cdh", tempdir, tdepth );
tablefp = fopen2 ( tagbuf, "r" );
f = g = 0, tty = 0, j[6] = 0;
// l = ftell ( tablefp );
sy2 = tx.sy;
if ( tableborder ) {
fprintf ( cdhfp, "L%lu,%lu,%lu,%lu\n",(ulong)tbx+cellx[0]-5, tx.sy+2, (ulong)tbx+cellx[j[4]]-5, tx.sy+2 );
}
if ( tablefp != NULL ) while ( !feof ( tablefp ) ) {
taddbuf[0] = '\0';
fgets ( taddbuf, 200, tablefp );
switch ( taddbuf[0] ) {
case 'C':
// セルの終了
sscanf ( &taddbuf[1], "%u,%u,%u,%lu", &j[0], &j[1], &j[2], &tty2 );
//if ( j[6] ) {
// 2回目
if ( tty < tty2 ) tty = tty2;
// l = ftell ( tablefp );
// j[6] = 0;
break;
case 'S':
// セルの開始
sscanf ( &taddbuf[1], "%u,%u", &j[0], &j[1] );
//} else {
// 1回目(場所を記録)
if ( g != j[1] ) {
// 罫線(表が2行以上の場合の中央)
if ( ( tableborder ) && ( tty > 0 ) ) {
fprintf ( cdhfp, "L%lu,%lu,%lu,%lu\n", (ulong)tbx+cellx[0]-5, tx.sy + tty + 2, (ulong)tbx+cellx[j[4]]-5, tx.sy + tty + 2 );
}
// 次の行
tx.sy += tty + 8;
tty = 0;
}
f = j[0], g = j[1];
// fseek ( tablefp, l, SEEK_SET );
// j[6] = 1;
//}
break;
case 'T':
// Txx,yy,str
//if ( j[6] ) {
// 2回目のみ
sscanf ( &taddbuf[1], "%u,%lu", &tpx, &tpy );
tap = &taddbuf[1];
for ( i = 0 ; i < 2 ; i++ ) {
while ( *tap != ',' ) tap++;
tap++;
}
fprintf ( cdhfp, "T%lu,%lu,%s", (ulong)(tbx + cellx[f-1] + tpx), (ulong)(tx.sy + tpy), tap );
//}
break;
case 'L':
// Txx,yy,xx,yy
//if ( j[6] ) {
// 2回目のみ
sscanf ( &taddbuf[1], "%u,%lu,%u,%lu", &tpx, &tpy, &tpx2, &tpy2 );
/* tap = &taddbuf[1];
for ( i = 0 ; i < 2 ; i++ ) {
while ( *tap != ',' ) tap++;
tap++;
}
*/
fprintf ( cdhfp, "L%lu,%lu,%lu,%lu\n", (ulong)(tbx + cellx[f-1] + tpx), (ulong)(tx.sy + tpy), (ulong)(tbx + cellx[f-1] + tpx2), (ulong)(tx.sy + tpy2) );
//}
break;
case 'G':
sscanf ( &taddbuf[1], "%u,%lu,%u,%lu", &tpx, &tpy, &tpx2, &tpy2 );
tap = &taddbuf[1];
for ( i = 0 ; i < 4 ; i++ ) {
while ( *tap != ',' ) tap++;
tap++;
}
if ( tpx2 > cellx[f] - cellx[f-1] - 8 ) tpx2 = cellx[f] - cellx[f-1] - 8; // 表の幅より大きい画像は右カット
fprintf ( cdhfp, "G%lu,%lu,%lu,%lu,%s\n", (ulong)(tbx + cellx[f-1] + tpx), (ulong)(tx.sy + tpy), (ulong)(tpx2), (ulong)(tpy2), tap );
break;
default:
// Eなど
//if ( j[6] ) {
fputs ( taddbuf, cdhfp );
//}
break;
}
}
fclose ( tablefp );
if ( tableborder ) {
tx.sy += tty + 2;
fprintf ( cdhfp, "L%lu,%lu,%lu,%lu\n",(ulong)tbx+cellx[0]-5, tx.sy, (ulong)tbx+cellx[j[4]]-5, tx.sy ); // 下のforを見てもわかるように0~j[4](ntd~ではない)
for ( i = 0 ; i <= j[4] ; i++ ) {
fprintf ( cdhfp, "L%lu,%lu,%lu,%lu\n", (ulong)tbx+cellx[i]-5 , sy2+2, (ulong)tbx+cellx[i]-5, tx.sy );
}
}
tx.sy = sy2;
sprintf ( tagbuf, "%s$table%02u.hdr", tempdir, tdepth );
tablefp = fopen2 ( tagbuf, "r" );
f = g = 0, tty = 0, j[6] = 0;
//l = ftell ( tablefp );
if ( tablefp != NULL ) while ( !feof ( tablefp ) ) {
taddbuf[0] = '\0';
fgets ( taddbuf, 200, tablefp );
switch ( taddbuf[0] ) {
case 'C':
sscanf ( &taddbuf[1], "%u,%u,%u,%lu", &j[0], &j[1], &j[2], &tty2 );
//if ( j[6] ) {
// 2回目
if ( tty < tty2 ) tty = tty2;
// l = ftell ( tablefp );
// j[6] = 0;
case 'S':
sscanf ( &taddbuf[1], "%u,%u", &j[0], &j[1] );
//} else {
// 1回目(場所を記録)
if ( g != j[1] ) {
// 次の行
tx.sy += tty + 8;
tty = 0;
}
f = j[0], g = j[1];
// fseek ( tablefp, l, SEEK_SET );
// j[6] = 1;
//}
break;
case 'A':
// Axx,yy,xx,yy,str
//if ( j[6] ) {
// 2回目のみ
sscanf ( &taddbuf[1], "%u,%lu,%u,%lu", &tpx, &tpy, &tpx2, &tpy2 );
tap = &taddbuf[1];
for ( i = 0 ; i < 4 ; i++ ) {
while ( *tap != ',' ) tap++;
tap++;
}
fprintf ( headfp, "A%lu,%lu,%lu,%lu,%s", (ulong)(tbx + cellx[f-1] + tpx), (ulong)(tx.sy + tpy), (ulong)(tbx + cellx[f-1] + tpx2), (ulong)(tx.sy + tpy2), tap );
//}
break;
case 'N':
// Add Ver2.10
// Nyy,str
sscanf ( &taddbuf[1], "%lu", &tpy );
tap = &taddbuf[1];
for ( i = 0 ; i < 1 ; i++ ) {
while ( *tap != ',' ) tap++;
tap++;
}
fprintf ( headfp, "N%lu,%s", (ulong)(tx.sy + tpy), tap );
break;
default:
// Xなど
//if ( j[6] ) {
fputs ( taddbuf, headfp );
//}
break;
}
}
fclose ( tablefp );
tx.sy += tty + 8;
if ( tx.maxx < cellx[j[4]] /8 ) tx.maxx = cellx[j[4]] /8;
if ( tx.maxy < tx.sy ) tx.maxy = tx.sy;
} else {
cdhfp = cdhtmlfp;
headfp = headerfp;
}
tdepth--;
fsetpos ( htmlfp, &tableend );
break;
case 0:
// 表の最後のセルはここで
if ( ( ntd > 0 ) && ( ntr > 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
fprintf ( cdhfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
fprintf ( headfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
}
// ここまでで書き終える そしてcase1:の再帰後へ
}
}
if ( ntable == 1 ) {
if ( ( stricmp ( tagbuf, "td" ) == 0 ) || ( stricmp ( tagbuf, "th" ) == 0 ) ) {
if ( stricmp ( tagbuf, "th" ) == 0 ) {
he_addeff ( 1, ft_ef_b );
//neff |= ft_ef_b;
} else {
he_endeff ( 1 ); // tdの開始ということはthの終了としてよい
// neff &= ~ft_ef_b;
}
tx.align = tralign;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) tx.align = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tx.align = tx_align_c;
else tx.align = tx_align_l;
}
}
if ( ( ntd > 0 ) && ( ntr > 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
fprintf ( cdhfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
fprintf ( headfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
}
ntd++;
oex = xl[ntd]- inblock - indd - inlist;
if ( ntr > 0 ) {
fprintf ( cdhfp, "S%u,%u\n", ntd, ntr );
fprintf ( headfp, "S%u,%u\n", ntd, ntr );
}
tx_init ( &tx, xl[ntd] - inblock - indd - inlist);
}
if ( stricmp ( tagbuf, "tr" ) == 0 ) {
// 行の最後のセルはここで(tr後のtdではもうntd,ntrが変わっている)
tralign = tx_align_l;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) tralign = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tralign = tx_align_c;
else tralign = tx_align_l;
}
}
if ( ( ntd > 0 ) && ( ntr > 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
fprintf ( cdhfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
fprintf ( headfp, "C%u,%u,%lu,%lu\n", ntd, ntr, (ulong)tx.maxx*8UL, (ulong)tx.maxy );
}
ntr++;
ntd = 0;
oex = xl[ntd]- inblock - indd - inlist;
tx_init ( &tx, xl[ntd] - inblock - indd - inlist );
}
if ( stricmp ( tagbuf, "caption" ) == 0 ) incaption = 1;
if ( stricmp ( tagbuf, "/caption" ) == 0 ) incaption = 0;
}
// style内は書かないようにする
// body内を書くよりもstyleとscriptを書かない方がよいらしい
// if ( stricmp ( tagbuf, "body" ) == 0 ) inbody = 1;
// if ( stricmp ( tagbuf, "/body" ) == 0 ) inbody = 0;
if ( stricmp ( tagbuf, "style" ) == 0 ) inbody = 0;
if ( stricmp ( tagbuf, "/style" ) == 0 ) inbody = 1;
if ( stricmp ( tagbuf, "script" ) == 0 ) inbody = 0;
if ( stricmp ( tagbuf, "/script" ) == 0 ) inbody = 1;
if ( ( inbody ) && ( ntable < 2 ) ) { // これ以後はtable内の仮読み中には感知されないようにする
if ( stricmp ( tagbuf, "title" ) == 0 ) {
intitle = 1;
titlelen = 0;
inspace = 2;
}
if ( stricmp ( tagbuf, "/title" ) == 0 ) {
intitle = 0;
title[titlelen] = '\0';
fprintf ( headfp, "T%s\n", title );
inspace = 2;
}
// 改行コードのBR化・無視
if ( stricmp ( tagbuf, "pre" ) == 0 ) inpre = 1;
if ( stricmp ( tagbuf, "/pre" ) == 0 ) inpre = 0;
if ( stricmp ( tagbuf, "xmp" ) == 0 ) inpre = 1;
if ( stricmp ( tagbuf, "/xmp" ) == 0 ) inpre = 0;
if ( stricmp ( tagbuf, "listing" ) == 0 ) inpre = 1;
if ( stricmp ( tagbuf, "/listing" ) == 0 ) inpre = 0;
// テキスト効果(neff関連)
if ( stricmp ( tagbuf, "i" ) == 0 ) he_addeff ( 2, ft_ef_i ); //neff |= ft_ef_i;
if ( stricmp ( tagbuf, "/i" ) == 0 ) he_endeff ( 2 );//neff &= ~ft_ef_i;
if ( stricmp ( tagbuf, "em" ) == 0 ) he_addeff ( 3, ft_ef_i );//neff |= ft_ef_i;
if ( stricmp ( tagbuf, "/em" ) == 0 ) he_endeff ( 3 );//neff &= ~ft_ef_i;
if ( stricmp ( tagbuf, "cite" ) == 0 ) he_addeff ( 4, ft_ef_i );//neff |= ft_ef_i;
if ( stricmp ( tagbuf, "/cite" ) == 0 ) he_endeff ( 4 );//neff &= ~ft_ef_i;
if ( stricmp ( tagbuf, "u" ) == 0 ) he_addeff ( 5, ft_ef_u );//neff |= ft_ef_u;
if ( stricmp ( tagbuf, "/u" ) == 0 ) he_endeff ( 5 );//neff &= ~ft_ef_u;
if ( stricmp ( tagbuf, "s" ) == 0 ) he_addeff ( 6, ft_ef_s );//neff |= ft_ef_s;
if ( stricmp ( tagbuf, "/s" ) == 0 ) he_endeff ( 6 );//neff &= ~ft_ef_s;
if ( stricmp ( tagbuf, "b" ) == 0 ) he_addeff ( 7, ft_ef_b );//neff |= ft_ef_b;
if ( stricmp ( tagbuf, "/b" ) == 0 ) he_endeff ( 7 );//neff &= ~ft_ef_b;
if ( stricmp ( tagbuf, "strong" ) == 0 ) he_addeff ( 8, ft_ef_b );//neff |= ft_ef_b;
if ( stricmp ( tagbuf, "/strong" ) == 0 ) he_endeff ( 8 );//neff &= ~ft_ef_b;
if ( ( ( tagbuf[0] == 'h' ) || ( tagbuf[0] == 'H' ) ) && ( tagbuf[1] > '0' ) && ( tagbuf[1] < '7' ) && ( tagbuf[2] == '\0' ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
he_addeff ( 9, ft_ef_b );
//neff |= ft_ef_b;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) tx.align = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tx.align = tx_align_c;
else tx.align = tx_align_l;
}
}
}
if ( ( tagbuf[0] == '/' ) && ( ( tagbuf[1] == 'h' ) || ( tagbuf[1] == 'H' ) ) && ( tagbuf[2] > '0' ) && ( tagbuf[2] < '7' ) && ( tagbuf[3] == '\0' ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
he_endeff ( 9 );
//neff &= ~ft_ef_b;
tx.align = tx_align_l;
}
if ( stricmp ( tagbuf, "font" ) == 0 ) {
f = 0;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "size" ) == 0 ) {
in = atoi ( tagp[i][1] );
// +1,-1(4,2)は特殊効果なしとする
if ( in < -1 ) {
// 相対マイナス指定 -2~-7
f = ft_ef_h;
} else if ( in > 0 ) {
if ( tagp[i][1][0] == '+' ) {
// 相対プラス指定 +2~+7
if ( in > 1 ) f = ft_ef_b;
} else {
// 絶対指定 1~7
switch ( in ) {
case 1:
f = ft_ef_h;
break;
case 5: case 6: case 7:
f = ft_ef_b;
break;
}
}
}
}
}
he_addeff ( 10, f );
}
if ( stricmp ( tagbuf, "/font" ) == 0 ) {
he_endeff ( 10 );
}
// リンク
if ( stricmp ( tagbuf, "a" ) == 0 ) {
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "href" ) == 0 ) {
tx_setlink ( &tx, headfp, tagp[i][1] );
he_addeff ( 11, ft_ef_u );
//neff |= ft_ef_u;
}
if ( stricmp ( tagp[i][0], "name" ) == 0 ) {
fprintf ( headfp, "N%lu,%s\n", tx.sy, tagp[i][1] );
}
}
}
if ( stricmp ( tagbuf, "/a" ) == 0 ) {
tx_setlink ( &tx, headfp, "" );
he_endeff ( 11 );
//neff &= ~ft_ef_u;
linkto[0] = '\0';
}
if ( stricmp ( tagbuf, "frame" ) == 0 ) {
f = ntagp, g = ntagp;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "src" ) == 0 ) {
f = i;
} else if ( stricmp ( tagp[i][0], "name" ) == 0 ) {
g = i;
}
}
if ( f != ntagp ) {
tx_setlink ( &tx, headfp, tagp[f][1] );
he_addeff ( 12, ft_ef_u );
if ( g == ntagp ) g = f;
strcpy ( tagtext, "[Frame " );
neff = he_geteff();
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
for ( i = 0 ; i < strlen ( tagp[g][1] ) ; i++ ) {
if ( iskanji ( tagp[g][1][i] ) ) {
tx_addstr ( &tx, tagp[g][1][i], 0, neff, cdhfp, headfp, retl );
i++;
}
tx_addstr ( &tx, tagp[g][1][i], 1, neff, cdhfp, headfp, retl );
}
strcpy ( tagtext, "]" );
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
tx_setlink ( &tx, headfp, "" );
he_endeff ( 12 );
tx_return ( &tx, cdhfp, headfp, retl );
}
}
// 改行・左右配置
if ( stricmp ( tagbuf, "br" ) == 0 ) tx_return ( &tx, cdhfp, headfp, retl );
if ( stricmp ( tagbuf, "p" ) == 0 ) {
if ( ntagp == 0 ) {
// 改行としてのpとして扱う
tx_return ( &tx, cdhfp, headfp, retl * 3 / 2 );
} else {
tx_empreturn ( &tx, cdhfp, headfp, retl * 3 / 2 );
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) tx.align = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tx.align = tx_align_c;
else tx.align = tx_align_l;
}
}
}
}
if ( stricmp ( tagbuf, "/p" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl * 3 / 2 );
tx.align = tx_align_l;
}
if ( stricmp ( tagbuf, "div" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) tx.align = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) tx.align = tx_align_c;
else tx.align = tx_align_l;
}
}
}
if ( stricmp ( tagbuf, "/div" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
tx.align = tx_align_l;
}
if ( stricmp ( tagbuf, "center" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
tx.align = tx_align_c;
}
if ( stricmp ( tagbuf, "/center" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
tx.align = tx_align_l;
}
// 水平線
if ( stricmp ( tagbuf, "hr" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl * 3 / 2 );
f = tx.ex - tx.sx;
if ( f < 8 ) f = 0; else f -= 8;
g = tx.align;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "align" ) == 0 ) {
if ( stricmp ( tagp[i][1], "right" ) == 0 ) g = tx_align_r;
else if ( stricmp ( tagp[i][1], "center" ) == 0 ) g = tx_align_c;
else g = tx_align_l;
} else if ( stricmp ( tagp[i][0], "width" ) == 0 ) {
in = atoi ( tagp[i][1] );
if ( in > 0 ) {
tap = tagp[i][1];
while ( ( *tap >= '0' ) && ( *tap <= '9' ) ) tap++;
if ( *tap == '%' ) {
// 相対指定
if ( ( in >= 0 ) && ( in <= 100 ) ) f = (uint)((ulong)f * in / 100);
} else {
// 絶対指定
if ( in < f ) f = in;
}
}
}
}
switch ( g ) {
case tx_align_r:
in = tx.ex - tx.sx - 8 - f;
break;
case tx_align_c:
in = ( tx.ex - tx.sx - 8 - f ) / 2;
break;
case tx_align_l:
default:
in = 0;
break;
}
fprintf ( cdhfp, "L%u,%lu,%u,%lu\n", (uint)tx.sx + 4 + in, (ulong)tx.sy + retl / 2, (uint)(tx.sx + 4 + in + f), (ulong)tx.sy + retl / 2 );
//100%
//fprintf ( cdhfp, "L%u,%lu,%u,%lu\n", (uint)tx.sx + 4, (ulong)tx.sy + retl / 2, (uint)(tx.sx + f - 4 ), (ulong)tx.sy + retl / 2 );
tx_return ( &tx, cdhfp, headfp, retl );
}
if ( stricmp ( tagbuf, "img" ) == 0 ) {
f = 0;
g = ntagp;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "src" ) == 0 ) g = i;
}
if ( g != ntagp ) {
// tagpを展開する
strcpy ( tagbuf2 + 200, "$temp.pat" );
dr_settempdir ( tagbuf2 + 200 );
fnsplit2 ( chname, &fns );
*(tagbuf + 600) = '\0';
fnadd ( &fns, tagbuf + 600, tagp[g][1] );
fnmerge2 ( tagbuf + 400, &fns );
// 画像を読んでみる
if ( bm_convbmp ( tagbuf2, tagbuf + 400, ttx, tpx, tagbuf2 + 200 ) == 0 ) {
f = 1;
tx_empreturn ( &tx, cdhfp, headfp, retl );
switch ( tx.align ) {
case tx_align_r:
if ( tx.ex < ttx ) tbx = 0;
else tbx = tx.ex - ttx;
break;
case tx_align_c:
if ( tx.ex + tx.sx < ttx ) tbx = 0;
else tbx = ( tx.ex - ttx + tx.sx ) / 2;
break;
case tx_align_l:
default:
tbx = tx.sx;
break;
}
if ( ttx > tx.ex - tx.sx ) ttx = tx.ex - tx.sx, tbx = tx.sx;
fprintf ( cdhfp, "G%u,%lu,%u,%u,%s\n", (uint)tbx, (ulong)tx.sy, (uint)ttx, (uint)tpx, tagbuf2 );
tx.sy += tpx + 4;
if ( tx.sy > tx.maxy ) tx.maxy = tx.sy;
if ( tx.maxx < ttx ) tx.maxx = ttx;
}
}
if ( f == 0 ) {
// 画像が出せなかった
g = ntagp;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "alt" ) == 0 ) g = i;
}
if ( g == ntagp ) {
strcpy ( tagtext, "[Image]" );
neff = he_geteff();
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
} else {
strcpy ( tagtext, "[" );
neff = he_geteff();
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
for ( i = 0 ; i < strlen ( tagp[g][1] ) ; i++ ) {
if ( iskanji ( tagp[g][1][i] ) ) {
tx_addstr ( &tx, tagp[g][1][i], 0, neff, cdhfp, headfp, retl );
i++;
}
tx_addstr ( &tx, tagp[g][1][i], 1, neff, cdhfp, headfp, retl );
}
tx_addstr ( &tx, ']', 1, neff, cdhfp, headfp, retl );
}
}
}
if ( stricmp ( tagbuf, "input" ) == 0 ) {
g = ntagp, f = ntagp;
for ( i = 0 ; i < ntagp ; i++ ) {
if ( stricmp ( tagp[i][0], "type" ) == 0 ) f = i;
if ( stricmp ( tagp[i][0], "value" ) == 0 ) g = i;
}
if ( f != ntagp ) {
if ( ( stricmp ( tagp[f][1], "submit" ) == 0 ) || ( stricmp ( tagp[f][1], "reset" ) == 0 ) ) {
if ( g == ntagp ) {
if ( stricmp ( tagp[f][1], "submit" ) == 0 ) strcpy ( tagtext, "[送信]" ); else strcpy ( tagtext, "[リセット]" );
neff = he_geteff();
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) {
if ( iskanji ( tagtext[i] ) ) {
tx_addstr ( &tx, tagtext[i], 0, neff, cdhfp, headfp, retl );
i++;
}
tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
}
} else {
strcpy ( tagtext, "[" );
neff = he_geteff();
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) tx_addstr ( &tx, tagtext[i], 1, neff, cdhfp, headfp, retl );
for ( i = 0 ; i < strlen ( tagp[g][1] ) ; i++ ) {
if ( iskanji ( tagp[g][1][i] ) ) {
tx_addstr ( &tx, tagp[g][1][i], 0, neff, cdhfp, headfp, retl );
i++;
}
tx_addstr ( &tx, tagp[g][1][i], 1, neff, cdhfp, headfp, retl );
}
tx_addstr ( &tx, ']', 1, neff, cdhfp, headfp, retl );
}
}
}
}
// 横幅変動
if ( stricmp ( tagbuf, "blockquote" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
tx_return ( &tx, cdhfp, headfp, retl / 2 );
inblock = 24;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( stricmp ( tagbuf, "/blockquote" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
tx_return ( &tx, cdhfp, headfp, retl / 2 );
inblock = 0;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( stricmp ( tagbuf, "dl" ) == 0 ) {
indd = 0;
}
if ( stricmp ( tagbuf, "/dl" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
indd = 0;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( stricmp ( tagbuf, "dt" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
indd = 0;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( stricmp ( tagbuf, "dd" ) == 0 ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
indd = 24;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( ( stricmp ( tagbuf, "ul" ) == 0 ) || ( stricmp ( tagbuf, "ol" ) == 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
inlist += 32;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( ( stricmp ( tagbuf, "/ul" ) == 0 ) || ( stricmp ( tagbuf, "/ol" ) == 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl );
if ( inlist > 0 ) inlist -= 32;
tx.sx = tx.nx = osx + inblock + indd + inlist;
tx.ex = oex - inblock;
}
if ( ( stricmp ( tagbuf, "li" ) == 0 ) && ( inlist > 0 ) ) {
// このマークは文字効果なしで送る
tx_empreturn ( &tx, cdhfp, headfp, retl * 3 / 2 );
strcpy ( tagtext, " ● " );
ttx = tx.sx, tty = tx.sy;
tx.sx = tx.nx = osx + inblock + indd + inlist - 32;
for ( i = 0 ; i < strlen ( tagtext ) ; i++ ) {
if ( iskanji ( tagtext[i] ) ) {
tx_addstr ( &tx, tagtext[i], 0, 0, cdhfp, headfp, retl );
i++;
}
tx_addstr ( &tx, tagtext[i], 1, 0, cdhfp, headfp, retl );
}
tx_return ( &tx, cdhfp, headfp, retl );
tx.sx = tx.nx = ttx, tx.sy = tty;
}
if ( ( stricmp ( tagbuf, "lh" ) == 0 ) && ( inlist > 0 ) ) {
tx_empreturn ( &tx, cdhfp, headfp, retl * 3 / 2 );
}
// if ( stricmp ( tagbuf, "" ) == 0 ) {
// }
}
} else if ( intitle ) {
if ( iskanji ( ch ) ) {
title[titlelen] = ch;
titlelen++;
ch = fgetc ( htmlfp );
c++;
}
if ( ( ch == ' ' ) || ( ch == '\t' ) ) {
if ( inspace == 0 ) {
title[titlelen] = ' ';
titlelen++;
}
inspace = 2;
} else if ( ch > ' ' ) {
title[titlelen] = ch;
titlelen++;
}
} else if ( ( inbody ) && ( !incaption ) && ( ntable < 2 ) ) { // テキスト読み飛ばし判定
if ( iskanji ( ch ) ) {
vsw = 1;
neff = he_geteff ();
tx_addstr ( &tx, ch, 0, neff, cdhfp, headfp, retl );
ch = fgetc ( htmlfp );
c++;
tx_addstr ( &tx, ch, 1, neff, cdhfp, headfp, retl );
} else if ( ch == '\n' ) { // LFで次行へ
if ( inpre ) {
if ( ch2 != '\r' ) {
// CR LFではreturnしない LF単独のときのみreturn
tx_return ( &tx, cdhfp, headfp, retl );
}
} else inspace = 2;
} else if ( ch == '\r' ) { // CRは空でないとき次行へ
// CR または CR LF
if ( inpre ) tx_return ( &tx, cdhfp, headfp, retl );
else inspace = 2;
} else if ( ( ch == '\t' ) || ( ch == ' ' ) ) {
if ( ( inspace == 0 ) || ( inpre ) ) {
neff = he_geteff ();
tx_addstr ( &tx, ' ', 1, neff, cdhfp, headfp, retl );
}
inspace = 2;
} else {
vsw = 1;
neff = he_geteff ();
tx_addstr ( &tx, ch, 1, neff, cdhfp, headfp, retl );
}
}
if ( inspace ) inspace--;
c++;
ch2 = ch;
// 進行状況
if ( vsw ) vsw = 0;
else {
vsw2++;
if ( vsw2 == 10 ) {
convhtmlbar ( tdepth, c, length, istext );
//printf ( "[%u]%lu/%lu \r", tdepth, c, length );
vsw2 = 0;
}
}
}
tx_empreturn ( &tx, cdhfp, headfp, retl );
convhtmlbar ( tdepth, c, length, istext );
//printf ( "[%u]%lu/%lu \n", tdepth, c, length );
//printf ( "%lu,%lu\n", (ulong)tx.maxx*8UL, (ulong)tx.maxy );
*hx = tx.maxx;
*hy = tx.maxy;
}
void convhtmlbar ( uchar ntable, ulong now, ulong size, uchar istext ) {
uint i, r, c;
uchar buf[16], buf2[16];
uchar bar[9] = { ' ', 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 };
static cbs = 0;
static l = 0;
if ( cbs == 0 ) {
// 初期化
for ( i = 0 ; i < 16 ; i++ ) {
convhtmlpt[i][0] = 0;
convhtmlpt[i][1] = 1;
}
cbs = 1;
}
switch ( istext ) {
case 255:
case 254:
break;
case 4:
convhtmlpt[6][0] = now;
convhtmlpt[6][1] = size;
break;
default:
convhtmlpt[ntable][0] = now;
convhtmlpt[ntable][1] = size;
break;
}
switch ( istext ) {
case 255:
strcpy ( buf, "Browser" );
strcpy ( buf2, "Returns" );
break;
case 254:
strcpy ( buf, "Now " );
strcpy ( buf2, "Drawing" );
break;
case 4:
strcpy ( buf, "BITMAP " );
break;
case 3:
strcpy ( buf, "FOLDER " );
sprintf ( buf2, "%6lu ", now );
break;
case 2:
strcpy ( buf, "CODE " );
break;
case 1:
strcpy ( buf, "TEXT " );
break;
default:
sprintf ( buf, "HTML%2u ", ntable );
l = ntable;
break;
}
for ( i = 0 ; i < 7 ; i++ ) {
poke ( 0xa000, 2 * ( 73 + i ), buf[i] );
pokeb ( 0xa200, 2 * ( 73 + i ), 0xe1 );
}
switch ( istext ) {
case 3:
case 255:
case 254:
for ( i = 0 ; i < 7 ; i++ ) {
poke ( 0xa000, 2 * ( 73 + i ) + 160, buf2[i] );
pokeb ( 0xa200, 2 * ( 73 + i ) + 160, 0xe1 );
}
break;
case 4:
r = l;
if ( r > 5 ) r = 5;
for ( i = 0 ; i <= r ; i++ ) {
if ( convhtmlpt[i][1] == 0 ) c = 0;
else c = (uchar)( convhtmlpt[i][0] * 8 / convhtmlpt[i][1] );
poke ( 0xa000, 2 * ( 73 + i ) + 160, bar[c] );
pokeb ( 0xa200, 2 * ( 73 + i ) + 160, 0xe1 );
}
for ( i = r + 1 ; i <= 5 ; i++ ) {
poke ( 0xa000, 2 * ( 73 + i ) + 160, ' ' );
pokeb ( 0xa200, 2 * ( 73 + i ) + 160, 0xe1 );
}
if ( convhtmlpt[6][1] == 0 ) c = 0;
else c = (uchar)( convhtmlpt[6][0] * 8 / convhtmlpt[6][1] );
poke ( 0xa000, 2 * ( 73 + 6 ) + 160, bar[c] );
pokeb ( 0xa200, 2 * ( 73 + 6 ) + 160, 0xe1 );
break;
default:
r = ntable;
if ( r > 5 ) r = 5;
for ( i = 0 ; i <= r ; i++ ) {
if ( convhtmlpt[i][1] == 0 ) c = 0;
else c = (uchar)( convhtmlpt[i][0] * 8 / convhtmlpt[i][1] );
poke ( 0xa000, 2 * ( 73 + i ) + 160, bar[c] );
pokeb ( 0xa200, 2 * ( 73 + i ) + 160, 0xe1 );
}
for ( i = r + 1 ; i <= 5 ; i++ ) {
poke ( 0xa000, 2 * ( 73 + i ) + 160, ' ' );
pokeb ( 0xa200, 2 * ( 73 + i ) + 160, 0xe1 );
}
poke ( 0xa000, 2 * ( 73 + 6 ) + 160, ' ' );
pokeb ( 0xa200, 2 * ( 73 + 6 ) + 160, 0xe1 );
break;
}
}
void maketop ( uchar *buf, uchar *filename, uchar *ext, uint len ) {
uchar b[100], ch, s = 0, k = 0;
FILE *fp;
uint i = 0;
*buf = '\0';
b[0] = '\0';
if ( ( stricmp ( ext, "exe" ) == 0 ) || ( stricmp ( ext, "com" ) == 0 ) ) return;
fp = fopen2 ( filename, "rb" );
if ( fp == NULL ) return;
while ( ( !feof ( fp ) ) && ( i < len ) ) {
ch = fgetc ( fp );
if ( ( stricmp ( ext, "htm" ) == 0 ) || ( stricmp ( ext, "sht" ) == 0 ) ) {
if ( k == 1 ) {
k = 0;
b[i] = ch;
if ( ( b[i-1] == 0x81 ) && ( b[i] == 0x40 ) ) i -= 2;
i++;
} else if ( ch == '<' ) {
s = 1;
} else if ( ch == '>' ) {
s = 0;
} else if ( ( ch >= '!' ) && ( ch != 0x7f ) && ( s == 0 ) ) {
if ( iskanji ( ch ) ) {
if ( i == len - 1 ) break;
k = 1;
}
b[i] = ch;
i++;
}
} else {
if ( ( ch >= '!' ) && ( ch != 0x7f ) && ( s == 0 ) ) {
if ( k == 1 ) {
k = 0;
} else if ( iskanji ( ch ) ) {
k = 1;
if ( i == len - 1 ) break;
}
b[i] = ch;
if ( ( b[i-1] == 0x81 ) && ( b[i] == 0x40 ) ) i -= 2;
i++;
}
}
}
b[i] = '\0';
strcpy ( buf, b );
fclose ( fp );
}
void he_addeff ( uchar tag, uchar eff ) {
if ( neffs > he_maxeff ) return;
htmleff[neffs].tag = tag;
htmleff[neffs].eff = eff;
neffs++;
}
uchar he_geteff ( void ) {
uchar c = 0;
uint i;
for ( i = 0 ; i < neffs ; i++ ) {
c |= htmleff[i].eff;
}
return ( c );
}
void he_endeff ( uchar tag ) {
int i, j;
if ( neffs == 0 ) return;
for ( i = neffs - 1; i >= 0 ; i-- ) {
if ( htmleff[i].tag == tag ) break;
}
if ( i < 0 ) return;
for ( j = i ; j < neffs - 1 ; j++ ) {
htmleff[j].tag = htmleff[j+1].tag;
htmleff[j].eff = htmleff[j+1].eff;
}
neffs--;
}
void tx_init ( struct tx *tx, ulong w ) {
txbuf[0] = linkto[0] = '\0';
tx->nx = tx->sx = 0;
tx->ex = w;
tx->nl = 0;
tx->sy = 0;
tx->maxx = tx->maxy = 0;
tx->linkline = 0;
}
uint tx_nlcheck ( struct tx *tx, uchar sw ) {
// 8というのは、全角文字に対応するため
// ↓ここが右端
// 漢字
// ABC
// ↑ここまで達していればYesを返す
if ( sw ) return ( tx->ex - tx->sx <= tx->nl );
else return ( tx->ex - tx->sx <= tx->nl + 8 );
}
void tx_return ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl ) {
ulong x, x2, i, nl2;
if ( tx->nl > 0 ) { // 何もなしに<br>の場合はアドレス変更のみでよいことになるのでパス
switch ( tx->align ) {
case tx_align_r:
x = tx->ex - tx->nl;
x2 = x - tx->sx;
break;
case tx_align_c:
x = ( tx->sx + tx->ex - tx->nl ) / 2;
x2 = x - tx->sx;
break;
case tx_align_l:
default:
x = tx->sx;
x2 = 0;
break;
}
nl2 = tx->nl >> 3;
txbuf[nl2] = '\0';
fprintf ( cdhfp, "E%lu,", (ulong)nl2 );
for ( i = 0 ; i < nl2 ; i++ ) { // 文字単位の効果を16進出力(16~31はG~V)
if ( txeff[i] > 9 ) fputc ( 'A' + txeff[i] - 10, cdhfp ); // 10だとA
else fputc ( '0' + txeff[i], cdhfp );
}
fprintf ( cdhfp, "\nT%lu,%lu,%s\n", (ulong)x, (ulong)(tx->sy), (ulong)txbuf );
if ( linkto[0] != '\0' ) {
tx_writelink ( tx, headfp );
linksx = tx->nx;
}
if ( tx->linkline ) {
fprintf ( headfp, "X%lu\n", (ulong)x2 ); // 直前のリンクのx座標を補正(alignによる補正の前に出力するので座標がVer1のようにずれる、これを補正する)
tx->linkline = 0;
}
if ( linkto[0] != '\0' ) tx->linkline = 1;
txbuf[0] = '\0';
}
tx->sy += yl;
if ( tx->sy > tx->maxy ) tx->maxy = tx->sy;
tx->sx = tx->nx;
tx->nl = 0;
}
void tx_maxreturn ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl, uchar sw ) {
if ( tx_nlcheck ( tx, sw ) ) tx_return ( tx, cdhfp, headfp, yl );
}
void tx_empreturn ( struct tx *tx, FILE *cdhfp, FILE *headfp, uint yl ) {
if ( tx->nl > 0 ) tx_return ( tx, cdhfp, headfp, yl );
}
void tx_setlink ( struct tx *tx, FILE *headfp, uchar *href ) {
tx->linkline = 1;
if ( href[0] == '\0' ) {
if ( linkto[0] != '\0' ) tx_writelink ( tx, headfp );
} else {
linksx = tx->sx + tx->nl;
}
strcpy ( linkto, href );
}
void tx_writelink ( struct tx *tx, FILE *headfp ) {
if ( linksx < tx->sx + tx->nl ) // x1=x2の場合は必要ない
fprintf ( headfp, "A%lu,%lu,%lu,%lu,%s\n", (ulong)linksx, (ulong)(tx->sy), (ulong)(tx->sx + tx->nl - 1), (ulong)(tx->sy + 15), linkto );
}
void tx_addstr ( struct tx *tx, uchar ch, uchar sw, uchar eff, FILE *cdhfp, FILE *headfp, uint yl ) {
ulong nl2;
uchar c;
tx_maxreturn ( tx, cdhfp, headfp, yl, sw );
nl2 = tx->nl >> 3;
txbuf[nl2] = ch;
txbuf[nl2+1]='\0'; // 特殊文字チェックを行うため必要
txeff[nl2] = eff;
tx->nl += 8;
nl2++;
if ( tx->sx + nl2 > tx->maxx ) tx->maxx = tx->sx + nl2;
if ( ch == ';' ) {
// 特殊文字チェックを行う(出現するならば末尾)
// ただし、特殊文字の途中に改行が入ったら関知できない
if ( ( jstrstr ( txbuf, ">" ) != NULL ) || ( jstrstr ( txbuf, ">" ) != NULL )) {
tx->nl -= 24, nl2 -= 3;
txbuf[nl2-1] = '>';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, "<" ) != NULL ) || ( jstrstr ( txbuf, "<" ) != NULL )) {
tx->nl -= 24, nl2 -= 3;
txbuf[nl2-1] = '<';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, "&" ) != NULL ) || ( jstrstr ( txbuf, "&" ) != NULL )) {
tx->nl -= 32, nl2 -= 4;
txbuf[nl2-1] = '&';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, """ ) != NULL ) || ( jstrstr ( txbuf, """ ) != NULL ) ) {
tx->nl -= 40, nl2 -= 5;
txbuf[nl2-1] = '"';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, " " ) != NULL ) || ( jstrstr ( txbuf, "&NBSP;" ) != NULL )) {
tx->nl -= 40, nl2 -= 5;
txbuf[nl2-1] = ' ';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, "©" ) != NULL ) || ( jstrstr ( txbuf, "©" ) != NULL )) {
tx->nl -= 24, nl2 -= 3;
txbuf[nl2-3] = '(';
txbuf[nl2-2] = 'C';
txbuf[nl2-1] = ')';
txbuf[nl2] = '\0';
}
if ( ( jstrstr ( txbuf, "®" ) != NULL ) || ( jstrstr ( txbuf, "®" ) != NULL )) {
tx->nl -= 16, nl2 -= 2;
txbuf[nl2-3] = '(';
txbuf[nl2-2] = 'R';
txbuf[nl2-1] = ')';
txbuf[nl2] = '\0';
}
// 32~126が対象なのでは見なくてよい
if ( ( nl2 > 5 ) && ( txbuf[nl2-6] == '&' ) && ( txbuf[nl2-5] == '#' ) && ( txbuf[nl2-4] >= '0' ) && ( txbuf[nl2-4] <= '9' ) && ( txbuf[nl2-3] >= '0' ) && ( txbuf[nl2-3] <= '9' ) && ( txbuf[nl2-2] >= '0' ) && ( txbuf[nl2-2] <= '9' ) ) {
//
c = txbuf[nl2-4] - '0';
c *= 10;
c += txbuf[nl2-3] - '0';
c *= 10;
c += txbuf[nl2-2] - '0';
if ( ( c >= ' ' ) && ( c <= '~' ) ) {
tx->nl -= 40, nl2 -= 5;
txbuf[nl2-1] = c;
txbuf[nl2] = '\0';
} else switch ( c ) {
case 169:
// ©と同じ
tx->nl -= 16, nl2 -= 2;
txbuf[nl2-3] = '(';
txbuf[nl2-2] = 'R';
txbuf[nl2-1] = ')';
txbuf[nl2] = '\0';
break;
case 174:
// ®と同じ(但し元の長さが異なる)
tx->nl -= 24, nl2 -= 3; // ←注意
txbuf[nl2-3] = '(';
txbuf[nl2-2] = 'R';
txbuf[nl2-1] = ')';
txbuf[nl2] = '\0';
break;
}
}
if ( ( nl2 > 4 ) && ( txbuf[nl2-5] == '&' ) && ( txbuf[nl2-4] == '#' ) && ( txbuf[nl2-3] >= '0' ) && ( txbuf[nl2-3] <= '9' ) && ( txbuf[nl2-2] >= '0' ) && ( txbuf[nl2-2] <= '9' ) ) {
//
c = txbuf[nl2-3] - '0';
c *= 10;
c += txbuf[nl2-2] - '0';
if ( ( c >= ' ' ) && ( c <= '~' ) ) {
tx->nl -= 32, nl2 -= 4;
txbuf[nl2-1] = c;
txbuf[nl2] = '\0';
}
}
}
}
void writecdh ( uchar *filename, uint tx, uint sx, uint ty, uint sy, long fy ) {
long endy = sy + fy;
uchar buf[200], ebuf[200], eb2[80], ebsw = 0;
FILE *fp;
uchar *p;
uint i, j, c;
int x1, x2, xe, xe2; // 1はファイル内座標値・2は画面内座標値
long y1, y2, ye, ye2;
uint x3, y3;
fp = fopen2 ( filename, "r" );
if ( fp == NULL ) return;
do {
while ( kbhit() ) getch();
buf[0] = '\0'; // これがないと最後の行がだぶって実行される
fgets ( buf, 200, fp );
switch ( buf[0] ) {
case '\0':
break;
case 'E':
case 'e':
strcpy ( ebuf, buf );
ebsw = 0;
break;
case 'L':
case 'l':
p = buf + strlen ( buf ) - 1;
if ( *p == '\n' ) *p = '\0';
sscanf( buf + 1, "%d,%ld,%d,%ld", &x1, &y1, &xe, &ye );
if ( ( y1 > endy ) && ( ye > endy ) ) break;
if ( ( y1 < fy ) && ( ye < fy ) ) break;
if ( ye < y1 ) {
// y1<=yeとなるように入れ換える
y2 = y1; y1 = ye; ye = y2;
x2 = x1; x1 = xe; xe = x2;
}
if ( ( y1 > endy ) || ( ye < fy ) ) break;
if ( y1 < fy ) {
y1 = fy;
if ( x1 != xe ) x1 = x1 + ( xe - x1 ) * ( fy - y1 ) / ( ye - y1 );
}
if ( ye > endy ) {
ye = endy;
if ( x1 != xe ) xe = x1 + ( xe - x1 ) * ( endy - y1 ) / ( ye - y1 );
}
x2 = tx + x1;
y2 = ty + y1 - fy;
xe2 = tx + xe;
ye2 = ty + ye - fy;
gd_gline ( x2, y2, xe2, ye2, 15 );
break;
case 'T':
case 't':
p = buf + strlen ( buf ) - 1;
if ( *p == '\n' ) *p = '\0'; // 判定しないと最終行の最後がおかしくなる
sscanf( buf + 1, "%d,%ld", &x1, &y1 );
if ( ( y1 >= fy - 20 ) && ( y1 <= endy ) ) {
if ( ebsw == 0 ) {
// Eは使うときに初めて変換する
sscanf ( ebuf + 1, "%u", &j );
p = ebuf + 1;
while ( *p != ',' ) p++;
p++;
if ( j > 80 ) j = 80;
for ( i = 0 ; i < j ; i++ ) {
c = *( p + i );
if ( c <= '9' ) eb2[i] = c - '0';
else eb2[i] = c - 'A' + 10;
}
for ( i = j ; i < 80 ; i++ ) eb2[i] = 0;
ebsw = 1;
}
p = buf + 1;
for ( i = 0 ; i < 2 ; i++ ) {
while ( *p != ',' ) p++;
p++;
}
x2 = tx + x1;
y2 = ty + y1 - fy;
// gd_waitdraw(); // ここに入れないとGDC描画が終わっていないときに描いてしまう(gd_glineの最後に入れてはいるのだが?)
ft_writestrs ( p, eb2, x2/8, y2, ty, ty + sy, sx / 8 );
}
break;
case 'G':
case 'g':
p = buf + strlen ( buf ) - 1;
if ( *p == '\n' ) *p = '\0';
sscanf( buf + 1, "%d,%ld,%u,%u", &x1, &y1, &x3, &y3 );
if ( ( y1 + y3 >= fy ) && ( y1 <= endy ) ) {
p = buf + 1;
for ( i = 0 ; i < 4 ; i++ ) {
while ( *p != ',' ) p++;
p++;
}
x2 = tx + x1;
y2 = ty + y1 - fy;
// gd_waitdraw();
bm_writecdb ( p, x2, y2, x3, y3, ty, ty + sy, 2, 77 );
}
break;
default:
break;
}
} while ( !feof ( fp ) );
gd_waitdraw();
fclose ( fp );
}
void loadhdr ( uchar *filename, uchar *name, ulong &starty, ulong &maxy, uchar *title, uchar *fname ) {
FILE *fp;
uchar buf[200];
uint i;
ulong l;
uchar *p;
*title = '\0';
starty = 0;
maxy = 0;
fp = fopen2 ( filename, "r" );
if ( fp == NULL ) return;
do {
buf[0] = '\0';
fgets ( buf, 200, fp );
i = strlen ( buf );
if ( i > 0 ) {
if ( buf[i-1] == '\n' ) buf[i-1] = '\0';
}
switch ( buf[0] ) {
case 'T':
case 't':
// タイトル
p = buf + 1;
i = 0;
while ( *p != '\0' ) {
if ( iskanji ( *p ) ) {
if ( i >= 63 ) break;
title[i] = *p;
i++; p++;
title[i] = *p;
i++; p++;
} else {
if ( i >= 64 ) break;
title[i] = *p;
i++; p++;
}
}
title[i] = '\0';
break;
case 'F':
case 'f':
// ファイル名
p = buf + 1;
i = 0;
while ( *p != '\0' ) {
if ( iskanji ( *p ) ) {
if ( i >= 63 ) break;
fname[i] = *p;
i++; p++;
fname[i] = *p;
i++; p++;
} else {
if ( i >= 64 ) break;
fname[i] = *p;
i++; p++;
}
}
fname[i] = '\0';
break;
case 'N':
case 'n':
// A NAME
p = buf + 1;
while ( ( *p != ',' ) && ( *p != '\0' ) ) p++;
if ( *p == ',' ) p++;
if ( strcmp ( p, name ) == 0 ) {
l = 0;
sscanf ( buf + 1, "%lu" , &l );
starty = l;
}
case 'Y':
case 'y':
// 縦幅
sscanf ( buf + 1, "%lu", &maxy );
break;
default:
break;
}
} while ( !feof ( fp ) );
fclose ( fp );
}
void extlink ( uchar *hdrname, uchar *hdr2name, ulong y1, ulong y2 ) {
FILE *fp;
FILE *fp2;
uint x1, x2, i;
ulong fy1, fy2;
uchar r, buf[200];
fp = fopen2 ( hdrname, "r" );
if ( fp == NULL ) return;
remove ( hdr2name );
fp2 = fopen2 ( hdr2name, "w" );
if ( fp2 == NULL ) {
fclose ( fp );
return;
}
r = 0;
do {
buf[0] = '\0';
fgets ( buf, 200, fp );
i = strlen ( buf );
if ( i > 0 ) {
if ( buf[i-1] == '\n' ) buf[i-1] = '\0';
}
switch ( buf[0] ) {
case 'A':
sscanf ( buf + 1, "%u,%lu,%u,%lu", &x1, &fy1, &x2, &fy2 );
if ( !( ( fy2 < y1 ) || ( fy1 > y2 ) ) ) {
fprintf ( fp2, "%s\n", buf );
r = 1;
}
break;
case 'X':
if ( r ) {
fprintf ( fp2, "%s\n", buf );
r = 0;
}
break;
default:
break;
}
} while ( !feof ( fp ) );
fclose ( fp2 );
fclose ( fp );
}
void getlink ( uchar *filename, uchar *linkto, uint x, ulong y ) {
FILE *fp;
uint i;
uchar buf[200];
uint x1, x2;
ulong y1, y2, mv;
uchar *p;
fpos_t f;
uchar s;
linkto[0] = '\0';
fp = fopen2 ( filename, "r" );
if ( fp == NULL ) return;
s = 0, mv = 0;
fgetpos ( fp, &f );
do {
buf[0] = '\0';
fgets ( buf, 200, fp );
i = strlen ( buf );
if ( i > 0 ) {
if ( buf[i-1] == '\n' ) buf[i-1] = '\0';
}
switch ( buf[0] ) {
// AとX以外も使うときはextlinkも変更する
case 'A':
if ( s == 0 ) break;
sscanf ( buf + 1, "%u,%lu,%u,%lu", &x1, &y1, &x2, &y2 );
x1 += mv;
x2 += mv;
if ( ( x1 <= x ) && ( x2 >= x ) && ( y1 <= y ) && ( y2 >= y ) ) {
p = buf + 1;
for ( i = 0 ; i < 4 ; i++ ) {
while ( *p != ',' ) p++;
p++;
}
strcpy ( linkto, p );
}
break;
case 'X':
if ( s ) {
fgetpos ( fp, &f );
s = 0;
} else {
fsetpos ( fp, &f );
sscanf ( buf + 1, "%lu", &mv );
s = 1;
}
break;
default:
break;
}
if ( ( feof ( fp ) ) && ( s == 0 ) ) {
fsetpos ( fp, &f );
mv = 0;
s = 1;
}
} while ( !feof ( fp ) );
fclose ( fp );
}
void draw1 ( void ) {
// draw1→HTML変換→draw2
// このためHTML両脇スクロールバー部は表示しない
uint i = ft_km_auto;
gb_gcls ();
printf ( "\033[2J\r" );
rt_clock ();
gd_gline ( 0, 0, 639, 0, 15 );
gd_gline ( 0, 40, 639, 40, 15 );
gd_gline ( 72, 20, 575, 20, 15 );
gd_gline ( 70, 2, 70, 38, 15 );
gd_gline ( 577, 2, 577, 38, 15 );
gd_gline ( 0, 359, 639, 359, 15 );
gd_gline ( 0, 399, 639, 399, 15 );
gd_gline ( 0, 379, 639, 379, 15 );
gd_waitdraw();
ft_writestr ( "1終了 2漢SJIS 3漢EUC 4移動 5前ファイル 6先頭 7最終 8DIR 9 0 ", 0, 0, 382, 0, 399, i );
}
void draw2 ( uchar *cdhname, long y, ulong maxy, uchar *title, uchar *fname, uchar *hdrname, uchar *hdr2name ) {
const long hei = 357 - 42;
long y1, y2;
uint i;
printf ( "\033[19;1H%-79.79s\033[3;1H\r", "" );
// タイトル・ファイル名
i = ft_km_auto;
gb_gcls2 ( 1, 19, 9, 71 );
ft_writestr ( title, 0, 9, 2, 0, 399, i );
gb_gcls2 ( 21, 39, 9, 71 );
ft_writestr ( fname, 0, 9, 22, 0, 399, i );
gb_gcls2 ( 41, 358 );
ft_writestr ( "▲", 0, 0, 42, 0, 399, i );
ft_writestr ( "■", 0, 0, 192, 0, 399, i );
ft_writestr ( "▼", 0, 0, 357-15, 0, 399, i );
gd_gline ( 625, 42, 625, 357, 15 );
gd_gline ( 14, 42, 14, 357, 15 );
rt_clock ();
convhtmlbar ( 0, 0, 0, 254 );
writecdh ( cdhname, 16, 616, 42, hei, y );
extlink ( hdrname, hdr2name, y, y + 357 - 42 );
// 右ゲージ
if ( maxy > 0 ) {
y1 = hei * y / (long)maxy;
y2 = hei * ( y + hei ) / (long)maxy;
if ( y1 <= 0 ) y1 = 0;
if ( y1 >= hei ) y1 = hei;
if ( y2 <= 0 ) y2 = 0;
if ( y2 >= hei ) y2 = hei;
y1 += 42;
y2 += 42;
gd_gline ( 627, y1, 639, y1, 15 );
gd_gline ( 627, y2, 639, y2, 15 );
gd_gline ( 627, y1, 627, y2, 15 );
gd_gline ( 639, y1, 639, y2, 15 );
}
rt_clock ();
convhtmlbar ( 0, 0, 0, 255 );
gd_waitdraw();
}
void draw3 ( uchar *hdrname, uchar *linkto, long y, struct ip_joy &ipjoy ) {
uchar buf[81], c;
uint i, j;
// added Ver2.1
gb_waitvsync();
ip_get ( ipjoy );
while ( kbhit() ) getch();
linkto[0] = '\0';
if ( ( ipjoy.my >= 42 ) && ( ipjoy.my <= 357 ) ) {
if ( ( ipjoy.mx == 15 ) || ( ipjoy.mx == 624 ) ) {
buf[0] = '\0';
} else if ( ipjoy.mx < 15 ) {
// スクロール
sprintf ( buf, "%4dドットスクロールします", ( (int)ipjoy.my - 200 ) * 2 );
} else if ( ipjoy.mx > 624 ) {
// ゲージ
sprintf ( buf, "%3ld%%の位置へジャンプします", ( (long)ipjoy.my - 42 ) * 100 / ( 357 - 42 ) );
} else {
// リンク
getlink ( hdrname, linkto, ipjoy.mx - 16, (long)ipjoy.my - 42 + y );
strncpy ( buf, linkto, 80 );
buf[80] = '\0';
}
} else if ( ipjoy.my >= 380 ) {
// ファンクションキー
i = ipjoy.mx & 63;
j = ipjoy.mx / 64;
if ( ( i > 7 ) && ( i < 56 ) ) {
switch ( j ) {
case 0:
strcpy ( buf, "ブラウザを終了します" );
break;
case 1:
strcpy ( buf, "漢字コードをShiftJISに固定して読み直します(フォルダ一覧・画像には無効)" );
break;
case 2:
strcpy ( buf, "漢字コードをEUC-JPに固定して読み直します(フォルダ一覧・画像には無効)" );
break;
case 3:
strcpy ( buf, "キーボードで位置を入力して移動します" );
break;
case 4:
strcpy ( buf, "前に見ていたファイルに戻ります" );
break;
case 5:
strcpy ( buf, "一番上までスクロールします" );
break;
case 6:
strcpy ( buf, "一番下までスクロールします" );
break;
case 7:
strcpy ( buf, "現在見ているファイルがあるフォルダの一覧を出します" );
break;
default:
buf[0] = '\0';
}
} else buf[0] = '\0';
} else {
buf[0] = '\0';
}
if ( buf[0] == '\0' ) {
c = tempdrive + 'A' - 1;
sprintf ( buf, "作業ドライブ%c: 空き%luバイト", c, tempfree );
}
printf ( "\033[19;1H%-79.79s\033[3;1H\r", buf );
}
void makename ( uint number, uchar *cdhname, uchar *hdrname ) {
number %= 1000;
sprintf ( cdhname, "$temp%u.cdh", number );
dr_settempdir ( cdhname );
sprintf ( hdrname, "$temp%u.hdr", number );
dr_settempdir ( hdrname );
}
uint inputline ( uchar *buf ) {
uchar c, r, k;
uint i, j;
uchar *p;
uchar *q;
r = 0;
do {
printf ( "\033[19;1H移動先:%-72.72s\033[19;8H%s\033[>5l", "", buf );
i = strlen ( buf );
c = getch();
printf ( "\033[>5h\033[3;1H\r" );
switch ( c ) {
case '\n':
case '\r':
r = 1;
break;
case '\033':
r = 2;
break;
case 8:
p = q = buf;
while ( *p != '\0' ) {
q = p;
p = nextchar ( p );
}
*q = '\0';
break;
default:
if ( iskanji ( c ) ) {
if ( i < 71 ) {
buf[i] = c;
buf[i+1] = getch();
buf[i+2] = '\0';
}
} else {
if ( i < 72 ) {
buf[i] = c;
buf[i+1] = '\0';
}
}
}
} while ( r == 0 );
return ( r - 1 );
}
void rt_init ( void ) {
double s;
double pai = 3.14159265358979;
uint i;
for ( i = 0 ; i < 60 ; i++ ) {
s = sin ( pai * ( (double)i * 6.0 + 270.0 ) / 180.0 );
rt_sinbuf[i] = (int)( s * 128 + .5);
}
}
int rt_sin ( int min ) {
return ( rt_sinbuf[( min + 60 ) % 60] );
}
int rt_cos ( int min ) {
return ( rt_sinbuf[( min + 75 ) % 60] );
}
void rt_clock ( void ) {
uint x, y, i;
int x2, y2;
struct time ti;
struct date dt;
uchar month[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
uint km = ft_km_auto;
uchar buf[4];
// if ( eg_ison ) eg_off ();
//消去
gb_gdcmode ( 0x80 );
gb_gdctile ( 0 );
for ( y = 1 ; y < 40 ; y++ ) {
for ( x = 0 ; x < 7 ; x++ ) poke ( 0xa800, y * 80 + x, 0 );
}
gb_gdcmode ( 0 );
gettime ( &ti );
// 補助線
for ( i = 0 ; i < 12 ; i++ ) {
x2 = ( rt_cos ( i * 5 ) * 18 ) / 128 + 19;
y2 = ( rt_sin ( i * 5 ) * 18 ) / 128 + 19;
gd_gline ( x2, y2, x2 + 1, y2, 15 );
gd_gline ( x2, y2 + 1, x2 + 1, y2 + 1, 15 );
}
// 時
y = ( ti.ti_hour % 12 ) * 5 + ( ti.ti_min + 6 ) / 12;
x2 = ( rt_cos ( y ) * 10 ) / 128 + 19;
y2 = ( rt_sin ( y ) * 10 ) / 128 + 19;
gd_gline ( 19, 19, x2, y2, 15 );
gd_gline ( 19, 20, x2, y2 + 1, 15 );
gd_gline ( 20, 19, x2 + 1, y2, 15 );
gd_gline ( 20, 20, x2 + 1, y2 + 1, 15 );
// 分
y = ti.ti_min + ( ti.ti_sec + 30 ) / 60;
x2 = ( rt_cos ( ti.ti_min ) * 14 ) / 128 + 19;
y2 = ( rt_sin ( ti.ti_min ) * 14 ) / 128 + 19;
gd_gline ( 19, 19, x2, y2, 15 );
gd_gline ( 19, 20, x2, y2 + 1, 15 );
gd_gline ( 20, 19, x2 + 1, y2, 15 );
gd_gline ( 20, 20, x2 + 1, y2 + 1, 15 );
// 秒
//x2 = ( rt_cos ( ti.ti_sec ) * 15 ) / 128 + 20;
//y2 = ( rt_sin ( ti.ti_sec ) * 15 ) / 128 + 20;
//gd_gline ( 20, 20, x2, y2, 15 );
getdate ( &dt );
// 月
ft_writestr ( month[dt.da_mon - 1], 0, 5, 22, 0, 399, km );
// 日
sprintf ( buf, "%2u", dt.da_day );
ft_writestr ( buf, 0, 6, 2, 0, 399, km );
}
// sw=1ならデータ書き込み sw=0ならアドレス書き込み
void ip_sbout ( uchar data, uchar sw = 1 ) {
uint i = 0;
if ( ip_joy == 0 ) return;
while ( ( i < 500 ) && ( inportb ( ip_joyport[ip_joy][0] ) & 0x80 ) ) i++;
outportb ( ip_joyport[ip_joy][sw], data );
}
uchar ip_sbin ( uchar sw = 1 ) {
if ( ip_joy == 0 ) return ( 0xff );
return ( inportb ( ip_joyport[ip_joy][sw] ) );
}
void ip_init ( uchar speed ) {
uint i, j, k;
// Joystick
if ( ip_joy > 3 ) {
for ( i = 1 ; i <= 3 ; i++ ) {
for ( j = 0 ; j < 20 ; j++ ) outportb ( 0x5f, 0 );
k = inportb ( ip_joyport[i][0] );
if ( k != 0xff ) ip_joy = i;
}
// Add Ver2.11 該当無しの場合
if ( ip_joy > 3 ) ip_joy = 0;
}
if ( ip_joy ) {
ip_sbout ( 7, 0 );
i = inportb ( ip_joyport[ip_joy][1] );
i &= 0x3f;
i |= 0x80;
ip_sbout ( i );
}
// Keyboard
inregs.h.ah = 0x03;
int86 ( 0x18, &inregs, &outregs );
// Mouse
if ( ip_mouse ) { // Added Ver2.11
inregs.x.ax = 0x0000;
inregs.x.bx = 0;
int86 ( 0x33, &inregs, &outregs );
}
if ( ip_mouse == 3 ) {
if ( outregs.x.ax == 0 ) {
ip_mouse = 0;
} else {
if ( outregs.x.bx == 0 ) {
// NEC Function
ip_mouse = 1;
} else {
// MS Function
ip_mouse = 2;
}
}
}
switch ( ip_mouse ) {
case 1:
inregs.x.ax = 0x12;
inregs.x.bx = 2; // プレーン2
int86 ( 0x33, &inregs, &outregs );
ip_mvoff ();
break;
case 2:
inregs.x.ax = 0xfd;
inregs.x.bx = 1;
int86 ( 0x33, &inregs, &outregs ); // プレーン3も使う
inregs.x.ax = 0xff;
inregs.x.bx = 15;
int86 ( 0x33, &inregs, &outregs ); // プレーン0~3を使う
ip_mvoff ();
break;
}
ip_sp[0] = speed * 4;
ip_sp[1] = speed * 2;
ip_sp[2] = speed;
}
void ip_structinit ( struct ip_joy &ipjoy ) {
uint i;
ipjoy.mx = ip_mx;
ipjoy.my = ip_my;
ipjoy.jx = ipjoy.jy = 0;
ipjoy.e = ipjoy.pe = ipjoy.s = ipjoy.b = ipjoy.pb = 0;
for ( i = 0 ; i < 16 ; i++ ) ipjoy.key[i] = 0;
}
void ip_get ( struct ip_joy &ipjoy ) {
uint i;
char x = 0, y = 0, e = 0, s = 1, b = 0;
for ( i = 0 ; i <= 15 ; i++ ) {
inregs.h.ah = 0x04;
inregs.h.al = i;
int86 ( 0x18, &inregs, &outregs );
ipjoy.key[i] = outregs.h.ah;
}
if ( ipjoy.key[0] & 1 ) e--; // ESC
if ( ipjoy.key[3] & 16 ) e++; // Return
i = ipjoy.key[7];
if ( i & 4 ) y--; // Cursor
if ( i & 8 ) x--;
if ( i & 16 ) x++;
if ( i & 32 ) y++;
i = ipjoy.key[14];
if ( i & 1 ) s++; // Shift
if ( i & 16 ) s--; // Ctrl
if ( ipjoy.key[1] & 64 ) b++; // BS
i = ipjoy.key[12];
if ( i & 4 ) e--; // f1終了
if ( i & 64 ) b++; // f5戻る
if ( ip_joy ) {
// Joy1
ip_sbout ( 0x0f, 0 );
ip_sbout ( 0x8f );
ip_sbout ( 0x0e, 0 );
i = ip_sbin ();
i = ~i;
if ( i & 1 ) y--;
if ( i & 2 ) y++;
if ( ( i & 3 ) == 3 ) b++; // SELECT(上下同時)
if ( i & 4 ) x--;
if ( i & 8 ) x++;
if ( ( i & 12 ) == 12 ) b++; // START(左右同時)
if ( i & 16 ) e++;
if ( i & 32 ) s++;
// Joy2
ip_sbout ( 0x0f, 0 );
ip_sbout ( 0xcf );
ip_sbout ( 0x0e, 0 );
i = ip_sbin ();
i = ~i;
if ( i & 1 ) y--;
if ( i & 2 ) y++;
if ( ( i & 3 ) == 3 ) b++; // START・SELECTは戻る
if ( i & 4 ) x--;
if ( i & 8 ) x++;
if ( ( i & 12 ) == 12 ) b++;
if ( i & 16 ) e++;
if ( i & 32 ) s++; // 第2は減速
}
// 座標値はマウス利用時はマウス座標・非利用時はip_mx・ip_my
switch ( ip_mouse ) {
case 2:
inregs.x.ax = 3;
int86 ( 0x33, &inregs, &outregs );
ipjoy.mx = outregs.x.cx;
ipjoy.my = outregs.x.dx;
e += outregs.x.bx & 1;
b += ( outregs.x.bx & 2 ) >> 1;
break;
case 1:
inregs.x.ax = 3;
int86 ( 0x33, &inregs, &outregs );
ipjoy.mx = outregs.x.cx;
ipjoy.my = outregs.x.dx;
if ( outregs.x.ax ) e++;
if ( outregs.x.bx ) b++;
break;
default:
ipjoy.mx = ip_mx;
ipjoy.my = ip_my;
break;
}
if ( y > 1 ) y = 1;
if ( y < -1 ) y = -1;
if ( x > 1 ) x = 1;
if ( x < -1 ) x = -1;
if ( e > 1 ) e = 1;
if ( e < -1 ) e = -1;
if ( s > 2 ) s = 2;
if ( s < 0 ) s = 0;
if ( b > 1 ) b = 1;
ipjoy.e = e;
if ( ip_be == e ) ipjoy.pe = 0;
else ipjoy.pe = e;
ipjoy.b = b;
if ( ip_bb == b ) ipjoy.pb = 0;
else ipjoy.pb = b;
ipjoy.s = s;
ipjoy.jx = x;
ipjoy.jy = y;
// 新座標計算
ipjoy.mx += (int)(x) * ip_sp[s];
if ( ipjoy.mx < 0 ) ipjoy.mx = 0;
if ( ipjoy.mx > 639 ) ipjoy.mx = 639;
ipjoy.my += (int)(y) * ip_sp[s];
if ( ipjoy.my < 0 ) ipjoy.my = 0;
if ( ipjoy.my > 399 ) ipjoy.my = 399;
// ip_mx・ip_myへの保存・マウス座標更新
switch ( ip_mouse ) {
case 2:
case 1:
inregs.x.ax = 4;
inregs.x.cx = ipjoy.mx;
inregs.x.dx = ipjoy.my;
int86 ( 0x33, &inregs, &outregs );
break;
default:
ip_mx = ipjoy.mx;
ip_my = ipjoy.my;
break;
}
ip_be = e;
ip_bb = b;
}
void ip_mvon ( void ) {
uint i;
if ( ip_mouse ) {
inregs.x.ax = 1;
for ( i = 0 ; i < ip_mvo ; i++ )
int86 ( 0x33, &inregs, &outregs );
ip_mvo = 0;
}
}
void ip_mvoff ( void ) {
if ( ip_mouse ) {
inregs.x.ax = 2;
int86 ( 0x33, &inregs, &outregs );
ip_mvo++;
}
}
void ip_wmcursor ( struct ip_joy &ipjoy, uchar sw, uchar b ) {
int static bx = 320, by = 200, bs = 0;
int x1, y1, x2, y2;
// ちらつき防止
if ( ( sw == 0 ) && ( bs == b ) && ( ipjoy.mx == bx ) && ( ipjoy.my == by ) ) return;
// 0通常 1描画のみ 2消去のみ
if ( sw != 1 ) {
// 前カーソル消去
x1 = bx - 8;
x2 = bx + 8;
y1 = by - 8;
y2 = by + 8;
if ( x1 < 0 ) x1 = 0;
if ( x2 > 639 ) x2 = 639;
if ( y1 < 0 ) y1 = 0;
if ( y2 > 399 ) y2 = 399;
gd_gline ( x1, by, x2, by, 16 );
gd_gline ( bx, y1, bx, y2, 16 );
if ( bs ) {
if ( by < 399 ) gd_gline ( x1, by+1, x2, by+1, 16 );
if ( bx < 639 ) gd_gline ( bx+1, y1, bx+1, y2, 16 );
}
}
// 新カーソル描画
if ( sw != 2 ) {
x1 = ipjoy.mx - 8;
x2 = ipjoy.mx + 8;
y1 = ipjoy.my - 8;
y2 = ipjoy.my + 8;
if ( x1 < 0 ) x1 = 0;
if ( x2 > 639 ) x2 = 639;
if ( y1 < 0 ) y1 = 0;
if ( y2 > 399 ) y2 = 399;
gd_gline ( x1, ipjoy.my, x2, ipjoy.my, 16 );
gd_gline ( ipjoy.mx, y1, ipjoy.mx, y2, 16 );
if ( b ) {
if ( ipjoy.my < 399 ) gd_gline ( x1, ipjoy.my+1, x2, ipjoy.my+1, 16 );
if ( ipjoy.mx < 639 ) gd_gline ( ipjoy.mx+1, y1, ipjoy.mx+1, y2, 16 );
}
}
bx = ipjoy.mx;
by = ipjoy.my;
bs = b;
}