📄 misc.c
字号:
return ETC_INTCONV; return ETC_OK;}static int etc_CopyAndLocate (FILE* etc_fp, FILE* tmp_fp, const char* pSection, const char* pKey, char* tempSection){ if (pSection && etc_LocateSection (etc_fp, pSection, tmp_fp) != ETC_OK) return ETC_SECTIONNOTFOUND; if (etc_LocateKeyValue (etc_fp, pKey, pSection != NULL, NULL, 0, tmp_fp, tempSection) != ETC_OK) return ETC_KEYNOTFOUND; return ETC_OK;}static int etc_FileCopy (FILE* sf, FILE* df){ char line [ETC_MAXLINE + 1]; while (fgets (line, ETC_MAXLINE + 1, sf) != NULL) if (fputs (line, df) == EOF) { return ETC_FILEIOFAILED; } return ETC_OK;}/* Function: SetValueToEtcFile(const char* pEtcFile, const char* pSection, * const char* pKey, char* pValue); * Parameter: * pEtcFile: etc file path name. * pSection: Section name. * pKey: Key name. * pValue: Value. * Return: * int meaning * ETC_FILENOTFOUND The etc file not found. * ETC_TMPFILEFAILED Create tmp file failure. * ETC_OK OK. */int GUIAPI SetValueToEtcFile (const char* pEtcFile, const char* pSection, const char* pKey, char* pValue){ FILE* etc_fp; FILE* tmp_fp; int rc; char tempSection [ETC_MAXLINE + 2]; if ((tmp_fp = tmpfile ()) == NULL) return ETC_TMPFILEFAILED; if (!(etc_fp = fopen (pEtcFile, "r+"))) { fclose (tmp_fp); if (!(etc_fp = fopen (pEtcFile, "w"))) return ETC_FILEIOFAILED; fprintf (etc_fp, "[%s]\n", pSection); fprintf (etc_fp, "%s=%s\n", pKey, pValue); fclose (etc_fp); return ETC_OK; } switch (etc_CopyAndLocate (etc_fp, tmp_fp, pSection, pKey, tempSection)) { case ETC_SECTIONNOTFOUND: fprintf (tmp_fp, "\n[%s]\n", pSection); fprintf (tmp_fp, "%s=%s\n", pKey, pValue); break; case ETC_KEYNOTFOUND: fprintf (tmp_fp, "%s=%s\n\n", pKey, pValue); fprintf (tmp_fp, "%s\n", tempSection); break; default: fprintf (tmp_fp, "%s=%s\n", pKey, pValue); break; } if ((rc = etc_FileCopy (etc_fp, tmp_fp)) != ETC_OK) goto error; // replace etc content with tmp file content // truncate etc content first fclose (etc_fp); if (!(etc_fp = fopen (pEtcFile, "w"))) return ETC_FILEIOFAILED; rewind (tmp_fp); rc = etc_FileCopy (tmp_fp, etc_fp);error: fclose (etc_fp); fclose (tmp_fp); return rc;}/****************************** Ping and Beep *********************************/void GUIAPI Ping(void){ putchar ('\a'); fflush (stdout);}void GUIAPI Tone (int frequency_hz, int duration_ms){ /* FIXME: Tone will not work in X Window */ long argument = (1190000 / frequency_hz) | ((duration_ms / (1000/HZ)) << 16); ioctl (0, KDMKTONE, (long) argument);}/****************************** Drawing Helpers *******************************/void GUIAPI Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, gal_pixel fillc){ r--; b--; SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT_INNER)); Rectangle(hDC, l, t, r, b); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER)); Rectangle(hDC, l, t, r - 1, b - 1); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER)); MoveTo(hDC, l, b); LineTo(hDC, r, b); LineTo(hDC, r, t); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT_OUTER)); MoveTo(hDC, l + 1, b - 1); LineTo(hDC, l + 1, t + 1); LineTo(hDC, r - 1, t + 1); if (fillc != 0) { SetBrushColor(hDC, fillc); FillBox(hDC, l + 2, t + 2, r - l - 3, b - t - 3); }}void GUIAPI Draw3DDownFrame(HDC hDC, int l, int t, int r, int b, gal_pixel fillc){ SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER)); MoveTo(hDC, l, b); LineTo(hDC, l, t); LineTo(hDC, r, t); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER)); MoveTo(hDC, l + 1, b - 1); LineTo(hDC, l + 1, t + 1); LineTo(hDC, r - 1, t + 1); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT_INNER)); MoveTo(hDC, l + 1, b - 1); LineTo(hDC, r - 1, b - 1); LineTo(hDC, r - 1, t + 1); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT_OUTER)); MoveTo(hDC, l, b); LineTo(hDC, r, b); LineTo(hDC, r, t); if (fillc != 0) { SetBrushColor(hDC, fillc); FillBox(hDC, l + 2, t + 2, r - l - 3, b - t - 3); }}void GUIAPI Draw3DUpThinFrame(HDC hDC, int l, int t, int r, int b, gal_pixel fillc){ SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT)); MoveTo(hDC, l, b); LineTo(hDC, r, b); LineTo(hDC, r, t); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT)); MoveTo(hDC, l, b); LineTo(hDC, l, t); LineTo(hDC, r, t); if (fillc != 0) { SetBrushColor(hDC, fillc); FillBox(hDC, l + 1, t + 1, r - l - 2, b - t - 2); }}void GUIAPI Draw3DDownThinFrame (HDC hDC, int l, int t, int r, int b, gal_pixel fillc){ SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_LEFT)); MoveTo(hDC, l, b); LineTo(hDC, r, b); LineTo(hDC, r, t); SetPenColor(hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT)); MoveTo(hDC, l, b); LineTo(hDC, l, t); LineTo(hDC, r, t); if (fillc != 0) { SetBrushColor(hDC, fillc); FillBox(hDC, l + 1, t + 1, r - l - 2, b - t - 2); }}void GUIAPI Draw3DBorder (HDC hdc, int l, int t, int r, int b){ SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT)); Rectangle (hdc, l + 1, t + 1, r - 1, b - 1); SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT)); Rectangle (hdc, l, t, r - 2, b - 2);}void GUIAPI DisabledTextOut (HDC hDC, int x, int y, const char* szText){ SetBkMode (hDC, BM_TRANSPARENT); SetTextColor (hDC, GetWindowElementColor (WEC_3DFRAME_LEFT)); TextOut (hDC, x + 1, y + 1, szText); SetTextColor (hDC, GetWindowElementColor (WEC_3DFRAME_RIGHT)); TextOut (hDC, x, y, szText);}#ifndef _INCORE_RES/****************************** System resource support *********************/BOOL GUIAPI LoadSystemBitmap (PBITMAP pBitmap, const char* szItemName){ char szPathName[MAX_PATH + 1]; char szFileName[MAX_PATH + 1]; char szValue[MAX_NAME + 1]; if (GetValueFromEtcFile(ETCFILEPATH, "bitmapinfo", szItemName, szValue, MAX_NAME) < 0 ) { fprintf (stderr, "Get bitmap file name error!\n"); return FALSE; } if (GetValueFromEtcFile(ETCFILEPATH, "bitmapinfo", "bitmappath", szPathName, MAX_PATH) < 0 ) { fprintf (stderr, "Get bitmap path error!\n"); return FALSE; } strcpy(szFileName, szPathName); strcat(szFileName, szValue); if (LoadBitmap (HDC_SCREEN, pBitmap, szFileName) < 0) { fprintf (stderr, "Load bitmap error: %s!\n", szFileName); return FALSE; } return TRUE;}HICON GUIAPI LoadSystemIcon (const char* szItemName, int which){ char szPathName[MAX_PATH + 1]; char szFileName[MAX_PATH + 1]; char szValue[MAX_NAME + 1]; HICON hIcon; if (GetValueFromEtcFile(ETCFILEPATH, "iconinfo", szItemName, szValue, MAX_NAME) < 0 ) { fprintf (stderr, "Get icon file name error!\n"); return 0; } if (GetValueFromEtcFile(ETCFILEPATH, "iconinfo", "iconpath", szPathName, MAX_PATH) < 0 ) { fprintf (stderr, "Get icon path error!\n"); return 0; } strcpy (szFileName, szPathName); strcat (szFileName, szValue); if ((hIcon = LoadIconFromFile (HDC_SCREEN, szFileName, which)) == 0) { fprintf (stderr, "Load icon error: %s!\n", szFileName); return 0; } return hIcon;}#endif /* _INCORE_RES */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -