static void load_nls(void) { const char *lang_file = ReadString(extensionsrcPath(), "blackbox.options.language:", NULL); if (NULL == lang_file) return; char full_path[MAX_PATH]; FILE *fp = fopen (make_bb_path(full_path, lang_file), "rb"); if (NULL == fp) return; char line[4000], key[200], new_text[4000], *np; int nl; key[0] = 0; new_text[0] = 0; np = new_text; nl = 0; for (;;) { bool eof = false == read_next_line(fp, line, sizeof line); char *s = line, c = *s; if ('$' == c || eof) { if (key[0] && new_text[0]) { struct nls *t = (struct nls *)c_alloc(sizeof *t + strlen(key)); t->hash = calc_hash(t->key, key, &t->k); t->translation = new_str(new_text); cons_node(&pNLS, t); } if (eof) break; if (' ' == s[1]) s += 2; decode_escape(key, s); new_text[0] = 0; np = new_text; nl = 0; continue; } if ('#' == c || '!' == c) continue; if ('\0' != c) { while (nl--) *np++ = '\n'; np += decode_escape(np, s); nl = 0; } nl ++; } fclose(fp); reverse_list(&pNLS); }
void log_printf(int flag, const char *fmt, ...) { if ((Settings_LogFlag & flag) || 0 == (flag & 0x7FFF)) { if (NULL == hlog_file) { char log_path[MAX_PATH]; hlog_file = CreateFile( make_bb_path(log_path, "blackbox.log"), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); SetFilePointer(hlog_file, 0, NULL, FILE_END); char date[32]; _strdate(date); char time[10]; _strtime(time); log_printf(flag, "\nStarting Log %s %s\n", date, time); } char buffer[4096]; buffer[0] = 0; if ('\n' != *fmt) { if (0 == (0x8000 & flag)) _strtime(buffer); strcat(buffer, " "); } va_list arg; va_start(arg, fmt); vsprintf (buffer+strlen(buffer), fmt, arg); strcat(buffer, "\n"); DWORD written; WriteFile(hlog_file, buffer, strlen(buffer), &written, NULL); } }
int CreateRecentItemMenu(char *pszFileName, char *pszCommand, char *pszTitle, char *pszIcon, int nKeep, int nSort, bool bBeginEnd){ static ItemList *KeepItemList; static ItemList *SortItemList; char szFilePath[MAX_PATH]; char buf[MAX_PATH]; ItemList *iln = (ItemList*)m_alloc(sizeof(ItemList)); // make path (compliant with relative-path) make_bb_path(szFilePath, pszFileName); // Newer Item if (pszIcon && *pszIcon) _snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s} <%s>", pszTitle, pszCommand, pszIcon); else _snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s}", pszTitle, pszCommand); _strcpy(iln->szItem, buf); iln->nFrequency = 1; append_node(&KeepItemList, iln); int cnt_k = 0; // keep items counter int cnt_s = 0; // sort items counter if (FILE *fp = fopen(szFilePath, "r")){ // read Recent-menu while(fgets(buf, MAX_PATH, fp)){ if (strstr(buf, "[end]")) break; else if (strstr(buf, "[exec]")){ if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; char *p0 = strchr(buf, '{'); // command char *p1 = strchr(buf, '}'); // end of command if (p0 && p1){ UINT nFrequency = 0; if (char *p = strrchr(buf, '#')){ nFrequency = atoi(p+1); while(*(p--) == ' '); // delete space of eol *p = '\0'; } if (0 != strnicmp(pszCommand, p0+1 , p1 - p0 - 1)){ // ignore duplicated item ItemList *il = (ItemList*)m_alloc(sizeof(ItemList)); _strcpy(il->szItem, buf); il->nFrequency = imin(nFrequency, UINT_MAX); if (cnt_k++ < nKeep - 1) append_node(&KeepItemList, il); else if (cnt_s++ < nSort) append_node(&SortItemList, il); else m_free(il); } else{ // if duplicate, increment freq iln->nFrequency += imin(nFrequency, UINT_MAX - 1); } } } } fclose(fp); } bool isSortList = listlen(SortItemList) != 0; bool isKeepList = listlen(KeepItemList) != 0; if (isSortList) SortItemList = sortlist(SortItemList); if (FILE *fp = fopen(szFilePath, "w")){ // write Recent-menu if (bBeginEnd) fprintf(fp, "[begin] (Recent Item)\n"); // most recent item ItemList *p; dolist (p, KeepItemList){ fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency); } if (isKeepList && isSortList) fprintf(fp, "\t[separator]\n"); dolist (p, SortItemList){ fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency); }