📄 pageit.c
字号:
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);
} /* 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 */
if(aline[0] == '\n'){
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];
int i,
new_line = 1,
too_long = 0,
traversing_list = 1;
struct word_list_struct *this_word;
this_word = word_list;
fill_string(line, L, '\0');
fill_string(line, LEFT_MARGIN, SPACE);
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");
output_line(line, 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");
output_line(line, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
fill_string(line, L, '\0');
fill_string(line, LEFT_MARGIN, SPACE);
strcat(line, this_word->word);
strcat(line, "\n");
output_line(line, 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);
this_word = this_word->next_word;
} /* ends 1 0 */
if(traversing_list == 1 && too_long == 1){
strcat(line, "\n");
output_line(line, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
fill_string(line, L, '\0');
fill_string(line, LEFT_MARGIN, SPACE);
strcat(line, this_word->word);
this_word = this_word->next_word;
} /* ends 1 1 */
} /* ends while traversing_list */
fill_string(line, L, '\0');
fill_string(line, LEFT_MARGIN, SPACE);
strcat(line, "\n");
output_line(line, output_file,
line_counter, page_counter,
title, print_date, print_page,
double_space);
} /* 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 */
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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -