소스 검색

- made some of the bit shifting attribute access simpler (in my mind)

- added extern declarations for global vars
- removed comments from static inlines (too time consuming to do them
  all, considering all so far have been due to the ridiculous amount of
  redundancy within the API spec)
- removed a few more extern func decls for funcs that cannot be
  implemented at this time
tags/v0.9.3
Dan Lynch 18 년 전
부모
커밋
acf572905c
1개의 변경된 파일50개의 추가작업 그리고 248개의 파일을 삭제
  1. 50
    248
      src/include/curses.h

+ 50
- 248
src/include/curses.h 파일 보기

@@ -68,21 +68,33 @@ typedef struct _curses_window {
68 68
 } WINDOW;
69 69
 
70 70
 extern WINDOW _stdscr;
71
+extern SCREEN _curscr;
72
+extern unsigned short _COLS;
73
+extern unsigned short _LINES;
74
+extern unsigned short _COLOURS;
75
+extern unsigned int *_COLOUR_PAIRS;
76
+
71 77
 #define stdscr ( &_stdscr )
78
+#define curscr ( &_curscr )
79
+#define COLS _COLS
80
+#define LINES _LINES
81
+#define COLORS _COLOURS
82
+#define COLOR_PAIRS COLOUR_PAIRS
72 83
 
73
-#define MUCURSES_ATTR_SHIFT	16
74
-#define MUCURSES_BITS( mask, shift ) (( mask ) << (( shift ) + MUCURSES_ATTR_SHIFT ))
84
+#define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
85
+#define CPAIR_SHIFT	8
86
+#define ATTRS_SHIFT	16
75 87
 
76 88
 #define A_DEFAULT	( 1UL - 1UL )
77
-#define A_ALTCHARSET	MUCURSES_BITS( 1UL, 0 )
78
-#define A_BLINK		MUCURSES_BITS( 1UL, 1 )
79
-#define A_BOLD		MUCURSES_BITS( 1UL, 2 )
80
-#define A_DIM		MUCURSES_BITS( 1UL, 3 )
81
-#define A_INVIS		MUCURSES_BITS( 1UL, 4 )
82
-#define A_PROTECT	MUCURSES_BITS( 1UL, 5 )
83
-#define A_REVERSE	MUCURSES_BITS( 1UL, 6 )
84
-#define A_STANDOUT	MUCURSES_BITS( 1UL, 7 )
85
-#define A_UNDERLINE	MUCURSES_BITS( 1UL, 8 )
89
+#define A_ALTCHARSET	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 0 )
90
+#define A_BLINK		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 1 )
91
+#define A_BOLD		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 2 )
92
+#define A_DIM		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 3 )
93
+#define A_INVIS		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 4 )
94
+#define A_PROTECT	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 5 )
95
+#define A_REVERSE	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 6 )
96
+#define A_STANDOUT	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 7 )
97
+#define A_UNDERLINE	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 8 )
86 98
 
87 99
 #define WA_ALTCHARSET	A_ALTCHARSET
88 100
 #define WA_BLINK	A_BLINK
@@ -93,16 +105,16 @@ extern WINDOW _stdscr;
93 105
 #define WA_REVERSE	A_REVERSE
94 106
 #define WA_STANDOUT	A_STANDOUT
95 107
 #define WA_UNDERLINE	A_UNDERLINE
96
-#define WA_HORIZONTAL	MUCURSES_BITS( 1UL, 9 )
97
-#define WA_VERTICAL	MUCURSES_BITS( 1UL, 10 )
98
-#define WA_LEFT		MUCURSES_BITS( 1UL, 11 )
99
-#define WA_RIGHT	MUCURSES_BITS( 1UL, 12 )
100
-#define WA_LOW		MUCURSES_BITS( 1UL, 13 )
101
-#define WA_TOP		MUCURSES_BITS( 1UL, 14 )
102
-
103
-#define A_ATTRIBUTES	MUCURSES_BITS( ~( 1UL - 1UL ), 0 )
108
+#define WA_HORIZONTAL	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 9 )
109
+#define WA_VERTICAL	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 10 )
110
+#define WA_LEFT		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 11 )
111
+#define WA_RIGHT	MUCURSES_BITS( 1UL, ATTRS_SHIFT + 12 )
112
+#define WA_LOW		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 13 )
113
+#define WA_TOP		MUCURSES_BITS( 1UL, ATTRS_SHIFT + 14 )
114
+
115
+#define A_ATTRIBUTES	( MUCURSES_BITS( 1UL, ATTRS_SHIFT ) - 1UL )
104 116
 #define A_CHARTEXT	( MUCURSES_BITS( 1UL, 0 ) - 1UL )
