× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'm having problems with a program that was written using opendir and
closedir. This program is run every 4 minutes, We are opening one
directory at a time when it can't open it is creates a dump. The
problem is when it dump it continues to dump every 4 minutes and never
process the information the program was intending to process. It seems
to start dumping at dump3 and then every time it runs it dumps at all
dump commands. Below is the code can some one give me advice. I don't
mind that it dumps but it should keeping dump every time is dumps. It
seems something is not getting reset prior to running again.

// Open upload directory -- must go through path one directory at a
CurrentDir = '/transfer/WMS/Upload/MAPICS/';
Dir = opendir('/transfer');

// in the case of errors, the program will retrieve the error numbe
// and description and create a dump.
If Dir = *null;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump1';
Endif;

Dir = opendir('/transfer/WMS/');
If Dir = *null;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump2';
Endif;

Dir = opendir('/transfer/WMS/Upload/');
If Dir = *null;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump3';
Endif;

Dir = opendir('/transfer/WMS/Upload/MAPICS/');
If Dir = *null;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump4';
Endif;
// read first file in directory
p_dirent = readdir(Dir);

Dow p_dirent <> *null;

//retrieve file name
DataFile = %subst(d_name:1:d_namelen);
If %trim(DataFile) <> '.' and %trim(DataFile) <> '..';
OpenDirWithFile = %trim(CurrentDir) + %trim(Datafile);

// set flags and open file (read only, exclusive open, text dat
flags = O_RDONLY + O_SHARE_NONE + O_TEXTDATA;
FDCurrent = open(OpenDirWithFile : flags);

// FDCurrent will be -1 if there is an open error on the file
// it will contain a pointer value if it is successful
If FDCurrent < 0;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump5';
endif;

// Open file
If FDCurrent >= 0;

// retrieve file name without extension
//Position = 0;
//Position = %scan(CurExt : Datafile : 1);

// create new file name for history
//NewFile = %subst(Datafile:1:Position - 1) + NewExt;
NewFile = Datafile;

// create path and file name to write to history directory
HistoryFolder = '/transfer/WMS/Upload/MAPICS.SAVE';
Path = %trim(HistoryFolder) + '/' + %trim(Newfile);

// set file usage (create if not created, read/write, clear)
Flags = O_CREAT + O_WRONLY + O_TRUNC + O_TEXTDATA;

//set file authority (open to everyone)
Mode = S_IRWXU + S_IRWXG + S_IRWXO;

// create file in new directory
NewfileD = Open(%trimr(path) : flags : mode);

// retrieve record count, close file if error cuz won't be a
If fstat(FDCurrent : %addr(FileStat)) < 0;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump6';
callp close(FDCurrent);
EndIf;


// set data structure to value that is pointed to by FileSta
p_statds = %addr(FileStat);

// retrieve record count by dividing file size by record siz
Recordcount = st_size / %size(rddata);

// set number of reads to record count and goto pos of next
For Recno = 1 to RecordCount;
pos = (recno - 1) * %size(rddata);
callp lseek(FDCurrent : pos : SEEK_SET);

// set file data to Upload data structure (RecLen is a va
// just contains the length of the record written to Uplo
RecLen = read(FDCurrent : %addr(upload) : %size(upload));
If RecLen < 1;
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump7';
callp close(FDCurrent);
EndIf;

// save data to variable to write to history file
%subst(WriteData:1:%size(Upload)) = Upload;

// write the record to the mapics file
Callp WriteTofile();

// write data to history file
If write(NewFileD:%addr(WriteData):%size(WriteData))
< %size(WriteData);
error_p = strerror(errno);
errmsg = %str(error_p);
dump 'dump8';
callp close(FDCurrent);
EndIf;

Endfor;

// close current file
callp close(FDCurrent);

// delete file from current directory
Callp Unlink(OpenDirWithFile);

// close history file
callp close(NewFileD);
Endif;
Endif;

// read next file in directory
p_dirent = readdir(Dir);

Enddo;

callp closedir(Dir);
*inlr = *on;
Return;

/end-free

Steve Seroogy
Business Analyst
Phone: (262) 544-4811 x2734
Fax: (262) 968-9372

Generac Power System, Inc
Hwy 59 and Hillside Road
Waukesha, Wisconsin 53187



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.