GALiRe 2,1,2-b Inventory
 -- aAScript



CONDITIONALS
tertiary:  (EXP  ?  RET1  :  RET0)
if( EXP ) {}  else if( EXP ) {}  else {} -- FILE_OK, MDARY_OK




LOOP
while( EXP ) {} -- FILES, TYPEOF (partial), MDARY_OK

if EXP takes the form $ = %:
	loop through each set of hash returning the key to $ each time

elsif EXP takes the form $=IN1 and $<=>IN2 and $MATH:
	set $ to IN1 and loop, incrementing $ by MATH until IN1 <=> IN2
	
elsif EXP takes the form VAR = @  OR  VAR = # (file):
	loop through each value/line returning the value to VAR each time
	
	if the individual value of @ is an array (MDARY):
		if VAR: ?
			return the entire array to @VAR as an array and set ?VAR to 2
		elsif VAR: @
			return the entire array to the VAR array
		elsif VAR: $
			return the length of the array to VAR
			
	else (individual value of @/# (file) is a scalar):
		if VAR: $
			return the value to VAR
		elsif VAR: @
			return the value to VAR (should be scalar)
		elsif VAR: ?
			return the value to $VAR and set ?VAR to 1
		elsif VAR: %
			return the value to VAR (should be scalar)

else
	loops until EXP is false




METHOD
 -- FILE_OK -- CANT IMPORT ARRAYS (YET)
 method IN1( IN2 ) {}
 
IN2 can be a variable or a list of variables
execute the method by &IN1 or &IN1(IN2)




shortcut assignment operators
works on scalars only (+= and =+ works as concatenators otherwise)
**=    *=    +=    -=    /=    %=    -- ex)  A /= B   means A = A/B
=**    =*    =+    =-    =/    =%    -- ex)  A =/ B   means A = B/A




VARS
docReferrer
docLocation
browserInfo
queryString
requestMethod "POST" "GET" or "UPLOAD"
%POST
%GET
%UPLOAD
	%"FILE_NAME" - name of the <file> TAG
		"name" 
		"type"
		"format" ('binary' or 'ascii')
		"isbinary"or "isBinary"  (0/1) 
		"isascii" or "isAscii" or "isASCII" (0/1)
		"size"
		"contents" (contents of file)




incremental (++)  and  decremental (--)
 -- scalar only, MDARY
only works on tokens $, @ (multi-level) and % (acting as string only)
takes the form ++IN1/--IN1  OR  IN1++/IN1--
if ++IN1 then return value before incrementing, else return after incrementing (same for --)




array concatenation @+@
works with multi-level




add( IN1 ) to( IN2 )X  -DESTRUCTIVE
 -- FILES, MDARY_OK, TYPEOF, hashes -- one at a time
