Changeset ce7b824


Ignore:
Timestamp:
Aug 11, 2007, 1:04:07 AM (17 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
18fb3d4f
Parents:
ad15610
Message:
Implement :punt and :unpunt to punt arbitrary filters, rather than
just z-triplets. closes #6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rad15610 rce7b824  
    280280              "suppressed to be received again.\n\n"
    281281              "SEE ALSO:  zpunt, show zpunts\n"),
     282
     283  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
     284              "suppress an arbitrary filter",
     285              "punt <filter-name>",
     286              "punt <filter-text (multiple words)>\n"
     287              "The punt command will supress message to the specified\n"
     288              "filter\n\n"
     289              "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
     290
     291  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
     292              "remove an entry from the punt list",
     293              "zpunt <filter-name>\n"
     294              "zpunt <filter-text>\n"
     295              "zpunt <number>\n",
     296              "The unpunt command will remove an entry from the puntlist.\n"
     297              "The first two forms correspond to the first two forms of the :punt\n"
     298              "command. The latter allows you to remove a specific entry from the\n"
     299              "the list (see :show zpunts)\n\n"
     300              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
    282301
    283302  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
     
    22942313}
    22952314
    2296 
    22972315void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type)
    22982316{
     
    23442362}
    23452363
     2364char *owl_command_punt(int argc, char **argv, char *buff)
     2365{
     2366  owl_command_punt_unpunt(argc, argv, buff, 0);
     2367  return NULL;
     2368}
     2369
     2370char *owl_command_unpunt(int argc, char **argv, char *buff)
     2371{
     2372  owl_command_punt_unpunt(argc, argv, buff, 1);
     2373  return NULL;
     2374}
     2375
     2376void owl_command_punt_unpunt(int argc, char ** argv, char *buff, int unpunt)
     2377{
     2378  owl_list * fl;
     2379  owl_filter * f;
     2380  char * text;
     2381  int i;
     2382
     2383  fl = owl_global_get_puntlist(&g);
     2384  if(argc == 1) {
     2385    owl_function_show_zpunts();
     2386  }
     2387
     2388  if(argc == 2) {
     2389    /* Handle :unpunt <number> */
     2390    if(unpunt && (i=atoi(argv[1])) !=0) {
     2391      i--;      /* Accept 1-based indexing */
     2392      if(i < owl_list_get_size(fl)) {
     2393        f = (owl_filter*)owl_list_get_element(fl, i);
     2394        owl_list_remove_element(fl, i);
     2395        owl_filter_free(f);
     2396        return;
     2397      } else {
     2398        owl_function_error("No such filter number: %d", i+1);
     2399      }
     2400    }
     2401    text = owl_sprintf("filter %s", argv[1]);
     2402  } else {
     2403    text = skiptokens(buff, 1);
     2404  }
     2405
     2406  owl_function_punt(text, unpunt);
     2407}
     2408
     2409
    23462410char *owl_command_getview(int argc, char **argv, char *buff)
    23472411{
  • functions.c

    rad15610 rce7b824  
    25582558  for (i=0; i<j; i++) {
    25592559    f=owl_list_get_element(fl, i);
     2560    snprintf(buff, sizeof(buff), "[% 2d] ", i+1);
     2561    owl_fmtext_append_normal(&fm, buff);
    25602562    owl_filter_print(f, buff);
    25612563    owl_fmtext_append_normal(&fm, buff);
     
    30173019void owl_function_zpunt(char *class, char *inst, char *recip, int direction)
    30183020{
    3019   owl_filter *f;
    3020   owl_list *fl;
    30213021  char *buff;
    30223022  char *quoted;
    3023   int ret, i, j;
    3024 
    3025   fl=owl_global_get_puntlist(&g);
    3026 
    3027   /* first, create the filter */
    3028   f=malloc(sizeof(owl_filter));
     3023
    30293024  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
    30303025  strcpy(buff, "class");
     
    30573052    owl_free(quoted);
    30583053  }
    3059  
    3060   owl_function_debugmsg("About to filter %s", buff);
    3061   ret=owl_filter_init_fromstring(f, "punt-filter", buff);
     3054
     3055  owl_function_punt(buff, direction);
    30623056  owl_free(buff);
     3057}
     3058
     3059void owl_function_punt(char *filter, int direction)
     3060{
     3061  owl_filter *f;
     3062  owl_list *fl;
     3063  int ret, i, j;
     3064  fl=owl_global_get_puntlist(&g);
     3065
     3066  /* first, create the filter */
     3067  f=malloc(sizeof(owl_filter));
     3068
     3069  owl_function_debugmsg("About to filter %s", filter);
     3070  ret=owl_filter_init_fromstring(f, "punt-filter", filter);
    30633071  if (ret) {
    30643072    owl_function_error("Error creating filter for zpunt");
     
    30713079  for (i=0; i<j; i++) {
    30723080    if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
     3081      owl_function_debugmsg("found an equivalent punt filter");
    30733082      /* if we're punting, then just silently bow out on this duplicate */
    30743083      if (direction==0) {
     
    30813090        owl_filter_free(owl_list_get_element(fl, i));
    30823091        owl_list_remove_element(fl, i);
     3092        owl_filter_free(f);
    30833093        return;
    30843094      }
     
    30863096  }
    30873097
     3098  owl_function_debugmsg("punting");
    30883099  /* If we're punting, add the filter to the global punt list */
    30893100  if (direction==0) {
Note: See TracChangeset for help on using the changeset viewer.