/*
*
* 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_write_config - Write an updated configuration file
*/
#include <errno.h> /* errno */
#include <stdio.h> /* fdopen(), fprintf(), fseeko(), ... */
#include <stdlib.h> /* mkstemp() */
#include <string.h> /* strcat(), strcpy(), strlen(), strerror() */
#include <unistd.h>
#include "xf86Parser.h" /* Public function, etc. declatations */
#include "Configint.h" /* Private definitions, etc. */
#include "configProcs.h" /* Private function, etc. declarations */
#include "fields.h" /* Write aligned whitespace and text fields */
#include "fbc.h" /* Common fbconf_xorg(1M) definitions */
#include "fbc_properties.h" /* fbconf_xorg(1M) program properties */
#include "fbc_error.h" /* Error reporting */
#include "fbc_fields.h" /* Measure aligned whitespace fields */
#include "fbc_line_er.h" /* External Representation of config lines */
#include "fbc_write_config.h" /* Write an updated configuration file */
/*
* fbc_reread_config_line()
*
* Reread a line from an xorg.conf input file. Measure the
* indentation whitespace (to be used when modifying this current
* line or when inserting subsequent lines).
*/
static
int
char **configBuf, /* Config file line buffer */
int *configBufLen, /* Line buffer length */
{
/*
* Position the input configuration file to the line in question
*/
return (FBC_ERR_SEEK);
}
/*
* Reread the line from the input configuration file
*/
== NULL) {
return (FBC_ERR_READ);
}
/*
* Measure the first whitespace fields if this is a non-comment line
*/
return (FBC_SUCCESS);
} /* fbc_reread_config_line() */
/*
* fbc_print_config_text()
*
* Write a text string, typically a single line, to the output
* configuration file.
*
* This is considered to be an xf86_print_fn_t typed function.
*/
void
const char *text, /* Text string */
const char *const whitespace[]) /* Line indentation, ignored */
{
} /* fbc_print_config_text() */
static void
{
if (modes_sectn_ptr == NULL)
return;
}
}
}
}
/*
* fbc_write_config_file()
*
* Write the updated configuration data to a file.
*/
static
int
{
/*
* Initial line indentation
*/
/*
* Repeat for each configuration line in the External Representation
*/
/*
* Copy, modify, or delete the current config line
*/
default:
/*
* Unlikely internal error
*/
"Internal error; unknown config line status code, %d\n",
"### The following line was copied verbatim"
" due to an unknown status code, %d\n",
/*FALLTHROUGH*/
case FBC_LINE_ORIGINAL:
/*
* Go copy the original configuration line
*/
break;
case FBC_LINE_INSERTED:
/*
* See whether we know what we're doing
*/
"Internal error; no print function for inserted line\n");
"### A line to be inserted here was discarded"
" for lack of a print function\n");
continue; /* Discard the unknown line */
}
/*
* Attempt to match the original indentation style
*
* The original heuristic assumed that a line
* to be inserted should be indented to match
* the line that precedes it. This works for
* a line to be inserted at the end of an
* existing and well-formed section. Now
* we support insertion of omitted sections
* and subsections in empty and in existing
* config files. Tricksy it is, yessss.
*/
if (!wspace_measured ||
/*
* Nothing to match, so use the default style
*/
switch (line_ptr->indent_level) {
case FBC_INDENT_0:
break;
case FBC_INDENT_1:
case FBC_INDENT_ENTRY:
break;
case FBC_INDENT_2:
default:
break;
}
}
/*
* Insert a new configuration line
*/
continue;
case FBC_LINE_MODIFIED:
/*
* Measure the whitespace (then discard the input line)
*/
(void) fbc_reread_config_line(
&wspace_chars);
/*
* Insert a replacement configuration line
*/
"Internal error; no print function for modified line\n");
"### The following line was not modified"
" for lack of a print function\n");
break; /* Copy the unknown line */
}
continue;
case FBC_LINE_DELETED:
/*
* Discard the configuration line
*/
continue;
}
/*
* Copy the original configuration line
*/
&wspace_chars);
if (error_code != FBC_SUCCESS) {
fbc_errormsg("Configuration file input error\n");
return (error_code);
}
}
/*
* Lastly output the device specific SunModes section
*/
}
return (FBC_SUCCESS);
} /* fbc_write_config_file() */
/*
* fbc_write_config()
*
* Write the updated configuration data to a new output file having a
* temporary name. Close the input configuration file, if any.
* Replace any input configuration file with the output configuration
* file, preserving the original file name, modes, and ownership.
*/
int
{
/*
* Generate the template for the temporary name of the output file
*
* The temporary pathname is the concatenation of the input
* config file pathname, "XXXXXX", and a Nul terminator.
*/
> sizeof (config_path_out)) {
fbc_errormsg("Configuration file pathname is too long, %s\n",
return (FBC_ERR_PATH_LEN); /* Output name would be too long */
}
/*
* Create and open the output config file using the temporary name
*/
if (config_fd_out == -1) {
return (FBC_ERR_OPEN);
}
if (config_stream_out == NULL) {
return (FBC_ERR_OPEN);
}
/*
* Write the configuration data to the output file
*/
/*
* Close the input config file(s), release resources, etc.
*/
if (error_code == FBC_SUCCESS) {
/*
* Get any input cfg file mode and ownership, else use defaults
*/
}
/*
* Set the mode and ownership of the output config file
*/
fbc_errormsg("%s, %s\n",
}
== -1)
{
fbc_errormsg("%s, %s\n",
}
}
/*
* Close the output config file (whether or not all went well)
*/
/*
* Delete the input file, if any, replacing it with the output file
*/
if (error_code == FBC_SUCCESS) {
}
}
if (error_code != FBC_SUCCESS) {
/*
* Just delete the temporary output file
*/
(void) unlink(config_path_out);
}
/*
* Return, indicating whether or not all went well
*/
return (error_code);
} /* fbc_write_config() */
/* End of fbc_write_config.c */