void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p) { cairo_pattern_t *pat; runPath(path, c->cr); pat = mkbrush(b); cairo_set_source(c->cr, pat); switch (p->Cap) { case uiDrawLineCapFlat: cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_BUTT); break; case uiDrawLineCapRound: cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_ROUND); break; case uiDrawLineCapSquare: cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_SQUARE); break; } switch (p->Join) { case uiDrawLineJoinMiter: cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_MITER); cairo_set_miter_limit(c->cr, p->MiterLimit); break; case uiDrawLineJoinRound: cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_ROUND); break; case uiDrawLineJoinBevel: cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_BEVEL); break; } cairo_set_line_width(c->cr, p->Thickness); cairo_set_dash(c->cr, p->Dashes, p->NumDashes, p->DashPhase); cairo_stroke(c->cr); cairo_pattern_destroy(pat); }
void uiDrawClip(uiDrawContext *c, uiDrawPath *path) { runPath(path, c->cr); switch (pathFillMode(path)) { case uiDrawFillModeWinding: cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_WINDING); break; case uiDrawFillModeAlternate: cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_EVEN_ODD); break; } cairo_clip(c->cr); }
void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b) { cairo_pattern_t *pat; runPath(path, c->cr); pat = mkbrush(b); cairo_set_source(c->cr, pat); switch (pathFillMode(path)) { case uiDrawFillModeWinding: cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_WINDING); break; case uiDrawFillModeAlternate: cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_EVEN_ODD); break; } cairo_fill(c->cr); cairo_pattern_destroy(pat); }
int main(int argc, char **argv) { while(1) //shell runs till user enters exit { char * cwd = malloc(256); //find current working directory for prompt assert(cwd != NULL); getCurrentDir(cwd); printf("\nMyShell:%s$ ", cwd); //print shell prompt free(cwd); char *consoleinput = malloc(256); assert(consoleinput != NULL); //TO DO: Change buffer size to variable readCommand(consoleinput); //accept input removeNewLineChar(consoleinput); //remove '\n' character from input removeWhiteSpaces(consoleinput); //remove all spaces before and after command if(strncmp(consoleinput, SUPPORTED_COMMANDS[1], 4) == 0) //exit { free(consoleinput); printf("\nMyShell Terminated\n"); return 0; } else if(strncmp(consoleinput, SUPPORTED_COMMANDS[0], 2) == 0) //cd { int result = runChangeDir(consoleinput); if(result!=0) { perror("cd error:"); } } else if(strncmp(consoleinput, SUPPORTED_COMMANDS[2], 4) == 0) //path { int result = runPath(consoleinput); if(result!=0) { errno = result; perror("path error:"); } } else { //handle pipes char **commands = parseArgv(consoleinput, SPECIAL_CHARS[4]); //input destoyed int numcommands = 0; while( commands[numcommands]!=NULL ) { numcommands++; } //printf("\nNumber of commands:[%d]", numcommands); const int numpipes = 2*(numcommands-1); //printf("\nNumber of pipe file descriptors:[%d]", numpipes); /*read and write ends of pipes stay apart by 3 -increment open pipe indexes by 2 after every command -close all pipes */ int pipefds[numpipes]; int i=0; for(i=0; i<numpipes;i=i+2) { pipe(pipefds+i); } //printf("\npipe() call successful"); // for(i=0;i<numpipes;i++) // { // printf("[%d]", pipefds[i]); // } int pipe_w = 1; int pipe_r = pipe_w - 3; int curcommand = 0; while(curcommand < numcommands) { //printf("\nCommand number:[%d]", curcommand); //printf("\ninside pipe loop for command [%s]", commands[curcommand]); //Parse Command and Arguments into formatneeded by execv char **argv = parseArgv(commands[curcommand], SPECIAL_CHARS[0]); //printf("\nCurrent Command:[%s]", argv[0]); if(findPath(argv) == 0) { //executeCommand(argv); int child_pid = fork(); //int child_status; if(child_pid < 0) { //errno = 3; perror("fork error:"); } else if(child_pid == 0) //fork success { if(pipe_w < numpipes) { //open write end //printf("\nWrite pipe:[%d] to stdout", pipefds[pipe_w]); if(dup2(pipefds[pipe_w], 1) < 0) { perror("pipe write-end error: "); } } if((pipe_r >= 0)&&(pipe_r < numpipes)) { //open read end //printf("\nRead pipe:[%d] to stdin", pipefds[pipe_r]); if(dup2(pipefds[pipe_r], 0) < 0) { perror("pipe read-end error: "); } } for(i=0;i<numpipes;i++) //close off all pipes { //printf("\nclosing all pipes"); close(pipefds[i]); } if(execv(argv[0], argv) == -1) { perror("Bad command or filename:"); exit(0); //TODO: child hangs here } //fflush(stdin); } } else { printf("\nBad command or filename"); //TODO: ForkBomb occuring here //exit(0); } free(argv); //printf("\nIncrementing pipe ends, moving to next command."); curcommand++; pipe_w = pipe_w + 2; pipe_r = pipe_r + 2; } //int i=0; for(i=0;i<numpipes;i++) //close off all pipes { //printf("\nclosing all pipes"); close(pipefds[i]); } int status; for(i=0;i<numcommands;i++) { wait(&status); } free(commands); } free(consoleinput); } freeList(pathlist); }