📄 kf.c
字号:
if(print_title == 1 && print_date == 0){
l1 = strlen(title);
l3 = CPL-LEFT_MARGIN-RIGHT_MARGIN-RIGHT_MARGIN-l1;
headerline[0] = '\n';
for(i=1; i<l3; i++)
headerline[i] = SPACE;
strcat(headerline, title);
} /* ends if print title but not date */
if(print_title == 1 && print_date == 1){
strcpy(temp, title);
strcat(temp, " - ");
strcat(temp, time_string);
l1 = strlen(temp);
l3 = CPL-LEFT_MARGIN-RIGHT_MARGIN-RIGHT_MARGIN-l1;
headerline[0] = '\n';
for(i=1; i<l3; i++)
headerline[i] = SPACE;
strcat(headerline, temp);
} /* ends if print title and print date */
strcpy(blankline, "\n");
sprintf(classline, "\n");
fputs(blankline, file_pointer);
fputs(classline, file_pointer);
fputs(headerline, file_pointer);
fputs(pageline, file_pointer);
fputs(blankline, file_pointer);
*line_counter = 5;
} /* ends print_report_header */
/**************************************************/
/**************************************************/
/*
void strip_characters(...
*/
void strip_characters(char *input, char *output)
{
int i, j, not_yet;
char response[L];
fill_string(output, L, '\0');
if(input[0] != '.' &&
input[0] != '<'){
for(i=0; i<L; i++)
output[i] = input[i];
} /* ends if no special characters */
if(input[0] == '.'){
j = 0;
for(i=0; i<L; i++){
if(input[i] == '.'){
/* do nothing */
}
else{
output[j++] = input[i];
}
} /* ends loop over i */
} /* period case */
if(input[0] == '<'){
not_yet = 1;
j = 0;
for(i=0; i<L; i++){
if(not_yet == 0){
output[j++] = input[i];
}
if(input[i] == '>'){
not_yet = 0;
}
} /* ends loop over i */
} /* < case */
} /* ends strip_characters */
/***********************************************/
/***********************************************/
/*
struct line_list_struct * read_a_record(...
FILE *, int *);
Read until hitting <START>.
Do not put the <START> line in the list of lines.
Put all the lines in the line list until
hitting <END>
Do not put the <END> line in the list of lines.
*/
struct line_list_struct * read_a_record(
FILE *input_file, int *file_done)
{
char aline[L];
int first_pass = 1,
searching = 1,
reading = 1;
struct line_list_struct *new_one,
*result,
*temp;
while(searching){
if(fgets(aline, L, input_file) == NULL){
*file_done = 1;
reading = 0;
searching = 0;
} /* ends if fgets is NULL */
else{
if(strncmp(aline, "<START>", 7) == 0)
searching = 0;
} /* ends else */
} /* ends while searching */
while(reading){
if(fgets(aline, L, input_file) == NULL){
*file_done = 1;
reading = 0;
} /* ends if fgets is NULL */
if(strncmp(aline, "<END>", 5) == 0)
reading = 0;
else{ /* not END so process line */
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("\nput this line in the list\n%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);
/*printf("\nput this line in the list\n%s\n", aline);*/
} /* ends else not first_pass */
} /* ends else not END */
} /* ends while reading */
return(result);
} /* ends read_a_record */
/***********************************************/
/***********************************************/
/*
void traverse_line_list(struct line_list_struct *)
*/
void traverse_line_list(struct line_list_struct *this_list)
{
struct line_list_struct *temp;
temp = this_list;
while(temp != END_OF_LIST){
printf("--%s--", temp->line);
temp = temp->next_line;
} /* ends while */
} /* ends traverse_line_list */
/***********************************************/
/***********************************************/
/*
void traverse_word_list(struct word_list_struct *)
*/
void traverse_word_list(struct word_list_struct *this_list)
{
struct word_list_struct *temp;
temp = this_list;
while(temp != END_OF_LIST){
printf("--%s", temp->word);
temp = temp->next_word;
} /* ends while */
} /* ends traverse_word_list */
/**************************************************/
/**************************************************/
/*
void write_a_record(...
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_record(
struct line_list_struct *line_list,
FILE *out_file,
int *line_counter,
int *page_counter,
char *title,
int print_date,
int print_page,
int double_space)
{
char line[L], line2[L];
char response[L];
int first_line_of_entry = 1,
i = 0,
new_line = 1,
this = 0,
too_long = 0,
traversing_list = 1;
struct line_list_struct *current_line,
*end_of_current,
*temp,
*the_next_line;
struct word_list_struct *words;
temp = line_list;
the_next_line = line_list;
while(temp != END_OF_LIST){
/****************************
if(temp->line[0] == '\n' ||
temp->line[0] == ' ' ||
temp->line[0] == '#')
this = BLANK_OR_COMMENT;
*****************************/
if(the_next_line->line[0] == '<' ||
the_next_line->line[0] == '.'){
/* new entry AND first line of entry
so put the entry into the current
line */
if(first_line_of_entry){
first_line_of_entry = 0;
current_line = temp;
end_of_current = temp;
temp = temp->next_line;
the_next_line = temp;
} /* ends if first_line_of_entry */
/* new entry AND not first line of entry
so stop adding to the current line,
convert it to a word list, convert
the word list to a paragraph,
and print the paragraph */
else{ /* not first_line_of_entry */
first_line_of_entry = 1;
end_of_current->next_line = END_OF_LIST;
words = convert_lines_to_words(current_line);
write_a_paragraph(words, out_file,
line_counter,
page_counter,
title,
print_date,
print_page,
double_space);
current_line = the_next_line;
} /* ends else not first_line_of_entry */
} /* ends if a new entry */
/* NOT a new entry AND don't care
so add the next line to the current
line */
else{ /* not a new entry */
end_of_current = the_next_line;
temp = temp->next_line;
the_next_line = temp;
} /* ends else not a new entry */
} /* ends while */
/* take care of the last current line */
if(current_line->line[0] == '<' ||
current_line->line[0] == '.'){
words = convert_lines_to_words(current_line);
current_line = the_next_line;
write_a_paragraph(words, out_file,
line_counter,
page_counter,
title,
print_date,
print_page,
double_space);
} /* ends if current_line is an entry */
/* put a few blank lines after each record */
fill_string(line, L, '\0');
strcat(line, "\n");
output_line(line, out_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
output_line(line, out_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
output_line(line, out_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
} /* ends write_a_record */
/**************************************************/
/**************************************************/
int number_of_indent_levels(char *line)
{
int i,
result = 0;
for(i=0; i<L; i++){
if(line[i] == '.')
result++;
if(line[i] != '.')
i = L+1;
} /* ends loop over i */
return(result);
} /* ends number_of_indent_levels */
/**************************************************/
/**************************************************/
void add_indents(char *line, int spaces)
{
int i,
result = 0;
char temp[L];
fill_string(temp, L, '\0');
for(i=0; i<spaces*2; i++)
temp[i] = SPACE;
strcat(temp, line);
for(i=0; i<L; i++)
line[i] = temp[i];
} /* ends add_indents */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -