~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/xml/shl/XmlReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2007 amaury darsch                                   -
 
14
// - copyright (c) 1999-2011 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#include "Stack.hpp"
414
414
  // this function parse a parameter entity element
415
415
  static XmlNode* parse_xml_pent (XmlBuffer& xbuf) {
416
416
    // check that we have a parameter entity
417
 
    if (xbuf.read () != XML_CHAR_PC) {
 
417
    if (xbuf.getu () != XML_CHAR_PC) {
418
418
      throw Exception ("internal-error", 
419
419
                       "trying to parse a parameter entity");
420
420
    }
674
674
    // state: s_helo
675
675
    // get the first character for dispatch
676
676
  s_helo:
677
 
    t_quad c = xis.rduc ();
 
677
    t_quad c = xis.getu ();
678
678
    switch (c) {
679
679
    case XML_CHAR_LT:
680
680
      xbuf.begin (xis.getlnum ());
683
683
      xbuf.begin (xis.getlnum ());
684
684
      goto s_xref;
685
685
    case nilq:
686
 
    case eofq:
 
686
    case eosq:
687
687
      return nilp;
688
688
    default:
689
689
      xbuf.add (c);
698
698
    // state: s_text
699
699
    // read some text and accumulate
700
700
  s_text:
701
 
    c = xis.rduc ();
 
701
    c = xis.getu ();
702
702
    switch (c) {
703
703
    case XML_CHAR_AM:
704
704
    case XML_CHAR_LT:
705
 
    case eofq:
 
705
    case eosq:
706
706
      xis.pushback (c);
707
707
      return parse_xml_text (xbuf);
708
708
    default:
713
713
    // state: s_stag
714
714
    // start a tag or any xml stuff
715
715
  s_stag:
716
 
    c = xis.rduc ();
 
716
    c = xis.getu ();
717
717
    switch (c) {
718
718
    case XML_CHAR_EP:
719
719
      goto s_rtag;
721
721
      goto s_ptag;
722
722
    case XML_CHAR_SL:
723
723
      goto s_etag;
724
 
    case eofq:
 
724
    case eosq:
725
725
      goto s_error;
726
726
    default:
727
727
      xbuf.add (c);
731
731
    // state: s_ntag
732
732
    // read a normal tag
733
733
  s_ntag:
734
 
    c = xis.rduc ();
 
734
    c = xis.getu ();
735
735
    switch (c) {
736
736
    case XML_CHAR_SL:
737
737
      goto s_entg;
738
738
    case XML_CHAR_GT:
739
739
      return parse_xml_tag (xbuf, false);
740
 
    case eofq:
 
740
    case eosq:
741
741
      goto s_error;
742
742
    default:
743
743
      xbuf.add (c);
747
747
    // state: s_entg
748
748
    // read an empty normal tag
749
749
  s_entg:
750
 
    c = xis.rduc ();
 
750
    c = xis.getu ();
751
751
    switch (c) {
752
752
    case XML_CHAR_GT:
753
753
      return parse_xml_tag (xbuf, true);
754
 
    case eofq:
 
754
    case eosq:
755
755
      goto s_error;
756
756
    default:
757
757
      xbuf.add (XML_CHAR_SL);
762
762
    // state: s_etag
763
763
    // read an end tag
764
764
  s_etag:
765
 
    c = xis.rduc ();
 
765
    c = xis.getu ();
766
766
    switch (c) {
767
767
    case XML_CHAR_GT:
768
768
      return parse_xml_etag (xbuf);
769
 
    case eofq:
 
769
    case eosq:
770
770
      goto s_error;
771
771
    default:
772
772
      xbuf.add (c);
776
776
    // state: s_rtag
777
777
    // start a reserved tag
778
778
  s_rtag:
779
 
    c = xis.rduc ();
 
779
    c = xis.getu ();
780
780
    switch (c) {
781
781
    case XML_CHAR_MN:
782
782
      goto s_bgcm;
783
783
    case XML_CHAR_LB:
784
784
      goto s_bgcs;
785
 
    case eofq:
 
785
    case eosq:
786
786
      goto s_error;
787
787
    default:
788
788
      xbuf.add (c);
792
792
    // state: s_rdrt
793
793
    // read a reserved tag
794
794
  s_rdrt:
795
 
    c = xis.rduc ();
 
795
    c = xis.getu ();
796
796
    switch (c) {
797
797
    case XML_CHAR_GT:
798
798
      return parse_xml_rtag (xbuf);
799
799
    case XML_CHAR_LB:
800
800
      xbuf.add (c);
801
801
      goto s_rsub;
802
 
    case eofq:
 
802
    case eosq:
803
803
      goto s_error;
804
804
    default:
805
805
      xbuf.add (c);
809
809
    // state: s_rsub
810
810
    // read a subset node in a reserved tag
811
811
  s_rsub:
812
 
    c = xis.rduc ();
 
812
    c = xis.getu ();
813
813
    switch (c) {
814
814
    case XML_CHAR_RB:
815
815
      xbuf.add (c);
816
816
      goto s_rdrt;
817
817
    case XML_CHAR_LB:
818
818
      goto s_error;
819
 
    case eofq:
 
819
    case eosq:
820
820
      goto s_error;
821
821
    default:
822
822
      xbuf.add (c);
826
826
    // state: s_bgcm
827
827
    // begin a comment node
828
828
  s_bgcm:
829
 
    c = xis.rduc ();
 
829
    c = xis.getu ();
830
830
    switch (c) {
831
831
    case XML_CHAR_MN:
832
832
      goto s_ctag;
833
 
    case eofq:
 
833
    case eosq:
834
834
      goto s_error;
835
835
    default:
836
836
      xbuf.add (c);
840
840
    // state: s_ctag
841
841
    // read a comment node
842
842
  s_ctag:
843
 
    c = xis.rduc ();
 
843
    c = xis.getu ();
844
844
    switch (c) {
845
845
    case XML_CHAR_MN:
846
846
      goto s_encm;
847
 
    case eofq:
 
847
    case eosq:
848
848
      goto s_error;
849
849
    default:
850
850
      xbuf.add (c);
854
854
    // state: s_encm
855
855
    // start the end comment node
856
856
  s_encm:
857
 
    c = xis.rduc ();
 
857
    c = xis.getu ();
858
858
    switch (c) {
859
859
    case XML_CHAR_MN:
860
860
      goto s_fncm;
861
 
    case eofq:
 
861
    case eosq:
862
862
      goto s_error;
863
863
    default:
864
864
      xbuf.add (XML_CHAR_MN);
869
869
    // state: s_fncm
870
870
    // finish the end comment node
871
871
  s_fncm:
872
 
    c = xis.rduc ();
 
872
    c = xis.getu ();
873
873
    switch (c) {
874
874
    case XML_CHAR_GT:
875
875
      return parse_xml_comt (xbuf);
876
 
    case eofq:
 
876
    case eosq:
877
877
      throw Exception ("xml-error", "unterminated comment node");
878
878
    default:
879
879
      throw Exception ("xml-error", "invalid -- sequence in comment node");
882
882
    // state: s_bgcs
883
883
    // start a cdata or section node
884
884
  s_bgcs:
885
 
    c = xis.rduc ();
 
885
    c = xis.getu ();
886
886
    switch (c) {
887
887
    case XML_CHAR_LB:
888
888
      if (xbuf.tostring () == "CDATA") {
891
891
      }
892
892
      xbuf.add (c);
893
893
      goto s_rdcs;
894
 
    case eofq:
 
894
    case eosq:
895
895
      throw Exception ("xml-error", "unterminated node", xbuf.tostring ());
896
896
    default:
897
897
      xbuf.add (c);
901
901
    // state: s_rdcd
902
902
    // read cdata characters
903
903
  s_rdcd:
904
 
    c = xis.rduc ();
 
904
    c = xis.getu ();
905
905
    switch (c) {
906
906
    case XML_CHAR_RB:
907
907
      goto s_encd;
908
 
    case eofq:
 
908
    case eosq:
909
909
      throw Exception ("xml-error", "unterminated cdata node");
910
910
    default:
911
911
      xbuf.add (c);
915
915
    // state: s_encd
916
916
    // start end cdata node
917
917
  s_encd:
918
 
    c = xis.rduc ();
 
918
    c = xis.getu ();
919
919
    switch (c) {
920
920
    case XML_CHAR_RB:
921
921
      goto s_fncd;
922
 
    case eofq:
 
922
    case eosq:
923
923
      throw Exception ("xml-error", "unterminated cdata node");
924
924
    default:
925
925
      xbuf.add (XML_CHAR_RB);
930
930
    // state: s_fncd
931
931
    // finish end cdata node
932
932
  s_fncd:
933
 
    c = xis.rduc ();
 
933
    c = xis.getu ();
934
934
    switch (c) {
935
935
    case XML_CHAR_GT:
936
936
      return parse_xml_data (xbuf);
937
 
    case eofq:
 
937
    case eosq:
938
938
      throw Exception ("xml-error", "unterminated cdata node");
939
939
    default:
940
940
      xbuf.add (XML_CHAR_RB);
946
946
    // state: s_rdcs
947
947
    // read section character
948
948
  s_rdcs:
949
 
    c = xis.rduc ();
 
949
    c = xis.getu ();
950
950
    switch (c) {
951
951
    case XML_CHAR_RB:
952
952
      goto s_encs;
953
 
    case eofq:
 
953
    case eosq:
954
954
      throw Exception ("xml-error", "unterminated section node");
955
955
    default:
956
956
      xbuf.add (c);
960
960
    // state: s_encs
961
961
    // start end section node
962
962
  s_encs:
963
 
    c = xis.rduc ();
 
963
    c = xis.getu ();
964
964
    switch (c) {
965
965
    case XML_CHAR_RB:
966
966
      goto s_fncs;
967
 
    case eofq:
 
967
    case eosq:
968
968
      throw Exception ("xml-error", "unterminated section node");
969
969
    default:
970
970
      xbuf.add (XML_CHAR_RB);
975
975
    // state: s_fncs
976
976
    // finish end section node
977
977
  s_fncs:
978
 
    c = xis.rduc ();
 
978
    c = xis.getu ();
979
979
    switch (c) {
980
980
    case XML_CHAR_GT:
981
981
      xbuf.add (XML_CHAR_RB);
982
982
      return parse_xml_sect (xbuf);
983
 
    case eofq:
 
983
    case eosq:
984
984
      throw Exception ("xml-error", "unterminated section node");
985
985
    default:
986
986
      xbuf.add (XML_CHAR_RB);
992
992
    // state: s_ptag
993
993
    // processing instruction tag
994
994
  s_ptag:
995
 
    c = xis.rduc ();
 
995
    c = xis.getu ();
996
996
    switch (c) {
997
997
    case XML_CHAR_QM:
998
998
      goto s_etpi;
999
 
    case eofq:
 
999
    case eosq:
1000
1000
      throw Exception ("xml-error", "unterminated processing node");
1001
1001
    default:
1002
1002
      xbuf.add (c);
1006
1006
    // state: s_etpi
1007
1007
    // end processing instruction tag
1008
1008
  s_etpi:
1009
 
    c = xis.rduc ();
 
1009
    c = xis.getu ();
1010
1010
    switch (c) {
1011
1011
    case XML_CHAR_GT:
1012
1012
      return parse_xml_pi (xbuf);
1013
 
    case eofq:
 
1013
    case eosq:
1014
1014
      throw Exception ("xml-error", "unterminated processing node");
1015
1015
    default:
1016
1016
      xbuf.add (c);
1020
1020
    // state: s_xref
1021
1021
    // start a reference node
1022
1022
  s_xref:
1023
 
    c = xis.rduc ();
 
1023
    c = xis.getu ();
1024
1024
    switch (c) {
1025
1025
    case XML_CHAR_DZ:
1026
1026
      xbuf.add (XML_CHAR_AM);
1027
1027
      xbuf.add (c);
1028
1028
      goto s_cref;
1029
1029
    case XML_CHAR_LT:
1030
 
    case eofq:
 
1030
    case eosq:
1031
1031
      xbuf.add (XML_CHAR_AM);
1032
1032
      xis.pushback (c);
1033
1033
      goto s_text;
1039
1039
    // state: s_cref
1040
1040
    // start a character reference node
1041
1041
  s_cref:
1042
 
    c = xis.rduc ();
 
1042
    c = xis.getu ();
1043
1043
    switch (c) {
1044
1044
    case XML_CHAR_SC:
1045
1045
      return parse_xml_cref (xbuf);
1046
 
    case eofq:
 
1046
    case eosq:
1047
1047
      throw Exception ("xml-error", "unterminated character reference node");
1048
1048
    default:
1049
1049
      xbuf.add (c);
1053
1053
    // state: s_eref
1054
1054
    // process an entity reference node
1055
1055
  s_eref:
1056
 
    c = xis.rduc ();
 
1056
    c = xis.getu ();
1057
1057
    switch (c) {
1058
1058
    case XML_CHAR_SC:
1059
1059
      return parse_xml_eref (xbuf);
1060
1060
    case XML_CHAR_LT:
1061
 
    case eofq:
 
1061
    case eosq:
1062
1062
      xbuf.pushback (XML_CHAR_AM);
1063
1063
      xis.pushback  (c);
1064
1064
      return parse_xml_text (xbuf);
1171
1171
    return "XmlReader";
1172
1172
  }
1173
1173
 
1174
 
  // make this document shared
1175
 
 
1176
 
  void XmlReader::mksho (void) {
1177
 
    if (p_shared != nilp) return;
1178
 
    Object::mksho ();
1179
 
    if (p_root != nilp) p_root->mksho ();
1180
 
  }
1181
 
 
1182
1174
  // reset this reader
1183
1175
 
1184
1176
  void XmlReader::reset (void) {
1204
1196
 
1205
1197
  // get the next available node
1206
1198
 
1207
 
  XmlNode* XmlReader::getnode (Input* is) {
 
1199
  XmlNode* XmlReader::getnode (InputStream* is) {
1208
1200
    // check the input stream
1209
1201
    if (is == nilp) return nilp;
1210
1202
    // create a xml stream
1234
1226
 
1235
1227
  XmlNode* XmlReader::getnode (const String& value) {
1236
1228
    // create an input stream
1237
 
    Input* is = new InputString (value);
 
1229
    InputStream* is = new InputString (value);
1238
1230
    // lock and parse
1239
1231
    wrlock ();
1240
1232
    try {
1251
1243
 
1252
1244
  // parse the input stream
1253
1245
 
1254
 
  void XmlReader::parse (Input* is) {
 
1246
  void XmlReader::parse (InputStream* is) {
1255
1247
    // check the input stream
1256
1248
    if (is == nilp) return;
1257
1249
    // create a xml stream
1285
1277
 
1286
1278
  void XmlReader::parse (const String& value) {
1287
1279
    // create an input stream
1288
 
    Input* is = new InputString (value);
 
1280
    InputStream* is = new InputString (value);
1289
1281
    // lock and parse
1290
1282
    wrlock ();
1291
1283
    try {
1364
1356
        Object* obj = argv->get (0);
1365
1357
        if (obj == nilp) return nilp;
1366
1358
        // check for an input stream
1367
 
        Input* is = dynamic_cast <Input*> (obj);
 
1359
        InputStream* is = dynamic_cast <InputStream*> (obj);
1368
1360
        if (is != nilp) {
1369
1361
          parse (is);
1370
1362
          return nilp;
1382
1374
        Object* obj = argv->get (0);
1383
1375
        if (obj == nilp) return nilp;
1384
1376
        // check for an input stream
1385
 
        Input* is = dynamic_cast <Input*> (obj);
 
1377
        InputStream* is = dynamic_cast <InputStream*> (obj);
1386
1378
        if (is != nilp) return getnode (is);
1387
1379
        // check for a string
1388
1380
        String* sobj = dynamic_cast <String*> (obj);