home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / util / surf / unixextr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  1.8 KB  |  106 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=0;
  54.     int ntry=0;
  55.     union wait *status;
  56.     int p;
  57.  
  58.     unlink("gledir.tmp");
  59.     p = fork();
  60.     if (p==-1) {perror("Unable to fork ls command \n"); return true;}
  61.     if (p==0) {
  62.         strcpy(buff,"ls ");
  63.         strcat(buff,wild);
  64.         strcat(buff,">gledir.tmp");
  65.         execlp("sh","sh","-c", buff,0);
  66.         exit(1);
  67.     }
  68.     waitpid(p,status,op);
  69.     wilddir = NULL;
  70. /* 
  71.     for (;ntry<20 && wilddir==NULL;ntry++) {
  72. #ifndef ultrix
  73.       usleep(100000); 
  74. #else
  75.     sleep(1);
  76. #endif 
  77.       wilddir = fopen("gledir.tmp","r");        
  78.       if (wilddir!=NULL) fclose(wilddir);
  79. #ifndef ultrix
  80.       usleep(100000);
  81. #else
  82. #endif
  83. */
  84.     wilddir = fopen("gledir.tmp","r");        
  85.     if (wilddir==NULL) {printf("Fork ls failed \n"); return true;}
  86.     if feof(wilddir) { fclose(wilddir); return true;}
  87.     fgets(buff,100,wilddir);
  88.     trimcr(buff);
  89.     ffblk->ff_name = buff;
  90.     return false;
  91. }    
  92. trimcr(char *s)
  93. {
  94.     s = strchr(s,'\n');
  95.     if (s!=NULL) *s = 0;
  96. }
  97. findnext(struct ffblk *ffblk)
  98. {
  99.     static char buff[200];
  100.     if feof(wilddir) { fclose(wilddir); return true;}
  101.     fgets(buff,100,wilddir);
  102.     trimcr(buff);
  103.     ffblk->ff_name = buff;
  104.     return false;
  105. }
  106.