void ScopeI::wakeupRaw(int) { // dbx("wakeup raw"); try { int r = sleeper->poll(); switch (r) { case Wakeup::Trig: // fall through to Poll stuff. if (seentrig) { nexttrig = rawsf->aux()->trig.t_latest + rawsf->first(); seentrig = false; } case Wakeup::Poll: { if (!rawpoll) { rawpoll=true; setStatus(rawstatus, Wakeup::Poll, rawpoll, rawsf); } if (freezeflag->isChecked()) break; timeref_t sftime = rawsf->latest(); timeref_t next; if (trigflag->isChecked()) { next = nexttrig + scopes->period() - pretrig->value()*FREQKHZ; if (next > sftime || next==scopes->latest()) break; seentrig = true; } else { timeref_t last = scopes->latest(); next = last + scopes->period(); if (next > sftime) break; if (sftime - next > MAXLAG) next = sftime; // lose some (partial) frames // sdbx("Scope: refresh %.3f",next/25000.0); } scopes->refresh(next); timeref_t ival = next - scopes->first(); time->setText(Sprintf("%.3f s",ival/1000./FREQKHZ).c_str()); } break; case Wakeup::Start: { freeze(false); freezeflag->setChecked(false); rawpoll=false; setStatus(rawstatus, Wakeup::Start, rawpoll, rawsf); copybasics(); scopes->restart(); nexttrig = scopes->latest(); seentrig = true; } break; case Wakeup::Stop: rawpoll=false; setStatus(rawstatus, Wakeup::Stop, rawpoll, rawsf); break; default: break; } } catch (Expectable const &e) { // probably EOF e.report(); reopen_raw(); } }
void FreezeInfo::scrollTo(int dt_ms) { timeref_t endtime = t0 + (dt_ms+width_ms)*FREQKHZ; sdbx("freezeinfo scrollto: %i - endtime=%Li",dt_ms,endtime); backend->refresh(endtime); timeref_t ival = endtime - backend->first(); timereport->setText(Sprintf("%.3f s",ival/1000./FREQKHZ).c_str()); sdbx("freezeinfo scrollto: refresh done"); }
/* outrip(winid, int) -- The tombstone code. If you want the traditional code use genl_outrip for the value and check the #if in rip.c. */ void gnome_outrip(winid wid, int how) { /* Follows roughly the same algorithm as genl_outrip() */ char buf[BUFSZ]; char ripString[BUFSZ]="\0"; extern const char *killed_by_prefix[]; /* Put name on stone */ Sprintf(buf, "%s\n", plname); Strcat(ripString, buf); /* Put $ on stone */ Sprintf(buf, "%ld Au\n", #ifndef GOLDOBJ u.ugold); #else done_money); #endif Strcat(ripString, buf); /* Put together death description */ switch (killer_format) { default: impossible("bad killer format?"); case KILLED_BY_AN: Strcpy(buf, killed_by_prefix[how]); Strcat(buf, an(killer)); break; case KILLED_BY: Strcpy(buf, killed_by_prefix[how]); Strcat(buf, killer); break; case NO_KILLER_PREFIX: Strcpy(buf, killer); break; } /* Put death type on stone */ Strcat(ripString, buf); Strcat(ripString, "\n"); /* Put year on stone */ Sprintf(buf, "%4d\n", getyear()); Strcat(ripString, buf); ghack_text_window_rip_string( ripString); }
static char * sitoa(int a) { static char buf[13]; Sprintf(buf, (a < 0) ? "%d" : "+%d", a); return (buf); }
Psym *hoc_getsym(const char* cp) { Symbol *sp, *sym; Symlist *symlist = (Symlist *)0; Inst *last, *pcsav; int i, n; char s[256]; Psym *p=0; Sprintf(s, "{%s}\n", cp); sp = hoc_install("", PROCEDURE, 0., &symlist); sp->u.u_proc->defn.in = STOP; sp->u.u_proc->list = (Symlist *)0; sp->u.u_proc->nauto = 0; n = hoc_xopen_run(sp, s); last = (Inst *)sp->u.u_proc->defn.in + n; if (n < 5 || last[-3].pf != hoc_eval) { hoc_execerror(s, " not a variable"); } last[-3].in = STOP; /*before doing last EVAL*/ pcsav = hoc_pc; hoc_execute(sp->u.u_proc->defn.in); hoc_pc = pcsav; sym = hoc_spop(); switch(sym->type) { case UNDEF: hoc_execerror(s, " is undefined"); case VAR: if (ISARRAY(sym)) { Arrayinfo* a; if (sym->subtype == NOTUSER) { a = OPARINFO(sym); }else{ a = sym->arayinfo; } p = (Psym *)emalloc((unsigned)(sizeof(Psym) + a->nsub)); p->arayinfo = a; ++a->refcount; p->nsub = a->nsub; for (i=p->nsub; i > 0;) { p->sub[--i] = hoc_xpop(); } } else { p = (Psym *)emalloc(sizeof(Psym)); p->arayinfo = 0; p->nsub = 0; } p->sym = sym; break; case AUTO: hoc_execerror(s, " is local variable"); default: hoc_execerror(s, " not a variable"); } hoc_free_list(&symlist); return p; }
INT_PTR CALLBACK CClassicCopyFolder::DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { if (uMsg==WM_INITDIALOG) { SetWindowText(hwndDlg,FindTranslation(L"Folder.Title",L"Confirm Folder Replace")); CClassicCopyFolder *pThis=(CClassicCopyFolder*)lParam; wchar_t text[2048]; // find the link control and get its text HWND link=FindWindowEx(pThis->m_Original,NULL,WC_LINK,NULL); if (link) GetWindowText(link,text,_countof(text)); else text[0]=0; Strcat(text,_countof(text),L"\r\n\r\n"); Strcat(text,_countof(text),FindTranslation(L"Folder.Prompt",L"Do you still want to move or copy the folder?")); SetDlgItemText(hwndDlg,IDC_STATICFNAME,text); // load icon for file conflict (146) from Shell32.dll HMODULE hShell32=GetModuleHandle(L"Shell32.dll"); pThis->m_Icon=LoadIcon(hShell32,MAKEINTRESOURCE(146)); if (pThis->m_Icon) SendDlgItemMessage(hwndDlg,IDC_STATICICON1,STM_SETICON,(LPARAM)pThis->m_Icon,0); // set the localized text SetDlgItemText(hwndDlg,IDOK,FindTranslation(L"Copy.Yes",L"&Yes")); SetDlgItemText(hwndDlg,IDNO,FindTranslation(L"Copy.No",L"&No")); if (GetDlgItem(hwndDlg,IDYES)) SetDlgItemText(hwndDlg,IDYES,FindTranslation(L"Copy.YesAll",L"Yes to &All")); if (GetDlgItem(hwndDlg,IDCANCEL)) SetDlgItemText(hwndDlg,IDCANCEL,FindTranslation(L"Copy.Cancel",L"Cancel")); Sprintf(text,_countof(text),L"<a>%s</a>",FindTranslation(L"Copy.More",L"&More...")); SetDlgItemText(hwndDlg,IDC_LINKMORE,text); PostMessage(hwndDlg,WM_BRINGFOREGROUND,0,0); return TRUE; } if (uMsg==WM_BRINGFOREGROUND) { // bring window to front (sometimes on Windows7 it shows up behind Explorer) SetForegroundWindow(hwndDlg); return TRUE; } if (uMsg==WM_COMMAND && (wParam==IDOK || wParam==IDYES || wParam==IDNO || wParam==IDCANCEL)) { EndDialog(hwndDlg,wParam); return TRUE; } if (uMsg==WM_NOTIFY) { NMHDR *pHdr=(NMHDR*)lParam; if (pHdr->idFrom==IDC_LINKMORE && (pHdr->code==NM_CLICK || pHdr->code==NM_RETURN)) { EndDialog(hwndDlg,IDC_LINKMORE); return TRUE; } } return FALSE; }
void done_in_by(struct monst *mtmp) { static char buf[BUFSZ]; pline("You die ..."); if(mtmp->data->mlet == ' '){ Sprintf(buf, "the ghost of %s", (char *) mtmp->mextra); killer = buf; } else if(mtmp->mnamelth) { Sprintf(buf, "%s called %s", mtmp->data->mname, NAME(mtmp)); killer = buf; } else if(mtmp->minvis) { Sprintf(buf, "invisible %s", mtmp->data->mname); killer = buf; } else killer = mtmp->data->mname; done("died"); }
char * sitoa(int n) /* make a signed digit string from a number */ { Static char buf[13]; Sprintf(buf, (n < 0) ? "%d" : "+%d", n); return buf; }
static Str ftp_command(FTP ftp, char *cmd, char *arg, int *status) { Str tmp; if (!ftp->host) return NULL; if (cmd) { if (arg) tmp = Sprintf("%s %s\r\n", cmd, arg); else tmp = Sprintf("%s\r\n", cmd); fwrite(tmp->ptr, sizeof(char), tmp->length, ftp->wf); fflush(ftp->wf); } if (!status) return NULL; *status = -1; /* error */ tmp = StrISgets(ftp->rf); if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) && IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') sscanf(tmp->ptr, "%d", status); if (tmp->ptr[3] != '-') return tmp; /* RFC959 4.2 FTP REPLIES */ /* multi-line response start */ /* * Thus the format for multi-line replies is that the * first line will begin with the exact required reply * code, followed immediately by a Hyphen, "-" (also known * as Minus), followed by text. The last line will begin * with the same code, followed immediately by Space <SP>, * optionally some text, and the Telnet end-of-line code. */ while (1) { tmp = StrISgets(ftp->rf); if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) && IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') { sscanf(tmp->ptr, "%d", status); break; } } return tmp; }
void editMailcap(char *mailcap, struct parsed_tagarg *args) { TextList *t = newTextList(); TextListItem *ti; FILE *f; Str tmp; char *type, *viewer; struct parsed_tagarg *a; bool delete_it; if ((f = fopen(mailcap, "rt")) == NULL) bye("Can't open", mailcap); while (tmp = Strfgets(f), tmp->length > 0) { if (tmp->ptr[0] == '#') continue; Strchop(tmp); extractMailcapEntry(tmp->ptr, &type, &viewer); delete_it = false; for (a = args; a != NULL; a = a->next) { if (!strcmp(a->arg, "delete") && !strcmp(a->value, type)) { delete_it = true; break; } } if (!delete_it) pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr); } type = tag_get_value(args, "newtype"); viewer = tag_get_value(args, "newcmd"); if (type != NULL && *type != '\0' && viewer != NULL && *viewer != '\0') pushText(t, Sprintf("%s;\t%s\n", type, viewer)->ptr); fclose(f); if ((f = fopen(mailcap, "w")) == NULL) bye("Can't write to", mailcap); for (ti = t->first; ti != NULL; ti = ti->next) fputs(ti->ptr, f); fclose(f); printf("Content-Type: text/plain\n"); printf("w3m-control: BACK\nw3m-control: BACK\n"); printf("w3m-control: REINIT MAILCAP\n"); }
static void add_news_message(Str str, int index, char *date, char *name, char *subject, char *mid, char *scheme, char *group) { time_t t; struct tm *tm; name = name_from_address(name, 16); t = mymktime(date); tm = localtime(&t); Strcat(str, Sprintf("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s", index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name))); if (group) Strcat(str, Sprintf("<td><a href=\"%s%s/%d\">%s</a>\n", scheme, group, index, html_quote(subject))); else Strcat(str, Sprintf("<td><a href=\"%s%s\">%s</a>\n", scheme, html_quote(file_quote(mid)), html_quote(subject))); }
UnicodeString FmtLoadStr(intptr_t Id, fmt::ArgList args) { UnicodeString Fmt = GetGlobals()->GetMsg(Id); if (!Fmt.IsEmpty()) { UnicodeString Result = Sprintf(Fmt, args); return Result; } DEBUG_PRINTF("Unknown resource string id: %d\n", Id); return UnicodeString(); }
char * getdate() { static char datestr[7]; register struct tm *lt = getlt(); Sprintf(datestr, "%2d%2d%2d", lt->tm_year, lt->tm_mon + 1, lt->tm_mday); if(datestr[2] == ' ') datestr[2] = '0'; if(datestr[4] == ' ') datestr[4] = '0'; return(datestr); }
/* setup cookie for local CGI */ Str localCookie() { char hostname[256]; if (Local_cookie) return Local_cookie; gethostname(hostname, 256); srand48((long)New(char) + (long)time(NULL)); Local_cookie = Sprintf("%ld@%s", lrand48(), hostname); return Local_cookie; }
static void PutOctalString(Stream& out, const char *b, const char *e, bool split = false) { out.Put('\"'); int64 start = out.GetPos(); while(b < e) { if(split && out.GetPos() >= start + 200u) { out.Put("\"\r\n\t\""); start = out.GetPos(); } if((byte)*b >= ' ' && *b != '\x7F' && *b != '\xFF') { if(*b == '\\' || *b == '\"' || *b == '\'') out.Put('\\'); out.Put(*b++); } else if(IsDigit(b[1])) out.Put(Sprintf("\\%03o", (byte)*b++)); else out.Put(Sprintf("\\%o", (byte)*b++)); } out.Put('\"'); }
static Str to_str(struct param_ptr *p) { switch (p->type) { case P_INT: #ifdef USE_COLOR case P_COLOR: #endif #ifdef USE_M17N case P_CODE: return Sprintf("%d", (int)(*(wc_ces *) p->varptr)); #endif case P_NZINT: return Sprintf("%d", *(int *)p->varptr); case P_SHORT: return Sprintf("%d", *(short *)p->varptr); case P_CHARINT: return Sprintf("%d", *(char *)p->varptr); case P_CHAR: return Sprintf("%c", *(char *)p->varptr); case P_STRING: #if defined(USE_SSL) && defined(USE_SSL_VERIFY) case P_SSLPATH: #endif /* SystemCharset -> InnerCharset */ return Strnew_charp(conv_from_system(*(char **)p->varptr)); case P_PIXELS: case P_SCALE: return Sprintf("%g", *(double *)p->varptr); } /* not reached */ return NULL; }
// it's the function that Lua scripts will see as "tfexec" static int tfeval_for_lua(lua_State *state) { String *func; const char *arg = luaL_checkstring(state, 1); (func = Stringnew(NULL, 0, 0))->links++; Sprintf(func, arg); handle_eval_command(func, 0); Stringfree(func); return 0; }
static int parseFrameSetLength(char *s, char ***ret) { int i, len; char *p, *q, **lv; i = 1; if (s) for (p = s; (p = strchr(p, ',')); ++p) ++i; else s = "*"; lv = New_N(char *, i); for (i = 0, p = s;; ++p) { SKIP_BLANKS(p); len = strtol(p, &q, 10); switch (*q) { case '%': lv[i++] = Sprintf("%d%%", len)->ptr; break; case '*': lv[i++] = "*"; break; default: lv[i++] = Sprintf("%d", len)->ptr; break; } if (!(p = strchr(q, ','))) break; } *ret = lv; return i; }
void list_symbol() { unsigned int i=0; char debug__[80]; i = 0; while(tab_import_symb[i].address && (i<MAX_SYMBOL)) { Sprintf(debug__, "%s %.8X", tab_import_symb[i].name, tab_import_symb[i].address); insertinbuffer(debug__); i++; } }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteBool( bool data, const char* optionalLabel ) { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) { // DEBUGGING - { int q = 5; } //ConsolePrintf( "WriteBool: Writing bool, value=%d, at offset %d (\"%s\")\n", (int) data, m_dataBytesAvailable, optionalLabel ? optionalLabel : "" ); WriteByte( (unsigned char) data, optionalLabel ); return; } std::string asText; Sprintf( asText, "%s ", data ? "true" : "false" ); WriteStringIndentedIfNeeded( asText ); WriteLineEndIfVerbose( optionalLabel ); }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteShort( short data, const char* optionalLabel ) { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) { // DEBUGGING - { int q = 5; } //ConsolePrintf( "WriteShort: value=%d, at offset %d (\"%s\")\n", data, m_dataBytesAvailable, optionalLabel ? optionalLabel : "" ); WriteBinaryType( data ); return; } std::string asText; Sprintf( asText, "%d ", data ); WriteStringIndentedIfNeeded( asText ); WriteLineEndIfVerbose( optionalLabel ); }
static Str news_command(News * news, char *cmd, char *arg, int *status) { Str tmp; if (!news->host) return NULL; if (cmd) { if (arg) tmp = Sprintf("%s %s\r\n", cmd, arg); else tmp = Sprintf("%s\r\n", cmd); fwrite(tmp->ptr, sizeof(char), tmp->length, news->wf); fflush(news->wf); } if (!status) return NULL; *status = -1; tmp = StrISgets(news->rf); if (tmp->length) sscanf(tmp->ptr, "%d", status); return tmp; }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteAABB2( const AABB2& data, const char* optionalLabel ) { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) { // DEBUGGING - { int q = 5; } //ConsolePrintf( "WriteAABB2: value=(%g,%g),(g,%g), at offset %d (\"%s\")\n", data.mins.x, data.mins.y, data.maxs.x, data.maxs.y, m_dataBytesAvailable, optionalLabel ? optionalLabel : "" ); WriteBinaryType( data ); return; } std::string asText; Sprintf( asText, "AABB2[(%g,%g),(%g,%g)] ", data.mins.x, data.mins.y, data.maxs.x, data.maxs.y ); WriteStringIndentedIfNeeded( asText ); WriteLineEndIfVerbose( optionalLabel ); }
static void WriteString( HANDLE csv, int id, const wchar_t *string, int len, CSettingsParser &parser, int subid=INT_MAX ) { DWORD q; wchar_t buf[256]; int len2; if (subid!=INT_MAX) len2=Sprintf(buf,_countof(buf),L"%d/%d",id,subid&65535); else len2=Sprintf(buf,_countof(buf),L"%d",id); const wchar_t *comment=parser.FindSetting(buf); if (comment && _wcsicmp(comment,L"ignore")==0) return; WriteFile(csv,buf,len2*2,&q,NULL); WriteFile(csv,L"\t",2,&q,NULL); for (int i=0;i<len;i++) { WORD c=string[i]; if (c=='\t') WriteFile(csv,L"\\t",4,&q,NULL); else if (c=='\r') WriteFile(csv,L"\\r",4,&q,NULL); else if (c=='\n') WriteFile(csv,L"\\n",4,&q,NULL); else if (c=='\\') WriteFile(csv,L"\\\\",4,&q,NULL); else WriteFile(csv,&c,2,&q,NULL); } WriteFile(csv,L"\t\t",4,&q,NULL); if (comment) WriteFile(csv,comment,Strlen(comment)*2,&q,NULL); WriteFile(csv,L"\r\n",4,&q,NULL); }
int CSettingsParser::ParseTreeRec( const wchar_t *str, std::vector<TreeItem> &items, CString *names, int level ) { size_t start=items.size(); while (*str) { wchar_t token[256]; str=GetToken(str,token,_countof(token),L", \t"); if (token[0]) { // bool bFound=false; for (int i=0;i<level;i++) if (_wcsicmp(token,names[i])==0) { bFound=true; break; } if (!bFound) { TreeItem item={token,-1}; items.push_back(item); } } } size_t end=items.size(); if (start==end) return -1; TreeItem item={L"",-1}; items.push_back(item); if (level<MAX_TREE_LEVEL-1) { for (size_t i=start;i<end;i++) { wchar_t buf[266]; Sprintf(buf,_countof(buf),L"%s.Items",items[i].name); const wchar_t *str2=FindSetting(buf); if (str2) { names[level]=items[i].name; // these two statements must be on separate lines. otherwise items[i] is evaluated before ParseTreeRec, but // the items vector can be reallocated inside ParseTreeRec, causing the address to be invalidated -> crash! int idx=ParseTreeRec(str2,items,names,level+1); items[i].children=idx; } } } return (int)start; }
void ListSysEnhanced(FILE *fpout, const T_hklCond *cnd, const int *SysEnhanced, int cndn) { int i,j,n,m; char hkl[3]="hkl"; int x[3]; int S[3][3]; char buf[128]; Fprintf(fpout, "Systematically enhanced reflections\n"); for(m=0;m<cndn;m++,cnd++) { if(SysEnhanced[m]==0) continue; (void) memcpy(S,cnd->Mx,sizeof(S)); (void) memcpy(x,cnd->Gl,sizeof(x)); buf[0] = 0; for(j=0; j<3; j++){ for(n=i=0; i<3; i++) if((n=S[i][j]) != 0) break; if(i==3) Sprintf(&buf[strlen(buf)],"0"); else { if (n==1) Sprintf(&buf[strlen(buf)],"%1c",hkl[i]); else if (n==-1) Sprintf(&buf[strlen(buf)],"-%1c",hkl[i]); else Sprintf(&buf[strlen(buf)],"%d%1c",n,hkl[i]); } } Sprintf(&buf[strlen(buf)],": e=%d",SysEnhanced[m]); Fprintf(fpout, " %s\n", buf); } putc('\n', fpout); }
char * var_name_nomap_ASL(ASL *asl, int n, int *p /* not used */) { char buf[32], **np, *rv; if (n < 0 || n >= asl->i.n_var1) return badvarname; if (!asl->i.varnames) asl->i.varnames = get_names(asl, ".col", 0, asl->i.n_var0); np = asl->i.varnames + n; if (!(rv = *np)) { *np = rv = (char*)mem(Sprintf(buf,"_svar[%d]",n+1)+1); strcpy(rv, buf); } return rv; }
char * getdate() { #ifdef LINT /* static char datestr[7]; */ char datestr[7]; #else static char datestr[7]; #endif register struct tm *lt = getlt(); Sprintf(datestr, "%2d%2d%2d", lt->tm_year, lt->tm_mon + 1, lt->tm_mday); if(datestr[2] == ' ') datestr[2] = '0'; if(datestr[4] == ' ') datestr[4] = '0'; return(datestr); }
char * lcon_name_ASL(ASL *asl, int n) { char buf[32], **np, *rv; static char badlconname[] = "**lcon_name(bad n)**"; if (n < 0 || n >= n_lcon) return badlconname; if (!asl->i.lconnames) get_row_names(asl); np = asl->i.lconnames + n; if (!(rv = *np)) { *np = rv = (char*)mem(Sprintf(buf,"_slogcon[%d]",n+1)+1); strcpy(rv, buf); } return rv; }
void hoc_execstr(const char* cp) { Symbol *sp; Symlist *symlist = (Symlist *)0; Inst *pcsav; char s[256]; Sprintf(s, "{%s}\n", cp); sp = hoc_install("", PROCEDURE, 0., &symlist); sp->u.u_proc->defn.in = STOP; sp->u.u_proc->list = (Symlist *)0; sp->u.u_proc->nauto = 0; IGNORE(hoc_xopen_run(sp, s)); pcsav = hoc_pc; hoc_execute(sp->u.u_proc->defn.in); hoc_pc = pcsav; hoc_free_list(&symlist); }