int32_t commandlineAPI_registerCMD(tobServ_commandline *commandline, char *CMD, char *description, CMD_function cmdfunction, void *data) { tobServ_commandlineCMD *newcommand; uint32_t i=0; pthread_mutex_lock(&commandline->commandlist_mutex); //check if it exists already for(i=0;i< commandline->numCommands ;i++) { if(!strcmp(CMD, commandline->commands[i].name)) { pthread_mutex_unlock(&commandline->commandlist_mutex); return -1; } } commandline->numCommands++; commandline->commands = realloc(commandline->commands, sizeof(tobServ_commandlineCMD)*commandline->numCommands); //copy for easier accessibility newcommand = &commandline->commands[commandline->numCommands-1]; stringcpy(newcommand->name, CMD, sizeof(newcommand->name)); stringcpy(newcommand->description, description, sizeof(newcommand->description)); newcommand->function = cmdfunction; newcommand->data = data; pthread_mutex_unlock(&commandline->commandlist_mutex); return 0; }
void do_note(COMMAND_ARGS) { User *u; Note *n; Strp *sp,**np; char header[MSGLEN]; /* * no-args is handled in on_msg() */ if (!(u = find_handle(rest))) { to_user(from,TEXT_UNKNOWNUSER,rest); return; } to_user(from,"Enter your note for %s, end with \".\" on a line by itself", u->name); set_mallocdoer(do_note); n = Calloc(sizeof(Note) + StrlenX(from,to,u->name,NULL)); n->start = now; n->next = notelist; notelist = n; n->to = stringcat(n->from,from) + 1; n->user = stringcat(n->to,to) + 1; stringcpy(n->user,rest); /* * add a note header */ sprintf(header,"\001%s %s",from,time2str(now)); append_strp(&u->note,header); }
/** * This is the main method. */ int main() { char s1[MAXLEN]; char s2[] = "dawg"; stringcpy(s1, s2); printf("s1: %s\n", s1); return 0; }
int check_address(const char *addy) { char validuser[BIG_BUF]; /* Jump through hoops to build the regexp */ stringcpy(validuser, "^[^@( ){}<>[]+@[^@(){}<> .[]+\\.[^@( ){}<>[]+"); return match_reg(validuser, addy); }
/* =============================================================================== 函数 Full Path converts To Sector,SectorOffset,Cluster 入口:u8 *filename 出口:SUCC,FAIL(u32 *cluster_no,u32 *sector,u16 *offset) =============================================================================== */ static u8 FullPathToSectorCluster(u8 *filename1) { u8 buf[280]; u8 *filename; filename = buf; stringcpy(filename1,filename); UPCASE(filename); if( ((* filename) >= 'C' && ( * filename ) <= 'Z')|| ((* filename) >= 'c' && ( * filename ) <= 'z') ) //从指定盘符根目录开始寻址 { if(( * (filename + 1)) == ':') { if( *( filename + 2 ) == '\\') { if(LengthofString(filename) > Maximum_File_Path_Name) return(EpathLengthsOVERFLOW); if(Read_partition_PBP((u8)((*filename) - 'C')) != SUCC) return(FAIL); filename += 3; CORE.SectorNum = CORE.FirstRootDirSecNum; CORE.DirectoryType = RootDirectory; CORE.offset = 0; } } else { if((LengthofString(filename) + LengthofString(CORE.current_folder)) > Maximum_File_Path_Name) return(EpathLengthsOVERFLOW); if(CORE.CurrentDirectoryType == RootDirectory) { CORE.SectorNum = CORE.FirstRootDirSecNum; } else { CORE.ClusterNum = CORE.ClusterNOofCurrentFolder; CORE.SectorNum = FirstSectorofCluster(CORE.ClusterNum); } CORE.DirectoryType = CORE.CurrentDirectoryType; CORE.offset = 0; } } else if((* filename) == '\\') { if((LengthofString(filename) + 1) > Maximum_File_Path_Name) return(EpathLengthsOVERFLOW); filename ++; //从当前盘符,根目录开始寻址 CORE.SectorNum = CORE.FirstRootDirSecNum; CORE.DirectoryType = RootDirectory; CORE.offset = 0; } if(*filename) return(RelativePathToSectorCluster(filename)); else return(SUCC); }
int main() { char *sample = "MyString"; char buffer[64]; stringcpy(sample, buffer); printf("sample: %s\nbuffer: %s\n", sample, buffer); return 0; }
Shit *add_shit(char *from, char *chan, char *mask, char *reason, int axs, int expire) { Shit *shit; set_mallocdoer(add_shit); shit = (Shit*)Calloc(sizeof(Shit) + StrlenX(from,chan,mask,reason,NULL)); shit->action = axs; shit->time = now; shit->expire = expire; shit->next = current->shitlist; current->shitlist = shit; shit->chan = stringcpy(shit->mask,mask) + 1; shit->from = stringcpy(shit->chan,chan) + 1; shit->reason = stringcpy(shit->from,from) + 1; stringcpy(shit->reason,reason); current->ul_save++; return(shit); }
u8 FAT_filesystem_initialiation() { u8 root[] = "C:\\",i; Directory_Entry.filename[0] = 0; CORE.PartitionID = 0xff; CORE.CurrentDirectoryType = RootDirectory; stringcpy(root,CORE.current_folder); for (i = 0; i < MaximumFCB;i++) { FCB[i].file_openned_flag = UnusedFlag; //UsedFlag FCB[i].Modified_Flag = 0; } //read defalut partition BPB and related information to RAM buffer return(Read_partition_PBP(0)); }
char *GetPostVariable(header* headerstruct, char *name) { uint32_t i; char *result; for(i=0;i<headerstruct->numpostdata;i++) { if(!strcmp(headerstruct->postdata[i].name, name)) { result = malloc(strlen(headerstruct->postdata[i].value)+1); check_mem(result); stringcpy(result, headerstruct->postdata[i].value, strlen(headerstruct->postdata[i].value)+1); return result; } } log_warn("Variable %s was not found during a GetPostVariable call. Use IsPostVariableSet", name); error: //also executed if var not found return NULL; }
int main(int argc, const char *argv[]) { GDALAllRegister(); string modelPath = ""; int scenarioID = -1; /// By default, no BMPs Scenario is used, in case of lack of BMPs database. int i = 0; int numThread = 1; LayeringMethod layeringMethod = UP_DOWN; char mongodbIP[16]; stringcpy(mongodbIP,"127.0.0.1"); int port = 27017; if (argc < 2) { cout << "Error: To run the program, use either the Simple Usage option or Usage option as below." << endl; goto errexit; } else if (argc > 2) i = 1; else i = 2; while (argc > i) { if (isPathExists(argv[i])) { modelPath = argv[i]; i++; } else goto errexit; if (argc > i) { if (atoi(argv[i]) > 0) { numThread = atoi(argv[i]); i++; } else goto errexit; } if (argc > i) { if (atoi(argv[i]) == 0 || atoi(argv[i]) == 1) { if (atoi(argv[i]) == 0) layeringMethod = UP_DOWN; else layeringMethod = DOWN_UP; i++; } else goto errexit; } if (argc > i) { if (isIPAddress(argv[i])) { stringcpy(mongodbIP,argv[i]); i++; if (argc > i && atoi(argv[i]) > 0) { port = atoi(argv[i]); i++; } else goto errexit; } else goto errexit; } if (argc > i) { if (atoi(argv[i]) >= 0) { scenarioID = atoi(argv[i]); i++; } else goto errexit; } } if (argc == 2) modelPath = argv[1]; //cout<<modelPath<<endl; //cout<<numThread<<endl; //cout<<layeringMethod<<endl; //cout<<mongodbIP<<":"<<port<<endl; //cout<<scenarioID<<endl; //omp_set_num_threads(2); #ifdef MAIN while (modelPath.length() == 0) { cout << "Please input the model path:" << endl; cin >> modelPath; } #ifdef USE_MONGODB MainMongoDB(modelPath, mongodbIP, port, scenarioID, numThread, layeringMethod); #endif #endif #ifdef TEST // run the model //Run(strTmp); //testSettingInput(); //testBMP(); //testSettingOutput(); //testModule(); //testRaster(); #endif //system("pause"); return 0; errexit: cout << "Simple Usage:\n " << argv[0] << " <ModelPath>" << endl; cout << "\tBy default: " << endl; cout << "\t\tThe MongoDB IP is 127.0.0.1 (i.e., localhost), and the port is 27017." << endl; cout << "\t\tThe threads or processor number is 1." << endl; cout << "\t\tThe Layering Method is UP_DOWN." << endl; cout << "\t\tThe Scenario ID is 0" << endl << endl; cout << "Usage: " << argv[0] << "<ModelPath> [<threadsNum> <layeringMethod> <IP> <port> <ScenarioID>]" << endl; cout << "\t<ModelPath> is the path of the configuration of the Model." << endl; cout << "\t<threadsNum> must be greater or equal than 1." << endl; cout << "\t<layeringMethod> can be 0 and 1, which means UP_DOWN and DOWN_UP respectively." << endl; cout << "\t<IP> is the address of MongoDB database, and <port> is its port number." << endl; cout << "\t<ScenarioID> is the ID of BMPs Scenario which will be defined in BMPs database." << endl; exit(0); }
u8 folder_enumeration(u8 *return_string,u8 mode,u8 *ATTR) { u8 Extension[4]; u16 temp; if(mode == 0x0) { CORE.FullPathType = DirectoryPath; if(cd_folder(CORE.current_folder,0) != SUCC) return(FAIL); CORE.offset = 0; if(CORE.CurrentDirectoryType == RootDirectory) CORE.SectorNum = CORE.FirstRootDirSecNum; else { CORE.ClusterNum = CORE.ClusterNOofCurrentFolder; CORE.SectorNum = FirstSectorofCluster(CORE.ClusterNum); } CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum; //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset CORE.DIR_ENUM_SectorNum =CORE.SectorNum ; CORE.DIR_ENUM_offset = CORE.offset; CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry; //存放Directory Entry32字节中对应first Cluster Num CORE.DIR_ENUM_DirectoryType = CORE.DirectoryType; CORE.DIR_ENUM_FullPathType = CORE.FullPathType; CORE.DIR_ENUM_CurPathType = CORE.CurPathType; } CORE.ClusterNum = CORE.DIR_ENUM_ClusterNum; //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset CORE.SectorNum = CORE.DIR_ENUM_SectorNum; CORE.offset = CORE.DIR_ENUM_offset; CORE.ClusterOfDirectoryEntry = CORE.DIR_ENUM_ClusterOfDirectoryEntry; //存放Directory Entry32字节中对应first Cluster Num CORE.DirectoryType = CORE.DIR_ENUM_DirectoryType; CORE.FullPathType = CORE.DIR_ENUM_FullPathType; CORE.CurPathType = CORE.DIR_ENUM_CurPathType; stringcpy(CORE.current_folder,return_string); temp = LengthofString(return_string); if(return_string[temp-1] != '\\') { return_string[temp] = '\\'; return_string[temp+1] = 0; } if(GetEntryFromDirectory(return_string+LengthofString(return_string), Extension,Get_All_Entries) == SUCC) { temp = LengthofString(return_string); *ATTR = CORE.Entry_Attr; if(temp > 0 && (!((*ATTR) & ATTR_DIRECTORY))) { if(Extension[0] != 0) { return_string[temp] = '.'; return_string[temp+1] = 0; concanenateString(return_string,Extension); } } CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum; //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset CORE.DIR_ENUM_SectorNum =CORE.SectorNum ; CORE.DIR_ENUM_offset = CORE.offset; CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry; //存放Directory Entry32字节中对应first Cluster Num CORE.DIR_ENUM_DirectoryType = CORE.DirectoryType; CORE.DIR_ENUM_FullPathType = CORE.FullPathType; CORE.DIR_ENUM_CurPathType = CORE.CurPathType; return(SUCC); } return(FAIL); }
u8 cd_folder(u8 *foldername,u8 mode) { u16 offset; if(mode) //返回上一层目录 { if (CORE.CurrentDirectoryType == RootDirectory) return(0x55); else { CORE.FullPathType = DirectoryPath; if(FullPathToSectorCluster(CORE.current_folder) != SUCC) return(FAIL); offset = LengthofString(CORE.current_folder); offset --; do{ if(CORE.current_folder[offset] != '\\') CORE.current_folder[offset] = 0; else { if(CORE.current_folder[offset-1] == ':') break; CORE.current_folder[offset] = 0; break; } offset--; }while(1); if(LengthofString(CORE.current_folder) <= 3) CORE.CurrentDirectoryType = RootDirectory; else CORE.CurrentDirectoryType = NoneRootDirectory; return(SUCC); } } else //进入子目录 { CORE.FullPathType = DirectoryPath; if(FullPathToSectorCluster(foldername) == SUCC) { if(((* foldername) >= 'C' && ( * foldername ) <= 'Z') || ((* foldername) >= 'c' && ( * foldername ) <= 'z')) { if(* (foldername + 1) == ':' && * (foldername + 2 ) == '\\') { stringcpy(foldername,CORE.current_folder); } else { if(LengthofString(CORE.current_folder) != 3) { CORE.current_folder[LengthofString(CORE.current_folder)] = '\\'; CORE.current_folder[LengthofString(CORE.current_folder) + 1] = 0; } concanenateString(CORE.current_folder,foldername); } } else if(*foldername == '\\') { stringcpy(foldername,CORE.current_folder + 1); } if(LengthofString(CORE.current_folder) <= 3) { CORE.SectorNum = CORE.FirstRootDirSecNum; CORE.CurrentDirectoryType = RootDirectory; } else { CORE.CurrentDirectoryType = NoneRootDirectory; CORE.ClusterNum = CORE.ClusterOfDirectoryEntry; CORE.ClusterNOofCurrentFolder = CORE.ClusterOfDirectoryEntry; CORE.SectorNum = FirstSectorofCluster(CORE.ClusterNum); } CORE.offset = 0; return(SUCC); } } return(FAIL); }
/* =============================================================================== 函数 从目录读一个EntryWithLongFileName 入口: 出口:SUCC,FAIL =============================================================================== */ static u8 GetEntryWithLongFileName(u8 *buf,u8* longFileName,u8 *Extension) { u8 j,FileNameOffset; u8 flag,k,i; u16 len; struct LongNameDirectoryEntry *LongNameDirectoryEntry_Local; *Extension = 0; FileNameOffset = 242; LongNameDirectoryEntry_Local = (struct LongNameDirectoryEntry *) (buf + CORE.offset); do{ //flag = FILE_NAME; k = FileNameOffset; for(j = 1;j < 10;j+=2) { if (LongNameDirectoryEntry_Local->dir_lname1[j] == 0) break; longFileName[k] = LongNameDirectoryEntry_Local->dir_lname1[j]; k ++; } longFileName[k] = 0; if(j >= 10) { for(j = 0;j < 12;j += 2) { if (LongNameDirectoryEntry_Local->dir_lname2[j] == 0) break; longFileName[k] = LongNameDirectoryEntry_Local->dir_lname2[j]; k++; } if(j >= 12) for(j = 0;j < 4;j += 2) { if (LongNameDirectoryEntry_Local->dir_lname3[j] == 0) break; longFileName[k] = LongNameDirectoryEntry_Local->dir_lname3[j]; k ++; } } if(k > 242) longFileName[k] = 0; CORE.PreEntrySectorNum = CORE.SectorNum; CORE.PreEntryoffset = CORE.offset; if(CORE_offset_add_32(buf) == FAIL) //Directory Entry offset + 32 return(FAIL); FileNameOffset -= 13; k = FileNameOffset; LongNameDirectoryEntry_Local = (struct LongNameDirectoryEntry *) (buf + CORE.offset); if(LongNameDirectoryEntry_Local->dir_attr != ATTR_LONG_NAME) { if ( ! (LongNameDirectoryEntry_Local->dir_attr & ATTR_VOLUME_ID)) { CORE.ClusterOfDirectoryEntry = LongNameDirectoryEntry_Local->dir_first[0]+ LongNameDirectoryEntry_Local->dir_first[1] * 256; CORE.FileSize = *((u32*)LongNameDirectoryEntry_Local->dir_lname3); stringcpy(longFileName+FileNameOffset+13,longFileName); len = LengthofString(longFileName); len --; i = 0; do{ if(longFileName[len] == '.') { longFileName[len] = 0; stringcpy(longFileName + len + 1,Extension); break; } len--; i++; if(i >= 4 ) break; }while(1); break; } flag = FILE_NAME; FileNameOffset = 256 - 13; k = FileNameOffset; do{ CORE.PreEntrySectorNum = CORE.SectorNum; CORE.PreEntryoffset = CORE.offset; if(CORE_offset_add_32(buf) == FAIL) //Directory Entry offset + 32 return(FAIL); LongNameDirectoryEntry_Local = (struct LongNameDirectoryEntry *) (buf + CORE.offset); if(LongNameDirectoryEntry_Local->dir_lname1[0] == 0xe5) continue; if(LongNameDirectoryEntry_Local->dir_attr != ATTR_LONG_NAME) { if ( ! (LongNameDirectoryEntry_Local->dir_attr & ATTR_VOLUME_ID)) return(GetEntryWith8_3Name(buf,longFileName,Extension)); else continue; } else break; } while(1); } }while(1); return(SUCC); }
int main() { struct timeval t1,t2; int count, data[22] = { 1, 2, 3, -3, -99, 999, 42, 14, 56, 76, 99, 12, -2345, 3456789, 199, 123, 234, -567, -999, 21, 32, -12345}; int z,i; i=0; long long timeleaf, timenorm, difference; void lstringcpy(char *dst, char *src); void stringcpy(char *dst, char *src); void lstringcat(char *dst, char *src); void stringcat(char *dst, char *src); void lreversestr(char *st); void reversestr(char *st); void lstringucase(char *st); void stringucase(char *st); void lstringlcase(char *st); void stringlcase(char *st); int lstringcmp(char *str1, char *str2); int stringcmp(char *str1, char *str2); int lcntofevens(int *list, int n); int cntofevens(int *list, int n); int lfindlargest(int *list, int n); int findlargest(int *list, int n); int lcntlessthanx(int *list, int n, int x); int cntlessthanx(int *list, int n, int x); int lcntofmultiplesof8(int *list, int n); int cntofmultiplesof8(int *list, int n); timeleaf = 0; timenorm = 0; while(i<100000){ char astr[64] = "A long long string is here!!"; char astr2[64]= "A long long string is here!!"; char *str = "True"; char *str2= "True"; char s[4]="Tru"; char s2[4]="Tru"; char *t="e"; char *st2="e"; char backwards[15]="eurT"; char backwards2[15]="eurT"; /* start timer for leaf */ gettimeofday(&t1,NULL); lstringcpy(astr, str); lstringcat(s,t); lreversestr(backwards); lstringucase(s); lstringlcase(s); z = lstringcmp(s,str); count = lcntofevens(data, 22); count = lfindlargest(data, 22); count = lcntlessthanx(data,22,0); count = lcntofmultiplesof8(data,22); gettimeofday(&t2,NULL); /* end timer for leaf */ timeleaf+=t2.tv_usec-t1.tv_usec; /* start timer for normal */ gettimeofday(&t1,NULL); stringcpy(astr2, str2); stringcat(s2,st2); reversestr(backwards2); stringucase(s2); stringlcase(s2); z = stringcmp(s2,str2); count = cntofevens(data, 22); count = findlargest(data, 22); count = cntlessthanx(data,22,0); count = cntofmultiplesof8(data,22); gettimeofday(&t2,NULL); /* end timer for normal */ timenorm+=t2.tv_usec-t1.tv_usec; difference=timenorm-timeleaf; i++; } printf("leaf time: %lld\nnormal time: %lld\ndifference: %lld\n",timeleaf,timenorm,difference); exit(0); }
/* help:CPUINFO:(no arguments) See also: hostinfo, meminfo */ void do_cpuinfo(COMMAND_ARGS) { char bogostr[64],cpustr[64]; char *a1,*a2,*a3,*dst; int fd,n; #ifdef DEVELOPING a1 = chop(&rest); if (a1) sprintf(bogostr,"/home/git/cpuinfo/%s",a1); else stringcpy(bogostr,"/proc/cpuinfo"); if ((fd = open(bogostr,O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips3",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips2",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/mips1",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/intel1",O_RDONLY)) < 0) // if ((fd = open("/home/git/cpuinfo/cosmiccow",O_RDONLY)) < 0) #endif if ((fd = open("/proc/cpuinfo",O_RDONLY)) < 0) #ifdef DEBUG { debug("(do_cpuinfo) /proc/cpuinfo: %s\n",strerror(errno)); return; } #else return; #endif global_from = from; havemodel = bogo = siblings = procct = cpus = cores = physid = 0; omni[1] = 0; readline(fd,&parse_proc_cpuinfo); // readline closes fd if ((fd = open("/proc/loadavg",O_RDONLY)) < 0) #ifdef DEBUG { debug("(do_cpuinfo) /proc/loadavg: %s\n",strerror(errno)); return; } #else return; #endif n = read(fd,globaldata,MSGLEN-2); globaldata[n] = 0; close(fd); rest = globaldata; a1 = chop(&rest); a2 = chop(&rest); a3 = chop(&rest); if (!a3 || !*a3) return; #ifdef DEBUG debug("(do_cpuinfo) procct %i, physid %i, cores %i, bogo %i\n",procct,physid,cores,bogo); #endif if (cores == 0) cores = bogo; if (cores && physid && (physid % cores) == 0) cpus = (physid / cores)-1; if (cores && (cpus == 0 || physid == cores)) cpus = 1; *bogostr = 0; *cpustr = 0; if (bogo) sprintf(bogostr,", %s BogoMips",vmlib); if (cpus > 1 || (cores > cpus)) { sprintf(cpustr,", %i physical cpu%s",cpus,(cpus == 1) ? "" : "s"); if (cores) sprintf(STREND(cpustr),", %i core%s",cores,(cores == 1) ? "" : "s"); } to_user_q(from,"%s%s%s, loadavg: %s(1m) %s(5m) %s(15m)", omni+1,bogostr,cpustr,a1,a2,a3); }