F

<< Click to Display Table of Contents >>

Navigation:  Concordance Programming Language Reference > Functions >

F

The following topic discusses the Concordance Programming Language (CPL) functions that begin with the letter F. For more information on CPL functions, see Functions, About the Advanced Programming Features, and About CPL Functions.

FindFirst

text findfirst(text fileMatch; int attribute);

Description - Locates the first matching file name for the fileMatch string parameter that has matching file attributes. All DOS wildcards are valid.

oThe attribute parameter specifies DOS file attributes that are included in the search. They include:

0  Normal files - no read/write restrictions.

1  Read only files.

2  Hidden files.

4  Systems files.

8  Volume ID file.

16  Subdirectory.

32  Archived file.

oThe file attributes can be or'ed together to find various file types. For example: findfirst("C:\*.*", 1 | 2 | 4);

Return Value - The name of the first file found that matches the file specification string and the attribute value.

See Also - findnext()

Example

main()

{

char f[128];

 /* Erase all matching files. */

 for(f=findfirst("\*.TMP",0); f[0]<>0; f=findnext())

  erase(f);

}

 

FindLine

int findline(text line; int offset, length);

Description - Locates a line of text which contains the character at "offset" bytes from the beginning. The line is terminated by an end-of-line character. The end-of-line character is handled internally to Concordance and may not be compatible with other programs.

oThe "line" parameter can be a database field, a character array, or a text variable. It cannot be a numeric or date formatted field, or a numeric variable.

oText begins with character 1. An 11 character char array would contain characters at offsets 1 through 11, though it would be indexed with values 0 through 10.

Return Value - Returns the offset into the text variable where the line begins, the length entry will contain the length of the line. The length is only for the text on the line, it does not include the end-of-line terminator.

oIf the line isn't found, the field is empty, or offset is out of range, then findline will return 0 and length will be undefined. Remember that a length of 0 is legal since some lines may be empty.

See Also - findpline(), findnline()

Example

main()

{

int file, i, width, db;

 /* Open the printer as a file. */

 if ((file = open("prn","w")) == -1) {

  puts(0,0,"Couldn't access printer.");

  return;

 }

 /* Open a database for business. */

 if ((db = opendb("c:\concord\research")) < 0) {

  puts(0,0,"Couldn't open the database.");

  close(file);

  return;

 }

 /* Find and print every line in the */

 /* note field that mentions stock. */

 i = match(db->NOTE,"stocks",1);

 while (i > 0) {

  i = findline(db->NOTE,i,width);

  writeln(file,substr(db->NOTE,i,width),width);

  /* Look for next hit in the next line. */

  i = match(db->NOTE,"stocks",i+width);

 }

 /* Close all files before exiting. */

 close(file);

 closedb(db);

}

 

FindNext

text findnext();

Description - Locates the name of the next matching file first located using findfirst().

Return Value - A file name, or an empty string if no file name is available.

See Also - findfirst()

Example

main()

{

char f[256];

 /* Erase all matching files. */

 for(f=findfirst("\*.TMP",0); f[0]<>0; f=findnext())

  erase(f);

}

 

FindNLine

int findnline(text line; int offset, length);

Description - Locates the next line of text following the line indicated by offset. Offset is an index into the field, text variable, or character array.

Return Value - findnline() returns the offset of the first character in the next line or 0 if there isn't a following line. Length will contain the length of the line when the function returns.

See Also - findline(), findpline()

Example

/* Print every line in the text field to file.

** Watch for disk full errors in writeln(). */

PrintField(int db, i, fh)

{

int offset, length;

int error;

 

 /* Wrap the field to fit in 40 columns. */

 /* Get the offset of the first line. */

 /* Enter the loop, print the line, then */

 /* continue writing lines until there */

 /* aren't any left to process. */

 wrap(db->i, 40);

 offset = findline(db->i,1,length);

 while((offset > 0) and (error == 0)) {

  if(writeln(fh,addr(db->i,offset),length)<length)

   error = 1;

  offset = findnline(db->i, offset, length);

 }

 return(error);

}

 

FindPLine

int findpline(text line; int offset, length);

Description - Locates the line of text preceding the line indicated by offset. Offset is an index into the field, text variable, or character array.

Return Value - The value of findpline() is the offset of the first character of the preceding line, or 0 if there is no preceding line. The length parameter will contain the length of the preceding line.

See Also - findline(), findnline()

Example

/* Scan up several lines in the field.

** Returns offset of the nth line above or

** a 0 if there aren't enough lines.

*/

scanup(int db, i, offset, lines)

{

int length;

 while((offset > 0) and (lines > 0)) {

  lines = lines - 1;

  offset = findpline(db->i, offset, length);

 }

 return(offset);

}

 

First

int first(int db, document, field, offset);

Description - Reads the first document in the current query. If no query exists, the first document in the database is used.

oThe variables document, field, and offset are optional. If one or more are provided, they will contain the document's number, the field number that contains the search word, and the offset into the field where the word occurs. The document number is the relative document number in the query, not the physical document number in the database. For instance, the 100th document in the database may be the first in the query. In this case the value of the document variable after issuing a first() would be 1.

oUse the recno() function to get the physical document number.

Select queries, and query 0, will return 0's for the values of field and offset. Mixing select and search mode queries will result in some values for field and offset containing 0's within the retrieved query set.

Return Value - Returns the physical document number of the first document retrieved in the query. Returns a value less than or equal to zero if the query or database is empty, or if document could not be read.

See Also - last(), next(), nexthit(), prev(), prevhit(), count(), docno(), hits()

 

Func

text func(int level);

Description - Returns the name of the currently executing function, and all previous call functions. Level is a number determining which function name is returned. Level 0 returns the name of the current function, level -1 returns the name of the function that called the current function, level -2 returns the name of the function two functions back, and so on.

Return Value - The name of a currently executing function, or an empty string if the level parameter is out of range.

Example

/* Display the names of all functions

** (currently called) on the screen.

*/

ListFunctions()

{

int con, i;

 

 if ((con = open("con","w")) >= 0) {

  for(i = 0; string = func(i); i = i - 1)

   writeln(con,string,len(string));

  close(con);

 }

}

 

Fuzzy

int fuzzy( int db,

text szWord,

text szDestination,

int certainty, flag);

Description - This function locates words that match the szWord parameter either in spelling or sound. The matches are placed in a file, whose name and path is provided in szDestination. Concordance will append to the file if it exists. certainty is the percent of a match for spelled-like words. A value of 70 (70%) or higher is recommended.

oThe following flag parameters are integer values that are predefined for you. Do not declare them. Do not pass them in quotes. Never assign values to them. Simply use them. They can be or’ed together with the | operator to combine functions.

Flag Parameter

Function

CPLSOUNDSLIKE

Retrieves words that sound like the passed szWord parameter. Concordance uses a sounds-like algorithm similar to soundex.

CPLSPELLEDLIKE

Retrieves words that are spelled like szWord. This takes longer than a sounds-like search. The certainty parameter is used to determine if a word has similar spelling.

CPLSYNONYMSORT

Words are returned with the best matches first.

CPLSYNONYMS

Words are returned in quotes.

Return Value - Returns a count of the words found to match the passed parameter.

Version - Version 7.30 and later.