She basically deals with command line options like so:
while ((ch = getopt(argc, argv, "rchtf")) != -1)
switch (ch) {
case 'r':
rflag = 1; /* read log, like tail */
break;
case 't':
tflag = 1; /* read top of log like head */
break;
case 'f':
fflag = 1; /* log to a diffrent file */
break;
When ever a switch is "On" or "1" we perform an action. When no switches are given we fscanf stdin into a str[256] char array. This is more then enough space and shouldn't be to memory hungry for right now. Input is taken until a new line is given then we store it in the char array and fprintf it into our logfile + a newline. I toyed around with trying to resize str to match stdin should str be to small, so we could avoid a segfault when trying to write huge entries. Yet allow no major limit on entry size. That nett'd me a good junk pointer warning I'm sure not able to find out all the details of.
Right now I'm working on trying to get the t switch working using the source for the head command as a reference. So far no real luck, we never get any output from it. It seems to break apart in the line of execuition so I know I've got to change things around.
I know I could just pass things along to head and tail via sh, but what is the fun in that? I'll figure this out later must sleeeeeeeeeeeeppp!!!!
/* I don't do HTML ! */
No comments:
Post a Comment