From: slitel@netcom.com (Stuart Litel)
Subject: read ascii in Informix
Newsgroups: comp.databases.informix

Here is a program I have been using for a few years that will read an
ascii file in Informix.  It is 'c' code with a sample of the Informix
'4gl' code needed to run it.

Have Fun

Stuart Litel
slitel@netcom.com

------ cut here-----
/*From: slitel@netcom.com */

/* fileio.c for use with 4gl*/gl*/
/* 

Many people have looked for 'c' code to link into informix to read
an ascii file.  A few years back a friend of mine wrote this for me
for which I still use today.  The file has three main functions:

openfile: usedx to open the ascii file on disk
getline : used to retrieved a line of code one at a time
closefile : used to close the ascii file.

Sample Infromix code to use this program:

function read_ascii()
	define errcode		smallint
	define txt		char(200)
	define len		smallint
	define file_name	char(80)


	let file_name = "myfile"
	let len = length(file_name)
	call openfile(file_name, len) returning errcode
	if (errcode != 0) then
		error "We could not open the file: ", file_name
	else
		while true
			call getline() returning txt, errcode
			if (errcode != 0) then
				call closefile()
				exit while
			else
				display txt clipped	#my text from the file
			end if
		end while
	end if
			
end funciton
	
*/


#include <stdio.h>

static FILE *in_fp,
            *out_fp;

openfile(n)
int n;
{
  char filename[81];
  int len;

  popquote(iomode, 2); /* get the read/write mode */
  popint(&len); /* get the read/write mode */
  popquote(filename, len+1); 

  iomode[0] = tolower(iomode[0]);

    retint(((in_fp = fopen(filename,'r')) != NULL));

  return(1);                                     /* 0 if didn't get file */
}

getline(n)
int n;
{
  char line[201];
  int len;

  if(fgets(line,201,in_fp)!=NULL) {   /* no EOF yet */
    len = strlen(line);
    line[len-1]=0; /* get rid of linefeed */
    retquote(line);
    retint(0);
  }
  else {
    retquote("");
    retint(1);
  }
  return(2);
}

closetext(n)
int n;
{
	fclose(in_fp);
	fclose(out_fp);
  	return(0);
}


---- cut here ------
