Пример #1
0
int processFileInCommand(int i)
{
	char *argv[5];
	char *commandName;
	int j;
	for(j=0;j<i;j++){
		argv[j] = command.argv[j];
	}
	argv[j] = NULL;
	commandName = lookupPath(argv, pathv);

	int pid, status;
	fflush(stdout);

	switch((pid = fork())){
		case -1:
			perror("fork");
			break;
		case 0:
			executeFileInCommand(commandName, argv, command.argv[i+1]);
			break;
		default:
			pid = wait(&status);
			return 0;
	}
	return 0;
}
Пример #2
0
OSErr makeFSSpec(char *pathString, int pathStringLength,FSSpec *spec)
{	
    CFURLRef    sillyThing;
    CFStringRef tmpStrRef;
	CFMutableStringRef filePath;
    FSRef	theFSRef;
    OSErr	err;
    
    tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) pathString,
										pathStringLength, gCurrentVMEncoding, true);
    if (tmpStrRef == nil)
        return -1000;
	filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef);
	if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
		CFStringNormalize(filePath, kCFStringNormalizationFormD);
    sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
	if (sillyThing == NULL) 
		return -2000;
		
    if (CFURLGetFSRef(sillyThing,&theFSRef) == false) {
        // name contains multiple aliases or does not exist, so fallback to lookupPath
        CFRelease(filePath);
        CFRelease(sillyThing);
        return lookupPath(pathString,pathStringLength,spec,true,true);
    } 
            
    CFRelease(filePath);
    err = FSGetCatalogInfo (&theFSRef,kFSCatInfoNone,nil,nil,spec,nil);
    CFRelease(sillyThing);
    return err;
}
Пример #3
0
int main(int argc, char *argv[]) {
	int i;
	int pid, numChildren;
	int status;
	FILE *fid;
	char cmdLine[MAX_LINE_LEN]; 
	struct command_t command;

	char *pathv[] = (char *) malloc(MAX_LINE_LEN);
	parsePath(pathv); /* Get directory paths from PATH */

	/* Read the command line parameters */ 
	if ( argc != 2) {
		fprintf(stderr, "Usage: launch <launch_set_filename>\n");
		exit (0);
	}

	/* Open a file that contains a set of commands */ 
	fid = fopen(argv[1], "r");

	/* Process each command in the launch file */ 
	numChildren = 0;
	
	while(fgets(cmdLine, MAX_LINE_LEN, fid) != NULL) {
		parseCommand(cmdLine, &command); 
		command.argv[command.argc] = NULL;

		/* Create a child process to execute the command */ 
		if((pid = fork()) == 0) {
			/* Child executing command */ 
			//execvp(command.name, command.argv); // must use execv instead
			if(command.name[0] == '/') {
				execv(command.name, command.argv);
			} else {
				execv(lookupPath(*pathv, command.argv), command.argv);
			}
		}

		/* Parent continuing to the next command in the file */ 
		numChildren++;
	}

	printf("\n\nlaunch: Launched %d commands\n", numChildren);

	/* Terminate after all children have terminated */ 
	for(i = 0; i < numChildren; i++) {
		wait(&status);
		/* Should free dynamic storage in command data structure */
	}

	printf("\n\nlaunch: Terminating successfully\n"); 
	return 0;
}
Пример #4
0
int processFileOutCommand(int i)
{
	char *argv[5];
	char *commandName;
	int j;
	for(j=0; j<i; j++){
		argv[j] = command.argv[j];
	}
	argv[j] = NULL;
	commandName = lookupPath(argv, pathv);
	return executeFileOutCommand(commandName, argv, command.argv[i+1]);
}
Пример #5
0
static JSchemaResolutionResult simpleResolver(JSchemaResolverRef resolver, jschema_ref *resolved)
{
	QString resourceName = QString::fromUtf8(resolver->m_resourceToResolve.m_str, resolver->m_resourceToResolve.m_len);
	QFileInfo lookupPath(resolutionDir, resourceName + ".schema");
	if (!lookupPath.isFile() || !lookupPath.isReadable()) {
		qWarning() << "Failed to resolve" << resourceName << ".  Resolved path" << lookupPath.absoluteFilePath() << " isn't a file";
		return SCHEMA_NOT_FOUND;
	}

	QFile resourceData(lookupPath.absoluteFilePath());
	if (!resourceData.open(QIODevice::ReadOnly)) {
		qWarning() << "Failed to open" << resourceName << "(" << lookupPath.absoluteFilePath() << ")";
		return SCHEMA_IO_ERROR;
	}

	raw_buffer readSchema;
	if (resourceData.size() > std::numeric_limits<typeof(readSchema.m_len)>::max()) {
		qWarning() << "Schema" << lookupPath.absoluteFilePath() << "is too big";
		return SCHEMA_GENERIC_ERROR;
	}

	readSchema.m_len = resourceData.size();
	readSchema.m_str = new char[readSchema.m_len];

	QDataStream schemaReader(&resourceData);
	if (!readSchema.m_len == schemaReader.readRawData((char *)readSchema.m_str, readSchema.m_len)) {
		qWarning() << "Failed to read schema" << resourceName << "fully";
		delete [] readSchema.m_str;
		return SCHEMA_IO_ERROR;
	}

	*resolved = jschema_parse(readSchema, DOMOPT_NOOPT, NULL);
	delete [] readSchema.m_str;
	if (*resolved == NULL)
		return SCHEMA_INVALID;

	qDebug() << "Resolved reference for" << resourceName;
	return SCHEMA_RESOLVED;
}
Пример #6
0
int main(int argc, char **argv)
{
	int i;
	int debug = 0;

	parsePath(pathv);
	welcomeMessage();

	//main loop
	while(1){
			printPrompt();
			commandInput = getchar();
			if(commandInput == '\n'){
				continue;
			}else{
				readCommand(commandLine, &commandInput);
				if((strcmp(commandLine, "exit") == 0) || \
						(strcmp(commandLine, "quit") == 0))
					break;

				parseCommand(commandLine, &command);
				if(checkInternalCommand() == 0){
					command.name = lookupPath(command.argv, pathv);
					
					if(command.name == NULL){
						printf("Stub: error\n");
						continue;
					}

					processCommand();
				}
			}
	}

	printf("\n");
	return 0;
}
Пример #7
0
int processPipedCommand(int i)
{
	char *argvA[5];
	char *argvB[5];
	char *nameA, *nameB;

	int ii;
	for(ii = 0; ii < i; ii++){
		argvA[ii] = command.argv[ii];
	}
	argvA[ii] == NULL;
	nameA = lookupPath(argvA, pathv);

	int j, jj = 0;
	for(j=i+1; j<command.argc; j++){
		argvB[jj] = command.argv[j];
		jj++;
	}
	argvB[jj] = NULL;

	int pid, status;
	fflush(stdout);

	switch((pid = fork())){
		case -1:
			perror("fork");
		case 0:
			//child
			executePipedCommand(argvA, argvB, nameA, nameB);
			break;
		default:
			pid = wait(&status);
			return 0;
	}
	return 1;
}
int dir_Lookup(char *pathString, int pathStringLength, int index,
  /* outputs: */
  char *name, int *nameLength, int *creationDate, int *modificationDate,
  int *isDirectory, squeakFileOffsetType *sizeIfFile) {
	/* Lookup the index-th entry of the directory with the given path, starting
	   at the root of the file system. Set the name, name length, creation date,
	   creation time, directory flag, and file size (if the entry is a file).
	   Return:	0 	if a entry is found at the given index
	   			1	if the directory has fewer than index entries
	   			2	if the given path has bad syntax or does not reach a directory
	*/

	int okay;
	HVolumeParam volumeParams;
    FSSpec      spec;
    long        parentDirectory;
    OSErr       err;
    Str255      longFileName;
    
	/* default return values */
	*name             = 0;
	*nameLength       = 0;
	*creationDate     = 0;
	*modificationDate = 0;
	*isDirectory      = false;
	*sizeIfFile       = 0;

	if ((pathStringLength == 0)) {
		/* get volume info */
		volumeParams.ioNamePtr = (unsigned char *) name;
		volumeParams.ioVRefNum = 0;
		volumeParams.ioVolIndex = index;
		okay = PBHGetVInfoSync((HParmBlkPtr) &volumeParams) == noErr;
		if (okay) {
			CopyPascalStringToC((ConstStr255Param) name,name);
			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(volumeParams.ioVCrDate);
			*modificationDate = convertToSqueakTime(volumeParams.ioVLsMod);
			*isDirectory      = true;
			*sizeIfFile       = 0;
			return ENTRY_FOUND;
		} else {
			return NO_MORE_ENTRIES;
		}
	} else {
		/* get file or directory info */
		if (!equalsLastPath(pathString, pathStringLength)) {
 			/* lookup and cache the refNum for this path */
			err = lookupPath(pathString, pathStringLength, &spec,false,true);
 			if (err == noErr) 
				recordPath(pathString, pathStringLength, &spec);
			else 
				return BAD_PATH;
		}
	    spec = lastSpec;
				*sizeIfFile   = 0;
		okay = fetchFileInfo(index,&spec,(unsigned char *) name,true,&parentDirectory,isDirectory,creationDate,modificationDate,sizeIfFile,&longFileName);
		if (okay == noErr) {
			CopyPascalStringToC((ConstStr255Param) longFileName,name);
			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(*creationDate);
			*modificationDate = convertToSqueakTime(*modificationDate);
			return ENTRY_FOUND;
		} else
			return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH;
	}
}
int dir_Lookup(char *pathString, int pathStringLength, int index,
  /* outputs: */
  char *name, int *nameLength, int *creationDate, int *modificationDate,
  int *isDirectory, squeakFileOffsetType *sizeIfFile) {
	/* Lookup the index-th entry of the directory with the given path, starting
	   at the root of the file system. Set the name, name length, creation date,
	   creation time, directory flag, and file size (if the entry is a file).
	   Return:	0 	if a entry is found at the given index
	   			1	if the directory has fewer than index entries
	   			2	if the given path has bad syntax or does not reach a directory
	*/

	int okay;
    FSSpec      spec;
    long        parentDirectory;
    OSErr       err;
    Str255      longFileName;
		FSVolumeInfoParam fsVolumeParam;
		HFSUniStr255 uniStr;
		FSVolumeInfo volumeInfo;
    
	/* default return values */
	*name             = 0;
	*nameLength       = 0;
	*creationDate     = 0;
	*modificationDate = 0;
	*isDirectory      = false;
	*sizeIfFile       = 0;

	if ((pathStringLength == 0)) {
		/* get volume info */
		fsVolumeParam.volumeName = &uniStr;
		fsVolumeParam.ioVRefNum = kFSInvalidVolumeRefNum;
		fsVolumeParam.volumeIndex = index;
		fsVolumeParam.whichInfo = 0;
		fsVolumeParam.volumeInfo = &volumeInfo;
		fsVolumeParam.ref = NULL;
		fsVolumeParam.whichInfo = kFSVolInfoCreateDate + kFSVolInfoModDate; 
		okay = PBGetVolumeInfoSync( &fsVolumeParam) == noErr;
/*
		FSGetVolumeInfo (kFSInvalidVolumeRefNum,
			index,
			NULL,
			)
*/
		if (okay) {
			CFStringRef strRef = CFStringCreateWithCharacters( kCFAllocatorDefault, uniStr.unicode, uniStr.length );
			CFMutableStringRef mStr = CFStringCreateMutableCopy(NULL, 0, strRef);
			// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined
			Boolean result = CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); // buffer size is to see primitiveDirectoryLookup
			CFRelease(strRef);
			CFRelease(mStr);
			if (result == true) {
				// strncpy(name, &(uniStr.unicode), uniStr.length);
				// *nameLength       = uniStr.length;
				*nameLength       = strlen(name);
				{	
					LocalDateTime local;
					
					ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->createDate,&local);
					*creationDate     = convertToSqueakTime(local.lowSeconds);
				}
				{	
					LocalDateTime local;
					
					ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->modifyDate,&local);
					*modificationDate     = convertToSqueakTime(local.lowSeconds);
				}
				*isDirectory      = true;
				*sizeIfFile       = 0;
				return ENTRY_FOUND;
			} else {
				return NO_MORE_ENTRIES;
			}
		} else {
			return NO_MORE_ENTRIES;
		}
	} else {
		/* get file or directory info */
		if (!equalsLastPath(pathString, pathStringLength)) {
 			/* lookup and cache the refNum for this path */
			err = lookupPath(pathString, pathStringLength, &spec,false,true);
 			if (err == noErr) 
				recordPath(pathString, pathStringLength, &spec);
			else 
				return BAD_PATH;
		}
	    spec = lastSpec;
		*sizeIfFile   = 0;
		okay = fetchFileInfo(index,&spec,(unsigned char *) name,true,
							&parentDirectory,isDirectory,creationDate,
							modificationDate,sizeIfFile,&longFileName);
		if (okay == noErr) {
			CFStringRef cfs= CFStringCreateWithPascalString(NULL, longFileName, gCurrentVMEncoding);
			CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, cfs);
			CFRelease(cfs);
			// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined
			CFStringGetCString(mStr, name, 256, gCurrentVMEncoding);
			CFRelease(mStr);

			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(*creationDate);
			*modificationDate = convertToSqueakTime(*modificationDate);
			return ENTRY_FOUND;
		} else
			return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH;
	}
}
Пример #10
0
OSErr __path2fss(const char * pathName, FSSpecPtr spec) {
    return lookupPath((char *) pathName, strlen(pathName),spec,true,true);
}
Пример #11
0
sqInt	ioFilenamefromStringofLengthresolveAliases(char* dst, char* src, sqInt num, sqInt resolveAlias) {
        FSRef		theFSRef;
        FSSpec		convertFileNameSpec,failureRetry;
        OSErr		err;
        Boolean		isFolder=false,isAlias=false;
        CFURLRef 	sillyThing,appendedSillyThing;
        CFStringRef 	lastPartOfPath,filePath2;
		CFMutableStringRef filePath;
        
        *dst = 0x00;
        err = quicklyMakePath((char *) src,num,dst,resolveAlias);
        if (err == noErr) 
            return;
            
        err = lookupPath((char *) src,num,&convertFileNameSpec,true,false);
        if ((err == noErr) && resolveAlias) {
            err = ResolveAliasFile(&convertFileNameSpec,true,&isFolder,&isAlias);
            if (err == fnfErr) {
				err = lookupPath((char *) src,num,&convertFileNameSpec,false,false);
	            err = ResolveAliasFile(&convertFileNameSpec,true,&isFolder,&isAlias);
            }
        }
        
        if (err == fnfErr) {
            failureRetry = convertFileNameSpec;
            CopyCStringToPascal("::",failureRetry.name);
            err = FSpMakeFSRef(&failureRetry,&theFSRef);
            if (err != noErr) 
                return;
//            filePath   = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false);
			CFStringRef tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false);
            if (tmpStrRef == nil) 
                return;
			filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef);
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(filePath, kCFStringNormalizationFormKD); // canonical decomposition

            sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
            CFRelease(filePath);
			if (sillyThing == NULL) 
					return;

            lastPartOfPath = CFURLCopyLastPathComponent(sillyThing);
            CFRelease(sillyThing);
            sillyThing = CFURLCreateFromFSRef(kCFAllocatorDefault,&theFSRef);
            appendedSillyThing = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,sillyThing,lastPartOfPath,false);
#if defined(__MWERKS__) && !defined(__APPLE__) && !defined(__MACH__)
            filePath2 = CFURLCopyFileSystemPath (appendedSillyThing, kCFURLHFSPathStyle);
#else
            filePath2 = CFURLCopyFileSystemPath (appendedSillyThing, kCFURLPOSIXPathStyle);
#endif
            CFStringGetCString (filePath2,dst,1000, gCurrentVMEncoding);
            CFRelease(sillyThing);
            CFRelease(appendedSillyThing);
            CFRelease(lastPartOfPath);
            CFRelease(filePath2);        
            return; 
        }
        	
        err = FSpMakeFSRef(&convertFileNameSpec,&theFSRef);
#if defined(__MWERKS__) && !defined(__APPLE__) && !defined(__MACH__)
		sillyThing = CFURLCreateFromFSRef(kCFAllocatorDefault,&theFSRef);
        filePath = CFURLCopyFileSystemPath (sillyThing, kCFURLHFSPathStyle);
        CFStringGetCString (filePath,dst,1000, gCurrentVMEncoding);
		CFRelease(sillyThing);
        CFRelease(filePath);        
        return;
 #else
        err = FSRefMakePath(&theFSRef,(UInt8 *)dst,1000); 
 #endif
}