void list_deffn(char *var, statement *stmt) { int x = 0, y = 0, z = 0, ctr = 0; char *reorder[32]; // find bounds for param list for (x=0; x<=stmt->metapos; x++) if (stmt->metalist[x].operation == 0xF5) break; for (y=x; y<=stmt->metapos; y++) if (stmt->metalist[y].operation == 0xF8) break; simplifylist(var, stmt, x-1, x); mysprintf(var, "%s(", listpop()); simplifylist(var, stmt, x, y); z = outcount; for (ctr = 0; ctr < z; ctr++) { reorder[ctr] = SafeMalloc(MAX_STRING_LENGTH); reorder[ctr] = listpop(); } for (ctr = ctr-1; ctr >= 0; ctr--) { mysprintf(var, "%s", reorder[ctr]); if (ctr) mysprintf(var, ","); } simplifylist(var, stmt, y, stmt->metapos); mysprintf(var, ")=%s", listpop()); }
LOCALELIST *get_locales_language() { LOCALELIST *list = NULL; struct dirent **dirents; int ndirents; int cnt; ndirents = scandir(LOCALEDIR, &dirents, select_dirs, alphasort); // build languages list for (cnt = 0; cnt < ndirents; ++cnt) { LOCALELIST *ptr = calloc(sizeof (LOCALELIST), 1); if (!ptr) return NULL; ptr->locale_code = strdup(dirents[cnt]->d_name); { char buf[sizeof (LOCALEDIR) + strlen(dirents[cnt]->d_name) + sizeof "/LC_IDENTIFICATION"]; char *enddir; struct stat st; stpcpy(enddir = stpcpy(stpcpy(stpcpy(buf, LOCALEDIR), "/"), dirents[cnt]->d_name), "/LC_IDENTIFICATION"); if (stat(buf, &st) == 0 && S_ISREG(st.st_mode)) { int fd = open(buf, O_RDONLY); if (fd != -1) { void *mapped = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (mapped != MAP_FAILED) { char *lang = get_language(mapped, st.st_size); ptr->language_name = mysprintf("%s (%.2s)", lang ? lang : ptr->locale_code, &ptr->locale_code[3]); munmap(mapped, st.st_size); } close(fd); } } } append_localelist(&list, ptr); } // free direntries if (ndirents > 0) { while (ndirents--) { free(dirents[ndirents]); } free(dirents); } if (list == NULL) { list = calloc(sizeof (LOCALELIST), 1); if (!list) return NULL; list->locale_code = mysprintf("%s%.2s.utf8", current_language, current_language); list->locale_code[3] = toupper(list->locale_code[3]); list->locale_code[4] = toupper(list->locale_code[4]); list->language_name = strdup(list->locale_code); } return list; }
SExpr* SPrimScope::tryConstantFold() { const fint MaxPrimArgs = 5; // fix switch stmt below when increasing this if (!pd->canBeConstantFolded() || nargs > MaxPrimArgs) return NULL; oop a[MaxPrimArgs]; // argument oops if (!receiver->isConstantSExpr()) return NULL; oop r = receiver->constant(); // get arguments (NB: args is in reverse order) fint i; for (i = 0; i < nargs; i++) { if (!args->nth(i)->isConstantSExpr()) return NULL; a[nargs - i - 1] = args->nth(i)->constant(); }; // ok, all args are consts: call the primitive oop res; fntype f = pd->fn(); switch(nargs) { case 0: res = f(r); break; case 1: res = f(r, a[0]); break; case 2: res = f(r, a[0], a[1]); break; case 3: res = f(r, a[0], a[1], a[2]); break; case 4: res = f(r, a[0], a[1], a[2], a[3]); break; case 5: res = f(r, a[0], a[1], a[2], a[3], a[4]); break; default: ShouldNotReachHere(); } if (PrintInlining) { char buf[1024]; char* b = buf; mysprintf(b, "%*s*constant-folding %s %s ", (void*)depth, "", r->debug_print(), pd->name()); for (i = 0; i < nargs; i++) { mysprintf(b, "%s ", a[i]->debug_print()); } mysprintf(b, "--> %s\n", res->debug_print()); lprintf(buf); } // should scan backwards here and discard all nodes computing the args if (res->is_mark()) { // primitive will always fail ConstPReg* error = new_ConstPReg(_sender, res->memify()); Node* dummy; MergeNode* mdummy = NULL; SExpr* failExpr = genPrimFailure(NULL, error, dummy, mdummy, resultPR, false); return failExpr; } else { theNodeGen->loadOop(res, resultPR); return new ConstantSExpr(res, resultPR, theNodeGen->current); } }
static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { struct myprogress *myp = (struct myprogress *)p; CURL *curl = myp->curl; STRING **list = myp->list; double curtime = 0; curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime); /* under certain circumstances it may be desirable for certain functionality to only run every N seconds, in order to do this the transaction time can be used */ if ((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) { myp->lastruntime = curtime; } if (list && dltotal) { long long x = ((dlnow * (long)100) / dltotal); char *s = mysprintf(_("Downloading archive (%d%%)"), x > 100 ? 100 : x); HandleSemaphoreText(s, list, 0); if (s) free(s); } return 0; }
void test_xint(const char * fmt, int ival) { struct sbuf sb; char myval[512]; char stdval[512]; char msg[80]; sb.b = myval; sb.pos = 0; sprintf(msg, "\"%s\", %d", fmt, ival); printf("\n%s ", msg); mysprintf(&sb, fmt, ival); sprintf(stdval, fmt, ival); printf("... |%s| != |%s| ", myval, stdval); CU_ASSERT_STRING_EQUAL(myval, stdval); /* if (strcmp(myval, stdval) == 0) { CU_PASS(msg); } else { CU_FAIL(msg); printf("%s", msg); } */ }
struct MidiCluster *NewCluster(char *name,struct CamdBase *CamdBase){ struct MyMidiCluster *mymidicluster; struct MidiCluster *midicluster; mymidicluster=AllocMem(sizeof(struct MyMidiCluster),MEMF_ANY | MEMF_CLEAR | MEMF_PUBLIC); if(mymidicluster==NULL) return NULL; InitSemaphore(&mymidicluster->semaphore); midicluster=&mymidicluster->cluster; midicluster->mcl_Node.ln_Name=AllocVec(mystrlen(name) + 1,MEMF_ANY|MEMF_PUBLIC); if(midicluster->mcl_Node.ln_Name==NULL){ FreeMem(midicluster,sizeof(struct MyMidiCluster)); return NULL; } mysprintf(CamdBase,midicluster->mcl_Node.ln_Name,"%s",name); NEWLIST(&midicluster->mcl_Receivers); NEWLIST(&midicluster->mcl_Senders); AddTail(&CB(CamdBase)->midiclusters,&midicluster->mcl_Node); return midicluster; }
void list_let(char *var, statement *stmt) { int x = 0, start = 0; for (x=1; x<stmt->metapos; x++) { if (!start) start = x; if (stmt->metalist[x].operation == 0xEC) { simplifylist(var, stmt, start, x); start = 0; mysprintf(var, "%s%s, ", listpop(), listpop()); } } simplifylist(var, stmt, start, stmt->metapos); mysprintf(var, "%s%s", listpop(), listpop()); }
void list_on(char *var, statement *stmt) { int x = 0; for (x=0; x<=stmt->metapos; x++) if ((stmt->metalist[x].operation == 0x00F4) || (stmt->metalist[x].operation == 0x01F4)) break; simplifylist(var, stmt, 0, x); mysprintf(var, "%s", listpop()); if (stmt->metalist[x].operation == 0x00F4) mysprintf(var, " GOTO "); else mysprintf(var, " GOSUB "); simplifylist(var, stmt, x+1, stmt->metapos); mysprintf(var, "%s", listpop()); }
void list_for(char *var, statement *stmt) { char *tmp1 = 0, *tmp2 = 0, *tmp3 = 0; mysprintf(var, "%s=", get_symname(stmt->metalist[1].shortarg)); simplifylist(var, stmt, 2, stmt->metapos); if (outcount == 3) { tmp3 = listpop(); tmp2 = listpop(); tmp1 = listpop(); } else { tmp2 = listpop(); tmp1 = listpop(); } mysprintf(var, "%s TO %s", tmp1, tmp2); if (tmp3) mysprintf(var, " STEP %s", tmp3); }
void SerialLCD::printNum(int dta) { char tmp[10]; mysprintf(tmp, "%d", dta); Serial.println(tmp); print(tmp); }
void test_mytest2(void) { struct sbuf sb; char buf[512]; sb.b = buf; RESET_BUF(sb, 512); mysprintf(&sb, "%5d", 1); CU_ASSERT_STRING_EQUAL(buf, " 1"); RESET_BUF(sb, 512); mysprintf(&sb, "%05d", 1); CU_ASSERT_STRING_EQUAL(buf, "00001"); RESET_BUF(sb, 512); mysprintf(&sb, "%-5d", 1); CU_ASSERT_STRING_EQUAL(buf, "1 "); RESET_BUF(sb, 512); mysprintf(&sb, "%-05d", 1); CU_ASSERT_STRING_EQUAL(buf, "1 "); RESET_BUF(sb, 512); mysprintf(&sb, "%+5d", 1); CU_ASSERT_STRING_EQUAL(buf, " +1"); RESET_BUF(sb, 512); mysprintf(&sb, "%+05d", 1); CU_ASSERT_STRING_EQUAL(buf, "+0001"); RESET_BUF(sb, 512); mysprintf(&sb, "%+-5d", 1); CU_ASSERT_STRING_EQUAL(buf, "+1 "); RESET_BUF(sb, 512); mysprintf(&sb, "%+-05d", 1); CU_ASSERT_STRING_EQUAL(buf, "+1 "); RESET_BUF(sb, 512); mysprintf(&sb, "%5.2d", 1); printf("\n|%s|\n", buf); CU_ASSERT_STRING_EQUAL(buf, " 01"); }
void test_mytest(void) { struct sbuf sb; char buf[512]; sprintf(buf, "%05d", 1); CU_ASSERT_STRING_EQUAL(buf, "00001"); memset(buf, 0, 512); sb.b = buf; sb.pos = 0; mysprintf(&sb, "%05d", 1); CU_ASSERT_STRING_EQUAL(buf, "00001"); }
void BB::print_vcg_nodes(FILE* f, bool suppressTrivial) { fprintf(f, "graph: { title: \"BB%d (%d..%d)\" folding:1\n", id(), first->id(), last->id()); for (Node* n = first; n != last->next(); n = n->next()) { if (n->deleted && !(n == first || n == last)) continue; if (suppressTrivial && n->isTrivial()) { // don't print } else { char b[256], nname[256]; char* buf = b; mysprintf(buf, "node: { title:\"%d\" label: \"%s\" }\n", (void*)n->id(), n->print_string(nname, false)); fputs(b, f); } } fprintf(f, "}\n"); }
void test_xfloat(const char * fmt, double dval) { struct sbuf sb; char myval[512]; char stdval[512]; char msg[80]; sb.b = myval; sb.pos = 0; sprintf(msg, "\"%s\", %f", fmt, dval); printf("\n%s ", msg); mysprintf(&sb, fmt, dval); sprintf(stdval, fmt, dval); printf("... |%s| != |%s| ", myval, stdval); CU_ASSERT_STRING_EQUAL(myval, stdval); }
void DoTest(void) { struct passwd *user; char *user_string; int euid, tno; char dot1[] = "\n<li><small>"; char dot2[] = "</small></li>"; printf("\n<ul>"); printf("%s%s: %s%s", dot1, _("Software version"), VERSION, dot2); euid = geteuid(); user = getpwuid(euid); // printf("%s%s: %s%s",dot1,_("Application user"),user?user->pw_name:(_("Can't get user name")),dot2); if (user) user_string = user->pw_name; else user_string = mysprintf("<span style='color:red'>%s</span>", strerror(errno)); printf("%s%s: %s%s", dot1, _("Application user"), user_string, dot2); if (!user) free(user_string); printf("%s%s: %s%s", dot1, _("Localization setup"), globaldata.gd_locale_code, dot2); if (MySqlTest()) printf("%s%s%s", dot1, _("MySQL connection is OK"), dot2); else printf("%s<span style='color:red'>%s</span>%s", dot1, _("Error with MySQL connection"), dot2); if (globaldata.gd_php_sapi) // php handler printf("%s%s: %s%s", dot1, _("PHP Handler"), globaldata.gd_php_sapi, dot2); tno = TempCount(); printf("%s%s: %d%s", dot1, _("Temporary files found"), tno, dot2); if (tno > 0) { printf("%s<a onClick=\"if (confirm('%s')) return true; return false;\" href=\"%s?deltemp\">%s</a>%s\n", dot1, _("Are you sure\\nyou want to delete temporary files?"), getenv("SCRIPT_NAME"), _("Delete temporary files"), dot2); } printf("\n</ul>\n<br /><a href=\"%s?editconf\">%s</a>", getenv("SCRIPT_NAME"), _("Edit configuration")); }
char * hprofStartupp (char *outputFileName, char *ctx) { char fileName[1000]; int fp; mysprintf (fileName, outputFileName); if (access (fileName, 1) == 0) { myfree (ctx); return 0; } fp = fopen (fileName, 0); if (fp == 0) { myfree (ctx); return 0; } foo (outputFileName, fp); return ctx; }
char* DeadBlockNode::print_string(char* buf, bool printAddr) { char* b = buf; mysprintf(buf, "DeadBlockTrap"); if (printAddr) mysprintf(buf, " p *(DeadBlockNode*)%#lx", this); return b; }
/* print the value of stat variable STAT */ void stat_print_stat(struct stat_sdb_t *sdb, /* stat database */ struct stat_stat_t *stat,/* stat variable */ FILE *fd) /* output stream */ { struct eval_value_t val; switch (stat->sc) { case sc_int: fprintf(fd, "%-22s ", stat->name); myfprintf(fd, stat->format, *stat->variant.for_int.var); fprintf(fd, " # %s", stat->desc); break; case sc_uint: fprintf(fd, "%-22s ", stat->name); myfprintf(fd, stat->format, *stat->variant.for_uint.var); fprintf(fd, " # %s", stat->desc); break; #ifdef HOST_HAS_QWORD case sc_qword: { char buf[128]; fprintf(fd, "%-22s ", stat->name); mysprintf(buf, stat->format, *stat->variant.for_qword.var); fprintf(fd, "%s # %s", buf, stat->desc); } break; case sc_sqword: { char buf[128]; fprintf(fd, "%-22s ", stat->name); mysprintf(buf, stat->format, *stat->variant.for_sqword.var); fprintf(fd, "%s # %s", buf, stat->desc); } break; #endif /* HOST_HAS_QWORD */ case sc_float: fprintf(fd, "%-22s ", stat->name); myfprintf(fd, stat->format, (double)*stat->variant.for_float.var); fprintf(fd, " # %s", stat->desc); break; case sc_double: fprintf(fd, "%-22s ", stat->name); myfprintf(fd, stat->format, *stat->variant.for_double.var); fprintf(fd, " # %s", stat->desc); break; case sc_dist: print_dist(stat, fd); break; case sc_sdist: print_sdist(stat, fd); break; case sc_formula: { /* instantiate a new evaluator to avoid recursion problems */ struct eval_state_t *es = eval_new(stat_eval_ident, sdb); char *endp; fprintf(fd, "%-22s ", stat->name); val = eval_expr(es, stat->variant.for_formula.formula, &endp); if (eval_error != ERR_NOERR || *endp != '\0') fprintf(fd, "<error: %s>", eval_err_str[eval_error]); else myfprintf(fd, stat->format, eval_as_double(val)); fprintf(fd, " # %s", stat->desc); /* done with the evaluator */ eval_delete(es); } break; default: panic("bogus stat class"); } fprintf(fd, "\n"); }
int write_config(void) { int rc, result = 0; char *config_name = ".internet_icon"; xmlTextWriterPtr writer; #ifdef MEMORY int fd; xmlBufferPtr buf; /* Create a new XML buffer, to which the XML document will be * written */ buf = xmlBufferCreate(); if (buf == NULL) { return 0; } /* Create a new XmlWriter for memory, with no compression. * Remark: there is no compression for this kind of xmlTextWriter */ writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { xmlBufferFree(buf); return 0; } #else // create the file writer = xmlNewTextWriterFilename(config_name, 0); if (writer == NULL) return 0; #endif // start the document rc = xmlTextWriterStartDocument(writer, NULL, NULL, NULL); if (rc < 0) goto finish; // root element rc = xmlTextWriterStartElement(writer, BAD_CAST "internet_icon"); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; ///////////////////////////////////// // timeout char *tm = mysprintf ("%d", cfg.timeout_seconds); rc = xmlTextWriterWriteElement(writer, BAD_CAST "timeout", BAD_CAST tm); free (tm); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // test_ip rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_ip", BAD_CAST cfg.test_ip); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // the port char *port = mysprintf ("%d", cfg.test_port); rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_port", BAD_CAST port); free (port); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // operating mode rc = xmlTextWriterWriteElement(writer, BAD_CAST "opmode", BAD_CAST flag_value[cfg.op_mode]); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // wan ip page rc = xmlTextWriterWriteElement(writer, BAD_CAST "wan_ip_page", BAD_CAST cfg.wanip_page); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n "); if (rc < 0) goto finish; // wan ip page rc = xmlTextWriterWriteElement(writer, BAD_CAST "user_agent", BAD_CAST cfg.user_agent); if (rc < 0) goto finish; // newline rc = xmlTextWriterWriteString(writer, BAD_CAST "\n"); if (rc < 0) goto finish; /* Close the start element. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) goto finish; ///////////////////////////////////// /* Close all. */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) goto finish; #ifdef MEMORY xmlFreeTextWriter(writer); writer = NULL; remove(config_name); fd = open(config_name, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) goto finish; write(fd, (const void *) buf->content, strlen((const char *)buf->content)); close(fd); #endif result = 1; finish: if (writer) xmlFreeTextWriter(writer); #ifdef MEMORY xmlBufferFree(buf); #endif return result; }
void list_if(char *var, statement *stmt) { int x = 0, y = 0, z = 0, ctr = 0; statement *tmpstmt; tmpstmt = SafeMalloc(sizeof(statement)); stmtinit(tmpstmt); for (x=0; x<stmt->metapos; x++) if (stmt->metalist[x].operation == 0xE7) break; y = x; for (x=y; x<stmt->metapos; x++) { if (stmt->metalist[x].operation == 0xE7) ctr++; if (stmt->metalist[x].operation == 0xE2) ctr -= 2; if (ctr == 0) break; } z = x; simplifylist(var, stmt, 0, y); mysprintf(var, "%s THEN ", listpop()); ctr = 1; tmpstmt->opcode = stmt->metalist[y+1].operation; for (x=y+2; x<z; x++) { tmpstmt->metalist[ctr].operation = stmt->metalist[x].operation; if (stmt->metalist[x].intarg) tmpstmt->metalist[ctr].intarg = stmt->metalist[x].intarg; if (stmt->metalist[x].floatarg.mantisa.i) tmpstmt->metalist[ctr].floatarg = stmt->metalist[x].floatarg; if (stmt->metalist[x].shortarg) tmpstmt->metalist[ctr].shortarg = stmt->metalist[x].shortarg; if (stmt->metalist[x].stringarg) { if (stmt->metalist[x].operation == MNEMONICREF && !stmt->metalist[x].intarg) { tmpstmt->metalist[ctr].stringarg[0] = stmt->metalist[x].stringarg[0]; tmpstmt->metalist[ctr].stringarg[1] = stmt->metalist[x].stringarg[1]; } else { for (y=0; y<stmt->metalist[x].intarg; y++) tmpstmt->metalist[ctr].stringarg[y] = stmt->metalist[x].stringarg[y]; } } ctr++; } tmpstmt->metapos = ctr; listline(var, tmpstmt, 0); if (z != stmt->metapos) { stmtinit(tmpstmt); ctr = 0; mysprintf(var, " ELSE "); tmpstmt->opcode = stmt->metalist[z+1].operation; for (x=z+2; x<stmt->metapos; x++) { tmpstmt->metalist[ctr].operation = stmt->metalist[x].operation; if (stmt->metalist[x].intarg) tmpstmt->metalist[ctr].intarg = stmt->metalist[x].intarg; if (stmt->metalist[x].floatarg.mantisa.i) tmpstmt->metalist[ctr].floatarg = stmt->metalist[x].floatarg; if (stmt->metalist[x].shortarg) tmpstmt->metalist[ctr].shortarg = stmt->metalist[x].shortarg; if (stmt->metalist[x].stringarg) { if (stmt->metalist[x].operation == MNEMONICREF && !stmt->metalist[x].intarg) { tmpstmt->metalist[ctr].stringarg[0] = stmt->metalist[x].stringarg[0]; tmpstmt->metalist[ctr].stringarg[1] = stmt->metalist[x].stringarg[1]; } else { for (y=0; y<stmt->metalist[x].intarg; y++) tmpstmt->metalist[ctr].stringarg[y] = stmt->metalist[x].stringarg[y]; } } ctr++; } tmpstmt->metapos = ctr; listline(var, tmpstmt, 0); } }
void simplifylist(char *var, statement *stmt, int start, int end) { int y = 0, channels = 0; char tmp[MAX_STRING_LENGTH], *hex; char *tmp1, *tmp2, *tmp3; char *reorder[32]; int ctr = 0; for (y=start; y<=end; y++) { oppush(0); if (get_sysvarname(stmt->metalist[y].operation)) { sprintf(tmp, "%s", get_sysvarname(stmt->metalist[y].operation)); listpush(tmp); } else if (get_fncname(stmt->metalist[y].operation)) { if ((stmt->metalist[y].operation == OP_AND) || (stmt->metalist[y].operation == OP_OR) || (stmt->metalist[y].operation == OP_XOR)) goto blah; sprintf(tmp, "%s(", get_fncname(stmt->metalist[y].operation)); if (stmt->metalist[y].intarg) { for (ctr=0; ctr<stmt->metalist[y].intarg; ctr++) { reorder[ctr] = SafeMalloc(MAX_STRING_LENGTH); reorder[ctr] = listpop(); } } else { for (ctr=0; ctr<fnctable[get_fnc(get_fncname(stmt->metalist[y]. operation))].numparms; ctr++) { reorder[ctr] = SafeMalloc(MAX_STRING_LENGTH); reorder[ctr] = listpop(); } } for (ctr=ctr-1; ctr>=0; ctr--) { strcat(tmp, reorder[ctr]); if (ctr) strcat(tmp, ","); } strcat(tmp, ")"); listpush(tmp); } else blah: switch(stmt->metalist[y].operation) { case HEXSTRING: hex = SafeMalloc(2+(stmt->metalist[y].intarg*2)); *hex = 0; sprintf(tmp, "$"); for (ctr = 0; ctr < stmt->metalist[y].intarg; ctr++) { sprintf(hex, "%X", stmt->metalist[y].stringarg[ctr]); sprintf(hex, "%c%c", hex[strlen(hex)-2], hex[strlen(hex)-1]); strcat(tmp, hex); } strcat(tmp, "$"); GC_free(hex); listpush(tmp); break; case 0xF5: if (stmt->opcode != CMD_DEFFN) listpush("<BEGINLIST>"); break; case 0xF8: if (stmt->opcode != CMD_DEFFN) { ctr = 0; do { reorder[ctr] = SafeMalloc(MAX_STRING_LENGTH); reorder[ctr] = listpop(); if (!strcmp(reorder[ctr], "<BEGINLIST>")) break; ctr++; } while(1); sprintf(tmp, "%s(", listpop()); for (ctr = ctr-1; ctr >= 0; ctr--) { strcat(tmp, reorder[ctr]); if (ctr) strcat(tmp, ","); } strcat(tmp, ")"); listpush(tmp); } break; case 0x8DC9: listpush(gprog->userfunctions[stmt->metalist[y].shortarg].name); break; case 0xF1: case 0xEC: // workaround, LET handles its own commas if (stmt->opcode != CMD_LET) { sprintf(tmp, "%s,", listpop()); listpush(tmp); for (ctr = 0; ctr < outcount; ctr++) mysprintf(var, "%s", listpop()); } break; case 0xF4F1: if (channels) mysprintf(var, ") "); break; case 0xE1: channels = 1; mysprintf(var, "(%s", listpop()); break; case OP_OPT: case OP_SEP: case OP_SRT: case OP_BNK: case OP_DOM: case OP_END: case OP_IND: case OP_IOL: case OP_ISZ: case OP_KEY: case OP_SIZ: case OP_TBL: case OP_TIM: case OP_ERR: case OP_LEN: case OP_PWD: case OP_ATR: if (channels) mysprintf(var, ", %s=%s", get_symbol(stmt->metalist[y].operation), listpop()); else { sprintf(tmp, "%s, %s=%s", listpop(), get_symbol(stmt->metalist[y].operation), listpop()); listpush(tmp); } break; case LABELREF: sprintf(tmp, "%s", get_labelname(stmt->metalist[y].shortarg)); listpush(tmp); break; case LINEREF: sprintf(tmp, "%.5d", stmt->metalist[y].shortarg); listpush(tmp); break; case MNEMONICREF: sprintf(tmp, "\'%s\'", stmt->metalist[y].stringarg); listpush(tmp); break; case 0xF7: tmp2 = listpop(); sprintf(tmp, "@(%s,%s)", listpop(), tmp2); listpush(tmp); break; case 0xF6: sprintf(tmp, "@(%s)", listpop()); listpush(tmp); break; case FLOAT: sprintf(tmp, "%s", flt2asc(stmt->metalist[y].floatarg)); listpush(tmp); break; case GETVAL_STRINGARRAY: case SETVAL_STRINGARRAY: case GETVAL_STRING: case SETVAL_STRING: ctr = stmt->metalist[y].shortarg; tmp3 = SafeMalloc(MAX_STRING_LENGTH); if (stmt->metalist[y].shortarg & 0x2000) { ctr -= 0x2000; sprintf(tmp3, "(%s)", listpop()); } else if (stmt->metalist[y].shortarg & 0x4000) { ctr -= 0x4000; tmp2 = listpop(); sprintf(tmp3, "(%s,%s)", listpop(), tmp2); } else tmp3 = 0; if (stmt->metalist[y].shortarg & 0x8000) { ctr -= 0x8000; if (stmt->metalist[y].operation == GETVAL_STRINGARRAY || stmt->metalist[y].operation == SETVAL_STRINGARRAY) { tmp1 = listpop(); tmp2 = listpop(); sprintf(tmp, "[%s,%s,%s]", listpop(), tmp2, tmp1); listpush(tmp); } else { sprintf(tmp, "[%s]", listpop()); listpush(tmp); } } else if (stmt->metalist[y].operation == GETVAL_STRINGARRAY || stmt->metalist[y].operation == SETVAL_STRINGARRAY) { tmp1 = listpop(); sprintf(tmp, "[%s,%s]", listpop(), tmp1); listpush(tmp); } else listpush(""); // noarrayref if (tmp3) sprintf(tmp, "%s%s%s", get_symname(ctr), listpop(), tmp3); else sprintf(tmp, "%s%s", get_symname(ctr), listpop()); GC_free(tmp3); if ((stmt->metalist[y].operation == SETVAL_STRING) || (stmt->metalist[y].operation == SETVAL_STRINGARRAY)) { if ((stmt->opcode == CMD_LET) || (stmt->opcode == CMD_FOR)) strcat(tmp, "="); } listpush(tmp); break; case GETVAL_NUMERIC: case SETVAL_NUMERIC: case GETVAL_NUMERICARRAY: case SETVAL_NUMERICARRAY: ctr = stmt->metalist[y].shortarg; if (stmt->metalist[y].shortarg & 0x8000) { ctr -= 0x8000; if (stmt->metalist[y].operation == GETVAL_NUMERICARRAY || stmt->metalist[y].operation == SETVAL_NUMERICARRAY) { tmp1 = listpop(); tmp2 = listpop(); sprintf(tmp, "[%s,%s,%s]", listpop(), tmp2, tmp1); listpush(tmp); } else { sprintf(tmp, "[%s]", listpop()); listpush(tmp); } } else if (stmt->metalist[y].operation == GETVAL_NUMERICARRAY || stmt->metalist[y].operation == SETVAL_NUMERICARRAY) { tmp1 = listpop(); sprintf(tmp, "[%s,%s]", listpop(), tmp1); listpush(tmp); } else listpush(""); // noarrayref sprintf(tmp, "%s%s", get_symname(ctr), listpop()); if (stmt->metalist[y].operation == SETVAL_NUMERIC || stmt->metalist[y].operation == SETVAL_NUMERICARRAY) if ((stmt->opcode == CMD_LET) || (stmt->opcode == CMD_FOR)) strcat(tmp, "="); listpush(tmp); break; case SHORTLITERAL: sprintf(tmp, "\"%s\"", stmt->metalist[y].stringarg); listpush(tmp); break; case OP_NEGATE: sprintf(tmp, "(-%s)", listpop()); listpush(tmp); break; case OP_STRCAT: tmp2 = listpop(); sprintf(tmp, "%s+%s", listpop(), tmp2); listpush(tmp); break; case OP_AND: case OP_XOR: case OP_OR: case OP_LESSTHAN: case OP_GREATTHAN: case OP_NOTEQUAL: case OP_EQUALSCMP: case OP_LTEQ: case OP_GTEQ: case OP_ADD: case OP_SUBTRACT: case OP_MULTIPLY: case OP_DIVIDE: case OP_EXPONENT: oppop(); if (oppop() >= getprec(get_symbol(stmt->metalist[y].operation))) { tmp3 = listpop(); tmp1 = SafeMalloc(strlen(tmp3)+2); sprintf(tmp1, "(%s)", tmp3); } else tmp1 = listpop(); if (oppop() >= getprec(get_symbol(stmt->metalist[y].operation))) { tmp3 = listpop(); tmp2 = SafeMalloc(strlen(tmp3)+2); sprintf(tmp2, "(%s)", tmp3); } else tmp2 = listpop(); oppush(getprec(get_symbol(stmt->metalist[y].operation))); sprintf(tmp, "%s%s%s", tmp2, get_symbol(stmt->metalist[y].operation), tmp1); listpush(tmp); break; } } }
void listline(char *var, statement *stmt, byte showline) { int x; outcount = 0; if (stmt->errorflag) { mysprintf(var, "*ERR "); for (x=0; x<tokenpos; x++) mysprintf(var, " "); mysprintf(var, "V\n"); } if (showline) mysprintf(var, "%.5d ", stmt->linenum); if (stmt->errorflag) { mysprintf(var, "%s", stmt->metalist[1].stringarg); return; } if (stmt->numlabels) { for (x=0; x<stmt->numlabels; x++) mysprintf(var, "%s: ", get_labelname(stmt->labelset[x]->labelnum)); } mysprintf(var, "%s ", get_opname(stmt->opcode)); switch(stmt->opcode) { case CMD_DEFFN: list_deffn(var, stmt); break; case CMD_REM: mysprintf(var, "%s", stmt->metalist[1].stringarg); break; case CMD_IF: list_if(var, stmt); break; case CMD_LET: list_let(var, stmt); break; case CMD_SETESC: case CMD_SETERR: case CMD_GOTO: case CMD_GOSUB: if (stmt->metalist[1].operation == LABELREF) mysprintf(var, "%s", get_labelname(stmt->metalist[1].shortarg)); else mysprintf(var, "%.5d", stmt->metalist[1].shortarg); break; case CMD_FOR: list_for(var, stmt); break; case CMD_NEXT: mysprintf(var, "%s", get_symname(stmt->metalist[1].shortarg)); break; case CMD_LIST: case CMD_DELETE: if (stmt->metapos == 1) mysprintf(var, "00001, 65534"); else if (stmt->metapos == 2) mysprintf(var, "%.5d", flt2int(stmt->metalist[1].floatarg)); else mysprintf(var, "%.5d, %.5d", flt2int(stmt->metalist[1].floatarg), flt2int(stmt->metalist[3].floatarg)); break; case CMD_RETURN: case CMD_WEND: case CMD_RETRY: case CMD_SETERRON: case CMD_SETERROFF: break; case CMD_ON: list_on(var, stmt); break; default: if (stmt->metapos == 1) break; simplifylist(var, stmt, 0, stmt->metapos); mysprintf(var, "%s", listpop()); break; } }
// Add a log entry given a variable argument list OsStatus OsSysLog::vadd(const char* taskName, const OsTaskId_t taskId, const OsSysLogFacility facility, const OsSysLogPriority priority, const char* format, va_list ap) { // If the log has not been initialized, print everything to the console if (!isTaskPtrNull()) { if (willLog(facility, priority)) { UtlString logData; UtlString logEntry; myvsprintf(logData, format, ap) ; logData = escape(logData) ; #ifdef ANDROID __android_log_print(androidPri(priority), "sipXsyslog", "[%s] %s", OsSysLog::sFacilityNames[facility], logData.data()); #endif OsTime timeNow; OsDateTime::getCurTime(timeNow); OsDateTime logTime(timeNow); UtlString strTime ; logTime.getIsoTimeStringZus(strTime) ; UtlString taskHex; // TODO: Should get abstracted into a OsTaskBase method #ifdef __pingtel_on_posix__ OsTaskLinux::getIdString_X(taskHex, taskId); #endif mysprintf(logEntry, "\"%s\":%d:%s:%s:%s:%s:%s:%s:\"%s\"", strTime.data(), ++sEventCount, OsSysLog::sFacilityNames[facility], OsSysLog::sPriorityNames[priority], sHostname.data(), (taskName == NULL) ? "" : taskName, taskHex.data(), sProcessId.data(), logData.data()) ; // If the logger for some reason trys to log a message // there is a recursive problem. Drop the message on the // floor for now. This can occur if one of the os utilities // logs a message. if(strcmp("syslog", taskName) == 0) { // Just discard the log entry // // (rschaaf): // NOTE: Don't try to use osPrintf() to emit the log entry since this // can cause consternation for applications (e.g. CGIs) that expect to // use stdout for further processing. } else { char* szPtr = strdup(logEntry.data()) ; OsSysLogMsg msg(OsSysLogMsg::LOG, szPtr) ; OsTime timeout(1000) ; OsSysLogTask *pOsSysLogTask = spOsSysLogTask; if ( pOsSysLogTask != NULL && pOsSysLogTask->postMessage(msg, timeout) != OS_SUCCESS) { printf("OsSysLog jammed: %s\n", szPtr) ; free(szPtr) ; OsTask::yield() ; } } } } return OS_SUCCESS ; }
int CurlDownload(char *url, int mask, int tempname, STRING **list) { CURL *curl; CURLcode res = CURLE_GOT_NOTHING; struct myprogress prog; char *urlfile = NULL; FILE *pagefile; int fd = NO_FILE; // static char cwd[512]; if ((!(url)) || (!(*url))) return 0; if (globaldata.gd_inidata && globaldata.gd_inidata->filename) urlfile = globaldata.gd_inidata->filename; curl = curl_easy_init(); if(curl) { prog.lastruntime = 0; prog.curl = curl; prog.list = list; curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Ezinstall downloader/0.1"); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog); #if LIBCURL_VERSION_NUM >= 0x072000 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo); curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog); #endif curl_easy_setopt(curl, CURLOPT_NOPROGRESS, list == NULL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); // getcwd(cwd, 512); // ChDirRoot(); fd = create_file(tempname ? NULL : urlfile, mask); if (fd == NO_FILE) { curl_easy_cleanup(curl); if (list) DaemonError(_( "Can't create archive file"), list); else Error(_( "Can't create archive file")); } // chdir(cwd); pagefile = fdopen(fd, "wb"); if (pagefile) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, pagefile); res = curl_easy_perform(curl); fclose(pagefile); } if(res != CURLE_OK) { char *msg = mysprintf("%s", curl_easy_strerror(res)); curl_easy_cleanup(curl); if (list) DaemonError(msg, list); else Error(msg); } curl_easy_cleanup(curl); } return (res == CURLE_OK); }