Merge branch 'master' into cpp-c-improvements

This commit is contained in:
Arfon Smith
2015-01-03 11:12:55 -06:00
250 changed files with 5526 additions and 383 deletions

View File

@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Simple")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@@ -0,0 +1,20 @@
using System;
namespace MongoDB.Serialization.Descriptors
{
internal class BsonPropertyValue
{
public bool IsDictionary { get; private set; }
public Type Type { get; private set; }
public object Value { get; private set; }
public BsonPropertyValue(Type type, object value, bool isDictionary)
{
Type = type;
Value = value;
IsDictionary = isDictionary;
}
}
}

View File

@@ -0,0 +1,153 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
{
internal class MongoExpressionVisitor : ExpressionVisitor
{
protected override Expression Visit(Expression exp)
{
if (exp == null)
return null;
switch ((MongoExpressionType)exp.NodeType)
{
case MongoExpressionType.Collection:
return VisitCollection((CollectionExpression)exp);
case MongoExpressionType.Field:
return VisitField((FieldExpression)exp);
case MongoExpressionType.Projection:
return VisitProjection((ProjectionExpression)exp);
case MongoExpressionType.Select:
return VisitSelect((SelectExpression)exp);
case MongoExpressionType.Aggregate:
return VisitAggregate((AggregateExpression)exp);
case MongoExpressionType.AggregateSubquery:
return VisitAggregateSubquery((AggregateSubqueryExpression)exp);
case MongoExpressionType.Scalar:
return VisitScalar((ScalarExpression)exp);
default:
return base.Visit(exp);
}
}
protected virtual Expression VisitAggregate(AggregateExpression aggregate)
{
var exp = Visit(aggregate.Argument);
if (exp != aggregate.Argument)
return new AggregateExpression(aggregate.Type, aggregate.AggregateType, exp, aggregate.Distinct);
return aggregate;
}
protected virtual Expression VisitAggregateSubquery(AggregateSubqueryExpression aggregateSubquery)
{
Expression e = Visit(aggregateSubquery.AggregateAsSubquery);
ScalarExpression subquery = (ScalarExpression)e;
if (subquery != aggregateSubquery.AggregateAsSubquery)
return new AggregateSubqueryExpression(aggregateSubquery.GroupByAlias, aggregateSubquery.AggregateInGroupSelect, subquery);
return aggregateSubquery;
}
protected virtual Expression VisitCollection(CollectionExpression collection)
{
return collection;
}
protected virtual Expression VisitField(FieldExpression field)
{
var e = Visit(field.Expression);
if (field.Expression != e)
field = new FieldExpression(e, field.Alias, field.Name);
return field;
}
protected virtual Expression VisitProjection(ProjectionExpression projection)
{
var source = (SelectExpression)Visit(projection.Source);
var projector = Visit(projection.Projector);
if (source != projection.Source || projector != projection.Projector)
return new ProjectionExpression(source, projector, projection.Aggregator);
return projection;
}
protected ReadOnlyCollection<OrderExpression> VisitOrderBy(ReadOnlyCollection<OrderExpression> orderBys)
{
if (orderBys != null)
{
List<OrderExpression> alternate = null;
for (int i = 0, n = orderBys.Count; i < n; i++)
{
OrderExpression expr = orderBys[i];
Expression e = this.Visit(expr.Expression);
if (alternate == null && e != expr.Expression)
alternate = orderBys.Take(i).ToList();
if (alternate != null)
alternate.Add(new OrderExpression(expr.OrderType, e));
}
if (alternate != null)
return alternate.AsReadOnly();
}
return orderBys;
}
protected virtual Expression VisitScalar(ScalarExpression scalar)
{
SelectExpression select = (SelectExpression)Visit(scalar.Select);
if (select != scalar.Select)
return new ScalarExpression(scalar.Type, select);
return scalar;
}
protected virtual Expression VisitSelect(SelectExpression select)
{
var from = VisitSource(select.From);
var where = Visit(select.Where);
var groupBy = Visit(select.GroupBy);
var orderBy = VisitOrderBy(select.OrderBy);
var skip = Visit(select.Skip);
var take = Visit(select.Take);
var fields = VisitFieldDeclarationList(select.Fields);
if (from != select.From || where != select.Where || orderBy != select.OrderBy || groupBy != select.GroupBy || skip != select.Skip || take != select.Take || fields != select.Fields)
return new SelectExpression(select.Alias, fields, from, where, orderBy, groupBy, select.IsDistinct, skip, take);
return select;
}
protected virtual Expression VisitSource(Expression source)
{
return Visit(source);
}
protected virtual Expression VisitSubquery(SubqueryExpression subquery)
{
switch ((MongoExpressionType)subquery.NodeType)
{
case MongoExpressionType.Scalar:
return VisitScalar((ScalarExpression)subquery);
}
return subquery;
}
protected virtual ReadOnlyCollection<FieldDeclaration> VisitFieldDeclarationList(ReadOnlyCollection<FieldDeclaration> fields)
{
if (fields == null)
return fields;
List<FieldDeclaration> alternate = null;
for (int i = 0, n = fields.Count; i < n; i++)
{
var f = fields[i];
var e = Visit(f.Expression);
if (f.Expression != e && alternate == null)
alternate = fields.Take(i).ToList();
if (alternate != null)
alternate.Add(new FieldDeclaration(f.Name, e));
}
if (alternate != null)
return alternate.AsReadOnly();
return fields;
}
}
}

File diff suppressed because it is too large Load Diff

56
samples/Jasmin/if1.j Normal file
View File

@@ -0,0 +1,56 @@
.class public if1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If556261059
goto IfElse556261059
If556261059:
.line 3
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone556261059
IfElse556261059:
.line 5
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone556261059:
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
.line 7
ldc 0x1
ldc 0x1
if_icmpne IfNot-920218690
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x4
invokevirtual java/io/PrintStream/print(I)V
IfNot-920218690:
EndGlobal:
return
.end method

167
samples/Jasmin/if2.j Normal file
View File

