/*
* Copyright (c) 2002 John Rochester
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* in this position and unchanged.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
*/
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "man.h"
#include "stringlist.h"
/* Information collected about each man page in a section */
struct page_info {
char *filename;
char *name;
char *suffix;
};
/* An expanding string */
struct sbuf {
};
/* Remove the last amount characters from the sbuf */
/* Return the length of the sbuf content */
/*
* While the whatis line is being formed, it is stored in whatis_proto.
* When finished, it is reformatted into whatis_final and then appended
* to whatis_lines.
*/
/* Free a struct page_info and its content */
static void
{
}
/*
* Allocate and fill in a new struct page_info given the
* name of the man section directory and the dirent of the file.
* If the file is not a man page, return NULL.
*/
static struct page_info *
{
int basename_length;
char *suffix;
for (;;) {
if (*suffix == '.')
break;
return (NULL);
}
}
*suffix++ = '\0';
return (NULL);
}
return (NULL);
}
return (info);
}
/*
* Reset sbuf length to 0.
*/
static void
{
}
/*
* Allocate a new sbuf.
*/
static struct sbuf *
new_sbuf(void)
{
return (sbuf);
}
/*
* Ensure that there is enough room in the sbuf
* for nchars more characters.
*/
static void
{
char *new_content;
}
/* Grow if the buffer isn't big enough */
perror("realloc");
if (tempfile[0] != '\0')
exit(1);
}
}
}
/*
* Append a string of a given length to the sbuf.
*/
static void
{
if (length > 0) {
}
}
/*
* Append a null-terminated string to the sbuf.
*/
static void
{
}
/*
* Append an edited null-terminated string to the sbuf.
*/
static void
{
int length;
}
}
/*
* Strip any of a set of chars from the end of the sbuf.
*/
static void
{
}
/*
* Return the null-terminated string built by the sbuf.
*/
static char *
{
}
/*
* Return true if no man page exists in the directory with
* any of the names in the stringlist.
*/
static int
{
size_t i;
int j;
return (0);
}
}
}
return (1);
}
/* ARGSUSED sig */
static void
{
if (tempfile[0] != '\0')
exit(1);
}
/*
* Attempt to open an output file.
* Return NULL if unsuccessful.
*/
static FILE *
{
whatis_lines = sl_init();
return (NULL);
}
return (output);
}
static int
linesort(const void *a, const void *b)
{
return (strcmp((*(const char * const *)a), (*(const char * const *)b)));
}
/*
* Write the unique sorted lines to the output file.
*/
static void
{
size_t i;
linesort);
for (i = 0; i < whatis_lines->sl_cur; i++) {
continue;
}
}
static FILE *
{
return (open_output(filename));
}
static void
{
}
/*
* Remove trailing spaces from a string, returning a pointer to just
* beyond the new last character.
*/
static char *
{
char *rhs;
;
*++rhs = '\0';
return (rhs);
}
/*
* Return a pointer to the next non-space character in the string.
*/
static char *
skip_spaces(char *s)
{
while (*s != '\0' && isspace(*s))
s++;
return (s);
}
/*
* Return whether the line is of one of the forms:
* .Sh NAME
* .Sh "NAME"
* etc.
* assuming that section_start is ".Sh".
*/
static int
{
char *rhs;
return (0);
if (*line == '"') {
line++;
if (*--rhs == '"')
*rhs = '\0';
}
return (1);
return (0);
}
/*
* \(em, \(mi, \s[+-N], \&
* \fF, \f(fo, \f[font]
* \*s, \*(st, \*[stringvar]
*/
static char *
{
switch (*from) {
case '\\':
switch (*++from) {
case '(':
from += 3;
continue;
}
break;
case 's':
if (*++from == '-')
from++;
from++;
continue;
case 'f':
case '*':
if (*++from == '(') {
from += 3;
} else if (*from == '[') {
while (*++from != ']' &&
;
from++;
} else {
from++;
}
continue;
case '&':
from++;
continue;
}
break;
}
}
return (to);
}
/*
* Append a string with the nroff formatting removed.
*/
static void
{
}
/*
* Appends "name(suffix), " to whatis_final
*/
static void
{
if (*name != '\0') {
}
}
/*
* Processes an old-style man(7) line. This ignores commands with only
* a single number argument.
*/
static void
{
char *p;
if (*line == '.') {
;
while (*p != '\0') {
if (!isdigit(*p))
break;
p++;
}
if (*p == '\0')
return;
} else
if (*line != '\0') {
}
}
/*
* Processes a new-style mdoc(7) line.
*/
static void
{
int xref;
int arg = 0;
char *next;
if (*line == '\0')
return;
return;
}
line += 3;
if (*line == '"') {
for (;;) {
break;
line_end--;
if (*next != '"')
break;
next++;
}
} else {
}
*next++ = '\0';
else
arg = 0;
continue;
}
continue;
}
}
if (xref) {
xref = 0;
} else {
}
}
arg++;
}
}
/*
* Collect a list of comma-separated names from the text.
*/
static void
{
char *arg;
for (;;) {
*text++ = '\0';
return;
if (*text == ' ')
text++;
}
}
/*
* Process a man page source into a single whatis line and add it
* to whatis_lines.
*/
static void
{
char *descr;
size_t i;
return;
}
/* Skip comments */
continue;
switch (state) {
/* Haven't reached the NAME section yet */
case STATE_UNKNOWN:
continue;
/* Inside an old-style .SH NAME section */
case STATE_MANSTYLE:
break;
continue;
line += 3;
}
continue;
/* Inside a new-style .Sh NAME section (the .Nm part) */
case STATE_MDOCNAME:
continue;
} else {
continue;
}
/* FALLTHROUGH */
/* Inside a new-style .Sh NAME section (after the .Nm-s) */
case STATE_MDOCDESC:
break;
continue;
continue;
}
break;
}
/*
* Line now contains the appropriate data, but without the
* proper indentation or the section appended to each name.
*/
return;
*descr++ = '\0';
} else {
*descr = '\0';
descr += 3;
}
/*
* Add the page name since that's the only
* thing that man(1) will find.
*/
}
/* Remove last ", " */
}
/*
* Sort pages first by inode number, then by name.
*/
static int
pagesort(const void *a, const void *b)
{
}
/*
* Process a single man section.
*/
static void
{
int nentries;
int npages = 0;
int i;
/* Scan the man section directory for pages */
/* Collect information about man pages */
sizeof (struct page_info *));
for (i = 0; i < nentries; i++) {
}
/* Process each unique page */
for (i = 0; i < npages; i++) {
}
}
}
/*
* Return whether the directory entry is a man page section.
*/
static int
{
return (0);
while (*p != '\0') {
if (!isalnum(*p++))
return (0);
}
return (1);
}
/*
* Process a single top-level man directory by finding all the
* sub-directories named man* and processing each one in turn.
*/
void
{
int nsections;
int i;
whatis_proto = new_sbuf();
whatis_final = new_sbuf();
return;
for (i = 0; i < nsections; i++) {
}
}