home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / rsed / stuff.c < prev   
Encoding:
C/C++ Source or Header  |  1989-02-03  |  1.7 KB  |  91 lines

  1. /*
  2.  * This code copyright 1988 by Doug Davis (doug@letni.lawnet.com) 
  3.  *  You are free to modify, hack, fold, spindle, or mutlate this code in
  4.  *  any maner provided you give credit where credit is due and don't pretend
  5.  *  you wrote it.
  6.  *  If you do my lawyers (and I have a lot of lawyers) will teach you a lesson
  7.  *  in copyright law that you will never ever forget.
  8.  */
  9. #include "defs.h"    /* just for the #define of a NULL */
  10. #include "externs.h" /* for the strings things. */
  11.  
  12. /* append  s2 unto s1, returning a pointer to the new "end" of s1 */
  13. char *
  14. strappend(s1, s2)
  15. char *s1, *s2;
  16. {
  17.     register char *p, *r;
  18.     p = s1;
  19.     r = s2;
  20.     do {
  21.         *(p++) = *r;
  22.     } while ( *(r++) != '\0');
  23.     p--;
  24.     return(p);
  25. }
  26. /* return a pointer to the first occurence of s2 in s1 otherwise NULL */
  27. char *
  28. strindex(s1, s2)
  29. char *s1, *s2;
  30. {
  31.     register char *p, *s;
  32.     register int len;
  33.     p=s1;
  34.     len = strlen(s2);
  35.     /* quick test to blow away short lines */
  36.     if (len > strlen(s1))
  37.         return(NULL);
  38.     while ((s=STRCHR(p, *s2)) != NULL) {
  39.         if (!strncmp(s, s2, len))  {
  40.             return(s);
  41.         }
  42.         p= (++s);
  43.     }
  44.     return(NULL);
  45. }
  46. long
  47. makenum(buf)
  48. char *buf;
  49. {
  50.     switch (*buf) {
  51.         case '\0':
  52.             return(-1L);
  53.         break;
  54.         case '$':
  55.             return(NumberLines);
  56.         break;
  57.         case '^':
  58.             return(1L);
  59.         break;
  60.         case '0':
  61.         case '1':
  62.         case '2':
  63.         case '3':
  64.         case '4':
  65.         case '5':
  66.         case '6':
  67.         case '7':
  68.         case '8':
  69.         case '9':
  70.             return(atol(buf) > 1L ? atol(buf) : 1L);
  71.         break;
  72.         default:
  73.             return(-1L);
  74.     }
  75.     return(-1L);
  76. }
  77. help()
  78. {
  79.     register int input, amount;
  80.     if ((input = open (HelpName, O_RDONLY)) < 0) {
  81.         fprintf(stderr, "%s: Could not open file \"%s\"",
  82.             Progname, HelpName);
  83.         perror("");
  84.         return(!OK);
  85.     }
  86.     while((amount=read(input, buf, BUFSIZ)) > 0)
  87.         write(1, buf, amount);
  88.     close(input);
  89.     return(OK);
  90. }
  91.