@@ -0,0 +1,167 @@
.class public if2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq Cmp1893841232
ldc 0x0
goto CmpDone1893841232
Cmp1893841232:
ldc 0x1
CmpDone1893841232:
ldc 0x1
if_icmpeq If-1736765035
goto IfElse-1736765035
If-1736765035:
.line 2
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1736765035
IfElse-1736765035:
.line 4
.line 4
ldc 0x2
ldc 0x1
if_icmpeq Cmp-1460884369
ldc 0x0
goto CmpDone-1460884369
Cmp-1460884369:
ldc 0x1
CmpDone-1460884369:
ldc 0x1
if_icmpeq If-247349760
goto IfElse-247349760
If-247349760:
.line 4
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-247349760
IfElse-247349760:
.line 6
.line 7
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-247349760:
IfDone-1736765035:
.line 10
ldc 0x1
ldc 0x2
if_icmpeq Cmp933554851
ldc 0x0
goto CmpDone933554851
Cmp933554851:
ldc 0x1
CmpDone933554851:
ldc 0x1
if_icmpeq If1623625546
goto IfElse1623625546
If1623625546:
.line 10
.line 11
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1623625546
IfElse1623625546:
.line 12
.line 12
ldc 0x2
ldc 0x2
if_icmpeq Cmp1572138409
ldc 0x0
goto CmpDone1572138409
Cmp1572138409:
ldc 0x1
CmpDone1572138409:
ldc 0x1
if_icmpeq If126354425
goto IfElse126354425
If126354425:
.line 12
.line 13
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone126354425
IfElse126354425:
.line 14
.line 15
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone126354425:
IfDone1623625546:
.line 18
ldc 0x1
ldc 0x2
if_icmpeq Cmp126493150
ldc 0x0
goto CmpDone126493150
Cmp126493150:
ldc 0x1
CmpDone126493150:
ldc 0x1
if_icmpeq If1522284422
goto IfElse1522284422
If1522284422:
.line 18
.line 19
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1522284422
IfElse1522284422:
.line 20
.line 20
ldc 0x2
ldc 0x1
if_icmpeq Cmp-906666545
ldc 0x0
goto CmpDone-906666545
Cmp-906666545:
ldc 0x1
CmpDone-906666545:
ldc 0x1
if_icmpeq If1083939031
goto IfElse1083939031
If1083939031:
.line 20
.line 21
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1083939031
IfElse1083939031:
.line 22
.line 23
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone1083939031:
IfDone1522284422:
EndGlobal:
return
.end method

55
samples/Jasmin/if3.j Normal file
View File

@@ -0,0 +1,55 @@
.class public if3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If-811796083
goto IfElse-811796083
If-811796083:
.line 3
.line 3
ldc 0x0
ldc 0x1
if_icmpeq If-1001319390
goto IfElse-1001319390
If-1001319390:
.line 4
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1001319390
IfElse-1001319390:
.line 6
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone-1001319390:
goto IfDone-811796083
IfElse-811796083:
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-811796083:
EndGlobal:
return
.end method

37
samples/Jasmin/if4.j Normal file
View File

@@ -0,0 +1,37 @@
.class public if4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot1919266740
.line 2
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot613368541
.line 2
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
IfNot613368541:
IfNot1919266740:
EndGlobal:
return
.end method

54
samples/Jasmin/op1.j Normal file
View File

@@ -0,0 +1,54 @@
.class public op1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
iadd
invokevirtual java/io/PrintStream/println(I)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0xa
ldc 0x5
isub
invokevirtual java/io/PrintStream/println(I)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x15
ldc 0x3
idiv
invokevirtual java/io/PrintStream/println(I)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x159
ldc 0x38
imul
invokevirtual java/io/PrintStream/println(I)V
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x52
ldc 0x9
irem
invokevirtual java/io/PrintStream/println(I)V
EndGlobal:
return
.end method

34
samples/Jasmin/op2.j Normal file
View File

@@ -0,0 +1,34 @@
.class public op2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
iand
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
ior
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op3.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpeq Cmp-1307183590
ldc 0x0
goto CmpDone-1307183590
Cmp-1307183590:
ldc 0x1
CmpDone-1307183590:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpeq Cmp-1443270821
ldc 0x0
goto CmpDone-1443270821
Cmp-1443270821:
ldc 0x1
CmpDone-1443270821:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpeq Cmp1759327329
ldc 0x0
goto CmpDone1759327329
Cmp1759327329:
ldc 0x1
CmpDone1759327329:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpeq Cmp-678570146
ldc 0x0
goto CmpDone-678570146
Cmp-678570146:
ldc 0x1
CmpDone-678570146:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op4.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpne Cmp-191731100
ldc 0x0
goto CmpDone-191731100
Cmp-191731100:
ldc 0x1
CmpDone-191731100:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpne Cmp-901585603
ldc 0x0
goto CmpDone-901585603
Cmp-901585603:
ldc 0x1
CmpDone-901585603:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpne Cmp1522577937
ldc 0x0
goto CmpDone1522577937
Cmp1522577937:
ldc 0x1
CmpDone1522577937:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpne Cmp-1653028684
ldc 0x0
goto CmpDone-1653028684
Cmp-1653028684:
ldc 0x1
CmpDone-1653028684:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

View File

