24 |
#include <ctype.h> |
#include <ctype.h> |
25 |
|
|
26 |
void |
void |
27 |
arshell_spell_check_buffer() |
arshell_spell_check_buffer () |
28 |
{ |
{ |
29 |
char *command; |
char *command; |
30 |
char *spell_checker; |
char *spell_checker; |
31 |
|
|
32 |
arshell_save_work_area(); |
arshell_save_work_area (); |
33 |
spell_checker=antiright_pipe_read("which ispell | tail -1"); |
spell_checker = antiright_pipe_read ("which ispell | tail -1"); |
34 |
if(strlen(spell_checker)>1) |
if (strlen (spell_checker) > 1) |
35 |
asprintf(&command, "xterm -e ispell %s", arshell.edit.filename); |
asprintf (&command, "xterm -e ispell %s", arshell.edit.filename); |
36 |
else |
else |
37 |
{ |
{ |
38 |
free(spell_checker); |
free (spell_checker); |
39 |
spell_checker=antiright_pipe_read("which aspell | tail -1"); |
spell_checker = antiright_pipe_read ("which aspell | tail -1"); |
40 |
if(strlen(spell_checker)>1) |
if (strlen (spell_checker) > 1) |
41 |
asprintf(&command, "xterm -e aspell -c %s", arshell.edit.filename); |
asprintf (&command, "xterm -e aspell -c %s", arshell.edit.filename); |
42 |
else |
else |
43 |
{ |
{ |
44 |
free(spell_checker); |
free (spell_checker); |
45 |
spell_checker=antiright_pipe_read("which spell | tail -1"); |
spell_checker = antiright_pipe_read ("which spell | tail -1"); |
46 |
if(strlen(spell_checker)>1) |
if (strlen (spell_checker) > 1) |
47 |
asprintf(&command, "xterm -e aspell -c %s", arshell.edit.filename); |
asprintf (&command, "xterm -e aspell -c %s", |
48 |
|
arshell.edit.filename); |
49 |
else |
else |
50 |
{ |
{ |
51 |
free(spell_checker); |
free (spell_checker); |
52 |
asprintf(&command, "arshell -ADm 'No spell checker was found.'&"); |
asprintf (&command, |
53 |
|
"arshell -ADm 'No spell checker was found.'&"); |
54 |
} |
} |
55 |
} |
} |
56 |
} |
} |
57 |
free(spell_checker); |
free (spell_checker); |
58 |
system(command); |
system (command); |
59 |
free(command); |
free (command); |
60 |
if(arshell.flags.file_open) |
if (arshell.flags.file_open) |
61 |
arshell_revert_file_cb(); |
arshell_revert_file_cb (); |
62 |
} |
} |
63 |
|
|
64 |
void |
void |
65 |
arshell_select_all() |
arshell_select_all () |
66 |
{ |
{ |
67 |
XmTextSetSelection(arshell.gui.widgets.work, 0, |
XmTextSetSelection (arshell.gui.widgets.work, 0, |
68 |
XmTextGetLastPosition(arshell.gui.widgets.work), |
XmTextGetLastPosition (arshell.gui.widgets.work), |
69 |
XtLastTimestampProcessed(antiright.display)); |
XtLastTimestampProcessed (antiright.display)); |
70 |
} |
} |
71 |
|
|
72 |
void |
void |
73 |
arshell_selection_case(int (*operation)(int)) |
arshell_selection_case (int (*operation) (int)) |
74 |
{ |
{ |
75 |
char *text=XmTextGetString(arshell.gui.widgets.work); |
char *text = XmTextGetString (arshell.gui.widgets.work); |
76 |
XmTextPosition left, right; |
XmTextPosition left, right; |
77 |
int counter=0; |
int counter = 0; |
78 |
XmTextGetSelectionPosition(arshell.gui.widgets.work, &left, &right); |
XmTextGetSelectionPosition (arshell.gui.widgets.work, &left, &right); |
79 |
for(counter=left; counter <= right; counter++) |
for (counter = left; counter <= right; counter++) |
80 |
text[counter]=(*operation)(text[counter]); |
text[counter] = (*operation) (text[counter]); |
81 |
XmTextSetString(arshell.gui.widgets.work, text); |
XmTextSetString (arshell.gui.widgets.work, text); |
82 |
XtFree(text); |
XtFree (text); |
83 |
} |
} |
84 |
|
|
85 |
void |
void |
86 |
arshell_lower_selection_case() |
arshell_lower_selection_case () |
87 |
{ |
{ |
88 |
arshell_selection_case(&tolower); |
arshell_selection_case (&tolower); |
89 |
} |
} |
90 |
|
|
91 |
void |
void |
92 |
arshell_upper_selection_case() |
arshell_upper_selection_case () |
93 |
{ |
{ |
94 |
arshell_selection_case(&toupper); |
arshell_selection_case (&toupper); |
95 |
} |
} |
96 |
|
|
97 |
void |
void |
98 |
arshell_change_font_cb() |
arshell_change_font_cb () |
99 |
{ |
{ |
100 |
char *font_string; |
char *font_string; |
101 |
XFontStruct *font_struct; |
XFontStruct *font_struct; |
102 |
|
|
103 |
font_string=antiright_pipe_read("arshell -ADF"); |
font_string = antiright_pipe_read ("arshell -ADF"); |
104 |
if((*font_string)!='\0') |
if ((*font_string) != '\0') |
105 |
{ |
{ |
106 |
font_struct=XLoadQueryFont(antiright.display, font_string); |
font_struct = XLoadQueryFont (antiright.display, font_string); |
107 |
if(font_struct!=NULL) |
if (font_struct != NULL) |
108 |
{ |
{ |
109 |
XmFontList font_list=XmFontListCreate(font_struct, |
XmFontList font_list = XmFontListCreate (font_struct, |
110 |
XmSTRING_DEFAULT_CHARSET); |
XmSTRING_DEFAULT_CHARSET); |
111 |
ARCLARG; |
ARCLARG; |
112 |
antiright_set(XmNfontList, (XtArgVal)font_list); |
antiright_set (XmNfontList, (XtArgVal) font_list); |
113 |
antiright_set_values(arshell.gui.widgets.work); |
antiright_set_values (arshell.gui.widgets.work); |
114 |
ARCLARG; |
ARCLARG; |
115 |
XmFontListFree(font_list); |
XmFontListFree (font_list); |
116 |
} |
} |
117 |
else |
else |
118 |
{ |
{ |
120 |
("arshell -ADm 'The entered font was not found. ' &"); |
("arshell -ADm 'The entered font was not found. ' &"); |
121 |
} |
} |
122 |
} |
} |
123 |
free(font_string); |
free (font_string); |
124 |
} |
} |
125 |
|
|
126 |
/* This is a simple method of printing the current file. */ |
/* This is a simple method of printing the current file. */ |
127 |
void |
void |
128 |
arshell_print_cb() |
arshell_print_cb () |
129 |
{ |
{ |
130 |
char *command; |
char *command; |
131 |
char *print_string; |
char *print_string; |
132 |
|
|
133 |
print_string= |
print_string = antiright_pipe_read ("echo -n `ACE -r Print`"); |
134 |
antiright_pipe_read("echo -n `ACE -r Print`"); |
asprintf (&command, "%s %s &", print_string, arshell.edit.filename); |
135 |
asprintf(&command, "%s %s &", print_string, arshell.edit.filename); |
free (print_string); |
136 |
free(print_string); |
system (command); /* Print the file. */ |
137 |
system(command); /* Print the file. */ |
free (command); /* Free the unneeded memory. */ |
|
free(command); /* Free the unneeded memory. */ |
|
138 |
} |
} |
139 |
|
|
140 |
void |
void |
141 |
arshell_value_changed_cb() |
arshell_value_changed_cb () |
142 |
{ |
{ |
143 |
char *title_string; |
char *title_string; |
144 |
|
|
145 |
asprintf(&title_string, |
asprintf (&title_string, "%s [%s]", arshell.edit.filename, "modified"); |
146 |
"%s [%s]", |
XtVaSetValues (antiright.parent_widget, XmNtitle, title_string, NULL); |
147 |
arshell.edit.filename, |
free (title_string); |
148 |
"modified"); |
|
149 |
XtVaSetValues(antiright.parent_widget, |
arshell.flags.modified = True; |
150 |
XmNtitle, title_string, |
} |
151 |
NULL); |
|
152 |
free(title_string); |
void |
153 |
|
arshell_text_return_cb (Widget parent_widget, |
154 |
arshell.flags.modified=True; |
XtPointer client_data, XtPointer call_data) |
155 |
} |
{ |
156 |
void |
char *text_string = XmTextGetString (parent_widget); |
157 |
arshell_text_return_cb(Widget parent_widget, |
printf ("%s %s", (char *) client_data, text_string); |
158 |
XtPointer client_data, |
free (text_string); |
159 |
XtPointer call_data) |
fflush (stdout); |
160 |
{ |
call_data = (XtPointer) NULL; |
161 |
char* text_string=XmTextGetString(parent_widget); |
exit (0); |
|
printf("%s %s", (char*)client_data, text_string); |
|
|
free(text_string); |
|
|
fflush(stdout); |
|
|
call_data=(XtPointer)NULL; |
|
|
exit(0); |
|
162 |
} |
} |
163 |
unsigned int |
unsigned int |
164 |
arshell_line(XmTextPosition end_position) |
arshell_line (XmTextPosition end_position) |
165 |
{ |
{ |
166 |
int lines=1; |
int lines = 1; |
167 |
char *text=XmTextGetString(arshell.gui.widgets.work); |
char *text = XmTextGetString (arshell.gui.widgets.work); |
168 |
XmTextPosition position=0; |
XmTextPosition position = 0; |
169 |
while(position < end_position) |
while (position < end_position) |
170 |
{ |
{ |
171 |
if(text[position]=='\n') |
if (text[position] == '\n') |
172 |
lines++; |
lines++; |
173 |
position++; |
position++; |
174 |
} |
} |
175 |
XtFree(text); |
XtFree (text); |
176 |
return(lines); |
return (lines); |
177 |
} |
} |
178 |
|
|
179 |
void |
void |
180 |
arshell_position(XmTextPosition current_position, unsigned int *total_lines, |
arshell_position (XmTextPosition current_position, unsigned int *total_lines, |
181 |
unsigned int *current_line) |
unsigned int *current_line) |
182 |
{ |
{ |
183 |
char *text=XmTextGetString(arshell.gui.widgets.work); |
char *text = XmTextGetString (arshell.gui.widgets.work); |
184 |
XmTextPosition position=0; |
XmTextPosition position = 0; |
185 |
XmTextPosition end_position=XmTextGetLastPosition(arshell.gui.widgets.work); |
XmTextPosition end_position = |
186 |
(*total_lines)=1; |
XmTextGetLastPosition (arshell.gui.widgets.work); |
187 |
while(position <= end_position) |
(*total_lines) = 1; |
188 |
|
while (position <= end_position) |
189 |
{ |
{ |
190 |
if(text[position]=='\n') |
if (text[position] == '\n') |
191 |
(*total_lines)++; |
(*total_lines)++; |
192 |
if(position==current_position) |
if (position == current_position) |
193 |
{ |
{ |
194 |
(*current_line)=(*total_lines); |
(*current_line) = (*total_lines); |
195 |
if(text[current_position]=='\n') |
if (text[current_position] == '\n') |
196 |
(*current_line)--; |
(*current_line)--; |
197 |
} |
} |
198 |
position++; |
position++; |
199 |
} |
} |
200 |
XtFree(text); |
XtFree (text); |
201 |
} |
} |
202 |
|
|
203 |
void |
void |
204 |
arshell_goto_line(unsigned int line) |
arshell_goto_line (unsigned int line) |
205 |
{ |
{ |
206 |
/* Declare a counter for the number of lines counted. */ |
/* Declare a counter for the number of lines counted. */ |
207 |
unsigned int line_counter=1; |
unsigned int line_counter = 1; |
208 |
/* Declare a text position counter. */ |
/* Declare a text position counter. */ |
209 |
XmTextPosition position=0; |
XmTextPosition position = 0; |
210 |
char *text=XmTextGetString(arshell.gui.widgets.work); |
char *text = XmTextGetString (arshell.gui.widgets.work); |
211 |
unsigned int text_length=strlen(text); |
unsigned int text_length = strlen (text); |
212 |
while(((unsigned int)position < text_length) & (line_counter<line)) |
while (((unsigned int) position < text_length) & (line_counter < line)) |
213 |
{ |
{ |
214 |
if(text[position]=='\n') |
if (text[position] == '\n') |
215 |
line_counter++; |
line_counter++; |
216 |
position++; |
position++; |
217 |
} |
} |
218 |
XtFree(text); |
XtFree (text); |
219 |
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
XmTextSetInsertionPosition (arshell.gui.widgets.work, position); |
220 |
} |
} |
221 |
|
|
222 |
void |
void |
223 |
arshell_goto_line_cb() |
arshell_goto_line_cb () |
224 |
{ |
{ |
225 |
char *line_string=antiright_pipe_read("arshell -ADp Line:"); |
char *line_string = antiright_pipe_read ("arshell -ADp Line:"); |
226 |
arshell_goto_line(atoi(line_string)); |
arshell_goto_line (atoi (line_string)); |
227 |
free(line_string); |
free (line_string); |
228 |
} |
} |
229 |
|
|
230 |
int |
int |
231 |
arshell_current_line() |
arshell_current_line () |
232 |
{ |
{ |
233 |
return(arshell_line(XmTextGetInsertionPosition(arshell.gui.widgets.work)+1)); |
return (arshell_line |
234 |
|
(XmTextGetInsertionPosition (arshell.gui.widgets.work) + 1)); |
235 |
} |
} |
236 |
|
|
237 |
int |
int |
238 |
arshell_text_lines() |
arshell_text_lines () |
239 |
{ |
{ |
240 |
return(arshell_line(XmTextGetLastPosition(arshell.gui.widgets.work))); |
return (arshell_line (XmTextGetLastPosition (arshell.gui.widgets.work))); |
241 |
} |
} |
242 |
|
|
243 |
void |
void |
244 |
arshell_get_rid_of_modified_status() |
arshell_get_rid_of_modified_status () |
245 |
{ |
{ |
246 |
if(arshell.flags.modified) |
if (arshell.flags.modified) |
247 |
arshell.flags.modified=False; |
arshell.flags.modified = False; |
248 |
} |
} |
249 |
|
|
250 |
void |
void |
251 |
arshell_set_work_area_arguments() |
arshell_set_work_area_arguments () |
252 |
{ |
{ |
253 |
ARCLARG; |
ARCLARG; |
254 |
antiright_set(XmNeditMode, XmMULTI_LINE_EDIT); |
antiright_set (XmNeditMode, XmMULTI_LINE_EDIT); |
255 |
antiright_set(XmNcolumns, 80); |
antiright_set (XmNcolumns, 80); |
256 |
antiright_set(XmNrows, 24); |
antiright_set (XmNrows, 24); |
257 |
} |
} |
258 |
|
|
259 |
void |
void |
260 |
arshell_verified_status(XmTextVerifyCallbackStruct *call_pointer) |
arshell_verified_status (XmTextVerifyCallbackStruct * call_pointer) |
261 |
{ |
{ |
262 |
char *status; |
char *status; |
263 |
XmTextPosition last=XmTextGetLastPosition(arshell.gui.widgets.work); |
XmTextPosition last = XmTextGetLastPosition (arshell.gui.widgets.work); |
264 |
XmTextPosition current=call_pointer->newInsert; |
XmTextPosition current = call_pointer->newInsert; |
265 |
unsigned int lines_uint; |
unsigned int lines_uint; |
266 |
unsigned int current_uint; |
unsigned int current_uint; |
267 |
float percent; |
float percent; |
268 |
arshell_position(current, &lines_uint, ¤t_uint); |
arshell_position (current, &lines_uint, ¤t_uint); |
269 |
percent=(float)current/(float)last; |
percent = (float) current / (float) last; |
270 |
asprintf(&status, "Lines:%d, Current:%d, Percent:%f", |
asprintf (&status, "Lines:%d, Current:%d, Percent:%f", |
271 |
lines_uint, current_uint, percent*100); |
lines_uint, current_uint, percent * 100); |
272 |
antiright_status(status); |
antiright_status (status); |
273 |
free(status); |
free (status); |
274 |
} |
} |
275 |
|
|
276 |
void |
void |
277 |
arshell_modify_verify_cb(Widget widget, XtPointer client_data, |
arshell_modify_verify_cb (Widget widget, XtPointer client_data, |
278 |
XtPointer call_data) |
XtPointer call_data) |
279 |
{ |
{ |
280 |
client_data=NULL; |
client_data = NULL; |
281 |
widget=NULL; |
widget = NULL; |
282 |
arshell_verified_status(call_data); |
arshell_verified_status (call_data); |
283 |
} |
} |
284 |
|
|
285 |
void |
void |
286 |
arshell_motion_verify_cb(Widget widget, XtPointer client_data, |
arshell_motion_verify_cb (Widget widget, XtPointer client_data, |
287 |
XtPointer call_data) |
XtPointer call_data) |
288 |
{ |
{ |
289 |
client_data=NULL; |
client_data = NULL; |
290 |
widget=NULL; |
widget = NULL; |
291 |
arshell_verified_status(call_data); |
arshell_verified_status (call_data); |
292 |
} |
} |
293 |
|
|
294 |
void |
void |
295 |
arshell_setup_work_area_callbacks() |
arshell_setup_work_area_callbacks () |
296 |
{ |
{ |
297 |
XtAddCallback(arshell.gui.widgets.work, XmNvalueChangedCallback, |
XtAddCallback (arshell.gui.widgets.work, XmNvalueChangedCallback, |
298 |
arshell_value_changed_cb, NULL); |
arshell_value_changed_cb, NULL); |
299 |
XtAddCallback(arshell.gui.widgets.work, XmNmodifyVerifyCallback, |
XtAddCallback (arshell.gui.widgets.work, XmNmodifyVerifyCallback, |
300 |
arshell_modify_verify_cb, NULL); |
arshell_modify_verify_cb, NULL); |
301 |
XtAddCallback(arshell.gui.widgets.work, XmNmotionVerifyCallback, |
XtAddCallback (arshell.gui.widgets.work, XmNmotionVerifyCallback, |
302 |
arshell_motion_verify_cb, NULL); |
arshell_motion_verify_cb, NULL); |
303 |
} |
} |
304 |
|
|
305 |
void |
void |
306 |
arshell_work_area_pixmap_hack() |
arshell_work_area_pixmap_hack () |
307 |
{ |
{ |
308 |
char *icon; |
char *icon; |
309 |
asprintf(&icon, "%s/handtoface.xpm", ICONDIR); |
asprintf (&icon, "%s/handtoface.xpm", ICONDIR); |
310 |
antiright_set_bitmap_from_file(antiright.parent_widget, icon); |
antiright_set_bitmap_from_file (antiright.parent_widget, icon); |
311 |
free(icon); |
free (icon); |
312 |
} |
} |
313 |
|
|
314 |
void |
void |
315 |
arshell_create_text_work_area() |
arshell_create_text_work_area () |
316 |
{ |
{ |
317 |
arshell_set_work_area_arguments(); |
arshell_set_work_area_arguments (); |
318 |
arshell.gui.widgets.work=XmCreateText(arshell.gui.widgets.mainwindow, "work", |
arshell.gui.widgets.work = |
319 |
antiright.arguments, |
XmCreateText (arshell.gui.widgets.mainwindow, "work", antiright.arguments, |
320 |
antiright.arguments_int); |
antiright.arguments_int); |
321 |
XtManageChild(arshell.gui.widgets.work); |
XtManageChild (arshell.gui.widgets.work); |
322 |
antiright_defined_popup_menu(arshell.gui.widgets.work); |
antiright_defined_popup_menu (arshell.gui.widgets.work); |
323 |
arshell_setup_work_area_callbacks(); |
arshell_setup_work_area_callbacks (); |
324 |
arshell_setup_work_menubar(); |
arshell_setup_work_menubar (); |
325 |
arshell_work_area_pixmap_hack(); |
arshell_work_area_pixmap_hack (); |
326 |
} |
} |
327 |
|
|
328 |
void |
void |
329 |
arshell_create_default_text_label(Widget form_widget, |
arshell_create_default_text_label (Widget form_widget, char *label_string) |
|
char* label_string) |
|
330 |
{ |
{ |
331 |
ARCLARG; |
ARCLARG; |
332 |
antiright_form_positions(0, 100, 0, 25); |
antiright_form_positions (0, 100, 0, 25); |
333 |
antiright_label(form_widget, label_string); |
antiright_label (form_widget, label_string); |
334 |
} |
} |
335 |
|
|
336 |
void |
void |
337 |
arshell_set_text_field_arguments() |
arshell_set_text_field_arguments () |
338 |
{ |
{ |
339 |
ARCLARG; |
ARCLARG; |
340 |
antiright_form_positions(0, 100, 25, 100); |
antiright_form_positions (0, 100, 25, 100); |
341 |
antiright_set(XmNeditMode, XmSINGLE_LINE_EDIT); |
antiright_set (XmNeditMode, XmSINGLE_LINE_EDIT); |
342 |
antiright_set(XmNscrollHorizontal, False); |
antiright_set (XmNscrollHorizontal, False); |
343 |
} |
} |
344 |
|
|
345 |
Widget |
Widget |
346 |
arshell_create_default_text_field(Widget parent_widget, char* return_string) |
arshell_create_default_text_field (Widget parent_widget, char *return_string) |
347 |
{ |
{ |
348 |
Widget text_widget; |
Widget text_widget; |
349 |
arshell_set_text_field_arguments(); |
arshell_set_text_field_arguments (); |
350 |
text_widget=XmCreateText(parent_widget, "text_widget", |
text_widget = XmCreateText (parent_widget, "text_widget", |
351 |
antiright.arguments, antiright.arguments_int); |
antiright.arguments, antiright.arguments_int); |
352 |
assert(text_widget!=NULL); |
assert (text_widget != NULL); |
353 |
XtManageChild(text_widget); |
XtManageChild (text_widget); |
354 |
XtAddCallback(text_widget, XmNactivateCallback, |
XtAddCallback (text_widget, XmNactivateCallback, |
355 |
arshell_text_return_cb, return_string); |
arshell_text_return_cb, return_string); |
356 |
return(text_widget); |
return (text_widget); |
357 |
} |
} |
358 |
|
|
359 |
void |
void |
360 |
arshell_set_work_area_from_stdin() |
arshell_set_work_area_from_stdin () |
361 |
{ |
{ |
362 |
char buffer[BUFSIZ]; |
char buffer[BUFSIZ]; |
363 |
if(arshell.gui.widgets.work==NULL) |
if (arshell.gui.widgets.work == NULL) |
364 |
arshell_create_text_work_area(); |
arshell_create_text_work_area (); |
365 |
while(fgets(buffer, BUFSIZ, stdin) != NULL) |
while (fgets (buffer, BUFSIZ, stdin) != NULL) |
366 |
XmTextInsert(arshell.gui.widgets.work, |
XmTextInsert (arshell.gui.widgets.work, |
367 |
XmTextGetInsertionPosition(arshell.gui.widgets.work), buffer); |
XmTextGetInsertionPosition (arshell.gui.widgets.work), |
368 |
XmTextSetInsertionPosition(arshell.gui.widgets.work, 0); |
buffer); |
369 |
|
XmTextSetInsertionPosition (arshell.gui.widgets.work, 0); |
370 |
} |
} |
371 |
|
|
372 |
void |
void |
373 |
arshell_create_default_text_entry(Widget widget_row_widget, |
arshell_create_default_text_entry (Widget widget_row_widget, |
374 |
int* counter_int, |
int *counter_int, char **argv) |
|
char** argv) |
|
375 |
{ |
{ |
376 |
Widget form_widget; |
Widget form_widget; |
377 |
|
|
378 |
ARCLARG; |
ARCLARG; |
379 |
form_widget=antiright_form(widget_row_widget); |
form_widget = antiright_form (widget_row_widget); |
380 |
arshell_create_default_text_label(form_widget, argv[(*counter_int)]); |
arshell_create_default_text_label (form_widget, argv[(*counter_int)]); |
381 |
arshell_create_default_text_field(form_widget, argv[(*counter_int)]); |
arshell_create_default_text_field (form_widget, argv[(*counter_int)]); |
382 |
} |
} |