* New alpha version 2.24.1
[alpine.git] / pith / osdep / color.c
blobfe65898d8b918aa09701444b196bfb7c69301ef3
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: color.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2021 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
21 * These routines themselves aren't necessarily OS-specific, they
22 * are all called from within pico, pine and webpine.
24 * They used to be in pico source (osdep/unix, mswin.c), but considering
25 * webpine uses color as well and it should *not* have to be linked
26 * against libpico and considering pico uses these routines but should
27 * not have to link against libpith (and in turn c-client) we put them
28 * in pith/osdep which should only have to link against system libraries
29 * and thus be include freely in all of pine, pico and webpine.
30 */
33 #include <system.h>
34 #include "./color.h"
39 * new_color_pair - allocate a new color pair structure assigning
40 * given foreground and background color strings
42 COLOR_PAIR *
43 new_color_pair(char *fg, char *bg)
45 COLOR_PAIR *ret;
47 if((ret = (COLOR_PAIR *) malloc(sizeof(*ret))) != NULL){
48 memset(ret, 0, sizeof(*ret));
49 if(fg){
50 strncpy(ret->fg, fg, MAXCOLORLEN);
51 ret->fg[MAXCOLORLEN] = '\0';
54 if(bg){
55 strncpy(ret->bg, bg, MAXCOLORLEN);
56 ret->bg[MAXCOLORLEN] = '\0';
60 return(ret);
65 * free_color_pair - release resources associated with given
66 * color pair structure
68 void
69 free_color_pair(COLOR_PAIR **cp)
71 if(cp && *cp){
72 free(*cp);
73 *cp = NULL;
79 * Just like pico_set_color except it doesn't set the color, it just
80 * returns the value. Assumes def of PSC_NONE, since otherwise we always
81 * succeed and don't need to call this.
83 int
84 pico_is_good_colorpair(COLOR_PAIR *cp)
86 return(cp && pico_is_good_color(cp->fg) && pico_is_good_color(cp->bg));
90 COLOR_PAIR *
91 pico_set_colorp(COLOR_PAIR *col, int flags)
93 return(pico_set_colors(col ? col->fg : NULL, col ? col->bg : NULL, flags));