/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* fbc_Screen - Edit Screen sections
*/
#include <stdio.h> /* NULL */
#include "xf86Parser.h" /* Public function, etc. declarations */
#include "Configint.h" /* Private definitions, etc. */
#include "configProcs.h" /* Private function, etc. declarations */
#include "xf86Optrec.h" /* Option lists, memory management, etc. */
#include "fbc_Monitor.h" /* Edit Monitor sections */
#include "fbc_Option.h" /* Edit Option lists */
#include "fbc_Screen.h" /* Edit Screen sections */
#include "fbc_error.h" /* Error reporting */
#include "fbc_line_er.h" /* External Representation of config lines */
#include "fbc_write_config.h" /* Write an updated config file */
/*
* fbc_find_active_Monitor_entry()
*
* Find the first Monitor entry within a list of Monitor section
* identifiers.
* ??? The man pages don't seem to have said which is the active
* ??? Monitor section when there is more than one Monitor entry.
* The list of Monitor sections comes from an active Screen section.
* The list may be empty, which means a default configuration is to
* be used.
*
* ???
* Monitor entries within a Screen section are optional. Currently
* we don't support omitted Monitor sections and default
* configurations ...
*
* Note that the syntax and data structures being traversed by this
* function belong to the Screen section, which is why this function
* is in fbc_Screen.c rather than a fbc_Monitor.c.
*/
{
/*
* Return the first Monitor section entry in the list, else NULL
*/
return (scrn_monitor_lst);
} /* fbc_find_active_Monitor_entry() */
/*
* fbc_insert_Monitor_entry()
*
* Insert the specified Monitor entry line into the specified Screen
* section.
*
* It is assumed that this function is called when no active Monitor
* section was found by fbc_find_active_Monitor_entry(), i.e. the
* list of Monitor entries is empty. In any case, this function must
* not cause:
* * Omitted Monitor numbers when there are muliple Monitor entries
* * Duplicate Monitor numbers
* * Duplicate Monitor names
* See xf86parseScrnMonitor() in Screen.c.
*/
int
{
/*
* Allocate, zero, and further initialize the new Monitor entry element
*/
return (FBC_ERR_NOMEM);
}
(*mon_ptr)->scrn_monitor_name =
return (FBC_ERR_NOMEM);
}
/*
* Append new the Monitor entry element to the (empty) list
*/
/*
* Insert the External Representation data for the Monitor entry line
*/
(void) fbc_insert_line_ER(
(void *)*mon_ptr,
return (FBC_SUCCESS);
} /* fbc_insert_Monitor_entry() */
/*
* fbc_find_active_Mode_name()
*
* Return a pointer to the name of the first ModeLine / Mode-EndMode
* entry, if any, referenced by this Display subsection. Otherwise
* return NULL.
*
* This function supports the -propt functionality.
*/
const char *
{
}
return (NULL);
} /* fbc_find_active_Mode_name() */
/*
* fbc_find_active_Display_subsection()
*
* Find the active Display subsection in this Screen section that
* matches the specified active Monitor entry.
*
* "The 'active' Display subsections are the first for each monitor
* failing that, the first for each monitor number that has neither a
* depth or fbbpp value specified. ... The Display subsections are
* optional. ..." - XF86Config(5)
*/
{
/*
* Find any Display subsection referencing this Monitor section
*/
for (display_subsectn_ptr = scrn_display_lst;
/*
* Check for matching monitor numbers
*
* There is no match if one entity (Display
* subsection or Monitor entry) specifies a monitor
* number and the other doesn't.
*
* Considering only monitor numbers, there is a match
* if both entities have the same monitor number.
* There is a match if both entities have no monitor
* number.
*/
continue; /* Not a match */
}
!= mon_ptr->scrn_monitor_num)) {
continue; /* Not a match */
}
/*
*
* rather than "and." This seems to allow for the
* possibility that only one of the two values is
* specified. If both values are specified, we'll
* require a match on both.
*
??? * Though the parser code does not check for this, it
??? * is assumed that zero is not a valid value for
??? * depth nor [fb]bpp, and further assumed that a zero
??? * in the Display subsection data structure indicates
??? * that the value was not specified.
*/
!= screen_sectn_ptr->scrn_defaultdepth)) {
continue; /* Not a match */
}
!= screen_sectn_ptr->scrn_defaultfbbpp)) {
continue; /* Not a match */
}
/*
* Return the first matching Display subsection found
*/
return (display_subsectn_ptr);
}
/*
* Return unsuccessfully
*/
return (NULL);
} /* fbc_find_active_Display_subsection() */
/*
* fbc_find_active_Screen_section()
*
* Find the Screen section that refers to the specified device name.
*
* Note that we can't tell whether a given Screen section will be
* considered active at execution time. This is because even if we
* could guess which ServerLayout section is likely to be active, the
* -screen command line option could still be used to override our
* best guess.
*/
const char * const device_identifier) /* Device name */
{
/*
* Search each Screen section for the specified device identifier
*/
for (scrn_sectn_ptr = conf_screen_lst;
scrn_sectn_ptr != NULL;
device_identifier) == 0) {
/*
* Return this as the active Screen section
*/
return (scrn_sectn_ptr);
}
}
/*
* Return unsuccessfully
*/
return (NULL);
} /* fbc_find_active_Screen_section() */
/*
* fbc_edit_Display_subsection()
*
* Modify or insert Display subsection values to the Internal and
* External Representations of the configuration file:
* Modes "<mode_name>" ...
*/
int
{
/*
* See whether a Mode name has been specified (-res option)
*/
return (FBC_SUCCESS); /* No "-res <video_mode>" option */
}
/*
* Before disturbing it, remember whether we found the list empty
*/
/*
* Look for a matching Modes name element or create one if not found
*/
;
/*
* See whether we've reached the end of the Modes list
*/
if (disp_mode_ptr == NULL) {
/*
* Create a new Modes list element for this Mode name
*/
if (disp_mode_ptr == NULL) {
"Insufficient memory, \"%s\" list element\n",
return (FBC_ERR_NOMEM);
}
"Insufficient memory, \"%s\" name string\n",
return (FBC_ERR_NOMEM);
}
break;
}
/*
* See whether this existing Mode name is a match
*/
disp_mode_ptr->mode_name) == 0) {
/*
* Unlink the matching Mode name element from the list
*/
break;
}
}
/*
* Replace the Mode
*/
/*
* Insert a new Mode line ER or modify an existing one
*/
if (no_modes_line) {
/*
* Insert the External Representation of the new Modes line
*/
(void) fbc_insert_line_ER(
(xf86_print_fn_t *)
} else {
/*
* Modify the External Representation of the Modes line
*/
}
return (FBC_SUCCESS);
} /* fbc_edit_Display_subsection() */
/*
* fbc_insert_Display_subsection()
*
* Insert a new, semi-empty Display subsection in the configuration
* at the specified location.
*
* Subsection "Display"
* [ Monitor <monitor_num> ]
* #[ Depth <depth> ]
* #[ FbBpp <bpp> ]
* EndSubsection
*/
int
{
/*
* Allocate and initialize the Internal Rep for new Display subsection
*/
if (*display_ptr == NULL) {
return (FBC_ERR_NOMEM);
}
/*
* Insert the External Representation data for the Display subsection
*/
/* Subsection "Display" */
(void) fbc_insert_line_ER(
(xf86_print_fn_t *)
/* Monitor <monitor_num> */
(void) fbc_insert_line_ER(
}
/* Depth <depth> */
/* FbBpp <bpp> */
/* EndSubsection */
(*display_ptr)->disp_end_line_er =
(xf86_print_fn_t *)
/*
* Add the new Display subsection to the in-memory configuration
*/
(glp)*display_ptr);
return (FBC_SUCCESS);
} /* fbc_insert_Display_subsection() */
/*
* fbc_edit_Screen_section()
*
* Modify or insert Screen section values to the Internal
* Representation of the configuration file.
* DefaultDepth "8"|"24" # -defdepth "8"|"24"
*/
int
{
/*
* Make any DefaultDepth modification to the Screen section
*/
/*
* Update the line's Internal Representation
*/
/*
* Insert or modify the line's External Representation
*/
(xf86_print_fn_t *)
}
return (FBC_SUCCESS);
} /* fbc_edit_Screen_section() */
/*
* fbc_insert_new_Screen_section()
*
* Insert a new, mostly empty Screen section in the configuration at
* the specified location.
*
* Section "Screen"
* Identifier "<screen_identifier>"
* Device "<device_identifier>"
* EndSection
* <blank line>
*
* The Monitor entry will be inserted later, iff there are command
* line options that modify a Monitor section.
*
* Note that the Screen section identifier string, scrn_identifier,
* has been dynamically allocated by our caller. The Device section
* identifier, scrn_device_str, is assumed not to have been.
*/
static
int
char *scrn_identifier, /* Screen section identifier */
const char *scrn_device_str, /* Device section identifier */
{
/*
* Allocate and initialize the Internal Rep for a new Screen section
*/
if (*screen_ptr == NULL) {
return (FBC_ERR_NOMEM);
}
/*
* Insert the External Representation data for the Screen section
*/
/* Section "Screen" */
(void) fbc_insert_line_ER(
/* Identifier "<screen_identifier>" */
(void) fbc_insert_line_ER(
/* Device "<device_identifier>" */
(void) fbc_insert_line_ER(
/* EndSection */
(*screen_ptr)->scrn_end_line_er =
/* <blank line> */
(void) fbc_insert_line_ER(
"\n",
/*
* Add the new Screen section to the in-memory configuration
*
* The External and Internal Representations of this Screen
* section must agree that it is either first (FBC_FIRST_ER)
* or last (FBC_LAST_ER aka NULL) in the configuration.
*/
if (next_line_er == FBC_LAST_ER) {
/*
* Last Screen section in the configuration
*/
(glp)*screen_ptr);
} else {
/*
* First Screen section in the configuration
*/
}
return (FBC_SUCCESS);
} /* fbc_insert_new_Screen_section() */
/*
* fbc_insert_Screen_section()
*
* Insert a new, empty Screen section in the configuration at the
* specified location.
*/
int
const char *scrn_ident_tmpl, /* Screen section ident template */
const char *scrn_device_str, /* Device section identifier */
{
unsigned int i; /* Loop counter / uniqueness factor */
/*
* Allocate memory for the new Screen identifier string
*
* Allocate space for the intended name and any extra
* underscore and decimal digits needed to make it unique.
* The number of digits will never be greater than the byte
* size of the loop counter, i, multiplied by three decimal
* digits per byte.
*/
+ 1 /* "_" */
+ 3 * sizeof (i) /* Digits */
+ 1); /* Nul */
if (scrn_identifier == NULL) {
return (FBC_ERR_NOMEM);
}
/*
* Insure that the new Screen section identifier will be unique
*/
ident_format = "%s";
for (i = 0; ; ) {
/*
* Try the name alone and then the name with a numeric suffix
*/
ident_format = "%s_%u";
/*
* Search for this name among the existing Screen sections
*/
scrn_ptr->scrn_identifier) == 0) {
break; /* Not unique */
}
}
/*
* Stop when the name is unique (or if the loop counter wraps)
*/
i += 1;
break; /* The name is unique enough */
}
}
/*
* Insert a new Screen section into the in-memory configuration
*/
if (error_code != FBC_SUCCESS) {
return (error_code);
}
return (FBC_SUCCESS);
} /* fbc_insert_Screen_section() */
/* End of fbc_Screen.c */