@@ -0,0 +1,434 @@
//
// AppController.j
// FlickrPhoto
//
// Created by Ross Boucher.
// Copyright 2008 - 2010, 280 North, Inc. All rights reserved.
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
var SliderToolbarItemIdentifier = "SliderToolbarItemIdentifier",
AddToolbarItemIdentifier = "AddToolbarItemIdentifier",
RemoveToolbarItemIdentifier = "RemoveToolbarItemIdentifier";
/*
Important note about CPJSONPConnection: CPJSONPConnection is ONLY for JSONP APIs.
If aren't sure you NEED JSONP (see http://ajaxian.com/archives/jsonp-json-with-padding ),
you most likely don't want to use CPJSONPConnection, but rather the more standard
CPURLConnection. CPJSONPConnection is designed for cross-domain
connections, and if you are making requests to the same domain (as most web
applications do), you do not need it.
*/
@implementation AppController : CPObject
{
CPString lastIdentifier;
CPDictionary photosets;
CPCollectionView listCollectionView;
CPCollectionView photosCollectionView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
//the first thing we need to do is create a window to take up the full screen
//we'll also create a toolbar to go with it, and grab its size for future reference
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView],
toolbar = [[CPToolbar alloc] initWithIdentifier:"Photos"],
bounds = [contentView bounds];
//we tell the toolbar that we want to be its delegate and attach it to theWindow
[toolbar setDelegate:self];
[toolbar setVisible:true];
[theWindow setToolbar:toolbar];
photosets = [CPDictionary dictionary]; //storage for our sets of photos return from Flickr
//now we create a scroll view to contain the list of collections of photos (photosets)
//inside the scroll view, we'll place our collection view, which manages a collection of "cells"
//each cell will represent one photo collection, and choosing cells will select that collection
var listScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight(bounds) - 58)];
[listScrollView setAutohidesScrollers:YES];
[listScrollView setAutoresizingMask:CPViewHeightSizable];
[[listScrollView contentView] setBackgroundColor:[CPColor colorWithRed:213.0 / 255.0 green:221.0 / 255.0 blue:230.0 / 255.0 alpha:1.0]];
//we create the collection view cells by creating a single prototype (CPCollectionViewItem) and setting its view.
//the CPCollectionView class will then duplicate this item as many times as it needs
var photosListItem = [[CPCollectionViewItem alloc] init];
[photosListItem setView:[[PhotosListCell alloc] initWithFrame:CGRectMakeZero()]];
listCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];
[listCollectionView setDelegate:self]; //we want delegate methods
[listCollectionView setItemPrototype:photosListItem]; //set the item prototype
[listCollectionView setMinItemSize:CGSizeMake(20.0, 45.0)];
[listCollectionView setMaxItemSize:CGSizeMake(1000.0, 45.0)];
[listCollectionView setMaxNumberOfColumns:1]; //setting a single column will make this appear as a vertical list
[listCollectionView setVerticalMargin:0.0];
[listCollectionView setAutoresizingMask:CPViewWidthSizable];
//finally, we put our collection view inside the scroll view as it's document view, so it can be scrolled
[listScrollView setDocumentView:listCollectionView];
//and we add it to the window's content view, so it will show up on the screen
[contentView addSubview:listScrollView];
//repeat the process with another collection view for the actual photos
//this time we'll use a different view for the prototype (PhotoCell)
var photoItem = [[CPCollectionViewItem alloc] init];
[photoItem setView:[[PhotoCell alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(200, 0, CGRectGetWidth(bounds) - 200, CGRectGetHeight(bounds) - 58)];
photosCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds) - 200, 0)];
[photosCollectionView setDelegate:self];
[photosCollectionView setItemPrototype:photoItem];
[photosCollectionView setMinItemSize:CGSizeMake(150, 150)];
[photosCollectionView setMaxItemSize:CGSizeMake(150, 150)];
[photosCollectionView setAutoresizingMask:CPViewWidthSizable];
[scrollView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
[scrollView setDocumentView:photosCollectionView];
[scrollView setAutohidesScrollers:YES];
[[scrollView contentView] setBackgroundColor:[CPColor colorWithCalibratedWhite:0.25 alpha:1.0]];
[contentView addSubview:scrollView];
//bring forward the window to display it
[theWindow orderFront:self];
//get the most interesting photos on flickr
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?method=flickr.interestingness.getList&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
var connection = [CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = "Interesting Photos";
}
- (void)add:(id)sender
{
var string = prompt("Enter a tag to search Flickr for photos.");
if (string)
{
//create a new request for the photos with the tag returned from the javascript prompt
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?"+
"method=flickr.photos.search&tags="+encodeURIComponent(string)+
"&media=photos&machine_tag_mode=any&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
[CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = string;
}
}
- (void)remove:(id)sender
{
//remove this photo
[self removeImageListWithIdentifier:[[photosets allKeys] objectAtIndex:[[listCollectionView selectionIndexes] firstIndex]]];
}
- (void)addImageList:(CPArray)images withIdentifier:(CPString)aString
{
[photosets setObject:images forKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:[[photosets allKeys] indexOfObject:aString]]];
}
- (void)removeImageListWithIdentifier:(CPString)aString
{
var nextIndex = MAX([[listCollectionView content] indexOfObject:aString] - 1, 0);
[photosets removeObjectForKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:nextIndex]];
}
- (void)adjustImageSize:(id)sender
{
var newSize = [sender value];
[photosCollectionView setMinItemSize:CGSizeMake(newSize, newSize)];
[photosCollectionView setMaxItemSize:CGSizeMake(newSize, newSize)];
}
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
{
if (aCollectionView == listCollectionView)
{
var listIndex = [[listCollectionView selectionIndexes] firstIndex];
if (listIndex === CPNotFound)
return;
var key = [listCollectionView content][listIndex];
[photosCollectionView setContent:[photosets objectForKey:key]];
[photosCollectionView setSelectionIndexes:[CPIndexSet indexSet]];
}
}
- (void)connection:(CPJSONPConnection)aConnection didReceiveData:(CPString)data
{
//this method is called when the network request returns. the data is the returned
//information from flickr. we set the array of photo urls as the data to our collection view
[self addImageList:data.photos.photo withIdentifier:lastIdentifier];
}
- (void)connection:(CPJSONPConnection)aConnection didFailWithError:(CPString)error
{
alert(error); //a network error occurred
}
//these two methods are the toolbar delegate methods, and tell the toolbar what it should display to the user
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return [self toolbarDefaultItemIdentifiers:aToolbar];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return [AddToolbarItemIdentifier, RemoveToolbarItemIdentifier, CPToolbarFlexibleSpaceItemIdentifier, SliderToolbarItemIdentifier];
}
//this delegate method returns the actual toolbar item for the given identifier
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
if (anItemIdentifier == SliderToolbarItemIdentifier)
{
[toolbarItem setView:[[PhotoResizeView alloc] initWithFrame:CGRectMake(0, 0, 180, 32)]];
[toolbarItem setMinSize:CGSizeMake(180, 32)];
[toolbarItem setMaxSize:CGSizeMake(180, 32)];
[toolbarItem setLabel:"Scale"];
}
else if (anItemIdentifier == AddToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"add.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"addHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(add:)];
[toolbarItem setLabel:"Add Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
else if (anItemIdentifier == RemoveToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"remove.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"removeHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(remove:)];
[toolbarItem setLabel:"Remove Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
return toolbarItem;
}
@end
/*
This code demonstrates how to add a category to an existing class.
In this case, we are adding the class method +flickr_labelWithText: to
the CPTextField class. Later on, we can call [CPTextField flickr_labelWithText:"foo"]
to return a new text field with the string foo.
Best practices suggest prefixing category methods with your unique prefix, to prevent collisions.
*/
@implementation CPTextField (CreateLabel)
+ (CPTextField)flickr_labelWithText:(CPString)aString
{
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:aString];
[label sizeToFit];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
return label;
}
@end
// This class wraps our slider + labels combo
@implementation PhotoResizeView : CPView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
var slider = [[CPSlider alloc] initWithFrame:CGRectMake(30, CGRectGetHeight(aFrame) / 2.0 - 8, CGRectGetWidth(aFrame) - 65, 24)];
[slider setMinValue:50.0];
[slider setMaxValue:250.0];
[slider setIntValue:150.0];
[slider setAction:@selector(adjustImageSize:)];
[self addSubview:slider];
var label = [CPTextField flickr_labelWithText:"50"];
[label setFrameOrigin:CGPointMake(0, CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
label = [CPTextField flickr_labelWithText:"250"];
[label setFrameOrigin:CGPointMake(CGRectGetWidth(aFrame) - CGRectGetWidth([label frame]), CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
return self;
}
@end
// This class displays a single photo collection inside our list of photo collecitions
@implementation PhotosListCell : CPView
{
CPTextField label;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!label)
{
label = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
[label setFont:[CPFont systemFontOfSize:16.0]];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
[self addSubview:label];
}
[label setStringValue:anObject];
[label sizeToFit];
[label setFrameOrigin:CGPointMake(10,CGRectGetHeight([label bounds]) / 2.0)];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
[highlightView setBackgroundColor:[CPColor blueColor]];
}
if (flag)
{
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:label];
[label setTextColor:[CPColor whiteColor]];
[label setTextShadowColor:[CPColor blackColor]];
}
else
{
[highlightView removeFromSuperview];
[label setTextColor:[CPColor blackColor]];
[label setTextShadowColor:[CPColor whiteColor]];
}
}
@end
// This class displays a single photo from our collection
@implementation PhotoCell : CPView
{
CPImage image;
CPImageView imageView;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!imageView)
{
imageView = [[CPImageView alloc] initWithFrame:CGRectMakeCopy([self bounds])];
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[imageView setImageScaling:CPScaleProportionally];
[imageView setHasShadow:YES];
[self addSubview:imageView];
}
[image setDelegate:nil];
image = [[CPImage alloc] initWithContentsOfFile:thumbForFlickrPhoto(anObject)];
[image setDelegate:self];
if ([image loadStatus] == CPImageLoadStatusCompleted)
[imageView setImage:image];
else
[imageView setImage:nil];
}
- (void)imageDidLoad:(CPImage)anImage
{
[imageView setImage:anImage];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:[self bounds]];
[highlightView setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
[highlightView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
}
if (flag)
{
[highlightView setFrame:[self bounds]];
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:imageView];
}
else
[highlightView removeFromSuperview];
}
@end
// helper javascript functions for turning a Flickr photo object into a URL for getting the image
function urlForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id+"_" + photo.secret + ".jpg";
}
function thumbForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_m.jpg";
}

