VOID SelectFormat(IN HWND hDlg, IN LPCTSTR format) { HWND hwndCombo = NULL; int index = -1; DWORD nId = -1; for (int i=0; i<ARRCOUNT(g_vectorFormats); i++) { LPCTSTR fmt = g_vectorFormats[i].strName; if (_tcsncmp(format, fmt, strLen(format)) == 0) { hwndCombo = GetDlgItem(hDlg, IDC_COMBO_VECTOR_FORMAT); index = i; nId = IDC_VECTOR_FORMAT_RADIOBOX; break; } } if (index == -1) { for (int i=0; i<ARRCOUNT(g_rasterFormats); i++) { LPCTSTR fmt = g_rasterFormats[i].strName; if (_tcsncmp(format, fmt, strLen(format)) == 0) { hwndCombo = GetDlgItem(hDlg, IDC_COMBO_RASTER_FORMAT); index = i; nId = IDC_RASTER_FORMAT_RADIOBOX; break; } } } SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)index, 0); // select the radio button next to the combo which we just selected CheckRadioButton(hDlg, IDC_VECTOR_FORMAT_RADIOBOX, IDC_RASTER_FORMAT_RADIOBOX, nId); }
int strBeginsWith(char* a, char*b){ if(strLen(a) < strLen(b)) return 0; int i = 0; while(a[i] == b[i]) i++; if(b[i] == 0) return 1; return 0; }
char* replace(char* str, char replacing, char* with) { int strL = strLen(str); char* result = addSpaces(str); int newLen = strLen(result); int withLen = strLen(with); int i = 0; while ((strL - 1)!= 0) { if (str[strL - 1] != replacing) { result[newLen - 1] = str[strL - 1]; newLen--; strL--; } else { for (i = withLen - 1; i >= 0 ; i--) result[--newLen] = with[i]; strL--; } } return result; }
void strCopy(char* dest, const char* src) { ASSERT(strIsValid(src)); ASSERT(memIsValid(dest, strLen(src) + 1)); ASSERT(memIsDisjoint(src, dest, strLen(src) + 1)); memcpy(dest, src, strLen(src) + 1); }
//???????ͷŵ?callback static int free_callback(void* param) { int loop; struct mod_conf_param* data = (struct mod_conf_param*) param; if(data) { for(loop=0; loop<data->count; loop++) { if(data->acp[loop]) { if(data->acp[loop]->hdr) { if(strLen(data->acp[loop]->hdr->header)) stringClean(&data->acp[loop]->hdr->header); if(strLen(data->acp[loop]->hdr->value)) stringClean(&data->acp[loop]->hdr->value); memPoolFree(header_info_pool, data->acp[loop]->hdr); data->acp[loop]->hdr = NULL; } memPoolFree(action_part_pool, data->acp[loop]); data->acp[loop] = NULL; } } memPoolFree(mod_config_pool, data); data = NULL; } return 0; }
HttpHdrExtField * httpHdrExtFieldDup(HttpHdrExtField * f) { assert(f); return httpHdrExtFieldDoCreate( strBuf(f->name), strLen(f->name), strBuf(f->value), strLen(f->value)); }
char *stringCat(char *destination, const char *source){ int i = 0, j = 0; for(i = strLen(destination), j = 0; j < strLen(source); i++, j++){ destination[i] = source[j]; } destination[i] = '\0'; return destination; }
void httpHeaderEntryPackInto(const HttpHeaderEntry * e, Packer * p) { assert(e && p); packerAppend(p, strBuf(e->name), strLen(e->name)); packerAppend(p, ": ", 2); packerAppend(p, strBuf(e->value), strLen(e->value)); packerAppend(p, "\r\n", 2); }
int main() { int strLen(char string[]); char w1[]={'r','a','j'}; char w2[]={'k','u','m','a','r'}; printf("%d %d",strLen(w1),strLen(w2)); getch(); return 0; }
bool_t strEndsWith(const char* str, const char* suffix) { ASSERT(strIsValid(str)); ASSERT(strIsValid(suffix)); if (strLen(str) < strLen(suffix)) return FALSE; for(str += strLen(str) - strLen(suffix); *suffix; ++suffix, ++str) if (*str != *suffix) return FALSE; return TRUE; }
void reverseInPlace(char s[]){ if(strLen(s) <= 1){ return; } int i,j; char c; for(i = 0, j = strLen(s)-2; i < j; i++, j--){ c = s[i]; s[i] = s[j]; s[j] = c; } }
/** * \brief Moves chars to the right of \a at to the cache. * * \param[in,out] from Char array containing the chars to be moved. * \param[in] in Point along \a from[] that marks the split point */ void moveToCache(char from[], int at) { int i, j, len; len = strLen(from); for (i = at+1, j = strLen(cache); i < len && cacheFreeSpace > 0; i++, j++) { cache[j] = from[i]; from[i] = '\0'; if (cache[j] == '\n') j--; } }
/* * deletes an entry at pos and leaves a gap; leaving a gap makes it * possible to iterate(search) and delete fields at the same time */ void httpHeaderDelAt(HttpHeader * hdr, HttpHeaderPos pos) { HttpHeaderEntry *e; assert(pos >= HttpHeaderInitPos && pos < hdr->entries.count); e = hdr->entries.items[pos]; hdr->entries.items[pos] = NULL; /* decrement header length, allow for ": " and crlf */ hdr->len -= strLen(e->name) + 2 + strLen(e->value) + 2; assert(hdr->len >= 0); httpHeaderEntryDestroy(e); }
void clearBuffer(){ struct StringListNode *temp = fileBuffer->firstLine; struct StringListNode *next; while(temp){ free(temp->str, strLen(temp->str)); next = temp->next; free(temp, sizeof(struct StringListNode)); temp = next; } free(fileBuffer->filename, strLen(fileBuffer->filename)); fileBuffer->filename = 0; fileBuffer->filesize = 0; }
int httpHeaderIdByName(const char *name, int name_len, const HttpHeaderFieldInfo * info, int end) { int i; for (i = 0; i < end; ++i) { if (name_len >= 0 && name_len != strLen(info[i].name)) continue; if (!strncasecmp(name, strBuf(info[i].name), name_len < 0 ? strLen(info[i].name) + 1 : name_len)) return i; } return -1; }
void sh_rand(char* params){ int i; for(i = 0; i < strLen(params)-1; i++){ if(params[i] < '0' || params[i] > '9'){ ttprint("parameter must be numeric:"); ttprintChar(params[i]); return; } } if(strLen(params) == 1) ttprintIntln(rand(10)); else ttprintIntln(rand(strToInt(params))); return; }
static int free_callback(void* param) { struct mod_conf_param* data = (struct mod_conf_param*) param; if(data) { if(strLen(data->orig_name)) stringClean(&data->orig_name); if(strLen(data->new_name)) stringClean(&data->new_name); memPoolFree(mod_config_pool, data); data = NULL; } return 0; }
int stringCompare(const char *str1, const char *str2){ int result = 0; int i = 0; while(result == 0 && i <= strLen(str1) && i <= strLen(str2)){ if(str1[i] < str2[i]){ result = -1; } else if(str1[i] > str2[i]){ result = 1; } i++; } return result; }
void EventShow() { void ExamineEvent(), ShowTW(); int i; mPrintf("\nCurAbs=%ld\n ", CurAbsolute()); mPrintf("ANYTIME NET is %d\n ", ClassActive[CL_ANYTIME_NET]); mPrintf("non-preempt nextabs is %ld, %ld seconds away\n ", Types[2].NextAbs, Types[2].NextAbs - CurAbsolute()); mPrintf("Preemptive list (%ld):\n ", Types[0].NextAbs); RunList(&Types[0].List, ExamineEvent); modIn(); mPrintf("Non-Preemptive list (%ld):\n ", Types[1].NextAbs); RunList(&Types[1].List, ExamineEvent); modIn(); mPrintf("Quiet list (%ld):\n ", Types[2].NextAbs); RunList(&Types[2].List, ExamineEvent); modIn(); mPrintf("Event ending list:\n "); RunList(&EventEnds, ShowTW); mPrintf("Anytime net is %s\n ", (ClassActive[CL_ANYTIME_NET]) ? "On" : "Off"); if (ClassActive[CL_ANYTIME_NET]) { msgBuf.mbtext[0] = 0; for (i = 0; i < 32; i++) if ((1l << i) & AnyTimeNets) sprintf(lbyte(msgBuf.mbtext), "%d, ", i + 1); if (strlen(msgBuf.mbtext)) msgBuf.mbtext[strLen(msgBuf.mbtext) - 2] = 0; mPrintf("Anytime nets: %s\n ", msgBuf.mbtext); } }
/* * ActiveEvents() * * This puts together something vaguely resembling a useful list of currently * active events. */ void ActiveEvents(char *buf) { int i; void ShowRed(); sprintf(lbyte(buf), "\n Active Events:\n "); if (Dl_Limit_On()) sprintf(lbyte(buf), "D-L time limit of %ld minutes.\n ", Dl_Limit); if (Door_Limit_On()) sprintf(lbyte(buf), "Door time limit of %ld minutes.\n ", Door_Limit); if (GetFirst(&Redirected) != NULL) sprintf(lbyte(buf), "%d Redirect Files active.\n ", RunList(&Redirected, NoFree)); if (GetFirst(&AutoDoors) != NULL) sprintf(lbyte(buf), "%d Auto Doors active.\n ", RunList(&AutoDoors, NoFree)); if (NewUserAllowed()) sprintf(lbyte(buf), "New Users Allowed event active.\n "); if (NewUserDisAllowed()) sprintf(lbyte(buf), "New Users Disallowed event active.\n "); if (ClassActive[CL_ANYTIME_NET]) { sprintf(lbyte(buf), "Anytime net (deadtime=%d) active for net(s) ", DeadTime); for (i = 0; i < 32; i++) if ((1l << i) & AnyTimeNets) sprintf(lbyte(buf), "%d, ", i + 1); buf[strLen(buf) - 2] = 0; strcat(buf, ".\n "); } }
ValPtr VALcopy(ValPtr d, const ValRecord *s) { if (!ATOMextern(s->vtype)) { *d = *s; } else if (s->val.pval == 0) { d->val.pval = ATOMnil(s->vtype); d->vtype = s->vtype; } else if (s->vtype == TYPE_str) { d->vtype = TYPE_str; d->val.sval = GDKstrdup(s->val.sval); d->len = strLen(d->val.sval); } else if (s->vtype == TYPE_bit) { d->vtype = s->vtype; d->len = 1; d->val.btval = s->val.btval; } else { ptr p = s->val.pval; d->vtype = s->vtype; d->len = ATOMlen(d->vtype, p); d->val.pval = GDKmalloc(d->len); memcpy(d->val.pval, p, d->len); } return d; }
HttpHeaderFieldInfo * httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count) { int i; HttpHeaderFieldInfo *table = NULL; assert(attrs && count); /* allocate space */ table = xcalloc(count, sizeof(HttpHeaderFieldInfo)); for (i = 0; i < count; ++i) { const int id = attrs[i].id; HttpHeaderFieldInfo *info = table + id; /* sanity checks */ assert(id >= 0 && id < count); assert(attrs[i].name); assert(info->id == 0 && info->type == 0); /* was not set before */ /* copy and init fields */ info->id = id; info->type = attrs[i].type; stringInit(&info->name, attrs[i].name); assert(strLen(info->name)); /* init stats */ memset(&info->stat, 0, sizeof(info->stat)); } return table; }
/* * CheckArea() * * This function deals with the question of whether the given string is a * directory and to create it if possible and needed. */ char CheckArea(MenuId id, char c, char *drive, char *dir_x) { char work[100]; switch (c) { case IS_DIR: return TRUE; case NO_IDEA: if (strLen(dir_x) != 0) { sprintf(work, "%s does not exist. Create it", dir_x); if (SysopGetYesNo(id, "", work)) { DoBdos(SETDISK, toUpper(*drive) - 'A'); if (mkdir(dir_x) == BAD_DIR) { SysopPrintf(id, "?ERROR CREATING!"); homeSpace(); return FALSE; } else { homeSpace(); return TRUE; } } } else { return TRUE; } return FALSE; default: SysopPrintf(id, "That's not a directory!\n "); return FALSE; } }
/* * DisableModem() * * This function will disable the modem. */ void DisableModem(char FromNet) { if (FromNet || strLen(cfg.DepData.sDisable) == 0) InternalEnDis(FALSE); else OutString(cfg.DepData.sDisable); }
void storeLog(int tag, const StoreEntry * e) { MemBuf mb; MemObject *mem = e->mem_obj; HttpReply *reply; if (storelog_fd < 0) return; if (mem == NULL) return; if (EBIT_TEST(e->flags, ENTRY_DONT_LOG)) return; if (mem->log_url == NULL) { debug(20, 1) ("storeLog: NULL log_url for %s\n", mem->url); storeMemObjectDump(mem); mem->log_url = xstrdup(mem->url); } memBufDefInit(&mb); reply = mem->reply; memBufPrintf(&mb, "%9d.%03d %-7s %08X %4d %9d %9d %9d %s %d/%d %s %s\n", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, storeLogTags[tag], e->swap_file_number, reply->sline.status, (int) reply->date, (int) reply->last_modified, (int) reply->expires, strLen(reply->content_type) ? strBuf(reply->content_type) : "unknown", reply->content_length, (int) (mem->inmem_hi - mem->reply->hdr_sz), RequestMethodStr[mem->method], mem->log_url); file_write_mbuf(storelog_fd, -1, mb, NULL, NULL); }
/* * EnableModem() * * This will enable the modem for use. */ void EnableModem(char FromNet) { if (FromNet || strLen(cfg.DepData.sEnable) == 0) InternalEnDis(TRUE); else OutString(cfg.DepData.sEnable); }
/* * ReInitModem() * * This function will reinitialize the modem at a high speed. */ void ReInitModem() { if (strLen(cfg.DepData.HiSpeedInit) != 0 && !gotCarrier()) { setNetCallBaud(cfg.sysBaud); OutString(cfg.DepData.HiSpeedInit); } }
/* * OutsideEditorWork() * * This will execute an outside editor for anyone. */ void OutsideEditorWork(char *EditLine) { char cmdline[90]; extern FILE *upfd; extern int outPut; doCR(); /* this gets crtColumn back to zero */ sprintf(cmdline, "%stempmsg.sys", cfg.DepData.EditArea); if (!redirect(cmdline, INPLACE_OF)) return; mFormat(msgBuf.mbtext, oChar, doCR); undirect(); MakeCmdLine(cmdline, EditLine, "", sizeof cmdline - 1); if (cfg.DepData.IBM) ModemShutdown(FALSE); CitSystem(TRUE, "%s %stempmsg.sys", cmdline, cfg.DepData.EditArea); if (cfg.DepData.IBM) { ModemOpen(FALSE); if (!gotCarrier() && strLen(cfg.DepData.sDisable) == 0) DisableModem(FALSE); } /* homeSpace(); */ /* Commented out for 120.692 */ msgBuf.mbtext[0] = 0; sprintf(cmdline, "%stempmsg.sys", cfg.DepData.EditArea); msgBuf.mbtext[0] = 0; ingestFile(cmdline, msgBuf.mbtext); unlink(cmdline); }
void sh_htoi(char* params){ int len = strLen(params)-1; if(len < 3 || params[0] != '0' || params[1] != 'x'){ ttprintln("htoi param must start with `0x`"); return; } reverseInPlace(params+2); len -= 2; int i; int sum = 0; for(i = 0; i < len; i++){ if(isAlpha(params[i+2])){ if(isLower(params[i+2]) && params[i+2] <= 'f'){ sum += pow(16,i) * (params[i+2]-'a'+10); } else if(isUpper(params[i+2]) && params[i+2] <= 'F'){ sum += pow(16,i) * (params[i+2]-'A'+10); } else { ttprintln("improperly formed hex"); return; } } else sum += pow(16,i) * (params[i+2]-'0'); } ttprintIntln(sum); }
void sh_poke(char* params){ // poke pointer byte(decimal) int i; for(i=0;i<strLen(params);i++){ if(params[i] == ' ') break; } char substr[i+1]; memCopy(params,substr,i); substr[i] = 0; char* pointer = (char*) ((int*)strToInt(substr)); char substr2[strLen(params)-i]; memCopy(params+i+1,substr2,strLen(params)-i); int value = strToInt(substr2); *pointer = value; }