• getFirstDayOfMonth()

    From Mike Sanders@21:1/5 to All on Fri Mar 1 03:48:05 2024
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to Mike Sanders on Fri Mar 1 15:39:27 2024
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I assume the two versions end up being equivalent.

    BTW, how long do you think it will be until this thread gets hijacked into
    a long, acrimonious debate about what the definition of the first day of
    the month is and how various cultures define it differently, and how insensitive we are (especially, if "we" are USA Americans) to assume that
    our way is the only way? A matter of hours, I suspect.

    --
    You know politics has really been turned upside down when you have someone in the
    government with a last name of Cheney (Liz, Senator from Wyoming) who is the voice of
    reason.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kenny McCormack on Fri Mar 1 17:12:35 2024
    On 01.03.2024 16:39, Kenny McCormack wrote:
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I assume the two versions end up being equivalent.

    Are they?

    I'm certainly irritated about the OP's final

    return (f % 7) - 1;

    returning values from -1 to 5. And then using these indexes
    to address a C array. (Looks wrong to me, but I'm anyway
    not interested in second hand copies of generally available
    algorithms; there's little value.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Fri Mar 1 17:33:13 2024
    On 01.03.2024 17:28, Keith Thompson wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt
    [...]
    I'm certainly irritated about the OP's final

    return (f % 7) - 1;

    returning values from -1 to 5. And then using these indexes
    to address a C array. (Looks wrong to me, but I'm anyway
    not interested in second hand copies of generally available
    algorithms; there's little value.)

    Yes, that's a bug in the original code. The program only tests for
    August 2024, but the algorithm fails for June 2024, which starts on
    Saturday.

    One fix is to change
    return (f % 7) - 1;
    to:
    return (f + 6) % 7;
    which works correctly at least for all months of 2024.

    Yes. Though I'd have done the correction on the previous line.

    int f = d + ... - 1;
    return f % 7;

    To me that would be clearer.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Fri Mar 1 17:37:17 2024
    On 01.03.2024 17:33, Janis Papanagnou wrote:

    Yes. Though I'd have done the correction on the previous line.

    int f = d + ... - 1;
    return f % 7;

    To me that would be clearer.

    Or completely removing the 'd' and the '-1' since 'd' is actually
    a (non-const declared) constant and equals to 1.

    (Gee! Why do I mind, anyway.)


    Janis


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kenny McCormack on Fri Mar 1 16:47:38 2024
    gazelle@shell.xmission.com (Kenny McCormack) writes:
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I assume the two versions end up being equivalent.

    BTW, how long do you think it will be until this thread gets hijacked into
    a long, acrimonious debate about what the definition of the first day of
    the month is and how various cultures define it differently, and how >insensitive we are (especially, if "we" are USA Americans) to assume that
    our way is the only way? A matter of hours, I suspect.

    Seconds, it would appear, as you have highjacked your own thread.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kenny McCormack on Fri Mar 1 17:56:07 2024
    On 01.03.2024 16:39, Kenny McCormack wrote:

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I'm wondering what would be the better approach, using some date
    functions or calculating it by a formula. (Serious question.)

    I'm asking since I had previously used time-functions in another
    context (determining Fri 13th dates) for such a purpose. And the
    rewrite to the "first day" task is simple, and the code pattern
    very flexible. Here's the Gawk counterpart just for illustration:

    BEGIN { y = ARGV[1] ; m = ARGV[2]
    print strftime ("%a", mktime (y " " m " 1 0 0 0"))
    }

    ...and I'm sure you can also use this approach in C.

    So what's more advantageous? - Is the domain of one or the other
    approach restricted? Is one or the other more accurate? Or may
    the runtime be an issue?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Keith Thompson on Fri Mar 1 17:20:56 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    Yes, that's a bug in the original code. The program only tests for
    August 2024, but the algorithm fails for June 2024, which starts on
    Saturday.

    One fix is to change
    return (f % 7) - 1;
    to:
    return (f + 6) % 7;
    which works correctly at least for all months of 2024.

    Negative index values can be valid. For example, foo[-1] can be valid,
    but only if foo is a pointer to an array element other than the first
    one, not if foo is an array object.

    Thanks Keith, will use this moving forward. Glad to have some extra
    eyeballs on it.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Kenny McCormack on Fri Mar 1 17:18:22 2024
    Kenny McCormack <gazelle@shell.xmission.com> wrote:

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I assume the two versions end up being equivalent.

    Hey-hey Kenny!

    Many thanks for sharing this, now I have something to compare it too
    more thoroughly.

    BTW, how long do you think it will be until this thread gets hijacked into
    a long, acrimonious debate about what the definition of the first day of
    the month is and how various cultures define it differently, and how insensitive we are (especially, if "we" are USA Americans) to assume that
    our way is the only way? A matter of hours, I suspect.

    Well...

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Kenny McCormack on Fri Mar 1 20:47:53 2024
    Kenny McCormack <gazelle@shell.xmission.com> wrote:

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I've put this right to work too Kenny...

    Prints calander for the given year with every 2 months adjacent

    https://busybox.neocities.org/notes/adjacent-calendars.txt

    Example...

    Jan Feb
    Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
    1 1 2 3 4 5
    2 3 4 5 6 7 8 6 7 8 9 10 11 12
    9 10 11 12 13 14 15 13 14 15 16 17 18 19
    16 17 18 19 20 21 22 20 21 22 23 24 25 26
    23 24 25 26 27 28 29 27 28
    30 31

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Fri Mar 1 22:03:57 2024
    On 01.03.2024 19:34, Keith Thompson wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 01.03.2024 17:33, Janis Papanagnou wrote:
    Yes. Though I'd have done the correction on the previous line.

    int f = d + ... - 1;
    return f % 7;

    To me that would be clearer.

    Or completely removing the 'd' and the '-1' since 'd' is actually
    a (non-const declared) constant and equals to 1.

    (Gee! Why do I mind, anyway.)

    I think the point of defining 'd' is to allow for computing the day of
    the week for days of the month other than the first. The code as
    presented suggests a lot of opportunities for generalization (such as handling months other than August 2024). The local variable 'd' could
    be replaced by a parameter 'int mday'.

    Surely I am aware of that. But the OP's code isn't addressing any generalization (cf. "int getFirstDayOfMonth(int year, int month)").
    If you'd strive for a generalization you'd define a function like
    the one Kenny posted (cf. "int day(d,m,y)"). If you want a special
    function (for whatever reason) as the OP did you can as well just
    optimize it by reducing redundant parts. (Anyway, it's not worth
    the dispute.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Scott Lurndal on Fri Mar 1 21:50:31 2024
    Scott Lurndal <scott@slp53.sl.home> wrote:

    That must not have been for 2024, or you have a bug.

    Well Scott, in the code of the link posted its displaying 2022:

    int year = 2022;

    A calendar utility comes with most linux systems. It also supports
    ISO 8601 which starts the week on Monday instead of Sunday.

    Yes sir, I know that. But I want to build my own instead so I can
    learn more about it. Even if that means reiventing the wheel, at
    least I'll learn it as I wish. Hoping not to sound contrite,
    cant we all just help each other learn? Darn man.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Fri Mar 1 21:38:11 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Kenny McCormack <gazelle@shell.xmission.com> wrote:

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
    }

    I've put this right to work too Kenny...

    Prints calander for the given year with every 2 months adjacent

    https://busybox.neocities.org/notes/adjacent-calendars.txt

    Example...

    Jan Feb
    Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
    1 1 2 3 4 5
    2 3 4 5 6 7 8 6 7 8 9 10 11 12
    9 10 11 12 13 14 15 13 14 15 16 17 18 19
    16 17 18 19 20 21 22 20 21 22 23 24 25 26
    23 24 25 26 27 28 29 27 28
    30 31

    That must not have been for 2024, or you have a bug.

    A calendar utility comes with most linux systems. It also supports
    ISO 8601 which starts the week on Monday instead of Sunday.

    https://en.wikipedia.org/wiki/ISO_8601

    https://github.com/util-linux/util-linux/blob/master/misc-utils/cal.c

    $ cal 2024
    2024

    January February March
    Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
    1 2 3 4 5 6 1 2 3 1 2
    7 8 9 10 11 12 13 4 5 6 7 8 9 10 3 4 5 6 7 8 9
    14 15 16 17 18 19 20 11 12 13 14 15 16 17 10 11 12 13 14 15 16
    21 22 23 24 25 26 27 18 19 20 21 22 23 24 17 18 19 20 21 22 23
    28 29 30 31 25 26 27 28 29 24 25 26 27 28 29 30
    31

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Scott Lurndal on Sat Mar 2 00:00:58 2024
    Scott Lurndal <scott@slp53.sl.home> wrote:

    https://en.wikipedia.org/wiki/ISO_8601

    Have partial ISO8601 compliance now (when using option: -D=2):

    Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]

    -A=NUM Number of days in advance to look ahead (366 max)
    -P=NUM Number of days in the past to look back (366 max)
    -D=NUM Format dates as: 1 mm/dd/yyyy, 2 yyyy/mm/dd
    -S=NUM Separate date fields using: 1 Slash, 2 Dash, 3 Dot
    -X=NUM Export results as: 1 TXT, 2 CSV, 3 SQL, 4 HTML
    -T=TAG Filter results for 'TAG' (16 characters max)
    -H Include holidays (see manual for list)
    -W Include weekday abbreviations
    -F Include attribute flags (see manual for details)
    -C Display calendar for current year
    -M Display embedded user manual

    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    But hey its Friday I should lighten up & have some fun:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    const char *getChineseZodiac(int year) {

    const char* animals[] = {
    "Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
    "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"
    };

    return animals[year % 12];
    }

    int main() {

    time_t now = time(NULL);
    struct tm *localTime = localtime(&now);
    int year = localTime->tm_year;
    printf("%d Year of the %s\n", year + 1900, getChineseZodiac(year));

    return 0;
    }

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Sat Mar 2 02:49:59 2024
    Kenny McCormack ha scritto:
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

    Hi,
    I am referring in particular to this part of the equation:
    y + y/4 - y/100 + y/400
    Shouldn't it be calculated in a floating point and then truncated only
    the final result? Because, for example, if the year is 2024, the
    floating point calculation is 2514 (2514.82) while executed between
    integer is 2515.

    }

    I assume the two versions end up being equivalent.

    BTW, how long do you think it will be until this thread gets hijacked into
    a long, acrimonious debate about what the definition of the first day of
    the month is and how various cultures define it differently, and how insensitive we are (especially, if "we" are USA Americans) to assume that
    our way is the only way? A matter of hours, I suspect.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kenny McCormack on Sat Mar 2 03:44:29 2024
    On 2024-03-01, Kenny McCormack <gazelle@shell.xmission.com> wrote:
    int day(d,m,y)
    int d, m, y;
    {
    [...]
    BTW, how long do you think it will be until this thread gets hijacked into
    a long, acrimonious debate about what the definition of the first day of
    the month is and how various cultures define it differently, and how

    Pissing on new code using old-style C in 5... 4... 3....

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Sat Mar 2 14:46:45 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    https://en.wikipedia.org/wiki/ISO_8601

    Have partial ISO8601 compliance now (when using option: -D=2):

    Nice.


    Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]

    -A=NUM Number of days in advance to look ahead (366 max)
    -P=NUM Number of days in the past to look back (366 max)
    -D=NUM Format dates as: 1 mm/dd/yyyy, 2 yyyy/mm/dd
    -S=NUM Separate date fields using: 1 Slash, 2 Dash, 3 Dot
    -X=NUM Export results as: 1 TXT, 2 CSV, 3 SQL, 4 HTML
    -T=TAG Filter results for 'TAG' (16 characters max)
    -H Include holidays (see manual for list)
    -W Include weekday abbreviations
    -F Include attribute flags (see manual for details)
    -C Display calendar for current year
    -M Display embedded user manual


    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    For commands defined by POSIX (and generally in
    unix), an exit status of zero indicates success.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Scott Lurndal on Sat Mar 2 16:41:46 2024
    On 02.03.2024 15:46, Scott Lurndal wrote:
    porkchop@invalid.foo (Mike Sanders) writes:

    Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]
    [...]

    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Or, since there's a mandatory file name argument, provide usage
    information (also) if no argument or option is provided.

    Janis

    [...]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Scott Lurndal on Sat Mar 2 19:59:35 2024
    Scott Lurndal <scott@slp53.sl.home> wrote:

    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    Many thanks for the link too btw.

    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    For commands defined by POSIX (and generally in
    unix), an exit status of zero indicates success.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.
    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    Thanks again for the links Scott, I'll read them this
    weekend.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Mike Sanders on Sat Mar 2 22:14:20 2024
    On 02.03.2024 20:59, Mike Sanders wrote:

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.

    Again you have a misconception; errors on Unix systems are
    regularly indicated by any value unequal to 0, not only by 1.
    That way you can differentiate any possible errors or types
    of errors.

    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue.

    (I would be astonished. But since you haven't provided any
    hint on its specific "methodology" the statement is void.)

    0/1 provides next to no nuance.

    That's why on Unixes you can and typically return more than
    just two values.

    But I'm no expert, just my experience.

    You haven't provided any evidence or facts of experience.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Mike Sanders on Sun Mar 3 04:06:31 2024
    On 3/2/24 14:59, Mike Sanders wrote:
    ...
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.

    It would be, if that's what POSIX required. Instead, it uses 0 - good,
    non-zero bad. Note that 0 representing successful results is mandated by
    the C standard as well. EXIT_SUCCESS is another way of indicating
    success, which might or might not be the same as 0. EXIT_FAILURE is the
    only portable way to indicate failure as far as C itself is concerned,
    but if you're willing to write POSIX-specific code, you can use a much
    wider variety of values. The same is true of all of the other operating
    systems I've written C code for (Windows and VMS, mostly).

    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance.

    The lack of nuance is apparently the result of your being unaware of the
    fact that 1 is not the only permitted error return.

    Keep in mind that the make utility and shells designed for Unix-like
    systems (as well as many other programs targeting such systems) expect 0
    for success, and may produce unexpected results if you violate that
    convention.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Bourne@21:1/5 to Scott Lurndal on Sun Mar 3 13:17:00 2024
    Scott Lurndal wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    For commands defined by POSIX (and generally in
    unix), an exit status of zero indicates success.

    Also on Windows, an exit status of zero indicates success and non-zero
    failure. From a command prompt, the status of the last command can be
    accessed via the %ERRORLEVEL% environment variable (similar to $? on *nix).

    --
    Mark.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Sun Mar 3 15:43:22 2024
    On 02.03.2024 23:22, Keith Thompson wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:
    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html >>>
    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    [snip code sample]

    And most users of Unix-like systems won't expect '-?' to be an option;

    I cannot speak for "most users of Unix-like systems" but my personal
    experience differs.

    '-h' is much more common.

    The "problem" is that you may want to have -h as an option character, especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    The advantage of -? is that is has as non-alpha option not a mnemonic character. (We thus used it since the 1990's even in coding standards
    as our preferred standard way to interrogate usage.)

    Your point that -h may be a file is nonetheless valid, of course, as
    would be a file named -?. Both are rather rare though and typically
    the result of an error; especially commands started from the shell
    will report errors and you have to use '--' to create files like -h.
    The Shell also allows to disable file globbing if that happens to
    appear to be an issue and if you don't want to just quote the -? in
    such (rare) corner-cases with pathological filenames.

    There's functional option names with application semantics (usually
    expressed with mnemonic characters, or long names) and meta options
    like issuing a usage synopsis. I'd certainly like to have mnemonics
    preserved for the applications!

    That's why using non-alpha key-symbols is also the standard for e.g.
    Ksh; its option processing builtin 'getopts' _inherently_ supports
    (for all shell scripts that use this function for option processing)
    the meta options -? (for usage synopsis), --?? (for a verbose usage
    message), and the prefix --?? generally for other meta-formats (like
    --??html or also long form alternatives like --html to create usage
    information in HTML).[**]

    Janis

    [*] In scripts you may of course also define long option names but
    for interactive use it's certainly not a preferred workaround.

    [**] That's also why I think that [without evidence] we cannot assume
    "most users of Unix-like systems" to be a reliable qualification. It
    seems to be a common standard.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Sun Mar 3 15:24:29 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    Many thanks for the link too btw.

    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    For commands defined by POSIX (and generally in
    unix), an exit status of zero indicates success.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.

    The reason posix commands return zero for success
    is because the posix (and all other shells)
    check the exit status of a command and treat
    non-zero values as failure.

    $ grep 'sigdelset' asim.cpp
    $ echo $?
    1
    $ grep 'sigaddset' asim.cpp
    sigaddset(&signals, SIGHUP);
    sigaddset(&signals, SIGABRT);
    sigaddset(&signals, SIGPIPE);
    sigaddset(&signals, SIGUSR1);
    sigaddset(&signals, SIGUSR2);
    sigaddset(&sa.sa_mask, SIGHUP);
    sigaddset(&sa.sa_mask, SIGINT);
    sigaddset(&sa.sa_mask, SIGQUIT);
    sigaddset(&sa.sa_mask, SIGTERM);
    sigaddset(&sa.sa_mask, SIGXCPU);
    $ echo $?
    0

    if grep -q 'sigaddset' asim.cpp
    then
    echo "Found it!"
    fi

    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    It's not 0/1, it is 0 for success and non-zero for
    failure, where the failure is indicated by the
    exit value (often restricted to 8-bits due to
    the legacy wait(2) system call, however the
    newer (for some value of new) system call waitid(2)
    supports the full 32-bit exit status).

    For example, the grep command returns
    0 - success
    1 - No lines were matched/selected
    1 - An error occurred.

    Some utilities define additional exit status values.

    VMS defined '1' (SS$_NORMAL) as the success return
    value from system calls and commands, which is likely
    the source of that feature in windows.

    I've yet to find any feature of windows that is truely
    superior (rather than just different).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to jak on Sun Mar 3 09:47:39 2024
    jak <nospam@please.ty> writes:

    Kenny McCormack ha scritto:

    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:

    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

    I am referring in particular to this part of the equation:
    y + y/4 - y/100 + y/400
    Shouldn't it be calculated in a floating point and then truncated only
    the final result? Because, for example, if the year is 2024, the
    floating point calculation is 2514 (2514.82) while executed between
    integer is 2515.

    The short answer is No. If you try some examples I expect
    you will see that using integer division always gives
    correct results. Leap days always happen in integer amounts,
    so integer division is the right way to calculate them.

    Note: I haven't tested this particular algorithm and so
    cannot vouch for its correctness. But the part that
    determines an extra number of days based on what year
    it is matches other algorithms that I have tested.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Mike Sanders on Sun Mar 3 09:52:46 2024
    porkchop@invalid.foo (Mike Sanders) writes:

    Scott Lurndal <scott@slp53.sl.home> wrote:

    That must not have been for 2024, or you have a bug.

    Well Scott, in the code of the link posted its displaying 2022:

    int year = 2022;

    A calendar utility comes with most linux systems. It also supports
    ISO 8601 which starts the week on Monday instead of Sunday.

    Yes sir, I know that. But I want to build my own instead so I can
    learn more about it. Even if that means reiventing the wheel, at
    least I'll learn it as I wish. Hoping not to sound contrite,
    cant we all just help each other learn? Darn man.

    If you want to reinvent wheels, I suggest looking for some
    rather more interesting wheels.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Janis Papanagnou on Sun Mar 3 18:45:26 2024
    On 03/03/2024 15:43, Janis Papanagnou wrote:
    On 02.03.2024 23:22, Keith Thompson wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:
    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html >>>>
    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    [snip code sample]

    And most users of Unix-like systems won't expect '-?' to be an option;

    I cannot speak for "most users of Unix-like systems" but my personal experience differs.


    Try "cmd -h" and "cmd -?" for a selection of programs on your *nix
    system. You'll find that "-h" will almost invariably give you a brief
    help message. "-?" will also work for some programs, but not many - and typically "-h" will work too for these programs.

    "-?" is common in the DOS/Windows world, and for programs that come from
    there, while "-h" is vastly more common in the *nix world. (And of
    course, "--help" works too, as single-letter options usually also have a
    full word version.)

    '-h' is much more common.

    The "problem" is that you may want to have -h as an option character, especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    Having "-h" as an option for something other than "--help" would be insane.


    The advantage of -? is that is has as non-alpha option not a mnemonic character. (We thus used it since the 1990's even in coding standards
    as our preferred standard way to interrogate usage.)

    Your point that -h may be a file is nonetheless valid, of course, as
    would be a file named -?.

    File names that match "-?" would be any file name that starts with "-",
    and is followed by a single character. So "-x" would match just as well
    as "-?". I don't think it is likely to have such filenames, but it is
    perhaps not /quite/ as unlikely as "-?".

    Both are rather rare though and typically
    the result of an error; especially commands started from the shell
    will report errors and you have to use '--' to create files like -h.

    There are a variety of ways of doing it. The easiest way would be to
    use "./-x" (or "./-h", or whatever).

    The Shell also allows to disable file globbing if that happens to
    appear to be an issue and if you don't want to just quote the -? in
    such (rare) corner-cases with pathological filenames.

    That would be an extraordinary effort to work around poor choices of
    options in a program.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Scott Lurndal on Sun Mar 3 20:20:04 2024
    On Sun, 03 Mar 2024 15:24:29 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html >>
    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    Many thanks for the link too btw.

    Error levels returned:

    3 Option syntax errors
    2 File open-read errors
    1 Dates match today or matching tags
    0 No dates match today or no tags match

    For commands defined by POSIX (and generally in
    unix), an exit status of zero indicates success.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.

    The reason posix commands return zero for success
    is because the posix (and all other shells)
    check the exit status of a command and treat
    non-zero values as failure.

    $ grep 'sigdelset' asim.cpp
    $ echo $?
    1
    $ grep 'sigaddset' asim.cpp
    sigaddset(&signals, SIGHUP);
    sigaddset(&signals, SIGABRT);
    sigaddset(&signals, SIGPIPE);
    sigaddset(&signals, SIGUSR1);
    sigaddset(&signals, SIGUSR2);
    sigaddset(&sa.sa_mask, SIGHUP);
    sigaddset(&sa.sa_mask, SIGINT);
    sigaddset(&sa.sa_mask, SIGQUIT);
    sigaddset(&sa.sa_mask, SIGTERM);
    sigaddset(&sa.sa_mask, SIGXCPU);
    $ echo $?
    0

    if grep -q 'sigaddset' asim.cpp
    then
    echo "Found it!"
    fi

    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    It's not 0/1, it is 0 for success and non-zero for
    failure, where the failure is indicated by the
    exit value (often restricted to 8-bits due to
    the legacy wait(2) system call, however the
    newer (for some value of new) system call waitid(2)
    supports the full 32-bit exit status).

    For example, the grep command returns
    0 - success
    1 - No lines were matched/selected
    1 - An error occurred.

    Some utilities define additional exit status values.

    VMS defined '1' (SS$_NORMAL) as the success return
    value from system calls and commands, which is likely
    the source of that feature in windows.


    Source of what feature in Windows?
    Windows does not care too much about exit code, but to the level it
    does care it follows the same conventions as Unix.

    I've yet to find any feature of windows that is truely
    superior (rather than just different).

    How about F8 in cmd.exe shell?
    Is not it non-trivially better than Crrl-r ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to David Brown on Sun Mar 3 18:42:00 2024
    On 2024-03-03, David Brown <david.brown@hesbynett.no> wrote:
    On 03/03/2024 15:43, Janis Papanagnou wrote:
    On 02.03.2024 23:22, Keith Thompson wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:
    If I may suggest:

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html >>>>>
    '-h' or '-?' have traditionally been used to display
    usage information for an utility.

    Yep, it will definitely be '-?' (still working to finalize things).

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    [snip code sample]

    And most users of Unix-like systems won't expect '-?' to be an option;

    I cannot speak for "most users of Unix-like systems" but my personal
    experience differs.


    Try "cmd -h" and "cmd -?" for a selection of programs on your *nix
    system. You'll find that "-h" will almost invariably give you a brief
    help message.

    Mostly because it's an unrecognized option.

    E.g. gnu grep:

    $ grep -z
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try 'grep --help' for more information.
    !2!
    $ grep -h
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try 'grep --help' for more information.
    !2!

    -h isn't special in this data point.

    There is no convention in POSIX or traditional Unix that -h means
    help.

    The lack of a -h convention is one of the reasons why GNU invented the
    --help option. Plus the problem of the letters having inconsistent
    meanings is also addressed with long option synonyms.

    The GNU Coding Standards document contains a summary of the long
    options used by GNU programs. The idea is that if you're introducing a
    new option, it's a good idea to look here to see if other programs
    already have something with similar semantics, and then use that
    name.

    https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table

    Having "-h" as an option for something other than "--help" would be insane.

    du -h # human-readable sizes

    df -h # human-readable sizes

    ls -h # human-readhable sizes

    free -h # human-readhable sizes

    ps -h # suppress (h)eader.

    grep -h # suppress prefixing of filenames when multiple files saerched.

    rsync -h # human-readable sizes

    Some of these are in POSIX.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Michael S on Sun Mar 3 18:56:55 2024
    Michael S <already5chosen@yahoo.com> writes:
    On Sun, 03 Mar 2024 15:24:29 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:



    I've yet to find any feature of windows that is truely
    superior (rather than just different).

    How about F8 in cmd.exe shell?
    Is not it non-trivially better than Crrl-r ?

    I have no idea what F8 does in cmd.exe.

    Or crrl-r.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Mon Mar 4 02:26:56 2024
    Tim Rentsch ha scritto:
    jak <nospam@please.ty> writes:

    Kenny McCormack ha scritto:

    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:

    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

    I am referring in particular to this part of the equation:
    y + y/4 - y/100 + y/400
    Shouldn't it be calculated in a floating point and then truncated only
    the final result? Because, for example, if the year is 2024, the
    floating point calculation is 2514 (2514.82) while executed between
    integer is 2515.

    The short answer is No. If you try some examples I expect
    you will see that using integer division always gives
    correct results. Leap days always happen in integer amounts,
    so integer division is the right way to calculate them.

    Note: I haven't tested this particular algorithm and so
    cannot vouch for its correctness. But the part that
    determines an extra number of days based on what year
    it is matches other algorithms that I have tested.


    Thank you

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Kaz Kylheku on Mon Mar 4 09:49:43 2024
    On 03/03/2024 19:42, Kaz Kylheku wrote:
    On 2024-03-03, David Brown <david.brown@hesbynett.no> wrote:

    https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table

    Having "-h" as an option for something other than "--help" would be insane.

    du -h # human-readable sizes

    df -h # human-readable sizes

    ls -h # human-readhable sizes

    free -h # human-readhable sizes

    ps -h # suppress (h)eader.

    grep -h # suppress prefixing of filenames when multiple files saerched.

    rsync -h # human-readable sizes

    Some of these are in POSIX.


    You are, of course, entirely correct. Sorry for my complete lack of
    thought there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Malcolm McLean on Mon Mar 4 14:23:03 2024
    On 04/03/2024 11:31, Malcolm McLean wrote:
    On 03/03/2024 17:45, David Brown wrote:


    Having "-h" as an option for something other than "--help" would be
    insane.


    And Baby X resource compiler by yours truly. Write out a C source file,
    but of course there's also an option for a header. And did I just go and
    do that? And I can't remember, and I have to check, and, no, I knew
    about that, and it is "-header" and that only. But it's just so easily
    done.


    Why do you specify -e twice? And why so many options to specify a
    header file?

    [Okay, I'm joking. And, yes, I know it's not funny]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to David Brown on Mon Mar 4 17:27:08 2024
    On 03.03.2024 18:45, David Brown wrote:
    On 03/03/2024 15:43, Janis Papanagnou wrote:

    The "problem" is that you may want to have -h as an option character,
    especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    Having "-h" as an option for something other than "--help" would be insane.

    A strong wording that is completely ignoring the existing tools
    and the (very sensible, and certainly not "insane"!) rationale
    that I - sadly, unsuccessfully, despite being so obvious - tried
    to make clear.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Mon Mar 4 17:34:17 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    Embarrassed to say I know that, but had forgotten it...

    And most users of Unix-like systems won't expect '-?' to be an option;
    '-h' is much more common.

    Can of worms there too, '-h' (or whatever) is valid file name. Under win,
    we also use '/h' which certainly wont work under unix.

    No, there is no chance of '-h' being interpreted as a filename.

    The issue is that _iff_ there is a two character filename in
    the current working directory where the first character of
    the filename is the hypen character, the shell may substitute that
    for '-?' when parsing the command line. E.g if you had a file
    called '-F' in the current working directory, the shell may
    change '-?' (if not quoted) into '-F'.

    Pesonally, I find this highly unlikely in real world. However,
    there are cases where this could be a security issue.

    The C standard, not just POSIX, defines 0 as a successful status.

    POSIX defines 0 as a successful status "for shell commmands", in
    the context of this discussion.

    Unix defines 0 as a successful status for system calls handled
    by the kernel. A non-zero status is accompanied by an updated
    errno (thread-specific when threaded) value.

    strcmp(3) is neither a command nor a kernel call, it's a
    library function and the return value is well documented.

    I refer you to Ralph Waldo Emerson's quote about consistency :-).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Keith Thompson on Mon Mar 4 17:26:21 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    Embarrassed to say I know that, but had forgotten it...

    And most users of Unix-like systems won't expect '-?' to be an option;
    '-h' is much more common.

    Can of worms there too, '-h' (or whatever) is valid file name. Under win,
    we also use '/h' which certainly wont work under unix.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.
    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    The C standard, not just POSIX, defines 0 as a successful status. If
    your program is intended to work on Unix-like systems (or on Windows if
    I'm not mistaken), using a status of 0 to indicate an error will cause problems. Conventions exist for a reason.

    int ok = strcmp(foo, bar);

    if (!ok) then success

    ok == -1 less
    ok == 0 same
    ok == 1 greater

    Hmm, so for someone from a differing OS, things need to be considered.

    Use 0 for success, 1 for unspecified errors, and other positive values
    for more specific errors.

    This is not a problem under win, I've got lots of tools that use
    varying %errorlevels% (unix analog '$?') all processed without
    issue by %comspec% (analog '$SHELL'). No big deal.

    But I'll take your word, here's where I'm at...

    Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]

    -A=NUM Number of days in advance to look ahead (366 max)
    -P=NUM Number of days in the past to look back (366 max)
    -S=NUM Separate date fields using: 1 Slash, 2 Dash, 3 Dot
    -X=NUM Export results as: 1 TXT, 2 CSV, 3 SQL, 4 HTML
    -T=TAG Filter results for 'TAG' (16 characters max)
    -I Use ISO8601 dates: yyyy/mm/dd (default is mm/dd/yyyy)
    -W Include weekday abbreviations
    -H Include holidays (see manual for list)
    -F Include attribute flags (see manual for details)
    -C Display calendar for current year
    -D Debugging enabled
    -M Display embedded user manual

    Error levels returned:

    0 Success
    1 Error

    'debugger' is a simple printf macro that among other things,
    confirms my returns:

    dates -a=30 -d -t="bank note" file

    DEBUG: Exit 1

    I'm getting there, in fact real close.

    Thanks Keith.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Janis Papanagnou on Mon Mar 4 17:34:18 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    The "problem" is that you may want to have -h as an option character, especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    This is my rationale as well: All of the switches have a more/or less
    mnemonic feel -X (eXport), -H (Holiday), -C (Calendar), -M (Manual).

    I thought it made good sense at least.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Mon Mar 4 17:40:05 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    The "problem" is that you may want to have -h as an option character,
    especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    This is my rationale as well: All of the switches have a more/or less >mnemonic feel -X (eXport), -H (Holiday), -C (Calendar), -M (Manual).

    I thought it made good sense at least.

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Janis Papanagnou on Mon Mar 4 18:08:43 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    You haven't provided any evidence or facts of experience.

    Janis, relax. I have nothing to prove to anyone. From
    your remarks it certainly looks like you don't use
    WinAPI much & from that I don't infer you're unintelligent,
    its simply not an area you're familiar with.

    Now apply that same thinking to other folks, in other
    walks of life. You need to slow down with the often
    wrong conclusions...

    Now prove me wrong by not responding with more snark.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Scott Lurndal on Mon Mar 4 18:11:45 2024
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to James Kuyper on Mon Mar 4 18:21:06 2024
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    The lack of nuance is apparently the result of your being unaware of the
    fact that 1 is not the only permitted error return.

    Keep in mind that the make utility and shells designed for Unix-like
    systems (as well as many other programs targeting such systems) expect 0
    for success, and may produce unexpected results if you violate that convention.

    Not at all, what the shell accepts as success under unix, is not the
    same under windows. The convention is OS specific, everyone here tends
    to think only in terms of POSIX & $SHELL & yet, there are other worlds
    out there...

    :: comment

    @echo off & cls

    if %errorlevel% EQU 1000 (

    echo successful as defined by my needs not yours

    )

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Mon Mar 4 18:26:06 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    It does explain why CamelCase never gained traction in Unix.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Scott Lurndal on Mon Mar 4 18:30:44 2024
    On 2024-03-04, Scott Lurndal <scott@slp53.sl.home> wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    It does explain why CamelCase never gained traction in Unix.

    How did it come about in XWindow? Anyone know?

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kaz Kylheku on Mon Mar 4 19:01:29 2024
    Kaz Kylheku <433-929-6894@kylheku.com> writes:
    On 2024-03-04, Scott Lurndal <scott@slp53.sl.home> wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    It does explain why CamelCase never gained traction in Unix.

    How did it come about in XWindow? Anyone know?

    X Windows came from MIT, not AT&T, and long after the
    Teletype had reached obsolescence. They apparently didn't
    mind the extra hassles typing identifiers with mixed case.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Mike Sanders on Mon Mar 4 14:42:53 2024
    On 3/4/24 13:21, Mike Sanders wrote:
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    The lack of nuance is apparently the result of your being unaware of the
    fact that 1 is not the only permitted error return.

    Keep in mind that the make utility and shells designed for Unix-like
    systems (as well as many other programs targeting such systems) expect 0
    for success, and may produce unexpected results if you violate that
    convention.

    Not at all, what the shell accepts as success under unix, is not the
    same under windows.

    I was talking about the problems you would have with ignoring that
    convention on Unix-like systems, which I'm very familiar with, I had no intention of giving advice relevant to other operating systems. The need
    to do different things on different operating systems is part of the
    reason why the EXIT_SUCCESS and EXIT_FAILURE macros exist, but that only scratches the surface of what needs to be done for portability.
    If your program needs to be portable to POSIX systems, it needs to have
    a mode that returns 0 on success, regardless of what it does on any
    other operating system.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Mike Sanders on Mon Mar 4 21:21:25 2024
    On Mon, 04 Mar 2024 17:26:21 +0000, Mike Sanders wrote:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If you
    don't, the behavior depends on the shell and settings.

    Embarrassed to say I know that, but had forgotten it...

    And most users of Unix-like systems won't expect '-?' to be an option;
    '-h' is much more common.

    Can of worms there too, '-h' (or whatever) is valid file name. Under win,
    we also use '/h' which certainly wont work under unix.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.
    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    The C standard, not just POSIX, defines 0 as a successful status. If
    your program is intended to work on Unix-like systems (or on Windows if
    I'm not mistaken), using a status of 0 to indicate an error will cause
    problems. Conventions exist for a reason.

    int ok = strcmp(foo, bar);

    if (!ok) then success

    ok == -1 less
    ok == 0 same
    ok == 1 greater

    Ahhhhh..... no. (CLC has had this conversation before :-) )

    The standard only guarantees that strcmp()
    "returns an integer greater than, equal to, or less than zero"
    but otherwise does not state what value that integer will be.

    So, strcmp() could just as easily return -30 for "less than"
    or +97 for "greater than".

    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument > 0
    */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }

    as in
    int ok = isignof(strcmp(foo, bar));


    Hmm, so for someone from a differing OS, things need to be considered.

    Always.

    HTH
    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Mike Sanders on Tue Mar 5 01:08:24 2024
    On Mon, 4 Mar 2024 18:21:06 -0000 (UTC)
    porkchop@invalid.foo (Mike Sanders) wrote:

    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    The lack of nuance is apparently the result of your being unaware
    of the fact that 1 is not the only permitted error return.

    Keep in mind that the make utility and shells designed for Unix-like systems (as well as many other programs targeting such systems)
    expect 0 for success, and may produce unexpected results if you
    violate that convention.

    Not at all, what the shell accepts as success under unix, is not the
    same under windows. The convention is OS specific, everyone here tends
    to think only in terms of POSIX & $SHELL & yet, there are other worlds
    out there...

    :: comment

    @echo off & cls

    if %errorlevel% EQU 1000 (

    echo successful as defined by my needs not yours

    )


    However all Microsoft-supplied utilities as well as most (all ?)
    built-in commands of their shells , like 'copy' or 'move', follow Unix conventions for exit codes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Lew Pitcher on Tue Mar 5 00:37:23 2024
    On Mon, 4 Mar 2024 21:21:25 -0000 (UTC)
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:

    On Mon, 04 Mar 2024 17:26:21 +0000, Mike Sanders wrote:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I wouldn't use '-?'. The '?' character is a wildcard in most Unix
    shells. If you happen to have a file in the current directory that
    matches the pattern, it will expand to the name of that file. If
    you don't, the behavior depends on the shell and settings.

    Embarrassed to say I know that, but had forgotten it...

    And most users of Unix-like systems won't expect '-?' to be an
    option; '-h' is much more common.

    Can of worms there too, '-h' (or whatever) is valid file name.
    Under win, we also use '/h' which certainly wont work under unix.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.
    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    The C standard, not just POSIX, defines 0 as a successful status.
    If your program is intended to work on Unix-like systems (or on
    Windows if I'm not mistaken), using a status of 0 to indicate an
    error will cause problems. Conventions exist for a reason.

    int ok = strcmp(foo, bar);

    if (!ok) then success

    ok == -1 less
    ok == 0 same
    ok == 1 greater

    Ahhhhh..... no. (CLC has had this conversation before :-) )

    The standard only guarantees that strcmp()
    "returns an integer greater than, equal to, or less than zero"
    but otherwise does not state what value that integer will be.

    So, strcmp() could just as easily return -30 for "less than"
    or +97 for "greater than".

    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument > 0
    */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }


    Too tricky to my liking.
    I'd rather write straight-forward code and let compiler to figure out
    the best sequence.

    int iSignOf(int val)
    {
    if (val < 0)
    return -1;
    if (val > 0)
    return +1;
    return 0;
    }

    https://godbolt.org/z/TzsevxKeE
    https://godbolt.org/z/TzsevxKeE


    as in
    int ok = isignof(strcmp(foo, bar));


    Hmm, so for someone from a differing OS, things need to be
    considered.

    Always.

    HTH

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Scott Lurndal on Mon Mar 4 23:47:49 2024
    Scott Lurndal <scott@slp53.sl.home> wrote:

    POSIX defines 0 as a successful status "for shell commmands", in
    the context of this discussion.

    Sure enough & Keith as well. Cobbled together a simple solution
    just display more informative error messages as well as sticking
    to zero/one. This satisfies scripting in the unix world:

    [ dates -op1 -op2 file || echo no banana ]

    And specific messaging in the windows world (-d is my new debug
    switch):

    C:\type junk.txt

    fubar/5/2024

    C:\dates -op1 -op2 -d junk.txt

    DEBUG: Invalid month field line 1 in file junk.txt

    I refer you to Ralph Waldo Emerson's quote about consistency :-).

    =)

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Lew Pitcher on Mon Mar 4 23:35:12 2024
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:

    int ok = strcmp(foo, bar);

    if (!ok) then success

    ok == -1 less
    ok == 0 same
    ok == 1 greater

    Ahhhhh..... no. (CLC has had this conversation before :-) )

    The standard only guarantees that strcmp()
    "returns an integer greater than, equal to, or less than zero"
    but otherwise does not state what value that integer will be.

    So, strcmp() could just as easily return -30 for "less than"
    or +97 for "greater than".

    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument > 0
    */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }

    as in
    int ok = isignof(strcmp(foo, bar));


    Hmm, so for someone from a differing OS, things need to be considered.

    Always.

    HTH

    Yes sir, it does help in fact, copied to my notes. Lots of brainfood
    from you all, appreciate it =)

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Mike Sanders on Tue Mar 5 00:12:56 2024
    Mike Sanders <porkchop@invalid.foo> wrote:

    [ dates -op1 -op2 file || echo no banana ]

    Make that instead:

    [ cmd ] || failure

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Michael S on Tue Mar 5 00:18:50 2024
    Michael S <already5chosen@yahoo.com> wrote:

    However all Microsoft-supplied utilities as well as most (all ?)
    built-in commands of their shells , like 'copy' or 'move', follow Unix conventions for exit codes.

    Well, maybe not so much in practice as in theory, witness...

    cmd /c exit -1073741510

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Keith Thompson on Tue Mar 5 00:40:08 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    Sure, you can write a script that assumes 1000 indicates success -- but
    it's just as non-idiomatic on Windows as on POSIX systems. (POSIX only supports values from 0 to 255.)

    some_command
    if [ $? = 100 ] ; then
    echo SUCCESS
    else
    echo FAILURE
    fi

    But Windows, like POSIX, has a convention than an exit code of zero
    denotes success, and non-zero denotes an error. The convention probably isn't as hardwired into the system on Windows as it is on POSIX, but
    it's there.

    For example, the documentation for the C# Environment.Exit() function
    says "Use 0 (zero) to indicate that the process completed
    successfully.". Windows cmd (the command that runs batch files) has a special syntax in its "if" statement that tests the value of
    %errorlevel; "if errorlevel 1" is used to test if the errorlevel is 1 or greater, i.e., denotes failure.

    VMS (officially OpenVMS) uses 1 to denote success, which is why exit(0)
    in a VMS C program sets the system status to 1, not 0.

    Interesting stuff. The main thing with me is to (under Windows at least) facilitate an easier way to use my tool in an automated way.

    The GetExitCodeProcess function documentation specifies that the ExitCode
    is a "DWORD 32-bits integer". This means that from cmd.exe point of view (remember, cmd.exe *is the primary interface* or shell under win):

    (emphasis mine)

    *****
    an .exe program may return as %ERRORLEVEL% a value from -2147483648 to 2147483647
    *****

    So... yeah. I mean, I would rather leverage that force multiplier than not.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Mike Sanders on Tue Mar 5 01:27:50 2024
    On 2024-03-05, Mike Sanders <porkchop@invalid.foo> wrote:
    Interesting stuff. The main thing with me is to (under Windows at least) facilitate an easier way to use my tool in an automated way.

    The GetExitCodeProcess function documentation specifies that the ExitCode
    is a "DWORD 32-bits integer". This means that from cmd.exe point of view (remember, cmd.exe *is the primary interface* or shell under win):

    (emphasis mine)

    *****
    an .exe program may return as %ERRORLEVEL% a value from -2147483648 to 2147483647
    *****

    Your reasoning is far from air tight here.

    Consider that on Unix, the exit system call takes an "int". Does that
    mean that any value from INT_MIN to INT_MAX will be passed through
    cleanly as a termination status?

    For monitoring the status of a child process, you can use waitpid.
    Again, that takes a pointer to an int.

    That int is not simply an exit code. It can indicate whether the
    process terminated successfully or abnormally (due to a fatal signal),
    and if abnormally, which signal. There are portable C macros for
    obtaining this information, like WIFEXITED and whatnot.

    In the Microsoft exit code case, the docuumentation says:

    This function returns immediately. If the process has not terminated
    and the function succeeds, the status returned is STILL_ACTIVE (a
    macro for STATUS_PENDING (minwinbase.h)). If the process has
    terminated and the function succeeds, the status returned is one of
    the following values:

    - The exit value specified in the ExitProcess or TerminateProcess
    function.

    - The return value from the main or WinMain function of the process.

    - The exception value for an unhandled exception that caused the
    process to terminate.

    So while you could use any value in the DWORD range, some of the values would be confused for STILL_ACTIVE, STATUS_PENDING, or might look like the
    code of an unhandled exception (I'm guessing 0xCxxxxxxx? Or are therere others). If you don't want to know what all those are, and don't require
    a vast range of exit statuses, your best bet is probably to stick to
    small, nonnegative integers.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Mike Sanders on Tue Mar 5 02:56:48 2024
    On 04.03.2024 18:34, Mike Sanders wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    The "problem" is that you may want to have -h as an option character,
    especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    This is my rationale as well: All of the switches have a more/or less mnemonic feel -X (eXport), -H (Holiday), -C (Calendar), -M (Manual).

    I thought it made good sense at least.

    Yes, of course it does. Most software developers obviously try
    to choose memorable mnemonics. (Imagine we'd have -o1 -o2 -o3
    ..., or -a -b -c ..., as option interface design rules.)

    I wonder, though, my you've chosen letters in caps; I'd avoided
    the additional <shift> key press. (First I thought it might be
    some Windows/DOS restriction or so.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Mike Sanders on Tue Mar 5 03:03:10 2024
    On 04.03.2024 19:08, Mike Sanders wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    You haven't provided any evidence or facts of experience.

    Janis, relax. I have nothing to prove to anyone. [...]

    No, you don't have to. Just expect responses if you're posting
    just opinions based on misconceptions. - But yes, let's relax
    and close that file.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Scott Lurndal on Tue Mar 5 03:09:37 2024
    On 04.03.2024 19:26, Scott Lurndal wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    It does explain why CamelCase never gained traction in Unix.

    You mean in Unix commands, or in the Unix source code, or in
    application source code developed for Unix. - I can just say
    that for the latter we used camel-case. For the Unix sources
    it's probably just a natural evolution to stay with the
    convention used as it started. - But how does is come then
    that there's CPP identifiers typically in all caps...?
    (We're speculating.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Lew Pitcher on Tue Mar 5 03:20:27 2024
    On 04.03.2024 22:21, Lew Pitcher wrote:

    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument > 0
    */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }

    Neat!

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Kaz Kylheku on Tue Mar 5 02:40:45 2024
    Kaz Kylheku <433-929-6894@kylheku.com> wrote:

    Your reasoning is far from air tight here.

    Hey-hey Kaz! But I've got a simple way...

    For monitoring the status of a child process, you can use waitpid.
    Again, that takes a pointer to an int.

    For threaded stuff & children I'm actually not sure. Was under the
    impression that the parent's return value was defacto, YMMV.

    So while you could use any value in the DWORD range, some of the values would be confused for STILL_ACTIVE, STATUS_PENDING, or might look like the
    code of an unhandled exception (I'm guessing 0xCxxxxxxx? Or are therere others). If you don't want to know what all those are, and don't require
    a vast range of exit statuses, your best bet is probably to stick to
    small, nonnegative integers.

    Here's the way I'm handling it (the error code debate), because the app
    I'm working is a subsystem exe (console only in this case as you know),
    I don't have WinMain(), & a confounded message pump (so never need to
    filter WM_CLOSE, WM_DESTROY, etc) no manifest, no packed icons (multiple
    icons are required now - ugh) & all the rest, just plain-jane main() &
    am happily (mercifully?) insulated from several layers of abstraction.
    That & limiting myself to a range, likely the real secret sauce...

    class 3 errors: 300x
    class 2 errors: 200x
    class 1 errors: 100x

    So 3 cheers for subsystem exes' small & quick. but hey, I'm getting close rankling the other guys so I'll let it be.

    Saw your page too at: https://www.kylheku.com/~kaz/

    You're a very creative guy, keep on keepin' on =)

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Keith Thompson on Tue Mar 5 02:43:05 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    Why?

    Sure, assuming %ERRORLEVEL% can really take on any integer value from -2147483648 to +2147483647 (I don't know whether it can), you can write Windows-specific code that takes full advantage of that range.

    Do you really have a requirement to use that full range? Do you have
    several billion distinct error conditions that you want to report? Or
    are you using %ERRORLEVEL% as some kind of counter? You've only shown
    us 4 distinct error conditions for the tool we were discussing.

    On POSIX, "$?" is restricted to the range 0 to 255. Do you really need
    more than 256 distinct status codes? (The most I've seen in any common command is less than 100, for curl, and that's a rather extreme
    outlier.)

    If you don't care about portability to non-Windows systems, that's fine,
    but then there are better places to discuss your requirements.

    The C standard doesn't guarantee more than 0, EXIT_SUCCESS (which is
    usually equal to 0), and EXIT_FAILURE.

    Its no big deal Keith =) I'll let it ride, but earnest thanks for all
    your help.

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Sanders@21:1/5 to Janis Papanagnou on Tue Mar 5 02:49:52 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    I thought it made good sense at least.

    Yes, of course it does. Most software developers obviously try
    to choose memorable mnemonics. (Imagine we'd have -o1 -o2 -o3
    ..., or -a -b -c ..., as option interface design rules.)

    Considering also --gnu-style, might remove some ambiguities
    here & there.

    I wonder, though, my you've chosen letters in caps; I'd avoided
    the additional <shift> key press. (First I thought it might be
    some Windows/DOS restriction or so.)

    Honestly just habit... the options are all case-insensitive
    in the app across all platforms. Still very much, a work in
    progress. I learn, I try new things, I mess up & try again =)

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Michael S on Tue Mar 5 11:41:44 2024
    On Tue, 5 Mar 2024 00:37:23 +0200
    Michael S <already5chosen@yahoo.com> wrote:

    On Mon, 4 Mar 2024 21:21:25 -0000 (UTC)
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:

    On Mon, 04 Mar 2024 17:26:21 +0000, Mike Sanders wrote:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I wouldn't use '-?'. The '?' character is a wildcard in most
    Unix shells. If you happen to have a file in the current
    directory that matches the pattern, it will expand to the name
    of that file. If you don't, the behavior depends on the shell
    and settings.

    Embarrassed to say I know that, but had forgotten it...

    And most users of Unix-like systems won't expect '-?' to be an
    option; '-h' is much more common.

    Can of worms there too, '-h' (or whatever) is valid file name.
    Under win, we also use '/h' which certainly wont work under unix.

    Oh yeah. Have been wrestling with the potential
    consequences of this for a good while. I think I'm
    going leave it as is because, (only speaking for
    myself here) the POSIX 0 good, 1 bad is terrible.
    This is perhaps the only area I've ever seen where
    other OSs, like Windows, have a superior methodology
    on the issue. 0/1 provides next to no nuance. But
    I'm no expert, just my experience.

    The C standard, not just POSIX, defines 0 as a successful status.
    If your program is intended to work on Unix-like systems (or on
    Windows if I'm not mistaken), using a status of 0 to indicate an
    error will cause problems. Conventions exist for a reason.

    int ok = strcmp(foo, bar);

    if (!ok) then success

    ok == -1 less
    ok == 0 same
    ok == 1 greater

    Ahhhhh..... no. (CLC has had this conversation before :-) )

    The standard only guarantees that strcmp()
    "returns an integer greater than, equal to, or less than zero"
    but otherwise does not state what value that integer will be.

    So, strcmp() could just as easily return -30 for "less than"
    or +97 for "greater than".

    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument
    0 */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }


    Too tricky to my liking.
    I'd rather write straight-forward code and let compiler to figure out
    the best sequence.

    int iSignOf(int val)
    {
    if (val < 0)
    return -1;
    if (val > 0)
    return +1;
    return 0;
    }

    https://godbolt.org/z/TzsevxKeE
    https://godbolt.org/z/TzsevxKeE



    I posted the same link twice by mistake. Meant this https://godbolt.org/z/4rcfqrje7

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter 'Shaggy' Haywood@21:1/5 to All on Tue Mar 5 14:07:32 2024
    Groovy hepcat Kaz Kylheku was jivin' in comp.lang.c on Sat, 2 Mar 2024
    02:44 pm. It's a cool scene! Dig it.

    On 2024-03-01, Kenny McCormack <gazelle@shell.xmission.com> wrote:
    int day(d,m,y)
    int d, m, y;
    {
    [...]
    BTW, how long do you think it will be until this thread gets hijacked
    into a long, acrimonious debate about what the definition of the
    first day of the month is and how various cultures define it
    differently, and how

    Pissing on new code using old-style C in 5... 4... 3....

    I'm surprised noone's mentioned this until now.

    --


    ----- Dig the NEW and IMPROVED news sig!! -----


    -------------- Shaggy was here! ---------------
    Ain't I'm a dawg!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter 'Shaggy' Haywood@21:1/5 to All on Tue Mar 5 14:03:40 2024
    Groovy hepcat jak was jivin' in comp.lang.c on Sat, 2 Mar 2024 12:49 pm.
    It's a cool scene! Dig it.

    Kenny McCormack ha scritto:
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

    Hi,
    I am referring in particular to this part of the equation:
    y + y/4 - y/100 + y/400
    Shouldn't it be calculated in a floating point and then truncated only
    the final result? Because, for example, if the year is 2024, the
    floating point calculation is 2514 (2514.82) while executed between
    integer is 2515.

    No. The "+ y/4 - y/100 + y/400" part is adding a day for each leap
    year. You see, a leap year is divisible by 4, but is not divisible by
    100, but is divisible by 400. So, it's adding the number of years
    divisible by 4, subtracting those divisible by 100 and adding those
    divisible by 400 to determine the number of leap days up to the given
    date.
    So often in the last week or two I've heard people (who ought to know
    better) on news programs on telly say that a leap year comes every 4
    years, and I want to beat them about the head with a humorous object of
    some kind until they get this right! A leap year does NOT come EVERY 4
    years.

    --


    ----- Dig the NEW and IMPROVED news sig!! -----


    -------------- Shaggy was here! ---------------
    Ain't I'm a dawg!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to 433-929-6894@kylheku.com on Tue Mar 5 13:30:59 2024
    In article <20240301180259.118@kylheku.com>,
    Kaz Kylheku <433-929-6894@kylheku.com> wrote:
    ...
    Pissing on new code using old-style C in 5... 4... 3....

    Actually, the code in question says (according to the comments) that it
    was written 12/10/99. I suppose even that is fairly modern (by the
    standards of CLC newsgroup regs).

    Obviously, the algorithm goes much further back than that.

    See: https://en.wikipedia.org/wiki/Christian_Zeller

    Julius Christian Johannes Zeller (24 June 1822, Mühlhausen am Neckar ? 31
    May 1899, Cannstatt)

    --
    Modern Conservative: Someone who can take time out from demanding more
    flag burning laws, more abortion laws, more drug laws, more obscenity
    laws, and more police authority to make warrantless arrests to remind
    us that we need to "get the government off our backs".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to Peter 'Shaggy' Haywood on Tue Mar 5 13:19:48 2024
    On 05/03/2024 03:03, Peter 'Shaggy' Haywood wrote:
    Groovy hepcat jak was jivin' in comp.lang.c on Sat, 2 Mar 2024 12:49 pm.
    It's a cool scene! Dig it.

    Kenny McCormack ha scritto:
    In article <urrj5l$124o9$1@dont-email.me>,
    Mike Sanders <porkchop@invalid.foo> wrote:
    Just sharing what I've learned, hope some of you can adapt
    it for your own use.

    Calculates the name of the weekday (Sun, Mon, etc) for the
    1st day of a given month & year...

    https://busybox.neocities.org/notes/get-first-day-of-month.txt

    Here's the guts of my version of the Zeller algorithm:

    int day(d,m,y)
    int d, m, y;
    {
    if (m < 3) {
    m += 12;
    y--;
    }
    return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

    Hi,
    I am referring in particular to this part of the equation:
    y + y/4 - y/100 + y/400
    Shouldn't it be calculated in a floating point and then truncated only
    the final result? Because, for example, if the year is 2024, the
    floating point calculation is 2514 (2514.82) while executed between
    integer is 2515.

    No. The "+ y/4 - y/100 + y/400" part is adding a day for each leap
    year. You see, a leap year is divisible by 4, but is not divisible by
    100, but is divisible by 400. So, it's adding the number of years
    divisible by 4, subtracting those divisible by 100 and adding those
    divisible by 400 to determine the number of leap days up to the given
    date.
    So often in the last week or two I've heard people (who ought to know better) on news programs on telly say that a leap year comes every 4
    years, and I want to beat them about the head with a humorous object of
    some kind until they get this right! A leap year does NOT come EVERY 4
    years.


    For most practical purposes and for the lifetimes of most of the 8
    billion people on the planet, leap years do come every four years.

    That's the case for years 1901 to 2099.

    What exactly do you expect those news readers that reach a massive
    audience to do, get into those details of being divisible or not by 100
    or 400? Maybe they should also mention odd years like 1752 where there
    was a calendar reform for even more exceptions to the rule.

    Half the audience probably barely know what a leap year is.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mike Sanders on Tue Mar 5 15:03:35 2024
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    POSIX defines 0 as a successful status "for shell commmands", in
    the context of this discussion.

    Sure enough & Keith as well. Cobbled together a simple solution
    just display more informative error messages as well as sticking
    to zero/one. This satisfies scripting in the unix world:

    [ dates -op1 -op2 file || echo no banana ]

    One performance note about this.

    '[' does a PATH lookup, finding a utility
    (actually a link to the 'test' utility) followed by fork(2)
    and exec(2)).

    '[[' is built into the shell, so more efficient.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Janis Papanagnou on Tue Mar 5 15:06:46 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 04.03.2024 19:26, Scott Lurndal wrote:
    porkchop@invalid.foo (Mike Sanders) writes:
    Scott Lurndal <scott@slp53.sl.home> wrote:

    As someone who started using unix in an environment where there
    was only one case, I find I prefer lower-case option
    flags, simply because they're easier to type.

    (In the old days, to type upper-case characters on a teletype
    required prefixing each upper-case character with a backslash
    character - and the terminal driver would display uppercase
    with the prefix).

    Wow, chuckle, really made you work hard for the results!

    It does explain why CamelCase never gained traction in Unix.

    You mean in Unix commands, or in the Unix source code,

    Yes, much of which was written on a teletype originally.

    I've seen plenty of camelcase in application code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kaz Kylheku on Tue Mar 5 15:05:19 2024
    Kaz Kylheku <433-929-6894@kylheku.com> writes:
    On 2024-03-05, Mike Sanders <porkchop@invalid.foo> wrote:
    Interesting stuff. The main thing with me is to (under Windows at least)
    facilitate an easier way to use my tool in an automated way.

    The GetExitCodeProcess function documentation specifies that the ExitCode
    is a "DWORD 32-bits integer". This means that from cmd.exe point of view
    (remember, cmd.exe *is the primary interface* or shell under win):

    (emphasis mine)

    *****
    an .exe program may return as %ERRORLEVEL% a value from -2147483648 to
    2147483647
    *****

    Your reasoning is far from air tight here.

    Consider that on Unix, the exit system call takes an "int". Does that
    mean that any value from INT_MIN to INT_MAX will be passed through
    cleanly as a termination status?

    For monitoring the status of a child process, you can use waitpid.
    Again, that takes a pointer to an int.

    POSIX also supports waitid() which does return the entire
    'int' exit code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Bourne@21:1/5 to Janis Papanagnou on Wed Mar 6 20:40:10 2024
    Janis Papanagnou wrote:
    On 04.03.2024 18:34, Mike Sanders wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    The "problem" is that you may want to have -h as an option character,
    especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    This is my rationale as well: All of the switches have a more/or less
    mnemonic feel -X (eXport), -H (Holiday), -C (Calendar), -M (Manual).

    I thought it made good sense at least.

    Yes, of course it does. Most software developers obviously try
    to choose memorable mnemonics. (Imagine we'd have -o1 -o2 -o3
    ..., or -a -b -c ..., as option interface design rules.)

    I wonder, though, my you've chosen letters in caps; I'd avoided
    the additional <shift> key press. (First I thought it might be
    some Windows/DOS restriction or so.)

    From what I've seen, usage help for Windows commands typically shows
    options in uppercase, although they tend to be interpreted
    case-insensitively (just as file names are on Windows). Windows
    utilities also typically use "/" rather than "-" to indicate options (at
    least before PowerShell). So "-x" for a *nix utility would more
    typically be "/X" for a Windows utility (but typing "/x" would also work).

    It's also quite common for Windows utilities to use "/?" rather than
    "/H" to get usage help, which might be where the "-?" idea came from
    (which I think I saw somewhere earlier in this thread).

    Of course, on both platforms, it's up to application code to interpret
    the options passed on the command line. There's nothing to stop a
    Windows utility from using "-x", or a *nix utility using "/X" - and a
    utility ported from one platform to the other might stick with the
    option style from the original platform. Using "/" to indicate options
    on *nix might cause problems for anyone wanting to pass an absolute
    path, though...

    --
    Mark.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Mark Bourne on Wed Mar 6 20:54:56 2024
    Mark Bourne <nntp.mbourne@spamgourmet.com> writes:
    Janis Papanagnou wrote:
    On 04.03.2024 18:34, Mike Sanders wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    The "problem" is that you may want to have -h as an option character,
    especially if your program supports a lot of options and you have no
    creative naming way of choosing another character. (An example from
    one of my recent implementations is using -h for 'height'.[*])

    This is my rationale as well: All of the switches have a more/or less
    mnemonic feel -X (eXport), -H (Holiday), -C (Calendar), -M (Manual).

    I thought it made good sense at least.

    Yes, of course it does. Most software developers obviously try
    to choose memorable mnemonics. (Imagine we'd have -o1 -o2 -o3
    ..., or -a -b -c ..., as option interface design rules.)

    I wonder, though, my you've chosen letters in caps; I'd avoided
    the additional <shift> key press. (First I thought it might be
    some Windows/DOS restriction or so.)

    From what I've seen, usage help for Windows commands typically shows
    options in uppercase, although they tend to be interpreted
    case-insensitively (just as file names are on Windows). Windows
    utilities also typically use "/" rather than "-" to indicate options (at >least before PowerShell). So "-x" for a *nix utility would more
    typically be "/X" for a Windows utility (but typing "/x" would also work).

    Ah, Powershell. The COBOL of scripting languages.

    It's also quite common for Windows utilities to use "/?" rather than
    "/H" to get usage help, which might be where the "-?" idea came from
    (which I think I saw somewhere earlier in this thread).

    In my experience, the '-?' is derived from the getopt(3) semantics
    where it returns the option character '?' for any undefined
    option flags.

    Which means that

    switch (getopt(...)) {
    case '?':
    usage();
    break;
    }

    handles both -? and any undefined flags.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Mar 13 06:01:22 2024
    jak ha scritto:
    bart ha scritto:
    For most practical purposes and for the lifetimes of most of the 8
    billion people on the planet, leap years do come every four years.

    That's the case for years 1901 to 2099.

    What exactly do you expect those news readers that reach a massive
    audience to do, get into those details of being divisible or not by
    100 or 400? Maybe they should also mention odd years like 1752 where
    there was a calendar reform for even more exceptions to the rule.

    Half the audience probably barely know what a leap year is.


    You are right, but this usenet is followed by people, professionals and computer enthusiasts. I would like to try to make a statistics but I
    think at least 70% read somewhere how to determine if a year is a leap.
    I, example, discovered this by writing my first management program in
    Rmcobol almost 40 years ago.

    Instead, I would be curious to understand why nobody follows a standard
    about the dates. Let's take this date for example: January 1, 1580.
    On the web 50% of the sites searched with "day of week calculator" say
    that the day was Tuesday while the others say it was Friday. Excel and
    Calc (OpenOffice) say it was Friday and the same says "cal" on *nix if
    the "--iso" option is not used. So, someone follows the ISO convention
    and others Julian but I read somewhere that the ISO convention had to be followed in the computer scope.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Mar 13 05:40:19 2024
    bart ha scritto:
    For most practical purposes and for the lifetimes of most of the 8
    billion people on the planet, leap years do come every four years.

    That's the case for years 1901 to 2099.

    What exactly do you expect those news readers that reach a massive
    audience to do, get into those details of being divisible or not by 100
    or 400? Maybe they should also mention odd years like 1752 where there
    was a calendar reform for even more exceptions to the rule.

    Half the audience probably barely know what a leap year is.


    You are right, but this usenet is followed by people, professionals and computer enthusiasts. I would like to try to make a statistics but I
    think at least 70% read somewhere how to determine if a year is a leap.
    I, example, discovered this by writing my first management program in
    Rmcobol almost 40 years ago.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Michael S on Thu Mar 14 15:57:54 2024
    Michael S <already5chosen@yahoo.com> writes:

    On Mon, 4 Mar 2024 21:21:25 -0000 (UTC)
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
    [...]
    If you want to /guarantee/ that the return value of strcmp()
    is -1, 0, or +1 (for "less than", "equal to", or "greater than")
    you will have to process the return value with something like

    /*
    ** Returns -1 if argument < 0, 0 if argument == 0, 1 if argument > 0
    */
    int iSignOf(int valu)
    {
    return ((valu > 0) - (valu < 0));
    }

    Too tricky to my liking.
    I'd rather write straight-forward code and let compiler to figure
    out the best sequence.

    int iSignOf(int val)
    {
    if (val < 0)
    return -1;
    if (val > 0)
    return +1;
    return 0;
    }

    I've seen the idiomatic form before, and my reaction to it is
    more of it being overly cute than overly tricky. That said,
    it is a bit on the tricky side; even so, I'm not sure the cure
    suggested is much better than the disease. I would simply write
    a single return statement:

    return val < 0 ? -1 : val > 0 ? 1 : 0;

    (possibly condensed to take advantage of the 0/1 result of the
    "greater than" operator for non-negative operands).

    I suppose some people prefer the multiple return form to the ?:
    form, although I'm not sure why except perhaps as a carryover
    from earlier experience.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Keith Thompson on Thu Mar 14 19:56:21 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    jak <nospam@please.ty> writes:

    [about different date formats]

    So, someone follows the ISO convention and others Julian but I
    read somewhere that the ISO convention had to be followed in the
    computer scope.

    Where did you read that? ISO has no police force. [...]

    Note that there are organizations that mandate compliance with
    some ISO standards under certain circumstances even though the
    organizations themselves have no direct relationship with ISO.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)