105
-#define A_COLOR		MUCURSES_BITS( ( 1UL << 8 ) - 1UL, 0 )
117
+#define A_COLOR		MUCURSES_BITS( ( 1UL << 8 ) - 1UL, CPAIR_SHIFT )
106 118
 
107 119
 #define ACS_ULCORNER	'+'
108 120
 #define ACS_LLCORNER	'+'
@@ -258,7 +270,6 @@ extern int attr_on ( attr_t, void * );
258 270
 extern int attr_set ( attr_t, short, void * );
259 271
 extern int baudrate ( void );
260 272
 extern int beep ( void );
261
-/*extern int bkgd ( chtype );*/
262 273
 /*extern void bkgdset ( chtype );*/
263 274
 /*extern int border ( chtype, chtype, chtype, chtype, chtype, chtype, chtype,
264 275
   chtype );*/
@@ -266,15 +277,12 @@ extern int box ( WINDOW *, chtype, chtype );
266 277
 extern bool can_change_colour ( void );
267 278
 #define can_change_color() can_change_colour()
268 279
 extern int cbreak ( void ); 
269
-extern int chgat ( int, attr_t, short, const void * );
270
-extern int clearok ( WINDOW *, bool );
271
-extern int clear ( void );
272
-extern int clrtobot ( void );
273
-extern int clrtoeol ( void );
280
+/*extern int clrtobot ( void );*/
281
+/*extern int clrtoeol ( void );*/
274 282
 extern int colour_content ( short, short *, short *, short * );
275 283
 #define color_content( col, r, g, b ) colour_content( (col), (r), (g), (b) )
276
-extern int colour_set ( short, void * );
277
-#define color_set( cpno, opts ) colour_set( (cpno), (opts) )
284
+/*extern int colour_set ( short, void * );*/
285
+/*#define color_set( cpno, opts ) colour_set( (cpno), (opts) )*/
278 286
 extern int copywin ( const WINDOW *, WINDOW *, int, int, int, 
279 287
 		     int, int, int, int );
280 288
 extern int curs_set ( int );
@@ -337,7 +345,6 @@ extern int meta ( WINDOW *, bool );
337 345
 /*extern int mvaddchstr ( int, int, const chtype * );*/
338 346
 /*extern int mvaddnstr ( int, int, const char *, int );*/
339 347
 /*extern int mvaddstr ( int, int, const char * );*/
340
-extern int mvchgat ( int, int, int, attr_t, short, const void * );
341 348
 extern int mvcur ( int, int, int, int );
342 349
 extern int mvdelch ( int, int );
343 350
 extern int mvderwin ( WINDOW *, int, int );
@@ -361,7 +368,6 @@ extern int mvvline ( int, int, chtype, int );
361 368
 /*extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );*/
362 369
 /*extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );*/
363 370
 /*extern int mvwaddstr ( WINDOW *, int, int, const char * );*/
364
-extern int mvwchgat ( WINDOW *, int, int, int, attr_t, short, const void * );
365 371
 extern int mvwdelch ( WINDOW *, int, int );
366 372
 extern int mvwgetch ( WINDOW *, int, int );
367 373
 extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
@@ -476,16 +482,14 @@ extern int wattr_get ( WINDOW *, attr_t *, short *, void * );
476 482
 extern int wattr_off ( WINDOW *, attr_t, void * );
477 483
 extern int wattr_on ( WINDOW *, attr_t, void * );
478 484
 extern int wattr_set ( WINDOW *, attr_t, short, void * );
479
-extern int wbkgd ( WINDOW *, chtype );
480 485
 /*extern void wbkgdset ( WINDOW *, chtype );*/
481 486
 extern int wborder ( WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
482 487
 		   chtype, chtype );
483
-extern int wchgat ( WINDOW *, int, attr_t, short, const void * );
484
-extern int wclear ( WINDOW * );
485 488
 extern int wclrtobot ( WINDOW * );
