aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/make-docfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src/make-docfile.c')
-rw-r--r--lib-src/make-docfile.c105
1 files changed, 87 insertions, 18 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 4f68fdb78c9..bd87b5b6524 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -76,7 +76,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
76static int scan_file (char *filename); 76static int scan_file (char *filename);
77static int scan_lisp_file (const char *filename, const char *mode); 77static int scan_lisp_file (const char *filename, const char *mode);
78static int scan_c_file (char *filename, const char *mode); 78static int scan_c_file (char *filename, const char *mode);
79static void fatal (const char *s1, const char *s2) NO_RETURN;
80static void start_globals (void); 79static void start_globals (void);
81static void write_globals (void); 80static void write_globals (void);
82 81
@@ -111,7 +110,7 @@ error (const char *s1, const char *s2)
111/* Print error message and exit. */ 110/* Print error message and exit. */
112 111
113/* VARARGS1 */ 112/* VARARGS1 */
114static void 113static _Noreturn void
115fatal (const char *s1, const char *s2) 114fatal (const char *s1, const char *s2)
116{ 115{
117 error (s1, s2); 116 error (s1, s2);
@@ -542,7 +541,7 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
542 541
543 /* In C code, `default' is a reserved word, so we spell it 542 /* In C code, `default' is a reserved word, so we spell it
544 `defalt'; demangle that here. */ 543 `defalt'; demangle that here. */
545 if (ident_length == 6 && strncmp (ident_start, "defalt", 6) == 0) 544 if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0)
546 fprintf (out, "DEFAULT"); 545 fprintf (out, "DEFAULT");
547 else 546 else
548 while (ident_length-- > 0) 547 while (ident_length-- > 0)
@@ -565,6 +564,7 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
565/* The types of globals. */ 564/* The types of globals. */
566enum global_type 565enum global_type
567{ 566{
567 FUNCTION,
568 EMACS_INTEGER, 568 EMACS_INTEGER,
569 BOOLEAN, 569 BOOLEAN,
570 LISP_OBJECT, 570 LISP_OBJECT,
@@ -576,6 +576,7 @@ struct global
576{ 576{
577 enum global_type type; 577 enum global_type type;
578 char *name; 578 char *name;
579 int value;
579}; 580};
580 581
581/* All the variable names we saw while scanning C sources in `-g' 582/* All the variable names we saw while scanning C sources in `-g'
@@ -585,7 +586,7 @@ int num_globals_allocated;
585struct global *globals; 586struct global *globals;
586 587
587static void 588static void
588add_global (enum global_type type, char *name) 589add_global (enum global_type type, char *name, int value)
589{ 590{
590 /* Ignore the one non-symbol that can occur. */ 591 /* Ignore the one non-symbol that can occur. */
591 if (strcmp (name, "...")) 592 if (strcmp (name, "..."))
@@ -606,6 +607,7 @@ add_global (enum global_type type, char *name)
606 607
607 globals[num_globals - 1].type = type; 608 globals[num_globals - 1].type = type;
608 globals[num_globals - 1].name = name; 609 globals[num_globals - 1].name = name;
610 globals[num_globals - 1].value = value;
609 } 611 }
610} 612}
611 613
@@ -614,13 +616,29 @@ compare_globals (const void *a, const void *b)
614{ 616{
615 const struct global *ga = a; 617 const struct global *ga = a;
616 const struct global *gb = b; 618 const struct global *gb = b;
619
620 if (ga->type == FUNCTION)
621 {
622 if (gb->type != FUNCTION)
623 return 1;
624 }
625 else if (gb->type == FUNCTION)
626 return -1;
627
617 return strcmp (ga->name, gb->name); 628 return strcmp (ga->name, gb->name);
618} 629}
619 630
620static void 631static void
632close_emacs_globals (void)
633{
634 fprintf (outfile, "};\n");
635 fprintf (outfile, "extern struct emacs_globals globals;\n");
636}
637
638static void
621write_globals (void) 639write_globals (void)
622{ 640{
623 int i; 641 int i, seen_defun = 0;
624 qsort (globals, num_globals, sizeof (struct global), compare_globals); 642 qsort (globals, num_globals, sizeof (struct global), compare_globals);
625 for (i = 0; i < num_globals; ++i) 643 for (i = 0; i < num_globals; ++i)
626 { 644 {
@@ -637,20 +655,55 @@ write_globals (void)
637 case LISP_OBJECT: 655 case LISP_OBJECT:
638 type = "Lisp_Object"; 656 type = "Lisp_Object";
639 break; 657 break;
658 case FUNCTION:
659 if (!seen_defun)
660 {
661 close_emacs_globals ();
662 fprintf (outfile, "\n");
663 seen_defun = 1;
664 }
665 break;
640 default: 666 default:
641 fatal ("not a recognized DEFVAR_", 0); 667 fatal ("not a recognized DEFVAR_", 0);
642 } 668 }
643 669
644 fprintf (outfile, " %s f_%s;\n", type, globals[i].name); 670 if (globals[i].type != FUNCTION)
645 fprintf (outfile, "#define %s globals.f_%s\n", 671 {
646 globals[i].name, globals[i].name); 672 fprintf (outfile, " %s f_%s;\n", type, globals[i].name);
673 fprintf (outfile, "#define %s globals.f_%s\n",
674 globals[i].name, globals[i].name);
675 }
676 else
677 {
678 /* It would be nice to have a cleaner way to deal with these
679 special hacks. */
680 if (strcmp (globals[i].name, "Fthrow") == 0
681 || strcmp (globals[i].name, "Ftop_level") == 0
682 || strcmp (globals[i].name, "Fkill_emacs") == 0)
683 fprintf (outfile, "_Noreturn ");
684 fprintf (outfile, "EXFUN (%s, ", globals[i].name);
685 if (globals[i].value == -1)
686 fprintf (outfile, "MANY");
687 else if (globals[i].value == -2)
688 fprintf (outfile, "UNEVALLED");
689 else
690 fprintf (outfile, "%d", globals[i].value);
691 fprintf (outfile, ");\n");
692 }
693
647 while (i + 1 < num_globals 694 while (i + 1 < num_globals
648 && !strcmp (globals[i].name, globals[i + 1].name)) 695 && !strcmp (globals[i].name, globals[i + 1].name))
649 ++i; 696 {
697 if (globals[i].type == FUNCTION
698 && globals[i].value != globals[i + 1].value)
699 error ("function '%s' defined twice with differing signatures",
700 globals[i].name);
701 ++i;
702 }
650 } 703 }
651 704
652 fprintf (outfile, "};\n"); 705 if (!seen_defun)
653 fprintf (outfile, "extern struct emacs_globals globals;\n"); 706 close_emacs_globals ();
654} 707}
655 708
656 709
@@ -700,6 +753,7 @@ scan_c_file (char *filename, const char *mode)
700 int defvarperbufferflag = 0; 753 int defvarperbufferflag = 0;
701 int defvarflag = 0; 754 int defvarflag = 0;
702 enum global_type type = INVALID; 755 enum global_type type = INVALID;
756 char *name IF_LINT (= 0);
703 757
704 if (c != '\n' && c != '\r') 758 if (c != '\n' && c != '\r')
705 { 759 {
@@ -765,8 +819,9 @@ scan_c_file (char *filename, const char *mode)
765 } 819 }
766 else continue; 820 else continue;
767 821
768 if (generate_globals && (!defvarflag || defvarperbufferflag 822 if (generate_globals
769 || type == INVALID)) 823 && (!defvarflag || defvarperbufferflag || type == INVALID)
824 && !defunflag)
770 continue; 825 continue;
771 826
772 while (c != '(') 827 while (c != '(')
@@ -785,7 +840,6 @@ scan_c_file (char *filename, const char *mode)
785 if (generate_globals) 840 if (generate_globals)
786 { 841 {
787 int i = 0; 842 int i = 0;
788 char *name;
789 843
790 /* Skip "," and whitespace. */ 844 /* Skip "," and whitespace. */
791 do 845 do
@@ -806,8 +860,12 @@ scan_c_file (char *filename, const char *mode)
806 860
807 name = xmalloc (i + 1); 861 name = xmalloc (i + 1);
808 memcpy (name, input_buffer, i + 1); 862 memcpy (name, input_buffer, i + 1);
809 add_global (type, name); 863
810 continue; 864 if (!defunflag)
865 {
866 add_global (type, name, 0);
867 continue;
868 }
811 } 869 }
812 870
813 /* DEFVAR_LISP ("name", addr, "doc") 871 /* DEFVAR_LISP ("name", addr, "doc")
@@ -815,7 +873,7 @@ scan_c_file (char *filename, const char *mode)
815 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */ 873 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
816 874
817 if (defunflag) 875 if (defunflag)
818 commas = 5; 876 commas = generate_globals ? 4 : 5;
819 else if (defvarperbufferflag) 877 else if (defvarperbufferflag)
820 commas = 3; 878 commas = 3;
821 else if (defvarflag) 879 else if (defvarflag)
@@ -842,7 +900,12 @@ scan_c_file (char *filename, const char *mode)
842 scanned = fscanf (infile, "%d", &minargs); 900 scanned = fscanf (infile, "%d", &minargs);
843 else /* Pick up maxargs. */ 901 else /* Pick up maxargs. */
844 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ 902 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
845 maxargs = -1; 903 {
904 if (generate_globals)
905 maxargs = (c == 'M') ? -1 : -2;
906 else
907 maxargs = -1;
908 }
846 else 909 else
847 scanned = fscanf (infile, "%d", &maxargs); 910 scanned = fscanf (infile, "%d", &maxargs);
848 if (scanned < 0) 911 if (scanned < 0)
@@ -855,6 +918,12 @@ scan_c_file (char *filename, const char *mode)
855 c = getc (infile); 918 c = getc (infile);
856 } 919 }
857 920
921 if (generate_globals)
922 {
923 add_global (FUNCTION, name, maxargs);
924 continue;
925 }
926
858 while (c == ' ' || c == '\n' || c == '\r' || c == '\t') 927 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
859 c = getc (infile); 928 c = getc (infile);
860 929