diff options
| author | Karl Heuer | 1994-11-18 02:02:18 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-11-18 02:02:18 +0000 |
| commit | e0f93814bf93d5205c1d2f7b92c61685848b1ed0 (patch) | |
| tree | 15d8a9825fde009e7fdb81b61e2e48710c7886c2 /src | |
| parent | 6d6432476c78812bf0bb88d4122da4c4c9888a2d (diff) | |
| download | emacs-e0f93814bf93d5205c1d2f7b92c61685848b1ed0.tar.gz emacs-e0f93814bf93d5205c1d2f7b92c61685848b1ed0.zip | |
(print): Use type test macros.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 297 |
1 files changed, 137 insertions, 160 deletions
diff --git a/src/print.c b/src/print.c index b07b770dadd..416cd32ce1b 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -745,39 +745,22 @@ print (obj, printcharfun, escapeflag) | |||
| 745 | } | 745 | } |
| 746 | #endif /* MAX_PRINT_CHARS */ | 746 | #endif /* MAX_PRINT_CHARS */ |
| 747 | 747 | ||
| 748 | #ifdef SWITCH_ENUM_BUG | 748 | if (INTEGERP (obj)) |
| 749 | switch ((int) XTYPE (obj)) | ||
| 750 | #else | ||
| 751 | switch (XTYPE (obj)) | ||
| 752 | #endif | ||
| 753 | { | 749 | { |
| 754 | default: | ||
| 755 | /* We're in trouble if this happens! | ||
| 756 | Probably should just abort () */ | ||
| 757 | strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun); | ||
| 758 | sprintf (buf, "(#o%3o)", (int) XTYPE (obj)); | ||
| 759 | strout (buf, -1, printcharfun); | ||
| 760 | strout (" Save your buffers immediately and please report this bug>", | ||
| 761 | -1, printcharfun); | ||
| 762 | break; | ||
| 763 | |||
| 764 | #ifdef LISP_FLOAT_TYPE | ||
| 765 | case Lisp_Float: | ||
| 766 | { | ||
| 767 | char pigbuf[350]; /* see comments in float_to_string */ | ||
| 768 | |||
| 769 | float_to_string (pigbuf, XFLOAT(obj)->data); | ||
| 770 | strout (pigbuf, -1, printcharfun); | ||
| 771 | } | ||
| 772 | break; | ||
| 773 | #endif /* LISP_FLOAT_TYPE */ | ||
| 774 | |||
| 775 | case Lisp_Int: | ||
| 776 | sprintf (buf, "%d", XINT (obj)); | 750 | sprintf (buf, "%d", XINT (obj)); |
| 777 | strout (buf, -1, printcharfun); | 751 | strout (buf, -1, printcharfun); |
| 778 | break; | 752 | } |
| 753 | #ifdef LISP_FLOAT_TYPE | ||
| 754 | else if (FLOATP (obj)) | ||
| 755 | { | ||
| 756 | char pigbuf[350]; /* see comments in float_to_string */ | ||
| 779 | 757 | ||
| 780 | case Lisp_String: | 758 | float_to_string (pigbuf, XFLOAT(obj)->data); |
| 759 | strout (pigbuf, -1, printcharfun); | ||
| 760 | } | ||
| 761 | #endif | ||
| 762 | else if (STRINGP (obj)) | ||
| 763 | { | ||
| 781 | if (!escapeflag) | 764 | if (!escapeflag) |
| 782 | print_string (obj, printcharfun); | 765 | print_string (obj, printcharfun); |
| 783 | else | 766 | else |
| @@ -831,85 +814,82 @@ print (obj, printcharfun, escapeflag) | |||
| 831 | 814 | ||
| 832 | UNGCPRO; | 815 | UNGCPRO; |
| 833 | } | 816 | } |
| 834 | break; | 817 | } |
| 835 | 818 | else if (SYMBOLP (obj)) | |
| 836 | case Lisp_Symbol: | 819 | { |
| 837 | { | 820 | register int confusing; |
| 838 | register int confusing; | 821 | register unsigned char *p = XSYMBOL (obj)->name->data; |
| 839 | register unsigned char *p = XSYMBOL (obj)->name->data; | 822 | register unsigned char *end = p + XSYMBOL (obj)->name->size; |
| 840 | register unsigned char *end = p + XSYMBOL (obj)->name->size; | 823 | register unsigned char c; |
| 841 | register unsigned char c; | 824 | |
| 842 | 825 | if (p != end && (*p == '-' || *p == '+')) p++; | |
| 843 | if (p != end && (*p == '-' || *p == '+')) p++; | 826 | if (p == end) |
| 844 | if (p == end) | 827 | confusing = 0; |
| 845 | confusing = 0; | 828 | else |
| 846 | else | 829 | { |
| 847 | { | 830 | while (p != end && *p >= '0' && *p <= '9') |
| 848 | while (p != end && *p >= '0' && *p <= '9') | 831 | p++; |
| 849 | p++; | 832 | confusing = (end == p); |
| 850 | confusing = (end == p); | 833 | } |
| 851 | } | ||
| 852 | |||
| 853 | p = XSYMBOL (obj)->name->data; | ||
| 854 | while (p != end) | ||
| 855 | { | ||
| 856 | QUIT; | ||
| 857 | c = *p++; | ||
| 858 | if (escapeflag) | ||
| 859 | { | ||
| 860 | if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' || | ||
| 861 | c == '(' || c == ')' || c == ',' || c =='.' || c == '`' || | ||
| 862 | c == '[' || c == ']' || c == '?' || c <= 040 || confusing) | ||
| 863 | PRINTCHAR ('\\'), confusing = 0; | ||
| 864 | } | ||
| 865 | PRINTCHAR (c); | ||
| 866 | } | ||
| 867 | } | ||
| 868 | break; | ||
| 869 | 834 | ||
| 870 | case Lisp_Cons: | 835 | p = XSYMBOL (obj)->name->data; |
| 836 | while (p != end) | ||
| 837 | { | ||
| 838 | QUIT; | ||
| 839 | c = *p++; | ||
| 840 | if (escapeflag) | ||
| 841 | { | ||
| 842 | if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' || | ||
| 843 | c == '(' || c == ')' || c == ',' || c =='.' || c == '`' || | ||
| 844 | c == '[' || c == ']' || c == '?' || c <= 040 || confusing) | ||
| 845 | PRINTCHAR ('\\'), confusing = 0; | ||
| 846 | } | ||
| 847 | PRINTCHAR (c); | ||
| 848 | } | ||
| 849 | } | ||
| 850 | else if (CONSP (obj)) | ||
| 851 | { | ||
| 871 | /* If deeper than spec'd depth, print placeholder. */ | 852 | /* If deeper than spec'd depth, print placeholder. */ |
| 872 | if (INTEGERP (Vprint_level) | 853 | if (INTEGERP (Vprint_level) |
| 873 | && print_depth > XINT (Vprint_level)) | 854 | && print_depth > XINT (Vprint_level)) |
| 855 | strout ("...", -1, printcharfun); | ||
| 856 | else | ||
| 874 | { | 857 | { |
| 875 | strout ("...", -1, printcharfun); | 858 | PRINTCHAR ('('); |
| 876 | break; | ||
| 877 | } | ||
| 878 | |||
| 879 | PRINTCHAR ('('); | ||
| 880 | { | ||
| 881 | register int i = 0; | ||
| 882 | register int max = 0; | ||
| 883 | |||
| 884 | if (INTEGERP (Vprint_length)) | ||
| 885 | max = XINT (Vprint_length); | ||
| 886 | /* Could recognize circularities in cdrs here, | ||
| 887 | but that would make printing of long lists quadratic. | ||
| 888 | It's not worth doing. */ | ||
| 889 | while (CONSP (obj)) | ||
| 890 | { | 859 | { |
| 891 | if (i++) | 860 | register int i = 0; |
| 892 | PRINTCHAR (' '); | 861 | register int max = 0; |
| 893 | if (max && i > max) | 862 | |
| 863 | if (INTEGERP (Vprint_length)) | ||
| 864 | max = XINT (Vprint_length); | ||
| 865 | /* Could recognize circularities in cdrs here, | ||
| 866 | but that would make printing of long lists quadratic. | ||
| 867 | It's not worth doing. */ | ||
| 868 | while (CONSP (obj)) | ||
| 894 | { | 869 | { |
| 895 | strout ("...", 3, printcharfun); | 870 | if (i++) |
| 896 | break; | 871 | PRINTCHAR (' '); |
| 872 | if (max && i > max) | ||
| 873 | { | ||
| 874 | strout ("...", 3, printcharfun); | ||
| 875 | break; | ||
| 876 | } | ||
| 877 | print (Fcar (obj), printcharfun, escapeflag); | ||
| 878 | obj = Fcdr (obj); | ||
| 897 | } | 879 | } |
| 898 | print (Fcar (obj), printcharfun, escapeflag); | ||
| 899 | obj = Fcdr (obj); | ||
| 900 | } | 880 | } |
| 901 | } | 881 | if (!NILP (obj) && !CONSP (obj)) |
| 902 | if (!NILP (obj) && !CONSP (obj)) | 882 | { |
| 903 | { | 883 | strout (" . ", 3, printcharfun); |
| 904 | strout (" . ", 3, printcharfun); | 884 | print (obj, printcharfun, escapeflag); |
| 905 | print (obj, printcharfun, escapeflag); | 885 | } |
| 886 | PRINTCHAR (')'); | ||
| 906 | } | 887 | } |
| 907 | PRINTCHAR (')'); | 888 | } |
| 908 | break; | 889 | else if (COMPILEDP (obj) || VECTORP (obj)) |
| 909 | 890 | { | |
| 910 | case Lisp_Compiled: | 891 | if (COMPILEDP (obj)) |
| 911 | strout ("#", -1, printcharfun); | 892 | PRINTCHAR ('#'); |
| 912 | case Lisp_Vector: | ||
| 913 | PRINTCHAR ('['); | 893 | PRINTCHAR ('['); |
| 914 | { | 894 | { |
| 915 | register int i; | 895 | register int i; |
| @@ -922,10 +902,10 @@ print (obj, printcharfun, escapeflag) | |||
| 922 | } | 902 | } |
| 923 | } | 903 | } |
| 924 | PRINTCHAR (']'); | 904 | PRINTCHAR (']'); |
| 925 | break; | 905 | } |
| 926 | |||
| 927 | #ifndef standalone | 906 | #ifndef standalone |
| 928 | case Lisp_Buffer: | 907 | else if (BUFFERP (obj)) |
| 908 | { | ||
| 929 | if (NILP (XBUFFER (obj)->name)) | 909 | if (NILP (XBUFFER (obj)->name)) |
| 930 | strout ("#<killed buffer>", -1, printcharfun); | 910 | strout ("#<killed buffer>", -1, printcharfun); |
| 931 | else if (escapeflag) | 911 | else if (escapeflag) |
| @@ -936,9 +916,9 @@ print (obj, printcharfun, escapeflag) | |||
| 936 | } | 916 | } |
| 937 | else | 917 | else |
| 938 | print_string (XBUFFER (obj)->name, printcharfun); | 918 | print_string (XBUFFER (obj)->name, printcharfun); |
| 939 | break; | 919 | } |
| 940 | 920 | else if (PROCESSP (obj)) | |
| 941 | case Lisp_Process: | 921 | { |
| 942 | if (escapeflag) | 922 | if (escapeflag) |
| 943 | { | 923 | { |
| 944 | strout ("#<process ", -1, printcharfun); | 924 | strout ("#<process ", -1, printcharfun); |
| @@ -947,9 +927,9 @@ print (obj, printcharfun, escapeflag) | |||
| 947 | } | 927 | } |
| 948 | else | 928 | else |
| 949 | print_string (XPROCESS (obj)->name, printcharfun); | 929 | print_string (XPROCESS (obj)->name, printcharfun); |
| 950 | break; | 930 | } |
| 951 | 931 | else if (WINDOWP (obj)) | |
| 952 | case Lisp_Window: | 932 | { |
| 953 | strout ("#<window ", -1, printcharfun); | 933 | strout ("#<window ", -1, printcharfun); |
| 954 | sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number)); | 934 | sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number)); |
| 955 | strout (buf, -1, printcharfun); | 935 | strout (buf, -1, printcharfun); |
| @@ -959,72 +939,69 @@ print (obj, printcharfun, escapeflag) | |||
| 959 | print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun); | 939 | print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun); |
| 960 | } | 940 | } |
| 961 | PRINTCHAR ('>'); | 941 | PRINTCHAR ('>'); |
| 962 | break; | 942 | } |
| 963 | 943 | else if (WINDOW_CONFIGURATIONP (obj)) | |
| 964 | case Lisp_Window_Configuration: | 944 | { |
| 965 | strout ("#<window-configuration>", -1, printcharfun); | 945 | strout ("#<window-configuration>", -1, printcharfun); |
| 966 | break; | 946 | } |
| 967 | |||
| 968 | #ifdef MULTI_FRAME | 947 | #ifdef MULTI_FRAME |
| 969 | case Lisp_Frame: | 948 | else if (FRAMEP (obj)) |
| 949 | { | ||
| 970 | strout ((FRAME_LIVE_P (XFRAME (obj)) | 950 | strout ((FRAME_LIVE_P (XFRAME (obj)) |
| 971 | ? "#<frame " : "#<dead frame "), | 951 | ? "#<frame " : "#<dead frame "), |
| 972 | -1, printcharfun); | 952 | -1, printcharfun); |
| 973 | print_string (XFRAME (obj)->name, printcharfun); | 953 | print_string (XFRAME (obj)->name, printcharfun); |
| 974 | if (sizeof (EMACS_INT) > 4) | 954 | sprintf (buf, " 0x%lx", (unsigned long) (XFRAME (obj))); |
| 975 | sprintf (buf, " 0x%lx", (EMACS_UINT) (XFRAME (obj))); | ||
| 976 | else | ||
| 977 | sprintf (buf, " 0x%x", (EMACS_UINT) (XFRAME (obj))); | ||
| 978 | strout (buf, -1, printcharfun); | 955 | strout (buf, -1, printcharfun); |
| 979 | strout (">", -1, printcharfun); | 956 | PRINTCHAR ('>'); |
| 980 | break; | 957 | } |
| 981 | #endif /* MULTI_FRAME */ | 958 | #endif |
| 982 | 959 | else if (MARKERP (obj)) | |
| 983 | case Lisp_Misc: | 960 | { |
| 984 | switch (XMISC (obj)->type) | 961 | strout ("#<marker ", -1, printcharfun); |
| 962 | if (!(XMARKER (obj)->buffer)) | ||
| 963 | strout ("in no buffer", -1, printcharfun); | ||
| 964 | else | ||
| 985 | { | 965 | { |
| 986 | case Lisp_Misc_Marker: | 966 | sprintf (buf, "at %d", marker_position (obj)); |
| 987 | strout ("#<marker ", -1, printcharfun); | 967 | strout (buf, -1, printcharfun); |
| 988 | if (!(XMARKER (obj)->buffer)) | 968 | strout (" in ", -1, printcharfun); |
| 989 | strout ("in no buffer", -1, printcharfun); | 969 | print_string (XMARKER (obj)->buffer->name, printcharfun); |
| 990 | else | ||
| 991 | { | ||
| 992 | sprintf (buf, "at %d", marker_position (obj)); | ||
| 993 | strout (buf, -1, printcharfun); | ||
| 994 | strout (" in ", -1, printcharfun); | ||
| 995 | print_string (XMARKER (obj)->buffer->name, printcharfun); | ||
| 996 | } | ||
| 997 | PRINTCHAR ('>'); | ||
| 998 | break; | ||
| 999 | |||
| 1000 | case Lisp_Misc_Overlay: | ||
| 1001 | strout ("#<overlay ", -1, printcharfun); | ||
| 1002 | if (!(XMARKER (OVERLAY_START (obj))->buffer)) | ||
| 1003 | strout ("in no buffer", -1, printcharfun); | ||
| 1004 | else | ||
| 1005 | { | ||
| 1006 | sprintf (buf, "from %d to %d in ", | ||
| 1007 | marker_position (OVERLAY_START (obj)), | ||
| 1008 | marker_position (OVERLAY_END (obj))); | ||
| 1009 | strout (buf, -1, printcharfun); | ||
| 1010 | print_string (XMARKER (OVERLAY_START (obj))->buffer->name, | ||
| 1011 | printcharfun); | ||
| 1012 | } | ||
| 1013 | PRINTCHAR ('>'); | ||
| 1014 | break; | ||
| 1015 | |||
| 1016 | default: | ||
| 1017 | abort (); | ||
| 1018 | } | 970 | } |
| 1019 | break; | 971 | PRINTCHAR ('>'); |
| 1020 | 972 | } | |
| 973 | else if (OVERLAYP (obj)) | ||
| 974 | { | ||
| 975 | strout ("#<overlay ", -1, printcharfun); | ||
| 976 | if (!(XMARKER (OVERLAY_START (obj))->buffer)) | ||
| 977 | strout ("in no buffer", -1, printcharfun); | ||
| 978 | else | ||
| 979 | { | ||
| 980 | sprintf (buf, "from %d to %d in ", | ||
| 981 | marker_position (OVERLAY_START (obj)), | ||
| 982 | marker_position (OVERLAY_END (obj))); | ||
| 983 | strout (buf, -1, printcharfun); | ||
| 984 | print_string (XMARKER (OVERLAY_START (obj))->buffer->name, | ||
| 985 | printcharfun); | ||
| 986 | } | ||
| 987 | PRINTCHAR ('>'); | ||
| 988 | } | ||
| 1021 | #endif /* standalone */ | 989 | #endif /* standalone */ |
| 1022 | 990 | else if (SUBRP (obj)) | |
| 1023 | case Lisp_Subr: | 991 | { |
| 1024 | strout ("#<subr ", -1, printcharfun); | 992 | strout ("#<subr ", -1, printcharfun); |
| 1025 | strout (XSUBR (obj)->symbol_name, -1, printcharfun); | 993 | strout (XSUBR (obj)->symbol_name, -1, printcharfun); |
| 1026 | PRINTCHAR ('>'); | 994 | PRINTCHAR ('>'); |
| 1027 | break; | 995 | } |
| 996 | else | ||
| 997 | { | ||
| 998 | /* We're in trouble if this happens! | ||
| 999 | Probably should just abort () */ | ||
| 1000 | strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun); | ||
| 1001 | sprintf (buf, "(#o%3o)", (int) XTYPE (obj)); | ||
| 1002 | strout (buf, -1, printcharfun); | ||
| 1003 | strout (" Save your buffers immediately and please report this bug>", | ||
| 1004 | -1, printcharfun); | ||
| 1028 | } | 1005 | } |
| 1029 | 1006 | ||
| 1030 | print_depth--; | 1007 | print_depth--; |