t_l *sort_t(t_l *list, char *flag, t_l *base, char *path) { t_stat fs; t_stat sf; t_l *tmp; char *npath; char *xpath; tmp = list; list = list->next; while (list) { xpath = getpath(path, tmp->str); npath = getpath(path, list->str); ft_putstr("/nPATH ______________"); ft_putstr(npath); if (stat(npath, &fs) < 0 || stat(xpath, &sf) < 0) return (0); ft_memdel((void *)&npath); ft_memdel((void *)&xpath); if (isflag(flag, 'r') && fs.st_mtime < sf.st_mtime) { sortswap(tmp, list); list = base; } else if (!(isflag(flag, 'r')) && fs.st_mtime > sf.st_mtime) { sortswap(tmp, list); list = base; } tmp = list; list = list->next; } return (base); }
int istrue(char *flag, char *file, char *sl, char *path) { char *npath; char *lpath; t_stat fs; t_stat sf; int i; int c; c = 0; i = 0; if (path) { npath = getpath(path, file); lpath = getpath(path, sl); c = -1; } else { npath = file; lpath = sl; } if (fs.st_mtime < sf.st_mtime && isflag(flag, 'r') && isflag(flag, 't')) i = 1; if (c == -1) { ft_memdel((void **)&npath); ft_memdel((void **)&lpath); } return (i); }
t_l *sort(t_l *list, char *flag, char *path) { t_l *base; base = list; sor(list); if (isflag(flag, 't')) list = sort_t(list, flag, base, path); else if (isflag(flag, 'r')) list = sort_r(list, base); return (list); }
t_l *initlist(t_l **file, char *str, char *flag, char *path) { if (!*file) return (listadd(str)); if (isflag(flag, "tr")) return (listtr(file, str, path)); if (isflag(flag, "t")) return (listt(file, str, path)); if (isflag(flag, "r")) return (listr(file, str)); return (alphalistsort(file, str)); }
/*---------------------------------------------------------------*/ static int nth_is_arg(int nargc, char **argv, int nth) { /* Checks that nth arg exists and is not a flag */ /* nth is 0-based */ /* This is typically called from parse_commandline(), for example, the following code specifies that --psdwin requires two arguments but there may be a third. The first two are read in, then nth_is_arg() is called to determine whether the third exists and whether it is an argument or a flag. It is not neccessary to check whether there are enough arguments (ie, if nargc > 2) because this is done in nth_is_arg(). else if (stringmatch(option, "--psdwin")){ if(nargc < 2) argnerr(option,2); sscanf(pargv[0],"%f",&PSDMin); sscanf(pargv[1],"%f",&PSDMax); nargsused = 2; if(nargc > 2 && nth_is_arg(2,pargv,nargc)){ sscanf(pargv[2],"%f",&dPSDfTR); nargsused++; } else dPSDfTR = 1.0; } */ /* check that there are enough args for nth to exist */ if (nargc <= nth) return(0); /* check whether the nth arg is a flag */ if (isflag(argv[nth])) return(0); return(1); }
/*---------------------------------------------------------------*/ static int nth_is_arg(int nargc, char **argv, int nth) { /* Checks that nth arg exists and is not a flag */ /* nth is 0-based */ /* check that there are enough args for nth to exist */ if (nargc <= nth) return(0); /* check whether the nth arg is a flag */ if (isflag(argv[nth])) return(0); return(1); }
int cwt_vsnprintf(CWT_CHAR *string, size_t length, const CWT_CHAR *format, va_list args) { struct DATA data; CWT_CHAR conv_field[MAX_FIELD]; double d; /* temporary holder */ int state; int i; data.length = length - 1; /* leave room for '\0' */ data.holder = string; data.pf = format; data.counter = 0; /* sanity check, the string must be > 1 */ if (length < 1) return -1; for (; *data.pf && (data.counter < data.length); data.pf++) { if ( *data.pf == _T('%') ) { /* we got a magic % cookie */ conv_flag((CWT_CHAR *)0, &data); /* initialise format flags */ for (state = 1; *data.pf && state;) { switch (*(++data.pf)) { case _T('\0'): /* a NULL here ? ? bail out */ *data.holder = _T('\0'); return data.counter; break; case _T('f'): /* float, double */ STAR_ARGS(&data); d = va_arg(args, double); floating(&data, d); state = 0; break; case _T('g'): case _T('G'): STAR_ARGS(&data); DEF_PREC(&data); d = va_arg(args, double); i = log_10(d); /* for '%g|%G' ANSI: use f if exponent * is in the range or [-4,p] exclusively * else use %e|%E */ if (-4 < i && i < data.precision) floating(&data, d); else exponent(&data, d); state = 0; break; case _T('e'): case _T('E'): /* Exponent double */ STAR_ARGS(&data); d = va_arg(args, double); exponent(&data, d); state = 0; break; case _T('u'): case _T('d'): /* decimal */ STAR_ARGS(&data); if (data.a_long == FOUND) d = va_arg(args, long); else d = va_arg(args, int); decimal(&data, d); state = 0; break; case _T('o'): /* octal */ STAR_ARGS(&data); if (data.a_long == FOUND) d = va_arg(args, long); else d = va_arg(args, int); octal(&data, d); state = 0; break; case _T('x'): case _T('X'): /* hexadecimal */ STAR_ARGS(&data); if (data.a_long == FOUND) d = va_arg(args, long); else d = va_arg(args, int); hexa(&data, d); state = 0; break; case _T('c'): /* character */ d = va_arg(args, int); PUT_CHAR((CWT_CHAR)d, &data); state = 0; break; case _T('s'): /* string */ STAR_ARGS(&data); strings(&data, va_arg(args, CWT_CHAR *)); state = 0; break; case _T('n'): *(va_arg(args, int *)) = data.counter; /* what's the count ? */ state = 0; break; case _T('l'): data.a_long = FOUND; break; case _T('h'): break; case _T('%'): /* nothing just % */ PUT_CHAR(_T('%'), &data); state = 0; break; case _T('#'): case _T(' '): case _T('+'): case _T('*'): case _T('-'): case _T('.'): case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'): /* initialize width and precision */ for (i = 0; isflag(*data.pf); i++, data.pf++) if (i < MAX_FIELD - 1) conv_field[i] = *data.pf; conv_field[i] = _T('\0'); conv_flag(conv_field, &data); data.pf--; /* went to far go back */ break; default: /* is this an error ? maybe bail out */ state = 0; break; } /* end switch */