View File

@@ -0,0 +1,88 @@
@import <Foundation/CPObject.j>
@import <AppKit/CPView.j>
@import <AppKit/CPButton.j>
@import <AppKit/CPWebView.j>
@import "LOBoard.j"
@implementation LOInfoView : CPView
{
}
- (void)drawRect:(CGRect)r
{
[[CPColor whiteColor] setFill]
var path = [CPBezierPath bezierPath];
[path appendBezierPathWithRoundedRect:CGRectMake(5, 0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds])) xRadius:10 yRadius:10];
[path fill];
}
@end
@implementation AppController : CPObject
{
}
- (CPPanel)initInfoWindow
{
var infoWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(400, 50, 320, 480) styleMask:CPHUDBackgroundWindowMask | CPResizableWindowMask];
[infoWindow setFloatingPanel:YES];
var _infoContent = [infoWindow contentView],
_iconImage = [[CPImage alloc] initWithContentsOfFile:"Resources/icon.png" size:CPSizeMake(59, 60)],
_iconView = [[CPImageView alloc] initWithFrame:CGRectMake(125, 0, 59, 60)];
[_iconView setImage:_iconImage];
[_infoContent addSubview:_iconView];
var _infoView = [[LOInfoView alloc] initWithFrame:CGRectMake(0, 65, 320, 395)],
_webView = [[CPWebView alloc] initWithFrame:CGRectMake(20, 0, 270, 370)];
[_webView loadHTMLString:@"<center><h3>Lights Off</h3></center> <p>Lights Off is a fantastic game exclusively for iPhone and iPod touch and inspired by Tiger Electronic's 'Lights Out'.</p> <p>The goal of the game is simply to switch all of the lights off, but it's harder than it looks! Give the first few levels a try in the playable demo to the left.</p><center><img src='Resources/avail_on_app_store.png'></center>"];
[_infoView addSubview:_webView];
[_infoContent addSubview:_infoView];
return infoWindow;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
/* Enable Logging (DEBUG) */
// CPLogRegister(CPLogPopup);
var rootWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
[rootWindow setBackgroundColor:[CPColor grayColor]];
[rootWindow orderFront:self];
var infoWindow = [self initInfoWindow],
gameWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(50, 50, 324, 482) styleMask:CPHUDBackgroundWindowMask];
[gameWindow setFloatingPanel:YES];
[gameWindow setTitle:@"Lights Off"];
contentView = [gameWindow contentView];
var _board = [[LOBoard alloc] initWithFrame:CGRectMake(2, 0, 320, 480)],
_bgImage = [[CPImage alloc] initWithContentsOfFile:"Resources/lo-background.png" size:CPSizeMake(320, 480)];
[_board setImage:_bgImage];
[_board resetBoard];
var _buttonImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset.png" size:CPSizeMake(90, 28)],
_buttonPressImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset-press.png" size:CPSizeMake(90, 28)],
_resetButton = [[CPButton alloc] initWithFrame:CGRectMake(195, 422, 90, 28)];
[_resetButton setImage:_buttonImage];
[_resetButton setAlternateImage:_buttonPressImage];
[_resetButton setBordered:NO];
[contentView addSubview:_board];
[contentView addSubview:_resetButton];
[_resetButton setTarget:_board];
[_resetButton setAction:@selector(resetBoard)];
[gameWindow orderFront:self];
[infoWindow orderFront:self];
}
@end

View File

@@ -0,0 +1,47 @@
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// The end result of this layout will be the kind of master/detail/auxilliary view
// found in iTunes, Mail, and many other apps.
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
[navigationArea setBackgroundColor:[CPColor redColor]];
// This view will grow in height, but stay fixed width attached to the left side of the screen.
[navigationArea setAutoresizingMask:CPViewHeightSizable | CPViewMaxXMargin];
[contentView addSubview:navigationArea];
var metaDataArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY([navigationArea frame]), 150.0, 150.0)];
[metaDataArea setBackgroundColor:[CPColor greenColor]];
// This view will stay the same size in both directions, and fixed to the lower left corner.
[metaDataArea setAutoresizingMask:CPViewMinYMargin | CPViewMaxXMargin];
[contentView addSubview:metaDataArea];
var contentArea = [[CPView alloc] initWithFrame:CGRectMake(150.0, 0.0, CGRectGetWidth([contentView bounds]) - 150.0, CGRectGetHeight([contentView bounds]))];
[contentArea setBackgroundColor:[CPColor blueColor]];
// This view will grow in both height an width.
[contentArea setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[contentView addSubview:contentArea];
[theWindow orderFront:self];
}
@end

View File

