int Spam::GetSpamNick(char ** nicks, char *test) { int j_st, w_fill, c_nick = 0; char *oth; for(int i = 0; i < strlen(test); i++) { if(test[i] == '3' && test[i+1] == '5' && test[i+2] == '3') { j_st = i; w_fill = 0; oth = new char[1024]; strnset(oth, '\0', 1024); for(int j = j_st; j < strlen(test); j++) { oth[w_fill] = test[j]; w_fill++; } } } string nick; char *a1, *a2; a1 = oth; a2 = oth; while(*a2 && !strchr(":", *a2)) ++a2; nick.assign(a1, a2 - a1); if(*a2 != ':') a1 = ++a2; a1 = ++a2; while(*a2 != ':') { while(*a2 && !strchr(" ", *a2)) ++a2; nick.assign(a1, a2 - a1); if(*a2 != isspace(*a2)) a1 = ++a2; char *tmp_nick = new char[strlen(nick.c_str())]; strnset(tmp_nick, '\0', strlen(nick.c_str())); strcpy(tmp_nick, nick.c_str()); nicks[c_nick] = tmp_nick; c_nick++; } return c_nick; }
void TestBounded( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufB[80]; char *bufPtr; int status; size_t len; len = strlcpy( bufB, "FoO baR", sizeof( bufB ) ); /* copy string */ VERIFY( len == strlen( "FoO baR" ) ); len = strlcat( bufB, " gOoBeR bLaH", sizeof( bufB ) ); /* append rest */ VERIFY( len == strlen( bufA ) ); status = strcmp( bufA, bufB ); /* check result */ VERIFY( status == 0 ); bufPtr = strset( bufB, 0x00 ); /* zero out buffer */ VERIFY( bufPtr == bufB ); len = strlcpy( bufB, "ABCDEFGHIJ", 3 ); /* copy two chars */ VERIFY( len == strlen( "ABCDEFGHIJ" ) ); len = strlcat( bufB, "CDEFGHIJ", 6 ); /* copy three more */ VERIFY( len == strlen( "ABCDEFGHIJ" ) ); status = strcmp( bufB, "ABCDE" ); /* ensure only five chars */ VERIFY( status == 0 ); len = strlcat( bufB, "junk", 3 ); /* ensure no running off */ VERIFY( len == 3 ); bufPtr = strnset( bufB, 0x00, 10 ); /* blank string */ VERIFY( bufPtr == bufB ); }
void TestMove( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufB[80]; char *bufPtr; char *newBuf; int status; bufPtr = strcpy( bufB, "FoO baR" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = strcat( bufB, " gOoBeR bLaH" ); /* append the rest */ VERIFY( bufPtr == bufB ); status = strcmp( bufA, bufB ); /* check result */ VERIFY( status == 0 ); bufPtr = strset( bufB, 0x00 ); /* zero out buffer */ VERIFY( bufPtr == bufB ); bufPtr = strncpy( bufB, "ABCDEFGHIJ", 2 ); /* copy two bytes */ VERIFY( bufPtr == bufB ); bufPtr = strncat( bufB, "CDEFGHIJ", 3 ); /* copy three more */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "ABCDE" ); /* ensure only five bytes */ VERIFY( status == 0 ); bufPtr = strnset( bufB, 0x00, 10 ); /* blank string */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "" ); /* verify empty */ VERIFY( status == 0 ); bufPtr = strcpy( bufB, "abcdefghij" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = strrev( bufB ); /* reverse it */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "jihgfedcba" ); /* ensure reversed ok */ VERIFY( status == 0 ); newBuf = strdup( bufA ); /* duplicate string */ status = strcmp( bufA, newBuf ); VERIFY( status == 0 ); }
int getopt(int argc, char* const * argv, const char* opts) { static int sp = 1; register int c; register char *cp; char noswitch[3]; strnset(noswitch, optswi, 2); noswitch[2]=0; if (sp == 1) if (optind >= argc || argv[optind][0] != optswi || argv[optind][1] == '\0') return(EOF); else if (strcmp(argv[optind], noswitch) == 0) { optind++; return(EOF); } optopt = c = argv[optind][sp]; if (c == ':' || (cp=strchr(opts, c)) == NULL) { V_ERR(": illegal option -- ", c); if (argv[optind][++sp] == '\0') { optind++; sp = 1; } return('?'); } if (*++cp == ':') { if (argv[optind][sp+1] != '\0') optarg = &argv[optind++][sp+1]; else if (++optind >= argc) { V_ERR(": option requires an argument -- ", c); sp = 1; return('?'); } else optarg = argv[optind++]; sp = 1; } else { if (argv[optind][++sp] == '\0') { sp = 1; optind++; } optarg = NULL; } return(c); }
void main() { printf( "%s\n", source ); printf( "%s\n", strnset( source, '=', 100 ) ); printf( "%s\n", strnset( source, '*', 7 ) ); }
/* ************************************************************************** */ int fget_c_string(char *string, int Max_Str_Len, FILE *fspec) { /* gets a string from the input and removes comments from it */ /* allows comments in standard "c" syntax, starting with / * ending with * / */ /* also allows c++ type comments, // causes rest of line to be skipped */ int check; char comment_start[4]="/*"; /* signals start of comment */ char comment_stop[4]="*/"; /* signals end of comment */ int clen; /* length of string for start/stop*/ int ilen; /* length of input string */ char *istring; /* input string */ int olen; /* location on output string */ int icnt; /* location on string */ // int n_pass = 0; /* Number of passes through the file looking for a value */ olen = 0; /* allocate memory for input string */ istring = (char *)calloc(Max_Str_Len,sizeof(char)); if(istring == NULL) { printf("\n ERROR: Allocating memory for input string if fget_c_string"); return(FAIL); } strnset(string,'\0',Max_Str_Len); /* null entire output string */ strnset(istring,'\0',Max_Str_Len); /* null entire input string */ #ifdef DEBUG printf ("\n --------------fget_c_string"); #endif clen = strlen(comment_start); /* read in the line, verify that it exists */ do{ /* read in a line from the file */ while(fgets(istring, Max_Str_Len, fspec) == NULL) /* output warning if not a valid read */ { #ifdef DEBUG printf("\n istring: %s", istring); #endif #ifdef ALLOW_REWIND if(n_pass) /* if already gone through file once looking for value, quit */ #endif { #ifdef DEBUG // printf ("\n***End of Input File in get_string, closing"); #endif // printf ("\nERROR: Reading File : End of File On Read "); // fclose(fspec); free(istring); return(FAIL); } #ifdef ALLOW_REWIND n_pass++; /* increment the number of times through the file */ rewind(fspec); /* rewind to the beginning of the file */ free(istring); return(REWIND_STREAM); #endif } #ifdef DEBUG printf("\n istring: %s", istring); #endif ilen = strlen(istring); /* length of input string */ istring[ilen]='\0'; /* null terminate the string */ if(ilen < clen) /* not possible to have comment on the line */ { /* so output the string as is */ strcpy(string,istring); olen = strlen(string); } else { /* strip comments out of input string */ icnt=0; do{ check = 1; if(icnt < ilen - clen) /* make sure have enough characters for start of comment */ check = strncmp(istring+icnt,comment_start,clen); /* check if start of comment */ if(check == 0) /* comment found for standard c syntax */ { /* find end of comment */ icnt+=clen; /* advance past comment delimeter */ clen=strlen(comment_stop); /* get length of end of comment delimiter */ /* look for end of comment till end of string */ do{ check = 1; if(icnt < ilen - clen) /* make sure have enough characters for end of comment */ check = strncmp(istring+icnt, comment_stop,clen); if(check != 0) /* if not end of comment */ { icnt++; /* increment location on string */ if(icnt>ilen) /* if advance past end of string, get a new one */ { if(fgets(istring, Max_Str_Len, fspec) == NULL) /* output warning if not a valid read */ { printf ("\nERROR: Reading File, looking for end of comment %s",comment_stop); // fclose(fspec); free(istring); return(FAIL); } ilen = strlen(istring); /* get length of this new string */ /* null terminate the string */ istring[ilen]='\0'; icnt = 0; /* reset the counter to the start of the string */ } } else { icnt+=clen; /* advance past comment delimiter */ } }while(check != 0); /* end of comment found */ } /* end if */ else /* check if comment is in c++ format */ { check = strncmp(istring+icnt, "//",2); if(check == 0) /* c++ style comment found */ { /* skip till end of string */ icnt = ilen; string[olen++]='\n'; string[olen]='\0'; } else /* is a valid character for the string */ { string[olen++] = istring[icnt++]; /* append value to the string */ string[olen]='\0'; } } }while(icnt < ilen && /* do till end of string */ olen < Max_Str_Len); /* and output string not too long */ /* check for only carriage return (should have been caught above) */ if(olen == 1 && string[0] == '\n') olen = 0; } /* end else */ }while(olen == 0); /* do till read in a string */ if(olen == Max_Str_Len) { printf ("\nERROR: Input line too long"); // fclose(fspec); free(istring); return(FAIL); } free(istring); return(OK); }
// syslogdtcp( ) // // Entry into syslogdipc.cpp to setup and start UDP listening // void syslogdtcp( ) { bool firststart = TRUE; int msgrecv; int seterr; int i; char recv_buffer[1024]; char *ptr_recv_buffer = recv_buffer; // setup for running, if error bug out - don't worry about main // will timeout waiting for TCPSEM1. seterr = setuptcp( ); if(seterr) { if(seterr == 1) { psock_errno( NULL ); closetcp( ); } if(seterr == 3) printf("DosGetSharedMem failed\n"); } // main working loop ********************** while(TRUE) { // Just my play. Set SEM1 (SYSLOGD is waiting), delay 1 sec // (let SYSLOGD reset), and start now FALSE - continue - // sleep 1.5 sec for SEM sets or thread will shutdown if(firststart) { DosPostEventSem(hevTCPSEM1); // tell main I am up!! DosSleep(1500); firststart = FALSE; } // clear recv_buffer for(i = 0; i < 1024; i++) recv_buffer[i] = 0; msgrecv = recv(tcpsocket, ptr_recv_buffer, 1024, 0); // read socket // have a message msgrecv > 0 and not blocked if(msgrecv > 0 && prgoptions->securemode) { if(DosRequestMutexSem(mtxMEMMUX, 60000L) != 0) { printf("SYSLOGTCP: Timeout waiting for MUX\n"); } else { if(pShareMem->slotstat[pShareMem->index]) { printf("SYSLOGTCP: Buffer full!!\n"); stats.tcpoverflows++; } else { // clear the slot strnset(pShareMem->data[pShareMem->index], '\0 ', sizeof(pShareMem->data[pShareMem->index])); // write message into slot replace any character < 32 or > 126 // with a space RFC 3164 characters must be in this range for(i = 0; i < strlen(recv_buffer); i++) { if(((int)recv_buffer[i] < 32) || ((int)recv_buffer[i] > 126)) pShareMem->data[pShareMem->index][i] = ' '; else pShareMem->data[pShareMem->index][i] = recv_buffer[i]; } // set flag slot has message pShareMem->slotstat[pShareMem->index] = 1; ++pShareMem->index; // increment index to next slot ++stats.systcprecvmsg; // ++tcpatcount; // if reached top of buffer reset index to 0 or bottom if(pShareMem->index == (BUFFER_SLOTS)) pShareMem->index = 0; DosPostEventSem(hevIDLESEM); // wakeup MAIN if IDE } DosReleaseMutexSem(mtxMEMMUX); } } // end of msg recv // check for shutdown signal from main DosQueryEventSem(hevTCPSEM2, &TCPSEM2Ct); if(TCPSEM2Ct && !firststart) { DosResetEventSem(hevTCPSEM1, &TCPSEM1Ct); closetcp( ); } // sleep 1 minute if blocked so do not suckup the CPU if(!prgoptions->securemode) DosSleep(60000L); } //$* end working loop } //$* end of syslogdtcp