home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright 1988, 1989 by Chuck Musciano and Harris Corporation */
- /* */
- /* Permission to use, copy, modify, and distribute this software */
- /* and its documentation for any purpose and without fee is */
- /* hereby granted, provided that the above copyright notice */
- /* appear in all copies and that both that copyright notice and */
- /* this permission notice appear in supporting documentation, and */
- /* that the name of Chuck Musciano and Harris Corporation not be */
- /* used in advertising or publicity pertaining to distribution */
- /* of the software without specific, written prior permission. */
- /* Chuck Musciano and Harris Corporation make no representations */
- /* about the suitability of this software for any purpose. It is */
- /* provided "as is" without express or implied warranty. This */
- /* software may not be sold without the prior explicit permission */
- /* of Harris Corporation. */
- /************************************************************************/
-
- #include <stdio.h>
-
- #include <sys/file.h>
-
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
-
- #include "contool.h"
- #include "entry.h"
-
- PUBLIC Pixrect *better_button_image();
-
- EXPORT Pixfont *bold, *regular;
- EXPORT Panel other;
-
- PRIVATE Frame dialog = NULL;
- PRIVATE Panel items;
- PRIVATE Panel_item file_name;
-
- /************************************************************************/
- /* Support routines for edit buttons */
- /************************************************************************/
-
- /************************************************************************/
- PRIVATE f_ptr update_filters()
-
- { int i, curr, limit, errors = FALSE;
- char *result, *start, *end;
- f_ptr f, new_filters = NULL;
-
- for (i = 0; i < entries; i++)
- panel_set(entry[i].handle, PANEL_VALUE, 0, 0);
- for (i = 0; i < entries; i++)
- if (entry[i].created) {
- start = (char *) panel_get(entry[i].start, PANEL_VALUE);
- if (panel_get(entry[i].lines, PANEL_VALUE)) {
- if (*start == '\0') {
- window_error("Filter error:\n Filter %d is missing its starting pattern", i + 1);
- panel_set(entry[i].handle, PANEL_VALUE, 1, 0);
- panel_set(items, PANEL_CARET_ITEM, entry[i].start, 0);
- errors = TRUE;
- continue;
- }
- end = (char *) panel_get(entry[i].end, PANEL_VALUE);
- if (*end == '\0') {
- window_error("Filter error:\n Filter %d is missing its ending pattern", i + 1);
- panel_set(entry[i].handle, PANEL_VALUE, 1, 0);
- panel_set(items, PANEL_CARET_ITEM, entry[i].end, 0);
- errors = TRUE;
- continue;
- }
- }
- else {
- end = NULL;
- if (*start == '\0') {
- window_error("Filter error:\n Filter %d has no pattern specified", i + 1);
- panel_set(entry[i].handle, PANEL_VALUE, 1, 0);
- panel_set(items, PANEL_CARET_ITEM, entry[i].start, 0);
- errors = TRUE;
- continue;
- }
- }
- if (result = compile_exp(NULL, start, end)) {
- window_error("Error in filter %d:\n %s", i + 1, result);
- panel_set(entry[i].handle, PANEL_VALUE, 1, 0);
- panel_set(items, PANEL_CARET_ITEM, entry[i].start, 0);
- errors = TRUE;
- continue;
- }
- }
- if (errors)
- return(NULL);
- for (i = 0, f = next_filter(&new_filters, &curr, &limit); i < MAX_ENTRIES; i++)
- if (entry[i].created) {
- f->save = (int) panel_get(entry[i].save, PANEL_VALUE);
- f->beep = (int) panel_get(entry[i].beep, PANEL_VALUE);
- f->open = (int) panel_get(entry[i].open, PANEL_VALUE);
- f->flash = (int) panel_get(entry[i].flash, PANEL_VALUE);
- f->stamp = (int) panel_get(entry[i].stamp, PANEL_VALUE);
- f->start = strsave(panel_get(entry[i].start, PANEL_VALUE));
- f->end = panel_get(entry[i].lines, PANEL_VALUE)? strsave(panel_get(entry[i].end, PANEL_VALUE)) : NULL;
- f->valid = TRUE;
- compile_exp(f, f->start, f->end);
- f = next_filter(&new_filters, &curr, &limit);
- }
- return(new_filters);
- }
-
- /************************************************************************/
- /* Edit button action routines */
- /************************************************************************/
-
- /************************************************************************/
- PRIVATE load_filters()
-
- { char *path, *result;
- f_ptr new_filters, f;
-
- path = (char *) panel_get(file_name, PANEL_VALUE);
- if (access(path, R_OK) == 0) {
- if (new_filters = read_filters(path, window_error)) {
- for (f = new_filters; f->start; f++)
- if (result = compile_exp(f, f->start, f->end)) {
- window_error("Bad filter encountered in %s:\n %s", path, result);
- f->valid = FALSE;
- }
- update_edit_dialog(new_filters);
- free_filters(new_filters);
- }
- }
- else
- window_error("Cannot read filter file %s", path);
- }
-
- /************************************************************************/
- PRIVATE save_filters()
-
- { char *path;
- f_ptr filters;
-
- if (filters = update_filters()) {
- path = (char *) panel_get(file_name, PANEL_VALUE);
- write_filters(filters, path, window_error);
- }
- else
- window_error("Filters have not been saved");
- }
-
- /************************************************************************/
- PRIVATE cut_filter()
-
- { int i, j;
-
- clear_clipboard();
- for (i = 0; i < entries; i++)
- if (panel_get(entry[i].handle, PANEL_VALUE)) {
- add_to_clipboard(entry + i);
- delete_entry(entry + i);
- }
- else if (cb_size > 0)
- move_entry(entry, i, i - cb_size);
- entries -= cb_size;
- panel_update_scrolling_size(items);
- panel_paint(items, PANEL_NO_CLEAR);
- }
-
- /************************************************************************/
- PRIVATE copy_filter()
-
- { int i;
- f_ptr f;
-
- clear_clipboard();
- for (i = cb_size = 0; i < entries; i++)
- if (panel_get(entry[i].handle, PANEL_VALUE))
- add_to_clipboard(entry + i);
- }
-
- /************************************************************************/
- PRIVATE paste_filter()
-
- { int i, j, count;
-
- for (i = 0; i < entries; i++)
- if (panel_get(entry[i].handle, PANEL_VALUE))
- break;
- for (j = entries - 1, count = cb_size? cb_size : 1; j >= i; j--)
- move_entry(entry, j, j + count);
- if (cb_size == 0) {
- update_entry(items, entry, i, NULL);
- panel_set(items, PANEL_CARET_ITEM, entry[i].start, 0);
- entries++;
- }
- else {
- for (j = 0; j < cb_size; j++)
- update_entry(items, entry, i + j, clipboard + j);
- entries += cb_size;
- }
- panel_update_scrolling_size(items);
- panel_paint(items, PANEL_NO_CLEAR);
- }
-
- /************************************************************************/
- PRIVATE done_edit()
-
- { f_ptr new_filters;
-
- if (new_filters = update_filters()) {
- free_filters(filters);
- filters = new_filters;
- curr_filter = NULL;
- install_defaults();
- strcpy(filter_path, panel_get(file_name, PANEL_VALUE));
- window_set(dialog, WIN_SHOW, FALSE, 0);
- }
- }
-
- /************************************************************************/
- PRIVATE reset_edit()
-
- {
- update_edit_dialog(filters);
- update_defaults();
- }
-
- /************************************************************************/
- PRIVATE quit_edit()
-
- {
- window_set(dialog, WIN_SHOW, FALSE, 0);
- }
-
- /************************************************************************/
- /* External entry points to this module */
- /************************************************************************/
-
- /************************************************************************/
- EXPORT update_edit_dialog(filters)
-
- f_ptr filters;
-
- { register int i;
- register e_ptr e;
- register f_ptr f;
-
- for (i = 0, f = filters; f->start; i++, e++, f++) {
- create_entry(items, entry, i);
- update_entry(items, entry, i, f);
- }
- for (entries = i, e = entry + i; i < MAX_ENTRIES; i++, e++)
- delete_entry(e);
- panel_update_scrolling_size(items);
- panel_paint(items, PANEL_CLEAR);
- }
-
- /************************************************************************/
- EXPORT Frame create_dialog_box(base)
-
- Frame base;
-
- { Panel control;
- Panel_item c, p, d;
- int i;
-
- if (dialog)
- return;
- bold = pf_open(BOLD_FONT);
- regular = pf_open(REGULAR_FONT);
- dialog = window_create(base, FRAME,
- FRAME_LABEL, "<< Contool Filter Editor >>",
- FRAME_SHOW_LABEL, TRUE,
- FRAME_NO_CONFIRM, TRUE,
- FRAME_DONE_PROC, done_edit,
- 0);
- control = window_create(dialog, PANEL,
- WIN_WIDTH, ITEM_WIDTH,
- 0);
- panel_create_item(control, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, better_button_image(control, "Load", 12, 4, bold),
- PANEL_NOTIFY_PROC, load_filters,
- 0);
- panel_create_item(control, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, better_button_image(control, "Save", 12, 3, bold),
- PANEL_NOTIFY_PROC, save_filters,
- 0);
- c = panel_create_item(control, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, better_button_image(control, "Cut", 12, 4, bold),
- PANEL_NOTIFY_PROC, cut_filter,
- 0);
- p = panel_create_item(control, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, better_button_image(control, "Paste", 12, 3, bold),
- PANEL_NOTIFY_PROC, paste_filter,
- 0);
- d = panel_create_item(control, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, better_button_image(control, "Done", 12, 4, bold),
- PANEL_NOTIFY_PROC, done_edit,
- 0);
- file_name = panel_create_item(control, PANEL_TEXT,
- PANEL_ITEM_Y, 35,
- PANEL_LABEL_STRING, "File:",
- PANEL_LABEL_FONT, bold,
- PANEL_VALUE_STORED_LENGTH, 256,
- PANEL_VALUE_DISPLAY_LENGTH, 24,
- PANEL_VALUE_FONT, regular,
- PANEL_VALUE, filter_path,
- 0);
- panel_create_item(control, PANEL_BUTTON,
- PANEL_ITEM_Y, 31,
- PANEL_LABEL_IMAGE, better_button_image(control, "Copy", 12, 4, bold),
- PANEL_NOTIFY_PROC, copy_filter,
- PANEL_ITEM_X, panel_get(c, PANEL_ITEM_X),
- 0);
- panel_create_item(control, PANEL_BUTTON,
- PANEL_ITEM_Y, 31,
- PANEL_LABEL_IMAGE, better_button_image(control, "Reset", 12, 4, bold),
- PANEL_NOTIFY_PROC, reset_edit,
- PANEL_ITEM_X, panel_get(p, PANEL_ITEM_X),
- 0);
- panel_create_item(control, PANEL_BUTTON,
- PANEL_ITEM_Y, 31,
- PANEL_LABEL_IMAGE, better_button_image(control, "Cancel", 12, 4, bold),
- PANEL_NOTIFY_PROC, quit_edit,
- PANEL_ITEM_X, panel_get(d, PANEL_ITEM_X),
- 0);
- window_fit_height(control);
- items = window_create(dialog, PANEL,
- WIN_X, 0,
- WIN_BELOW, control,
- WIN_WIDTH, ITEM_WIDTH,
- WIN_HEIGHT, ROW_HEIGHT * 10 + ROW_MARGIN * 11,
- WIN_VERTICAL_SCROLLBAR, scrollbar_create(0),
- 0);
- other = window_create(dialog, PANEL,
- WIN_X, 0,
- WIN_BELOW, items,
- WIN_WIDTH, ITEM_WIDTH,
- WIN_HEIGHT, ROW_HEIGHT + ROW_MARGIN * 2,
- 0);
- window_fit(dialog);
- for (i = 0; i < MAX_ENTRIES; i++)
- entry[i].created = FALSE;
- return(dialog);
- }
-