whpcvt.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 2,343 行 · 第 1/5 页
C
2,343 行
memcpy( buf, ptr + 1, end - ptr - 1 );
buf[end - ptr - 1] = '\0';
add_ctx_keyword( Curr_ctx, buf );
ptr = end + 1;
if( *ptr == '\0' ) {
return( NULL );
} else if( *ptr == ' ' ) {
/* kludge fix cuz of GML: GML thinks that keywords are
are real words, so it puts a space after them.
This should fix that */
++ptr;
}
}
return( ptr );
}
int trans_add_char(
/******************/
char ch,
section_def *section,
int *alloc_size
) {
++section->section_size;
if( section->section_size > *alloc_size ) {
*alloc_size += 1024; // grow by a good, big amount
_renew( section->section_text, *alloc_size );
}
section->section_text[section->section_size - 1] = ch;
return( 1 );
}
int trans_add_str(
/****************/
char *str,
section_def *section,
int *alloc_size
) {
int len;
len = 0;
for( ; *str != '\0'; ++str ) {
trans_add_char( *str, section, alloc_size );
++len;
}
return( len );
}
int trans_add_nobreak_str(
/************************/
char *str,
section_def *section,
int *alloc_size
) {
int len;
len = 0;
for( ; *str != '\0'; ++str ) {
if( *str != ' ' || Break_link ) {
len = trans_add_char( *str, section, alloc_size );
} else {
/* non-breaking space */
if( Output_type == OUT_RTF ) {
len = trans_add_char( '\\', section, alloc_size );
len += trans_add_char( '~', section, alloc_size );
} else {
/* IPF and InfoBench do not break alternate spaces */
len = trans_add_char( '\xFF', section, alloc_size );
}
}
}
return( len );
}
void add_link(
/************/
char *link_name
) {
link_def *link;
_new( link, 1 );
link->next = NULL;
Link_list = link;
_new( link->link_name, strlen( link_name ) + 1 );
strcpy( link->link_name, link_name );
link->line_num = Line_num;
}
bool find_keyword(
/****************/
ctx_def *ctx,
char *keyword
) {
keylist_def *keylist;
for( keylist = ctx->keylist; keylist != NULL; keylist = keylist->next ) {
if( stricmp( keylist->key->keyword, keyword ) == 0 ) {
return( TRUE );
}
}
return( FALSE );
}
keyword_def *find_keyword_all(
/****************************/
char *keyword
) {
keyword_def *key;
for( key = Keyword_list; key != NULL; key = key->next ) {
if( stricmp( key->keyword, keyword ) == 0 ) {
return( key );
}
}
return( NULL );
}
static void add_key_ctx(
/**********************/
keyword_def *key,
ctx_def *ctx
) {
if( key->ctx_list == NULL ) {
_new( key->ctx_list, 1);
key->ctx_list_alloc = 1;
key->ctx_list_size = 0;
}
++key->ctx_list_size;
if( key->ctx_list_size > key->ctx_list_alloc ) {
key->ctx_list_alloc += 16; // grow by a reasonable amount
_renew( key->ctx_list, key->ctx_list_alloc );
}
key->ctx_list[ key->ctx_list_size - 1] = ctx;
}
void add_ctx_keyword(
/*******************/
ctx_def *ctx,
char *keyword
) {
keyword_def *key;
keylist_def *keylist;
if( !find_keyword( ctx, keyword ) ) {
key = find_keyword_all( keyword );
if( key != NULL ) {
key->duplicate = TRUE;
} else {
_new( key, 1 );
key->duplicate = FALSE;
key->defined_ctx = ctx;
_new( key->keyword, strlen( keyword ) + 1 );
strcpy( key->keyword, keyword );
key->next = Keyword_list;
key->id = Keyword_id;
++Keyword_id;
Keyword_list = key;
key->ctx_list = NULL;
}
add_key_ctx( key, ctx );
_new( keylist, 1 );
keylist->key = key;
keylist->next = ctx->keylist;
ctx->keylist = keylist;
}
}
static int trans_line(
/********************/
section_def *section,
int alloc_size
) {
switch( Output_type ) {
case OUT_RTF:
return( rtf_trans_line( section, alloc_size ) );
case OUT_IPF:
return( ipf_trans_line( section, alloc_size ) );
case OUT_IB:
return( ib_trans_line( section, alloc_size ) );
case OUT_HTML:
return( html_trans_line( section, alloc_size ) );
case OUT_WIKI:
return( wiki_trans_line( section, alloc_size ) );
}
return( 0 );
}
static void topic_init( void )
/****************************/
{
switch( Output_type ) {
case OUT_RTF:
rtf_topic_init();
break;
case OUT_IPF:
ipf_topic_init();
break;
case OUT_IB:
ib_topic_init();
break;
case OUT_HTML:
html_topic_init();
break;
case OUT_WIKI:
wiki_topic_init();
break;
}
}
static bool read_topic_text(
/**************************/
ctx_def *ctx,
bool is_blank,
int order_num
) {
bool more_to_do;
section_def *section;
section_def **ins_section;
int sect_alloc_size;
section = NULL;
topic_init();
for( ;; ) {
more_to_do = read_line();
if( !more_to_do ) {
break;
}
if( *Line_buf == CH_CTX_DEF || *Line_buf == CH_TOPIC ) {
break;
}
if( section == NULL ) {
_new( section, 1 );
section->section_text = NULL;
section->section_size = 0;
sect_alloc_size = 0;
}
sect_alloc_size = trans_line( section, sect_alloc_size );
}
if( section != NULL ) {
for( ins_section = &ctx->section_list; *ins_section != NULL;
ins_section = &((*ins_section)->next) ) {
if( is_blank && !(*ins_section)->blank_order ) {
break;
} else if( order_num < (*ins_section)->order_num ) {
break;
}
}
section->next = *ins_section;
*ins_section = section;
section->blank_order = is_blank;
section->order_num = order_num;
}
return( more_to_do );
}
ctx_def *find_ctx(
/****************/
char *ctx_name
) {
ctx_def *ctx;
for( ctx = Ctx_list; ctx != NULL; ctx = ctx->next ) {
if( stricmp( ctx->ctx_name, ctx_name ) == 0 ) {
return( ctx );
}
}
return( NULL );
}
static char *skip_prep(
/*********************/
char *str
) {
char ch;
char *start;
char *end;
char *next;
for( start = str; *start == ' ' || *start == '\t'; ++start );
for( end = start; *end != ' ' && *end != '\t' && *end != '\0'; ++end );
/* now 'end' points to the terminating char after the first word */
if( start == end ) {
/* no first word */
return( str );
}
for( next = end; *next == ' ' || *next == '\t'; ++next );
if( *next == '\0' ) {
/* nothing after the first word */
return( start );
}
ch = *end;
*end = '\0';
if( stricmp( "the", start ) == 0 ||
stricmp( "a", start ) == 0 ||
stricmp( "an", start ) == 0 ) {
start = next;
}
*end = ch;
return( start );
}
static browse_def *add_browse(
/****************************/
char *browse_name,
ctx_def *ctx
) {
browse_def *browse;
browse_def *browse_prev;
browse_ctx *b_ctx;
browse_ctx **b_ctx_list;
if( browse_name == NULL ) {
return( NULL );
}
browse_prev = NULL;
for( browse = Browse_list;; browse_prev = browse, browse = browse->next ) {
if( browse == NULL ) {
_new( browse, 1 );
_new( browse->browse_name, strlen( browse_name ) + 1 );
strcpy( browse->browse_name, browse_name );
browse->ctx_list = NULL;
browse->next = NULL;
/* keep the browse list in the order they are parsed */
if( browse_prev == NULL ) {
Browse_list = browse;
} else {
browse_prev->next = browse;
}
break;
} else if( stricmp( browse->browse_name, browse_name ) == 0 ) {
break;
}
}
_new( b_ctx, 1 );
b_ctx->ctx = ctx;
for( b_ctx_list = &browse->ctx_list; *b_ctx_list != NULL;
b_ctx_list = &((*b_ctx_list)->next) ) {
if( Browse_sort && stricmp( skip_prep( ctx->title ),
skip_prep( (*b_ctx_list)->ctx->title ) ) < 0 ) {
break;
}
}
b_ctx->next = *b_ctx_list;
*b_ctx_list = b_ctx;
return( browse );
}
static void add_ctx(
/******************/
ctx_def *ctx,
char *title,
char *keywords,
char *browse_name,
int head_level
) {
char *ptr;
char *end;
char ch;
ctx_def *up_ctx;
ctx_def *ctx_list;
if( title != NULL && ctx->title == NULL ) {
_new( ctx->title, strlen( title ) + 1 );
strcpy( ctx->title, title );
}
if( keywords != NULL && ctx->keylist == NULL &&
*skip_blank( keywords ) != '\0' ) {
for( ptr = keywords;; ) {
for( end = ptr; *end != ',' && *end != ';' && *end != '\0'; ++end );
ch = *end;
*end = '\0';
if( !find_keyword( ctx, ptr ) ) {
add_ctx_keyword( ctx, ptr );
}
*end = ch;
if( ch == '\0' ) {
break;
}
ptr = end + 1;
}
}
if( Do_topic_keyword && ( keywords != NULL )) {
add_ctx_keyword( ctx, ctx->title );
}
ctx->head_level = head_level;
up_ctx = NULL;
for( ctx_list = Ctx_list; ctx_list != ctx; ctx_list = ctx_list->next ) {
if( ctx_list->head_level < head_level ) {
up_ctx = ctx_list;
}
}
ctx->up_ctx = up_ctx;
ctx->browse = add_browse( browse_name, ctx );
}
static ctx_def *init_ctx(
/***********************/
char *ctx_name
) {
ctx_def *ctx;
_new( ctx, 1 );
ctx->section_list = NULL;
if( Ctx_list == NULL ) {
Ctx_list = ctx;
} else {
*Ctx_list_end = ctx;
}
Ctx_list_end = &(ctx->next);
ctx->next = NULL;
ctx->keylist = NULL;
ctx->browse = NULL;
ctx->title = NULL;
ctx->ctx_id = -1;
ctx->empty = TRUE;
ctx->req_by_link = FALSE;
_new( ctx->ctx_name, strlen( ctx_name ) + 1 );
strcpy( ctx->ctx_name, ctx_name );
return( ctx );
}
static ctx_def *define_ctx( void )
/********************************/
{
char *title;
char *keywords;
char *browse_name;
char *ctx_name;
ctx_def *ctx;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?