/*linecounter.c*/
/*----------------------------------------------------------------------------*/
/* include file */
/*----------------------------------------------------------------------------*/
//#include "StdAfx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "count_cmn.h"
#include "count_line.h"
/*----------------------------------------------------------------------------*/
/* define */
/*----------------------------------------------------------------------------*/
//#define TESTFILE "D:\\work\\test.c"
/*----------------------------------------------------------------------------*/
/* structure definition */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* global variable declaration */
/*----------------------------------------------------------------------------*/
_LINECOUNT gtCount;
/*----------------------------------------------------------------------------*/
/* static variable declaration */
/*----------------------------------------------------------------------------*/
static _LINECOL stCol;
static _COMMENT stComment;
static int siStatus; /*行ステータス*/
static int siStrStatus; /*文字ステータス*/
static int siCommentIndex; /*ブロックコメントのインデックス*/
static char buff[BUFF_LINE_SIZE];
/*----------------------------------------------------------------------------*/
/* static function declaration */
/*----------------------------------------------------------------------------*/
static int seachLine();
static int getStatus(char **ppcurrent);
static void countCols(char *currentp, char *oldp);
static void countCol();
static void countLine();
static int isCommentStart(char *curentp);
static int seachCommentEnd(char **ppcurent);
static int seachStringKey(char **ppcurent);
static int isStringKey(char *pcurent);
/*----------------------------------------------------------------------------*/
/* global function */
/*----------------------------------------------------------------------------*/
/*コメントの設定*/
int initDefaultSetComment()
{
int iRet;
_COMMENT tComment;
iRet = RET_OK;
memset(&tComment, 0x00, sizeof(_COMMENT));
/*コメント数*/
tComment.iNum = COMMENT_DEFAULTNUM;
/*ラインコメント*/
tComment.stCmnt[0].iType = COMMENT_TYPE_LINE;
strcpy(tComment.stCmnt[0].cCmntS, COMMENT_LINE);
/*ブロックコメント*/
tComment.stCmnt[1].iType = COMMENT_TYPE_BLOCK;
strcpy(tComment.stCmnt[1].cCmntS, COMMENT_BLOCKSTART);
strcpy(tComment.stCmnt[1].cCmntE, COMMENT_BLOCKEND);
setComment(&tComment);
return iRet;
}
/*コメントの設定*/
int setComment(_COMMENT* ptComment)
{
int iRet;
iRet = RET_OK;
memcpy(&stComment, ptComment, sizeof(_COMMENT));
return iRet;
}
/*カウント*/
int getLineCount(FILE *fin) {
int iRet;/*返却値*/
/*初期化*/
iRet = RET_NG;
memset(>Count, 0x00, sizeof(_LINECOUNT));
/*引数確認*/
if(fin == NULL) {
goto FUNC_END;
}
/*静的変数の初期化*/
siStatus = LINE_STATUS_INIT;
siStrStatus = STR_STATUS_INIT;
siCommentIndex = COMMENT_INDEX_NONE;
/*一行取得*/
while(fgets(buff, BUFF_LINE_SIZE, fin) != NULL){
/*一文字ずつチェックする*/
seachLine();
/*ライン数カウント*/
countLine();
}
iRet = RET_OK;
FUNC_END:
return iRet;
}
/*----------------------------------------------------------------------------*/
/* static function */
/*----------------------------------------------------------------------------*/
/*ラインの状態検索*/
static int seachLine(){
char *currentp, *oldp;
/*文字数初期化*/
memset(&stCol, 0x00, sizeof(_LINECOL));
/*buffの末尾の改行文字を取り除いておく*/
while(strlen(buff) > 0){
if(IS_BREAK_LINE(&buff[strlen(buff) - 1])){
buff[strlen(buff) - 1] = '\0';
}else{
break;
}
}
currentp = buff;
/*一文字ずつチェックする*/
while(!IS_NULL_CHAR(currentp)){
/*空白省略*/
if(IS_WHITE_SPACE(currentp) || IS_BREAK_LINE(currentp)){
currentp++;
continue;
}
/*現在ポインタを覚えておく*/
oldp = currentp;
/*文字列状態確認*/
if(siStrStatus != STR_STATUS_INIT){
/*文字列終了検索*/
seachStringKey(¤tp);
/*文字数カウント*/
countCols(currentp, oldp);
/*次の文字へ*/
currentp++;
continue;
}
/*TODO 文字数カウントがちゅうとはんぱ?*/
/*行ステータス確認*/
switch(siStatus){
case LINE_STATUS_PREPRO: /*FALLTHROUGH*/
case LINE_STATUS_INIT:
/*実行行*/
getStatus(¤tp);
/*次の文字へ*/
currentp++;
/*文字数カウント*/
countCols(currentp, oldp);
break;
case LINE_STATUS_BLOCKCOMMENT:
/*ブロックコメント終了検索*/
seachCommentEnd(¤tp);
stCol.iCmntCol += currentp - oldp;
break;
case LINE_STATUS_LINECOMMENT:
default:
/*行末尾(NULL文字前)まで移動*/
currentp += strlen(currentp);
stCol.iCmntCol += currentp - oldp;
break;
}
}/*END while*/
return RET_OK;
}
/*コメント,プリプロ行開始検索*/
static int getStatus(char **ppcurrent)
{
int iRet;
char *p;
p = *ppcurrent;
iRet = RET_FALSE;
if(isCommentStart(p)){
/*コメント文字の末尾まで移動*/
p += strlen(stComment.stCmnt[siCommentIndex].cCmntS) - 1;
/*コメント行開始*/
iRet = RET_TRUE;
goto FUNC_END;
}else if(IS_PREPRO(p)
&& (stCol.iCol + stCol.iPreCol) == 0){
/*コメントを除いた行頭に#がある場合のみ*/
/*プリプロ行開始*/
siStatus = LINE_STATUS_PREPRO;
iRet = RET_TRUE;
/*インクルード開始か?*/
/*プリプロ開始文字の次の文字を見る(空白省略)*/
p++;
SKIP_WHITE_SPACE(&p);
if(!IS_NULL_CHAR(p)){
if(strncmp(p, PREPRO_NAME_INCLUDE, strlen(PREPRO_NAME_INCLUDE)) == 0){
/*include<>かどうかを探す*/
p += strlen(PREPRO_NAME_INCLUDE);
SKIP_WHITE_SPACE(&p);
if((*p) == '<'){
siStrStatus = STR_STATUS_INCLUDE;
}else if((*p) == '\"'){
siStrStatus = STR_STATUS_STRING;
}
/*'はありえない*/
}
}
goto FUNC_END;
}
/*文字列開始か?*/
if(isStringKey(p)){
iRet = RET_TRUE;
}
FUNC_END:
*ppcurrent= p;
return RET_OK;
}
/*文字数かうんと*/
static void countCols(char *currentp, char *oldp)
{
char *p;
p = oldp;
while(p <= currentp){
countCol();
p++;
}
return;
}
/*文字数かうんと*/
static void countCol()
{
/*文字数カウント*/
switch(siStatus){
case LINE_STATUS_LINECOMMENT:
/*ラインコメント*/
stCol.iCmntCol++;
break;
case LINE_STATUS_BLOCKCOMMENT:
stCol.iCmntCol++;
break;
case LINE_STATUS_PREPRO:
/*プリプロ行*/
stCol.iPreCol++;
break;
case LINE_STATUS_INIT: /*FALLTHROUGH*/
default:
/*実行行*/
stCol.iCol++;
break;
}
}
/*ライン数かうんと*/
static void countLine()
{
#if CNT_DEBUG
// printf("col = %d, pre = %d, comment = %d\n",stCol.iCol, stCol.iPreCol, stCol.iCmntCol);
#endif
/*ライン数カウント*/
if(stCol.iCol > 0){
/*実
没有合适的资源?快使用搜索试试~ 我知道了~
能够对文件夹,代码文件进行行数统计
共30个文件
c:18个
h:4个
makefile:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 182 浏览量
2023-01-30
11:22:39
上传
评论
收藏 30KB ZIP 举报
温馨提示
能够对文件夹,代码文件进行行数统计,还可以对头文件也可以进行统计,统计出实际的行数,对注释也可以进行统计。 支持多种语言的代码统计C#.zip
资源推荐
资源详情
资源评论
收起资源包目录
能够对文件夹,代码文件进行行数统计,还可以对头文件也可以进行统计,统计出实际的行数,对注释也可以进行统计。 支持多种语言的代码统计C#.zip (30个子文件)
G2
diff
after
equ.c 180B
newfile.c 255B
newdir
newdir_diff.c 2KB
diffdir
diffdir_equ.c 180B
diffdir_diff.c 2KB
diffdir_newfile.c 255B
diff.c 2KB
before
equ.c 180B
diffdir
diffdir_equ.c 180B
diffdir_diff.c 2KB
diffdir_delfile.c 255B
delfile.c 255B
diff.c 2KB
deldir
deldir_diff.c 2KB
cnt
inc
file_cmn.h 2KB
count_cmn.h 2KB
lib
file
src
file_util.c 6KB
Makefile 1KB
Makefile 280B
CodeMetrics_win
CodeMetrics
CodeMetrics.plg 1KB
CodeMetrics.dsw 551B
CodeMetrics.dsp 5KB
CodeMetrics.ncb 49KB
CodeMetrics.opt 48KB
main
inc
count_result.h 2KB
count_line.h 4KB
Makefile 1KB
src
count_main.c 5KB
count_result.c 4KB
count_line.c 12KB
共 30 条
- 1
资源评论
处处清欢
- 粉丝: 149
- 资源: 2471
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功