Beispiel #1
0
std::string TextReader::readTextLine()
{
	/*
	auto delim = data.find('\n', pos);
    std::string ret(data.substr(pos, delim))
    pos = (delim == std::string::npos) ? data.size() : delim + 1;
    if(!ret.empty() && (ret.back() == '\r')){
      ret.pop_back();
    }
    return std::move(ret);
  }
	*/

	if (checkEOF())
	{
		//std::cout << "EOF-1!" << std::endl;
		index = textBytes.size();
		return std::string();
	}

	auto begin = &this->textBytes[this->index];
	if (auto end = strpbrk(begin, "\n\r")) 
	{
		auto length = end - begin;

		this->index += length;

		if (checkEOF())
		{
			//std::cout << "EOF-1!" << std::endl;
			index = textBytes.size();
			return std::string();
		}

		while (this->textBytes.at(this->index) == '\r' || this->textBytes.at(this->index) == '\n')
		{
			++this->index;
		}

		return std::string(begin, end);
	}

	//std::cout << "EOF-2!" << std::endl;
	index = textBytes.size();
	return std::string();
}
Beispiel #2
0
static int
tiffcmp(TIFF* tif1, TIFF* tif2)
{
    uint16 config1, config2;
    tsize_t size1;
    uint32 s, row;
    unsigned char *buf1, *buf2;

    if (!CheckShortTag(tif1, tif2, TIFFTAG_BITSPERSAMPLE, "BitsPerSample"))
        return (0);
    if (!CheckShortTag(tif1, tif2, TIFFTAG_SAMPLESPERPIXEL, "SamplesPerPixel"))
        return (0);
    if (!CheckLongTag(tif1, tif2, TIFFTAG_IMAGEWIDTH, "ImageWidth"))
        return (0);
    if (!cmptags(tif1, tif2))
        return (1);
    (void) TIFFGetField(tif1, TIFFTAG_BITSPERSAMPLE, &bitspersample);
    (void) TIFFGetField(tif1, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
    (void) TIFFGetField(tif1, TIFFTAG_IMAGEWIDTH, &imagewidth);
    (void) TIFFGetField(tif1, TIFFTAG_IMAGELENGTH, &imagelength);
    (void) TIFFGetField(tif1, TIFFTAG_PLANARCONFIG, &config1);
    (void) TIFFGetField(tif2, TIFFTAG_PLANARCONFIG, &config2);
    buf1 = (unsigned char *)_TIFFmalloc(size1 = TIFFScanlineSize(tif1));
    buf2 = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif2));
    if (buf1 == NULL || buf2 == NULL) {
        fprintf(stderr, "No space for scanline buffers\n");
        exit(-1);
    }
    if (config1 != config2 && bitspersample != 8 && samplesperpixel > 1) {
        fprintf(stderr,
                "Can't handle different planar configuration w/ different bits/sample\n");
        goto bad;
    }
#define	pack(a,b)	((a)<<8)|(b)
    switch (pack(config1, config2)) {
    case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG):
        for (row = 0; row < imagelength; row++) {
            if (TIFFReadScanline(tif2, buf2, row, 0) < 0)
                checkEOF(tif2, row, -1)
                for (s = 0; s < samplesperpixel; s++) {
                    if (TIFFReadScanline(tif1, buf1, row, s) < 0)
                        checkEOF(tif1, row, s)
                        SeparateCompare(1, s, row, buf2, buf1);
                }
        }
        break;
    case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE):
        for (row = 0; row < imagelength; row++) {
            if (TIFFReadScanline(tif1, buf1, row, 0) < 0)
                checkEOF(tif1, row, -1)
                for (s = 0; s < samplesperpixel; s++) {
                    if (TIFFReadScanline(tif2, buf2, row, s) < 0)
                        checkEOF(tif2, row, s)
                        SeparateCompare(0, s, row, buf1, buf2);
                }
        }
        break;
    case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE):
        for (s = 0; s < samplesperpixel; s++)
            for (row = 0; row < imagelength; row++) {
                if (TIFFReadScanline(tif1, buf1, row, s) < 0)
                    checkEOF(tif1, row, s)
                    if (TIFFReadScanline(tif2, buf2, row, s) < 0)
                        checkEOF(tif2, row, s)
                        ContigCompare(s, row, buf1, buf2, size1);
            }
        break;
    case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG):
        for (row = 0; row < imagelength; row++) {
            if (TIFFReadScanline(tif1, buf1, row, 0) < 0)
                checkEOF(tif1, row, -1)
                if (TIFFReadScanline(tif2, buf2, row, 0) < 0)
                    checkEOF(tif2, row, -1)
                    ContigCompare(-1, row, buf1, buf2, size1);
        }
        break;
    }
    if (buf1) _TIFFfree(buf1);
    if (buf2) _TIFFfree(buf2);
    return (1);
