Method and system for processing fields in a document processor5552982Abstract A method and system for providing calculated fields in a document processing environment. A calculated field comprises a beginning field character, a field code, and an ending field character. The field code specifies a behavior of the calculated field. A user may insert a calculated field into a document. After insertion, the result of the calculated field can be determined based on the behavior specified by the field code. The result of the calculated field is then stored within the document and preferably within the calculated field. The document can be displayed in either field code or results mode. In field code mode, when the document is displayed, the calculated field is displayed (i.e., beginning field character, field code, and ending field character). In results mode, when the document is displayed, the result is displayed, rather than the calculated field. Claims We claim: Description FIELD OF THE INVENTION
______________________________________
Field Codes Arguments
______________________________________
foo bar foo
bar
"foo bar" foo bar
"foo .backslash." bar"
foo " bar
.backslash."Joe.backslash."
"Joe"
"John .backslash."Johnny.backslash.""
John "Johnny"
.backslash..backslash. .backslash."
.backslash.
"
abc"def"ghi abc
def
ghi
foo "" bar foo
(empty string)
bar
______________________________________
In the preferred practice of the present invention, fields can be nested, up to a pre-selected limit, such as twenty deep. The only restriction on nesting is that the keyword for a field cannot be a nested field. Any argument can be a nested field. If there is a nested field in an argument or switch, the result of the nested field will be used to evaluate the enclosing field. A field nested within field codes is treated as a single argument or switch, regardless of the presence of spaces or quotes in the result of the nested field. It is also considered to be exactly one argument, unless it is "grouped" by using quotes. For example, the nested fields {date}{time} are considered to be two arguments: the result of the date field and the result of the time field. Whereas, the nested fields "{date}{time}" are considered to be one argument-the concatenation of the date field and the result of the time field. Except inside quotes or to separate arguments, white space characters are always ignored in field codes. Thus, a field could be formatted as:
______________________________________
{
if appname = "Opus"
"This is the true text."
"This is the false text."
}
______________________________________
A field may contain one or more switches. A switch indicates that behavior other than the default is desired for this field. System switches are defined for all fields. In addition, a field type may specify its own switches. A switch may be defined to take a switch argument. If so, the switch argument is immediately following the switch. A space between a switch and its switch argument that follows is optional. In one implementation, a field preferably can contain up to at least ten system and ten field specific switches. Additional switches will be ignored. If a backslash character in the field codes is followed by a character that is not a valid switch identifier, that character is part of the argument. For example, the field {quote.backslash.q.backslash..backslash.foo.backslash.b.backslash."} has one argument q.backslash.foo" assuming that q, .backslash., b, and " are not valid switch identifiers. Inside quotes, the backslash character is stripped out and ignored. For instance, .backslash..backslash. results in .backslash. and .backslash." results in ". The field codes of a field may contain hidden text. If the beginning field character ("{") is hidden, then the hidden text in the remainder of the field codes will be used when parsing the field codes. If the beginning field character is not hidden, then any hidden text within the field codes will not be used when parsing the field codes. This provides a means to annotate the field. When displaying a file containing a field, the present invention determines the appropriate portion of the field to display according to whether the user has selected field code mode or result mode. During a generate operation, for each field in the text stream, the field processing algorithms of the present invention are invoked. The result of each field may be generated and updated in a user invoked update operation, whenever a file containing fields is printed, during a print merge operation, or during periodic automatic updates. Typical field types and keywords are set forth in Table 1. TABLE 1 1. Cross-Reference of text within document (REF) 2. Index Entry (XE) 3. Footnote reference cross reference (FTNREF) 4. Set bookmark to value (SET) 5. Conditional selection of text (IF) 6. Index generation (INDEX) 7. Table of contents entry (TC) 8. Last text of style cross reference (STYLEREF) 9. Referred-to-document for Index and TOC (RD) 10. User defined sequence and sequence cross reference (SEQ) 11. Table of Contents and Tables of other things (TOC) 12. Document Information (INFO) (see fields that follow) 13. Document Title (TITLE and INFO TITLE) 14. Document Subject (SUBJECT and INFO SUBJECT) 15. Document Author (AUTHOR and INFO AUTHOR) 16. Document Keywords (KEYWORDS and INFO KEYWORDS) 17. Document Comments (COMMENTS and INFO COMMENTS) 18. Document last saved by (LASTSAVEDBY and INFO LASTSAVEDBY) 19. Document create date (CREATEDATE and INFO CREATEDATE) 20. Document last saved date (SAVEDATE and INFO SAVEDATE) 21. Document last print date (PRINTDATE and INFO PRINTDATE) 22. Document revision number (REVNUM and INFO REVNUM) 23. Document edit time (EDITTIME and INFO EDITTIME) 24. Number of pages in doc (NUMPAGES and INFO NUMPAGES) 25. Number of words in doc (NUMWORDS and INFO NUMWORDS) 26. Number of characters in doc (NUMCHARS and INFO NUMCHARS) 27. Name of document file (FILENAME and INFO FILENAME) 28. Name of document template (TEMPLATE and INFO TEMPLATE) 29. Current date (DATE) 30. Current time (TIME) 31. Page number (PAGE) 32. Mathematical Expression (calculated value) (=) 33. Copy argument to result (QUOTE) 34. Include separate document (INCLUDE) 35. Page number cross reference (PAGEREF) 36. Ask for user data (set to bookmark) (ASK) 37. Ask for user data (place in result) (FILLIN) 38. Data file for Print Merge (DATA) 39. Invoke next record for Print Merge (NEXT) 40. Conditionally invoke next record for Print Merge (NEXTIF) 41. Conditionally skip current record for Print Merge (SKIPIF) 42. Dynamic Data Exchange to other app (DDE) 43. Hot DDE Link (DDEHOT) 44. Expand glossary (retaining link to glossary) (GLOSSARY) A display showing the field mechanism of the present invention is shown in FIGS. 1A and 1B. A document may include conventional text strings 102 and fields 104, 106, and 108. The fields may provide any of a number of predefined functions and be positioned in any location. For example, field 104 is a data field, field 106 is a field for inserting a title (e.g., Mr.), and field 108 is a field for inserting a last name. In FIG. 1A, fields are shown in the field code mode. In FIG. 1B, fields are shown in the result mode. FIG. 5 shows data structures of a preferred embodiment of the present invention. Each character in a document has a character position (cp), which is the character offset within the document. As shown in FIG. 5, the beginning field character for the first field shown has a cp of 34, the separator character has a cp of 48, and the ending field character has a cp of 58. The data structure plcfld contains two parallel arrays: rgcp and rgfld. The array rgcp contains an entry for each beginning field character, separator character, and ending field character in the document. The entries contain the cp of the corresponding character. The entries are preferably maintained in sorted order during document generation. The array rgfld contains an entry corresponding to each entry in the array rgcp. The rgfld entries are an FLD data structure as described below. The FLD data structure contains the variables ch, flt, fDiffer, and flocked. The variable ch indicates whether the corresponding entry in the rgcp points to a beginning field character, a field separator, or an ending field character. The variable flt indicates the field type. The variable fDiffer indicates that the result of the field is to be displayed in the mode that is different than the global mode setting. The variable flocked indicates that the field is locked, which indicates that the result for the field is not to be regenerated. FIG. 5 also shows array dnflt. Array dnflt contains an entry for each field type, that is, keyword that is defined. The dnflt entries are EFLT data structures that contain the constants fResult, frm, and pfnCalcFunc. The constant fResult indicates that the field type produces a result. The constant frm is a refresh mask that indicates when the field type is to have a result generated. The constant pfnCalcFunc contains a pointer to the routine that generates the result for the field type. The variable flt in the array rgfld is an index into the array dnflt. FIG. 5 shows two fields that are in the document. The first field starts at character position 34. The second field starts at character position 60. As shown, array rgcp contains six entries corresponding to the beginning field characters, the field separators, and the ending field characters for these two fields. Array rgfld contains six corresponding entries. The entries corresponding to the beginning field characters contain the variable flt set to indicate the field type. In this example, both fields have the keyword "ref"; thus the variable flt in both rgfld entries is set to three. Entry number three in array dnflt corresponds to the "ref" field type and the constant pfnCalcFunc contains a pointer to the routine FcrCalcFltBkmkRef, which generates the result for a "ref" field.
TABLE 2
__________________________________________________________________________
/*CP is a long describing a character position in the document*/
/*BOOL is a boolean flag*/
/* A plc is a structure containing an array of cp's and an array of
objects (in this case fld's) in
which the index to the array serves as the link between the two pieces of
Information. A handle to
the plcfld is stored In the document descriptor. The plcfld itself is
stored in the file format.*/
/* Information stored in plcfld for each field character*/
struct FLD
{/* FIELD Descriptor*/
struct
{
int ch : 7; /*chFieldBegin, chFieldSeparate or chFieldEnd*/
int fDirty : 1; /*field must be reparsed*/
};
union
{
char flt; /*chFieldBegin:FIELD Type*/
char bData; /*chFieldSeparate: field-specific
cached data*/
struct
{ /*chFieldEnd*/
int fDiffer : 1; /*this field in ! show
results mode*/
int : 1;
int fLocked : 1; /*this field is locked
from recalc*/
int fNested : 1; /*field is nested within
another field*/
int : 4; /*spare*/
};
char grpf; /*chFieldEnd: GRouP of bit Flags*/
};
};
/*Used to cache information about a field.
Constructed from the info in the two or three fld's corresponding to the
field.*/
struct FLCD
{/* FIELD Composite Descriptor*/
CP cpFirst; /*cp where field begins*/
CP dcplnst; /*Includes both {} and all field codes*/
CP dcpResult; /*Includes .vertline. and all result text*/
BOOL fDirty; /*field is dirty and must be reparsed*/
int flt; /*field's type*/
int bData; /*flt specific cached data*/
int ifldChBegin;
int ifldChSeparate;
int ifldChEnd;
union
{
struct
{
intfDiffer : 1; /*this field in ! show results mode*/
int : 1;
int fLocked : 1; /*this field is locked from recalc*/
int fNested : 1; /*field is nested within another field*/
int : 4; /*spare*/
};
int grpf : 8;
};
};
/*This structure provides general information about a specific field
type*/
struct EFLT
{ /*Element of dnflt, an array of the info below for each field type.
flt is the index into
this array*/
int fResult : 1; /*this field may have a result*/
int : 4; /*spare*/
int : 1; /*spare*/
int frm : 8; /*refresh time mask*/
PFN pfnCalcFunc; /*pointer to recalc function*/
};
/*this is used to map ich's to cp's*/
struct CR
{ /*CP Run*/
CP cp;
int ccp;
};
/*holds information about switches found during a fetch*/
struct FSF
{ /*Field Switch Fetched*/
int c; /*how many were fetched*/
CHAR rgch [cSwitchMax]; /*the switches themselves*/
CP rgcpSw [cSwitchMax]; /*cp of the switches*/
CP rgcp [cSwitchMax]; /*cpNil or the cp of the switch's arg*/
};
/*this is used by FetchFromField and functions that call it*/
struct FFB
{ /*Field Fetch Block*/
union
{
/*this is used also by FetchVisibleRgch*/
struct FVB
{ /*Fetch Visible Block*/
int doc; /*document fetching from*/
CP cpFirst; /*first cp to fetch in next fetch (modified)*/
CP cLim; /*limit of fetches*/
int cch; /*number of ch's read if rgch. under if !rgch*/
int ccr; /*number of cr's corresponding to ch's read*/
union
{
struct FBB
{ /*Fetch Block Buffers*/
int cchMax; /*max number of ch to place in rgch*/
CHAR *rgch; /*buffer in which to place chars*/
int ccrMax; /*max number of cr's to place in rgcr*/
struct CR *rgcr;/*buffer in which to place cp runs*/
};
struct FBB fbb;
};
BOOL fOverflow; /*fetch overflowed cchMax or ccrMax, fetch again*/
};
struct FVB fvb;
};
union
{
struct FSFB
{ /*Field Specific Fetch Block*/
CP cpField; /*cpFirst of the field being fetched from*/
/*inputs*/
int flt; /*what flt is the field being fetched*/
int foc; /*how to treat fetch options*/
/*outputs*/
BOOL fGrouped; /*indicates returned argument was grouped*/
BOOL fNested; /*fetched data contained fields*/
BOOL fNoArg; /*there was no argument fetched*/
/*state (be very careful modifying)*/
int cchFieldBegin; /*count of chfieldBegin's to be matched*/
BOOL fGroupPending; /*indicates inside chGroupExternal pair*/
struct FSF fsfFlt; /*flt specific switches found*/
struct FSF fsfSys; /*system switches found*/
};
struct FSFB fsfb;
};
;
/*stores information about all defined field switches*/
struct FSI
{ /*Field Switch Information*/
int ch : 7; /*the switch character, note: packed to 7 bits*/
int fArg : 1; /*switch expects an argument*/
int flt : 8; /*what flt does this switch apply to*/
};
__________________________________________________________________________
The generic field handling mechanism of the present invention comprises two main components: routines for generating field results and routines for displaying fields. Referring now to FIG. 2, the FCalcFields routine is invoked by a user or is invoked automatically by the system to regenerate field results of a document within a specific range. Specifically, the routine FCalcFields is invoked when a user requests regeneration of fields, during the initial layout of headers, during print, page view and print preview operations, during print merge operations, whenever a document is opened, and whenever a new document is created based on a template that contains fields. The routine FCalcFields is passed as arguments the pointer pca and the variable frm. The pointer pca points to a structure containing a document and a range of character positions. The variable frm is a refresh mask, which indicates what action caused the results generation to be invoked. The routine FCalcFields returns the flag fReturn, which indicates the success or failure of the update operation. When routine FCalcFields is invoked, item 202 selects the first field in the range to be regenerated. The system then enters loop 203 where fields are processed while (i) the process is not interrupted and (ii) the selected field is within the range of fields to be regenerated. Decision 204 tests whether the looping conditions are satisfied. If not satisfied, the routine returns with the flag fReturn. Otherwise, item 206 invokes routine FCalcFieldIfld to generate the result of the selected field. Item 208 sets flag fReturn to the logical-OR of flag fReturn and the value returned by routine FCalcFieldIfld. Item 210 positions the routine at the end of the selected field in preparation for selection of the next field, and item 212 selects the next field and loops to decision 204 to process the next field. Referring now to FIG. 3, the routine FCalcFieldIfld is invoked to generate the result of a field. Routine FCalcFieldIfld receives as arguments a pointer to the current document, the index ifld into the array rgcp, the variable frm, and the variable cNestLevel, which is a count of nested levels. The index ifld contains the index into the plcfld data structure of the beginning field character of the field to have its result generated, referred to as the current field. Flag fReturn is returned by routine FCalcFieldIfld. Item 302 retrieves the FLD data from array rgfld for the current field. Decision 304 then determines whether the current nesting level indicated by the variable cNestLevel is equal to the maximum nesting level to ensure the nesting level does not exceed the nesting limit. If the maximum nesting level is exceeded, the routine returns. If the nesting level is less than the maximum, the routine enters loop 305, which calls routine FCalcFieldIfld recursively to generate the result for the nested fields in the field codes portion of the current field. Decision 306 determines whether a field that has not yet been processed exists within the range of field codes for the current field. If such a field does not exist, control passes to item 312. Otherwise, item 307 calls routine FCalcFieldIfld recursively to generate the result of the nested field. Item 308 sets the flag fReturn equal to the logical-OR of flag fReturn and the value returned from the call to routine FCalcFieldIfld. Item 310 positions the routine at the end of the nested field and loops to decision 306 to process the next field within the range of field codes of the current field. Item 312 uses the variable flt in the retrieved FLD data for the current field to retrieve the EFLT data from array dnflt for the field type of the current field. Decision 314 determines whether the result of the field should be regenerated based on the value in variable frm in the EFLT data and the passed variable frm, and the flag flocked in the FLD data. If the flag flocked is set, then the field is locked and the result will not be regenerated. A field is locked under user control. If the result is not to be regenerated, control passes to item 322. Otherwise, item 316 sets the value of flag fReturn to true and item 318 inserts a separator character in the current field if one is not already in the current field. Item 320 invokes routine CallCalcFunc to generate the result and to insert the result in the current field just after the separator character and just before the old result, if present. Item 322 positions the routine at the beginning of the result of the current field. The routine then enters loop 323, which recursively invokes routine FCalcFieldIfld to generate the results for all nested fields within the result portion of the current field. When loop 323 is entered, decision 324 determines whether the result is locked or whether a field that has not yet been processed exists within the range of the result portion of the current field. A locked result indicates that fields which are part of the result are not updated. If the result is locked or such a field does not exist, control passes to item 332. Otherwise, item 326 recursively invokes routine FCalcFieldIfld to generate the result of the nested field. Item 328 sets the flag fReturn equal to the logical-OR of flag fReturn and the value returned from the call to routine FCalcFieldIfld. Item 330 positions the routine at the end of the nested field and loops to decision 324. Item 332 returns with the value of flag fReturn. Referring now to FIG. 4, the routine CallCalcFunc is invoked to perform field specific functions and to fetch and apply switches. Item 402 initializes composite field descriptor information in the FLCD data structure. The FLCD data structure contains data derived from the entries associated with the current field in the data structure plcfld. Item 404 saves flag fDirty that indicates the field codes of the current field may have been edited. This flag is set by the document processor when the field codes are modified. The routines that perform the field-specific generating may modify this flag. Item 406 fetches the field type characteristics, the EFLT data, from the array dnflt based on the variable flt in the data structure plcfld. Item 408 initializes the field fetch block. The field fetch block (FFB) is a data structure that stores the state of the fetching of the arguments of a field. The field fetch block is initialized to point to the first character in the current field (cpFirst) and the character after the ending field character of the current field (cpLim). As arguments are fetched, the field fetch block is updated. Also, the data structure FieldSwitchFetched (FSF) is updated with the field switches as arguments are fetched. Item 410 calls the field specific function through the pointer pfnCalcFunc in the EFLT data. The field specific function generates a new result, inserts it in the document in front of the old result, and returns a value fcr which indicates the degree of success or failure. The field specific function may invoke the routine FetchFromField to fetch the field arguments and as those arguments are fetched, any switches encountered are stored in the FSF data structure. The return values are fcrKeepOld (process failed, keep old result), fcrError (process failed or an error occurred), fcrNormal (process succeeded), fcrNumeric (process succeeded, numeric result was generated) or fcrDateTime (process succeeded, a date/time result was generated). Decision 411 determines whether fcrNormal, fcrNumeric, or fcrDateTime was returned. If fcrNormal, fcrNumeric, or fcrDateTime was not returned control passes to decision 416. Otherwise, item 412 calls routine FetchFromField to ensure that all switches in the field codes have been stored in the FSF data structure, and item 414 calls DcpApplySysSwitches to apply the switches. Decision 416 determines whether fcrKeepOld was returned (indicating the old result is to be retained). If the old result is to be kept, the routine continues at item 420. Otherwise, item 418 removes the old result from the field and the routine continues at item 420. Item 420 restores the flag fDirty and the routine returns. The routine FetchFromField is invoked to parse the field codes of a particular field into arguments and switches and then return the text of those arguments. The routine FetchFromField receives as an argument the variable designated pffb, which is a pointer to a field fetch block (FFB) data structure. The FFB is passed with values to indicate what field is being fetched from and how far the fetch process has progressed. The FFB contains a pointer to a character buffer which is to receive the output of this routine. Routine FetchFromField scans the field codes and returns in the character buffer the text of the next argument in the field codes. This routine updates the FFB structure so that a subsequent call to routine FetchFromField with the same FFB structure will fetch the argument following the argument just fetched. Also, the FFB contains two FSF data structures, fsfFlt and fsfSys. These data structures cache information about each of the switches seen by FetchFromField during normal operation. Routine ChFetchSwitch is invoked to return these cached switches. In a preferred embodiment, routine FetchFromField acts as a state machine, which means that as it scans characters, it sets a flag or a count to change its state. The manner in which different characters in field codes are treated by FetchFromField are dependent on the state of these variables. In a preferred embodiment, the state variables include: fChFieldPreceding which indicates that that previous character looked at by FetchFromField was a beginning field character; and fChEscapePreceding which indicates that the previous character looked at by FetchFromField was a backslash character (`.backslash.`). The variable cchFieldBegin contains the nesting level of fields within the field codes (every time a beginning field character is encountered, a field is nested within the field code portion of the current field, FetchFromField increments cchFieldBegin and jumps to the results of the field just encountered. When the ending field FieldEnd character is encountered cchFieldBegin is decremented. The variable fGroupPending indicates that the current text being fetched was preceded by a quote character. All the text that follows until the next quote character will be grouped into a single argument. The FFB structure is initially set up by the caller with cpFirst containing the character position of the first character of the field codes and cpLim containing the character position of the character following the last character of the field codes. As arguments are fetched using FetchFromField, cpFirst is advanced to indicate the new starting location and cpLim is used to determine when to stop fetching. Referring now to FIG. 6, the routine DcpApplySysSwitches is invoked to apply system switches to field results. The routine receives as arguments a pointer pffb (pointer to the field fetch block), the current document, a value designated cpResult (a result character position), a value designated dcpNew (the number of character positions of the new result), a value dcpPrev (the number of character positions of the old result), and a value fcr (the return value of a field specific generation function). The routine returns the value dcpNew (the length in characters of a new result) and the FFB modified. When routine DcpApplySysSwitches is invoked, item 602 calls routine ChFetchSwitch to determine whether all the system switches have been processed and returns the switch identifier. Routine ChFetchSwitch is described below. If all the switches have been processed, routine DcpApplySysSwitches returns. Otherwise, item 604 determines which switch identifier is currently being processed. If the current switch identifier is a "@" or "#" character (corresponding to a date/time or numeric switch), control passes to decision 610 which determines whether this is the first date/time, numeric, or formatting switch for the field. If not the first, a rule violation has occurred and item 614 outputs an error message in the result and routine DcpApplySysSwitches returns. Otherwise, item 612 invokes the routine DcpApplyPictureSw (discussed below) to apply the picture switch and to update dcpNew, and then loops to decision 602. If decision 604 indicates that the current switch identifier is a "*" character (corresponding to a formatting switch), then item 608 invokes routine DcpApplyFormatSw to apply the format switch and to update dcpNew, and then loops to decision 602 to process the next switch. If decision 604 indicates that the current switch identifier is a "! " character, item 606 locks the result, which indicates that the fields in the result will not be updated, and loops to decision 602 to process the next switch. Referring now to FIG. 7, the routine ChFetchSwitch is shown. The routine ChFetchSwitch is invoked to fetch switches from the FFB data structure and to set up arguments for fetching. It receives as arguments the pointer pffb that points to the FFB data structure and returns a switch identifier and the FFB data structure modified. When routine ChFetchSwitch is invoked, item 702 increments the switch counter in the FFB. Decision 704 then determines whether the switch counter is less than the total count of switches stored in the FFB. The total count of switches was set by routine FetchFromField. If not less than, then the routine returns indicating no more switches to process. Otherwise, a switch has not yet been fetched and decision 706 determines whether the character position of the switch's argument, rgcp[switch counter] of the FSF data structure in the FFB, is equal to cpNil, which indicates that the switch has no argument. If equal to cpNil, item 708 sets the value of cpFirst in the FFB to the value of cpLim so that the fetch operation (FetchFromField) will do nothing when next called and the routine returns. Otherwise, item 710 sets cpFirst to the beginning character position of the switch argument. Item 714 gets the switch identifier (*,! ,@or #) stored in the array element rgch[switch counter] and the routine returns. Referring now to FIG. 8, the routine DcpApplyFormatSw is invoked to apply formatting switches. Routine DcpApplyFormatSw receives as arguments the pointer pffb to the field fetch block, the document, the variable cpResult (the character position of the result in the field), the variable dcpNew (the number of character positions of the new result), the variable dcpPrev (the number of character positions occupied by the old result), and the variable fcr (the return value of the field specific generation function). The routine returns a new value of dcpNew which corresponds to the length of the new result. When routine DcpApplyFormatSw is invoked, item 802 fetches the switch argument by calling routine FetchFromField. Decision 804 then determines whether a switch argument exists for the current switch. If none exists, item 806 inserts an error message into the result and the routine returns. Otherwise, decision 810 evaluates the switch argument. If the switch argument is a case change, item 812 transforms the case of the new result, item 814 replaces the new result with the transformed result, and the routine returns. If the switch argument is numeric formatting, decision 818 determines whether the new result is numeric by testing whether flag fcr indicates numeric. If not, control passes to item 820 to parse the new result to extract a numeric value and then control passes to item 824. Otherwise, control passes to item 822 to retrieve the numeric value from the new result. Item 824 then formats the numeric value, and item 826 replaces the new result with the formatted result and the routine returns with the updated dcpNew. If the switch argument is a character format, item 828 fetches the format of the first character in the field, applies it to the new result, and the routine returns. If the switch argument is a merge format, item 830 merges the character formatting of the old result with the new result on a word-by-word basis and the routine returns. Referring now to FIG. 9, the DcpApplyPictureSw routine is invoked to apply number and date/time formatting. Routine DcpApplyPictureSw is called with the same parameters as described above for routine DcpApplyFormatSw plus the parameter switch identifier. When routine DcpApplyPictureSw is invoked, item 902 calls routine FetchFromField to fetch the switch argument for the current switch. Decision 904 then determines whether a switch argument exists. If a switch argument does not exist, item 906 inserts an error message in the result and the routine returns. Otherwise, control passes to item 910 which determines whether the switch identifier indicates numeric formatting or date/time formatting. If the switch identifier indicates date/time formatting, control passes to decision 916. If the switch identifier indicates numeric formatting, decision 912 determines whether the new result is numeric. If not numeric, control passes to item 914 which parses the new result to extract a numeric value and control passes to item 917. Otherwise, item 916 retrieves the numeric value from the new result and control passes to item 917. Item 917 formats the numeric value and control passes to item 924. If the switch identifier indicates date/time formatting, decision 916 determines whether the new result is in date/time format. If not a date/time, item 918 parses the result to extract a date/time value, and control passes to item 922. Otherwise, item 920 retrieves the date/time value from the new result and control passes to item 922. Item 922 formats the date/time value. Once a value is formatted by item 917 or item 922, item 924 replaces the new result with formatted result and updates the variable dcpNew, and the routine returns. The following routines are invoked for text display operations. Referring now to FIG. 10, the routine FormatLine is invoked to determine how many and which characters will be shown in a line of text. The routine FormatLine receives as arguments the variable ww which defines the current window, the document, the variable cp which defines the current character position, and the variable dxa which defines the width of a column of text. This routine returns grpchr which is a group of character runs and the variable vfli which is a format line structure containing the width of the line and an array of the characters to be included in the line. When routine FormatLine is invoked, item 1002 fetches a run of characters, that is, a group of adjacent characters with the same character properties, from the document starting with a character designated cpNext. Decision 1004 then retrieves the next character in the run and determines whether the character is a field beginning, ending or separator character. If not, control passes to item 1024. Otherwise, decision 1006 determines whether flag fPassChSpec is true, which indicates that the current character is to be displayed. If the current character is to be displayed, item 1020 sets the current character property to bold (so the user can distinguish between a bracket and a beginning field character), item 1022 sets the flag fPassChSpec to false, and control passes to item 1024. If the current character is not to be displayed, item 1008 saves the character position and the current character. Item 1012 gets the next character position to show by calling routine FfcFormatFieldPdcp (described below). Decision 1014 determines if routine FfcFormatFieldPdcp indicates that characters are to be skipped. If text is to be skipped, item 1016 creates a character for the skipped text and control passes to item 1024. Otherwise, item 1018 sets the variable fPassChSpec to true to indicate that the next character is to be displayed and item 1019 increments the character position by the number of characters to skip and the routine loops to item 1002 to process the next character run. Items 1024 and 1026 process any hidden and normal text. Decision 1028 then determines whether the end of the line has been reached. If so, the routine returns. Otherwise, control loops to item 1002. Referring now to FIG. 11, the routine FfcFormatFieldPdcp is invoked to determine whether a portion of a field is to be displayed and the offset to the next character to be displayed. Routine FfcFormatFieldPdcp receives as arguments a variable designated pdcp which is a pointer to the offset of the next visible character, the current window, the current document, the character position variable cp, and the current character ch. The routine returns a value designated ffcReturn which is the field format code and the variable pdcp indicating how many characters to skip. When routine FfcFormatFieldPdcp is invoked, item 1102 sets the value of the field format code (ffcReturn) to a default value. Item 1104 then fetches the composite field descriptor for the current field. Decision 1106 then determines whether the field codes have changed by checking flag fDirty. If the field codes have changed, item 1108 parses the field type by calling routine FltParseDocCp. Item 1110 gets the display state for the field by calling routine FShowResultPflcdFvc, which returns the flag fShowResult set to true if the result is to be displayed. Item 1112 gets the character position offset to the next visible field by calling routine DcpSkipFieldChPflcd, which returns variable dcp to indicate the number of characters to skip. Decision 1114 determines the value of the current character position offset. If the value of the current offset is zero, the item 1116 sets the variable ffcReturn to indicate that the current character is to be displayed. The routine then returns. Referring now to FIG. 12, the routine FShowResultPflcdFvc is invoked to determine the ShowResult state for a single field. The routine receives as arguments the pointer pflcd to the composite field descriptor for the current field and the variable fvc which is a field visibility code. The routine returns a flag fReturn that indicates whether the current field should be shown in the result mode. When routine FShowResultPflcdFvc is invoked, decision 1202 determines whether the global variable ShowAll is set for the current window. If it is set, the routine returns with the flag fReturn set to false. Otherwise, item 1204 sets flag fReturn equal to the ShowResult state of the window. Decision 1206 then determines whether the current window fForceField bit is set (set for cases where fields are to be ignored and if the current window is not in a page view mode). If fForcefield is not set, item 1208 sets flag fReturn by exclusive-ORing the value of flag fReturn with a value designated fDiffer for the field which indicates this field should be in the reverse view from other fields as stored in array rgfld. The routine then returns with flag fReturn. Referring to FIG. 13, the routine DcpSkipFieldChPflcd is invoked to determine how many character positions to skip based on which field character is currently being evaluated and the ShowResult state of the field. The routine DcpSkipFieldChPflcd receives as arguments the current character, the pointer pflcd to the composite descriptor for the current field, and the flag fShowResult which indicates whether the field should be shown in the result mode. The routine returns the value dcp which indicates the number of character positions to be skipped. When the routine DcpSkipFieldChPflcd is invoked, item 1302 determines the type of the current field character. If the current character is a field separator, decision 1304 determines whether the flag fShowResult is true. If true, item 1305 sets dcp equal to one to indicate the beginning of the result and the routine returns. Otherwise, item 1307 sets dcp equal to the length of the result to indicate that the result is to be skipped and the routine returns. If the field character is an ending field character, decision 1308 determines whether flag ShowResult is true. If true, item 1311 sets dcp equal to one to indicate that the ending field character is to be skipped and the routine returns. Otherwise, item 1309 sets dcp equal to zero to indicate that the ending field character is to be shown and the routine returns. If the current field character is a beginning field character, decision 1310 determines whether flag fShowResult is true. If true, item 1312 sets dcp equal to the length of the field codes to indicate the separate or ending field character and the routine returns. Otherwise, item 1314 sets dcp equal to zero to indicate that the field beginning character is to be displayed and the routine returns. Referring now to FIG. 14, the routine FltParseDocCp is invoked to fetch a field keyword and to return the field type (flt) of the keyword. The routine receives as arguments the current document, the current character position and the ifld index into array plcfld. The routine returns the variable flt, which is the index into the array dnflt. When routine FltParseDocCp is invoked, item 1402 initializes the field fetch block. Item 1404 then fetches the first word of the field codes for the field by calling routine FetchFromField. Item 1406 then looks-up the keyword in a keyword flt table. Item 1408 then adds flt information the flcd array. Decision 1412 determines whether the current window is the one with the focus. If the window is not with the focus, the routine returns. Otherwise, item 1414 determines whether ShowResult is true. If not true, the routine returns. Otherwise, item 1416 toggles fDiffer and the routine returns. In summary, an improved method and system for implementing fields in a document processor has been described with reference to a preferred embodiment. Accordingly, other uses and modifications of this invention will be apparent to persons of ordinary skill without departing from the scope of this invention.
|
Same subclass Same class Consider this |
||||||||||