X can be b (begenning), anything else renders as e (end)

	if IN2: @
		if IN1: !@ (stringVar)
			treat IN1 as list, break up at commas and store as array
		else
			retrieve values of array
		
		if X: b
			append each value to beginning of IN2 (in reverse order)
		else
			append each value to end of IN2
		
		return new length of IN2

	elsif IN2: %
		IN1 can hold hash stubs, which is then added to IN2 (order doesn't matter)
		IN1 can also hold another hash (combines it with IN2 hash)
		IN1 can hold an array 
			base indices used - 0,1,2 ..., unless an array value has '=' in it
			if a value has '=', then split it at the = and use key=value format
		IN1 can also hold a stringVar (0 used as key)
		return new number of values (keys) in IN2

	elsif IN2: # (DB)
		IN1 should hold hash stubs, which are then added to the database at IN2 as a new row
		or it can contain a hash, which are then added to the database IN2 as new row
		return success fail (1/0)
		
	elsif IN2: # (file)
		if IN1: !@ (stringVar)
			treat IN1 as list, break up at commas and store as array
		else
			retrieve values of array
		
		if X: b
			append each value to beginning of IN2 (in reverse order)
		else
			append each value to end of IN2
		
		set IN2 as altered
		return new length of IN2
	
	else 
		IN1 can be a stringVar only
		
		if X: b
			append to beginning of IN2
		else
			append to end of IN2
		
		return new strlen of IN2




 IN1 beginsWith( IN2 )  OR   IN1 endsWith( IN2 )X  -NON_DESTRUCTIVE
 -- first letter (scalar) or first element (array) or first line (file) -- FILES, TYPEOF, MDARY_OK -- ONLY GOES DEPTH OF 1 WITH MDARY (keeps parens -- 1,2,(2,3),5 -- )
X can be i (case-insensitive), anything else renders as (case-sensitive)

NOTE: this can also take the form b( IN1 IN2 )X  OR  e( IN1 IN2 )X
IN2 can be a stringVar only (or REGEX if IN1 is a stringVar)

	if IN1: @
		retrieve values of array, if beginsWith then store first value, otherwise store last value
		
	elsif IN1: # (file)
		retrieve lines of file, if beginsWith then store first line, otherwise store last line
		
	else
		if IN2: !REGEX
			if beginsWith then store first character, otherwise store last character
		else 
			store IN2
	
	evaluate, return 0/1




compare( IN1 )X and( IN2 )  OR  contrast( IN1 )X and( IN2 )  -NON_DESTRUCTIVE
X can be k (keys)  and  v (values)  -- defaults k

IN1 must be same type as IN2

	combine IN1 and IN2 and store
	
	if IN1: @  OR  # (file)
		if compare then return array of intersection, otherwise return array of difference
		
	elsif IN1: %
		compute intersection of hashes (based on k,v,kv)
			if X: kv
				return hash of intersection/difference where both k and v pair matched/contrasted
			else
				return array of intersection/difference where k (or v) matched/contrasted




IN1 contains( IN2 )X  OR  IN1 lacks( IN2 )X  -NON_DESTRUCTIVE
 -- FILES, TYPEOF, MDARY_OK
X can be i (case-insensitive), else renders as (case-sensitive)
X can also be k (keys)  and  v (values) -- defaults k

NOTE: this can also take the form c( IN1 IN2 )X  OR  l( IN1 IN2 )X

	if IN1: @
		if IN2: @
			evaluate if IN1 contains all IN2, return 0/1
		else
			IN2 can be REGEX or a string (match entire value)
			evaluate if IN2 is any value in IN1, return 0/1
			
	elsif IN1: # (file)
		IN2 can be REGEX or a string (match entire line)
		evaluate if IN2 is any value in IN1, return 0/1
		
	elsif IN1: %
		if X: kv
			evaluate whether either k or v, return 0/1
		else
			evaluate whether either k (or v), return 0/1
			
	else
		IN2 can be REGEX only
		evaluate and return 0/1




delete( IN1 )  -DESTRUCTIVE

	if IN1: @
		if IN1 specifies a higher level only remove that level, otherwise delete the @
		
	elsif IN1: %
		if IN1 specifies a higher level only remove that level, otherwise delete the %
		
	elsif IN1: #
		delete the filehandle only
		
	else
		delete the variable
	
	return 0/1 (fail/success)




indexOf( IN1 )X in( IN2 )X  OR  lastIndexOf( IN1 )X in( IN2 )X  -NON_DESTRUCTIVE
 -- FILES, TYPEOF, MDARY_OK, no hashes
X can be i (case-insensitive), anything else renders as (case-sensitive)

NOTE:  return value starts at -1 (no instances returns -1)

	if IN2: # (file)  OR  @
		IN1 can be stringVar or REGEX
		return first/last value instance of IN1 in IN2
		
	else
		IN1 can be stringVar only (REGEX treated as stringVar)
		return first/last instance of IN1 in IN2




IN1 isDefined()  -NON_DESTRUCTIVE

NOTE:  this can be done by asking if (IN1) as well

	if IN1: @
		IN1 can be multi-level
		evaluate, return 0/1
		
	elsif IN1: %
		IN1 can be whole hash or one value
		evaluate, return 0/1
		
	elsif IN1: #
		evaluate if filehandle exists, return 0/1
		
	else
		evaluate if variable exists, return 0/1




join( IN1 )X by( IN2 )  OR  join( IN1 )X  -NON_DESTRUCTIVE
 -- FILES, MDARY_OK, TYPEOF -- collapses MDARYs and joins them by commas, hashes
X can be k (key) or v (value) -- defaults v

NOTE: if IN2 doesn't exist, default to comma ","

	if IN1: # (file)
		retrieve file and store as array
		
	elsif IN1: %
		if X: k
			store keys as array
		else
			store values as array
			
	else
		IN1 can be an array only
		
		retrieve array and store
	
	join values of store by IN2 and return as string




lc( IN1 ) where( IN2 )  OR  uc( IN1 ) where( IN2 )  -NON_DESTRUCTIVE
 -- DBA
 
NOTE: also takes for forms lower, lowercase, upper, and uppercase
IN1 MUST be a database filehandle
IN2 is a where() match and may contain functions

	retrieve rows from database where IN2 is true
	uppercase/lowercase them
	return as an array




lc( IN1 )X  OR  uc( IN1 )X  -NON_DESTRUCTIVE
 -- FILES, MDARY_OK, TYPEOF, DBA
X can be k (key) and  v (value) -- defaults v

NOTE: also takes for forms lower, lowercase, upper, and uppercase
IN1 can be array, file, database, hash, or stringVar

	return evaluated as respective




lcfirst( IN1 ) where( IN2 )  OR  ucfirst( IN1 ) where( IN2 )  -NON_DESTRUCTIVE
 -- DBA
 
IN1 MUST be a database filehandle
IN2 is a where() match and may contain functions

	retrieve rows from database where IN2 is true
	uppercase/lowercase the first character of each cell
	return as an array




lcfirst( IN1 )X  OR  ucfirst( IN1 )X  -NON_DESTRUCTIVE
 -- FILES, TYPEOF, MDARY_OK, DBA
X can be k (key) and  v (value) -- defaults v

IN1 can be array, file, database, hash, or stringVar

	return evaluated as respective




length( IN1 )  -NON_DESTRUCTIVE
 -- FILES, TYPEOF, MDARY_OK, DIR, DBA
 
NOTE: also takes for form lengthOf( IN1 )
can handle file, array, stringVar, hash

	if IN1: stringVar
		return text length
	else
		return number of values




random( IN1 ) -NON_DESTRUCTIVE
 -- scalar, arrays
 
	if IN1: @
		randomize the order of the values in the array
	else
		if IN1 is a range (#-#) then generate a random number from lower to upper bound
		otherwise generate a random number from 0 to IN1
	
	return respective




remove( IN1 )X from( IN2 ) -DESTRUCTIVE
 -- index/range (array/file), key (hash), pattern/range (scalar), FILES, TYPEOF, MDARY_OK, DBA
X can be g (global removal)  and  i (case-insesitive) -- defaulting to (case-sensitive)  and  (single-instance)

	if IN2: @
		IN1 can be "duplicate", "duplicates", "first", "last", an integer, a startLen (start,length) or range (#-#) 
		returns what is removed
		
	elsif IN2: # (file)
		IN1 can be "duplicate", "duplicates", "first", "last", an integer, a startLen (start,length) or range (#-#) 
		NOTE: this alters the file itself
		returns what is removed

	elsif IN2: # (DBA)
		IN1 is the name of a column, must be used in conjunction with where() statement (right now)
		NOTE: this alters the table itself
		returns what is removed
		
	elsif IN2: %
		IN1 can be "duplicate", "duplicates", or an integer
		return what is removed
		
	else
		IN1 can be "duplicate", "duplicates", REGEX, or a stringVar
		takes heed of X
		return what is removed




replace( IN1 )X with( IN2 )X in( IN3 )X -NON_DESTRUCTIVE
 -- FILES, TYPEOF, DBA, MDARY_OK -- ONLY GOES DEPTH OF 1 WITH MDARY (keeps parens -- 1,2,(2,3),5 -- ), hashes - must be global for literal hash
X can be k (keys) and  v (values) -- defaults v
X can be i (case-insensitive) -- defaults (case-sensitive)
X can be g (global replace) -- defaults (single-instance)

	if IN1: startLen  OR  range  OR  integer  AND IN3: @  OR  # (file)
		splice and return new respective
		
	elsif IN1: startLen  OR  range  OR  integer AND IN3: stringVar
		substr and return new string
		
	elsif IN3: @  OR  # (file)
		IN1 should be REGEX or stringVar
		replace in each value and return new respective

	elsif IN3: # (DBA)
		IN1 should be a column name, can be used with a where() statement
		replace in each value and return new respective
		
	elsif IN3: %
		IN1 should be REGEX or stringVar
		replace in each key/value (based on X) and return new hash
		
	else
		IN1 should be REGEX (stringVar treated as REGEX)
		replaces and returns string




reverse( IN1 ) -DESTRUCTIVE
 -- FILES, TYPEOF, DBA, MDARY_OK - should be depth of 1 only, hashes
 
	if IN1: @
		reverse array order and return new array
		
	elsif IN1: %
		reverse keys and values and returns new hash
		
	elsif IN1: # (file)
		reverse lines of file and returns as array
		NOTE: this alters the file itself
		
	else
		stringVar only
		reverses the text and returns the new string




round( IN1 ) by( IN2 )  OR  round( IN1 )  -NON_DESTRUCTIVE
 -- scalar, MDARY, TYPEOF
 
NOTE: this can also take the form round( IN1 ) to( IN2 )
NOTE: if IN2 doesn't exist, default to 1

	if IN1: @
		round each value of array to IN2 and return as array
	else
		round IN1 to IN2 and return as string




sort( IN1 ) by( IN2 )  OR  sort( IN1 )  -DESTRUCTIVE, unless for a DB
 -- FILES, TYPEOF, DBA, MDARY_OK - rigged up -- uses first elements of MDARYs --- parens removed temporarily
 
IN2 can be "A-Z" ("letters"), "Z-A", "0-9" ("numbers"), or "9-0"
NOTE: if IN2 doesn't exist, default to "letters" ("A-Z")

	if IN1: # (file)
		sort the array by IN2 and return as array
	else
		IN1 must be an array
		sort IN1 by IN2 and return as array




split( IN1 ) by( IN2 )  -NON_DESTRUCTIVE
 -- scalar, arrays into hashes
 
IN2 can be REGEX or stringVar

	if IN1: @
		split each value of the array by IN2 and return as hash (left of split becomes key)
	else
		IN1 must be stringVar
		split IN1 by IN2 and return as array




select( IN1 )X from( IN2 ) where( IN3 ) -NON_DESTRUCTIVE
 -- DBA
 X can be i (case-insensitive) -- defaults (case-sensitive)

IN2 MUST be a database filehandle
IN3 is a where() match and may contain functions

	retrieve IN1 rows from database where IN3 is true
	return as array




select( IN1 )X from( IN2 )X -NON_DESTRUCTIVE
 -- FILES, TYPEOF, MDARY_OK, hashes, DBA, DIR
X can be i (case-insensitive) -- defaults (case-sensitive)
X can be k (keys)  and  v (values) -- defaults v

	if IN1: startLen  OR  range  OR  integer  AND  !REGEX
		if IN2: # (DB)
			retrieve IN1 rows from database and return as array
		elsif IN2: # (file)
			return line(s) from file according to IN1 as array
		elsif IN2: @
			return value(s) from array according to IN1 as array
		else 
			return substr WRT IN1 as string
	
	else
		IN2 cannot be scalar
		IN1 can be "keys" or "values" or stringVar
		
		if IN2: # (DB)
			retrieve IN1 rows from database and return as array
		elsif IN2: # (file)  OR  @
			if IN1: REGEX
				returns where line/array value matches IN1 as array
			else
				returns where line/array value equal IN1 as array
		elsif IN2: # (DIR)
			if IN1: REGEX
				returns where filename matches IN1 as array
			else
				returns where filename value equal IN1 as array
		elsif IN2: %
			if IN1: "keys"
				return keys of hash as array
			elsif IN1: "values"
				return values of hash as array
			else
				return match in hash based on X as hash




valueOf( IN1 )  -NON_DESTRUCTIVE
 - FILES, MDARY_OK, TYPEOF, DBA, DIR

NOTE: this can also take the form value( IN1 )

	if IN1: # (file) 
		returns entire file as array
	elsif IN1: # (DB)
		returns all columns and rows from database as array
	else
		returns value of IN1




submit( IN1 )  -DESTRUCTIVE
 - FILES

save file and return 0/1 on fail/success




close( IN1 )  -DESTRUCTIVE
 - FILES, DBA, DIR

	if IN1: # (file) 
		saves file, removes the IN1 filehandle,  and returns 1
	elsif IN1: # (DB)
		optimizes the table, removes the IN1 filehandle, and returns 1
	elsif IN1: # (DIR)
		removes the IN1 filehandle, and returns 1




reset( IN1 )   -DESTRUCTIVE
 - FILES

clears out the IN1 filehandle and resets it to the value of the file, returns 0/1 on fail/success




open( IN1 ) as( IN2 )   -DESTRUCTIVE
 - FILES, DBA, DIR

opens the file, directory, or database, creates the IN2 filehandle, and returns 0/1 on fail/success
if file doesn't exist ... create it and continue




multiply( IN1 ) by( IN2 )  -NON_DESTRUCTIVE
 -- FILE_OK, TYPEOF, MDARY_OK, no hashes

NOTE: IN2 must be between 2 and 500

repeat the string/array IN2 times and return as respective




charAt( IN1 ) in( IN2 )  -NON_DESTRUCTIVE
 -- scalar only

IN1 must be an integer starting at 0
returns the character in IN2 at position IN1




solve( IN1 )  -NON_DESTRUCTIVE
 -- scalar only

solves IN1 mathematically and returns the value




return( IN1 )  -NON_DESTRUCTIVE
 -- FILE_OK

return IN1 (for methods)




quit()  OR  die()
 -- FILE_OK
 
 NOTE: this can also take the form quit;  and  die;

 exits scripting, no returns
 
 
 
 
 next;  OR  continue;
  -- FILE_OK, MDARY_OK
 
 skips the rest of the loop and starts on the next loop, returns nothing
 
 
 
 
 info( IN1 )  -NON_DESTRUCTIVE
 
 IN1 should be the name of a file
 returns a hash containing information about the file
	 mdate = date last modified
	 mtime = time (since epoch) last modified
	 size = file size (in bytes)
	 ftype = file type (binary/ascii/empty)
	 stype = type of system data (directory/file)
	 isdir = is a directory
	 isfile = is a file
	 isascii = is ascii (text)
	 isbinary = is binary
 
 
 
 
  move( IN1 ) to( IN2 )  -NON_DESTRUCTIVE
  
  IN1 should be the name of a file
  IN2 should be the destination (folder)
  returns success/fail (1/0)




   rename( IN1 ) to( IN2 )  -NON_DESTRUCTIVE
   
   IN1 should be the name of a file
   IN2 should be the new name of the file
   returns success/fail (1/0)




 break;  OR  last;
  -- FILE_OK, MDARY_OK
 
 quits the current loop and returns nothing
 
 
 
 
 print( IN1 )
  -- FILE_OK, MDARY_OK
 
NOTE: this can also take the form print "";  and  print VAR;

prints IN1 to the output stream





printc( IN1 )
 -- FILE_OK, MDARY_OK

NOTE: this can also take the form printc "";  and  printc VAR;

print IN1 as code to the output stream (GALiRe tags)