misc.cc revision 10d63b7db37a83b39c7f511cf9426c9d03ea0760
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* misc.cc
*
* This file contains various unclassified routines. Some main groups:
* getname
* Memory allocation
* String handling
* Property handling
* Error message handling
* Make internal state dumping
* main routine support
*/
/*
* Included files
*/
#include <stdarg.h> /* va_list, va_start(), va_end() */
#include <stdlib.h> /* mbstowcs() */
#include <string.h> /* strerror() */
#include <libintl.h>
/*
* Defined macros
*/
/*
* typedefs & structs
*/
/*
* Static variables
*/
extern "C" {
}
long getname_bytes_count = 0;
long getname_names_count = 0;
long getname_struct_count = 0;
long freename_bytes_count = 0;
long freename_names_count = 0;
long freename_struct_count = 0;
long expandstring_count = 0;
long getwstring_count = 0;
/*
* File table of contents
*/
#define FATAL_ERROR_MSG_SIZE 200
/*
* getmem(size)
*
* malloc() version that checks the returned value.
*
* Return value:
* The memory chunk we allocated
*
* Parameters:
* size The size of the chunk we need
*
* Global variables used:
*/
char *
{
char buf[FATAL_ERROR_MSG_SIZE];
exit_status = 1;
exit(1);
}
return result;
}
/*
* retmem(p)
*
* Cover funtion for free() to make it possible to insert advises.
*
* Parameters:
* p The memory block to free
*
* Global variables used:
*/
void
retmem(wchar_t *p)
{
(void) free((char *) p);
}
void
{
(void) free(p);
}
/*
* getname_fn(name, len, dont_enter)
*
* Hash a name string to the corresponding nameblock.
*
* Return value:
* The Name block for the string
*
* Parameters:
* name The string we want to internalize
* len The length of that string
* dont_enter Don't enter the name if it does not exist
*
* Global variables used:
* funny The vector of semantic tags for characters
* hashtab The hashtable used for the nametable
*/
{
register int length;
static Name_rec empty_Name;
char *tmp_mbs_buffer = NULL;
char *mbs_name = mbs_buffer;
/*
* First figure out how long the string is.
* If the len argument is -1 we count the chars here.
*/
if (len == FIND_LENGTH) {
} else {
}
if (length >= MAXPATHLEN) {
}
/* Look for the string */
if (dont_enter || (foundp != 0)) {
if (foundp != 0) {
}
if ((np != 0) || dont_enter) {
if(tmp_mbs_buffer != NULL) {
}
return np;
} else {
}
} else {
if (found) {
if(tmp_mbs_buffer != NULL) {
}
return np;
}
}
getname_struct_count += sizeof(struct _Name);
*np = empty_Name;
if(tmp_mbs_buffer != NULL) {
}
/* Fill in the new Name */
/* Scan the namestring to classify it */
}
return np;
}
void
{
}
void
{
freename_struct_count += sizeof(struct _Name);
free(p);
}
}
/*
* enable_interrupt(handler)
*
* This routine sets a new interrupt handler for the signals make
* wants to deal with.
*
* Parameters:
* handler The function installed as interrupt handler
*
* Static variables used:
* sigivalue The original signal handler
* sigqvalue The original signal handler
* sigtvalue The original signal handler
* sighvalue The original signal handler
*/
void
enable_interrupt(register void (*handler) (int))
{
}
}
}
}
}
/*
* setup_char_semantics()
*
* Load the vector char_semantics[] with lexical markers
*
* Parameters:
*
* Global variables used:
* char_semantics The vector of character semantics that we set
*/
void
setup_char_semantics(void)
{
const char *s;
wchar_t wc_buffer[1];
int entry;
if (svr4) {
s = "@-";
} else {
s = "=@-?!+";
}
}
}
}
}
}
/*
* errmsg(errnum)
*
* Return the error message for a system call error
*
* Return value:
* An error message string
*
* Parameters:
* errnum The number of the error we want to describe
*
* Global variables used:
* sys_errlist A vector of error messages
* sys_nerr The size of sys_errlist
*/
char *
{
extern int sys_nerr;
char *errbuf;
return errbuf;
} else {
}
}
/*
* fatal_mksh(format, args...)
*
* Print a message and die
*
* Parameters:
* format printf type format string
* args Arguments to match the format
*/
/*VARARGS*/
void
fatal_mksh(const char *message, ...)
{
char *buf = static_buf;
sizeof(static_buf) - mksh_fat_err_len,
+ 3; // "\n\n"
if (buf_len >= sizeof(static_buf)) {
}
/*
if (report_pwd) {
*/
if (1) {
}
if (buf != static_buf) {
}
exit_status = 1;
exit(1);
}
/*
* fatal_reader_mksh(format, args...)
*
* Parameters:
* format printf style format string
* args arguments to match the format
*/
/*VARARGS*/
void
fatal_reader_mksh(const char * pattern, ...)
{
char message[1000];
/*
if (file_being_read != NULL) {
WCSTOMBS(mbs_buffer, file_being_read);
if (line_number != 0) {
(void) sprintf(message,
gettext("%s, line %d: %s"),
mbs_buffer,
line_number,
pattern);
} else {
(void) sprintf(message,
"%s: %s",
mbs_buffer,
pattern);
}
pattern = message;
}
*/
/*
if (temp_file_name != NULL) {
(void) fprintf(stderr,
gettext("mksh: Temp-file %s not removed\n"),
temp_file_name->string_mb);
temp_file_name = NULL;
}
*/
/*
if (report_pwd) {
*/
if (1) {
gettext("Current working directory %s\n"),
}
exit_status = 1;
exit(1);
}
/*
* warning_mksh(format, args...)
*
* Print a message and continue.
*
* Parameters:
* format printf type format string
* args Arguments to match the format
*/
/*VARARGS*/
void
warning_mksh(char * message, ...)
{
/*
if (report_pwd) {
*/
if (1) {
gettext("Current working directory %s\n"),
}
}
/*
* get_current_path_mksh()
*
* Stuff current_path with the current path if it isnt there already.
*
* Parameters:
*
* Global variables used:
*/
char *
get_current_path_mksh(void)
{
static char *current_path;
if (current_path == NULL) {
pwd[0] = (int) slash_char;
}
}
return current_path;
}
/*
* append_prop(target, type)
*
* Create a new property and append it to the property list of a Name.
*
* Return value:
* A new property block for the target
*
* Parameters:
* target The target that wants a new property
* type The type of property being requested
*
* Global variables used:
*/
{
register int size;
switch (type) {
case conditional_prop:
size = sizeof (struct Conditional);
break;
case line_prop:
break;
case macro_prop:
break;
case makefile_prop:
break;
case member_prop:
break;
case recursive_prop:
break;
case sccs_prop:
break;
case suffix_prop:
break;
case target_prop:
break;
case time_prop:
break;
case vpath_alias_prop:
size = sizeof (struct Vpath_alias);
break;
case long_member_name_prop:
size = sizeof (struct Long_member_name);
break;
case macro_append_prop:
size = sizeof (struct _Macro_appendix);
break;
case env_mem_prop:
break;
default:
}
return prop;
}
/*
* maybe_append_prop(target, type)
*
* Append a property to the Name if none of this type exists
* else return the one already there
*
* Return value:
* A property of the requested type for the target
*
* Parameters:
* target The target that wants a new property
* type The type of property being requested
*
* Global variables used:
*/
{
return prop;
}
}
/*
* get_prop(start, type)
*
* Scan the property list of a Name to find the next property
* of a given type.
*
* Return value:
* The first property of the type, if any left
*
* Parameters:
* start The first property block to check for type
* type The type of property block we need
*
* Global variables used:
*/
{
return start;
}
}
return NULL;
}
/*
* append_string(from, to, length)
*
* Append a C string to a make string expanding it if nessecary
*
* Parameters:
* from The source (C style) string
* to The destination (make style) string
* length The length of the from string
*
* Global variables used:
*/
void
{
if (length == FIND_LENGTH) {
}
}
length);
}
if (length > 0) {
}
}
wchar_t * get_wstring(char *from) {
return NULL;
}
return wcbuf;
}
void
{
if (length == FIND_LENGTH) {
}
}
length);
}
if (length > 0) {
}
}
/*
* expand_string(string, length)
*
* Allocate more memory for strings that run out of space.
*
* Parameters:
* string The make style string we want to expand
* length The new length we need
*
* Global variables used:
*/
static void
{
register wchar_t *p;
/* For strings that have no memory allocated */
string->free_after_use = true;
return;
}
/* If we really don't need more memory. */
return;
}
/*
* Get more memory, copy the string and free the old buffer if
* it is was malloc()'ed.
*/
if (string->free_after_use) {
}
string->free_after_use = true;
}
/*
* append_char(from, to)
*
* Append one char to a make string expanding it if nessecary
*
* Parameters:
* from Single character to append to string
* to The destination (make style) string
*
* Global variables used:
*/
void
{
}
}
}
/*
* handle_interrupt_mksh()
*
* This is where C-C traps are caught.
*/
void
{
/* Make sure the processes running under us terminate first. */
if (childPid > 0) {
childPid = -1;
}
exit_status = 2;
exit(2);
}
/*
* setup_interrupt()
*
* This routine saves the original interrupt handler pointers
*
* Parameters:
*
* Static variables used:
* sigivalue The original signal handler
* sigqvalue The original signal handler
* sigtvalue The original signal handler
* sighvalue The original signal handler
*/
void
setup_interrupt(register void (*handler) (int))
{
}
void
{
}
}
{
}
{
}
{
if(string.free_after_use) {
}
}
void
{
if(string.free_after_use) {
}
}
void
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
void
{
}
{
if (res < 0) {
} else if (res > 0) {
} else {
}
}
return 0;
}
{
if (root != 0) {
if (res < 0) {
} else {
found = false;
}
} else if (res > 0) {
} else {
found = false;
}
} else {
found = true;
}
}
} else {
found = false;
}
return name;
}
void
if (root != 0) {
if (res < 0) {
} else {
break;
}
} else if (res > 0) {
} else {
break;
}
} else {
// should be an error: inserting already existing name
break;
}
}
} else {
}
}
void
}
} else {
}
} else {
}
node->setup_depth();
}
} else {
}
} else {
}
node->setup_depth();
}
node->setup_depth();
}
}
}
}
return iterator();
}
if (node != 0) {
}
} else {
}
}
}
return *this;
}