Changeset 1fd0b25


Ignore:
Timestamp:
Aug 17, 2002, 10:31:35 AM (22 years ago)
Author:
James M. Kretchmar <kretch@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:
37c27cf
Parents:
8509c08
Message:
Added the 'search' command.
'/' is a keybinding for 'search'
'?' is a keybinding for 'search -r'
Fixed stristr, which was completely broken
renamed owl_fmtext_ztext_stylestrip to owl_function_ztext_styletsrip
     and put it in functions.c
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r8509c08 r1fd0b25  
    11$Id$
     2
     31.2.2
     4        Added the 'search' command.
     5        '/' is a keybinding for 'search'
     6        '?' is a keybinding for 'search -r'
     7        Fixed stristr, which was completely broken
     8        renamed owl_fmtext_ztext_stylestrip to owl_function_ztext_styletsrip
     9             and put it in functions.c
    210
    3111.2.1
  • commands.c

    rf2e36b5 r1fd0b25  
    497497              "returns the value of a variable",
    498498              "getvar <varname>", ""),
     499
     500  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
     501              "search messages for a particular string",
     502              "search [-r] [<string>]",
     503              "The search command will find messages that contain the\n"
     504              "specified string and move the cursor there.  If no string\n"
     505              "argument is supplied then the previous one is used.  By\n"
     506              "default searches are done fowards, if -r is used the search\n"
     507              "is performed backwards"),
    499508
    500509  /****************************************************************/
     
    14781487}
    14791488
     1489char *owl_command_search(int argc, char **argv, char *buff) {
     1490  int direction;
     1491  char *buffstart;
     1492
     1493  direction=OWL_DIRECTION_DOWNWARDS;
     1494  buffstart=skiptokens(buff, 1);
     1495  if (argc>1 && !strcmp(argv[1], "-r")) {
     1496    direction=OWL_DIRECTION_UPWARDS;
     1497    buffstart=skiptokens(buff, 2);
     1498  }
     1499   
     1500  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
     1501    owl_function_search_continue(direction);
     1502  } else {
     1503    owl_function_search_start(buffstart, direction);
     1504  }
     1505 
     1506  return(NULL);
     1507}
     1508
    14801509/*********************************************************************/
    14811510/************************** EDIT SPECIFIC ****************************/
  • fmtext.c

    re1c4636 r1fd0b25  
    1919  for (i=first; i<=last; i++) {
    2020    f->fmbuff[i]=(unsigned char) attr;
     21  }
     22}
     23
     24void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) {
     25  int i;
     26  for (i=first; i<=last; i++) {
     27    f->fmbuff[i]|=(unsigned char) attr;
    2128  }
    2229}
     
    332339}
    333340
    334 /* strips formatting from ztext and returns the unformatted text.
    335  * caller is responsible for freeing. */
    336 char *owl_fmtext_ztext_stylestrip(char *zt) {
    337   owl_fmtext fm;
    338   char *plaintext;
    339 
    340   owl_fmtext_init_null(&fm);
    341   owl_fmtext_append_ztext(&fm, zt);
    342   plaintext = owl_fmtext_print_plain(&fm);
    343   owl_fmtext_free(&fm);
    344   return(plaintext);
    345 }
    346 
    347341
    348342void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) {
     
    516510  memcpy(dst->colorbuff, src->colorbuff, src->textlen);
    517511}
     512
     513
     514int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) {
     515  /* highlight all instance of "string".  Return the number of
     516   * instances found.  This is case insensitive. */
     517
     518  int found, len;
     519  char *ptr1, *ptr2;
     520
     521  len=strlen(string);
     522  found=0;
     523  ptr1=f->textbuff;
     524  while (ptr1-f->textbuff <= f->textlen) {
     525    ptr2=stristr(ptr1, string);
     526    if (!ptr2) return(found);
     527
     528    found++;
     529    _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE,
     530                         ptr2 - f->textbuff,
     531                         ptr2 - f->textbuff + len - 1);
     532
     533    ptr1=ptr2+len;
     534  }
     535  return(found);
     536}
     537
     538int owl_fmtext_search(owl_fmtext *f, char *string) {
     539  /* return 1 if the string is found, 0 if not.  This is case
     540   *  insensitive */
     541
     542  if (stristr(f->textbuff, string)) return(1);
     543  return(0);
     544}
  • functions.c

    rf2e36b5 r1fd0b25  
    15971597
    15981598  if (argc<2) {
    1599     owl_function_makemsg("Wrong number of arguments to the pexec command");
     1599    owl_function_makemsg("Wrong number of arguments to the exec command");
    16001600    return NULL;
    16011601  }
     
    21822182/* TODO: implement for real */
    21832183void owl_function_show_keymap(char *name) {
    2184   owl_fmtext  fm;
     2184  owl_fmtext fm;
    21852185  owl_keymap *km;
    21862186
     
    21982198
    21992199void owl_function_help_for_command(char *cmdname) {
    2200   owl_fmtext   fm;
     2200  owl_fmtext fm;
    22012201
    22022202  owl_fmtext_init_null(&fm);
     
    22052205  owl_fmtext_free(&fm);
    22062206}
     2207
     2208void owl_function_search_start(char *string, int direction) {
     2209  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
     2210  owl_global_set_search_active(&g, string);
     2211  owl_function_search_helper(0, direction);
     2212}
     2213
     2214void owl_function_search_continue(int direction) {
     2215  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
     2216  owl_function_search_helper(1, direction);
     2217}
     2218
     2219void owl_function_search_helper(int mode, int direction) {
     2220  /* move to a message that contains the string.  If direction is
     2221   * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is
     2222   * OWL_DIRECTION_UPWARDS then search backwards.
     2223   *
     2224   * If mode==0 then it will stay on the current message if it
     2225   * contains the string.
     2226   */
     2227
     2228  owl_view *v;
     2229  int viewsize, i, curmsg, start;
     2230  owl_message *m;
     2231
     2232  v=owl_global_get_current_view(&g);
     2233  viewsize=owl_view_get_size(v);
     2234  curmsg=owl_global_get_curmsg(&g);
     2235 
     2236  if (viewsize==0) {
     2237    owl_function_makemsg("No messages present");
     2238    return;
     2239  }
     2240
     2241  if (mode==0) {
     2242    start=curmsg;
     2243  } else if (direction==OWL_DIRECTION_DOWNWARDS) {
     2244    start=curmsg+1;
     2245  } else {
     2246    start=curmsg-1;
     2247  }
     2248
     2249  /* bounds check */
     2250  if (start>=viewsize || start<0) {
     2251    owl_function_makemsg("No further matches found");
     2252    return;
     2253  }
     2254
     2255  for (i=start; i<viewsize && i>=0;) {
     2256    m=owl_view_get_element(v, i);
     2257    if (owl_message_search(m, owl_global_get_search_string(&g))) {
     2258      owl_global_set_curmsg(&g, i);
     2259      owl_function_calculate_topmsg(direction);
     2260      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     2261      if (direction==OWL_DIRECTION_DOWNWARDS) {
     2262        owl_global_set_direction_downwards(&g);
     2263      } else {
     2264        owl_global_set_direction_upwards(&g);
     2265      }
     2266      return;
     2267    }
     2268    if (direction==OWL_DIRECTION_DOWNWARDS) {
     2269      i++;
     2270    } else {
     2271      i--;
     2272    }
     2273  }
     2274  owl_function_makemsg("No matches found");
     2275}
     2276
     2277
     2278/* strips formatting from ztext and returns the unformatted text.
     2279 * caller is responsible for freeing. */
     2280char *owl_function_ztext_stylestrip(char *zt) {
     2281  owl_fmtext fm;
     2282  char *plaintext;
     2283
     2284  owl_fmtext_init_null(&fm);
     2285  owl_fmtext_append_ztext(&fm, zt);
     2286  plaintext = owl_fmtext_print_plain(&fm);
     2287  owl_fmtext_free(&fm);
     2288  return(plaintext);
     2289}
  • global.c

    re1c4636 r1fd0b25  
    5858  g->colorpairs=COLOR_PAIRS;
    5959  g->debug=OWL_DEBUG;
     60  g->searchactive=0;
     61  g->searchstring=NULL;
    6062  g->starttime=time(NULL); /* assumes we call init only a start time */
    6163  strcpy(g->buffercommand, "");
     
    593595  return(0);
    594596}
     597
     598int owl_global_is_search_active(owl_global *g) {
     599  if (g->searchactive) return(1);
     600  return(0);
     601}
     602
     603void owl_global_set_search_active(owl_global *g, char *string) {
     604  g->searchactive=1;
     605  if (g->searchstring != NULL) owl_free(g->searchstring);
     606  g->searchstring=owl_strdup(string);
     607}
     608
     609void owl_global_set_search_inactive(owl_global *g) {
     610  g->searchactive=0;
     611}
     612
     613char *owl_global_get_search_string(owl_global *g) {
     614  if (g->searchstring==NULL) return("");
     615  return(g->searchstring);
     616}
  • keys.c

    rf2e36b5 r1fd0b25  
    203203  BIND_CMD("M-n", "smartnarrow",      "narrow to a view based on the current message");
    204204  BIND_CMD("M-N", "smartnarrow -i",   "narrow to a view based on the current message, and consider instance pair");
     205
     206  BIND_CMD("/",   "start-command search ", "start a search command");
     207  BIND_CMD("?",   "start-command search -r ", "start a revrerse search command");
    205208
    206209  BIND_CMD("LEFT",   "recv:shiftleft", "");
  • message.c

    re50cd56 r1fd0b25  
    460460    owl_fmtext_colorize(&b, color);
    461461  }
     462
     463  if (owl_global_is_search_active(&g)) {
     464    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
     465  }
     466     
    462467  owl_fmtext_curs_waddstr(&b, win);
    463468
     
    626631}
    627632                                       
     633int owl_message_search(owl_message *m, char *string) {
     634  /* return 1 if the message contains "string", 0 otherwise.  This is
     635   * case insensitive because the functions it uses are */
     636
     637  return (owl_fmtext_search(&(m->fmtext), string));
     638}
  • owl.h

    r8509c08 r1fd0b25  
    1212static const char owl_h_fileIdent[] = "$Id$";
    1313
    14 #define OWL_VERSION         1.2.1
    15 #define OWL_VERSION_STRING "1.2.1"
     14#define OWL_VERSION         1.2.2
     15#define OWL_VERSION_STRING "1.2.2"
    1616
    1717#define OWL_DEBUG 0
     
    384384  int hascolors;
    385385  int colorpairs;
     386  int searchactive;
     387  char *searchstring;
    386388  owl_filterelement fe_true;
    387389  owl_filterelement fe_false;
  • perlglue.xs

    re1c4636 r1fd0b25  
    99extern void owl_free(void *);
    1010extern int owl_zwrite_create_and_send_from_line(char *, char *);
    11 extern char *owl_fmtext_ztext_stylestrip(char *);
     11extern char *owl_function_ztext_stylestrip(char *);
    1212
    1313MODULE = owl            PACKAGE = owl           
     
    4141                char *rv = NULL;
    4242        CODE:
    43                 rv = owl_fmtext_ztext_stylestrip(ztext);
     43                rv = owl_function_ztext_stylestrip(ztext);
    4444                RETVAL = rv;
    4545        OUTPUT:
  • util.c

    re50cd56 r1fd0b25  
    294294  downstr(y);
    295295  ret=strstr(x, y);
     296  if (ret==NULL) {
     297    owl_free(x);
     298    owl_free(y);
     299    return(NULL);
     300  }
     301  ret=ret-x+a;
    296302  owl_free(x);
    297303  owl_free(y);
     
    337343  int i;
    338344  for (i=0; s[i]; i++) {
    339     if (!isspace(s[i])) return(0);
     345    if (!isspace((int) s[i])) return(0);
    340346  }
    341347  return(1);
Note: See TracChangeset for help on using the changeset viewer.