home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume8
/
mgt
/
part03
/
comment.c
next >
Wrap
C/C++ Source or Header
|
1990-02-23
|
2KB
|
117 lines
/*
"mgt" Copyright 1990 Shodan
All Rights Reserved.
Program by Greg Hale
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that this entire comment and copyright notice appear in all
copies and that both that copyright notice and this permission notice
appear in supporting documentation. No representations are made about
the suitability of this software for any purpose. It is provided "as
is" without express or implied warranty.
Please send copies of extensions to:
hale@scam.berkeley.edu
128.32.138.4 scam.berkeley.edu sting sting.Berkeley.EDU
Donations for the 'From My Go Teacher' series may be sent to:
Shodan
P.O. Box 4456
Berkeley, CA 94704
(415) 849-9475
*/
#include "mgt.h"
#include <strings.h>
#include <stdio.h>
#include <ctype.h>
#define MAXWIDTH 256
#define MAXCOMMENT 128
short commentlines;
char commentbuf[MAXCOMMENT][MAXWIDTH];
FUNCTION char *commentGet(line) /* int */
int line;
{
return commentbuf[line];
}
FUNCTION int commentLines()
{
return commentlines;
}
FUNCTION void commentClear()
{
int i;
commentlines = 0;
}
FUNCTION int wordLength(word) /* char * */
char * word;
{
int len;
len = 0;
while (*word && !isspace(*word++))
len++;
return MIN(len,1);
}
FUNCTION int commentLineLength(comment,width) /* char *, int */
char *comment;
int width;
{
int len,wlen;
len = 0;
while (wlen = wordLength(comment), *comment && wlen + len < width)
len += wlen, comment+= wlen;
return len ? len : MIN(wlen,width);
}
FUNCTION void formatComment(comment,width) /* char *, int */
char *comment;
int width;
{
char c;
commentlines = 0;
width = MIN(width,MAXWIDTH-1);
do {
short len, srch;
len = srch = 0;
do {
c = comment[srch++];
if (c == ' ') {
len = srch;
} else if (c == '\n' || !c) {
len = srch-1;
break;
}
if (srch == width) {
len = len ? len : srch;
break;
}
} while (c);
if (len)
strncpy(commentbuf[commentlines], comment, len);
commentbuf[commentlines++][len] = '\0';
comment += len + (c == '\n');
while (*comment==' ')
comment++;
} while (c);
}