bad:
    if (stopondiff)
        exit(1);
    if (buf1) _TIFFfree(buf1);
    if (buf2) _TIFFfree(buf2);
    return (0);
}
Beispiel #3
0
int main(int argc, char *argv[]) 
{
	
		char *line;
		char *prompt = "myshell>";
		char *envPrompt = "DASH_PROMPT";
		char *args[2048];
		char *str;
		char *multiCmd[2048];
				
		int i=0;
		int flag;
	        int jobid;
		int code;
		int fd1,fd2;	
					
		tcpid = getpgrp();
		
		ObjectPtr myObj;
		NodePtr node;

		lst = createList(getKey,toString,freeObject);  // Creating a List
			
		prompt = getenv(envPrompt);

		if(prompt == NULL)
			prompt = "myshell>";
		
		using_history();

		if(signal(SIGINT,signalHandling) == SIG_ERR){}
		
		if(signal(SIGTSTP,signalHandling) == SIG_ERR){}

		if(signal(SIGTTOU,SIG_IGN)==SIG_ERR){}
		if(signal(SIGCHLD,SIG_DFL)==SIG_ERR){}

		if((argc == 2) && (strcmp(argv[1],"-v")==0))
		{
			printf("%s\n",svn_version());
			exit(0);
		}
			
		code = sigsetjmp(env,TRUE);
				
		while ((line=readline(prompt))) 		// Reading Input
		{
			if(line==NULL)
			{	
				printf("\n read line failed \n");
				continue;
			}
			
		      	add_history(line);
 
			str = (char *)mymalloc(sizeof(char)*(strlen(line)+1));
			strcpy(str,line);
											
			if(str[0] == '&' || str[0] == ';')
			{
				printf("dash: syntax error near unexpected token %c \n",str[0]);
				freeVar(line,str,args);
				continue;
			}
			
			while((pid = waitpid(-1,NULL,WNOHANG)) > 0)
			{
				node = search(lst,pid);
				((ObjectPtr)(node->obj))->jobStatus = 0;
				printf("%s\n",(*toString)(node->obj));
				removeNode(lst,node);
			}
			
						
			if(checkMultiCmd(str, multiCmd)== -1)
				continue;
			
			while(multiCmd[i])			
			{
				flag = searchAmp(multiCmd[i]);	// Function to check if there is an '&' in the Command
				struct IORedirect *ior = tokenize(multiCmd[i],args);
				if((int)ior == -1)
				break;		       // Parsing the Command that needs to be executed
				
				if(exitLogout(multiCmd[i]))	// Function to check Exit and Logout Commands
				{
					if(checkStoppedJobs())
					{
						//memset(multiCmd,0,sizeof(multiCmd));
						break;
					}
					else
					{
						freeVar(line,str,args);
						freeList(lst);
						memset(multiCmd,'\0',sizeof(multiCmd));
						myfree(ior);
						exit(0);
					}
				}
				if(checkEOF(multiCmd[i]))			// Function to check EOF
				{
					freeVar(line,str,args);
					memset(multiCmd,'\0',sizeof(multiCmd));	
					freeList(lst);
					myfree(ior);
					exit(0);
				}
				if(checkEmptyCmd(multiCmd[i]))		// Function to Check if Enter Key is pressed
				break;
			
			
				if((strcmp(args[0],"cd")==0) && (flag == FALSE))  // Function to check if 'cd' command is used
				{
					chgDir(args);
					break;
				}
			
				if((strcmp(args[0],"jobs")==0) && (flag == FALSE)) // Function to check if 'jobs' command is used
				{
					jobsCmd();
					break;
				}
			
				if(strcmp(args[0],"history")==0)
        		        {
                     	        	printHistory(args, str, flag);
	                                break;
       			        }
	
				if((strcmp(args[0],"bg") == 0) && (flag == FALSE))
				{
					bgCmd(args);
					break;
				}
					
				if((strcmp(args[0],"fg")==0) && (flag == FALSE))
				{
					fgCmd(args);
					break;
				}
			
				if(ampCount(multiCmd[i]))
				{
					printf(" dash: syntax error near unexpected token '&' \n");
					break;
				}
				if ( (pid = fork()) < 0)		// Forking a Process
				err_sys("fork error");
					
				else if (pid == 0) 
				{		
					struct stat buf;
					/* child */
    				     	if(flag == TRUE)
					{
						if(setpgid(0,0)!=0)
						perror("setpid() error");
					
						if(tcsetpgrp(0,tcpid)!=0)
						perror("tcsetpgrp() error");
					}
				
					if(ior->input != NULL)
					{
					
						if((fd1 = stat(ior->input,&buf))==-1){
                	                        printf("dash: %s file does not exist\n",ior->input);
                       			        break;
                                        	}

                                        	if((fd1= access(ior->input,R_OK))==-1){
                                   	        printf("dash: %s permission denied\n",ior->input);
                                        	break;
                                        	}
		                                if((fd1 = open(ior->input,O_RDONLY))==-1){
                		                printf("dash: %s inpRedirect opening failed\n",ior->input);
                                	        break;
                               		        }
                                      		else {
							close(0);
					 		dup(fd1);
						}
					}
	
					if(ior->output != NULL)				
					{
						/*if((fd1= access(ior->output,W_OK))==-1){
                        	                printf("dash: %s permission denied",ior->output);
                                	        break;}*/
                                        	if((fd2=open(ior->output,O_WRONLY|O_TRUNC|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH ))==-1){
                                        	printf("dash: %s outRedirect opening failed\n",ior->output);
                                       		break;}
                                       		else{
							close(1);
							dup(fd2);
						}
					}
					if (setpgid(0,0) != 0)
       		         		perror("setpgid() error");

			                if (tcsetpgrp(0, getpid()) != 0)
                			perror("tcsetpgrp() error");
					
					execvp(args[0],args);
					err_ret("couldn't execute: %s", line);
					exit(127);
				}
				if(flag == TRUE && (*args[0] !='\0'))
				{
					jobid = assignJobId();
					myObj = createObject(pid,multiCmd[i],jobid,1); 
					node = createNode(myObj);
					addAtRear(lst,node);
				
					printf("[%d] %d %s &\n",((ObjectPtr)(node->obj))->jobId, ((ObjectPtr)(node->obj))->key, ((ObjectPtr)(node->obj))->data);
					
					if ( (pid = waitpid(pid, &status, WNOHANG)) < 0)
					err_sys("waitpid error");
					if((tcsetpgrp(0,tcpid))!=0)
					perror("tcsetgroup error");
				
				}
				else
				{
				
					if ( (pid = waitpid(pid, &status, 0|WUNTRACED)) < 0)
					err_sys("waitpid error");
					if((tcsetpgrp(0,tcpid))!=0)
					perror("tcsetgroup error");
					if(WIFSTOPPED(status))
					{
						jobid = assignJobId();
                				myObj = createObject(pid,line,jobid,2);
                				node = createNode(myObj);
                				addAtRear(lst,node);
                				printf("%s\n",(*toString)(node->obj));
					}
			
				}
			i++;
			}
			freeVar(line,str,args);
			memset(multiCmd,'\0',sizeof(multiCmd));
			i=0;
		}
		freeList(lst);
		exit(0);
	}