486 489
 extern int wclrtoeol ( WINDOW * );
487 490
 extern void wcursyncup ( WINDOW * );
488
-extern int wcolor_set ( WINDOW *, short, void * );
491
+/*extern int wcolor_set ( WINDOW *, short, void * );*/
492
+#define wcolor_set(w,s,v) wcolour_set((w),(s),(v))
489 493
 extern int wdelch ( WINDOW * );
490 494
 extern int wdeleteln ( WINDOW * );
491 495
 extern int wechochar ( WINDOW *, const chtype );
@@ -520,326 +524,124 @@ extern void wtimeout ( WINDOW *, int );
520 524
 extern int wtouchln ( WINDOW *, int, int, int );
521 525
 extern int wvline ( WINDOW *, chtype, int );
522 526
 
523
-#define COLOUR_PAIR(n)	MUCURSES_BITS( (n), -8 )
524
-#define COLOR_PAIR(n)	COLOUR_PAIR(n)
525
-
526 527
 /*
527
- * static inlines
528
+ * There is frankly a ridiculous amount of redundancy within the
529
+ * curses API - ncurses decided to get around this by using #define
530
+ * macros, but I've decided to be type-safe and implement them all as
531
+ * static inlines instead...
528 532
  */
529 533
 
530
-/**
531
- * Add a single-byte character and rendition to stdscr and advance the
532
- * cursor
533
- *
534
- * @v ch	character to be added at cursor
535
- * @ret rc	return status code
536
- */
537 534
 static inline int addch ( const chtype ch ) {
538 535
 	return waddch( stdscr, ch );
539 536
 }
540 537
 
541
-/**
542
- * Add string of single-byte characters and renditions to stdscr
543
- *
544
- * @v *chstr	pointer to first chtype in "string"
545
- * @v n		number of chars from chstr to render
546
- * @ret rc	return status code
547
- */
548 538
 static inline int addchnstr ( const chtype *chstr, int n ) {
549 539
 	return waddchnstr ( stdscr, chstr, n );
550 540
 }
551 541
 
552
-/**
553
- * Add string of single-byte characters and renditions to stdscr
554
- *
555
- * @v *chstr	pointer to first chtype in "string"
556
- * @ret rc	return status code
557
- */
558 542
 static inline int addchstr ( const chtype *chstr ) {
559 543
 	return waddchnstr ( stdscr, chstr, -1 );
560 544
 }
561 545
 
562
-/**
563
- * Add string of single-byte characters to stdscr
564
- *
565
- * @v *str	standard c-style string
566
- * @v n		max number of chars from string to render
567
- * @ret rc	return status code
568
- */
569 546
 static inline int addnstr ( const char *str, int n ) {
570 547
 	return waddnstr ( stdscr, str, n );
571 548
 }
572 549
 
573
-/**
574
- * Add string of single-byte characters to stdscr
575
- *
576
- * @v *str	standard c-style string
577
- * @ret rc	return status code
578
- */
579 550
 static inline int addstr ( const char *str ) {
580 551
 	return waddnstr ( stdscr, str, -1 );
581 552
 }
582 553
 
583
-/**
584
- * Turn off attributes
585
- *
586
- * @v win	subject window
587
- * @v attrs	attributes to enable
588
- * @ret rc	return status code
589
- */
590 554
 static inline int attroff ( int attrs ) {
591 555
 	return wattroff ( stdscr, attrs );
592 556
 }
593 557
 
594
-/**
595
- * Turn on attributes
596
- *
597
- * @v win	subject window
598
- * @v attrs	attributes to enable
599
- * @ret rc	return status code
600
- */
601 558
 static inline int attron ( int attrs ) {
602 559
 	return wattron ( stdscr, attrs );
603 560
 }
604 561
 
605
-/**
606
- * Set attributes
607
- *
608
- * @v win	subject window
609
- * @v attrs	attributes to enable
610
- * @ret rc	return status code
611
- */
612 562
 static inline int attrset ( int attrs ) {
613 563
 	return wattrset ( stdscr, attrs );
614 564
 }
615 565
 
