int main() { unsigned int num_iterations = 1000; // number of iterations to run float v[2] = {0.0405f, 0.5f}; // gradsearch gs = gradsearch_create(NULL,v,2,gserror,LIQUID_OPTIM_MINIMIZE); // execute search one iteration at a time unsigned int i; float rmse; for (i=0; i<num_iterations; i++) { rmse = gserror(NULL,v,2); gradsearch_step(gs); if (((i+1)%100)==0) gradsearch_print(gs); } gradsearch_destroy(gs); // print results for (i=0; i<41; i++) printf(" z = %12.8f, g = %12.8f (%12.8f)\n", z[i], lngamma_test[i], sandbox_lngammaf(z[i], v)); printf("rmse = %12.4e;\n", rmse); printf("v0 = %12.8f\n", v[0]); printf("v1 = %12.8f\n", v[1]); printf("done.\n"); return 0; }
/* Write out a BMP file */ void paste_to_file(void) { LPBITMAP1 pbm1 = (LPBITMAP1)bitmap.pbmi; BITMAPFILEHEADER2 bmfh; UINT bmfh_length = sizeof(BITMAPFILEHEADER2) - sizeof(BITMAPINFOHEADER2); UINT offset = 0; UINT length = 0; /* bitmap length */ ULONG fh; /* file handle */ ULONG action; ULONG count; char output[MAXSTR]; strcpy(output, "*.bmp"); if (!get_filename(output, TRUE, FILTER_BMP, 0, IDS_TOPICCLIP)) return; bmfh.usType = 0x4d42; /* "BM" */ if (bitmap.pbmi->cbFix == sizeof(BITMAP1)) { offset = pbm1->bcSize + sizeof(RGB3) * dib_pal_colors((unsigned char *)bitmap.pbmi); length = offset + ( dib_bytewidth((unsigned char *)bitmap.pbmi) * pbm1->bcHeight ); } else { offset = bitmap.pbmi->cbFix + sizeof(RGB2) * dib_pal_colors((unsigned char *)bitmap.pbmi); length = offset + ( dib_bytewidth((unsigned char *)bitmap.pbmi) * bitmap.pbmi->cy ); } bmfh.cbSize = bmfh_length + length; bmfh.xHotspot = bmfh.yHotspot = 0; bmfh.offBits = bmfh_length + offset; if (DosOpen((PCSZ)output, /* filename */ &fh, /* pointer to handle */ &action, /* pointer to result */ 0, /* initial length */ FILE_NORMAL, /* normal file */ OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE, 0)) { gserror(0, "Error opening BMP file", MB_ICONEXCLAMATION, SOUND_ERROR); return; } if (DosWrite(fh, (PBYTE)&bmfh, bmfh_length, &count)) gserror(0, "Error writing BMP header", MB_ICONEXCLAMATION, SOUND_ERROR); if (DosWrite(fh, (PBYTE)bitmap.pbmi, length, &count)) gserror(0, "Error writing BMP body", MB_ICONEXCLAMATION, SOUND_ERROR); if (DosClose(fh)) gserror(0, "Error closing BMP file", MB_ICONEXCLAMATION, SOUND_ERROR); }
void gsview_check_usersize() { if ( (option.user_width > option.user_width_warn) || (option.user_height > option.user_width_warn) ) { gserror(IDS_LARGEMEDIA, NULL, 0, SOUND_ERROR); } }
/* if no document open, display error message and return true */ BOOL not_open() { if (psfile.name[0] != '\0') return FALSE; gserror(IDS_NOTOPEN, NULL, MB_ICONEXCLAMATION, SOUND_NOTOPEN); return TRUE; }
/* if not DSC document or not open, display error message and return true */ BOOL not_dsc() { if (not_open()) return TRUE; if (psfile.dsc!=(CDSC *)NULL) return FALSE; gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER); return TRUE; }
/* stop specified program */ void stop_pgm(PROG* prog) { QMSG q_mess; /* queue message */ int i = 0; if (!prog->valid) { cleanup_pgm(prog); return; } DosStopSession(STOP_SESSION_SPECIFIED, prog->session_id); while (prog->valid && (i < 100)) { /* wait for termination queue message to cause cleanup_pgm() to be called */ if (WinGetMsg(hab, &q_mess, 0L, 0, 0)) WinDispatchMsg(hab, &q_mess); i++; } if (i >= 100) gserror(0, "can't stop program", MB_ICONHAND, SOUND_ERROR); /* cleanup should already have occurred */ cleanup_pgm(prog); }
/* if error is TRUE, an error message can be shown */ BOOL dialog_get_float_error(HWND hwnd, int field, float *fres, BOOL error) { float ftemp ; char buf[64] ; GetDlgItemText(hwnd, field, (PBYTE)buf, sizeof(buf)-1) ; if ((1 > sscanf(buf,"%g",&ftemp)) && error) { HWND errfld = WinWindowFromID(hwnd, field); gserror(IDS_INVALIDNUMBER, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER) ; WinSetFocus(HWND_DESKTOP, errfld) ; /* Replace 100 with the end */ WinSendMsg( errfld, EM_SETSEL, MPFROM2SHORT(0, 100), MPFROMLONG(0) ); } else { *fres = ftemp ; return TRUE ; } return FALSE; }
int main() { // options unsigned int num_samples = 400; // number of samples float sig = 0.1f; // noise variance unsigned int num_iterations = 1000; // number of iterations to run float v[3] = {1, 1, 1}; unsigned int i; // range float xmin = 0.0f; float xmax = 6.0f; float dx = (xmax - xmin) / (num_samples-1); // generate data set float x[num_samples]; float y[num_samples]; for (i=0; i<num_samples; i++) { x[i] = xmin + i*dx; y[i] = sincf(x[i]) + randnf()*sig; } struct gsdataset q = {x, y, num_samples}; // create gradsearch object gradsearchprops_s gsprops; gradsearchprops_init_default(&gsprops); gsprops.delta = 1e-6f; // gradient approximation step size gsprops.gamma = 0.002f; // vector step size gsprops.alpha = 0.1f; // momentum parameter gsprops.mu = 0.999f; // decremental gamma paramter (best if not exactly 1.0) gradsearch gs = gradsearch_create((void*)&q, v, 3, gserror, LIQUID_OPTIM_MINIMIZE, &gsprops); float rmse; // execute search //rmse = gradsearch_run(gs, num_iterations, -1e-6f); // open output file FILE*fid = fopen(OUTPUT_FILENAME,"w"); fprintf(fid,"%% %s : auto-generated file\n", OUTPUT_FILENAME); fprintf(fid,"clear all;\n"); fprintf(fid,"close all;\n"); // execute search one iteration at a time fprintf(fid,"u = zeros(1,%u);\n", num_iterations); for (i=0; i<num_iterations; i++) { rmse = gserror((void*)&q,v,3); fprintf(fid,"u(%3u) = %12.4e;\n", i+1, rmse); gradsearch_step(gs); if (((i+1)%100)==0) gradsearch_print(gs); } // print results printf("\n"); gradsearch_print(gs); printf(" c0 = %12.8f, opt = 1\n", v[0]); printf(" c1 = %12.8f, opt = 0\n", v[1]); printf(" c2 = %12.8f, opt = 1\n", v[2]); printf(" rmse = %12.4e\n", rmse); fprintf(fid,"figure;\n"); fprintf(fid,"semilogy(u);\n"); fprintf(fid,"xlabel('iteration');\n"); fprintf(fid,"ylabel('error');\n"); fprintf(fid,"title('gradient search results');\n"); fprintf(fid,"grid on;\n"); // save sampled data set for (i=0; i<num_samples; i++) { fprintf(fid," x(%4u) = %12.8f;\n", i+1, x[i]); fprintf(fid," y(%4u) = %12.8f;\n", i+1, y[i]); fprintf(fid," y_hat(%4u) = %12.8f;\n", i+1, gsfunc(x[i],v)); } fprintf(fid,"figure;\n"); fprintf(fid,"plot(x,y,'x', x,y_hat,'-');\n"); fprintf(fid,"xlabel('x');\n"); fprintf(fid,"ylabel('f(x)');\n"); fprintf(fid,"grid on;\n"); fprintf(fid,"legend('data','fit',1);\n"); fclose(fid); printf("results written to %s.\n", OUTPUT_FILENAME); gradsearch_destroy(gs); return 0; }
/* Start child program with inherited pipe */ BOOL start_gvwgs_with_pipe(HDC hdc) { STARTUPINFO siStartInfo; LPVOID env; TCHAR wcommand[MAXSTR+MAXSTR]; TCHAR wgsdll[MAXSTR]; TCHAR woptname[MAXSTR]; TCHAR wpsname[MAXSTR]; convert_multibyte(wgsdll, option.gsdll, sizeof(wgsdll)/sizeof(TCHAR)-1); convert_multibyte(woptname, printer.optname, sizeof(woptname)/sizeof(TCHAR)-1); convert_multibyte(wpsname, printer.psname, sizeof(wpsname)/sizeof(TCHAR)-1); PGDI_THREAD *pth= (PGDI_THREAD *)malloc(sizeof(PGDI_THREAD)); if (pth == NULL) { gs_addmess("Failed to allocate PGDI_THREAD\n"); return FALSE; } if (psfile.dsc != (CDSC *)NULL && !psfile.print_ignoredsc) { // PostScript file contains only needed pages // Print all pth->from = 1; pth->to = 9999; pth->oddeven = ALL_PAGES; } else { // we render all pages, and print only some pth->from = psfile.print_from; pth->to = psfile.print_to; pth->oddeven = psfile.print_oddeven; } pth->hdc = hdc; pth->hPipeRd = print_gdi_read_handle; wsprintf(wcommand, TEXT("\042%s%s\042 %s \042%s\042 \042%s\042 \042%s\042"), szExePath, #ifdef DECALPHA TEXT("gvwgsda.exe"), #else # ifdef _WIN64 TEXT("gvwgs64.exe"), # else TEXT("gvwgs32.exe"), # endif #endif debug ? TEXT("/d") : TEXT(""), wgsdll, woptname, wpsname); info_wait(IDS_WAIT); /* Now create the child process. */ /* Set up members of STARTUPINFO structure. */ siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.lpReserved = NULL; siStartInfo.lpDesktop = NULL; siStartInfo.lpTitle = NULL; /* use executable name as title */ siStartInfo.dwX = siStartInfo.dwY = CW_USEDEFAULT; /* ignored */ siStartInfo.dwXSize = siStartInfo.dwYSize = CW_USEDEFAULT; /* ignored */ siStartInfo.dwXCountChars = 80; siStartInfo.dwYCountChars = 25; siStartInfo.dwFillAttribute = 0; /* ignored */ siStartInfo.dwFlags = STARTF_USESHOWWINDOW; // siStartInfo.wShowWindow = SW_SHOWNORMAL; siStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; siStartInfo.cbReserved2 = 0; siStartInfo.lpReserved2 = NULL; siStartInfo.hStdInput = NULL; siStartInfo.hStdOutput = NULL; siStartInfo.hStdError = NULL; env = NULL; /* Create the child process. */ PROCESS_INFORMATION piProcInfo; if (!CreateProcess(NULL, wcommand, /* command line */ NULL, /* process security attributes */ NULL, /* primary thread security attributes */ TRUE, /* handles are inherited */ 0, /* creation flags */ env, /* environment */ NULL, /* use parent's current directory */ &siStartInfo, /* STARTUPINFO pointer */ &piProcInfo) /* receives PROCESS_INFORMATION */ ) { char command[MAXSTR+MAXSTR]; // cleanup items created by gsviev_cprint() if (!debug) unlink(printer.psname); printer.psname[0] = '\0'; if (!debug) unlink(printer.optname); printer.optname[0] = '\0'; // also items PRINT_GDI items CloseHandle(print_gdi_read_handle); print_gdi_read_handle = NULL; CloseHandle(print_gdi_write_handle); print_gdi_write_handle = NULL; EndDoc(pth->hdc); free(pth); info_wait(IDS_NOWAIT); convert_widechar(command, wcommand, sizeof(command)-1); gserror(IDS_CANNOTRUN, command, MB_ICONHAND, SOUND_ERROR); return FALSE; } WaitForInputIdle(piProcInfo.hProcess, 30000); info_wait(IDS_NOWAIT); /* we shouldn't exit GSview until print_gdi_thread finishes * and print_count becomes 0. */ print_count++; _beginthread(print_gdi_thread, 65536, (void *)pth); // we don't need to know anything more */ CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); // Now that Ghostscript has started, close our copy of the write // handle so that pipe will break when Ghostscript closes its // write handle. CloseHandle(print_gdi_write_handle); return TRUE; }
/* execute program */ BOOL exec_pgm(char *name, char *arg, PROG* prog) { STARTDATA sdata; APIRET rc; char buf[MAXSTR]; CHAR progname[MAXSTR]; PROG pg; PTIB pptib; PPIB pppib; memset(&pg, 0, sizeof(PROG)); if (DosGetInfoBlocks(&pptib, &pppib)) { error_message("\nexec_pgm: Couldn't get environment\n"); return FALSE; } /* Look for program in same directory as this EXE */ progname[0] = '\0'; if (!strchr(name, '\\')) strcpy(progname, szExePath); strcat(progname, name); memset(&sdata, 0, sizeof(sdata)); /* because new program is a different EXE type, * we must use start session not DosExecPgm() */ sdata.Length = sizeof(sdata); sdata.Related = SSF_RELATED_INDEPENDENT; sdata.FgBg = SSF_FGBG_BACK; /* start in background */ sdata.TraceOpt = 0; sdata.PgmTitle = (PSZ)name; sdata.PgmName = (PSZ)progname; sdata.PgmInputs = (PSZ)arg; sdata.TermQ = 0; sdata.Environment = (PBYTE)pppib->pib_pchenv; /* use Parent's environment */ sdata.InheritOpt = 0; sdata.InheritOpt = SSF_INHERTOPT_PARENT; sdata.SessionType = SSF_TYPE_DEFAULT; /* default is text */ sdata.IconFile = NULL; sdata.PgmHandle = 0; sdata.PgmControl = 0; /* normal, not SSF_CONTROL_MINIMIZE */ sdata.InitXPos = 0; sdata.InitYPos = 0; sdata.InitXSize = 0; sdata.InitYSize = 0; sdata.ObjectBuffer = NULL; sdata.ObjectBuffLen = 0; /* sprintf(buf,"exec_pgm: %s %s\n",sdata.PgmName, sdata.PgmInputs); message_box(buf, 0); */ rc = DosStartSession(&sdata, &pg.session_id, &pg.process_id); if (rc == ERROR_FILE_NOT_FOUND) { /* didn't find it in same directory as this EXE so try PATH */ sdata.PgmName = (PSZ)name; rc = DosStartSession(&sdata, &pg.session_id, &pg.process_id); } if (rc) { sprintf(buf,"\"%s %s\", rc = %ld\n", sdata.PgmName, sdata.PgmInputs, rc); gserror(IDS_CANNOTRUN, buf, MB_ICONHAND, SOUND_ERROR); nHelpTopic = IDS_TOPICINSTALL; get_help(); return FALSE; } pg.valid = TRUE; *prog = pg; /* give details back to caller */ return TRUE; }
int not_implemented() { gserror(IDS_NOTIMPLEMENTED, NULL, 0, 0); return 0; }
/* gsview menu commands */ int gsview_command(int command) { switch (command) { case IDM_NEXTHOME: case IDM_NEXT: case IDM_NEXTSKIP: case IDM_REDISPLAY: case IDM_PREVHOME: case IDM_PREVSKIP: case IDM_PREV: case IDM_GOBACK: case IDM_GOFWD: case IDM_MAGPLUS: case IDM_MAGMINUS: case IDM_FITWIN: case IDM_ZOOM: case IDM_FULLSCREEN: /* These don't close the full screen window */ break; default: gsview_fullscreen_end(); } switch (command) { case IDM_FULLSCREEN: gsview_fullscreen(); return 0; case IDM_OPEN: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_display(); return 0; case IDM_LASTFILE1: case IDM_LASTFILE2: case IDM_LASTFILE3: case IDM_LASTFILE4: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } make_cwd(last_files[command-IDM_LASTFILE1]); gsview_displayfile(last_files[command-IDM_LASTFILE1]); return 0; case IDM_CLOSE: /* doesn't unload DLL */ /* close file */ if (gsdll.open && (gsdll.state != GS_UNINIT)) { PSFILE *tpsfile; if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } tpsfile = (PSFILE *)malloc(sizeof(PSFILE)); if (tpsfile == NULL) return 0; memset((char *)tpsfile, 0, sizeof(PSFILE)); pending.psfile = tpsfile; pending.now = TRUE; if (psfile.name[0] && psfile.dsc==(CDSC *)NULL) pending.abort = TRUE; } else { /* DLL isn't loaded */ if (psfile.file) dfclose(); /* just to make sure */ psfile_free(&psfile); post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_CLOSE_DONE: if (selectname[0] != '\0') { /* pending IDM_SELECT */ PSFILE *tpsfile; tpsfile = gsview_openfile(selectname); if (tpsfile) { psfile = *tpsfile; free(tpsfile); } selectname[0] = '\0'; post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_NEXTHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_NEXT: if (not_open()) return 0; gs_page_skip(1); return 0; case IDM_NEXTSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(page_skip); return 0; case IDM_REDISPLAY: if (dfchanged()) { PSFILE *tpsfile; if (dfchanged() < 0) { gs_addmess("File has been deleted\n"); gsview_command(IDM_CLOSE); pending.unload = TRUE; pending.now = FALSE; return 0; } if (pending.psfile) tpsfile = pending.psfile; /* new file, old file deleted */ else tpsfile = gsview_openfile(psfile.name); if (tpsfile) { tpsfile->pagenum = psfile.pagenum; request_mutex(); pending.psfile = tpsfile; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; pending.now = TRUE; release_mutex(); } } if (not_open()) return 0; if (psfile.dsc==(CDSC *)NULL) { /* don't know where we are so close and reopen */ if (gsdll.state != GS_IDLE) { if (!pending.psfile) { pending.psfile = (PSFILE *)malloc(sizeof(PSFILE)); if (pending.psfile) *pending.psfile = psfile; } pending.psfile->pagenum = pending.pagenum = 1; pending.abort = TRUE; pending.now = TRUE; } } else { pending.pagenum = -1; /* default page number is current page */ if (psfile.dsc->page_order == CDSC_SPECIAL) pending.pagenum = 1; /* restart */ } gsview_unzoom(); pending.now = TRUE; return 0; case IDM_PREVHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_PREV: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-1); return 0; case IDM_PREVSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-page_skip); return 0; case IDM_GOTO: if (not_dsc()) return 0; if (order_is_special()) return 0; if (psfile.dsc->page_count == 0) { gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER); return 0; } nHelpTopic = IDS_TOPICGOTO; { int pagenum; pagenum = psfile.pagenum; if (get_page(&pagenum, FALSE, FALSE)) { gsview_goto_page(pagenum); } } return 0; case IDM_GOBACK: if (not_dsc()) return 0; if (order_is_special()) return 0; history_back(); return 0; case IDM_GOFWD: if (not_open()) return 0; if (psfile.dsc == (CDSC *)NULL) gsview_command(IDM_NEXT); else history_forward(); return 0; case IDM_INFO: show_info(); return 0; case IDM_SELECT: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_select(); return 0; #ifndef VIEWONLY case IDM_PRINT: case IDM_PRINTTOFILE: case IDM_CONVERTFILE: if (psfile.name[0] == '\0') gsview_select(); if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (dfreopen() != 0) return 0; if (command == IDM_PRINTTOFILE) option.print_to_file = TRUE; if (psfile.name[0] != '\0') gsview_print(command == IDM_CONVERTFILE); dfclose(); return 0; case IDM_SPOOL: gsview_spool((char *)NULL, (char *)NULL); return 0; case IDM_SAVEAS: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_saveas(); return 0; case IDM_EXTRACT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (order_is_special()) return 0; if (psfile.name[0] != '\0') gsview_extract(); return 0; case IDM_PSTOEDIT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); (void)order_is_special(); /* warn, but allow it anyway */ if (dfreopen() != 0) return 0; if (psfile.name[0] != '\0') gsview_pstoedit(); dfclose(); return 0; case IDM_TEXTEXTRACT: if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_text_extract(); return 0; case IDM_TEXTEXTRACT_SLOW: gsview_text_extract_slow(); return 0; case IDM_TEXTFIND: gsview_text_find(); return 0; case IDM_TEXTFINDNEXT: gsview_text_findnext(); return 0; case IDM_COPYCLIP: copy_clipboard(); return 0; case IDM_PASTETO: paste_to_file(); return 0; case IDM_CONVERT: clip_convert(); return 0; case IDM_MEASURE: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } measure_show(); return 0; #endif /* !VIEWONLY */ case IDM_GSMESS: gs_showmess(); /* show messages from Ghostscript */ return 0; case IDM_EXIT: if (print_count) { /* Still busy printing. Warn user. */ TCHAR buf[MAXSTR]; load_string(IDS_BUSYPRINTING, buf, sizeof(buf)/sizeof(TCHAR)-1); if (message_box(buf, MB_OKCANCEL) != IDOK) return 0; } post_img_message(WM_CLOSE, 0); return 0; case IDM_CFG: /* Easy configure */ config_wizard(TRUE); return 0; case IDM_GSCOMMAND: /* Advanced configure */ if (install_gsdll() && gsdll.open) pending.unload = TRUE; return 0; case IDM_UNITPT: case IDM_UNITMM: case IDM_UNITINCH: gsview_unit(command); return 0; case IDM_UNITFINE: option.unitfine = !option.unitfine; check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine); return 0; case IDM_LANGMENU+1: case IDM_LANGMENU+2: case IDM_LANGMENU+3: case IDM_LANGMENU+4: case IDM_LANGMENU+5: case IDM_LANGMENU+6: case IDM_LANGMENU+7: case IDM_LANGMENU+8: case IDM_LANGMENU+9: case IDM_LANGMENU+10: case IDM_LANGMENU+11: case IDM_LANGMENU+12: case IDM_LANGMENU+13: case IDM_LANGMENU+14: case IDM_LANGMENU+15: case IDM_LANGMENU+16: case IDM_LANGMENU+17: case IDM_LANGMENU+18: case IDM_LANGMENU+19: gsview_language(command); return 0; case IDM_SAFER: option.safer = !option.safer; check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer); return 0; case IDM_SAVEDIR: option.save_dir = !option.save_dir; check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir); return 0; case IDM_BUTTONSHOW: option.button_show = !option.button_show; check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show); show_buttons(); return 0; case IDM_FITPAGE: option.fit_page = !option.fit_page; check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page); /* should cause WM_SIZE message to be sent */ return 0; case IDM_PSTOTEXTDIS: case IDM_PSTOTEXTNORM: case IDM_PSTOTEXTCORK: check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE); option.pstotext = command - IDM_PSTOTEXTMENU - 1; check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE); return 0; case IDM_AUTOREDISPLAY: option.redisplay = !option.redisplay; check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay); return 0; case IDM_EPSFCLIP: option.epsf_clip = !option.epsf_clip; check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip); gs_resize(); return 0; case IDM_EPSFWARN: option.epsf_warn = !option.epsf_warn; check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn); return 0; case IDM_IGNOREDSC: option.ignore_dsc = !option.ignore_dsc; check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc); if (psfile.name[0]) { if (option.redisplay) gsview_displayfile(psfile.name); else gsview_selectfile(psfile.name); } return 0; case IDM_SHOWBBOX: option.show_bbox = !option.show_bbox; check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox); #ifdef UNIX gtk_widget_draw(img, NULL); #else #ifdef _Windows PostMessage(hwndimg, WM_GSSYNC, 0, 0L); #else if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE)) error_message("error invalidating rect"); if (!WinUpdateWindow(hwnd_bmp)) error_message("error updating window"); #endif #endif return 0; #ifndef VIEWONLY case IDM_PSTOEPS: if (not_open()) return 0; if (psfile.name[0] != '\0') { if (dfreopen() != 0) return 0; ps_to_eps(); dfclose(); } return 0; case IDM_MAKEEPSI: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_interchange(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPST4: case IDM_MAKEEPST6U: case IDM_MAKEEPST6P: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_tiff(command, FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSW: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_metafile(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSU: if (dfreopen() != 0) return 0; make_eps_user(); dfclose(); return 0; case IDM_EXTRACTPS: case IDM_EXTRACTPRE: if (dfreopen() != 0) return 0; extract_doseps(command); dfclose(); return 0; #endif case IDM_SETTINGS: write_profile(); return 0; case IDM_SAVESETTINGS: option.settings = !option.settings; check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings); { char buf[MAXSTR]; PROFILE *prf = profile_open(szIniFile); sprintf(buf, "%d", (int)option.settings); profile_write_string(prf, INISECTION, "SaveSettings", buf); profile_close(prf); } return 0; case IDM_SOUNDS: change_sounds(); return 0; case IDM_AUTOORIENT: case IDM_PORTRAIT: case IDM_LANDSCAPE: case IDM_UPSIDEDOWN: case IDM_SEASCAPE: case IDM_SWAPLANDSCAPE: gsview_orientation(command); return 0; case IDM_DSC_OFF: case IDM_DSC_ERROR: case IDM_DSC_WARN: case IDM_DSC_INFO: check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE); option.dsc_warn = command; check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE); return 0; case IDM_ZOOM: /* called indirectly from Right Mouse Button */ if (not_dsc()) { zoom = FALSE; return 0; } if (order_is_special()) { zoom = FALSE; return 0; } if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) { zoom = FALSE; gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); return 0; } gs_resize(); pending.pagenum = -1; /* default page number is current page */ pending.now = TRUE; return 0; case IDM_MAGPLUS: gs_magnify((float)1.2); return 0; case IDM_MAGMINUS: gs_magnify((float)0.8333); return 0; case IDM_FITWIN: /* fit media to size of current window */ gsview_fitwin(); return 0; case IDM_DISPLAYSETTINGS: display_settings(); return 0; case IDM_MEDIAROTATE: option.media_rotate = !option.media_rotate; check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE, option.media_rotate); zoom = FALSE; gs_resize(); return 0; case IDM_11x17: case IDM_A3: case IDM_A4: case IDM_A5: case IDM_B4: case IDM_B5: case IDM_LEDGER: case IDM_LEGAL: case IDM_LETTER: case IDM_NOTE: case IDM_USERSIZE: case IDM_USERSIZE1: case IDM_USERSIZE2: case IDM_USERSIZE3: case IDM_USERSIZE4: case IDM_USERSIZE5: case IDM_USERSIZE6: case IDM_USERSIZE7: case IDM_USERSIZE8: case IDM_USERSIZE9: case IDM_USERSIZE10: case IDM_USERSIZE11: case IDM_USERSIZE12: case IDM_USERSIZE13: if (command == IDM_USERSIZE) if (!gsview_usersize()) return 0; gsview_media(command); return 0; case IDM_HELPCONTENT: #ifdef UNIX nHelpTopic = IDS_TOPICROOT; get_help(); #else #ifdef _Windows #ifdef USE_HTMLHELP nHelpTopic = IDS_TOPICROOT; get_help(); #else WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL); #endif #else WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L); #endif #endif return 0; case IDM_HELPSEARCH: #ifdef UNIX gs_addmess("IDM_HELPSEARCH: not implemented\n"); #else #ifdef _Windows #ifdef USE_HTMLHELP HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT("")); gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName); #else WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)""); #endif #else WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L); #endif #endif return 0; case IDM_HELPKEYS: nHelpTopic = IDS_TOPICKEYS; get_help(); return 0; case IDM_ABOUT: show_about(); return 0; case IDM_REGISTER: registration_nag(); return 0; } return 0; }