#ifndef lint
char copyright[] = "@(#) Copyright (c) 1980 Regents of the University of "
"California.\nAll rights reserved.\n";
#endif
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#define bool char
#define TRUE (1)
#define FALSE (0)
#define CPFLAG 3
#define iswhite(arg) (_wht[arg])
#define begtoken(arg) (_btk[arg])
#define intoken(arg) (_itk[arg])
#define endtoken(arg) (_etk[arg])
#define isgood(arg) (_gd[arg])
#define optoken(arg) (_opr[arg])
#define max(I1, I2) (I1 > I2 ? I1 : I2)
struct nd_st {
char *entry;
char *file;
bool f;
int lno;
char *pat;
bool been_warned;
struct nd_st *left, *right;
};
long ftell();
typedef struct nd_st NODE;
static bool
number,
gotone,
_wht[0177], _etk[0177], _itk[0177], _btk[0177], _gd[0177];
static bool _opr[0177];
typedef enum {none, begin, begin_rec, begin_tag, middle, end } TYST;
static TYST tydef = none;
static char searchar = '/';
#define LINEBUFSIZ 4*BUFSIZ
static int lineno;
static char
line[LINEBUFSIZ],
*curfile,
*outfile = "tags",
*white = " \f\t\n",
*endtk = " \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?",
*begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
*intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
"0123456789",
*notgd = ",;";
static char *oprtk = " =-+%*/&|^~!<>[]()";
static int file_num;
static int aflag;
#ifndef XPG4
static int tflag;
#endif
static int uflag;
static int wflag;
static int vflag;
static int xflag;
static char lbuf[LINEBUFSIZ];
static FILE
*inf,
*outf;
static long lineftell;
static NODE *head;
static int infile_fail;
static char *dbp = lbuf;
static int pfcnt;
static int mac;
static char **mav;
static void init(void);
static void find_entries(char *);
static void pfnote(char *, int, bool);
static void C_entries(void);
static int start_entry(char **, char *, int *);
static void Y_entries(void);
static char *toss_comment(char *);
static void getaline(long int);
static void free_tree(NODE *);
static void add_node(NODE *, NODE *);
static void put_entries(NODE *);
static int PF_funcs(FILE *);
static int tail(char *);
static void takeprec(void);
static void getit(void);
static char *savestr(char *);
static void L_funcs(FILE *);
static void L_getit(int);
static int striccmp(char *, char *);
static int first_char(void);
static void toss_yysec(void);
static void Usage(void);
static void parseargs(int, char **);
int
main(int ac, char *av[])
{
int i;
char cmd[100];
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
parseargs(ac, av);
while ((i = getopt(mac, mav, "aBFtuvwxf:")) != EOF) {
switch (i) {
case 'a':
aflag++;
break;
case 'B':
searchar = '?';
break;
case 'F':
searchar = '/';
break;
case 't':
#ifndef XPG4
tflag++;
#endif
break;
case 'u':
uflag++;
break;
case 'v':
vflag++;
xflag++;
break;
case 'w':
wflag++;
break;
case 'x':
xflag++;
break;
case 'f':
outfile = strdup(optarg);
break;
default:
Usage();
break;
}
}
if (optind == mac) {
Usage();
}
init();
for (file_num = optind; file_num < mac; file_num++)
find_entries(mav[file_num]);
if (xflag) {
put_entries(head);
exit(infile_fail > 0 ? 2 : 0);
}
if (uflag) {
for (i = 1; i < mac; i++) {
(void) sprintf(cmd,
"mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",
outfile, mav[i], outfile);
(void) system(cmd);
}
aflag++;
}
outf = fopen(outfile, aflag ? "a" : "w");
if (outf == NULL) {
perror(outfile);
exit(1);
}
put_entries(head);
(void) fclose(outf);
if (uflag) {
(void) sprintf(cmd, "sort %s -o %s", outfile, outfile);
(void) system(cmd);
}
return (infile_fail > 0 ? 2 : 0);
}
static void
init(void)
{
char *sp;
int i;
for (i = 0; i < 0177; i++) {
_wht[i] = _etk[i] = _itk[i] = _btk[i] = FALSE;
_opr[i] = FALSE;
_gd[i] = TRUE;
}
for (sp = white; *sp; sp++)
_wht[*sp] = TRUE;
for (sp = endtk; *sp; sp++)
_etk[*sp] = TRUE;
for (sp = intk; *sp; sp++)
_itk[*sp] = TRUE;
for (sp = begtk; *sp; sp++)
_btk[*sp] = TRUE;
for (sp = oprtk; *sp; sp++)
_opr[*sp] = TRUE;
for (sp = notgd; *sp; sp++)
_gd[*sp] = FALSE;
}
static void
find_entries(char *file)
{
char *cp;
struct stat st;
if (stat(file, &st) == 0 && !S_ISREG(st.st_mode))
return;
if ((inf = fopen(file, "r")) == NULL) {
perror(file);
infile_fail++;
return;
}
curfile = savestr(file);
lineno = 0;
cp = strrchr(file, '.');
if (cp && cp[1] == 'l' && cp[2] == '\0') {
if (strchr(";([", first_char()) != NULL)
{
L_funcs(inf);
(void) fclose(inf);
return;
} else {
toss_yysec();
getaline(lineftell);
pfnote("yylex", lineno, TRUE);
toss_yysec();
C_entries();
(void) fclose(inf);
return;
}
}
if (cp && cp[1] == 'y' && cp[2] == '\0') {
toss_yysec();
Y_entries();
C_entries();
(void) fclose(inf);
return;
}
if (cp && (cp[1] != 'C' && cp[1] != 'c' && cp[1] != 'h') &&
cp[2] == '\0' && (strcmp(cp, ".cc") == 0) &&
(strcmp(cp, ".cxx") == 0)) {
if (PF_funcs(inf) != 0) {
(void) fclose(inf);
return;
}
rewind(inf);
}
C_entries();
(void) fclose(inf);
}
static void
pfnote(char *name, int ln, bool f)
{
char *fp;
NODE *np;
char *nametk;
char nbuf[BUFSIZ];
if ((np = malloc(sizeof (NODE))) == NULL) {
(void) fprintf(stderr,
gettext("ctags: too many entries to sort\n"));
put_entries(head);
free_tree(head);
head = np = (NODE *) malloc(sizeof (NODE));
}
if (xflag == 0 && (strcmp(name, "main") == 0)) {
fp = strrchr(curfile, '/');
if (fp == 0)
fp = curfile;
else
fp++;
(void) sprintf(nbuf, "M%s", fp);
fp = strrchr(nbuf, '.');
if (fp && ((fp[2] == 0) || (fp[2] == 'c' && fp[3] == 0) ||
(fp[3] == 'x' && fp[4] == 0)))
*fp = 0;
name = nbuf;
}
if (strchr(name, ' ') != NULL)
{
(void) strcpy(name, strtok(name, " "));
while ((nametk = strtok(0, " ")) != NULL)
(void) strcat(name, nametk);
}
np->entry = savestr(name);
np->file = curfile;
np->f = f;
np->lno = ln;
np->left = np->right = 0;
if (xflag == 0) {
lbuf[50] = 0;
(void) strcat(lbuf, "$");
lbuf[50] = 0;
}
np->pat = savestr(lbuf);
if (head == NULL)
head = np;
else
add_node(np, head);
}
static void
C_entries(void)
{
int c;
char *token, *tp;
bool incomm, inquote, inchar, midtoken, isoperator, optfound;
int level;
char *sp;
char tok[BUFSIZ];
long int tokftell;
number = gotone = midtoken = inquote = inchar =
incomm = isoperator = optfound = FALSE;
level = 0;
sp = tp = token = line;
lineno++;
lineftell = tokftell = ftell(inf);
for (;;) {
*sp = c = getc(inf);
if (feof(inf))
break;
if (c == '\n') {
lineftell = ftell(inf);
lineno++;
} else if (c == '\\') {
c = *++sp = getc(inf);
if ((c == '\n') || (c == EOF)) {
lineftell = ftell(inf);
lineno++;
c = ' ';
}
} else if (incomm) {
if (c == '*') {
while ((*++sp = c = getc(inf)) == '*')
continue;
if ((c == '\n') || (c == EOF)) {
lineftell = ftell(inf);
lineno++;
}
if (c == '/')
incomm = FALSE;
}
} else if (inquote) {
if (c == '"')
inquote = FALSE;
continue;
} else if (inchar) {
if (c == '\'')
inchar = FALSE;
continue;
} else if (midtoken == TRUE) {
goto dotoken;
} else switch (c) {
case '"':
inquote = TRUE;
continue;
case '\'':
inchar = TRUE;
continue;
case '/':
*++sp = c = getc(inf);
if (c == '*')
incomm = TRUE;
else if (c == '/') {
do {
c = getc(inf);
} while ((c != '\n') && (c != EOF));
lineftell = ftell(inf);
lineno++;
*--sp = c;
}
else
(void) ungetc(*sp, inf);
continue;
case '#':
if (sp == line)
number = TRUE;
continue;
case '{':
if ((tydef == begin_rec) || (tydef == begin_tag)) {
tydef = middle;
}
level++;
continue;
case '}':
if (sp == line)
level = 0;
else
level--;
if (!level && tydef == middle) {
tydef = end;
}
if (!level && tydef == none)
goto dotoken;
continue;
}
dotoken:
if (!level && !inquote && !incomm && gotone == FALSE) {
if (midtoken) {
if (endtoken(c)) {
if (optoken(c)) {
if (isoperator) {
if (optfound) {
if (c != '(') {
tp++;
goto next_char;
}
} else {
if (c != ' ') {
optfound = TRUE;
}
tp++;
goto next_char;
}
} else {
char *backptr = tp - 7;
if (strncmp(backptr, "operator", 8) == 0) {
isoperator = TRUE;
if (c != ' ') {
optfound = TRUE;
}
tp++;
goto next_char;
} else if (c == '~') {
tp++;
goto next_char;
}
}
} else if (c == ':') {
if ((*++sp = getc(inf)) == ':') {
tp += 2;
c = *sp;
goto next_char;
} else {
(void) ungetc (*sp, inf);
--sp;
}
}
{
int f;
int pfline = lineno;
if (start_entry(&sp, token, &f)) {
(void) strncpy(tok, token, tp-token+1);
tok[tp-token+1] = 0;
getaline(tokftell);
pfnote(tok, pfline, f);
gotone = f;
}
isoperator = optfound = midtoken = FALSE;
token = sp;
}
} else if (intoken(c))
tp++;
} else if (begtoken(c)) {
token = tp = sp;
midtoken = TRUE;
tokftell = lineftell;
}
}
next_char:
if (c == ';' && tydef == end)
tydef = none;
sp++;
if (c == '\n' ||c == '}'|| sp > &line[sizeof (line) - BUFSIZ]) {
tp = token = sp = line;
number = gotone = midtoken = inquote =
inchar = isoperator = optfound = FALSE;
}
}
}
static int
start_entry(char **lp, char *token, int *f)
{
char *sp;
int c;
static bool found;
bool firsttok;
int bad;
*f = 1;
sp = *lp;
c = *sp;
bad = FALSE;
if (!number) {
while (iswhite(c)) {
*++sp = c = getc(inf);
if ((c == '\n') || (c == EOF)) {
lineno++;
lineftell = ftell(inf);
if (sp > &line[sizeof (line) - BUFSIZ])
goto ret;
}
}
} else {
if (strncmp(token, "define", 6) == 0)
found = 0;
else
found++;
if (found >= 2) {
gotone = TRUE;
badone: bad = TRUE;
goto ret;
}
}
#ifdef XPG4
if (strncmp(token, "typedef", 7) == 0) {
#else
if (tflag && (strncmp(token, "typedef", 7) == 0)) {
#endif
tydef = begin;
goto badone;
}
if (tydef == begin && ((strncmp(token, "struct", 6) == 0) ||
(strncmp(token, "class", 5) == 0) ||
(strncmp(token, "union", 5) == 0)||
(strncmp(token, "enum", 4) == 0))) {
tydef = begin_rec;
goto badone;
}
if (tydef == begin) {
tydef = end;
goto badone;
}
if (tydef == begin_rec) {
tydef = begin_tag;
goto badone;
}
if (tydef == begin_tag) {
tydef = end;
goto gottydef;
}
gottydef:
if (tydef == end) {
*f = 0;
goto ret;
}
if (c != '(')
goto badone;
firsttok = FALSE;
while ((*++sp = c = getc(inf)) != ')') {
if ((c == '\n') || (c == EOF)) {
lineftell = ftell(inf);
lineno++;
if (sp > &line[sizeof (line) - BUFSIZ])
goto ret;
}
if (begtoken(c) || c == '/')
firsttok = TRUE;
else if (!iswhite(c) && !firsttok)
goto badone;
}
while (iswhite(*++sp = c = getc(inf)))
if ((c == '\n') || (c == EOF)) {
lineno++;
lineftell = ftell(inf);
if (sp > &line[sizeof (line) - BUFSIZ])
break;
}
ret:
*lp = --sp;
if (c == '\n')
lineno--;
(void) ungetc(c, inf);
return (!bad && (!*f || isgood(c)));
}
static void
Y_entries(void)
{
char *sp, *orig_sp;
int brace;
bool in_rule = FALSE;
size_t toklen;
char tok[LINEBUFSIZ];
brace = 0;
getaline(lineftell);
pfnote("yyparse", lineno, TRUE);
while (fgets(line, sizeof (line), inf) != NULL) {
for (sp = line; *sp; sp++) {
switch (*sp) {
case '\n':
lineno++;
case ' ':
case '\t':
case '\f':
case '\r':
break;
case '"':
case '\'': {
char start = *sp;
sp++;
while ((*sp != '\0') && (*sp != start)) {
if (*sp == '\\')
sp++;
sp++;
}
if (*sp == '\0')
sp--;
break;
}
case '/':
if (*++sp == '*')
sp = toss_comment(sp);
else
--sp;
break;
case '{':
brace++;
break;
case '}':
brace--;
break;
case '%':
if (sp[1] == '%' && sp == line)
return;
break;
case '|':
case ';':
in_rule = FALSE;
break;
default:
if (brace == 0 && !in_rule && (isalpha(*sp) ||
*sp == '.' ||
*sp == '_')) {
orig_sp = sp;
++sp;
while (isalnum(*sp) || *sp == '_' ||
*sp == '.')
sp++;
toklen = sp - orig_sp;
while (isspace(*sp))
sp++;
if (*sp == ':' || (*sp == '\0' &&
first_char() == ':')) {
(void) strncpy(tok,
orig_sp, toklen);
tok[toklen] = '\0';
(void) strcpy(lbuf, line);
lbuf[strlen(lbuf) - 1] = '\0';
pfnote(tok, lineno, TRUE);
in_rule = TRUE;
if (*sp == '\0')
sp--;
} else {
sp--;
}
}
break;
}
}
}
}
static char *
toss_comment(char *start)
{
char *sp;
do {
while ((sp = strchr(start, '*')) != NULL)
if (sp[1] == '/')
return (++sp);
else
start = (++sp);
start = line;
lineno++;
} while (fgets(line, sizeof (line), inf) != NULL);
return (sp);
}
static void
getaline(long int where)
{
long saveftell = ftell(inf);
char *cp;
(void) fseek(inf, where, 0);
(void) fgets(lbuf, sizeof (lbuf), inf);
cp = strrchr(lbuf, '\n');
if (cp)
*cp = 0;
(void) fseek(inf, saveftell, 0);
}
static void
free_tree(NODE *node)
{
NODE *next;
while (node) {
free_tree(node->right);
next = node->left;
free(node);
node = next;
}
}
static void
add_node(NODE *node, NODE *cur_node)
{
int dif;
dif = strcmp(node->entry, cur_node->entry);
if (dif == 0) {
if (node->file == cur_node->file) {
if (!wflag) {
(void) fprintf(stderr,
gettext("Duplicate entry in file %s, line %d: %s\n"),
node->file, lineno, node->entry);
(void) fprintf(stderr,
gettext("Second entry ignored\n"));
}
return;
}
if (!cur_node->been_warned)
if (!wflag) {
(void) fprintf(stderr, gettext("Duplicate "
"entry in files %s and %s: %s "
"(Warning only)\n"),
node->file, cur_node->file,
node->entry);
}
cur_node->been_warned = TRUE;
return;
}
if (dif < 0) {
if (cur_node->left != NULL)
add_node(node, cur_node->left);
else
cur_node->left = node;
return;
}
if (cur_node->right != NULL)
add_node(node, cur_node->right);
else
cur_node->right = node;
}
static void
put_entries(NODE *node)
{
char *sp;
if (node == NULL)
return;
put_entries(node->left);
#ifdef XPG4
if (xflag == 0) {
(void) fprintf(outf, "%s\t%s\t%c^",
node->entry, node->file, searchar);
for (sp = node->pat; *sp; sp++)
if (*sp == '\\')
(void) fprintf(outf, "\\\\");
else if (*sp == searchar)
(void) fprintf(outf, "\\%c", searchar);
else
(void) putc(*sp, outf);
(void) fprintf(outf, "%c\n", searchar);
} else if (vflag)
(void) fprintf(stdout, "%s %s %d\n",
node->entry, node->file, (node->lno+63)/64);
else
(void) fprintf(stdout, "%-16s %4d %-16s %s\n",
node->entry, node->lno, node->file, node->pat);
#else
if (xflag == 0)
if (node->f) {
(void) fprintf(outf, "%s\t%s\t%c^",
node->entry, node->file, searchar);
for (sp = node->pat; *sp; sp++)
if (*sp == '\\')
(void) fprintf(outf, "\\\\");
else if (*sp == searchar)
(void) fprintf(outf, "\\%c", searchar);
else
(void) putc(*sp, outf);
(void) fprintf(outf, "%c\n", searchar);
} else {
(void) fprintf(outf, "%s\t%s\t%d\n",
node->entry, node->file, node->lno);
} else if (vflag)
(void) fprintf(stdout, "%s %s %d\n",
node->entry, node->file, (node->lno+63)/64);
else
(void) fprintf(stdout, "%-16s %4d %-16s %s\n",
node->entry, node->lno, node->file, node->pat);
#endif
put_entries(node->right);
}
static int
PF_funcs(FILE *fi)
{
pfcnt = 0;
while (fgets(lbuf, sizeof (lbuf), fi)) {
lineno++;
dbp = lbuf;
if (*dbp == '%') dbp++;
while (isspace(*dbp))
dbp++;
if (*dbp == 0)
continue;
switch (*dbp |' ') {
case 'i':
if (tail("integer"))
takeprec();
break;
case 'r':
if (tail("real"))
takeprec();
break;
case 'l':
if (tail("logical"))
takeprec();
break;
case 'c':
if (tail("complex") || tail("character"))
takeprec();
break;
case 'd':
if (tail("double")) {
while (isspace(*dbp))
dbp++;
if (*dbp == 0)
continue;
if (tail("precision"))
break;
continue;
}
break;
}
while (isspace(*dbp))
dbp++;
if (*dbp == 0)
continue;
switch (*dbp|' ') {
case 'f':
if (tail("function"))
getit();
continue;
case 's':
if (tail("subroutine"))
getit();
continue;
case 'p':
if (tail("program")) {
getit();
continue;
}
if (tail("procedure"))
getit();
continue;
}
}
return (pfcnt);
}
static int
tail(char *cp)
{
int len = 0;
while (*cp && (*cp&~' ') == ((*(dbp+len))&~' '))
cp++, len++;
if (*cp == 0) {
dbp += len;
return (1);
}
return (0);
}
static void
takeprec(void)
{
while (isspace(*dbp))
dbp++;
if (*dbp != '*')
return;
dbp++;
while (isspace(*dbp))
dbp++;
if (!isdigit(*dbp)) {
--dbp;
return;
}
do
dbp++;
while (isdigit(*dbp));
}
static void
getit(void)
{
char *cp;
char c;
char nambuf[LINEBUFSIZ];
for (cp = lbuf; *cp; cp++)
;
*--cp = 0;
while (isspace(*dbp))
dbp++;
if (*dbp == 0 || !isalpha(*dbp) || !isascii(*dbp))
return;
for (cp = dbp+1; *cp && (isalpha(*cp) || isdigit(*cp)); cp++)
continue;
c = cp[0];
cp[0] = 0;
(void) strcpy(nambuf, dbp);
cp[0] = c;
pfnote(nambuf, lineno, TRUE);
pfcnt++;
}
static char *
savestr(char *cp)
{
int len;
char *dp;
len = strlen(cp);
dp = (char *)malloc(len+1);
(void) strcpy(dp, cp);
return (dp);
}
static void
L_funcs(FILE *fi)
{
int special;
pfcnt = 0;
while (fgets(lbuf, sizeof (lbuf), fi)) {
lineno++;
dbp = lbuf;
if (dbp[0] == '(' &&
(dbp[1] == 'D' || dbp[1] == 'd') &&
(dbp[2] == 'E' || dbp[2] == 'e') &&
(dbp[3] == 'F' || dbp[3] == 'f')) {
dbp += 4;
if (striccmp(dbp, "method") == 0 ||
striccmp(dbp, "wrapper") == 0 ||
striccmp(dbp, "whopper") == 0)
special = TRUE;
else
special = FALSE;
while (!isspace(*dbp))
dbp++;
while (isspace(*dbp))
dbp++;
L_getit(special);
}
}
}
static void
L_getit(int special)
{
char *cp;
char c;
char nambuf[LINEBUFSIZ];
for (cp = lbuf; *cp; cp++)
continue;
*--cp = 0;
if (*dbp == 0)
return;
if (special) {
if ((cp = strchr(dbp, ')')) == NULL)
return;
while (cp >= dbp && *cp != ':')
cp--;
if (cp < dbp)
return;
dbp = cp;
while (*cp && *cp != ')' && *cp != ' ')
cp++;
}
else
for (cp = dbp + 1; *cp && *cp != '(' && *cp != ' '; cp++)
continue;
c = cp[0];
cp[0] = 0;
(void) strcpy(nambuf, dbp);
cp[0] = c;
pfnote(nambuf, lineno, TRUE);
pfcnt++;
}
static int
striccmp(char *str, char *pat)
{
int c1;
while (*pat) {
if (isupper(*str))
c1 = tolower(*str);
else
c1 = *str;
if (c1 != *pat)
return (c1 - *pat);
pat++;
str++;
}
return (0);
}
static int
first_char(void)
{
int c;
long off;
off = ftell(inf);
while ((c = getc(inf)) != EOF)
if (!isspace(c) && c != '\r') {
(void) fseek(inf, off, 0);
return (c);
}
(void) fseek(inf, off, 0);
return (EOF);
}
static void
toss_yysec(void)
{
char buf[BUFSIZ];
for (;;) {
lineftell = ftell(inf);
if (fgets(buf, BUFSIZ, inf) == NULL)
return;
lineno++;
if (strncmp(buf, "%%", 2) == 0)
return;
}
}
static void
Usage(void)
{
#ifdef XPG4
(void) fprintf(stderr, gettext("Usage:\tctags [-aBFuvw] "
#else
(void) fprintf(stderr, gettext("Usage:\tctags [-aBFtuvw] "
#endif
"[-f tagsfile] file ...\n"));
(void) fprintf(stderr, gettext("OR:\tctags [-x] file ...\n"));
exit(1);
}
static void
parseargs(int ac, char **av)
{
int i;
int a;
int fflag;
size_t sz;
size_t mav_sz;
i = mac = fflag = 0;
mav_sz = ((ac + 1) * sizeof (char *));
if ((mav = malloc(mav_sz)) == (char **)NULL) {
perror("Can't malloc argument space");
exit(1);
}
for (; (av[i] != NULL) && (av[i][0] != '\0'); i++) {
if (strcmp(av[i], "--") == 0) {
fflag = 1;
}
sz = strlen(&av[i][0]);
if (fflag == 0 &&
av[i][0] == '-' &&
sz > 2) {
for (a = 1; av[i][a]; a++) {
if (a > 1) {
mav_sz += sizeof (char *);
if ((mav = realloc(mav, mav_sz)) ==
(char **)NULL) {
perror("Can't realloc "
"argument space");
exit(1);
}
}
if ((mav[mac] = malloc((size_t)CPFLAG)) ==
(char *)NULL) {
perror("Can't malloc argument space");
exit(1);
}
(void) sprintf(mav[mac], "-%c", av[i][a]);
++mac;
}
} else {
if ((mav[mac] = malloc(sz + 1)) == (char *)NULL) {
perror("Can't malloc argument space");
exit(1);
}
(void) strcpy(mav[mac], av[i]);
++mac;
}
}
mav[mac] = (char *)NULL;
}