616
-/**
617
- * Set background rendition attributes for stdscr and apply to
618
- * contents
619
- *
620
- * @v ch	chtype containing rendition attributes
621
- * @ret rc	return status code
622
- */
623
-static inline int bkgd ( chtype ch ) {
624
-	return wbkgd ( stdscr, ch );
625
-}
626
-
627
-/**
628
- * Set background rendition attributes for stdscr
629
- */
630 566
 static inline void bkgdset ( chtype ch ) {
631 567
 	wattrset ( stdscr, ch );
632 568
 }
633 569
 
634
-/**
635
- * Draw borders from single-byte characters and renditions around
636
- * stdscr
637
- *
638
- * @v ls	left side
639
- * @v rs	right side
640
- * @v ts	top
641
- * @v bs	bottom
642
- * @v tl	top left corner
643
- * @v tr	top right corner
644
- * @v bl	bottom left corner
645
- * @v br	bottom right corner
646
- * @ret rc	return status code
647
- */
648 570
 static inline int border ( chtype ls, chtype rs, chtype ts, chtype bs,
649 571
 			   chtype tl, chtype tr, chtype bl, chtype br ) {
650 572
 	return wborder ( stdscr, ls, rs, ts, bs, tl, tr, bl, br );
651 573
 }
652 574
 
653
-/**
654
- * Move stdscr cursor to the specified position
655
- *
656
- * @v y		Y position
657
- * @v x		X position
658
- * @ret rc	return status code
659
- */
575
+static inline int clrtobot ( void ) {
576
+	return wclrtobot( stdscr );
577
+}
578
+
579
+static inline int clrtoeol ( void ) {
580
+	return wclrtoeol( stdscr );
581
+}
582
+
660 583
 static inline int move ( int y, int x ) {
661 584
 	return wmove ( stdscr, y, x );
662 585
 }
663 586
 
664
-/**
665
- * Add a single-byte character and rendition to stdscr at the
666
- * specified position and advance the cursor
667
- *
668
- * @v y		Y position
669
- * @v x		X position
670
- * @v ch	character to be added at cursor
671
- * @ret rc	return status code
672
- */
673 587
 static inline int mvaddch ( int y, int x, const chtype ch ) {
674 588
 	return ( wmove ( stdscr, y, x ) == ERR 
675 589
 		 ? ERR : waddch( stdscr, ch ) );
676 590
 }
677 591
 
678
-/**
679
- * Add string of single-byte characters and renditions to stdscr at
680
- * the specified position
681
- *
682
- * @v y		Y position
683
- * @v x		X position
684
- * @v *chstr	pointer to first chtype in "string"
685
- * @v n		max number of chars from chstr to render
686
- * @ret rc	return status code
687
- */
688 592
 static inline int mvaddchnstr ( int y, int x, const chtype *chstr, int n ) {
689 593
 	return ( wmove ( stdscr, y, x ) == ERR
690 594
 		 ? ERR : waddchnstr ( stdscr, chstr, n ) );
691 595
 }
692 596
 
693
-/**
694
- * Add string of single-byte characters and renditions to stdscr at
695
- * the specified position
696
- *
697
- * @v y		Y position
698
- * @v x		X position
699
- * @v *chstr	pointer to first chtype in "string"
700
- * @ret rc	return status code
701
- */
702 597
 static inline int mvaddchstr ( int y, int x, const chtype *chstr ) {
703 598
 	return ( wmove ( stdscr, y, x ) == ERR
704 599
 		 ? ERR : waddchnstr ( stdscr, chstr, -1 ) );
705 600
 }
706 601
 
707
-/**
708
- * Add string of single-byte characters to stdscr at the specified
709
- * position
710
- *
711
- * @v y		Y position
712
- * @v x		X position
713
- * @v *str	standard c-style string
714
- * @v n		max number of chars from string to render
715
- * @ret rc	return status code
716
- */
717 602
 static inline int mvaddnstr ( int y, int x, const char *str, int n ) {
718 603
 	return ( wmove ( stdscr, y, x ) == ERR
719 604
 		 ? ERR : waddnstr ( stdscr, str, n ) );
720 605
 }
721 606
 
722
-/**
723
- * Add string of single-byte characters to stdscr at the specified
724
- * position
725
- *
726
- * @v y		Y position
727
- * @v x		X position
728
- * @v *str	standard c-style string
729
- * @ret rc	return status code
730
- */
731 607
 static inline int mvaddstr ( int y, int x, const char *str ) {
732 608
 	return ( wmove ( stdscr, y, x ) == ERR
733 609
 		 ? ERR : waddnstr ( stdscr, str, -1 ) );
734 610
 }
