From: Marc Liyanage Date: Sun, 13 Feb 2005 13:10:18 +0000 (+0000) Subject: Initial revision X-Git-Tag: v1.2~5 X-Git-Url: http://www.entropy.ch/git/LeanCalc.git/commitdiff_plain/37cf92c0cb27ae14e6ed507cd63f7035e00c8887 Initial revision git-svn-id: svn+ssh://www.entropy.ch/Users/liyanage/Documents/svnroot/trunk/LeanCalc@128 153f8dbc-cef0-0310-8e0e-ba1d6c9f8c6b --- 37cf92c0cb27ae14e6ed507cd63f7035e00c8887 diff --git a/English.lproj/Credits.rtf b/English.lproj/Credits.rtf new file mode 100644 index 0000000..42e1d9a --- /dev/null +++ b/English.lproj/Credits.rtf @@ -0,0 +1,22 @@ +{\rtf1\mac\ansicpg10000\cocoartf102 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural + +\f0\fs24 \cf0 \ +A GUI wrapper around the calc library.\ + +\f1\b \ +Written By: +\f0\b0 \ + Marc Liyanage\ +\ + +\f1\b More Information: +\f0\b0 \ + http://www.entropy.ch\ +\ + +\f1\b Calc Library: +\f0\b0 \ + http://sourceforge.net/projects/calc/} \ No newline at end of file diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..7496c38 Binary files /dev/null and b/English.lproj/InfoPlist.strings differ diff --git a/English.lproj/MainMenu.nib/classes.nib b/English.lproj/MainMenu.nib/classes.nib new file mode 100644 index 0000000..9b902be --- /dev/null +++ b/English.lproj/MainMenu.nib/classes.nib @@ -0,0 +1,17 @@ +{ + IBClasses = ( + { + ACTIONS = {showFunctionReference = id; }; + CLASS = AppDelegate; + LANGUAGE = ObjC; + SUPERCLASS = NSObject; + }, + { + ACTIONS = {insertPrevious = id; }; + CLASS = FirstResponder; + LANGUAGE = ObjC; + SUPERCLASS = NSObject; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/English.lproj/MainMenu.nib/info.nib b/English.lproj/MainMenu.nib/info.nib new file mode 100644 index 0000000..e58d1c8 --- /dev/null +++ b/English.lproj/MainMenu.nib/info.nib @@ -0,0 +1,21 @@ + + + + + IBDocumentLocation + 142 45 373 303 0 0 1440 878 + IBEditorPositions + + 29 + 168 580 276 44 0 0 1440 878 + + IBFramework Version + 364.0 + IBOpenObjects + + 29 + + IBSystem Version + 7U16 + + diff --git a/English.lproj/MainMenu.nib/keyedobjects.nib b/English.lproj/MainMenu.nib/keyedobjects.nib new file mode 100644 index 0000000..c91d4a8 Binary files /dev/null and b/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/English.lproj/MyDocument.nib/classes.nib b/English.lproj/MyDocument.nib/classes.nib new file mode 100644 index 0000000..fa6f0a1 --- /dev/null +++ b/English.lproj/MyDocument.nib/classes.nib @@ -0,0 +1,14 @@ +{ + IBClasses = ( + {CLASS = CmdKeyInterceptWindow; LANGUAGE = ObjC; SUPERCLASS = NSWindow; }, + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + { + ACTIONS = {commit = id; }; + CLASS = MyDocument; + LANGUAGE = ObjC; + OUTLETS = {arrayController = NSArrayController; expressionField = NSTextField; }; + SUPERCLASS = NSDocument; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/English.lproj/MyDocument.nib/info.nib b/English.lproj/MyDocument.nib/info.nib new file mode 100644 index 0000000..c3538f3 --- /dev/null +++ b/English.lproj/MyDocument.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBDocumentLocation + 57 82 400 277 0 0 1440 878 + IBFramework Version + 364.0 + IBOpenObjects + + 5 + + IBSystem Version + 7U16 + + diff --git a/English.lproj/MyDocument.nib/keyedobjects.nib b/English.lproj/MyDocument.nib/keyedobjects.nib new file mode 100644 index 0000000..5240545 Binary files /dev/null and b/English.lproj/MyDocument.nib/keyedobjects.nib differ diff --git a/Icon Artwork/Calculations.icns b/Icon Artwork/Calculations.icns new file mode 100644 index 0000000..d9f2ffa Binary files /dev/null and b/Icon Artwork/Calculations.icns differ diff --git a/Icon Artwork/Calculations.tif b/Icon Artwork/Calculations.tif new file mode 100644 index 0000000..c15c6aa Binary files /dev/null and b/Icon Artwork/Calculations.tif differ diff --git a/Icon Artwork/LeanCalc.ai b/Icon Artwork/LeanCalc.ai new file mode 100644 index 0000000..a4c7bdc Binary files /dev/null and b/Icon Artwork/LeanCalc.ai differ diff --git a/Icon Artwork/LeanCalc.icns b/Icon Artwork/LeanCalc.icns new file mode 100644 index 0000000..f429617 Binary files /dev/null and b/Icon Artwork/LeanCalc.icns differ diff --git a/Icon Artwork/LeanCalc.psd b/Icon Artwork/LeanCalc.psd new file mode 100644 index 0000000..8e15535 Binary files /dev/null and b/Icon Artwork/LeanCalc.psd differ diff --git a/Icon Artwork/LeanCalc.tif b/Icon Artwork/LeanCalc.tif new file mode 100644 index 0000000..265fa4e Binary files /dev/null and b/Icon Artwork/LeanCalc.tif differ diff --git a/Icon Artwork/LeanCalcool.ai b/Icon Artwork/LeanCalcool.ai new file mode 100644 index 0000000..d23c5b9 Binary files /dev/null and b/Icon Artwork/LeanCalcool.ai differ diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..3885509 --- /dev/null +++ b/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + calc + + CFBundleTypeIconFile + Calculations + CFBundleTypeName + Calculations + CFBundleTypeOSTypes + + ???? + + CFBundleTypeRole + Editor + NSDocumentClass + MyDocument + + + CFBundleExecutable + LeanCalc + CFBundleIconFile + LeanCalc + CFBundleIdentifier + ch.entropy.leancalc + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSMainNibFile + MainMenu + NSPrincipalClass + CmdKeyInterceptApplication + + diff --git a/LeanCalc.xcode/liyanage.mode1 b/LeanCalc.xcode/liyanage.mode1 new file mode 100644 index 0000000..0dcbab0 --- /dev/null +++ b/LeanCalc.xcode/liyanage.mode1 @@ -0,0 +1,1191 @@ + + + + + ActivePerspectiveName + Project + AllowedModules + + + BundleLoadPath + + MaxInstances + n + Module + PBXSmartGroupTreeModule + Name + Groups and Files Outline View + + + BundleLoadPath + + MaxInstances + n + Module + PBXNavigatorGroup + Name + Editor + + + BundleLoadPath + + MaxInstances + n + Module + XCTaskListModule + Name + Task List + + + BundleLoadPath + + MaxInstances + n + Module + XCDetailModule + Name + File and Smart Group Detail Viewer + + + BundleLoadPath + + MaxInstances + 1 + Module + PBXBuildResultsModule + Name + Detailed Build Results Viewer + + + BundleLoadPath + + MaxInstances + 1 + Module + PBXProjectFindModule + Name + Project Batch Find Tool + + + BundleLoadPath + + MaxInstances + n + Module + PBXRunSessionModule + Name + Run Log + + + BundleLoadPath + + MaxInstances + n + Module + PBXBookmarksModule + Name + Bookmarks Tool + + + BundleLoadPath + + MaxInstances + n + Module + PBXClassBrowserModule + Name + Class Browser + + + BundleLoadPath + + MaxInstances + n + Module + PBXCVSModule + Name + Source Code Control Tool + + + BundleLoadPath + + MaxInstances + n + Module + PBXDebugBreakpointsModule + Name + Debug Breakpoints Tool + + + BundleLoadPath + + MaxInstances + n + Module + XCDockableInspector + Name + Inspector + + + BundleLoadPath + + MaxInstances + n + Module + PBXOpenQuicklyModule + Name + Open Quickly Tool + + + BundleLoadPath + + MaxInstances + 1 + Module + PBXDebugSessionModule + Name + Debugger + + + BundleLoadPath + + MaxInstances + 1 + Module + PBXDebugCLIModule + Name + Debug Console + + + Description + This workspace mimics that found in Xcode 1.2, with various minor improvements such as including attached editors to the build results window and the project find window. + DockingSystemVisible + + Extension + mode1 + FirstTimeWindowDisplayed + + Identifier + com.apple.perspectives.project.mode1 + MajorVersion + 31 + MinorVersion + 0 + Name + Default Workspace + Notifications + + + XCObserverAutoDisconnectKey + + XCObserverDefintionKey + + XCObserverFactoryKey + XCPerspectivesSpecificationIdentifier + XCObserverGUIDKey + XCObserverProjectIdentifier + XCObserverNotificationKey + PBXStatusBuildStateMessageNotification + XCObserverTargetKey + XCMainBuildResultsModuleGUID + XCObserverTriggerKey + awakenModuleWithObserver: + XCObserverValidationKey + + + + OpenEditors + + Perspectives + + + ChosenToolbarItems + + active-target-popup + action + NSToolbarFlexibleSpaceItem + buildOrClean + build-and-runOrDebug + build-and-debug + com.apple.ide.PBXToolbarStopButton + get-info + toggle-editor + NSToolbarFlexibleSpaceItem + com.apple.pbx.toolbar.searchfield + + ControllerClassBaseName + + IconName + WindowOfProject + Identifier + perspective.project + IsVertical + + Layout + + + ContentConfiguration + + PBXBottomSmartGroupGIDs + + 1C37FBAC04509CD000000102 + 1C37FAAC04509CD000000102 + 1C08E77C0454961000C914BD + 1C37FABC05509CD000000102 + 1C37FABC05539CD112110102 + E2644B35053B69B200211256 + 1C37FABC04509CD000100104 + 1CC0EA4004350EF90044410B + 1CC0EA4004350EF90041110B + + PBXProjectModuleGUID + 1CE0B1FE06471DED0097A5F4 + PBXProjectModuleLabel + Files + PBXProjectStructureProvided + yes + PBXSmartGroupTreeModuleColumnData + + PBXSmartGroupTreeModuleColumnWidthsKey + + 186 + + PBXSmartGroupTreeModuleColumnsKey_v4 + + MainColumn + + + PBXSmartGroupTreeModuleOutlineStateKey_v7 + + PBXSmartGroupTreeModuleOutlineStateExpansionKey + + 2A37F4AAFDCFA73011CA2CEA + 2A37F4AFFDCFA73011CA2CEA + 2A37F4B8FDCFA73011CA2CEA + 2A37F4C3FDCFA73011CA2CEA + 1058C7A6FEA54F5311CA2CBB + 1C37FBAC04509CD000000102 + 1C37FABC05509CD000000102 + 1CC0EA4004350EF90041110B + + PBXSmartGroupTreeModuleOutlineStateSelectionKey + + + 3 + 2 + 0 + + + PBXSmartGroupTreeModuleOutlineStateVisibleRectKey + {{0, 0}, {186, 634}} + + PBXTopSmartGroupGIDs + + + GeometryConfiguration + + Frame + {{0, 0}, {203, 652}} + GroupTreeTableConfiguration + + MainColumn + 186 + + RubberWindowFrame + 78 157 900 694 0 0 1440 878 + + Module + PBXSmartGroupTreeModule + Proportion + 203pt + + + Dock + + + ContentConfiguration + + PBXProjectModuleGUID + 1CE0B20306471E060097A5F4 + PBXProjectModuleLabel + LeanCalc_Prefix.pch + PBXSplitModuleInNavigatorKey + + Split0 + + PBXProjectModuleGUID + 1CE0B20406471E060097A5F4 + PBXProjectModuleLabel + LeanCalc_Prefix.pch + bookmark + 1B8243EF07BF879700279D6D + history + + 1BD2F3F207B74F230022B69D + 1BC8F72507B97E7C00987A06 + 1BD2F45007B829610022B69D + 1B82418207BE13B000279D6D + 1B82427B07BF61C600279D6D + 1B82434A07BF7A4B00279D6D + 1B8243C007BF863D00279D6D + 1B8243C407BF865300279D6D + 1B8243C507BF865300279D6D + 1B8243E107BF86BE00279D6D + 1B8243E707BF86C900279D6D + 1B8243E807BF86C900279D6D + + prevStack + + 1BD2F3F507B74F230022B69D + 1BD2F45307B829610022B69D + 1BD2F45407B829610022B69D + 1BC8F14907B8301200987A06 + 1BC8F72C07B97E7C00987A06 + 1BADE91E07BC0E6C0020BE61 + 1B82418507BE13B000279D6D + 1B82427E07BF61C600279D6D + 1B82427F07BF61C600279D6D + 1B82429107BF677B00279D6D + 1B8242D207BF6C9D00279D6D + 1B82434F07BF7A4B00279D6D + 1B8243C207BF863D00279D6D + 1B8243C607BF865300279D6D + 1B8243E307BF86BE00279D6D + 1B8243E907BF86C900279D6D + + + SplitCount + 1 + + StatusBarVisibility + + + GeometryConfiguration + + Frame + {{0, 0}, {691, 497}} + RubberWindowFrame + 78 157 900 694 0 0 1440 878 + + Module + PBXNavigatorGroup + Proportion + 497pt + + + ContentConfiguration + + PBXProjectModuleGUID + 1CE0B20506471E060097A5F4 + PBXProjectModuleLabel + Detail + + GeometryConfiguration + + Frame + {{0, 504}, {691, 148}} + RubberWindowFrame + 78 157 900 694 0 0 1440 878 + + Module + XCDetailModule + Proportion + 148pt + + + Proportion + 691pt + + + Name + Project + ServiceClasses + + XCModuleDock + PBXSmartGroupTreeModule + XCModuleDock + PBXNavigatorGroup + XCDetailModule + + TableOfContents + + 1B82411B07BD690200279D6D + 1CE0B1FE06471DED0097A5F4 + 1B82411C07BD690200279D6D + 1CE0B20306471E060097A5F4 + 1CE0B20506471E060097A5F4 + + ToolbarConfiguration + xcode.toolbar.config.default + + + PerspectivesBarVisible + + StatusbarIsVisible + + TimeStamp + 129992599.06281091 + ToolbarDisplayMode + 1 + ToolbarIsVisible + + ToolbarSizeMode + 1 + Type + Perspectives + UpdateMessage + + WindowJustification + 5 + WindowOrderList + + 1B82411E07BD690200279D6D + 1C0AD2B3069F1EA900FABCE6 + /Users/liyanage/Desktop/LeanCalc/LeanCalc.xcode + + WindowString + 78 157 900 694 0 0 1440 878 + WindowTools + + + FirstTimeWindowDisplayed + + Identifier + windowTool.build + Layout + + + Dock + + + ContentConfiguration + + PBXProjectModuleGUID + 1CD0528F0623707200166675 + PBXProjectModuleLabel + <No Editor> + PBXSplitModuleInNavigatorKey + + Split0 + + PBXProjectModuleGUID + 1CD052900623707200166675 + history + + 1BFAB30407AF78F800C841BA + + prevStack + + 1BFAB30607AF78F800C841BA + + + SplitCount + 1 + + StatusBarVisibility + + + GeometryConfiguration + + Frame + {{0, 0}, {589, 8}} + RubberWindowFrame + 661 163 589 501 0 0 1440 878 + + Module + PBXNavigatorGroup + Proportion + 8pt + + + BecomeActive + + ContentConfiguration + + PBXProjectModuleGUID + XCMainBuildResultsModuleGUID + PBXProjectModuleLabel + Build + XCBuildResultsTrigger_Collapse + 1021 + XCBuildResultsTrigger_Open + 1010 + + GeometryConfiguration + + Frame + {{0, 15}, {589, 444}} + RubberWindowFrame + 661 163 589 501 0 0 1440 878 + + Module + PBXBuildResultsModule + Proportion + 444pt + + + Proportion + 459pt + + + Name + Build Results + ServiceClasses + + PBXBuildResultsModule + + StatusbarIsVisible + + TableOfContents + + 1B82411E07BD690200279D6D + 1B82411F07BD690200279D6D + 1CD0528F0623707200166675 + XCMainBuildResultsModuleGUID + + ToolbarConfiguration + xcode.toolbar.config.build + WindowString + 661 163 589 501 0 0 1440 878 + WindowToolGUID + 1B82411E07BD690200279D6D + WindowToolIsVisible + + + + FirstTimeWindowDisplayed + + Identifier + windowTool.debugger + Layout + + + Dock + + + ContentConfiguration + + Debugger + + HorizontalSplitView + + _collapsingFrameDimension + 0.0 + _indexOfCollapsedView + 0 + _percentageOfCollapsedView + 0.0 + isCollapsed + yes + sizes + + {{0, 0}, {249, 164}} + {{249, 0}, {445, 164}} + + + VerticalSplitView + + _collapsingFrameDimension + 0.0 + _indexOfCollapsedView + 0 + _percentageOfCollapsedView + 0.0 + isCollapsed + yes + sizes + + {{0, 0}, {694, 164}} + {{0, 164}, {694, 216}} + + + + LauncherConfigVersion + 8 + PBXProjectModuleGUID + 1C162984064C10D400B95A72 + PBXProjectModuleLabel + Debug - GLUTExamples (Underwater) + + GeometryConfiguration + + DebugConsoleDrawerSize + {100, 120} + DebugConsoleVisible + None + DebugConsoleWindowFrame + {{200, 200}, {500, 300}} + DebugSTDIOWindowFrame + {{200, 200}, {500, 300}} + Frame + {{0, 0}, {694, 380}} + RubberWindowFrame + 247 86 694 422 0 0 1440 878 + + Module + PBXDebugSessionModule + Proportion + 380pt + + + Proportion + 380pt + + + Name + Debugger + ServiceClasses + + PBXDebugSessionModule + + StatusbarIsVisible + + TableOfContents + + 1CD10A99069EF8BA00B06720 + 1BC8F14107B82BB400987A06 + 1C162984064C10D400B95A72 + 1BC8F14207B82BB400987A06 + + ToolbarConfiguration + xcode.toolbar.config.debug + WindowString + 247 86 694 422 0 0 1440 878 + WindowToolGUID + 1CD10A99069EF8BA00B06720 + WindowToolIsVisible + + + + Identifier + windowTool.find + Layout + + + Dock + + + Dock + + + ContentConfiguration + + PBXProjectModuleGUID + 1CDD528C0622207200134675 + PBXProjectModuleLabel + <No Editor> + PBXSplitModuleInNavigatorKey + + Split0 + + PBXProjectModuleGUID + 1CD0528D0623707200166675 + + SplitCount + 1 + + StatusBarVisibility + + + GeometryConfiguration + + Frame + {{0, 0}, {781, 167}} + RubberWindowFrame + 62 385 781 470 0 0 1440 878 + + Module + PBXNavigatorGroup + Proportion + 781pt + + + Proportion + 50% + + + BecomeActive + + ContentConfiguration + + PBXProjectModuleGUID + 1CD0528E0623707200166675 + PBXProjectModuleLabel + Project Find + + GeometryConfiguration + + Frame + {{8, 0}, {773, 254}} + RubberWindowFrame + 62 385 781 470 0 0 1440 878 + + Module + PBXProjectFindModule + Proportion + 50% + + + Proportion + 428pt + + + Name + Project Find + ServiceClasses + + PBXProjectFindModule + + StatusbarIsVisible + + TableOfContents + + 1C530D57069F1CE1000CFCEE + 1C530D58069F1CE1000CFCEE + 1C530D59069F1CE1000CFCEE + 1CDD528C0622207200134675 + 1C530D5A069F1CE1000CFCEE + 1CE0B1FE06471DED0097A5F4 + 1CD0528E0623707200166675 + + WindowString + 62 385 781 470 0 0 1440 878 + WindowToolGUID + 1C530D57069F1CE1000CFCEE + WindowToolIsVisible + + + + Identifier + MENUSEPARATOR + + + FirstTimeWindowDisplayed + + Identifier + windowTool.debuggerConsole + Layout + + + Dock + + + ContentConfiguration + + PBXProjectModuleGUID + 1C78EAAC065D492600B07095 + PBXProjectModuleLabel + Debugger Console + + GeometryConfiguration + + Frame + {{0, 0}, {547, 359}} + RubberWindowFrame + 104 431 547 401 0 0 1440 878 + + Module + PBXDebugCLIModule + Proportion + 359pt + + + Proportion + 359pt + + + Name + Debugger Console + ServiceClasses + + PBXDebugCLIModule + + StatusbarIsVisible + + TableOfContents + + 1BFAB2C307AF66EA00C841BA + 1BD2F24107B6BFB60022B69D + 1C78EAAC065D492600B07095 + + WindowString + 104 431 547 401 0 0 1440 878 + WindowToolGUID + 1BFAB2C307AF66EA00C841BA + WindowToolIsVisible + + + + FirstTimeWindowDisplayed + + Identifier + windowTool.run + Layout + + + Dock + + + ContentConfiguration + + LauncherConfigVersion + 3 + PBXProjectModuleGUID + 1CD0528B0623707200166675 + PBXProjectModuleLabel + Run + Runner + + HorizontalSplitView + + _collapsingFrameDimension + 0.0 + _indexOfCollapsedView + 0 + _percentageOfCollapsedView + 0.0 + isCollapsed + yes + sizes + + {{0, 0}, {491, 167}} + {{0, 176}, {491, 267}} + + + VerticalSplitView + + _collapsingFrameDimension + 0.0 + _indexOfCollapsedView + 0 + _percentageOfCollapsedView + 0.0 + isCollapsed + yes + sizes + + {{0, 0}, {405, 443}} + {{414, 0}, {514, 443}} + + + + + GeometryConfiguration + + Frame + {{0, 0}, {856, 173}} + RubberWindowFrame + 132 91 856 215 0 0 1440 878 + + Module + PBXRunSessionModule + Proportion + 173pt + + + Proportion + 173pt + + + Name + Run Log + ServiceClasses + + PBXRunSessionModule + + StatusbarIsVisible + + TableOfContents + + 1C0AD2B3069F1EA900FABCE6 + 1B82412007BD690200279D6D + 1CD0528B0623707200166675 + 1B82412107BD690200279D6D + + ToolbarConfiguration + xcode.toolbar.config.run + WindowString + 132 91 856 215 0 0 1440 878 + WindowToolGUID + 1C0AD2B3069F1EA900FABCE6 + WindowToolIsVisible + + + + Identifier + windowTool.scm + Layout + + + Dock + + + ContentConfiguration + + PBXProjectModuleGUID + 1C78EAB2065D492600B07095 + PBXProjectModuleLabel + <No Editor> + PBXSplitModuleInNavigatorKey + + Split0 + + PBXProjectModuleGUID + 1C78EAB3065D492600B07095 + + SplitCount + 1 + + StatusBarVisibility + + + GeometryConfiguration + + Frame + {{0, 0}, {452, 0}} + RubberWindowFrame + 743 379 452 308 0 0 1280 1002 + + Module + PBXNavigatorGroup + Proportion + 0pt + + + BecomeActive + + ContentConfiguration + + PBXProjectModuleGUID + 1CD052920623707200166675 + PBXProjectModuleLabel + SCM + + GeometryConfiguration + + ConsoleFrame + {{0, 259}, {452, 0}} + Frame + {{0, 7}, {452, 259}} + RubberWindowFrame + 743 379 452 308 0 0 1280 1002 + TableConfiguration + + Status + 30 + FileName + 199 + Path + 197.09500122070312 + + TableFrame + {{0, 0}, {452, 250}} + + Module + PBXCVSModule + Proportion + 259pt + + + Proportion + 266pt + + + Name + SCM + ServiceClasses + + PBXCVSModule + + StatusbarIsVisible + + TableOfContents + + 1C78EAB4065D492600B07095 + 1C78EAB5065D492600B07095 + 1C78EAB2065D492600B07095 + 1CD052920623707200166675 + + WindowString + 743 379 452 308 0 0 1280 1002 + + + Identifier + windowTool.breakpoints + Layout + + + Dock + + + BecomeActive + + ContentConfiguration + + PBXProjectModuleGUID + 1CD052930623707200166675 + PBXProjectModuleLabel + Breakpoints + + GeometryConfiguration + + BreakpointsTreeTableConfiguration + + enabledColumn + 16 + breakpointColumn + 201.5830078125 + + Frame + {{0, 0}, {240, 195}} + RubberWindowFrame + 342 421 240 216 0 0 1440 878 + + Module + PBXDebugBreakpointsModule + Proportion + 195pt + + + Proportion + 195pt + + + Name + Breakpoints + ServiceClasses + + PBXDebugBreakpointsModule + + StatusbarIsVisible + + TableOfContents + + 1C0AD2AD069F1E9B00FABCE6 + 1C0AD2AE069F1E9B00FABCE6 + 1CD052930623707200166675 + + WindowString + 342 421 240 216 0 0 1440 878 + WindowToolGUID + 1C0AD2AD069F1E9B00FABCE6 + WindowToolIsVisible + + + + Identifier + windowTool.bookmarks + Layout + + + Dock + + + Module + PBXBookmarksModule + Proportion + 166pt + + + Proportion + 166pt + + + Name + Bookmarks + ServiceClasses + + PBXBookmarksModule + + StatusbarIsVisible + + WindowString + 538 42 401 187 0 0 1280 1002 + + + Identifier + windowTool.classBrowser + Layout + + + Dock + + + BecomeActive + + ContentConfiguration + + OptionsSetName + Hierarchy, all classes + PBXProjectModuleGUID + 1CA6456E063B45B4001379D8 + PBXProjectModuleLabel + Class Browser - NSObject + + GeometryConfiguration + + ClassesFrame + {{0, 0}, {374, 96}} + ClassesTreeTableConfiguration + + PBXClassNameColumnIdentifier + 208 + PBXClassBookColumnIdentifier + 22 + + Frame + {{0, 0}, {630, 331}} + MembersFrame + {{0, 105}, {374, 395}} + MembersTreeTableConfiguration + + PBXMemberTypeIconColumnIdentifier + 22 + PBXMemberNameColumnIdentifier + 216 + PBXMemberTypeColumnIdentifier + 97 + PBXMemberBookColumnIdentifier + 22 + + PBXModuleWindowStatusBarHidden2 + + RubberWindowFrame + 385 179 630 352 0 0 1440 878 + + Module + PBXClassBrowserModule + Proportion + 331pt + + + Proportion + 331pt + + + Name + Class Browser + ServiceClasses + + PBXClassBrowserModule + + StatusbarIsVisible + + TableOfContents + + 1C0AD2AF069F1E9B00FABCE6 + 1C0AD2B0069F1E9B00FABCE6 + 1CA6456E063B45B4001379D8 + + ToolbarConfiguration + xcode.toolbar.config.classbrowser + WindowString + 385 179 630 352 0 0 1440 878 + WindowToolGUID + 1C0AD2AF069F1E9B00FABCE6 + WindowToolIsVisible + + + + + diff --git a/LeanCalc.xcode/liyanage.pbxuser b/LeanCalc.xcode/liyanage.pbxuser new file mode 100644 index 0000000..24f3141 --- /dev/null +++ b/LeanCalc.xcode/liyanage.pbxuser @@ -0,0 +1,659 @@ +// !$*UTF8*$! +{ + 1B30E57307AEA98F00363386 = { + activeArgIndex = 2147483647; + activeArgIndices = ( + ); + argumentStrings = ( + ); + configStateDict = { + }; + cppStopOnCatchEnabled = 0; + cppStopOnThrowEnabled = 0; + customDataFormattersEnabled = 1; + debuggerPlugin = GDBDebugging; + disassemblyDisplayState = 0; + dylibVariantSuffix = ""; + enableDebugStr = 1; + environmentEntries = ( + ); + isa = PBXExecutable; + libgmallocEnabled = 0; + name = LeanCalc; + savedGlobals = { + }; + shlibInfoDictList = ( + ); + sourceDirectories = ( + ); + }; + 1B30E57E07AEA99900363386 = { + fallbackIsa = XCSourceControlManager; + isSCMEnabled = 0; + isa = PBXSourceControlManager; + scmConfiguration = { + }; + scmType = ""; + }; + 1B30E57F07AEA99900363386 = { + indexTemplatePath = ""; + isa = PBXCodeSenseManager; + usesDefaults = 1; + wantsCodeCompletion = 1; + wantsCodeCompletionAutoSuggestions = 1; + wantsCodeCompletionCaseSensitivity = 0; + wantsCodeCompletionListAlways = 1; + wantsCodeCompletionOnlyMatchingItems = 1; + wantsCodeCompletionParametersIncluded = 1; + wantsCodeCompletionPlaceholdersInserted = 1; + wantsCodeCompletionTabCompletes = 1; + wantsIndex = 1; + }; + 1B82418207BE13B000279D6D = { + fRef = 2A37F4B7FDCFA73011CA2CEA; + isa = PBXBookmark; + }; + 1B82418507BE13B000279D6D = { + fRef = 2A37F4B7FDCFA73011CA2CEA; + isa = PBXBookmark; + }; + 1B82427B07BF61C600279D6D = { + fRef = 089C1660FE840EACC02AAC07; + isa = PBXTextBookmark; + name = "English: 4"; + rLen = 0; + rLoc = 115; + rType = 0; + vrLen = 124; + vrLoc = 0; + }; + 1B82427E07BF61C600279D6D = { + fRef = 8D15AC360486D014006FF6A4; + isa = PBXTextBookmark; + name = "Info.plist: 48"; + rLen = 0; + rLoc = 1273; + rType = 0; + vrLen = 878; + vrLoc = 382; + }; + 1B82427F07BF61C600279D6D = { + fRef = 089C1660FE840EACC02AAC07; + isa = PBXTextBookmark; + name = "English: 4"; + rLen = 0; + rLoc = 115; + rType = 0; + vrLen = 124; + vrLoc = 0; + }; + 1B82429107BF677B00279D6D = { + fRef = 2A37F4BAFDCFA73011CA2CEA; + isa = PBXTextBookmark; + name = "English: 2"; + rLen = 0; + rLoc = 1; + rType = 0; + vrLen = 163; + vrLoc = 0; + }; + 1B8242D207BF6C9D00279D6D = { + fRef = 8D15AC360486D014006FF6A4; + isa = PBXTextBookmark; + name = "Info.plist: 25"; + rLen = 0; + rLoc = 688; + rType = 0; + vrLen = 949; + vrLoc = 0; + }; + 1B82434A07BF7A4B00279D6D = { + fRef = 8D15AC360486D014006FF6A4; + isa = PBXTextBookmark; + name = "Info.plist: 45"; + rLen = 0; + rLoc = 1246; + rType = 0; + vrLen = 949; + vrLoc = 0; + }; + 1B82434F07BF7A4B00279D6D = { + fRef = 8D15AC360486D014006FF6A4; + isa = PBXTextBookmark; + name = "Info.plist: 45"; + rLen = 0; + rLoc = 1246; + rType = 0; + vrLen = 949; + vrLoc = 0; + }; + 1B8243AF07BF85FE00279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = file; + name = main.m; + path = /Users/liyanage/Desktop/LeanCalc/src/main.m; + refType = 0; + sourceTree = ""; + }; + 1B8243C007BF863D00279D6D = { + fRef = 2A37F4BAFDCFA73011CA2CEA; + isa = PBXTextBookmark; + name = "English: 2"; + rLen = 0; + rLoc = 1; + rType = 0; + vrLen = 163; + vrLoc = 0; + }; + 1B8243C207BF863D00279D6D = { + fRef = 2A37F4BAFDCFA73011CA2CEA; + isa = PBXTextBookmark; + name = "English: 2"; + rLen = 0; + rLoc = 1; + rType = 0; + vrLen = 163; + vrLoc = 0; + }; + 1B8243C407BF865300279D6D = { + fRef = 1B8243BC07BF863600279D6D; + isa = PBXBookmark; + }; + 1B8243C507BF865300279D6D = { + fRef = 1B8243AF07BF85FE00279D6D; + isa = PBXBookmark; + }; + 1B8243C607BF865300279D6D = { + fRef = 1B8243BC07BF863600279D6D; + isa = PBXBookmark; + }; + 1B8243C807BF866200279D6D = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {650, 465}}"; + sepNavSelRange = "{0, 0}"; + sepNavVisRect = "{{0, 0}, {650, 465}}"; + }; + }; + 1B8243CD07BF867300279D6D = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {650, 465}}"; + sepNavSelRange = "{204, 0}"; + sepNavVisRect = "{{0, 0}, {650, 465}}"; + }; + }; + 1B8243E107BF86BE00279D6D = { + fRef = 1B8243CD07BF867300279D6D; + isa = PBXTextBookmark; + name = "AppDelegate.h: 13"; + rLen = 0; + rLoc = 204; + rType = 0; + vrLen = 347; + vrLoc = 0; + }; + 1B8243E307BF86BE00279D6D = { + fRef = 1B8243CD07BF867300279D6D; + isa = PBXTextBookmark; + name = "AppDelegate.h: 13"; + rLen = 0; + rLoc = 204; + rType = 0; + vrLen = 347; + vrLoc = 0; + }; + 1B8243E507BF86C300279D6D = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {650, 465}}"; + sepNavSelRange = "{147, 0}"; + sepNavVisRect = "{{0, 0}, {650, 465}}"; + }; + }; + 1B8243E707BF86C900279D6D = { + fRef = 1B8243C807BF866200279D6D; + isa = PBXTextBookmark; + name = "main.m: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 306; + vrLoc = 0; + }; + 1B8243E807BF86C900279D6D = { + fRef = 1B8243E507BF86C300279D6D; + isa = PBXTextBookmark; + name = "LeanCalc_Prefix.pch: 8"; + rLen = 0; + rLoc = 147; + rType = 0; + vrLen = 147; + vrLoc = 0; + }; + 1B8243E907BF86C900279D6D = { + fRef = 1B8243C807BF866200279D6D; + isa = PBXTextBookmark; + name = "main.m: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 306; + vrLoc = 0; + }; + 1B8243EF07BF879700279D6D = { + fRef = 1B8243E507BF86C300279D6D; + isa = PBXTextBookmark; + name = "LeanCalc_Prefix.pch: 8"; + rLen = 0; + rLoc = 147; + rType = 0; + vrLen = 147; + vrLoc = 0; + }; + 1BADE91E07BC0E6C0020BE61 = { + fRef = 2A37F4B7FDCFA73011CA2CEA; + isa = PBXBookmark; + }; + 1BC8F14907B8301200987A06 = { + fRef = 8D15AC360486D014006FF6A4; + isa = PBXTextBookmark; + name = "Info.plist: 48"; + rLen = 0; + rLoc = 1273; + rType = 0; + vrLen = 949; + vrLoc = 0; + }; + 1BC8F72507B97E7C00987A06 = { + fRef = 1BC8F72607B97E7C00987A06; + isa = PBXTextBookmark; + name = "(null): 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 912; + vrLoc = 0; + }; + 1BC8F72607B97E7C00987A06 = { + isa = PBXFileReference; + lastKnownFileType = text; + name = abs; + path = /Users/liyanage/Desktop/LeanCalc/help/abs; + refType = 0; + sourceTree = ""; + }; + 1BC8F72C07B97E7C00987A06 = { + fRef = 1BC8F72D07B97E7C00987A06; + isa = PBXTextBookmark; + name = "(null): 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 912; + vrLoc = 0; + }; + 1BC8F72D07B97E7C00987A06 = { + isa = PBXFileReference; + lastKnownFileType = text; + name = abs; + path = /Users/liyanage/Desktop/LeanCalc/help/abs; + refType = 0; + sourceTree = ""; + }; + 1BD2F3F207B74F230022B69D = { + fRef = 2A37F4B5FDCFA73011CA2CEA; + isa = PBXBookmark; + }; + 1BD2F3F507B74F230022B69D = { + fRef = 2A37F4B5FDCFA73011CA2CEA; + isa = PBXBookmark; + }; + 1BD2F44B07B828E30022B69D = { + isa = PBXFileReference; + lastKnownFileType = file; + name = LeanCalc.icns; + path = /Users/liyanage/Desktop/LeanCalc/LeanCalc.icns; + refType = 0; + sourceTree = ""; + }; + 1BD2F45007B829610022B69D = { + fRef = 1BD2F44B07B828E30022B69D; + isa = PBXBookmark; + }; + 1BD2F45307B829610022B69D = { + fRef = 2A37F4BAFDCFA73011CA2CEA; + isa = PBXTextBookmark; + name = "English: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 157; + vrLoc = 0; + }; + 1BD2F45407B829610022B69D = { + fRef = 1BD2F44B07B828E30022B69D; + isa = PBXBookmark; + }; + 1BFAB24607AEDC1800C841BA = { + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = zmath.h; + path = /Users/liyanage/Desktop/LeanCalc/Calc/calc/zmath.h; + refType = 0; + sourceTree = ""; + }; + 1BFAB30407AF78F800C841BA = { + fRef = 1BFAB24607AEDC1800C841BA; + isa = PBXTextBookmark; + name = "//typedef SB32 BOOL;\t\t\t/* TRUE or FALSE value */\n"; + rLen = 49; + rLoc = 5600; + rType = 0; + vrLen = 592; + vrLoc = 5342; + }; + 1BFAB30607AF78F800C841BA = { + fRef = 1BFAB24607AEDC1800C841BA; + isa = PBXTextBookmark; + name = "//typedef SB32 BOOL;\t\t\t/* TRUE or FALSE value */\n"; + rLen = 49; + rLoc = 5600; + rType = 0; + vrLen = 592; + vrLoc = 5342; + }; + 2A37F4A9FDCFA73011CA2CEA = { + activeBuildStyle = 4A9504D1FFE6A4CB11CA0CBA; + activeExecutable = 1B30E57307AEA98F00363386; + activeTarget = 8D15AC270486D014006FF6A4; + addToTargets = ( + 8D15AC270486D014006FF6A4, + ); + breakpoints = ( + ); + codeSenseManager = 1B30E57F07AEA99900363386; + executables = ( + 1B30E57307AEA98F00363386, + ); + perUserDictionary = { + PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = { + PBXFileTableDataSourceColumnSortingDirectionKey = "-1"; + PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID; + PBXFileTableDataSourceColumnWidthsKey = ( + 20, + 422, + 20, + 78, + 43, + 43, + 20, + ); + PBXFileTableDataSourceColumnsKey = ( + PBXFileDataSource_FiletypeID, + PBXFileDataSource_Filename_ColumnID, + PBXFileDataSource_Built_ColumnID, + PBXFileDataSource_ObjectSize_ColumnID, + PBXFileDataSource_Errors_ColumnID, + PBXFileDataSource_Warnings_ColumnID, + PBXFileDataSource_Target_ColumnID, + ); + }; + PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = { + PBXFileTableDataSourceColumnSortingDirectionKey = "-1"; + PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID; + PBXFileTableDataSourceColumnWidthsKey = ( + 20, + 360, + 80, + 20, + 80, + 43, + 43, + ); + PBXFileTableDataSourceColumnsKey = ( + PBXFileDataSource_FiletypeID, + PBXFileDataSource_Filename_ColumnID, + PBXTargetDataSource_PrimaryAttribute, + PBXFileDataSource_Built_ColumnID, + PBXFileDataSource_ObjectSize_ColumnID, + PBXFileDataSource_Errors_ColumnID, + PBXFileDataSource_Warnings_ColumnID, + ); + }; + PBXPerProjectTemplateStateSaveDate = 129853534; + PBXPrepackagedSmartGroups_v2 = ( + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + activationKey = OldTargetSmartGroup; + clz = PBXTargetSmartGroup; + description = "Displays all targets of the project."; + globalID = 1C37FABC04509CD000000102; + name = Targets; + preferences = { + image = Targets; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXTargetSmartGroup2; + description = "Displays all targets of the project as well as nested build phases."; + globalID = 1C37FBAC04509CD000000102; + name = Targets; + preferences = { + image = Targets; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXExecutablesSmartGroup; + description = "Displays all executables of the project."; + globalID = 1C37FAAC04509CD000000102; + name = Executables; + preferences = { + image = Executable; + }; + }, + { + " PBXTransientLocationAtTop " = bottom; + absolutePathToBundle = ""; + clz = PBXErrorsWarningsSmartGroup; + description = "Displays files with errors or warnings."; + globalID = 1C08E77C0454961000C914BD; + name = "Errors and Warnings"; + preferences = { + fnmatch = ""; + image = WarningsErrors; + recursive = 1; + regex = ""; + root = ""; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXFilenameSmartGroup; + description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter."; + globalID = 1CC0EA4004350EF90044410B; + name = "Implementation Files"; + preferences = { + canSave = 1; + fnmatch = ""; + image = SmartFolder; + isLeaf = 0; + recursive = 1; + regex = "?*\\.[mcMC]"; + root = ""; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXFilenameSmartGroup; + description = "This group displays Interface Builder NIB Files."; + globalID = 1CC0EA4004350EF90041110B; + name = "NIB Files"; + preferences = { + canSave = 1; + fnmatch = "*.nib"; + image = SmartFolder; + isLeaf = 0; + recursive = 1; + regex = ""; + root = ""; + }; + }, + { + PBXTransientLocationAtTop = no; + absolutePathToBundle = ""; + clz = PBXFindSmartGroup; + description = "Displays Find Results."; + globalID = 1C37FABC05509CD000000102; + name = "Find Results"; + preferences = { + image = spyglass; + }; + }, + { + PBXTransientLocationAtTop = no; + absolutePathToBundle = ""; + clz = PBXBookmarksSmartGroup; + description = "Displays Project Bookmarks."; + globalID = 1C37FABC05539CD112110102; + name = Bookmarks; + preferences = { + image = Bookmarks; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = XCSCMSmartGroup; + description = "Displays files with interesting SCM status."; + globalID = E2644B35053B69B200211256; + name = SCM; + preferences = { + image = PBXRepository; + isLeaf = 0; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXSymbolsSmartGroup; + description = "Displays all symbols for the project."; + globalID = 1C37FABC04509CD000100104; + name = "Project Symbols"; + preferences = { + image = ProjectSymbols; + isLeaf = 1; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXFilenameSmartGroup; + description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter."; + globalID = PBXTemplateMarker; + name = "Simple Filter SmartGroup"; + preferences = { + canSave = 1; + fnmatch = "*.nib"; + image = SmartFolder; + isLeaf = 0; + recursive = 1; + regex = ""; + root = ""; + }; + }, + { + PBXTransientLocationAtTop = bottom; + absolutePathToBundle = ""; + clz = PBXFilenameSmartGroup; + description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter."; + globalID = PBXTemplateMarker; + name = "Simple Regular Expression SmartGroup"; + preferences = { + canSave = 1; + fnmatch = ""; + image = SmartFolder; + isLeaf = 0; + recursive = 1; + regex = "?*\\.[mcMC]"; + root = ""; + }; + }, + { + PBXTransientLocationAtTop = bottom; + clz = XDDesignSmartGroup; + description = "Displays Xdesign models"; + globalID = 2E4A936305E6979E00701470; + name = Design; + preferences = { + image = Design; + isLeaf = 0; + }; + }, + ); + PBXWorkspaceStateSaveDate = 129853534; + }; + perUserProjectItems = { + 1B82418207BE13B000279D6D = 1B82418207BE13B000279D6D; + 1B82418507BE13B000279D6D = 1B82418507BE13B000279D6D; + 1B82427B07BF61C600279D6D = 1B82427B07BF61C600279D6D; + 1B82427E07BF61C600279D6D = 1B82427E07BF61C600279D6D; + 1B82427F07BF61C600279D6D = 1B82427F07BF61C600279D6D; + 1B82429107BF677B00279D6D = 1B82429107BF677B00279D6D; + 1B8242D207BF6C9D00279D6D = 1B8242D207BF6C9D00279D6D; + 1B82434A07BF7A4B00279D6D = 1B82434A07BF7A4B00279D6D; + 1B82434F07BF7A4B00279D6D = 1B82434F07BF7A4B00279D6D; + 1B8243C007BF863D00279D6D = 1B8243C007BF863D00279D6D; + 1B8243C207BF863D00279D6D = 1B8243C207BF863D00279D6D; + 1B8243C407BF865300279D6D = 1B8243C407BF865300279D6D; + 1B8243C507BF865300279D6D = 1B8243C507BF865300279D6D; + 1B8243C607BF865300279D6D = 1B8243C607BF865300279D6D; + 1B8243E107BF86BE00279D6D = 1B8243E107BF86BE00279D6D; + 1B8243E307BF86BE00279D6D = 1B8243E307BF86BE00279D6D; + 1B8243E707BF86C900279D6D = 1B8243E707BF86C900279D6D; + 1B8243E807BF86C900279D6D = 1B8243E807BF86C900279D6D; + 1B8243E907BF86C900279D6D = 1B8243E907BF86C900279D6D; + 1B8243EF07BF879700279D6D = 1B8243EF07BF879700279D6D; + 1BADE91E07BC0E6C0020BE61 = 1BADE91E07BC0E6C0020BE61; + 1BC8F14907B8301200987A06 = 1BC8F14907B8301200987A06; + 1BC8F72507B97E7C00987A06 = 1BC8F72507B97E7C00987A06; + 1BC8F72C07B97E7C00987A06 = 1BC8F72C07B97E7C00987A06; + 1BD2F3F207B74F230022B69D = 1BD2F3F207B74F230022B69D; + 1BD2F3F507B74F230022B69D = 1BD2F3F507B74F230022B69D; + 1BD2F45007B829610022B69D = 1BD2F45007B829610022B69D; + 1BD2F45307B829610022B69D = 1BD2F45307B829610022B69D; + 1BD2F45407B829610022B69D = 1BD2F45407B829610022B69D; + 1BFAB30407AF78F800C841BA = 1BFAB30407AF78F800C841BA; + 1BFAB30607AF78F800C841BA = 1BFAB30607AF78F800C841BA; + }; + sourceControlManager = 1B30E57E07AEA99900363386; + userBuildSettings = { + }; + }; + 2A37F4BAFDCFA73011CA2CEA = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {650, 480}}"; + sepNavSelRange = "{1, 0}"; + sepNavVisRect = "{{0, 0}, {650, 480}}"; + }; + }; + 8D15AC270486D014006FF6A4 = { + activeExec = 0; + executables = ( + 1B30E57307AEA98F00363386, + ); + }; + 8D15AC360486D014006FF6A4 = { + uiCtxt = { + sepNavIntBoundsRect = "{{0, 0}, {797, 672}}"; + sepNavSelRange = "{688, 0}"; + sepNavVisRect = "{{0, 0}, {650, 465}}"; + sepNavWindowFrame = "{{79, 294}, {750, 558}}"; + }; + }; +} diff --git a/LeanCalc.xcode/project.pbxproj b/LeanCalc.xcode/project.pbxproj new file mode 100644 index 0000000..81f5333 --- /dev/null +++ b/LeanCalc.xcode/project.pbxproj @@ -0,0 +1,646 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 39; + objects = { + 089C165FFE840EACC02AAC07 = { + children = ( + 089C1660FE840EACC02AAC07, + ); + isa = PBXVariantGroup; + name = InfoPlist.strings; + refType = 4; + sourceTree = ""; + }; + 089C1660FE840EACC02AAC07 = { + fileEncoding = 10; + isa = PBXFileReference; + lastKnownFileType = text.plist.strings; + name = English; + path = English.lproj/InfoPlist.strings; + refType = 4; + sourceTree = ""; + }; +//080 +//081 +//082 +//083 +//084 +//100 +//101 +//102 +//103 +//104 + 1058C7A6FEA54F5311CA2CBB = { + children = ( + 1BFAB21207AED78500C841BA, + 1BFAB26607AEE8C900C841BA, + 1058C7A7FEA54F5311CA2CBB, + ); + isa = PBXGroup; + name = "Linked Frameworks"; + refType = 4; + sourceTree = ""; + }; + 1058C7A7FEA54F5311CA2CBB = { + isa = PBXFileReference; + lastKnownFileType = wrapper.framework; + name = Cocoa.framework; + path = /System/Library/Frameworks/Cocoa.framework; + refType = 0; + sourceTree = ""; + }; + 1058C7A8FEA54F5311CA2CBB = { + children = ( + 2A37F4C5FDCFA73011CA2CEA, + 2A37F4C4FDCFA73011CA2CEA, + ); + isa = PBXGroup; + name = "Other Frameworks"; + refType = 4; + sourceTree = ""; + }; +//100 +//101 +//102 +//103 +//104 +//190 +//191 +//192 +//193 +//194 + 19C28FB0FE9D524F11CA2CBB = { + children = ( + 8D15AC370486D014006FF6A4, + ); + isa = PBXGroup; + name = Products; + refType = 4; + sourceTree = ""; + }; +//190 +//191 +//192 +//193 +//194 +//1B0 +//1B1 +//1B2 +//1B3 +//1B4 + 1B8243BC07BF863600279D6D = { + isa = PBXFileReference; + lastKnownFileType = image.icns; + name = Calculations.icns; + path = "Icon Artwork/Calculations.icns"; + refType = 4; + sourceTree = ""; + }; + 1B8243BD07BF863600279D6D = { + isa = PBXFileReference; + lastKnownFileType = image.icns; + name = LeanCalc.icns; + path = "Icon Artwork/LeanCalc.icns"; + refType = 4; + sourceTree = ""; + }; + 1B8243BE07BF863600279D6D = { + fileRef = 1B8243BC07BF863600279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243BF07BF863600279D6D = { + fileRef = 1B8243BD07BF863600279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243C807BF866200279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = main.m; + path = Sources/main.m; + refType = 4; + sourceTree = ""; + }; + 1B8243CA07BF866200279D6D = { + fileRef = 1B8243C807BF866200279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243CD07BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = AppDelegate.h; + path = Sources/AppDelegate.h; + refType = 4; + sourceTree = ""; + }; + 1B8243CE07BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = AppDelegate.m; + path = Sources/AppDelegate.m; + refType = 4; + sourceTree = ""; + }; + 1B8243CF07BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = Calculation.h; + path = Sources/Calculation.h; + refType = 4; + sourceTree = ""; + }; + 1B8243D007BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = Calculation.m; + path = Sources/Calculation.m; + refType = 4; + sourceTree = ""; + }; + 1B8243D107BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = CmdKeyInterceptApplication.h; + path = Sources/CmdKeyInterceptApplication.h; + refType = 4; + sourceTree = ""; + }; + 1B8243D207BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = CmdKeyInterceptApplication.m; + path = Sources/CmdKeyInterceptApplication.m; + refType = 4; + sourceTree = ""; + }; + 1B8243D307BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = MyDocument.h; + path = Sources/MyDocument.h; + refType = 4; + sourceTree = ""; + }; + 1B8243D407BF867300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = MyDocument.m; + path = Sources/MyDocument.m; + refType = 4; + sourceTree = ""; + }; + 1B8243D507BF867300279D6D = { + fileRef = 1B8243CD07BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243D607BF867300279D6D = { + fileRef = 1B8243CE07BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243D707BF867300279D6D = { + fileRef = 1B8243CF07BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243D807BF867300279D6D = { + fileRef = 1B8243D007BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243D907BF867300279D6D = { + fileRef = 1B8243D107BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243DA07BF867300279D6D = { + fileRef = 1B8243D207BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243DB07BF867300279D6D = { + fileRef = 1B8243D307BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243DC07BF867300279D6D = { + fileRef = 1B8243D407BF867300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1B8243E507BF86C300279D6D = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = LeanCalc_Prefix.pch; + refType = 4; + sourceTree = ""; + }; + 1B8243E607BF86C300279D6D = { + fileRef = 1B8243E507BF86C300279D6D; + isa = PBXBuildFile; + settings = { + }; + }; + 1BC8F40907B8A3F700987A06 = { + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 7; + files = ( + 1BC8F6E107B9782800987A06, + ); + isa = PBXCopyFilesBuildPhase; + runOnlyForDeploymentPostprocessing = 0; + }; + 1BC8F59807B9780900987A06 = { + isa = PBXFileReference; + lastKnownFileType = folder; + path = help; + refType = 4; + sourceTree = ""; + }; + 1BC8F6E107B9782800987A06 = { + fileRef = 1BC8F59807B9780900987A06; + isa = PBXBuildFile; + settings = { + }; + }; + 1BFAB21207AED78500C841BA = { + isa = PBXFileReference; + lastKnownFileType = archive.ar; + name = libcalc.a; + path = Calc/libcalc.a; + refType = 4; + sourceTree = ""; + }; + 1BFAB21307AED78500C841BA = { + fileRef = 1BFAB21207AED78500C841BA; + isa = PBXBuildFile; + settings = { + }; + }; + 1BFAB26607AEE8C900C841BA = { + isa = PBXFileReference; + lastKnownFileType = archive.ar; + name = libcustcalc.a; + path = Calc/libcustcalc.a; + refType = 4; + sourceTree = ""; + }; + 1BFAB26707AEE8C900C841BA = { + fileRef = 1BFAB26607AEE8C900C841BA; + isa = PBXBuildFile; + settings = { + }; + }; +//1B0 +//1B1 +//1B2 +//1B3 +//1B4 +//2A0 +//2A1 +//2A2 +//2A3 +//2A4 + 2A37F4A9FDCFA73011CA2CEA = { + buildSettings = { + }; + buildStyles = ( + 4A9504D0FFE6A4CB11CA0CBA, + 4A9504D1FFE6A4CB11CA0CBA, + ); + hasScannedForEncodings = 1; + isa = PBXProject; + mainGroup = 2A37F4AAFDCFA73011CA2CEA; + projectDirPath = ""; + targets = ( + 8D15AC270486D014006FF6A4, + ); + }; + 2A37F4AAFDCFA73011CA2CEA = { + children = ( + 2A37F4ABFDCFA73011CA2CEA, + 2A37F4AFFDCFA73011CA2CEA, + 2A37F4B8FDCFA73011CA2CEA, + 2A37F4C3FDCFA73011CA2CEA, + 19C28FB0FE9D524F11CA2CBB, + ); + isa = PBXGroup; + name = LeanCalc; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4ABFDCFA73011CA2CEA = { + children = ( + 1B8243CD07BF867300279D6D, + 1B8243CE07BF867300279D6D, + 1B8243CF07BF867300279D6D, + 1B8243D007BF867300279D6D, + 1B8243D107BF867300279D6D, + 1B8243D207BF867300279D6D, + 1B8243D307BF867300279D6D, + 1B8243D407BF867300279D6D, + ); + isa = PBXGroup; + name = Classes; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4AFFDCFA73011CA2CEA = { + children = ( + 1B8243E507BF86C300279D6D, + 1B8243C807BF866200279D6D, + ); + isa = PBXGroup; + name = "Other Sources"; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4B4FDCFA73011CA2CEA = { + children = ( + 2A37F4B5FDCFA73011CA2CEA, + ); + isa = PBXVariantGroup; + name = MyDocument.nib; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4B5FDCFA73011CA2CEA = { + isa = PBXFileReference; + lastKnownFileType = wrapper.nib; + name = English; + path = English.lproj/MyDocument.nib; + refType = 4; + sourceTree = ""; + }; + 2A37F4B6FDCFA73011CA2CEA = { + children = ( + 2A37F4B7FDCFA73011CA2CEA, + ); + isa = PBXVariantGroup; + name = MainMenu.nib; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4B7FDCFA73011CA2CEA = { + isa = PBXFileReference; + lastKnownFileType = wrapper.nib; + name = English; + path = English.lproj/MainMenu.nib; + refType = 4; + sourceTree = ""; + }; + 2A37F4B8FDCFA73011CA2CEA = { + children = ( + 1B8243BC07BF863600279D6D, + 1B8243BD07BF863600279D6D, + 1BC8F59807B9780900987A06, + 2A37F4B9FDCFA73011CA2CEA, + 2A37F4B6FDCFA73011CA2CEA, + 2A37F4B4FDCFA73011CA2CEA, + 8D15AC360486D014006FF6A4, + 089C165FFE840EACC02AAC07, + ); + isa = PBXGroup; + name = Resources; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4B9FDCFA73011CA2CEA = { + children = ( + 2A37F4BAFDCFA73011CA2CEA, + ); + isa = PBXVariantGroup; + name = Credits.rtf; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4BAFDCFA73011CA2CEA = { + isa = PBXFileReference; + lastKnownFileType = text.rtf; + name = English; + path = English.lproj/Credits.rtf; + refType = 4; + sourceTree = ""; + }; + 2A37F4C3FDCFA73011CA2CEA = { + children = ( + 1058C7A6FEA54F5311CA2CBB, + 1058C7A8FEA54F5311CA2CBB, + ); + isa = PBXGroup; + name = Frameworks; + path = ""; + refType = 4; + sourceTree = ""; + }; + 2A37F4C4FDCFA73011CA2CEA = { + isa = PBXFileReference; + lastKnownFileType = wrapper.framework; + name = AppKit.framework; + path = /System/Library/Frameworks/AppKit.framework; + refType = 0; + sourceTree = ""; + }; + 2A37F4C5FDCFA73011CA2CEA = { + isa = PBXFileReference; + lastKnownFileType = wrapper.framework; + name = Foundation.framework; + path = /System/Library/Frameworks/Foundation.framework; + refType = 0; + sourceTree = ""; + }; +//2A0 +//2A1 +//2A2 +//2A3 +//2A4 +//4A0 +//4A1 +//4A2 +//4A3 +//4A4 + 4A9504D0FFE6A4CB11CA0CBA = { + buildSettings = { + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + HEADER_SEARCH_PATHS = "Calc Sources"; + ZERO_LINK = YES; + }; + isa = PBXBuildStyle; + name = Development; + }; + 4A9504D1FFE6A4CB11CA0CBA = { + buildSettings = { + COPY_PHASE_STRIP = YES; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + HEADER_SEARCH_PATHS = "Calc Sources"; + ZERO_LINK = NO; + }; + isa = PBXBuildStyle; + name = Deployment; + }; +//4A0 +//4A1 +//4A2 +//4A3 +//4A4 +//8D0 +//8D1 +//8D2 +//8D3 +//8D4 + 8D15AC270486D014006FF6A4 = { + buildPhases = ( + 8D15AC2B0486D014006FF6A4, + 8D15AC300486D014006FF6A4, + 8D15AC330486D014006FF6A4, + 1BC8F40907B8A3F700987A06, + ); + buildRules = ( + ); + buildSettings = { + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = LeanCalc_Prefix.pch; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = "/Users/liyanage/Desktop/LeanCalc /Users/liyanage/Desktop/LeanCalc/Calc"; + PRODUCT_NAME = LeanCalc; + WRAPPER_EXTENSION = app; + }; + dependencies = ( + ); + isa = PBXNativeTarget; + name = LeanCalc; + productInstallPath = "$(HOME)/Applications"; + productName = LeanCalc; + productReference = 8D15AC370486D014006FF6A4; + productType = "com.apple.product-type.application"; + }; + 8D15AC2B0486D014006FF6A4 = { + buildActionMask = 2147483647; + files = ( + 8D15AC2C0486D014006FF6A4, + 8D15AC2D0486D014006FF6A4, + 8D15AC2E0486D014006FF6A4, + 8D15AC2F0486D014006FF6A4, + 1B8243BE07BF863600279D6D, + 1B8243BF07BF863600279D6D, + 1B8243D507BF867300279D6D, + 1B8243D707BF867300279D6D, + 1B8243D907BF867300279D6D, + 1B8243DB07BF867300279D6D, + 1B8243E607BF86C300279D6D, + ); + isa = PBXResourcesBuildPhase; + runOnlyForDeploymentPostprocessing = 0; + }; + 8D15AC2C0486D014006FF6A4 = { + fileRef = 2A37F4B9FDCFA73011CA2CEA; + isa = PBXBuildFile; + settings = { + }; + }; + 8D15AC2D0486D014006FF6A4 = { + fileRef = 2A37F4B6FDCFA73011CA2CEA; + isa = PBXBuildFile; + settings = { + }; + }; + 8D15AC2E0486D014006FF6A4 = { + fileRef = 2A37F4B4FDCFA73011CA2CEA; + isa = PBXBuildFile; + settings = { + }; + }; + 8D15AC2F0486D014006FF6A4 = { + fileRef = 089C165FFE840EACC02AAC07; + isa = PBXBuildFile; + settings = { + }; + }; + 8D15AC300486D014006FF6A4 = { + buildActionMask = 2147483647; + files = ( + 1B8243CA07BF866200279D6D, + 1B8243D607BF867300279D6D, + 1B8243D807BF867300279D6D, + 1B8243DA07BF867300279D6D, + 1B8243DC07BF867300279D6D, + ); + isa = PBXSourcesBuildPhase; + runOnlyForDeploymentPostprocessing = 0; + }; + 8D15AC330486D014006FF6A4 = { + buildActionMask = 2147483647; + files = ( + 8D15AC340486D014006FF6A4, + 1BFAB21307AED78500C841BA, + 1BFAB26707AEE8C900C841BA, + ); + isa = PBXFrameworksBuildPhase; + runOnlyForDeploymentPostprocessing = 0; + }; + 8D15AC340486D014006FF6A4 = { + fileRef = 1058C7A7FEA54F5311CA2CBB; + isa = PBXBuildFile; + settings = { + }; + }; + 8D15AC360486D014006FF6A4 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = text.plist; + path = Info.plist; + refType = 4; + sourceTree = ""; + }; + 8D15AC370486D014006FF6A4 = { + explicitFileType = wrapper.application; + includeInIndex = 0; + isa = PBXFileReference; + path = LeanCalc.app; + refType = 3; + sourceTree = BUILT_PRODUCTS_DIR; + }; + }; + rootObject = 2A37F4A9FDCFA73011CA2CEA; +} diff --git a/LeanCalc_Prefix.pch b/LeanCalc_Prefix.pch new file mode 100644 index 0000000..19e379a --- /dev/null +++ b/LeanCalc_Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'LeanCalc' target in the 'LeanCalc' project +// + +#ifdef __OBJC__ + #import +#endif diff --git a/Sources/AppDelegate.h b/Sources/AppDelegate.h new file mode 100644 index 0000000..23b25b4 --- /dev/null +++ b/Sources/AppDelegate.h @@ -0,0 +1,21 @@ +// +// AppDelegate.h +// LeanCalc +// +// Created by Marc Liyanage on 08.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface AppDelegate : NSObject { + + NSMutableArray *functionReference; + +} + +- (void)initFunctionReference; +- (NSArray *)completionsForPartialWord:(NSString *)partialWord; + +@end diff --git a/Sources/AppDelegate.m b/Sources/AppDelegate.m new file mode 100644 index 0000000..58b6163 --- /dev/null +++ b/Sources/AppDelegate.m @@ -0,0 +1,75 @@ +// +// AppDelegate.m +// LeanCalc +// +// Created by Marc Liyanage on 08.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import "AppDelegate.h" + +@implementation AppDelegate + +- (id)init { + + self = [super init]; + if (!self) return nil; + + [self initFunctionReference]; + + return self; + +} + + +- (void)initFunctionReference { + + + NSLog(@"start"); + functionReference = [[NSMutableArray alloc] init]; + + NSString *helpBasedir = [NSString stringWithFormat:@"%@/help", [[NSBundle mainBundle] resourcePath]]; + NSArray *helpFiles = [[NSFileManager defaultManager] directoryContentsAtPath:helpBasedir]; + + NSEnumerator *enumerator = [helpFiles objectEnumerator]; + id filename; + while (filename = [enumerator nextObject]) { + NSString *fullPath = [NSString stringWithFormat:@"%@/%@", helpBasedir, filename]; + NSString *fileContents = [NSString stringWithContentsOfFile:fullPath]; + NSDictionary *newEntry = [NSDictionary dictionaryWithObjectsAndKeys:filename, @"name", fileContents, @"text", nil]; + [functionReference addObject:newEntry]; + } + NSLog(@"stop"); + +} + + + +- (NSArray *)completionsForPartialWord:(NSString *)partialWord { + + NSEnumerator *enumerator = [functionReference objectEnumerator]; + NSMutableArray *completions = [NSMutableArray array]; + + id entry; + while (entry = [enumerator nextObject]) { + NSString *name = [NSString stringWithFormat:@"%@()", [entry valueForKey:@"name"]]; + if ([name hasPrefix:partialWord]) { + [completions addObject:name]; + } + } + + return completions; + +} + + + +- (void)dealloc { + + [functionReference release]; + +} + + + +@end diff --git a/Sources/Calculation.h b/Sources/Calculation.h new file mode 100644 index 0000000..0b308a6 --- /dev/null +++ b/Sources/Calculation.h @@ -0,0 +1,24 @@ +// +// Calculation.h +// LeanCalc +// +// Created by Marc Liyanage on 04.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import +#include +#include "calc/zmath.h" +#include "calc/value.h" + +@interface Calculation : NSObject { + NSString *expression; + id next; +} + +- (NSString *)result; +- (NSString *)shortcut; +- (int)historyIndex; +- (BOOL)expressionIsEmpty; + +@end diff --git a/Sources/Calculation.m b/Sources/Calculation.m new file mode 100644 index 0000000..51c8913 --- /dev/null +++ b/Sources/Calculation.m @@ -0,0 +1,134 @@ +// +// Calculation.m +// LeanCalc +// +// Created by Marc Liyanage on 04.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import "Calculation.h" + + +@implementation Calculation + +- (id)init { + + self = [super init]; + if (!self) return nil; + + STRING *falseString = makestring("false"); + VALUE falseValue; + falseValue.v_type = V_STR; + falseValue.v_subtype = V_NOSUBTYPE; + falseValue.v_str = falseString; + setconfig(CONFIG_TILDE, &falseValue); + setconfig(CONFIG_TAB, &falseValue); + + [Calculation setKeys:[NSArray arrayWithObject:@"expression"] triggerChangeNotificationsForDependentKey:@"result"]; + + return self; +} + + + +- (void)dealloc { + + [expression release]; + [next release]; +} + + + +- (NSString *)shortcut { + + int historyIndex = [self historyIndex]; + if (historyIndex < 1) return nil; + + unichar ch = 0x2318; + NSString *str = [NSString stringWithCharacters:&ch length:1]; + return [NSString stringWithFormat:@"%@ %d", str, historyIndex]; +} + + + +- (int)historyIndex { + if (!next) return 0; + int nextIndex = [next historyIndex]; + if (nextIndex > 8 || nextIndex == -1) return -1; + return nextIndex + 1; +} + + + + + + + + +extern jmp_buf calc_jmp_buf; +extern jmp_buf jmpbuf; +extern int calc_jmp; +extern char *calc_error; + +- (NSString *)result { + + if (![expression length]) return nil; + + int error; + if ((error = setjmp(calc_jmp_buf)) != 0) { + reinitialize(); + calc_jmp = 1; + return nil; + } + calc_jmp = 1; + + if ((error = setjmp(jmpbuf)) != 0) { + reinitialize(); + return nil; + } + reinitialize(); + + openstring([expression UTF8String], [expression length]); + math_divertio(); + getcommands(1); + char *result = math_getdivertedio(); + NSString *resultString = [[NSString stringWithCString:result] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if (result) free(result); + + return resultString; + +} + + +- (BOOL)expressionIsEmpty { + return ![expression length]; +} + + + +- (void)encodeWithCoder:(NSCoder *)coder +{ + +// [super encodeWithCoder:coder]; + [coder encodeObject:expression forKey:@"expression"]; + [coder encodeObject:next forKey:@"next"]; + +} + + +- (id)initWithCoder:(NSCoder *)decoder { + + self = [super init]; + if (!self) return nil; + + [self setValue:[decoder decodeObjectForKey:@"expression"] forKey:@"expression"]; + [self setValue:[decoder decodeObjectForKey:@"next"] forKey:@"next"]; + return self; +} + + + + + +@end diff --git a/Sources/CmdKeyInterceptApplication.h b/Sources/CmdKeyInterceptApplication.h new file mode 100644 index 0000000..187344f --- /dev/null +++ b/Sources/CmdKeyInterceptApplication.h @@ -0,0 +1,18 @@ +// +// CmdKeyInterceptApplication.h +// LeanCalc +// +// Created by Marc Liyanage on 13.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface CmdKeyInterceptApplication : NSApplication { + + + +} + +@end diff --git a/Sources/CmdKeyInterceptApplication.m b/Sources/CmdKeyInterceptApplication.m new file mode 100644 index 0000000..7178043 --- /dev/null +++ b/Sources/CmdKeyInterceptApplication.m @@ -0,0 +1,38 @@ +// +// CmdKeyInterceptApplication.m +// LeanCalc +// +// Created by Marc Liyanage on 13.02.05. +// Copyright 2005 __MyCompanyName__. All rights reserved. +// + +#import "CmdKeyInterceptApplication.h" + + +@implementation CmdKeyInterceptApplication + +- (void)sendEvent:(NSEvent *)event { + + if ([event type] != NSKeyDown) { + [super sendEvent:event]; + return; + } + + /* Look at the top 16 bits, only intercept + * key down events whose only modifier is the command key */ + if (([event modifierFlags] & 0xffff0000) != NSCommandKeyMask) { + [super sendEvent:event]; + return; + } + + int index = [[event characters] intValue]; + if (index > 9 || index < 1) { + [super sendEvent:event]; + return; + } + + [self sendAction:@selector(insertPrevious:) to:nil from:[NSNumber numberWithInt:index]]; + +} + +@end diff --git a/Sources/MyDocument.h b/Sources/MyDocument.h new file mode 100644 index 0000000..f842c24 --- /dev/null +++ b/Sources/MyDocument.h @@ -0,0 +1,35 @@ +// +// MyDocument.h +// LeanCalc +// +// Created by Marc Liyanage on 31.01.05. +// Copyright __MyCompanyName__ 2005 . All rights reserved. +// + + +#import +#import "Calculation.h" +#import "AppDelegate.h" + +@interface MyDocument : NSDocument +{ +// NSString *inputString, *resultValue; + NSTextField *expressionField; + NSMutableArray *calculations; + NSArrayController *arrayController; + NSWindow *window; +} + + + +- (IBAction)commit:(id)sender; +- (void)addItem; +- (BOOL)lastItemIsSelected; +- (void)insertPrevious:(id)sender; +//- (void)insertPrevious; + +/* +- (BOOL)setupHistoryMenu:(NSMenu *)submenu; +- (void)updateHistoryMenu; +*/ +@end diff --git a/Sources/MyDocument.m b/Sources/MyDocument.m new file mode 100644 index 0000000..51823fe --- /dev/null +++ b/Sources/MyDocument.m @@ -0,0 +1,144 @@ +// +// MyDocument.m +// LeanCalc +// +// Created by Marc Liyanage on 31.01.05. +// Copyright __MyCompanyName__ 2005 . All rights reserved. +// + + +/* todo + +- num lock / esc clear expression + + +*/ + + + +#import "MyDocument.h" + +@implementation MyDocument + +- (id)init { + + self = [super init]; + if (!self) return nil; + + calculations = [[NSMutableArray alloc] init]; + + return self; +} + + + +- (void)dealloc { + [calculations release]; +} + + + +- (void)awakeFromNib { + + if (![self fileName]) { + [arrayController add:self]; + } + + [arrayController setSelectionIndex:[calculations count] - 1]; + +} + + +- (IBAction)commit:(id)sender { + + if (![[sender stringValue] length]) return; + + if (![self lastItemIsSelected] && [[calculations lastObject] expressionIsEmpty]) { + [arrayController setSelectedObjects:[NSArray arrayWithObject:[calculations lastObject]]]; + return; + } + [self addItem]; +} + + + +- (BOOL)lastItemIsSelected { + + id lastObject = [calculations lastObject]; + id selectedObject = [[arrayController selectedObjects] objectAtIndex:0]; + + return selectedObject == lastObject; + +} + + +- (void)addItem { + + [arrayController add:self]; + int count = [calculations count]; + id last = [calculations objectAtIndex:count - 1]; + id secondtolast = [calculations objectAtIndex:count - 2]; + [secondtolast setValue:last forKey:@"next"]; + +} + + +- (void)insertPrevious:(NSNumber *)sender { + + int index = [sender intValue]; + if ([calculations count] <= index) return; + + NSString *value = [[calculations objectAtIndex:[calculations count] - index - 1] valueForKey:@"result"]; + [[expressionField currentEditor] insertText:value]; +} + + + + + +- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index { + + NSString *partialWord = [[textView string] substringWithRange:charRange]; + NSArray *completions = [[[NSApplication sharedApplication] delegate] completionsForPartialWord:partialWord]; + + return completions; + +} + + + +- (NSString *)windowNibName +{ + // Override returning the nib file name of the document + // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. + return @"MyDocument"; +} + +- (void)windowControllerDidLoadNib:(NSWindowController *) aController +{ + [super windowControllerDidLoadNib:aController]; + // Add any code here that needs to be executed once the windowController has loaded the document's window. + +} + +- (NSData *)dataRepresentationOfType:(NSString *)aType { + + NSMutableData *data = [[[NSMutableData alloc] init] autorelease]; + NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:data] autorelease]; + [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0]; + [archiver encodeObject:calculations forKey:@"calculations"]; + [archiver finishEncoding]; + return data; +} + + +- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType { + + NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:data] autorelease]; + [self setValue:[unarchiver decodeObjectForKey:@"calculations"] forKey:@"calculations"]; + [unarchiver finishDecoding]; + + return YES; +} + +@end diff --git a/Sources/main.m b/Sources/main.m new file mode 100644 index 0000000..ff6d71e --- /dev/null +++ b/Sources/main.m @@ -0,0 +1,16 @@ +// +// main.m +// LeanCalc +// +// Created by Marc Liyanage on 31.01.05. +// Copyright __MyCompanyName__ 2005 . All rights reserved. +// + +#import +#include "calc/qmath.h" + +int main(int argc, char *argv[]) +{ + libcalc_call_me_first(); + return NSApplicationMain(argc, (const char **) argv); +} diff --git a/calc/calc-ml.diff b/calc/calc-ml.diff new file mode 100644 index 0000000..1f85fac --- /dev/null +++ b/calc/calc-ml.diff @@ -0,0 +1,135 @@ +Only in calc-2.11.10.1-ml/: .hsrc +diff -ru calc-2.11.10.1/Makefile calc-2.11.10.1-ml/Makefile +--- calc-2.11.10.1/Makefile Thu Jul 29 07:18:56 2004 ++++ calc-2.11.10.1-ml/Makefile Tue Feb 1 22:58:07 2005 +@@ -670,7 +670,7 @@ + # + # If in doubt, use T= + # +-T= ++T=/tmp/calc + + # where man pages are installed + # +@@ -999,7 +999,7 @@ + CCOPT= ${DEBUG} ${NO_SHARED} + CCMISC= + # +-CFLAGS= -DCALC_SRC ${CCWARN} ${CCOPT} ${CCMISC} ++CFLAGS= -DHAVE_SNPRINTF -DCALC_SRC ${CCWARN} ${CCOPT} ${CCMISC} + ICFLAGS= -DCALC_SRC ${CCWARN} ${CCMISC} + # + LDFLAGS= ${NO_SHARED} ${LD_NO_SHARED} +Only in calc-2.11.10.1-ml/: align32.h +Only in calc-2.11.10.1-ml/: args.h +Only in calc-2.11.10.1-ml/cal: .all +Only in calc-2.11.10.1-ml/: calc +Only in calc-2.11.10.1-ml/: calc.1 +Only in calc-2.11.10.1-ml/: calcerr.c +Only in calc-2.11.10.1-ml/: calcerr.h +Only in calc-2.11.10.1-ml/: conf.h +Only in calc-2.11.10.1-ml/cscript: .all +Only in calc-2.11.10.1-ml/cscript: 4dsphere +Only in calc-2.11.10.1-ml/cscript: fproduct +Only in calc-2.11.10.1-ml/cscript: mersenne +Only in calc-2.11.10.1-ml/cscript: piforever +Only in calc-2.11.10.1-ml/cscript: plus +Only in calc-2.11.10.1-ml/cscript: powerterm +Only in calc-2.11.10.1-ml/cscript: simple +Only in calc-2.11.10.1-ml/cscript: square +Only in calc-2.11.10.1-ml/custom: .all +Only in calc-2.11.10.1-ml/: endian_calc.h +Only in calc-2.11.10.1-ml/: fposval.h +Only in calc-2.11.10.1-ml/: have_const.h +Only in calc-2.11.10.1-ml/: have_fpos.h +Only in calc-2.11.10.1-ml/: have_fpos_pos.h +Only in calc-2.11.10.1-ml/: have_getpgid.h +Only in calc-2.11.10.1-ml/: have_getprid.h +Only in calc-2.11.10.1-ml/: have_getsid.h +Only in calc-2.11.10.1-ml/: have_gettime.h +Only in calc-2.11.10.1-ml/: have_malloc.h +Only in calc-2.11.10.1-ml/: have_memmv.h +Only in calc-2.11.10.1-ml/: have_newstr.h +Only in calc-2.11.10.1-ml/: have_offscl.h +Only in calc-2.11.10.1-ml/: have_posscl.h +Only in calc-2.11.10.1-ml/: have_rusage.h +Only in calc-2.11.10.1-ml/: have_stdlib.h +Only in calc-2.11.10.1-ml/: have_strdup.h +Only in calc-2.11.10.1-ml/: have_string.h +Only in calc-2.11.10.1-ml/: have_times.h +Only in calc-2.11.10.1-ml/: have_uid_t.h +Only in calc-2.11.10.1-ml/: have_unistd.h +Only in calc-2.11.10.1-ml/: have_unused.h +Only in calc-2.11.10.1-ml/: have_urandom.h +Only in calc-2.11.10.1-ml/: have_ustat.h +Only in calc-2.11.10.1-ml/help: .all +Only in calc-2.11.10.1-ml/help: binding +Only in calc-2.11.10.1-ml/help: bindings +Only in calc-2.11.10.1-ml/help: bug +Only in calc-2.11.10.1-ml/help: bugs +Only in calc-2.11.10.1-ml/help: builtin +Only in calc-2.11.10.1-ml/help: calc +Only in calc-2.11.10.1-ml/help: change +Only in calc-2.11.10.1-ml/help: changes +Only in calc-2.11.10.1-ml/help: copy +Only in calc-2.11.10.1-ml/help: cscript +Only in calc-2.11.10.1-ml/help: custom_cal +Only in calc-2.11.10.1-ml/help: errorcode +Only in calc-2.11.10.1-ml/help: errorcodes +Only in calc-2.11.10.1-ml/help: full +Only in calc-2.11.10.1-ml/help: libcalc +Only in calc-2.11.10.1-ml/help: new_custom +Only in calc-2.11.10.1-ml/help: resource +Only in calc-2.11.10.1-ml/help: type +Only in calc-2.11.10.1-ml/: longbits.h +diff -ru calc-2.11.10.1/math_error.c calc-2.11.10.1-ml/math_error.c +--- calc-2.11.10.1/math_error.c Sat Mar 17 22:55:52 2001 ++++ calc-2.11.10.1-ml/math_error.c Tue Feb 1 23:18:28 2005 +@@ -76,7 +76,7 @@ + */ + jmp_buf calc_jmp_buf; + int calc_jmp = 0; /* non-zero => use calc_jmp_buf */ +-char calc_error[MAXERROR+1]; /* last calc error message */ ++//char calc_error[MAXERROR+1]; /* last calc error message */ + + + /* +diff -ru calc-2.11.10.1/math_error.h calc-2.11.10.1-ml/math_error.h +--- calc-2.11.10.1/math_error.h Fri Jun 8 23:00:58 2001 ++++ calc-2.11.10.1-ml/math_error.h Tue Feb 1 23:18:43 2005 +@@ -43,6 +43,8 @@ + /* + * Global data definitions. + */ ++char calc_error[MAXERROR+1]; /* last calc error message */ ++ + extern DLL jmp_buf jmpbuf; /* for errors */ + + +Only in calc-2.11.10.1-ml/sample: .all +Only in calc-2.11.10.1-ml/sample: many_random +Only in calc-2.11.10.1-ml/sample: test_random +Only in calc-2.11.10.1-ml/: terminal.h +diff -ru calc-2.11.10.1/token.c calc-2.11.10.1-ml/token.c +--- calc-2.11.10.1/token.c Sat Mar 17 22:55:52 2001 ++++ calc-2.11.10.1-ml/token.c Tue Feb 1 23:19:13 2005 +@@ -702,6 +702,8 @@ + } + + ++//extern char *calc_error; ++ + /* + * Describe an error message. + * Then skip to the next specified token (or one more powerful). +@@ -722,8 +724,9 @@ + fprintf(stderr, "\"%s\", line %ld: ", name, linenumber()); + va_start(ap, fmt); + vsprintf(buf, fmt, ap); ++ vsprintf(calc_error, fmt, ap); + va_end(ap); +- fprintf(stderr, "%s\n", buf); ++// fprintf(stderr, "%s\n", buf); + + /* bail out if continuation not permitted */ + if ((!c_flag && !stoponerror) || stoponerror > 0) diff --git a/calc/calc/align32.h b/calc/calc/align32.h new file mode 100644 index 0000000..e368689 --- /dev/null +++ b/calc/calc/align32.h @@ -0,0 +1,15 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__MUST_ALIGN32_H__) +#define __MUST_ALIGN32_H__ + + +/* must we always align 32 bit accesses? */ +/* guess we must align 32 bit values */ +#define MUST_ALIGN32 + + +#endif /* !__MUST_ALIGN32_H__ */ diff --git a/calc/calc/alloc.h b/calc/calc/alloc.h new file mode 100644 index 0000000..2b2527d --- /dev/null +++ b/calc/calc/alloc.h @@ -0,0 +1,106 @@ +/* + * alloc - storage allocation and storage debug macros + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:29 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__ALLOC_H__) +#define __ALLOC_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/have_malloc.h" +# include "calc/have_newstr.h" +# include "calc/have_string.h" +# include "calc/have_memmv.h" +#else +# include +# include +# include +# include +#endif + +#ifdef HAVE_MALLOC_H +# include +#else +#if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || defined(__cplusplus) + extern void *malloc(); + extern void *realloc(); + extern void free(); +# else + extern char *malloc(); + extern char *realloc(); + extern void free(); +# endif +#endif + +#ifdef HAVE_STRING_H +# include + +#else + +# if defined(HAVE_NEWSTR) +extern void *memcpy(); +extern void *memset(); +#if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || defined(__cplusplus) +extern size_t strlen(); +# else +extern long strlen(); +# endif +# else /* HAVE_NEWSTR */ +extern void bcopy(); +extern void bfill(); +extern char *index(); +# endif /* HAVE_NEWSTR */ +extern char *strchr(); +extern char *strcpy(); +extern char *strncpy(); +extern char *strcat(); +extern int strcmp(); + +#endif + +#if !defined(HAVE_NEWSTR) +#undef memcpy +#define memcpy(s1, s2, n) bcopy(s2, s1, n) +#undef memset +#define memset(s, c, n) bfill(s, n, c) +#undef strchr +#define strchr(s, c) index(s, c) +#endif /* HAVE_NEWSTR */ + +#if !defined(HAVE_MEMMOVE) +# undef CALC_SIZE_T +#if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || defined(__cplusplus) +# define CALC_SIZE_T size_t +# else +# define CALC_SIZE_T long +# endif +extern void *memmove(void *s1, const void *s2, CALC_SIZE_T n); +#endif + +#endif /* !__ALLOC_H__ */ diff --git a/calc/calc/args.h b/calc/calc/args.h new file mode 100644 index 0000000..4f72462 --- /dev/null +++ b/calc/calc/args.h @@ -0,0 +1,18 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__ARGS_H__) +#define __ARGS_H__ + + +/* what type of variable args do we have? */ +#define STDARG /* use */ +#include + +/* should we use vsprintf()? */ +#define HAVE_VS /* yes */ + + +#endif /* !__ARGS_H__ */ diff --git a/calc/calc/blkcpy.h b/calc/calc/blkcpy.h new file mode 100644 index 0000000..c7736f4 --- /dev/null +++ b/calc/calc/blkcpy.h @@ -0,0 +1,62 @@ +/* + * blkcpy - general values and related routines used by the calculator + * + * Copyright (C) 1999 Landon Curt Noll and Ernest Bowen + * + * Primary author: Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/04/18 20:41:25 + * File existed as early as: 1997 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__BLKCPY_H__) +#define __BLKCPY_H__ + +/* + * the main copy gateway function + */ +extern int copystod(VALUE *, long, long, VALUE *, long); + +/* + * specific copy functions + */ +extern int copyblk2blk(BLOCK *, long, long, BLOCK *, long, BOOL); +extern int copyblk2file(BLOCK *, long, long, FILEID, long); +extern int copyblk2mat(BLOCK *, long, long, MATRIX *, long); +extern int copyblk2num(BLOCK *, long, long, NUMBER *, long, NUMBER **); +extern int copyblk2str(BLOCK *, long, long, STRING *, long); +extern int copyfile2blk(FILEID, long, long, BLOCK *, long, BOOL); +extern int copylist2list(LIST *, long, long, LIST *, long); +extern int copylist2mat(LIST *, long, long, MATRIX *, long); +extern int copymat2blk(MATRIX *, long, long, BLOCK *, long, BOOL); +extern int copymat2list(MATRIX *, long, long, LIST *, long); +extern int copymat2mat(MATRIX *, long, long, MATRIX *, long); +extern int copynum2blk(NUMBER *, long, long, BLOCK *, long, BOOL); +extern int copyostr2blk(char *, long, long, BLOCK *, long, BOOL); +extern int copyostr2str(char *, long, long, STRING *, long); +extern int copystr2blk(STRING *, long, long, BLOCK *, long, BOOL); +extern int copystr2file(STRING *, long, long, FILEID, long); +extern int copystr2str(STRING *, long, long, STRING *, long); + +#endif /* !__BLKCPY_H__ */ diff --git a/calc/calc/block.h b/calc/calc/block.h new file mode 100644 index 0000000..d1df35c --- /dev/null +++ b/calc/calc/block.h @@ -0,0 +1,225 @@ +/* + * block - fixed, dynamic, fifo and circular memory blocks + * + * Copyright (C) 1999 Landon Curt Noll and Ernest Bowen + * + * Primary author: Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/02/21 05:03:39 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__BLOCK_H__) +#define __BLOCK_H__ + + +/* + * block - the basic block structure + * + * A block comes is one of several types. At the moment, only fixed + * types are defined. + * + *** + * + * Block functions and operations: + * + * x[i] + * (i-1)th octet + * + * blk(len [, blkchunk]) + * unnamed block + * len > 0 + * blkchunk defaults to BLK_CHUNKSIZE + * + * blk(name, [len [, blkchunk]]) + * named block + * len > 0 + * blkchunk defaults to BLK_CHUNKSIZE + * + * blkfree(x) + * Reduce storage down to 0 octetes. + * + * size(x) + * The length of data stored in the block. + * + * sizeof(x) == blk->maxsize + * Allocation size in memory + * + * isblk(x) + * returns 0 is x is not a BLOCK, 1 if x is an + * unnamed block, 2 if x is a named BLOCK + * + * blkread(x, size, count, fd [, offset]) + * blkwrite(x, size, count, fd [, offset]) + * returns number of items written + * offset is restricted in value by block type + * + * blkset(x, val, length [, offset]) + * only the lower octet of val is used + * offset is restricted in value by block type + * + * blkchr(x, val, length [, offset]) + * only the lower octet of val is used + * offset is restricted in value by block type + * + * blkcpy(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * dest may not == src + * + * blkmove(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * overlapping moves are handeled correctly + * + * blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * + * blkcmp(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * + * blkswap(x, a, b) + * swaps groups of 'a' octets within each 'b' octets + * b == a is a noop + * b = a*k for some integer k >= 1 + * + * scatter(src, dest1, dest2 [, dest3 ] ...) + * copy sucessive octets from src into dest1, dest2, ... + * restarting with dest1 after end of list + * stops at end of src + * + * gather(dest, src1, src2 [, src3 ] ...) + * copy first octet from src1, src2, ... + * copy next octet from src1, src2, ... + * ... + * copy last octet from src1, src2, ... + * copy 0 when there is no more data from a given source + * + * blkseek(x, offset, {"in","out"}) + * some seeks may not be allowed by block type + * + * config("blkmaxprint", count) + * number of octets of a block to print, 0 means all + * + * config("blkverbose", boolean) + * TRUE => print all lines, FALSE => skip dup lines + * + * config("blkbase", "base") + * output block base = { "hex", "octal", "char", "binary", "raw" } + * binary is base 2, raw is just octet values + * + * config("blkfmt", "style") + * style of output = { + * "line", lines in blkbase with no spaces between octets + * "string", as one long line with no spaces between octets + * "od_style", position, spaces between octets + * "hd_style"} position, spaces between octets, chars on end + */ +struct block { + LEN blkchunk; /* allocation chunk size */ + LEN maxsize; /* octets actually malloced for this block */ + LEN datalen; /* octets of data held this block */ + USB8 *data; /* pointer to the 1st octet of the allocated data */ +}; +typedef struct block BLOCK; + + +struct nblock { + char *name; + int subtype; + int id; + BLOCK *blk; +}; +typedef struct nblock NBLOCK; + + +/* + * block debug + */ +extern int blk_debug; /* 0 => debug off */ + + +/* + * block defaults + */ +#define BLK_CHUNKSIZE 256 /* default allocation chunk size for blocks */ + +#define BLK_DEF_MAXPRINT 256 /* default octets to print */ + +#define BLK_BASE_HEX 0 /* output octets in a block in hex */ +#define BLK_BASE_OCT 1 /* output octets in a block in octal */ +#define BLK_BASE_CHAR 2 /* output octets in a block in characters */ +#define BLK_BASE_BINARY 3 /* output octets in a block in base 2 chars */ +#define BLK_BASE_RAW 4 /* output octets in a block in raw binary */ + +#define BLK_FMT_HD_STYLE 0 /* output in base with chars on end of line */ +#define BLK_FMT_LINE 1 /* output is lines of up to 79 chars */ +#define BLK_FMT_STRING 2 /* output is one long string */ +#define BLK_FMT_OD_STYLE 3 /* output in base with chars */ + + +/* + * block macros + */ +/* length of data stored in a block */ +#define blklen(blk) ((blk)->datalen) + +/* block footpint in memory */ +#define blksizeof(blk) ((blk)->maxsize) + +/* block allocation chunk size */ +#define blkchunk(blk) ((blk)->blkchunk) + + +/* + * OCTET - what the INDEXADDR produces from a blk[offset] + */ +typedef USB8 OCTET; + + +/* + * external functions + */ +extern BLOCK *blkalloc(int, int); +extern void blk_free(BLOCK*); +extern BLOCK *blkrealloc(BLOCK*, int, int); +extern void blktrunc(BLOCK*); +extern BLOCK *blk_copy(BLOCK*); +extern int blk_cmp(BLOCK*, BLOCK*); +extern void blk_print(BLOCK*); +extern void nblock_print(NBLOCK *); +extern NBLOCK *createnblock(char *, int, int); +extern NBLOCK *reallocnblock(int, int, int); +extern int removenblock(int); +extern int findnblockid(char *); +extern NBLOCK *findnblock(int); +extern BLOCK *copyrealloc(BLOCK*, int, int); +extern int countnblocks(void); +extern void shownblocks(void); + + +#endif /* !__BLOCK_H__ */ diff --git a/calc/calc/byteswap.h b/calc/calc/byteswap.h new file mode 100644 index 0000000..5bbb08f --- /dev/null +++ b/calc/calc/byteswap.h @@ -0,0 +1,181 @@ +/* + * byteswap - byte swapping macros + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1995/10/11 04:44:01 + * File existed as early as: 1995 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__BYTESWAP_H__) +#define __BYTESWAP_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/longbits.h" +#else +# include +#endif + + +/* + * SWAP_B8_IN_B16 - swap 8 bits in 16 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 16 bit value to swap + * + * This macro will either switch to the opposite byte sex (Big Endian vs. + * Little Endian) a 16 bit value. + */ +#define SWAP_B8_IN_B16(dest, src) ( \ + *((USB16*)(dest)) = \ + (((*((USB16*)(src))) << 8) | ((*((USB16*)(src))) >> 8)) \ +) + +/* + * SWAP_B16_IN_B32 - swap 16 bits in 32 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 32 bit value to swap + */ +#define SWAP_B16_IN_B32(dest, src) ( \ + *((USB32*)(dest)) = \ + (((*((USB32*)(src))) << 16) | ((*((USB32*)(src))) >> 16)) \ +) + +/* + * SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 32 bit value to swap + * + * This macro will either switch to the opposite byte sex (Big Endian vs. + * Little Endian) a 32 bit value. + */ +#define SWAP_B8_IN_B32(dest, src) ( \ + SWAP_B16_IN_B32(dest, src), \ + (*((USB32*)(dest)) = \ + ((((*((USB32*)(dest))) & (USB32)0xff00ff00) >> 8) | \ + (((*((USB32*)(dest))) & (USB32)0x00ff00ff) << 8))) \ +) + +#if defined(HAVE_B64) + +/* + * SWAP_B32_IN_B64 - swap 32 bits in 64 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + */ +#define SWAP_B32_IN_B64(dest, src) ( \ + *((USB64*)(dest)) = \ + (((*((USB64*)(src))) << 32) | ((*((USB64*)(src))) >> 32)) \ +) + +/* + * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + */ +#define SWAP_B16_IN_B64(dest, src) ( \ + SWAP_B32_IN_B64(dest, src), \ + (*((USB64*)(dest)) = \ + ((((*((USB64*)(dest))) & (USB64)0xffff0000ffff0000) >> 16) | \ + (((*((USB64*)(dest))) & (USB64)0x0000ffff0000ffff) << 16))) \ +) + +/* + * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + * + * This macro will either switch to the opposite byte sex (Big Endian vs. + * Little Endian) a 64 bit value. + */ +#define SWAP_B8_IN_B64(dest, src) ( \ + SWAP_B16_IN_B64(dest, src), \ + (*((USB64*)(dest)) = \ + ((((*((USB64*)(dest))) & (USB64)0xff00ff00ff00ff00) >> 8) | \ + (((*((USB64*)(dest))) & (USB64)0x00ff00ff00ff00ff) << 8))) \ +) + +#else /* HAVE_B64 */ + +/* + * SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values) + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + */ +#define SWAP_B32_IN_B64(dest, src) ( \ + ((USB32*)(dest))[1] = ((USB32*)(dest))[0], \ + ((USB32*)(dest))[0] = ((USB32*)(dest))[1] \ +) + +/* + * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals) + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + */ +#define SWAP_B16_IN_B64(dest, src) ( \ + SWAP_B16_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ + SWAP_B16_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ +) + +/* + * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals) + * + * dest - pointer to where the swapped src wil be put + * src - pointer to a 64 bit value to swap + * + * This macro will either switch to the opposite byte sex (Big Endian vs. + * Little Endian) a 64 bit value. + */ +#define SWAP_B8_IN_B64(dest, src) ( \ + SWAP_B8_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ + SWAP_B8_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ +) + +#endif /* HAVE_B64 */ + +#if LONG_BITS == 64 + +#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B64(dest, src) + +#else /* LONG_BITS == 64 */ + +#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B32(dest, src) +#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B32(dest, src) + +#endif /* LONG_BITS == 64 */ + + +#endif /* !__BYTESWAP_H__ */ diff --git a/calc/calc/calc.h b/calc/calc/calc.h new file mode 100644 index 0000000..eda1532 --- /dev/null +++ b/calc/calc/calc.h @@ -0,0 +1,270 @@ +/* + * calc - definitions for calculator program + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:31 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__CALC_H__) +#define __CALC_H__ + +#include +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +# include "calc/value.h" +# include "calc/have_const.h" +#else +# include +# include +# include +#endif + + +/* + * Configuration definitions + */ +#define CALCPATH "CALCPATH" /* environment variable for files */ +#define CALCRC "CALCRC" /* environment variable for startup */ +#define CALCBINDINGS "CALCBINDINGS" /* env variable for hist bindings */ +#define HOME "HOME" /* environment variable for home dir */ +#define PAGER "PAGER" /* environment variable for help */ +#define SHELL "SHELL" /* environment variable for shell */ +#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */ +#define DEFAULTCALCHELP "help" /* help file that -h prints */ +#define DEFAULTSHELL "sh" /* default shell to use */ +#define CALCEXT ".cal" /* extension for files read in */ +#define MAX_CALCRC 1024 /* maximum length of $CALCRC */ +#define HOMECHAR '~' /* char which indicates home directory */ +#define DOTCHAR '.' /* char which indicates current directory */ +#define PATHCHAR '/' /* char which separates path components */ +#if defined(__MSDOS__) || defined(__WIN32) +#define LISTCHAR ';' /* char which separates paths in a list */ +#else +#define LISTCHAR ':' /* char which separates paths in a list */ +#endif +#define MAXCMD 16384 /* maximum length of command invocation */ +#define MAXERROR 512 /* maximum length of error message string */ + +#define SYMBOLSIZE 256 /* maximum symbol name size */ +#define MAXLABELS 100 /* maximum number of user labels in function */ +#define MAXSTRING 1024 /* maximum size of string constant */ +#define MAXSTACK 2048 /* maximum depth of evaluation stack */ +#define MAXFILES 20 /* maximum number of opened files */ +#define PROMPT1 "> " /* default normal prompt*/ +#define PROMPT2 ">> " /* default prompt inside multi-line input */ + + +#define TRACE_NORMAL 0x00 /* normal trace flags */ +#define TRACE_OPCODES 0x01 /* trace every opcode */ +#define TRACE_NODEBUG 0x02 /* suppress debugging opcodes */ +#define TRACE_LINKS 0x04 /* display links for real and complex numbers */ +#define TRACE_FNCODES 0x08 /* display code for newly defined function */ +#define TRACE_MAX 0x0f /* maximum value for trace flag */ + +#define ABORT_NONE 0 /* abort not needed yet */ +#define ABORT_STATEMENT 1 /* abort on statement boundary */ +#define ABORT_OPCODE 2 /* abort on any opcode boundary */ +#define ABORT_MATH 3 /* abort on any math operation */ +#define ABORT_NOW 4 /* abort right away */ + +#define ERRMAX 20 /* default errmax value */ + +/* + * File ids corresponding to standard in, out, error, and when not in use. + */ +#define FILEID_STDIN ((FILEID) 0) +#define FILEID_STDOUT ((FILEID) 1) +#define FILEID_STDERR ((FILEID) 2) +#define FILEID_NONE ((FILEID) -1) + +/* + * File I/O routines. + */ +extern DLL FILEID openid(char *name, char *mode); +extern DLL FILEID indexid(long index); +extern DLL BOOL validid(FILEID id); +extern DLL BOOL errorid(FILEID id); +extern DLL BOOL eofid(FILEID id); +extern DLL int closeid(FILEID id); +extern DLL int getcharid(FILEID id); +extern DLL int idprintf(FILEID id, char *fmt, int count, VALUE **vals); +extern DLL int idfputc(FILEID id, int ch); +extern DLL int idfputs(FILEID id, char *str); +extern DLL int printid(FILEID id, int flags); +extern DLL int flushid(FILEID id); +extern DLL int readid(FILEID id, int flags, char **retptr); +extern DLL int getloc(FILEID id, ZVALUE *loc); +extern DLL int setloc(FILEID id, ZVALUE zpos); +extern DLL int getsize(FILEID id, ZVALUE *size); +extern DLL int get_device(FILEID id, ZVALUE *dev); +extern DLL int get_inode(FILEID id, ZVALUE *ino); +extern DLL FILEID reopenid(FILEID id, char *mode, char *name); +extern DLL int closeall(void); + +#if !defined(_WIN32) +extern DLL int flushall(void); +#endif + +extern DLL int idfputstr(FILEID id, char *str); +extern DLL int rewindid(FILEID id); +extern DLL void rewindall(void); +extern DLL ZVALUE zfilesize(FILEID id); +extern DLL void showfiles(void); +extern DLL int fscanfid(FILEID id, char *fmt, int count, VALUE **vals); +extern DLL int scanfstr(char *str, char *fmt, int count, VALUE **vals); +extern DLL int ftellid(FILEID id, ZVALUE *res); +extern DLL int fseekid(FILEID id, ZVALUE offset, int whence); +extern DLL int isattyid(FILEID id); +extern DLL int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res); +extern DLL int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res); +extern DLL void showconstants(void); +extern DLL void freeconstant(unsigned long); +extern DLL void freestringconstant(long); +extern DLL void trimconstants(void); + +/* + * Input routines. + */ +extern DLL int openstring(char *str, long num); +extern DLL int openterminal(void); +extern DLL int opensearchfile(char *name, char *pathlist, char *exten, int reopen_ok); +extern DLL char *nextline(void); +extern DLL int nextchar(void); +extern DLL void reread(void); +extern DLL void resetinput(void); +extern DLL void setprompt(char *); +extern DLL BOOL inputisterminal(void); +extern DLL int inputlevel(void); +extern DLL long calclevel(void); +extern DLL char *inputname(void); +extern DLL long linenumber(void); +extern DLL void runrcfiles(void); +extern DLL void closeinput(void); + +/* + * Other routines. + */ +extern DLL NUMBER *constvalue(unsigned long index); +extern DLL long addnumber(char *str); +extern DLL long addqconstant(NUMBER *q); +extern DLL void initstack(void); +extern DLL void getcommands(BOOL toplevel); +extern DLL void givehelp(char *type); +extern DLL void libcalc_call_me_first(void); +extern DLL void libcalc_call_me_last(void); +extern DLL BOOL calc_tty(int fd); +extern DLL BOOL orig_tty(int fd); +extern DLL void showerrors(void); +extern DLL char *calc_strdup(CONST char *); + +/* + * Initialization + */ +extern DLL void initialize(void); +extern DLL void reinitialize(void); +#if !defined (_WIN32) +extern DLL int isatty(int tty); /* TRUE if fd is a tty */ +#endif +extern DLL char *version(void); /* return version string */ +extern DLL int post_init; /* TRUE => math_error setjmp is ready */ + +/* + * global flags and definitions + */ +extern DLL int abortlevel; /* current level of aborts */ +extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */ +extern DLL jmp_buf jmpbuf; /* for errors */ + +extern DLL int p_flag; /* TRUE => pipe mode */ +extern DLL int q_flag; /* TRUE => don't execute rc files */ +extern DLL int u_flag; /* TRUE => unbuffer stdin and stdout */ +extern DLL int d_flag; /* TRUE => disable heading, resource_debug */ +extern DLL int c_flag; /* TRUE => continue after error if permitted */ +extern DLL int i_flag; /* TRUE => try to go interactive after error */ +extern DLL int s_flag; /* TRUE => keep args as strings for argv() */ +extern DLL int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ +extern DLL BOOL abort_now; /* TRUE => try to go interactive */ + +extern DLL int argc_value; /* count of argv[] strings for argv() builtin */ +extern DLL char **argv_value; /* argv[] strings for argv() builtin */ + +extern DLL char *pager; /* $PAGER or default */ +extern DLL int stdin_tty; /* TRUE if stdin is a tty */ +extern DLL int havecommands; /* TRUE if have cmd args) */ +extern DLL char *program; /* our name */ +extern DLL char *base_name; /* basename of our name */ +extern DLL char cmdbuf[]; /* command line expression */ + +extern DLL int abortlevel; /* current level of aborts */ +extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */ +extern DLL VALUE *stack; /* execution stack */ +extern DLL int dumpnames; /* TRUE => dump names rather than indices */ + +extern DLL char *calcpath; /* $CALCPATH or default */ +extern DLL char *calcrc; /* $CALCRC or default */ +extern DLL char *calcbindings; /* $CALCBINDINGS or default */ +extern DLL char *home; /* $HOME or default */ +extern DLL char *shell; /* $SHELL or default */ +extern DLL char *program; /* our name (argv[0]) */ + +extern DLL int no_env; /* TRUE (-e) => ignore env vars on startup */ +extern DLL int errmax; /* if >= 0, error when errcount exceeds errmax */ +extern DLL int use_old_std; /* TRUE (-O) => use classic configuration */ + +extern DLL int allow_read; /* FALSE => dont open any files for reading */ +extern DLL int allow_write; /* FALSE => dont open any files for writing */ +extern DLL int allow_exec; /* FALSE => may not execute any commands */ + +/* + * calc startup and run state + */ +typedef enum { + RUN_ZERO, /* unknown or unset start state */ + RUN_BEGIN, /* calc execution starts */ + RUN_RCFILES, /* rc files being evaluated */ + RUN_PRE_CMD_ARGS, /* prepare to evaluate cmd args */ + RUN_CMD_ARGS, /* cmd args being evaluated */ + RUN_PRE_TOP_LEVEL, /* prepare to start top level activity */ + RUN_TOP_LEVEL, /* running at top level */ + RUN_EXIT, /* normal exit from calc */ + RUN_EXIT_WITH_ERROR /* exit with error */ +} run; +extern DLL run run_state; +extern DLL char *run_state_name(run state); + +/* + * calc version information + */ +#define CALC_TITLE "C-style arbitrary precision calculator" +extern int calc_major_ver; +extern int calc_minor_ver; +extern int calc_major_patch; +extern int calc_minor_patch; +extern char *Copyright; +extern DLL char *version(void); + + +#endif /* !__CALC_H__ */ diff --git a/calc/calc/calcerr.h b/calc/calc/calcerr.h new file mode 100644 index 0000000..e764cbf --- /dev/null +++ b/calc/calc/calcerr.h @@ -0,0 +1,383 @@ +/* + * DO NOT EDIT + * + * generated by calcerr.tbl via Makefile + */ + + +#if !defined(__CALCERR_H__) +#define __CALCERR_H__ + + +#define E__BASE 10000 /* calc errors start above here */ + +#define E_1OVER0 10001 /* Division by zero */ +#define E_0OVER0 10002 /* Indeterminate (0/0) */ +#define E_ADD 10003 /* Bad arguments for + */ +#define E_SUB 10004 /* Bad arguments for binary - */ +#define E_MUL 10005 /* Bad arguments for * */ +#define E_DIV 10006 /* Bad arguments for / */ +#define E_NEG 10007 /* Bad argument for unary - */ +#define E_SQUARE 10008 /* Bad argument for squaring */ +#define E_INV 10009 /* Bad argument for inverse */ +#define E_INCV 10010 /* Bad argument for ++ */ +#define E_DECV 10011 /* Bad argument for -- */ +#define E_INT 10012 /* Bad argument for int */ +#define E_FRAC 10013 /* Bad argument for frac */ +#define E_CONJ 10014 /* Bad argument for conj */ +#define E_APPR 10015 /* Bad first argument for appr */ +#define E_APPR2 10016 /* Bad second argument for appr */ +#define E_APPR3 10017 /* Bad third argument for appr */ +#define E_ROUND 10018 /* Bad first argument for round */ +#define E_ROUND2 10019 /* Bad second argument for round */ +#define E_ROUND3 10020 /* Bad third argument for round */ +#define E_BROUND 10021 /* Bad first argument for bround */ +#define E_BROUND2 10022 /* Bad second argument for bround */ +#define E_BROUND3 10023 /* Bad third argument for bround */ +#define E_SQRT 10024 /* Bad first argument for sqrt */ +#define E_SQRT2 10025 /* Bad second argument for sqrt */ +#define E_SQRT3 10026 /* Bad third argument for sqrt */ +#define E_ROOT 10027 /* Bad first argument for root */ +#define E_ROOT2 10028 /* Bad second argument for root */ +#define E_ROOT3 10029 /* Bad third argument for root */ +#define E_NORM 10030 /* Bad argument for norm */ +#define E_SHIFT 10031 /* Bad first argument for << or >> */ +#define E_SHIFT2 10032 /* Bad second argument for << or >> */ +#define E_SCALE 10033 /* Bad first argument for scale */ +#define E_SCALE2 10034 /* Bad second argument for scale */ +#define E_POWI 10035 /* Bad first argument for ^ */ +#define E_POWI2 10036 /* Bad second argument for ^ */ +#define E_POWER 10037 /* Bad first argument for power */ +#define E_POWER2 10038 /* Bad second argument for power */ +#define E_POWER3 10039 /* Bad third argument for power */ +#define E_QUO 10040 /* Bad first argument for quo or // */ +#define E_QUO2 10041 /* Bad second argument for quo or // */ +#define E_QUO3 10042 /* Bad third argument for quo */ +#define E_MOD 10043 /* Bad first argument for mod or % */ +#define E_MOD2 10044 /* Bad second argument for mod or % */ +#define E_MOD3 10045 /* Bad third argument for mod */ +#define E_SGN 10046 /* Bad argument for sgn */ +#define E_ABS 10047 /* Bad first argument for abs */ +#define E_ABS2 10048 /* Bad second argument for abs */ +#define E_EVAL 10049 /* Scan error in argument for eval */ +#define E_STR 10050 /* Non-simple type for str */ +#define E_EXP1 10051 /* Non-real epsilon for exp */ +#define E_EXP2 10052 /* Bad first argument for exp */ +#define E_FPUTC1 10053 /* Non-file first argument for fputc */ +#define E_FPUTC2 10054 /* Bad second argument for fputc */ +#define E_FPUTC3 10055 /* File not open for writing for fputc */ +#define E_FGETC1 10056 /* Non-file first argument for fgetc */ +#define E_FGETC2 10057 /* File not open for reading for fgetc */ +#define E_FOPEN1 10058 /* Non-string arguments for fopen */ +#define E_FOPEN2 10059 /* Unrecognized mode for fopen */ +#define E_FREOPEN1 10060 /* Non-file first argument for freopen */ +#define E_FREOPEN2 10061 /* Non-string or unrecognized mode for freopen */ +#define E_FREOPEN3 10062 /* Non-string third argument for freopen */ +#define E_FCLOSE1 10063 /* Non-file argument for fclose */ +#define E_FFLUSH 10064 /* Non-file argument for fflush */ +#define E_FPUTS1 10065 /* Non-file first argument for fputs */ +#define E_FPUTS2 10066 /* Non-string argument after first for fputs */ +#define E_FPUTS3 10067 /* File not open for writing for fputs */ +#define E_FGETS1 10068 /* Non-file argument for fgets */ +#define E_FGETS2 10069 /* File not open for reading for fgets */ +#define E_FPUTSTR1 10070 /* Non-file first argument for fputstr */ +#define E_FPUTSTR2 10071 /* Non-string argument after first for fputstr */ +#define E_FPUTSTR3 10072 /* File not open for writing for fputstr */ +#define E_FGETSTR1 10073 /* Non-file first argument for fgetstr */ +#define E_FGETSTR2 10074 /* File not open for reading for fgetstr */ +#define E_FGETLINE1 10075 /* Non-file argument for fgetline */ +#define E_FGETLINE2 10076 /* File not open for reading for fgetline */ +#define E_FGETFIELD1 10077 /* Non-file argument for fgetfield */ +#define E_FGETFIELD2 10078 /* File not open for reading for fgetfield */ +#define E_REWIND1 10079 /* Non-file argument for rewind */ +#define E_FILES 10080 /* Non-integer argument for files */ +#define E_PRINTF1 10081 /* Non-string fmt argument for fprint */ +#define E_PRINTF2 10082 /* Stdout not open for writing to ??? */ +#define E_FPRINTF1 10083 /* Non-file first argument for fprintf */ +#define E_FPRINTF2 10084 /* Non-string second (fmt) argument for fprintf */ +#define E_FPRINTF3 10085 /* File not open for writing for fprintf */ +#define E_STRPRINTF1 10086 /* Non-string first (fmt) argument for strprintf */ +#define E_STRPRINTF2 10087 /* Error in attempting strprintf ??? */ +#define E_FSCAN1 10088 /* Non-file first argument for fscan */ +#define E_FSCAN2 10089 /* File not open for reading for fscan */ +#define E_STRSCAN 10090 /* Non-string first argument for strscan */ +#define E_FSCANF1 10091 /* Non-file first argument for fscanf */ +#define E_FSCANF2 10092 /* Non-string second (fmt) argument for fscanf */ +#define E_FSCANF3 10093 /* Non-lvalue argument after second for fscanf */ +#define E_FSCANF4 10094 /* File not open for reading or other error for fscanf */ +#define E_STRSCANF1 10095 /* Non-string first argument for strscanf */ +#define E_STRSCANF2 10096 /* Non-string second (fmt) argument for strscanf */ +#define E_STRSCANF3 10097 /* Non-lvalue argument after second for strscanf */ +#define E_STRSCANF4 10098 /* Some error in attempting strscanf ??? */ +#define E_SCANF1 10099 /* Non-string first (fmt) argument for scanf */ +#define E_SCANF2 10100 /* Non-lvalue argument after first for scanf */ +#define E_SCANF3 10101 /* Some error in attempting scanf ??? */ +#define E_FTELL1 10102 /* Non-file argument for ftell */ +#define E_FTELL2 10103 /* File not open or other error for ftell */ +#define E_FSEEK1 10104 /* Non-file first argument for fseek */ +#define E_FSEEK2 10105 /* Non-integer or negative second argument for fseek */ +#define E_FSEEK3 10106 /* File not open or other error for fseek */ +#define E_FSIZE1 10107 /* Non-file argument for fsize */ +#define E_FSIZE2 10108 /* File not open or other error for fsize */ +#define E_FEOF1 10109 /* Non-file argument for feof */ +#define E_FEOF2 10110 /* File not open or other error for feof */ +#define E_FERROR1 10111 /* Non-file argument for ferror */ +#define E_FERROR2 10112 /* File not open or other error for ferror */ +#define E_UNGETC1 10113 /* Non-file argument for ungetc */ +#define E_UNGETC2 10114 /* File not open for reading for ungetc */ +#define E_UNGETC3 10115 /* Bad second argument or other error for ungetc */ +#define E_BIGEXP 10116 /* Exponent too big in scanning */ +#define E_ISATTY1 10117 /* E_ISATTY1 is no longer used */ +#define E_ISATTY2 10118 /* E_ISATTY2 is no longer used */ +#define E_ACCESS1 10119 /* Non-string first argument for access */ +#define E_ACCESS2 10120 /* Bad second argument for access */ +#define E_SEARCH1 10121 /* Bad first argument for search */ +#define E_SEARCH2 10122 /* Bad second argument for search */ +#define E_SEARCH3 10123 /* Bad third argument for search */ +#define E_SEARCH4 10124 /* Bad fourth argument for search */ +#define E_SEARCH5 10125 /* Cannot find fsize or fpos for search */ +#define E_SEARCH6 10126 /* File not readable for search */ +#define E_RSEARCH1 10127 /* Bad first argument for rsearch */ +#define E_RSEARCH2 10128 /* Bad second argument for rsearch */ +#define E_RSEARCH3 10129 /* Bad third argument for rsearch */ +#define E_RSEARCH4 10130 /* Bad fourth argument for rsearch */ +#define E_RSEARCH5 10131 /* Cannot find fsize or fpos for rsearch */ +#define E_RSEARCH6 10132 /* File not readable for rsearch */ +#define E_FOPEN3 10133 /* Too many open files */ +#define E_REWIND2 10134 /* Attempt to rewind a file that is not open */ +#define E_STRERROR1 10135 /* Bad argument type for strerror */ +#define E_STRERROR2 10136 /* Index out of range for strerror */ +#define E_COS1 10137 /* Bad epsilon for cos */ +#define E_COS2 10138 /* Bad first argument for cos */ +#define E_SIN1 10139 /* Bad epsilon for sin */ +#define E_SIN2 10140 /* Bad first argument for sin */ +#define E_EVAL2 10141 /* Non-string argument for eval */ +#define E_ARG1 10142 /* Bad epsilon for arg */ +#define E_ARG2 10143 /* Bad first argument for arg */ +#define E_POLAR1 10144 /* Non-real argument for polar */ +#define E_POLAR2 10145 /* Bad epsilon for polar */ +#define E_FCNT 10146 /* Non-integral argument for fcnt */ +#define E_MATFILL1 10147 /* Non-variable first argument for matfill */ +#define E_MATFILL2 10148 /* Non-matrix first argument-value for matfill */ +#define E_MATDIM 10149 /* Non-matrix argument for matdim */ +#define E_MATSUM 10150 /* Non-matrix argument for matsum */ +#define E_ISIDENT 10151 /* E_ISIDENT is no longer used */ +#define E_MATTRANS1 10152 /* Non-matrix argument for mattrans */ +#define E_MATTRANS2 10153 /* Non-two-dimensional matrix for mattrans */ +#define E_DET1 10154 /* Non-matrix argument for det */ +#define E_DET2 10155 /* Matrix for det not of dimension 2 */ +#define E_DET3 10156 /* Non-square matrix for det */ +#define E_MATMIN1 10157 /* Non-matrix first argument for matmin */ +#define E_MATMIN2 10158 /* Non-positive-integer second argument for matmin */ +#define E_MATMIN3 10159 /* Second argument for matmin exceeds dimension */ +#define E_MATMAX1 10160 /* Non-matrix first argument for matmin */ +#define E_MATMAX2 10161 /* Second argument for matmax not positive integer */ +#define E_MATMAX3 10162 /* Second argument for matmax exceeds dimension */ +#define E_CP1 10163 /* Non-matrix argument for cp */ +#define E_CP2 10164 /* Non-one-dimensional matrix for cp */ +#define E_CP3 10165 /* Matrix size not 3 for cp */ +#define E_DP1 10166 /* Non-matrix argument for dp */ +#define E_DP2 10167 /* Non-one-dimensional matrix for dp */ +#define E_DP3 10168 /* Different-size matrices for dp */ +#define E_STRLEN 10169 /* Non-string argument for strlen */ +#define E_STRCAT 10170 /* Non-string argument for strcat */ +#define E_SUBSTR1 10171 /* Non-string first argument for strcat */ +#define E_SUBSTR2 10172 /* Non-non-negative integer second argument for strcat */ +#define E_CHAR 10173 /* Bad argument for char */ +#define E_ORD 10174 /* Non-string argument for ord */ +#define E_INSERT1 10175 /* Non-list-variable first argument for insert */ +#define E_INSERT2 10176 /* Non-integral second argument for insert */ +#define E_PUSH 10177 /* Non-list-variable first argument for push */ +#define E_APPEND 10178 /* Non-list-variable first argument for append */ +#define E_DELETE1 10179 /* Non-list-variable first argument for delete */ +#define E_DELETE2 10180 /* Non-integral second argument for delete */ +#define E_POP 10181 /* Non-list-variable argument for pop */ +#define E_REMOVE 10182 /* Non-list-variable argument for remove */ +#define E_LN1 10183 /* Bad epsilon argument for ln */ +#define E_LN2 10184 /* Non-numeric first argument for ln */ +#define E_ERROR1 10185 /* Non-integer argument for error */ +#define E_ERROR2 10186 /* Argument outside range for error */ +#define E_EVAL3 10187 /* Attempt to eval at maximum input depth */ +#define E_EVAL4 10188 /* Unable to open string for reading */ +#define E_RM1 10189 /* First argument for rm is not a non-empty string */ +#define E_RM2 10190 /* Unable to remove a file */ +#define E_RDPERM 10191 /* Operation allowed because calc mode disallows read operations */ +#define E_WRPERM 10192 /* Operation allowed because calc mode disallows write operations */ +#define E_EXPERM 10193 /* Operation allowed because calc mode disallows exec operations */ +#define E_MIN 10194 /* Unordered arguments for min */ +#define E_MAX 10195 /* Unordered arguments for max */ +#define E_LISTMIN 10196 /* Unordered items for minimum of list */ +#define E_LISTMAX 10197 /* Unordered items for maximum of list */ +#define E_SIZE 10198 /* Size undefined for argument type */ +#define E_NO_C_ARG 10199 /* Calc must be run with a -C argument to use custom function */ +#define E_NO_CUSTOM 10200 /* Calc was built with custom functions disabled */ +#define E_UNK_CUSTOM 10201 /* Custom function unknown, try: show custom */ +#define E_BLK1 10202 /* Non-integral length for block */ +#define E_BLK2 10203 /* Negative or too-large length for block */ +#define E_BLK3 10204 /* Non-integral chunksize for block */ +#define E_BLK4 10205 /* Negative or too-large chunksize for block */ +#define E_BLKFREE1 10206 /* Named block does not exist for blkfree */ +#define E_BLKFREE2 10207 /* Non-integral id specification for blkfree */ +#define E_BLKFREE3 10208 /* Block with specified id does not exist */ +#define E_BLKFREE4 10209 /* Block already freed */ +#define E_BLKFREE5 10210 /* No-realloc protection prevents blkfree */ +#define E_BLOCKS1 10211 /* Non-integer argument for blocks */ +#define E_BLOCKS2 10212 /* Non-allocated index number for blocks */ +#define E_COPY1 10213 /* Non-integer or negative source index for copy */ +#define E_COPY2 10214 /* Source index too large for copy */ +#define E_COPY3 10215 /* E_COPY3 is no longer used */ +#define E_COPY4 10216 /* Non-integer or negative number for copy */ +#define E_COPY5 10217 /* Number too large for copy */ +#define E_COPY6 10218 /* Non-integer or negative destination index for copy */ +#define E_COPY7 10219 /* Destination index too large for copy */ +#define E_COPY8 10220 /* Freed block source for copy */ +#define E_COPY9 10221 /* Unsuitable source type for copy */ +#define E_COPY10 10222 /* Freed block destinction for copy */ +#define E_COPY11 10223 /* Unsuitable destination type for copy */ +#define E_COPY12 10224 /* Incompatible source and destination for copy */ +#define E_COPY13 10225 /* No-copy-from source variable */ +#define E_COPY14 10226 /* No-copy-to destination variable */ +#define E_COPY15 10227 /* No-copy-from source named block */ +#define E_COPY16 10228 /* No-copy-to destination named block */ +#define E_COPY17 10229 /* No-relocation destination for copy */ +#define E_COPYF1 10230 /* File not open for copy */ +#define E_COPYF2 10231 /* fseek or fsize failure for copy */ +#define E_COPYF3 10232 /* fwrite error for copy */ +#define E_COPYF4 10233 /* fread error for copy */ +#define E_PROTECT1 10234 /* Non-variable first argument for protect */ +#define E_PROTECT2 10235 /* Non-integer second argument for protect */ +#define E_PROTECT3 10236 /* Out-of-range second argument for protect */ +#define E_MATFILL3 10237 /* No-copy-to destination for matfill */ +#define E_MATFILL4 10238 /* No-assign-from source for matfill */ +#define E_MATTRACE1 10239 /* Non-matrix argument for mattrace */ +#define E_MATTRACE2 10240 /* Non-two-dimensional argument for mattrace */ +#define E_MATTRACE3 10241 /* Non-square argument for mattrace */ +#define E_TAN1 10242 /* Bad epsilon for tan */ +#define E_TAN2 10243 /* Bad argument for tan */ +#define E_COT1 10244 /* Bad epsilon for cot */ +#define E_COT2 10245 /* Bad argument for cot */ +#define E_SEC1 10246 /* Bad epsilon for sec */ +#define E_SEC2 10247 /* Bad argument for sec */ +#define E_CSC1 10248 /* Bad epsilon for csc */ +#define E_CSC2 10249 /* Bad argument for csc */ +#define E_SINH1 10250 /* Bad epsilon for sinh */ +#define E_SINH2 10251 /* Bad argument for sinh */ +#define E_COSH1 10252 /* Bad epsilon for cosh */ +#define E_COSH2 10253 /* Bad argument for cosh */ +#define E_TANH1 10254 /* Bad epsilon for tanh */ +#define E_TANH2 10255 /* Bad argument for tanh */ +#define E_COTH1 10256 /* Bad epsilon for coth */ +#define E_COTH2 10257 /* Bad argument for coth */ +#define E_SECH1 10258 /* Bad epsilon for sech */ +#define E_SECH2 10259 /* Bad argument for sech */ +#define E_CSCH1 10260 /* Bad epsilon for csch */ +#define E_CSCH2 10261 /* Bad argument for csch */ +#define E_ASIN1 10262 /* Bad epsilon for asin */ +#define E_ASIN2 10263 /* Bad argument for asin */ +#define E_ACOS1 10264 /* Bad epsilon for acos */ +#define E_ACOS2 10265 /* Bad argument for acos */ +#define E_ATAN1 10266 /* Bad epsilon for atan */ +#define E_ATAN2 10267 /* Bad argument for atan */ +#define E_ACOT1 10268 /* Bad epsilon for acot */ +#define E_ACOT2 10269 /* Bad argument for acot */ +#define E_ASEC1 10270 /* Bad epsilon for asec */ +#define E_ASEC2 10271 /* Bad argument for asec */ +#define E_ACSC1 10272 /* Bad epsilon for acsc */ +#define E_ACSC2 10273 /* Bad argument for acsc */ +#define E_ASINH1 10274 /* Bad epsilon for asin */ +#define E_ASINH2 10275 /* Bad argument for asinh */ +#define E_ACOSH1 10276 /* Bad epsilon for acosh */ +#define E_ACOSH2 10277 /* Bad argument for acosh */ +#define E_ATANH1 10278 /* Bad epsilon for atanh */ +#define E_ATANH2 10279 /* Bad argument for atanh */ +#define E_ACOTH1 10280 /* Bad epsilon for acoth */ +#define E_ACOTH2 10281 /* Bad argument for acoth */ +#define E_ASECH1 10282 /* Bad epsilon for asech */ +#define E_ASECH2 10283 /* Bad argument for asech */ +#define E_ACSCH1 10284 /* Bad epsilon for acsch */ +#define E_ACSCH2 10285 /* Bad argument for acsch */ +#define E_GD1 10286 /* Bad epsilon for gd */ +#define E_GD2 10287 /* Bad argument for gd */ +#define E_AGD1 10288 /* Bad epsilon for agd */ +#define E_AGD2 10289 /* Bad argument for agd */ +#define E_LOGINF 10290 /* Log of zero or infinity */ +#define E_STRADD 10291 /* String addition failure */ +#define E_STRMUL 10292 /* String multiplication failure */ +#define E_STRNEG 10293 /* String reversal failure */ +#define E_STRSUB 10294 /* String subtraction failure */ +#define E_BIT1 10295 /* Bad argument type for bit */ +#define E_BIT2 10296 /* Index too large for bit */ +#define E_SETBIT1 10297 /* Non-integer second argument for setbit */ +#define E_SETBIT2 10298 /* Out-of-range index for setbit */ +#define E_SETBIT3 10299 /* Non-string first argument for setbit */ +#define E_OR 10300 /* Bad argument for or */ +#define E_AND 10301 /* Bad argument for and */ +#define E_STROR 10302 /* Allocation failure for string or */ +#define E_STRAND 10303 /* Allocation failure for string and */ +#define E_XOR 10304 /* Bad argument for xorvalue */ +#define E_COMP 10305 /* Bad argument for comp */ +#define E_STRDIFF 10306 /* Allocation failure for string diff */ +#define E_STRCOMP 10307 /* Allocation failure for string comp */ +#define E_SEG1 10308 /* Bad first argument for segment */ +#define E_SEG2 10309 /* Bad second argument for segment */ +#define E_SEG3 10310 /* Bad third argument for segment */ +#define E_STRSEG 10311 /* Failure for string segment */ +#define E_HIGHBIT1 10312 /* Bad argument type for highbit */ +#define E_HIGHBIT2 10313 /* Non-integer argument for highbit */ +#define E_LOWBIT1 10314 /* Bad argument type for lowbit */ +#define E_LOWBIT2 10315 /* Non-integer argument for lowbit */ +#define E_CONTENT 10316 /* Bad argument type for unary hash op */ +#define E_HASHOP 10317 /* Bad argument type for binary hash op */ +#define E_HEAD1 10318 /* Bad first argument for head */ +#define E_HEAD2 10319 /* Bad second argument for head */ +#define E_STRHEAD 10320 /* Failure for strhead */ +#define E_TAIL1 10321 /* Bad first argument for tail */ +#define E_TAIL2 10322 /* Bad second argument for tail */ +#define E_STRTAIL 10323 /* Failure for strtail */ +#define E_STRSHIFT 10324 /* Failure for strshift */ +#define E_STRCMP 10325 /* Non-string argument for strcmp */ +#define E_STRNCMP 10326 /* Bad argument type for strncmp */ +#define E_XOR1 10327 /* Varying types of argument for xor */ +#define E_XOR2 10328 /* Bad argument type for xor */ +#define E_STRCPY 10329 /* Bad argument type for strcpy */ +#define E_STRNCPY 10330 /* Bad argument type for strncpy */ +#define E_BACKSLASH 10331 /* Bad argument type for unary backslash */ +#define E_SETMINUS 10332 /* Bad argument type for setminus */ +#define E_INDICES1 10333 /* Bad first argument type for indices */ +#define E_INDICES2 10334 /* Bad second argument for indices */ +#define E_EXP3 10335 /* Too-large re(argument) for exp */ +#define E_SINH3 10336 /* Too-large re(argument) for sinh */ +#define E_COSH3 10337 /* Too-large re(argument) for cosh */ +#define E_SIN3 10338 /* Too-large im(argument) for sin */ +#define E_COS3 10339 /* Too-large im(argument) for cos */ +#define E_GD3 10340 /* Infinite or too-large result for gd */ +#define E_AGD3 10341 /* Infinite or too-large result for agd */ +#define E_POWER4 10342 /* Too-large value for power */ +#define E_ROOT4 10343 /* Too-large value for root */ +#define E_DGT1 10344 /* Non-real first arg for digit */ +#define E_DGT2 10345 /* Non-integral second arg for digit */ +#define E_DGT3 10346 /* Bad third arg for digit */ +#define E_PLCS1 10347 /* Bad first argument for places */ +#define E_PLCS2 10348 /* Bad second argument for places */ +#define E_DGTS1 10349 /* Bad first argument for digits */ +#define E_DGTS2 10350 /* Bad second argument for digits */ +#define E_ILOG 10351 /* Bad first argument for ilog */ +#define E_ILOGB 10352 /* Bad second argument for ilog */ +#define E_ILOG10 10353 /* Bad argument for ilog10 */ +#define E_ILOG2 10354 /* Bad argument for ilog2 */ +#define E_COMB1 10355 /* Non-integer second arg for comb */ +#define E_COMB2 10356 /* Too-large second arg for comb */ +#define E_CTLN 10357 /* Bad argument for catalan */ +#define E_BERN 10358 /* Bad argument for bern */ +#define E_EULER 10359 /* Bad argument for euler */ +#define E_SLEEP 10360 /* Bad argument for sleep */ +#define E_TTY 10361 /* calc_tty failure */ + +#define E__HIGHEST 10361 /* highest calc error */ +#define E__COUNT 361 /* number of calc errors */ +#define E_USERDEF 20000 /* base of user defined errors */ + +/* names of calc error values */ + + +#endif /* !__CALCERR_H__ */ diff --git a/calc/calc/cmath.h b/calc/calc/cmath.h new file mode 100644 index 0000000..f13cf95 --- /dev/null +++ b/calc/calc/cmath.h @@ -0,0 +1,158 @@ +/* + * cmath - data structures for extended precision complex arithmetic + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1993/07/30 19:42:45 + * File existed as early as: 1993 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__CMATH_H__) +#define __CMATH_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/qmath.h" +#else +# include +#endif + + +/* + * Complex arithmetic definitions. + */ +typedef struct { + NUMBER *real; /* real part of number */ + NUMBER *imag; /* imaginary part of number */ + long links; /* link count */ +} COMPLEX; + + +/* + * Input, output, and conversion routines. + */ +extern COMPLEX *comalloc(void); +extern COMPLEX *qqtoc(NUMBER *q1, NUMBER *q2); +extern void comfree(COMPLEX *c); +extern void comprint(COMPLEX *c); +extern void cprintfr(COMPLEX *c); + + +/* + * Basic numeric routines. + */ + +extern COMPLEX *cadd(COMPLEX *c1, COMPLEX *c2); +extern COMPLEX *csub(COMPLEX *c1, COMPLEX *c2); +extern COMPLEX *cmul(COMPLEX *c1, COMPLEX *c2); +extern COMPLEX *cdiv(COMPLEX *c1, COMPLEX *c2); +extern COMPLEX *caddq(COMPLEX *c, NUMBER *q); +extern COMPLEX *csubq(COMPLEX *c, NUMBER *q); +extern COMPLEX *cmulq(COMPLEX *c, NUMBER *q); +extern COMPLEX *cdivq(COMPLEX *c, NUMBER *q); +extern COMPLEX *cscale(COMPLEX *c, long i); +extern COMPLEX *cshift(COMPLEX *c, long i); +extern COMPLEX *csquare(COMPLEX *c); +extern COMPLEX *cconj(COMPLEX *c); +extern COMPLEX *c_real(COMPLEX *c); +extern COMPLEX *c_imag(COMPLEX *c); +extern COMPLEX *cneg(COMPLEX *c); +extern COMPLEX *cinv(COMPLEX *c); +extern COMPLEX *cint(COMPLEX *c); +extern COMPLEX *cfrac(COMPLEX *c); +extern BOOL ccmp(COMPLEX *c1, COMPLEX *c2); + + +/* + * More complicated functions. + */ +extern COMPLEX *cpowi(COMPLEX *c, NUMBER *q); +extern NUMBER *cilog(COMPLEX *c, ZVALUE base); + + +/* + * Transcendental routines. These all take an epsilon argument to + * specify how accurately these are to be calculated. + */ +extern COMPLEX *cpower(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon); +extern COMPLEX *csqrt(COMPLEX *c, NUMBER *epsilon, long R); +extern COMPLEX *croot(COMPLEX *c, NUMBER *q, NUMBER *epsilon); +extern COMPLEX *cexp(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cln(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *ccos(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *csin(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *ccosh(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *csinh(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cpolar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern COMPLEX *crel(COMPLEX *c1, COMPLEX *c2); +extern COMPLEX *casin(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacos(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *catan(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacot(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *casec(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacsc(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *casinh(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacosh(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *catanh(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacoth(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *casech(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cacsch(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cgd(COMPLEX *c, NUMBER *epsilon); +extern COMPLEX *cagd(COMPLEX *c, NUMBER *epsilon); + + + +/* + * external functions + */ +extern COMPLEX *swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); +extern COMPLEX *swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); +extern COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all); + + +/* + * macro expansions to speed this thing up + */ +#define cisreal(c) (qiszero((c)->imag)) +#define cisimag(c) (qiszero((c)->real) && !cisreal(c)) +#define ciszero(c) (cisreal(c) && qiszero((c)->real)) +#define cisone(c) (cisreal(c) && qisone((c)->real)) +#define cisnegone(c) (cisreal(c) && qisnegone((c)->real)) +#define cisrunit(c) (cisreal(c) && qisunit((c)->real)) +#define cisiunit(c) (qiszero((c)->real) && qisunit((c)->imag)) +#define cisunit(c) (cisrunit(c) || cisiunit(c)) +#define cistwo(c) (cisreal(c) && qistwo((c)->real)) +#define cisint(c) (qisint((c)->real) && qisint((c)->imag)) +#define ciseven(c) (qiseven((c)->real) && qiseven((c)->imag)) +#define cisodd(c) (qisodd((c)->real) || qisodd((c)->imag)) +#define clink(c) ((c)->links++, (c)) + + +/* + * Pre-defined values. + */ +extern COMPLEX _czero_, _cone_, _conei_; + + +#endif /* !__CMATH_H__ */ diff --git a/calc/calc/conf.h b/calc/calc/conf.h new file mode 100644 index 0000000..4b8cf46 --- /dev/null +++ b/calc/calc/conf.h @@ -0,0 +1,41 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__CONF_H__) +#define __CONF_H__ + + +/* the default :-separated search path */ +#if !defined(DEFAULTCALCPATH) +#define DEFAULTCALCPATH ".:./cal:~/.cal:/usr/share/calc:/usr/share/calc/custom" +#endif /* DEFAULTCALCPATH */ + +/* the default :-separated startup file list */ +#if !defined(DEFAULTCALCRC) +#define DEFAULTCALCRC "/usr/share/calc/startup:~/.calcrc:./.calcinit" +#endif /* DEFAULTCALCRC */ + +/* the location of the help directory */ +#if !defined(HELPDIR) +#define HELPDIR "/usr/share/calc/help" +#endif /* HELPDIR */ + +/* the location of the custom help directory */ +#if !defined(CUSTOMHELPDIR) +#define CUSTOMHELPDIR "/usr/share/calc/custhelp" +#endif /* CUSTOMHELPDIR */ + +/* the default pager to use */ +#if !defined(DEFAULTCALCPAGER) +#define DEFAULTCALCPAGER "more" +#endif /* DEFAULTCALCPAGER */ + +/* where the echo command is located */ +#if !defined(ECHO_PROG) +#define ECHO_PROG "/bin/echo" +#endif /* ECHO_PROG */ + + +#endif /* !__CONF_H__ */ diff --git a/calc/calc/config.h b/calc/calc/config.h new file mode 100644 index 0000000..07a0bde --- /dev/null +++ b/calc/calc/config.h @@ -0,0 +1,221 @@ +/* + * config - configuration routines + * + * Copyright (C) 1999-2004 Landon Curt Noll and David I. Bell + * + * Primary author: Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1995/11/01 22:20:17 + * File existed as early as: 1995 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__CONFIG_H__) +#define __CONFIG_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +# include "calc/nametype.h" +# include "calc/qmath.h" +#else +# include +# include +# include +#endif + + +/* + * configuration element types + */ +#define CONFIG_ALL 0 /* not a real configuration parameter */ +#define CONFIG_MODE 1 /* types of configuration parameters */ +#define CONFIG_DISPLAY 2 +#define CONFIG_EPSILON 3 +#define CONFIG_EPSILONPREC 3 /* not a real type -- tied to CONFIG_EPSILON */ +#define CONFIG_TRACE 4 +#define CONFIG_MAXPRINT 5 +#define CONFIG_MUL2 6 +#define CONFIG_SQ2 7 +#define CONFIG_POW2 8 +#define CONFIG_REDC2 9 +#define CONFIG_TILDE 10 +#define CONFIG_TAB 11 +#define CONFIG_QUOMOD 12 +#define CONFIG_QUO 13 +#define CONFIG_MOD 14 +#define CONFIG_SQRT 15 +#define CONFIG_APPR 16 +#define CONFIG_CFAPPR 17 +#define CONFIG_CFSIM 18 +#define CONFIG_OUTROUND 19 +#define CONFIG_ROUND 20 +#define CONFIG_LEADZERO 21 +#define CONFIG_FULLZERO 22 +#define CONFIG_MAXSCAN 23 +#define CONFIG_PROMPT 24 +#define CONFIG_MORE 25 +#define CONFIG_BLKMAXPRINT 26 +#define CONFIG_BLKVERBOSE 27 +#define CONFIG_BLKBASE 28 +#define CONFIG_BLKFMT 29 +#define CONFIG_RESOURCE_DEBUG 30 +#define CONFIG_LIB_DEBUG CONFIG_RESOURCE_DEBUG +#define CONFIG_CALC_DEBUG 31 +#define CONFIG_USER_DEBUG 32 +#define CONFIG_VERBOSE_QUIT 33 +#define CONFIG_CTRL_D 34 +#define CONFIG_PROGRAM 35 +#define CONFIG_BASENAME 36 +#define CONFIG_VERSION 37 +#define CONFIG_WINDOWS 38 +#define CONFIG_MODE2 39 +#define CONFIG_CYGWIN 40 +#define CONFIG_COMPILE_CUSTOM 41 +#define CONFIG_ALLOW_CUSTOM 42 + + +/* + * config default symbols + */ +#define DISPLAY_DEFAULT 20 /* default digits for float display */ +#define EPSILON_DEFAULT "1e-20" /* allowed error for float calculations */ +#define EPSILONPREC_DEFAULT 67 /* 67 ==> 2^-67 <= EPSILON_DEFAULT < 2^-66 */ +#define MAXPRINT_DEFAULT 16 /* default number of elements printed */ +#define MAXSCANCOUNT 20 /* default max scan errors before an abort */ + + +/* + * configuration object + * + * If you add elements to this structure, you need to also update: + * + * quickhash.c - config_hash() + * hash.c - hash_value() + * config.c - configs[], oldstd, newstd, setconfig(), + * config_value(), config_cmp(), + * and perhaps config_copy(), config_free() + * config.h - CONFIG_XYZ_SYMBOL (see above) + */ +struct config { + int outmode; /* current output mode */ + int outmode2; /* current secondary output mode */ + LEN outdigits; /* current output digits for float or exp */ + NUMBER *epsilon; /* default error for real functions */ + long epsilonprec; /* epsilon binary precision (tied to epsilon) */ + FLAG traceflags; /* tracing flags */ + LEN maxprint; /* number of elements to print */ + LEN mul2; /* size of number to use multiply algorithm 2 */ + LEN sq2; /* size of number to use square algorithm 2 */ + LEN pow2; /* size of modulus to use REDC for powers */ + LEN redc2; /* size of modulus to use REDC algorithm 2 */ + BOOL tilde_ok; /* ok to print a tilde on aproximations */ + BOOL tab_ok; /* ok to print tab before numeric values */ + LEN quomod; /* quomod() default rounding mode */ + LEN quo; /* quotient // default rounding mode */ + LEN mod; /* mod % default rounding mode */ + LEN sqrt; /* sqrt() default rounding mode */ + LEN appr; /* appr() default rounding mode */ + LEN cfappr; /* cfappr() default rounding mode */ + LEN cfsim; /* cfsim() default rounding mode */ + LEN outround; /* output default rounding mode */ + LEN round; /* round()/bround() default rounding mode */ + BOOL leadzero; /* ok to print leading 0 before decimal pt */ + BOOL fullzero; /* ok to print trailing 0's */ + long maxscancount; /* max scan errors before abort */ + char *prompt1; /* normal prompt */ + char *prompt2; /* prompt when inside multi-line input */ + int blkmaxprint; /* octets of a block to print, 0 => all */ + BOOL blkverbose; /* TRUE => print all lines if a block */ + int blkbase; /* block output base */ + int blkfmt; /* block output style */ + long calc_debug; /* internal debug, see CALC_DEBUG_XXX below */ + long resource_debug; /* resource debug, see RSCDBG_XXX below */ + long user_debug; /* user defined debug value: 0 default */ + BOOL verbose_quit; /* TRUE => print Quit or abort executed msg */ + int ctrl_d; /* see CTRL_D_xyz below */ + char *program; /* our name */ + char *base_name; /* basename of our name */ + BOOL windows; /* TRUE => running under MS windows */ + BOOL cygwin; /* TRUE => compiled with cygwin */ + BOOL compile_custom; /* TRUE => compiled with -DCUSTOM */ + BOOL *allow_custom; /* ptr to if custom functions are allowed */ + char *version; /* calc version string */ +}; +typedef struct config CONFIG; + + +/* + * resource_debug bit masks + */ +#define RSCDBG_STDIN_FUNC (0x00000001) /* interactive func define debug */ +#define RSCDBG_FILE_FUNC (0x00000002) /* file read func define debug */ +#define RSCDBG_FUNC_INFO (0x00000004) /* print extra info for show func */ +#define RSCDBG_PRINT_DBG (0x00000008) /* print debug messages */ +#define RSCDBG_MASK (0x0000000f) + + +/* + * calc_debug bit masks + */ +#define CALCDBG_SYSTEM (0x00000001) /* print system cmd prior to exec */ +#define CALCDBG_FUNC_QUIT (0x00000002) /* active functions when quit */ +#define CALCDBG_HASH_STATE (0x00000004) /* hash state details */ +#define CALCDBG_BLOCK (0x00000008) /* block debug */ +#define CALCDBG_TTY (0x00000010) /* report TTY state changes */ +#define CALCDBG_RUNSTATE (0x00000020) /* report run_state changes */ +#define CALCDBG_RAND (0x00000040) /* report rand() activity */ +#define CALCDBG_MASK (0x0000007f) + +/* + * ctrl-d meanings + */ +#define CTRL_D_VIRGIN_EOF (0) /* ^D only exits on virgin command lines */ +#define CTRL_D_NEVER_EOF (1) /* ^D never exits, emacs binding meaning only */ +#define CTRL_D_EMPTY_EOF (2) /* ^D always exits at start of line */ + + +/* + * global configuration states and aliases + */ +extern DLL CONFIG *conf; /* current configuration */ +extern DLL CONFIG oldstd; /* old classic standard configuration */ +extern DLL CONFIG newstd; /* default compatible configuration */ +extern DLL char *calc_debug; /* !=NULL => value of config("calc_debug") */ +extern DLL char *resource_debug; /* !=NULL => config("resource_debug") value */ +extern DLL char *user_debug; /* !=NULL => value of config("user_debug") */ + + +/* + * configuration externals + */ +extern DLL CONFIG *config_copy(CONFIG *src); +extern DLL void config_free(CONFIG *cfg); +extern DLL void config_print(CONFIG *cfg); +extern DLL int configtype(char*); +extern DLL void config_print(CONFIG*); +extern DLL BOOL config_cmp(CONFIG*, CONFIG*); + + +#endif /* !__CONFIG_H__ */ diff --git a/calc/calc/custom.h b/calc/calc/custom.h new file mode 100644 index 0000000..557889d --- /dev/null +++ b/calc/calc/custom.h @@ -0,0 +1,80 @@ +/* + * custom - interface for custom software and hardware interfaces + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/03/03 04:53:08 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + +/* + * Be careful what you put in this file, upper .c files include + * this file even when CUSTOM is not defined (ALLOW_CUSTOM is empty). + * + * Don't include anything, let the including .c file bring in: + * + * have_const.h + * value.h + * + * before they include this file. + * + * Keep this file down to a minimum. Don't put custom builtin funcion + * stuff in this file! + */ + + +#if !defined(CUSTOM_H) +#define CUSTOM_H + + +/* + * arg count definitons + */ +#define MAX_CUSTOM_ARGS 100 /* maximum number of custom arguments */ + + +/* + * custom function interface + */ +struct custom { + char *name; /* name of the custom builtin */ + char *desc; /* very brief description of custom builtin */ + short minargs; /* minimum number of arguments */ + short maxargs; /* maximum number of arguments */ + VALUE (*func)(char *name, int argc, VALUE **argv); /* custom func */ +}; + + +/* + * external declarations + * + * These are the required interfaces. The dummy.c stubs these interfaces too. + */ +extern VALUE custom(char*, int, VALUE**); /* master custom interface */ +extern BOOL allow_custom; /* TRUE => custom builtins allowed */ +extern void showcustom(void); /* print custom functions */ +extern void customhelp(char *); /* direct custom help */ +extern CONST struct custom cust[]; /* custom interface table */ + +#endif /* !CUSTOM_H */ diff --git a/calc/calc/endian_calc.h b/calc/calc/endian_calc.h new file mode 100644 index 0000000..d57c0c7 --- /dev/null +++ b/calc/calc/endian_calc.h @@ -0,0 +1,15 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__ENDIAN_CALC_H__) +#define __ENDIAN_CALC_H__ + + +/* what byte order are we? */ +#include +#define CALC_BYTE_ORDER BYTE_ORDER + + +#endif /* !__ENDIAN_CALC_H__ */ diff --git a/calc/calc/file.h b/calc/calc/file.h new file mode 100644 index 0000000..fb76329 --- /dev/null +++ b/calc/calc/file.h @@ -0,0 +1,99 @@ +/* + * file - file I/O routines callable by users + * + * Copyright (C) 1999 David I. Bell and Landon Curt Noll + * + * Primary author: David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1996/05/24 05:55:58 + * File existed as early as: 1996 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__FILE_H__) +#define __FILE_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/have_fpos.h" +#else +# include +#endif + + +/* + * Definition of opened files. + */ +typedef struct { + FILEID id; /* id to identify this file */ + FILE *fp; /* real file structure for I/O */ + dev_t dev; /* file device */ + ino_t inode; /* file inode */ + char *name; /* file name */ + BOOL reading; /* TRUE if opened for reading */ + BOOL writing; /* TRUE if opened for writing */ + char action; /* most recent use for 'r', 'w' or 0 */ + char mode[sizeof("rb+")];/* open mode */ +} FILEIO; + + +/* + * fgetpos/fsetpos vs fseek/ftell interface + * + * f_seek_set(FILE *stream, FILEPOS *loc) + * Seek loc bytes from the beginning of the open file, stream. + * + * f_tell(FILE *stream, FILEPOS *loc) + * Set loc to bytes from the beinning of the open file, stream. + * + * We assume that if your system does not have fgetpos/fsetpos, + * then it will have a FILEPOS that is a scalar type (e.g., long). + * Some obscure systems without fgetpos/fsetpos may not have a simple + * scalar type. In these cases the f_tell macro below will fail. + */ +#if defined(HAVE_FPOS) + +#define f_seek_set(stream, loc) fsetpos((FILE*)(stream), (FILEPOS*)(loc)) +#define f_tell(stream, loc) fgetpos((FILE*)(stream), (FILEPOS*)(loc)) + +#else + +#define f_seek_set(stream, loc) \ + fseek((FILE*)(stream), *(FILEPOS*)(loc), SEEK_SET) +#define f_tell(stream, loc) (*((FILEPOS*)(loc)) = ftell((FILE*)(stream))) + +#endif + + +/* + * external functions + */ +extern FILEIO * findid(FILEID id, int writable); +extern int fgetposid(FILEID id, FILEPOS *ptr); +extern int fsetposid(FILEID id, FILEPOS *ptr); +extern int get_open_siz(FILE *fp, ZVALUE *res); +extern char* findfname(FILEID); + + +#endif /* !__FILE_H__ */ diff --git a/calc/calc/fposval.h b/calc/calc/fposval.h new file mode 100644 index 0000000..f5f067a --- /dev/null +++ b/calc/calc/fposval.h @@ -0,0 +1,28 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__FPOSVAL_H__) +#define __FPOSVAL_H__ + + +/* what are our file position & size types? */ +#undef FILEPOS_BITS +#define FILEPOS_BITS 64 +#define SWAP_HALF_IN_FILEPOS(dest, src) SWAP_HALF_IN_B64(dest, src) + +#undef OFF_T_BITS +#define OFF_T_BITS 64 +#define SWAP_HALF_IN_OFF_T(dest, src) SWAP_HALF_IN_B64(dest, src) + +#undef DEV_BITS +#define DEV_BITS 32 +#define SWAP_HALF_IN_DEV(dest, src) SWAP_HALF_IN_B32(dest, src) + +#undef INODE_BITS +#define INODE_BITS 32 +#define SWAP_HALF_IN_INODE(dest, src) SWAP_HALF_IN_B32(dest, src) + + +#endif /* !__FPOSVAL_H__ */ diff --git a/calc/calc/func.h b/calc/calc/func.h new file mode 100644 index 0000000..9f65ae6 --- /dev/null +++ b/calc/calc/func.h @@ -0,0 +1,113 @@ +/* + * func - built-in function interface definitions + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:33 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__FUNC_H__) +#define __FUNC_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/calc.h" +# include "calc/label.h" +#else +# include +# include +#endif + + +/* + * Structure of a function. + * The f_opcodes array is actually of variable size. + */ +typedef struct func FUNC; +struct func { + FUNC *f_next; /* next function in list */ + unsigned long f_opcodecount; /* size of opcode array */ + unsigned int f_localcount; /* number of local variables */ + unsigned int f_paramcount; /* max number of parameters */ + char *f_name; /* function name */ + VALUE f_savedvalue; /* saved value of last expression */ + unsigned long f_opcodes[1]; /* array of opcodes (variable length) */ +}; + + +/* + * Amount of space needed to allocate a function of n opcodes. + */ +#define funcsize(n) (sizeof(FUNC) + (n) * sizeof(long)) + + +/* + * Size of a character pointer rounded up to a number of opcodes. + */ +#define PTR_SIZE ((sizeof(char *) + sizeof(long) - 1) / sizeof(long)) + + +/* + * The current function being compiled. + */ +extern FUNC *curfunc; + + +/* + * Functions to handle functions. + */ +extern FUNC *findfunc(long index); +extern char *namefunc(long index); +extern BOOL evaluate(BOOL nestflag); +extern long adduserfunc(char *name); +extern void rmuserfunc(char *name); +extern void rmalluserfunc(void); +extern long getuserfunc(char *name); +extern void beginfunc(char *name, BOOL newflag); +extern int builtinopcode(long index); +extern char *builtinname(long index); +extern int dumpop(unsigned long *pc); +extern void addop(long op); +extern void endfunc(void); +extern void addopone(long op, long arg); +extern void addoptwo(long op, long arg1, long arg2); +extern void addoplabel(long op, LABEL *label); +extern void addopptr(long op, char *ptr); +extern void writeindexop(void); +extern void showbuiltins(void); +extern int getbuiltinfunc(char *name); +extern void builtincheck(long index, int count); +extern void addopfunction(long op, long index, int count); +extern void showfunctions(void); +extern void initfunctions(void); +extern void clearopt(void); +extern void updateoldvalue(FUNC *fp); +extern void calculate(FUNC *fp, int argcount); +extern VALUE builtinfunc(long index, int argcount, VALUE *stck); +extern void freenumbers(FUNC *); +extern void freefunc(FUNC *); + + +#endif /* !__FUNC_H__ */ diff --git a/calc/calc/hash.h b/calc/calc/hash.h new file mode 100644 index 0000000..ee4f168 --- /dev/null +++ b/calc/calc/hash.h @@ -0,0 +1,141 @@ +/* + * hash - one-way hash routines + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1995/11/14 23:57:45 + * File existed as early as: 1995 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__HASH_H__) +#define __HASH_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/shs.h" +# include "calc/shs1.h" +# include "calc/md5.h" +# include "calc/zmath.h" +#else +# include +# include +# include +# include +#endif + + +/* MAX_CHUNKSIZE is the largest chunksize of any hash */ +#define MAX_CHUNKSIZE (SHS1_CHUNKSIZE) + +/* max size of debugging strings in xyz_print() functions */ +#define DEBUG_SIZE 127 + + +/* + * hashstate - state of a hash system + * + * Hashing some types of values requires a checkpoint (chkpt function call) + * to be performed, which pads buffered data with 0's and performs an + * update. The checkpoint thus causes the value to start on a new hash + * block boundary with no buffered data. + * + * Some data types (strings, BLOCKs and OCTETs) do not require a + * checkpoint as long as the previous value hashed was a string, + * BLOCK or OCTET. + */ +typedef struct hashstate HASH; +struct hashstate { + int hashtype; /* XYZ_HASH_TYPE debug value */ + BOOL bytes; /* TRUE => reading bytes rather than words */ + void (*update)(HASH*, USB8*, USB32); /* update arbitrary length */ + void (*chkpt)(HASH*); /* checkpoint a state */ + void (*note)(int, HASH*); /* note a special value */ + void (*type)(int, HASH*); /* note a VALUE type */ + ZVALUE (*final)(HASH*); /* complete hash state */ + int (*cmp)(HASH*,HASH*); /* compare to states, TRUE => a!=b */ + void (*print)(HASH*); /* print the value of a hash */ + int base; /* XYZ_BASE special hash value */ + int chunksize; /* XYZ_CHUNKSIZE input chunk size */ + int unionsize; /* h_union element size */ + union { /* hash dependent states */ + USB8 data[1]; /* used by hash_value to hash below */ + SHS_INFO h_shs; /* old SHS/SHA internal state */ + SHS1_INFO h_shs1; /* new SHS-1/SHA-1 internal state */ + MD5_CTX h_md5; /* MD5 internal state */ + } h_union; +}; + + +/* + * what to xor to digest value when hashing special values + * + * IMPORTANT: To avoid overlap due to the HASH_XYZ macros below, the + * XYZ_BASE values should be unique random hex values + * that end in 00 (i.e., 0 mod 256). + */ +#define SHS_BASE 0x12face00 /* old SHS / SHA */ +#define SHS1_BASE 0x23cafe00 /* new SHS-1 / SHA-1 */ +#define MD5_BASE 0x34feed00 /* MD5 */ + + +/* + * XYZ_HASH_TYPE - hash types + * + * we support these hash types + */ +#define SHS_HASH_TYPE 1 +#define SHS1_HASH_TYPE 2 +#define MD5_HASH_TYPE 3 + + +/* + * Note a special value given the base value + */ +#define HASH_NEG(base) (1+base) /* note a negative value */ +#define HASH_COMPLEX(base) (2+base) /* note a complex value */ +#define HASH_DIV(base) (4+base) /* note a division by a value */ +#define HASH_ZERO(base) (8+base) /* note a zero numeric value */ +#define HASH_ZVALUE(base) (16+base) /* note a ZVALUE */ + + +/* + * external functions + */ +extern HASH* hash_init(int, HASH*); +extern void hash_free(HASH*); +extern HASH* hash_copy(HASH*); +extern int hash_cmp(HASH*, HASH*); +extern void hash_print(HASH*); +extern ZVALUE hash_final(HASH*); +extern HASH* hash_long(int, long, HASH*); +extern HASH* hash_zvalue(int, ZVALUE, HASH*); +extern HASH* hash_number(int, void*, HASH*); +extern HASH* hash_complex(int, void*, HASH*); +extern HASH* hash_str(int, char*, HASH*); +extern HASH* hash_usb8(int, USB8*, int, HASH*); +extern HASH* hash_value(int, void*, HASH*); + + +#endif /* !__HASH_H__ */ diff --git a/calc/calc/have_const.h b/calc/calc/have_const.h new file mode 100644 index 0000000..0ee752f --- /dev/null +++ b/calc/calc/have_const.h @@ -0,0 +1,16 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_CONST_H__) +#define __HAVE_CONST_H__ + + +/* do we have or want const? */ +#define HAVE_CONST /* yes */ +#undef CONST +#define CONST const /* yes */ + + +#endif /* !__HAVE_CONST_H__ */ diff --git a/calc/calc/have_fpos.h b/calc/calc/have_fpos.h new file mode 100644 index 0000000..bd095cb --- /dev/null +++ b/calc/calc/have_fpos.h @@ -0,0 +1,17 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_FPOS_H__) +#define __HAVE_FPOS_H__ + + +/* do we have fgetpos & fsetpos functions? */ +#undef HAVE_FPOS +#define HAVE_FPOS 1 /* yes */ + +typedef fpos_t FILEPOS; + + +#endif /* !__HAVE_FPOS_H__ */ diff --git a/calc/calc/have_fpos_pos.h b/calc/calc/have_fpos_pos.h new file mode 100644 index 0000000..916527c --- /dev/null +++ b/calc/calc/have_fpos_pos.h @@ -0,0 +1,15 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_FPOS_POS_H__) +#define __HAVE_FPOS_POS_H__ + + +/* do we have fgetpos & fsetpos functions? */ +#undef HAVE_FPOS_POS /* no */ +#undef FPOS_POS_BITS + + +#endif /* !__HAVE_FPOS_POS_H__ */ diff --git a/calc/calc/have_getpgid.h b/calc/calc/have_getpgid.h new file mode 100644 index 0000000..e0c9025 --- /dev/null +++ b/calc/calc/have_getpgid.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_GETPGID_H__) +#define __HAVE_GETPGID_H__ + + +/* do we have or want getpgid()? */ +#define HAVE_GETPGID /* yes */ + + +#endif /* !__HAVE_GETPGID_H__ */ diff --git a/calc/calc/have_getprid.h b/calc/calc/have_getprid.h new file mode 100644 index 0000000..67eb83b --- /dev/null +++ b/calc/calc/have_getprid.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_GETPRID_H__) +#define __HAVE_GETPRID_H__ + + +/* do we have or want getprid()? */ +#undef HAVE_GETPRID /* no */ + + +#endif /* !__HAVE_GETPRID_H__ */ diff --git a/calc/calc/have_getsid.h b/calc/calc/have_getsid.h new file mode 100644 index 0000000..359e0ec --- /dev/null +++ b/calc/calc/have_getsid.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_GETSID_H__) +#define __HAVE_GETSID_H__ + + +/* do we have or want getsid()? */ +#define HAVE_GETSID /* yes */ + + +#endif /* !__HAVE_GETSID_H__ */ diff --git a/calc/calc/have_gettime.h b/calc/calc/have_gettime.h new file mode 100644 index 0000000..a31859a --- /dev/null +++ b/calc/calc/have_gettime.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_GETTIME_H__) +#define __HAVE_GETTIME_H__ + + +/* do we have or want clock_gettime()? */ +#undef HAVE_GETTIME /* no - no SGI_CYCLE and no REALTIME */ + + +#endif /* !__HAVE_GETTIME_H__ */ diff --git a/calc/calc/have_malloc.h b/calc/calc/have_malloc.h new file mode 100644 index 0000000..edff153 --- /dev/null +++ b/calc/calc/have_malloc.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_MALLOC_H__) +#define __HAVE_MALLOC_H__ + + +/* do we have ? */ +#undef HAVE_MALLOC_H /* no */ + + +#endif /* !__HAVE_MALLOC_H__ */ diff --git a/calc/calc/have_memmv.h b/calc/calc/have_memmv.h new file mode 100644 index 0000000..cb42589 --- /dev/null +++ b/calc/calc/have_memmv.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_MEMMV_H__) +#define __HAVE_MEMMV_H__ + + +/* do we have or want memmove()? */ +#define HAVE_MEMMOVE /* yes */ + + +#endif /* !__HAVE_MEMMV_H__ */ diff --git a/calc/calc/have_newstr.h b/calc/calc/have_newstr.h new file mode 100644 index 0000000..0a8768c --- /dev/null +++ b/calc/calc/have_newstr.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_NEWSTR_H__) +#define __HAVE_NEWSTR_H__ + + +/* do we have or want memcpy(), memset() & strchr()? */ +#define HAVE_NEWSTR /* yes */ + + +#endif /* !__HAVE_NEWSTR_H__ */ diff --git a/calc/calc/have_offscl.h b/calc/calc/have_offscl.h new file mode 100644 index 0000000..68b5931 --- /dev/null +++ b/calc/calc/have_offscl.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_OFFSCL_H__) +#define __HAVE_OFFSCL_H__ + + +#undef HAVE_OFF_T_SCALAR +#define HAVE_OFF_T_SCALAR /* off_t is a simple value */ + + +#endif /* !__HAVE_OFFSCL_H__ */ diff --git a/calc/calc/have_posscl.h b/calc/calc/have_posscl.h new file mode 100644 index 0000000..9fcd49d --- /dev/null +++ b/calc/calc/have_posscl.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_POSSCL_H__) +#define __HAVE_POSSCL_H__ + + +#undef HAVE_FILEPOS_SCALAR +#define HAVE_FILEPOS_SCALAR /* FILEPOS is a simple value */ + + +#endif /* !__HAVE_POSSCL_H__ */ diff --git a/calc/calc/have_rusage.h b/calc/calc/have_rusage.h new file mode 100644 index 0000000..d4d20b7 --- /dev/null +++ b/calc/calc/have_rusage.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_RUSAGE_H__) +#define __HAVE_RUSAGE_H__ + + +/* do we have or want getrusage()? */ +#define HAVE_GETRUSAGE /* yes */ + + +#endif /* !__HAVE_RUSAGE_H__ */ diff --git a/calc/calc/have_stdlib.h b/calc/calc/have_stdlib.h new file mode 100644 index 0000000..6537608 --- /dev/null +++ b/calc/calc/have_stdlib.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_STDLIB_H__) +#define __HAVE_STDLIB_H__ + + +/* do we have ? */ +#define HAVE_STDLIB_H /* yes */ + + +#endif /* !__HAVE_STDLIB_H__ */ diff --git a/calc/calc/have_strdup.h b/calc/calc/have_strdup.h new file mode 100644 index 0000000..a8b8d63 --- /dev/null +++ b/calc/calc/have_strdup.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_RUSAGE_H__) +#define __HAVE_RUSAGE_H__ + + +/* do we have or want getstrdup()? */ +#define HAVE_STRDUP /* yes */ + + +#endif /* !__HAVE_RUSAGE_H__ */ diff --git a/calc/calc/have_string.h b/calc/calc/have_string.h new file mode 100644 index 0000000..18aa9f3 --- /dev/null +++ b/calc/calc/have_string.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_STRING_H__) +#define __HAVE_STRING_H__ + + +/* do we have ? */ +#define HAVE_STRING_H /* yes */ + + +#endif /* !__HAVE_STRING_H__ */ diff --git a/calc/calc/have_times.h b/calc/calc/have_times.h new file mode 100644 index 0000000..688ad3e --- /dev/null +++ b/calc/calc/have_times.h @@ -0,0 +1,17 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_TIMES_H__) +#define __HAVE_TIMES_H__ + + +/* do we have ? */ +#undef HAVE_TIMES_H /* no */ +#define HAVE_SYS_TIMES_H /* yes */ +#define HAVE_TIME_H /* yes */ +#define HAVE_SYS_TIME_H /* yes */ + + +#endif /* !__HAVE_TIMES_H__ */ diff --git a/calc/calc/have_uid_t.h b/calc/calc/have_uid_t.h new file mode 100644 index 0000000..9370ed8 --- /dev/null +++ b/calc/calc/have_uid_t.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_UID_T_H__) +#define __HAVE_UID_T_H__ + + +/* do we have or want uid_t? */ +#define HAVE_UID_T /* yes */ + + +#endif /* !__HAVE_UID_T_H__ */ diff --git a/calc/calc/have_unistd.h b/calc/calc/have_unistd.h new file mode 100644 index 0000000..8c2a948 --- /dev/null +++ b/calc/calc/have_unistd.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_UNISTD_H__) +#define __HAVE_UNISTD_H__ + + +/* do we have ? */ +#define HAVE_UNISTD_H /* yes */ + + +#endif /* !__HAVE_UNISTD_H__ */ diff --git a/calc/calc/have_unused.h b/calc/calc/have_unused.h new file mode 100644 index 0000000..986cded --- /dev/null +++ b/calc/calc/have_unused.h @@ -0,0 +1,16 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_UNUSED_H__) +#define __HAVE_UNUSED_H__ + + +/* do we have/want the unused attribute? */ +#define HAVE_UNUSED /* yes */ +#undef UNUSED +#define UNUSED __attribute__((unused)) /* yes */ + + +#endif /* !__HAVE_UNUSED_H__ */ diff --git a/calc/calc/have_urandom.h b/calc/calc/have_urandom.h new file mode 100644 index 0000000..737d15f --- /dev/null +++ b/calc/calc/have_urandom.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_URANDOM_H__) +#define __HAVE_URANDOM_H__ + + +/* do we have /dev/urandom? */ +#define HAVE_URANDOM_H /* yes */ + + +#endif /* !__HAVE_URANDOM_H__ */ diff --git a/calc/calc/have_ustat.h b/calc/calc/have_ustat.h new file mode 100644 index 0000000..65594f0 --- /dev/null +++ b/calc/calc/have_ustat.h @@ -0,0 +1,14 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__HAVE_USTAT_H__) +#define __HAVE_USTAT_H__ + + +/* do we have or want ustat()? */ +#undef HAVE_USTAT /* no */ + + +#endif /* !__HAVE_USTAT_H__ */ diff --git a/calc/calc/hist.h b/calc/calc/hist.h new file mode 100644 index 0000000..3adc051 --- /dev/null +++ b/calc/calc/hist.h @@ -0,0 +1,77 @@ +/* + * hist - definitions for command history module + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1993/05/02 20:09:20 + * File existed as early as: 1993 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__HIST_H__) +#define __HIST_H__ + + +/* + * Default binding file and history size. + */ +#ifndef HIST_BINDING_FILE +#define HIST_BINDING_FILE "/usr/lib/hist.bind" +#endif + +#ifndef HIST_SIZE +#define HIST_SIZE (1024*10) +#endif + + +/* + * path search defines + */ +#define HOMECHAR '~' /* char which indicates home directory */ +#define DOTCHAR '.' /* char which indicates current directory */ +#define PATHCHAR '/' /* char which separates path components */ +#if defined(__MSDOS__) || defined(__WIN32) +#define LISTCHAR ';' /* char which separates paths in a list */ +#else +#define LISTCHAR ':' /* char which separates paths in a list */ +#endif + + +/* + * Possible returns from hist_init. Note that an error from hist_init does + * not prevent calling the other routines, but fancy command line editing + * is then disabled. + */ +#define HIST_SUCCESS 0 /* successfully inited */ +#define HIST_INITED 1 /* initialization is already done */ +#define HIST_NOFILE 2 /* bindings file could not be read */ +#define HIST_NOTTY 3 /* terminal modes could not be set */ + + +extern DLL int hist_init(char *filename); +extern DLL void hist_term(void); +extern DLL int hist_getline(char *prompt, char *buf, int len); +extern DLL void hist_saveline(char *line, int len); + + +#endif /* !__HIST_H__ */ diff --git a/calc/calc/jump.h b/calc/calc/jump.h new file mode 100644 index 0000000..34789aa --- /dev/null +++ b/calc/calc/jump.h @@ -0,0 +1,108 @@ +/* + * jump - trivial prime jump table + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1994/06/29 04:03:55 + * File existed as early as: 1994 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + +/* + * If x is divisible by a trivial prime (2,3,5,7,11), then: + * + * x + jmpindx[ (x>>1)%JMPMOD ] + * + * is the value of the smallest value > x that is not divisible by a + * trivial prime. JMPMOD is the product of the odd trivial primes. + * + * This table is useful for skipping values that are obviously not prime + * by skipping values that are a multiple of trivial prime. + * + * If x is not divisible by a trivial prime, then: + * + * x + jmp[ -jmpindx[(x>>1)%JMPMOD] ] + * + * is the value of the smallest value > x that is not divisible by a + * trivial prime. + * + * If jmpindx[y] > 0 (y = x mod JMPMOD*2), then it refers to an 'x' that + * is divisible by a trivial prime and jmpindx[y] is the offset to the next + * value that is not divisible. + * + * If jmpindx[y] <= 0, then 'x' is not divisible by a trivial prime and + * the negative of jmpindx[y] is the index into the jmp[] table. We use + * successive values from jmp[] (wrapping around to the beginning when + * we move off the end of jmp[]) to move to higher and higher values + * that are not divisible by trivial primes. + * + * Instead of testing successive odd values, this system allows us to + * skip odd values divisible by trivial primes. This is process on the + * average reduces the values we need to test by a factor of at least 2.4. + */ + + +#if !defined(__JUMP_H__) +#define __JUMP_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/have_const.h" +#else +# include +#endif + + +/* + * trivial prime CONSTants + */ +#define JMPMOD (3*5*7*11) /* product of odd trivial primes */ +#define JMPSIZE (2*4*6*10) /* ints mod JMPMOD not div by trivial primes */ +#define JPRIME (prime+4) /* pointer to first non-trivial prime */ + +/* given x, return the index within jmpindx that applies */ +#define jmpmod(x) (((x)>>1)%JMPMOD) + +/* jmpindx table value */ +#define jmpindxval(x) (jmpindx[jmpmod(x)]) + +/* return the smallest value >= x not divisible by a trivial prime */ +#define firstjmp(x,tmp) ((tmp) = jmpindxval(x), ((tmp) > 0) ? ((x)+(tmp)) : (x)) + +/* given x not divisible by a trivial prime, return jmp[] index */ +#define jmpptr(x) (-jmpindxval(x)) + +/* given a jmp pointer, return current jump increment and bump the pointer */ +#define nxtjmp(p) ( *( ((p)jmp) ? (--(p)) : ((p)=lastjmp) ) ) + +/* + * external jump tables + */ +extern CONST short jmpindx[]; +extern CONST unsigned char jmp[]; +extern CONST unsigned char *CONST lastjmp; + +#endif /* !__JUMP_H__ */ diff --git a/calc/calc/label.h b/calc/calc/label.h new file mode 100644 index 0000000..9011e9c --- /dev/null +++ b/calc/calc/label.h @@ -0,0 +1,64 @@ +/* + * label - label handling routines + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:33 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__LABEL_H__) +#define __LABEL_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/zmath.h" +#else +# include +#endif + + +#define NULL_LABEL ((LABEL *) 0) + + +/* + * Label structures. + */ +typedef struct { + long l_offset; /* offset into code of label */ + long l_chain; /* offset into code of undefined chain */ + char *l_name; /* name of label if any */ +} LABEL; + + +extern void initlabels(void); +extern void definelabel(char *name); +extern void addlabel(char *name); +extern void clearlabel(LABEL *lp); +extern void setlabel(LABEL *lp); +extern void uselabel(LABEL *lp); +extern void checklabels(void); + + +#endif /* !__LABEL_H__ */ diff --git a/calc/calc/lib_util.h b/calc/calc/lib_util.h new file mode 100644 index 0000000..d9177a3 --- /dev/null +++ b/calc/calc/lib_util.h @@ -0,0 +1,47 @@ +/* + * lib_util - calc link library utility routines + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/04/19 21:38:30 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + +/* + * These routines are here to support users of libcalc.a. These routines + * are not directly used by calc itself, however. + */ + + +#if !defined(__LIB_UTIL_H__) +#define __LIB_UTIL_H__ + +/* external functions in lib_util.c */ +extern int lowhex2bin[256]; +extern char lowbin2hex[256]; +extern ZVALUE convstr2z(char*); +extern ZVALUE convhex2z(char *hex); +extern char *convz2hex(ZVALUE z); + +#endif /* __LIB_UTIL_H__ */ diff --git a/calc/calc/longbits.h b/calc/calc/longbits.h new file mode 100644 index 0000000..4f16d10 --- /dev/null +++ b/calc/calc/longbits.h @@ -0,0 +1,32 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__LONGBITS_H__) +#define __LONGBITS_H__ + + +#undef LONG_BITS +#define LONG_BITS 32 /* bit length of a long */ + +typedef unsigned char USB8; /* unsigned 8 bits */ +typedef char SB8; /* signed 8 bits */ + +typedef unsigned short USB16; /* unsigned 16 bits */ +typedef short SB16; /* signed 16 bits */ + +typedef unsigned long USB32; /* unsigned 32 bits */ +typedef long SB32; /* signed 32 bits */ + +#undef HAVE_B64 +#define HAVE_B64 /* have USB64 and SB64 types */ +typedef unsigned long long USB64; /* unsigned 64 bits */ +typedef long long SB64; /* signed 64 bits */ + +/* how to form 64 bit constants */ +#define U(x) x ## ULL +#define L(x) x ## LL + + +#endif /* !__LONGBITS_H__ */ diff --git a/calc/calc/math_error.h b/calc/calc/math_error.h new file mode 100644 index 0000000..6d01acc --- /dev/null +++ b/calc/calc/math_error.h @@ -0,0 +1,51 @@ +/* + * math_error - a simple libcalc math error routine + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/03/23 18:37:10 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__MATH_ERROR_H__) +#define __MATH_ERROR_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +#else +# include +#endif + + +/* + * Global data definitions. + */ +char calc_error[MAXERROR+1]; /* last calc error message */ + +extern DLL jmp_buf jmpbuf; /* for errors */ + + +#endif /* !__MATH_ERROR_H__ */ diff --git a/calc/calc/md5.h b/calc/calc/md5.h new file mode 100644 index 0000000..c60e20c --- /dev/null +++ b/calc/calc/md5.h @@ -0,0 +1,86 @@ +/* + * md5 - RSA Data Security, Inc. MD5 Message-Digest Algorithm + * + * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT + * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * This file is not covered under version 2.1 of the GNU LGPL. + */ + +/* + *********************************************************************** + ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** + ** ** + ** License to copy and use this software is granted provided that ** + ** it is identified as the "RSA Data Security, Inc. MD5 Message- ** + ** Digest Algorithm" in all material mentioning or referencing this ** + ** software or this function. ** + ** ** + ** License is also granted to make and use derivative works ** + ** provided that such works are identified as "derived from the RSA ** + ** Data Security, Inc. MD5 Message-Digest Algorithm" in all ** + ** material mentioning or referencing the derived work. ** + ** ** + ** RSA Data Security, Inc. makes no representations concerning ** + ** either the merchantability of this software or the suitability ** + ** of this software for any particular purpose. It is provided "as ** + ** is" without express or implied warranty of any kind. ** + ** ** + ** These notices must be retained in any copies of any part of this ** + ** documentation and/or software. ** + *********************************************************************** + */ + +#if !defined(__MD5_H__) +#define __MD5_H__ + +/* MD5_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */ +#define MD5_CHUNKSIZE (1<<6) +#define MD5_CHUNKWORDS (MD5_CHUNKSIZE/sizeof(USB32)) + +/* MD5_DIGESTSIZE is a the length of the digest as defined by the algorithm */ +#define MD5_DIGESTSIZE (16) +#define MD5_DIGESTWORDS (MD5_DIGESTSIZE/sizeof(USB32)) + +/* MD5_LOW - where low 32 bits of 64 bit count is stored during final */ +#define MD5_LOW 14 + +/* MD5_HIGH - where high 32 bits of 64 bit count is stored during final */ +#define MD5_HIGH 15 + +/* + * MD5COUNT(MD5_CTX*, USB32) - update the 64 bit count in an MD5_CTX + * + * We will count bytes and convert to bit count during the final + * transform. + */ +#define MD5COUNT(md5info, count) { \ + USB32 tmp_countLo; \ + tmp_countLo = (md5info)->countLo; \ + if (((md5info)->countLo += (count)) < tmp_countLo) { \ + (md5info)->countHi++; \ + } \ +} + +/* + * Data structure for MD5 (Message-Digest) computation + */ +typedef struct { + USB32 digest[MD5_DIGESTWORDS]; /* message digest */ + USB32 countLo; /* 64 bit count: bits 3-34 */ + USB32 countHi; /* 64 bit count: bits 35-63 (64-66 ignored) */ + USB32 datalen; /* length of data in inp.inp_USB8 */ + USB32 data[MD5_CHUNKWORDS]; /* USB32 chunk buffer */ +} MD5_CTX; + +#endif /* __MD5_H__ */ diff --git a/calc/calc/nametype.h b/calc/calc/nametype.h new file mode 100644 index 0000000..6fbf68d --- /dev/null +++ b/calc/calc/nametype.h @@ -0,0 +1,45 @@ +/* + * nametype - associate names with values + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/03/08 13:44:55 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__NAMETYPE_H__) +#define __NAMETYPE_H__ + + +/* + * Configuration parameter name and type. + */ +typedef struct { + char *name; /* name of configuration string */ + long type; /* type for configuration */ +} NAMETYPE; + + +#endif /* !__NAMETYPE_H__ */ diff --git a/calc/calc/opcodes.h b/calc/calc/opcodes.h new file mode 100644 index 0000000..c08e106 --- /dev/null +++ b/calc/calc/opcodes.h @@ -0,0 +1,188 @@ +/* + * opcodes - opcode execution module definition + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:35 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__OPCODES_H__) +#define __OPCODES_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +#else +# include +#endif + + +/* + * Opcodes + */ +#define OP_NOP 0L /* no operation */ +#define OP_LOCALADDR 1L /* load address of local variable */ +#define OP_GLOBALADDR 2L /* load address of global variable */ +#define OP_PARAMADDR 3L /* load address of paramater variable */ +#define OP_LOCALVALUE 4L /* load value of local variable */ +#define OP_GLOBALVALUE 5L /* load value of global variable */ +#define OP_PARAMVALUE 6L /* load value of paramater variable */ +#define OP_NUMBER 7L /* load constant real numeric value */ +#define OP_INDEXADDR 8L /* load array index address */ +#define OP_PRINTRESULT 9L /* print result of top-level expression */ +#define OP_ASSIGN 10L /* assign value to variable */ +#define OP_ADD 11L /* add top two values */ +#define OP_SUB 12L /* subtract top two values */ +#define OP_MUL 13L /* multiply top two values */ +#define OP_DIV 14L /* divide top two values */ +#define OP_MOD 15L /* take mod of top two values */ +#define OP_SAVE 16L /* save value for later use */ +#define OP_NEGATE 17L /* negate top value */ +#define OP_INVERT 18L /* invert top value */ +#define OP_INT 19L /* take integer part of top value */ +#define OP_FRAC 20L /* take fraction part of top value */ +#define OP_NUMERATOR 21L /* take numerator of top value */ +#define OP_DENOMINATOR 22L /* take denominator of top value */ +#define OP_DUPLICATE 23L /* duplicate top value on stack */ +#define OP_POP 24L /* pop top value from stack */ +#define OP_RETURN 25L /* return value of function */ +#define OP_JUMPZ 26L /* jump if top value is zero */ +#define OP_JUMPNZ 27L /* jump if top value is nonzero */ +#define OP_JUMP 28L /* jump unconditionally */ +#define OP_USERCALL 29L /* call a user-defined function */ +#define OP_GETVALUE 30L /* convert address to value */ +#define OP_EQ 31L /* test top two elements for equality */ +#define OP_NE 32L /* test top two elements for inequality */ +#define OP_LE 33L /* test top two elements for <= */ +#define OP_GE 34L /* test top two elements for >= */ +#define OP_LT 35L /* test top two elements for < */ +#define OP_GT 36L /* test top two elements for > */ +#define OP_PREINC 37L /* add one to variable (++x) */ +#define OP_PREDEC 38L /* subtract one from variable (--x) */ +#define OP_POSTINC 39L /* add one to variable (x++) */ +#define OP_POSTDEC 40L /* subtract one from variable (x--) */ +#define OP_DEBUG 41L /* debugging point */ +#define OP_PRINT 42L /* print value */ +#define OP_ASSIGNPOP 43L /* assign to variable and remove it */ +#define OP_ZERO 44L /* put zero on the stack */ +#define OP_ONE 45L /* put one on the stack */ +#define OP_PRINTEOL 46L /* print end of line */ +#define OP_PRINTSPACE 47L /* print a space */ +#define OP_PRINTSTRING 48L /* print constant string */ +#define OP_DUPVALUE 49L /* duplicate value of top value */ +#define OP_OLDVALUE 50L /* old calculation value */ +#define OP_QUO 51L /* integer quotient of top two values */ +#define OP_POWER 52L /* number raised to a power */ +#define OP_QUIT 53L /* quit program */ +#define OP_CALL 54L /* call built-in routine */ +#define OP_GETEPSILON 55L /* get allowed error for calculations */ +#define OP_AND 56L /* arithmetic and */ +#define OP_OR 57L /* arithmetic or */ +#define OP_NOT 58L /* logical not */ +#define OP_ABS 59L /* absolute value */ +#define OP_SGN 60L /* sign of number */ +#define OP_ISINT 61L /* whether top value is integer */ +#define OP_CONDORJUMP 62L /* conditional or jump */ +#define OP_CONDANDJUMP 63L /* conditional and jump */ +#define OP_SQUARE 64L /* square top value */ +#define OP_STRING 65L /* load constant string value */ +#define OP_ISNUM 66L /* whether top value is a number */ +#define OP_UNDEF 67L /* load undefined value on stack */ +#define OP_ISNULL 68L /* whether variable is the null value */ +#define OP_ARGVALUE 69L /* load value of argument (parameter) n */ +#define OP_MATCREATE 70L /* create matrix */ +#define OP_ISMAT 71L /* whether variable is a matrix */ +#define OP_ISSTR 72L /* whether variable is a string */ +#define OP_GETCONFIG 73L /* get value of configuration parameter */ +#define OP_LEFTSHIFT 74L /* left shift of integer */ +#define OP_RIGHTSHIFT 75L /* right shift of integer */ +#define OP_CASEJUMP 76L /* test case and jump if not matched */ +#define OP_ISODD 77L /* whether value is an odd integer */ +#define OP_ISEVEN 78L /* whether value is even integer */ +#define OP_FIADDR 79L /* 'fast index' matrix value address */ +#define OP_FIVALUE 80L /* 'fast index' matrix value */ +#define OP_ISREAL 81L /* test value for real number */ +#define OP_IMAGINARY 82L /* load imaginary numeric constant */ +#define OP_RE 83L /* real part of complex number */ +#define OP_IM 84L /* imaginary part of complex number */ +#define OP_CONJUGATE 85L /* complex conjugate of complex number */ +#define OP_OBJCREATE 86L /* create object */ +#define OP_ISOBJ 87L /* whether value is an object */ +#define OP_NORM 88L /* norm of value (square of abs) */ +#define OP_ELEMADDR 89L /* address of element of object */ +#define OP_ELEMVALUE 90L /* value of element of object */ +#define OP_ISTYPE 91L /* whether two values are the same type */ +#define OP_SCALE 92L /* scale value by a power of two */ +#define OP_ISLIST 93L /* whether value is a list */ +#define OP_SWAP 94L /* swap values of two variables */ +#define OP_ISSIMPLE 95L /* whether value is a simple type */ +#define OP_CMP 96L /* compare values returning -1, 0, or 1 */ +#define OP_QUOMOD 97L /* calculate quotient and remainder */ +#define OP_SETCONFIG 98L /* set configuration parameter */ +#define OP_SETEPSILON 99L /* set allowed error for calculations */ +#define OP_ISFILE 100L /* whether value is a file */ +#define OP_ISASSOC 101L /* whether value is an association */ +#define OP_INITSTATIC 102L /* once only code for static initialization */ +#define OP_ELEMINIT 103L /* assign element of matrix or object */ +#define OP_ISCONFIG 104L /* whether value is a configuration state */ +#define OP_ISHASH 105L /* whether value is a hash state */ +#define OP_ISRAND 106L /* whether value is additive 55 random state */ +#define OP_ISRANDOM 107L /* whether value is a Blum random state */ +#define OP_SHOW 108L /* show data about current state */ +#define OP_INITFILL 109L /* fill new matrix with copies of a value */ +#define OP_ASSIGNBACK 110L /* assign in reverse order */ +#define OP_TEST 111L /* test whether value is "nonzero" */ +#define OP_ISDEFINED 112L /* whether string names a function */ +#define OP_ISOBJTYPE 113L /* whether string names an object type */ +#define OP_ISBLK 114L /* whether value is a block */ +#define OP_PTR 115L /* octet pointer */ +#define OP_DEREF 116L /* dereference an octet pointer */ +#define OP_ISOCTET 117L /* whether value is an octet */ +#define OP_ISPTR 118L /* whether value is a pointer */ +#define OP_SAVEVAL 119L /* activate updating */ +#define OP_LINKS 120L /* return links for numbers and strings */ +#define OP_BIT 121L /* whether specified bit is set */ +#define OP_COMP 122L /* complement value */ +#define OP_XOR 123L /* xor (~) of values */ +#define OP_HIGHBIT 124L /* index of high bit of value */ +#define OP_LOWBIT 125L /* index of low bit of value */ +#define OP_CONTENT 126L /* value returned by unary # */ +#define OP_HASHOP 127L /* binary # */ +#define OP_BACKSLASH 128L /* unary backslash */ +#define OP_SETMINUS 129L /* binary backslash */ +#define OP_PLUS 130L /* unary + */ +#define OP_JUMPNN 131L /* jump if top value is non-null */ +#define OP_ABORT 132L /* abort operation */ +#define MAX_OPCODE 132L /* highest legal opcode */ + + +/* + * external declarations + */ +extern DLL char *funcname; /* function being executed */ +extern DLL long funcline; /* function line being executed */ + + +#endif /* !__OPCODES_H__ */ diff --git a/calc/calc/prime.h b/calc/calc/prime.h new file mode 100644 index 0000000..249e5c8 --- /dev/null +++ b/calc/calc/prime.h @@ -0,0 +1,94 @@ +/* + * prime - quickly determine if a small number is prime + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1994/06/04 03:26:15 + * File existed as early as: 1994 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__PRIME_H__) +#define __PRIME_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/qmath.h" +# include "calc/have_const.h" +#else +# include +# include +#endif + + +#define MAX_MAP_PRIME ((FULL)65521) /* (2^16-15) larest prime in prmap */ +#define MAX_MAP_VAL ((FULL)65535) /* (2^16-1) larest bit in pr_map */ +#define MAX_SM_PRIME ((FULL)0xfffffffb) /* (2^32-5) larest 32 bit prime */ +#define MAX_SM_VAL ((FULL)0xffffffff) /* (2^32-1) larest 32 bit value */ + +#define MAP_POPCNT 6541 /* number of odd primes in pr_map */ + +#define NXT_MAP_PRIME ((FULL)65537) /* (2^16+1) smallest prime > 2^16 */ + +#define PIX_32B ((FULL)203280221) /* pix(2^32-1) - max pix() value */ + +/* + * product of primes that fit into a long + */ +#if BASEB == 32 +#define MAX_PFACT_VAL 52 /* max x, for which pfact(x) is a long */ +#define NXT_PFACT_VAL 14 /* next prime for higher pfact values */ +#else +#define MAX_PFACT_VAL 28 /* max x, for which pfact(x) is a long */ +#define NXT_PFACT_VAL 8 /* next prime for higher pfact values */ +#endif + +/* + * If n is odd and 1 <= n <= MAX_MAP_VAL, then: + * + * pr_map_bit(n) != 0 ==> n is prime + * pr_map_bit(n) == 0 ==> n is NOT prime + */ +#define pr_map_bit(n) (pr_map[(HALF)(n)>>4] & (1 << (((HALF)(n)>>1)&0x7))) + +/* + * Limits for piXb tables. Do not test about this value using the + * given table, even though the table has a higher sentinal value. + */ +#define MAX_PI10B ((1024*256)-1) /* largest pi10b value to test */ +#define MAX_PI18B ((FULL)(0xFFFFFFFF)) /* largest pi18b value to test */ + +/* + * Prime related external arrays. + */ +extern CONST unsigned short prime[]; +extern CONST unsigned char pr_map[]; +extern CONST unsigned short pi10b[]; +extern CONST unsigned short pi18b[]; +extern NUMBER _nxtprime_; /* 2^32+15 - smallest prime > 2^32 */ +extern CONST ZVALUE _nxt_prime_; /* 2^32+15 - smallest prime > 2^32 */ +extern CONST ZVALUE _jmpmod2_; /* JMPMOD*2 as a ZVALUE */ + + +#endif /* !__PRIME_H__ */ diff --git a/calc/calc/qmath.h b/calc/calc/qmath.h new file mode 100644 index 0000000..643733c --- /dev/null +++ b/calc/calc/qmath.h @@ -0,0 +1,276 @@ +/* + * qmath - declarations for extended precision rational arithmetic + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1993/07/30 19:42:47 + * File existed as early as: 1993 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__QMATH_H__) +#define __QMATH_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/zmath.h" +#else +# include +#endif + + +#define INITCONSTCOUNT 9 /* number of initnumbs[] pre-defined constants */ + +/* + * Rational arithmetic definitions. + */ +struct number { + ZVALUE num; /* numerator (containing sign) */ + ZVALUE den; /* denominator (always positive) */ + long links; /* number of links to this value */ + struct number *next; /* pointer to next number */ +}; + +typedef struct number NUMBER; + +extern NUMBER _qlge_; + +/* + * Input. output, allocation, and conversion routines. + */ +extern NUMBER *qalloc(void); +extern NUMBER *qcopy(NUMBER *q); +extern NUMBER *uutoq(FULL i1, FULL i2); +extern NUMBER *iitoq(long i1, long i2); +extern NUMBER *str2q(char *str); +extern NUMBER *itoq(long i); +extern NUMBER *utoq(FULL i); +extern long qtoi(NUMBER *q); +extern FULL qtou(NUMBER *q); +extern long qparse(char *str, int flags); +extern void qfreenum(NUMBER *q); +extern void qprintnum(NUMBER *q, int mode); +extern void qprintff(NUMBER *q, long width, long precision); +extern void qprintfe(NUMBER *q, long width, long precision); +extern void qprintfr(NUMBER *q, long width, BOOL force); +extern void qprintfd(NUMBER *q, long width); +extern void qprintfx(NUMBER *q, long width); +extern void qprintfb(NUMBER *q, long width); +extern void qprintfo(NUMBER *q, long width); +extern void qprintf(char *, ...); +extern void shownumbers(void); +extern void showredcdata(void); +extern void freeredcdata(void); +extern void fitprint(NUMBER *, long); + + + +/* + * Basic numeric routines. + */ +extern NUMBER *qaddi(NUMBER *q, long i); +extern NUMBER *qmuli(NUMBER *q, long i); +extern NUMBER *qdivi(NUMBER *q, long i); +extern NUMBER *qqadd(NUMBER *q1, NUMBER *q2); +extern NUMBER *qsub(NUMBER *q1, NUMBER *q2); +extern NUMBER *qmul(NUMBER *q1, NUMBER *q2); +extern NUMBER *qqdiv(NUMBER *q1, NUMBER *q2); +extern NUMBER *qquo(NUMBER *q1, NUMBER *q2, long rnd); +extern NUMBER *qmod(NUMBER *q1, NUMBER *q2, long rnd); +extern NUMBER *qmin(NUMBER *q1, NUMBER *q2); +extern NUMBER *qmax(NUMBER *q1, NUMBER *q2); +extern NUMBER *qand(NUMBER *q1, NUMBER *q2); +extern NUMBER *qor(NUMBER *q1, NUMBER *q2); +extern NUMBER *qxor(NUMBER *q1, NUMBER *q2); +extern NUMBER *qandnot(NUMBER *q1, NUMBER *q2); +extern NUMBER *qcomp(NUMBER *q); +extern NUMBER *qpowermod(NUMBER *q1, NUMBER *q2, NUMBER *q3); +extern NUMBER *qpowi(NUMBER *q1, NUMBER *q2); +extern NUMBER *qsquare(NUMBER *q); +extern NUMBER *qneg(NUMBER *q); +extern NUMBER *qsign(NUMBER *q); +extern NUMBER *qint(NUMBER *q); +extern NUMBER *qfrac(NUMBER *q); +extern NUMBER *qnum(NUMBER *q); +extern NUMBER *qden(NUMBER *q); +extern NUMBER *qinv(NUMBER *q); +extern NUMBER *qqabs(NUMBER *q); +extern NUMBER *qinc(NUMBER *q); +extern NUMBER *qdec(NUMBER *q); +extern NUMBER *qshift(NUMBER *q, long n); +extern NUMBER *qtrunc(NUMBER *q1, NUMBER *q2); +extern NUMBER *qround(NUMBER *q, long places, long rnd); +extern NUMBER *qbtrunc(NUMBER *q1, NUMBER *q2); +extern NUMBER *qbround(NUMBER *q, long places, long rnd); +extern NUMBER *qscale(NUMBER *q, long i); +extern BOOL qdivides(NUMBER *q1, NUMBER *q2); +extern BOOL qcmp(NUMBER *q1, NUMBER *q2); +extern BOOL qcmpi(NUMBER *q, long i); +extern FLAG qrel(NUMBER *q1, NUMBER *q2); +extern FLAG qreli(NUMBER *q, long i); +extern BOOL qisset(NUMBER *q, long i); + + +/* + * More complicated numeric functions. + */ +extern NUMBER *qcomb(NUMBER *q1, NUMBER *q2); +extern NUMBER *qgcd(NUMBER *q1, NUMBER *q2); +extern NUMBER *qlcm(NUMBER *q1, NUMBER *q2); +extern NUMBER *qfact(NUMBER *q); +extern NUMBER *qpfact(NUMBER *q); +extern NUMBER *qminv(NUMBER *q1, NUMBER *q2); +extern NUMBER *qfacrem(NUMBER *q1, NUMBER *q2); +extern NUMBER *qperm(NUMBER *q1, NUMBER *q2); +extern NUMBER *qgcdrem(NUMBER *q1, NUMBER *q2); +extern NUMBER *qlowfactor(NUMBER *q1, NUMBER *q2); +extern NUMBER *qfib(NUMBER *q); +extern NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R); +extern NUMBER *qcfsim(NUMBER *q, long R); +extern NUMBER *qisqrt(NUMBER *q); +extern NUMBER *qjacobi(NUMBER *q1, NUMBER *q2); +extern NUMBER *qiroot(NUMBER *q1, NUMBER *q2); +extern NUMBER *qmappr(NUMBER *q, NUMBER *e, long R); +extern NUMBER *qlcmfact(NUMBER *q); +extern NUMBER *qredcin(NUMBER *q1, NUMBER *q2); +extern NUMBER *qredcout(NUMBER *q1, NUMBER *q2); +extern NUMBER *qredcmul(NUMBER *q1, NUMBER *q2, NUMBER *q3); +extern NUMBER *qredcsquare(NUMBER *q1, NUMBER *q2); +extern NUMBER *qredcpower(NUMBER *q1, NUMBER *q2, NUMBER *q3); +extern BOOL qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3); +extern BOOL qissquare(NUMBER *q); +extern long qilog2(NUMBER *q); +extern long qilog10(NUMBER *q); +extern NUMBER *qilog(NUMBER *q, ZVALUE base); +extern BOOL qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3); +extern BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **retdiv, NUMBER **retmod); +extern FLAG qnear(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern NUMBER *qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base); +extern long qprecision(NUMBER *q); +extern long qplaces(NUMBER *q, ZVALUE base); +extern long qdecplaces(NUMBER *q); +extern long qdigits(NUMBER *q, ZVALUE base); +extern void setepsilon(NUMBER *q); +extern NUMBER *qbitvalue(long i); +extern NUMBER *qtenpow(long i); + + +/* + * Transcendental functions. These all take an epsilon argument to + * specify the required accuracy of the calculation. + */ +extern void qsincos(NUMBER *q, long bitnum, NUMBER **vs, NUMBER **vc); +extern NUMBER *qsqrt(NUMBER *q, NUMBER *epsilon, long R); +extern NUMBER *qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern NUMBER *qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern NUMBER *qcos(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qsin(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qexp(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qln(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qtan(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qsec(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qcot(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qcsc(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacos(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qasin(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qatan(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qasec(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacsc(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacot(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qatan2(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern NUMBER *qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); +extern NUMBER *qcosh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qsinh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qtanh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qcoth(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qsech(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qcsch(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacosh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qasinh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qatanh(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qasech(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacsch(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qacoth(NUMBER *q, NUMBER *epsilon); +extern NUMBER *qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg); +extern NUMBER *qpi(NUMBER *epsilon); +extern NUMBER *qcatalan(NUMBER *); +extern NUMBER *qbern(ZVALUE z); +extern void qfreebern(void); +extern NUMBER *qeuler(ZVALUE z); +extern void qfreeeuler(void); + + +/* + * pseudo-seed generator + */ +extern NUMBER *pseudo_seed(void); + + +/* + * external swap functions + */ +extern NUMBER *swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); +extern NUMBER *swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); +extern NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all); + + +/* + * macro expansions to speed this thing up + */ +#define qiszero(q) (ziszero((q)->num)) +#define qisneg(q) (zisneg((q)->num)) +#define qispos(q) (zispos((q)->num)) +#define qisint(q) (zisunit((q)->den)) +#define qisfrac(q) (!zisunit((q)->den)) +#define qisunit(q) (zisunit((q)->num) && zisunit((q)->den)) +#define qisone(q) (zisone((q)->num) && zisunit((q)->den)) +#define qisnegone(q) (zisnegone((q)->num) && zisunit((q)->den)) +#define qistwo(q) (zistwo((q)->num) && zisunit((q)->den)) +#define qiseven(q) (zisunit((q)->den) && ziseven((q)->num)) +#define qisodd(q) (zisunit((q)->den) && zisodd((q)->num)) +#define qistwopower(q) (zisunit((q)->den) && zistwopower((q)->num)) + +#define qhighbit(q) (zhighbit((q)->num)) +#define qlowbit(q) (zlowbit((q)->num)) +#define qdivcount(q1, q2) (zdivcount((q1)->num, (q2)->num)) +#define qlink(q) ((q)->links++, (q)) + +#define qfree(q) {if (--((q)->links) <= 0) qfreenum(q);} + + +/* + * Flags for qparse calls + */ +#define QPF_SLASH 0x1 /* allow slash for fractional number */ +#define QPF_IMAG 0x2 /* allow trailing 'i' for imaginary number */ + + +/* + * constants used often by the arithmetic routines + */ +extern NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_; +extern NUMBER _qtwo_, _qthree_, _qfour_; +extern NUMBER * initnumbs[]; + + +#endif /* !__QMATH_H__ */ diff --git a/calc/calc/shs.h b/calc/calc/shs.h new file mode 100644 index 0000000..232636c --- /dev/null +++ b/calc/calc/shs.h @@ -0,0 +1,85 @@ +/* + * shs - old Secure Hash Standard + * + ************************************************************************** + * This version implements the old Secure Hash Algorithm specified by * + * (FIPS Pub 180). This version is kept for backward compatibility with * + * shs version 2.10.1. See the shs utility for the new standard. * + ************************************************************************** + * + * Written 2 September 1992, Peter C. Gutmann. + * + * This file was Modified by: + * + * Landon Curt Noll + * http://www.isthe.com/chongo/ + * + * chongo /\../\ + * + * This code has been placed in the public domain. Please do not + * copyright this code. + * + * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT + * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * This file is not covered under version 2.1 of the GNU LGPL. + */ + + +#if !defined(__SHS_H__) +#define __SHS_H__ + + +/* SHS_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */ +#define SHS_CHUNKSIZE (1<<6) +#define SHS_CHUNKWORDS (SHS_CHUNKSIZE/sizeof(USB32)) + +/* SHS_DIGESTSIZE is a the length of the digest as defined by the algorithm */ +#define SHS_DIGESTSIZE (20) +#define SHS_DIGESTWORDS (SHS_DIGESTSIZE/sizeof(USB32)) + +/* SHS_LOW - where low 32 bits of 64 bit count is stored during final */ +#define SHS_LOW 15 + +/* SHS_HIGH - where high 32 bits of 64 bit count is stored during final */ +#define SHS_HIGH 14 + +/* + * The structure for storing SHS info + * + * We will assume that bit count is a multiple of 8. + */ +typedef struct { + USB32 digest[SHS_DIGESTWORDS]; /* message digest */ + USB32 countLo; /* 64 bit count: bits 3-34 */ + USB32 countHi; /* 64 bit count: bits 35-63 */ + USB32 datalen; /* length of data in data */ + USB32 data[SHS_CHUNKWORDS]; /* SHS chunk buffer */ +} SHS_INFO; + +/* + * SHSCOUNT(SHS_INFO*, USB32) - update the 64 bit count in an SHS_INFO + * + * We will count bytes and convert to bit count during the final + * transform. This assumes that the count is < 2^32. + */ +#define SHSCOUNT(shsinfo, count) { \ + USB32 tmp_countLo; \ + tmp_countLo = (shsinfo)->countLo; \ + if (((shsinfo)->countLo += (count)) < tmp_countLo) { \ + (shsinfo)->countHi++; \ + } \ +} + + +#endif /* !__SHS_H__ */ diff --git a/calc/calc/shs1.h b/calc/calc/shs1.h new file mode 100644 index 0000000..b61610c --- /dev/null +++ b/calc/calc/shs1.h @@ -0,0 +1,79 @@ +/* + * shs1 - new NIST Secure Hash Standard-1 (SHS1) + * + * Written 2 September 1992, Peter C. Gutmann. + * + * This file and been extensively modified by: + * + * Landon Curt Noll + * http://www.isthe.com/chongo/ + * + * chongo /\../\ + * + * This code has been placed in the public domain. Please do not + * copyright this code. + * + * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT + * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * This file is not covered under version 2.1 of the GNU LGPL. + */ + + +#if !defined(__SHS1_H__) +#define __SHS1_H__ + + +/* SHS1_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */ +#define SHS1_CHUNKSIZE (1<<6) +#define SHS1_CHUNKWORDS (SHS1_CHUNKSIZE/sizeof(USB32)) + +/* SHS1_DIGESTSIZE is a the length of the digest as defined by the algorithm */ +#define SHS1_DIGESTSIZE (20) +#define SHS1_DIGESTWORDS (SHS1_DIGESTSIZE/sizeof(USB32)) + +/* SHS1_LOW - where low 32 bits of 64 bit count is stored during final */ +#define SHS1_LOW 15 + +/* SHS1_HIGH - where high 32 bits of 64 bit count is stored during final */ +#define SHS1_HIGH 14 + +/* + * The structure for storing SHS1 info + * + * We will assume that bit count is a multiple of 8. + */ +typedef struct { + USB32 digest[SHS1_DIGESTWORDS]; /* message digest */ + USB32 countLo; /* 64 bit count: bits 3-34 */ + USB32 countHi; /* 64 bit count: bits 35-63 */ + USB32 datalen; /* length of data in data */ + USB32 data[SHS1_CHUNKWORDS]; /* SHS1 chunk buffer */ +} SHS1_INFO; + +/* + * SHS1COUNT(SHS1_INFO*, USB32) - update the 64 bit count in an SHS1_INFO + * + * We will count bytes and convert to bit count during the final + * transform. + */ +#define SHS1COUNT(shs1info, count) { \ + USB32 tmp_countLo; \ + tmp_countLo = (shs1info)->countLo; \ + if (((shs1info)->countLo += (count)) < tmp_countLo) { \ + (shs1info)->countHi++; \ + } \ +} + + +#endif /* !__SHS1_H__ */ diff --git a/calc/calc/string.h b/calc/calc/string.h new file mode 100644 index 0000000..e41cf00 --- /dev/null +++ b/calc/calc/string.h @@ -0,0 +1,81 @@ +/* + * string - string list routines + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:36 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__CALCSTRING_H__) +#define __CALCSTRING_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/zmath.h" +#else +# include +#endif + + +struct string { + char *s_str; + long s_len; + long s_links; + struct string *s_next; +}; + +typedef struct string STRING; + + +typedef struct { + char *h_list; /* list of strings separated by nulls */ + long h_used; /* characters used so far */ + long h_avail; /* characters available for use */ + long h_count; /* number of strings */ +} STRINGHEAD; + + +extern void initstr(STRINGHEAD *hp); +extern char *addstr(STRINGHEAD *hp, char *str); +extern char *namestr(STRINGHEAD *hp, long n); +extern int findstr(STRINGHEAD *hp, char *str); +extern char *charstr(int ch); +extern char *addliteral(char *str); +extern long stringindex(char *str1, char *str2); +extern STRING *stralloc(void); +extern long addstring(char *str, long len); +extern STRING *charstring(int ch); +extern STRING *makestring(char *str); +extern STRING *makenewstring(char *str); +extern STRING *findstring(long index); +extern STRING *slink(STRING *); +extern void sfree(STRING *); +extern void fitstring(char *, long, long); +extern void showstrings(void); +extern void showliterals(void); +extern STRING _nullstring_; + + +#endif /* !__CALCSTRING_H__ */ diff --git a/calc/calc/symbol.h b/calc/calc/symbol.h new file mode 100644 index 0000000..0f601e4 --- /dev/null +++ b/calc/calc/symbol.h @@ -0,0 +1,110 @@ +/* + * symbol - global and local symbol routines + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:37 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__SYMBOL_H__) +#define __SYMBOL_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/zmath.h" +#else +# include +#endif + + +/* + * Symbol Declarations. + */ +#define SYM_UNDEFINED 0 /* undefined symbol */ +#define SYM_PARAM 1 /* parameter symbol */ +#define SYM_LOCAL 2 /* local symbol */ +#define SYM_GLOBAL 3 /* global symbol */ +#define SYM_STATIC 4 /* static symbol */ + +#define SCOPE_GLOBAL 0 /* file scope level for global variables */ +#define SCOPE_STATIC 1 /* lowest file scope for static variables */ + + +typedef struct global GLOBAL; +struct global { + int g_len; /* length of symbol name */ + short g_filescope; /* file scope level of symbol (0 if global) */ + short g_funcscope; /* function scope level of symbol */ + char *g_name; /* global symbol name */ + VALUE g_value; /* global symbol value */ + GLOBAL *g_next; /* next symbol in hash chain */ +}; + + +/* + * Routines to search for global symbols. + */ +extern GLOBAL *addglobal(char *name, BOOL isstatic); +extern GLOBAL *findglobal(char *name); + + +/* + * Routines to return names of variables. + */ +extern char *localname(long n); +extern char *paramname(long n); +extern char *globalname(GLOBAL *sp); + + +/* + * Routines to handle entering and leaving of scope levels. + */ +extern void resetscopes(void); +extern void enterfilescope(void); +extern void exitfilescope(void); +extern void enterfuncscope(void); +extern void exitfuncscope(void); +extern void endscope (char *name, BOOL isglobal); + + +/* + * Other routines. + */ +extern long addlocal(char *name); +extern long findlocal(char *name); +extern long addparam(char *name); +extern long findparam(char *name); +extern void initlocals(void); +extern void initglobals(void); +extern int writeglobals(char *name); +extern int symboltype(char *name); +extern void showglobals(void); +extern void showallglobals(void); +extern void freeglobals(void); +extern void showstatics(void); +extern void freestatics(void); + + +#endif /* !__SYMBOL_H__ */ diff --git a/calc/calc/terminal.h b/calc/calc/terminal.h new file mode 100644 index 0000000..85cd962 --- /dev/null +++ b/calc/calc/terminal.h @@ -0,0 +1,23 @@ +/* + * DO NOT EDIT -- generated by the Makefile + */ + + +#if !defined(__TERMINAL_H__) +#define __TERMINAL_H__ + + +/* determine the type of terminal interface */ +#if !defined(USE_TERMIOS) +#if !defined(USE_TERMIO) +#if !defined(USE_SGTTY) +/* use termios */ +#define USE_TERMIOS /* */ +#undef USE_TERMIO /* */ +#undef USE_SGTTY /* */ +#endif +#endif +#endif + + +#endif /* !__TERMINAL_H__ */ diff --git a/calc/calc/token.h b/calc/calc/token.h new file mode 100644 index 0000000..ddcb458 --- /dev/null +++ b/calc/calc/token.h @@ -0,0 +1,181 @@ +/* + * token - token defines + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1990/02/15 01:48:37 + * File existed as early as: before 1990 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__TOKEN_H__) +#define __TOKEN_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/zmath.h" +#else +# include +#endif + + +/* + * Token types + */ +#define T_NULL 0 /* null token */ +#define T_LEFTPAREN 1 /* left parenthesis "(" */ +#define T_RIGHTPAREN 2 /* right parenthesis ")" */ +#define T_LEFTBRACE 3 /* left brace "{" */ +#define T_RIGHTBRACE 4 /* right brace "}" */ +#define T_SEMICOLON 5 /* end of statement ";" */ +#define T_EOF 6 /* end of file */ +#define T_COLON 7 /* label character ":" */ +#define T_ASSIGN 8 /* assignment "=" */ +#define T_PLUS 9 /* plus sign "+" */ +#define T_MINUS 10 /* minus sign "-" */ +#define T_MULT 11 /* multiply sign "*" */ +#define T_DIV 12 /* divide sign "/" */ +#define T_MOD 13 /* modulo sign "%" */ +#define T_POWER 14 /* power sign "^" or "**" */ +#define T_EQ 15 /* equality "==" */ +#define T_NE 16 /* notequal "!=" */ +#define T_LT 17 /* less than "<" */ +#define T_GT 18 /* greater than ">" */ +#define T_LE 19 /* less than or equals "<=" */ +#define T_GE 20 /* greater than or equals ">=" */ +#define T_LEFTBRACKET 21 /* left bracket "[" */ +#define T_RIGHTBRACKET 22 /* right bracket "]" */ +#define T_SYMBOL 23 /* symbol name */ +#define T_STRING 24 /* string value (double quotes) */ +#define T_NUMBER 25 /* numeric real constant */ +#define T_PLUSEQUALS 26 /* plus equals "+=" */ +#define T_MINUSEQUALS 27 /* minus equals "-=" */ +#define T_MULTEQUALS 28 /* multiply equals "*=" */ +#define T_DIVEQUALS 29 /* divide equals "/=" */ +#define T_MODEQUALS 30 /* modulo equals "%=" */ +#define T_PLUSPLUS 31 /* plusplus "++" */ +#define T_MINUSMINUS 32 /* minusminus "--" */ +#define T_COMMA 33 /* comma "," */ +#define T_ANDAND 34 /* logical and "&&" */ +#define T_OROR 35 /* logical or "||" */ +#define T_OLDVALUE 36 /* old value from prev calculation */ +#define T_SLASHSLASH 37 /* integer divide "//" */ +#define T_NEWLINE 38 /* newline character */ +#define T_SLASHSLASHEQUALS 39 /* integer divide equals "//=" */ +#define T_AND 40 /* arithmetic and "&" */ +#define T_OR 41 /* arithmetic or "|" */ +#define T_NOT 42 /* logical not "!" */ +#define T_LEFTSHIFT 43 /* left shift "<<" */ +#define T_RIGHTSHIFT 44 /* right shift ">>" */ +#define T_ANDEQUALS 45 /* and equals "&=" */ +#define T_OREQUALS 46 /* or equals "|= */ +#define T_LSHIFTEQUALS 47 /* left shift equals "<<=" */ +#define T_RSHIFTEQUALS 48 /* right shift equals ">>= */ +#define T_POWEREQUALS 49 /* power equals "^=" or "**=" */ +#define T_PERIOD 50 /* period "." */ +#define T_IMAGINARY 51 /* numeric imaginary constant */ +#define T_AMPERSAND 52 /* ampersand "&" */ +#define T_QUESTIONMARK 53 /* question mark "?" */ +#define T_AT 54 /* at sign "@" */ +#define T_DOLLAR 55 /* dollar sign "$" */ +#define T_HASH 56 /* hash or pound sign "#" */ +#define T_HASHEQUALS 57 /* hash equals "#=" */ +#define T_BACKQUOTE 58 /* backquote sign "`" */ +#define T_ARROW 59 /* arrow "->" */ +#define T_TILDE 60 /* tilde "~" */ +#define T_TILDEEQUALS 61 /* tilde equals "~=" */ +#define T_BACKSLASH 62 /* backslash or setminus "\" */ +#define T_BACKSLASHEQUALS 63 /* backslash equals "\=" */ +#define T_POUNDBANG 64 /* #!/usr/local/bin/calc comment */ +#define T_POUNDCOMMENT 65 /* #[whitespace] comment */ + + +/* + * Keyword tokens + */ +#define T_IF 101 /* if keyword */ +#define T_ELSE 102 /* else keyword */ +#define T_WHILE 103 /* while keyword */ +#define T_CONTINUE 104 /* continue keyword */ +#define T_BREAK 105 /* break keyword */ +#define T_GOTO 106 /* goto keyword */ +#define T_RETURN 107 /* return keyword */ +#define T_LOCAL 108 /* local keyword */ +#define T_GLOBAL 109 /* global keyword */ +#define T_STATIC 110 /* static keyword */ +#define T_DO 111 /* do keyword */ +#define T_FOR 112 /* for keyword */ +#define T_SWITCH 113 /* switch keyword */ +#define T_CASE 114 /* case keyword */ +#define T_DEFAULT 115 /* default keyword */ +#define T_QUIT 116 /* quit keyword */ +#define T_DEFINE 117 /* define keyword */ +#define T_READ 118 /* read keyword */ +#define T_SHOW 119 /* show keyword */ +#define T_HELP 120 /* help keyword */ +#define T_WRITE 121 /* write keyword */ +#define T_MAT 122 /* mat keyword */ +#define T_OBJ 123 /* obj keyword */ +#define T_PRINT 124 /* print keyword */ +#define T_CD 125 /* change directory keyword */ +#define T_UNDEFINE 126 /* undefine keyword */ +#define T_ABORT 127 /* abort operation */ + + +#define iskeyword(n) ((n) > 100) /* TRUE if token is a keyword */ + + +/* + * Flags returned describing results of expression parsing. + */ +#define EXPR_RVALUE 0x0001 /* result is an rvalue */ +#define EXPR_CONST 0x0002 /* result is constant */ +#define EXPR_ASSIGN 0x0004 /* result is an assignment */ + +#define isrvalue(n) ((n) & EXPR_RVALUE) /* TRUE if expression is rvalue */ +#define islvalue(n) (((n) & EXPR_RVALUE) == 0) /* TRUE if expr is lvalue */ +#define isconst(n) ((n) & EXPR_CONST) /* TRUE if expr is constant */ +#define isassign(n) ((n) & EXPR_ASSIGN) /* TRUE if expr is an assignment */ + + +/* + * Flags for modes for tokenizing. + */ +#define TM_DEFAULT 0x0 /* normal mode */ +#define TM_NEWLINES 0x1 /* treat any newline as a token */ +#define TM_ALLSYMS 0x2 /* treat almost everything as a symbol */ + + +extern long errorcount; /* number of errors found */ + +extern long tokenstring(void); +extern long tokennumber(void); +extern char *tokensymbol(void); +extern void inittokens(void); +extern int tokenmode(int flag); +extern int gettoken(void); +extern void rescantoken(void); +extern void scanerror(int, char *, ...); + + +#endif /* !__TOKEN_H__ */ diff --git a/calc/calc/value.h b/calc/calc/value.h new file mode 100644 index 0000000..a253fef --- /dev/null +++ b/calc/calc/value.h @@ -0,0 +1,535 @@ +/* + * value - definitions of general values and related routines used by calc + * + * Copyright (C) 1999 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1993/07/30 19:42:47 + * File existed as early as: 1993 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__VALUE_H__) +#define __VALUE_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +# include "calc/cmath.h" +# include "calc/config.h" +# include "calc/shs.h" +# include "calc/calcerr.h" +# include "calc/hash.h" +# include "calc/block.h" +# include "calc/nametype.h" +# include "calc/string.h" +#else +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + + +#define MAXDIM 4 /* maximum number of dimensions in matrices */ +#define USUAL_ELEMENTS 4 /* usual number of elements for objects */ + + +/* + * Flags to modify results from the printvalue routine. + * These flags are OR'd together. + */ +#define PRINT_NORMAL 0x00 /* print in normal manner */ +#define PRINT_SHORT 0x01 /* print in short format (no elements) */ +#define PRINT_UNAMBIG 0x02 /* print in non-ambiguous manner */ + + +/* + * Definition of values of various types. + */ +typedef struct value VALUE; +typedef struct object OBJECT; +typedef struct matrix MATRIX; +typedef struct list LIST; +typedef struct assoc ASSOC; +typedef long FILEID; +typedef struct rand RAND; +typedef struct random RANDOM; + + +/* + * calc values + * + * See below for information on what needs to be added for a new type. + */ +struct value { + short v_type; /* type of value */ + short v_subtype; /* other data related to some types */ + union { /* types of values (see V_XYZ below) */ + long vv_int; /* 1: small integer value */ + NUMBER *vv_num; /* 2, 21: real number */ + COMPLEX *vv_com; /* 3: complex number */ + VALUE *vv_addr; /* 4, 18: address of variable value */ + STRING *vv_str; /* 5, 20: string value */ + MATRIX *vv_mat; /* 6: address of matrix */ + LIST *vv_list; /* 7: address of list */ + ASSOC *vv_assoc; /* 8: address of association */ + OBJECT *vv_obj; /* 9: address of object */ + FILEID vv_file; /* 10: id of opened file */ + RAND *vv_rand; /* 11: additive 55 random state */ + RANDOM *vv_random; /* 12: Blum random state */ + CONFIG *vv_config; /* 13: configuration state */ + HASH *vv_hash; /* 14: hash state */ + BLOCK *vv_block; /* 15: memory block */ + OCTET *vv_octet; /* 16, 19: octet addr (unsigned char) */ + NBLOCK *vv_nblock; /* 17: named memory block */ + } v_union; +}; + + +/* + * For ease in referencing + */ +#define v_int v_union.vv_int +#define v_file v_union.vv_file +#define v_num v_union.vv_num +#define v_com v_union.vv_com +#define v_addr v_union.vv_addr +#define v_str v_union.vv_str +#define v_mat v_union.vv_mat +#define v_list v_union.vv_list +#define v_assoc v_union.vv_assoc +#define v_obj v_union.vv_obj +#define v_valid v_union.vv_int +#define v_rand v_union.vv_rand +#define v_random v_union.vv_random +#define v_config v_union.vv_config +#define v_hash v_union.vv_hash +#define v_block v_union.vv_block +#define v_octet v_union.vv_octet +#define v_nblock v_union.vv_nblock + + +/* + * Value types. + * + * NOTE: The following files should be checked/adjusted for a new type: + * + * size.c - elm_count(), lsizeof() + * help/size - update what the size() builtin will report + * hash.c - hash_value() + * quickhash.c - hashvalue() + * value.c - freevalue(), copyvalue(), comparevalue(), + * printvalue(), + * and other as needed such as testvalue(), etc. + * + * There may be others, but at is at least a start. + */ +#define V_NULL 0 /* null value */ +#define V_INT 1 /* normal integer */ +#define V_NUM 2 /* number */ +#define V_COM 3 /* complex number */ +#define V_ADDR 4 /* address of variable value */ +#define V_STR 5 /* address of string */ +#define V_MAT 6 /* address of matrix structure */ +#define V_LIST 7 /* address of list structure */ +#define V_ASSOC 8 /* address of association structure */ +#define V_OBJ 9 /* address of object structure */ +#define V_FILE 10 /* opened file id */ +#define V_RAND 11 /* address of additive 55 random state */ +#define V_RANDOM 12 /* address of Blum random state */ +#define V_CONFIG 13 /* configuration state */ +#define V_HASH 14 /* hash state */ +#define V_BLOCK 15 /* memory block */ +#define V_OCTET 16 /* octet (unsigned char) */ +#define V_NBLOCK 17 /* named memory block */ +#define V_VPTR 18 /* value address as pointer */ +#define V_OPTR 19 /* octet address as pointer */ +#define V_SPTR 20 /* string address as pointer */ +#define V_NPTR 21 /* number address as pointer */ +#define V_MAX 21 /* highest legal value */ + +#define V_NOSUBTYPE 0 /* subtype has no meaning */ +#define V_NOASSIGNTO 1 /* protection status 1 */ +#define V_NONEWVALUE 2 /* protection status 2 */ +#define V_NONEWTYPE 4 /* protection status 4 */ +#define V_NOERROR 8 /* protection status 8 */ +#define V_NOCOPYTO 16 /* protection status 16 */ +#define V_NOREALLOC 32 /* protection status 32 */ +#define V_NOASSIGNFROM 64 /* protection status 64 */ +#define V_NOCOPYFROM 128 /* protection status 128 */ +#define V_PROTECTALL 256 /* protection status 256 */ + +#define MAXPROTECT 511 + +/* + * At present protect(var, sts) determines bits in var->v_subtype + * corresponding to 4 * sts. MAXPROTECT is the sum of the simple + * (power of two) protection status values. + */ + + +#define TWOVAL(a,b) ((a) << 5 | (b)) /* for switch of two values */ + +#define NULL_VALUE ((VALUE *) 0) + + +/* + * value functions + */ +extern DLL void freevalue(VALUE *vp); +extern DLL void copyvalue(VALUE *vp, VALUE *vres); +extern DLL void negvalue(VALUE *vp, VALUE *vres); +extern DLL void addvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void subvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void orvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void andvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void compvalue(VALUE *vp, VALUE *vres); +extern DLL void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void squarevalue(VALUE *vp, VALUE *vres); +extern DLL void invertvalue(VALUE *vp, VALUE *vres); +extern DLL void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void setminusvalue(VALUE *, VALUE *, VALUE *); +extern DLL void backslashvalue(VALUE *, VALUE *); +extern DLL void contentvalue(VALUE *, VALUE *); +extern DLL void hashopvalue(VALUE *, VALUE *, VALUE *); +extern DLL void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void intvalue(VALUE *vp, VALUE *vres); +extern DLL void fracvalue(VALUE *vp, VALUE *vres); +extern DLL void incvalue(VALUE *vp, VALUE *vres); +extern DLL void decvalue(VALUE *vp, VALUE *vres); +extern DLL void conjvalue(VALUE *vp, VALUE *vres); +extern DLL void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void absvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void normvalue(VALUE *vp, VALUE *vres); +extern DLL void shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres); +extern DLL void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void powivalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void divvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres); +extern DLL BOOL testvalue(VALUE *vp); +extern DLL BOOL comparevalue(VALUE *v1, VALUE *v2); +extern DLL BOOL acceptvalue(VALUE *v1, VALUE *v2); +extern DLL void relvalue(VALUE *v1, VALUE *v2, VALUE *vres); +extern DLL void sgnvalue(VALUE *vp, VALUE *vres); +extern DLL QCKHASH hashvalue(VALUE *vp, QCKHASH val); +extern DLL void printvalue(VALUE *vp, int flags); +extern DLL BOOL precvalue(VALUE *v1, VALUE *v2); +extern DLL VALUE error_value(int e); +extern DLL int set_errno(int e); +extern DLL int set_errcount(int e); +extern DLL long countlistitems(LIST *lp); +extern DLL void addlistitems(LIST *lp, VALUE *vres); +extern DLL void addlistinv(LIST *lp, VALUE *vres); +extern DLL void copy2octet(VALUE *, OCTET *); +extern DLL int copystod(VALUE *, long, long, VALUE *, long); +extern DLL void protectall(VALUE *, int); +extern DLL void set_update(int); + + +/* + * Structure of a matrix. + */ +struct matrix { + long m_dim; /* dimension of matrix */ + long m_size; /* total number of elements */ + long m_min[MAXDIM]; /* minimum bound for indices */ + long m_max[MAXDIM]; /* maximum bound for indices */ + VALUE m_table[1]; /* actually varying length table */ +}; + +#define matsize(n) (sizeof(MATRIX) - sizeof(VALUE) + ((n) * sizeof(VALUE))) + + +extern DLL MATRIX *matadd(MATRIX *m1, MATRIX *m2); +extern DLL MATRIX *matsub(MATRIX *m1, MATRIX *m2); +extern DLL MATRIX *matmul(MATRIX *m1, MATRIX *m2); +extern DLL MATRIX *matneg(MATRIX *m); +extern DLL MATRIX *matalloc(long size); +extern DLL MATRIX *matcopy(MATRIX *m); +extern DLL MATRIX *matinit(MATRIX *m, VALUE *v1, VALUE *v2); +extern DLL MATRIX *matsquare(MATRIX *m); +extern DLL MATRIX *matinv(MATRIX *m); +extern DLL MATRIX *matscale(MATRIX *m, long n); +extern DLL MATRIX *matshift(MATRIX *m, long n); +extern DLL MATRIX *matmulval(MATRIX *m, VALUE *vp); +extern DLL MATRIX *matpowi(MATRIX *m, NUMBER *q); +extern DLL MATRIX *matconj(MATRIX *m); +extern DLL MATRIX *matquoval(MATRIX *m, VALUE *vp, VALUE *v3); +extern DLL MATRIX *matmodval(MATRIX *m, VALUE *vp, VALUE *v3); +extern DLL MATRIX *matint(MATRIX *m); +extern DLL MATRIX *matfrac(MATRIX *m); +extern DLL MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3); +extern DLL VALUE mattrace(MATRIX *m); +extern DLL MATRIX *mattrans(MATRIX *m); +extern DLL MATRIX *matcross(MATRIX *m1, MATRIX *m2); +extern DLL BOOL mattest(MATRIX *m); +extern DLL void matsum(MATRIX *m, VALUE *vres); +extern DLL BOOL matcmp(MATRIX *m1, MATRIX *m2); +extern DLL int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL int matrsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL VALUE matdet(MATRIX *m); +extern DLL VALUE matdot(MATRIX *m1, MATRIX *m2); +extern DLL void matfill(MATRIX *m, VALUE *v1, VALUE *v2); +extern DLL void matfree(MATRIX *m); +extern DLL void matprint(MATRIX *m, long max_print); +extern DLL VALUE *matindex(MATRIX *mp, BOOL create, long dim, VALUE *indices); +extern DLL void matreverse(MATRIX *m); +extern DLL void matsort(MATRIX *m); +extern DLL BOOL matisident(MATRIX *m); +extern DLL MATRIX *matround(MATRIX *m, VALUE *v2, VALUE *v3); +extern DLL MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3); + + +/* + * List definitions. + * An individual list element. + */ +typedef struct listelem LISTELEM; +struct listelem { + LISTELEM *e_next; /* next element in list (or NULL) */ + LISTELEM *e_prev; /* previous element in list (or NULL) */ + VALUE e_value; /* value of this element */ +}; + + +/* + * Structure for a list of elements. + */ +struct list { + LISTELEM *l_first; /* first list element (or NULL) */ + LISTELEM *l_last; /* last list element (or NULL) */ + LISTELEM *l_cache; /* cached list element (or NULL) */ + long l_cacheindex; /* index of cached element (or undefined) */ + long l_count; /* total number of elements in the list */ +}; + + +extern DLL void insertlistfirst(LIST *lp, VALUE *vp); +extern DLL void insertlistlast(LIST *lp, VALUE *vp); +extern DLL void insertlistmiddle(LIST *lp, long index, VALUE *vp); +extern DLL void removelistfirst(LIST *lp, VALUE *vp); +extern DLL void removelistlast(LIST *lp, VALUE *vp); +extern DLL void removelistmiddle(LIST *lp, long index, VALUE *vp); +extern DLL void listfree(LIST *lp); +extern DLL void listprint(LIST *lp, long max_print); +extern DLL int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL int listrsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL BOOL listcmp(LIST *lp1, LIST *lp2); +extern DLL VALUE *listfindex(LIST *lp, long index); +extern DLL LIST *listalloc(void); +extern DLL LIST *listcopy(LIST *lp); +extern DLL void listreverse(LIST *lp); +extern DLL void listsort(LIST *lp); +extern DLL LIST *listappr(LIST *lp, VALUE *v2, VALUE *v3); +extern DLL LIST *listround(LIST *m, VALUE *v2, VALUE *v3); +extern DLL LIST *listbround(LIST *m, VALUE *v2, VALUE *v3); +extern DLL LIST *listquo(LIST *lp, VALUE *v2, VALUE *v3); +extern DLL LIST *listmod(LIST *lp, VALUE *v2, VALUE *v3); +extern DLL BOOL evp(LISTELEM *cp, LISTELEM *x, VALUE *vres); +extern DLL BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *vres); +extern DLL void insertitems(LIST *lp1, LIST *lp2); +extern DLL LISTELEM *listelement(LIST *, long); +extern DLL LIST *listsegment(LIST *, long, long); + + +/* + * Structures for associations. + * Associations are "indexed" by one or more arbitrary values, and are + * stored in a hash table with their hash values for quick indexing. + */ +typedef struct assocelem ASSOCELEM; +struct assocelem { + ASSOCELEM *e_next; /* next element in list (or NULL) */ + long e_dim; /* dimension of indexing for this element */ + QCKHASH e_hash; /* hash value for this element */ + VALUE e_value; /* value of association */ + VALUE e_indices[1]; /* index values (variable length) */ +}; + + +struct assoc { + long a_count; /* number of elements in the association */ + long a_size; /* current size of association hash table */ + ASSOCELEM **a_table; /* current hash table for elements */ +}; + + +extern DLL ASSOC *assocalloc(long initsize); +extern DLL ASSOC *assoccopy(ASSOC *ap); +extern DLL void assocfree(ASSOC *ap); +extern DLL void assocprint(ASSOC *ap, long max_print); +extern DLL int assocsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index); +extern DLL BOOL assoccmp(ASSOC *ap1, ASSOC *ap2); +extern DLL VALUE *assocfindex(ASSOC *ap, long index); +extern DLL VALUE *associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices); + + +/* + * Object actions. + */ +#define OBJ_PRINT 0 /* print the value */ +#define OBJ_ONE 1 /* create the multiplicative identity */ +#define OBJ_TEST 2 /* test a value for "zero" */ +#define OBJ_ADD 3 /* add two values */ +#define OBJ_SUB 4 /* subtrace one value from another */ +#define OBJ_NEG 5 /* negate a value */ +#define OBJ_MUL 6 /* multiply two values */ +#define OBJ_DIV 7 /* divide one value by another */ +#define OBJ_INV 8 /* invert a value */ +#define OBJ_ABS 9 /* take absolute value of value */ +#define OBJ_NORM 10 /* take the norm of a value */ +#define OBJ_CONJ 11 /* take the conjugate of a value */ +#define OBJ_POW 12 /* take the power function */ +#define OBJ_SGN 13 /* return the sign of a value */ +#define OBJ_CMP 14 /* compare two values for equality */ +#define OBJ_REL 15 /* compare two values for inequality */ +#define OBJ_QUO 16 /* integer quotient of values */ +#define OBJ_MOD 17 /* remainder of division of values */ +#define OBJ_INT 18 /* integer part of */ +#define OBJ_FRAC 19 /* fractional part of */ +#define OBJ_INC 20 /* increment by one */ +#define OBJ_DEC 21 /* decrement by one */ +#define OBJ_SQUARE 22 /* square value */ +#define OBJ_SCALE 23 /* scale by power of two */ +#define OBJ_SHIFT 24 /* shift left (or right) by number of bits */ +#define OBJ_ROUND 25 /* round to specified decimal places */ +#define OBJ_BROUND 26 /* round to specified binary places */ +#define OBJ_ROOT 27 /* take nth root of value */ +#define OBJ_SQRT 28 /* take square root of value */ +#define OBJ_OR 29 /* take bitwise or of values */ +#define OBJ_AND 30 /* take bitwise and of values */ +#define OBJ_NOT 31 /* take logical not of value */ +#define OBJ_FACT 32 /* factorial or postfix ! */ +#define OBJ_MIN 33 /* minimum value */ +#define OBJ_MAX 34 /* maximum value */ +#define OBJ_SUM 35 /* sum value */ +#define OBJ_ASSIGN 36 /* assign value */ +#define OBJ_XOR 37 /* ~ difference of values */ +#define OBJ_COMP 38 /* ~ complement of value */ +#define OBJ_CONTENT 39 /* unary hash op */ +#define OBJ_HASHOP 40 /* binary hash op */ +#define OBJ_BACKSLASH 41 /* unary backslash op */ +#define OBJ_SETMINUS 42 /* binary backslash op */ +#define OBJ_PLUS 43 /* unary + op */ +#define OBJ_MAXFUNC 43 /* highest function */ + + +/* + * Definition of an object type. + * This is actually a varying sized structure. + */ +typedef struct { + int oa_index; /* index of object type */ + int oa_count; /* number of elements defined */ + long oa_indices[OBJ_MAXFUNC+1]; /* function indices for actions */ + int oa_elements[1]; /* element indices (MUST BE LAST) */ +} OBJECTACTIONS; + +#define objectactionsize(elements) \ + (sizeof(OBJECTACTIONS) + ((elements) - 1) * sizeof(int)) + + +/* + * Structure of an object. + * This is actually a varying sized structure. + * However, there are always at least USUAL_ELEMENTS values in the object. + */ +struct object { + OBJECTACTIONS *o_actions; /* action table for this object */ + VALUE o_table[USUAL_ELEMENTS]; /* object values (MUST BE LAST) */ +}; + +#define objectsize(elements) \ + (sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE)) + + +extern DLL OBJECT *objcopy(OBJECT *op); +extern DLL OBJECT *objalloc(long index); +extern DLL VALUE objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3); +extern DLL void objfree(OBJECT *op); +extern DLL int addelement(char *name); +extern DLL int defineobject(char *name, int indices[], int count); +extern DLL int checkobject(char *name); +extern DLL void showobjfuncs(void); +extern DLL void showobjtypes(void); +extern DLL int findelement(char *name); +extern DLL char *objtypename(unsigned long index); +extern DLL int objoffset(OBJECT *op, long index); + + +/* + * Configuration parameter name and type. + */ +extern NAMETYPE configs[]; +extern DLL void config_value(CONFIG *cfg, int type, VALUE *ret); +extern DLL void setconfig(int type, VALUE *vp); +extern DLL void config_print(CONFIG *cfg); /* the CONFIG to print */ + + +/* + * size, memsize and sizeof support + */ +extern DLL long elm_count(VALUE *vp); +extern DLL long lsizeof(VALUE *vp); +extern DLL long memsize(VALUE *vp); + +/* + * String functions + */ +extern DLL STRING *stringadd(STRING *, STRING *); +extern DLL STRING *stringcopy(STRING *); +extern DLL STRING *stringsub(STRING *, STRING *); +extern DLL STRING *stringmul(NUMBER *, STRING *); +extern DLL STRING *stringand(STRING *, STRING *); +extern DLL STRING *stringor(STRING *, STRING *); +extern DLL STRING *stringxor(STRING *, STRING *); +extern DLL STRING *stringdiff(STRING *, STRING *); +extern DLL STRING *stringsegment(STRING *, long, long); +extern DLL STRING *stringshift(STRING *, long); +extern DLL STRING *stringcomp(STRING *); +extern DLL STRING *stringneg(STRING *); +extern DLL STRING *stringcpy(STRING *, STRING *); +extern DLL STRING *stringncpy(STRING *, STRING *, long); +extern DLL long stringcontent(STRING *s); +extern DLL long stringlowbit(STRING *s); +extern DLL long stringhighbit(STRING *s); +extern DLL BOOL stringcmp(STRING *, STRING *); +extern DLL BOOL stringrel(STRING *, STRING *); +extern DLL int stringbit(STRING *, long); +extern DLL BOOL stringtest(STRING *); +extern DLL int stringsetbit(STRING *, long, BOOL); +extern DLL int stringsearch(STRING *, STRING *, long, long, ZVALUE *); +extern DLL int stringrsearch(STRING *, STRING *, long, long, ZVALUE *); + +#endif /* !__VALUE_H__ */ diff --git a/calc/calc/win32dll.h b/calc/calc/win32dll.h new file mode 100644 index 0000000..f472034 --- /dev/null +++ b/calc/calc/win32dll.h @@ -0,0 +1,50 @@ +/* + * win32dll - definitions for building windoz dll files + * + * Copyright (C) 2001 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 2001/03/17 13:05:31 + * File existed as early as: 2001 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__WIN32DLL_H__) +#define __WIN32DLL_H__ + +#if defined(_WIN32) + +# if defined(_EXPORTING) +# define DLL __declspec(dllexport) +# else +# define DLL __declspec(dllimport) +# endif + +#else /* Windoz free systems */ + +# define DLL + +#endif /* Windoz free systems */ + + +#endif /* !__WIN32DLL_H__ */ diff --git a/calc/calc/zmath.h b/calc/calc/zmath.h new file mode 100644 index 0000000..6e05f89 --- /dev/null +++ b/calc/calc/zmath.h @@ -0,0 +1,640 @@ +/* + * zmath - declarations for extended precision integer arithmetic + * + * Copyright (C) 1999,2002,2004 David I. Bell + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1993/07/30 19:42:48 + * File existed as early as: 1993 + * + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + +/* + * Data structure declarations for extended precision integer arithmetic. + * The assumption made is that a long is 32 bits and shorts are 16 bits, + * and longs must be addressible on word boundaries. + */ + + +#if !defined(__ZMATH_H__) +#define __ZMATH_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/win32dll.h" +# include "calc/alloc.h" +# include "calc/endian_calc.h" +# include "calc/longbits.h" +# include "calc/byteswap.h" +# include "calc/have_stdlib.h" +#else +# include +# include +# include +# include +# include +# include +#endif +#ifdef HAVE_STDLIB_H +# include +#endif + + +#ifndef ALLOCTEST +# define freeh(p) { if (((void *)p != (void *)_zeroval_) && \ + ((void *)p != (void *)_oneval_)) free((void *)p); } +#endif + + +#if !defined(TRUE) +#define TRUE ((BOOL) 1) /* booleans */ +#endif +#if !defined(FALSE) +#define FALSE ((BOOL) 0) +#endif + + +/* + * NOTE: FULL must be twice the storage size of a HALF + * HALF must be BASEB bits long + */ + +#if defined(HAVE_B64) + +#define BASEB 32 /* use base 2^32 */ +typedef USB32 HALF; /* unit of number storage */ +typedef SB32 SHALF; /* signed HALF */ +typedef USB64 FULL; /* double unit of number storage */ +typedef SB64 SFULL; /* signed FULL */ + +#define SWAP_HALF_IN_B64(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_HALF_IN_B32(dest, src) (*(dest) = *(src)) +#define SWAP_HALF_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) +#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) +#define SWAP_HALF_IN_BOOL(dest, src) SWAP_B16_IN_BOOL(dest, src) +#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) +#define SWAP_B32_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_B16_IN_HALF(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B64(dest, src) +#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B32(dest, src) + +#else + +#define BASEB 16 /* use base 2^16 */ +typedef USB16 HALF; /* unit of number storage */ +typedef SB16 SHALF; /* signed HALF */ +typedef USB32 FULL; /* double unit of number storage */ +typedef SB32 SFULL; /* signed FULL */ + +#define SWAP_HALF_IN_B64(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_HALF_IN_B32(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_HALF_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) +#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) +#define SWAP_HALF_IN_BOOL(dest, src) SWAP_B16_IN_BOOL(dest, src) +#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) +#define SWAP_B32_IN_FULL(dest, src) (*(dest) = *(src)) +#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B16_IN_HALF(dest, src) (*(dest) = *(src)) +#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B32(dest, src) +#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B16(dest, src) + +#endif + +#define BASE ((FULL)1< /\../\ + * + * Note that the \'s above are not back-slashing escape characters. + * They are literal ASCII backslash 0x5c characters. + * + * The effect of this virgin initial value is the same as starting + * with 0 and pre-pending those 32 characters onto the data being + * hashed. + * + * Yes, even with this non-zero virgin value there is a set of data + * that will result in a zero hash value. Worse, appending any + * about of zero bytes will continue to produce a zero hash value. + * But that would happen with any initial value so long as the + * hash of the initial was the `inverse' of the virgin prefix string. + * + * But then again for any hash function, there exists sets of data + * which that the hash of every member is the same value. That is + * life with many to few mapping functions. All we do here is to + * prevent sets whose members consist of 0 or more bytes of 0's from + * being such an awkward set. + * + * And yes, someone can figure out what the magic 'inverse' of the + * 32 ASCII character are ... but this hash function is NOT intended + * to be a cryptographic hash function, just a fast and reasonably + * good hash function. + */ +#define FNV1_32_BASIS ((QCKHASH)(0x811c9dc5)) + + +/* + * The largest power of 10 we will compute for our decimal conversion + * internal constants is: 10^(2^TEN_MAX). + */ +#define TEN_MAX 31 /* 10^2^31 requires about 1.66 * 2^29 bytes */ + + +/* + * LEN storage size must be <= FULL storage size + */ +#define MAXLEN ((LEN) 0x7fffffff >> 3) /* longest value allowed */ + + +#define MAXREDC 5 /* number of entries in REDC cache */ +#define SQ_ALG2 20 /* size for alternative squaring */ +#define MUL_ALG2 20 /* size for alternative multiply */ +#define POW_ALG2 40 /* size for using REDC for powers */ +#define REDC_ALG2 50 /* size for using alternative REDC */ + + +typedef union { + FULL ivalue; + struct { + HALF Svalue1; + HALF Svalue2; + } sis; +} SIUNION; + + +#if !defined(LITTLE_ENDIAN) +#define LITTLE_ENDIAN 1234 /* Least Significant Byte first */ +#endif +#if !defined(BIG_ENDIAN) +#define BIG_ENDIAN 4321 /* Most Significant Byte first */ +#endif +/* PDP_ENDIAN - LSB in word, MSW in long is not supported */ + +#if CALC_BYTE_ORDER == LITTLE_ENDIAN +# define silow sis.Svalue1 /* low order half of full value */ +# define sihigh sis.Svalue2 /* high order half of full value */ +#else +# if CALC_BYTE_ORDER == BIG_ENDIAN +# define silow sis.Svalue2 /* low order half of full value */ +# define sihigh sis.Svalue1 /* high order half of full value */ +# else + /\oo/\ CALC_BYTE_ORDER must be BIG_ENDIAN or LITTLE_ENDIAN /\oo/\ !!! +# endif +#endif + + +typedef struct { + HALF *v; /* pointer to array of values */ + LEN len; /* number of values in array */ + BOOL sign; /* sign, nonzero is negative */ +} ZVALUE; + + + +/* + * Function prototypes for integer math routines. + */ +extern DLL HALF * alloc(LEN len); +#ifdef ALLOCTEST +extern DLL void freeh(HALF *); +#endif + + +/* + * Input, output, and conversion routines. + */ +extern DLL void zcopy(ZVALUE z, ZVALUE *res); +extern DLL void itoz(long i, ZVALUE *res); +extern DLL void utoz(FULL i, ZVALUE *res); +extern DLL void str2z(char *s, ZVALUE *res); +extern DLL long ztoi(ZVALUE z); +extern DLL FULL ztou(ZVALUE z); +extern DLL void zprintval(ZVALUE z, long decimals, long width); +extern DLL void zprintx(ZVALUE z, long width); +extern DLL void zprintb(ZVALUE z, long width); +extern DLL void zprinto(ZVALUE z, long width); +extern DLL void fitzprint(ZVALUE, long, long); + + +/* + * Basic numeric routines. + */ +extern DLL void zmuli(ZVALUE z, long n, ZVALUE *res); +extern DLL long zdivi(ZVALUE z, long n, ZVALUE *res); +extern DLL long zmodi(ZVALUE z, long n); +extern DLL void zadd(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zsub(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zmul(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL long zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *res, ZVALUE *rem, long R); +extern DLL long zquo(ZVALUE z1, ZVALUE z2, ZVALUE *res, long R); +extern DLL long zmod(ZVALUE z1, ZVALUE z2, ZVALUE *rem, long R); +extern DLL void zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL BOOL zdivides(ZVALUE z1, ZVALUE z2); +extern DLL void zor(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zand(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zxor(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zandnot(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL long zpopcnt(ZVALUE z, int bitval); +extern DLL void zshift(ZVALUE z, long n, ZVALUE *res); +extern DLL void zsquare(ZVALUE z, ZVALUE *res); +extern DLL long zlowbit(ZVALUE z); +extern DLL LEN zhighbit(ZVALUE z); +extern DLL void zbitvalue(long n, ZVALUE *res); +extern DLL BOOL zisset(ZVALUE z, long n); +extern DLL BOOL zisonebit(ZVALUE z); +extern DLL BOOL zisallbits(ZVALUE z); +extern DLL FLAG ztest(ZVALUE z); +extern DLL FLAG zrel(ZVALUE z1, ZVALUE z2); +extern DLL FLAG zabsrel(ZVALUE z1, ZVALUE z2); +extern DLL BOOL zcmp(ZVALUE z1, ZVALUE z2); + + +/* + * More complicated numeric functions. + */ +extern DLL FULL uugcd(FULL i1, FULL i2); +extern DLL long iigcd(long i1, long i2); +extern DLL void zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zlcm(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zreduce(ZVALUE z1, ZVALUE z2, ZVALUE *z1res, ZVALUE *z2res); +extern DLL void zfact(ZVALUE z, ZVALUE *dest); +extern DLL void zperm(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL int zcomb(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL FLAG zjacobi(ZVALUE z1, ZVALUE z2); +extern DLL void zfib(ZVALUE z, ZVALUE *res); +extern DLL void zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void ztenpow(long power, ZVALUE *res); +extern DLL void zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res); +extern DLL BOOL zmodinv(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL BOOL zrelprime(ZVALUE z1, ZVALUE z2); +extern DLL long zlog(ZVALUE z1, ZVALUE z2); +extern DLL long zlog10(ZVALUE z); +extern DLL long zdivcount(ZVALUE z1, ZVALUE z2); +extern DLL long zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem); +extern DLL long zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL long zdigits(ZVALUE z1); +extern DLL long zdigit(ZVALUE z1, long n); +extern DLL FLAG zsqrt(ZVALUE z1, ZVALUE *dest, long R); +extern DLL void zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest); +extern DLL BOOL zissquare(ZVALUE z); +extern DLL void zhnrmod(ZVALUE v, ZVALUE h, ZVALUE zn, ZVALUE zr, ZVALUE *res); + + +/* + * Prime related functions. + */ +extern DLL FLAG zisprime(ZVALUE z); +extern DLL FULL znprime(ZVALUE z); +extern DLL FULL next_prime(FULL v); +extern DLL FULL zpprime(ZVALUE z); +extern DLL void zpfact(ZVALUE z, ZVALUE *dest); +extern DLL BOOL zprimetest(ZVALUE z, long count, ZVALUE skip); +extern DLL BOOL zredcprimetest(ZVALUE z, long count, ZVALUE skip); +extern DLL BOOL znextcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand); +extern DLL BOOL zprevcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, ZVALUE *cand); +extern DLL FULL zlowfactor(ZVALUE z, long count); +extern DLL FLAG zfactor(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL long zpix(ZVALUE z1); +extern DLL void zlcmfact(ZVALUE z, ZVALUE *dest); + + +/* + * Misc misc functions. :-) + */ +extern DLL void zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL BOOL zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3); +extern DLL void zio_init(void); + + +/* + * These functions are for internal use only. + */ +extern DLL void ztrim(ZVALUE *z); +extern DLL void zshiftr(ZVALUE z, long n); +extern DLL void zshiftl(ZVALUE z, long n); +extern DLL HALF *zalloctemp(LEN len); + + +/* + * Modulo arithmetic definitions. + * Structure holding state of REDC initialization. + * Multiple instances of this structure can be used allowing + * calculations with more than one modulus at the same time. + * Len of zero means the structure is not initialized. + */ +typedef struct { + LEN len; /* number of words in binary modulus */ + ZVALUE mod; /* modulus REDC is computing with */ + ZVALUE inv; /* inverse of modulus in binary modulus */ + ZVALUE one; /* REDC format for the number 1 */ +} REDC; + +extern DLL REDC *zredcalloc(ZVALUE z1); +extern DLL void zredcfree(REDC *rp); +extern DLL void zredcencode(REDC *rp, ZVALUE z1, ZVALUE *res); +extern DLL void zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res); +extern DLL void zredcmul(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); +extern DLL void zredcsquare(REDC *rp, ZVALUE z1, ZVALUE *res); +extern DLL void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); + + +/* + * macro expansions to speed this thing up + */ +#define ziseven(z) (!(*(z).v & 01)) +#define zisodd(z) (*(z).v & 01) +#define ziszero(z) ((*(z).v == 0) && ((z).len == 1)) +#define zisneg(z) ((z).sign) +#define zispos(z) (((z).sign == 0) && (*(z).v || ((z).len > 1))) +#define zisunit(z) ((*(z).v == 1) && ((z).len == 1)) +#define zisone(z) ((*(z).v == 1) && ((z).len == 1) && !(z).sign) +#define zisnegone(z) ((*(z).v == 1) && ((z).len == 1) && (z).sign) +#define zistwo(z) ((*(z).v == 2) && ((z).len == 1) && !(z).sign) +#define zisabstwo(z) ((*(z).v == 2) && ((z).len == 1)) +#define zisabsleone(z) ((*(z).v <= 1) && ((z).len == 1)) +#define zislezero(z) (zisneg(z) || ziszero(z)) +#define zisleone(z) (zisneg(z) || zisabsleone(z)) +#define zistiny(z) ((z).len == 1) + +/* + * zgtmaxfull(z) TRUE if abs(z) > MAXFULL + */ +#define zgtmaxfull(z) (((z).len > 2) || (((z).len == 2) && (((SHALF)(z).v[1]) < 0))) + +/* + * zgtmaxufull(z) TRUE if abs(z) will not fit into a FULL (> MAXUFULL) + */ +#define zgtmaxufull(z) ((z).len > 2) + +/* + * zgtmaxulong(z) TRUE if abs(z) > MAXULONG + */ +#if BASEB >= LONG_BITS +#define zgtmaxulong(z) ((z).len > 1) +#else +#define zgtmaxulong(z) zgtmaxufull(z) +#endif + +/* + * zgtmaxlong(z) TRUE if abs(z) > MAXLONG + */ +#if BASEB >= LONG_BITS +#define zgtmaxlong(z) (((z).len > 1) || (((z).len == 1) && (((SHALF)(z).v[0]) < 0))) +#else +#define zgtmaxlong(z) zgtmaxfull(z) +#endif + +/* + * Some algorithms testing for values of a certain length. Macros such as + * zistiny() do this well. In other cases algorthms require tests for values + * in comparison to a given power of 2. In the later case, zistiny() compares + * against a different power of 2 on a 64 bit machine. The macros below + * provide a tests against powers of 2 that are independent of the work size. + * + * zge16b(z) TRUE if abs(z) >= 2^16 + * zge24b(z) TRUE if abs(z) >= 2^24 + * zge31b(z) TRUE if abs(z) >= 2^31 + * zge32b(z) TRUE if abs(z) >= 2^32 + * zge64b(z) TRUE if abs(z) >= 2^64 + */ +#if BASEB == 32 + +#define zge16b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x10000)) +#define zge24b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x1000000)) +#define zge31b(z) (!zistiny(z) || (((SHALF)(z).v[0]) < 0)) +#define zge32b(z) (!zistiny(z)) +#define zge64b(z) ((z).len > 2) + +#else + +#define zge16b(z) (!zistiny(z)) +#define zge24b(z) (((z).len > 2) || (((z).len == 2) && ((z).v[1] >= (HALF)0x100))) +#define zge31b(z) (((z).len > 2) || (((z).len == 2) && (((SHALF)(z).v[1]) < 0))) +#define zge32b(z) ((z).len > 2) +#define zge64b(z) ((z).len > 4) + +#endif + + +/* + * ztofull - convert an absolute value of a ZVALUE to a FULL if possible + * + * If the value is too large, only the low order bits that are able to + * be converted into a FULL will be used. + */ +#define ztofull(z) (zistiny(z) ? ((FULL)((z).v[0])) : \ + ((FULL)((z).v[0]) + \ + ((FULL)((z).v[1]) << BASEB))) + +#define z1tol(z) ((long)((z).v[0])) +#define z2tol(z) ((long)(((z).v[0]) + \ + (((z).v[1] & MAXHALF) << BASEB))) + +/* + * ztoulong - convert an absolute value of a ZVALUE to an unsigned long + * + * If the value is too large, only the low order bits that are able to + * be converted into a long will be used. + */ +#if BASEB >= LONG_BITS +# define ztoulong(z) ((unsigned long)z1tol(z)) +#else +# define ztoulong(z) ((unsigned long)ztofull(z)) +#endif + +/* + * ztolong - convert an absolute value of a ZVALUE to a long + * + * If the value is too large, only the low order bits that are able to + * be converted into a long will be used. + */ +#define ztolong(z) ((long)(ztoulong(z) & MAXLONG)) + +#define zclearval(z) memset((z).v, 0, (z).len * sizeof(HALF)) +#define zcopyval(z1,z2) memcpy((z2).v, (z1).v, (z1).len * sizeof(HALF)) +#define zquicktrim(z) {if (((z).len > 1) && ((z).v[(z).len-1] == 0)) \ + (z).len--;} +#define zfree(z) freeh((z).v) + + +/* + * Output modes for numeric displays. + */ +#define MODE_DEFAULT 0 +#define MODE_FRAC 1 +#define MODE_INT 2 +#define MODE_REAL 3 +#define MODE_EXP 4 +#define MODE_HEX 5 +#define MODE_OCTAL 6 +#define MODE_BINARY 7 +#define MODE_MAX 7 +#define MODE2_OFF (MODE_MAX+1) + +#define MODE_INITIAL MODE_REAL +#define MODE2_INITIAL MODE2_OFF + + +/* + * Output routines for either FILE handles or strings. + */ +extern DLL void math_chr(int ch); +extern DLL void math_str(char *str); +extern DLL void math_fill(char *str, long width); +extern DLL void math_flush(void); +extern DLL void math_divertio(void); +extern DLL void math_cleardiversions(void); +extern DLL char *math_getdivertedio(void); +extern DLL int math_setmode(int mode); +extern DLL int math_setmode2(int mode); +extern DLL LEN math_setdigits(LEN digits); +extern DLL void math_fmt(char *, ...); + + +/* + * The error routine. + */ +extern DLL void math_error(char *, ...); + + +/* + * external swap functions + */ +extern DLL HALF *swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len); +extern DLL ZVALUE *swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); +extern DLL HALF *swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len); +extern DLL ZVALUE *swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); +extern DLL ZVALUE *swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all); + + +/* + * constants used often by the arithmetic routines + */ +extern HALF _zeroval_[], _oneval_[], _twoval_[], _threeval_[], _fourval_[]; +extern HALF _fiveval_[], _sixval_[], _sevenval_[], _eightval_[], _nineval_[]; +extern HALF _tenval_[], _elevenval_[], _twelveval_[], _thirteenval_[]; +extern HALF _fourteenval_[], _fifteenval_[]; +extern HALF _sqbaseval_[]; +extern HALF _fourthbaseval_[]; + +extern ZVALUE zconst[]; /* ZVALUE integers from 0 thru 15 */ + +extern ZVALUE _zero_, _one_, _two_, _ten_, _neg_one_; +extern ZVALUE _sqbase_, _pow4base_, _pow8base_; + +extern ZVALUE _b32_, _b64_; + +extern DLL BOOL _math_abort_; /* nonzero to abort calculations */ +extern ZVALUE _tenpowers_[]; /* table of 10^2^n */ + +/* + * Bit fiddeling functions and types + */ +extern HALF bitmask[]; /* bit rotation, norm 0 */ +extern HALF lowhalf[]; /* bit masks from low end of HALF */ +extern HALF rlowhalf[]; /* reversed bit masks from low end of HALF */ +extern HALF highhalf[]; /* bit masks from high end of HALF */ +extern HALF rhighhalf[]; /* reversed bit masks from high end of HALF */ +#define HAVE_REVERSED_MASKS /* allows old code to know libcalc.a has them */ + + +/* + * BITSTR - string of bits within an array of HALFs + * + * This typedef records a location of a bit in an array of HALFs. + * Bit 0 in a HALF is assumed to be the least significant bit in that HALF. + * + * The most significant bit is found at (loc,bit). Bits of lesser + * significance may be found in previous bits and HALFs. + */ +typedef struct { + HALF *loc; /* half address of most significant bit */ + int bit; /* bit position within half of most significant bit */ + int len; /* length of string in bits */ +} BITSTR; + + +#endif /* !__ZMATH_H__*/ diff --git a/calc/calc/zrand.h b/calc/calc/zrand.h new file mode 100644 index 0000000..4ae245a --- /dev/null +++ b/calc/calc/zrand.h @@ -0,0 +1,225 @@ +/* + * zrand - subtractive 100 shuffle generator + * + * Copyright (C) 1999,2004 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1995/01/07 09:45:26 + * File existed as early as: 1994 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + +/* + * random number generator - see zrand.c for details + */ + + +#if !defined(__ZRAND_H__) +#define __ZRAND_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/value.h" +# include "calc/have_const.h" +#else +# include +# include +#endif + + +/* + * s100 generator defines + * + * NOTE: SBITS must be a power of two to make the (&= (SBITS-1)) + * in slotcp() to work. + */ +#define SBITS (64) /* size of subtractive or shuffle entry in bits */ +#define SBYTES (SBITS/8) /* size of subtractive or shuffle entry in bytes */ +#define SHALFS (SBYTES/sizeof(HALF)) /* size in HALFs */ + +/* + * seed defines + */ +#define SEEDXORBITS 64 /* low bits of s100 seed devoted to xor */ + +/* + * shuffle table defines + */ +#define SHUFPOW 8 /* power of 2 size of the shuffle table */ +#define SHUFCNT (1 << SHUFPOW) /* size of shuffle table */ +#define SHUFLEN (SLEN*SHUFCNT) /* length of shuffle table in FULLs */ +#define SHUFMASK (SHUFLEN-1) /* mask for shuffle table entry selection */ + +/* + * subtractive 100 constants + */ +#define S100 100 /* slots in an subtractive 100 table */ +#define INIT_J 36 /* initial first walking table index */ +#define INIT_K 99 /* initial second walking table index */ + +/* + * subtractive 100 table defines + * + * SLEN - length in FULLs of an subtractive 100 slot + * + * SLOAD(s,i,z) - load table slot i from subtractive 100 state s with zvalue z + * s: type RAND + * i: type int, s.slot[i] slot index + * z: type ZVALUE, what to load into s.slot[i] + * + * SSUB(s,k,j) - slot[k] -= slot[j] + * s: type RAND + * k: type int, s.slot[k] slot index, what to gets changed + * j: type int, s.slot[j] slot index, what to add to s.slot[k] + * (may use local variable tmp) + * + * SINDX(s,k) - select the shuffle table entry from slot[k] (uses top bits) + * s: type RAND + * k: type int, s.slot[k] slot index, selects shuffle entry + * result type int, refers to s.shuf[SINDX(s,k)] + * + * SBUFFER(s,t) - load s100 buffer with t + * s: type RAND + * t: type int, s.shuf[t] entry index, replace buffer with it + * + * SSHUF(s,t,k) - save slot[k] into shuffle entry t + * s: type RAND + * t: type int, s.shuf[t] entry index, what gets changed + * k: type int, s.slot[k] slot index, load into s.shuf[t] + * + * SSWAP(s,j,k) - swap slot[j] with slot[k] + * s: type RAND + * j: type int, s.slot[j] slot index, goes into s.slot[k] + * k: type int, s.slot[k] slot index, goes into s.slot[j] + * (uses local variable tmp) + * + * SMOD64(t,z) - t = seed z mod 2^64 + * t: type FULL*, array of FULLs that get z mod 2^64 + * z: type ZVALUE, what gets (mod 2^64) placed into t + * + * SOXR(s,i,v) - xor slot[i] with lower 64 bits of slot value v + * s: type RAND + * i: type int, s.slot[i] slot index, what gets xored + * v: type FULL*, 64 bit value to xor into s.slot[i] + * + * SCNT - length of an subtractive 100 table in FULLs + */ +#if FULL_BITS == SBITS + +# define SLEN 1 /* a 64 bit slot can be held in a FULL */ +#define SLOAD(s,i,z) ((s).slot[i] = ztofull(z)) +#define SSUB(s,k,j) ((s).slot[k] -= (s).slot[j]) +#define SINDX(s,k) ((int)((s).slot[k] >> (FULL_BITS - SHUFPOW))) +#define SBUFFER(s,t) {(s).buffer[0] = ((s).shuf[t] & BASE1); \ + (s).buffer[1] = ((s).shuf[t] >> BASEB); \ + } +#define SSHUF(s,t,k) ((s).shuf[t] = (s).slot[k]) +#define SSWAP(s,j,k) {FULL tmp = (s).slot[j]; \ + (s).slot[j] = (s).slot[k]; \ + (s).slot[k] = tmp; \ + } +#define SMOD64(t,z) ((t)[0] = ztofull(z)) +#define SXOR(s,i,v) ((s).slot[i] ^= (v)[0]) + +#elif 2*FULL_BITS == SBITS + +# define SLEN 2 /* a 64 bit slot needs 2 FULLs */ +#define SLOAD(s,i,z) {(s).slot[(i)<<1] = ztofull(z); \ + (s).slot[1+((i)<<1)] = \ + (((z).len <= 2) ? (FULL)0 : \ + (((z).len == 3) ? (FULL)((z).v[2]) : \ + ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ + } +#define SSUB(s,k,j) {FULL tmp = (s).slot[(k)<<1]; \ + (s).slot[(k)<<1] -= (s).slot[(j)<<1]; \ + (s).slot[1+((k)<<1)] -= ((tmp <= (s).slot[(k)<<1]) ? \ + (s).slot[1+((j)<<1)] : \ + (s).slot[1+((j)<<1)] + 1); \ + } +#define SINDX(s,k) ((int)((s).slot[1+((k)<<1)] >> (FULL_BITS - SHUFPOW))) +#define SBUFFER(s,t) {(s).buffer[0] = ((s).shuf[(t)<<1] & BASE1); \ + (s).buffer[1] = ((s).shuf[(t)<<1] >> BASEB); \ + (s).buffer[2] = ((s).shuf[1+((t)<<1)] & BASE1); \ + (s).buffer[3] = ((s).shuf[1+((t)<<1)] >> BASEB); \ + } +#define SSHUF(s,t,k) {(s).shuf[(t)<<1] = (s).slot[(k)<<1]; \ + (s).shuf[1+((t)<<1)] = (s).slot[1+((k)<<1)]; \ + } +#define SSWAP(s,j,k) {FULL tmp = (s).slot[(j)<<1]; \ + (s).slot[(j)<<1] = (s).slot[(k)<<1]; \ + (s).slot[(k)<<1] = tmp; \ + tmp = (s).slot[1+((j)<<1)]; \ + (s).slot[1+((j)<<1)] = (s).slot[1+((k)<<1)]; \ + (s).slot[1+((k)<<1)] = tmp; \ + } +#define SMOD64(t,z) {(t)[0] = ztofull(z); \ + (t)[1] = (((z).len <= 2) ? (FULL)0 : \ + (((z).len == 3) ? (FULL)((z).v[2]) : \ + ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ + } +#define SXOR(s,i,v) {(s).slot[(i)<<1] ^= (v)[0]; \ + (s).slot[1+((i)<<1)] ^= (v)[1]; \ + } + +#else + + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + +#endif + +#define SCNT (SLEN*S100) /* length of subtractive 100 table in FULLs */ + +#define RAND_CONSEQ_USE (100) /* use this many before skipping */ +#define RAND_SKIP (1009-RAND_CONSEQ_USE) /* skip this many after use */ + + +/* + * s100 generator state + */ +struct rand { + int seeded; /* 1 => state has been seeded */ + int bits; /* buffer bit count */ + FULL buffer[SLEN]; /* unused random bits from last call */ + int j; /* first walking table index */ + int k; /* second walking table index */ + int need_to_skip; /* 1 => skip the next 909 values */ + FULL slot[SCNT]; /* subtractive 100 table */ + FULL shuf[SHUFLEN]; /* shuffle table entries */ +}; + + +/* + * s100 generator function declarations + */ +extern RAND *zsrand(CONST ZVALUE *seed, CONST MATRIX *pmat100); +extern RAND *zsetrand(CONST RAND *state); +extern void zrandskip(long count); +extern void zrand(long count, ZVALUE *res); +extern void zrandrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res); +extern long irand(long s); +extern RAND *randcopy(CONST RAND *rand); +extern void randfree(RAND *rand); +extern BOOL randcmp(CONST RAND *s1, CONST RAND *s2); +extern void randprint(CONST RAND *state, int flags); + + +#endif /* !__ZRAND_H__ */ diff --git a/calc/calc/zrandom.h b/calc/calc/zrandom.h new file mode 100644 index 0000000..2c9994f --- /dev/null +++ b/calc/calc/zrandom.h @@ -0,0 +1,94 @@ +/* + * zrandom - Blum-Blum-Shub pseudo-random generator + * + * Copyright (C) 1999 Landon Curt Noll + * + * Calc is open software; you can redistribute it and/or modify it under + * the terms of the version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * Calc is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * A copy of version 2.1 of the GNU Lesser General Public License is + * distributed with calc under the filename COPYING-LGPL. You should have + * received a copy with calc; if not, write to Free Software Foundation, Inc. + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * @(#) $Revision$ + * @(#) $Id$ + * @(#) $Source$ + * + * Under source code control: 1997/02/15 04:01:56 + * File existed as early as: 1997 + * + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + */ + + +#if !defined(__ZRANDOM_H__) +#define __ZRANDOM_H__ + + +#if defined(CALC_SRC) /* if we are building from the calc source tree */ +# include "calc/value.h" +# include "calc/have_const.h" +#else +# include +# include +#endif + + +/* + * Blum generator state + * + * The size of the buffer implies that a turn of the quadratic residue crank + * will never yield as many at the than the number of bits in a HALF. At + * most this implies that a turn can yield no more than 15 bits when BASEB==16 + * or 31 bits when BASEB==32. Should we deal with a excessively large + * Blum modulus (>=2^16 bits long for BASEB==16, >=2^32 bits for BASEB==32) + * the higher order random bits will be tossed. This is not a loss as + * regular sub-segments of the sequence are just as random. It only means + * that excessively large Blum modulus values waste CPU time. + */ +struct random { + int seeded; /* 1 => state has been seeded */ + int bits; /* number of unused bits in buffer */ + int loglogn; /* int(log2(log2(n))), bits produced per turn */ + HALF buffer; /* unused random bits from previous call */ + HALF mask; /* mask for the log2(log2(n)) lower bits of r */ + ZVALUE n; /* Blum modulus */ + ZVALUE r; /* Blum quadratic residue */ +}; + + +/* + * Blum constants + */ +#define BLUM_PREGEN 20 /* number of non-default predefined Blum generators */ + + +/* + * Blum generator function declarations + */ +extern RANDOM *zsrandom1(CONST ZVALUE seed, BOOL need_ret); +extern RANDOM *zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn); +extern RANDOM *zsrandom4(CONST ZVALUE seed, + CONST ZVALUE ip, CONST ZVALUE iq, long trials); +extern RANDOM *zsetrandom(CONST RANDOM *state); +extern void zrandomskip(long count); +extern void zrandom(long count, ZVALUE *res); +extern void zrandom(long count, ZVALUE *res); +extern void zrandomrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res); +extern long irandom(long s); +extern RANDOM *randomcopy(CONST RANDOM *random); +extern void randomfree(RANDOM *random); +extern BOOL randomcmp(CONST RANDOM *s1, CONST RANDOM *s2); +extern void randomprint(CONST RANDOM *state, int flags); +extern void random_libcalc_cleanup(void); + + +#endif /* !__ZRANDOM_H__ */ diff --git a/calc/libcalc.a b/calc/libcalc.a new file mode 100644 index 0000000..16dbd32 Binary files /dev/null and b/calc/libcalc.a differ diff --git a/calc/libcustcalc.a b/calc/libcustcalc.a new file mode 100644 index 0000000..6f7b465 Binary files /dev/null and b/calc/libcustcalc.a differ diff --git a/help/BUILTIN b/help/BUILTIN new file mode 100644 index 0000000..2a4e641 --- /dev/null +++ b/help/BUILTIN @@ -0,0 +1,505 @@ +Builtin functions + + There is a large number of built-in functions. Many of the + functions work on several types of arguments, whereas some only + work for the correct types (e.g., numbers or strings). In the + following description, this is indicated by whether or not the + description refers to values or numbers. This display is generated + by the 'show builtin' command. + + + Name Args Description + + abs 1-2 absolute value within accuracy b + access 1-2 determine accessibility of file a for mode b + acos 1-2 arccosine of a within accuracy b + acosh 1-2 inverse hyperbolic cosine of a within accuracy b + acot 1-2 arccotangent of a within accuracy b + acoth 1-2 inverse hyperbolic cotangent of a within accuracy b + acsc 1-2 arccosecant of a within accuracy b + acsch 1-2 inverse csch of a within accuracy b + agd 1-2 inverse gudermannian function + append 1+ append values to end of list + appr 1-3 approximate a by multiple of b using rounding c + arg 1-2 argument (the angle) of complex number + argv 0-1 calc argc or argv string + asec 1-2 arcsecant of a within accuracy b + asech 1-2 inverse hyperbolic secant of a within accuracy b + asin 1-2 arcsine of a within accuracy b + asinh 1-2 inverse hyperbolic sine of a within accuracy b + assoc 0 create new association array + atan 1-2 arctangent of a within accuracy b + atan2 2-3 angle to point (b,a) within accuracy c + atanh 1-2 inverse hyperbolic tangent of a within accuracy b + avg 0+ arithmetic mean of values + base 0-1 set default output base + base2 0-1 set default secondary output base + bernoulli 1 Bernoulli number for index a + bit 2 whether bit b in value a is set + blk 0-3 block with or without name, octet number, chunksize + blkcpy 2-5 copy value to/from a block: blkcpy(d,s,len,di,si) + blkfree 1 free all storage from a named block + blocks 0-1 named block with specified index, or null value + bround 1-3 round value a to b number of binary places + btrunc 1-2 truncate a to b number of binary places + calclevel 0 current calculation level + calc_tty 0 set tty for interactivity + catalan 1 catalan number for index a + ceil 1 smallest integer greater than or equal to number + cfappr 1-3 approximate a within accuracy b using + continued fractions + cfsim 1-2 simplify number using continued fractions + char 1 character corresponding to integer value + cmdbuf 0 command buffer + cmp 2 compare values returning -1, 0, or 1 + comb 2 combinatorial number a!/b!(a-b)! + config 1-2 set or read configuration value + conj 1 complex conjugate of value + copy 2-5 copy value to/from a block: copy(s,d,len,si,di) + cos 1-2 cosine of value a within accuracy b + cosh 1-2 hyperbolic cosine of a within accuracy b + cot 1-2 cotangent of a within accuracy b + coth 1-2 hyperbolic cotangent of a within accuracy b + count 2 count listr/matrix elements satisfying some condition + cp 2 cross product of two vectors + csc 1-2 cosecant of a within accuracy b + csch 1-2 hyperbolic cosecant of a within accuracy b + ctime 0 date and time as string + custom 0+ custom builtin function interface + delete 2 delete element from list a at position b + den 1 denominator of fraction + det 1 determinant of matrix + digit 2-3 digit at specified decimal place of number + digits 1-2 number of digits in base b representation of a + display 0-1 number of decimal digits for displaying numbers + dp 2 dot product of two vectors + epsilon 0-1 set or read allowed error for real calculations + errcount 0-1 set or read error count + errmax 0-1 set or read maximum for error count + errno 0-1 set or read calc_errno + error 0-1 generate error value + euler 1 Euler number + eval 1 evaluate expression from string to value + exp 1-2 exponential of value a within accuracy b + factor 1-3 lowest prime factor < b of a, return c if error + fcnt 2 count of times one number divides another + fib 1 Fibonacci number F(n) + forall 2 do function for all elements of list or matrix + frem 2 number with all occurrences of factor removed + fact 1 factorial + fclose 0+ close file + feof 1 whether EOF reached for file + ferror 1 whether error occurred for file + fflush 0+ flush output to file(s) + fgetc 1 read next char from file + fgetfield 1 read next white-space delimited field from file + fgetline 1 read next line from file, newline removed + fgets 1 read next line from file, newline is kept + fgetstr 1 read next null-terminated string from file, null character is kept + files 0-1 return opened file or max number of opened files + floor 1 greatest integer less than or equal to number + fopen 2 open file name a in mode b + fprintf 2+ print formatted output to opened file + fputc 2 write a character to a file + fputs 2+ write one or more strings to a file + fputstr 2+ write one or more null-terminated strings to a file + free 0+ free listed or all global variables + freebernoulli 0 free stored Bernoulli numbers + freeeuler 0 free stored Euler numbers + freeglobals 0 free all global and visible static variables + freeredc 0 free redc data cache + freestatics 0 free all unscoped static variables + freopen 2-3 reopen a file stream to a named file + fscan 2+ scan a file for assignments to one or more variables + fscanf 2+ formatted scan of a file for assignment to one or more variables + fseek 2-3 seek to position b (offset from c) in file a + fsize 1 return the size of the file + ftell 1 return the file position + frac 1 fractional part of value + gcd 1+ greatest common divisor + gcdrem 2 a divided repeatedly by gcd with b + gd 1-2 gudermannian function + getenv 1 value of environment variable (or NULL) + hash 1+ return non-negative hash value for one or + more values + head 2 return list of specified number at head of a list + highbit 1 high bit number in base 2 representation + hmean 0+ harmonic mean of values + hnrmod 4 v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1 + hypot 2-3 hypotenuse of right triangle within accuracy c + ilog 2 integral log of a to integral base b + ilog10 1 integral log of a number base 10 + ilog2 1 integral log of a number base 2 + im 1 imaginary part of complex number + indices 2 indices of a specified assoc or mat value + inputlevel 0 current input depth + insert 2+ insert values c ... into list a at position b + int 1 integer part of value + inverse 1 multiplicative inverse of value + iroot 2 integer b'th root of a + isassoc 1 whether a value is an association + isatty 1 whether a file is a tty + isblk 1 whether a value is a block + isconfig 1 whether a value is a config state + isdefined 1 whether a string names a function + iserror 1 where a value is an error + iseven 1 whether a value is an even integer + isfile 1 whether a value is a file + ishash 1 whether a value is a hash state + isident 1 returns 1 if identity matrix + isint 1 whether a value is an integer + islist 1 whether a value is a list + ismat 1 whether a value is a matrix + ismult 2 whether a is a multiple of b + isnull 1 whether a value is the null value + isnum 1 whether a value is a number + isobj 1 whether a value is an object + isobjtype 1 whether a string names an object type + isodd 1 whether a value is an odd integer + isoctet 1 whether a value is an octet + isprime 1-2 whether a is a small prime, return b if error + isptr 1 whether a value is a pointer + isqrt 1 integer part of square root + isrand 1 whether a value is a additive 55 state + israndom 1 whether a value is a Blum state + isreal 1 whether a value is a real number + isrel 2 whether two numbers are relatively prime + isstr 1 whether a value is a string + issimple 1 whether value is a simple type + issq 1 whether or not number is a square + istype 2 whether the type of a is same as the type of b + jacobi 2 -1 => a is not quadratic residue mod b + 1 => b is composite, or a is quad residue of b + join 1+ join one or more lists into one list + lcm 1+ least common multiple + lcmfact 1 lcm of all integers up till number + lfactor 2 lowest prime factor of a in first b primes + links 1 links to number or string value + list 0+ create list of specified values + ln 1-2 natural logarithm of value a within accuracy b + lowbit 1 low bit number in base 2 representation + ltol 1-2 leg-to-leg of unit right triangle (sqrt(1 - a^2)) + makelist 1 create a list with a null elements + matdim 1 number of dimensions of matrix + matfill 2-3 fill matrix with value b (value c on diagonal) + matmax 2 maximum index of matrix a dim b + matmin 2 minimum index of matrix a dim b + matsum 1 sum the numeric values in a matrix + mattrace 1 return the trace of a square matrix + mattrans 1 transpose of matrix + max 0+ maximum value + md5 0+ MD5 Hash Algorithm + memsize 1 number of octets used by the value, including overhead + meq 3 whether a and b are equal modulo c + min 0+ minimum value + minv 2 inverse of a modulo b + mmin 2 a mod b value with smallest abs value + mne 3 whether a and b are not equal modulo c + mod 2-3 residue of a modulo b, rounding type c + modify 2 modify elements of a list or matrix + name 1 name assigned to block or file + near 2-3 sign of (abs(a-b) - c) + newerror 0-1 create new error type with message a + nextcand 1-5 smallest value == d mod e > a, ptest(a,b,c) true + nextprime 1-2 return next small prime, return b if err + norm 1 norm of a value (square of absolute value) + null 0+ null value + num 1 numerator of fraction + ord 1 integer corresponding to character value + param 1 value of parameter n (or parameter count if n + is zero) + perm 2 permutation number a!/(a-b)! + prevcand 1-5 largest value == d mod e < a, ptest(a,b,c) true + prevprime 1-2 return previous small prime, return b if err + pfact 1 product of primes up till number + pi 0-1 value of pi accurate to within epsilon + pix 1-2 number of primes <= a < 2^32, return b if error + places 1-2 places after "decimal" point (-1 if infinite) + pmod 3 mod of a power (a ^ b (mod c)) + polar 2-3 complex value of polar coordinate (a * exp(b*1i)) + poly 1+ evaluates a polynomial given its coefficients or coefficient-list + pop 1 pop value from front of list + popcnt 1-2 number of bits in a that match b (or 1) + power 2-3 value a raised to the power b within accuracy c + protect 1-2 read or set protection level for variable + ptest 1-3 probabilistic primality test + printf 1+ print formatted output to stdout + prompt 1 prompt for input line using value a + push 1+ push values onto front of list + putenv 1-2 define an environment variable + quo 2-3 integer quotient of a by b, rounding type c + quomod 4 set c and d to quotient and remainder of a + divided by b + rand 0-2 additive 55 random number [0,2^64), [0,a), or [a,b) + randbit 0-1 additive 55 random number [0,2^a) + random 0-2 Blum-Blum-Shub random number [0,2^64), [0,a), or [a,b) + randombit 0-1 Blum-Blum-Sub random number [0,2^a) + randperm 1 random permutation of a list or matrix + rcin 2 convert normal number a to REDC number mod b + rcmul 3 multiply REDC numbers a and b mod c + rcout 2 convert REDC number a mod b to normal number + rcpow 3 raise REDC number a to power b mod c + rcsq 2 square REDC number a mod b + re 1 real part of complex number + remove 1 remove value from end of list + reverse 1 reverse a copy of a matrix or list + rewind 0+ rewind file(s) + rm 1+ remove file(s), -f turns off no-such-file errors + root 2-3 value a taken to the b'th root within accuracy c + round 1-3 round value a to b number of decimal places + rsearch 2-4 reverse search matrix or list for value b + starting at index c + runtime 0 user mode cpu time in seconds + saveval 1 set flag for saving values + scale 2 scale value up or down by a power of two + scan 1+ scan standard input for assignment to one or more variables + scanf 2+ formatted scan of standard input for assignment to variables + search 2-4 search matrix or list for value b starting + at index c + sec 1-2 sec of a within accuracy b + sech 1-2 hyperbolic secant of a within accuracy b + seed 0 return a 64 bit seed for a psuedo-random generator + segment 2-3 specified segment of specified list + select 2 form sublist of selected elements from list + setbit 2-3 set specified bit in string + sgn 1 sign of value (-1, 0, 1) + sha 0+ old Secure Hash Algorithm (SHS FIPS Pub 180) + sha1 0+ Secure Hash Algorithm (SHS-1 FIPS Pub 180-1) + sin 1-2 sine of value a within accuracy b + sinh 1-2 hyperbolic sine of a within accuracy b + size 1 total number of elements in value + sizeof 1 number of octets used to hold the value + sleep 0-1 suspend operation for a seconds + sort 1 sort a copy of a matrix or list + sqrt 1-3 square root of value a within accuracy b + srand 0-1 seed the rand() function + srandom 0-4 seed the random() function + ssq 1+ sum of squares of values + stoponerror 0-1 assign value to stoponerror flag + str 1 simple value converted to string + strcat 1+ concatenate strings together + strcmp 2 compare two null-terminated strings + strcpy 2 copy null-terminated string to string + strerror 0-1 string describing error type + strlen 1 length of string + strncmp 3 compare strings a, b to c characters + strncpy 3 copy up to c characters from string to string + strpos 2 index of first occurrence of b in a + strprintf 1+ return formatted output as a string + strscan 2+ scan a string for assignments to one or more variables + strscanf 2+ formatted scan of string for assignments to variables + substr 3 substring of a from position b for c chars + sum 0+ sum of list or object sums and/or other terms + swap 2 swap values of variables a and b (can be dangerous) + system 1 call Unix command + tail 2 retain list of specified number at tail of list + tan 1-2 tangent of a within accuracy b + tanh 1-2 hyperbolic tangent of a within accuracy b + test 1 test that value is nonzero + time 0 number of seconds since 00:00:00 1 Jan 1970 UTC + trunc 1-2 truncate a to b number of decimal places + ungetc 2 unget char read from file + version 0 calc version string + xor 1+ logical xor + + + The config function sets or reads the value of a configuration + parameter. The first argument is a string which names the parameter + to be set or read. If only one argument is given, then the current + value of the named parameter is returned. If two arguments are given, + then the named parameter is set to the value of the second argument, + and the old value of the parameter is returned. Therefore you can + change a parameter and restore its old value later. The possible + parameters are explained in the next section. + + The scale function multiplies or divides a number by a power of 2. + This is used for fractional calculations, unlike the << and >> + operators, which are only defined for integers. For example, + scale(6, -3) is 3/4. + + The quomod function is used to obtain both the quotient and remainder + of a division in one operation. The first two arguments a and b are + the numbers to be divided. The last two arguments c and d are two + variables which will be assigned the quotient and remainder. For + nonnegative arguments, the results are equivalent to computing a//b + and a%b. If a is negative and the remainder is nonzero, then the + quotient will be one less than a//b. This makes the following three + properties always hold: The quotient c is always an integer. The + remainder d is always 0 <= d < b. The equation a = b * c + d always + holds. This function returns 0 if there is no remainder, and 1 if + there is a remainder. For examples, quomod(10, 3, x, y) sets x to 3, + y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x + to -2, y to 2.28318, and returns the value 1. + + The eval function accepts a string argument and evaluates the + expression represented by the string and returns its value. + The expression can include function calls and variable references. + For example, eval("fact(3) + 7") returns 13. When combined with + the prompt function, this allows the calculator to read values from + the user. For example, x=eval(prompt("Number: ")) sets x to the + value input by the user. + + The digit and bit functions return individual digits of a number, + either in base 10 or in base 2, where the lowest digit of a number + is at digit position 0. For example, digit(5678, 3) is 5, and + bit(0b1000100, 2) is 1. Negative digit positions indicate places + to the right of the decimal or binary point, so that for example, + digit(3.456, -1) is 4. + + The ptest builtin is a primality testing function. The + 1st argument is the suspected prime to be tested. The + absolute value of the 2nd argument is an iteration count. + + If ptest is called with only 2 args, the 3rd argument is + assumed to be 0. If ptest is called with only 1 arg, the + 2nd argument is assumed to be 1. Thus, the following + calls are equivalent: + + ptest(a) + ptest(a,1) + ptest(a,1,0) + + Normally ptest performs a some checks to determine if the + value is divisable by some trivial prime. If the 2nd + argument is < 0, then the trivial check is omitted. + + For example, ptest(a,10) performs the same work as: + + ptest(a,-3) (7 tests without trivial check) + ptest(a,-7,3) (3 more tests without the trivial check) + + The ptest function returns 0 if the number is definitely not + prime, and 1 is the number is probably prime. The chance + of a number which is probably prime being actually composite + is less than 1/4 raised to the power of the iteration count. + For example, for a random number p, ptest(p, 10) incorrectly + returns 1 less than once in every million numbers, and you + will probably never find a number where ptest(p, 20) gives + the wrong answer. + + The first 3 args of nextcand and prevcand functions are the same + arguments as ptest. But unlike ptest, nextcand and prevcand return + the next and previous values for which ptest is true. + + For example, nextcand(2^1000) returns 2^1000+297 because + 2^1000+297 is the smallest value x > 2^1000 for which + ptest(x,1) is true. And for example, prevcand(2^31-1,10,5) + returns 2147483629 (2^31-19) because 2^31-19 is the largest + value y < 2^31-1 for which ptest(y,10,5) is true. + + The nextcand and prevcand functions also have a 5 argument form: + + nextcand(num, count, skip, modval, modulus) + prevcand(num, count, skip, modval, modulus) + + return the smallest (or largest) value ans > num (or < num) that + is also == modval % modulus for which ptest(ans,count,skip) is true. + + The builtins nextprime(x) and prevprime(x) return the + next and previous primes with respect to x respectively. + As of this release, x must be < 2^32. With one argument, they + will return an error if x is out of range. With two arguments, + they will not generate an error but instead will return y. + + The builtin function pix(x) returns the number of primes <= x. + As of this release, x must be < 2^32. With one argument, pix(x) + will return an error if x is out of range. With two arguments, + pix(x,y) will not generate an error but instead will return y. + + The builtin function factor may be used to search for the + smallest factor of a given number. The call factor(x,y) + will attempt to find the smallest factor of x < min(x,y). + As of this release, y must be < 2^32. If y is omitted, y + is assumed to be 2^32-1. + + If x < 0, factor(x,y) will return -1. If no factor < + min(x,y) is found, factor(x,y) will return 1. In all other + cases, factor(x,y) will return the smallest prime factor + of x. Note except for the case when abs(x) == 1, factor(x,y) + will not return x. + + If factor is called with y that is too large, or if x or y + is not an integer, calc will report an error. If a 3rd argument + is given, factor will return that value instead. For example, + factor(1/2,b,c) will return c instead of issuing an error. + + The builtin lfactor(x,y) searches a number of primes instead + of below a limit. As of this release, y must be <= 203280221 + (y <= pix(2^32-1)). In all other cases, lfactor is operates + in the same way as factor. + + If lfactor is called with y that is too large, or if x or y + is not an integer, calc will report an error. If a 3rd argument + is given, lfactor will return that value instead. For example, + lfactor(1/2,b,c) will return c instead of issuing an error. + + The lfactor function is slower than factor. If possible factor + should be used instead of lfactor. + + The builtin isprime(x) will attempt to determine if x is prime. + As of this release, x must be < 2^32. With one argument, isprime(x) + will return an error if x is out of range. With two arguments, + isprime(x,y) will not generate an error but instead will return y. + + The functions rcin, rcmul, rcout, rcpow, and rcsq are used to + perform modular arithmetic calculations for large odd numbers + faster than the usual methods. To do this, you first use the + rcin function to convert all input values into numbers which are + in a format called REDC format. Then you use rcmul, rcsq, and + rcpow to multiply such numbers together to produce results also + in REDC format. Finally, you use rcout to convert a number in + REDC format back to a normal number. The addition, subtraction, + negation, and equality comparison between REDC numbers are done + using the normal modular methods. For example, to calculate the + value 13 * 17 + 1 (mod 11), you could use: + + p = 11; + t1 = rcin(13, p); + t2 = rcin(17, p); + t3 = rcin(1, p); + t4 = rcmul(t1, t2, p); + t5 = (t4 + t3) % p; + answer = rcout(t5, p); + + The swap function exchanges the values of two variables without + performing copies. For example, after: + + x = 17; + y = 19; + swap(x, y); + + then x is 19 and y is 17. This function should not be used to + swap a value which is contained within another one. If this is + done, then some memory will be lost. For example, the following + should not be done: + + mat x[5]; + swap(x, x[0]); + + The hash function returns a relatively small non-negative integer + for one or more input values. The hash values should not be used + across runs of the calculator, since the algorithms used to generate + the hash value may change with different versions of the calculator. + + The base function allows one to specify how numbers should be + printer. The base function provides a numeric shorthand to the + config("mode") interface. With no args, base() will return the + current mode. With 1 arg, base(val) will set the mode according to + the arg and return the previous mode. + + The following convention is used to declare modes: + + base config + value string + + 2 "binary" binary fractions + 8 "octal" octal fractions + 10 "real" decimal floating point + 16 "hex" hexadecimal fractions + -10 "int" decimal integer + 1/3 "frac" decimal fractions + 1e20 "exp" decimal exponential + + For convenience, any non-integer value is assumed to mean "frac", + and any integer >= 2^64 is assumed to mean "exp". + diff --git a/help/COMMAND b/help/COMMAND new file mode 100644 index 0000000..b3e8b30 --- /dev/null +++ b/help/COMMAND @@ -0,0 +1,309 @@ +Command sequence + + This is a sequence of any the following command formats, where + each command is terminated by a semicolon or newline. Long command + lines can be extended by using a back-slash followed by a newline + character. When this is done, the prompt shows a double angle + bracket to indicate that the line is still in progress. Certain + cases will automatically prompt for more input in a similar manner, + even without the back-slash. The most common case for this is when + a function is being defined, but is not yet completed. + + Each command sequence terminates only on an end of file. In + addition, commands can consist of expression sequences, which are + described in the next section. + + + define a function + ----------------- + define function(params) { body } + define function(params) = expression + This first form defines a full function which can consist + of declarations followed by many statements which implement + the function. + + The second form defines a simple function which calculates + the specified expression value from the specified parameters. + The expression cannot be a statement. However, the comma + and question mark operators can be useful. Examples of + simple functions are: + + define sumcubes(a, b) = a^3 + b^3 + define pimod(a) = a % pi() + define printnum(a, n, p) + { + if (p == 0) { + print a: "^": n, "=", a^n; + } else { + print a: "^": n, "mod", p, "=", pmod(a,n,p); + } + } + + + read calc commands + ------------------ + read filename + read -once filename + This reads definitions from the specified calc resource filename. + + The name can be quoted if desired. The calculator uses the + CALCPATH environment variable to search through the specified + directories for the filename, similarly to the use of the + PATH environment variable. If CALCPATH is not defined, + then a default path which is usually ":/usr/local/lib/calc" + is used. + + The ".cal" extension is defaulted for input files, so that + if "filename" is not found, then "filename.cal" is then + searched for. The contents of the filename are command + sequences which can consist of expressions to evaluate or + functions to define, just like at the top level command level. + + When -once is given, the read command acts like the regular + read expect that it will ignore filename if is has been + previously read. + + The read -once form is particularly useful in a resource + file that needs to read a 2nd resource file. By using the + READ -once command, one will not reread that 2nd resource + file, nor will once risk entering into a infinite READ loop + (where that 2nd resource file directly or indirectly does + a READ of the first resource file). + + If the -m mode disallows opening of files for reading, + this command will be disabled. + + + write calc commands + ------------------- + write filename + This writes the values of all global variables to the + specified filename, in such a way that the file can be + later read in order to recreate the variable values. + For speed reasons, values are written as hex fractions. + This command currently only saves simple types, so that + matrices, lists, and objects are not saved. Function + definitions are also not saved. + + If the -m mode disallows opening of files for writing, + this command will be disabled. + + + quit or exit + ------------ + quit + quit string + exit + exit string + The action of these commands depends on where they are used. + At the interactive level, they will cause calc it edit. + This is the normal way to leave the calculator. In any + other use, they will stop the current calculation as if + an error had occurred. + + If a string is given, then the string is printed as the reason + for quitting, otherwise a general quit message is printed. + The routine name and line number which executed the quit is + also printed in either case. + + Exit is an alias for quit. + + Quit is useful when a routine detects invalid arguments, + in order to stop a calculation cleanly. For example, + for a square root routine, an error can be given if the + supplied parameter was a negative number, as in: + + define mysqrt(n) + { + if (! isnum(n)) + quit "non-numeric argument"; + if (n < 0) + quit "Negative argument"; + return sqrt(n); + } + + See 'more information about abort and quit' below for + more information. + + + + abort + ----- + abort + abort string + This command behaves like QUIT except that it will attempt + to return to the interactive level if permitted, otherwise + calc exit. + + See 'more information about abort and quit' below for + more information. + + + change current directory + ------------------------ + cd + cd dir + Change the current directory to 'dir'. If 'dir' is ommitted, + change the current directory to the home directory, if $HOME + is set in the environment. + + + show information + ---------------- + show item + This command displays some information where 'item' is + one of the following: + + blocks unfreed named blocks + builtin built in functions + config config parameters and values + constants cache of numeric constants + custom custom functions if calc -C was used + errors new error-values created + files open files, file position and sizes + function user-defined functions + globaltypes global variables + objfunctions possible object functions + objtypes defined objects + opcodes func internal opcodes for function `func' + sizes size in octets of calc value types + realglobals numeric global variables + statics unscoped static variables + numbers calc number cache + redcdata REDC data defined + strings calc string cache + literals calc literal cache + + Only the first 4 characters of item are examined, so: + + show globals + show global + show glob + + do the same thing. + + + calc help + --------- + help + help name + This displays a help related to 'name' or general + help of none is given. + + + =-= + + + more information about abort and quit + ===================================== + + Consider the following calc file called myfile.cal: + + print "start of myfile.cal"; + define q() {quit "quit from q()"; print "end of q()"} + define a() {abort "abort from a()"} + x = 3; + {print "start #1"; if (x > 1) q()} print "after #1"; + {print "start #2"; if (x > 1) a()} print "after #2"; + {print "start #3"; if (x > 1) quit "quit from 3rd statement"} + print "end of myfile.cal"; + + The command: + + calc read myfile + + will produce: + + q() defined + a() defined + start statment #1 + quit from q() + after statment #1 + start statment #2 + abort from a() + + The QUIT within the q() function prevented the ``end of q()'' + statement from being evaluated. This QUIT command caused + control to be returned to just after the place where q() + was called. + + Notice that unlike QUIT, the ABORT inside function a() halts + the processing of statements from the input source (myfile.cal). + Because calc was not interactive, ABORT causes calc to exit. + + The command: + + calc -i read myfile + + will produce: + + q() defined + a() defined + start statment #1 + quit from q() + after statment #1 + start statment #2 + abort from a() + > <==== calc interactive prompt + + because the '-i' calc causes ABORT to drop into an + interactive prompt. However typing a QUIT or ABORT + at the interactive prompt level will always calc to exit, + even when calc is invoked with '-i'. + + Also observe that both of these commands: + + cat myfile.cal | calc + cat myfile.cal | calc -i + + will produce: + + q() defined + a() defined + start statment #1 + quit from q() + after statment #1 + start statment #2 + abort from a() + + The ABORT inside function a() halts the processing of statements + from the input source (standard input). Because standard input + is not a terminal, using '-i' does not force it to drop into + an interactive prompt. + + If one were to type in the contents of myfile.cal interactively, + calc will produce: + + > print "start of myfile.cal"; + start of myfile.cal + > define q() {quit "quit from q()"; print "end of q()"} + q() defined + > define a() {abort "abort from a()"} + a() defined + > x = 3; + > {print "start #1"; if (x > 1) q()} print "after #1"; + start statment #1 + quit from q() + after statment #1 + > {print "start #2"; if (x > 1) a()} print "after #2"; + start statment #2 + abort from a() + > {print "start #3"; if (x > 1) quit "quit from 3rd statement"} + start #3 + quit from 3rd statement + + The ABORT from within the a() function returned control to + the interactive level. + + The QUIT (after the if (x > 1) ...) will cause calc to exit + because it was given at the interactive prompt level. + + + =-= + + + Also see the help topic: + + statement flow control and declaration statements + usage how to invoke the calc command and calc -options + diff --git a/help/CONFIG b/help/CONFIG new file mode 100644 index 0000000..2ea8bce --- /dev/null +++ b/help/CONFIG @@ -0,0 +1,757 @@ +Configuration parameters + + Configuration parameters affect how the calculator performs certain + operations. Among features that are controlled by these parameters + are the accuracy of some calculations, the displayed format of results, + the choice from possible alternative algorithms, and whether or not + debugging information is displayed. The parameters are + read or set using the "config" built-in function; they remain in effect + until their values are changed by a config or equivalent instruction. + The following parameters can be specified: + + "all" all configuration values listed below + + "trace" turns tracing features on or off + "display" sets number of digits in prints. + "epsilon" sets error value for transcendentals. + "maxprint" sets maximum number of elements printed. + "mode" sets printout mode. + "mode2" sets 2nd base printout mode. + "mul2" sets size for alternative multiply. + "sq2" sets size for alternative squaring. + "pow2" sets size for alternate powering. + "redc2" sets size for alternate REDC. + "tilde" enable/disable printing of the roundoff '~' + "tab" enable/disable printing of leading tabs + "quomod" sets rounding mode for quomod + "quo" sets rounding mode for //, default for quo + "mod" sets "rounding" mode for %, default for mod + "sqrt" sets rounding mode for sqrt + "appr" sets rounding mode for appr + "cfappr" sets rounding mode for cfappr + "cfsim" sets rounding mode for cfsim + "round" sets rounding mode for round and bround + "outround" sets rounding mode for printing of numbers + "leadzero" enables/disables printing of 0 as in 0.5 + "fullzero" enables/disables padding zeros as in .5000 + "maxscan" maximum number of scan errors before abort + "prompt" default interactive prompt + "more" default interactive multi-line input prompt + "blkmaxprint" number of block octets to print, 0 means all + "blkverbose" TRUE=>print all lines, FALSE=>skip duplicates + "blkbase" block output base + "blkfmt" block output format + "calc_debug" controls internal calc debug information + "resource_debug" controls resource file debug information + "user_debug" for user defined debug information + "verbose_quit" TRUE=>print message on empty quit or abort + "ctrl_d" The interactive meaning of ^D (Control D) + "program" Read-only calc program or shell script path + "basename" Read-only basename of the program value + "windows" Read-only indicator of MS windows + "cygwin" TRUE=>calc compiled with cygwin, Read-only + "compile_custom" TRUE=>calc was compiled with custom functions + "allow_custom" TRUE=>custom functions are enabled + "version" Read-only calc version + + The "all" config value allows one to save/restore the configuration + set of values. The return of: + + config("all") + + is a CONFIG type which may be used as the 2rd arg in a later call. + One may save, modify and restore the configuration state as follows: + + oldstate = config("all") + ... + config("tab", 0) + config("mod", 10) + ... + config("all", oldstate) + + This save/restore method is useful within functions. + It allows functions to control their configuration without impacting + the calling function. + + There are two configuration state aliases that may be set. To + set the backward compatible standard configuration: + + config("all", "oldstd") + + The "oldstd" will restore the configuration to the default at startup. + + A new configuration that some people prefer may be set by: + + config("all", "newstd") + + The "newstd" is not backward compatible with the historic + configuration. Even so, some people prefer this configuration + and place the config("all", "newstd") command in their CALCRC + startup files; newstd may also be established by invoking calc + with the flag -n. + + The following are synonyms for true: + + "on" + "true" + "t" + "yes" + "y" + "set" + "1" + any non-zero number + + The following are synonyms for false: + + "off" + "false" + "f" + "no" + "n" + "unset" + "0" + the number zero (0) + + Examples of setting some parameters are: + + config("mode", "exp"); exponential output + config("display", 50); 50 digits of output + epsilon(epsilon() / 8); 3 bits more accuracy + config("tilde", 0) disable roundoff tilde printing + config("tab", "off") disable leading tab printing + + +Detailed config descriptions + + =-= + + config("trace", bitflag) + + When nonzero, the "trace" parameter activates one or more features + that may be useful for debugging. These features correspond to + powers of 2 which contribute additively to config("trace"): + + 1: opcodes are displayed as functions are evaluated + + 2: disables the inclusion of debug lines in opcodes for functions + whose definitions are introduced with a left-brace. + + 4: the number of links for real and complex numbers are displayed + when the numbers are printed; for real numbers "#" or for + complex numbers " printed immediately after the number. + + 8: the opcodes for a new functions are displayed when the function + is successfully defined. + + See also resource_debug, calc_debug and user_debug below for more + debug levels. + + =-= + + config("display", int) + + The "display" parameter specifies the maximum number of digits after + the decimal point to be printed in real or exponential mode in + normal unformatted printing (print, strprint, fprint) or in + formatted printing (printf, strprintf, fprintf) when precision is not + specified. The initial value for oldstd is 20, for newstd 10. + The parameter may be changed to the value d by either + config("display", d) or by display (d). This parameter does not change + the stored value of a number. Where rounding is necessary to + display up to d decimal places, the type of rounding to be used is + controlled by config("outround"). + + =-= + + config("epsilon", real) + epsilon(real) + + The "epsilon" parameter specifies the default accuracy for the + calculation of functions for which exact values are not possible or + not desired. For most functions, the + + remainder = exact value - calculated value + + has absolute value less than epsilon, but, except when the sign of + the remainder is controlled by an appropriate parameter, the + absolute value of the remainder usually does not exceed epsilon/2. + Functions which require an epsilon value accept an + optional argument which overrides this default epsilon value for + that single call. The value v can be assigned to the "epsilon" + parameter by either config("epsilon", v) or epsilon(v); each of + these functions return the current epsilon value; config("epsilon") + or epsilon() returns but does not change the epsilon value. + For the transcendental functions and the functions sqrt() and + appr(), the calculated value is always a multiple of epsilon. + + =-= + + config("mode", "mode_string") + config("mode2", "mode_string") + + The "mode" parameter is a string specifying the mode for printing of + numbers by the unformatted print functions, and the default + ("%d" specifier) for formatted print functions. The initial mode + is "real". The available modes are: + + config("mode") meaning equivalent + string base() call + + "binary" base 2 fractions base(2) + "bin" + + "octal" base 8 fractions base(8) + "oct" + + "real" base 10 floating point base(10) + "float" + "default" + + "integer" base 10 integer base(-10) + "int" + + "hexadecimal" base 16 fractions base(16) + "hex" + + "fraction" base 10 fractions base(1/3) + "frac" + + "scientific" base 10 scientific notation base(1e20) + "sci" + "exp" + + Where multiple strings are given, the first string listed is what + config("mode") will return. + + The "mode2" controls the double base output. When set to a value + other than "off", calc outputs files in both the "base" mode as + well as the "base2" mode. The "mode2" value may be any of the + "mode" values with the addition of: + + "off" disable 2nd base output mode base2(0) + + The base() builtin function sets and returns the "mode" value. + The base2() builtin function sets and returns the "mode2" value. + + The default "mode" is "real". The default "mode2" is "off". + + =-= + + config("maxprint", int) + + The "maxprint" parameter specifies the maximum number of elements to + be displayed when a matrix or list is printed. The initial value is 16. + + =-= + + config("mul2", int) + config("sq2", int) + + Mul2 and sq2 specify the sizes of numbers at which calc switches + from its first to its second algorithm for multiplying and squaring. + The first algorithm is the usual method of cross multiplying, which + runs in a time of O(N^2). The second method is a recursive and + complicated method which runs in a time of O(N^1.585). The argument + for these parameters is the number of binary words at which the + second algorithm begins to be used. The minimum value is 2, and + the maximum value is very large. If 2 is used, then the recursive + algorithm is used all the way down to single digits, which becomes + slow since the recursion overhead is high. If a number such as + 1000000 is used, then the recursive algorithm is never used, causing + calculations for large numbers to slow down. For a typical example + on a 386, the two algorithms are about equal in speed for a value + of 20, which is about 100 decimal digits. A value of zero resets + the parameter back to its default value. Usually there is no need + to change these parameters. + + =-= + + config("pow2", int) + + Pow2 specifies the sizes of numbers at which calc switches from + its first to its second algorithm for calculating powers modulo + another number. The first algorithm for calculating modular powers + is by repeated squaring and multiplying and dividing by the modulus. + The second method uses the REDC algorithm given by Peter Montgomery + which avoids divisions. The argument for pow2 is the size of the + modulus at which the second algorithm begins to be used. + + =-= + + config("redc2", int) + + Redc2 specifies the sizes of numbers at which calc switches from + its first to its second algorithm when using the REDC algorithm. + The first algorithm performs a multiply and a modular reduction + together in one loop which runs in O(N^2). The second algorithm + does the REDC calculation using three multiplies, and runs in + O(N^1.585). The argument for redc2 is the size of the modulus at + which the second algorithm begins to be used. + + =-= + + config("tilde", boolean) + + Config("tilde") controls whether or not a leading tilde ('~') is + printed to indicate that a number has not been printed exactly + because the number of decimal digits required would exceed the + specified maximum number. The initial "tilde" value is 1. + + =-= + + config("tab", boolean) + + Config ("tab") controls the printing of a tab before results + automatically displayed when working interactively. It does not + affect the printing by the functions print, printf, etc. The initial + "tab" value is 1. + + =-= + + config("quomod", bitflag) + config("quo", bitflag) + config("mod", bitflag) + config("sqrt", bitflag) + config("appr", bitflag) + config("cfappr", bitflag) + config("cfsim", bitflag) + config("outround", bitflag) + config("round", bitflag) + + The "quomod", "quo", "mod", "sqrt", "appr", "cfappr", "cfsim", and + "round" control the way in which any necessary rounding occurs. + Rounding occurs when for some reason, a calculated or displayed + value (the "approximation") has to differ from the "true value", + e.g. for quomod and quo, the quotient is to be an integer, for sqrt + and appr, the approximation is to be a multiple of an explicit or + implicit "epsilon", for round and bround (both controlled by + config("round")) the number of decimal places or fractional bits + in the approximation is limited. Zero value for any of these + parameters indicates that the true value is greater than the approximation, + i.e. the rounding is "down", or in the case of mod, that the + residue has the same sign as the divisor. If bit 4 of the + parameter is set, the rounding of to the nearest acceptable candidate + when this is uniquely determined; in the remaining ambiguous cases, + the type of rounding is determined by the lower bits of the parameter + value. If bit 3 is set, the rounding for quo, appr and sqrt, + is to the nearest even integer or the nearest even multiple of epsilon, + and for round to the nearest even "last decimal place". The effects + of the 3 lowest bits of the parameter value are as follows: + + Bit 0: Unconditional reversal (down to up, even to odd, etc.) + Bit 1: Reversal if the exact value is negative + Bit 2: Reversal if the divisor or epsilon is negative + + (Bit 2 is irrelevant for the functions round and bround since the + equivalent epsilon (a power of 1/10 or 1/2) is always positive.) + + For quomod, the quotient is rounded to an integer value as if + evaluating quo with config("quo") == config("quomod"). Similarly, + quomod and mod give the same residues if config("mod") == config("quomod"). + + For the sqrt function, if bit 5 of config("sqrt") is set, the exact + square-root is returned when this is possible; otherwise the + result is rounded to a multiple of epsilon as determined by the + five lower order bits. Bit 6 of config("sqrt") controls whether the + principal or non-principal square-root is returned. + + For the functions cfappr and cfsim, whether the "rounding" is down + or up, etc. is controlled by the appropriate bits of config("cfappr") + and config("cfsim") as for quomod, quo, etc. + + The "outround" parameter determines the type of rounding to be used + by the various kinds of printing to the output: bits 0, 1, 3 and 4 + are used in the same way as for the functions round and bround. + + =-= + + config("leadzero", bool) + + The "leadzero" parameter controls whether or not a 0 is printed + before the decimal point in non-zero fractions with absolute value + less than 1, e.g. whether 1/2 is printed as 0.5 or .5. The + initial value is 0, corresponding to the printing .5. + + =-= + + config("fullzero", bool) + + The "fullzero" parameter controls whether or not in decimal floating- + point printing, the digits are padded with zeros to reach the + number of digits specified by config("display") or by a precision + specification in formatted printing. The initial value for this + parameter is 0, so that, for example, if config("display") >= 2, + 5/4 will print in "real" mode as 1.25. + + =-= + + config("maxscan", int) + + The maxscan value controls how many scan errors are allowed + before the compiling phase of a computation is aborted. The initial + value of "maxscan" is 20. Setting maxscan to 0 disables this feature. + + =-= + + config("prompt", str) + + The default prompt when in interactive mode is "> ". One may change + this prompt to a more cut-and-paste friendly prompt by: + + config("prompt", "; ") + + On windowing systems that support cut/paste of a line, one may + cut/copy an input line and paste it directly into input. The + leading ';' will be ignored. + + =-= + + config("more", str) + + When inside multi-line input, the more prompt is used. One may + change it by: + + config("more", ";; ") + + =-= + + config("blkmaxprint", int) + + The "blkmaxprint" config value limits the number of octets to print + for a block. A "blkmaxprint" of 0 means to print all octets of a + block, regardless of size. + + The default is to print only the first 256 octets. + + =-= + + config("blkverbose", bool) + + The "blkverbose" determines if all lines, including duplicates + should be printed. If TRUE, then all lines are printed. If false, + duplicate lines are skipped and only a "*" is printed in a style + similar to od. This config value has not meaning if "blkfmt" is "str". + + The default value for "blkverbose" is FALSE: duplicate lines are + not printed. + + =-= + + config("blkbase", "blkbase_string") + + The "blkbase" determines the base in which octets of a block + are printed. Possible values are: + + "hexadecimal" Octets printed in 2 digit hex + "hex" + "default" + + "octal" Octets printed in 3 digit octal + "oct" + + "character" Octets printed as chars with non-printing + "char" chars as \123 or \n, \t, \r + + "binary" Octets printed as 0 or 1 chars + "bin" + + "raw" Octets printed as is, i.e. raw binary + "none" + + Where multiple strings are given, the first string listed is what + config("blkbase") will return. + + The default "blkbase" is "hexadecimal". + + =-= + + config("blkfmt", "blkfmt_string") + + The "blkfmt" determines for format of how block are printed: + + "lines" print in lines of up to 79 chars + newline + "line" + + "strings" print as one long string + "string" + "str" + + "od_style" print in od-like format, with leading offset, + "odstyle" followed by octets in the given base + "od" + + "hd_style" print in hex dump format, with leading offset, + "hdstyle" followed by octets in the given base, followed + "hd" by chars or '.' if no-printable or blank + "default" + + Where multiple strings are given, the first string listed is what + config("blkfmt") will return. + + The default "blkfmt" is "hd_style". + + =-= + + config("calc_debug", bitflag) + + The "calc_debug" is intended for controlling internal calc routines + that test its operation, or collect or display information that + might be useful for debug purposes. Much of the output from these + will make sense only to calc wizards. Zero value (the default for + both oldstd and newstd) of config("resource_debug") corresponds to + switching off all these routines. For nonzero value, particular + bits currently have the following meanings: + + n Meaning of bit n of config("calc_debug") + + 0 outputs shell commands prior to execution + + 1 outputs currently active functions when a quit instruction + is executed + + 2 some details of shs, shs1 and md5 hash states are included + in the output when these are printed + + 3 when a function constructs a block value, tests are + made that the result has the properties required for use of + that block, e.g. that the pointer to the start of the + block is not NULL, and that its "length" is not negative. + A failure will result in a runtime error. + + 4 Report on changes to the state of stdin as well as changes + to internal variables that control the setting and restoring + of stdin. + + 5 Report on changes to the run state of calc. + + 6 Report on rand() subtractive 100 shuffle generator issues. + + Bits >= 7 are reserved for future use and should not be used at this time. + + By default, "calc_debug" is 0. The initial value may be overridden + by the -D command line option. + + =-= + + config("resource_debug", bitflag) + config("lib_debug", bitflag) + + The "resource_debug" parameter is intended for controlling the possible + display of special information relating to functions, objects, and + other structures created by instructions in calc scripts. + Zero value of config("resource_debug") means that no such information + is displayed. For other values, the non-zero bits which currently + have meanings are as follows: + + n Meaning of bit n of config("resource_debug") + + 0 When a function is defined, redefined or undefined at + interactive level, a message saying what has been done + is displayed. + + 1 When a function is defined, redefined or undefined during + the reading of a file, a message saying what has been done + is displayed. + + 2 Show func will display more information about a functions + arguments and argument summary information. + + 3 During execution, allow calc standard resource files + to output additional debugging information. + + The value for config("resource_debug") in both oldstd and newstd is 3, + but if calc is invoked with the -d flag, its initial value is zero. + Thus, if calc is started without the -d flag, until config("resource_debug") + is changed, a message will be output when a function is defined + either interactively or during the reading of a file. + + The name config("lib_debug") is equivalent to config("resource_debug") + and is included for backward compatibility. + + By default, "resource_debug" is 3. The -d flag changes this default to 0. + The initial value may be overridden by the -D command line option. + + =-= + + config("user_debug", int) + + The "user_debug" is provided for use by users. Calc ignores this value + other than to set it to 0 by default (for both "oldstd" and "newstd"). + No calc code or standard resource should change this value. Users + should feel free to use it in any way. In particular they may + use particular bits for special purposes as with "calc_debug", or + they may use it to indicate a debug level with larger values + indicating more stringent and more informative tests with presumably + slower operation or more memory usage, and a particular value (like + -1 or 0) corresponding to "no tests". + + By default, "user_debug" is 0. The initial value may be overridden + by the -D command line option. + + =-= + + config("verbose_quit", bool) + + The "verbose_quit" controls the print of the message: + + quit or abort executed + + when a non-interactive quit or abort without an argument is encountered. + A quit of abort without an argument does not display a message when + invoked at the interactive level. + + By deafult, "verbose_quit" is false. + + =-= + + config("ctrl_d", "ctrl_d_string") + + For calc that is using the calc binding (not GNU-readline) facility: + + The "ctrl_d" controls the interactive meaning of ^D (Control D): + + "virgin_eof" If ^D is the only character that has been typed + "virgineof" on a line, then calc will exit. Otherwise ^D + "virgin" will act according to the calc binding, which + "default" by default is a Emacs-style delete-char. + + "never_eof" The ^D never exits calc and only acts according + "nevereof" calc binding, which by default is a Emacs-style + "never" delete-char. + + "empty_eof" The ^D always exits calc if typed on an empty line. + "emptyeof" This condition occurs when ^D either the first + "empty" character typed, or when all other characters on + the line have been removed (say by deleting them). + + Where multiple strings are given, the first string listed is what + config("ctrl_d") will return. + + Note that config("ctrl_d") actually controls each and every character + that is bound to ``delete_char''. By default, ``delete_char'' is + Control D. Any character(s) bound to ``delete_char'' will cause calc + to exit (or not exit) as directed by config("ctrl_d"). + + See the ``binding'' help for information on the default calc bindings. + + The default "ctrl_d", without GNU-readline is "virgin_eof". + + For calc that was compiled with the GNU-readline facility: + + The "ctrl_d" controls the interactive meaning of ^D (Control D): + + "virgin_eof" Same as "empty_eof" + "virgineof" + "virgin" + "default" + + "never_eof" The ^D never exits calc and only acts according + "nevereof" calc binding, which by default is a Emacs-style + "never" delete-char. + + "empty_eof" The ^D always exits calc if typed on an empty line. + "emptyeof" This condition occurs when ^D either the first + "empty" character typed, or when all other characters on + + Where multiple strings are given, the first string listed is what + config("ctrl_d") will return. + + The default "ctrl_d", with GNU-readline is effectively "empty_eof". + + Literally it is "virgin_eof", but since "virgin_eof" is the + same as "empty_eof", the default is effectively "empty_eof". + + Emacs users may find the default behavior objectionable, particularly + when using the GNU-readline facility. Such users may want to add the line: + + config("ctrl_d", "never_eof"),; + + to their ~/.calcrc startup file to prevent ^D from causing calc to exit. + + =-= + + config("program") <== NOTE: This is a read-only config value + + The full path to the calc program, or the calc shell script can be + obtained by: + + config("program") + + This config parameter is read-only and cannot be set. + + =-= + + config("basename") <== NOTE: This is a read-only config value + + The calc program, or the calc shell script basename can be obtained by: + + config("basename") + + The config("basename") is the config("program") without any leading + path. If config("program") has a / in it, config("basename") is + everything after the last /, otherwise config("basename") is the + same as config("program"). + + This config parameter is read-only and cannot be set. + + =-= + + config("windows") <== NOTE: This is a read-only config value + + Returns TRUE if you are running on a MS windows system, false if you + are running on an operating system that does not hate you. + + This config parameter is read-only and cannot be set. + + =-= + + config("cygwin") <== NOTE: This is a read-only config value + + Returns TRUE if you calc was compiled with cygwin, false otherwise. + + This config parameter is read-only and cannot be set. + + =-= + + config("compile_custom") <== NOTE: This is a read-only config value + + Returns TRUE if you calc was compiled with -DCUSTOM. By default, + the calc Makefile uses ALLOW_CUSTOM= -DCUSTOM so by default + config("compile_custom") is TRUE. If, however, calc is compiled + without -DCUSTOM, then config("compile_custom") will be FALSE. + + The config("compile_custom") value is only affected by compile + flags. The calc -D runtime command line option does not change + the config("compile_custom") value. + + See also config("allow_custom"). + + This config parameter is read-only and cannot be set. + + =-= + + config("allow_custom") <== NOTE: This is a read-only config value + + Returns TRUE if you custom functions are enabled. To allow the use + of custom functions, calc must be compiled with -DCUSTOM (which it + is by default) AND calc run be run with the -D runtime command line + option (which it is not by default). + + If config("allow_custom") is TRUE, then custom functions are allowed. + If config("allow_custom") is FALSE, then custom functions are not + allowed. + + See also config("compile_custom"). + + This config parameter is read-only and cannot be set. + + =-= + + config("version") <== NOTE: This is a read-only config value + + The version string of the calc program can be obtained by: + + config("version") + + This config parameter is read-only and cannot be set. + diff --git a/help/COPYING b/help/COPYING new file mode 100644 index 0000000..349a60e --- /dev/null +++ b/help/COPYING @@ -0,0 +1,227 @@ + calc - arbitrary precision calculator + + +This file is Copyrighted +------------------------ + + This file is covered under the following Copyright: + + Copyright (C) 1999 Landon Curt Noll + All rights reserved. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + # @(#) $Revision$ + # @(#) $Id$ + # @(#) $Source$ + +=-= + +Calc is covered by the GNU Lesser General Public License +-------------------------------------------------------- + + Calc is open software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation version 2.1 of the License. + + Calc is several binary link libraries, several modules, associated + interface definition files and scripts used to control its compilation + and installation. + + Calc is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + Public License for more details. + + A copy of the GNU Lesser General Public License is distributed with + calc under the filename: + + COPYING-LGPL + + You may display this file by the calc command: help copying + + You may display the GNU Lesser General + Public License by the calc command: help copying-lgpl + + You should have received a copy of the version 2.1 GNU Lesser General + Public License with calc; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place + Suite 330 + Boston, MA 02111-1307 + USA + + The contact addresses for calc is as follows: + + Web: http://www.isthe.com/chongo/tech/comp/calc/email.html + + To join the low volume calc mailing list. Send a EMail message to: + + calc-tester-request at asthe dot com + + Your subject must contain the words: + + calc mailing list subscription + + You may have additional words in your subject line. + + Your message body (not the subject) should consist of: + + subscribe calc-tester address + end + name your_full_name + + where ``address'' is your EMail address and ``your_full_name'' is + your full name. + + Feel free to follow the name line with additional EMail text as desired. + +=-= + + Calc bug reports and calc bug fixes should be sent to: + + calc-bugs at asthe dot com + + [[ NOTE: Replace 'at' with @, 'dot' is with . and remove the spaces ]] + [[ NOTE: The EMail address uses 'asthe' and the web site URL uses 'isthe' ]] + + Your subject must contain the words: + + calc bug report + + You may have additional words in your subject line. + +=-= + +Calc's relationship to the GNU Lesser General Public License +------------------------------------------------------------ + + In section 0 of the GNU Lesser General Public License, one finds + the following definition: + + The "Library", below, refers to any such software library or + work which has been distributed under these terms. + + Calc is distributed under the terms of the GNU Lesser + General Public License. + + In the same section 0, one also find the following: + + For a library, complete source code means all the source code + for all modules it contains, plus any associated interface + definition files, plus the scripts used to control compilation + and installation of the library. + + There are at least two calc binary link libraries found in calc: + + libcalc.a libcustcalc.a + + Clearly all files that go into the creation of those binary link + libraries are covered under the License. + + The ``scripts used to control compilation and installation of the + of the library'' include: + + * Makefiles + * source files created by the Makefiles + * source code used in the creation of intermediate source files + + All of those files are covered under the License. + + The ``associated interface definition files'' are those files that: + + * show how the calc binary link libraries are used + * test the validity of the binary link libraries + * document routines found in the binary link libraries + * show how one can interactively use the binary link libraries + + Calc provides an extensive set of files that perform the above + functions. + + * files under the sample sub-directory + * files under the help sub-directory + * files under the lib sub-directory + * the main calc.c file + + The ``complete source code'' includes ALL files shipped with calc, + except for the exception files explicitly listed in the ``Calc + copyrights and exception files'' section below. + +=-= + +Calc copyrights and exception files +----------------------------------- + + With the exception of the files listed below, Calc is covered under + the following GNU Lesser General Public License Copyrights: + + Copyright (C) year David I. Bell + Copyright (C) year David I. Bell and Landon Curt Noll + Copyright (C) year David I. Bell and Ernest Bowen + Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen + Copyright (C) year Landon Curt Noll + Copyright (C) year Ernest Bowen and Landon Curt Noll + Copyright (C) year Ernest Bowen + Copyright (C) year Petteri Kettunen and Landon Curt Noll + + These files are not covered under one of the Copyrights listed above: + + shs1.c shs1.h shs.c shs.h + md5.c md5.h COPYING COPYING-LGPL + cal/qtime.cal + + The file COPYING-LGPL, which contains a copy of the version 2.1 + GNU Lesser General Public License, is itself Copyrighted by the + Free Software Foundation, Inc. Please note that the Free Software + Foundation, Inc. does NOT have a copyright over calc, only the + COPYING-LGPL that is supplied with calc. + + This file, COPYING, is distributed under the Copyright found at the + top of this file. It is important to note that you may distribute + verbatim copies of this file but you may not modify this file. + + Some of these exception files are in the public domain. Other + exception files have non-LGPL Copyrights. Other files are under a + LGPL Copyright but have different authors. + + In all cases one may use and distribute these exception files freely. + And because one may freely distribute the LGPL covered files, the + entire calc source may be freely used and distributed. + +=-= + +General Copyleft and License info +--------------------------------- + + For general information on Copylefts, see: + + http://www.gnu.org/copyleft/ + + For information on GNU Lesser General Public Licenses, see: + + http://www.gnu.org/copyleft/lesser.html + http://www.gnu.org/copyleft/lesser.txt + +=-= + +Why calc did not use the GNU General Public License +--------------------------------------------------- + + It has been suggested that one should consider using the GNU General + Public License instead of the GNU Lesser General Public License: + + http://www.gnu.org/philosophy/why-not-lgpl.html + + As you can read in the above URL, there are times where a library + cannot give free software any particular advantage. One of those + times is when there is significantly similar versions available + that are not covered under a Copyleft such as the GNU General Public + License. + + The reason why calc was placed under the GNU Lesser General Public + License is because for many years (1984 thru 1999), calc was offered + without any form of Copyleft. At the time calc was placed under + the GNU Lesser General Public License, a number of systems and + distributions distributed calc without a Copyleft. diff --git a/help/COPYING-LGPL b/help/COPYING-LGPL new file mode 100644 index 0000000..223ede7 --- /dev/null +++ b/help/COPYING-LGPL @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/help/EXPRESSION b/help/EXPRESSION new file mode 100644 index 0000000..20b3082 --- /dev/null +++ b/help/EXPRESSION @@ -0,0 +1,36 @@ +Expression sequences + + This is a sequence of statements, of which expression statements + are the commonest case. Statements are separated with semicolons, + and the newline character generally ends the sequence. If any + statement is an expression by itself, or is associated with an + 'if' statement which is true, then two special things can happen. + If the sequence is executed at the top level of the calculator, + then the value of '.' is set to the value of the last expression. + Also, if an expression is a non-assignment, then the value of the + expression is automatically printed if its value is not NULL. + Some operations such as pre-increment and plus-equals are also + treated as assignments. + + Examples of this are the following: + + expression sets '.' to prints + ---------- ----------- ------ + 3+4 7 7 + 2*4; 8+1; fact(3) 6 8, 9, and 6 + x=3^2 9 - + if (3 < 2) 5; else 6 6 6 + x++ old x - + print fact(4) - 24 + null() null() - + + Variables can be defined at the beginning of an expression sequence. + This is most useful for local variables, as in the following example, + which sums the square roots of the first few numbers: + + local s, i; s = 0; for (i = 0; i < 10; i++) s += sqrt(i); s + + If a return statement is executed in an expression sequence, then + the result of the expression sequence is the returned value. In + this case, '.' is set to the value, but nothing is printed. + diff --git a/help/FILE b/help/FILE new file mode 100644 index 0000000..c7dd36f --- /dev/null +++ b/help/FILE @@ -0,0 +1,168 @@ +Using files + + The calculator provides some functions which allow the program to + read or write text files. These functions use stdio internally, + and the functions appear similar to some of the stdio functions. + Some differences do occur, as will be explained here. + + Names of files are subject to ~ expansion just like the C or + Korn shell. For example, the file name: + + ~/.rc.cal + + refers to the file '.rc.cal' under your home directory. The + file name: + + ~chongo/.rc.cal + + refers to the a file 'rc.cal' under the home directory of 'chongo'. + + A file can be opened for either reading, writing, or appending. + To do this, the 'fopen' function is used, which accepts a filename + and an open mode, both as strings. You use 'r' for reading, 'w' + for writing, and 'a' for appending. For example, to open the file + 'foo' for reading, the following could be used: + + fd = fopen('foo', 'r'); + + If the open is unsuccessful, the numeric value of errno is returned. + If the open is successful, a value of type 'file' will be returned. + You can use the 'isfile' function to test the return value to see + if the open succeeded. You should assign the return value of fopen + to a variable for later use. File values can be copied to more than + one variable, and using any of the variables with the same file value + will produce the same results. + + If you overwrite a variable containing a file value or don't save the + result of an 'fopen', the opened file still remains open. Such 'lost' + files can be recovered by using the 'files' function. This function + either takes no arguments or else takes one integer argument. If no + arguments are given, then 'files' returns the maximum number of opened + files. If an argument is given, then the 'files' function uses it as + an index into an internal table of open files, and returns a value + referring to one the open files. If that entry in the table is not + in use, then the null value is returned instead. Index 0 always + refers to standard input, index 1 always refers to standard output, + and index 2 always refers to standard error. These three files are + already open by the calculator and cannot be closed. As an example + of using 'files', if you wanted to assign a file value which is + equivalent to stdout, you could use: + + stdout = files(1); + + The 'fclose' function is used to close a file which had been opened. + When this is done, the file value associated with the file remains + a file value, but appears 'closed', and cannot be used in further + file-related calls (except fclose) without causing errors. This same + action occurs to all copies of the file value. You do not need to + explicitly close all the copies of a file value. The 'fclose' + function returns the numeric value of errno if there had been an + error using the file, or the null value if there was no error. + + The builtin 'errno' can be use to convert an errno number into + a slightly more meaningful error message: + + badfile = fopen("not_a_file", "r"); + if (!isfile(badfile)) { + print "error #" : badfile : ":", errno(badfile); + } + + File values can be printed. When this is done, the filename of the + opened file is printed inside of quote marks. If the file value had + been closed, then the null string is printed. If a file value is the + result of a top-level expression, then in addition to the filename, + the open mode, file position, and possible EOF, error, and closed + status is also displayed. + + File values can be used inside of 'if' tests. When this is done, + an opened file is TRUE, and a closed file is FALSE. As an example + of this, the following loop will print the names of all the currently + opened non-standard files with their indexes, and then close them: + + for (i = 3; i < files(); i++) { + if (files(i)) { + print i, files(i); + fclose(files(i)); + } + } + + The functions to read from files are 'fgetline' and 'fgetc'. + The 'fgetline' function accepts a file value, and returns the next + input line from a file. The line is returned as a string value, and + does not contain the end of line character. Empty lines return the + null string. When the end of file is reached, fgetline returns the + null value. (Note the distinction between a null string and a null + value.) If the line contained a numeric value, then the 'eval' + function can then be used to convert the string to a numeric value. + Care should be used when doing this, however, since eval will + generate an error if the string doesn't represent a valid expression. + The 'fgetc' function returns the next character from a file as a + single character string. It returns the null value when end of file + is reached. + + The 'printf' and 'fprintf' functions are used to print results to a + file (which could be stdout or stderr). The 'fprintf' function + accepts a file variable, whereas the 'printf' function assumes the + use of 'files(1)' (stdout). They both require a format string, which + is used in almost the same way as in normal C. The differences come + in the interpretation of values to be printed for various formats. + Unlike in C, where an unmatched format type and value will cause + problems, in the calculator nothing bad will happen. This is because + the calculator knows the types of all values, and will handle them + all reasonably. What this means is that you can (for example), always + use %s or %d in your format strings, even if you are printing a non- + string or non-numeric value. For example, the following is valid: + + printf("Two values are %d and %s\n", "fred", 4567); + + and will print "Two values are fred and 4567". + + Using particular format characters, however, is still useful if + you wish to use width or precision arguments in the format, or if + you wish to print numbers in a particular format. The following + is a list of the possible numeric formats: + + %d print in currently defined numeric format + %f print as floating point + %e print as exponential + %r print as decimal fractions + %x print as hex fractions + %o print as octal fractions + %b print as binary fractions + + Note then, that using %d in the format makes the output configurable + by using the 'config' function to change the output mode, whereas + the other formats override the mode and force the output to be in + the specified format. + + Using the precision argument will override the 'config' function + to set the number of decimal places printed. For example: + + printf("The number is %.100f\n", 1/3); + + will print 100 decimal places no matter what the display configuration + value is set to. + + The %s and %c formats are identical, and will print out the string + representation of the value. In these cases, the precision argument + will truncate the output the same way as in standard C. + + If a matrix or list is printed, then the output mode and precision + affects the printing of each individual element. However, field + widths are ignored since these values print using multiple lines. + Field widths are also ignored if an object value prints on multiple + lines. + + The functions 'fputc' and 'fputs' write a character and string to + a file respectively. + + The final file-related functions are 'fflush', 'ferror', and 'feof'. + The 'fflush' function forces buffered output to a file. The 'ferror' + function returns nonzero if an error had occurred to a file. The + 'feof' function returns nonzero if end of file has been reached + while reading a file. + + The 'strprintf' function formats output similarly to 'printf', + but the output is returned as a string value instead of being + printed. + diff --git a/help/OPERATOR b/help/OPERATOR new file mode 100644 index 0000000..dd9cb6b --- /dev/null +++ b/help/OPERATOR @@ -0,0 +1,211 @@ +operators + + The operators are similar to C, but there are some differences in + the associativity and precedence rules for some operators. In + addition, there are several operators not in C, and some C + operators are missing. A more detailed discussion of situations + that may be unexpected for the C programmer may be found in + the 'unexpected' help file. + + Below is a list giving the operators arranged in order of + precedence, from the least tightly binding to the most tightly + binding. Except where otherwise indicated, operators at the same + level of precedence associate from left to right. + + Unlike C, calc has a definite order for evaluation of terms (addends + in a sum, factors in a product, arguments for a function or a + matrix, etc.). This order is always from left to right. but + skipping of terms may occur for ||, && and ? : . For example, + an expression of the form: + + A * B + C * D + + is evaluated in the following order: + + A + B + A * B + C + D + C * D + A * B + C * D + + This order of evaluation is significant if evaluation of a + term changes a variable on which a later term depends. For example: + + x++ * x++ + x++ * x++ + + returns the value of: + + x * (x + 1) + (x + 2) * (x + 3) + + and increments x as if by x += 4. Similarly, for functions f, g, + the expression: + + f(x++, x++) + g(x++) + + evaluates to: + + f(x, x + 1) + g(x + 2) + + and increments x three times. + + In A || B, B is read only if A tests as false; in A && B, B is + read only if A tests as true. Thus if x is nonzero, + x++ || x++ returns x and increments x once; if x is zero, + it returns x + 1 and increments x twice. + + + , Comma operator. + a, b returns the value of b. + For situations in which a comma is used for another purpose + (function arguments, array indexing, and the print statement), + parenthesis must be used around the comma operator expression. + E.g., if A is a matrix, A[(a, b), c] evaluates a, b, and c, and + returns the value of A[b, c]. + + += -= *= /= %= //= &= |= <<= >>= ^= **= + Operator-with-assignments. + These associate from left to right, e.g. a += b *= c has the + effect of a = (a + b) * c, where only a is required to be an + lvalue. For the effect of b *= c; a += b; when both a and b + are lvalues, use a += (b *= c). + + = Assignment. + As in C, this, when repeated, this associates from right to left, + e.g. a = b = c has the effect of a = (b = c). Here both a and b + are to be lvalues. + + ? : Conditional value. + a ? b : c returns b if a tests as true (i.e. nonzero if + a is a number), c otherwise. Thus it is equivalent to: + if (a) return b; else return c;. + All that is required of the arguments in this function + is that the "is-it-true?" test is meaningful for a. + As in C, this operator associates from right to left, + i.e. a ? b : c ? d : e is evaluated as a ? b : (c ? d : e). + + || Logical OR. + Unlike C, the result for a || b is one of the operands + a, b rather than one of the numbers 0 and 1. + a || b is equivalent to a ? a : b, i.e. if a tests as + true, a is returned, otherwise b. The effect in a + test like "if (a || b) ... " is the same as in C. + + && Logical AND. + Unlike C, the result for a && b is one of the operands + a, b rather than one of the numbers 0 and 1. + a && b is equivalent to a ? b : a, i.e. if a tests as + true, b is returned, otherwise a. The effect in a + test like "if (a && b) ... " is the same as in C. + + == != <= >= < > + Relations. + + + - + Binary plus and minus and unary plus and minus when applied to + a first or only term. + + * / // % + Multiply, divide, and modulo. + Please Note: The '/' operator is a fractional divide, + whereas the '//' is an integral divide. Thus think of '/' + as division of real numbers, and think of '//' as division + of integers (e.g., 8 / 3 is 8/3 whereas 8 // 3 is 2). + The '%' is integral or fractional modulus (e.g., 11%4 is 3, + and 10%pi() is ~.575222). + + | Bitwise OR. + In a | b, both a and b are to be real integers; + the signs of a and b are ignored, i.e. + a | b = abs(a) | abs(b) and the result will + be a non-negative integer. + + & Bitwise AND. + In a & b, both a and b are to be real integers; + the signs of a and b are ignored as for a | b. + + ^ ** << >> + Powers and shifts. + The '^' and '**' are both exponentiation, e.g. 2^3 + returns 8, 2^-3 returns .125. In a ^ b, b has to be + an integer and if a is zero, nonnegative. 0^0 returns + the value 1. + + For the shift operators both arguments are to be + integers, or if the first is complex, it is to have + integral real and imaginary parts. Changing the + sign of the second argument reverses the shift, e.g. + a >> -b = a << b. The result has the same sign as + the first argument except that a nonzero value is + reduced to zero by a sufficiently long shift to the + right. These operators associate right to left, + e.g. a << b ^ c = a << (b ^ c). + + + - ! + Plus (+) and minus (-) have their usual meanings as unary + prefix operators at this level of precedence when applied to + other than a first or only term. + + As a prefix operator, '!' is the logical NOT: !a returns 0 if + a tests as nonzero, and 1 if a tests as zero, i.e. it is + equivalent to a ? 0 : 1. Be careful about + using this as the first character of a top level command, + since it is also used for executing shell commands. + + As a postfix operator ! gives the factorial function, i.e. + a! = fact(a). + + ++ -- + Pre or post incrementing or decrementing. + These are applicable only to variables. + + [ ] [[ ]] . ( ) + Indexing, double-bracket indexing, element references, + and function calls. Indexing can only be applied to matrices, + element references can only be applied to objects, but + double-bracket indexing can be applied to matrices, objects, + or lists. + + variables constants . ( ) + These are variable names and constants, the special '.' symbol, + or a parenthesized expression. Variable names begin with a + letter, but then can contain letters, digits, or underscores. + Constants are numbers in various formats, or strings inside + either single or double quote marks. + + + The most significant difference from the order of precedence in + C is that | and & have higher precedence than ==, +, -, *, / and %. + For example, in C a == b | c * d is interpreted as: + + (a == b) | (c * d) + + and calc it is: + + a == ((b | c) * d) + + + Most of the operators will accept any real or complex numbers + as arguments. The exceptions are: + + / // % + Second argument must be nonzero. + + ^ + The exponent must be an integer. When raising zero + to a power, the exponent must be non-negative. + + | & + Both both arguments must be integers. + + << >> + The shift amount must be an integer. The value being + shifted must be an integer or a complex number with + integral real and imaginary parts. + + + See the 'unexpected' help file for a list of unexpected + surprises in calc syntax/usage. Persons familiar with C should + read the 'unexpected' help file to avoid confusion. + diff --git a/help/STATEMENT b/help/STATEMENT new file mode 100644 index 0000000..44d57e4 --- /dev/null +++ b/help/STATEMENT @@ -0,0 +1,243 @@ +Statements + + Statements are very much like C statements. Most statements act + identically to those in C, but there are minor differences and + some additions. The following is a list of the statement types, + with explanation of the non-C statements. In this list, upper + case words identify the keywords which are actually in lower case. + Statements are generally terminated with semicolons, except if the + statement is the compound one formed by matching braces. Various + expressions are optional and may be omitted (as in RETURN). + + + C-like statements + ----------------- + { statement } + { statement; ... statement } + if (expr) statement + if (expr) statement ELSE statement + for (optionalexpr ; optionalexpr ; optionalexpr) statement + while (expr) statement + do statement while (expr) + continue + break + goto label + These all work like in normal C. + + See 'help expression' for details on expressions. + See 'help builtin' for details on calc builtin functions. + + + return + ------ + return optionalexpr + return ( optionalexpr ) + This returns a value from a function. Functions always + have a return value, even if this statement is not used. + If no return statement is executed, or if no expression + is specified in the return statement, then the return + value from the function is the null type. + + + switch + ------ + switch (expr) { caseclauses } + Switch statements work similarly to C, except for the + following. A switch can be done on any type of value, + and the case statements can be of any type of values. + The case statements can also be expressions calculated + at runtime. The calculator compares the switch value + with each case statement in the order specified, and + selects the first case which matches. The default case + is the exception, and only matches once all other cases + have been tested. + + + matrix + ------ + mat variable [dimension] [dimension] ... + mat variable [dimension, dimension, ...] + mat variable [] = { value, ... } + This creates a matrix variable with the specified dimensions. + Matrices can have from 1 to 4 dimensions. When specifying + multiple dimensions, you can use either the standard C syntax, + or else you can use commas for separating the dimensions. + For example, the following two statements are equivalent, + and so will create the same two dimensional matrix: + + mat foo[3][6]; + mat foo[3,6]; + + By default, each dimension is indexed starting at zero, + as in normal C, and contains the specified number of + elements. However, this can be changed if a colon is + used to separate two values. If this is done, then the + two values become the lower and upper bounds for indexing. + This is convenient, for example, to create matrices whose + first row and column begin at 1. Examples of matrix + definitions are: + + mat x[3] one dimension, bounds are 0-2 + mat foo[4][5] two dimensions, bounds are 0-3 and 0-4 + mat a[-7:7] one dimension, bounds are (-7)-7 + mat s[1:9,1:9] two dimensions, bounds are 1-9 and 1-9 + + Note that the MAT statement is not a declaration, but is + executed at runtime. Within a function, the specified + variable must already be defined, and is just converted to + a matrix of the specified size, and all elements are set + to the value of zero. For convenience, at the top level + command level, the MAT command automatically defines a + global variable of the specified name if necessary. + + Since the MAT statement is executed, the bounds on the + matrix can be full expressions, and so matrices can be + dynamically allocated. For example: + + size = 20; + mat data[size*2]; + + allocates a matrix which can be indexed from 0 to 39. + + Initial values for the elements of a matrix can be specified + by following the bounds information with an equals sign and + then a list of values enclosed in a pair of braces. Even if + the matrix has more than one dimension, the elements must be + specified as a linear list. If too few values are specified, + the remaining values are set to zero. If too many values are + specified, a runtime error will result. Examples of some + initializations are: + + mat table1[5] = {77, 44, 22}; + mat table2[2,2] = {1, 2, 3, 4}; + + When an initialization is done, the bounds of the matrix + can optionally be left out of the square brackets, and the + correct bounds (zero based) will be set. This can only be + done for one-dimensional matrices. An example of this is: + + mat fred[] = {99, 98, 97}; + + The MAT statement can also be used in declarations to set + variables as being matrices from the beginning. For example: + + local mat temp[5]; + static mat strtable[] = {"hi", "there", "folks"); + + + object + ------ + obj type { elementnames } optionalvariables + obj type variable + These create a new object type, or create one or more + variables of the specified type. For this calculator, + an object is just a structure which is implicitly acted + on by user defined routines. The user defined routines + implement common operations for the object, such as plus + and minus, multiply and divide, comparison and printing. + The calculator will automatically call these routines in + order to perform many operations. + + To create an object type, the data elements used in + implementing the object are specified within a pair + of braces, separated with commas. For example, to + define an object will will represent points in 3-space, + whose elements are the three coordinate values, the + following could be used: + + obj point {x, y, z}; + + This defines an object type called point, whose elements + have the names x, y, and z. The elements are accessed + similarly to structure element accesses, by using a period. + For example, given a variable 'v' which is a point object, + the three coordinates of the point can be referenced by: + + v.x + v.y + v.z + + A particular object type can only be defined once, and + is global throughout all functions. However, different + object types can be used at the same time. + + In order to create variables of an object type, they + can either be named after the right brace of the object + creation statement, or else can be defined later with + another obj statement. To create two points using the + second (and most common) method, the following is used: + + obj point p1, p2; + + This statement is executed, and is not a declaration. + Thus within a function, the variables p1 and p2 must have + been previously defined, and are just changed to be the + new object type. For convenience, at the top level command + level, object variables are automatically defined as being + global when necessary. + + Initial values for an object can be specified by following + the variable name by an equals sign and a list of values + enclosed in a pair of braces. For example: + + obj point pt = {5, 6}; + + The OBJ statement can also be used in declarations to set + variables as being objects from the beginning. If multiple + variables are specified, then each one is defined as the + specified object type. Examples of declarations are: + + local obj point temp1; + static obj point temp2 = {4, 3}; + global obj point p1, p2, p3; + + + print expressions + ----------------- + print expr + print expr, ... expr + print expr: ... expr + For interactive expression evaluation, the values of all + typed-in expressions are automatically displayed to the + user. However, within a function or loop, the printing of + results must be done explicitly. This can be done using + the 'printf' or 'fprintf' functions, as in standard C, or + else by using the built-in 'print' statement. The advantage + of the print statement is that a format string is not needed. + Instead, the given values are simply printed with zero or one + spaces between each value. + + Print accepts a list of expressions, separated either by + commas or colons. Each expression is evaluated in order + and printed, with no other output, except for the following + special cases. The comma which separates expressions prints + a single space, and a newline is printed after the last + expression unless the statement ends with a colon. As + examples: + + print 3, 4; prints "3 4" and newline. + print 5:; prints "5" with no newline. + print 'a' : 'b' , 'c'; prints "ab c" and newline. + print; prints a newline. + + For numeric values, the format of the number depends on the + current "mode" configuration parameter. The initial mode + is to print real numbers, but it can be changed to other + modes such as exponential, decimal fractions, or hex. + + If a matrix or list is printed, then the elements contained + within the matrix or list will also be printed, up to the + maximum number specified by the "maxprint" configuration + parameter. If an element is also a matrix or a list, then + their values are not recursively printed. Objects are printed + using their user-defined routine. Printing a file value + prints the name of the file that was opened. + + + Also see the help topic: + + command top level commands + expression calc expression syntax + builtin calc builtin functions + usage how to invoke the calc command and calc -options + diff --git a/help/TYPE b/help/TYPE new file mode 100644 index 0000000..3bca81c --- /dev/null +++ b/help/TYPE @@ -0,0 +1,103 @@ +Builtin types + + The calculator has the following built-in types. + + null value + This is the undefined value type. The function 'null' + returns this value. Functions which do not explicitly + return a value return this type. If a function is called + with fewer parameters than it is defined for, then the + missing parameters have the null type. The null value is + false if used in an IF test. + + rational numbers + This is the basic data type of the calculator. + These are fractions whose numerators and denominators + can be arbitrarily large. The fractions are always + in lowest terms. Integers have a denominator of 1. + The numerator of the number contains the sign, so that + the denominator is always positive. When a number is + entered in floating point or exponential notation, it is + immediately converted to the appropriate fractional value. + Printing a value as a floating point or exponential value + involves a conversion from the fractional representation. + + Numbers are stored in binary format, so that in general, + bit tests and shifts are quicker than multiplies and divides. + Similarly, entering or displaying of numbers in binary, + octal, or hex formats is quicker than in decimal. The + sign of a number does not affect the bit representation + of a number. + + complex numbers + Complex numbers are composed of real and imaginary parts, + which are both fractions as defined above. An integer which + is followed by an 'i' character is a pure imaginary number. + Complex numbers such as "2+3i" when typed in, are processed + as the sum of a real and pure imaginary number, resulting + in the desired complex number. Therefore, parenthesis are + sometimes necessary to avoid confusion, as in the two values: + + 1+2i ^2 (which is -3) + (1+2i) ^2 (which is -3+4i) + + Similar care is required when entering fractional complex + numbers. Note the differences below: + + 3/4i (which is -(3/4)i) + 3i/4 (which is (3/4)i) + + The imaginary unit itself is input using "1i". + + strings + Strings are a sequence of zero or more characters. + They are input using either of the single or double + quote characters. The quote mark which starts the + string also ends it. Various special characters can + also be inserted using back-slash. Example strings: + + "hello\n" + "that's all" + 'lots of """"' + 'a' + "" + + There is no distinction between single character and + multi-character strings. The 'str' and 'ord' functions + will convert between a single character string and its + numeric value. The 'str' and 'eval' functions will + convert between longer strings and the corresponding + numeric value (if legal). The 'strcat', 'strlen', and + 'substr' functions are also useful. + + matrices + These are one to four dimensional matrices, whose minimum + and maximum bounds can be specified at runtime. Unlike C, + the minimum bounds of a matrix do not have to start at 0. + The elements of a matrix can be of any type. There are + several built-in functions for matrices. Matrices are + created using the 'mat' statement. + + associations + These are one to four dimensional matrices which can be + indexed by arbitrary values, instead of just integers. + These are also known as associative arrays. The elements of + an association can be of any type. Very few operations are + permitted on an association except for indexing. Associations + are created using the 'assoc' function. + + lists + These are a sequence of values, which are linked together + so that elements can be easily be inserted or removed + anywhere in the list. The values can be of any type. + Lists are created using the 'list' function. + + files + These are text files opened using stdio. Files may be opened + for sequential reading, writing, or appending. Opening a + file using the 'fopen' function returns a value which can + then be used to perform I/O to that file. File values can + be copied by normal assignments between variables, or by + using the result of the 'files' function. Such copies are + indistinguishable from each other. + diff --git a/help/VARIABLE b/help/VARIABLE new file mode 100644 index 0000000..91a22a3 --- /dev/null +++ b/help/VARIABLE @@ -0,0 +1,83 @@ +Variable declarations + + Variables can be declared as either being global, local, or static. + Global variables are visible to all functions and on the command + line, and are permanent. Local variables are visible only within + a single function or command sequence. When the function or command + sequence returns, the local variables are deleted. Static variables + are permanent like global variables, but are only visible within the + same input file or function where they are defined. + + To declare one or more variables, the 'local', 'global', or 'static' + keywords are used, followed by the desired list of variable names, + separated by commas. The definition is terminated with a semicolon. + Examples of declarations are: + + local x, y, z; + global fred; + local foo, bar; + static var1, var2, var3; + + Variables may have initializations applied to them. This is done + by following the variable name by an equals sign and an expression. + Global and local variables are initialized each time that control + reaches them (e.g., at the entry to a function which contains them). + Static variables are initialized once only, at the time that control + first reaches them (but in future releases the time of initialization + may change). Unlike in C, expressions for static variables may + contain function calls and refer to variables. Examples of such + initializations are: + + local a1 = 7, a2 = 3; + static b = a1 + sin(a2); + + Within function declarations, all variables must be defined. + But on the top level command line, assignments automatically define + global variables as needed. For example, on the top level command + line, the following defines the global variable x if it had not + already been defined: + + x = 7 + + The static keyword may be used at the top level command level to + define a variable which is only accessible interactively, or within + functions defined interactively. + + Variables have no fixed type, thus there is no need or way to + specify the types of variables as they are defined. Instead, the + types of variables change as they are assigned to or are specified + in special statements such as 'mat' and 'obj'. When a variable is + first defined using 'local', 'global', or 'static', it has the + value of zero. + + If a procedure defines a local or static variable name which matches + a global variable name, or has a parameter name which matches a + global variable name, then the local variable or parameter takes + precedence within that procedure, and the global variable is not + directly accessible. + + The MAT and OBJ keywords may be used within a declaration statement + in order to initially define variables as that type. Initialization + of these variables are also allowed. Examples of such declarations + are: + + static mat table[3] = {5, 6, 7}; + local obj point p1, p2; + + There are no pointers in the calculator language, thus all + arguments to user-defined functions are normally passed by value. + This is true even for matrices, strings, and lists. In order + to circumvent this, the '&' operator is allowed before a variable + when it is an argument to a function. When this is done, the + address of the variable is passed to the function instead of its + value. This is true no matter what the type of the variable is. + This allows for fast calls of functions when the passed variable + is huge (such as a large array). However, the passed variable can + then be changed by the function if the parameter is assigned into. + The function being called does not need to know if the variable + is being passed by value or by address. + + Built-in functions and object functions always accept their + arguments as addresses, thus there is no need to use '&' when + calling built-in functions. + diff --git a/help/abs b/help/abs new file mode 100644 index 0000000..1106a14 --- /dev/null +++ b/help/abs @@ -0,0 +1,46 @@ +NAME + abs - absolute value + +SYNOPSIS + abs(x [,eps]) + +TYPES + If x is an object of type xx, the function xx_abs has to have + been defined; this will determine the types for x, eps and + the returned value. + + For non-object x and eps: + + x number (real or complex) + eps ignored if x is real, nonzero real for complex x, + defaults to epsilon(). + + return non-negative real + +DESCRIPTION + If x is real, returns the absolute value of x, i.e. x if x >= 0, + -x if x < 0. + + For complex x with zero real part, returns the absolute value of im(x). + + For other complex x, returns the multiple of eps nearest to the absolute + value of x, or in the case of two equally near nearest values, the + the nearest even multiple of eps. In particular, with eps = 10^-n, + the result will be the absolute value correct to n decimal places. + +EXAMPLE + > print abs(3.4), abs(-3.4) + 3.4 3.4 + + > print abs(3+4i, 1e-5), abs(4+5i, 1e-5), abs(4+5i, 1e-10) + 5 6.40312 6.4031242374 + +LIMITS + none + +LINK LIBRARY + NUMBER *qqabs(NUMBER *x) + +SEE ALSO + cmp, epsilon, hypot, norm, near, obj + diff --git a/help/access b/help/access new file mode 100644 index 0000000..63dad2b --- /dev/null +++ b/help/access @@ -0,0 +1,50 @@ +NAME + access - determine existence or accessibility of named file + +SYNOPSIS + access(name [, mode]) + +TYPES + name string + mode integer or string containing only 'r', 'w', 'x' characters + + return null value or error + +DESCRIPTION + access(name) or access(name, 0) or access(name, "") returns the null + value if a file with this name exists. + + If non-null mode is specified, the null value is returned if there + is a file with the specified name and accessibility indicated by the + bits or characters of the mode argument: 'r' or bit 2 for reading, + 'w' or bit 1 for writing, 'x' or bit 0 for execution. + +EXAMPLE + The system error-numbers and messages may differ for different + implementations + + > !rm -f junk + > access("junk") + System error 2 + > strerror(.) + "No such file or directory" + > f = fopen("junk", "w") + > access("junk") + > fputs(f, "Alpha") + > fclose(f) + > !chmod u-w junk + > access("junk", "w") + System error 13 + > strerror(.) + "Permission denied" + +LIMITS + There may be implementation-dependent limits inherited from the + system call "access" used by this function. + +LINK LIBRARY + none + +SEE ALSO + fopen, fclose, isfile, files + diff --git a/help/acos b/help/acos new file mode 100644 index 0000000..9828678 --- /dev/null +++ b/help/acos @@ -0,0 +1,31 @@ +NAME + acos - inverse trigonometric cosine + +SYNOPSIS + acos(x [,eps]) + +TYPES + x real, -1 <= x <= 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the acos of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = acos(x) is the number in [0, pi] for which cos(v) = x. + +EXAMPLE + > print acos(.5, 1e-5), acos(.5, 1e-10), acos(.5, 1e-15), acos(.5, 1e-20) + 1.0472 1.0471975512 1.047197551196598 1.04719755119659774615 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacos(NUMBER *x, NUMBER *eps) + +SEE ALSO + asin, atan, asec, acsc, acot, epsilon + diff --git a/help/acosh b/help/acosh new file mode 100644 index 0000000..a69e318 --- /dev/null +++ b/help/acosh @@ -0,0 +1,34 @@ +NAME + acosh - inverse hyperbolic cosine + +SYNOPSIS + acosh(x [,eps]) + +TYPES + x real, x >= 1 + eps nonzero real, defaults to epsilon() + + return nonnegative real + +DESCRIPTION + Returns the acosh of x to a multiple of eps with error less in + absolute value than .75 * eps. + + acosh(x) is the nonnegative real number v for which cosh(v) = x. + It is given by + + acosh(x) = ln(x + sqrt(x^2 - 1)) + +EXAMPLE + > print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20) + 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacosh(NUMBER *x, NUMBER *eps) + +SEE ALSO + asinh, atanh, asech, acsch, acoth, epsilon + diff --git a/help/acot b/help/acot new file mode 100644 index 0000000..1749cbc --- /dev/null +++ b/help/acot @@ -0,0 +1,31 @@ +NAME + acot - inverse trigonometric cotangent + +SYNOPSIS + acot(x [,eps]) + +TYPES + x real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the acot of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = acot(x) is the number in (0, pi) for which cot(v) = x. + +EXAMPLE + > print acot(2, 1e-5), acot(2, 1e-10), acot(2, 1e-15), acot(2, 1e-20) + .46365 .463647609 .463647609000806 .46364760900080611621 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacot(NUMBER *x, NUMBER *eps) + +SEE ALSO + asin, acos, atan, asec, acsc, epsilon + diff --git a/help/acoth b/help/acoth new file mode 100644 index 0000000..589bf3a --- /dev/null +++ b/help/acoth @@ -0,0 +1,33 @@ +NAME + acoth - inverse hyperbolic cotangent + +SYNOPSIS + acoth(x [,eps]) + +TYPES + x real, with abs(x) > 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the acoth of x to a multiple of eps with error less in + absolute value than .75 * eps. + + acoth(x) is the real number v for which coth(v) = x. + It is given by + acoth(x) = ln((x + 1)/(x - 1))/2 + +EXAMPLE + > print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20) + .54931 .5493061443 .549306144334055 .5493061443340548457 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacoth(NUMBER *x, NUMBER *eps) + +SEE ALSO + asinh, acosh, atanh, asech, acsch, epsilon + diff --git a/help/acsc b/help/acsc new file mode 100644 index 0000000..73545bb --- /dev/null +++ b/help/acsc @@ -0,0 +1,31 @@ +NAME + acsc - inverse trigonometric cosecant + +SYNOPSIS + acsc(x [,eps]) + +TYPES + x real, with absolute value >= 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the acsc of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = acsc(x) is the number in [-pi/2, pi/2] for which csc(v) = x. + +EXAMPLE + > print acsc(2, 1e-5), acsc(2, 1e-10), acsc(2, 1e-15), acsc(2, 1e-20) + .5236 .5235987756 .523598775598299 .52359877559829887308 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacsc(NUMBER *x, NUMBER *eps) + +SEE ALSO + asin, acos, atan, asec, acot, epsilon + diff --git a/help/acsch b/help/acsch new file mode 100644 index 0000000..f11904e --- /dev/null +++ b/help/acsch @@ -0,0 +1,34 @@ +NAME + acsch - inverse hyperbolic cosecant + +SYNOPSIS + acsch(x [,eps]) + +TYPES + x nonzero real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the acsch of x to a multiple of eps with error less in + absolute value than .75 * eps. + + acsch(x) is the real number v for which csch(v) = x. It is given by + + acsch(x) = ln((1 + sqrt(1 + x^2))/x) + + +EXAMPLE + > print acsch(2, 1e-5), acsch(2, 1e-10), acsch(2, 1e-15), acsch(2, 1e-20) + .48121 .4812118251 .481211825059603 .4812118250596034475 + +LIMITS + none + +LINK LIBRARY + NUMBER *qacsch(NUMBER *x, NUMBER *eps) + +SEE ALSO + asinh, acosh, atanh, asech, acoth, epsilon + diff --git a/help/address b/help/address new file mode 100644 index 0000000..926ec5a --- /dev/null +++ b/help/address @@ -0,0 +1,162 @@ +NAME + & - address operator + +SYNOPSIS + &X + +TYPES + X expression specifying an octet, lvalue, string or number + + return pointer + +DESCRIPTION + &X returns the address at which information for determining the current + value of X is stored. After an assignment as in p = &X, the + value of X is accessible by *p so long as the connection between p + and the value is not broken by relocation of the information or by the + value ceasing to exist. Use of an address after the connection + is broken is unwise since the calculator may use that address for other + purposes; the consequences of attempting to write data to, or + otherwise accessing, such a vacated address may be catastrophic. + + An octet is normally expressed by B[i] where B is a block and + 0 <= i < sizeof(B). &B[i] then returns the address at which this + octet is located until the block is freed or relocated. Freeing + of an unnamed block B occurs when a new value is assigned to B or + when B ceases to exist; a named block B is freed by blkfree(B). + A block is relocated when an operation like copying to B requires + a change of sizeof(B). + + An lvalue may be expressed by an identifier for a variable, or by + such an identifier followed by one or more qualifiers compatible with + the type of values associated with the variable and earlier qualifiers. + If an identifier A specifies a global or static variable, the address + &A is permanently associated with that variable. For a local variable + or function parameter A, the association of the variable with &A + is limited to each occasion when the function is called. If X specifies a + component or element of a matrix or object, connection of + &X with that component or element depends only on the continued existence + of the matrix or object. For example, after + + > mat A[3] + + the addresses &A[0], &A[1], &A[2] locate the three elements + of the matrix specified by A until another value is assigned to A, etc. + Note one difference from C in that &A[0] is not the same as A. + + An element of a list has a fixed address while the list exists and + the element is not removed by pop(), remove(), or delete(); the index + of the element changes if an element is pushed onto the list, or if + earlier elements are popped or deleted. + + Elements of an association have fixed addresses so long as the association + exists. If A[a,b,...] has not been defined for the association A, + &A[a,b,...] returns the constant address of a particular null value. + + Some other special values have fixed addresses; e.g. the old value (.). + + Some arithmetic operations are defined for addresses but these should + be used only for octets or components of a matrix or object where the + results refer to octets in the same block or existing components of the + same matrix or object. For example, immediately after + + > mat A[10] + > p = &A[5] + + it is permitted to use expressions like p + 4, p - 5, p++ . + + Strings defined literally have fixed addresses, e.g., after + + > p = &"abc" + > A = "abc" + + the address &*A of the value of A will be equal to p. + + Except in cases like strcat(A, "") when *A identified with a literal + string as above, definitions of string values using strcat() or substr() + will copy the relevant strings to newly allocated addresses which will + be useable only while the variables retain these defined values. + For example, after + + > B = C = strcat("a", "bc"); + + &*B and &*C will be different. If p is defined by p = &*B, p should + not be used after a new value is assigned to B, or B ceases to exist, + etc. + + When compilation of a function encounters for the first time a particular + literal number or the result of simple arithmetic operations (like +, -, *, + or /) on literal numbers, that number is assigned to a particular + address which is then used for later similar occurrences of that number + so long as the number remains associated with at least one function or + lvalue. For example, after + + > x = 27; + > y = 3 * 9; + > define f(a) = 27 + a; + + the three occurrences of 27 have the same address which may be displayed + by any of &27, &*x, &*y and &f(0). If x and y are assigned + other values and f is redefined or undefined and the 27 has not been + stored elsewhere (e.g. as the "old value" or in another function + definition or as an element in an association), the address assigned at + the first occurrence of 27 will be freed and calc may later use it for + another number. + + When a function returns a number value, that number value is usually + placed at a newly allocated address, even if an equal number is stored + elsewhere. For example calls to f(a), as defined above, with the same + non-zero value for a will be assigned to different addresses as can be + seen from printing &*A, &*B, &*C after + + > A = f(2); B = f(2); C = f(2); + + (the case of f(0) is exceptional since 27 + 0 simply copies the 27 + rather than creating a new number value). Here it is clearly more + efficient to use + + > A = B = C = f(2); + + which, not only performs the addition in f() only once, but stores the + number values for A, B and C at the same address. + + Whether a value V is a pointer and if so, its type, is indicated by the + value returned by isptr(V): 1, 2, 3, 4 for octet-, value-, string- + and number-pointer respectively, and 0 otherwise. + + The output when addresses are printed consists of a description (o_ptr, + v_ptr, s_ptr, n_ptr) followed by : and the address printed in + %p format. + + Iteration of & is not permitted; &&X causes a "non-variable operand" + scan error. + +EXAMPLE + Addresses for particular systems may differ from those displayed here. + + > mat A[3] + > B = blk() + + > print &A, &A[0], &A[1] + v-ptr: 1400470d0 v-ptr: 140044b70 v-ptr: 140044b80 + + > print &B, &B[0], &B[1] + v-ptr: 140047130 o-ptr: 140044d00 o-ptr: 140044d01 + + > a = A[0] = 27 + > print &*a, &*A[0]. &27 + n_ptr: 14003a850 n_ptr: 14003a850 n_ptr: 14003a850 + + > a = A[0] = "abc" + > print &*a, &*A[0], &"abc" + s_ptr: 14004cae0 s_ptr: 14004cae0 s_ptr: 14004cae0 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + dereference, isptr + diff --git a/help/agd b/help/agd new file mode 100644 index 0000000..77d6643 --- /dev/null +++ b/help/agd @@ -0,0 +1,58 @@ +NAME + agd - inverse gudermannian function + +SYNOPSIS + agd(z [,eps]) + +TYPES + z number (real or complex) + eps nonzero real, defaults to epsilon() + + return number or infinite error value + +DESCRIPTION + Calculate the inverse gudermannian of z to a nultiple of eps with + errors in real and imaginary parts less in absolute value than .75 * eps, + or an error value if z is very close to one of the one of the branch + points of agd(z).. + + agd(z) is usually defined initially for real z with abs(z) < pi/2 by + one of the formulae + + agd(z) = ln(sec(z) + tan(z)) + + = 2 * atanh(tan(z/2)) + + = asinh(tan(z)), + + or as the integral from 0 to z of (1/cos(t))dt. For complex z, the + principal branch, approximated by gd(z, eps), has cuts along the real + axis outside -pi/2 < z < pi/2. + + If z = x + i * y and abs(x) < pi/2, agd(z) is given by + + agd(z) = atanh(sin(x)/cosh(y)) + i * atan(sinh(y)/cos(x)> + + +EXAMPLE + > print agd(1, 1e-5), agd(1, 1e-10), agd(1, 1e-15) + 1.22619 1.2261911709 1.226191170883517 + + > print agd(2, 1e-5), agd(2, 1e-10) + 1.52345-3.14159i 1.5234524436-3.1415926536i + + > print agd(5, 1e-5), agd(5, 1e-10), agd(5, 1e-15) + -1.93237 -1.9323667197 -1.932366719745925 + + > print agd(1+2i, 1e-5), agd(1+2i, 1e-10) + .22751+1.42291i .2275106584+1.4229114625i + +LIMITS + none + +LINK LIBRARY + COMPLEX *cagd(COMPLEX *x, NUMBER *eps) + +SEE ALSO + gd, exp, ln, sin, sinh, etc. + diff --git a/help/append b/help/append new file mode 100644 index 0000000..c16c3a0 --- /dev/null +++ b/help/append @@ -0,0 +1,61 @@ +NAME + append - append one or more values to end of list + +SYNOPSIS + append(x, y_0, y_1, ...) + +TYPES + x lvalue whose value is a list + y_0, ... any + + return null value + +DESCRIPTION + If after evaluation of y_0, y_1, ..., x is a list with contents + (x_0, x_1, ...), then after append(x, y_0, y_1, ...), x has + contents (x_0, x_1, ..., y_0, y_1, ...). + + If after evaluation of y_0, y_1, ..., x has size n, + append(x, y_0, y_1, ...) is equivalent to insert(x, n, y_0, y_1, ...). + +EXAMPLE + > x = list(2,3,4) + > append(x, 5, 6) + > print x + + list (5 elements, 5 nonzero): + [[0]] = 2 + [[1]] = 3 + [[2]] = 4 + [[3]] = 5 + [[4]] = 6 + + > append(x, pop(x), pop(x)) + > print x + + list (5 elements, 5 nonzero): + [[0]] = 4 + [[1]] = 5 + [[2]] = 6 + [[3]] = 2 + [[4]] = 3 + + > append(x, (remove(x), 7)) + > print x + + list (5 elements, 5 nonzero): + [[0]] = 4 + [[1]] = 5 + [[2]] = 6 + [[3]] = 2 + [[4]] = 7 + +LIMITS + append() can have at most 100 arguments + +LINK LIBRARY + none + +SEE ALSO + delete, insert, islist, list, pop, push, remove, rsearch, search, size + diff --git a/help/appr b/help/appr new file mode 100644 index 0000000..7cde524 --- /dev/null +++ b/help/appr @@ -0,0 +1,153 @@ +NAME + appr - approximate numbers by multiples of a specified number + +SYNOPSIS + appr(x [,y [,z]]) + +TYPES + x real, complex, matrix, list + y real + z integer + + return same type as x except that complex x may return a real number + +DESCRIPTION + Return the approximate value of x as specified by a specific error + (epsilon) and config ("appr") value. + + The default value for y is epsilon(). The default value for z is + the current value of the "appr" configuration parameter. + + If y is zero or x is a multiple of y, appr(x,y,z) returns x. I.e., + there is no "approximation" - the result represents x exactly. + + In the following it is assumed y is nonzero and x is not a multiple of y. + For real x: + + appr(x,y,z) is either the nearest multiple of y greater + than x or the nearest multiple of y less than x. Thus, if + we write a = appr(x,y,z) and r = x - a, then a/y is an integer + and abs(r) < abs(y). If r > 0, we say x has been "rounded down" + to a; if r < 0, the rounding is "up". For particular x and y, + whether the rounding is down or up is determined by z. + + Only the 5 lowest bits of z are used, so we may assume z has been + replaced by its value modulo 32. The type of rounding depends on + z as follows: + + z = 0 round down or up according as y is positive or negative, + sgn(r) = sgn(y) + + z = 1 round up or down according as y is positive or negative, + sgn(r) = -sgn(y) + + z = 2 round towards zero, sgn(r) = sgn(x) + + z = 3 round away from zero, sgn(r) = -sgn(x) + + z = 4 round down, r > 0 + + z = 5 round up, r < 0 + + z = 6 round towards or from zero according as y is positive or + negative, sgn(r) = sgn(x/y) + + z = 7 round from or towards zero according as y is positive or + negative, sgn(r) = -sgn(x/y) + + z = 8 a/y is even + + z = 9 a/y is odd + + z = 10 a/y is even or odd according as x/y is positive or negative + + z = 11 a/y is odd or even according as x/y is positive or negative + + z = 12 a/y is even or odd according as y is positive or negative + + z = 13 a/y is odd or even according as y is positive or negative + + z = 14 a/y is even or odd according as x is positive or negative + + z = 15 a/y is odd or even according as x is positive or negative + + z = 16 to 31 abs(r) <= abs(y)/2; if there is a unique multiple + of y that is nearest x, appr(x,y,z) is that multiple of y + and then abs(r) < abs(y)/2. If x is midway between + successive multiples of y, then abs(r) = abs(y)/2 and + the value of a is as given by appr(x, y, z-16). + + Matrix or List x: + + appr(x,y,z) returns the matrix or list indexed in the same way as x, + in which each element t has been replaced by appr(t,y,z). + + Complex x: + + Returns appr(re(x), y, z) + appr(im(x), y, z) * 1i + +PROPERTIES + If appr(x,y,z) != x, then abs(x - appr(x,y,z)) < abs(y). + + If appr(x,y,z) != x and 16 <= z <= 31, abs(x - appr(x,y,z)) <= abs(y)/2. + + For z = 0, 1, 4, 5, 16, 17, 20 or 21, and any integer n, + appr(x + n*y, y, z) = appr(x, y, z) + n * y. + + If y is nonzero, appr(x,y,8)/y = an odd integer n only if x = n * y. + +EXAMPLES + > print appr(-5.44,0.1,0), appr(5.44,0.1,0), appr(5.7,1,0), appr(-5.7,1,0) + -5.5 5.4 5 -6 + + > print appr(-5.44,-.1,0), appr(5.44,-.1,0), appr(5.7,-1,0), appr(-5.7,-1,0) + -5.4 5.5 6 -5 + + > print appr(-5.44,0.1,3), appr(5.44,0.1,3), appr(5.7,1,3), appr(-5.7,1,3) + -5.5 5.5 6 -6 + + > print appr(-5.44,0.1,4), appr(5.44,0.1,4), appr(5.7,1,4), appr(-5.7,1,4) + -5.5 5.4 5 -6 + + > print appr(-5.44,0.1,6), appr(5.44,0.1,6), appr(5.7,1,6), appr(-5.7,1,6) + -5.4 5.4 6 -5 + + > print appr(-5.44,-.1,6), appr(5.44,-.1,6), appr(5.7,-1,6), appr(-5.7,-1,6) + -5.5 5.5 6 -6 + + > print appr(-5.44,0.1,9), appr(5.44,0.1,9), appr(5.7,1,9), appr(-5.7,1,9) + -5.5 5.5 5 -5 + + > print appr(-.44,0.1,11), appr(.44,0.1,11), appr(5.7,1,11), appr(-5.7,1,11) + -.4 .5 5 -6 + + > print appr(-.44,-.1,11),appr(.44,-.1,11),appr(5.7,-1,11),appr(-5.7,-1,11) + -.5 .4 6 -5 + + > print appr(-.44,0.1,12), appr(.44,0.1,12), appr(5.7,1,12), appr(-5.7,1,12) + -.4 .5 5 -6 + + > print appr(-.44,-.1,12),appr(.44,-.1,12),appr(5.7,-1,12),appr(-5.7,-1,12) + -.5 .4 6 -5 + + > print appr(-.44,0.1,15), appr(.44,0.1,15), appr(5.7,1,15), appr(-5.7,1,15) + -.4 .5 5 -6 + + > print appr(-.44,-.1,15),appr(.44,-.1,15),appr(5.7,-1,15),appr(-5.7,-1,15) + -.4 .5 5 -6 + + > x = sqrt(7-3i, 1e-20) + > print appr(x,1e-5,0), appr(x,1e-5,1), appr(x,1e-5,2), appr(x,1e-6,3) + 2.70331-.55488i 2.70332-.55487i 2.70331-.55487i 2.70332-.55488i + +LIMITS + none + +LINK LIBRARY + NUMBER *qmappr(NUMBER *q, NUMBER *e, long R); + LIST *listappr(LIST *oldlp, VALUE *v2, VALUE *v3); + MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3); + +SEE ALSO + round, bround, cfappr, cfsim + diff --git a/help/arg b/help/arg new file mode 100644 index 0000000..b66ec52 --- /dev/null +++ b/help/arg @@ -0,0 +1,34 @@ +NAME + arg - argument (the angle or phase) of a complex number + +SYNOPSIS + arg(x [,eps]) + +TYPES + x number + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the argument of x to the nearest or next to nearest multiple of + eps; the error will be less in absolute value than 0.75 * abs(eps), + but usually less than 0.5 * abs(eps). + +EXAMPLE + > print arg(2), arg(2+3i, 1e-5), arg(2+3i, 1e-10), arg(2+3i, 1e-20) + 0 .98279 .9827937232 .98279372324732906799 + + > pi = pi(1e-10); deg = pi/180; eps = deg/10000 + > print arg(2+3i, eps)/deg, arg(-1 +1i, eps)/deg, arg(-1 - 1i,eps)/deg + 56.3099 135 -135 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + conj, im, polar, re + diff --git a/help/argv b/help/argv new file mode 100644 index 0000000..d343bd4 --- /dev/null +++ b/help/argv @@ -0,0 +1,55 @@ +NAME + argv - count or value of a calc command line supplied argument + +SYNOPSIS + argv([n]) + +TYPES + n nonnegative integer + + return any + +DESCRIPTION + Without args, this builtin returns the number of calc command line + strings available. + + If the numeric arg is supplied, then the corresponding command line + string is return, if it exists. Otherwise a nul() value is returned. + + In keeping with the argc/argv convention of C, argv(0) will refer + to the 1st argv string, and argv(argv()-1) will refer to the last. + This differs from the way the param() builtin works. + + By default, calc will evaluate all of its command line arguments. + However, if calc is invoked with -s, all non-dashed options will + be left as unevaluated strings. Thus: + + calc -i 2+2 + + will cause calc to print 4 and enter interactive mode. In this case + argv() will return 0. + + On the other hand: + + calc -i -s 2+2 + + will cause calc to interactive mode. The argv() builtin will return 1 + and argv(0) will return the string "2+2". + +EXAMPLE + $ calc -s a bb ccc + > argc = argv(); + > for (i = 0; i < argc; i++) print "argv[": i : '] = "': argv(i) : '"'; + argv[0] = "a" + argv[1] = "bb" + argv[2] = "ccc" + +LIMITS + 0 <= n < 2^31 + +LINK LIBRARY + none + +SEE ALSO + param, usage + diff --git a/help/arrow b/help/arrow new file mode 100644 index 0000000..29b8ed1 --- /dev/null +++ b/help/arrow @@ -0,0 +1,52 @@ +SYMBOL and NAME + -> - arrow operator + +SYNOPSIS + p -> X + +TYPES + p pointer to an lvalue + X identifier + + return lvalue + +DESCRIPTION + p->X returns the same as (*p).X. Thus the current value of *p is + to be an object of a type for which X identifies one element. + p->X then returns the lvalue corresponding to that element of the + value of *p. + + The expression *p.X will cause a runtime error since this is + interpreted as *(p.X) in which p is expected to be an object of + an appropriate type. + + Spaces or tabs on either side of -> are optional. + +EXAMPLES + > obj pair {one, two} + > obj pair A, B + > p = &A + > p->one = 1; p->two = 2 + > A + obj pair {1, 2} + + > A->two = &B + > p->two->one = 3; p->two->two = 4 + + > *p->ptwo + obj pair {3, 4} + + > B = {5,6} + > *p->two + obj pair {5, 6} + + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + address, dereference, isptr, dot + diff --git a/help/asec b/help/asec new file mode 100644 index 0000000..c964b78 --- /dev/null +++ b/help/asec @@ -0,0 +1,31 @@ +NAME + asec - inverse trigonometric secant + +SYNOPSIS + asec(x [,eps]) + +TYPES + x real, with absolute value >= 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the asec of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = asec(x) is the number in [0, pi] for which sec(v) = x. + +EXAMPLE + > print asec(2, 1e-5), asec(2, 1e-10), asec(2, 1e-15), asec(2, 1e-20) + 1.0472 1.0471975512 1.047197551196598 1.04719755119659774615 + +LIMITS + none + +LINK LIBRARY + NUMBER *qasec(NUMBER *x, NUMBER *eps) + +SEE ALSO + asin, acos, atan, acsc, acot, epsilon + diff --git a/help/asech b/help/asech new file mode 100644 index 0000000..d1e048b --- /dev/null +++ b/help/asech @@ -0,0 +1,33 @@ +NAME + asech - inverse hyperbolic secant + +SYNOPSIS + asech(x [,eps]) + +TYPES + x real, 0 < x <= 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the asech of x to a multiple of eps with error less in + absolute value than .75 * eps. + + asech(x) is the real number v for which sech(v) = x. It is given by + + asech(x) = ln((1 + sqrt(1 - x^2))/x) + +EXAMPLE + > print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20) + 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 + +LIMITS + none + +LINK LIBRARY + NUMBER *qasech(NUMBER *x, NUMBER *eps) + +SEE ALSO + asinh, acosh, atanh, acsch, acoth, epsilon + diff --git a/help/asin b/help/asin new file mode 100644 index 0000000..d9188e9 --- /dev/null +++ b/help/asin @@ -0,0 +1,31 @@ +NAME + asin - inverse trigonometric sine + +SYNOPSIS + asin(x [,eps]) + +TYPES + x real, -1 <= x <= 1 + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the asin of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = asin(x) is the number in [-pi/2, pi/2] for which sin(v) = x. + +EXAMPLE + > print asin(.5, 1e-5), asin(.5, 1e-10), asin(.5, 1e-15), asin(.5, 1e-20) + .5236 .5235987756 .523598775598299 .52359877559829887308 + +LIMITS + none + +LINK LIBRARY + NUMBER *qasin(NUMBER *q, NUMBER *epsilon) + +SEE ALSO + acos, atan, asec, acsc, acot, epsilon + diff --git a/help/asinh b/help/asinh new file mode 100644 index 0000000..2a5812e --- /dev/null +++ b/help/asinh @@ -0,0 +1,33 @@ +NAME + asinh - inverse hyperbolic sine + +SYNOPSIS + asinh(x [,eps]) + +TYPES + x real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the asinh of x to a multiple of eps with error less in + absolute value than .75 * eps. + + asinh(x) is the real number v for which sinh(v) = x. It is given by + + asinh(x) = ln(x + sqrt(1 + x^2)) + +EXAMPLE + > print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20) + 1.44363 1.4436354752 1.44363547517881 1.44363547517881034249 + +LIMITS + none + +LINK LIBRARY + NUMBER *qasinh(NUMBER *x, NUMBER *eps) + +SEE ALSO + acosh, atanh, asech, acsch, acoth, epsilon + diff --git a/help/assign b/help/assign new file mode 100644 index 0000000..7b8ea3b --- /dev/null +++ b/help/assign @@ -0,0 +1,119 @@ +NAME + = + +SYNOPSIS + a = b + a = {e_1, e_2, ...[ { ... } ] } + +TYPES + a lvalue, current value a structure in { } case + + b expression + + e_0, e_1, ... expressions, blanks, or initializer lists + + + return lvalue (a) + +DESCRIPTION + Here an lvalue is either a simple variable specified by an identifier, + or an element of an existing structure specified by one or more + qualifiers following an identifier. + + An initializer list is a comma-separated list enclosed in braces as in + + {e_0, e_1, ... } + + where each e_i is an expression, blank or initializer list. + + a = b evaluates b, assigns its value to a, and returns a. + + a = {e_0, e_1, ... } where the e_i are expressions or blanks, + requires the current value of a to be a matrix, list + or object with at least as many elements as listed e_i. Each non-blank + e_i is evaluated and its value is assigned to a[[i]]; elements a[[i]] + corresponding to blank e_i are unchanged. + + If, in a = {e_0, e_1, ...}, e_i is an initializer list, as in + {e_i_0, e_1_1, ...}, the corresponding a[[i]] is to be a matrix, list + or object with at least as many elements as listed e_i_j. Depending on + whether e_i_j is an expression, blank, or initializer list, one, no, or + possibly more than one assignment, is made to a[[i]][[j]] or, if + relevant and possible, its elements. + + In simple assignments, = associates from right to left so that, for + example, + + a = b = c + + has the effect of a = (b = c) and results in assigning the value of c + to both a and b. The expression (a = b) = c is acceptable, but has the + effect of a = b; a = c; in which the first assignment is superseded by + the second. + + In initializations, = { ...} associates from left to right so that, + for example, + + a = {e_0, ... } = {v_0, ...} + + first assigns e_0, ... to the elements of a, and then assigns v_0, ... + to the result. + + If there are side effects in the evaluations involved in executing a = b, + it should be noted that the order of evaluations is: first the address + for a, then the value of b, and finally the assignment. For example if + A is a matrix and i = 0, then the assignment in A[i++] = A[i] is + that of A[0] = A[1]. + + If, in execution of a = b, a is changed by the evaluation of b, the + value of b may be stored in an unintended or inaccessible location. For + example, + mat A[2]= {1,2}; + A[0] = (A = 3); + + results in the value 3 being stored not only as the new value for A + but also at the now unnamed location earlier used for A[0]. + + +EXAMPLE + > b = 3+1 + > a = b + > print a, b + 4 4 + + > obj point {x,y} + > mat A[3] = {1, list(2,3), obj point = {4,5}} + + > A[1][[0]] = 6; A[2].x = 7 + > print A[1] + + list (2 elements, 2 nonzero): + [[0]] = 6 + [[1]] = 3 + + > print A[2] + obj point {7, 5} + + > A = {A[2], , {9,10}} + > print A[0] + obj point {7, 5} + + > print A[2] + obj point {9, 10} + + > A = {, {2}} + print A[1] + + list (2 elements, 2 nonzero): + [[0]] = 2 + [[1]] = 3 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + swap, quomod + diff --git a/help/assoc b/help/assoc new file mode 100644 index 0000000..27eee67 --- /dev/null +++ b/help/assoc @@ -0,0 +1,84 @@ +NAME + assoc - create a new association array + +SYNOPSIS + assoc() + +TYPES + return association + +DESCRIPTION + This function returns an empty association array. + + After A = assoc(), elements can be added to the association by + assignments of the forms + + A[a_1] = v_1 + A[a_1, a_2] = v_2 + A[a_1, a_2, a_3] = v_3 + A[a_1, a_2, a_3, a_4] = v_4 + + There are no restrictions on the values of the "indices" a_i or + the "values" v_i. + + After the above assignments, so long as no new values have been + assigned to A[a_i], etc., the expressions A[a_1], A[a_1, a_2], etc. + will return the values v_1, v_2, ... + + Until A[a_1], A[a_1, a_2], ... are defined as described above, these + expressions return the null value. + + Thus associations act like matrices except that different elements + may have different numbers (between 1 and 4 inclusive) of indices, + and these indices need not be integers in specified ranges. + + Assignment of a null value to an element of an association does not + delete the element, but a later reference to that element will return + the null value as if the element is undefined. + + The elements of an association are stored in a hash table for + quick access. The index values are hashed to select the correct + hash chain for a small sequential search for the element. The hash + table will be resized as necessary as the number of entries in + the association becomes larger. + + The size function returns the number of elements in an association. + This size will include elements with null values. + + Double bracket indexing can be used for associations to walk through + the elements of the association. The order that the elements are + returned in as the index increases is essentially random. Any + change made to the association can reorder the elements, this making + a sequential scan through the elements difficult. + + The search and rsearch functions can search for an element in an + association which has the specified value. They return the index + of the found element, or a NULL value if the value was not found. + + Associations can be copied by an assignment, and can be compared + for equality. But no other operations on associations have meaning, + and are illegal. + +EXAMPLE + > A = assoc(); print A + assoc (0 elements): + + > A["zero"] = 0; A["one"] = 1; A["two"] = 2; A["three"] = 3; + > A["smallest", "prime"] = 2; + > print A + assoc (5 elements); + ["two"] = 2 + ["three"] = 3 + ["one"] = 1 + ["zero"] = 0 + ["smallest","prime"] = 2 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + isassoc, rsearch, search, size + diff --git a/help/atan b/help/atan new file mode 100644 index 0000000..0de9945 --- /dev/null +++ b/help/atan @@ -0,0 +1,31 @@ +NAME + atan - inverse trigonometric tangent + +SYNOPSIS + atan(x [,eps]) + +TYPES + x real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the atan of x to a multiple of eps with error less in + absolute value than .75 * eps. + + v = atan(x) is the number in (-pi/2, pi/2) for which tan(v) = x. + +EXAMPLE + > print atan(2, 1e-5), atan(2, 1e-10), atan(2, 1e-15), atan(2, 1e-20) + 1.10715 1.1071487178 1.107148717794091 1.10714871779409050302 + +LIMITS + none + +LINK LIBRARY + NUMBER *qatan(NUMBER *x, NUMBER *eps) + +SEE ALSO + asin, acos, asec, acsc, acot, epsilon + diff --git a/help/atan2 b/help/atan2 new file mode 100644 index 0000000..8339f9c --- /dev/null +++ b/help/atan2 @@ -0,0 +1,38 @@ +NAME + atan2 - angle to point + +SYNOPSIS + atan2(y, x, [,eps]) + +TYPES + y real + x real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + If x and y are not both zero, atan2(y, x, eps) returns, as a multiple of + eps with error less than abs(eps), the angle t such that + -pi < t <= pi and x = r * cos(t), y = r * sin(t), where + r > 0. Usually the error does not exceed abs(eps)/2. + + Note that by convention, y is the first argument; if x > 0, + atan2(y, x) = atan(y/x). + + To conform to the 4.3BSD ANSI/IEEE 754-1985 math lib, atan2(0,0) + returns 0. + +EXAMPLE + > print atan2(0,0), atan2(1,sqrt(3)), atan2(17,53,1e-100) + 0 ~.52359877559829887307 ~.31038740713235146535 + +LIMITS + none + +LINK LIBRARY + NUMBER *qatan2(NUMBER *y, *x, *acc) + +SEE ALSO + acos, asin, atan, cos, epsilon, sin, tan + diff --git a/help/atanh b/help/atanh new file mode 100644 index 0000000..e268899 --- /dev/null +++ b/help/atanh @@ -0,0 +1,33 @@ +NAME + atanh - inverse hyperbolic tangent + +SYNOPSIS + atanh(x [,eps]) + +TYPES + x real + eps nonzero real, defaults to epsilon() + + return real + +DESCRIPTION + Returns the atanh of x to a multiple of eps with error less in + absolute value than .75 * eps. + + atanh(x) is the real number v for which tanh(v) = x. It is given by + + atanh(x) = ln((1 + x)/(1 - x))/2 + +EXAMPLE + > print atanh(.5,1e-5), atanh(.5,1e-10), atanh(.5,1e-15), atanh(.5,1e-20) + .54931 .5493061443 .549306144334055 .5493061443340548457 + +LIMITS + none + +LINK LIBRARY + NUMBER *qatanh(NUMBER *x, NUMBER *eps) + +SEE ALSO + asinh, acosh, asech, acsch, acoth, epsilon + diff --git a/help/avg b/help/avg new file mode 100644 index 0000000..66a1857 --- /dev/null +++ b/help/avg @@ -0,0 +1,51 @@ +NAME + avg - average (arithmetic) mean of values + +SYNOPSIS + avg(x_1, x_2, ...) + +TYPES + x_1, ... arithmetic or list + + return as determined by types of items averaged + +DESCRIPTION + If there are n non-list arguments x_1, x_2, ..., x_n, + for which the required additions and division by n are defined, + avg(x_1, x_2, ..., x_n) returns the value of: + + (x_1 + x_2 + ... + x_n)/n. + + If the x_i are real, the result will be a real number; if the + x_i are real or complex numbers, the result will be a real or complex + number. If the x_i are summable matrices the result will be a matrix + of the same size (e.g. if the x_i are all 3 x 4 matrices with real + entries, the result will be a 3 x 4 matrix with real entries). + + If an argument x_i is list-valued, e.g. list(y_1, y_2, ...), this + is treated as contributing y_1, y_2, ... to the list of items to + be averaged. + +EXAMPLE + > print avg(1,2,3,4,5), avg(list(1,2,3,4,5)), avg(1,2,list(3,4,5)) + 3 3 3 + + > mat x[2,2] = {1,2,3,4} + > mat y[2,2] = {1,2,4,8} + > avg(x,y) + + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 3.5 + [1,1] = 6 + +LIMITS + The number of arguments is not to exceed 100. + +LINK LIBRARY + none + +SEE ALSO + hmean + diff --git a/help/base b/help/base new file mode 100644 index 0000000..4cea122 --- /dev/null +++ b/help/base @@ -0,0 +1,83 @@ +NAME + base - set default output base + +SYNOPSIS + base([mode]) + +TYPES + mode real + + return real + +DESCRIPTION + The base function allows one to specify how numbers should be + printed. The base function provides a numeric shorthand to the + config("mode") interface. With no args, base() will return the + current mode. With 1 arg, base(val) will set the mode according to + the arg and return the previous mode. + + The following convention is used to declare modes: + + base equivalent + config("mode")'s + + 2 "binary" base 2 fractions + "bin" + + 8 "octal" base 8 fractions + "oct" + + 10 "real" base 10 floating point + "float" + "default" + + -10 "integer" base 10 integers + "int" + + 16 "hexadecimal" base 16 fractions + "hex" + + 1/3 "fraction" base 10 fractions + "frac" + + 1e20 "scientific" base 10 scientific notation + "sci" + "exp" + + For convenience, any non-integer value is assumed to mean base 10 + fractions and any integer >= 2^64 is assumed to mean base 10 + scientific notation. + + These base() calls have the same meaning as config("mode", "fraction"): + + base(1/3) base(0.1415) base(16/37) + + These base() calls have the same meaning as config("mode", "scientific"): + + base(1e20) base(2^64) base(2^8191-1) + + However the base() function will only return one of the base values + listed in the table above. + +EXAMPLE + > base() + 10 + + > base(8) + 012 + + > print 10 + 012 + +LIMITS + none + +LINK LIBRARY + int math_setmode(int newmode) + + NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT, + MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY + +SEE ALSO + base2, config, str + diff --git a/help/base2 b/help/base2 new file mode 100644 index 0000000..73fdbd6 --- /dev/null +++ b/help/base2 @@ -0,0 +1,95 @@ +NAME + base2 - set 2nd output base + +SYNOPSIS + base2([mode]) + +TYPES + mode real + + return real + +DESCRIPTION + By default, calc will output values according to the default base + as controlled by the base() builtin function. + + The base2() builtin function, if given a non-zero argument, enables + double base output mode. In double base output mode, calc values + are displayed twice, once according to base() and again according + to base2(). In double base output mode, the second time a value is + displayed, it is displayed within comments: + + 21701 /* 0x54c5 */ + + The arguments for base2() are identical to base() with the addition + of the 0 value: + + base2 equivalent + config("mode2")'s + + 2 "binary" base 2 fractions + "bin" + + 8 "octal" base 8 fractions + "oct" + + 10 "real" base 10 floating point + "float" + "default" + + -10 "integer" base 10 integers + "int" + + 16 "hexadecimal" base 16 fractions + "hex" + + 1/3 "fraction" base 10 fractions + "frac" + + 1e20 "scientific" base 10 scientific notation + "sci" + "exp" + + 0 "off" disable double base output + + For convenience, any non-integer non-zero value is assumed to mean + base 10 fractions and any integer >= 2^64 is assumed to mean base 10 + scientific notation. + + These base2() calls have the same meaning as config("mode2", "fraction"): + + base2(1/3) base2(0.1415) base2(16/37) + + These base2() calls have the same meaning as config("mode2", "scientific"): + + base2(1e20) base2(2^64) base2(2^8191-1) + + However the base2() function will only return one of the base values + listed in the table above. + +EXAMPLE + > base2() + 0 + > base2(8) + 0 /* 0 */ + > print 10 + 10 /* 012 */ + > base2(16), + > 131072 + 131072 /* 0x20000 */ + > 2345 + 2345 /* 0x929 */ + +LIMITS + none + +LINK LIBRARY + int math_setmode2(int newmode) + + NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT, + MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY, + MODE2_OFF + +SEE ALSO + base, config, str + diff --git a/help/bernoulli b/help/bernoulli new file mode 100644 index 0000000..1875bb7 --- /dev/null +++ b/help/bernoulli @@ -0,0 +1,43 @@ +NAME + bernoulli - Bernoulli number + +SYNOPSIS + bernoulli(n) + +TYPES + n integer, n < 2^31 if even + + return rational + +DESCRIPTION + Returns the Bernoulli number with index n, i.e. the coefficient B_n in + the expansion + + t/(exp(t) - 1) = Sum B_n * t^n/n! + + bernoulli(n) is zero both for n < 0 and for n odd and > 2. + When bernoulli(n) is computed for positive even n, the values for + n and smaller positive even indices are stored in a table so that + a later call to bernoulli(k) with 0 <= k < n will be executed quickly. + + Considerable runtime and memory are required for calculating + bernoulli(n) for large even n. For n = 1000, the numerator has + 1779 digits, the denominator 9 digits. + + The memory used to store calculated bernoulli numbers is freed by + freebernoulli(). + +EXAMPLE + > config("mode", "frac"),; + > for (n = 0; n <= 6; n++) print bernoulli(n),; print; + 1 -1/2 1/6 0 -1/30 0 1/42 + +LIMITS + n < 2^31-1 + +LIBRARY + NUMBER *qbernoulli(long n) + +SEE ALSO + euler, catalan, comb, fact, perm + diff --git a/help/bit b/help/bit new file mode 100644 index 0000000..fd33c18 --- /dev/null +++ b/help/bit @@ -0,0 +1,44 @@ +NAME + bit - whether a given binary bit is set in a value + +SYNOPSIS + bit(x, y) + +TYPES + x real + y int + + return int + +DESCRIPTION + Determine if the binary bit y is set in x. If: + + x + int(---) mod 2 == 1 + 2^y + + return 1, otherwise return 0. + +EXAMPLE + > print bit(9,0), bit(9,1), bit(9,2), bit(9,3) + 1 0 0 1 + + > print bit(9,4), bit(0,0), bit(9,-1) + 0 0 0 + + > print bit(1.25, -2), bit(1.25, -1), bit(1.25, 0) + 1 0 1 + + > p = pi() + > print bit(p, 1), bit(p, -2), bit(p, -3) + 1 0 1 + +LIMITS + -2^31 < y < 2^31 + +LINK LIBRARY + BOOL qbit(NUMBER *x, long y) + +SEE ALSO + highbit, lowbit, digit + diff --git a/help/blk b/help/blk new file mode 100644 index 0000000..67d3d07 --- /dev/null +++ b/help/blk @@ -0,0 +1,220 @@ +NAME + blk - generate or modify block values + +SYNOPSIS + blk([len, chunk]); + blk(val [, len, chunk]); + +TYPES + len null or integer + chunk null or integer + val non-null string, block, or named block + + return block or named block + +DESCRIPTION + With only integer arguments, blk(len, chunk) attempts to + allocate a block of memory consisting of N octets (unsigned 8-bit + bytes). Allocation is always done in multiples of chunk + octets, so the actual allocation size of len rounded up + to the next multiple of chunk. + + The default value for len is 0. The default value for chunk is 256. + + If the allocation is successful, blk(len, chunk) returns a value B, say, + for which the octets in the block may be referenced by B[0], B[1], + ... , B[len-1], these all initially having zero value. + + The octets B[i] for i >= len always have zero value. If B[i] with + some i >= len is referenced, len is increased by 1. For example: + + B[i] = x + + has an effect like that of two operations on a file stream fs: + + fseek(fs, pos); + fputc(fs, x). + + Similarly: + + x = B[i] + + is like: + + fseek(fs, pos); + x = fgetc(fs). + + The value of chunk is stored as the "chunksize" for B. + + The size(B) builtin returns the current len for the block; sizeof(B) + returns its maxsize; memsize(B) returns maxsize + overhead for any block + value. Also size(B) is analogous to the length of a file stream in that + if size(B) < sizeof(B): + + B[size(B)] = x + + will append one octet to B and increment size(B). + + The builtin test(B) returns 1 or 0 according as at least one octet + is zero or all octets are zero. If B1 and B2 are blocks, they are + considered equal (B1 == B2) if they have the same length and the + same data, i.e. B1[i] == B2[i] for 0 <= i < len. Chunksizes + and maxsizes are ignored. + + The output for print B occupies two lines, the first line giving + the chunksize, number of octets allocated (len rounded up to the + next chunk) and len, and the second line up to 30 octets of data. + If the datalen is zero, the second line is blank. If the datalen + exceeds 30, this indicated by a trailing "...". + + If a block value B created by B = blk(len, chunk) is assigned to + another variable by C = B, a new block of the same structure as B + is created to become the value of C, and the octets in B are copied + to this new block. A block with possibly different length or + chunksize is created by C = blk(B, newlen, newchunk), only the first + min(len, newlen) octets being copied from B; later octets are + assigned zero value. If omitted, newlen and newchunk default to + the current datalen and chunk-size for B. The current datalen, + chunksize and number of allocated octets for B may be changed by: + + B = blk(B, newlen, newchunk). + + No data is lost if newlen is greater than or equal to the old + size(B). + + The memory block allocated by blk(len, chunk) is freed at or before + termination of the statement in which this occurred, the memory + allocated in B = blk(len, chunk) is freed when B is assigned another + value. + + With a string str as its first argument, blk(str [, len, chunk]) + when called for the first time creates a block with str as its + name. Here there no restriction on the characters used in str; + thus the string may include white space or characters normally used + for punctuation or operators. Any subsequent call to blk(str, ...) + with the same str will refer to the same named block. + + A named block is assigned length and chunksize and consequent + maximum size in the same way as unnamed blocks. A major difference + is that in assignments, a named block is not copied. Thus, if a + block A has been created by: + + A = blk("foo") + any subsequent: + B = A + or: + B = blk("foo") + + will give a second variable B referring to the same block as A. + Either A[i] = x or B[i] = x may then be used to assign a value + to an octet in the book. Its length or chunksize may be changed by + instructions like: + + blk(A, len, chunk); + + A = blk(A, len, chunk); + + null(blk(A, len, chunk)). + + These have the same effect on A; when working interactively, the + last two avoid printing of the new value for A. + + Named blocks are assigned index numbers 0, 1, 2, ..., in the order + of their creation. The block with index id is returned by blocks(id). + With no argument, blocks() returns the number of current unfreed + named blocks. + + The memory allocated to a named block is freed by the blkfree() + function with argument the named block, its name, or its id number. + The block remains in existence but with a null data pointer, + its length and size being reduced to zero. A new block of memory + may be allocated to it, with possibly new length and chunksize by: + + blk(val [, len, chunk]) + + where val is either the named block or its name. + + The printing output for a named block is in three lines, the first + line displaying its id number and name, the other two as for an + unnamed block, except that "NULL" is printed if the memory has been + freed. + + The identifying numbers and names of the current named blocks are + displayed by: + show blocks + + If A and B are named blocks, A == B will be true only if they refer + to the same block of memory. Thus, blocks with the same data and + datalen will be considered unequal if they have different names. + + If A is a named block, str(A) returns the name of the block. + + Values may be assigned to the early octets of a named or unnamed + block by use of = { } initialization as for matrices. + +EXAMPLE + + > B = blk(15,10) + + > B[7] = 0xff + > B + chunksize = 10, maxsize = 20, datalen = 15 + 00000000000000ff00000000000000 + + > B[18] = 127 + > B + chunksize = 10, maxsize = 20, datalen = 18 + 00000000000000ff0000000000000000007f + + > B[20] = 2 + Index out of bounds for block + + > print size(B), sizeof(B) + 18 20 + + > B = blk(B, 100, 20) + > B + chunksize = 20, maxsize = 120, datalen = 100 + 00000000000000ff0000000000000000007f000000000000000000000000... + + > C = blk(B, 10} = {1,2,3} + > C + chunksize = 20, maxsize = 20, datalen = 10 + 01020300000000ff0000 + + > A1 = blk("alpha") + > A1 + block 0: alpha + chunksize = 256, maxsize = 256, datalen = 0 + + > A1[7] = 0xff + > A2 = A1 + > A2[17] = 127 + > A1 + block 0: alpha + chunksize = 256, maxsize = 256, datalen = 18 + 00000000000000ff0000000000000000007f + + > A1 = blk(A1, 1000) + > A1 + block 0: alpha + chunksize = 256, maxsize = 1024, datalen = 1000 + 00000000000000ff0000000000000000007f000000000000000000000000... + + > A1 = blk(A1, , 16) + > A1 + block 0: alpha + chunksize = 16, maxsize = 1008, datalen = 1000 + 00000000000000ff0000000000000000007f000000000000000000000000... + +LIMITS + 0 <= len < 2^31 + + 1 <= chunk < 2^31 + +LINK LIBRARY + XXX + +SEE ALSO + blocks, blkfree + diff --git a/help/blkcpy b/help/blkcpy new file mode 100644 index 0000000..a16f031 --- /dev/null +++ b/help/blkcpy @@ -0,0 +1,193 @@ +NAME + blkcpy, copy - copy items from a structure to a structure + +SYNOPSIS + blkcpy(dst, src [, num [, dsi [, ssi]]] + copy(src, dest [, [ssi [, num [, dsi]]]) + +TYPES + src block, file, string, matrix, or list + dest block, file, matrix or list - compatible with src + + ssi nonnegative integer, defaults to zero + num nonnegative integer, defaults to maximum possible + dsi nonnegative integer, defaults to datalen for a block, filepos + for a file, zero for other structures + + return null if successful, error value otherwise + +DESCRIPTION + A call to: + + blkcpy(dst, src, num, dsi, ssi) + + attempts to copy 'num' consecutive items (octets or values) starting + from the source item 'src' with index 'ssi'. By default, 'num' + is the maximum possible and 'ssi' is 0. + + A call to: + + copy(src, dst, ssi, num, dsi) + + does the same thing, but with a different arg order. + + A copy fails if ssi or num is too large for the number of items in + the source, if sdi is too large for the number of positions + available in the destination, or, in cases involving a file stream, + if the file is not open in the required mode. The source and + destination need not be of the same type, e.g. when a block is + copied to a matrix the octets are converted to numbers. + + The following pairs of source-type, destination-type are permitted: + + block to + int + block + matrix + file + + matrix to + block + matrix + list + + string to + block + file + + list to + list + matrix + + file to + block + + int to + block + + In the above table, int refers to integer values. However if a + rational value is supplied, only the numerator is copied. + + Each copied octet or value replaces the octet or value in the + corresponding place in the destination structure. When copying values + to values, the new values are stored in a buffer, the old values are + removed, and the new values copied from the buffer to the destination. + This permits movement of data within one matrix or list, and copying + of an element of structure to the structure. + + Except for copying to files or blocks, the destination is already to have + sufficient memory allocated for the copying. For example, to copy + a matrix M of size 100 to a newly created list, one may use: + + L = makelist(100); + copy(M, L); + or: + L = makelist(100); + blkcpy(L, M); + + For copying from a block B (named or unnamed), the total number of octets + available for copying is taken to the the datalen for that block, + so that num can be at most size(B) - ssi. + + For copying to a block B (named or unnamed), reallocation will be + required if dsi + num > sizeof(B). (This will not be permitted if + protect(B) has bit 4 set.) + + For copying from a file stream fs, num can be at most size(fs) - ssi. + + For copying from a string str, the string is taken to include the + terminating '\0', so the total number of octets available is + strlen(str) + 1 and num can be at most strlen(str) + 1 - ssi. + If num <= strlen(str) - ssi, the '\0' is not copied. + + For copying from or to a matrix M, the total number of values in + M is size(M), so in the source case, num <= size(M) - ssi, and + in the destination case, num <= size(M) - dsi. The indices ssi + and dsi refer to the double-bracket method of indexing, i.e. the + matrix is as if its elements were indexed 0, 1, ..., size(M) - 1. + + +EXAMPLE + > A = blk() = {1,2,3,4} + > B = blk() + > blkcpy(B,A) + > B + chunksize = 256, maxsize = 256, datalen = 4 + 01020304 + > + > blkcpy(B,A) + > B + chunksize = 256, maxsize = 256, datalen = 8 + 0102030401020304 + > blkcpy(B, A, 2, 10) + > B + chunksize = 256, maxsize = 256, datalen = 12 + 010203040102030400000102 + > blkcpy(B,32767) + > B + chunksize = 256, maxsize = 256, datalen = 16 + 010203040102030400000102ff7f0000 + > mat M[2,2] + > blkcpy(M, A) + > M + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 3 + [1,1] = 4 + > blkcpy(M, A, 2, 2) + > M + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 1 + [1,1] = 2 + + > A = blk() = {1,2,3,4} + > B = blk() + > copy(A,B) + > B + chunksize = 256, maxsize = 256, datalen = 4 + 01020304 + > copy(A,B) + > B + chunksize = 256, maxsize = 256, datalen = 8 + 0102030401020304 + > copy(A,B,1,2) + > B + chunksize = 256, maxsize = 256, datalen = 10 + 01020304010203040203 + > mat M[2,2] + > copy(A,M) + > M + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 3 + [1,1] = 4 + + > copy(A,M,2) + > M + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 3 + [0,1] = 4 + [1,0] = 3 + [1,1] = 4 + + > copy(A,M,0,2,2) + > M + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 3 + [0,1] = 4 + [1,0] = 1 + [1,1] = 2 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + blk, mat, file, list, str + diff --git a/help/blkfree b/help/blkfree new file mode 100644 index 0000000..c4380ce --- /dev/null +++ b/help/blkfree @@ -0,0 +1,59 @@ +NAME + blkfree - free memory allocated to named block + +SYNOPSIS + blkfree(val) + +TYPES + val named block, string, or integer + + return null value + +DESCRIPTION + If val is a named block, or the name of a named block, or the + identifying index for a named block, blkfree(val) frees the + memory block allocated to this named block. The block remains + in existence with the same name, identifying index, and chunksize, + but its size and maxsize becomes zero and the pointer for the start + of its data block null. + + A new block of memory may be allocated to a freed block B by + blk(B [, len, chunk]), len defaulting to zero and chunk to the + chunksize when the block was freed. + +EXAMPLE + + > B1 = blk("foo") + > B2 = blk("Second block") + show blocks + id name + ---- ----- + 0 foo + 1 Second block + + > blkfree(B1) + > show blocks + id name + ---- ----- + 1 Second block + + > B1 + block 0: foo + chunksize = 256, maxsize = 0, datalen = 0 + NULL + + > blk(B1); B[7] = 5 + > B1 + block 0: foo + chunksize = 256, maxsize = 256, datalen = 8 + 0000000000000005 + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + blk, blocks + diff --git a/help/blocks b/help/blocks new file mode 100644 index 0000000..7ea9785 --- /dev/null +++ b/help/blocks @@ -0,0 +1,44 @@ +NAME + blocks - return a named block or number of unfreed named blocks + +SYNOPSIS + blocks([id]) + +TYPES + id non-negative integer + + return named block or null value + +DESCRIPTION + With no argument blocks() returns the number of blocks that have + been created but not freed by the blkfree function. + + With argument id less than the number of named blocks that have been + created, blocks(id) returns the named block with identifying index id. + These indices 0, 1, 2, ... are assigned to named blocks in the order + of their creation. + +EXAMPLE + + > A = blk("alpha") + > B = blk("beta") = {1,2,3} + > blocks() + 2 + > blocks(1) + block 1: beta + chunksize = 256, maxsize = 256, datalen = 3 + 010203 + > blocks(2) + Error 10211 + > strerror() + "Non-allocated index number for blocks" + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + blk, blkfree + diff --git a/help/bround b/help/bround new file mode 100644 index 0000000..da8eafb --- /dev/null +++ b/help/bround @@ -0,0 +1,124 @@ +NAME + bround - round numbers to a specified number of binary digits + +SYNOPSIS + bround(x [,plcs [, rnd]]) + +TYPES + If x is a matrix or a list, bround(x[[i]], ...) is to return + a value for each element x[[i]] of x; the value returned will be + a matrix or list with the same structure as x. + + Otherwise, if x is an object of type tt, or if x is not an object or + number but y is an object of type tt, and the function tt_bround has + to be defined; the types for x, plcs, rnd, and the returned value, + if any, are as required for specified in tt_bround. For the object + case, plcs and rnd default to the null value. + + For other cases: + + x number (real or complex) + plcs integer, defaults to zero + rnd integer, defaults to config("round") + + return number + +DESCRIPTION + For real x, bround(x, plcs, rnd) returns x rounded to either + plcs significant binary digits (if rnd & 32 is nonzero) or to plcs + binary places (if rnd & 32 is zero). In the significant-figure + case the rounding is to plcs - ilog10(x) - 1 binary places. + If the number of binary places is n and eps = 10^-n, the + result is the same as for appr(x, eps, rnd). This will be + exactly x if x is a multiple of eps; otherwise rounding occurs + to one of the nearest multiples of eps on either side of x. Which + of these multiples is returned is determined by z = rnd & 31, i.e. + the five low order bits of rnd, as follows: + + z = 0 or 4: round down, i.e. towards minus infinity + z = 1 or 5: round up, i.e. towards plus infinity + z = 2 or 6: round towards zero + z = 3 or 7: round away from zero + z = 8 or 12: round to the nearest even multiple of eps + z = 9 or 13: round to the nearest odd multiple of eps + z = 10 or 14: round to nearest even or odd multiple of eps + according as x > or < 0 + z = 11 or 15: round to nearest odd or even multiple of eps + according as x > or < 0 + z = 16 to 31: round to the nearest multiple of eps when + this is uniquely determined. Otherwise + rounding is as if z is replaced by z - 16 + + For complex x: + + The real and imaginary parts are rounded as for real x; if the + imaginary part rounds to zero, the result is real. + + For matrix or list x: + + The returned values has element bround(x[[i]], plcs, rnd) in + the same position as x[[i]] in x. + + For object x or plcs: + + When bround(x, plcs, rnd) is called, x is passed by address so may be + changed by assignments; plcs and rnd are copied to temporary + variables, so their values are not changed by the call. + +EXAMPLES + > a = 7/32, b = -7/32 + + > print a, b + .21875 -.21875 + + > print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) + .218, .219, .218, .219 + + > print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) + -.219, -.218, -.218, -.219 + + > print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) + .2188 .2188 .2188 .2188 + + > print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) + .2187 .2188 .2187 .2188 + + > print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) + .22 .218 .2188 .21875 + + > print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) + .22 .219 .2188 .21875 + + > c = 21875 + > print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) + 21800 21900 21000 22000 + + > print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) + 21000 22000 22000 21880 + + > A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) + > print round(A,2,24) + + list(7 elements, 7 nonzero): + [[0]] = .12 + [[1]] = .25 + [[3]] = .38 + [[4]] = .5 + [[5]] = .62 + [[6]] = .75 + [[7]] = .88 + +LIMITS + For non-object case: + 0 <= abs(plcs) < 2^31 + 0 <= abs(rnd) < 2^31 + +LINK LIBRARY + void broundvalue(VALUE *x, VALUE *plcs, VALUE *rnd, VALUE *result) + MATRIX *matbround(MATRIX *m, VALUE *plcs, VALUE *rnd); + LIST *listbround(LIST *m, VALUE *plcs, VALUE *rnd); + NUMBER *qbround(NUMBER *m, long plcs, long rnd); + +SEE ALSO + round, trunc, btrunc, int, appr + diff --git a/help/btrunc b/help/btrunc new file mode 100644 index 0000000..a10c64d --- /dev/null +++ b/help/btrunc @@ -0,0 +1,45 @@ +NAME + btrunc - truncate a value to a number of binary places + +SYNOPSIS + btrunc(x [,plcs]) + +TYPES + x real + plcs integer, defaults to zero + + return real + +DESCRIPTION + Truncate x to plcs binary places, rounding if necessary towards zero, + i.e. btrunc(x, plcs) is a multiple of 2^-plcs and the remainder + x - btrunc(x, plcs) is either zero or has the same sign as x and + absolute value less than 2^-plcs. Here plcs may be positive, zero or + negative. + + Except that it is defined only for real x, btrunc(x, plcs) is equivalent + to bround(x, plcs, 2). btrunc(x,0) and btrunc(x) are equivalent to + int(x). + +EXAMPLE + > print btrunc(pi()), btrunc(pi(), 10) + 3 3.140625 + + > print btrunc(3.3), btrunc(3.7), btrunc(3.3, 2), btrunc(3.7, 2) + 3 3 3.25 3.5 + + > print btrunc(-3.3), btrunc(-3.7), btrunc(-3.3, 2), btrunc(-3.7, 2) + -3 -3 -3.25 -3.5 + + > print btrunc(55.123, -4), btrunc(-55.123, -4) + 48 -48 + +LIMITS + abs(j) < 2^31 + +LINK LIBRARY + NUMBER *qbtrunc(NUMBER *x, *j) + +SEE ALSO + bround, int, round, trunc + diff --git a/help/calc_tty b/help/calc_tty new file mode 100644 index 0000000..17b6ffa --- /dev/null +++ b/help/calc_tty @@ -0,0 +1,28 @@ +NAME + calc_tty - restore normal input conditions for interactive use + +SYNOPSIS + calc_tty() + +TYPES + return none if appears to be successful, error-value otherwise + +DESCRIPTION + This may enable a return to normal operation if abnormal activity + results from a change of one or more terminal characteristics, as + may occur when activity is resumed by an fg command after a ctrl-Z + interrupt, or by any of the three commands: + + > !stty echo + > !stty -cbreak + > !stty echo -cbreak + +EXAMPLE + > calc_tty(); + +LIBRARY + none + +SEE ALSO + none + diff --git a/help/calclevel b/help/calclevel new file mode 100644 index 0000000..b70ffe7 --- /dev/null +++ b/help/calclevel @@ -0,0 +1,36 @@ +NAME + calclevel - current calculation level + +SYNOPSIS + calclevel() + +TYPES + return nonnegative integer + +DESCRIPTION + This function returns the calculation level at which it is called. + When a command is being read from a terminal or from a file, + calc is at calculation level zero. The level is increased + by 1 each time calculation starts of a user-defined function + or of eval(S) for some expression S which evaluates to a string. It + decreases to zero if an error occurs or a quit or abort statement + is executed. Otherwise, it decreases by 1 when the calculation + is completed. Except when an error occurs or abort is executed, + the input level is not affected by changes in the calculation level. + + Zero calculation level is also called top calculation level; greater + values of calclevel() indicate calculation is occurring at greater + depths. + +EXAMPLE + n/a + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + eval, read, quit, abort, inputlevel + diff --git a/help/catalan b/help/catalan new file mode 100644 index 0000000..91441d5 --- /dev/null +++ b/help/catalan @@ -0,0 +1,39 @@ +NAME + catalan - Catalan number + +SYNOPSIS + catalan(n) + +TYPES + n integer + + return integer + +DESCRIPTION + If n >= 0, this returns the Catalan number for index n: + + catalan(n) = comb(2*n,n)/(n + 1) + + Zero is returned for negative n. + + The Catalan numbers occur in solutions of several elementary + combinatorial problems, e.g. for n >= 1, catalan(n) is the number of + ways of using parentheses to express a product of n + 1 letters in + terms of binary products; it is the number of ways of dissecting a + convex polygon with n + 2 sides into triangles by nonintersecting + diagonals; it is the number of integer-component-incrementing paths + from (x,y) = (0,0) to (x,y) = (n,n) for which always y <= x. + +EXAMPLE + > print catalan(2), catalan(3), catalan(4), catalan(20) + 2 5 14 6564120420 + +LIMITS + none + +LINK LIBRARY + NUMBER *qcatalan(NUMBER *n) + +SEE ALSO + comb, fact, perm + diff --git a/help/ceil b/help/ceil new file mode 100644 index 0000000..feb5da5 --- /dev/null +++ b/help/ceil @@ -0,0 +1,34 @@ +NAME + ceil - ceiling + +SYNOPSIS + ceil(x) + +TYPES + x real, complex, list, matrix + + return real or complex, list, matrix + +DESCRIPTION + For real x, ceil(x) is the least integer not less than x. + + For complex, ceil(x) returns the real or complex number v for + which re(v) = ceil(re(x)), im(v) = ceil(im(x)). + + For list or matrix x, ceil(x) returns the list or matrix of the + same structure as x for which each element t of x has been replaced + by ceil(t). + +EXAMPLE + > print ceil(27), ceil(1.23), ceil(-4.56), ceil(7.8 - 9.1i) + 27 2 -4 8-9i + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + floor, int + diff --git a/help/cfappr b/help/cfappr new file mode 100644 index 0000000..572b3f4 --- /dev/null +++ b/help/cfappr @@ -0,0 +1,90 @@ +NAME + cfappr - approximate a real number using continued fractions + +SYNOPSIS + cfappr(x [,eps [,rnd]]) or cfappr(x, n [,rnd]) + +TYPES + x real + eps real with abs(eps) < 1, defaults to epsilon() + n real with n >= 1 + rnd integer, defaults to config("cfappr") + + return real + +DESCRIPTION + If x is an integer or eps is zero, either form returns x. + + If abs(eps) < 1, cfappr(x, eps) returns the smallest-denominator + number in one of the three intervals, [x, x + abs(eps)], + [x - abs(eps], x], [x - abs(eps)/2, x + abs(eps)/2]. + + If n >= 1 and den(x) > n, cfappr(x, n) returns the nearest above, + nearest below, or nearest, approximation to x with denominator less + than or equal to n. If den(x) <= n, cfappr(x,n) returns x. + + In either case when the result v is not x, how v relates to x is + determined by bits 0, 1, 2 and 4 of the argument rnd in the same way as + these bits are used in the functions round() and appr(). In the + following y is either eps or n. + + rnd sign of remainder x - v + + 0 sgn(y) + 1 -sgn(y + 2 sgn(x), "rounding to zero" + 3 -sgn(x), "rounding from zero" + 4 +, "rounding down" + 5 -, "rounding up" + 6 sgn(x/y) + 7 -sgn(x/y) + + If bit 4 of rnd is set, the other bits are irrelevant for the eps case; + thus for 16 <= rnd < 24, cfappr(x, eps, rnd) is the smallest-denominator + number differing from x by at most abs(eps)/2. + + If bit 4 of rnd is set and den(x) > 2, the other bits are irrelevant for + the bounded denominator case; in the case of two equally near nearest + approximations with denominator less than n, cfappr(x, n, rnd) + returns the number with smaller denominator. If den(x) = 2, bits + 0, 1 and 2 of rnd are used as described above. + + If -1 < eps < 1, cfappr(x, eps, 0) may be described as the smallest + denominator number in the closed interval with end-points x and x - eps. + It follows that if abs(a - b) < 1, cfappr(a, a - b, 0) gives the smallest + denominator number in the interval with end-points a and b; the same + result is returned by cfappr(b, b - a, 0) or cfappr(a, b - a, 1). + + If abs(eps) < 1 and v = cfappr(x, eps, rnd), then + cfappr(x, sgn(eps) * den(v), rnd) = v. + + If 1 <= n < den(x), u = cfappr(x, n, 0) and v = cfappr(x, n, 1), then + u < x < v, den(u) <= n, den(v) <= n, den(u) + den(v) > n, and + v - u = 1/(den(u) * den(v)). + + If x is not zero, the nearest approximation with numerator not + exceeding n is 1/cfappr(1/x, n, 16). + +EXAMPLE + > c = config("mode", "frac") + > x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1); + > print u, v, x - u, v - x, v - u, cfappr(x, 10, 16) + 10/7 13/9 1/210 1/90 1/63 10/7 + + > pi = pi(1e-10) + > print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16) + 311/99 22/7 355/113 + + > x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1); + > print u, v, x - u, v - x, cfappr(x,4,16) + 4/3 3/2 1/12 1/12 3/2 + +LIMITS + none + +LINK LIBRARY + NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R) + +SEE ALSO + appr, cfsim + diff --git a/help/cfsim b/help/cfsim new file mode 100644 index 0000000..cf76d5d --- /dev/null +++ b/help/cfsim @@ -0,0 +1,115 @@ +NAME + cfsim - simplify a value using continued fractions + +SYNOPSIS + cfsim(x [,rnd]) + +TYPES + x real + rnd integer, defaults to config("cfsim") + + return real + +DESCRIPTION + If x is not an integer, cfsim(x, rnd) returns either the nearest + above x, or the nearest below x, number with denominator less than + den(x). If x is an integer, cfsim(x, rnd) returns x + 1, x - 1, or 0. + Which of the possible results is returned is controlled + by bits 0, 1, 3 and 4 of the parameter rnd. + + For 0 <= rnd < 4, the sign of the remainder x - cfsim(x, rnd) is + as follows: + + rnd sign of x - cfsim(x, rnd) + + 0 +, as if rounding down + 1 -. as if rounding up + 2 sgn(x), as if rounding to zero + 3 -sgn(x), as if rounding from zero + + This corresponds to the use of rnd for functions like round(x, n, rnd). + + If bit 3 or 4 of rnd is set, the lower order bits are ignored; bit 3 + is ignored if bit 4 is set. Thusi, for rnd > 3, it sufficient to + consider the two cases rnd = 8 and rnd = 16. + + If den(x) > 2, cfsim(x, 8) returns the value of the penultimate simple + continued-fraction approximant to x, i.e. if: + + x = a_0 + 1/(a_1 + 1/(a_2 + ... + 1/a_n) ...)), + + where a_0 is an integer, a_1, ..., a_n are positive integers, + and a_n >= 2, the value returned is that of the continued fraction + obtained by dropping the last quotient 1/a_n. + + If den(x) > 2, cfsim(x, 16) returns the nearest number to x with + denominator less than den(x). In the continued-fraction representation + of x described above, this is given by replacing a_n by a_n - 1. + + If den(x) = 2, the definition adopted is to round towards zero for the + approximant case (rnd = 8) and from zero for the "nearest" case (rnd = 16). + + For integral x, cfsim(x, 8) returns zero, cfsim(x,16) returns x - sgn(x). + + In summary, for cfsim(x, rnd) when rnd = 8 or 16, the results are: + + rnd integer x half-integer x den(x) > 2 + + 8 0 x - sgn(x)/2 approximant + 16 x - sgn(x) x + sgn(x)/2 nearest + + From either cfsim(x, 0) and cfsim(x, 1), the other is easily + determined: if one of them has value w, the other has value + (num(x) - num(w))/(den(x) - den(w)). From x and w one may find + other optimal rational numbers near x; for example, the smallest- + denominator number between x and w is (num(x) + num(w))/(den(x) + den(w)). + + If x = n/d and cfsim(x, 8) = u/v, then for k * v < d, the k-th member of + the sequence of nearest approximations to x with decreasing denominators + on the other side of x is (n - k * u)/(d - k * v). This is nearer + to or further from x than u/v according as 2 * k * v < or > d. + + Iteration of cfsim(x,8) until an integer is obtained gives a sequence of + "good" approximations to x with decreasing denominators and + correspondingly decreasing accuracy; each denominator is less than half + the preceding denominator. (Unlike the "forward" sequence of + continued-fraction approximants these are not necessarily alternately + greater than and less than x.) + + Some other properties: + + For rnd = 0 or 1 and any x, or rnd = 8 or 16 and x with den(x) > 2: + + cfsim(n + x, rnd) = n + cfsim(x, rnd). + + This equation also holds for the other values of rnd if n + x and x + have the same sign. + + For rnd = 2, 3, 8 or 16, and any x: + + cfsim(-x, rnd) = -cfsim(x, rnd). + + If rnd = 8 or 16, except for integer x or 1/x for rnd = 8, and + zero x for rnd = 16: + + cfsim(1/x, rnd) = 1/cfsim(x, rnd). + +EXAMPLE + > c = config("mode", "frac"); + + > print cfsim(43/30, 0), cfsim(43/30, 1), cfsim(43/30, 8), cfsim(43/30,16) + 10/7 33/23 10/7 33/23 + + > x = pi(1e-20); c = config("mode", "frac"); + > while (!isint(x)) {x = cfsim(x,8); if (den(x) < 1e6) print x,:;} + 1146408/364913 312689/99532 104348/33215 355/113 22/7 3 + +LIMITS + none + +LINK LIBRARY + NUMBER *qcfsim(NUMBER *x, long rnd) + +SEE ALSO + cfappr + diff --git a/help/char b/help/char new file mode 100644 index 0000000..0ed5be7 --- /dev/null +++ b/help/char @@ -0,0 +1,28 @@ +NAME + char - character corresponding to a value + +SYNOPSIS + char(j) + +TYPES + j integer, 0 <= j < 256 + + return string + +DESCRIPTION + For j > 0, returns a string of length 1 with a character that has + the same value as j. For j = 0, returns the null string "". + +EXAMPLE + > print char(0102), char(0x6f), char(119), char(0145), char(0x6e) + B o w e n + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + ord + diff --git a/help/cmdbuf b/help/cmdbuf new file mode 100644 index 0000000..7c6a603 --- /dev/null +++ b/help/cmdbuf @@ -0,0 +1,30 @@ +NAME + cmdbuf - print the command buffer + +SYNOPSIS + cmdbuf() + +TYPES + return str + +DESCRIPTION + This function returns the command string that was formed by calc based + on its command line arguments. If calc was invoked without arguments, + this function will return an empty string. + +EXAMPLE + % calc "print cmdbuf(); a = 3; print a^2;" + print cmdbuf(); a = 3; print a^2; + + 9 + % + +LIMITS + none + +LINK LIBRARY + none + +SEE ALSO + XXX - fill in + diff --git a/help/cmp b/help/cmp new file mode 100644 index 0000000..696abed --- /dev/null +++ b/help/cmp @@ -0,0 +1,116 @@ +NAME + cmp - compare two values of certain simple or object types + +SYNOPSIS + cmp(x, y) + +TYPES + If x is an object of type xx, or x is not an object and y is an object + of type xx, the function xx_rel has to have been defined; any + further conditions on x and y, and the type of the returned + value depends on the definition of xx_rel. + + For non-object x and y: + + x any + y any + + return if x and y are both real: -1, 0, or 1 + if x and y are both numbers but not both real: + -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i, or 1-1i + if x and y are both strings: -1, 0, or 1 + all other cases: the null value + +DESCRIPTION + + x and y both real: cmp(x, y) = sgn(x - y), i.e. -1, 0, or 1 + according as x < y, x == y, or x > y + + x and y both numbers, at least one being complex: + cmp(x,y) = sgn(re(x) - re(y)) + sgn(im(x) - im(y)) * 1i + + x and y both strings: successive characters are compared until either + different characters are encountered or at least one string is + completed. If the comparison ends because of different characters, + cmp(x,y) = 1 or -1 according as the greater character is in x or y. + If all characters compared in both strings are equal, then + cmp(x,y) = -1, 0 or 1 according as the length of x is less than, + equal to, or greater than the length of y. (This comparison + is performed via the strcmp() libc function.) + + objects: comparisons of objects are usually intended for some total or + partial ordering and appropriate definitions of cmp(a,b) may + make use of comparison of numerical or string components. + definitions using comparison of numbers or strings are usually + appropriate. For example, after + + obj point {x,y}; + + if points with real components are to be partially ordered by their + euclidean distance from the origin, an appropriate point_rel + function may be that given by + + define point_rel(a,b) = sgn(a.x^2 + a.y^2 - b.x^2 - b.y^2); + + A total "lexicographic" ordering is that given by: + + define point_rel(a,b) { + if (a.y != b.y) + return sgn(a.y - b.y); + return (a.x - b.x); + } + + A comparison function that compares points analogously to + cmp(a,b) for real and complex numbers is that given by + + define point_rel(P1, P2) { + return obj point = {sgn(P1.x-P2.x), sgn(P1.y-P2.y)}; + } + + The range of this function is the set of nine points with zero + or unit components. + + + Some properties of cmp(a,b) for real or complex a and b are: + + cmp(a + c, b + c) = cmp(a, b) + + cmp(a, b) == 0 if and only if a == b + + cmp(b, a) = -cmp(a, b) + + if c is real or pure imaginary, cmp(c * a, c * b) = c * cmp(a,b) + + Then a function that defines "b is between a and c" in an often useful + sense is + + define between(a,b,c) = (cmp(a,b) == cmp(b,c)). + + For example, in this sense, 3 + 4i is between 1 + 5i and 4 + 2i. + + Note that using cmp to compare non-object values of different types, + for example, cmp(2, "2"), returns the null value. + +EXAMPLE + > print cmp(3,4), cmp(4,3), cmp(4,4), cmp("a","b"), cmp("abcd","abc") + -1 1 0 -1 1 + + > print cmp(3,4i), cmp(4,4i), cmp(5,4i), cmp(-5,4i), cmp(-4i,5), cmp(-4i,-5) + 1-1i 1-1i 1-1i -1-1i -1-1i 1-1i + + > print cmp(3i,4i), cmp(4i,4i), cmp(5i,4i), cmp(3+4i,5), cmp(3+4i,-5) + -1i 0 1i -1+1i 1+1i + + > print cmp(3+4i,3+4i), cmp(3+4i,3-4i), cmp(3+4i,2+3i), cmp(3+4i,-4-5i) + 0 1i 1+1i 1+1i + +LIMITS + none + +LINK LIBRARY + FLAG qrel(NUMBER *q1, NUMBER *q2) + FLAG zrel(ZVALUE z1, ZVALUE z2) + +SEE ALSO + sgn, test, operator + diff --git a/help/comb b/help/comb new file mode 100644 index 0000000..bbb34b5 --- /dev/null +++ b/help/comb @@ -0,0 +1,40 @@ +NAME + comb - combinatorial number + +SYNOPSIS + comb(x, y) + +TYPES + x integer + y integer + + return integer + +DESCRIPTION + Return the combinatorial number C(x,y) which is defined as: + + x! + --------- + y!*(x-y)! + + This function computes the number of combinations in which y things + may be chosen from x items ignoring the order in which they are chosen. + +EXAMPLE + > print comb(7,3), comb(7,4), comb(7,5), comb(3,0), comb(0,0) + 35 35 21 1 1 + + > print comb(2^31+1,2^31-1) + 2305843010287435776 + +LIMITS + x >= y >= 0 + y < 2^24 + x-y < 2^24 + +LINK LIBRARY + void zcomb(ZVALUE x, ZVALUE y, ZVALUE *res) + +SEE ALSO + fact, perm + diff --git a/help/conj b/help/conj new file mode 100644 index 0000000..09f9a42 --- /dev/null +++ b/help/conj @@ -0,0 +1,42 @@ +NAME + conj - complex conjugate + +SYNOPSIS + conj(x) + +TYPES + If x is an object of type xx, conj(x) calls xx_conj(x). + + For non-object x: + + x real, complex, or matrix + + return real, complex, or matrix + +DESCRIPTION + + For real x, conj(x) returns x. + + For complex x, conj(x) returns re(x) - im(x) * 1i. + + For matrix x, conj(x) returns a matrix of the same structure as x + in which each element t of x has been replaced by conj(t). + + For xx objects, xx_conj(a) may return any type of value, but + for the properties usually expected of conjugates, xx_conj(a) + would return an xx object in which each number component is the + conjugate of the corresponding component of a. + +EXAMPLE + > print conj(3), conj(3 + 4i) + 3 3-4i + +LIMITS + none + +LINK LIBRARY + void conjvalue(VALUE *x, *res) + +SEE ALSO + norm, abs, arg + diff --git a/help/copy b/help/copy new file mode 100644 index 0000000..a16f031 --- /dev/null +++ b/help/copy @@ -0,0 +1,193 @@ +NAME + blkcpy, copy - copy items from a structure to a structure + +SYNOPSIS + blkcpy(dst, src [, num [, dsi [, ssi]]] + copy(src, dest [, [ssi [, num [, dsi]]]) + +TYPES + src block, file, string, matrix, or list + dest block, file, matrix or list - compatible with src + + ssi nonnegative integer, defaults to zero + num nonnegative integer, defaults to maximum possible + dsi nonnegative integer, defaults to datalen for a block, filepos + for a file, zero for other structures + + return null if successful, error value otherwise + +DESCRIPTION + A call to: + + blkcpy(dst, src, num, dsi, ssi) + + attempts to copy 'num' consecutive items (octets or values) starting + from the source item 'src' with index 'ssi'. By default, 'num' + is the maximum possible and 'ssi' is 0. + + A call to: + + copy(src, dst, ssi, num, dsi) + + does the same thing, but with a different arg order. + + A copy fails if ssi or num is too large for the number of items in + the source, if sdi is too large for the number of positions + available in the destination, or, in cases involving a file stream, + if the file is not open in the required mode. The source and + destination need not be of the same type, e.g. when a block is + copied to a matrix the octets are converted to numbers. + + The following pairs of source-type, destination-type are permitted: + + block to + int + block + matrix + file + + matrix to + block + matrix + list + + string to + block + file + + list to + list + matrix + + file to + block + + int to + block + + In the above table, int refers to integer values. However if a + rational value is supplied, only the numerator is copied. + + Each copied octet or value replaces the octet or value in the + corresponding place in the destination structure. When copying values + to values, the new values are stored in a buffer, the old values are + removed, and the new values copied from the buffer to the destination. + This permits movement of data within one matrix or list, and copying + of an element of structure to the structure. + + Except for copying to files or blocks, the destination is already to have + sufficient memory allocated for the copying. For example, to copy + a matrix M of size 100 to a newly created list, one may use: + + L = makelist(100); + copy(M, L); + or: + L = makelist(100); + blkcpy(L, M); + + For copying from a block B (named or unnamed), the total number of octets + available for copying is taken to the the datalen for that block, + so that num can be at most size(B) - ssi. + + For copying to a block B (named or unnamed), reallocation will be + required if dsi + num > sizeof(B). (This will not be permitted if + protect(B) has bit 4 set.) + + For copying from a file stream fs, num can be at most size(fs) - ssi. + + For copying from a string str, the string is taken to include the + terminating '\0', so the total number of octets available is + strlen(str) + 1 and num can be at most strlen(str) + 1 - ssi. + If num <= strlen(str) - ssi, the '\0' is not copied. + + For copying from or to a matrix M, the total number of values in + M is size(M), so in t