void scroller::draw_first(image *screen) { if (sx >= t) sx = t - 1; draw(0, screen); screen->widget_bar(b1x(), b1y(), b1x() + bw() - 1, b1y() + bh() - 1, wm->bright_color(), wm->medium_color(), wm->dark_color()); screen->widget_bar(b2x(), b2y(), b2x() + bw() - 1, b2y() + bh() - 1, wm->bright_color(), wm->medium_color(), wm->dark_color()); show_icon(screen, b1x() + 2, b1y() + 2, bw() - 4, bh() - 4, b1()); show_icon(screen, b2x() + 2, b2y() + 2, bw() - 4, bh() - 4, b2()); int x1, y1, x2, y2; dragger_area(x1, y1, x2, y2); screen->bar(x1, y1, x2, y2, wm->black()); screen->bar(x1 + 1, y1 + 1, x2 - 1, y2 - 1, wm->medium_color()); draw_widget(screen, 0); scroll_event(sx, screen); }
char *URL_escape(const char *url) { char *escaped = 0; if (url) { char *p; int i, n; for (n = i = 0; url[i]; i++) if (urlunsafe[(unsigned char)(url[i])]) n += 2; p = escaped = ALLOC(i + n + 1); for (; *url; url++, p++) { if (urlunsafe[(unsigned char)(*p = *url)]) p = b2x(*url, p); } *p = 0; } return escaped; }
/*Main Method */ void main(int argc, char*argv[]){ int addition = 0; int subtraction = 0; int mult = 0; char * firstArg; char * secArg; char * firstForm; char * secForm; int negFirst = 0; int negSec = 0; int firstFinal = 0; int secFinal = 0; char * firstBin; char * secBin; /*check arguments*/ if (argc != 5){ fprintf(stderr, "Argc is off---should be 5\n"); return; } /*Check for addition and subtraction*/ char sign = *argv[1]; switch (sign){ case '+': addition = 1; break; case '-': subtraction = 1; break; case '*': mult = 1; break; default: fprintf(stderr, "Only addition, subtraction and multiplication allowed\n"); } firstArg = argv[2]; secArg = argv[3]; firstForm = firstArg; secForm = secArg; /*check for negatives*/ if(firstArg[0] == '-'){ negFirst = 1; firstForm+=1; } if(secArg[0] == '-'){ negSec = 1; secForm+=1; } switch(firstForm[0]) { case 'd': /*decimal to binary*/ firstForm++; firstFinal = atoi(firstForm); firstBin = (char*) malloc(3*(strlen(firstForm))); d2b(firstBin, firstFinal); break; case 'o': /*octal to binary */ firstForm++; firstBin = (char*) malloc(3*(strlen(firstForm))); o2b(firstBin, firstForm); break; case 'b': /*no conversion necessary */ firstForm++; firstBin = firstForm; break; case 'x': /*hexadecimal to binary */ firstForm++; firstBin = (char*) malloc(4*(strlen(firstForm))); x2b(firstBin, firstForm); break; default: fprintf(stderr, "not a valid conversion base option\n"); return; } switch(secForm[0]) { case 'd': /*decimal to binary*/ secForm++; secFinal = atoi(secForm); secBin = (char*) malloc(3*(strlen(secForm))); d2b(secBin, secFinal); break; case 'o': /*octal to binary */ secForm++; secBin = (char*) malloc(3*(strlen(secForm))); o2b(secBin, secForm); break; case 'b': /*no conversion necessary */ secForm++; secBin = secForm; break; case 'x': /*hexadecimal to binary */ secForm++; secBin = (char*) malloc(4*(strlen(secForm))); x2b(secBin, secForm); break; default: fprintf(stderr, "not a valid conversion base option\n"); return; } /* int diff; diff = abs(strlen(firstBin) - strlen(secBin)); char* shorter; char* shorterBin; char* longerBin; * if strings are different lengths, * we must do some adjusting* if(diff > 0){ if(strlen(firstBin) > strlen(secBin)){ longerBin = firstBin; shorterBin = secBin; shorter = (char*) malloc(strlen(shorterBin)); } else{ longerBin = secBin; shorterBin = firstBin; shorter = (char*) malloc(strlen(shorterBin)); } * add zeros to the front of the shorter binary string * so they can be compared * strcpy(shorter, "0"); int k; for(k=0; k<diff-1; k++){ strcat(shorter, "0"); } strcat(shorter, shorterBin); } else{ longerBin = firstBin; shorter = secBin; } if (addition){ binAdd(sum, longerBin, shorter); sum = reverse(sum); printf("binSum: %s\n", sum); } if (subtraction){ binSub(sum, longerBin, shorter); printf("Subtraction sum: %s\n", sum); } */ /*decimal aritmatic*/ int decAns = 0; if (addition){ if(negFirst){ decAns += -1*b2d(firstBin); }else{ decAns += b2d(firstBin); } if(negSec){ decAns += -1*b2d(secBin); }else{ decAns += b2d(secBin); } }else{ if (subtraction){ if(negFirst){ int addme = -1*b2d(firstBin); decAns = decAns + addme; }else{ decAns += b2d(firstBin); } if(negSec){ int addme = -1*b2d(secBin); decAns = decAns - addme; }else{ decAns -= b2d(secBin); } }else{ if (mult){ printf("need to complete multiplication"); } } } /*convert to final output form*/ char * ans = (char*) malloc(2*(strlen(firstBin))); char * temp = (char*) malloc(2*(strlen(firstBin))); char output = *argv[4]; switch (output){ case 'd': /*no conversion necessary*/ printf("Answer: %d\n", decAns); break; case 'o': /*binary to octal*/ d2b(temp, decAns); b2o(ans, temp); printf("Answer: %s\n", ans); break; case 'x': /*binary to hexadecimal*/ d2b(temp, decAns); b2x(ans, temp); printf("Answer: %s\n", ans); break; case 'b': /*decimal to binary*/ d2b(ans, decAns); printf("Answer: %s\n", ans); break; default: fprintf(stderr, "not a valid conversion output"); } }
void scroller::handle_event(Event &ev, image *screen, InputManager *inm) { int mx=ev.mouse_move.x,my=ev.mouse_move.y; switch (ev.type) { case EV_MOUSE_BUTTON : { if (ev.mouse_button && drag==-1) { if (mx>=b1x() && mx<b1x()+bw() && my>=b1y()-2 && my<b1y()+bh()) { if (sx>0) { draw_widget(screen,1); sx--; draw_widget(screen,0); scroll_event(sx,screen); } } else if (mx>=b2x() && mx<b2x()+bw() && my>=b2y() && my<=b2y()+bh()) { if (sx<t-1) { draw_widget(screen,1); sx++; draw_widget(screen,0); scroll_event(sx,screen); } } else { int dx1,dy1,dx2,dy2; dragger_area(dx1,dy1,dx2,dy2); if (mx>=dx1 && mx<=dx2 && my>=dy1 && my<=dy2) { int x1,y1,x2,y2; wig_area(x1,y1,x2,y2); if (mx>=x1 && mx<=x2 && my>=y1 && my<=y2) { drag=sx; inm->grab_focus(this); } else if (t>1) { int nx=mouse_to_drag(mx,my); if (nx!=sx && nx>=0 && nx<t) { draw_widget(screen,1); sx=nx; draw_widget(screen,0); scroll_event(sx,screen); } } } else handle_inside_event(ev,screen,inm); } } else if (!ev.mouse_button && drag!=-1) { inm->release_focus(); drag=-1; } } break; case EV_MOUSE_MOVE : { if (drag!=-1) { int nx=mouse_to_drag(mx,my); if (nx<0) nx=0; else if (nx>=t) nx=t-1; if (nx!=sx) { draw_widget(screen,1); sx=nx; draw_widget(screen,0); scroll_event(sx,screen); } } else if ( activate_on_mouse_move()) { int x1,y1,x2,y2; wig_area(x1,y1,x2,y2); if (mx>=m_pos.x && mx<=m_pos.x+l-1 && my>=m_pos.y && my<=m_pos.y+h-1) handle_inside_event(ev,screen,inm); } } break; case EV_KEY : { switch (ev.key) { case JK_LEFT : { handle_left(screen,inm); } break; case JK_RIGHT : { handle_right(screen,inm); } break; case JK_UP : { handle_up(screen,inm); } break; case JK_DOWN : { handle_down(screen,inm); } break; default : handle_inside_event(ev,screen,inm); } } break; } }