From: Erkin Alp Güney Date: Sun, 8 Mar 2015 15:38:25 +0000 (+0200) Subject: C11 improvements and factor X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7142577aa30ef8ff5bcb7b08a5be0e120d7286e9;p=FUZIX.git C11 improvements and factor C11: gets_s() added prime factorisation utility added --- diff --git a/Applications/util/factor.c b/Applications/util/factor.c index 570270ed..a2583b2c 100644 --- a/Applications/util/factor.c +++ b/Applications/util/factor.c @@ -1,9 +1,22 @@ /* factor.c - Factor integers - * - * Copyright 2014 Rob Landley - * - * No standard, but it's in coreutils +Copyright (C) 2006, 2013 by Rob Landley +Copyright (C) 2015 by Erkin Alp Güney +Original by Rob-FUZIX porting by Erkin Alp +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +(Note: some build infrastructure in the kconfig directory is still GPLv2, +cleaning that out is a TODO item, but it doesn't affect the resulting +binary.) USE_FACTOR(NEWTOY(factor, 0, TOYFLAG_USR|TOYFLAG_BIN)) config FACTOR @@ -71,17 +84,17 @@ static void factor(char *s) } } -void factor_main(void) +void main(int argc,char *argv[]) { - if (toys.optc) { + if (argc > 1) { char **ss; - for (ss = toys.optargs; *ss; ss++) factor(*ss); + for (ss = argv[0]; *ss; ss++) factor(*ss); } else for (;;) { char *s = 0; size_t len = 0; - if (-1 == getline(&s, &len, stdin)) break; + if (-1 == gets_s(&s, LINE_MAX)) break; factor(s); } }