BOOL SolveFullName ( LPSTR fullname, LPSTR* filename, LPSTR* path ) { char tmp1 [ MAX_PATH ], tmp2 [ _MAX_DIR ], tmp3 [ MAX_PATH ], tmp4 [ _MAX_EXT ]; _splitpath ( fullname, tmp1, tmp2, tmp3, tmp4 ); if ( filename != NULL ) { strcat ( tmp3, tmp4 ); strcpy2 ( filename, tmp3 ); } if ( path != NULL ) { strcat ( tmp1, tmp2 ); if ( strlen ( tmp1 ) > 0 ) if ( tmp1 [ strlen ( tmp1 ) - 1 ] == '\\' || tmp1 [ strlen ( tmp1 ) - 1 ] == '/' ) tmp1 [ strlen ( tmp1 ) - 1 ] = '\0'; strcpy2 ( path, tmp1 ); } return TRUE; }
static void itoa2(long n, char *s, int base, long *digits) { long i,j,sign; unsigned long n2; char number[20]; for(i=0;i<15;++i) { number[i]=' '; } number[15]=0; if(n>=0||base!=10) { sign=1; } else { sign=-1; } n2=n*sign; for(j=14;j>=0;--j) { i=n2%base; n2/=base; number[j]=i<10?'0'+i:'a'+i-10; if(n2==0&&15-j>=*digits) break; } if(sign==-1) { number[--j]='-'; } if(*digits==0||*digits<15-j) { strcpy2(s,&number[j]); *digits=15-j; } else { strcpy2(s,&number[15-*digits]); } }
int main (int argc, char * argv[]) { char string[32]; strcpy2(string, "Hello "); strcpy2(string, argv[1]); printf("hello %s", string); return 0; }
void TwitterRegisterSubject(char *subject, AsyncCallback_t callback) { if (!subjectA.callback) { subjectA.callback = callback; strcpy2(subjectA.subject, subject); } else if (!subjectB.callback) { subjectB.callback = callback; strcpy2(subjectB.subject, subject); } else { Crash(3); } }
void TwitterRegisterHashtag(char *hashtag, AsyncCallback_t callback) { if (!hashtagA.callback) { hashtagA.callback = callback; strcpy2(hashtagA.hashtag, hashtag); } else if (!hashtagB.callback) { hashtagB.callback = callback; strcpy2(hashtagB.hashtag, hashtag); } else if (!hashtagC.callback) { hashtagC.callback = callback; strcpy2(hashtagC.hashtag, hashtag); } else { Crash(2); } }
/* strdup2: copies the string given into a safe place using malloc */ char *strdup2(char *s) { /* make a duplicate of s */ char *p; p = (char *)malloc(strlen(s) + 1); /* +1 for '\0' */ if (p != NULL) strcpy2(p, s); return p; }
BOOL file_loader::Q2::Add_WAD ( LPSTR filename ) { // search in existing entries for ( int x = 0; x < Q2_Resources.num_files; x++ ) { if ( _stricmp ( Q2_Resources.files [ x ].fullname, filename ) == 0 ) return TRUE; } FILE* file = fopen ( filename, "r" ); if ( file == NULL ) return FALSE; fclose ( file ); int n = Q2_Resources.num_files; Q2_Resources.Resize ( n + 1 ); strcpy2 ( &Q2_Resources.files [ n ].fullname, filename ); SolveFullName ( Q2_Resources.files [ n ].fullname, &Q2_Resources.files [ n ].filename, &Q2_Resources.files [ n ].path ); Q2_Resources.num_files++; return TRUE; }
void AHTMODEL::SetSource( char *filename ) { strcpy2( fname, filename, AHTMODEL_FNMAX ); propstr = new CMemBuf; exp = new CMemBuf( 0x1000 ); flag = AHTMODEL_FLAG_READY; }
fivePointFive() { /* s is an array while p is a point, the case below show the difference. * The same thing for them is both them can visit value by adding steps.*/ char s[] = "i love you"; /* s can not be refered to another address, but string content can be modified.*/ // s = "iii"; //this will cause a compile error, for s is not a pointer. *(s + 1) = 'i'; // this is well, because for an array, the value can be modified. printf("%s %c\n", s, *s); char *p = "i love you"; /* p can be refered to another address, but string content can not be modified. */ p = "you love me"; // this is well, because p is a point, not a name of array. // *(p + 1) = 'u'; // this will cause a runtime error, for p can not modify the value. printf("%s %c\n", p, *p); // char *p = "you love me"; p will be pointed to an anonymous string, so it can't modify the value. // s = p; s++; //this will cause a compile error, for s is not a pointer. p = s; /* p now refered to an array and can be used just like s to modify the string content.*/ *(p + 1) = ' '; printf("%s\n", p); // char *ss = "123"; This will cause a runtime error, for ss should be an array which its value is allowed to be modified. char ss[10] = "123"; char *tt = "456"; // Here, use pointer is ok, for we just visit the value, no modification. printf("%s compared with %s: %d\n", ss, tt, strcmp(ss, tt)); strcpy(ss, tt); strcpy1(ss, tt); strcpy2(ss, tt); strcpy3(ss, tt); strcpy4(ss, tt); printf("copy tt to ss get %s\n", ss); printf("%s compared with %s: %d\n", ss, tt, strcmp2(ss, tt)); }
void TwitterWireMasterAddSlave(int id, char *name) { if (wireSlaveA.id == 0) { wireSlaveA.id = id; strcpy2(wireSlaveA.name, name); } else if (wireSlaveB.id == 0) { wireSlaveB.id = id; strcpy2(wireSlaveB.name, name); } else if (wireSlaveC.id == 0) { wireSlaveC.id = id; strcpy2(wireSlaveC.name, name); } else { Crash(3); } }
int main(void) { char str[10] = "abcdefg"; char dest[20] ;memset(dest, 0,sizeof(dest) ); strcpy2(dest, str ); printf("src %s\t", str); printf("dest %s \n", dest); char c ='d'; printf("strchr %s %c %s\n", str, c, strchr2(str, c)); const char* cc ="de"; printf("strchr %s %s %s\n", str, cc, strstr2(str, cc)); }
AHTPROP *AHTMODEL::SetPropertyType( char *propname, int type ) { AHTPROP *p; p = GetProperty( propname ); if ( p == NULL ) { char ptmp[128]; strcpy2( ptmp, propname, 128 ); strcase( ptmp ); p = AddProperty(); SetPropOrgName( p, ptmp ); } p->ahttype = type; return p; }
int AHTMODEL::GetPropertyID( char *propname ) { // プロパティ名から検索 // int i; char tmp[128]; strcpy2( tmp, propname, 128 ); strcase( tmp ); for(i=0;i<prop_cnt;i++) { if ( tstrcmp( mem_prop[i]->orgname, tmp ) ) { return i; } } return -1; }
AHTPROP *AHTMODEL::GetPropertyFromAlias( char *propname ) { // プロパティ名から検索 // int i; char tmp[128]; strcpy2( tmp, propname, 128 ); strcase( tmp ); for(i=0;i<prop_cnt;i++) { if ( tstrcmp( mem_prop[i]->name, tmp ) ) { return mem_prop[i]; } } return NULL; }
AHTPROP *AHTMODEL::SetProperty( char *propname, char *name, char *value ) { AHTPROP *p; p = GetProperty( propname ); if ( p == NULL ) { char ptmp[128]; strcpy2( ptmp, propname, 128 ); strcase( ptmp ); p = AddProperty(); SetPropOrgName( p, ptmp ); } if (( name == NULL )||( value == NULL )) return p; if ( SetProp( p, name, value ) < 0 ) return NULL; return p; }
int main() { char *s = "Hello World!"; char *p; char *p2; strcpy1(p, s); printf("%s\n", p); strcpy2(p, s); printf("%s\n", p); strcpy3(p, s); printf("%s\n", p); }
/* readlines: read input lines */ int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; //char *s; nlines = 0; //int getline2(char *, int); //len = getline2(s, MAXLEN); //while ((len = getline2(line, MAXLEN)) > 0) while ((len = getline2(line, MAXLEN)) > 0) //if (nlines >= maxlines || p = alloc(len) == NULL) if (nlines >= maxlines || (p = alloc(len)) == NULL) { printf("readlines: nlines (%d) exceeded maxlines (%d) or p (%p) was NULL\n", nlines, maxlines, p); return -1; } else { line[len-1] = '\0'; /* delete newline */ strcpy2(p, line); lineptr[nlines++] = p; } return nlines; }
void main() { char *string1 = (char*) malloc(5 * sizeof(char)); char *string2 = (char*) malloc(5 * sizeof(char)); int i = 0; int j; while (i < 5) { string1[i] = 'z'; i = i + 1; } strcpy2(string2, string1); for (j=0; j<5; j++) { printf("%c", string2[j]); } printf("\n"); printf("a toupper: %c\n", toupper('a')); printf("5 isdigit: %i\n", isdigit(5)); printf("asin 50.0: %f", asinh(50.0)); free(string1); free(string2); }
int main(void) { char s[100]; char *t = "Test strcpy;"; strcpy1(s,t); printf("%s\n", t); strcpy2(s,t); printf("%s\n", t); strcpy3(s,t); printf("%s\n", t); strcpy4(s,t); printf("%s\n", t); strcpy1(s+strlen1(s),t); printf("%s\n", s); printf("%d\n", strcmp1(s,t)); printf("%d\n", strcmp2(s,t)); return 0; }
void AHTMODEL::SetName( char *dname ) { strcpy2( name, dname, 128 ); }
void AHTMODEL::SetAuthor( char *name ) { strcpy2( author, name, 32 ); }
void AHTMODEL::SetVersion( char *name ) { strcpy2( ver, name, 32 ); }
void AHTMODEL::SetClass( char *name ) { strcpy2( classname, name, 128 ); }
BOOL file_loader::Find::Files_in_ZIP ( LPSTR zipname, LPSTR common, files_found_in_ZIP* files_found ) { FILE* file = fopen ( zipname, "rb" ); if ( file == NULL ) return FALSE; // read header fseek ( file, 0 - sizeof ( zip_dir_t ), SEEK_END ); zip_dir_t dir; if ( fread ( &dir, 1, sizeof ( zip_dir_t ), file ) != sizeof ( zip_dir_t ) ) return FALSE; zfile_entry_t* files = new zfile_entry_t [ dir.count ]; // navigate to file entries fseek ( file, dir.offset, SEEK_SET ); int i; for ( i = 0; i < dir.count; i++ ) { // read header followed by file name zip_file_t h; if ( fread ( &h, 1, sizeof ( zip_file_t ), file ) != sizeof ( zip_file_t ) ) return false; char name[256]; memset ( name, 0, sizeof ( name ) ); if ( fread ( name, 1, h.name_len, file ) != h.name_len ) return false; fseek ( file, h.extra_len+h.comment_len, SEEK_CUR ); strcpy ( files [ i ].name, _strlwr ( name ) ); files [ i ].offset = h.offset; files [ i ].size = h.size; files [ i ].csize = h.csize; } fclose ( file ); // search requested files ( *files_found ).Init ( ); // save zipname strcpy2 ( &( *files_found ).zipname, zipname ); // convert to lowercase char fcommon [ 256 ]; strcpy ( fcommon, common ); strcpy ( fcommon, _strlwr ( fcommon ) ); for ( i = 0; i < dir.count; i++ ) { if ( strstr ( files [ i ].name, fcommon ) != NULL ) { int n = ( *files_found ).num_files; ( *files_found ).Resize ( n + 1 ); strcpy2 ( &( *files_found ).files [ n ].fullname, files [ i ].name ); SolveFullName ( ( *files_found ).files [ n ].fullname, &( *files_found ).files [ n ].filename, &( *files_found ).files [ n ].path ); ( *files_found ).num_files++; } } SAFE_DELETE ( files ); return TRUE; }
void AHTMODEL::SetIconFile( char *name ) { strcpy2( icon, name, 32 ); }
BOOL file_loader::Find::Files ( LPSTR common, LPSTR path, files_found* files ) { char dir_save [ _MAX_PATH ]; GetCurrentDirectory ( _MAX_PATH, dir_save ); _chdir ( path ); ( *files ).Init ( ); struct _finddata_t c_files; long hFile; struct _finddata_t c_dirs [ 256 ]; long hDir [ 100 ]; int n = 0; int x = -1; goto start; next: if ( ( hDir [ x ] = _findfirst ( "*.*", &c_dirs [ x ] ) ) != -1 ) { if ( c_dirs [ x ].attrib & _A_SUBDIR ) { if ( strcmp ( c_dirs [ x ].name, "." ) == 0 || strcmp ( c_dirs [ x ].name, ".." ) == 0 ) goto last; _chdir ( c_dirs [ x ].name ); goto start; } } last: while ( ( _findnext ( hDir [ x ], &c_dirs [ x ] ) ) != -1 ) { if ( c_dirs [ x ].attrib & _A_SUBDIR ) { if ( strcmp ( c_dirs [ x ].name, "." ) == 0 || strcmp ( c_dirs [ x ].name, ".." ) == 0 ) goto last; _chdir ( c_dirs [ x ].name ); start: if ( ( hFile = _findfirst ( common, &c_files ) ) != -1L ) { if ( c_files.attrib & _A_SUBDIR ) goto jump; char dir [ _MAX_PATH ]; char name [ _MAX_PATH ]; GetCurrentDirectory ( _MAX_PATH, dir ); ( *files ).Resize ( n + 1); strcpy2 ( &( *files ).files [ n ].filename, c_files.name ); strcpy2 ( &( *files ).files [ n ].path, dir); sprintf ( name, "%s/%s", dir, c_files.name ); strcpy2 ( &( *files ).files [ n ].fullname, name ); ( *files ).num_files++; n++; jump: while ( ( _findnext ( hFile, &c_files ) ) != -1 ) { if ( c_files.attrib & _A_SUBDIR ) continue; ( *files ).Resize ( n + 1 ); strcpy2 ( &( *files ).files [ n ].filename, c_files.name ); strcpy2 ( &( *files ).files [ n ].path, dir ); sprintf ( name, "%s/%s", dir, c_files.name ); strcpy2 ( &( *files ).files [ n ].fullname, name ); ( *files ).num_files++; n++; } } _findclose ( hFile ); x++; goto next; } } _findclose ( hDir [ x ] ); if ( x == 0 ) { _chdir ( dir_save ); if ( ( *files ).num_files > 0 ) return TRUE; return FALSE; } _chdir ( ".." ); x--; goto last; }
int main(int argc,char *argv[]) { int i; for (i=0; i<1024; ++i) { printf("%08x%c",arc4random(),(i&15)==15 ? '\n' : ' '); } perror("write"); #if 0 int n; struct ucontext uc; n=0; getcontext(&uc); puts("getcontext returned"); if (n==0) { ++n; setcontext(&uc); puts("should not get here"); exit(1); } puts("all ok"); return 0; #endif #if 0 char* a=malloc(-3); char* b=malloc(0xffffffffull+1); printf("%p %p\n",a,b); #endif #if 0 printf("%u\n",getpagesize()); #endif #if 0 struct stat s; time_t t=time(0); struct tm* T; stat("/tmp/nyt.html",&s); T=gmtime(&s.st_mtime); #endif #if 0 static struct mq_attr x; mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x); mqd_t b=mq_open("fnord",O_RDONLY); #endif #if 0 struct statfs s; if (statfs("/tmp",&s)!=-1) { printf("%llu blocks, %llu free\n",(unsigned long long)s.f_blocks,(unsigned long long)s.f_bfree); } #endif #if 0 char* c=strndupa("fnord",3); puts(c); #endif #if 0 char buf[100]; __write2("foo!\n"); memset(buf,0,200); #endif #if 0 printf("%+05d\n",500); #endif #if 0 char* c; printf("%d\n",asprintf(&c,"foo %d",23)); puts(c); #endif #if 0 struct winsize ws; if (!ioctl(0, TIOCGWINSZ, &ws)) { printf("%dx%d\n",ws.ws_col,ws.ws_row); } #endif #if 0 struct termios t; if (tcgetattr(1,&t)) { puts("tcgetattr failed!"); return 1; } printf("%d\n",cfgetospeed(&t)); #endif #if 0 printf("%p\n",malloc(0)); #endif #if 0 char* argv[]= {"sh","-i",0}; char buf[PATH_MAX+100]; int i; for (i=0; i<PATH_MAX+20; ++i) buf[i]='a'; memmove(buf,"PATH=/",6); strcpy(buf+i,"/bin:/bin"); putenv(buf); execvp("sh",argv); printf("%d\n",islower(0xfc)); #endif #if 0 char buf[101]; __dtostr(-123456789.456,buf,100,6,2); puts(buf); return 0; #endif #if 0 time_t t=1009921588; puts(asctime(localtime(&t))); #endif #if 0 printf("%g\n",atof("30")); #endif #if 0 char* buf[]= {"FOO=FNORD","A=B","C=D","PATH=/usr/bin:/bin",0}; environ=buf; putenv("FOO=BAR"); putenv("FOO=BAZ"); putenv("BLUB=DUH"); system("printenv"); #endif #if 0 char buf[1024]; time_t t1=time(0); struct tm* t=localtime(&t1); printf("%d %s\n",strftime(buf,sizeof buf,"%b %d %H:%M",t),buf); #endif #if 0 tzset(); printf("%d\n",daylight); #endif #if 0 struct in_addr addr; inet_aton("10.0.0.100\t",&addr); printf("%s\n",inet_ntoa(addr)); #endif #if 0 printf("%u\n",getuid32()); #endif #if 0 FILE *f; int i; char addr6p[8][5]; int plen, scope, dad_status, if_idx; char addr6[40], devname[20]; if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { while ((i=fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope, &dad_status, devname)) != EOF) { printf("i=%d\n",i); } } #endif #if 0 printf("%s\n",crypt("test","$1$")); #endif #if 0 MD5_CTX x; unsigned char md5[16]; MD5Init(&x); MD5Update(&x,"a",1); MD5Final(md5,&x); { int i; for (i=0; i<16; ++i) { printf("%02x",md5[i]); } putchar('\n'); } #endif #if 0 long a,b,c; char buf[20]="fnord"; strcpy(buf,"Fnordhausen"); strcpy2(buf,"Fnordhausen"); rdtscl(a); strcpy(buf,"Fnordhausen"); rdtscl(b); strcpy2(buf,"Fnordhausen"); rdtscl(c); printf("C: %d ticks, asm: %d ticks\n",b-a,c-b); #endif /* printf("%d\n",strcmp(buf,"fnord")); */ #if 0 regex_t r; // printf("regcomp %d\n",regcomp(&r,"^(re([\\[0-9\\]+])*|aw):[ \t]*",REG_EXTENDED)); printf("regcomp %d\n",regcomp(&r,"^([A-Za-z ]+>|[]>:|}-][]>:|}-]*)",REG_EXTENDED)); printf("regexec %d\n",regexec(&r,"Marketing-Laufbahn hinterdir.",1,0,REG_NOSUB)); #endif #if 0 FILE *f=fopen("/home/leitner/Mail/outbox","r"); char buf[1024]; int i=0; if (f) { while (fgets(buf,1023,f)) { ++i; printf("%d %lu %s",i,ftell(f),buf); } } #endif #if 0 char template[]="/tmp/duh/fnord-XXXXXX";
void JWireRespond(char *msg) { //Copy message strcpy2(buffer, msg); }
void AHTMODEL::SetHelpKeyword( char *name ) { strcpy2( helpkw, name, 256 ); }
int messages_selection(MESSAGES *m, void *buffer, uint32_t len, _Bool names) { if(m->data->n == 0) { *(char_t*)buffer = 0; return 0; } MSG_IDX i = m->data->istart, n = m->data->iend + 1; void **dp = &m->data->data[i]; char_t *p = buffer; while(i != MSG_IDX_MAX && i != n) { MESSAGE *msg = *dp++; if(names && (i != m->data->istart || m->data->start == 0)) { if(m->type) { //TODO: get rid of such hacks or provide unpacker. //This basically undoes copy_groupmessage(). uint8_t l = (uint8_t)msg->msg[msg->length]; if(len <= l) { break; } memcpy(p, &msg->msg[msg->length + 1], l); p += l; len -= l; } else { FRIEND *f = &friend[m->data->id]; if(!msg->author) { if(len <= f->name_length) { break; } memcpy(p, f->name, f->name_length); p += f->name_length; len -= f->name_length; } else { if(len <= self.name_length) { break; } memcpy(p, self.name, self.name_length); p += self.name_length; len -= self.name_length; } } if(len <= 2) { break; } strcpy2(p, ": "); p += 2; len -= 2; } switch(msg->msg_type) { case MSG_TYPE_TEXT: case MSG_TYPE_ACTION_TEXT: { char_t *data; STRING_IDX length; if(i == m->data->istart) { if(i == m->data->iend) { data = msg->msg + m->data->start; length = m->data->end - m->data->start; } else { data = msg->msg + m->data->start; length = msg->length - m->data->start; } } else if(i == m->data->iend) { data = msg->msg; length = m->data->end; } else { data = msg->msg; length = msg->length; } if(len <= length) { goto BREAK; } memcpy(p, data, length); p += length; len -= length; break; } } i++; if(i != n) { #ifdef __WIN32__ if(len <= 2) { break; } *p++ = '\r'; *p++ = '\n'; len -= 2; #else if(len <= 1) { break; } *p++ = '\n'; len--; #endif } } BREAK: *p = 0; return (void*)p - buffer; }