DirStr.st
changeset 3816 af3f917c7759
parent 3164 4f37ae9c8961
child 3825 262f33c41418
equal deleted inserted replaced
3815:57aff51fbbfb 3816:af3f917c7759
   115 %{
   115 %{
   116 
   116 
   117 #ifndef HAS_OPENDIR
   117 #ifndef HAS_OPENDIR
   118 # if defined(__VMS__)
   118 # if defined(__VMS__)
   119 
   119 
   120 #  define lib$find_file	LIB$FIND_FILE
   120 #  define lib$find_file LIB$FIND_FILE
   121 
   121 
   122 /*
   122 /*
   123 **  VMS readdir() routines.
   123 **  VMS readdir() routines.
   124 **  Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
   124 **  Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
   125 **  This code has no copyright.
   125 **  This code has no copyright.
   467 	d = (DIR *)__FILEVal(dirP);
   467 	d = (DIR *)__FILEVal(dirP);
   468 
   468 
   469 	__BEGIN_INTERRUPTABLE__
   469 	__BEGIN_INTERRUPTABLE__
   470 	do {
   470 	do {
   471 	    do {
   471 	    do {
   472 	        errno = 0;
   472 		errno = 0;
   473 	        dp = readdir(d);
   473 		dp = readdir(d);
   474 	        /*
   474 		/*
   475 	         * for compatibility with ST-80,
   475 		 * for compatibility with ST-80,
   476 	         * skip entries for '.' and '..'.
   476 		 * skip entries for '.' and '..'.
   477 	         * If wanted, these must be added synthetically.
   477 		 * If wanted, these must be added synthetically.
   478 	         */
   478 		 */
   479 	    } while (dp && ((strcmp(dp->d_name, ".")==0) || (strcmp(dp->d_name, "..")==0)));
   479 	    } while (dp && ((strcmp(dp->d_name, ".")==0) || (strcmp(dp->d_name, "..")==0)));
   480 	} while ((dp == NULL) && (errno == EINTR));
   480 	} while ((dp == NULL) && (errno == EINTR));
   481 	__END_INTERRUPTABLE__
   481 	__END_INTERRUPTABLE__
   482 
   482 
   483 	if (dp != NULL) {
   483 	if (dp != NULL) {
   493 #else /* no HAS_OPENDIR */
   493 #else /* no HAS_OPENDIR */
   494 # ifdef WIN32
   494 # ifdef WIN32
   495     HANDLE d;
   495     HANDLE d;
   496     WIN32_FIND_DATA data;
   496     WIN32_FIND_DATA data;
   497     OBJ dirP;
   497     OBJ dirP;
       
   498     int rslt;
   498 
   499 
   499     if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) {
   500     if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) {
   500 	__INST(lastErrorNumber) = nil;
   501 	__INST(lastErrorNumber) = nil;
   501 	d = __HANDLEVal(dirP);
   502 	d = __HANDLEVal(dirP);
   502 
   503 
   503 	if (FindNextFile(d, &data)) {
   504 #  ifdef DO_WRAP_CALLS
       
   505 	rslt = __doWrapCall2(1,(void*)FindNextFile,(void *)d, (void *)&data);
       
   506 #  else
       
   507 	rslt = FindNextFile(d, &data);
       
   508 #  endif
       
   509 	if (rslt) {
   504 	    nextEntry = __MKSTRING( data.cFileName );
   510 	    nextEntry = __MKSTRING( data.cFileName );
   505 	} else {
   511 	} else {
   506 	   __INST(hitEOF) = true;
   512 	   __INST(hitEOF) = true;
   507 	}
   513 	}
   508     }
   514     }
   597 	path = __INST(pathName);
   603 	path = __INST(pathName);
   598 	if (__isString(path)) {
   604 	if (__isString(path)) {
   599 	    int l = __stringSize(path);
   605 	    int l = __stringSize(path);
   600 
   606 
   601 	    if (l < (sizeof(pattern)-4)) {
   607 	    if (l < (sizeof(pattern)-4)) {
   602 	        strncpy(pattern, __stringVal(path), l);
   608 		strncpy(pattern, __stringVal(path), l);
   603 	        strcpy(pattern+l, "\\*");
   609 		strcpy(pattern+l, "\\*");
   604 	        d = FindFirstFile(pattern, &data);
   610 #  ifdef DO_WRAP_CALLS
   605 	        if (d == INVALID_HANDLE_VALUE) {
   611 		d = __doWrapCall2(1,(void*)FindFirstFile,(void *)pattern, (void *)&data);
       
   612 #  else
       
   613 		d = FindFirstFile(pattern, &data);
       
   614 #  endif
       
   615 		if (d == INVALID_HANDLE_VALUE) {
   606 		    __INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
   616 		    __INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
   607 	        } else {
   617 		} else {
   608 		    __INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
   618 		    __INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
   609 		    entry = __MKSTRING( data.cFileName );
   619 		    entry = __MKSTRING( data.cFileName );
   610 		    ok = true;
   620 		    ok = true;
   611 		}
   621 		}
   612 	    }
   622 	    }
   656      This query changes the readPointer of the DirectoryStream"
   666      This query changes the readPointer of the DirectoryStream"
   657 
   667 
   658     |entry|
   668     |entry|
   659 
   669 
   660     [self atEnd] whileFalse:[
   670     [self atEnd] whileFalse:[
   661         entry := self nextLine.
   671 	entry := self nextLine.
   662         entry asFilename isImplicit ifFalse:[
   672 	entry asFilename isImplicit ifFalse:[
   663             ^ false.
   673 	    ^ false.
   664         ]
   674 	]
   665     ].
   675     ].
   666     ^ true
   676     ^ true
   667 
   677 
   668 
   678 
   669     "
   679     "
   670         (DirectoryStream directoryNamed:'/') isEmpty
   680 	(DirectoryStream directoryNamed:'/') isEmpty
   671         (DirectoryStream directoryNamed:'/var/tmp') isEmpty
   681 	(DirectoryStream directoryNamed:'/var/tmp') isEmpty
   672     "
   682     "
   673 
   683 
   674     "Modified: 18.9.1997 / 18:05:31 / stefan"
   684     "Modified: 18.9.1997 / 18:05:31 / stefan"
   675 ! !
   685 ! !
   676 
   686 
   677 !DirectoryStream class methodsFor:'documentation'!
   687 !DirectoryStream class methodsFor:'documentation'!
   678 
   688 
   679 version
   689 version
   680     ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.42 1998-01-12 13:21:57 cg Exp $'
   690     ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.43 1998-09-10 11:08:03 cg Exp $'
   681 ! !
   691 ! !