void LaosFileSystem::makeshortname(char* shortname, char* name) { char *tmpname = new char[MAXFILESIZE]; strcpy(tmpname, name); removespaces(tmpname); shorten(tmpname, SHORTFILESIZE); char *basename = strtok(tmpname, "."); char *ext_name = strtok(NULL, "."); strtolower(basename); strtolower(ext_name); int cnt = 1; char fullname[MAXFILESIZE+SHORTFILESIZE+2]; FILE *fp = NULL; do { if (fp != NULL) fclose(fp); while ((cnt/10+strlen(basename)+2) > 8) basename[strlen(basename)-1] = 0; if (strlen(ext_name) > 0) { sprintf(shortname, "%s~%d.%s", basename, cnt++, ext_name); } else { sprintf(shortname, "%s~%d", basename, cnt++); } sprintf(fullname, "%s%s", pathname, shortname); fp = fopen(fullname, "rb"); } while (fp!=NULL); FILE *tfp = fopen(tablename, "ab"); dirwrite(name, shortname, tfp); fclose(tfp); delete(tmpname); }
bool moorecoinunits::parse(int unit, const qstring &value, camount *val_out) { if(!valid(unit) || value.isempty()) return false; // refuse to parse invalid unit or empty string int num_decimals = decimals(unit); // ignore spaces and thin spaces when parsing qstringlist parts = removespaces(value).split("."); if(parts.size() > 2) { return false; // more than one dot } qstring whole = parts[0]; qstring decimals; if(parts.size() > 1) { decimals = parts[1]; } if(decimals.size() > num_decimals) { return false; // exceeds max precision } bool ok = false; qstring str = whole + decimals.leftjustified(num_decimals, '0'); if(str.size() > 18) { return false; // longer numbers will exceed 63 bits } camount retvalue(str.tolonglong(&ok)); if(val_out) { *val_out = retvalue; } return ok; }
fz_error pdf_load_windows_font(pdf_xref *xref, pdf_font_desc *font, char *fontname) { fz_error error; pdf_windows_fontmap *found = NULL; char *comma; if (xref->win_fontlist->len == 0) pdf_create_windows_fontlist(xref); if (xref->win_fontlist->len == 0) return !fz_okay; if (getenv("MULOG")) printf("pdf_load_windows_font: looking for font '%s'\n", fontname); // work on a normalized copy of the font name fontname = fz_strdup(xref->ctx, fontname); removespaces(fontname); // first, try to find the exact font name (including appended style information) comma = strchr(fontname, ','); if (comma) { *comma = '-'; found = pdf_find_windows_font_path(xref, fontname); *comma = ','; } // second, substitute the font name with a known PostScript name else { int i; for (i = 0; i < _countof(baseSubstitutes) && !found; i++) if (!strcmp(fontname, baseSubstitutes[i].name)) found = pdf_find_windows_font_path(xref, baseSubstitutes[i].pattern); } // third, search for the font name without additional style information if (!found) found = pdf_find_windows_font_path(xref, fontname); // fourth, try to separate style from basename for prestyled fonts (e.g. "ArialBold") if (!found && !comma && (strendswith(fontname, "Bold") || strendswith(fontname, "Italic"))) { int styleLen = strendswith(fontname, "Bold") ? 4 : strendswith(fontname, "BoldItalic") ? 10 : 6; fontname = fz_realloc(xref->ctx, fontname, (strlen(fontname) + 2) * sizeof(char)); comma = fontname + strlen(fontname) - styleLen; memmove(comma + 1, comma, styleLen + 1); *comma = '-'; found = pdf_find_windows_font_path(xref, fontname); *comma = ','; if (!found) found = pdf_find_windows_font_path(xref, fontname); } if (found && (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats"))) font->flags |= PDF_FD_SYMBOLIC; fz_free(xref->ctx, fontname); if (!found) return !fz_okay; error = fz_new_font_from_file(xref->ctx, &font->font, found->fontpath, found->index); if (error) return fz_error_note(xref->ctx, error, "cannot load freetype font from a file %s", found->fontpath); font->font->ft_file = fz_strdup(xref->ctx, found->fontpath); if (getenv("MULOG")) printf("pdf_load_windows_font: loading font from '%s'\n", found->fontpath); return fz_okay; }
static fz_error parseTTF(fz_stream *file, int offset, int index, char *path, pdf_xref *xref) { fz_error err = fz_okay; TT_OFFSET_TABLE ttOffsetTable; TT_TABLE_DIRECTORY tblDir; TT_NAME_TABLE_HEADER ttNTHeader; TT_NAME_RECORD ttRecord; char szPSName[MAX_FACENAME] = { 0 }, szTTName[MAX_FACENAME] = { 0 }, szStyle[MAX_FACENAME] = { 0 }; int i, count, tblOffset; fz_seek(file,offset,0); err = safe_read(file, (char *)&ttOffsetTable, sizeof(TT_OFFSET_TABLE)); if (err) return err; // check if this is a TrueType font of version 1.0 or an OpenType font if (BEtoHl(ttOffsetTable.uVersion) != TTC_VERSION1 && ttOffsetTable.uVersion != TTAG_OTTO) return fz_error_make(file->ctx, "fonterror : invalid font version"); // determine the name table's offset by iterating through the offset table count = BEtoHs(ttOffsetTable.uNumOfTables); for (i = 0; i < count; i++) { err = safe_read(file, (char *)&tblDir, sizeof(TT_TABLE_DIRECTORY)); if (err) return err; if (!tblDir.uTag || BEtoHl(tblDir.uTag) == TTAG_name) break; } if (count == i || !tblDir.uTag) return fz_error_make(file->ctx, "fonterror : nameless font"); tblOffset = BEtoHl(tblDir.uOffset); // read the 'name' table for record count and offsets fz_seek(file, tblOffset, 0); err = safe_read(file, (char *)&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER)); if (err) return err; offset = tblOffset + sizeof(TT_NAME_TABLE_HEADER); tblOffset += BEtoHs(ttNTHeader.uStorageOffset); // read through the strings for PostScript name and font family count = BEtoHs(ttNTHeader.uNRCount); for (i = 0; i < count; i++) { short nameId; fz_seek(file, offset + i * sizeof(TT_NAME_RECORD), 0); err = safe_read(file, (char *)&ttRecord, sizeof(TT_NAME_RECORD)); if (err) return err; // ignore non-English strings if (ttRecord.uLanguageID && BEtoHs(ttRecord.uLanguageID) != TT_MS_LANGID_ENGLISH_UNITED_STATES) continue; // ignore names other than font (sub)family and PostScript name nameId = BEtoHs(ttRecord.uNameID); if (TT_NAME_ID_FONT_FAMILY == nameId) err = pdf_read_ttf_string(file, tblOffset, &ttRecord, szTTName, MAX_FACENAME); else if (TT_NAME_ID_FONT_SUBFAMILY == nameId) err = pdf_read_ttf_string(file, tblOffset, &ttRecord, szStyle, MAX_FACENAME); else if (TT_NAME_ID_PS_NAME == nameId) err = pdf_read_ttf_string(file, tblOffset, &ttRecord, szPSName, MAX_FACENAME); if (err) fz_error_handle(file->ctx, err, "ignoring face name decoding fonterror"); } // TODO: is there a better way to distinguish Arial Caps from Arial proper? // cf. http://code.google.com/p/sumatrapdf/issues/detail?id=1290 if (!strcmp(szPSName, "ArialMT") && (strstr(path, "caps") || strstr(path, "Caps"))) return fz_error_make(file->ctx, "ignore %s, as it can't be distinguished from Arial,Regular", path); if (szPSName[0]) { err = insertmapping(xref->ctx, xref->win_fontlist, szPSName, path, index); if (err) return err; } if (szTTName[0]) { // derive a PostScript-like name and add it, if it's different from the font's // included PostScript name; cf. http://code.google.com/p/sumatrapdf/issues/detail?id=376 // append the font's subfamily, unless it's a Regular font if (szStyle[0] && _stricmp(szStyle, "Regular") != 0) { fz_strlcat(szTTName, "-", MAX_FACENAME); fz_strlcat(szTTName, szStyle, MAX_FACENAME); } removespaces(szTTName); // compare the two names before adding this one if (lookupcompare(szTTName, szPSName)) { err = insertmapping(xref->ctx, xref->win_fontlist, szTTName, path, index); if (err) return err; } } return fz_okay; }
static int try_login(void) { char username[300]; int retvalue, passwdcnt; DDPut(sd[usernamestr]); username[0] = 0; Prompt(username, 25, 0); removespaces(username); if (!checkcarrier()) return -1; if (!username[0]) { DDPut(""); return -1; } if (!strcasecmp("new", username) && !(maincfg.CFG_FLAGS & (1L << 17))) { CreateNewAccount(); return -1; } if (!strcasecmp("logoff", username)) return 0; if (!strcasecmp("chat", username)) { pagesysop(0); return -1; } retvalue = checklogon(username); if (!retvalue && !(maincfg.CFG_FLAGS & (1L << 17))) { if (maincfg.CFG_FLAGS & (1L << 9)) return create_new_account() ? 0 : -1; else { DDPut(sd[unknownuserstr]); return -1; } } else { if (retvalue != 1 && !(maincfg.CFG_FLAGS & (1L << 18))) return -1; for (passwdcnt = 0; passwdcnt < 3; passwdcnt++) { username[0] = 0; if (ispw() || retvalue != 1) { DDPut(sd[passwordstr]); Prompt(username, 25, PROMPT_SECRET); } if (!checkcarrier()) return -1; if (retvalue > 0 && (!ispw() || cmppasswds(username, user.user_password))) { if (retvalue == 2) DDPut(sd[alreadyonlinestr]); else getin(); return 0; } else { if (passwdcnt != 2) DDPut(sd[tryagainstr]); clog.cl_flags |= CL_PASSWDFAIL; } } if (retvalue != 2) { TypeFile("passwordfailure", TYPE_MAKE); DDPut(sd[excessivepwfailstr]); return 0; } } return -1; }
void fconfig_reloadenv(void) { char *env; rrcs::safelock l(fcmutex); fetchenv_bool("VGL_AUTOTEST", autotest); fetchenv_str("VGL_CLIENT", client); if ((env = getenv("VGL_SUBSAMP")) != NULL && strlen(env) > 0) { int subsamp = -1; if (!strnicmp(env, "G", 1)) subsamp = 0; else { char *t = NULL; int itemp = strtol(env, &t, 10); if (t && t != env) { switch (itemp) { case 0: subsamp = 0; break; case 444: case 11: case 1: subsamp = 1; break; case 422: case 21: case 2: subsamp = 2; break; case 411: case 420: case 22: case 4: subsamp = 4; break; case 410: case 42: case 8: subsamp = 8; break; case 44: case 16: subsamp = 16; break; } } } if (subsamp >= 0 && (!fcenv_set || fcenv.subsamp != subsamp)) fconfig.subsamp = fcenv.subsamp = subsamp; } fetchenv_str("VGL_TRANSPORT", transport); if ((env = getenv("VGL_COMPRESS")) != NULL && strlen(env) > 0) { char *t = NULL; int itemp = strtol(env, &t, 10); int compress = -1; if (t && t != env && itemp >= 0 && (itemp < RR_COMPRESSOPT || strlen(fconfig.transport) > 0)) compress = itemp; else if (!strnicmp(env, "p", 1)) compress = RRCOMP_PROXY; else if (!strnicmp(env, "j", 1)) compress = RRCOMP_JPEG; else if (!strnicmp(env, "r", 1)) compress = RRCOMP_RGB; else if (!strnicmp(env, "x", 1)) compress = RRCOMP_XV; else if (!strnicmp(env, "y", 1)) compress = RRCOMP_YUV; if (compress >= 0 && (!fcenv_set || fcenv.compress != compress)) { fconfig_setcompress(fconfig, compress); fcenv.compress = compress; } } fetchenv_str("VGL_CONFIG", config); if ((env = getenv("VGL_DISPLAY")) != NULL && strlen(env) > 0) { #ifdef USEGLP if ((env[0] == '/' || !strnicmp(env, "GLP", 3))) { fconfig.glp = true; removespaces(env); } #endif if (!fcenv_set || strncmp(env, fcenv.localdpystring, MAXSTR - 1)) { strncpy(fconfig.localdpystring, env, MAXSTR - 1); strncpy(fcenv.localdpystring, env, MAXSTR - 1); } } fetchenv_dbl("VGL_FPS", fps, 0.0, 1000000.0); if ((env = getenv("VGL_GAMMA")) != NULL && strlen(env) > 0) { if (!strcmp(env, "1")) { if (!fcenv_set || fcenv.gamma_usesun != 1 || fcenv.gamma != 2.22) { fconfig.gamma_usesun = fcenv.gamma_usesun = 1; fcenv.gamma = 2.22; fconfig_setgamma(fconfig, 2.22); } } else if (!strcmp(env, "0")) { if (!fcenv_set || fcenv.gamma_usesun != 0 || fcenv.gamma != 1.0) { fconfig.gamma_usesun = fcenv.gamma_usesun = 0; fcenv.gamma = 1.0; fconfig_setgamma(fconfig, 1.0); } } else { char *t = NULL; double dtemp = strtod(env, &t); if (t && t != env && (!fcenv_set || fcenv.gamma_usesun != 0 || fcenv.gamma != dtemp)) { fconfig.gamma_usesun = fcenv.gamma_usesun = 0; fcenv.gamma = dtemp; fconfig_setgamma(fconfig, dtemp); } } } fetchenv_str("VGL_GLLIB", gllib); fetchenv_str("VGL_GUI", guikeyseq); if (strlen(fconfig.guikeyseq) > 0) { if (!stricmp(fconfig.guikeyseq, "none")) fconfig.gui = false; else { unsigned int mod = 0, key = 0; for (unsigned int i = 0; i < strlen(fconfig.guikeyseq); i++) fconfig.guikeyseq[i] = tolower(fconfig.guikeyseq[i]); if (strstr(fconfig.guikeyseq, "ctrl")) mod |= ControlMask; if (strstr(fconfig.guikeyseq, "alt")) mod |= Mod1Mask; if (strstr(fconfig.guikeyseq, "shift")) mod |= ShiftMask; if (strstr(fconfig.guikeyseq, "f10")) key = XK_F10; else if (strstr(fconfig.guikeyseq, "f11")) key = XK_F11; else if (strstr(fconfig.guikeyseq, "f12")) key = XK_F12; else if (strstr(fconfig.guikeyseq, "f1")) key = XK_F1; else if (strstr(fconfig.guikeyseq, "f2")) key = XK_F2; else if (strstr(fconfig.guikeyseq, "f3")) key = XK_F3; else if (strstr(fconfig.guikeyseq, "f4")) key = XK_F4; else if (strstr(fconfig.guikeyseq, "f5")) key = XK_F5; else if (strstr(fconfig.guikeyseq, "f6")) key = XK_F6; else if (strstr(fconfig.guikeyseq, "f7")) key = XK_F7; else if (strstr(fconfig.guikeyseq, "f8")) key = XK_F8; else if (strstr(fconfig.guikeyseq, "f9")) key = XK_F9; if (key) fconfig.guikey = key; fconfig.guimod = mod; fconfig.gui = true; } } fetchenv_bool("VGL_INTERFRAME", interframe); fetchenv_str("VGL_LOG", log); fetchenv_bool("VGL_LOGO", logo); if ((env = getenv("VGL_MCOMPRESS")) != NULL && strlen(env) > 0) { char *t = NULL; int itemp = strtol(env, &t, 10); int mcompress = -1; if (t && t != env && itemp >= RRCOMP_JPEG && itemp <= RRCOMP_RGB) mcompress = itemp; else if (!strnicmp(env, "j", 1)) mcompress = RRCOMP_JPEG; else if (!strnicmp(env, "r", 1)) mcompress = RRCOMP_RGB; if (mcompress >= 0 && (!fcenv_set || fcenv.mcompress != mcompress)) fconfig.mcompress = fcenv.mcompress = mcompress; } fetchenv_str("VGL_MOVIE", moviefile); fetchenv_int("VGL_MQUAL", mqual, 1, 100); if ((env = getenv("VGL_MSUBSAMP")) != NULL && strlen(env) > 0) { int msubsamp = -1; if (!strnicmp(env, "G", 1)) msubsamp = 0; else { char *t = NULL; int itemp = strtol(env, &t, 10); if (t && t != env) { switch (itemp) { case 0: msubsamp = 0; break; case 444: case 11: case 1: msubsamp = 1; break; case 422: case 21: case 2: msubsamp = 2; break; case 411: case 420: case 22: case 4: msubsamp = 4; break; } } } if (msubsamp >= 0 && (!fcenv_set || fcenv.msubsamp != msubsamp)) fconfig.msubsamp = fcenv.msubsamp = msubsamp; } fetchenv_int("VGL_NPROCS", np, 1, min(numprocs(), MAXPROCS)); fetchenv_int("VGL_PORT", port, 0, 65535); fetchenv_int("VGL_QUAL", qual, 1, 100); fetchenv_bool("VGL_READBACK", readback); fetchenv_int("VGL_SAMPLES", samples, 0, 64); fetchenv_bool("VGL_SPOIL", spoil); fetchenv_bool("VGL_SSL", ssl); { if ((env = getenv("VGL_STEREO")) != NULL && strlen(env) > 0) { int stereo = -1; if (!strnicmp(env, "L", 1)) stereo = RRSTEREO_LEYE; else if (!strnicmp(env, "RC", 2)) stereo = RRSTEREO_REDCYAN; else if (!strnicmp(env, "R", 1)) stereo = RRSTEREO_REYE; else if (!strnicmp(env, "Q", 1)) stereo = RRSTEREO_QUADBUF; else { char *t = NULL; int itemp = strtol(env, &t, 10); if (t && t != env && itemp >= 0 && itemp < RR_STEREOOPT) stereo = itemp; } if (stereo >= 0 && (!fcenv_set || fcenv.stereo != stereo)) fconfig.stereo = fcenv.stereo = stereo; } } fetchenv_bool("VGL_SYNC", sync); fetchenv_int("VGL_TILESIZE", tilesize, 8, 1024); fetchenv_bool("VGL_TRACE", trace); fetchenv_int("VGL_TRANSPIXEL", transpixel, 0, 255); fetchenv_bool("VGL_TRAPX11", trapx11); fetchenv_bool("VGL_WINDOW", usewindow); fetchenv_str("VGL_XVENDOR", vendor); fetchenv_bool("VGL_VERBOSE", verbose); fetchenv_str("VGL_X11LIB", x11lib); if (strlen(fconfig.transport) > 0) { if (fconfig.compress < 0) fconfig.compress = 0; if (fconfig.subsamp < 0) fconfig.subsamp = 1; } if (fconfig.glp) fconfig.usewindow = false; fcenv_set = true; }
/* FIXME! buffer overflows? */ static int handle_choice(const char *askbuf) { char lesbabuf[30]; struct userbase muser = user; int leps; if (!(strcasecmp(askbuf, "1"))) { for (;;) { if (!isaccess(SECB_REALNAME, access2)) break; DDPut(sd[eu1str]); strlcpy(lesbabuf, user.user_realname, sizeof lesbabuf); if (!(Prompt(lesbabuf, 25, 0))) return 1; removespaces(lesbabuf); if (strcasecmp(lesbabuf, user.user_realname)) { leps = findusername(lesbabuf); if (leps == user.user_account_id || leps == -1) { if (lesbabuf[0]) strlcpy(user.user_realname, lesbabuf, sizeof user.user_realname); } else { DDPut(sd[newalreadystr]); continue; } } break; } } else if (!(strcasecmp(askbuf, "2"))) { for (;;) { if (!isaccess(SECB_HANDLE, access2)) break; DDPut(sd[eu2str]); strlcpy(lesbabuf, user.user_handle, sizeof lesbabuf); if (!(Prompt(lesbabuf, 25, 0))) return 1; removespaces(lesbabuf); if (strcasecmp(lesbabuf, user.user_handle)) { leps = findusername(lesbabuf); if (leps == user.user_account_id || leps == -1) { if (lesbabuf[0]) strlcpy(user.user_handle, lesbabuf, sizeof user.user_handle); } else { DDPut(sd[newalreadystr]); continue; } } break; } } else if (!(strcasecmp(askbuf, "3"))) { DDPut(sd[eu3str]); if (!(Prompt(user.user_organization, 25, 0))) return 1; } else if (!(strcasecmp(askbuf, "4"))) { DDPut(sd[eu4str]); if (!(Prompt(user.user_zipcity, 20, 0))) return 1; } else if (!(strcasecmp(askbuf, "5"))) { DDPut(sd[eu5str]); if (!(Prompt(user.user_voicephone, 20, 0))) return 1; } else if (!(strcasecmp(askbuf, "6"))) { MD_CTX context; char verifypw[32]; DDPut(sd[eu6str]); lesbabuf[0] = 0; if (!(Prompt(lesbabuf, 15, PROMPT_SECRET))) return 1; if (lesbabuf[0] == 0) return 0; *verifypw = 0; DDPut(sd[euverifypwstr]); if (!(Prompt(verifypw, 15, PROMPT_SECRET))) return 1; if (strcasecmp(lesbabuf, verifypw)) { DDPut(sd[eunomatchstr]); return 0; } strupr(lesbabuf); MDInit(&context); MDUpdate(&context, (unsigned char *) lesbabuf, strlen(lesbabuf)); MDFinal(user.user_password, &context); } else if (!strcasecmp(askbuf, "7")) { for (;;) { int fallos; DDPut(sd[eu7str]); lesbabuf[0] = 0; if (!(Prompt(lesbabuf, 3, 0))) return 1; if (lesbabuf[0] == 't' || lesbabuf[0] == 'T') { testscreenl(); continue; } fallos = atoi(lesbabuf); if (fallos < 10) { DDPut(sd[newminslstr]); continue; } user.user_screenlength = fallos; break; } } else if (!(strcasecmp(askbuf, "8"))) { struct DayDream_Protocol *tp; TypeFile("protocols", TYPE_MAKE | TYPE_WARN); DDPut(sd[eu8str]); *lesbabuf = 0; if (user.user_protocol) { *lesbabuf = user.user_protocol; lesbabuf[1] = 0; } if (!(Prompt(lesbabuf, 3, 0))) return 1; *lesbabuf = toupper(*lesbabuf); if (!*lesbabuf) return 0; tp = protocols; for (;;) { if (tp->PROTOCOL_ID == 0) return 0; if (tp->PROTOCOL_ID == *lesbabuf) { protocol = tp; user.user_protocol = *lesbabuf; return 0; } tp++; } } else if (!(strcasecmp(askbuf, "9"))) { DDPut(sd[eu9str]); if (!(Prompt(user.user_signature, 44, 0))) return 1; } else if (!(strcasecmp(askbuf, "10"))) { DDPut(sd[eu10str]); if (!(Prompt(user.user_computermodel, 20, 0))) return 1; } else if (!(strcasecmp(askbuf, "11"))) { DDPut(sd[eu11str]); snprintf(lesbabuf, sizeof lesbabuf, "%d", user.user_flines); if (!(Prompt(lesbabuf, 3, 0))) return 1; user.user_flines = atoi(lesbabuf); } else if (!(strcasecmp(askbuf, "12"))) { rundoor("doors/autosig %N", 0); return 1; } else if (!(strcasecmp(askbuf, "a"))) { DDPut(sd[euabortedstr]); user = muser; return 1; } else if (!(strcasecmp(askbuf, "v"))) { TypeFile("edituser", TYPE_MAKE | TYPE_WARN); } else if (!(strcasecmp(askbuf, "s"))) { switches(); } else if ((!(strcasecmp(askbuf, "c")) || (askbuf[0] == 0))) { DDPut(sd[eusavedstr]); saveuserbase(&user); return 1; } return 0; }