@@ -0,0 +1,137 @@
EnableExplicit
; ##################################################### Includes ####################################################
XIncludeFile "Includes/AudioOut.pbi"
; ##################################################### Prototypes ##################################################
; ##################################################### Structures ##################################################
; ##################################################### Constants ###################################################
#Samplerate = 44100
; ##################################################### Structures ##################################################
Structure Main
*AudioOut
Quit.i
EndStructure
Global Main.Main
Structure Main_Window
ID.i
TrackBar.i [10]
EndStructure
Global Main_Window.Main_Window
; ##################################################### Variables ###################################################
Global Frequency.d = 1000
Global Amplitude.d = 0.25
; ##################################################### Procedures ##################################################
Procedure Main_Window_Open()
Main_Window\ID = OpenWindow(#PB_Any, 0, 0, 800, 100, "AudioOut Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
If Main_Window\ID
Main_Window\TrackBar[0] = TrackBarGadget(#PB_Any, 10, 10, 780, 30, 0, 20000)
SetGadgetState(Main_Window\TrackBar[0], Frequency)
Main_Window\TrackBar[1] = TrackBarGadget(#PB_Any, 10, 40, 780, 30, 0, 1000)
SetGadgetState(Main_Window\TrackBar[1], Amplitude*1000)
EndIf
EndProcedure
Procedure Notifier_CallBack(*AudioOut)
Protected *Temp, Temp_Size.i
Static Rotation.d
While AudioOut::GetQueuedBlocks(*AudioOut) <= 3
Temp_Size = AudioOut::GetBufferBlocksize(*AudioOut)
If Temp_Size > 0
*Temp = AllocateMemory(Temp_Size)
Define Left.d, Right.d, i
For i = 0 To Temp_Size / 4 - 1
Left = Sin(Rotation) * Amplitude
Right = Sin(Rotation) * Amplitude
PokeW(*Temp + i*4 , Left*32767)
PokeW(*Temp + i*4 + 2, Right*32767)
Rotation + 2.0*#PI / #Samplerate * Frequency
Next
AudioOut::Write_Data(Main\AudioOut, *Temp, Temp_Size)
FreeMemory(*Temp)
EndIf
Wend
EndProcedure
; ##################################################### Initialisation ##############################################
Main_Window_Open()
AudioOut::GetDevices()
ForEach AudioOut::Device()
Debug PeekS(AudioOut::@Device()\szPname)
Next
Main\AudioOut = AudioOut::Initialize(#WAVE_MAPPER, #Samplerate, 2, 16, @Notifier_CallBack())
If Not Main\AudioOut
Debug AudioOut::GetError()
End
EndIf
Notifier_CallBack(Main\AudioOut)
; ##################################################### Main ########################################################
Repeat
Repeat
Select WaitWindowEvent(100)
Case #PB_Event_Gadget
Select EventGadget()
Case Main_Window\TrackBar[0]
Frequency = GetGadgetState(Main_Window\TrackBar[0])
Debug Frequency
Case Main_Window\TrackBar[1]
Amplitude = GetGadgetState(Main_Window\TrackBar[1]) / 1000
EndSelect
Case #PB_Event_CloseWindow
Main\Quit = #True
Case 0
Break
EndSelect
ForEver
Until Main\Quit
; ##################################################### End #########################################################
AudioOut::Deinitialize(Main\AudioOut)
; IDE Options = PureBasic 5.30 Beta 2 (Windows - x64)
; CursorPosition = 109
; FirstLine = 79
; Folding = -
; EnableUnicode
; EnableThread
; EnableXP

View File

@@ -0,0 +1,203 @@
Structure Memory_Operation
Src_Offset.q
Src_Size.q
Dst_Offset.q
Dst_Size.q
Copy_Size.q
EndStructure
; #### Cuts the Offset's / Sizes of the memory operation to prevent memory violations
Procedure Memory_Operation_Check(*Memory_Operation.Memory_Operation)
Protected Temp.q
If *Memory_Operation\Src_Offset < 0
*Memory_Operation\Copy_Size + *Memory_Operation\Src_Offset
*Memory_Operation\Dst_Offset - *Memory_Operation\Src_Offset
*Memory_Operation\Src_Offset - *Memory_Operation\Src_Offset
EndIf
If *Memory_Operation\Dst_Offset < 0
*Memory_Operation\Copy_Size + *Memory_Operation\Dst_Offset
*Memory_Operation\Src_Offset - *Memory_Operation\Dst_Offset
*Memory_Operation\Dst_Offset - *Memory_Operation\Dst_Offset
EndIf
Temp = *Memory_Operation\Src_Size - *Memory_Operation\Src_Offset
If *Memory_Operation\Copy_Size > Temp
*Memory_Operation\Copy_Size = Temp
EndIf
Temp = *Memory_Operation\Dst_Size - *Memory_Operation\Dst_Offset
If *Memory_Operation\Copy_Size > Temp
*Memory_Operation\Copy_Size = Temp
EndIf
If *Memory_Operation\Copy_Size < 0
*Memory_Operation\Copy_Size = 0
EndIf
ProcedureReturn #True
EndProcedure
; #### Fills a *Destination with a specified amount of data.
; #### It cuts everything, to prevent memory violations
Procedure Memory_Range_Fill(Ascii.a, Fill_Size.q, *Dst, Dst_Offset.q, Dst_Size.q=-1)
Protected Temp.q
If Not *Dst
ProcedureReturn #False
EndIf
If Dst_Size = -1
Dst_Size.q = MemorySize(*Dst)
EndIf
If Dst_Offset < 0
Fill_Size + Dst_Offset
Dst_Offset - Dst_Offset
EndIf
Temp = Dst_Size - Dst_Offset
If Fill_Size > Temp
Fill_Size = Temp
EndIf
If Fill_Size > 0
FillMemory(*Dst+Dst_Offset, Fill_Size, Ascii)
EndIf
ProcedureReturn #True
EndProcedure
; #### Copies a specified amount of data (Copy_Size) from the source to the destination.
; #### It cuts everything, to prevent memory violations
Procedure Memory_Range_Copy(*Src, Src_Offset.q, *Dst, Dst_Offset.q, Copy_Size.q, Src_Size.q=-1, Dst_Size.q=-1)
Protected Temp.q
If Not *Src
ProcedureReturn #False
EndIf
If Not *Dst
ProcedureReturn #False
EndIf
If Src_Size = -1
Src_Size.q = MemorySize(*Src)
EndIf
If Dst_Size = -1
Dst_Size.q = MemorySize(*Dst)
EndIf
If Src_Offset < 0
Copy_Size + Src_Offset
Dst_Offset - Src_Offset
Src_Offset - Src_Offset
EndIf
If Dst_Offset < 0
Copy_Size + Dst_Offset
Src_Offset - Dst_Offset
Dst_Offset - Dst_Offset
EndIf
Temp = Src_Size - Src_Offset
If Copy_Size > Temp
Copy_Size = Temp
EndIf
Temp = Dst_Size - Dst_Offset
If Copy_Size > Temp
Copy_Size = Temp
EndIf
If Copy_Size > 0
CopyMemory(*Src+Src_Offset, *Dst+Dst_Offset, Copy_Size)
EndIf
ProcedureReturn #True
EndProcedure
; #### Copies (MoveMemory) a specified amount of data (Copy_Size) from the source to the destination.
; #### It cuts everything, to prevent memory violations
Procedure Memory_Range_Move(*Src, Src_Offset.q, *Dst, Dst_Offset.q, Copy_Size.q, Src_Size.q=-1, Dst_Size.q=-1)
Protected Temp.q
If Not *Src
ProcedureReturn #False
EndIf
If Not *Dst
ProcedureReturn #False
EndIf
If Src_Size = -1
Src_Size.q = MemorySize(*Src)
EndIf
If Dst_Size = -1
Dst_Size.q = MemorySize(*Dst)
EndIf
If Src_Offset < 0
Copy_Size + Src_Offset
Dst_Offset - Src_Offset
Src_Offset - Src_Offset
EndIf
If Dst_Offset < 0
Copy_Size + Dst_Offset
Src_Offset - Dst_Offset
Dst_Offset - Dst_Offset
EndIf
Temp = Src_Size - Src_Offset
If Copy_Size > Temp
Copy_Size = Temp
EndIf
Temp = Dst_Size - Dst_Offset
If Copy_Size > Temp
Copy_Size = Temp
EndIf
If Copy_Size > 0
MoveMemory(*Src+Src_Offset, *Dst+Dst_Offset, Copy_Size)
EndIf
ProcedureReturn #True
EndProcedure
; #### Mirrors the memory, usable for little/big endian switching
Procedure Memory_Mirror(*Memory, Memory_Size)
Protected Elements, i
Protected Temp.a, *A.Ascii, *B.Ascii
If Not *Memory
ProcedureReturn #False
EndIf
If Memory_Size < 1
ProcedureReturn #True
EndIf
Elements = Memory_Size/2
*A = *Memory
*B = *Memory + Memory_Size - 1
For i = 0 To Elements - 1
Temp = *A\a
*A\a = *B\a
*B\a = Temp
*A + 1
*B - 1
Next
ProcedureReturn #True
EndProcedure
; IDE Options = PureBasic 5.31 (Windows - x64)
; CursorPosition = 190
; FirstLine = 177
; Folding = -
; EnableXP
; DisableDebugger

275
samples/SAS/detect_phi.sas Normal file
View File

@@ -0,0 +1,275 @@
%macro check_dataset(dset =, obs_lim = max, eldest_age = 89) ;
%local i ;
%local inset_name ;
%let inset_name = &dset ;
%if %lowcase(&obs_lim) = max %then %do ;
%** Nothing ;
%end ;
%else %do ;
proc surveyselect
data = &inset_name
out = __sub_dset
method = srs
sampsize = &obs_lim SELECTALL
seed = 1234567
noprint
;
run;
%let dset = __sub_dset ;
%end ;
%macro check_varname(regx, msg) ;
create table possible_bad_vars as
select name, label
from these_vars
where prxmatch(compress("/(&regx)/i"), name)
;
%if &sqlobs > 0 %then %do ;
insert into phi_warnings(dset, variable, label, warning)
select "&inset_name" as dset, name, label, "&msg"
from possible_bad_vars
;
%end ;
%mend check_varname ;
%macro check_vars_for_mrn(length_limit = 6, obs_lim = max) ;
%local char ;
%let char = 2 ;
proc sql noprint ;
select name
into :mrn_array separated by ' '
from these_vars
where type = &char and length ge &length_limit
;
quit ;
%if &sqlobs > 0 %then %do ;
%put Checking these vars for possible MRN contents: &mrn_array ;
data __gnu ;
retain
mrn_regex_handle
badcount
;
set &inset_name (obs = &obs_lim keep = &mrn_array) ;
if _n_ = 1 then do ;
mrn_regex_handle = prxparse("/&mrn_regex/") ;
badcount = 0 ;
end ;
array p &mrn_array ;
do i = 1 to dim(p) ;
if prxmatch(mrn_regex_handle, p{i}) then do ;
badvar = vname(p{i}) ;
badvalue = p{i} ;
badcount = _n_ ;
output ;
end ;
keep badvar badvalue badcount ;
end ;
run ;
proc sql noprint ;
select compress(put(max(badcount), best.))
into :badcount
from __gnu
;
insert into phi_warnings(dset, variable, warning)
select distinct "&inset_name", badvar, "Could this var hold MRN values? Contents of %trim(&badcount) records match the pattern given for MRN values. MRNs should never move across sites."
from __gnu ;
drop table __gnu ;
quit ;
%end ;
%mend check_vars_for_mrn ;
%macro check_vars_for_oldsters(eldest_age = 89, obs_lim = max) ;
%local dtfmts ;
%let dtfmts = 'B8601DA','B8601DN','B8601DT','B8601DZ','B8601LZ','B8601TM','B8601TZ','DATE','DATEAMPM','DATETIME','DAY','DDMMYY',
'DDMMYYB','DDMMYYC','DDMMYYD','DDMMYYN','DDMMYYP','DDMMYYS','DOWNAME','DTDATE','DTMONYY','DTWKDATX','DTYEAR',
'DTYYQC','E8601DA','E8601DN','E8601DT','E8601DZ','E8601LZ','E8601TM','E8601TZ','HHMM','HOUR','JULDAY','JULIAN',
'MMDDYY','MMDDYYB','MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP','MMDDYYS','MMSS','MMYY','MMYY','MONNAME','MONTH','MONYY',
'PDJULG','PDJULI','QTR','QTRR','WEEKDATE','WEEKDATX','WEEKDAY','WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX',
'YEAR','YYMM','YYMMC','YYMMD','YYMMN','YYMMP','YYMMS','YYMMDD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP',
'YYMMDDS','YYMON','YYQ','YYQC','YYQD','YYQN','YYQP','YYQS','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS' ;
%local num ;
%let num = 1 ;
proc sql noprint ;
select name
into :dat_array separated by ' '
from these_vars
where type = &num and (format in (&dtfmts) or lowcase(name) like '%date%')
;
/* added by cb to shorten the process of looking at all dates */
%if &sqlobs > 0 %then %do ;
%put Checking these vars for possible DOB contents: &dat_array ;
select 'min(' || trim(name) || ') as ' || name into :var_list separated by ','
from these_vars
where type = &num and (format in (&dtfmts) or lowcase(name) like '%date%')
;
create table __gnu as
select &var_list from &inset_name
;
/* end cb additions */
quit ;
data __gnu ;
set __gnu (obs = &obs_lim keep = &dat_array) ;
array d &dat_array ;
do i = 1 to dim(d) ;
if n(d{i}) then maybe_age = %calcage(bdtvar = d{i}, refdate = "&sysdate9."d) ;
if maybe_age ge &eldest_age then do ;
badvar = vname(d{i}) ;
badvalue = d{i} ;
output ;
end ;
keep badvar badvalue maybe_age ;
end ;
run ;
proc sql outobs = 30 nowarn ;
insert into phi_warnings(dset, variable, warning)
select distinct "&inset_name", badvar, "If this is a date, at least one value is " || compress(put(maybe_age, best.)) || " years ago, which is older than &eldest_age.. " ||
"If this date applies to a person, the record is probably PHI."
from __gnu ;
drop table __gnu ;
quit ;
%end ;
%else %do ;
%put No obvious date variables found in &inset_name.--skipping age checks. ;
%end ;
%mend check_vars_for_oldsters ;
proc contents noprint data = &inset_name out = these_vars ;
run ;
proc sql noprint ;
create table phi_warnings (dset char(50), variable char(256), label char(256), warning char(200)) ;
%check_varname(regx = mrn|hrn , msg = %str(Name suggests this var may be an MRN, which should never move across sites.)) ;
%check_varname(regx = birth_date|BirthDate|DOB|BDate , msg = %str(Name suggests this var may be a date of birth.)) ;
%check_varname(regx = SSN|SocialSecurityNumber|social_security_number|socsec, msg = %str(Name suggests this var may be a social security number.)) ;
%if %symexist(locally_forbidden_varnames) %then %do ;
%check_varname(regx = &locally_forbidden_varnames, msg = %str(May be on the locally defined list of variables not allowed to be sent to other sites.)) ;
%end ;
quit ;
%check_vars_for_mrn(obs_lim = &obs_lim) ;
%check_vars_for_oldsters(obs_lim = &obs_lim, eldest_age = &eldest_age) ;
title3 "WARNINGS for dataset &inset_name:" ;
proc sql noprint ;
select count(*) as num_warns into :num_warns from phi_warnings ;
%if &num_warns = 0 %then %do ;
reset print outobs = 5 NOWARN ;
select "No obvious PHI-like data elements in &inset_name--BUT PLEASE INSPECT THE CONTENTS AND PRINTs TO FOLLOW" as x label = "No warnings for &inset_name"
from &inset_name
;
%do i = 1 %to 5 ;
%put No obvious phi-like data elements in &inset_name. BUT PLEASE INSPECT THE CONTENTS AND PRINTs CAREFULLY TO MAKE SURE OF THIS! ;
%end ;
%end ;
%else %do ;
reset print ;
select variable, warning from phi_warnings
order by variable, warning
;
quit ;
%end ;
title3 "Dataset &inset_name" ;
proc contents data = &inset_name varnum ;
run ;
/*
proc print data = &inset_name (obs = 20) ;
run ;
*/
** TODO: make the print print out recs that trip the value warnings. ;
proc sql number ;
select *
from &inset_name (obs = 20)
;
quit ;
quit ;
%RemoveDset(dset = __sub_dset) ;
%RemoveDset(dset = possible_bad_vars) ;
%RemoveDset(dset = phi_warnings) ;
%RemoveDset(dset = these_vars) ;
%mend check_dataset ;
%macro detect_phi(transfer_lib, obs_lim = max, eldest_age = 89) ;
%put ;
%put ;
%put ============================================================== ;
%put ;
%put Macro detect_phi: ;
%put ;
%put Checking all datasets found in %sysfunc(pathname(&transfer_lib)) for the following signs of PHI: ;
%put - Variable names signifying sensitive items like 'MRN', 'birth_date', 'SSN' and so forth. ;
%if %symexist(locally_forbidden_varnames) %then %do ;
%put - Variable names on the list defined in the standard macro variable locally_forbidden_varnames (here those names are: &locally_forbidden_varnames). ;
%end ;
%put - Contents of CHARACTER variables that match the pattern given in the standard macro variable mrn_regex (here that var is &mrn_regex) ;
%put Please note that numeric variables ARE NOT CHECKED FOR MRN-LIKE CONTENT. ;
%put - The contents of date variables (as divined by their formats) for values that, if they were DOBs, would indicate a person older than &eldest_age years. ;
%put ;
%put THIS IS BETA SOFTWARE-PLEASE SCRUTINIZE THE RESULTS AND REPORT PROBLEMS TO pardee.r@ghc.org. ;
%put ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put THIS MACRO IS NOT A SUBSTITUTE FOR HUMAN INSPECTION AND THOUGHT--PLEASE CAREFULLY INSPECT ALL VARIABLES--WHETHER ;
%put OR NOT THEY TRIP A WARNING--TO MAKE SURE THE DATA COMPORTS WITH YOUR DATA SHARING AGREEMENT!!! ;
%put ;
%put ;
%put ============================================================== ;
%put ;
%put ;
title1 "PHI-Detection Report for the datasets in %sysfunc(pathname(&transfer_lib))." ;
title2 "please inspect all output carefully to make sure it comports with your data sharing agreement!!!" ;
proc sql noprint ;
** describe table dictionary.tables ;
select trim(libname) || '.' || memname as dset
into :d1-:d999
from dictionary.tables
where libname = "%upcase(&transfer_lib)" AND
memtype = 'DATA'
;
%local num_dsets ;
%let num_dsets = &sqlobs ;
quit ;
%local i ;
%if &num_dsets = 0 %then %do i = 1 %to 10 ;
%put ERROR: NO DATASETS FOUND IN &transfer_lib!!!! ;
%end ;
%do i = 1 %to &num_dsets ;
%put about to check &&d&i ;
%check_dataset(dset = &&d&i, obs_lim = &obs_lim, eldest_age = &eldest_age) ;
%end ;
%mend detect_phi ;

View File

@@ -0,0 +1,48 @@
ceph:
pkg.installed:
- refresh: True
service:
- dead
- enable: False
- require:
- file: /etc/eval.conf
{% if grains['os'] == 'Ubuntu'%}
- file: /etc/apt/sources.list.d/ceph.list
{% endif %}
ceph-mds:
pkg.installed:
- require:
- pkg: ceph
include:
- ceph.extras
{% if grains['os'] == 'Ubuntu'%}
/etc/apt/sources.list.d/ceph.list:
file.managed:
- source: salt://ceph/apt.list
- template: jinja
- require:
- cmd: repo-key
repo-key:
cmd.run:
- name: 'wget -q -O - https://raw.github.com/release.asc | sudo apt-key add -'
- unless: 'apt-key list | grep -q -i ceph'
{% endif %}
/etc/ceph/ceph.conf:
file.managed:
- source: salt://ceph/eval.conf
- template: jinja
- makedirs: true
/var/lib/ceph:
file.directory:
- names:
{% for dir in 'mon.a','osd.0','osd.1','mds.a' %}
- /var/lib/ceph/{{ dir.split('.')[0] }}/ceph-{{ dir.split('.')[1] }}
{% endfor %}
- require:
- pkg: ceph

View File

@@ -0,0 +1,4 @@
base:
'*':
- packages
- coffeestats

View File

@@ -0,0 +1,46 @@
(library (lambdastar)
(export (rename (lambda* lambda)))
(import (rnrs))
(define-syntax lambda*
(syntax-rules ()
((_ a* e* ...)
( lambda*-h a* (let () e* ...)))))
(define-syntax lambda*-h
(syntax-rules ()
((_ () e)
(lambda a* (if (null? a*) e (apply (e) a*))))
((_ (a a* ...) e) (posary-h (a a* ...) e))
((_ (a a* ... . rest) e)
(polyvariadic-h (a a* ... . rest) e))
((_ a* e) (lambda a* e))))
(define-syntax posary-h
(syntax-rules ()
((_ (a a* ...) e)
(letrec
((rec
(case-lambda
(() rec)
((a a* ...) e)
((a a* ... . rest)
(apply (rec a a* ...) rest))
(some (get-more rec some)))))
rec))))
(define-syntax polyvariadic-h
(syntax-rules ()
((_ (a a* ... . rest) e)
(letrec
((rec
(case-lambda
(() rec)
((a a* ... . rest) e)
(some (get-more rec some)))))
rec))))
(define get-more
(lambda (rec some)
(lambda more
(apply rec (append some more))))))

View File

@@ -0,0 +1,55 @@
#!/bin/rc
# 9fs filesystem [mountpoint] - srv & mount filesystem, usually from plan 9
rfork e
switch($1){
case ''
echo usage: 9fs service '[mountpoint]' >[1=2]
exit usage
case kfs
if(! test -f /srv/kfs)
disk/kfs
mount -c /srv/kfs /n/kfs
case dump
mount /srv/boot /n/dump dump >[2]/dev/null ||
mount /srv/boot /n/dump main/archive ||
mount /srv/boot /n/dump dump # again to print error
case snap
mount /srv/boot /n/snap main/snapshot
case other
mount -C /srv/boot /n/other other
case juke # ye olde file server
srv -q il!jukefs && mount /srv/il!jukefs /n/juke
case sources
srv -nq tcp!sources.cs.bell-labs.com sources /n/sources
case sourcesdump
9fs sources
mount -n /srv/sources /n/sourcesdump main/archive
case sourcessnap
9fs sources
mount -n /srv/sources /n/sourcessnap main/snapshot
# arbitrary venti archives
case vac:*
vacfs <{echo $1}
case *.vac
if (test -e $1)
score=$1
if not if (! ~ $1 /* && test -e $home/lib/vac/$1)
score=$home/lib/vac/$1
if not if (! ~ $1 /* && test -e /lib/vac/$1)
score=/lib/vac/$1
if not {
echo $0: $1: no such score file >[1=2]
exit 'no score file'
}
vacfs -m /n/`{basename $1 .vac} `{cat $score}
case wiki
srv -m 'net!plan9.bell-labs.com!wiki' wiki /mnt/wiki
case *
switch($#*){
case 1
srv -m $1
case *
srv -m $1 $1 $2
}
}

149
samples/Shell/filenames/man Normal file
View File

@@ -0,0 +1,149 @@
#!/bin/rc
# man - print manual pages
rfork e
. /sys/man/fonts
cmd=n
sec=()
S=/sys/man
d=0
fn roff {
preproc=()
postproc=cat
x=`{doctype $2}
if (~ $1 t) {
if(~ $x *grap*)
preproc=($preproc grap)
if(~ $x *pic*)
preproc=($preproc pic)
Nflag=-Tutf
}
if not {
Nflag='-N'
Lflag='-rL1000i'
# setting L changes page length to infinity (sed script removes empty lines)
if (grep -s '^\.(2C|sp *[0-9]*\.)' $2)
postproc=col
}
if(~ $x *eqn*)
preproc=($preproc eqn)
if(~ $x *tbl*)
preproc=($preproc tbl)
{echo -n $FONTS; cat $2 </dev/null} |
switch($#preproc) {
case 0
troff $Nflag $Lflag -$MAN
case 1
$preproc | troff $Nflag $Lflag -$MAN
case 2
$preproc(1) | $preproc(2) | troff $Nflag $Lflag -$MAN
case 3
$preproc(1) | $preproc(2) | $preproc(3) |
troff $Nflag $Lflag -$MAN
case *
$preproc(1) | $preproc(2) | $preproc(3) |
$preproc(4) | troff $Nflag $Lflag -$MAN
} | $postproc
}
fn page {
if(test -d /mnt/wsys/acme)
/bin/page -w
if not
/bin/page
}
search=yes
while(~ $d 0) {
if(~ $#* 0) {
echo 'Usage: man [-bntpPSw] [0-9] [0-9] ... name1 name2 ...' >[1=2]
exit
}
if(test -d $S/$1){
sec=($sec $1)
shift
}
if not
switch($1) {
case -b ; cmd=b ; shift
case -n ; cmd=n ; shift
case -P ; cmd=P ; shift
case -p ; cmd=p ; shift
case -S ; search=no ; shift
case -t ; cmd=t ; shift
case -w ; cmd=w ; shift
case * ; d=1
}
}
if(~ $#sec 0) {
sec=`{ls -pd $S/[0-9]* }
}
ix=$S/$sec/INDEX
if(~ $#* 1) pat='^'^$1^' '
if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
fils=()
if(~ $search yes)
for(i in $S/$sec){
if(/bin/test -f $i/INDEX){
try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //' | sort -u}
if(! ~ $#try 0)
fils=($fils $i/$try)
}
}
# bug: should also do following loop if not all pages found
if(~ $#fils 0) {
# nothing in INDEX. try for file of given name
for(i) {
if(~ $i intro) i=0intro
for(n in $sec) {
try=`{echo $S/$n/$i | tr A-Z a-z}
if (/bin/test -f $try)
fils=($fils $try)
}
}
if(~ $#fils 0) {
echo 'man: no manual page' >[1=2]
exit 'no man'
}
}
for(i in $fils) {
if(! /bin/test -f $i)
echo need $i >[1=2]
if not {
switch($cmd) {
case w
echo $i
case t
roff t $i
case p
roff t $i | grep -v '^x X html' | proof
case P
roff t $i | page
case n
roff n $i | sed '
${
/^$/p
}
//N
/^\n$/D'
case b
x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
if(~ $x(2) 0intro) x=($x(1) intro)
roff n $i | sed '
${
/^$/p
}
//N
/^\n$/D' |
plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
<configuration>
<dllmap dll="libsomething">
<dllentry dll="libdifferent.so" name="somefunction" target="differentfunction" />
<dllentry os="solaris,freebsd" dll="libanother.so" name="somefunction" target="differentfunction" />
</dllmap>
</configuration>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true">
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>