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

📄 sflxmll.c

📁 短小精悍的C语言标准函数库。提供450个以上的可移植的算法和工具代码。
💻 C
📖 第 1 页 / 共 3 页
字号:
          }
        if (!thisch)
          {
            line_nbr = start_line_nbr;
            error_exception ("File end inside literal.");
            mem_free (literal);
            return NULL;
          }

        token [chunk] = 0;
    
        bufptr = token;

        snippet = http_decode_meta (token, &bufptr, LINE_MAX + 1);
        if (literal)
            literal = mem_realloc (literal, length + snippet + 1);
        else
            literal = mem_alloc   (         length + snippet + 1);

        ASSERT (literal);
        memcpy (&literal [length], token, snippet);

        length += snippet;
        literal [length] = '\0';

        /*  If we zapped the & in http_decode_meta(), put it back            */
        if (bufptr - token < chunk)
            *bufptr = '&';

        strcpy (token, bufptr);
        chunk = strlen (token);
        if (thisch == terminator)
            return literal;
      }
}


/******************************   SKIP SPACES   ******************************/

MODULE skip_spaces (void)
{
    char thisch;                        /*  Next char in token               */

    thisch = get_next_char ();
    while (strchr (" \t\r\n", thisch) && thisch)
        thisch = get_next_char ();

    if (thisch)
        char_nbr--;
}


/****************************   ATTACH NEW ITEM   ****************************/

MODULE attach_new_item (void)
{
    item = xml_new (item, name, NULL);
    ASSERT (item);

    generation++;
}


/**************************   NOTE TOP LEVEL ITEM   **************************/

MODULE note_top_level_item (void)
{
    top_item = item;
}


/******************************   EXPECT NAME   ******************************/

MODULE expect_name (void)
{
    if (get_next_non_white_char ())
      {
        char_nbr--;
        if (collect_name ())
            strcpy (name, token);

        return;
      }
    error_exception ("Did not find a name.");
}


/***************************   CONFIRM ITEM NAME   ***************************/

MODULE confirm_item_name (void)
{
    if (strneq (name, xml_item_name (item)))
        error_exception ("Incorrect closing tag name: %s", name);
}


/********************   REMOVE VALUES IF ALL WHITE SPACE   *******************/

MODULE remove_values_if_all_white_space (void)
{
    XML_ITEM
        *child,
        *trash;
    char
        *value;

    for (child  = xml_first_child (item); child != NULL; )
      {
         if (!xml_item_name (child))
           {
             value = xml_item_value (child);
             while (*value)
               if (! isspace (*value))
                   break;
               else
                   value++;

             if (! *value)              /*  End of string with all spaces    */
               {
                 trash = child;
                 child  = xml_next_sibling (child);
                 xml_free (trash);
                 continue;
               }
           }
         child  = xml_next_sibling (child);
      }
}


/*****************************   CLOSE THE ITEM   ****************************/

MODULE close_the_item (void)
{
    item = xml_parent (item);
    if (!item)
        error_exception ("Incorrect closing tag name: %s", name);

    generation--;
}


/******************************   EXPECT CLOSE   *****************************/

MODULE expect_close (void)
{
    expect_token ('>');
}


static void
expect_token (char expect)
{
    char thisch;                        /*  Next char in token               */

    thisch = get_next_non_white_char ();
    if (thisch != expect)
        error_exception ("Unexpected token: %c", thisch);
}


/************************   SKIP REST OF PROCESSING   ************************/

MODULE skip_rest_of_processing (void)
{
    char
        thisch;                         /*  Next character                   */
    int
        start_line_nbr;                 /*  Where tag started                */

    start_line_nbr = line_nbr;
    FOREVER
      {
        thisch = get_next_non_white_char ();
        if (thisch == 0)
          {
            line_nbr = start_line_nbr;
            error_exception ("File end inside tag.");
            return;
          }

        if ((            thisch == '?')
        &&  (xmlline [char_nbr] == '>'))
          {
            char_nbr++;
            return;
          }
      }
}


/**************************   SKIP REST OF COMMENT   *************************/

MODULE skip_rest_of_comment (void)
{
    char
        thisch;                         /*  Next character                   */
    int
        start_line_nbr;                 /*  Where comment started            */

    start_line_nbr = line_nbr;
    FOREVER
      {
        thisch = get_next_non_white_char ();
        if (thisch == 0)
          {
            line_nbr = start_line_nbr;
            error_exception ("File end inside comment.");
            return;
          }

        if ((              thisch == '-')
        &&  (xmlline [char_nbr]   == '-')
        &&  (xmlline [char_nbr+1] == '>'))
          {
            char_nbr+= 2;
            return;
          }
      }
}


/**************************   SKIP REST OF SECTION   *************************/

MODULE skip_rest_of_section (void)
{
    char
        thisch;                         /*  Next character                   */
    int
        start_line_nbr;                 /*  Where tag started                */

    start_line_nbr = line_nbr;
    FOREVER
      {
        thisch = get_next_non_white_char ();
        if (thisch == 0)
          {
            line_nbr = start_line_nbr;
            error_exception ("File end inside tag.");
            return;
          }

        if (thisch == '>')
            return;
      }
}



/**************************   CHECK FOR OPEN ITEM   **************************/

MODULE check_for_open_item (void)
{
    if (generation > 0)
        the_next_event = ok_event;
    else
        if (extended)
            the_next_event = optional_items_event;
        else
            the_next_event = no_more_items_event;
}


/***************************   EXPECT END OF FILE   **************************/

MODULE expect_end_of_file (void)
{
    if (get_next_non_white_char ())
        error_exception ("End of file expected.");
}


/*****************************   REPORT NO XML   *****************************/

MODULE report_no_xml (void)
{
    error_exception ("File contains no XML items.");
}


/*****************************   CLOSE XML FILE   ****************************/

MODULE close_xml_file (void)
{
    if (xmlfile)
        if (file_close (xmlfile))
            error_exception ("Error closing file.");
}


/**************************   EXPECT EQUALS TOKEN   **************************/

MODULE expect_equals_token (void)
{
    expect_token ('=');
}


/*****************************   EXPECT LITERAL   ****************************/

MODULE expect_literal (void)
{
    char
        thisch;
 
    thisch = get_next_non_white_char ();
    if (thisch == 0)                    /* End-of-file was reached           */
        return;

    if (!is_quote (thisch))
      {
        error_exception ("Invalid literal opening quote: %c",
                         thisch);
        return;
      }

    literal = collect_literal (thisch);
}


/**************************   ATTACH NEW ATTRIBUTE   *************************/

MODULE attach_new_attribute (void)
{
    if (xml_put_attr (item, name, literal) != 1)
        error_exception ("Duplicate attribute name: %s", name);

    mem_strfree (&literal);
}


/*************************   FREE PARTIAL XML TREE   *************************/

MODULE free_partial_xml_tree (void)
{
    if (top_item)
        xml_free (top_item);
}


/*************************   RETURN ERROR FEEDBACK   *************************/

MODULE return_error_feedback (void)
{
    feedback = XML_LOADERROR;
}


/*************************   UNEXPECTED TOKEN ERROR   ************************/

MODULE unexpected_token_error (void)
{
    error_exception ("Unexpected character: %c", xmlline [char_nbr - 1]);
}


/***************************   GET EXTERNAL EVENT   **************************/

MODULE get_external_event (void)
{
}


/*************************   TERMINATE THE PROGRAM    ************************/

MODULE terminate_the_program (void)
{
    the_next_event = terminate_event;
}


/*****************************************************************************/

local
error_exception (char *format, ...)
{
    char
        *ch,
        *mess_ptr;
    int
        offset;
    va_list
        argptr;

    mess_ptr = error_message;
    if (line_nbr > 0)
      {
        ch = strchr (xmlline, '\n');
        if (ch)
            *ch = '\0';
        if (pname)
          {
            offset = sprintf (mess_ptr, "%s ", pname);
            mess_ptr += offset;
          }
        offset = sprintf (mess_ptr, "%d: %s\n", line_nbr, xmlline);
        mess_ptr += offset;
        if (ch)
            *ch = '\n';
      }

    va_start (argptr, format);          /*  Start variable arguments list    */
    offset = vsprintf (mess_ptr, format, argptr);
    va_end   (argptr);                  /*  End variable arguments list      */
    mess_ptr += offset;

    sprintf (mess_ptr, "\n");
    raise_exception (error_event);
}

⌨️ 快捷键说明

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