⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wiki.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  This file defines the wiki specific functions.
*
****************************************************************************/


#include "whpcvt.h"

static int Curr_head_level = 0;
static int Curr_head_skip = 0;

#define BOX_LINE_SIZE   200

#define FONT_STYLE_BOLD         1
#define FONT_STYLE_ITALIC       2
#define FONT_STYLE_UNDERLINE    4

static char     *Font_match[] = {
    "",                     // 0: PLAIN
    "<b>",                  // 1: BOLD
    "<i>",                  // 2: ITALIC
    "<b><i>",               // 3: BOLD + ITALIC
    "<u>",                  // 4: UNDERLINE
    "<b><u>",               // 5: BOLD + UNDERLINE
    "<i><u>",               // 6: ITALIC + UNDERLINE
    "<i><u><b>",            // 7: ITALIC + BOLD + UNDERLINE
};

static char     *Font_end[] = {
    "",                     // 0: PLAIN
    "</b>",                 // 1: BOLD
    "</i>",                 // 2: ITALIC
    "</i></b>",             // 3: BOLD + ITALIC
    "</u>",                 // 4: UNDERLINE
    "</u></b>",             // 5: BOLD + UNDERLINE
    "</u></i>",             // 6: ITALIC + UNDERLINE
    "</b></u></i>",         // 7: ITALIC + BOLD + UNDERLINE
};

#define WIKI_SPACE  " " //"&nbsp;"

static int Font_list[100];      // up to 100 nested fonts
static int Font_list_curr = 0;

static bool Blank_line_pfx = FALSE;
static bool Blank_line_sfx = TRUE;

#define WIKI_TRANS_LEN  50

static char *Trans_str = NULL;
static int  Trans_len   = 0;

#define MAX_TABS        100     // up to 100 tab stops
static int Tab_list[MAX_TABS];


static void draw_line( section_def *section, int *alloc_size )
/************************************************************/
{
    trans_add_str( "----\n", section, alloc_size );
}

static int translate_char_wiki( char ch, char next_ch, char *buf )
/****************************************************************/
{
    switch( ch ) {
#if 0
    case '<':
        strcpy( buf, "&lt;" );
        break;
    case '>':
        strcpy( buf, "&gt;" );
        break;
    case '&':
        strcpy( buf, "&amp;" );
        break;
    case '"':
        strcpy( buf, "&quot;" );
        break;
#endif
    case ' ':
        if( next_ch == ' ' ) {
            strcpy( buf, WIKI_SPACE );
            break;
        }
        /* fall through */
    default:
        buf[0] = ch;
        buf[1] = '\0';
        break;
    }

    return( strlen( buf ) );
}

static char *translate_str_wiki( char *str )
/******************************************/
{
    char                *t_str;
    int                 len;
    char                buf[WIKI_TRANS_LEN];
    char                *ptr;

    len = 1;
    for( t_str = str; *t_str != '\0'; ++t_str ) {
        len += translate_char_wiki( *t_str, *(t_str+1), buf );
    }
    if( len > Trans_len ) {
        if( Trans_str != NULL ) {
            _free( Trans_str );
        }
        _new( Trans_str, len );
        Trans_len = len;
    }
    ptr = Trans_str;
    for( t_str = str; *t_str != '\0'; ++t_str ) {
        len = translate_char_wiki( *t_str, *(t_str+1), buf );
        strcpy( ptr, buf );
        ptr += len;
    }
    *ptr = '\0';

    return( Trans_str );
}

static int trans_add_char_wiki( char ch, char next_ch,
                                section_def *section, int *alloc_size )
/*********************************************************************/
{
    char                buf[WIKI_TRANS_LEN];

    translate_char_wiki( ch, next_ch, buf );
    return( trans_add_str( buf, section, alloc_size ) );
}

static int trans_add_str_wiki( char *str, section_def *section,
                               int *alloc_size )
/*************************************************************/
{
    int                 len;

    len = 0;
    for( ; *str != '\0'; ++str ) {
        len += trans_add_char_wiki( *str, *(str+1), section, alloc_size );
    }

    return( len );
}

static int trans_add_list( char *list, section_def *section,
                           int *alloc_size, char *ptr )
/**********************************************************/
{
    int                 len;

    len = trans_add_str( list, section, alloc_size );
    ++ptr;
#if 0
  if( *ptr == 'c' ) {
        len += trans_add_str( " compact", section, alloc_size );
    }

    len += trans_add_str( ">\n", section, alloc_size );
#endif
    return( len );
}

static void read_tabs( char *tab_line )
/*************************************/
{
    char                *ptr;
    int                 i;
    int                 tabcol;

    Tab_xmp_char = *tab_line;

    ptr = strtok( tab_line + 1, " " );
    for( tabcol = 0, i = 0 ; ptr != NULL; ptr = strtok( NULL, " " ), ++i ) {
        if( *ptr == '+' ) {
            tabcol += atoi( ptr + 1 );
        } else {
            tabcol = atoi( ptr );
        }
        Tab_list[i] = tabcol;
    }
    Tab_list[i] = -1;
}

static int tab_align( int ch_len, section_def *section, int *alloc_size )
/***********************************************************************/
{
    int                 i;
    int                 len;

    // find the tab we should use
    i = 0;
    while( ch_len >= Tab_list[i]) {
        if( Tab_list[i] == -1 ) break;
        ++i;
    }

    len = 1;
    if( Tab_list[i] != -1 ) {
        len =  Tab_list[i] - ch_len;
    }
    for( i = len; i > 0; --i ) {
        trans_add_str_wiki( WIKI_SPACE, section, alloc_size );
    }

    return( len );
}

void wiki_topic_init( void )
/**************************/
{
}

int wiki_trans_line( section_def *section, int alloc_size )
/*********************************************************/
{
    char                *ptr;
    char                *end;
    char                ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[500];
    int                 font_idx;
    int                 line_len;
    bool                term_fix;
    int                 ch_len;
    int                 len;
    char                *file_name;

    /* check for special column 0 stuff first */
    ptr = Line_buf;
    ch = *ptr;
    ch_len = 0;
    line_len = 0;

    switch( ch ) {

    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
            trans_add_str( "</pre>\n", section, &alloc_size );
            Blank_line_sfx = FALSE;     // remove following blanks
        } else {
            read_tabs( ptr + 1 );
            trans_add_str( "<pre>\n", section, &alloc_size );
            Tab_xmp = TRUE;
            Blank_line_pfx = FALSE;     // remove preceding blanks
        }
        return( alloc_size );

    case CH_BOX_ON:
        /* Table support is the closest thing to boxing in IPF, but it
           doesn't work well with changing fonts on items in the tables
           (the edges don't line up). So we draw long lines at the
           top and bottom instead */
        draw_line( section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_BOX_OFF:
        draw_line( section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_START:
        trans_add_list( "# ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_LIST_START:
        trans_add_list( "* ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_DLIST_START:
        trans_add_str( "; ", section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_START:
        trans_add_list( "* ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -