diff --git a/src/frontend/wdisp/windisp.c b/src/frontend/wdisp/windisp.c index 877a42f49..6999fd113 100644 --- a/src/frontend/wdisp/windisp.c +++ b/src/frontend/wdisp/windisp.c @@ -32,29 +32,32 @@ #include "ngspice/suffix.h" /* Typen */ -typedef struct { /* Extra window data */ - HWND wnd; /* window */ - HDC hDC; /* Device context of window */ - RECT Area; /* plot area */ - int ColorIndex; /* Index of actual color */ - int PaintFlag; /* 1 with WM_PAINT */ - int FirstFlag; /* 1 before first update */ +typedef struct { /* Extra window data */ + HWND wnd; /* window */ + HDC hDC; /* Device context of window */ + RECT Area; /* plot area */ + int ColorIndex; /* Index of actual color */ + int PaintFlag; /* 1 with WM_PAINT */ + int FirstFlag; /* 1 before first update */ } tWindowData; -typedef tWindowData * tpWindowData; /* pointer to it */ +typedef tWindowData *tpWindowData; /* pointer to it */ + #define pWindowData(g) ((tpWindowData)(g->devdep)) /* forwards */ -LRESULT CALLBACK PlotWindowProc( HWND hwnd, /* window procedure */ -UINT uMsg, WPARAM wParam, LPARAM lParam); -void WPRINT_PrintInit( HWND hwnd); /* Windows printer init */ -void WaitForIdle(void); /* wait until no more events */ +LRESULT CALLBACK PlotWindowProc(HWND hwnd, /* window procedure */ + UINT uMsg, WPARAM wParam, LPARAM lParam); +void WPRINT_PrintInit(HWND hwnd); /* Windows printer init */ +void WaitForIdle(void); /* wait until no more events */ + static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy); -static LRESULT HcpyPlot( HWND hwnd); -static LRESULT HcpyPlotBW( HWND hwnd); -static LRESULT PrintPlot( HWND hwnd); -static LRESULT PrintInit( HWND hwnd); -//static void RealClose(void); +static LRESULT HcpyPlot(HWND hwnd); +static LRESULT HcpyPlotBW(HWND hwnd); +static LRESULT PrintPlot(HWND hwnd); +static LRESULT PrintInit(HWND hwnd); +//static void RealClose(void); /* externals */ + extern HINSTANCE hInst; /* application instance */ extern int WinLineWidth; /* width of text window */ extern HWND swString; /* string input window of main window */ @@ -65,6 +68,7 @@ extern void com_hardcopy(wordlist *wl); /* defines */ #define RAD_TO_DEG (180.0 / M_PI) + #ifndef M_LN10 #define M_LN10 2.30258509299404568402 #endif @@ -75,7 +79,7 @@ extern void com_hardcopy(wordlist *wl); static int IsRegistered = 0; /* 1 if window class is registered */ #define NumWinColors 23 /* predefined colors */ static COLORREF ColorTable[NumWinColors]; /* color memory */ -static char * WindowName = "Spice Plot"; /* window name */ +static char *WindowName = "Spice Plot"; /* window name */ static WNDCLASS TheWndClass; /* Plot-window class */ static HFONT PlotFont; /* which font */ #define ID_DRUCKEN 0xEFF0 /* System Menue: print */ @@ -84,10 +88,10 @@ static HFONT PlotFont; /* which font */ #define ID_HARDCOPY_BW 0xEFB0 /* System Menue: hardcopy b&w*/ #define ID_MASK 0xFFF0; /* System-Menue: mask */ -static char * STR_DRUCKEN = "Printer..."; /* System menue strings */ -static char * STR_DRUCKEINR = "Printer setup..."; -static char * STR_HARDCOPY = "Postscript file, color"; -static char * STR_HARDCOPY_BW = "Postscript file, b&w"; +static char *STR_DRUCKEN = "Printer..."; /* System menue strings */ +static char *STR_DRUCKEINR = "Printer setup..."; +static char *STR_HARDCOPY = "Postscript file, color"; +static char *STR_HARDCOPY_BW = "Postscript file, b&w"; static bool isblack = TRUE; /* background color of plot is black */ static bool isblackold = TRUE; static int linewidth = 0; /* linewidth of grid and plot */ @@ -107,460 +111,473 @@ WIN_Init() does not yet open a window, this happens only in WIN_NewViewport() int WIN_Init(void) { - char colorstring[BSIZE_SP]; - - /* Initialization of display descriptor */ - dispdev->width = GetSystemMetrics( SM_CXSCREEN); - dispdev->height = GetSystemMetrics( SM_CYSCREEN); - dispdev->numlinestyles = 5; /* see implications in WinPrint! */ - dispdev->numcolors = NumWinColors; - - /* always, user may have set color0 to white */ - /* get background color information from spinit, only "white" - is recognized as a suitable option! */ - if (cp_getvar("color0", CP_STRING, colorstring)) { - if (cieq(colorstring, "white")) isblack = FALSE; - else isblack = TRUE; - } - /* get linewidth information from spinit */ - if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) - linewidth = 0; - if (linewidth < 0) linewidth = 0; - - /* only for the first time: */ - if (!IsRegistered) { - - isblackold = isblack; - - /* get linewidth information from spinit - if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) - linewidth = 0; - if (linewidth < 0) linewidth = 0; */ - - /* Initialize colors */ - if (isblack) { - ColorTable[0] = RGB( 0, 0, 0); /* black = background */ - ColorTable[1] = RGB(255,255,255); /* white = text and grid */ - } - else { - ColorTable[0] = RGB(255,255,255); /* white = background */ - ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */ - } - - ColorTable[2] = RGB( 0,255, 0); /* green = first line */ - ColorTable[3] = RGB(255, 0, 0); /* red */ - ColorTable[4] = RGB( 0, 0,255); /* blue */ - ColorTable[5] = RGB(255,255, 0); /* yellow */ - ColorTable[6] = RGB(255, 0,255); /* violett */ - ColorTable[7] = RGB( 0,255,255); /* azur */ - ColorTable[8] = RGB(255,128, 0); /* orange */ - ColorTable[9] = RGB(128, 64, 0); /* brown */ - ColorTable[10]= RGB(128, 0,255); /* light violett */ - ColorTable[11]= RGB(255,128,128); /* pink */ - /* 2. color bank (with different line style */ - if (isblack) - ColorTable[12]= RGB(255,255,255); /* white */ - else - ColorTable[12]= RGB( 0, 0, 0); /* black */ - ColorTable[13]= RGB( 0,255, 0); /* green */ - ColorTable[14]= RGB(255, 0, 0); /* red */ - ColorTable[15]= RGB( 0, 0,255); /* blue */ - ColorTable[16]= RGB(255,255, 0); /* yellow */ - ColorTable[17]= RGB(255, 0,255); /* violett */ - ColorTable[18]= RGB( 0,255,255); /* azur */ - ColorTable[19]= RGB(255,128, 0); /* orange */ - ColorTable[20]= RGB(128, 64, 0); /* brown */ - ColorTable[21]= RGB(128, 0,255); /* light violett */ - ColorTable[22]= RGB(255,128,128); /* pink */ - - /* Ansii fixed font */ - PlotFont = GetStockFont( ANSI_FIXED_FONT); - - /* register window class */ - TheWndClass.lpszClassName = WindowName; - TheWndClass.hInstance = hInst; - TheWndClass.lpfnWndProc = PlotWindowProc; - TheWndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - TheWndClass.lpszMenuName = NULL; - TheWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); - if (isblack) - TheWndClass.hbrBackground = GetStockObject( BLACK_BRUSH); - else - TheWndClass.hbrBackground = GetStockObject( WHITE_BRUSH); - TheWndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(2)); - TheWndClass.cbClsExtra = 0; - TheWndClass.cbWndExtra = sizeof(GRAPH *); - if (!RegisterClass(&TheWndClass)) return 1; - } + char colorstring[BSIZE_SP]; + + /* Initialization of display descriptor */ + dispdev->width = GetSystemMetrics(SM_CXSCREEN); + dispdev->height = GetSystemMetrics(SM_CYSCREEN); + dispdev->numlinestyles = 5; /* see implications in WinPrint! */ + dispdev->numcolors = NumWinColors; + + /* always, user may have set color0 to white */ + /* get background color information from spinit, only "white" + is recognized as a suitable option! */ + if (cp_getvar("color0", CP_STRING, colorstring)) { + if (cieq(colorstring, "white")) isblack = FALSE; + else isblack = TRUE; + } + + /* get linewidth information from spinit */ + if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) + linewidth = 0; + if (linewidth < 0) linewidth = 0; + + /* only for the first time: */ + if (!IsRegistered) { + + isblackold = isblack; + + /* get linewidth information from spinit + if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth)) + linewidth = 0; + if (linewidth < 0) linewidth = 0; */ + + /* Initialize colors */ + if (isblack) { + ColorTable[0] = RGB( 0, 0, 0); /* black = background */ + ColorTable[1] = RGB(255, 255, 255); /* white = text and grid */ + } + else { + ColorTable[0] = RGB(255, 255, 255); /* white = background */ + ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */ + } + + ColorTable[2] = RGB( 0, 255, 0); /* green = first line */ + ColorTable[3] = RGB(255, 0, 0); /* red */ + ColorTable[4] = RGB( 0, 0, 255); /* blue */ + ColorTable[5] = RGB(255, 255, 0); /* yellow */ + ColorTable[6] = RGB(255, 0, 255); /* violett */ + ColorTable[7] = RGB( 0, 255, 255); /* azur */ + ColorTable[8] = RGB(255, 128, 0); /* orange */ + ColorTable[9] = RGB(128, 64, 0); /* brown */ + ColorTable[10] = RGB(128, 0, 255); /* light violett */ + ColorTable[11] = RGB(255, 128, 128); /* pink */ + + /* 2. color bank (with different line style */ + if (isblack) + ColorTable[12] = RGB(255, 255, 255); /* white */ + else + ColorTable[12] = RGB( 0, 0, 0); /* black */ + + ColorTable[13] = RGB( 0, 255, 0); /* green */ + ColorTable[14] = RGB(255, 0, 0); /* red */ + ColorTable[15] = RGB( 0, 0, 255); /* blue */ + ColorTable[16] = RGB(255, 255, 0); /* yellow */ + ColorTable[17] = RGB(255, 0, 255); /* violett */ + ColorTable[18] = RGB( 0, 255, 255); /* azur */ + ColorTable[19] = RGB(255, 128, 0); /* orange */ + ColorTable[20] = RGB(128, 64, 0); /* brown */ + ColorTable[21] = RGB(128, 0, 255); /* light violett */ + ColorTable[22] = RGB(255, 128, 128); /* pink */ + + /* Ansii fixed font */ + PlotFont = GetStockFont(ANSI_FIXED_FONT); + + /* register window class */ + TheWndClass.lpszClassName = WindowName; + TheWndClass.hInstance = hInst; + TheWndClass.lpfnWndProc = PlotWindowProc; + TheWndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + TheWndClass.lpszMenuName = NULL; + TheWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); + + if (isblack) + TheWndClass.hbrBackground = GetStockObject(BLACK_BRUSH); + else + TheWndClass.hbrBackground = GetStockObject(WHITE_BRUSH); + + TheWndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(2)); + TheWndClass.cbClsExtra = 0; + TheWndClass.cbWndExtra = sizeof(GRAPH *); + + if (!RegisterClass(&TheWndClass)) return 1; + } /* not first time */ - else if (isblackold != isblack) { - if (isblack) { - ColorTable[0] = RGB( 0, 0, 0); /* black = background */ - ColorTable[1] = RGB(255,255,255); /* white = text and grid */ - } - else { - ColorTable[0] = RGB(255,255,255); /* white = background */ - ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */ - } - if (isblack) - ColorTable[12]= RGB(255,255,255); /* white */ - else - ColorTable[12]= RGB( 0, 0, 0); /* black */ - - isblackold=isblack; - } - IsRegistered = 1; - - /* ready */ - return (0); + else if (isblackold != isblack) { + if (isblack) { + ColorTable[0] = RGB( 0, 0, 0); /* black = background */ + ColorTable[1] = RGB(255, 255, 255); /* white = text and grid */ + } + else { + ColorTable[0] = RGB(255, 255, 255); /* white = background */ + ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */ + } + if (isblack) + ColorTable[12] = RGB(255, 255, 255); /* white */ + else + ColorTable[12] = RGB( 0, 0, 0); /* black */ + + isblackold = isblack; + } + IsRegistered = 1; + + /* ready */ + return (0); } + /* get pointer to graph */ /* (attach to window) */ -static GRAPH * pGraph( HWND hwnd) +static GRAPH *pGraph(HWND hwnd) { - return (GRAPH *) GetWindowLongPtr( hwnd, 0); + return (GRAPH *) GetWindowLongPtr(hwnd, 0); } + /* return line style for plotting */ -static int LType( int ColorIndex) +static int LType(int ColorIndex) { - if (ColorIndex >= 12) - return PS_DOT; - else - return PS_SOLID; + if (ColorIndex >= 12) + return PS_DOT; + else + return PS_SOLID; } - - /* postscript hardcopy from a plot window */ + + +/* postscript hardcopy from a plot window */ /* called by SystemMenue / Postscript hardcopy */ -static LRESULT HcpyPlot( HWND hwnd) +static LRESULT HcpyPlot(HWND hwnd) { int colorval = isblack? 0 : 1; NG_IGNORE(hwnd); cp_vset("hcopypscolor", CP_NUM, &colorval); - com_hardcopy(NULL); + com_hardcopy(NULL); return 0; } - -static LRESULT HcpyPlotBW( HWND hwnd) + + +static LRESULT HcpyPlotBW(HWND hwnd) { - int bgcolor; - NG_IGNORE(hwnd); - if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor)) - cp_remvar("hcopypscolor"); - com_hardcopy(NULL); - return 0; + int bgcolor; + NG_IGNORE(hwnd); + if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor)) + cp_remvar("hcopypscolor"); + com_hardcopy(NULL); + return 0; } - + /* print a plot window */ /* called by SystemMenue / Print */ -static LRESULT PrintPlot( HWND hwnd) +static LRESULT PrintPlot(HWND hwnd) { - GRAPH * graph; - GRAPH * temp; + GRAPH *graph; + GRAPH *temp; - /* get pointer to graph */ - graph = pGraph( hwnd); - if (!graph) return 0; + /* get pointer to graph */ + graph = pGraph(hwnd); + if (!graph) return 0; - /* switch to printer */ - /* (results in WPRINT_Init()) */ - if (DevSwitch("WinPrint")) return 0; + /* switch to printer */ + /* (results in WPRINT_Init()) */ + if (DevSwitch("WinPrint")) return 0; - /* Cursor = wait */ - SetCursor( LoadCursor( NULL, IDC_WAIT)); + /* Cursor = wait */ + SetCursor(LoadCursor(NULL, IDC_WAIT)); - /* copy graph */ - temp = CopyGraph(graph); - if (!temp) goto PrintEND; + /* copy graph */ + temp = CopyGraph(graph); + if (!temp) goto PrintEND; - /* add to the copy the new printer data */ - if (NewViewport(temp)) goto PrintEND2; + /* add to the copy the new printer data */ + if (NewViewport(temp)) goto PrintEND2; - /* make correction to placement of grid (copy from gr_init) */ - temp->viewportxoff = temp->fontwidth * 8; - temp->viewportyoff = temp->fontheight * 4; + /* make correction to placement of grid (copy from gr_init) */ + temp->viewportxoff = temp->fontwidth * 8; + temp->viewportyoff = temp->fontheight * 4; - /* print the graph */ - gr_resize(temp); + /* print the graph */ + gr_resize(temp); -PrintEND2: - /* delete temporary graph */ - DestroyGraph(temp->graphid); + PrintEND2: + /* delete temporary graph */ + DestroyGraph(temp->graphid); -PrintEND: - /* switch back to screen */ - DevSwitch(NULL); + PrintEND: + /* switch back to screen */ + DevSwitch(NULL); - /* Cursor = normal */ - SetCursor( LoadCursor( NULL, IDC_ARROW)); + /* Cursor = normal */ + SetCursor(LoadCursor(NULL, IDC_ARROW)); - return 0; + return 0; } + /* initialze printer */ -static LRESULT PrintInit( HWND hwnd) +static LRESULT PrintInit(HWND hwnd) { - /* hand over to printer module */ - WPRINT_PrintInit(hwnd); - return 0; + /* hand over to printer module */ + WPRINT_PrintInit(hwnd); + return 0; } + /* window procedure */ -LRESULT CALLBACK PlotWindowProc( HWND hwnd, - UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK PlotWindowProc(HWND hwnd, + UINT uMsg, WPARAM wParam, LPARAM lParam) { - static int x0,y0,xep,yep; - int xe, ye, prevmix; - static double fx0,fy0; - double fxe, fye; - double angle; - char buf[BSIZE_SP]; - char buf2[128]; - char *t; - HDC hdc; - HPEN OldPen; - HPEN NewPen; - - switch (uMsg) { - case WM_SYSCOMMAND: - { - /* test command */ - WPARAM cmd = wParam & ID_MASK; - switch(cmd) { - case ID_DRUCKEN: return PrintPlot( hwnd); - case ID_DRUCKEINR: return PrintInit( hwnd); - case ID_HARDCOPY: return HcpyPlot( hwnd); - case ID_HARDCOPY_BW: return HcpyPlotBW( hwnd); - } - } - goto WIN_DEFAULT; - - case WM_LBUTTONDOWN: - { - GRAPH * gr = pGraph( hwnd); - xep = x0 = LOWORD (lParam); - yep = y0 = HIWORD (lParam); - /* generate x,y data from grid coordinates */ - WIN_ScreentoData(gr, x0, y0, &fx0, &fy0); - } - goto WIN_DEFAULT; - - case WM_MOUSEMOVE: - /* left mouse button: connect coordinate pair by dashed pair of x, y lines */ - if (wParam & MK_LBUTTON) - { - hdc = GetDC (hwnd) ; - if (isblack) - prevmix = SetROP2(hdc, R2_XORPEN); - else - prevmix = SetROP2(hdc, R2_NOTXORPEN); - /* Create white dashed pen */ - NewPen = CreatePen( LType(12), 0, ColorTable[1] ); - OldPen = SelectObject(hdc, NewPen); - /* draw lines with previous coodinates -> delete old line because of XOR */ - MoveToEx (hdc, x0, y0, NULL) ; - LineTo (hdc, x0, yep) ; - LineTo (hdc, xep, yep); - /* get new end point */ - xe = LOWORD (lParam); - ye = HIWORD (lParam); - /* draw new lines */ - MoveToEx (hdc, x0, y0, NULL) ; - LineTo (hdc, x0, ye) ; - LineTo (hdc, xe, ye); - /* restore standard color mix */ - SetROP2(hdc, prevmix); - OldPen = SelectObject(hdc, OldPen); - DeleteObject( NewPen); - ReleaseDC (hwnd, hdc) ; - /* restore new to previous coordinates */ - yep = ye; - xep = xe; - } - /* right mouse button: create white (black) dashed box */ - else if (wParam & MK_RBUTTON){ - hdc = GetDC (hwnd) ; - if (isblack) - prevmix = SetROP2(hdc, R2_XORPEN); - else - prevmix = SetROP2(hdc, R2_NOTXORPEN); - /* Create white (black) dashed pen */ - NewPen = CreatePen( LType(12), 0, ColorTable[1] ); - OldPen = SelectObject(hdc, NewPen); - /* draw box with previous coodinates -> delete old lines because of XOR */ - MoveToEx (hdc, x0, y0, NULL) ; - LineTo (hdc, x0, yep) ; - LineTo (hdc, xep, yep); - LineTo (hdc, xep, y0) ; - LineTo (hdc, x0, y0); - /* get new end point */ - xe = LOWORD (lParam); - ye = HIWORD (lParam); - /* draw new box */ - MoveToEx (hdc, x0, y0, NULL) ; - LineTo (hdc, x0, ye) ; - LineTo (hdc, xe, ye); - LineTo (hdc, xe, y0) ; - LineTo (hdc, x0, y0); - /* restore standard color mix */ - SetROP2(hdc, prevmix); - OldPen = SelectObject(hdc, OldPen); - DeleteObject( NewPen); - ReleaseDC (hwnd, hdc) ; - /* restore new to previous coordinates */ - yep = ye; - xep = xe; - } - goto WIN_DEFAULT; - - /* get final coordinates upon left mouse up */ - /* calculate and print out the data */ - case WM_LBUTTONUP: - { - GRAPH * gr = pGraph( hwnd); - InvalidateRect (hwnd, NULL, TRUE) ; - xe = LOWORD (lParam); - ye = HIWORD (lParam); - WIN_ScreentoData(gr, xe, ye, &fxe, &fye); - - /* print it out */ - if (xe == x0 && ye == y0) { /* only one location */ - fprintf(stdout, "\nx0 = %g, y0 = %g\n", fx0, fy0); - if (gr->grid.gridtype == GRID_POLAR - || gr->grid.gridtype == GRID_SMITH - || gr->grid.gridtype == GRID_SMITHGRID) - { - angle = RAD_TO_DEG * atan2( fy0, fx0 ); - fprintf(stdout, "r0 = %g, a0 = %g\n", - hypot(fx0, fy0), - (angle>0)?angle:360.0+angle); - } - } else { - /* need to print info about two points */ - fprintf(stdout, "\nx0 = %g, y0 = %g x1 = %g, y1 = %g\n", - fx0, fy0, fxe, fye); - fprintf(stdout, "dx = %g, dy = %g\n", fxe-fx0, fye - fy0); - if (xe != x0 && ye != y0) { - /* add slope info if both dx and dy are zero, */ - /* because otherwise either dy/dx or dx/dy is zero, */ - /* which is uninteresting */ - - fprintf(stdout, "dy/dx = %g dx/dy = %g\n", - (fye-fy0)/(fxe-fx0), (fxe-fx0)/(fye-fy0)); - } - } - SetFocus( swString); - } - goto WIN_DEFAULT; - - /* get starting coordinates upon right mouse button down */ - case WM_RBUTTONDOWN: - { - GRAPH * gr = pGraph( hwnd); - x0 = xep = LOWORD (lParam); - y0 = yep = HIWORD (lParam); - WIN_ScreentoData(gr, x0, y0, &fx0, &fy0); - } - goto WIN_DEFAULT; - /* get final coordinates upon right mouse button up */ - /* copy xlimit, ylimit command into buf */ - /* start plot loop with argument buf */ - case WM_RBUTTONUP: - { - GRAPH * gr = pGraph( hwnd); - InvalidateRect (hwnd, NULL, TRUE) ; - xe = LOWORD (lParam); - ye = HIWORD (lParam); - /* do nothing if mouse curser is not moved in both x and y */ - if ((xe == x0) || (ye == y0)) { - SetFocus( swString); - goto WIN_DEFAULT; - } - WIN_ScreentoData(gr, xe, ye, &fxe, &fye); - - strncpy(buf2, gr->plotname, sizeof(buf2)); - if ((t = strchr(buf2, ':')) != NULL) - *t = '\0'; - - if (!eq(plot_cur->pl_typename, buf2)) { - (void) sprintf(buf, + static int x0, y0, xep, yep; + int xe, ye, prevmix; + static double fx0, fy0; + double fxe, fye; + double angle; + char buf[BSIZE_SP]; + char buf2[128]; + char *t; + HDC hdc; + HPEN OldPen; + HPEN NewPen; + + switch (uMsg) { + case WM_SYSCOMMAND: + { + /* test command */ + WPARAM cmd = wParam & ID_MASK; + switch(cmd) { + case ID_DRUCKEN: return PrintPlot(hwnd); + case ID_DRUCKEINR: return PrintInit(hwnd); + case ID_HARDCOPY: return HcpyPlot(hwnd); + case ID_HARDCOPY_BW: return HcpyPlotBW(hwnd); + } + } + goto WIN_DEFAULT; + + case WM_LBUTTONDOWN: + { + GRAPH *gr = pGraph(hwnd); + xep = x0 = LOWORD (lParam); + yep = y0 = HIWORD (lParam); + /* generate x,y data from grid coordinates */ + WIN_ScreentoData(gr, x0, y0, &fx0, &fy0); + } + goto WIN_DEFAULT; + + case WM_MOUSEMOVE: + /* left mouse button: connect coordinate pair by dashed pair of x, y lines */ + if (wParam & MK_LBUTTON) + { + hdc = GetDC(hwnd); + if (isblack) + prevmix = SetROP2(hdc, R2_XORPEN); + else + prevmix = SetROP2(hdc, R2_NOTXORPEN); + /* Create white dashed pen */ + NewPen = CreatePen(LType(12), 0, ColorTable[1]); + OldPen = SelectObject(hdc, NewPen); + /* draw lines with previous coodinates -> delete old line because of XOR */ + MoveToEx (hdc, x0, y0, NULL); + LineTo (hdc, x0, yep); + LineTo (hdc, xep, yep); + /* get new end point */ + xe = LOWORD (lParam); + ye = HIWORD (lParam); + /* draw new lines */ + MoveToEx (hdc, x0, y0, NULL); + LineTo (hdc, x0, ye); + LineTo (hdc, xe, ye); + /* restore standard color mix */ + SetROP2(hdc, prevmix); + OldPen = SelectObject(hdc, OldPen); + DeleteObject(NewPen); + ReleaseDC (hwnd, hdc); + /* restore new to previous coordinates */ + yep = ye; + xep = xe; + } + /* right mouse button: create white (black) dashed box */ + else if (wParam & MK_RBUTTON) { + hdc = GetDC (hwnd); + if (isblack) + prevmix = SetROP2(hdc, R2_XORPEN); + else + prevmix = SetROP2(hdc, R2_NOTXORPEN); + /* Create white (black) dashed pen */ + NewPen = CreatePen(LType(12), 0, ColorTable[1]); + OldPen = SelectObject(hdc, NewPen); + /* draw box with previous coodinates -> delete old lines because of XOR */ + MoveToEx (hdc, x0, y0, NULL); + LineTo (hdc, x0, yep); + LineTo (hdc, xep, yep); + LineTo (hdc, xep, y0); + LineTo (hdc, x0, y0); + /* get new end point */ + xe = LOWORD (lParam); + ye = HIWORD (lParam); + /* draw new box */ + MoveToEx (hdc, x0, y0, NULL); + LineTo (hdc, x0, ye); + LineTo (hdc, xe, ye); + LineTo (hdc, xe, y0); + LineTo (hdc, x0, y0); + /* restore standard color mix */ + SetROP2(hdc, prevmix); + OldPen = SelectObject(hdc, OldPen); + DeleteObject(NewPen); + ReleaseDC (hwnd, hdc); + /* restore new to previous coordinates */ + yep = ye; + xep = xe; + } + goto WIN_DEFAULT; + + /* get final coordinates upon left mouse up */ + /* calculate and print out the data */ + case WM_LBUTTONUP: + { + GRAPH *gr = pGraph(hwnd); + InvalidateRect (hwnd, NULL, TRUE); + xe = LOWORD (lParam); + ye = HIWORD (lParam); + WIN_ScreentoData(gr, xe, ye, &fxe, &fye); + + /* print it out */ + if (xe == x0 && ye == y0) { /* only one location */ + fprintf(stdout, "\nx0 = %g, y0 = %g\n", fx0, fy0); + if (gr->grid.gridtype == GRID_POLAR + || gr->grid.gridtype == GRID_SMITH + || gr->grid.gridtype == GRID_SMITHGRID) + { + angle = RAD_TO_DEG * atan2(fy0, fx0); + fprintf(stdout, "r0 = %g, a0 = %g\n", + hypot(fx0, fy0), + (angle > 0) ? angle : 360.0 + angle); + } + } else { + /* need to print info about two points */ + fprintf(stdout, "\nx0 = %g, y0 = %g x1 = %g, y1 = %g\n", + fx0, fy0, fxe, fye); + fprintf(stdout, "dx = %g, dy = %g\n", fxe-fx0, fye - fy0); + if (xe != x0 && ye != y0) { + /* add slope info if both dx and dy are zero, */ + /* because otherwise either dy/dx or dx/dy is zero, */ + /* which is uninteresting */ + + fprintf(stdout, "dy/dx = %g dx/dy = %g\n", + (fye - fy0) / (fxe - fx0), (fxe - fx0) / (fye - fy0)); + } + } + SetFocus(swString); + } + goto WIN_DEFAULT; + + /* get starting coordinates upon right mouse button down */ + case WM_RBUTTONDOWN: + { + GRAPH *gr = pGraph(hwnd); + x0 = xep = LOWORD (lParam); + y0 = yep = HIWORD (lParam); + WIN_ScreentoData(gr, x0, y0, &fx0, &fy0); + } + goto WIN_DEFAULT; + + /* get final coordinates upon right mouse button up */ + /* copy xlimit, ylimit command into buf */ + /* start plot loop with argument buf */ + case WM_RBUTTONUP: + { + GRAPH *gr = pGraph(hwnd); + InvalidateRect (hwnd, NULL, TRUE); + xe = LOWORD (lParam); + ye = HIWORD (lParam); + /* do nothing if mouse curser is not moved in both x and y */ + if ((xe == x0) || (ye == y0)) { + SetFocus(swString); + goto WIN_DEFAULT; + } + WIN_ScreentoData(gr, xe, ye, &fxe, &fye); + + strncpy(buf2, gr->plotname, sizeof(buf2)); + if ((t = strchr(buf2, ':')) != NULL) + *t = '\0'; + + if (!eq(plot_cur->pl_typename, buf2)) { + (void) sprintf(buf, // "setplot %s; %s xlimit %e %e ylimit %e %e; setplot $curplot\n", - "setplot %s; %s xlimit %e %e ylimit %e %e\n", - buf2, gr->commandline, fx0, fxe, fy0, fye); - } else { - (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n", - gr->commandline, fx0, fxe, fy0, fye); - } - - (void) cp_evloop(buf); - SetFocus( swString); - } - goto WIN_DEFAULT; - - case WM_CLOSE: /* close window */ - { - GRAPH * g = pGraph( hwnd); - - if (g) { - /* if g equals currentgraph, reset currentgraph. */ - if (g == currentgraph) - currentgraph = NULL; - DestroyGraph(g->graphid); - } - } - goto WIN_DEFAULT; - - case WM_PAINT: /* replot window (e.g. after Resize) */ - { - PAINTSTRUCT ps; - GRAPH * g; - tpWindowData wd; - HDC saveDC; /* the DC from BeginPaint is different... */ - HDC newDC; - - /* has to happen */ - newDC = BeginPaint( hwnd, &ps); - g = pGraph( hwnd); - if (g) { + "setplot %s; %s xlimit %e %e ylimit %e %e\n", + buf2, gr->commandline, fx0, fxe, fy0, fye); + } else { + (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n", + gr->commandline, fx0, fxe, fy0, fye); + } + + (void) cp_evloop(buf); + SetFocus(swString); + } + goto WIN_DEFAULT; + + case WM_CLOSE: /* close window */ + { + GRAPH *g = pGraph(hwnd); + + if (g) { + /* if g equals currentgraph, reset currentgraph. */ + if (g == currentgraph) + currentgraph = NULL; + DestroyGraph(g->graphid); + } + } + goto WIN_DEFAULT; + + case WM_PAINT: /* replot window (e.g. after Resize) */ + { + PAINTSTRUCT ps; + GRAPH *g; + tpWindowData wd; + HDC saveDC; /* the DC from BeginPaint is different... */ + HDC newDC; + + /* has to happen */ + newDC = BeginPaint(hwnd, &ps); + g = pGraph(hwnd); + if (g) { wd = pWindowData(g); if (wd) { - if (!wd->PaintFlag && !wd->FirstFlag) { - /* avoid recursive call */ - wd->PaintFlag = 1; - /* get window sizes */ - GetClientRect( hwnd, &(wd->Area)); - g->absolute.width = wd->Area.right; - g->absolute.height = wd->Area.bottom; - /* switch DC */ - saveDC = wd->hDC; - wd->hDC = newDC; - - /* plot anew */ - { - GRAPH *tmp = currentgraph; - currentgraph = g; - gr_resize(g); - currentgraph = tmp; - } - - /* switch DC */ - wd->hDC = saveDC; - /* ready */ - wd->PaintFlag = 0; - } - } - } - /* finish */ - EndPaint( hwnd, &ps); - } - return 0; - - default: -WIN_DEFAULT: - return DefWindowProc( hwnd, uMsg, wParam, lParam); - } + if (!wd->PaintFlag && !wd->FirstFlag) { + /* avoid recursive call */ + wd->PaintFlag = 1; + /* get window sizes */ + GetClientRect(hwnd, &(wd->Area)); + g->absolute.width = wd->Area.right; + g->absolute.height = wd->Area.bottom; + /* switch DC */ + saveDC = wd->hDC; + wd->hDC = newDC; + + /* plot anew */ + { + GRAPH *tmp = currentgraph; + currentgraph = g; + gr_resize(g); + currentgraph = tmp; + } + + /* switch DC */ + wd->hDC = saveDC; + /* ready */ + wd->PaintFlag = 0; + } + } + } + /* finish */ + EndPaint(hwnd, &ps); + } + return 0; + + default: + WIN_DEFAULT: + return DefWindowProc(hwnd, uMsg, wParam, lParam); + } } @@ -571,282 +588,299 @@ WIN_DEFAULT: ******************************************************************************/ -int WIN_NewViewport( GRAPH * graph) +int WIN_NewViewport(GRAPH *graph) { - int i; - HWND window; - HDC dc; - TEXTMETRIC tm; - tpWindowData wd; - HMENU sysmenu; - - /* test the parameters */ - if (!graph) return 1; - - /* initialize if not yet done */ - if (WIN_Init() != 0) { - externalerror("Can't initialize GDI."); - return(1); - } - - /* allocate device dependency info */ - wd = calloc(1, sizeof(tWindowData)); - if (!wd) return 1; - graph->devdep = wd; - - /* Create the window */ - i = GetSystemMetrics( SM_CYSCREEN) / 3; - window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW, - 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); - if (!window) return 1; - - /* change the background color of all windows (both new and already plotted) - by assessing the registered window class */ - if (isblack) - SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(BLACK_BRUSH)); - else - SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH)); - - - wd->wnd = window; - SetWindowLongPtr(window, 0, (LONG_PTR)graph); - - /* show window */ - ShowWindow( window, SW_SHOWNORMAL); - - /* get the mask */ - GetClientRect( window, &(wd->Area)); - - /* get the DC */ - dc = GetDC( window); - wd->hDC = dc; - - /* set the Color Index */ - wd->ColorIndex = 0; - - /* still no flag */ - wd->PaintFlag = 0; - wd->FirstFlag = 1; - - /* modify system menue */ - sysmenu = GetSystemMenu( window, FALSE); - AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL); - AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN); - AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR); - AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY); - AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW); - - /* set default parameters of DC */ - SetBkColor( dc, ColorTable[0]); - SetBkMode( dc, TRANSPARENT ); - - /* set font */ - SelectObject( dc, PlotFont); - - /* query the font parameters */ - if (GetTextMetrics( dc, &tm)) { - graph->fontheight = tm.tmHeight; - graph->fontwidth = tm.tmAveCharWidth; - } - - /* set viewport parameters */ - graph->viewport.height = wd->Area.bottom; - graph->viewport.width = wd->Area.right; - - /* set absolute parameters */ - graph->absolute.xpos = 0; - graph->absolute.ypos = 0; - graph->absolute.width = wd->Area.right; - graph->absolute.height = wd->Area.bottom; - - /* wait until the window is really there */ - WaitForIdle(); - - /* ready */ - return(0); + int i; + HWND window; + HDC dc; + TEXTMETRIC tm; + tpWindowData wd; + HMENU sysmenu; + + /* test the parameters */ + if (!graph) return 1; + + /* initialize if not yet done */ + if (WIN_Init() != 0) { + externalerror("Can't initialize GDI."); + return(1); + } + + /* allocate device dependency info */ + wd = calloc(1, sizeof(tWindowData)); + if (!wd) return 1; + + graph->devdep = wd; + + /* Create the window */ + i = GetSystemMetrics(SM_CYSCREEN) / 3; + window = CreateWindow(WindowName, graph->plotname, WS_OVERLAPPEDWINDOW, + 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); + if (!window) return 1; + + /* change the background color of all windows (both new and already plotted) + by assessing the registered window class */ + if (isblack) + SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(BLACK_BRUSH)); + else + SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH)); + + + wd->wnd = window; + SetWindowLongPtr(window, 0, (LONG_PTR)graph); + + /* show window */ + ShowWindow(window, SW_SHOWNORMAL); + + /* get the mask */ + GetClientRect(window, &(wd->Area)); + + /* get the DC */ + dc = GetDC(window); + wd->hDC = dc; + + /* set the Color Index */ + wd->ColorIndex = 0; + + /* still no flag */ + wd->PaintFlag = 0; + wd->FirstFlag = 1; + + /* modify system menue */ + sysmenu = GetSystemMenu(window, FALSE); + AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL); + AppendMenu(sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN); + AppendMenu(sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR); + AppendMenu(sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY); + AppendMenu(sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW); + + /* set default parameters of DC */ + SetBkColor(dc, ColorTable[0]); + SetBkMode(dc, TRANSPARENT ); + + /* set font */ + SelectObject(dc, PlotFont); + + /* query the font parameters */ + if (GetTextMetrics(dc, &tm)) { + graph->fontheight = tm.tmHeight; + graph->fontwidth = tm.tmAveCharWidth; + } + + /* set viewport parameters */ + graph->viewport.height = wd->Area.bottom; + graph->viewport.width = wd->Area.right; + + /* set absolute parameters */ + graph->absolute.xpos = 0; + graph->absolute.ypos = 0; + graph->absolute.width = wd->Area.right; + graph->absolute.height = wd->Area.bottom; + + /* wait until the window is really there */ + WaitForIdle(); + + /* ready */ + return(0); } + /****************************************************************************** WIN_Close is essentially the counterpart to WIN_Init. unfortunately it might -happen, that WIN_Close is called during plotting, because one wants to switch +happen, that WIN_Close is called during plotting, because one wants to switch to the printer. Therefore WIN_Close is not allowed to do anything, cancelling of the structures occurs at program termination. ******************************************************************************/ int WIN_Close(void) { - return (0); + return (0); } + + /* static void RealClose(void) { - // delete window class - if (IsRegistered) { - if (TheWndClass.hIcon) { - DestroyIcon( TheWndClass.hIcon); - TheWndClass.hIcon = NULL; - } - UnregisterClass( WindowName, hInst); - IsRegistered = FALSE; - } + // delete window class + if (IsRegistered) { + if (TheWndClass.hIcon) { + DestroyIcon(TheWndClass.hIcon); + TheWndClass.hIcon = NULL; + } + UnregisterClass(WindowName, hInst); + IsRegistered = FALSE; + } } - */ +*/ + + int WIN_Clear(void) { - tpWindowData wd; - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; + tpWindowData wd; + + if (!currentgraph) return 0; - /* this is done by the window itself */ - if (!wd->PaintFlag) /* not necessary with WM_PAINT */ - SendMessage( wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0); + wd = pWindowData(currentgraph); + if (!wd) return 0; - return 0; + /* this is done by the window itself */ + if (!wd->PaintFlag) /* not necessary with WM_PAINT */ + SendMessage(wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0); + + return 0; } int WIN_DrawLine(int x1, int y1, int x2, int y2) { - tpWindowData wd; - HPEN OldPen; - HPEN NewPen; - - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; - - MoveToEx(wd->hDC, x1, wd->Area.bottom - y1, NULL); - NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] ); - OldPen = SelectObject(wd->hDC, NewPen); - LineTo(wd->hDC, x2, wd->Area.bottom - y2); - OldPen = SelectObject(wd->hDC, OldPen); - DeleteObject( NewPen); - - return (0); + tpWindowData wd; + HPEN OldPen; + HPEN NewPen; + + if (!currentgraph) return 0; + + wd = pWindowData(currentgraph); + if (!wd) return 0; + + MoveToEx(wd->hDC, x1, wd->Area.bottom - y1, NULL); + NewPen = CreatePen(LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex]); + OldPen = SelectObject(wd->hDC, NewPen); + LineTo(wd->hDC, x2, wd->Area.bottom - y2); + OldPen = SelectObject(wd->hDC, OldPen); + DeleteObject(NewPen); + + return (0); } int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta) - /* - * Notes: - * Draws an arc of and center at (x0,y0) beginning at - * angle theta (in rad) and ending at theta + delta_theta - */ +/* + * Notes: + * Draws an arc of and center at (x0,y0) beginning at + * angle theta (in rad) and ending at theta + delta_theta + */ { - tpWindowData wd; - HPEN OldPen; - HPEN NewPen; - int left, right, top, bottom; - int xs, ys, xe, ye; - int yb; - int direction; - double r; - double dx0; - double dy0; - - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; - - direction = AD_COUNTERCLOCKWISE; - if (delta_theta < 0) { - theta = theta + delta_theta; - delta_theta = - delta_theta; - direction = AD_CLOCKWISE; - } - SetArcDirection( wd->hDC, direction); - - /* some geometric considerations in advance */ - yb = wd->Area.bottom; - left = x0 - radius; - right = x0 + radius; - top = y0 + radius; - bottom = y0 - radius; - - r = radius; - dx0 = x0; - dy0 = y0; - xs = (int)(dx0 + (r * cos(theta))); - ys = (int)(dy0 + (r * sin(theta))); - xe = (int)(dx0 + (r * cos(theta + delta_theta))); - ye = (int)(dy0 + (r * sin(theta + delta_theta))); - - /* plot */ - NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] ); - OldPen = SelectObject(wd->hDC, NewPen); - Arc( wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); - OldPen = SelectObject(wd->hDC, OldPen); - DeleteObject( NewPen); - - return 0; + tpWindowData wd; + HPEN OldPen; + HPEN NewPen; + int left, right, top, bottom; + int xs, ys, xe, ye; + int yb; + int direction; + double r; + double dx0; + double dy0; + + if (!currentgraph) return 0; + + wd = pWindowData(currentgraph); + if (!wd) return 0; + + direction = AD_COUNTERCLOCKWISE; + if (delta_theta < 0) { + theta = theta + delta_theta; + delta_theta = - delta_theta; + direction = AD_CLOCKWISE; + } + SetArcDirection(wd->hDC, direction); + + /* some geometric considerations in advance */ + yb = wd->Area.bottom; + left = x0 - radius; + right = x0 + radius; + top = y0 + radius; + bottom = y0 - radius; + + r = radius; + dx0 = x0; + dy0 = y0; + xs = (int)(dx0 + (r * cos(theta))); + ys = (int)(dy0 + (r * sin(theta))); + xe = (int)(dx0 + (r * cos(theta + delta_theta))); + ye = (int)(dy0 + (r * sin(theta + delta_theta))); + + /* plot */ + NewPen = CreatePen(LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex]); + OldPen = SelectObject(wd->hDC, NewPen); + Arc(wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); + OldPen = SelectObject(wd->hDC, OldPen); + DeleteObject(NewPen); + + return 0; } + + /* -int WIN_Text_old( char * text, int x, int y, int degrees) +int WIN_Text_old(char * text, int x, int y, int degrees) { - tpWindowData wd; - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; + tpWindowData wd; + + if (!currentgraph) return 0; - SetTextColor( wd->hDC, ColorTable[wd->ColorIndex]); - TextOut( wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, strlen(text)); + wd = pWindowData(currentgraph); + if (!wd) return 0; - return (0); + SetTextColor(wd->hDC, ColorTable[wd->ColorIndex]); + TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, strlen(text)); + + return (0); } */ -int WIN_Text( char * text, int x, int y) + +int WIN_Text(char * text, int x, int y) { - tpWindowData wd; - HFONT hfont; - LOGFONT lf; - - int CentiDegrees = 0; - - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; - - lf.lfHeight = (int) (1.1 * currentgraph->fontheight) ; - lf.lfWidth = 0 ; - lf.lfEscapement = CentiDegrees ; - lf.lfOrientation = CentiDegrees ; - lf.lfWeight = 500 ; - lf.lfItalic = 0 ; - lf.lfUnderline = 0 ; - lf.lfStrikeOut = 0 ; - lf.lfCharSet = 0 ; - lf.lfOutPrecision = 0 ; - lf.lfClipPrecision = 0 ; - lf.lfQuality = 0 ; - lf.lfPitchAndFamily = 0 ; - - /* set up fonts */ - if (!cp_getvar("wfont", CP_STRING, lf.lfFaceName)) { - (void) lstrcpy(lf.lfFaceName, DEF_FONTW); - } - if (!cp_getvar("wfont_size", CP_NUM, &(lf.lfHeight))) { - lf.lfHeight = (int) (1.1 * currentgraph->fontheight) ; - } - -// lstrcpy (lf.lfFaceName, "Courier"/*"Times New Roman"*/) ; - - hfont = CreateFontIndirect (&lf); - SelectObject(wd->hDC, hfont); - - SetTextColor( wd->hDC, ColorTable[wd->ColorIndex]); - TextOut( wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text)); - - DeleteObject(SelectObject(wd->hDC, GetStockObject(SYSTEM_FONT))); - - return (0); + tpWindowData wd; + HFONT hfont; + LOGFONT lf; + + int CentiDegrees = 0; + + if (!currentgraph) return 0; + + wd = pWindowData(currentgraph); + if (!wd) return 0; + + lf.lfHeight = (int) (1.1 * currentgraph->fontheight); + lf.lfWidth = 0; + lf.lfEscapement = CentiDegrees; + lf.lfOrientation = CentiDegrees; + lf.lfWeight = 500; + lf.lfItalic = 0; + lf.lfUnderline = 0; + lf.lfStrikeOut = 0; + lf.lfCharSet = 0; + lf.lfOutPrecision = 0; + lf.lfClipPrecision = 0; + lf.lfQuality = 0; + lf.lfPitchAndFamily = 0; + + /* set up fonts */ + if (!cp_getvar("wfont", CP_STRING, lf.lfFaceName)) { + (void) lstrcpy(lf.lfFaceName, DEF_FONTW); + } + + if (!cp_getvar("wfont_size", CP_NUM, &(lf.lfHeight))) { + lf.lfHeight = (int) (1.1 * currentgraph->fontheight); + } + +// lstrcpy (lf.lfFaceName, "Courier"/*"Times New Roman"*/); + + hfont = CreateFontIndirect (&lf); + SelectObject(wd->hDC, hfont); + + SetTextColor(wd->hDC, ColorTable[wd->ColorIndex]); + TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text)); + + DeleteObject(SelectObject(wd->hDC, GetStockObject(SYSTEM_FONT))); + + return (0); } int WIN_DefineColor(int colorid, double red, double green, double blue) { - /* nothing */ + /* nothing */ NG_IGNORE(colorid); NG_IGNORE(red); NG_IGNORE(green); @@ -854,90 +888,104 @@ int WIN_DefineColor(int colorid, double red, double green, double blue) return (0); } + int WIN_DefineLinestyle(int num, int mask) { - /* nothing */ + /* nothing */ NG_IGNORE(num); NG_IGNORE(mask); return (0); } + int WIN_SetLinestyle(int style) { - /* nothing */ + /* nothing */ NG_IGNORE(style); return (0); } -int WIN_SetColor( int color) + +int WIN_SetColor(int color) { - tpWindowData wd; - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; + tpWindowData wd; + + if (!currentgraph) return 0; - wd->ColorIndex = color % NumWinColors; + wd = pWindowData(currentgraph); + if (!wd) return 0; - return (0); + wd->ColorIndex = color % NumWinColors; + + return (0); } + int WIN_Update(void) { - tpWindowData wd; - if (!currentgraph) return 0; - wd = pWindowData(currentgraph); - if (!wd) return 0; - - /* After the first run of Update() */ - /* FirstFlag again handles WM_PAINT messages. */ - /* This prevents double painting during displaying the window. */ - wd->FirstFlag = 0; - return 0; + tpWindowData wd; + + if (!currentgraph) return 0; + + wd = pWindowData(currentgraph); + if (!wd) return 0; + + /* After the first run of Update() */ + /* FirstFlag again handles WM_PAINT messages. */ + /* This prevents double painting during displaying the window. */ + wd->FirstFlag = 0; + return 0; } + + /* int WIN_DiagramReady(void) { - return 0; + return 0; } */ + + void RemoveWindow(GRAPH* dgraph) { - tpWindowData wd; - wd = pWindowData(dgraph); - if (wd) - SendMessage(wd->wnd, WM_CLOSE, (WPARAM) wd->hDC, 0); + tpWindowData wd; + + wd = pWindowData(dgraph); + if (wd) + SendMessage(wd->wnd, WM_CLOSE, (WPARAM) wd->hDC, 0); } + /* Function borrowed from x11.c */ static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy) { - double lmin, lmax; - - if (graph->grid.gridtype == GRID_XLOG - || graph->grid.gridtype == GRID_LOGLOG) - { - lmin = log10(graph->datawindow.xmin); - lmax = log10(graph->datawindow.xmax); - *fx = exp(((x - graph->viewportxoff) - * (lmax - lmin) / graph->viewport.width + lmin) - * M_LN10); - } else { - *fx = (x - graph->viewportxoff) * graph->aspectratiox + - graph->datawindow.xmin; - } - - if (graph->grid.gridtype == GRID_YLOG - || graph->grid.gridtype == GRID_LOGLOG) - { - lmin = log10(graph->datawindow.ymin); - lmax = log10(graph->datawindow.ymax); - *fy = exp(((graph->absolute.height - y - graph->viewportxoff) - * (lmax - lmin) / graph->viewport.height + lmin) - * M_LN10); - } else { - *fy = ((graph->absolute.height - y) - graph->viewportyoff) - * graph->aspectratioy + graph->datawindow.ymin; - } + double lmin, lmax; + + if (graph->grid.gridtype == GRID_XLOG + || graph->grid.gridtype == GRID_LOGLOG) + { + lmin = log10(graph->datawindow.xmin); + lmax = log10(graph->datawindow.xmax); + *fx = exp(((x - graph->viewportxoff) + * (lmax - lmin) / graph->viewport.width + lmin) + * M_LN10); + } else { + *fx = (x - graph->viewportxoff) * graph->aspectratiox + + graph->datawindow.xmin; + } + + if (graph->grid.gridtype == GRID_YLOG + || graph->grid.gridtype == GRID_LOGLOG) + { + lmin = log10(graph->datawindow.ymin); + lmax = log10(graph->datawindow.ymax); + *fy = exp(((graph->absolute.height - y - graph->viewportxoff) + * (lmax - lmin) / graph->viewport.height + lmin) + * M_LN10); + } else { + *fy = ((graph->absolute.height - y) - graph->viewportyoff) + * graph->aspectratioy + graph->datawindow.ymin; + } } diff --git a/src/include/ngspice/wstdio.h b/src/include/ngspice/wstdio.h index aa84ed0b6..dfa106786 100644 --- a/src/include/ngspice/wstdio.h +++ b/src/include/ngspice/wstdio.h @@ -1,13 +1,14 @@ /* I/O Redirection for Spice 3F4 under Win32s Autor: Wolfgang Muees Stand: 21.05.95 -*/ + */ #ifndef ngspice_WSTDIO_H #define ngspice_WSTDIO_H -#include /* original definitions */ -#undef getc /* old macros removed */ +#include /* original definitions */ + +#undef getc /* old macros removed */ #undef putc #undef ungetc #undef getchar @@ -15,90 +16,90 @@ #undef feof #undef ferror -/* -----------------------------------------------------------------*/ +/* ----------------------------------------------------------------- */ + +int win_x_fclose(FILE *stream); +int win_x_fflush(FILE *stream); +int win_x_fgetc(FILE *stream); +int win_x_fgetpos(FILE *stream, fpos_t *pos); +char *win_x_fgets(char *s, int n, FILE *stream); +int win_x_fprintf(FILE *stream, const char *format, ...); +int win_x_fputc(int c, FILE *stream); +int win_x_fputs(const char *s, FILE *stream); +size_t win_x_fread(void *ptr, size_t size, size_t n, FILE *stream); +FILE *win_x_freopen(const char *path, const char *mode, FILE *stream); +int win_x_fscanf(FILE *stream, const char *format, ...); +int win_x_fseek(FILE *stream, long offset, int whence); +int win_x_fsetpos(FILE *stream, const fpos_t*pos); +long win_x_ftell(FILE *stream); +size_t win_x_fwrite(const void *ptr, size_t size, size_t n, FILE *stream); +char *win_x_gets(char *s); +void win_x_perror(const char *s); +int win_x_printf(const char *format, ...); +int win_x_puts(const char *s); +int win_x_scanf(const char *format, ...); +int win_x_ungetc(int c, FILE *stream); +int win_x_vfprintf(FILE *stream, const char *format, void *arglist); +/* int win_x_vfscanf(FILE *stream, const char *format, void *arglist); */ +int win_x_vprintf(const char *format, void *arglist); +/* int win_x_vscanf(const char *format, void *arglist); */ -int win_x_fclose( FILE * stream); -int win_x_fflush( FILE * stream); -int win_x_fgetc( FILE * stream); -int win_x_fgetpos( FILE * stream, fpos_t * pos); -char * win_x_fgets(char * s, int n, FILE * stream); -int win_x_fprintf(FILE * stream, const char * format, ...); -int win_x_fputc(int c, FILE * stream); -int win_x_fputs(const char * s, FILE * stream); -size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream); -FILE * win_x_freopen(const char * path, const char * mode, FILE * stream); -int win_x_fscanf(FILE * stream, const char * format, ...); -int win_x_fseek(FILE * stream, long offset, int whence); -int win_x_fsetpos(FILE * stream, const fpos_t*pos); -long win_x_ftell(FILE * stream); -size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream); -char * win_x_gets(char * s); -void win_x_perror(const char * s); -int win_x_printf(const char * format, ...); -int win_x_puts(const char * s); -int win_x_scanf(const char * format, ...); -int win_x_ungetc(int c, FILE * stream); -int win_x_vfprintf(FILE * stream, const char * format, void * arglist); -/*int win_x_vfscanf(FILE * stream, const char * format, void * arglist);*/ -int win_x_vprintf(const char * format, void * arglist); -/*int win_x_vscanf(const char * format, void * arglist); */ -#ifdef _MSC_VER +#ifdef _MSC_VER #if _MSC_VER < 1500 /* VC++ 6.0, VC++ 2005 */ -_CRTIMP int __cdecl read(int fd, void * buf, unsigned int n); +_CRTIMP int __cdecl read(int fd, void *buf, unsigned int n); #else /* VC++ 2008 */ -_CRTIMP int __cdecl read(int fd, _Out_bytecap_(_MaxCharCount) void * buf, _In_ unsigned int n); +_CRTIMP int __cdecl read(int fd, _Out_bytecap_(_MaxCharCount) void *buf, _In_ unsigned int n); #endif #else -int win_x_read(int fd, char * buf, int n); +int win_x_read(int fd, char *buf, int n); #endif -int win_x_getc(FILE * fp); + +int win_x_getc(FILE *fp); int win_x_getchar(void); int win_x_putchar(const int c); -int win_x_putc(const int c, FILE * fp); -int win_x_feof(FILE * fp); -int win_x_ferror(FILE * fp); +int win_x_putc(const int c, FILE *fp); +int win_x_feof(FILE *fp); +int win_x_ferror(FILE *fp); int win_x_fputchar(int c); -/* ---------------------------------------------------------------*/ - -#define fclose win_x_fclose -#define fflush win_x_fflush -#define fgetc win_x_fgetc -#define fgetpos win_x_fgetpos -#define fgets win_x_fgets -#define fprintf win_x_fprintf -#define fputc win_x_fputc -#define fputs win_x_fputs -#define fread win_x_fread -/* #define freopen win_x_freopen hvogt 10.05.2000 */ -#define fscanf win_x_fscanf -#define fseek win_x_fseek -#define fsetpos win_x_fsetpos -#define ftell win_x_ftell -#define fwrite win_x_fwrite -#define gets win_x_gets -#define perror win_x_perror -#define printf win_x_printf -#define puts win_x_puts -#define scanf win_x_scanf -#define ungetc win_x_ungetc -#define vfprintf win_x_vfprintf -/*#define vfscanf win_x_vfscanf*/ -#define vprintf win_x_vprintf -/*#define vscanf win_x_vscanf*/ -#define read win_x_read -#define getc win_x_getc -#define getchar win_x_getchar -#define putchar win_x_putchar -#define putc win_x_putc -#define feof win_x_feof -#define ferror win_x_ferror -#define fputchar win_x_fputchar +/* --------------------------------------------------------------- */ +#define fclose win_x_fclose +#define fflush win_x_fflush +#define fgetc win_x_fgetc +#define fgetpos win_x_fgetpos +#define fgets win_x_fgets +#define fprintf win_x_fprintf +#define fputc win_x_fputc +#define fputs win_x_fputs +#define fread win_x_fread +/* #define freopen win_x_freopen hvogt 10.05.2000 */ +#define fscanf win_x_fscanf +#define fseek win_x_fseek +#define fsetpos win_x_fsetpos +#define ftell win_x_ftell +#define fwrite win_x_fwrite +#define gets win_x_gets +#define perror win_x_perror +#define printf win_x_printf +#define puts win_x_puts +#define scanf win_x_scanf +#define ungetc win_x_ungetc +#define vfprintf win_x_vfprintf +/* #define vfscanf win_x_vfscanf */ +#define vprintf win_x_vprintf +/* #define vscanf win_x_vscanf */ +#define read win_x_read +#define getc win_x_getc +#define getchar win_x_getchar +#define putchar win_x_putchar +#define putc win_x_putc +#define feof win_x_feof +#define ferror win_x_ferror +#define fputchar win_x_fputchar /*----------------------------------------------------------------------------*/ #endif - diff --git a/src/winmain.c b/src/winmain.c index 1683bf3fa..76550e7cf 100644 --- a/src/winmain.c +++ b/src/winmain.c @@ -1,10 +1,12 @@ /* Main program for ngspice under Windows OS - Autor: Wolfgang Muees - Stand: 28.10.97 - Autor: Holger Vogt - Stand: 17.10.2009 + Autor: Wolfgang Muees + Stand: 28.10.97 + Autor: Holger Vogt + Stand: 17.10.2009 */ + #include "ngspice/config.h" + #ifdef HAS_WINGUI #define STRICT // strict type checking @@ -24,7 +26,7 @@ #include #include #include -#include "ngspice/bool.h" /* bool defined as unsigned char */ +#include "ngspice/bool.h" /* bool defined as unsigned char */ #include "misc/misc_time.h" /* timediff */ /* Constants */ @@ -50,7 +52,7 @@ #define QUIT_BUTTON_ID 2 /* Types */ -typedef char SBufLine[SBufSize+1]; // Eingabezeile +typedef char SBufLine[SBufSize + 1]; // Eingabezeile /* Global variables */ HINSTANCE hInst; /* Application instance */ @@ -71,12 +73,12 @@ static WNDCLASS twTextClass; /* Class definition for the text static LPCTSTR twClassName = "SPICE_TEXT_BOX"; /* Class name for the text box */ static LPCTSTR twWindowName = "TextOut"; /* text box name */ static size_t TBufEnd = 0; /* Pointer to \0 */ -static char TBuffer [TBufSize+1]; /* Text buffer */ +static char TBuffer[TBufSize + 1]; /* Text buffer */ static SBufLine SBuffer; /* Input buffer */ static WNDCLASS swStringClass; /* Class definition of string window */ static LPCTSTR swClassName = "SPICE_STR_IN"; /* Class name of text input */ static LPCTSTR swWindowName = "StringIn"; /* Window name */ -static char CRLF [] = { CR, LF, SE} ; /* CR/LF */ +static char CRLF[] = {CR, LF, SE}; /* CR/LF */ static WNDCLASS hwElementClass; /* Class definition of status displays */ static LPCTSTR hwElementClassName = "ElementClass"; static LPCTSTR hwSourceWindowName = "SourceDisplay"; @@ -105,44 +107,51 @@ static void HistoryInit(void) int i; HistIndex = 0; HistPtr = 0; - for ( i = 0; i < HistSize; i++) + for (i = 0; i < HistSize; i++) HistBuffer[i][0] = SE; } + /* Delete first line of buffer, all other lines move one down */ static void HistoryScroll(void) { - memmove( &(HistBuffer[0]), &(HistBuffer[1]), sizeof(SBufLine) * (HistSize-1)); + memmove(&(HistBuffer[0]), &(HistBuffer[1]), sizeof(SBufLine) * (HistSize-1)); HistBuffer[HistSize-1][0] = SE; if (HistIndex) HistIndex--; if (HistPtr) HistPtr--; } + /* Enter new input line into history buffer */ -static void HistoryEnter( char * newLine) +static void HistoryEnter(char *newLine) { if (!newLine || !*newLine) return; + if (HistPtr == HistSize) HistoryScroll(); - strcpy( HistBuffer[HistPtr], newLine); + + strcpy(HistBuffer[HistPtr], newLine); HistPtr++; HistIndex = HistPtr; } + // Mit dem Index eine Zeile zurueckgehen und den dort stehenden Eintrag zurueckgeben -static char * HistoryGetPrev(void) +static char *HistoryGetPrev(void) { if (HistIndex) HistIndex--; return &(HistBuffer[HistIndex][0]); } + // Mit dem Index eine Zeile vorgehen und den dort stehenden Eintrag zurueckgeben -static char * HistoryGetNext(void) +static char *HistoryGetNext(void) { if (HistIndex < HistPtr) HistIndex++; if (HistIndex == HistPtr) return ""; //HistIndex--; return &(HistBuffer[HistIndex][0]); } + // ---------------------------------------------------------- // Warte, bis keine Messages mehr zu bearbeiten sind @@ -150,12 +159,13 @@ void WaitForIdle(void) { MSG m; // arbeite alle Nachrichten ab - while ( PeekMessage( &m, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage( &m); - DispatchMessage( &m); + while (PeekMessage(&m, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&m); + DispatchMessage(&m); } } + // ---------------------------------------------------------- // Warte, bis keine Messages mehr zu bearbeiten sind, @@ -164,103 +174,111 @@ static void WaitForMessage(void) { MSG m; // arbeite alle Nachrichten ab - while ( PeekMessage( &m, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage( &m); - DispatchMessage( &m); + while (PeekMessage(&m, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&m); + DispatchMessage(&m); } WaitMessage(); } + // ------------------------------------------------------------- // Loeschen des Stringfensters static void ClearInput(void) { // Darstellen - Edit_SetText( swString, ""); + Edit_SetText(swString, ""); } // -------------------------------------------------------- /* New text to Source file window */ -void SetSource( char * Name) +void SetSource(char *Name) { if (hwSource) { - SetWindowText( hwSource, Name); - InvalidateRgn( hwSource, NULL, TRUE); + SetWindowText(hwSource, Name); + InvalidateRgn(hwSource, NULL, TRUE); } } + // ----------------------------------------------------------- /* New progress report into analysis window. Update only every DELTATIME milliseconds */ + #define DELTATIME 150 -void SetAnalyse( - char * Analyse, /*in: analysis type */ - int DecaPercent /*in: 10 times the progress [%]*/ - /*HWND hwAnalyse, in: global handle to analysis window */ -) { - static int OldPercent = -2; /* Previous progress value */ - static char OldAn[128]; /* Previous analysis type */ - char s[128], t[128]; /* outputs to analysis window and task bar */ - static struct timeb timebefore; /* previous time stamp */ - struct timeb timenow; /* actual time stamp */ - int diffsec, diffmillisec; /* differences actual minus prev. time stamp */ - - WaitForIdle(); - if ((DecaPercent == OldPercent) && !strcmp(OldAn, Analyse)) return; - /* get actual time */ - ftime(&timenow); - timediff(&timenow, &timebefore, &diffsec, &diffmillisec); - - /* info every one percent of progress: - actual time, progress, - to catch linearity of progress of simulation */ - if (ft_ngdebug && !strcmp(Analyse, "tran")) - if ((int)((double)DecaPercent/10.) > (int)((double)OldPercent/10.)) { - win_x_printf("%3.1f%% percent progress after %4.2f seconds.\n", (double)DecaPercent/10., seconds()); - } - OldPercent = DecaPercent; - /* output only into hwAnalyse window and if time elapsed is larger than - DELTATIME given value, or if analysis has changed, else return */ - if (hwAnalyse && ((diffsec > 0) || (diffmillisec > DELTATIME) || strcmp(OldAn, Analyse))) { + +void SetAnalyse( + char *Analyse, /* in: analysis type */ + int DecaPercent /* in: 10 times the progress [%]*/ + /* HWND hwAnalyse, in: global handle to analysis window */ + ) { + static int OldPercent = -2; /* Previous progress value */ + static char OldAn[128]; /* Previous analysis type */ + char s[128], t[128]; /* outputs to analysis window and task bar */ + static struct timeb timebefore; /* previous time stamp */ + struct timeb timenow; /* actual time stamp */ + int diffsec, diffmillisec; /* differences actual minus prev. time stamp */ + + WaitForIdle(); + + if ((DecaPercent == OldPercent) && !strcmp(OldAn, Analyse)) return; + + /* get actual time */ + ftime(&timenow); + timediff(&timenow, &timebefore, &diffsec, &diffmillisec); + + /* info every one percent of progress: + actual time, progress, + to catch linearity of progress of simulation */ + if (ft_ngdebug && !strcmp(Analyse, "tran")) + if ((int)((double)DecaPercent/10.) > (int)((double)OldPercent/10.)) { + win_x_printf("%3.1f%% percent progress after %4.2f seconds.\n", (double)DecaPercent/10., seconds()); + } + + OldPercent = DecaPercent; + /* output only into hwAnalyse window and if time elapsed is larger than + DELTATIME given value, or if analysis has changed, else return */ + if (hwAnalyse && ((diffsec > 0) || (diffmillisec > DELTATIME) || strcmp(OldAn, Analyse))) { if (DecaPercent < 0) { - sprintf( s, "--ready--"); - sprintf( t, "%s", PACKAGE_STRING); - } - else if (DecaPercent == 0) { - sprintf( s, "%s", Analyse); - sprintf( t, "%s %s", PACKAGE_STRING, Analyse); - } - else if (!strcmp(Analyse, "shooting")) { - sprintf( s, "%s: %d", Analyse, DecaPercent); - sprintf( t, "%s %d", PACKAGE_STRING, DecaPercent); - } - else { - sprintf( s, "%s: %3.1f%%", Analyse, (double)DecaPercent/10.); - sprintf( t, "%s %3.1f%%", PACKAGE_STRING, (double)DecaPercent/10.); - } - timebefore.dstflag = timenow.dstflag; - timebefore.millitm = timenow.millitm; - timebefore.time = timenow.time; - timebefore.timezone = timenow.timezone; - /* info when previous analysis period has finished */ - if (strcmp(OldAn, Analyse)) { - if (ft_ngdebug && (strcmp(OldAn, ""))) - win_x_printf("%s finished after %4.2f seconds.\n", OldAn, seconds()); - strncpy(OldAn, Analyse, 127); - } - - SetWindowText( hwAnalyse, s); - SetWindowText( hwMain, t); - InvalidateRgn( hwAnalyse, NULL, TRUE); - InvalidateRgn( hwMain, NULL, TRUE); - } - UpdateWindow(hwAnalyse); - UpdateWindow(hwMain); + sprintf(s, "--ready--"); + sprintf(t, "%s", PACKAGE_STRING); + } + else if (DecaPercent == 0) { + sprintf(s, "%s", Analyse); + sprintf(t, "%s %s", PACKAGE_STRING, Analyse); + } + else if (!strcmp(Analyse, "shooting")) { + sprintf(s, "%s: %d", Analyse, DecaPercent); + sprintf(t, "%s %d", PACKAGE_STRING, DecaPercent); + } + else { + sprintf(s, "%s: %3.1f%%", Analyse, (double)DecaPercent/10.); + sprintf(t, "%s %3.1f%%", PACKAGE_STRING, (double)DecaPercent/10.); + } + timebefore.dstflag = timenow.dstflag; + timebefore.millitm = timenow.millitm; + timebefore.time = timenow.time; + timebefore.timezone = timenow.timezone; + /* info when previous analysis period has finished */ + if (strcmp(OldAn, Analyse)) { + if (ft_ngdebug && (strcmp(OldAn, ""))) + win_x_printf("%s finished after %4.2f seconds.\n", OldAn, seconds()); + strncpy(OldAn, Analyse, 127); + } + + SetWindowText(hwAnalyse, s); + SetWindowText(hwMain, t); + InvalidateRgn(hwAnalyse, NULL, TRUE); + InvalidateRgn(hwMain, NULL, TRUE); + } + UpdateWindow(hwAnalyse); + UpdateWindow(hwMain); } + // --------------------------------------------------------------- // Anpassen des Scrollers im Textfenster @@ -270,19 +288,22 @@ static void AdjustScroller(void) int LineCount; int FirstLine; int MyFirstLine; - LineCount = Edit_GetLineCount( twText); - FirstLine = Edit_GetFirstVisibleLine( twText); + LineCount = Edit_GetLineCount(twText); + FirstLine = Edit_GetFirstVisibleLine(twText); MyFirstLine = LineCount - VisibleRows; + if (MyFirstLine < 0 ) MyFirstLine = 0; - Edit_Scroll( twText, MyFirstLine - FirstLine, 0); + + Edit_Scroll(twText, MyFirstLine - FirstLine, 0); // Das wars DoUpdate = FALSE; } + // Loeschen einer Zeile im Textbuffer static void _DeleteFirstLine(void) { - char * cp = strchr( TBuffer, LF); + char *cp = strchr(TBuffer, LF); if (!cp) { // Buffer leeren TBufEnd = 0; @@ -291,15 +312,16 @@ static void _DeleteFirstLine(void) } cp++; TBufEnd -= (size_t)(cp - TBuffer); - memmove( TBuffer, cp, TBufEnd); + memmove(TBuffer, cp, TBufEnd); TBuffer[TBufEnd] = SE; } + // Anfuegen eines chars an den TextBuffer -static void AppendChar( char c) +static void AppendChar(char c) { // Textbuffer nicht zu grosz werden lassen - while ((TBufEnd+4) >= TBufSize) + while ((TBufEnd + 4) >= TBufSize) _DeleteFirstLine(); // Zeichen anfuegen TBuffer[TBufEnd++] = c; @@ -307,11 +329,12 @@ static void AppendChar( char c) DoUpdate = TRUE; // Sobald eine Zeile zuende, im Textfenster anzeigen if (c == LF) - DisplayText(); + DisplayText(); } + // Anfuegen eines Strings an den TextBuffer -static void AppendString( const char * Line) +static void AppendString(const char *Line) { size_t i; if (!Line) return; @@ -319,35 +342,40 @@ static void AppendString( const char * Line) // Zeilenlaenge bestimmen i = strlen(Line); // Textbuffer nicht zu grosz werden lassen - while ((i+TBufEnd+3) >= TBufSize) + while ((i + TBufEnd + 3) >= TBufSize) _DeleteFirstLine(); // Zeile dranhaengen - strcpy( &TBuffer[TBufEnd], Line); + strcpy(&TBuffer[TBufEnd], Line); TBufEnd += i; DoUpdate = TRUE; } + // Text neu darstellen -static void DisplayText( void) +static void DisplayText(void) { // Darstellen - Edit_SetText( twText, TBuffer); + Edit_SetText(twText, TBuffer); // Scroller updaten, neuen Text darstellen AdjustScroller(); } + + /* // Anfuegen einer Zeile an den Textbuffer -void AppendLine( const char * Line) +void AppendLine(const char *Line) { if (!Line) return; // String anhaengen - AppendString( Line); + AppendString(Line); // CRLF anhaengen - AppendString( CRLF); + AppendString(CRLF); } */ + + // ------------------------------------------------------------------- // Lese ein Zeichen ein @@ -362,34 +390,36 @@ static int w_getch(void) if (DoUpdate) DisplayText(); // Focus setzen - SetFocus( swString); + SetFocus(swString); // Cursor = normal - SetCursor( LoadCursor( NULL, IDC_IBEAM)); + SetCursor(LoadCursor(NULL, IDC_IBEAM)); // Analyse ist fertig - SetAnalyse("", -1); + SetAnalyse("", -1); // Warten auf die Eingabe do { WaitForMessage(); c = SBuffer[0]; - } while ( !c ); + } while (!c); // Zeichen an die Ausgabe anhaengen - AppendString( SBuffer); + AppendString(SBuffer); // Cursor = warten - SetCursor( LoadCursor( NULL, IDC_WAIT)); + SetCursor(LoadCursor(NULL, IDC_WAIT)); } // Zeichen abholen - memmove( &SBuffer[0], &SBuffer[1], SBufSize); + memmove(&SBuffer[0], &SBuffer[1], SBufSize); return c; } + // Gebe ein Zeichen aus -static int w_putch( int c) +static int w_putch(int c) { if (c) - AppendChar( (char)c ); + AppendChar((char) c); return c; } + /* --------------------------------------------------------- */ /* Main window changes size */ @@ -401,66 +431,69 @@ static void Main_OnSize(HWND hwnd, UINT state, int cx, int cy) NG_IGNORE(state); /* Expand text window */ - MoveWindow( twText, 0, 0, cx, h , TRUE); - VisibleRows = (h / RowHeight) -1; + MoveWindow(twText, 0, 0, cx, h , TRUE); + VisibleRows = (h / RowHeight) - 1; AdjustScroller(); /* Expand string window */ - MoveWindow( swString, 0, h, cx, LineHeight, TRUE); + MoveWindow(swString, 0, h, cx, LineHeight, TRUE); /* Expand Status Elements */ - h = cy - LineHeight + StatusFrame -1; - MoveWindow( hwSource, StatusFrame, h, SourceLength, StatusElHeight, TRUE); - MoveWindow( hwAnalyse, cx - 3 * StatusFrame - QuitButtonLength - AnalyseLength - 20, - h, AnalyseLength, StatusElHeight, TRUE); - MoveWindow( hwQuitButton, cx - StatusFrame - QuitButtonLength - 20, - h, QuitButtonLength, StatusElHeight, TRUE); + h = cy - LineHeight + StatusFrame - 1; + MoveWindow(hwSource, StatusFrame, h, SourceLength, StatusElHeight, TRUE); + MoveWindow(hwAnalyse, cx - 3 * StatusFrame - QuitButtonLength - AnalyseLength - 20, + h, AnalyseLength, StatusElHeight, TRUE); + MoveWindow(hwQuitButton, cx - StatusFrame - QuitButtonLength - 20, + h, QuitButtonLength, StatusElHeight, TRUE); } + /* Write a command into the command buffer */ -static void PostSpiceCommand( const char * const cmd) +static void PostSpiceCommand(const char *const cmd) { - strcpy( SBuffer, cmd); - strcat( SBuffer, CRLF); + strcpy(SBuffer, cmd); + strcat(SBuffer, CRLF); } + /* Main Window procedure */ -static LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { - /* command issued by pushing the "Quit" button */ + /* command issued by pushing the "Quit" button */ case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) - if (ft_batchmode && (MessageBox(NULL, "Do you want to quit ngspice?", "Quit", MB_OKCANCEL|MB_ICONERROR) - == IDCANCEL)) goto DEFAULT_AFTER; - if (LOWORD(wParam) == QUIT_BUTTON_ID) { - SendMessage(GetParent((HWND)lParam), WM_CLOSE, 0, 0); - } - /* write all achieved so far to log file */ - if (flogp) win_x_fflush(flogp); + if (ft_batchmode && (MessageBox(NULL, "Do you want to quit ngspice?", "Quit", MB_OKCANCEL|MB_ICONERROR) + == IDCANCEL)) goto DEFAULT_AFTER; + if (LOWORD(wParam) == QUIT_BUTTON_ID) { + SendMessage(GetParent((HWND)lParam), WM_CLOSE, 0, 0); + } + /* write all achieved so far to log file */ + if (flogp) win_x_fflush(flogp); goto DEFAULT_AFTER; case WM_CLOSE: /* Put Spice commmand "Quit" to end the program into the text buffer */ - PostSpiceCommand( "quit"); + PostSpiceCommand("quit"); - /* If simulation is running, set a breakpoint */ - raise (SIGINT); + /* If simulation is running, set a breakpoint */ + raise (SIGINT); return 0; case WM_SIZE: - HANDLE_WM_SIZE( hwnd, wParam, lParam, Main_OnSize); + HANDLE_WM_SIZE(hwnd, wParam, lParam, Main_OnSize); goto DEFAULT_AFTER; default: -DEFAULT_AFTER: - return DefWindowProc( hwnd, uMsg, wParam, lParam); + DEFAULT_AFTER: + return DefWindowProc(hwnd, uMsg, wParam, lParam); } } + /* Procedure for string window */ -static LRESULT CALLBACK StringWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK StringWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { char c; UINT i; @@ -471,51 +504,50 @@ static LRESULT CALLBACK StringWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, L i = (UINT) wParam; if ((i == VK_UP) || (i == VK_DOWN)) { /* Set old text to new */ - SetWindowText( hwnd, i == VK_UP? HistoryGetPrev(): HistoryGetNext()); + SetWindowText(hwnd, i == VK_UP ? HistoryGetPrev() : HistoryGetNext()); /* Put cursor to end of line */ - CallWindowProc( swProc, hwnd, uMsg, (WPARAM) VK_END, lParam); + CallWindowProc(swProc, hwnd, uMsg, (WPARAM) VK_END, lParam); return 0; } - if ( i == VK_ESCAPE) { + if (i == VK_ESCAPE) { ClearInput(); return 0; } - - goto DEFAULT; case WM_CHAR: - c = (char) wParam; - if (c == CR) { - GetWindowText( hwnd, SBuffer, SBufSize); - HistoryEnter( SBuffer); - strcat( SBuffer, CRLF); - ClearInput(); - return 0; - } - if (c == VK_ESCAPE) - return 0; - /* ctrl-z ends input from string window (like a console input), - FIXME: not yet working */ - if (c == VK_EOT) { -// strcat( SBuffer, ""); - SBuffer[0] = c; // '\004'; - SBuffer[1] = '\n'; - return 0; - } - /* ctrl-c interrupts simulation */ - if (c == VK_CANCEL) { - raise (SIGINT); - return 0; - } + c = (char) wParam; + if (c == CR) { + GetWindowText(hwnd, SBuffer, SBufSize); + HistoryEnter(SBuffer); + strcat(SBuffer, CRLF); + ClearInput(); + return 0; + } + if (c == VK_ESCAPE) + return 0; + /* ctrl-z ends input from string window (like a console input), + FIXME: not yet working */ + if (c == VK_EOT) { +// strcat(SBuffer, ""); + SBuffer[0] = c; // '\004'; + SBuffer[1] = '\n'; + return 0; + } + /* ctrl-c interrupts simulation */ + if (c == VK_CANCEL) { + raise (SIGINT); + return 0; + } default: -DEFAULT: - return CallWindowProc( swProc, hwnd, uMsg, wParam, lParam); + DEFAULT: + return CallWindowProc(swProc, hwnd, uMsg, wParam, lParam); } } + /* Procedure for text window */ -static LRESULT CALLBACK TextWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK TextWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { unsigned char c; UINT i; @@ -526,17 +558,17 @@ static LRESULT CALLBACK TextWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPA i = (UINT) wParam; if ((i == VK_UP) || (i == VK_DOWN) || (i == VK_ESCAPE)) { /* redirect input into string window */ - SetFocus( swString); - return SendMessage( swString, uMsg, wParam, lParam); + SetFocus(swString); + return SendMessage(swString, uMsg, wParam, lParam); } goto DEFAULT_TEXT; case WM_CHAR: c = (unsigned char) wParam; - if ((c == CR) || ( c >= ' ') || ( c == VK_ESCAPE)) { + if ((c == CR) || (c >= ' ') || (c == VK_ESCAPE)) { /* redirect input into string window */ - SetFocus( swString); - return SendMessage( swString, uMsg, wParam, lParam); + SetFocus(swString); + return SendMessage(swString, uMsg, wParam, lParam); } /* ctrl-c interrupts simulation */ if (c == VK_CANCEL) { @@ -544,8 +576,8 @@ static LRESULT CALLBACK TextWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPA return 0; } default: -DEFAULT_TEXT: - return CallWindowProc( twProc, hwnd, uMsg, wParam, lParam); + DEFAULT_TEXT: + return CallWindowProc(twProc, hwnd, uMsg, wParam, lParam); } } @@ -560,49 +592,49 @@ static void Element_OnPaint(HWND hwnd) int i; /* Prepare */ - HDC hdc = BeginPaint( hwnd, &ps); - GetClientRect( hwnd, &r); + HDC hdc = BeginPaint(hwnd, &ps); + GetClientRect(hwnd, &r); /* Draw frame */ - o = GetStockObject( GRAY_BRUSH); + o = GetStockObject(GRAY_BRUSH); s.left = r.left; s.right = r.right; s.top = r.top; - s.bottom = r.top+1; - FillRect( hdc, &s, o); + s.bottom = r.top + 1; + FillRect(hdc, &s, o); - s.right = r.left+1; + s.right = r.left + 1; s.bottom = r.bottom; - FillRect( hdc, &s, o); + FillRect(hdc, &s, o); - o = GetStockObject( WHITE_BRUSH); + o = GetStockObject(WHITE_BRUSH); s.right = r.right; - s.top = r.bottom-1; - FillRect( hdc, &s, o); + s.top = r.bottom - 1; + FillRect(hdc, &s, o); - s.left = r.right-1; + s.left = r.right - 1; s.top = r.top; - FillRect( hdc, &s, o); + FillRect(hdc, &s, o); /* Draw contents */ buffer[0] = '\0'; - i = GetWindowText( hwnd, buffer, 127); - s.left = r.left+1; - s.right = r.right-1; - s.top = r.top+1; - s.bottom = r.bottom-1; - o = GetStockObject( LTGRAY_BRUSH); - FillRect( hdc, &s, o); - SetBkMode( hdc, TRANSPARENT); - ExtTextOut( hdc, s.left+1, s.top+1, ETO_CLIPPED, &s, buffer, (unsigned)i, NULL); + i = GetWindowText(hwnd, buffer, 127); + s.left = r.left + 1; + s.right = r.right - 1; + s.top = r.top + 1; + s.bottom = r.bottom - 1; + o = GetStockObject(LTGRAY_BRUSH); + FillRect(hdc, &s, o); + SetBkMode(hdc, TRANSPARENT); + ExtTextOut(hdc, s.left + 1, s.top + 1, ETO_CLIPPED, &s, buffer, (unsigned)i, NULL); /* End */ - EndPaint( hwnd, &ps); + EndPaint(hwnd, &ps); } /* Procedure for element window */ -static LRESULT CALLBACK ElementWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK ElementWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -611,7 +643,7 @@ static LRESULT CALLBACK ElementWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, return 0; default: - return DefWindowProc( hwnd, uMsg, wParam, lParam); + return DefWindowProc(hwnd, uMsg, wParam, lParam); } } @@ -622,48 +654,51 @@ static LRESULT CALLBACK ElementWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, #define DELIMITERSTRING "\26" /* - This function converts a string into an argc/argv represenation. - INPUT: - cmdline - a string - OUTPUT: - argc - the number of equivalent argv strings - which is also the number of strings in argv - argv - the argv given the input string which - consists of seperate strings for each argument - RETURNS: - 0 on success - -1 on failure + This function converts a string into an argc/argv represenation. + INPUT: + cmdline - a string + OUTPUT: + argc - the number of equivalent argv strings + which is also the number of strings in argv + argv - the argv given the input string which + consists of seperate strings for each argument + RETURNS: + 0 on success + -1 on failure */ -static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) + +static int MakeArgcArgv(char *cmdline, int *argc, char ***argv) { - char *pC1; /* a temporary character pointer */ - char *pWorkString=NULL; /* a working copy of cmdline */ - int i; /* a loop counter */ - int quoteflag=0; /* for the finite state machine parsing cmdline */ - bool firstspace = TRUE; /* count only the first space */ - int numargs=1; /* the number of command line arguments, later - copied to *argc */ - char **tmpargv; /* the temporary argv, later copied to *argv */ + char *pC1; /* a temporary character pointer */ + char *pWorkString = NULL; /* a working copy of cmdline */ + int i; /* a loop counter */ + int quoteflag = 0; /* for the finite state machine parsing cmdline */ + bool firstspace = TRUE; /* count only the first space */ + int numargs = 1; /* the number of command line arguments, later + copied to *argc */ + char **tmpargv; /* the temporary argv, later copied to *argv */ int status = ERROR_SUCCESS; /* status */ - char buffer[MAX_PATH+1]; + char buffer[MAX_PATH + 1]; char deli[2]; /* make sure we aren't dealing with any NULL pointers */ - if ( (NULL == argc) - || (NULL == argv)) + if ((NULL == argc) + || (NULL == argv)) { status = -1; goto outahere; } + *argc = 0; /* set the count to zero to start */ *argv = NULL; /* set the pointer to NULL to start */ + /* if the string passed in was a NULL pointer, consider this to be an empty command line and give back only an argc of 1 and an argv[0] */ if (NULL != cmdline) { - /* make a copy of the string so that we can modify it + /* make a copy of the string so that we can modify it without messing up the original */ pWorkString = copy(cmdline); if (NULL == pWorkString) @@ -673,14 +708,14 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) between " marks with our own special delimiter for strtok */ /* trim all the whitespace off the end of the string. */ - for (i=(signed)strlen(pWorkString)-1; i >=0; i--) + for (i = (signed)strlen(pWorkString) - 1; i >= 0; i--) if (isspace((unsigned char) pWorkString[i])) pWorkString[i] = '\0'; else break; #if defined(__CYGWIN__) /* for CYGWIN: trim off the leading white space delivered by lpszCmdLine. */ - pWorkString = rlead(pWorkString); + pWorkString = rlead(pWorkString); #endif /* If we still have a string left, parse it for all the arguments. */ @@ -690,7 +725,7 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) but strtok is destructive if I wanted to look for " \"" and I couldn't tell what delimiter that I had bumped against */ - for (i=0; i < (signed)strlen(pWorkString); i++) + for (i = 0; i < (signed)strlen(pWorkString); i++) { switch (pWorkString[i]) { @@ -710,6 +745,7 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) break; } } + /* Now, we should have ctrl-Zs everywhere that there used to be a space not protected by quote marks. We should also have the number @@ -721,7 +757,7 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) } } /* malloc an argv */ - tmpargv = (char**)malloc((unsigned)numargs * sizeof(char *)); + tmpargv = (char**) malloc((unsigned)numargs * sizeof(char *)); if (NULL == tmpargv) { status = -1; @@ -734,11 +770,11 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) deli[0] = DELIMITER; deli[1] = '\0'; /* delimiter for strtok */ - + pC1 = NULL; /* Now actually strdup all the arguments out of the string and store them in the argv */ - for (i=1; i < numargs; i++) + for (i = 1; i < numargs; i++) { if (NULL == pC1) pC1 = pWorkString; @@ -750,10 +786,12 @@ static int MakeArgcArgv(char *cmdline,int *argc,char ***argv) /* copy the working values over to the arguments */ *argc = numargs; *argv = tmpargv; -outahere: + + outahere: /* free the working string if one was allocated */ if (pWorkString) free(pWorkString); + /* return status */ return status; } @@ -764,13 +802,13 @@ outahere: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { int ix, iy; /* width and height of screen */ - int iyt; /* height of screen divided by 3 */ + int iyt; /* height of screen divided by 3 */ int status; - + int argc; char **argv; - RECT wsize; /* size of usable window */ + RECT wsize; /* size of usable window */ NG_IGNORE(hPrevInstance); @@ -790,30 +828,35 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi hwMainClass.cbClsExtra = 0; hwMainClass.cbWndExtra = 0; hwMainClass.hInstance = hInst; - hwMainClass.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(1)); - hwMainClass.hCursor = LoadCursor( NULL, IDC_ARROW); - hwMainClass.hbrBackground = GetStockObject( LTGRAY_BRUSH); + hwMainClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(1)); + hwMainClass.hCursor = LoadCursor(NULL, IDC_ARROW); + hwMainClass.hbrBackground = GetStockObject(LTGRAY_BRUSH); hwMainClass.lpszMenuName = NULL; hwMainClass.lpszClassName = hwClassName; - if (!RegisterClass( &hwMainClass)) goto THE_END; + + if (!RegisterClass(&hwMainClass)) goto THE_END; /* Define text window class */ - if (!GetClassInfo( NULL, "EDIT", &twTextClass)) goto THE_END; + if (!GetClassInfo(NULL, "EDIT", &twTextClass)) goto THE_END; + twProc = twTextClass.lpfnWndProc; twTextClass.lpfnWndProc = TextWindowProc; twTextClass.hInstance = hInst; twTextClass.lpszMenuName = NULL; twTextClass.lpszClassName = twClassName; - if (!RegisterClass( &twTextClass)) goto THE_END; + + if (!RegisterClass(&twTextClass)) goto THE_END; /* Define string window class */ - if (!GetClassInfo( NULL, "EDIT", &swStringClass)) goto THE_END; + if (!GetClassInfo(NULL, "EDIT", &swStringClass)) goto THE_END; + swProc = swStringClass.lpfnWndProc; swStringClass.lpfnWndProc = StringWindowProc; swStringClass.hInstance = hInst; swStringClass.lpszMenuName = NULL; swStringClass.lpszClassName = swClassName; - if (!RegisterClass( &swStringClass)) goto THE_END; + + if (!RegisterClass(&swStringClass)) goto THE_END; /* Define status element class */ hwElementClass.style = CS_HREDRAW | CS_VREDRAW; @@ -822,111 +865,113 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi hwElementClass.cbWndExtra = 0; hwElementClass.hInstance = hInst; hwElementClass.hIcon = NULL; - hwElementClass.hCursor = LoadCursor( NULL, IDC_ARROW); - hwElementClass.hbrBackground = GetStockObject( LTGRAY_BRUSH); + hwElementClass.hCursor = LoadCursor(NULL, IDC_ARROW); + hwElementClass.hbrBackground = GetStockObject(LTGRAY_BRUSH); hwElementClass.lpszMenuName = NULL; hwElementClass.lpszClassName = hwElementClassName; - if (!RegisterClass( &hwElementClass)) goto THE_END; + + if (!RegisterClass(&hwElementClass)) goto THE_END; /*Create main window */ - SystemParametersInfo(SPI_GETWORKAREA, 0, &wsize, 0); + SystemParametersInfo(SPI_GETWORKAREA, 0, &wsize, 0); iy = wsize.bottom; - iyt = iy / 3; - ix = wsize.right; -// iy = GetSystemMetrics( SM_CYSCREEN); -// iyt = GetSystemMetrics( SM_CYSCREEN) / 3; -// ix = GetSystemMetrics( SM_CXSCREEN); - hwMain = CreateWindow( hwClassName, hwWindowName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, - 0, iyt * 2, ix, iyt, NULL, NULL, hInst, NULL); + iyt = iy / 3; + ix = wsize.right; +// iy = GetSystemMetrics(SM_CYSCREEN); +// iyt = GetSystemMetrics(SM_CYSCREEN) / 3; +// ix = GetSystemMetrics(SM_CXSCREEN); + hwMain = CreateWindow(hwClassName, hwWindowName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, + 0, iyt * 2, ix, iyt, NULL, NULL, hInst, NULL); if (!hwMain) goto THE_END; /* Create text window */ twText = CreateWindowEx(WS_EX_NOPARENTNOTIFY, twClassName, twWindowName, - ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_BORDER | WS_VSCROLL, - 20,20,300,100, hwMain, NULL, hInst, NULL); + ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_BORDER | WS_VSCROLL, + 20, 20, 300, 100, hwMain, NULL, hInst, NULL); if (!twText) goto THE_END; + /* Ansii fixed font */ { HDC textDC; HFONT font; TEXTMETRIC tm; - font = GetStockFont( ANSI_FIXED_FONT); - SetWindowFont( twText, font, FALSE); - textDC = GetDC( twText); + font = GetStockFont(ANSI_FIXED_FONT); + SetWindowFont(twText, font, FALSE); + textDC = GetDC(twText); if (textDC) { - SelectObject( textDC, font); - if (GetTextMetrics( textDC, &tm)) { + SelectObject(textDC, font); + if (GetTextMetrics(textDC, &tm)) { RowHeight = tm.tmHeight; WinLineWidth = 90 * tm.tmAveCharWidth; } - ReleaseDC( twText, textDC); + ReleaseDC(twText, textDC); } } /* Create string window */ swString = CreateWindowEx(WS_EX_NOPARENTNOTIFY, swClassName, swWindowName, - ES_LEFT | WS_CHILD | WS_BORDER, 20,20,300,100, hwMain, NULL, hInst, NULL); + ES_LEFT | WS_CHILD | WS_BORDER, 20,20,300,100, hwMain, NULL, hInst, NULL); if (!swString) goto THE_END; + { HDC stringDC; TEXTMETRIC tm; - stringDC = GetDC( swString); + stringDC = GetDC(swString); if (stringDC) { - if (GetTextMetrics( stringDC, &tm)) + if (GetTextMetrics(stringDC, &tm)) LineHeight = tm.tmHeight + tm.tmExternalLeading + BorderSize; - ReleaseDC( swString, stringDC); + ReleaseDC(swString, stringDC); } } /* Create source window */ hwSource = CreateWindowEx(WS_EX_NOPARENTNOTIFY, hwElementClassName, - hwSourceWindowName, WS_CHILD, 0,0, SourceLength, StatusElHeight, hwMain, - NULL, hInst, NULL); + hwSourceWindowName, WS_CHILD, 0,0, SourceLength, StatusElHeight, hwMain, + NULL, hInst, NULL); if (!hwSource) goto THE_END; /* Create analysis window */ hwAnalyse = CreateWindowEx(WS_EX_NOPARENTNOTIFY, hwElementClassName, - hwAnalyseWindowName, WS_CHILD, 0,0, AnalyseLength, StatusElHeight, hwMain, - NULL, hInst, NULL); + hwAnalyseWindowName, WS_CHILD, 0,0, AnalyseLength, StatusElHeight, hwMain, + NULL, hInst, NULL); if (!hwAnalyse) goto THE_END; /* Create "Quit" button */ - hwQuitButton = CreateWindow("BUTTON", "Quit", WS_CHILD | - BS_PUSHBUTTON, 0, 0, QuitButtonLength, - StatusElHeight, hwMain, (HMENU)(UINT_PTR)QUIT_BUTTON_ID, hInst, NULL); - + hwQuitButton = CreateWindow("BUTTON", "Quit", WS_CHILD | + BS_PUSHBUTTON, 0, 0, QuitButtonLength, + StatusElHeight, hwMain, (HMENU)(UINT_PTR)QUIT_BUTTON_ID, hInst, NULL); + if (!hwQuitButton) goto THE_END; /* Make main window and subwindows visible. - Size of windows allows display of 80 character line. - Limit window to screen size (if only VGA). */ - if (WinLineWidth > ix) - WinLineWidth = ix; - MoveWindow( hwMain, 0, (iyt * 2), WinLineWidth, iyt, FALSE); - ShowWindow( hwMain, nShowState); - ShowWindow( twText, SW_SHOWNORMAL); - ShowWindow( swString, SW_SHOWNORMAL); - ShowWindow( hwSource, SW_SHOWNORMAL); - ShowWindow( hwAnalyse,SW_SHOWNORMAL); - ShowWindow( hwQuitButton,SW_SHOWNORMAL); + Size of windows allows display of 80 character line. + Limit window to screen size (if only VGA). */ + if (WinLineWidth > ix) + WinLineWidth = ix; + MoveWindow(hwMain, 0, (iyt * 2), WinLineWidth, iyt, FALSE); + ShowWindow(hwMain, nShowState); + ShowWindow(twText, SW_SHOWNORMAL); + ShowWindow(swString, SW_SHOWNORMAL); + ShowWindow(hwSource, SW_SHOWNORMAL); + ShowWindow(hwAnalyse, SW_SHOWNORMAL); + ShowWindow(hwQuitButton, SW_SHOWNORMAL); ClearInput(); DisplayText(); - SetSource( ""); + SetSource(""); SetAnalyse("Start", 0); - UpdateWindow( hwMain); - SetFocus( swString); + UpdateWindow(hwMain); + SetFocus(swString); - status = MakeArgcArgv(lpszCmdLine,&argc,&argv); + status = MakeArgcArgv(lpszCmdLine, &argc, &argv); /* Wait until everything is settled */ WaitForIdle(); /* Go to main() */ nReturnCode = xmain(argc, argv); - -THE_END: + THE_END: /* terminate */ return nReturnCode; @@ -936,12 +981,12 @@ THE_END: // ------------------------------------------------------------------- /* Eigentlich wollte ich die Standard-Streams durch einen Hook in der Library umleiten, - aber so etwas gibt es anscheinend nicht. Deswegen musz ich praktisch alle - IO-Funktionen umdefinieren (siehe wstdio.h). Leider geht das nicht bei allen. - Man schaue also nach, bevor man eine Funktion benutzt! + aber so etwas gibt es anscheinend nicht. Deswegen musz ich praktisch alle + IO-Funktionen umdefinieren (siehe wstdio.h). Leider geht das nicht bei allen. + Man schaue also nach, bevor man eine Funktion benutzt! */ -int win_x_fflush( FILE * stream) +int win_x_fflush(FILE *stream) { if (((stream == stdout) && !flogp) || (stream == stderr)) return 0; @@ -949,19 +994,21 @@ int win_x_fflush( FILE * stream) return fflush(stream); } -int win_x_fgetc( FILE * stream) + +int win_x_fgetc(FILE *stream) { if (stream == stdin) { int c; do { c = w_getch(); - } while( c == CR); + } while (c == CR); return c; } else return fgetc(stream); } -int win_x_fgetpos( FILE * stream, fpos_t * pos) + +int win_x_fgetpos(FILE *stream, fpos_t *pos) { int result; if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { @@ -972,12 +1019,13 @@ int win_x_fgetpos( FILE * stream, fpos_t * pos) return result; } -char * win_x_fgets(char * s, int n, FILE * stream) + +char *win_x_fgets(char *s, int n, FILE *stream) { if (stream == stdin) { int i = 0; int c; - while ( i < (n-1)) { + while (i < (n - 1)) { c = w_getch(); if (c == LF) { s[i++] = LF; @@ -989,23 +1037,25 @@ char * win_x_fgets(char * s, int n, FILE * stream) s[i] = SE; return s; } else - return fgets( s, n, stream); + return fgets(s, n, stream); } -int win_x_fputc(int c, FILE * stream) + +int win_x_fputc(int c, FILE *stream) { if (!flogp && ((stream == stdout) || (stream == stderr))) { - if ( c == LF) - w_putch( CR); + if (c == LF) + w_putch(CR); return w_putch(c); // Ausgabe in Datei *.log 14.6.2000 } else if (flogp && ((stream == stdout) || stream == stderr)) { - return fputc( c, flogp); + return fputc(c, flogp); } else - return fputc( c, stream); + return fputc(c, stream); } -int win_x_fputs(const char * s, FILE * stream) + +int win_x_fputs(const char *s, FILE *stream) { // if (((stream == stdout) && !flogp) || (stream == stderr)) { hvogt 14.6.2000 if ((stream == stdout) || (stream == stderr)) { @@ -1020,51 +1070,55 @@ int win_x_fputs(const char * s, FILE * stream) return c; } } else - return fputs( s, stream); + return fputs(s, stream); } -int win_x_fprintf(FILE * stream, const char * format, ...) + +int win_x_fprintf(FILE *stream, const char *format, ...) { int result; - char s [IOBufSize]; + char s[IOBufSize]; va_list args; + va_start(args, format); // if (((stream == stdout) && !flogp) || (stream == stderr)) { if ((stream == stdout) || (stream == stderr)) { s[0] = SE; - result = vsprintf( s, format, args); - win_x_fputs( s, stream); + result = vsprintf(s, format, args); + win_x_fputs(s, stream); } else - result = vfprintf( stream, format, args); + result = vfprintf(stream, format, args); va_end(args); return result; } -int win_x_fclose( FILE * stream) + +int win_x_fclose(FILE *stream) { if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); return 0; } - return fclose( stream); + return fclose(stream); } -size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream) + +size_t win_x_fread(void *ptr, size_t size, size_t n, FILE *stream) { // if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { if (((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); return 0; } - + if (stream == stdin) { size_t i = 0; int c; - char s [IOBufSize]; - while ( i < (size * n - 1)) { + char s[IOBufSize]; + while (i < (size * n - 1)) { c = w_getch(); if (c == LF) { // s[i++] = LF; @@ -1075,24 +1129,28 @@ size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream) } // s[i] = SE; ptr = &s[0]; - return (size_t)(i/size); - } - return fread( ptr, size, n, stream); + return (size_t)(i / size); + } + + return fread(ptr, size, n, stream); } -FILE * win_x_freopen(const char * path, const char * mode, FILE * stream) + +FILE *win_x_freopen(const char *path, const char *mode, FILE *stream) { if ((stream == stdin)/* || ((stream == stdout) && !flogp) || (stream == stderr)*/) { assert(FALSE); return 0; } - return freopen( path, mode, stream); + return freopen(path, mode, stream); } -int win_x_fscanf(FILE * stream, const char * format, ...) + +int win_x_fscanf(FILE *stream, const char *format, ...) { int result; va_list args; + va_start(args, format); if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); @@ -1103,51 +1161,56 @@ int win_x_fscanf(FILE * stream, const char * format, ...) return result; } -int win_x_fseek(FILE * stream, long offset, int whence) + +int win_x_fseek(FILE *stream, long offset, int whence) { if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); return 0; } - return fseek( stream, offset, whence); + return fseek(stream, offset, whence); } -int win_x_fsetpos(FILE * stream, const fpos_t *pos) + +int win_x_fsetpos(FILE *stream, const fpos_t *pos) { if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); return 0; } - return fsetpos( stream, pos); + return fsetpos(stream, pos); } -long win_x_ftell(FILE * stream) + +long win_x_ftell(FILE *stream) { if ((stream == stdin) || ((stream == stdout) && !flogp) || (stream == stderr)) { assert(FALSE); return 0; } - return ftell( stream); + return ftell(stream); } -size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream) + +size_t win_x_fwrite(const void *ptr, size_t size, size_t n, FILE *stream) { // win_x_printf("entered fwrite, size %d, n %d \n", size, n); - if (stream == stdin) { + if (stream == stdin) { assert(FALSE); // win_x_printf("False \n"); return 0; } if ((stream == stdout) || (stream == stderr)) { - const char * s = ptr; + const char *s = ptr; int c = SE; size_t i = 0; // char *out; // win_x_printf("test1 %s\n", s); - if (!s) return 0 /*EOF*/; - for (i = 0; i< (size * n); i++) { + if (!s) return 0 /* EOF */; + + for (i = 0; i < (size * n); i++) { if (*s) { c = *s++; win_x_fputc(c, stream); @@ -1156,111 +1219,124 @@ size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream) } // win_x_fread(out, size, n, stream); // win_x_printf("test2 %s", out); - return (int)(i/size); + return (int)(i / size); } // win_x_printf("test3 %s\n", ptr); - return fwrite( ptr, size, n, stream); + return fwrite(ptr, size, n, stream); } -char * win_x_gets(char * s) + +char *win_x_gets(char *s) { - return win_x_fgets( s, 10000, stdin); + return win_x_fgets(s, 10000, stdin); } -void win_x_perror(const char * s) + +void win_x_perror(const char *s) { - const char * cp; -// char s [IOBufSize]; + const char *cp; +// char s[IOBufSize]; cp = strerror(errno); win_x_fprintf(stderr, "%s: %s\n", s, cp); - /* output to message box - sprintf(s, "%s: %s\n", s, cp); - if (!flogp) winmessage(s);*/ + /* output to message box + sprintf(s, "%s: %s\n", s, cp); + if (!flogp) winmessage(s);*/ } -int win_x_printf(const char * format, ...) + +int win_x_printf(const char *format, ...) { int result; - char s [IOBufSize]; + char s[IOBufSize]; va_list args; - va_start(args, format); + va_start(args, format); s[0] = SE; - result = vsprintf( s, format, args); - win_x_fputs( s, stdout); + result = vsprintf(s, format, args); + win_x_fputs(s, stdout); va_end(args); + return result; } -int win_x_puts(const char * s) + +int win_x_puts(const char *s) { - return win_x_fputs( s, stdout); + return win_x_fputs(s, stdout); } -int win_x_scanf(const char * format, ...) + +int win_x_scanf(const char *format, ...) { NG_IGNORE(format); - assert( FALSE); + assert(FALSE); return FALSE; } -int win_x_ungetc(int c, FILE * stream) + +int win_x_ungetc(int c, FILE *stream) { NG_IGNORE(c); NG_IGNORE(stream); - assert( FALSE); + assert(FALSE); return FALSE; } -int win_x_vfprintf(FILE * stream, const char * format, void * arglist) + +int win_x_vfprintf(FILE *stream, const char *format, void *arglist) { int result; - char s [IOBufSize]; + char s[IOBufSize]; s[0] = SE; // if (((stream == stdout) && !flogp) || (stream == stderr)) { if ((stream == stdout) || (stream == stderr)) { - result = vsprintf( s, format, arglist); - win_x_fputs( s, stdout); + result = vsprintf(s, format, arglist); + win_x_fputs(s, stdout); } else - result = vfprintf( stream, format, arglist); + result = vfprintf(stream, format, arglist); return result; } -/*int win_x_vfscanf(FILE * stream, const char * format, void * arglist) + +/*int win_x_vfscanf(FILE *stream, const char *format, void *arglist) { if (stream == stdin) { assert(FALSE); return 0; } - return vfscanf( stream, format, arglist); + return vfscanf(stream, format, arglist); } */ -int win_x_vprintf(const char * format, void * arglist) + + +int win_x_vprintf(const char *format, void *arglist) { int result; - char s [IOBufSize]; + char s[IOBufSize]; s[0] = SE; - result = vsprintf( s, format, arglist); - win_x_fputs( s, stdout); + result = vsprintf(s, format, arglist); + win_x_fputs(s, stdout); return result; } -/*int win_x_vscanf(const char * format, void * arglist) + +/*int win_x_vscanf(const char *format, void *arglist) { - assert( FALSE); + assert(FALSE); return FALSE; } */ -int win_x_read(int fd, char * buf, int n) + +int win_x_read(int fd, char *buf, int n) { if (fd == 0) { int i = 0; int c; - char s [IOBufSize]; - while ( i < n ) { + char s[IOBufSize]; + while (i < n) { c = w_getch(); if (c == LF) { // s[i++] = LF; @@ -1272,69 +1348,81 @@ int win_x_read(int fd, char * buf, int n) // s[i] = SE; buf = &s[0]; return (i); - } + } else { - return _read(fd, buf, n); + return _read(fd, buf, n); } } -int win_x_getc(FILE * fp) + + +int win_x_getc(FILE *fp) { - return win_x_fgetc( fp); + return win_x_fgetc(fp); } + int win_x_getchar(void) { - return win_x_fgetc( stdin); + return win_x_fgetc(stdin); } + int win_x_putchar(const int c) { - return win_x_fputc( c, stdout); + return win_x_fputc(c, stdout); } -int win_x_putc(const int c, FILE * fp) + +int win_x_putc(const int c, FILE *fp) { - return win_x_fputc( c, fp); + return win_x_fputc(c, fp); } -int win_x_feof(FILE * fp) + +int win_x_feof(FILE *fp) { if ((fp == stdin) || (fp == stdout) || (fp == stderr)) { assert(FALSE); return 0; } - return feof( fp); + return feof(fp); } -int win_x_ferror(FILE * fp) + +int win_x_ferror(FILE *fp) { if ((fp == stdin) || (fp == stdout) || (fp == stderr)) { assert(FALSE); return 0; } - return ferror( fp); + return ferror(fp); } + int win_x_fputchar(int c) { - return win_x_fputc( c, stdout); + return win_x_fputc(c, stdout); } + // ------------------------------------------------------ + /* size_t _memavl(void) { MEMORYSTATUS ms; DWORD sum; ms.dwLength = sizeof(MEMORYSTATUS); - GlobalMemoryStatus( &ms); + GlobalMemoryStatus(&ms); sum = ms.dwAvailPhys + ms.dwAvailPageFile; return (size_t) sum; } + // -------------------------------------------- + #ifndef _MSC_VER -int system( const char * command) +int system(const char *command) { // info-Bloecke STARTUPINFO si; @@ -1342,23 +1430,23 @@ int system( const char * command) DWORD ExitStatus; // Datenstrukturen fuellen - memset( &si, 0, sizeof( STARTUPINFO)); - si.cb = sizeof( STARTUPINFO); - memset( &pi, 0, sizeof( PROCESS_INFORMATION)); + memset(&si, 0, sizeof(STARTUPINFO)); + si.cb = sizeof(STARTUPINFO); + memset(&pi, 0, sizeof(PROCESS_INFORMATION)); // starte den neuen Prozess if (!CreateProcess( - NULL, // address of module name - (char *) command, // address of command line - NULL, // address of process security attributes - NULL, // address of thread security attributes - FALSE, // new process inherits handles - NORMAL_PRIORITY_CLASS, // creation flags - NULL, // address of new environment block - NULL, // address of current directory name - &si, // address of STARTUPINFO - &pi // address of PROCESS_INFORMATION - )) return -1; + NULL, // address of module name + (char *) command, // address of command line + NULL, // address of process security attributes + NULL, // address of thread security attributes + FALSE, // new process inherits handles + NORMAL_PRIORITY_CLASS, // creation flags + NULL, // address of new environment block + NULL, // address of current directory name + &si, // address of STARTUPINFO + &pi // address of PROCESS_INFORMATION + )) return -1; // dieses Handle musz da sein if (!pi.hProcess) return -1; @@ -1367,13 +1455,13 @@ int system( const char * command) // Multitasking ermoeglichen WaitForIdle(); // hole mir den Exit-Code des Prozesses - if (!GetExitCodeProcess( pi.hProcess, &ExitStatus)) return -1; + if (!GetExitCodeProcess(pi.hProcess, &ExitStatus)) return -1; // solange er existiert - } while( ExitStatus == STILL_ACTIVE); + } while (ExitStatus == STILL_ACTIVE); // Handles freigeben - if (pi.hThread) CloseHandle( pi.hThread); - if (pi.hProcess) CloseHandle( pi.hProcess); + if (pi.hThread) CloseHandle(pi.hThread); + if (pi.hProcess) CloseHandle(pi.hProcess); // fertig return 0; @@ -1381,38 +1469,42 @@ int system( const char * command) #endif */ + #ifdef __CYGWIN__ + /* Strip leading spaces, return a copy of s */ -static char* +static char * rlead(char *s) { - int i,j=0; - static char temp[512]; - bool has_space = TRUE; - for(i=0;s[i] != '\0';i++) - { - if(isspace((unsigned char) s[i]) && has_space) - { - ; //Do nothing - } - else - { - temp[j] = s[i]; - j++; - has_space = FALSE; - } - } - temp[j] = '\0'; - return copy(temp); -} + int i, j = 0; + static char temp[512]; + bool has_space = TRUE; + for (i = 0; s[i] != '\0'; i++) + { + if (isspace((unsigned char) s[i]) && has_space) + { + ; //Do nothing + } + else + { + temp[j] = s[i]; + j++; + has_space = FALSE; + } + } + temp[j] = '\0'; + return copy(temp); +} + #endif -void winmessage(char* new_msg) + +void winmessage(char *new_msg) { /* open a message box only if message is not written into -o xxx.log */ - if (!flogp) - MessageBox(NULL, new_msg, "Ngspice Info", MB_OK|MB_ICONERROR); + if (!flogp) + MessageBox(NULL, new_msg, "Ngspice Info", MB_OK | MB_ICONERROR); } -#endif /* HAS_WINGUI */ +#endif /* HAS_WINGUI */ diff --git a/src/winmain.h b/src/winmain.h index 32d8c90c7..ed3ff1ac4 100644 --- a/src/winmain.h +++ b/src/winmain.h @@ -3,71 +3,73 @@ */ /* Forward definition of main() */ -int xmain( int argc, char * argv[]); +int xmain(int argc, char *argv[]); + /* forward of Update function */ #ifdef __CYGWIN__ static char* rlead(char*); #endif + void winmessage(char*); static void HistoryInit(void); static void HistoryScroll(void); -static void HistoryEnter( char * newLine); -static char * HistoryGetPrev(void); -static char * HistoryGetNext(void); +static void HistoryEnter(char *newLine); +static char *HistoryGetPrev(void); +static char *HistoryGetNext(void); void WaitForIdle(void); static void WaitForMessage(void); static void ClearInput(void); -void SetSource( char * Name); -void SetAnalyse(char *, int ); +void SetSource(char *Name); +void SetAnalyse(char *, int); static void AdjustScroller(void); static void _DeleteFirstLine(void); -static void AppendChar( char c); -static void AppendString( const char * Line); -static void DisplayText( void); +static void AppendChar(char c); +static void AppendString(const char *Line); +static void DisplayText(void); static int w_getch(void); -static int w_putch( int c); +static int w_putch(int c); static void Main_OnSize(HWND hwnd, UINT state, int cx, int cy); -static void PostSpiceCommand( const char * const cmd); -static LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -static LRESULT CALLBACK StringWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -static LRESULT CALLBACK TextWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static void PostSpiceCommand(const char *const cmd); +static LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static LRESULT CALLBACK StringWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static LRESULT CALLBACK TextWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static void Element_OnPaint(HWND hwnd); -static LRESULT CALLBACK ElementWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -static int MakeArgcArgv(char *cmdline,int *argc,char ***argv); +static LRESULT CALLBACK ElementWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static int MakeArgcArgv(char *cmdline, int *argc, char ***argv); -int win_x_fclose( FILE * stream); -int win_x_fflush( FILE * stream); -int win_x_fgetc( FILE * stream); -int win_x_fgetpos( FILE * stream, fpos_t * pos); -char * win_x_fgets(char * s, int n, FILE * stream); -int win_x_fprintf(FILE * stream, const char * format, ...); -int win_x_fputc(int c, FILE * stream); -int win_x_fputs(const char * s, FILE * stream); -size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream); -FILE * win_x_freopen(const char * path, const char * mode, FILE * stream); -int win_x_fscanf(FILE * stream, const char * format, ...); -int win_x_fseek(FILE * stream, long offset, int whence); -int win_x_fsetpos(FILE * stream, const fpos_t*pos); -long win_x_ftell(FILE * stream); -size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream); -char * win_x_gets(char * s); -void win_x_perror(const char * s); -int win_x_printf(const char * format, ...); -int win_x_puts(const char * s); -int win_x_scanf(const char * format, ...); -int win_x_ungetc(int c, FILE * stream); -int win_x_vfprintf(FILE * stream, const char * format, void * arglist); -/*int win_x_vfscanf(FILE * stream, const char * format, void * arglist);*/ -int win_x_vprintf(const char * format, void * arglist); -/*int win_x_vscanf(const char * format, void * arglist); */ -int win_x_read(int fd, char * buf, int n); -int win_x_getc(FILE * fp); -int win_x_getchar(void); -int win_x_putchar(const int c); -int win_x_putc(const int c, FILE * fp); -int win_x_feof(FILE * fp); -int win_x_ferror(FILE * fp); -int win_x_fputchar(int c); +int win_x_fclose(FILE *stream); +int win_x_fflush(FILE *stream); +int win_x_fgetc(FILE *stream); +int win_x_fgetpos(FILE *stream, fpos_t *pos); +char *win_x_fgets(char *s, int n, FILE *stream); +int win_x_fprintf(FILE *stream, const char *format, ...); +int win_x_fputc(int c, FILE *stream); +int win_x_fputs(const char *s, FILE *stream); +size_t win_x_fread(void *ptr, size_t size, size_t n, FILE *stream); +FILE *win_x_freopen(const char *path, const char *mode, FILE *stream); +int win_x_fscanf(FILE *stream, const char *format, ...); +int win_x_fseek(FILE *stream, long offset, int whence); +int win_x_fsetpos(FILE *stream, const fpos_t*pos); +long win_x_ftell(FILE *stream); +size_t win_x_fwrite(const void *ptr, size_t size, size_t n, FILE *stream); +char *win_x_gets(char *s); +void win_x_perror(const char *s); +int win_x_printf(const char *format, ...); +int win_x_puts(const char *s); +int win_x_scanf(const char *format, ...); +int win_x_ungetc(int c, FILE *stream); +int win_x_vfprintf(FILE *stream, const char *format, void *arglist); +/* int win_x_vfscanf(FILE *stream, const char *format, void *arglist); */ +int win_x_vprintf(const char *format, void *arglist); +/* int win_x_vscanf(const char *format, void *arglist); */ +int win_x_read(int fd, char *buf, int n); +int win_x_getc(FILE *fp); +int win_x_getchar(void); +int win_x_putchar(const int c); +int win_x_putc(const int c, FILE *fp); +int win_x_feof(FILE *fp); +int win_x_ferror(FILE *fp); +int win_x_fputchar(int c);