Changeset 1fd0b25 for functions.c


Ignore:
Timestamp:
Aug 17, 2002, 10:31:35 AM (18 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.