int main() { // ex15.6 Quote q("textbook", 10.60); Bulk_quote bq("textbook", 10.60, 10, 0.3); print_total(std::cout, q, 12); print_total(std::cout, bq, 12); return 0; }
int main() { Quote q("text", 10.60); Bulk_quote bq("text", 10.60, 10, 0.3); Limit_quote lq("text", 10.60, 20, 0.3); print_total(std::cout, q, 12); print_total(std::cout, bq, 12); print_total(std::cout, lq, 21); return 0; }
void ls_l(char *arg) { t_file file; t_file **tab; t_llu llu; llu.total = 0; if (!(fill_tab(&tab, arg, &llu))) return ; sort_tab(&tab, &llu); if (!g_d) print_total(&llu); printfilelist(tab, llu.size, arg); llu.i = 0; while (llu.i < llu.size) { file = *((t_file *)tab[llu.i]); if (g_re && S_ISDIR(file.stats.st_mode) && ft_strcmp(file.name, ".") && ft_strcmp(file.name, "..")) llu.total = 0, ft_putchar('\n'), ft_putstr(ft_burger(arg, '/', file.name)), ft_putendl(":"), ls_l(ft_burger(arg, '/', file.name)); llu.i++; } free_ls(tab, &llu); }
int main(void) { item_base item; Bulk_item derived; print_total(std::cout, item, 10); print_total(std::cout, derived, 10); item_base* p = &item; Bulk_item bulk; item_base* baseP = &derived; double d = baseP->item_base::net_price(42); return 0; }
void print_recursive(char **files, char *flags, char *folder, int i) { char **path; struct stat *file_stat; int boolean; if (!files || !files[0] || !ft_strlen(files[0])) return ; boolean = 0; if (!(path = malloc(sizeof(char*) * ALL_RECURSIVE_POSSIBILITY))) return ; path = ft_set_null(path); print_total(files, flags, folder); while (files[i]) { if (!(file_stat = get_file_stat(files[i], file_stat, folder))) return ; print_by_flags(file_stat, flags, files, i); if (S_ISDIR(file_stat->st_mode) && files[i][0] != '.' && (boolean += 1)) path = new_dir(path, files[i]); free(file_stat); i++; } ft_putstr("\n"); free_files(files); (boolean) ? recursive_if(path, folder, flags) : free_files(path); }
void print_long(OBJ *obj) { struct stat *st; FTSENT *p; char mode[MODE_BUFF_SIZE]; p = obj->obj_list; if(!obj->obj_isroot) print_total(obj->obj_size_total); while (p != NULL) { if (p->fts_number == FTS_NO_PRINT) { p = p->fts_link; continue; } st = p->fts_statp; /* print inode */ if (f_ino) printf("%*"PRIuMAX" ", obj->obj_ino_max, (uintmax_t)st->st_ino); /* print number of blocks */ if (f_block) { print_block((int64_t)st->st_blocks * DEFAULT_BSIZE, obj->obj_block_max); } /* print mode */ strmode(st->st_mode, mode); printf("%11s ", mode); /* print number of links */ printf("%*"PRIuMAX" ", obj->obj_link_max, (uintmax_t)st->st_nlink); /* print owner and group */ print_user_and_group(st->st_uid, st->st_gid, obj->obj_user_max, obj->obj_group_max); /* print size */ if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) print_device(st->st_rdev, obj->obj_major_max, obj->obj_minor_max); else print_size(st->st_size, obj->obj_size_max); print_date(st); print_name(p, WITH_LINK); putchar('\n'); p = p->fts_link; } }
int main() { Quote q("text", 10.60); Bulk_quote bq("text", 10.60, 10, 0.3); Limit_quote lq("text", 10.60, 20, 0.3); print_total(std::cout, q, 12); print_total(std::cout, bq, 12); print_total(std::cout, lq, 21); std::cout << "*******************************" << std::endl; print_debug(q); print_debug(bq); print_debug(lq); return 0; }
int main() { Quote q("101-12345-999", 13.99); print_total(std::cout, q, 15) << std::endl; Bulk_quote b("101-12333-888", 17.99, 15, 0.8); print_total(std::cout, b, 3) << std::endl; print_total(std::cout, b, 60) << std::endl; Limited_quote l("101-12333-888", 17.99, 15, 0.8); print_total(std::cout, l, 15) << std::endl; print_total(std::cout, l, 16) << std::endl; /* Disc_quote d; error: variable type 'Disc_quote' is an abstract class */ return 0; }
int dir_print_body(char *arg, unsigned long *dircount) { int rv; unsigned long filecount, bytecount; char *pattern, *cachedPattern; char *p; /* Modified to pre-allocate path to 270 bytes so that we don't have to realloc() it later. That was causing "DIR /S" not to work properly. The path variable cannot be reallocated once dir_list() is called, because dir_list() is recursive. This will also help to reduce memory fragmentation. */ if((p = dfnfullpath(arg)) == NULL) { error_out_of_memory(); return E_NoMem; } if((path = realloc(p, 270*sizeof(char))) == NULL) { free(p); error_out_of_memory(); return E_NoMem; } filecount = bytecount = 0; /* print the header */ if((rv = dir_print_header(toupper(path[0]) - 'A')) == 0) { /* There are some directory specs that are not detected by dfnstat() as they are no part of the filesystem in DOS */ pattern = dfnfilename(path); assert(p); if(!*pattern || (dfnstat(path) & DFN_DIRECTORY) != 0) { pattern = strchr(pattern, '\0'); if(pattern[-1] != '\\') ++pattern; rv = dir_list(pattern - path, "*.*", dircount, &filecount , &bytecount ); } else { if((cachedPattern = strdup(pattern)) == NULL) { error_out_of_memory(); rv = E_NoMem; } else { rv = dir_list(pattern - path, cachedPattern, dircount , &filecount, &bytecount ); free(cachedPattern); } } } free(path); return rv || (optS? print_total(filecount, bytecount): 0); }
void print_short(OBJ *obj) { if (f_totalsum && !obj->obj_isroot) print_total(obj->obj_size_total); if (f_line) print_line(obj); else if(f_column) print_column(obj); else print_colacross(obj); }
double Basket::total_receipt(std::ostream &os) const { double sum = 0.0; for (auto iter = items.cbegin(); iter != items.cend(); iter = items.upper_bound(*iter)) // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ // @note this increment moves iter to the first element with key // greater than *iter. { sum += print_total(os, **iter, items.count(*iter)); } // ^^^^^^^^^^^^^ using count to fetch // the number of the same book. os << "Total Sale: " << sum << std::endl; return sum; }
void print_ls(t_list *list, t_arg *arg_list) { t_maxlen maxlen; ft_bzero(&maxlen, sizeof(t_maxlen)); get_maxlen(arg_list->arg[10], list, &maxlen); if (list != NULL && arg_list->arg[9] == 1 && S_ISDIR(((t_file *)list->content)->mode) == 1) print_total(list); while (list != NULL) { if (arg_list->arg[8] == 1) print_ino(((t_file *)list->content)->ino, maxlen.ino); if (list != NULL && arg_list->arg[9] == 1) print_ls_ext((t_file *)list->content, arg_list, &maxlen); print_name((t_file *)list->content, arg_list->arg[9]); list = list->next; } }
PUBLIC int main(int argc, char** argv) { status* state; char path[MAX_PATH]; int len = 0; search_pattern* pattern; if (alloc_status(&state) == FAILURE) return EXIT_FAILURE; if (parse_opt(argc, argv, state, &pattern) == FAILURE) return EXIT_FAILURE; /* if no path provided take the current one */ if (argc == 1) { strncpy(path, ".\0", 2); len = 1; } /* check that the last arg is not an option */ else { strncpy(path, argv[argc - 1], strlen(argv[argc - 1])); len = strlen(argv[argc - 1]); path[len ] = '\0'; if (path[0] == '-') strncpy(path, ".\0", 2); } if (start_browse(path, 0, state, pattern) == FAILURE) return EXIT_FAILURE; if (state->opt->d_total == ON) print_total(state); free(state); return EXIT_SUCCESS; }
void print_directories(t_list *dir, int c, int options) { t_list *i; t_list *content; i = dir; while (i) { content = NULL; get_directory_content(i, &content, options); sort(content, options); if (c > 1 || options & RECURSIVE_OPTION_MASK) print_directory_name(i, &c); if (options & LONG_OPTION_MASK) print_total(content); print(content, options); if (options & RECURSIVE_OPTION_MASK) print_recursive(content, i, c, options); ft_lstdel(&content, &free_file); i = i->next; } }
/* * dir_list * * list the files in the directory */ int dir_list(int pathlen , char *pattern , unsigned long *dcnt , unsigned long *fcnt , unsigned long *bcnt) { struct ffblk file; unsigned long bytecount = 0; unsigned long filecount = 0; unsigned long dircount = 0; int time; int count; unsigned mode = FA_RDONLY | FA_ARCH | FA_DIREC; char *p; int rv = E_None; assert(path); assert(pattern); assert(pathlen >= 2); /* at least root */ if((p = realloc(path, pathlen + sizeof(file.ff_name) + 1)) == NULL) { error_out_of_memory(); return E_NoMem; } path = p; /* if the user wants all files listed RL 06/17/98 */ if (optA) mode |= FA_HIDDEN | FA_SYSTEM; /* Search for matching entries */ path[pathlen - 1] = '\\'; strcpy(&path[pathlen], pattern); if (FINDFIRST(path, &file, mode) == 0) { /* moved down here because if we are recursively searching and * don't find any files, we don't want just to print * Directory of C:\SOMEDIR * with nothing else */ if(pathlen == 3) /* root directory */ path[pathlen] = '\0'; /* path := path w/o filename */ else path[pathlen - 1] = '\0'; if (!optB) { rv = flush_nl(); if(rv == E_None) { printf(" Directory of %s\n", path); if((rv = incline()) == E_None) { putchar('\n'); rv = incline(); } } } /* For counting columns of output */ count = WIDE_COLUMNS; if(rv == E_None) do { assert(strlen(file.ff_name) < 13); if (cbreak) rv = E_CBreak; else { if (optL) strlwr(file.ff_name); if (optW) { char buffer[sizeof(file.ff_name) + 3]; if (file.ff_attrib & FA_DIREC) { sprintf(buffer, "[%s]", file.ff_name); dircount++; } else { strcpy(buffer, file.ff_name); filecount++; bytecount += file.ff_fsize; } printf("%-15s", buffer); if (!--count) { /* outputted 5 columns */ putchar('\n'); rv = incline(); count = WIDE_COLUMNS; } } else if (optB) { if (strcmp(file.ff_name, ".") == 0 || strcmp(file.ff_name, "..") == 0) continue; if (optS) fputs(path, stdout); printf("%-13s\n", file.ff_name); if (file.ff_attrib & FA_DIREC) dircount++; else { filecount++; bytecount += file.ff_fsize; } rv = incline(); } else { char buffer[sizeof(long) * 4 + 2], *ext; if (file.ff_name[0] == '.') printf("%-13s", file.ff_name); else { ext = strrchr(file.ff_name, '.'); if (!ext) ext = ""; else *ext++ = '\0'; printf("%-8s %-3s ", file.ff_name, ext); } if (file.ff_attrib & FA_DIREC) { printf("%-14s", "<DIR>"); dircount++; } else { convert(file.ff_fsize, buffer); printf(" %10s ", buffer); bytecount += file.ff_fsize; filecount++; } printf("%.2d-%.2d-%02d", ((file.ff_fdate >> 5) & 0x000f), (file.ff_fdate & 0x001f), ((file.ff_fdate >> 9) + 80) % 100); time = file.ff_ftime >> 5 >> 6; printf(" %2d:%.2u%c\n", (time == 0 ? 12 : (time <= 12 ? time : time - 12)), ((file.ff_ftime >> 5) & 0x003f), (time <= 11 ? 'a' : 'p')); rv = incline(); } } } while (rv == E_None && FINDNEXT(&file) == 0); } /* Rob Lake, need to make clean output */ if (rv == E_None && optW && (count != 0)) { putchar('\n'); rv = incline(); } if (rv == E_None) if(filecount || dircount) { /* The code that was here is now in print_summary */ rv = print_summary(filecount, dircount, bytecount); } else if(!optS) { error_file_not_found(); rv = E_Other; } if(rv == E_None /* no error */ && optS /* do recursively */ && (pathlen == 3 /* root directory */ || dircount > 2)) { /* at least dir except . & .. */ path[pathlen - 1] = '\\'; strcpy(&path[pathlen], "*.*"); if (FINDFIRST(path, &file, mode) == 0) do { if((file.ff_attrib & FA_DIREC) != 0 /* is directory */ && strcmp(file.ff_name, ".") != 0 /* not cur dir */ && strcmp(file.ff_name, "..") != 0) { /* not parent dir */ if (optL) strlwr(file.ff_name); strcpy(&path[pathlen], file.ff_name); rv = dir_list(pathlen + strlen(file.ff_name) + 1, pattern , &dircount, &filecount, &bytecount); } } while (rv == E_None && FINDNEXT(&file) == 0); if(rv == E_None) { if(pathlen == 3) /* root directory */ path[pathlen] = '\0'; /* path := path w/o filename */ else path[pathlen - 1] = '\0'; rv = print_total(filecount, dircount, bytecount); } } *dcnt += dircount; *fcnt += filecount; *bcnt += bytecount; return rv; }
static int cpustat(void) { cpc_setgrp_t *accum; cpc_set_t *start; int c, i, retval; int lwps = 0; psetid_t mypset, cpupset; char *errstr; cpc_buf_t **data1, **data2, **scratch; int nreqs; kstat_ctl_t *kc; ncpus = (int)sysconf(_SC_NPROCESSORS_CONF); if ((gstate = calloc(ncpus, sizeof (*gstate))) == NULL) { (void) fprintf(stderr, gettext( "%s: out of heap\n"), opts->pgmname); return (1); } max_chip_id = sysconf(_SC_CPUID_MAX); if ((chip_designees = malloc(max_chip_id * sizeof (int))) == NULL) { (void) fprintf(stderr, gettext( "%s: out of heap\n"), opts->pgmname); return (1); } for (i = 0; i < max_chip_id; i++) chip_designees[i] = -1; if (smt) { if ((kc = kstat_open()) == NULL) { (void) fprintf(stderr, gettext( "%s: kstat_open() failed: %s\n"), opts->pgmname, strerror(errno)); return (1); } } if (opts->dosoaker) if (priocntl(0, 0, PC_GETCID, &fxinfo) == -1) { (void) fprintf(stderr, gettext( "%s: couldn't get FX scheduler class: %s\n"), opts->pgmname, strerror(errno)); return (1); } /* * Only include processors that are participating in the system */ for (c = 0, i = 0; i < ncpus; c++) { switch (p_online(c, P_STATUS)) { case P_ONLINE: case P_NOINTR: if (smt) { gstate[i].chip_id = get_chipid(kc, c); if (gstate[i].chip_id != -1 && chip_designees[gstate[i].chip_id] == -1) chip_designees[gstate[i].chip_id] = c; } gstate[i++].cpuid = c; break; case P_OFFLINE: case P_POWEROFF: case P_FAULTED: case P_SPARE: gstate[i++].cpuid = -1; break; default: gstate[i++].cpuid = -1; (void) fprintf(stderr, gettext("%s: cpu%d in unknown state\n"), opts->pgmname, c); break; case -1: break; } } /* * Examine the processor sets; if we're in one, only attempt * to report on the set we're in. */ if (pset_bind(PS_QUERY, P_PID, P_MYID, &mypset) == -1) { errstr = strerror(errno); (void) fprintf(stderr, gettext("%s: pset_bind - %s\n"), opts->pgmname, errstr); } else { for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; if (pset_assign(PS_QUERY, this->cpuid, &cpupset) == -1) { errstr = strerror(errno); (void) fprintf(stderr, gettext("%s: pset_assign - %s\n"), opts->pgmname, errstr); continue; } if (mypset != cpupset) this->cpuid = -1; } } if (opts->dotitle) print_title(opts->master); zerotime(); for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; this->sgrp = cpc_setgrp_clone(opts->master); if (this->sgrp == NULL) { this->cpuid = -1; continue; } if (thr_create(NULL, 0, gtick, this, THR_BOUND|THR_NEW_LWP, &this->tid) == 0) lwps++; else { (void) fprintf(stderr, gettext("%s: cannot create thread for cpu%d\n"), opts->pgmname, this->cpuid); this->status = 4; } } if (lwps != 0) for (i = 0; i < ncpus; i++) (void) thr_join(gstate[i].tid, NULL, NULL); if ((accum = cpc_setgrp_clone(opts->master)) == NULL) { (void) fprintf(stderr, gettext("%s: out of heap\n"), opts->pgmname); return (1); } retval = 0; for (i = 0; i < ncpus; i++) { struct tstate *this = &gstate[i]; if (this->cpuid == -1) continue; cpc_setgrp_accum(accum, this->sgrp); cpc_setgrp_free(this->sgrp); this->sgrp = NULL; if (this->status != 0) retval = 1; } cpc_setgrp_reset(accum); start = cpc_setgrp_getset(accum); do { nreqs = cpc_setgrp_getbufs(accum, &data1, &data2, &scratch); print_total(lwps, *data1, nreqs, cpc_setgrp_getname(accum)); } while (cpc_setgrp_nextset(accum) != start); cpc_setgrp_free(accum); accum = NULL; free(gstate); return (retval); }
int main() { Limit_quote item("abc-123", 10, 10, 0.1); print_total(std::cout, item, 11); system("pause"); return 0; }
/* execute local file test ----------------------------------------------------- * execute local file test * args : gtime_t ts,te I time start and end * double tint I time interval (s) * url_t *urls I download urls * int nurl I number of urls * char **stas I stations * int nsta I number of stations * char *dir I local directory * int ncol I number of column * int datefmt I date format (0:year-dow,1:year-dd/mm,2:week) * FILE *fp IO log test result file pointer * return : status (1:ok,0:error,-1:aborted) *-----------------------------------------------------------------------------*/ extern void dl_test(gtime_t ts, gtime_t te, double ti, const url_t *urls, int nurl, char **stas, int nsta, const char *dir, int ncol, int datefmt, FILE *fp) { gtime_t time; double tow; char year[32],date[32],date_p[32]; int i,j,n,m,*nc,*nt,week,flag,abort=0; if (ncol<1) ncol=1; else if (ncol>200) ncol=200; fprintf(fp,"** LOCAL DATA AVAILABILITY (%s, %s) **\n\n", time_str(timeget(),0),*dir?dir:"*"); for (i=n=0;i<nurl;i++) { n+=strstr(urls[i].path,"%s")||strstr(urls[i].path,"%S")?nsta:1; } nc=imat(n,1); nt=imat(n,1); for (i=0;i<n;i++) nc[i]=nt[i]=0; for (;timediff(ts,te)<1E-3&&!abort;ts=timeadd(ts,ti*ncol)) { genpath(datefmt==0?" %Y-":"%Y/%m/","",ts,0,year); if (datefmt<=1) fprintf(fp,"%s %s",datefmt==0?"DOY ":"DATE",year); else fprintf(fp,"WEEK "); *date_p='\0'; flag=0; m=datefmt==2?1:2; for (i=0;i<(ncol+m-1)/m;i++) { time=timeadd(ts,ti*i*m); if (timediff(time,te)>=1E-3) break; if (datefmt<=1) { genpath(datefmt==0?"%n":"%d","",time,0,date); fprintf(fp,"%-4s",strcmp(date,date_p)?date:""); } else { if (fabs(time2gpst(time,&week))<1.0) { fprintf(fp,"%04d",week); flag=1; } else { fprintf(fp,"%s",flag?"":" "); flag=0; } } strcpy(date_p,date); } fprintf(fp,"\n"); for (i=j=0;i<nurl&&!abort;i++) { time=timeadd(ts,ti*ncol-1.0); if (timediff(time,te)>=0.0) time=te; /* test local files */ abort=test_locals(ts,time,ti,urls+i,stas,nsta,dir,nc+j,nt+j,fp); j+=strstr(urls[i].path,"%s")||strstr(urls[i].path,"%S")?nsta:1; } fprintf(fp,"\n"); } fprintf(fp,"# COUNT : FILES/TOTAL\n"); for (i=j=0;i<nurl;i++) { j+=print_total(urls+i,stas,nsta,nc+j,nt+j,fp); } free(nc); free(nt); }