home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume8
/
cz
/
part07
/
get-header.c
< prev
Wrap
C/C++ Source or Header
|
1989-10-01
|
3KB
|
131 lines
/*
* get-header - extract a header from a mail message or news article
*/
#ifndef lint
static char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
#endif lint
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 1,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <howard/port.h>
#include <howard/version.h>
#include <howard/usage.h>
MAINVER ("@(#)$Header: get-header.c,v 1.3 89/08/19 11:11:26 howard Exp $");
USAGE ("[-f] [-i] [-w] header [default]");
#include <howard/malf.h>
#include <howard/registers.i>
#define MLINE 1024 /* Max line length.*/
PRIVATE char eIntern[] = "Internal error %s";
/* main - main function */
PUBLIC int main (argc, argv)
int argc; /* Number of arguments.*/
R4 bStrT *argv; /* Points to array of argument strings.*/
/* Function:
*
* Algorithm:
* Decode arguments. Read stdin until a match or a blank line.
* If no match, write the default if there is one.
* If there's no full name extraction, just write the field.
* Notes:
*
*/
{
R5 rcharT c; /* Option letter.*/
R3 bStrT cp; /* Steps through args.*/
extern int optind; /* See getopt (3).*/
extern cStrT optarg; /* See getopt (3).*/
R8 boolT fullnm = FALSE; /* Get full name.*/
R2 boolT igncase = FALSE; /* Ignore case.*/
unsigned ln = 0; /* Input line number.*/
R1 bStrT p; /* Steps through lb[].*/
R6 boolT stripwh = FALSE; /* Strip leading spaces and tabs.*/
byteT fnb[MLINE]; /* Line buffer.*/
byteT lb[MLINE]; /* Line buffer.*/
while (EOF != (c = getopt (argc, (cStrT *) argv, "fiw")))
{
switch (c)
{
case '?':
usage();
break;
case 'f':
fullnm = TRUE;
break;
case 'i':
igncase = TRUE;
break;
case 'w':
stripwh = TRUE;
break;
default:
malf1 (eIntern, "main 1");
break;
}
}
argv += optind;
cp = *argv++;
if (NULBSTR == cp) usage();
while (NULBSTR != (p = getlin (lb, MLINE, stdin, S("Standard Input"), &ln, 0)))
{
p = (igncase ? prefxi (cp, lb) : prefix (cp, lb));
if ((NULBSTR != p) && (':' == B(*p)) && SPCTAB (B(p[1])))
{
p += 2;
break;
}
else if (EOS == B(lb[0]))
{
p = NULBSTR;
break;
}
}
if (stripwh && (NULBSTR != p))
{
while (SPCTAB (B(*p)))
++p;
}
if ((NULBSTR == p) || (EOS == B(*p)))
{
cp = *argv++;
if (NULBSTR != cp)
{
if (NULBSTR != *argv) usage();
PUTS (cp);
}
}
else if (fullnm && msgfn (p, fnb))
PUTS (fnb);
else
PUTS (p);
mfflush (stdout, S("Standard Output"));
exit (SUCCESS);
#ifdef lint
return (SUCCESS);
#endif
}