void getlock(void) { int i = 0, fd; (void) fflush(stdout); /* we ignore QUIT and INT at this point */ if (link(HLOCK, LLOCK) == -1) { int errnosv = errno; perror(HLOCK); printf("Cannot link %s to %s\n", LLOCK, HLOCK); switch (errnosv) { case ENOENT: printf("Perhaps there is no (empty) file %s ?\n", HLOCK); break; case EACCES: printf("It seems you don't have write permission here.\n"); break; case EEXIST: printf("(Try again or rm %s.)\n", LLOCK); break; default: printf("I don't know what is wrong."); } getret(); error("%s", ""); /* NOTREACHED */ } regularize(lock); glo(0); if (locknum > 25) locknum = 25; do { if (locknum) lock[0] = 'a' + i++; if ((fd = open(lock, O_RDONLY)) == -1) { if (errno == ENOENT) goto gotlock; /* no such file */ perror(lock); (void) unlink(LLOCK); error("Cannot open %s", lock); } if (veryold(fd))/* if true, this closes fd and unlinks lock */ goto gotlock; (void) close(fd); } while (i < locknum); (void) unlink(LLOCK); error(locknum ? "Too many hacks running now." : "There is a game in progress under your name."); gotlock: fd = creat(lock, FMASK); if (unlink(LLOCK) == -1) error("Cannot unlink %s.", LLOCK); if (fd == -1) { error("cannot creat lock file."); } else { if (write(fd, &hackpid, sizeof(hackpid)) != sizeof(hackpid)) { error("cannot write lock"); } if (close(fd) == -1) { error("cannot close lock"); } } }
void PnlFmncSmpList::handleDpchAppDoButRegularizeClick( DbsFmnc* dbsfmnc , DpchEngFmnc** dpcheng ) { regularize(dbsfmnc, true, dpcheng); };
void endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg) { switch (activeTool) { case TOOL_FREESEL: { POINT *ptStackCopy; int i; rectSel_src[0] = rectSel_src[1] = 0x7fffffff; rectSel_src[2] = rectSel_src[3] = 0; for (i = 0; i <= ptSP; i++) { if (ptStack[i].x < rectSel_src[0]) rectSel_src[0] = ptStack[i].x; if (ptStack[i].y < rectSel_src[1]) rectSel_src[1] = ptStack[i].y; if (ptStack[i].x > rectSel_src[2]) rectSel_src[2] = ptStack[i].x; if (ptStack[i].y > rectSel_src[3]) rectSel_src[3] = ptStack[i].y; } rectSel_src[2] += 1 - rectSel_src[0]; rectSel_src[3] += 1 - rectSel_src[1]; rectSel_dest[0] = rectSel_src[0]; rectSel_dest[1] = rectSel_src[1]; rectSel_dest[2] = rectSel_src[2]; rectSel_dest[3] = rectSel_src[3]; if (ptSP != 0) { DeleteObject(hSelMask); hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL); DeleteObject(SelectObject(hSelDC, hSelMask)); ptStackCopy = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * (ptSP + 1)); for (i = 0; i <= ptSP; i++) { ptStackCopy[i].x = ptStack[i].x - rectSel_src[0]; ptStackCopy[i].y = ptStack[i].y - rectSel_src[1]; } Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE); HeapFree(GetProcessHeap(), 0, ptStackCopy); SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3])); resetToU1(); MaskBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0], rectSel_src[1], hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS)); Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE); newReversible(); MaskBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); placeSelWin(); ShowWindow(hSelection, SW_SHOW); /* force refresh of selection contents */ SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0); SendMessage(hSelection, WM_MOUSEMOVE, 0, 0); SendMessage(hSelection, WM_LBUTTONUP, 0, 0); } HeapFree(GetProcessHeap(), 0, ptStack); ptStack = NULL; break; } case TOOL_RECTSEL: resetToU1(); if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0)) { DeleteObject(hSelMask); hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL); DeleteObject(SelectObject(hSelDC, hSelMask)); Rect(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], 0x00ffffff, 0x00ffffff, 1, 2); SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3])); resetToU1(); BitBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0], rectSel_src[1], SRCCOPY); Rect(hdc, rectSel_src[0], rectSel_src[1], rectSel_src[0] + rectSel_src[2], rectSel_src[1] + rectSel_src[3], bgColor, bgColor, 0, TRUE); newReversible(); BitBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0, 0, SRCCOPY); placeSelWin(); ShowWindow(hSelection, SW_SHOW); /* force refresh of selection contents */ SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0); SendMessage(hSelection, WM_MOUSEMOVE, 0, 0); SendMessage(hSelection, WM_LBUTTONUP, 0, 0); } break; case TOOL_RUBBER: Erase(hdc, last.x, last.y, x, y, bg, rubberRadius); break; case TOOL_PEN: Line(hdc, last.x, last.y, x, y, fg, 1); SetPixel(hdc, x, y, fg); break; case TOOL_LINE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) roundTo8Directions(start.x, start.y, &x, &y); Line(hdc, start.x, start.y, x, y, fg, lineWidth); break; case TOOL_BEZIER: pointSP++; if (pointSP == 4) pointSP = 0; break; case TOOL_RECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Rect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; case TOOL_SHAPE: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, &pointStack[pointSP].x, &pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { if ((pointStack[0].x - x) * (pointStack[0].x - x) + (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1) { Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, TRUE); pointSP = 0; } else { Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE); } } if (pointSP == 255) pointSP--; break; case TOOL_ELLIPSE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Ellp(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; case TOOL_RRECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); RRect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; } }
void PnlPlnrRtcRec::handleDpchAppDoButRegularizeClick( DbsPlnr* dbsplnr , DpchEngPlnr** dpcheng ) { regularize(dbsplnr, true, dpcheng); };
void whilePaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg) { switch (activeTool) { case TOOL_RUBBER: Replace(hdc, last.x, last.y, x, y, fg, bg, rubberRadius); break; case TOOL_PEN: Line(hdc, last.x, last.y, x, y, bg, 1); break; case TOOL_BRUSH: Brush(hdc, last.x, last.y, x, y, bg, brushStyle); break; case TOOL_AIRBRUSH: Airbrush(hdc, x, y, bg, airBrushWidth); break; case TOOL_LINE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) roundTo8Directions(start.x, start.y, &x, &y); Line(hdc, start.x, start.y, x, y, bg, lineWidth); break; case TOOL_BEZIER: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; switch (pointSP) { case 1: Line(hdc, pointStack[0].x, pointStack[0].y, pointStack[1].x, pointStack[1].y, bg, lineWidth); break; case 2: Bezier(hdc, pointStack[0], pointStack[2], pointStack[2], pointStack[1], bg, lineWidth); break; case 3: Bezier(hdc, pointStack[0], pointStack[2], pointStack[3], pointStack[1], bg, lineWidth); break; } break; case TOOL_RECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Rect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; case TOOL_SHAPE: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, &pointStack[pointSP].x, &pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, bg, fg, lineWidth, shapeStyle, FALSE); break; case TOOL_ELLIPSE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Ellp(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; case TOOL_RRECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); RRect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; } last.x = x; last.y = y; }
void whilePaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg) { switch (activeTool) { case TOOL_FREESEL: if (ptSP == 0) newReversible(); ptSP++; if (ptSP % 1024 == 0) ptStack = HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, ptStack, sizeof(POINT) * (ptSP + 1024)); ptStack[ptSP].x = max(0, min(x, imgXRes)); ptStack[ptSP].y = max(0, min(y, imgYRes)); resetToU1(); Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE); break; case TOOL_RECTSEL: { POINT temp; resetToU1(); temp.x = max(0, min(x, imgXRes)); temp.y = max(0, min(y, imgYRes)); rectSel_dest[0] = rectSel_src[0] = min(start.x, temp.x); rectSel_dest[1] = rectSel_src[1] = min(start.y, temp.y); rectSel_dest[2] = rectSel_src[2] = max(start.x, temp.x) - min(start.x, temp.x); rectSel_dest[3] = rectSel_src[3] = max(start.y, temp.y) - min(start.y, temp.y); RectSel(hdc, start.x, start.y, temp.x, temp.y); break; } case TOOL_RUBBER: Erase(hdc, last.x, last.y, x, y, bg, rubberRadius); break; case TOOL_PEN: Line(hdc, last.x, last.y, x, y, fg, 1); break; case TOOL_BRUSH: Brush(hdc, last.x, last.y, x, y, fg, brushStyle); break; case TOOL_AIRBRUSH: Airbrush(hdc, x, y, fg, airBrushWidth); break; case TOOL_LINE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) roundTo8Directions(start.x, start.y, &x, &y); Line(hdc, start.x, start.y, x, y, fg, lineWidth); break; case TOOL_BEZIER: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; switch (pointSP) { case 1: Line(hdc, pointStack[0].x, pointStack[0].y, pointStack[1].x, pointStack[1].y, fg, lineWidth); break; case 2: Bezier(hdc, pointStack[0], pointStack[2], pointStack[2], pointStack[1], fg, lineWidth); break; case 3: Bezier(hdc, pointStack[0], pointStack[2], pointStack[3], pointStack[1], fg, lineWidth); break; } break; case TOOL_RECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Rect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; case TOOL_SHAPE: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, &pointStack[pointSP].x, &pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE); break; case TOOL_ELLIPSE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Ellp(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; case TOOL_RRECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); RRect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle); break; } last.x = x; last.y = y; }
int main(int argc, char *argv[]) { int fd; #ifdef CHDIR char *dir; #endif hname = argv[0]; hackpid = getpid(); #ifdef CHDIR /* otherwise no chdir() */ /* * See if we must change directory to the playground. * (Perhaps hack runs suid and playground is inaccessible * for the player.) * The environment variable HACKDIR is overridden by a * -d command line option (must be the first option given) */ dir = getenv("HACKDIR"); if (argc > 1 && !strncmp(argv[1], "-d", 2)) { argc--; argv++; dir = argv[0] + 2; if (*dir == '=' || *dir == ':') dir++; if (!*dir && argc > 1) { argc--; argv++; dir = argv[0]; } if (!*dir) error("Flag -d must be followed by a directory name."); } #endif /* * Who am i? Algorithm: 1. Use name as specified in HACKOPTIONS * 2. Use $USER or $LOGNAME (if 1. fails) * 3. Use getlogin() (if 2. fails) * The resulting name is overridden by command line options. * If everything fails, or if the resulting name is some generic * account like "games", "play", "player", "hack" then eventually * we'll ask him. * Note that we trust him here; it is possible to play under * somebody else's name. */ { char *s; initoptions(); if (!*plname && (s = getenv("USER"))) strncpy(plname, s, sizeof(plname) - 1); if (!*plname && (s = getenv("LOGNAME"))) strncpy(plname, s, sizeof(plname) - 1); if (!*plname && (s = getlogin())) strncpy(plname, s, sizeof(plname) - 1); } /* * Now we know the directory containing 'record' and * may do a prscore(). */ if (argc > 1 && !strncmp(argv[1], "-s", 2)) { #ifdef CHDIR chdirx(dir, 0); #endif prscore(argc, argv); exit(0); } /* * It seems he really wants to play. * Remember tty modes, to be restored on exit. */ gettty(); setbuf(stdout, obuf); umask(007); setrandom(); startup(); cls(); u.uhp = 1; /* prevent RIP on early quits */ u.ux = FAR; /* prevent nscr() */ signal(SIGHUP, hangup); /* * Find the creation date of this game, * so as to avoid restoring outdated savefiles. */ gethdate(hname); /* * We cannot do chdir earlier, otherwise gethdate will fail. */ #ifdef CHDIR chdirx(dir, 1); #endif /* * Process options. */ while (argc > 1 && argv[1][0] == '-') { argv++; argc--; switch (argv[0][1]) { #ifdef WIZARD case 'D': wizard = TRUE; break; #endif #ifdef NEWS case 'n': flags.nonews = TRUE; break; #endif case 'u': if (argv[0][2]) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); else if (argc > 1) { argc--; argv++; strncpy(plname, argv[0], sizeof(plname) - 1); } else printf("Player name expected after -u\n"); break; default: /* allow -T for Tourist, etc. */ strncpy(pl_character, argv[0] + 1, sizeof(pl_character) - 1); } } if (argc > 1) locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS if (!locknum || locknum > MAX_NR_OF_PLAYERS) locknum = MAX_NR_OF_PLAYERS; #endif #ifdef DEF_PAGER if (!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER"))) catmore = DEF_PAGER; #endif #ifdef MAIL getmailstatus(); #endif #ifdef WIZARD if (wizard) strcpy(plname, "wizard"); else #endif if (!*plname || !strncmp(plname, "player", 4) || !strncmp(plname, "games", 4)) askname(); plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ /* accepts any suffix */ #ifdef WIZARD if (!wizard) { #endif /* * check for multiple games under the same name * (if !locknum) or check max nr of players (otherwise) */ signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); if (!locknum) strcpy(lock, plname); getlock(); /* sets lock if locknum != 0 */ #ifdef WIZARD } else { char *sfoo; strcpy(lock, plname); if ((sfoo = getenv("MAGIC"))) while (*sfoo) { switch (*sfoo++) { case 'n': srandom(*sfoo++); break; } } if ((sfoo = getenv("GENOCIDED")) != NULL) { if (*sfoo == '!') { struct permonst *pm = mons; char *gp = genocided; while (pm < mons + CMNUM + 2) { if (!strchr(sfoo, pm->mlet)) *gp++ = pm->mlet; pm++; } *gp = 0; } else strncpy(genocided, sfoo, sizeof(genocided) - 1); strcpy(fut_geno, genocided); } } #endif setftty(); sprintf(SAVEF, "save/%d%s", getuid(), plname); regularize(SAVEF + 5); /* avoid . or / in name */ if ((fd = open(SAVEF, O_RDONLY)) >= 0 && (uptodate(fd) || unlink(SAVEF) == 666)) { signal(SIGINT, done1); pline("Restoring old save file..."); fflush(stdout); if (!dorecover(fd)) goto not_recovered; pline("Hello %s, welcome to %s!", plname, gamename); flags.move = 0; } else { not_recovered: fobj = fcobj = invent = 0; fmon = fallen_down = 0; ftrap = 0; fgold = 0; flags.ident = 1; init_objects(); u_init(); signal(SIGINT, done1); mklev(); u.ux = xupstair; u.uy = yupstair; inshop(); setsee(); flags.botlx = 1; makedog(); { struct monst *mtmp; if ((mtmp = m_at(u.ux, u.uy)) != NULL) mnexto(mtmp); /* riv05!a3 */ } seemons(); #ifdef NEWS if (flags.nonews || !readnews()) /* after reading news we did docrt() already */ #endif docrt(); /* give welcome message before pickup messages */ pline("Hello %s, welcome to %s!", plname, gamename); pickup(1); read_engr_at(u.ux, u.uy); flags.move = 1; } flags.moonphase = phase_of_the_moon(); if (flags.moonphase == FULL_MOON) { pline("You are lucky! Full moon tonight."); u.uluck++; } else if (flags.moonphase == NEW_MOON) pline("Be careful! New moon tonight."); initrack(); for (;;) { if (flags.move) { /* actual time passed */ settrack(); if (moves % 2 == 0 || (!(Fast & ~INTRINSIC) && (!Fast || rn2(3)))) { movemon(); if (!rn2(70)) makemon(NULL, 0, 0); } if (Glib) glibr(); p_timeout(); ++moves; if (flags.time) flags.botl = 1; if (u.uhp < 1) { pline("You die..."); done("died"); } if (u.uhp * 10 < u.uhpmax && moves - wailmsg > 50) { wailmsg = moves; if (u.uhp == 1) pline("You hear the wailing of the Banshee..."); else pline("You hear the howling of the CwnAnnwn..."); } if (u.uhp < u.uhpmax) { if (u.ulevel > 9) { if (Regeneration || !(moves % 3)) { flags.botl = 1; u.uhp += rnd((int)u.ulevel - 9); if (u.uhp > u.uhpmax) u.uhp = u.uhpmax; } } else if (Regeneration || (!(moves % (22 - u.ulevel * 2)))) { flags.botl = 1; u.uhp++; } } if (Teleportation && !rn2(85)) tele(); if (Searching && multi >= 0) dosearch(); gethungry(); invault(); amulet(); } if (multi < 0) { if (!++multi) { pline("%s", nomovemsg ? nomovemsg : "You can move again."); nomovemsg = 0; if (afternmv) (*afternmv)(); afternmv = NULL; } } find_ac(); #ifndef QUEST if (!flags.mv || Blind) #endif { seeobjs(); seemons(); nscr(); } if (flags.botl || flags.botlx) bot(); flags.move = 1; if (multi >= 0 && occupation) { if (monster_nearby()) stop_occupation(); else if ((*occupation)() == 0) occupation = NULL; continue; } if (multi > 0) { #ifdef QUEST if (flags.run >= 4) finddir(); #endif lookaround(); if (!multi) { /* lookaround may clear multi */ flags.move = 0; continue; } if (flags.mv) { if (multi < COLNO && !--multi) flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if (multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack(NULL); } if (multi && multi % 7 == 0) fflush(stdout); } }
TimeDiff::TimeDiff(long sec, long usec, bool is_valid) : m_isvalid(is_valid), m_sec(sec), m_usec(usec) { if (m_isvalid) regularize(m_sec, m_usec); }
/*------------------------------------------------------------*/ void AzpLmSgd::flushDelta(const AzpLmParam &p, const AzpLmSgd_Param &ps) { if (p.dont_update()) return; if (grad_num <= 0) return; double etab = (ps.etab_coeff == 1) ? ps.eta : ps.eta*ps.etab_coeff; if (ps.do_fast_flush && ps.momentum > 0) { check_ws("flushDelta with momentum (fast_flush)"); double mm = MAX(0,ps.momentum); if (p.reg_L2 > 0 && p.reg_L2init <= 0) { m_w_dlt.add(mm, &m_w_grad, -ps.eta/(double)grad_num, &m_w, -ps.eta*p.reg_L2); } else { m_w_dlt.add(mm, &m_w_grad, -ps.eta/(double)grad_num); if (!p.no_regadd()) { add_reg_grad(p, ps.eta, &m_w, &m_w_dlt, &m_w_init); } } m_w.add(&m_w_dlt); v_i_dlt.add(mm, &v_i_grad, -etab/(double)grad_num); if (p.do_reg_intercept && !p.no_regadd()) { add_reg_grad(p, etab, &v_i, &v_i_dlt, &v_i_init); /* regularization */ } v_i.add(&v_i_dlt); do_gradpart = false; } else if (ps.momentum > 0 || p.reg_L2init > 0) { /* use momentum; slower; keeping this for compatibility */ check_ws("flushDelta with momentum"); double mm = MAX(0,ps.momentum); m_w_grad.multiply(-ps.eta/(double)grad_num); add_reg_grad(p, ps.eta, &m_w, &m_w_grad, &m_w_init); /* regularization */ m_w_grad.add(&m_w_dlt, mm); m_w.add(&m_w_grad); m_w_dlt.set_chk(&m_w_grad); v_i_grad.multiply(-etab/(double)grad_num); if (p.do_reg_intercept) { add_reg_grad(p, etab, &v_i, &v_i_grad, &v_i_init); /* regularization */ } v_i_grad.add(&v_i_dlt, mm); v_i.add(&v_i_grad); v_i_dlt.set_chk(&v_i_grad); do_gradpart = false; } else { /* don't use momentum */ regularize(p, ps.eta, etab); if (doing_partial() && do_gradpart) { m_w.add_s2d(&m_w_grad, ia_p2w.point(), ia_p2w.size(), -ps.eta/(double)grad_num/ws); v_i.add_s2d(&v_i_grad, ia_p2w.point(), ia_p2w.size(), -etab/(double)grad_num); } else { m_w.add(&m_w_grad, -ps.eta/(double)grad_num/ws); v_i.add(&v_i_grad, -etab/(double)grad_num); } do_gradpart = doing_partial(); } if (p.reg_L2const > 0) do_l2const(p); grad_num = 0; if (ws < 1e-4) flush_ws(); }
void outputOPML( const MyClip *mp, int numOfClips, const char *title, int codeChange, FILE *fp ) { int i; int rate; char buf[BUFSIZ]; char tag[4096]; char comment[4096]; struct tm tm, *tt; time_t t; int yyyy, mm, dd, HH, MM, SS; char *p = NULL; /* OPML ファイル書き出し */ switch ( codeChange ) { case SJIS2UTF: p = sjis2utf( title ); break; case EUC2UTF: p = euc2utf( title ); break; case UTF8: default: p = NULL; break; } fprintf( fp, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<opml version=\"1.1\">\n<head>\n" "<title>%s</title>\n", p ? p : title ); fprintf( fp, "</head>\n<body>\n" ); for ( i = 0; i < numOfClips; i++ ) { switch ( codeChange ) { case SJIS2UTF: // p = sjis2utf( mp[i].title ); // strcpy( buf, p ? p : mp[i].title ); p = sjis2utf( mp[i].tags ); strcpy( tag, p ? p : mp[i].tags ); p = sjis2utf( mp[i].comment ); strcpy( comment, p ? p : mp[i].comment ); break; case EUC2UTF: // p = euc2utf( mp[i].title ); // strcpy( buf, p ? p : mp[i].title ); p = euc2utf( mp[i].tags ); strcpy( tag, p ? p : mp[i].tags ); p = euc2utf( mp[i].comment ); strcpy( comment, p ? p : mp[i].comment ); break; case UTF8: default: // strcpy( buf, mp[i].title ); strcpy( tag, mp[i].tags ); strcpy( comment, mp[i].comment ); break; } // MM/Memo 形式の title を扱うための処理 strcpy( buf, mp[i].title ); rate = getEvaluation( buf, UTF8 ); regularize( buf ); regularize( tag ); regularize( comment ); tm.tm_year = mp[i].yyyy - 1900; tm.tm_mon = mp[i].mm - 1; tm.tm_mday = mp[i].dd; tm.tm_hour = mp[i].HH; tm.tm_min = mp[i].MM; tm.tm_sec = mp[i].SS; t = timelocal( &tm ); #ifdef WIN32 if ( _timezone != 0 ) t += _timezone; #else t -= 9 * 60 * 60; /* JST → GMT */ #endif tt = gmtime( &t ); if ( !tt ) tt = localtime( &t ); if ( tt ) { yyyy = tt->tm_year + 1900; mm = tt->tm_mon + 1; dd = tt->tm_mday; HH = tt->tm_hour; MM = tt->tm_min; SS = tt->tm_sec; } else { yyyy = mp[i].yyyy; mm = mp[i].mm; dd = mp[i].dd; HH = mp[i].HH; MM = mp[i].MM; SS = mp[i].SS; } strcpy( buf, escapeQuote( buf ) ); fprintf( fp, "<outline text=\"%s\" type=\"Link\" " "url=\"%s\" title=\"%s\" notes=\"%s\" " "date=\"%04d-%02d-%02dT%02d:%02d:%02dZ\"", buf, escapeURL( mp[i].url ), tag, escapeQuote( comment ), yyyy, mm, dd, HH, MM, SS ); // 以下は bookey 独自拡張 [OPML 1.0 の仕様書を読む限りは、独自に属性を // 追加するのは問題なさそう] // -- 2006年11月17日現在、OPML validator は Internal database error // が発生して利用できない(新しいデータベースでサービス再開するま // で待っていてください、云々と表示される)ため、本当に valid なの // かどうかは未確認 if ( ((rate >= EVL_ONE) && (rate <= EVL_FIVE) ) || ((mp[i].evaluation >= EVL_ONE) && (mp[i].evaluation <= EVL_FIVE) ) ) fprintf( fp, " evaluation=\"%d\"", mp[i].evaluation ); if ( (mp[i].rating >= RAT_ONE) && (mp[i].rating <= RAT_THREE) ) fprintf( fp, " rating=\"%d\"", mp[i].rating ); if ((mp[i].affirmation == AFF_GOOD) || (mp[i].affirmation == AFF_BAD)) fprintf( fp, " affirmation=\"%s\"", mp[i].affirmation == AFF_GOOD ? "good" : "bad" ); if ( mp[i].publication != PUB_EVERYONE ) { switch ( mp[i].publication ) { case PUB_FRIENDS: fprintf( fp, " publication=\"friends\"" ); break; case PUB_PRIVATE: fprintf( fp, " publication=\"private\"" ); break; } } fputs( " />\n", fp ); #ifdef _DEBUG fprintf( stderr, "%d) %s (URL: %s)\n", i + 1, utf2sjis(buf), mp[i].url ); #endif } // fprintf( fp, "</body>\n</opml>\n" ); fputs( "</body>\n</opml>\n", fp ); }
void endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg) { switch (activeTool) { case TOOL_RUBBER: Replace(hdc, last.x, last.y, x, y, fg, bg, rubberRadius); break; case TOOL_PEN: Line(hdc, last.x, last.y, x, y, bg, 1); SetPixel(hdc, x, y, bg); break; case TOOL_LINE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) roundTo8Directions(start.x, start.y, &x, &y); Line(hdc, start.x, start.y, x, y, bg, lineWidth); break; case TOOL_BEZIER: pointSP++; if (pointSP == 4) pointSP = 0; break; case TOOL_RECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Rect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; case TOOL_SHAPE: resetToU1(); pointStack[pointSP].x = x; pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, &pointStack[pointSP].x, &pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { if ((pointStack[0].x - x) * (pointStack[0].x - x) + (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1) { Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE); pointSP = 0; } else { Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE); } } if (pointSP == 255) pointSP--; break; case TOOL_ELLIPSE: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); Ellp(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; case TOOL_RRECT: resetToU1(); if (GetAsyncKeyState(VK_SHIFT) < 0) regularize(start.x, start.y, &x, &y); RRect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle); break; } }