Kornshell convdate

Hello,

I'm currently doing some programming using the Kornshell environment. I have just been on a Unix course where our instructor gave us some coding examples. I am using one of these examples to solve a few problems.

However, the code examples use a function called 'convdate' to convert a date into seconds since 1970. I do not have this function on this version of Unix. I have looked on the internet and found that it is a common function to have.

Please could someone advise me as to where to get a copy of this function from. How to install it on Unix so I (and preferably my other 3 programming colleagues) can see and use it.

Any help will be much appreciated.

Thanks.

nezster,

At the bottom of every page is a link to our rules. Please reread the last sentence of rule number 4. Excuse me while I go mop up your mess. :stuck_out_tongue:

Sorry.

Needed a quick reply and didn't know which forum to ask in.

Apologies

Looking in google for convdate.c, I found this.

Thanks.

However... I found that code and tried it out but got errors regarding the 'extern' keyword.

A few details like what system, what compiler, and what error message would help. But maybe we can solve this anyway.

You need to look at your man page for the getopt function. This will probably be in section 3 of the manual.

man -k getopt
should show all the getopt pages.

man -s3 getopt
or
man 3 getopt
should bring up the page. Look at the page under "synopsis" to see what include file your getopt uses. Add that in. On SunOS it's

#include <stdlib>

Thankyou for your continued help.

Below is the contents of the man file you advised... Is it the libc.a file I need to use? Do I replace all the extern code in the code example you gave me with this file?

I am using an older version of Unix (according to the boss) the version info I have is... IBM RS6000 F50 - AIX Version 4.3.3.

-------------------------------------------------------------------------------
Base Operating System and Extensions Technical Reference, Volume 1
-------------------------------------------------------------------------------

getopt Subroutine

Purpose

Returns the next flag letter specified on the command line.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>

int getopt (ArgumentC, ArgumentV, OptionString)

int ArgumentC;

char *const ArgumentV [ ];

const char *OptionString;

extern int optind;

extern int optopt;

extern int opterr;

extern char *optarg;

Description

The optind parameter indexes the next element of the ArgumentV parameter to be
processed. It is initialized to 1 and the getopt subroutine updates it after
calling each element of the ArgumentV parameter.

The getopt subroutine returns the next flag letter in the ArgumentV parameter
list that matches a letter in the OptionString parameter. If the flag takes an
argument, the getopt subroutine sets the optarg parameter to point to the
argument as follows:

o If the flag was the last letter in the string pointed to by an element of
the ArgumentV parameter, the optarg parameter contains the next element of
the ArgumentV parameter and the optind parameter is incremented by 2. If the
resulting value of the optind parameter is not less than the ArgumentC
parameter, this indicates a missing flag argument, and the getopt subroutine
returns an error message.
o Otherwise, the optarg parameter points to the string following the flag
letter in that element of the ArgumentV parameter and the optind parameter
is incremented by 1.

Parameters

ArgumentC Specifies the number of parameters passed to the routine.

ArgumentV Specifies the list of parameters passed to the routine.

OptionString Specifies a string of recognized flag letters. If a letter is
followed by a : (colon), the flag is expected to take a parameter that may or
may not be separated from it by white space.

optind Specifies the next element of the ArgumentV array to be processed.

optopt Specifies any erroneous character in the OptionString parameter.

opterr Indicates that an error has occurred when set to a value other than 0.

optarg Points to the next option flag argument.

Return Values

The getopt subroutine returns the next flag letter specified on the command
line. A value of -1 is returned when all command line flags have been parsed.
When the value of the ArgumentV [optind] parameter is null, *ArgumentV [optind]
is not the - (minus) character, or ArgumentV [optind] points to the "-" (minus)
string, the getopt subroutine returns a value of -1 without changing the value.
If ArgumentV [optind] points to the "- -" (double minus) string, the getopt
subroutine returns a value of -1 after incrementing the value of the optind
parameter.

Error Codes

If the getopt subroutine encounters an option character that is not specified by
the OptionString parameter, a ? (question mark) character is returned. If it
detects a missing option argument and the first character of OptionString is a :
(colon), then a : (colon) character is returned. If this subroutine detects a
missing option argument and the first character of OptionString is not a colon,
it returns a ? (question mark). In either case, the getopt subroutine sets the
optopt parameter to the option character that caused the error. If the
application has not set the opterr parameter to 0 and the first character of
OptionString is not a : (colon), the getopt subroutine also prints a diagnostic
message to standard error.

Examples

The following code fragment processes the flags for a command that can take the
mutually exclusive flags a and b, and the flags f and o, both of which require
parameters.
#include <unistd.h> /Needed for access subroutine constants/

main (argc, argv)

int argc;

char **argv;

{

int c;

extern int optind;

extern char *optarg;

.

.

.

while ((c = getopt(argc, argv, "abf:o:")) != EOF)

{

  switch \(c\)

  \{

     case 'a':

        if \(bflg\)

           errflg\+\+;

        else

           aflg\+\+;

        break;

     case 'b':

        if \(aflg\)

           errflg\+\+;

        else

           bflg\+\+;

        break;

     case 'f':

        ifile = optarg;

        break;

     case 'o':

        ofile = optarg;

        break;

     case '?':

        errflg\+\+;

  \} /* case */

  if \(errflg\)

  \{

     fprintf\(stderr, "usage: . . . "\);

     exit\(2\);

  \}

} /* while */

for ( ; optind < argc; optind++)

{

  if \(access\(argv[optind], R_OK\)\)

  \{

     .

     .

     .

  \}

} /* for */

} /* main */

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The getopt command.

Post the exact command that you are using to compile the code. Post the exact text of any results that you get.

I don't have access to an AIX system. But I've tried that code with 4 compilers on two different OS's and I can't get it to fail.

Your include file would seem to be:
#include <unistd.h>
But's that the case on HP-UX too. HP-UX compiles it because the other include files seem to bring it in. I also did not need to add an include file on SunOS.

You might give that a try though. Look at the the top of the program. Right after the comment comes the include files. There are three lines that start out "#include". You need to add a fourth line.

But I'm thinking that you have some other problem.

Hmmmm, this is where my newbie Unix experience begins to show. Sorry about this. I thought I could copy the code from the internet, use vi to create a file called convdate, paste in the code and change the file properties to become executable. This file will be in the same directory as the script that I'm running.

I guess this is very wrong. Any advise would be welcome.

Very wrong would be an understatement. I don't know AIX so I can't help you keystroke by keystroke. But in general you need to copy the code from the internet and create a file called convdate.c. Then you need to to compile that into an executable. Maybe your compiler is called "cc" and maybe it's on your PATH. Try this:

cc convdate.c -o convdate

If that works, great! Otherwise, you will need to find an AIX expert.

Thanks for the advice. Had a feeling I was way off track.

Think the code you gave me would work. Tried typing cc and got the message that I don't have execute permissions.

Think I might be out of my league now. I am only a standard user on the system. However, being a VB programmer with a very weekly manual process I thought I could automate it. Went on a Unix course before christmas and it looked quite straightforward. Little did I know our version of Unix wouldn't have convdate nor does it have a personal cron file. I very much doubt I'll have access to the system cron so I might just give up. Good bit of tinkering whilst the office is quiet over the christmas period.

Looks like I won't be able to compile the convdate function code. Think I might just give up.

Sound good to you? Feel free to convince me otherwise! Beginning to feel that my VB is much much easier!