13 #include "trueprint.h"
20 #include "print_prompt.h"
26 char *print_selection
;
33 static boolean
check_selection(long page_no
, char *filename
);
34 static boolean no_prompt_to_print
;
38 * setup_print_prompter()
42 setup_print_prompter(void)
44 string_option("A", "print-pages", NULL
, &print_selection
, NULL
, NULL
,
46 "specify list of pages to be printed");
48 boolean_option("a", "no-prompt", "prompt", TRUE
, &no_prompt_to_print
, NULL
, NULL
,
50 "don't prompt for each page, whether it should be printed or not",
51 "prompt for each page, whether it should be printed or not");
59 * Returns whether or not this page should be printed. Uses
60 * -a and -A information.
63 print_prompt(page_types type
, long filepage_no
, char *filename
)
66 char prompt
[MAXLINELENGTH
];
67 char response
[INPUT_LINE_LEN
];
70 static int yes_count
=0;
71 static int no_count
=0;
72 static boolean all_yes
=FALSE
, all_no
=FALSE
;
74 if (pass
== 0) return FALSE
;
76 if (all_yes
) return TRUE
;
77 if (all_no
) return FALSE
;
79 if (print_selection
!= NULL
) return check_selection(page_number
, filename
);
92 if (no_prompt_to_print
==FALSE
)
97 fn_name
= get_function_name(page_number
);
99 sprintf(prompt
, "Print page %5ld, page %3ld of %s %s(%s%s)?",
100 page_number
, filepage_no
, filename
, page_changed(page_number
)?"[changed]":"", fn_name
,
101 function_changed(page_number
)?"[changed]":"");
103 sprintf(prompt
, "Print page %5ld, page %3ld of %s %s?",
104 page_number
, filepage_no
, filename
, page_changed(page_number
)?"[changed]":"");
108 sprintf(prompt
, "Print blank page %5ld?", page_number
+1);
111 sprintf(prompt
, "Print %s?", filename
);
117 while (retval
== UNSET
)
119 fprintf(stderr
, gettext("%s [n] ? for help: "), prompt
);
121 fgets(response
,INPUT_LINE_LEN
-1,stdin
);
123 response_ptr
= response
;
124 skipspaces(&response_ptr
);
125 switch (*response_ptr
++)
129 yes_count
= strtol(response_ptr
, &response_ptr
, 10);
130 if ((yes_count
== 0) && (*response_ptr
== '*')) all_yes
= TRUE
;
131 if (yes_count
== 1) yes_count
= 0;
136 no_count
= strtol(response_ptr
, &response_ptr
, 10);
137 if ((no_count
== 0) && (*response_ptr
== '*')) all_no
= TRUE
;
138 if (no_count
== 1) no_count
= 0;
145 print_selection
= strdup(response_ptr
);
146 retval
= check_selection(page_number
, filename
);
150 fprintf(stderr
, "---------------------------------------------\n");
151 fprintf(stderr
, gettext("y print this page\n"));
152 fprintf(stderr
, gettext("y<n> print <n> pages\n"));
153 fprintf(stderr
, gettext("y* print all remaining pages\n"));
154 fprintf(stderr
, gettext("n skip this page\n"));
155 fprintf(stderr
, gettext("n<n> skip <n> pages\n"));
156 fprintf(stderr
, gettext("n* skip all remaining pages\n"));
157 fprintf(stderr
, gettext("p<list> print all remaining pages that match <list>\n"));
158 fprintf(stderr
, gettext("? show this message\n\n"));
159 fprintf(stderr
, gettext("format for <list>:\n"));
160 fprintf(stderr
, gettext(" comma-separated list of specifiers:\n"));
161 fprintf(stderr
, gettext(" <n> print page <n>\n"));
162 fprintf(stderr
, gettext(" <n>-<o> print all pages from page <n> to <o>\n"));
163 fprintf(stderr
, gettext(" <function-name> print all pages for function\n"));
164 fprintf(stderr
, gettext(" f print function index\n"));
165 fprintf(stderr
, gettext(" F print file index\n"));
166 fprintf(stderr
, gettext(" c print cross reference info\n"));
167 fprintf(stderr
, gettext("e.g. p 1-3,main,5,6 will print pages 1,2,3,5,6 and all\n"));
168 fprintf(stderr
, gettext(" pages for function main.\n"));
169 fprintf(stderr
, "---------------------------------------------\n");
181 * Returns whether or not this page should be printed, using the -A
185 check_selection(long page_no
, char *filename
)
187 char *s_index
= print_selection
;
188 long start_page
, end_page
;
190 char *fn_name
= NULL
;
192 if (page_no
!= 0) fn_name
= get_function_name(page_no
);
196 start_page
= strtol(s_index
, &s_index
, 10);
197 skipspaces(&s_index
);
198 if ((start_page
!= 0) && (*s_index
== '-'))
201 end_page
= strtol(s_index
, &s_index
, 10);
202 if ((start_page
<= page_no
) && (page_no
<= end_page
)) return TRUE
;
203 skipspaces(&s_index
);
205 if ((start_page
!= 0) && ((*s_index
== ',')||(*s_index
== '\0')))
207 if (start_page
== page_no
) return TRUE
;
209 if ((start_page
== 0) && (*s_index
!= '\0'))
212 while ((s_index
[name_length
] != ',')
213 && (s_index
[name_length
] != '\0')
214 && !isspace(s_index
[name_length
]))
216 if (name_length
== 1)
220 case 'f': if (filename
&& (strcmp(filename
, "function index")==0)) return TRUE
; break;
221 case 'F': if (filename
&& (strcmp(filename
, "file index")==0)) return TRUE
; break;
222 case 'd': if (page_changed(page_no
)) return TRUE
; break;
223 case 'D': if (function_changed(page_no
)) return TRUE
; break;
224 default: fprintf(stderr
, gettext(CMD_NAME
": ignoring unrecognized letter %c\n"), *s_index
);
228 && (strlen(fn_name
) == name_length
)
229 && (strncmp(get_function_name(page_no
), s_index
, name_length
) == 0))
232 s_index
+= name_length
;
235 skipspaces(&s_index
);
236 if (*s_index
== ',') s_index
++;
237 skipspaces(&s_index
);