* xmlTextWriterStartComment: * @writer: the xmlTextWriterPtr * * Start an xml comment. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */
| 715 | * Returns the bytes written (may be 0 because of buffering) or -1 in case of error |
| 716 | */ |
| 717 | int |
| 718 | xmlTextWriterStartComment(xmlTextWriterPtr writer) |
| 719 | { |
| 720 | int count; |
| 721 | int sum; |
| 722 | xmlLinkPtr lk; |
| 723 | xmlTextWriterStackEntry *p; |
| 724 | |
| 725 | if (writer == NULL) { |
| 726 | xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR, |
| 727 | "xmlTextWriterStartComment : invalid writer!\n"); |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | sum = 0; |
| 732 | lk = xmlListFront(writer->nodes); |
| 733 | if (lk != 0) { |
| 734 | p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); |
| 735 | if (p != 0) { |
| 736 | switch (p->state) { |
| 737 | case XML_TEXTWRITER_TEXT: |
| 738 | case XML_TEXTWRITER_NONE: |
| 739 | break; |
| 740 | case XML_TEXTWRITER_NAME: |
| 741 | /* Output namespace declarations */ |
| 742 | count = xmlTextWriterOutputNSDecl(writer); |
| 743 | if (count < 0) |
| 744 | return -1; |
| 745 | sum += count; |
| 746 | count = xmlOutputBufferWriteString(writer->out, ">"); |
| 747 | if (count < 0) |
| 748 | return -1; |
| 749 | sum += count; |
| 750 | if (writer->indent) { |
| 751 | count = |
| 752 | xmlOutputBufferWriteString(writer->out, "\n"); |
| 753 | if (count < 0) |
| 754 | return -1; |
| 755 | sum += count; |
| 756 | } |
| 757 | p->state = XML_TEXTWRITER_TEXT; |
| 758 | break; |
| 759 | default: |
| 760 | return -1; |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | p = (xmlTextWriterStackEntry *) |
| 766 | xmlMalloc(sizeof(xmlTextWriterStackEntry)); |
| 767 | if (p == 0) { |
| 768 | xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY, |
| 769 | "xmlTextWriterStartElement : out of memory!\n"); |
| 770 | return -1; |
| 771 | } |
| 772 | |
| 773 | p->name = NULL; |
| 774 | p->state = XML_TEXTWRITER_COMMENT; |
no test coverage detected