home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / util / manip / unixextr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  1.6 KB  |  88 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define true (!false)
  5. #define false 0
  6. long coreleft(void)
  7. {
  8.     return 4000000l;
  9. }
  10. char *strlwr(char *s)
  11. {
  12.     char *ss=s;
  13.     while (*s!=0) {*s = tolower(*s); s++;}
  14.     return ss;
  15. }
  16. char *strupr(char *s)
  17. {
  18.     char *ss=s;
  19.     while (*s!=0) {*s = toupper(*s); s++;}
  20.     return ss;
  21. }
  22.  
  23. trim_file(char *s)
  24. {
  25.     char *t;
  26.     t = strchr(s,']');
  27.     if (t!=NULL) memcpy(s,t+1,strlen(t));
  28.     t = strchr(s,';');
  29.     if (s!=NULL) *t = 0;
  30. }
  31. char *getsymbol(char *sym)
  32. {
  33.     static char mystr[200],*s;
  34.     s = getenv(sym);
  35.     if (s==NULL) s = "";
  36.     strcpy(mystr,sym);
  37.     return mystr;    
  38. }
  39.  
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <sys/types.h>
  44. #include <sys/wait.h>
  45. #define false 0
  46. #define true (!false)
  47.  
  48. FILE *wilddir;
  49. struct ffblk {char *ff_name;};
  50. findfirst(char *wild, struct ffblk *ffblk, int zz)
  51. {
  52.     static char buff[200];
  53.     int op;
  54.     union wait *status;
  55.     int p;
  56.     p = fork();
  57.     if (p==-1) {perror("Unable to fork ls command \n"); return true;}
  58.     if (p==0) {
  59.         strcpy(buff,"ls ");
  60.         strcat(buff,wild);
  61.         strcat(buff,">gledir.tmp");
  62.         execlp("sh","sh","-c", buff,0);
  63.         exit(1);
  64.     }
  65.     waitpid(p,status,op);
  66.     wilddir = fopen("gledir.tmp","r");        
  67.     if (wilddir==NULL) {printf("Fork ls failed \n"); return true;}
  68.     if feof(wilddir) { fclose(wilddir); return true;}
  69.     fgets(buff,100,wilddir);
  70.     trimcr(buff);
  71.     ffblk->ff_name = buff;
  72.     return false;
  73. }    
  74. trimcr(char *s)
  75. {
  76.     s = strchr(s,'\n');
  77.     if (s!=NULL) *s = 0;
  78. }
  79. findnext(struct ffblk *ffblk)
  80. {
  81.     static char buff[200];
  82.     if feof(wilddir) { fclose(wilddir); return true;}
  83.     fgets(buff,100,wilddir);
  84.     trimcr(buff);
  85.     ffblk->ff_name = buff;
  86.     return false;
  87. }
  88.