home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / STR.C < prev    next >
Text File  |  1995-02-14  |  1KB  |  47 lines

  1. /* C_str.c
  2. C code for Sather 1.0 library external class C_STR */
  3.  
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7. #ifndef __OS2__
  8. #include <sys/file.h>
  9. #endif
  10. #include <fcntl.h>
  11.  
  12. /* Open a file for reading. */
  13. int c_str_file_open(char *nm){return open(nm,O_RDONLY,0);}
  14.  
  15. /* Return the size of the file with descriptor `fd'. */
  16. int c_str_file_size(int fd){return (int)lseek(fd,0L,2);}
  17.  
  18. /* Fill in `s' with the characters of `fd' starting at `st' and
  19. going for `sz' chars. */
  20. void c_str_file_in_str(int fd, char *s, int st, int sz)
  21. {lseek(fd,st,0); read(fd,s,sz);}
  22.  
  23. /* Fill in `s' with the characters of `fd' starting at `st' and
  24. going for `sz' chars, start at an offset of `bst' in `s'. */
  25. void c_str_file_in_fstr(int fd, char *s, int st, int sz, int bst)
  26. {lseek(fd,st,0); read(fd,s+bst,sz);}
  27.  
  28. /* Close the file described by descriptor `fd'. */
  29. void c_str_file_close(int fd){close(fd);}
  30.  
  31. /* Split concatinate strings separated by '\0' into array of string in C. */
  32. char **
  33. c_str_create_astr (int size, char *s)
  34. {
  35.   char **ptr;
  36.   int i;
  37.  
  38. /*  ptr = (char **) malloc (sizeof (char *) * size);                            -- NLP */
  39.   ptr = (char **) GC_malloc(sizeof (char *) * size);                         /* -- NLP */
  40.   for (i = 0; (i < size) && (*s != 0); i++)
  41.     {
  42.       ptr[i] = s;
  43.       s = (char *) (s + strlen(s) + 1);
  44.     }
  45.   return  ptr;
  46. }
  47.