Subject: Newbie C questions
From: " Clark Sims " <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Tue, 24 Aug 1999 06:32:32 -0700

I have written a program for paging. Neither the 
more pipe nor the pg pipe work on my machine. The
program mypg is ment to replace these programs that
I don't have. The code compiles and runs fine when
I use the Watcom compiler, but I can't get it to
compile with the Cygnus port of GCC. The include
file conio.h is not being found. conio.h exists
in one of the subdirectories of Cygnus, but GCC
can't find it. I have tried including it with the
-i switch on the command line (I think this is correct,
bug I don't know, I still haven't received my 
documentation from the FSF)

Attached are two files, mypg.c and compile.bat

I would be very greatful if someone could show me how
to get this to compile and link.

Thanks in Advance,

Clark Sims

--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.

#include <stdio.h>
#include <string.h>
#include <conio.h>

void append_input( const char *npt, char *pg, int ln, int mxln, int mxwdth);
/*
assumes: 
   ln > 0
   mxwdth > 0
   strlen( npt) < mxwdth
   ln < mxln
   npt can't contain a newline character
changes:
   characters between pg[ln*mxwdth] and pg[ln*mxwdth+strlen(npt)]
description:
   appends npt to pg, at line ln
*/

void dump_input( const char *pg, int nmln, int mxln, int mxwdth, int wait);
/*
assumes:
   mxln >= nmln  > 0
   pg contains vallid null terminated strings, with a stride of mxwdth
changes:
   stdout
description:
   this dumps pg to stdout
   if wait is true, than getch is called, which causes
   the program to pause untill a key is hit from the keyboard
*/
 
#define MAXWIDTH 258

char input[MAXWIDTH+1];

const char *_usage = "usage: mypg [-p=25]\n";
int main( int argc, const char* argv[])
{
int p=25, i;
char *pg, *pinput;

if (argc > 1)
{
  if (argc!=2)
    {
      goto usage;
    }
  if (memcmp( argv[1], "-p=", 3) != 0)
    {
      goto usage;
    }
  p = atol( argv[1]+3);
  if (p<=0)
    {
      printf( "p must be > 0\n");
      goto usage;
    }
}
  
pg = (char *)malloc( p*MAXWIDTH);
if (pg==NULL){
  printf( "out of memory\n");
  return 2;
}

i = 0;
do {
  input[0] = 0;
  pinput = gets( input);
  
  if (pinput != NULL || input[0]!=0)
    {
      append_input( input, pg, i, p, MAXWIDTH);
      i++;
    }
    
  if (i%p == 0 || pinput==NULL)
    {
      dump_input( pg, i, p, MAXWIDTH, pinput!=NULL);
      i = 0;
    }
} while (pinput != NULL);
      
return 0;

usage:

printf( _usage);

return 1;
}

void append_input( 
   const char *npt, 
   char *pg, 
   int ln, 
   int mxln, 
   int mxwdth)
{
char *funcname = "append_input";	
long nptlen;

if (npt==NULL)
   {
      printf( "npt==NULL in %s\n", funcname);
      exit( 1);
   }

if (pg==NULL)
   {
      printf( "pg==NULL in %s\n", funcname);
      exit( 1);
   }

if (ln < 0)
   {
	   printf( "ln<= in %s\n", funcname);
	   exit( 1);
   }

if (mxln < 0)
   {
	   printf( "mxln<= in %s\n", funcname);
	   exit( 1);
   }

if (mxwdth < 0)
   {
	   printf( "mxwdth<= in %s\n", funcname);
	   exit( 1);
   }

nptlen = strlen( npt);

if (nptlen >= mxwdth)
   {
      printf( "strlen(input) > maxwidth in %s\n", funcname);
      exit( 1);
   }
   
strcpy( pg+ln*mxwdth, npt);

}    

void dump_input( 
   const char *pg, 
   int nmln, 
   int mxln, 
   int mxwdth, 
   int wait)
{
int i;

if (nmln > mxln)
  {
    printf( "error, nmln > mxln in dump_input\n");
    exit( 1);
  }

for (i=0;i<nmln;i++)
  {
    puts( pg+i*mxwdth);
  }
  
fflush( NULL);

if (wait)
   {
      getch();
   }
}

--
Want to unsubscribe from this list?
Send a message to [email-masked]