📄 kf.c
字号:
/**************************************************/
/**************************************************/
/*
struct line_list_struct * read_the_lines(...
FILE *, int *);
Here in kf, a paragraph ends when the first character
of a new line is a special character . < #
*/
struct line_list_struct * read_the_lines(
FILE *input_file, int *file_done)
{
char aline[L];
int first_pass = 1,
reading = 1;
struct line_list_struct *new_one,
*result,
*temp;
while(reading){
if(fgets(aline, L, input_file) == NULL){
*file_done = 1;
reading = 0;
} /* ends if fgets is NULL */
if(first_pass){
new_one = (struct line_list_struct *)
calloc(1, sizeof(struct line_list_struct));
temp = new_one;
result = new_one;
first_pass = 0;
new_one->next_line = END_OF_LIST;
strcpy(new_one->line, aline);
/*printf("\nREAD LINE %s\n",aline);*/
} /* ends if first_pass */
else{ /* else not first_pass */
new_one = (struct line_list_struct *)
calloc(1, sizeof(struct line_list_struct));
temp->next_line = new_one;
temp = new_one;
new_one->next_line = END_OF_LIST;
strcpy(new_one->line, aline);
} /* ends else not first_pass */
/*
\
------- here is where you change it
/
PROBLEM HERE
This reading routine is setup so that it reads
until it finds a blank line that is the quit signal.
The quit signal comes after reading the lines.
BUT WE want the quit signal (a new para marker) to
come at the start of a new paragraph. If I
read the first line of the new para I will lose it.
So how do I know that the next para is starting
without reading that line??????? 19 Dec 99
*/
if(aline[0] == '\n' ||
aline[0] == '.' ||
aline[0] == '<' ||
aline[0] == '#'){
reading = 0;
}
} /* ends while reading */
return(result);
} /* ends read_the_lines */
/**************************************************/
/**************************************************/
/*
struct word_list_struct * read_a_paragraph(...
*/
struct word_list_struct * read_a_paragraph(
FILE *input_file,
int *file_done)
{
struct line_list_struct *line_list;
struct word_list_struct *result;
line_list = read_the_lines(input_file, file_done);
result = convert_lines_to_words(line_list);
free(line_list);
return(result);
} /* ends read_a_paragraph */
/**************************************************/
/**************************************************/
/*
void write_a_paragraph(...
traversing_list == 0 means this is the last word
in the paragraph
too_long == 1 means this word will not fit on the
current line
traversing_list too_long
0 0 put word on line
print line
THE END
0 1 print line
start new line
put word on line
print line
THE END
1 0 put word on line
go on
1 1 print line
start new line
put word on new line
go on
*/
void write_a_paragraph(
struct word_list_struct *word_list,
FILE *output_file,
int *line_counter,
int *page_counter,
char *title,
int print_date,
int print_page,
int double_space)
{
char line[L], line2[L];
int i,
new_line = 1,
spaces = 0,
too_long = 0,
traversing_list = 1;
struct word_list_struct *this_word;
char response[L];
/********************
printf("\nSTART OF write a para");
traverse_word_list(word_list);
spaces = number_of_indent_levels(word_list->word);
printf("\nSpaces=%d",spaces);
printf("\nPress enter to continue");
gets(response);
**********************/
this_word = word_list;
spaces = number_of_indent_levels(word_list->word);
fill_string(line, L, '\0');
while(traversing_list){
/* this is the last word in the paragraph */
if(this_word->next_word == END_OF_LIST)
traversing_list = 0;
/* If this word won't fit on this line, */
if( (strlen(this_word->word) + (strlen(line))) >
(CPL - (RIGHT_MARGIN+LEFT_MARGIN)) )
too_long = 1;
else
too_long = 0;
if(traversing_list == 0 && too_long == 0){
strcat(line, this_word->word);
strcat(line, "\n");
/*printf("\nTHE LINE IS %s",line);*/
strip_characters(line, line2);
add_indents(line2, spaces);
output_line(line2, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
} /* ends if 0 0 */
if(traversing_list == 0 && too_long == 1){
strcat(line, "\n");
strip_characters(line, line2);
add_indents(line2, spaces);
output_line(line2, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
fill_string(line, L, '\0');
strcat(line, this_word->word);
strcat(line, "\n");
strip_characters(line, line2);
add_indents(line2, spaces);
output_line(line2, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
} /* ends 0 1 */
if(traversing_list == 1 && too_long == 0){
strcat(line, this_word->word);
/**********
printf("BUILDING LINE::%s",line);
gets(response);
**************/
this_word = this_word->next_word;
} /* ends 1 0 */
if(traversing_list == 1 && too_long == 1){
/************
printf("\nTRAVERSING AND LINE TOO LONG");
printf("\nLINE IS:%s",line);
printf("\nLINE2 IS:%s",line2);
**************/
strcat(line, "\n");
strip_characters(line, line2);
add_indents(line2, spaces);
output_line(line2, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
fill_string(line, L, '\0');
strcat(line, this_word->word);
/**********
printf("OUTPUT WAS::%s",line2);
printf("\nStarted next line of this word list with:%s",line);
gets(response);
**************/
this_word = this_word->next_word;
} /* ends 1 1 */
} /* ends while traversing_list */
} /* ends write_a_paragraph */
/**************************************************/
/**************************************************/
/*
void output_line(...
*/
void output_line(char *line,
FILE *output_file,
int *line_counter,
int *page_counter,
char *title,
int print_date,
int print_page,
int double_space)
{
fputs(line, output_file);
*line_counter = *line_counter + 1;
if(*line_counter >= (lpp(0,0)-FOOTER)){
fill_page(output_file,
line_counter,
page_counter);
print_report_header(output_file,
line_counter,
page_counter,
title,
print_date,
print_page);
} /* ends if line_counter */
if(double_space){
fputs("\n", output_file);
*line_counter = *line_counter + 1;
if(*line_counter >= (lpp(0,0)-FOOTER)){
fill_page(output_file,
line_counter,
page_counter);
print_report_header(output_file,
line_counter,
page_counter,
title,
print_date,
print_page);
} /* ends if line_counter */
} /* ends if double_space */
} /* ends output_line */
/**************************************************/
/**************************************************/
/*
void fill_page(...
*/
void fill_page(FILE *file_pointer,
int *line_counter,
int *page_counter)
{
char temp[L];
int i;
strcpy(temp, "\n");
while(*line_counter < (lpp(0,0)-FOOTER)){
fputs(temp, file_pointer);
*line_counter = *line_counter+1;
}
for(i=0; i<FOOTER-2; i++)
fputs(temp, file_pointer);
fputs("\n .",file_pointer);
for(i=0; i<(FOOTER-(FOOTER-2)-1); i++)
fputs(temp, file_pointer);
*line_counter = 0;
*page_counter = *page_counter + 1;
} /* ends fill_page */
/**************************************************/
/**************************************************/
/*
void print_header(...
*/
void print_report_header(FILE *file_pointer,
int *line_counter,
int *page_counter,
char *title,
int print_date,
int print_page)
{
char blankline[L],
classline[L],
headerline[L],
pageline[L],
temp[L],
time_string[L];
int i,
l1,
l2,
l3,
print_title = 1;
struct tm *time_of_day;
time_t seconds;
time(&seconds);
time_of_day = localtime(&seconds);
sprintf(time_string, "%d-%d-%d\0",
time_of_day->tm_mon+1,
time_of_day->tm_mday,
time_of_day->tm_year);
if(title[0] == '\0')
print_title = 0;
fill_string(headerline, L, '\0');
fill_string(pageline, L, '\0');
if(print_page){
l3 = CPL-LEFT_MARGIN-RIGHT_MARGIN-RIGHT_MARGIN-9;
pageline[0] = '\n';
for(i=1; i<l3; i++)
pageline[i] = SPACE;
sprintf(temp, "%4d", *page_counter);
strcat(pageline, "Page ");
strcat(pageline, temp);
} /* ends if print_page */
else
strcpy(pageline, "\n");
if(print_title == 0 && print_date == 0)
strcpy(headerline, "\n");
if(print_title == 0 && print_date == 1){
l1 = strlen(time_string);
l3 = CPL-LEFT_MARGIN-RIGHT_MARGIN-RIGHT_MARGIN-l1;
headerline[0] = '\n';
for(i=1; i<l3; i++)
headerline[i] = SPACE;
strcat(headerline, time_string);
} /* ends if print date but not title */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -