static int visit_bbs(int m) { time_t aika; char *aikas; char puskur[300]; lrp = lsp = oldlrp = oldlsp = 0; lrpdatname[0] = 0; ffilestagged = filestagged = bytestagged = fbytestagged = 0; *reason = 0; memset(&clog, 0, sizeof(struct callerslog)); memset(&user, 0, sizeof(struct userbase)); onlinestat = 0; display = 0; clearlist(olms); clearlist(flaggedfiles); carrier = 1; aika = time(0); aikas = ctime(&aika); aikas[24] = 0; snprintf(puskur, sizeof puskur, "===============================================[ %s ]===\n%d BPS connection on line #%d\n\n", aikas, bpsrate, node); writelog(puskur); changenodestatus("Logging in..."); ddprintf("[0m[2J[HDayDream BBS/UNiX %s\nProgramming by Antti Häyrynen 1996, 1997,\n DayDream Development Team 1998, 1999, 2000, 2001, 2002, 2003, 2004,\n Bo Simonsen 2008, 2009, 2010\nCurrently maintained by Ryan Fantus\nYou are connected to node #%d at %d BPS.\n\n", versionstring, node, bpsrate); rundoorbatch("data/frontends.dat", NULL); if (!display) if (getdisplaymode(0, 0) < 1) { DDPut("Failed to load displaymode... disconnecting!\n\n"); return 0; } if (!syspw()) { DDPut(sd[disconnectingstr]); return 0; } TypeFile("banner", TYPE_MAKE | TYPE_WARN); if (m) { switch (checklogon("sysop")) { case 1: sleep(2); getin(); break; } return 1; } login_loop(); DDPut(sd[disconnectingstr]); dropcarrier(); return 1; }
/* Steps in program: determine the number of iterations of desired * function required to get a measurement interval of the desired * length, allocate vectors of that size, initialize to appropriate * values for both the related and random scenarios, make the runs, * output the results. */ main() { int i,itercount; unsigned ccount; /* The next two lines are just a sanity check -- particularly useful when trying on a new platform. Can comment out when doing repeated runs thereafter. */ /* display_CPUspeed(); printf("Cycle threshold for measurements: %.2f (millions)\n\n", (double) CMIN / 1e6); */ itercount = measurecnt(); printf("Measuring using %d iterations\n",itercount); /* allocate arrays for both scenarios */ allocarrays(itercount); /* initialize arrays for scenario 1: valA[i] < valB[i] */ initarrays1(itercount); /* do multiple runs for this scenario, recording each */ clearlist(); for (i = 0; i < MEASMAX; i++) { ccount = measure(itercount); addtolist(ccount); } /* test and output best */ printf("Cycles per function call, predictable branches\n"); testbest(); /* initialize arrays for scenario 2: valA[i] ? valB[i] */ initarrays2(itercount); /* do multiple runs for this scenario, recording each */ clearlist(); for (i = 0; i < MEASMAX; i++) { ccount = measure(itercount); addtolist(ccount); } /* test and output best */ printf("Cycles per function call, unpredictable branches\n"); testbest(); }
/* driver for everything: for current vector and operation types, * run through entire range of vector lengths, making repeated * measurements of each, then determine slope of line that best * matches data, and finally output results as CPE. */ main() { int i,j; unsigned ccount; /* The next two lines are just a sanity check -- particularly useful when trying on a new platform. Can comment out when doing repeated runs thereafter. */ /* display_CPUspeed(); printf("Cycle threshold for measurements: %.2f (millions)\n\n", (double) CMIN / 1e6); */ clearmaster(); initvlen(); for (i = 2; i <= VECMAX; i = i << 1) { /* printf("Vector length: %d\n",i); for debugging */ setupvectors(i); clearlist(); /* do multiple runs for this vector length, recording each */ for (j = 0; j < MEASMAX; j++) { ccount = measure(); addtolist(ccount); } testbest(); addtomaster(); /* record best time in master list */ } /* dumpmaster(); for debugging */ lsfit(); /* do linear fit */ }
// aqui libera ela totalmente da memoria void freelist(LIST* L){ if (L != NULL){ clearlist(L); free(L); } }
void main() {sqlist L; int i,j,k,b,n,e,m,a,cur_e,pre_e,next_e,s; initlist(L); cout<<"初始化后的基值地址:"<<L.elem<<" L.length=:"<<L.length<<" L.listsize=:"<<L.listsize<<endl; cout<<"新建一顺序表."<<endl; cout<<"当前表是否为空表"<<listempty(L)<<endl; cout<<"定义该线性表长度:"<<endl; cin>>a; cout<<"分别输入线性表的各个元素,按ENTER"<<endl; for(k=1;k<=a;k++){ cin>>j; i=listinsert(L,k,j);} for(b=1;b<=a;b++) cout<<L.elem[b-1]<<endl; listlength(L); cout<<"当前表长:"<<L.length<<endl; cout<<"输入要取的数的位置n(n<=a)"<<endl; cin>>n; getelem(L,n,e); //cout<<L.elem[n-1]<<endl; cout<<e<<endl; cout<<"与该数相等的的一个数的位序为:"<<locateelem(L,e,compare)<<endl; cout<<"输入要取前驱的数的位置m(<=a)"<<endl; cin>>m; getelem(L,m,cur_e); if(priorelem(L,cur_e,pre_e)) cout<<"cur_e的前驱为:"<<pre_e<<endl; else cout<<"该元素没前驱"<<endl; nextelem(L,cur_e,next_e); if(nextelem(L,cur_e,next_e)) cout<<"cur_e的后继为:"<<next_e<<endl; else cout<<"该元素没后继"<<endl; cout<<"奇数在前,偶数在后,并输出"<<endl; move(L); for(s=1;s<=a;s++) cout<<L.elem[s-1]<<endl; cout<<"输入要删元素的位序m(<=a)"<<endl; cin>>m; listdelete(L,m,e); cout<<"被删的元素为:"<<e<<endl; cout<<"删除元素后表长为"<<L.length<<endl; //listtraverse(L,visit); cout<<"置为空表"<<clearlist(L)<<endl; cout<<"销毁线性表"<<destroylist(L)<<endl; }
int main (){ char string[MAX]; /// variavel que sera utilizada para ler a frase unsigned i, j, k,m, size; // variaveis para loops e size para pegar o tamanha do string corretamente. LIST* l = listcreate(); // inciia uma nova lista // lendo o texto ate o fim do arquivo while (scanf("%s", string) != EOF){ size = (unsigned int) strlen(string); // seta o tamanho da string m = 0; // se houver mais de um '[' j = 0; // end = 0 home = 1 k = 0; // contador de posições de uma palavra dentro de um [exemplo] for (i = 0; i < size; i++){ if (string[i] == '[') { j = 1; k = 0; } if (string[i] == ']') j = 0; if (string[i] == '[' && qtlist(l) == 0) j = 0; if (string[i] != '[' && string[i] != ']'){ if (j == 1 && qtlist(l) != 0){ if (k == 0) insertinit(l, string[i]); else insertmeans(l, k, string[i]); k++; }else{ // j = 0 logo "end" insertfinal(l, string[i]); } } } printlist(l); printf("\n"); clearlist(l); } freelist(l); return 0; }
void TFileList::scandir () { char olddir[256]; DIR *d; clearlist (); my_getcwd (olddir, 255); chdir (path); d = opendir (path); if (d) { struct dirent *ent; rewinddir (d); while ((ent=readdir(d))!=NULL) if (passFilt (ent->d_name)) additem (ent->d_name); closedir (d); } chdir (olddir); }
int handleclient(int conn) { char *basedir; char *clientdir; mp3entry *mp3buf; FILE *stream; if ((stream = fdopen(conn, "r+")) == NULL || !readrequest(stream)) { debug(1, "error while reading client request"); fclose(stream); return(EXIT_FAILURE); } debug(1, "requested path %s", conf.path); GETCWD(basedir); if(chdir(conf.path)) die("incorrect dir"); GETCWD(clientdir); debug(1, "doing security checks"); if(strncmp(basedir, clientdir, strlen(basedir) - 1)) { fclose(stream); debug(1, "basedir %s, clientdir %s", basedir, clientdir); die("client tried to break out of base directory"); } debug(1, "looking for mp3 files in subdirectory %s", conf.path); if(!MODE_ISSET(MODE_SINGLE)) { getfiles("."); } else if(validfile(conf.filename, clientdir, &mp3buf)) { addentry(&root, mp3buf); } if(!root) die("no files"); else debug(1, "%d MP3 file(s) found", countentries(root)); if(!MODE_ISSET(MODE_INDEX) && !conf.order) { debug(1, "shuffling mp3 files"); shuffleentries(); } if(conf.debuglevel > 2) { debug(1, "listing mp3 files"); dumpentries(); } if(MODE_ISSET(MODE_INDEX)) { debug(1, "entering HTTP mode"); fprintf(stream, HTTPSERVMSG, AMPLE_VERSION); fflush(stream); createhtml(stream,(clientdir + strlen(basedir)),(strlen(clientdir) + 1)); } else if(MODE_ISSET(MODE_SINGLE)) { debug(1, "entering MP3-Single mode"); fprintf(stream, SINGLESERVMSG, AMPLE_VERSION, root->filesize); fflush(stream); playfile(stream, root); } else if (MODE_ISSET(MODE_METADATA)) { debug(1, "entering MP3-Metadata mode"); fprintf(stream, SHOUTSERVMSG, AMPLE_VERSION, conf.servername, BYTESBETWEENMETA); fflush(stream); playlist(stream); } else { debug(1, "entering MP3-Basic mode"); fprintf(stream, BASICSERVMSG, AMPLE_VERSION); fflush(stream); playlist(stream); } fclose(stream); clearlist(root); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { extern char *optarg; extern int optind; TAG *searchlist; glob_t pg; size_t len; int ch, f_cat, f_how, found; const char *pager, *p_path; char **ap, *cmd, *machine, *p, *p_add, *sflag; char *conffile; if (argv[1] == NULL && strcmp(basename(__progname), "help") == 0) { static char *nargv[3]; nargv[0] = "man"; nargv[1] = "help"; nargv[2] = NULL; argv = nargv; argc = 2; } machine = sflag = NULL; f_cat = f_how = 0; conffile = p_add = NULL; p_path = (const char *)NULL; while ((ch = getopt(argc, argv, "aC:cfhkM:m:P:s:S:w-")) != -1) switch (ch) { case 'a': f_all = 1; break; case 'C': conffile = optarg; break; case 'c': case '-': /* Deprecated. */ f_cat = 1; break; case 'h': f_how = 1; break; case 'm': p_add = optarg; break; case 'M': case 'P': /* Backward compatibility. */ p_path = optarg; break; case 's': /* SVR4 compatibility. */ sflag = optarg; break; case 'S': machine = optarg; break; /* * The -f and -k options are backward compatible * ways of calling whatis(1) and apropos(1). */ case 'f': jump(argv, "-f", "whatis"); /* NOTREACHED */ case 'k': jump(argv, "-k", "apropos"); /* NOTREACHED */ case 'w': f_where = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; if (!*argv) usage(); if (!f_cat && !f_how && !f_where) { if (!isatty(1)) f_cat = 1; else { pager = getenv("MANPAGER"); if (pager == NULL || *pager == '\0') pager = getenv("PAGER"); if (pager == NULL || *pager == '\0') pager = _PATH_PAGER; } } /* Read the configuration file. */ config(conffile); /* * 1: If the user specified a section, * use the section list from the configuration file. * Otherwise, fall back to the default list or to an empty list. */ if (sflag && (section = getlist(sflag)) == NULL) errx(1, "unknown manual section `%s'", sflag); else if (argv[1] && (section = getlist(*argv)) != NULL) ++argv; searchlist = section; if (searchlist == NULL) searchlist = getlist("_default"); if (searchlist == NULL) searchlist = addlist("_default"); /* * 2: If the user set the -M option or defined the MANPATH variable, * clear what we have and take the user's list instead. */ if (p_path == NULL) p_path = getenv("MANPATH"); if (p_path) { clearlist(searchlist); parse_path(searchlist, p_path); } /* * 3: If the user set the -m option, insert the user's list before * whatever list we have. */ if (p_add) parse_path(searchlist, p_add); /* * 4: Append the _subdir list where appropriate, * and always append the machine type. */ if (machine || (machine = getenv("MACHINE"))) { /* Avoid mangling argv/environment. */ if ((machine = strdup(machine)) == NULL) err(1, NULL); for (p = machine; *p; ++p) *p = tolower(*p); } else machine = MACHINE; append_subdirs(searchlist, machine); /* * 5: Search for the files. Set up an interrupt handler, so the * temporary files go away. */ (void)signal(SIGINT, onsig); (void)signal(SIGHUP, onsig); sigemptyset(&blocksigs); sigaddset(&blocksigs, SIGINT); sigaddset(&blocksigs, SIGHUP); memset(&pg, 0, sizeof(pg)); for (found = 0; *argv; ++argv) if (manual(*argv, searchlist, &pg)) found = 1; /* 6: If nothing found, we're done. */ if (!found) { (void)cleanup(0); exit (1); } /* 7: If it's simple, display it fast. */ if (f_cat) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { if (**ap == '\0') continue; cat(*ap); } exit (cleanup(0)); } if (f_how) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { if (**ap == '\0') continue; how(*ap); } exit(cleanup(0)); } if (f_where) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { if (**ap == '\0') continue; (void)puts(*ap); } exit(cleanup(0)); } /* * 8: We display things in a single command; build a list of things * to display. */ for (ap = pg.gl_pathv, len = strlen(pager) + 1; *ap != NULL; ++ap) { if (**ap == '\0') continue; len += strlen(*ap) + 1; } if ((cmd = malloc(len)) == NULL) { warn(NULL); (void)cleanup(0); exit(1); } p = cmd; len = strlen(pager); memcpy(p, pager, len); p += len; *p++ = ' '; for (ap = pg.gl_pathv; *ap != NULL; ++ap) { if (**ap == '\0') continue; len = strlen(*ap); memcpy(p, *ap, len); p += len; *p++ = ' '; } *--p = '\0'; /* Use system(3) in case someone's pager is "pager arg1 arg2". */ (void)system(cmd); exit(cleanup(0)); }
//生成变量的存储空间,并置所有字节为0 void generateVars() { idheap=(char*)malloc(size); memset(idheap,0,size); clearlist(); }