int main(int argc, char *argv[]) { char infilename[FILENAME_MAX], outfilename[FILENAME_MAX]; FILE *input, *output; int c, firstarg=1; int pt=10; /* pt size */ char name[16]; /* Font ID */ char *s; if (firstarg == argc) return -1; /* analyze command line flags */ /* if (*argv[firstarg] == '-') { */ while (firstarg < argc && *argv[firstarg] == '-') { s = argv[firstarg]; s++; while ((c = *s++) != '\0') { if (c == 'n') noscaling=1; else if (c == 'v') verboseflag=1; else if (c == 't') traceflag=1; else if (c == 'r') allowrotate=0; /* don't allow rotation */ else if (c == 's') tripledot=0; /* don't imnplement ... */ else fprintf(errout, "Don't understand %c flag\n", c); } firstarg++; } if (argc < firstarg+1) { /* useage */ printf("%s -v -t -r -s -n <mf-file> <pt-size>\n", argv[0]); printf("e.g. eulerint -v c:\\amsfonts\\mf\\eurmch 10\n"); exit(1); } printf("EULERINT - program for converting METAFONT code\n"); if (argc > firstarg+1) { /* font size specified ? */ s = argv[firstarg+1]; if(sscanf(s, "%d", &pt) < 1) { fprintf(errout, "Don't understand point size: %s\n", s); } } /* get rid of path name */ if ((s = strrchr(argv[firstarg], '\\')) == NULL) { if ((s = strrchr(argv[firstarg], '/')) == NULL) { if ((s = strrchr(argv[firstarg], ':')) == NULL) s = argv[firstarg]; else s++; } else s++; } else s++; strncpy(name, s, 4); /* extract font name */ *(name+4) = '\0'; if(setupfont(pt, name) < 0) { fprintf(errout, "Failed to set up font\n"); exit(3); } strcpy(infilename, argv[firstarg]); extension(infilename, "mf"); if ((input = fopen(infilename, "r")) == NULL) { perror(infilename); exit(3); } /* strcpy(outfilename, argv[firstarg]); */ strcpy(outfilename, name); sprintf(outfilename+4, "%d", pt); forceexten(outfilename, "out"); if ((output = fopen(outfilename, "w")) == NULL) { perror(outfilename); exit(3); } if (traceflag != 0) printf("Files open\n"); setconstants(); if (traceflag != 0) printf("a %lg b %lg c %lg\n", ha, hb, hc); scale = programem / 1000.0; skew = programem / 36.0; /* for eurm font specific */ line = 0; (void) scansidebearings(input); if (verboseflag != 0) { showtables(); printf("Exiting after verbose output of tables\n"); return 0; } rewind(input); line = 0; fprintf(output, "%lg %lg\n", ptsize, 1.0); /* ptsize and scale */ fprintf(output, "%d %d %d %d\n", xll, yll, xur, yur); /* FontBBox */ for(;;) { if (parseeuler(output, input) != 0) break; } if (traceflag != 0) printf("Files will be closed\n"); fclose(input); if(ferror(output) != 0) { perror(outfilename); } else fclose(output); return 0; }
/************************************************************************ * dasm * * - dasm is the application main window. * * - everything the main window does is in this routine (for now) and * * where a response is quick it appears in one of its helper functions * * later in this file, otherwise it has been substantial enough to * * warrant its own file and routines........ * * - this is long * ************************************************************************/ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { HDC hdc; TEXTMETRIC tm; POINT point; lptr scrll; int killcount; g_hMainWnd=hwnd; RECT tmp_rect; switch(message) { case WM_COMMAND: switch(LOWORD(wParam)) { case file_exit: SendMessage(g_hMainWnd,WM_CLOSE,0,0); break; case file_save: savefile_text(hwnd,true,false); break; case get_comment: getcomment(); break; case jump_to: jumpto(); break; case change_oep: changeoep(); break; case save_database: savedb(); break; case load_database: loaddb(); break; case save_asm: savefile_text(hwnd,false,false); break; case block_saveasm: savefile_text(hwnd,false,true); break; case block_savetext: savefile_text(hwnd,true,true); break; case cm_decrypt: decrypterdialog(); break; case file_open: newfile(); break; case view_segment: segviewer(); break; case view_names: namesviewer(); break; case view_imports: importsviewer(); break; case view_exports: exportsviewer(); break; case view_xrefs: xrefsviewer(); break; case make_code: g_scheduler.addtask(user_makecode,priority_userrequest,nlptr,NULL); break; case make_dword: g_scheduler.addtask(user_makedword,priority_userrequest,nlptr,NULL); break; case float_single: g_scheduler.addtask(user_makesingle,priority_userrequest,nlptr,NULL); break; case float_double: g_scheduler.addtask(user_makedouble,priority_userrequest,nlptr,NULL); break; case float_longdouble: g_scheduler.addtask(user_makelongdouble,priority_userrequest,nlptr,NULL); break; case make_word: g_scheduler.addtask(user_makeword,priority_userrequest,nlptr,NULL); break; case make_string: g_scheduler.addtask(user_makestring,priority_userrequest,nlptr,NULL); break; case pascal_string: g_scheduler.addtask(user_pascalstring,priority_userrequest,nlptr,NULL); break; case uc_string: g_scheduler.addtask(user_ucstring,priority_userrequest,nlptr,NULL); break; case up_string: g_scheduler.addtask(user_upstring,priority_userrequest,nlptr,NULL); break; case dos_string: g_scheduler.addtask(user_dosstring,priority_userrequest,nlptr,NULL); break; case general_string: g_scheduler.addtask(user_generalstring,priority_userrequest,nlptr,NULL); break; case argover_dec: g_scheduler.addtask(user_argoverdec,priority_userrequest,nlptr,NULL); break; case arg_single: g_scheduler.addtask(user_argsingle,priority_userrequest,nlptr,NULL); break; case argover_hex: g_scheduler.addtask(user_argoverhex,priority_userrequest,nlptr,NULL); break; case argnegate: g_scheduler.addtask(user_argnegate,priority_userrequest,nlptr,NULL); break; case offset_dseg: g_scheduler.addtask(user_argoveroffsetdseg,priority_userrequest,nlptr,NULL); break; case argover_char: g_scheduler.addtask(user_argoverchar,priority_userrequest,nlptr,NULL); break; case undefine_line: g_scheduler.addtask(user_undefineline,priority_userrequest,nlptr,NULL); break; case undefine_lines: g_scheduler.addtask(user_undefinelines,priority_userrequest,nlptr,NULL); break; case undefine_lines_long: g_scheduler.addtask(user_undefinelines_long,priority_userrequest,nlptr,NULL); break; case block_undefine: g_scheduler.addtask(user_undefineblock,priority_userrequest,nlptr,NULL); break; case block_view: blockview(); break; case block_top: g_scheduler.addtask(user_marktopblock,priority_userrequest,nlptr,NULL); break; case block_bottom: g_scheduler.addtask(user_markbottomblock,priority_userrequest,nlptr,NULL); break; case line_jumpto: g_scheduler.addtask(user_jumpto,priority_userrequest,nlptr,NULL); break; case line_jumptoarg2: g_scheduler.addtask(user_jumptoarg2,priority_userrequest,nlptr,NULL); break; case Name_Location: namelocation(); break; case help_short: DialogBox(g_hInst,MAKEINTRESOURCE(help_shortcuts),hwnd,(DLGPROC)helpshortcuts); break; case help_about: DialogBox(g_hInst,MAKEINTRESOURCE(D_help_about),hwnd,(DLGPROC)habox); break; case Jump_Back: g_scheduler.addtask(user_jumpback,priority_userrequest,nlptr,NULL); break; case main_search: searchengine(); break; case search_again: searchmore(); break; case set_bg_color: g_options.bgcolor=choosecolour(g_options.bgcolor); GetClientRect(g_hMainWnd,&tmp_rect); InvalidateRect(g_hMainWnd,&tmp_rect,true); g_scheduler.addtask(windowupdate,priority_window,nlptr,NULL); break; case set_high_color: g_options.highcolor=choosecolour(g_options.highcolor); GetClientRect(g_hMainWnd,&tmp_rect); InvalidateRect(g_hMainWnd,&tmp_rect,true); g_scheduler.addtask(windowupdate,priority_window,nlptr,NULL); break; case set_text_color: g_options.textcolor=choosecolour(g_options.textcolor); GetClientRect(g_hMainWnd,&tmp_rect); InvalidateRect(g_hMainWnd,&tmp_rect,true); g_scheduler.addtask(windowupdate,priority_window,nlptr,NULL); break; case font_system: g_options.font=systemfont; setupfont(); break; case font_courier: g_options.font=courierfont; setupfont(); break; case font_courier10: g_options.font=courierfont10; setupfont(); break; case font_courier12: g_options.font=courierfont12; setupfont(); break; case font_ansi: g_options.font=ansifont; setupfont(); break; default: return DefWindowProc(hwnd,message,wParam,lParam); } break; case WM_CHAR: if(charinputenabled) switch(wParam) { case 'c': g_scheduler.addtask(user_makecode,priority_userrequest,nlptr,NULL); break; case 'C': g_scheduler.addtask(user_argoverchar,priority_userrequest,nlptr,NULL); break; case 'd': g_scheduler.addtask(user_makedword,priority_userrequest,nlptr,NULL); break; case 'D': g_scheduler.addtask(user_argoverdec,priority_userrequest,nlptr,NULL); break; case 'H': g_scheduler.addtask(user_argoverhex,priority_userrequest,nlptr,NULL); break; case '-': g_scheduler.addtask(user_argnegate,priority_userrequest,nlptr,NULL); break; case 'n': namelocation(); break; case ';': getcomment(); break; case 'o': g_scheduler.addtask(user_argoveroffsetdseg,priority_userrequest,nlptr,NULL); break; case 'p': g_scheduler.addtask(user_pascalstring,priority_userrequest,nlptr,NULL); break; case 's': g_scheduler.addtask(user_makestring,priority_userrequest,nlptr,NULL); break; case 'u': g_scheduler.addtask(user_undefineline,priority_userrequest,nlptr,NULL); break; case 'U': g_scheduler.addtask(user_undefinelines,priority_userrequest,nlptr,NULL); break; case 'w': g_scheduler.addtask(user_makeword,priority_userrequest,nlptr,NULL); break; case 't': g_scheduler.addtask(user_marktopblock,priority_userrequest,nlptr,NULL); break; case 'b': g_scheduler.addtask(user_markbottomblock,priority_userrequest,nlptr,NULL); break; default: break; } break; case WM_LBUTTONDOWN: dio.setpos(HIWORD(lParam)); break; case WM_RBUTTONDOWN: dio.setpos(HIWORD(lParam)); point.x=LOWORD(lParam); point.y=HIWORD(lParam); ClientToScreen(g_hMainWnd,&point); TrackPopupMenu(rmenu,0,point.x,point.y,0,g_hMainWnd,NULL); break; case WM_PAINT: if(!KillThread) DoPaint(hwnd,cxChar,cyChar); else PaintBack(hwnd); ValidateRect(g_hMainWnd,NULL); break; case WM_CLOSE: if(MessageBox(g_hMainWnd,"Are you sure that you want to exit Borg ?\n\rHit Yes To Exit\n\rHit No to Stay","Borg Disassembler", MB_ICONEXCLAMATION|MB_YESNO)==IDNO) break; g_scheduler.stopthread(); g_scheduler.addtask(quitborg,priority_quit,nlptr,NULL); KillThread=true; if(InThread) SetThreadPriority(ThreadHandle,THREAD_PRIORITY_TIME_CRITICAL); DestroyWindow(g_hMainWnd); return 0; case WM_DESTROY: save_reg_entries(); KillThread=true; killcount=0; Sleep(0); SetPriorityClass(ThreadHandle,HIGH_PRIORITY_CLASS); if(InThread) while(TestThread()) { killcount++; if(killcount>2) { // this is a nasty way of getting out. // sometimes the thread just will not exit nicely when its busy. if(TerminateThread(ThreadHandle,1)) { CloseHandle(ThreadHandle); break; } } } DeleteCriticalSection(&g_hCs); PostQuitMessage(0); break; case WM_SIZE: if(wParam==SIZE_MAXIMIZED) g_options.winmax=true; else if (wParam==SIZE_RESTORED) g_options.winmax=false; mainwndsize.top=0; mainwndsize.left=0; mainwndsize.right=LOWORD(lParam); mainwndsize.bottom=HIWORD(lParam); GetWindowRect(hwndStatusBar,&StatusWindowSize); GetWindowRect(g_hMainWnd,&mainwnd); MoveWindow(hwndStatusBar,0,mainwndsize.bottom-StatusWindowSize.bottom+StatusWindowSize.top, mainwndsize.right,StatusWindowSize.bottom-StatusWindowSize.top,true); break; case WM_MOUSEWHEEL: if (GET_KEYSTATE_WPARAM(wParam) & MK_SHIFT) { scrll.assign(0,GET_WHEEL_DELTA_WPARAM(wParam)/WHEEL_DELTA); g_scheduler.addtask(hscroll,priority_userrequest,scrll,NULL); } else { scrll.assign(0,-GET_WHEEL_DELTA_WPARAM(wParam)/WHEEL_DELTA); if(InThread) g_scheduler.addtask(scrolling,priority_userrequest,scrll,NULL); } break; case WM_VSCROLL: switch(LOWORD(wParam)) { case SB_TOP: break; case SB_BOTTOM: break; case SB_LINEUP: scrll.assign(0,-1); if(InThread) g_scheduler.addtask(scrolling,priority_userrequest,scrll,NULL); break; case SB_LINEDOWN: scrll.assign(0,1); if(InThread) g_scheduler.addtask(scrolling,priority_userrequest,scrll,NULL); break; case SB_PAGEUP: scrll.assign(0,-mainwndsize.bottom/cyChar+1); if(InThread) g_scheduler.addtask(scrolling,priority_userrequest,scrll,NULL); break; case SB_PAGEDOWN: scrll.assign(0,mainwndsize.bottom/cyChar-1); if(InThread) g_scheduler.addtask(scrolling,priority_userrequest,scrll,NULL); break; case SB_THUMBPOSITION: scrll.assign(0,HIWORD(wParam)); if(InThread) g_scheduler.addtask(vthumbposition,priority_userrequest,scrll,NULL); break; default: break; } break; case WM_HSCROLL: switch(LOWORD(wParam)) { case SB_LINEUP: scrll.assign(0,-1); g_scheduler.addtask(hscroll,priority_userrequest,scrll,NULL); break; case SB_LINEDOWN: scrll.assign(0,1); g_scheduler.addtask(hscroll,priority_userrequest,scrll,NULL); break; case SB_PAGEUP: scrll.assign(0,-8); g_scheduler.addtask(hscroll,priority_userrequest,scrll,NULL); break; case SB_PAGEDOWN: scrll.assign(0,8); g_scheduler.addtask(hscroll,priority_userrequest,scrll,NULL); break; case SB_THUMBPOSITION: scrll.assign(0,HIWORD(wParam)); if(InThread) g_scheduler.addtask(hthumbposition,priority_userrequest,scrll,NULL); break; default: break; } break; case WM_REPEATNAMEVIEW: namesviewer(); break; case WM_REPEATXREFVIEW: xrefsviewer(); break; // maximises window, used when the reg is read in at the start to maximise // the main window after initialisation of it case WM_MAXITOUT: ShowWindow(g_hMainWnd,SW_MAXIMIZE); break; case WM_CREATE: optionsinit(); hdc=GetDC(hwnd); SelectObject(hdc,GetStockObject(ANSI_FIXED_FONT)); GetTextMetrics(hdc,&tm); cxChar=tm.tmAveCharWidth; cyChar=tm.tmHeight+tm.tmExternalLeading; ReleaseDC(hwnd,hdc); InitializeCriticalSection(&g_hCs); hwndStatusBar=CreateStatusWindow(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CCS_BOTTOM, "No File Loaded",hwnd,2); GetWindowRect(hwndStatusBar,&StatusWindowSize); GetWindowRect(g_hMainWnd,&mainwnd); SetScrollRange(hwnd,SB_VERT,0,VERTSCROLLRANGE,false); SetScrollPos(hwnd,SB_VERT,0,false); KillThread=false; InThread=false; rmenu=LoadMenu(g_hInst,MAKEINTRESOURCE(right_click_menu)); rmenu=GetSubMenu(rmenu,0); load_reg_entries(); setupfont(); break; case WM_KEYDOWN: if(!charinputenabled) break; switch(wParam) { case VK_HOME: SendMessage(hwnd,WM_VSCROLL,SB_TOP,0L); break; case VK_PRIOR: SendMessage(hwnd,WM_VSCROLL,SB_PAGEUP,0L); break; case VK_NEXT: SendMessage(hwnd,WM_VSCROLL,SB_PAGEDOWN,0L); break; case VK_DOWN: SendMessage(hwnd,WM_VSCROLL,SB_LINEDOWN,0L); break; case VK_UP: SendMessage(hwnd,WM_VSCROLL,SB_LINEUP,0L); break; case VK_LEFT: SendMessage(hwnd,WM_HSCROLL,SB_PAGEUP,0L); break; case VK_RIGHT: SendMessage(hwnd,WM_HSCROLL,SB_PAGEDOWN,0L); break; case VK_RETURN: if(GetKeyState(VK_SHIFT)&0x8000) g_scheduler.addtask(user_jumptoarg2,priority_userrequest,nlptr,NULL); else g_scheduler.addtask(user_jumpto,priority_userrequest,nlptr,NULL); break; case VK_ESCAPE: g_scheduler.addtask(user_jumpback,priority_userrequest,nlptr,NULL); break; case VK_F1: DialogBox(g_hInst,MAKEINTRESOURCE(help_shortcuts),hwnd,(DLGPROC)helpshortcuts); break; case VK_F3: searchmore(); break; default: break; } break; default: return DefWindowProc(hwnd,message,wParam,lParam); } return 0; }