static VOID HandleSetHandlePrintHex(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam) { LPVOID pMem; HANDLE hNewBuffer; int ret; LocalFree((HLOCAL)SendMessage(handle, EM_GETHANDLE, 0, 0L)); if (UnicodeUsed) { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 100); pMem = LocalLock(hNewBuffer); strcpyw_((wchar_t*)pMem,NewTextW); } else { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,50); pMem = LocalLock(hNewBuffer); strcpy_((char*)pMem,NewText); } LocalUnlock(pMem); hNewBuffer = LocalHandle(pMem); /* Updates the buffer and displays new buffer */ ret = SendMessage(handle, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L); htoa(ret,&TextBuffer[8]); PrintTextXY(TextBuffer,ResultX,ResultY,16); }
int main() { char string[200],word[20][10],*p,*t,*l; int count[50]={0},m,i,j=0,cout=0,flag=0,len; gets(string);p=string;/*len=strlen(string); string[len]=' ';string[len+1]='\n';*/ printf("Enter the mth number : "); scanf("%d",&m);l=p;p++; for(i=0;*l!='\n';) {p--; if(*p=='\n') break; p++; t=p; while(*p!=' ') {p++; }j=0; while(j<cout) { if(!(strcmp_(&word[j][0],t,p-t))) {++count[j]; flag=1; break; } j++; } if(!flag) { strcpy_(&word[cout][0],t,p-t); cout++; } l=p; p++; } for(i=0;i<cout;i++) { // if(count[i]==m) {printf("\nThe %d th most frequent word is %s",m,&word[i][0]); } } }
/* * Handle the multitudinous $ expansion forms. * Ugh. */ void Dgetdol(void) { tchar *np; struct varent *vp; tchar name[MAX_VREF_LEN]; int c, sc; int subscr = 0, lwb = 1, upb = 0; bool dimen = 0, bitset = 0; tchar wbuf[BUFSIZ + MB_LEN_MAX]; /* read_ may return extra bytes */ #ifdef TRACE tprintf("TRACE- Dgetdol()\n"); #endif dolmod = dolmcnt = 0; c = sc = DgetC(0); if (c == '{') c = DgetC(0); /* sc is { to take } later */ if ((c & TRIM) == '#') dimen++, c = DgetC(0); /* $# takes dimension */ else if (c == '?') bitset++, c = DgetC(0); /* $? tests existence */ switch (c) { case '$': if (dimen || bitset) syntax: error("Variable syntax"); /* No $?$, $#$ */ setDolp(doldol); goto eatbrac; case '<'|QUOTE: if (dimen || bitset) goto syntax; /* No $?<, $#< */ for (np = wbuf; read_(OLDSTD, np, 1) == 1; np++) { if (np >= &wbuf[BUFSIZ-1]) error("$< line too long"); if (*np <= 0 || *np == '\n') break; } *np = 0; /* * KLUDGE: dolmod is set here because it will * cause setDolp to call domod and thus to copy wbuf. * Otherwise setDolp would use it directly. If we saved * it ourselves, no one would know when to free it. * The actual function of the 'q' causes filename * expansion not to be done on the interpolated value. */ dolmod = 'q'; dolmcnt = 10000; setDolp(wbuf); goto eatbrac; case DEOF: case '\n': goto syntax; case '*': (void) strcpy_(name, S_argv); vp = adrof(S_argv); subscr = -1; /* Prevent eating [...] */ break; default: np = name; if (digit(c)) { if (dimen) goto syntax; /* No $#1, e.g. */ subscr = 0; do { subscr = subscr * 10 + c - '0'; c = DgetC(0); } while (digit(c)); unDredc(c); if (subscr < 0) error("Subscript out of range"); if (subscr == 0) { if (bitset) { dolp = file ? S_1 /* "1" */ : S_0 /* "0" */; goto eatbrac; } if (file == 0) error("No file for $0"); setDolp(file); goto eatbrac; } if (bitset) goto syntax; vp = adrof(S_argv); if (vp == 0) { vp = &nulargv; goto eatmod; } break; } if (!alnum(c)) goto syntax; for (;;) { *np++ = c; c = DgetC(0); if (!alnum(c)) break; /* if variable name is > 20, complain */ if (np >= &name[MAX_VAR_LEN]) error("Variable name too long"); } *np++ = 0; unDredc(c); vp = adrof(name); } if (bitset) { /* * getenv() to getenv_(), because 'name''s type is now tchar * * no need to xalloc */ dolp = (vp || getenv_(name)) ? S_1 /* "1" */ : S_0 /* "0" */; goto eatbrac; } if (vp == 0) { /* * getenv() to getenv_(), because 'name''s type is now tchar * * no need to xalloc */ np = getenv_(name); if (np) { addla(np); goto eatbrac; } udvar(name); /*NOTREACHED*/ } c = DgetC(0); upb = blklen(vp->vec); if (dimen == 0 && subscr == 0 && c == '[') { np = name; for (;;) { c = DgetC(DODOL); /* Allow $ expand within [ ] */ if (c == ']') break; if (c == '\n' || c == DEOF) goto syntax; if (np >= &name[MAX_VREF_LEN]) error("Variable reference too long"); *np++ = c; } *np = 0, np = name; if (dolp || dolcnt) /* $ exp must end before ] */ goto syntax; if (!*np) goto syntax; if (digit(*np)) { int i = 0; while (digit(*np)) i = i * 10 + *np++ - '0'; /* if ((i < 0 || i > upb) && !any(*np, "-*")) { */ if ((i < 0 || i > upb) && (*np != '-') && (*np != '*')) { oob: setname(vp->v_name); error("Subscript out of range"); } lwb = i; if (!*np) upb = lwb, np = S_AST /* "*" */; } if (*np == '*') np++; else if (*np != '-') goto syntax; else { int i = upb; np++; if (digit(*np)) { i = 0; while (digit(*np)) i = i * 10 + *np++ - '0'; if (i < 0 || i > upb) goto oob; } if (i < lwb) upb = lwb - 1; else upb = i; } if (lwb == 0) { if (upb != 0) goto oob; upb = -1; } if (*np) goto syntax; } else { if (subscr > 0) if (subscr > upb) lwb = 1, upb = 0; else lwb = upb = subscr; unDredc(c); } if (dimen) { tchar *cp = putn(upb - lwb + 1); addla(cp); xfree(cp); } else { eatmod: c = DgetC(0); if (c == ':') { c = DgetC(0), dolmcnt = 1; if (c == 'g') c = DgetC(0), dolmcnt = 10000; if (!any(c, S_htrqxe)) error("Bad : mod in $"); dolmod = c; if (c == 'q') dolmcnt = 10000; } else unDredc(c); dolnxt = &vp->vec[lwb - 1]; dolcnt = upb - lwb + 1; } eatbrac: if (sc == '{') { c = Dredc(); if (c != '}') goto syntax; } }
int httpResp( char* payload, int paylen ){ if( paylen > 14 && strcmp(payload, "GET / HTTP")){ //start ( '/' is the trailing part of the URL ) if(substr("\r\n\r\n", payload, paylen)){ //end //requested a webpage, in one packet. //printf_str("requested a webpage!\n"); g_httpContentLen = htmlDefault(); //content length seems to be minus the headers, the actual content length (surprise!) httpHeader(); //printf_int("header length:", g_httpHeaderLen); //printf_str("\n"); //printf_int("content length:", g_httpContentLen); //printf_str("\n"); return 1; } }else if(paylen >= 18 && substr("POST /data", payload, paylen)){ // get the specified past # ms of data. int pos = substr("rawLen=", payload, paylen); if(pos){ char* p; p = payload; p+= pos; int rawlen = atoi_(p, 10); if(rawlen >= 32 && rawlen <= 4000){ u32* wr_ptr = pWR_PTR; u32 ptr = ((*wr_ptr) & 0x3ffe0) - (rawlen*16*2); u32* dest = (u32*)HTTP_CONTENT; u32* src = (u32*)ptr; int i; for(i=0; i< rawlen*8; i++){ src = (u32*) ( ((u32)src) & 0x3ffff ); *dest++ = *src++; } g_httpContentLen = rawlen * 32; httpHeader(); } else { char* dest = (char*)HTTP_CONTENT; int len = 0; dest = strcpy_(dest, &len, "/data: rawLen unspecified or out of range"); g_httpContentLen = len; httpHeader(); } return 1; } }else if(paylen >= 18 && substr("POST",payload,paylen) ){ int pos = substr("POST",payload,paylen); payload += pos; paylen -= pos; char paramChanged = 0; if(substr("data_stream=",payload, paylen) ){ if(substr("=Enable",payload, paylen) ){ //then turn on the data stream! u32* wr_ptr = pWR_PTR; u32* tr_ptr = pTR_PTR; g_streamEnabled = 1; (*tr_ptr) = (*wr_ptr); //so that we don't spend a long time catching up. paramChanged = 1; } if(substr("=Disable",payload, paylen)){ g_streamEnabled = 0; paramChanged = 1; } } if(substr("filter_data",payload,paylen)){ if(substr("=Enable",payload, paylen) ){ *pRAW_ENAB = 0; //enable filter = disable raw. paramChanged = 1; } if(substr("=Disable",payload, paylen)){ *pRAW_ENAB = 1; //enable filter = disable raw. paramChanged = 1; } } // --- look at the mouse channels. char* p; pos = substr("xpos_chan=",payload,paylen); if(pos){ p = payload; p += pos; //g_mouseXpos = (u8)(PhysicalToLogicalChan(atoi_( p, 3)) & 0xff); paramChanged = 1; } pos = substr("ypos_chan=",payload,paylen); if(pos){ p = payload; p += pos; //g_mouseYpos = (u8)(PhysicalToLogicalChan(atoi_( p, 3)) & 0xff); paramChanged = 1; } pos = substr("xneg_chan=",payload,paylen); if(pos){ p = payload; p += pos; //g_mouseXneg = (u8)(PhysicalToLogicalChan(atoi_( p, 3)) & 0xff); paramChanged = 1; } pos = substr("yneg_chan=",payload,paylen); if(pos){ p = payload; p += pos; //g_mouseYneg = (u8)(PhysicalToLogicalChan(atoi_( p, 3)) & 0xff); paramChanged = 1; } //set the destination IP pos = substr("ip1=",payload,paylen); if(pos){ payload += pos; paylen -= pos; //speed up the search.. p = payload; u32 tip = atoi_(p,3) & 0xff; NetDataDestIP &= 0xffffff00 ; //big-endian order. NetDataDestIP += tip; paramChanged = 1; } pos = substr("ip2=",payload,paylen); if(pos){ payload += pos; paylen -= pos; //speed up the search.. p = payload; u32 tip = atoi_(p,3) & 0xff; NetDataDestIP &= 0xffff00ff ; NetDataDestIP += tip << 8; paramChanged = 1; } pos = substr("ip3=",payload,paylen); if(pos){ payload += pos; paylen -= pos; //speed up the search.. p = payload; u32 tip = atoi_(p,3) & 0xff; NetDataDestIP &= 0xff00ffff ; NetDataDestIP += tip << 16; paramChanged = 1; } pos = substr("ip4=",payload,paylen); if(pos){ payload += pos; paylen -= pos; //speed up the search.. p = payload; u32 tip = atoi_(p,3) & 0xff; NetDataDestIP &= 0x00ffffff ; NetDataDestIP += tip << 24; paramChanged = 1; } // -------------------------- if(paramChanged){ g_httpContentLen = htmlDefault(); httpHeader(); return 1; } // calibrate thresholds! if(substr("calibrate=Cal",payload,paylen)){ //look at the last 2 seconds of data & measure mean. //*assuming that the absolute value has been taken* int sum[16]; int i,j; for(i=0; i<16;i++){ sum[i] = 0; } u32* wr_ptr = pWR_PTR; u32 ptr = ((*wr_ptr) & 0x3ffe0) - (16*2048*2); ptr &= 0x3ffff; u16* p = (u16*)ptr; for(j=0; j<2048; j++){ for(i=0; i<16; i++){ sum[i] += *p++; p = (u16*)((u32)p & 0x3ffff); } } for(i=0; i<16;i++){ sum[i] = sum[i] >> 11; } int len = htmlDefault(); char* dest = (char*)HTTP_CONTENT; len -= 19; //overwrite the </body> </html> dest += len; dest = strcpy_(dest, &len, "<table>\n"); for(i=0; i<16; i++){ int logical = 0/*PhysicalToLogicalChan(i)*/; dest = strcpy_(dest, &len, "<tr><td>Channel "); dest = strprintf_int(dest, &len, i ); dest = strcpy_(dest, &len, "</td><td>mean "); dest = strprintf_int(dest, &len, sum[logical]); dest = strcpy_(dest, &len, "</td></tr>\n"); } dest = strcpy_( dest, &len, "</table></body></html>\r\n" ); g_httpContentLen = len ; httpHeader(); return 1; }