/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1994-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* ncsl [file ...]
*
* ncsl -- list the number of non-comment source lines for each C file
*/
static const char usage[] =
"[-?\n@(#)$Id: ncsl (AT&T Research) 1996-10-11 $\n]"
"[+NAME?ncsl - list the number of non-comment source lines for each C file]"
"[+DESCRIPTION?\bncsl\b lists the number of non-comment source lines for"
" each C \afile\a argument. If no \afile\a arguments are specified then"
" the standard input is read. /*...*/ and // style comments are"
" recognized.]"
"[s:summary?If more than one \afile\a is specified then list a summary count"
" for all files.]"
"\n"
"\n[ file ... ]\n"
"\n"
"[+SEE ALSO?\bwc\b(1)]"
;
#include <ast.h>
#include <ctype.h>
#include <error.h>
/*
* return number of ncsl in sp
*/
static int
{
register int c;
register int data;
register unsigned long line;
int quote;
line = 0;
data = 0;
{
case EOF:
return(line);
case ' ':
case '\f':
case '\t':
break;
case '\n':
if (data)
{
data = 0;
}
break;
case '/':
{
case '/':
{
case EOF:
goto again;
case '\n':
goto newline;
default:
if (JUNK(c))
{
data = -1;
goto again;
}
break;
}
break;
case '*':
{
case EOF:
case '*':
for (;;)
{
{
case EOF:
case '/':
goto again;
case '*':
continue;
default:
if (JUNK(c))
{
data = -1;
goto again;
}
break;
}
break;
}
break;
default:
if (JUNK(c))
{
data = -1;
goto again;
}
break;
}
break;
case EOF:
break;
default:
break;
}
break;
case '"':
case '\'':
data = 1;
quote = c;
{
case EOF:
goto again;
case '"':
case '\'':
break;
case '\n':
goto newline;
case '\\':
{
case EOF:
goto again;
case '\n':
line++;
continue;
}
/*FALLTHROUGH*/
default:
if (JUNK(c))
{
data = -1;
goto again;
}
break;
}
break;
default:
break;
}
/*NOTREACHED*/
}
int
{
register char* s;
unsigned long n;
int summary = 0;
unsigned long total = 0;
int trailer;
for (;;)
{
{
case 0:
break;
case 's':
summary = 1;
continue;
case '?':
continue;
case ':':
continue;
}
break;
}
if (error_info.errors)
if (*argv)
{
while (s = *argv++)
{
else
{
if (!summary)
total += n;
}
}
}
else
return error_info.errors != 0;
}