diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 29aa83e9..4ef7791b 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1719,6 +1719,7 @@ Pascal: - .dfm - .dpr - .lpr + - .pp Perl: type: programming diff --git a/samples/Pascal/custforms.pp b/samples/Pascal/custforms.pp new file mode 100644 index 00000000..a268aade --- /dev/null +++ b/samples/Pascal/custforms.pp @@ -0,0 +1,193 @@ +unit custforms; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms; + +Type + + { TCustomFormDescr } + + TCustomFormDescr = Class + private + FAuthor: String; + FCaption: String; + FCategory: String; + FDescription: String; + FFormClass: TFormClass; + FLazPackage: String; + FUnitName: String; + public + Constructor Create(AFormClass : TFormClass; const APackage: string); + Constructor Create(AFormClass : TFormClass; Const ACaption,ADescription,AUnit,APackage : String); + Property FormClass : TFormClass Read FFormClass Write FFormClass; + Property Caption : String Read FCaption Write FCaption; + Property Description : String Read FDescription Write FDescription; + Property UnitName : String Read FUnitName Write FUnitName; + Property Category : String Read FCategory Write FCategory; + Property Author : String Read FAuthor Write FAuthor; + Property LazPackage : String Read FLazPackage Write FLazPackage; + end; + +Procedure RegisterCustomForm(Descr : TCustomFormDescr); +Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string); +Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String); + +Procedure Register; + +implementation + +uses ProjectIntf,NewItemIntf,contnrs; + +Const + SAppFrameWork = 'Custom forms'; + SInstanceOf = 'Create a new instance of %s'; + +{ TCustomFormDescr } + +constructor TCustomFormDescr.Create(AFormClass: TFormClass; + const APackage: string); + +Var + N,U : String; + +begin + N:=AFormClass.ClassName; + U:=N; + If (Upcase(U[1])='T') then + Delete(U,1,1); + Create(AFormClass,N,Format(SInstanceOf,[N]),U,APackage); +end; + +constructor TCustomFormDescr.Create(AFormClass: TFormClass; + const ACaption, ADescription, AUnit, APackage: String); +begin + FFormClass:=AFormClass; + FCaption:=ACaption; + FDescription:=ADescription; + FUnitName:=AUnit; + FCategory:=SAppFrameWork; + FLazPackage:=APackage; +end; + +// Registration code. + +Type + { TCustomFormFileDescriptor } + TCustomFormFileDescriptor = Class(TFileDescPascalUnitWithResource) + private + FFormDescr: TCustomFormDescr; + Public + Constructor Create(ADescr : TCustomFormDescr); + Property FormDescr : TCustomFormDescr Read FFormDescr; + Function GetLocalizedName : String; override; + Function GetLocalizedDescription : String; override; + Function GetInterfaceUsesSection : String; override; + end; + +{ TCustomFormFileDescriptor } + +constructor TCustomFormFileDescriptor.Create(ADescr: TCustomFormDescr); +begin + Inherited Create; + FFormDescr:=ADescr; + ResourceClass:=FFormDescr.FFormClass; + Name:=FFormDescr.Caption; + RequiredPackages:=ADescr.LazPackage; + //Writeln('TCustomFormFileDescriptor.Create RequiredPackages=',RequiredPackages); +end; + +function TCustomFormFileDescriptor.GetLocalizedName: String; +begin + Result:=FFormDescr.Caption; +end; + +function TCustomFormFileDescriptor.GetLocalizedDescription: String; +begin + Result:=FFormDescr.Description; + If (FFormDescr.Author<>'') then + Result:=Result+LineEnding+'By '+FFormDescr.Author; +end; + +function TCustomFormFileDescriptor.GetInterfaceUsesSection: String; +begin + Result:=inherited GetInterfaceUsesSection; + Result:=Result+',Forms,'+FFormDescr.UnitName; +end; + +Var + CustomFormList : TObjectList; + +Procedure RegisterCustomForm(Descr : TCustomFormDescr); + +begin + CustomFormList.Add(Descr); +end; + +Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string); + +begin + RegisterCustomForm(TCustomFormDescr.Create(AFormClass,APackage)); +end; + +Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String); + +Var + D : TCustomFormDescr; + +begin + D:=TCustomFormDescr.Create(AFormClass,APackage); + D.UnitName:=AUnitName; + RegisterCustomForm(D); +end; + + +Procedure Register; + +Var + L : TStringList; + I : Integer; + D : TCustomFormDescr; + +begin + L:=TStringList.Create; + Try + L.Sorted:=True; + L.Duplicates:=dupIgnore; + For I:=0 to CustomFormList.Count-1 do + L.Add(TCustomFormDescr(CustomFormList[i]).Category); + For I:=0 to L.Count-1 do + begin + RegisterNewItemCategory(TNewIDEItemCategory.Create(L[i])); + end; + Finally + L.Free; + end; + For I:=0 to CustomFormList.Count-1 do + begin + D:=TCustomFormDescr(CustomFormList[i]); + RegisterProjectFileDescriptor(TCustomFormFileDescriptor.Create(D),D.Category); + end; +end; + +Procedure InitCustomForms; + +begin + CustomFormList:=TObjectList.Create; +end; + +Procedure DoneCustomForms; + +begin + FreeAndNil(CustomFormList); +end; + +Initialization + InitCustomForms; +Finalization + DoneCustomForms; +end. + diff --git a/samples/Pascal/gtkextra.pp b/samples/Pascal/gtkextra.pp new file mode 100644 index 00000000..9f2ebf8c --- /dev/null +++ b/samples/Pascal/gtkextra.pp @@ -0,0 +1,51 @@ +{ $Id$ } +{ + --------------------------------------------------------------------------- + gtkextra.pp - GTK(2) widgetset - additional gdk/gtk functions + --------------------------------------------------------------------------- + + This unit contains missing gdk/gtk functions and defines for certain + versions of gtk or fpc. + + --------------------------------------------------------------------------- + + @created(Sun Jan 28th WET 2006) + @lastmod($Date$) + @author(Marc Weustink ) + + ***************************************************************************** + This file is part of the Lazarus Component Library (LCL) + + See the file COPYING.modifiedLGPL.txt, included in this distribution, + for details about the license. + ***************************************************************************** + } + +unit GtkExtra; + +{$mode objfpc}{$H+} + +interface + +{$I gtkdefines.inc} + +{$ifdef gtk1} +{$I gtk1extrah.inc} +{$endif} + +{$ifdef gtk2} +{$I gtk2extrah.inc} +{$endif} + + +implementation + +{$ifdef gtk1} +{$I gtk1extra.inc} +{$endif} + +{$ifdef gtk2} +{$I gtk2extra.inc} +{$endif} + +end. diff --git a/samples/Puppet/expiringhost.pp b/samples/Puppet/expiringhost.pp new file mode 100644 index 00000000..039d506d --- /dev/null +++ b/samples/Puppet/expiringhost.pp @@ -0,0 +1,26 @@ +define example::expiringhost($ip, $timestamp) { + + # Calculate the age of this resource by comparing 'now' against $timestamp + $age = inline_template("<%= require 'time'; Time.now - Time.parse(timestamp) %>") + + # Max age, in seconds. + $maxage = 60 + + if $age > $maxage { + $expired = true + notice("Expiring resource $class[$name] due to age > $maxage (actual: $age)") + } else { + $expired = false + notice("Found recently-active $class[$name] (age: $age)") + } + + # I set target to a /tmp path so you can run this example as non-root. + # In production, you probabyl won't set target as it defaults to /etc/hosts + # (or wherever puppet thinks your platform wants it) + host { + $name: + ip => $ip, + target => "/tmp/expiring-hosts-example-output", + ensure => $expired ? { true => absent, false => present }; + } +} diff --git a/samples/Puppet/stages-example.pp b/samples/Puppet/stages-example.pp new file mode 100644 index 00000000..864ba5d3 --- /dev/null +++ b/samples/Puppet/stages-example.pp @@ -0,0 +1,26 @@ +class foo { + notify { + "foo": ; + } +} + +class bar { + notify { + "bar": ; + } +} + + +node default { + stage { + "one": ; + "two": ; + } + + class { + "foo": stage => "one"; + "bar": stage => "two"; + } + + Stage["one"] -> Stage["two"] +} diff --git a/samples/Puppet/unmanaged-notify-puppet25.pp b/samples/Puppet/unmanaged-notify-puppet25.pp new file mode 100644 index 00000000..3de728f8 --- /dev/null +++ b/samples/Puppet/unmanaged-notify-puppet25.pp @@ -0,0 +1,22 @@ +# Manually manage /tmp/original +# Each puppet run will copy it to /tmp/flag if there's a change and notify +# the exec when it changes. +# +# The idea here is you might need (in some case) to manually manage a file outside +# of puppet (in this case, "/tmp/original"). Using this example, you can make puppet +# signal other parts of your catalog based on changes to that file. + +file { + # This will, when different, copy /tmp/original to /tmp/flag and notify our + # exec. + "/tmp/flag": + source => "file:///tmp/original", + notify => Exec["hello world"]; +} + +exec { + "hello world": + command => "/bin/echo hello world", + refreshonly => true; +} +