Changeset 486688f


Ignore:
Timestamp:
Sep 28, 2002, 1:14:45 PM (21 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
88736cb
Parents:
55a4578
Message:
Will attempt to keep the current message as close as possible
	     to the previous current message after an expunge.
"set <variable>" and "unset <variable>" now work for boolean variables.
	   (although I'm not totally happy with how I implemented it.)
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r55faab7 r486688f  
    11$Id$
     2
    231.2.6
    34        Started adding code for newmsgproc.  It doesn't fully work yet!
    45          Don't use it.
    56        Added search, '/' and '?' to basic help.
     7        Will attempt to keep the current message as close as possible
     8             to the previous current message after an expunge.
     9        "set <variable>" and "unset <variable>" now work for boolean variables.
    610       
    7111.2.5
     
    2428        You can now use %me% in filters
    2529        The built-in personal filter is updated to do so
    26         Fixed a bug in moving the poiner after an expunge
     30        Fixed a bug in moving the pointer after an expunge
    2731        Fixed up the normal scrolling code.  Now it should always
    2832          land on a message, but it's still not optimal.
  • commands.c

    rbde7714 r486688f  
    114114  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
    115115              "set a variable value",
    116               "set [-q] <variable> <value>\n"
     116              "set [-q] <variable> [<value>]\n"
    117117              "set",
    118118              "Set the named variable to the specified value.  If no\n"
    119119              "arguments are used print the value of all variables.\n"
     120              "If value is unspecified and the variable is a boolean, will set it to 'on'.\n"
     121              "If -q is specified, is silent and doesn't print a message.\n"),
     122
     123  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
     124              "unset a boolean variable value",
     125              "set [-q] <variable>\n"
     126              "set",
     127              "Set the named boolean variable to off.\n"
    120128              "If -q is specified, is silent and doesn't print a message.\n"),
    121129
     
    946954  char *var, *val;
    947955  int  silent=0;
     956  int requirebool=0;
    948957
    949958  if (argc == 1) {
    950959    owl_function_printallvars();
    951960    return NULL;
    952   } else if (argc == 4 && !strcmp("-q",argv[1])) {
     961  }
     962
     963  if (argc > 1 && !strcmp("-q",argv[1])) {
    953964    silent = 1;
    954     var=argv[2];
    955     val=argv[3];
     965    argc--; argv++;
     966  }
     967
     968  if (argc == 2) {
     969    var=argv[1];
     970    val="on";
     971    requirebool=1;
    956972  } else if (argc == 3) {
    957973    var=argv[1];
     
    961977    return NULL;
    962978  }
    963 
    964   owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent);
     979  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
     980  return NULL;
     981}
     982
     983char *owl_command_unset(int argc, char **argv, char *buff) {
     984  char *var, *val;
     985  int  silent=0;
     986
     987  if (argc > 1 && !strcmp("-q",argv[1])) {
     988    silent = 1;
     989    argc--; argv++;
     990  }
     991  if (argc == 2) {
     992    var=argv[1];
     993    val="off";
     994  } else {
     995    owl_function_makemsg("Wrong number of arguments for unset command");
     996    return NULL;
     997  }
     998  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
    965999  return NULL;
    9661000}
  • functions.c

    r601a9e0 r486688f  
    397397  owl_messagelist *ml;
    398398  owl_view *v;
    399   int i, j;
     399  int lastmsgid=0;
    400400
    401401  curmsg=owl_global_get_curmsg(&g);
     
    403403  ml=owl_global_get_msglist(&g);
    404404
    405   /* just check to make sure we're in bounds... */
    406   if (curmsg>owl_view_get_size(v)-1) curmsg=owl_view_get_size(v)-1;
    407   if (curmsg<0) curmsg=0;
    408 
    409   /* first try to move to an undeleted message in the view */
    410405  m=owl_view_get_element(v, curmsg);
    411   if (owl_message_is_delete(m)) {
    412     /* try to find the next undeleted message */
    413     j=owl_view_get_size(v);
    414     for (i=curmsg+1; i<j; i++) {
    415       if (!owl_message_is_delete(owl_view_get_element(v, i))) {
    416         owl_global_set_curmsg(&g, i);
    417         break;
    418       }
    419     }
    420 
    421     /* if we weren't successful try to find one backwards */
    422     curmsg=owl_global_get_curmsg(&g);
    423     if (owl_message_is_delete(owl_view_get_element(v, curmsg))) {
    424       for (i=curmsg; i>0; i--) {
    425         if (!owl_message_is_delete(owl_view_get_element(v, i))) {
    426           owl_global_set_curmsg(&g, i);
    427           break;
    428         }
    429       }
    430     }
    431   }
     406  if (m) lastmsgid = owl_message_get_id(m);
    432407
    433408  /* expunge the message list */
     
    437412  owl_view_recalculate(v);
    438413
    439   if (curmsg>owl_view_get_size(v)-1) {
    440     owl_global_set_curmsg(&g, owl_view_get_size(v)-1);
    441     if (owl_global_get_curmsg(&g)<0) {
    442       owl_global_set_curmsg(&g, 0);
    443     }
    444     owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    445   }
    446 
     414  /* find where the new position should be
     415     (as close as possible to where we last where) */
     416  curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid);
     417  if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1;
     418  if (curmsg<0) curmsg = 0;
     419  owl_global_set_curmsg(&g, curmsg);
     420  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    447421  /* if there are no messages set the direction to down in case we
    448422     delete everything upwards */
  • util.c

    r5a6e6b9 r486688f  
    44#include <unistd.h>
    55#include <malloc.h>
     6#include <unistd.h>
    67#include <ctype.h>
    78
  • variable.c

    r700c712 r486688f  
    430430
    431431/* returns 0 on success, prints a status msg if msg is true */
    432 int owl_variable_set_fromstring(owl_vardict *d, char *name, char *value, int msg) {
     432int owl_variable_set_fromstring(owl_vardict *d, char *name, char *value, int msg, int requirebool) {
    433433  owl_variable *v;
    434434  char buff2[1024];
     
    441441  if (!v->set_fromstring_fn) {
    442442    if (msg) owl_function_makemsg("Variable %s is read-only", name);
    443     return -1;
    444    
     443    return -1;   
     444  }
     445  if (requirebool && v->type!=OWL_VARIABLE_BOOL) {
     446    if (msg) owl_function_makemsg("Variable %s is not a boolean", name);
     447    return -1;   
    445448  }
    446449  if (0 != v->set_fromstring_fn(v, value)) {
     
    801804  FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"personalbell"));
    802805  FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"personalbell"));
    803   FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"personalbell","off",0));
     806  FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"personalbell","off",0,0));
    804807  FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"personalbell"));
    805   FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"personalbell","xxx",0));
     808  FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"personalbell","xxx",0,0));
    806809  FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"personalbell"));
    807810
     
    819822  FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3));
    820823  FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize"));
    821   FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0));
     824  FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));
    822825  FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize"));
    823   FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0));
    824   FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0));
     826  FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));
     827  FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));
    825828  FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize"));
    826829
     
    833836  FAIL_UNLESS("set enum 1b", -1==owl_variable_set_int(&vd,"webbrowser",209));
    834837  FAIL_UNLESS("get enum 2b", OWL_WEBBROWSER_GALEON==owl_variable_get_int(&vd,"webbrowser"));
    835   FAIL_UNLESS("set enum 3", 0==owl_variable_set_fromstring(&vd,"webbrowser","none",0));
     838  FAIL_UNLESS("set enum 3", 0==owl_variable_set_fromstring(&vd,"webbrowser","none",0,0));
    836839  FAIL_UNLESS("get enum 4", OWL_WEBBROWSER_NONE==owl_variable_get_int(&vd,"webbrowser"));
    837   FAIL_UNLESS("set enum 5", 0==owl_variable_set_fromstring(&vd,"webbrowser","netscape",0));
     840  FAIL_UNLESS("set enum 5", 0==owl_variable_set_fromstring(&vd,"webbrowser","netscape",0,0));
    838841  FAIL_UNLESS("get enum 6", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    839   FAIL_UNLESS("set enum 7", -1==owl_variable_set_fromstring(&vd,"webbrowser","xxx",0));
    840   FAIL_UNLESS("set enum 8", -1==owl_variable_set_fromstring(&vd,"webbrowser","",0));
    841   FAIL_UNLESS("set enum 9", -1==owl_variable_set_fromstring(&vd,"webbrowser","netscapey",0));
     842  FAIL_UNLESS("set enum 7", -1==owl_variable_set_fromstring(&vd,"webbrowser","xxx",0,0));
     843  FAIL_UNLESS("set enum 8", -1==owl_variable_set_fromstring(&vd,"webbrowser","",0,0));
     844  FAIL_UNLESS("set enum 9", -1==owl_variable_set_fromstring(&vd,"webbrowser","netscapey",0,0));
    842845  FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    843846
Note: See TracChangeset for help on using the changeset viewer.