home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / rsed / find.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  1.3 KB  |  60 lines

  1.  
  2. /*
  3.  * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  4.  *  You are free to modify, hack, fold, spindle, or mutlate this code in
  5.  *  any maner provided you give credit where credit is due and don't pretend
  6.  *  you wrote it.
  7.  *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  8.  *  in copyright law that you will never ever forget.
  9.  */
  10. #include "defs.h"
  11. #include "externs.h"
  12.  
  13. #define __FILE__    "find.c"
  14.  
  15. long
  16. find(c)
  17. char c;
  18. {
  19.     if (find_work == (LINE *) NULL || find_line >= NumberLines) {
  20.         puts(Eof);
  21.         reset_find();
  22.         return(-1L);
  23.     }
  24.     while (find_work != (LINE *) NULL) {
  25.         if (strindex(find_work->text, find_string) != NULL) {
  26.             CurrentLine=find_line;
  27.             if (c == 'v') printline(CurrentLine);
  28.             find_work = find_work -> next;
  29.             find_line++;
  30.             return(CurrentLine);
  31.         }
  32.         find_work = find_work -> next;
  33.         find_line++;
  34.     }
  35.     puts(Eof);
  36.     return(-1L);
  37. }
  38. reset_find()
  39. {
  40.     find_work = l_start;
  41.     find_line = 1L;
  42. }
  43. setfind(number, string)
  44. long number;
  45. char *string;
  46. {
  47.     if (find_string != NULL)
  48.         free(find_string);
  49.     find_string = malloc(strlen(string) + 1);
  50.     if (find_string == NULL) {
  51.         fprintf(stderr, "%s: malloc(%d) failed\n", __FILE__,
  52.                 strlen(string));
  53.         return(!OK);
  54.     }
  55.     strcpy(find_string, string);
  56.     find_line = number;
  57.     find_work = setline(find_line);
  58.     return(find_work != (LINE *) NULL ? OK : !OK);
  59. }
  60.