735 611
 
736
-/**
737
- * Add a single-byte character and rendition to a window at the
738
- * specified position and advance the cursor
739
- *
740
- * @v *win	subject window
741
- * @v y		Y position
742
- * @v x		X position
743
- * @v ch	character to be added at cursor
744
- * @ret rc	return status code
745
- */
746 612
 static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
747 613
 	return ( wmove( win, y, x ) == ERR 
748 614
 		 ? ERR : waddch ( win, ch ) );
749 615
 }
750 616
 
751
-/**
752
- * Add string of single-byte characters and renditions to a window at
753
- * the specified position
754
- *
755
- * @v *win	subject window
756
- * @v y		Y position
757
- * @v x		X position
758
- * @v *chstr	pointer to first chtype in "string"
759
- * @v n		max number of chars from chstr to render
760
- * @ret rc	return status code
761
- */
762 617
 static inline int mvwaddchnstr ( WINDOW *win, int y, int x, const chtype *chstr, int n ) {
763 618
 	return ( wmove ( win, y, x ) == ERR 
764 619
 		 ? ERR : waddchnstr ( win, chstr, n ) );
765 620
 }
766 621
 
767
-/**
768
- * Add string of single-byte characters and renditions to a window at
769
- * the specified position
770
- *
771
- * @v *win	subject window
772
- * @v y		Y position
773
- * @v x		X position
774
- * @v *chstr	pointer to first chtype in "string"
775
- * @ret rc	return status code
776
- */
777 622
 static inline int mvwaddchstr ( WINDOW *win, int y, int x, const chtype *chstr ) {
778 623
 	return ( wmove ( win, y, x ) == ERR 
779 624
 		 ? ERR : waddchnstr ( win, chstr, -1 ) );
780 625
 }
781 626
 
782
-/**
783
- * Add string of single-byte characters to a window at the specified
784
- * position
785
- *
786
- * @v *win	window to be rendered in
787
- * @v y		Y position
788
- * @v x		X position
789
- * @v *str	standard c-style string
790
- * @v n		max number of chars from string to render
791
- * @ret rc	return status code
792
- */
793 627
 static inline int mvwaddnstr ( WINDOW *win, int y, int x, const char *str, int n ) {
794 628
 	return ( wmove ( win, y, x ) == ERR
795 629
 		 ? ERR : waddnstr ( win, str, n ) );
796 630
 }
797 631
 
798
-/**
799
- * Add string of single-byte characters to a window at the specified
800
- * position
801
- *
802
- * @v *win	window to be rendered in
803
- * @v y		Y position
804
- * @v x		X position
805
- * @v *str	standard c-style string
806
- * @ret rc	return status code
807
- */
808 632
 static inline int mvwaddstr ( WINDOW *win, int y, int x, const char *str ) {
809 633
 	return ( wmove ( win, y, x ) == ERR
810 634
 		 ? ERR : waddnstr ( win, str, -1 ) );
811 635
 }
812 636
 
813
-/**
814
- * Add string of single-byte characters and renditions to a window
815
- *
816
- * @v *win	subject window
817
- * @v *chstr	pointer to first chtype in "string"
818
- * @ret rc	return status code
819
- */
820 637
 static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
821 638
 	return waddchnstr ( win, chstr, -1 );
822 639
 }
823 640
 
824
-/**
825
- * Add string of single-byte characters to a window
826
- *
827
- * @v *win	window to be rendered in
828
- * @v *str	standard c-style string
829
- * @ret rc	return status code
830
- */
831 641
 static inline int waddstr ( WINDOW *win, const char *str ) {
832 642
 	return waddnstr ( win, str, -1 );
833 643
 }
834 644
 
835
-/**
836
- * Set background rendition attributes for a window and apply to
837
- * contents
838
- *
839
- * @v *win	window to be operated on
840
- * @v ch	chtype containing rendition attributes
841
- * @ret rc	return status code
842
- */
843 645
 static inline int wbkgdset ( WINDOW *win, chtype ch ) {
844 646
 	return wattrset( win, ch );
845 647
 }

Loading…
취소
저장