int main(int argc, char **argv) { int i, fd; if (argc <= 1) { if (dumpfile(STDIN_FILENO)) goto error_read; } else { for (i = 1; i < argc; i++) { errno = 0; fd = open(argv[i], O_RDONLY); if (fd == -1) { goto error_read; } else { if (dumpfile(fd)) goto error_read; close(fd); } } } exit(0); error_read: fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno)); close(fd); exit(1); }
int main(int argc, char **argv) { char readbuf; char writefilename[32] = {0}; int fd, i, intervalsize; int null_count = 0; int block_num = 0; int block_info[20][2] = {{0},{0}}; intervalsize = DEFAULT_INTERVAL_SIZE; if (argc == 3) intervalsize = atoi(argv[2]); fd = open(argv[1], O_RDONLY); if (fd<0) { printf("can't open %s\n", argv[1]); return -1; } /* skip first 4K */ block_num++; lseek(fd, 4096, SEEK_CUR); block_info[block_num][0]= 4096; dumpfile(argv[1], "b0", 0, 4096); while (read(fd, &readbuf, 1) == 1) { if (readbuf == 0) { null_count++; } else { if (null_count > intervalsize) { block_info[block_num][1] = null_count; block_num++; block_info[block_num][0] = lseek(fd, 0, SEEK_CUR)-1; sprintf(writefilename, "b%d", block_num-1); dumpfile(argv[1], writefilename, block_info[block_num-1][0], block_info[block_num][0]-block_info[block_num-1][0]-null_count); } null_count = 0; } } block_info[block_num+1][0] = lseek(fd, 0, SEEK_END); printf("No.\t\toff\t\tblocksize\tintervalsize\n"); for (i=0; i <= block_num; i++) printf("%d\t0x%08x-0x%08x\t%8d\t%8d\n", i, block_info[i][0], block_info[i+1][0] - 1, block_info[i+1][0] - block_info[i][0], block_info[i][1]); return 0; }
main (int argc, char *argv[]) { int fd,i,k; char passwd[18]; char dpasswd[9]; if (argc < 2) { printf("razor passwd to decrypt :"); fgets(passwd, 17, stdin); passwd[strlen(passwd)-1] = 0; k=0; for (i=0 ; i<9 ; dpasswd[i++]=0); for (i=(strlen(passwd)-1) ; i>=0 ; i--) { if (k & 1) { dpasswd[i/2] |= ((ASCII2BIN(passwd[i]) << 4) & 0xf0); } else { dpasswd[i/2] = ASCII2BIN(passwd[i]) & 0x0f; } k++; } for (i=0 ; i<strlen(dpasswd) ; i++) ROT8L(dpasswd[i], 2); printf("%s\n", dpasswd); exit(0); } fd = open (argv[1], O_RDONLY); if (fd < 0) { /* assume arg is a passwd to encrypt */ for ( i=0 ; i<strlen(argv[1]) ; i++) printf("%02X", (unsigned char)ROT8R(argv[1][i], 2) ); printf("\n"); } else { /* dump file */ dumpfile(fd); } exit(0); }
String* startcmd(void) { int n; char *filename; char **av; Link *l; String *cmd; /* * ignore the filterstate if the all the receivers prefer it. */ filterstate = optoutall(filterstate); switch (filterstate){ case BLOCKED: case DELAY: rejectcount++; logmsg("Blocked"); filename = dumpfile(s_to_c(senders.last->p)); cmd = s_new(); s_append(cmd, "cat > "); s_append(cmd, filename); pp = proc_start(s_to_c(cmd), instream(), 0, outstream(), 0, 0); break; case DIALUP: logmsg("Dialup"); rejectcount++; reply("554 5.7.1 We don't accept mail from dial-up ports.\r\n"); /* * we could exit here, because we're never going to accept mail * from this ip address, but it's unclear that RFC821 allows * that. Instead we set the hardreject flag and go stupid. */ hardreject = 1; return 0; case DENIED: logmsg("Denied"); rejectcount++; reply("554-5.7.1 We don't accept mail from %s.\r\n", s_to_c(senders.last->p)); reply("554 5.7.1 Contact postmaster@%s for more information.\r\n", dom); return 0; case REFUSED: logmsg("Refused"); rejectcount++; reply("554 5.7.1 Sender domain must exist: %s\r\n", s_to_c(senders.last->p)); return 0; default: case NONE: logmsg("Confused"); rejectcount++; reply("554-5.7.0 We have had an internal mailer error " "classifying your message.\r\n"); reply("554-5.7.0 Filterstate is %d\r\n", filterstate); reply("554 5.7.0 Contact postmaster@%s for more information.\r\n", dom); return 0; case ACCEPT: /* * now that all other filters have been passed, * do grey-list processing. */ if(gflag) vfysenderhostok(); /* fall through */ case TRUSTED: /* * set up mail command */ cmd = s_clone(mailer); n = 3; for(l = rcvers.first; l; l = l->next) n++; av = malloc(n * sizeof(char*)); if(av == nil){ reply("450 4.3.2 We're busy right now, try later\r\n"); s_free(cmd); return 0; } n = 0; av[n++] = s_to_c(cmd); av[n++] = "-r"; for(l = rcvers.first; l; l = l->next) av[n++] = s_to_c(l->p); av[n] = 0; /* * start mail process */ pp = noshell_proc_start(av, instream(), outstream(), outstream(), 0, 0); free(av); break; } if(pp == 0) { reply("450 4.3.2 We're busy right now, try later\r\n"); s_free(cmd); return 0; } return cmd; }
int main(int argc, char **argv) { int ch, version = 0; extern char build_info[]; int errors = 0; while ((ch = getopt(argc, argv, "C:dimvHc")) != -1) switch(ch) { case 'd': detail++; break; case 'i': ignorev1++; break; case 'm': dumpmap++; detail = 0; break; case 'C': chkpointdev = optarg; break; case 'v': version++; break; case 'c': checksums++; break; case 'h': case '?': default: usage(); } argc -= optind; argv += optind; if (version || detail) { fprintf(stderr, "%s\n", build_info); if (version) exit(0); } if (argc < 1) usage(); for (; argc > 0; argc--, argv++) { int isstdin = !strcmp(argv[0], "-"); if (!isstdin) { if ((infd = open(argv[0], O_RDONLY, 0666)) < 0) { perror(argv[0]); continue; } } else infd = fileno(stdin); #ifdef WITH_CRYPTO #ifdef SIGN_CHECKSUM if (checksums > 0) { char *keyfile = checksum_keyfile(argv[0]); if (!init_checksum(keyfile)) { fprintf(stderr, "%s: Cannot validate checksum signing key\n", argv[0]); continue; } } #endif #endif errors = dumpfile(isstdin ? "<stdin>" : argv[0], infd); #ifdef WITH_CRYPTO #ifdef SIGN_CHECKSUM if (checksums > 0) cleanup_checksum(); #endif #endif if (!isstdin) close(infd); } exit(errors); }
int CSVParser::loadTrainingCSV(string filename, vector<vector<double> > &dataTable, vector<bool> &truthTable){ ifstream inFile; string lineBuffer; double val = 0; dataTable.reserve(1000); //reserve 1000 slots truthTable.reserve(1000); inFile.open(filename.c_str()); if (inFile.fail()){ perror(filename.c_str()); return 1; } while (getline(inFile, lineBuffer)){ dataTable.push_back(vector <double>()); dataTable.back().reserve(320); //reserve all 320 slots so we dont reallocate int prev = 0; for (int i = 0; i < lineBuffer.size(); i++){ if ((int)lineBuffer[i] < 0){ //discard the UTF-8 Bom at the beginning of the file ( I think its bytes are always neg ) prev = i+1; continue; } if (lineBuffer[i] == ','){ lineBuffer[i] = '\0'; // so sscanf works if (sscanf(&(lineBuffer[prev]), "%lf", &val) < 1){ cerr << "sscanf failed\n"; } if (val > 1){ val = val / 900000.0 + 1.0; } dataTable.back().push_back(val); prev = i+1; } } if (strcmp(&(lineBuffer[prev]), "true") == 0){ truthTable.push_back(1); }else if (strcmp(&(lineBuffer[prev]), "false") == 0){ truthTable.push_back(0); } } PreprocessData(dataTable); ofstream dumpfile("pretest.txt"); for (int i = 0; i < dataTable.size(); i++){ dumpfile << i << " "; for (int j = 0; j < dataTable[i].size(); j++){ dumpfile << dataTable[i][j] << " "; } dumpfile << "\n"; } dumpfile.close(); inFile.close(); return 0; }
int main(int argc, char **argv) { int opt, age, quiet; char topdir[PATH_MAX]; char aunit = 'Y'; struct stat sb; char *datestr; char command[PATH_MAX]; char **workfile; // set up defaults quiet = 0; age = 3; strcpy(topdir, getenv("HOME")); head = newlistitem(); opfn = (char *)NULL; oldcount = 0; workfile = workfiles("/tmp/", argv[0], 4); fpo=dofopen(workfile[0], "w"); while((opt = getopt(argc, argv, ":ha:o:q")) != -1) { switch(opt){ /* I have no idea what the value of topdir will be during * options processing so all I can do is set a task variable * to select action after topdir is known or whether it's * actually needed. */ case 'h': dohelp(0); break; case 'a': // change default age age = strtol(optarg, NULL, 10); if (strchr(optarg, 'M')) aunit = 'M'; if (strchr(optarg, 'm')) aunit = 'M'; if (strchr(optarg, 'D')) aunit = 'D'; if (strchr(optarg, 'd')) aunit = 'D'; break; case 'q': quiet = 1; break; case 'o': // list files older than input file time datestr = strdup(optarg); fileage = parsetimestring(datestr); break; case ':': fprintf(stderr, "Option %c requires an argument\n",optopt); dohelp(1); break; case '?': fprintf(stderr, "Illegal option: %c\n",optopt); dohelp(1); break; } //switch() }//while() // now process the non-option arguments // 1.See if argv[1] exists. if ((argv[optind])) { strcpy(topdir, argv[optind]); // default is /home/$USER } // Check that the top dir is legitimate. if (stat(topdir, &sb) == -1) { perror(topdir); exit(EXIT_FAILURE); } // It exists then, but is it a dir? if (!(S_ISDIR(sb.st_mode))) { fprintf(stderr, "%s is not a directory!\n", topdir); exit(EXIT_FAILURE); } // Convert relative path to absolute if needed. if (topdir[0] != '/') dorealpath(argv[optind], topdir); fileage = cutofftimebyage(age, aunit); recursedir(topdir); fclose(fpo); if (oldcount > 0) { sprintf(command, "sort -u %s > %s", workfile[0], workfile[1]); dosystem(command); } else { if (!quiet) { fprintf(stderr, "No old files found\n"); } unlink(workfile[0]); exit(EXIT_SUCCESS); } // get rid of the leading inode and sort on pathname stripinode(workfile[1], workfile[2]); sprintf(command, "sort %s > %s", workfile[2], workfile[3]); dosystem(command); dumpfile(workfile[3], stdout); return 0; }//main()