v10i038: contool -- replacement for 'cmdtool -C', Part05/06
News stuff
news at trantor.harris-atd.com
Tue Oct 30 17:26:43 AEST 1990
Submitted-by: news at trantor.harris-atd.com (News stuff)
Posting-number: Volume 10, Issue 38
Archive-name: contool/part05
Path: trantor.harris-atd.com!melmac.harris-atd.com!chuck
From: chuck at melmac.harris-atd.com (Chuck Musciano)
Newsgroups: comp.sources.x
Subject: Contool, part 5/6
Message-ID: <4604 at trantor.harris-atd.com>
Date: 18 Oct 90 15:21:22 GMT
Sender: news at trantor.harris-atd.com
Reply-To: chuck at melmac.harris-atd.com (Chuck Musciano)
Distribution: world
Organization: Advanced Technology Dept., Harris Corp., Melbourne, Fl.
Lines: 911
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 5 (of 6)."
# Contents: filters.c
# Wrapped by chuck at melmac on Fri Aug 17 10:00:53 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'filters.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'filters.c'\"
else
echo shar: Extracting \"'filters.c'\" \(26766 characters\)
sed "s/^X//" >'filters.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1988-1990 by Chuck Musciano and Harris Corporation */
X/* */
X/* Permission to use, copy, modify, and distribute this software */
X/* and its documentation for any purpose and without fee is */
X/* hereby granted, provided that the above copyright notice */
X/* appear in all copies and that both that copyright notice and */
X/* this permission notice appear in supporting documentation, and */
X/* that the name of Chuck Musciano and Harris Corporation not be */
X/* used in advertising or publicity pertaining to distribution */
X/* of the software without specific, written prior permission. */
X/* Chuck Musciano and Harris Corporation make no representations */
X/* about the suitability of this software for any purpose. It is */
X/* provided "as is" without express or implied warranty. This */
X/* software may not be sold without the prior explicit permission */
X/* of Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* filters.c contool filters dialog manager */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X#include <sys/param.h>
X#include <sys/types.h>
X#include <xview/xview.h>
X#include <xview/panel.h>
X#include <xview/notice.h>
X#include <xview/xv_xrect.h>
X
X#include "manifest.h"
X#include "contool.h"
X#include "contool_ui.h"
X
XEXPORT Filter *filters = NULL;
X
XPUBLIC contool_base_objects *contool_base;
X
XPRIVATE short single_bits[] = {
X#include "images/single.icon"
X };
X
XPRIVATE short range_bits[] = {
X#include "images/range.icon"
X };
X
XPRIVATE short empty_bits[] = {
X#include "images/empty.icon"
X };
X
XPRIVATE Filter *edit_set = NULL, *clipboard = NULL;
XPRIVATE contool_filters_objects *contool_filters = NULL;
XPRIVATE Server_image single, range, empty;
X
X/************************************************************************/
XPRIVATE int selection_count()
X
X{ int i, s, total;
X
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (i = s = 0; i < total; i++)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X s++;
X return(s);
X}
X
X/************************************************************************/
XPRIVATE int curr_selection()
X
X{ int i, total;
X
X for (i = 0, total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS); i < total; i++)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X break;
X if (i >= total)
X fprintf(stderr, "No item selected!\n");
X return(i);
X}
X
X/************************************************************************/
XPRIVATE Filter *duplicate_filter(f)
X
XFilter *f;
X
X{ Filter *new;
X
X new = (Filter *) malloc(sizeof(Filter));
X *new = *f;
X new->start = strsave(f->start);
X new->stop = strsave(f->stop);
X compile_exp(new, new->start, new->stop);
X new->command = strsave(f->command);
X new->comment = strsave(f->comment);
X new->next = NULL;
X return(new);
X}
X
X/************************************************************************/
XPRIVATE Filter *duplicate_list(list)
X
XFilter *list;
X
X{ Filter *f, *head = NULL, *curr;
X
X for (f = list; f; f = f->next)
X if (head == NULL)
X head = curr = duplicate_filter(f);
X else {
X curr->next = duplicate_filter(f);
X curr = curr->next;
X }
X return(head);
X}
X
X/************************************************************************/
XPRIVATE free_filter(f)
X
XFilter *f;
X
X{
X cond_free(f->start);
X cond_free(f->start_re);
X cond_free(f->stop);
X cond_free(f->stop_re);
X cond_free(f->command);
X cond_free(f->comment);
X free(f);
X}
X
X/************************************************************************/
XEXPORT free_list(list)
X
XFilter *list;
X
X{ Filter *next;
X
X for ( ; list; list = next) {
X next = list->next;
X free_filter(list);
X }
X}
X
X/************************************************************************/
XPRIVATE update_controls()
X
X{ Filter *f;
X int i;
X
X if (selection_count() == 1) {
X for (f = edit_set, i = 0; f; f = f->next, i++)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X break;
X if (f == NULL) {
X error("Internal error: filters do not match scrolling list!");
X return;
X }
X xv_set(contool_filters->filter_update, PANEL_INACTIVE, FALSE, NULL);
X xv_set(contool_filters->filter_type, PANEL_INACTIVE, FALSE, PANEL_VALUE, f->stop? 1 : 0, NULL);
X xv_set(contool_filters->start, PANEL_INACTIVE, FALSE, PANEL_VALUE, is_null(f->start), NULL);
X xv_set(contool_filters->stop, PANEL_INACTIVE, f->stop == NULL, PANEL_VALUE, is_null(f->stop), NULL);
X xv_set(contool_filters->comment, PANEL_INACTIVE, FALSE, PANEL_VALUE, is_null(f->comment), NULL);
X xv_set(contool_filters->ignore, PANEL_INACTIVE, FALSE, PANEL_VALUE, f->save? 0 : 1, NULL);
X if (f->save) {
X i = 0;
X if (f->beep) {
X i |= BEEP_BIT;
X xv_set(contool_filters->filter_beep_count, PANEL_INACTIVE, FALSE, PANEL_VALUE, f->beep, NULL);
X xv_set(contool_filters->filter_beep_times, PANEL_INACTIVE, FALSE, NULL);
X }
X else {
X xv_set(contool_filters->filter_beep_count, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_beep_times, PANEL_INACTIVE, TRUE, NULL);
X }
X if (f->command) {
X i |= COMMAND_BIT;
X xv_set(contool_filters->filter_command, PANEL_INACTIVE, FALSE, PANEL_VALUE, f->command, NULL);
X xv_set(contool_filters->filter_beep_times, PANEL_INACTIVE, FALSE, NULL);
X }
X else
X xv_set(contool_filters->filter_command, PANEL_INACTIVE, TRUE, NULL);
X if (f->flash)
X i |= FLASH_BIT;
X if (f->open)
X i |= OPEN_BIT;
X if (f->stamp)
X i |= STAMP_BIT;
X xv_set(contool_filters->action, PANEL_INACTIVE, FALSE, PANEL_VALUE, i, NULL);
X }
X else {
X xv_set(contool_filters->action, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_beep_count, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_beep_times, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_command, PANEL_INACTIVE, TRUE, NULL);
X }
X }
X else {
X xv_set(contool_filters->filter_update, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_type, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->start, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->stop, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->comment, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->ignore, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->action, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_beep_count, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_beep_times, PANEL_INACTIVE, TRUE, NULL);
X xv_set(contool_filters->filter_command, PANEL_INACTIVE, TRUE, NULL);
X }
X}
X
X/************************************************************************/
XPRIVATE init_filters()
X
X{ Filter *f;
X int i, total;
X
X xv_set(contool_filters->filter_list, PANEL_PAINT, PANEL_NO_CLEAR, NULL);
X for (total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS); total > 0; total--)
X xv_set(contool_filters->filter_list, PANEL_LIST_DELETE, total - 1, NULL);
X xv_set(contool_filters->filter_list, PANEL_PAINT, PANEL_CLEAR, NULL);
X free_list(edit_set);
X edit_set = duplicate_list(filters);
X for (i = 0, f = edit_set; f; f = f->next, i++)
X xv_set(contool_filters->filter_list,
X PANEL_LIST_INSERT, i,
X PANEL_LIST_GLYPH, i, f->stop? range : single,
X PANEL_LIST_STRING, i, f->start,
X NULL);
X update_controls();
X}
X
X/************************************************************************/
XPRIVATE insert_item(pos)
X
Xint pos;
X
X{ int i, total;
X Filter *f, *t;
X
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (i = 0; i < total; i++)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X xv_set(contool_filters->filter_list, PANEL_LIST_SELECT, i, FALSE, NULL);
X xv_set(contool_filters->filter_list, PANEL_LIST_INSERT, pos, NULL);
X xv_set(contool_filters->filter_list, PANEL_LIST_GLYPH, pos, empty, NULL);
X xv_set(contool_filters->filter_list, PANEL_LIST_SELECT, pos, TRUE, NULL);
X if (pos == 0) {
X f = (Filter *) malloc(sizeof(Filter));
X f->next = edit_set;
X edit_set = f;
X }
X else {
X for (i = 1, f = edit_set; i < pos; i++, f = f->next)
X ;
X t = f->next;
X f->next = (Filter *) malloc(sizeof(Filter));
X f = f->next;
X f->next = t;
X }
X f->start = f->stop = f->comment = NULL;
X f->beep = defaults.beep;
X f->command = strsave(defaults.command);
X f->flash = defaults.flash;
X f->open = defaults.open;
X f->stamp = defaults.stamp;
X f->save = TRUE;
X update_controls();
X/* update the scrolling view */
X}
X
X/************************************************************************/
XPRIVATE paste_items(pos)
X
Xint pos;
X
X{ int i;
X Filter *new, *tail, *f;
X
X new = duplicate_list(clipboard);
X for (f = new, i = 0; f; f = f->next, i++) {
X xv_set(contool_filters->filter_list, PANEL_LIST_INSERT, pos + i, 0);
X xv_set(contool_filters->filter_list,
X PANEL_LIST_STRING, pos + i, f->start,
X PANEL_LIST_GLYPH, pos + i, f->stop? range : single,
X NULL);
X tail = f;
X }
X if (pos == 0) {
X tail->next = edit_set;
X edit_set = new;
X }
X else {
X for (i = 1, f = edit_set; i < pos; i++, f = f->next)
X ;
X tail->next = f->next;
X f->next = new;
X }
X update_controls();
X}
X
X/************************************************************************/
XPRIVATE int update_values(f, flag)
X
XFilter *f;
Xint flag;
X
X{ char *start, *stop, *msg;
X int i;
X
X start = (char *) xv_get(contool_filters->start, PANEL_VALUE);
X if (is_empty(start)) {
X if (flag)
X error("You must specify a starting message pattern");
X return(FALSE);
X }
X if (xv_get(contool_filters->filter_type, PANEL_VALUE) == 1)
X stop = (char *) xv_get(contool_filters->stop, PANEL_VALUE);
X else
X stop = NULL;
X if (msg = compile_exp(f, start, stop)) {
X if (flag)
X error(msg);
X return(FALSE);
X }
X if ((int) xv_get(contool_filters->ignore, PANEL_VALUE) == 0) {
X i = (int) xv_get(contool_filters->action, PANEL_VALUE);
X if (i & COMMAND_BIT)
X if (msg = (char *) xv_get(contool_filters->filter_command, PANEL_VALUE))
X f->command = strsave(msg);
X else {
X if (flag)
X error("You must specify a command for this filter");
X return(FALSE);
X }
X else
X f->command = NULL;
X if (i & BEEP_BIT)
X f->beep = (int) xv_get(contool_filters->filter_beep_count, PANEL_VALUE);
X else
X f->beep = 0;
X f->flash = (i & FLASH_BIT)? TRUE : FALSE;
X f->open = (i & OPEN_BIT)? TRUE : FALSE;
X f->stamp = (i & STAMP_BIT)? TRUE : FALSE;
X f->save = TRUE;
X }
X else
X f->save = FALSE;
X f->start = strsave(start);
X f->stop = strsave(stop);
X f->comment = strsave((char *) xv_get(contool_filters->comment, PANEL_VALUE));
X return(TRUE);
X}
X
X/************************************************************************/
XEXPORT Menu_item edit_filters(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{ Filter *f, *curr;
X
X if (op == MENU_NOTIFY) {
X xv_set(contool_base->base, FRAME_BUSY, TRUE, NULL);
X if (contool_filters == NULL) {
X contool_filters = contool_filters_objects_initialize(NULL, contool_base->base);
X place_dialog(contool_base->base, contool_filters->filters);
X xv_set(contool_filters->filter_list, PANEL_LIST_ROW_HEIGHT, 16, NULL);
X single = (Server_image) xv_create(NULL, SERVER_IMAGE,
X XV_WIDTH, 16,
X XV_HEIGHT, 16,
X SERVER_IMAGE_BITS, single_bits,
X 0);
X range = (Server_image) xv_create(NULL, SERVER_IMAGE,
X XV_WIDTH, 16,
X XV_HEIGHT, 16,
X SERVER_IMAGE_BITS, range_bits,
X 0);
X empty = (Server_image) xv_create(NULL, SERVER_IMAGE,
X XV_WIDTH, 16,
X XV_HEIGHT, 16,
X SERVER_IMAGE_BITS, empty_bits,
X 0);
X }
X if (xv_get(contool_filters->filters, XV_SHOW) == FALSE) {
X edit_set = duplicate_list(filters);
X free_list(clipboard);
X clipboard = NULL;
X init_filters();
X }
X xv_set(contool_filters->filters, XV_SHOW, TRUE, NULL);
X xv_set(contool_base->base, FRAME_BUSY, FALSE, NULL);
X }
X return item;
X}
X
X/************************************************************************/
XEXPORT int filter_notify(item, string, client_data, op, event)
X
XPanel_item item;
Xchar *string;
XXv_opaque client_data;
XPanel_list_op op;
XEvent *event;
X
X{
X if (op == PANEL_LIST_OP_DESELECT || op == PANEL_LIST_OP_SELECT)
X update_controls();
X return XV_OK;
X}
X
X/************************************************************************/
XEXPORT Menu filter_insert_handler(menu, op)
X
XMenu menu;
XMenu_generate op;
X
X{
X xv_set(menu, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X return menu;
X}
X
X/************************************************************************/
XEXPORT Menu_item insert_at_top(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_NOTIFY)
X insert_item(0);
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item insert_above(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() != 1, NULL);
X else if (op == MENU_NOTIFY)
X insert_item(curr_selection());
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item insert_below(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() != 1, NULL);
X else if (op == MENU_NOTIFY)
X insert_item(curr_selection() + 1);
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item insert_at_bottom(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_NOTIFY)
X insert_item(xv_get(contool_filters->filter_list, PANEL_LIST_NROWS));
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu filter_edit_handler(menu, op)
X
XMenu menu;
XMenu_generate op;
X
X{
X xv_set(menu, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_insert, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X return menu;
X}
X
X/************************************************************************/
XEXPORT Menu_item filter_cut(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{ int i, total;
X Filter *f, *prev, *curr = NULL;
X
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_edit, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() == 0, NULL);
X else if (op == MENU_NOTIFY) {
X free_list(clipboard);
X clipboard = NULL;
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (prev = NULL, f = edit_set, i = 0; i < total; i++, f = f->next)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i)) {
X if (clipboard == NULL)
X clipboard = curr = f;
X else {
X curr->next = f;
X curr = curr->next;
X }
X if (prev == NULL)
X edit_set = f->next;
X else
X prev->next = f->next;
X xv_set(contool_filters->filter_list, PANEL_LIST_DELETE, i, NULL);
X i--;
X total--;
X }
X else
X prev = f;
X if (curr)
X curr->next = NULL;
X update_controls();
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X }
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item filter_copy(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{ int i, total;
X Filter *f, *curr;
X
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_edit, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() == 0, NULL);
X else if (op == MENU_NOTIFY) {
X free_list(clipboard);
X clipboard = NULL;
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (f = edit_set, i = 0; i < total; i++, f = f->next)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X if (clipboard == NULL)
X clipboard = curr = duplicate_filter(f);
X else {
X curr->next = duplicate_filter(f);
X curr = curr->next;
X }
X curr->next = NULL;
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X }
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item filter_delete(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{ int i, total;
X Filter *f, *prev, *temp = NULL, *curr;
X
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(contool_filters->filter_edit, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() == 0, NULL);
X else if (op == MENU_NOTIFY) {
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (prev = NULL, f = edit_set, i = 0; i < total; i++, f = f->next)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i)) {
X if (temp == NULL)
X temp = curr = f;
X else {
X curr->next = f;
X curr = curr->next;
X }
X if (prev == NULL)
X edit_set = f->next;
X else
X prev->next = f->next;
X xv_set(contool_filters->filter_list, PANEL_LIST_DELETE, i, NULL);
X i--;
X total--;
X }
X else
X prev = f;
X if (curr)
X curr->next = NULL;
X free_list(temp);
X update_controls();
X xv_set(item, MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X }
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item filter_paste(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, clipboard == NULL, NULL);
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item paste_at_top(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_NOTIFY)
X paste_items(0);
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item paste_above(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() != 1, NULL);
X else if (op == MENU_NOTIFY)
X paste_items(curr_selection());
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item paste_below(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_DISPLAY)
X xv_set(item, MENU_INACTIVE, selection_count() != 1, NULL);
X else if (op == MENU_NOTIFY)
X paste_items(curr_selection() + 1);
X return item;
X}
X
X/************************************************************************/
XEXPORT Menu_item paste_at_bottom(item, op)
X
XMenu_item item;
XMenu_generate op;
X
X{
X xv_set(xv_get(contool_filters->filter_edit, PANEL_ITEM_MENU), MENU_NOTIFY_STATUS, XV_ERROR, NULL);
X if (op == MENU_NOTIFY)
X paste_items((int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS));
X return item;
X}
X
X/************************************************************************/
XEXPORT void filter_update(item, event)
X
XPanel_item item;
XEvent *event;
X
X{ int i, curr;
X Filter *f;
X
X xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X
X curr = curr_selection();
X for (i = 0, f = edit_set; i < curr; i++, f = f->next)
X ;
X if (update_values(f, TRUE))
X xv_set(contool_filters->filter_list,
X PANEL_LIST_STRING, curr, f->start,
X PANEL_LIST_GLYPH, curr, f->stop? range : single,
X NULL);
X}
X
X/************************************************************************/
XEXPORT void set_filter_type(item, value, event)
X
XPanel_item item;
Xint value;
XEvent *event;
X
X{
X xv_set(contool_filters->stop, PANEL_INACTIVE, value == 0, NULL);
X}
X
X/************************************************************************/
XEXPORT void set_filter_action(item, value, event)
X
XPanel_item item;
Xint value;
XEvent *event;
X
X{ contool_filters_objects *ip = (contool_filters_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
X
X if (value == 0) { /* save this message */
X xv_set(ip->action, PANEL_INACTIVE, FALSE, NULL);
X xv_set(ip->filter_beep_count, PANEL_INACTIVE, !((int) xv_get(ip->action, PANEL_VALUE) & BEEP_BIT), NULL);
X xv_set(ip->filter_beep_times, PANEL_INACTIVE, !((int) xv_get(ip->action, PANEL_VALUE) & BEEP_BIT), NULL);
X xv_set(ip->filter_command, PANEL_INACTIVE, !((int) xv_get(ip->action, PANEL_VALUE) & COMMAND_BIT), NULL);
X }
X else { /* ignore this message */
X xv_set(ip->action, PANEL_INACTIVE, TRUE, NULL);
X xv_set(ip->filter_beep_count, PANEL_INACTIVE, TRUE, NULL);
X xv_set(ip->filter_beep_times, PANEL_INACTIVE, TRUE, NULL);
X xv_set(ip->filter_command, PANEL_INACTIVE, TRUE, NULL);
X }
X}
X
X/************************************************************************/
XEXPORT void set_match_action(item, value, event)
X
XPanel_item item;
Xunsigned int value;
XEvent *event;
X
X{ contool_filters_objects *ip = (contool_filters_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
X
X xv_set(ip->filter_beep_count, PANEL_INACTIVE, !(value & BEEP_BIT), NULL);
X xv_set(ip->filter_beep_times, PANEL_INACTIVE, !(value & BEEP_BIT), NULL);
X xv_set(ip->filter_command, PANEL_INACTIVE, !(value & COMMAND_BIT), NULL);
X}
X
X/************************************************************************/
XEXPORT void filter_done(frame)
X
XFrame frame;
X
X{
X free_list(edit_set);
X edit_set = NULL;
X free_list(clipboard);
X clipboard = NULL;
X xv_set(frame, XV_SHOW, FALSE, 0);
X}
X
X/************************************************************************/
XPRIVATE int check_for_update()
X
X{ int i, result, curr, diff = FALSE;
X Filter *f, new;
X
X if (selection_count() != 1)
X return(TRUE);
X curr = curr_selection();
X for (i = 0, f = edit_set; i < curr; i++, f = f->next)
X ;
X new = *f;
X if (update_values(&new, FALSE) == FALSE)
X diff = TRUE;
X else if ((f->start != NULL && new.start == NULL) || (f->start == NULL && new.start != NULL))
X diff = TRUE;
X else if ((f->stop != NULL && new.stop == NULL) || (f->stop == NULL && new.stop != NULL))
X diff = TRUE;
X else if ((f->comment != NULL && new.comment == NULL) || (f->comment == NULL && new.comment != NULL))
X diff = TRUE;
X else if ((f->command != NULL && new.command == NULL) || (f->command == NULL && new.command != NULL))
X diff = TRUE;
X else if (f->save != new.save || f->beep != new.beep || f->flash != new.flash || f->open != new.open || f->stamp != new.stamp)
X diff = TRUE;
X else if (f->start && strcmp(f->start, new.start) != 0)
X diff = TRUE;
X else if (f->stop && strcmp(f->stop, new.stop) != 0)
X diff = TRUE;
X else if (f->comment && strcmp(f->comment, new.comment) != 0)
X diff = TRUE;
X else if (f->command && strcmp(f->command, new.command) != 0)
X diff = TRUE;
X if (diff) {
X result = notice_prompt(contool_base->base, NULL,
X NOTICE_MESSAGE_STRINGS,
X "You have modified the attributes of the selected filter.",
X " ",
X "Do you wish to perform an Update before doing an Apply?",
X NULL,
X NOTICE_BUTTON_YES, "Update, then Apply",
X NOTICE_BUTTON_NO, "Apply",
X NOTICE_BUTTON, "Cancel", 101,
X NULL);
X if (result == NOTICE_YES)
X filter_update(contool_filters->filters, NULL);
X return(result != 101);
X }
X return(TRUE);
X}
X
X/************************************************************************/
XEXPORT void accept_filters(item, event)
X
XPanel_item item;
XEvent *event;
X
X{ Filter *f;
X int i, total;
X char *msg = NULL;
X
X if (!check_for_update()) {
X xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X return;
X }
X
X total = (int) xv_get(contool_filters->filter_list, PANEL_LIST_NROWS);
X for (i = 0; i < total; i++)
X if (xv_get(contool_filters->filter_list, PANEL_LIST_SELECTED, i))
X xv_set(contool_filters->filter_list, PANEL_LIST_SELECT, i, FALSE, NULL);
X for (f = edit_set, i = 0; f; f = f->next, i++)
X if (is_empty(f->start) || (msg = compile_exp(f, f->start, f->stop))) {
X xv_set(contool_filters->filter_list, PANEL_LIST_SELECT, i, TRUE, NULL);
X update_controls();
X error(msg? msg : "No pattern is specified for the indicated filter");
X xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X return;
X }
X free_list(filters);
X filters = edit_set;
X if (xv_get(contool_filters->filters, FRAME_CMD_PUSHPIN_IN))
X edit_set = duplicate_list(filters);
X else {
X edit_set = NULL;
X free_list(clipboard);
X clipboard = NULL;
X }
X filters_changed();
X}
X
X/************************************************************************/
XEXPORT void reset_filters(item, event)
X
XPanel_item item;
XEvent *event;
X
X{
X init_filters();
X xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, NULL);
X}
END_OF_FILE
if test 26766 -ne `wc -c <'filters.c'`; then
echo shar: \"'filters.c'\" unpacked with wrong size!
fi
# end of 'filters.c'
fi
echo shar: End of archive 5 \(of 6\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 6 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
Chuck Musciano ARPA : chuck at trantor.harris-atd.com
Harris Corporation Usenet: ...!uunet!x102a!trantor!chuck
PO Box 37, MS 3A/1912 AT&T : (407) 727-6131
Melbourne, FL 32902 FAX : (407) 729-2537
A good newspaper is never good enough,
but a lousy newspaper is a joy forever. -- Garrison Keillor
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list