summaryrefslogtreecommitdiff
path: root/1088/CH23
diff options
context:
space:
mode:
Diffstat (limited to '1088/CH23')
-rwxr-xr-x1088/CH23/EX23.1/Example1.sce78
-rwxr-xr-x1088/CH23/EX23.1/Result1.txt88
-rwxr-xr-x1088/CH23/EX23.10/Example10.sce87
-rwxr-xr-x1088/CH23/EX23.10/Result10.txt150
-rwxr-xr-x1088/CH23/EX23.11/Example11.sce77
-rwxr-xr-x1088/CH23/EX23.11/Result11.txt98
-rwxr-xr-x1088/CH23/EX23.12/Example12.sce74
-rwxr-xr-x1088/CH23/EX23.12/Result12.txt93
-rwxr-xr-x1088/CH23/EX23.13/Example13.sce79
-rwxr-xr-x1088/CH23/EX23.13/Result13.txt93
-rwxr-xr-x1088/CH23/EX23.2/Example2.sce98
-rwxr-xr-x1088/CH23/EX23.2/Result2.txt161
-rwxr-xr-x1088/CH23/EX23.3/Example3.sce72
-rwxr-xr-x1088/CH23/EX23.3/Result3.txt87
-rwxr-xr-x1088/CH23/EX23.4/Example4.sce63
-rwxr-xr-x1088/CH23/EX23.4/Result4.txt91
-rwxr-xr-x1088/CH23/EX23.5/Example5.sce66
-rwxr-xr-x1088/CH23/EX23.5/Result5.txt92
-rwxr-xr-x1088/CH23/EX23.6/Example6.sce123
-rwxr-xr-x1088/CH23/EX23.6/Result6.txt176
-rwxr-xr-x1088/CH23/EX23.7/Example7.sce85
-rwxr-xr-x1088/CH23/EX23.7/Result7.txt99
-rwxr-xr-x1088/CH23/EX23.8/Example8.sce76
-rwxr-xr-x1088/CH23/EX23.8/Result8.txt137
-rwxr-xr-x1088/CH23/EX23.9/Example9.sce80
-rwxr-xr-x1088/CH23/EX23.9/Result9.txt108
26 files changed, 2531 insertions, 0 deletions
diff --git a/1088/CH23/EX23.1/Example1.sce b/1088/CH23/EX23.1/Example1.sce
new file mode 100755
index 000000000..2599a1e00
--- /dev/null
+++ b/1088/CH23/EX23.1/Example1.sce
@@ -0,0 +1,78 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 1 : Show the method of copying files with the read and write system calls \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program ccp.c -- Copies a file with the read and write system calls */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <fcntl.h> /* For O_RDONLY , O_WRONLY , O_CREAT etc. */'
+i=i+1;f(i)='#include <sys/stat.h> /* for S_IRUSR , S_IWUSR , S_IRGRP etc. */'
+i=i+1;f(i)='#define BUFSIZE 1024 /* May not be the rigth size here */'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' int fd1, fd2; /* File descriptors for read and write */'
+i=i+1;f(i)=' int n; /* Number of characters returned by read */'
+i=i+1;f(i)=' char buf[BUFSIZE]; /* BUFSIZE should be carefully chosen */'
+i=i+1;f(i)=' fd1 = open('+ascii(34)+'/etc/passwd'+ascii(34)+',O_RDONLY);'
+i=i+1;f(i)=' fd2 = open('+ascii(34)+'passwd.bak'+ascii(34)+',O_WRONLY | O_CREAT | O_TRUNC ,'
+i=i+1;f(i)=' S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); /* Mode 664*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' while ((n = read(fd1, buf, BUFSIZE)) > 0) /* Return value of read is */'
+i=i+1;f(i)=' write(fd2, buf, n); /* used by write as argument */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' close(fd1);'
+i=i+1;f(i)=' close(fd2);'
+i=i+1;f(i)=' exit(0); /* This would have closed all file descriptors */'
+i=i+1;f(i)='}'
+n=i
+printf("\n\n$ cat ccp.c # to open the file emp.lst")
+halt(' ')
+u=mopen('ccp.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc ccp.c")
+ halt(' ')
+ printf("$ a.out")
+ halt(' ')
+ printf("$ cmp /etc/passwd passwd.bak")
+ halt(' ')
+if getos()=='Linux' then
+unix_w('cc ccp.c;a.out;cmp /etc/passwd passwd.bak')
+else
+ printf("$ _ # Prompt returns-files identical")
+ halt(' ')
+end
+
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.1/Result1.txt b/1088/CH23/EX23.1/Result1.txt
new file mode 100755
index 000000000..13866ef0c
--- /dev/null
+++ b/1088/CH23/EX23.1/Result1.txt
@@ -0,0 +1,88 @@
+ ans =
+
+ 1.
+
+-->exec('Example1.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 1 : Show the method of copying files with the read and write system calls
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat ccp.c # to open the file emp.lst /* Program ccp.c -- Copies a file with the read and write system calls */
+
+#include <fcntl.h> /* For O_RDONLY , O_WRONLY , O_CREAT etc. */
+#include <sys/stat.h> /* for S_IRUSR , S_IWUSR , S_IRGRP etc. */
+#define BUFSIZE 1024 /* May not be the rigth size here */
+
+int main(void) {
+ int fd1, fd2; /* File descriptors for read and write */
+ int n; /* Number of characters returned by read */
+ char buf[BUFSIZE]; /* BUFSIZE should be carefully chosen */
+ fd1 = open("/etc/passwd",O_RDONLY);
+ fd2 = open("passwd.bak",O_WRONLY | O_CREAT | O_TRUNC ,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); /* Mode 664*/
+
+ while ((n = read(fd1, buf, BUFSIZE)) > 0) /* Return value of read is */
+ write(fd2, buf, n); /* used by write as argument */
+
+ close(fd1);
+ close(fd2);
+ exit(0); /* This would have closed all file descriptors */
+}
+ $ cc ccp.c $ a.out $ cmp /etc/passwd passwd.bak $ _ # Prompt returns-files identical
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.10/Example10.sce b/1088/CH23/EX23.10/Example10.sce
new file mode 100755
index 000000000..f6eb58d63
--- /dev/null
+++ b/1088/CH23/EX23.10/Example10.sce
@@ -0,0 +1,87 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 10 : Show the method of listing only directories in systems programming \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0;
+i=i+1;f(i)='/* Program lsdir.c -- Lists only directories using S_IFMT and S_ISDR macros */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <sys/types.h>'
+i=i+1;f(i)='#include <sys/stat.h>'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <dirent.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc,int **argv){'
+i=i+1;f(i)=' DIR *dir;'
+i=i+1;f(i)=' struct dirent *direntry; /* Returned by readdir() */'
+i=i+1;f(i)=' struct stat statbuf; /* Address of statbuf used by lstat() */'
+i=i+1;f(i)=' mode_t file_type, file_perm;'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if ((dir = opendir(argv[1])) == NULL)'
+i=i+1;f(i)=' quit('+ascii(34)+'Couldn'+ascii(39)+'t open directory'+ascii(34)+',1);'
+i=i+1;f(i)=' if((chdir(argv[1]) == -1)) /* Change to directory before */'
+i=i+1;f(i)=' quit('+ascii(34)+'chdir'+ascii(34)+',2); /* you starting reading its entries*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' while ((direntry = readdir(dir)) != NULL) { /* Read each entry in directory*/'
+i=i+1;f(i)=' if (lstat(direntry->d_name,&statbuf) < 0){ /* dname must be in */'
+i=i+1;f(i)=' perror('+ascii(34)+'lstat'+ascii(34)+'); /*current directory */'
+i=i+1;f(i)=' continue;'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' if (S_ISDIR(statbuf.st_mode)) { /*If file is a directory */'
+i=i+1;f(i)=' file_type = statbuf.st_mode & S_IFMT;'
+i=i+1;f(i)=' file_perm = statbuf.st_mode & -S_IFMT;'
+i=i+1;f(i)=' printf('+ascii(34)+'%o %4o %s\n'+ascii(34)+', file_type, file_perm, direntry->d_name);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat lsdir.c # to open the file emp.lst")
+halt(' ')
+u=mopen('lsdir.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc lsdir.c")
+ halt(' ')
+ printf("\n# Enter the name of the directory as command-line argument which you want to access \n")
+ nam=input("$ a.out ",'s')
+ halt(' ')
+ pwd
+ back=ans
+ cd(nam)
+x=dir()
+mprintf("40000 755 %s\n",x.name)
+cd(back)
+ printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.10/Result10.txt b/1088/CH23/EX23.10/Result10.txt
new file mode 100755
index 000000000..0866933af
--- /dev/null
+++ b/1088/CH23/EX23.10/Result10.txt
@@ -0,0 +1,150 @@
+ ans =
+
+ 1.
+
+-->exec('Example10.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 10 : Show the method of listing only directories in systems programming
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat lsdir.c # to open the file emp.lst /* Program lsdir.c -- Lists only directories using S_IFMT and S_ISDR macros */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <dirent.h>
+
+int main(int argc,int **argv){
+ DIR *dir;
+ struct dirent *direntry; /* Returned by readdir() */
+ struct stat statbuf; /* Address of statbuf used by lstat() */
+ mode_t file_type, file_perm;
+
+ if ((dir = opendir(argv[1])) == NULL)
+ quit("Couldn't open directory",1);
+ if((chdir(argv[1]) == -1)) /* Change to directory before */
+ quit("chdir",2); /* you starting reading its entries*/
+
+ while ((direntry = readdir(dir)) != NULL) { /* Read each entry in directory*/
+ if (lstat(direntry->d_name,&statbuf) < 0){ /* dname must be in */
+ perror("lstat"); /*current directory */
+ continue;
+ }
+ if (S_ISDIR(statbuf.st_mode)) { /*If file is a directory */
+ file_type = statbuf.st_mode & S_IFMT;
+ file_perm = statbuf.st_mode & -S_IFMT;
+ printf("%o %4o %s\n", file_type, file_perm, direntry->d_name);
+ }
+ }
+ exit(0);
+}
+ $ cc lsdir.c
+# Enter the name of the directory as command-line argument which you want to access
+ 40000 755 $Recycle.Bin
+40000 755 $SysReset
+40000 755 Boot
+40000 755 bootmgr
+40000 755 BOOTNXT
+40000 755 BOOTSECT.BAK
+40000 755 Dev-Cpp
+40000 755 Documents and Settings
+40000 755 Downloads
+40000 755 Dwimperl
+40000 755 eula.1028.txt
+40000 755 eula.1031.txt
+40000 755 eula.1033.txt
+40000 755 eula.1036.txt
+40000 755 eula.1040.txt
+40000 755 eula.1041.txt
+40000 755 eula.1042.txt
+40000 755 eula.2052.txt
+40000 755 eula.3082.txt
+40000 755 globdata.ini
+40000 755 hiberfil.sys
+40000 755 install.exe
+40000 755 install.ini
+40000 755 install.res.1028.dll
+40000 755 install.res.1031.dll
+40000 755 install.res.1033.dll
+40000 755 install.res.1036.dll
+40000 755 install.res.1040.dll
+40000 755 install.res.1041.dll
+40000 755 install.res.1042.dll
+40000 755 install.res.2052.dll
+40000 755 install.res.3082.dll
+40000 755 odf
+40000 755 pagefile.sys
+40000 755 PerfLogs
+40000 755 Perl64
+40000 755 Program Files
+40000 755 Program Files (x86)
+40000 755 ProgramData
+40000 755 Remote Programs
+40000 755 S
+40000 755 swapfile.sys
+40000 755 System Volume Information
+40000 755 UserGuidePDF
+40000 755 Users
+40000 755 VC_RED.cab
+40000 755 VC_RED.MSI
+40000 755 vcredist.bmp
+40000 755 Windows
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+
+-->diary(0)
diff --git a/1088/CH23/EX23.11/Example11.sce b/1088/CH23/EX23.11/Example11.sce
new file mode 100755
index 000000000..7dc21fa2e
--- /dev/null
+++ b/1088/CH23/EX23.11/Example11.sce
@@ -0,0 +1,77 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 11 : Show the method of listing all the permissions in a file \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: check_all_perm.c -- Checks all 12 permission bits of a file */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <sys/stat.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void print_permissions(char *,struct stat *) ;'
+i=i+1;f(i)='void check_permission(int, int, char *);'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc,char *argv[]) {'
+i=i+1;f(i)=' int i,fd,perm;'
+i=i+1;f(i)=' char *filename = argv[1];'
+i=i+1;f(i)=' struct stat statbuf;'
+i=i+1;f(i)=' mode_t perm_flag[] = {S_IRUSR,S_IWUSR,S_IXUSR,S_IRGRP,S_IWGRP,S_IXGRP,S_IROTH,S_IWOTH,S_IXOTH,S_ISUID,S_ISGID,S_ISVTX );'
+i=i+1;f(i)=''
+i=i+1;f(i)=' char *mesg[] = {'+ascii(34)+'User-readable'+ascii(34)+','+ascii(34)+'User-writable'+ascii(34)+','+ascii(34)+'User-executable'+ascii(34)+','+ascii(34)+'Group-readable'+ascii(34)+','+ascii(34)+'Group-writable'+ascii(34)+','+ascii(34)+'Group-executable'+ascii(34)+','+ascii(34)+'Others-readable'+ascii(34)+','+ascii(34)+'Others-writable'+ascii(34)+','+ascii(34)+'Others-executable'+ascii(34)+','+ascii(34)+'SUID bit set'+ascii(34)+','+ascii(34)+'SGID bit set'+ascii(34)+','+ascii(34)+'Sticky bit set'+ascii(34)+' );'
+i=i+1;f(i)=''
+i=i+1;f(i)=' print_permissions(filename,&statbuf);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' perm = statbuf.st_mode & -S_IFMT;'
+i=i+1;f(i)=' for(i = 0; i < 12;i ++)'
+i=i+1;f(i)=' check_permissions(perm, perm_flag[i], mesg[i]);'
+i=i+1;f(i)='}'
+n=i
+
+
+
+printf("\n\n$ cat check_all_perm.c # to open the file emp.lst")
+halt(' ')
+u=mopen('check_all_perm.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc check_all_perm.c")
+ halt(' ')
+
+ printf("\n$ a.out /usr/bin/passwd ")
+ halt(' ')
+ printf("\nFile: /usr/bin/passwd Permissions: 4511\nUser-readable\nUser-executable\nGroup-executable\nOthers-executable\nSUID bit set\n")
+halt(' ')
+ printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.11/Result11.txt b/1088/CH23/EX23.11/Result11.txt
new file mode 100755
index 000000000..9e0e96351
--- /dev/null
+++ b/1088/CH23/EX23.11/Result11.txt
@@ -0,0 +1,98 @@
+ ans =
+
+ 1.
+
+-->exec('Example11.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 11 : Show the method of listing all the permissions in a file
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat check_all_perm.c # to open the file emp.lst /* Program: check_all_perm.c -- Checks all 12 permission bits of a file */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+void print_permissions(char *,struct stat *) ;
+void check_permission(int, int, char *);
+
+int main(int argc,char *argv[]) {
+ int i,fd,perm;
+ char *filename = argv[1];
+ struct stat statbuf;
+ mode_t perm_flag[] = {S_IRUSR,S_IWUSR,S_IXUSR,S_IRGRP,S_IWGRP,S_IXGRP,S_IROTH,S_IWOTH,S_IXOTH,S_ISUID,S_ISGID,S_ISVTX );
+
+ char *mesg[] = {"User-readable","User-writable","User-executable","Group-readable","Group-writable","Group-executable","Others-readable","Others-writable","Others-executable","SUID bit set","SGID bit set","Sticky bit set" );
+
+ print_permissions(filename,&statbuf);
+
+ perm = statbuf.st_mode & -S_IFMT;
+ for(i = 0; i < 12;i ++)
+ check_permissions(perm, perm_flag[i], mesg[i]);
+}
+ $ cc check_all_perm.c
+$ a.out /usr/bin/passwd
+File: /usr/bin/passwd Permissions: 4511
+User-readable
+User-executable
+Group-executable
+Others-executable
+SUID bit set
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.12/Example12.sce b/1088/CH23/EX23.12/Example12.sce
new file mode 100755
index 000000000..5e3529558
--- /dev/null
+++ b/1088/CH23/EX23.12/Example12.sce
@@ -0,0 +1,74 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 12 : Show the file access rights of a file using the read UID and GID \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/*Program: faccess.c -- Determines a file'+ascii(39)+'s access rigths using read UID and GID */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *,int);'
+i=i+1;f(i)='int main(int argc, char *argv[]) {'
+i=i+1;f(i)=' short count;'
+i=i+1;f(i)=' for (count = 1; count < argc ;++count) {'
+i=i+1;f(i)=' printf('+ascii(34)+'%s '+ascii(34)+',argv[count]);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (access(argv[count],F_OK) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'File not found'+ascii(34)+',1);'
+i=i+1;f(i)=' if (access(argv[count],R_OK) == -1)'
+i=i+1;f(i)=' printf('+ascii(34)+'Not readable '+ascii(34)+');'
+i=i+1;f(i)=' if (access(argv[count],W_OK) == -1)'
+i=i+1;f(i)=' printf('+ascii(34)+'Not writable '+ascii(34)+');'
+i=i+1;f(i)=' if (access(argv[count],X_OK) == -1)'
+i=i+1;f(i)=' printf('+ascii(34)+'Not executable '+ascii(34)+');'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' printf('+ascii(34)+'\n'+ascii(34)+');'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat faccess.c # to open the file emp.lst")
+halt(' ')
+u=mopen('faccess.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc faccess.c")
+ halt(' ')
+ printf("$ a.out /etc/passwd /etc/shadow")
+ halt(' ')
+printf("/etc/passwd: Not writable Not executable\n/etc/shadow: Not readable Not writable Not executable\n\n");
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.12/Result12.txt b/1088/CH23/EX23.12/Result12.txt
new file mode 100755
index 000000000..42e4229e4
--- /dev/null
+++ b/1088/CH23/EX23.12/Result12.txt
@@ -0,0 +1,93 @@
+ ans =
+
+ 1.
+
+-->exec('Example12.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 12 : Show the file access rights of a file using the read UID and GID
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat faccess.c # to open the file emp.lst /*Program: faccess.c -- Determines a file's access rigths using read UID and GID */
+#include <stdio.h>
+#include <unistd.h>
+
+void quit(char *,int);
+int main(int argc, char *argv[]) {
+ short count;
+ for (count = 1; count < argc ;++count) {
+ printf("%s ",argv[count]);
+
+ if (access(argv[count],F_OK) == -1)
+ quit("File not found",1);
+ if (access(argv[count],R_OK) == -1)
+ printf("Not readable ");
+ if (access(argv[count],W_OK) == -1)
+ printf("Not writable ");
+ if (access(argv[count],X_OK) == -1)
+ printf("Not executable ");
+
+ printf("\n");
+ }
+ exit(0);
+}
+ $ cc faccess.c $ a.out /etc/passwd /etc/shadow /etc/passwd: Not writable Not executable
+/etc/shadow: Not readable Not writable Not executable
+
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.13/Example13.sce b/1088/CH23/EX23.13/Example13.sce
new file mode 100755
index 000000000..5f436192d
--- /dev/null
+++ b/1088/CH23/EX23.13/Example13.sce
@@ -0,0 +1,79 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 13 : Show the method of setting a file timestamps \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: atimemtime.c -- Sets a file time stamps to those of another file */'
+i=i+1;f(i)='#include <sys/stat.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)='#include <utime.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *,int);'
+i=i+1;f(i)='int main(int argc,char **argv) {'
+i=i+1;f(i)=' struct stat statbuf; /* To obtain time stamps for an existing file */'
+i=i+1;f(i)=' struct utimbuf timebuf; /* To set time stamps for another file */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (lstat(argv[1], &statbuf) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'stat'+ascii(34)+', 1);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' timebuf.actime = statbuf.st_atime; /* Setting members of timebuf with */'
+i=i+1;f(i)=' timebuf.modtime= statbuf.st_mtime; /* values obtained from statbuf */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (open(argv[2], O_RWR | O_CREAT, 0644) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'open'+ascii(34)+', 2);'
+i=i+1;f(i)=' close(argv[2]); /* Previously used open only to create it */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (utime(argv[2]), &timebuf) == -1) /* Sets both time stamps for file */'
+i=i+1;f(i)=' quit('+ascii(34)+'utime'+ascii(34)+', 3);'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat atimemtime.c # to open the file emp.lst")
+halt(' ')
+u=mopen('atimemtime.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc atimemtime.c")
+ halt(' ')
+ printf("$ mv a.out $HOME;cd;a.out .profile .logintime")
+ halt(' ')
+ printf("$ ls -l .logintime ; ls -lu .logintime")
+ halt(' ')
+ printf("-rw-r--r-- 1 <user> <group> 0 Jun 20 00:55 .logintime\n")
+ printf("-rw-r--r-- 1 <user> <group> 0 Jun 5 00:30 .logintime\n")
+halt(' ')
+
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.13/Result13.txt b/1088/CH23/EX23.13/Result13.txt
new file mode 100755
index 000000000..75f06c5c5
--- /dev/null
+++ b/1088/CH23/EX23.13/Result13.txt
@@ -0,0 +1,93 @@
+ ans =
+
+ 1.
+
+-->exec('Example13.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 13 : Show the method of setting a file timestamps
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat atimemtime.c # to open the file emp.lst /* Program: atimemtime.c -- Sets a file time stamps to those of another file */
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <utime.h>
+
+void quit(char *,int);
+int main(int argc,char **argv) {
+ struct stat statbuf; /* To obtain time stamps for an existing file */
+ struct utimbuf timebuf; /* To set time stamps for another file */
+
+ if (lstat(argv[1], &statbuf) == -1)
+ quit("stat", 1);
+
+ timebuf.actime = statbuf.st_atime; /* Setting members of timebuf with */
+ timebuf.modtime= statbuf.st_mtime; /* values obtained from statbuf */
+
+ if (open(argv[2], O_RWR | O_CREAT, 0644) == -1)
+ quit("open", 2);
+ close(argv[2]); /* Previously used open only to create it */
+
+ if (utime(argv[2]), &timebuf) == -1) /* Sets both time stamps for file */
+ quit("utime", 3);
+ exit(0);
+}
+ $ cc atimemtime.c $ mv a.out $HOME;cd;a.out .profile .logintime $ ls -l .logintime ; ls -lu .logintime -rw-r--r-- 1 <user> <group> 0 Jun 20 00:55 .logintime
+-rw-r--r-- 1 <user> <group> 0 Jun 5 00:30 .logintime
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.2/Example2.sce b/1088/CH23/EX23.2/Example2.sce
new file mode 100755
index 000000000..27a705be5
--- /dev/null
+++ b/1088/CH23/EX23.2/Example2.sce
@@ -0,0 +1,98 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 2 : Show the method of reversing a file using lseek \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: reverse_read.c -- Reads a file in reverse - uses lseek */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <fcntl.h> /* For O_RONLY */'
+i=i+1;f(i)='#include <unistd.h> /* For STDOUT_FILENO */'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' char buf; /* Single-character buffer; will make */'
+i=i+1;f(i)=' int size, fd; /* I/O inefficient. See Section 23.4 */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' fd= open(argv[1], O_RDONLY);'
+i=i+1;f(i)=' size = lseek(fd, -1, SEEK_END); /* Pointer taken to EOF - 1 ... */'
+i=i+1;f(i)=' while (size-- >= 0) { /* ... so siz = file size - 1 */'
+i=i+1;f(i)=' read(fd, &buf, 1); /* Read one character at a time */'
+i=i+1;f(i)=' write(STD_FILENO, &buf, 1); /* and write it immediately */'
+i=i+1;f(i)=' lseek(fd, -2, SEEK_CUR); /* Now move the file pointer back */'
+i=i+1;f(i)=' } /* by two characters */'
+i=i+1;f(i)=' /* exit(0); */ /* done deliberately */'
+i=i+1;f(i)='}'
+n=i
+printf("\n\n$ cat reverse_read.c # to open the file emp.lst")
+halt(' ')
+u=mopen('reverse_read.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+printf("\n$ ls \n")
+halt(' ')
+mode(0)
+ls
+mode(-1)
+nam=input("# Please enter a file from the above list : ",'s')
+printf("\n$ cat %s ",nam)
+halt(' ')
+v=mopen(nam,"rt")
+while ~meof(v)
+ [n,a]=mfscanf(v,"%c");
+ if meof(v) break
+ end
+ printf("%c",a)
+end
+mclose(v)
+halt("")
+printf("\n$ cc reverse_read.c")
+halt("")
+printf("$ a.out %s \n......a blank line... The terminating \\n of the last line",nam)
+halt("")
+v=mopen(nam,"rt")
+mseek(-1,v,'end')
+siz=mtell(v)
+siz=siz-1
+while siz~=-1
+ [n,a]=mfscanf(v,"%c");
+ printf("%c",a)
+ mseek(siz,v)
+ siz=siz-1
+end
+mseek(0,v)
+ [n,a]=mfscanf(v,"%c");
+ printf("%c",a)
+mclose(v)
+halt(' ')
+
+
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.2/Result2.txt b/1088/CH23/EX23.2/Result2.txt
new file mode 100755
index 000000000..4378e7744
--- /dev/null
+++ b/1088/CH23/EX23.2/Result2.txt
@@ -0,0 +1,161 @@
+ ans =
+
+ 1.
+
+-->exec('Example2.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 2 : Show the method of reversing a file using lseek
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat reverse_read.c # to open the file emp.lst /* Program: reverse_read.c -- Reads a file in reverse - uses lseek */
+
+#include <fcntl.h> /* For O_RONLY */
+#include <unistd.h> /* For STDOUT_FILENO */
+
+int main(int argc, char **argv) {
+ char buf; /* Single-character buffer; will make */
+ int size, fd; /* I/O inefficient. See Section 23.4 */
+
+ fd= open(argv[1], O_RDONLY);
+ size = lseek(fd, -1, SEEK_END); /* Pointer taken to EOF - 1 ... */
+ while (size-- >= 0) { /* ... so siz = file size - 1 */
+ read(fd, &buf, 1); /* Read one character at a time */
+ write(STD_FILENO, &buf, 1); /* and write it immediately */
+ lseek(fd, -2, SEEK_CUR); /* Now move the file pointer back */
+ } /* by two characters */
+ /* exit(0); */ /* done deliberately */
+}
+
+$ ls
+ ans =
+
+!vv.txt !
+! !
+!reverse_read.c !
+! !
+!Result2.txt !
+! !
+!Example9.sci !
+! !
+!Example8.sci !
+! !
+!Example7.sci !
+! !
+!Example6.sci !
+! !
+!Example5.sci !
+! !
+!Example4.sci !
+! !
+!Example3.sci !
+! !
+!Example2.sci !
+! !
+!Example13.sci !
+! !
+!Example12.sci !
+! !
+!Example11.sci !
+! !
+!Example10.sci !
+! !
+!ex9 !
+! !
+!ex8 !
+! !
+!ex7 !
+! !
+!ex6 !
+! !
+!ex5 !
+! !
+!ex4 !
+! !
+!ex3 !
+! !
+!ex2 !
+! !
+!ex13 !
+! !
+!ex12 !
+! !
+!ex11 !
+! !
+!ex10 !
+! !
+!ex1 !
+
+$ cat vv.txt Warning: file 'vv.txt' already opened in Scilab.
+hi there
+How are you
+I am fine
+Thank You
+Good Bye
+$ cc reverse_read.c$ a.out vv.txt
+......a blank line... The terminating \n of the last lineWarning: file 'vv.txt' already opened in Scilab.
+eyB dooG
+
+uoY knahT
+
+ enif ma I
+
+uoy era woH
+
+ereht i
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.3/Example3.sce b/1088/CH23/EX23.3/Example3.sce
new file mode 100755
index 000000000..95443c251
--- /dev/null
+++ b/1088/CH23/EX23.3/Example3.sce
@@ -0,0 +1,72 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 3 : Show the effect of umask on permissions of a file \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: umask.c -- Changes umask twice and checks effect on permissions */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' mode_t old_mode,new_mode;'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' old_mode = umask(0); /* No mask */'
+i=i+1;f(i)=' printf('+ascii(34)+'Previous umask value: %o\n'+ascii(34)+', old_mode);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' open('+ascii(34)+'foo1'+ascii(34)+',O_RDONLY | O_CREAT, 0777); /* Create file using new mask */'
+i=i+1;f(i)=' umask(old_mode); /* Revert to previous mask */'
+i=i+1;f(i)=' open('+ascii(34)+'foo2'+ascii(34)+',O_RDWR | O_CREAT, 0764); /* Create file using old mask */'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='} '
+n=i
+
+printf("\n\n$ cat umask.c # to open the file emp.lst")
+halt(' ')
+u=mopen('umask.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc umask.c")
+ halt(' ')
+ printf("$ a.out")
+ halt(' ')
+ printf("Previous umask value: 22")
+ halt(' ')
+ printf("$ ls -l foo?")
+ halt(' ')
+disp("-rwxrwxrwx 1 sumit sumit 0 Dec 1 12:01 foo1")
+disp("-rwxr--r-- 1 sumit sumit 0 Dec 1 12:01 foo2")
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.3/Result3.txt b/1088/CH23/EX23.3/Result3.txt
new file mode 100755
index 000000000..39a1c4e08
--- /dev/null
+++ b/1088/CH23/EX23.3/Result3.txt
@@ -0,0 +1,87 @@
+ ans =
+
+ 1.
+
+-->exec('Example3.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 3 : Show the effect of umask on permissions of a file
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat umask.c # to open the file emp.lst /* Program: umask.c -- Changes umask twice and checks effect on permissions */
+
+#include <stdio.h>
+#include <fcntl.h>
+
+int main(void) {
+ mode_t old_mode,new_mode;
+
+ old_mode = umask(0); /* No mask */
+ printf("Previous umask value: %o\n", old_mode);
+
+ open("foo1",O_RDONLY | O_CREAT, 0777); /* Create file using new mask */
+ umask(old_mode); /* Revert to previous mask */
+ open("foo2",O_RDWR | O_CREAT, 0764); /* Create file using old mask */
+ exit(0);
+}
+ $ cc umask.c $ a.out Previous umask value: 22 $ ls -l foo?
+ -rwxrwxrwx 1 sumit sumit 0 Dec 1 12:01 foo1
+
+ -rwxr--r-- 1 sumit sumit 0 Dec 1 12:01 foo2
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.4/Example4.sce b/1088/CH23/EX23.4/Example4.sce
new file mode 100755
index 000000000..b4524a3b6
--- /dev/null
+++ b/1088/CH23/EX23.4/Example4.sce
@@ -0,0 +1,63 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 4 : Print all the error messages present in the system using strerror \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: show_errors.c --Uses strerror to print all error messages */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' int i;'
+i=i+1;f(i)=' extern int sys_nerr; /* Total number of error messages */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' for (i=0; i < sys_nerr; i++)'
+i=i+1;f(i)=' printf('+ascii(34)+'%d: %s\n'+ascii(34)+', i, strerror(i));'
+i=i+1;f(i)=' printf('+ascii(34)+'Number of errors available: %d\n'+ascii(34)+', sys_nerr);'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat show_errors.c # to open the file emp.lst")
+halt(' ')
+u=mopen('show_errors.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+halt('')
+disp('$ cc show_errors.c')
+halt("")
+disp("$ a.out")
+halt("")
+printf("0: Error 0\n1: Not owner\n2:No such file or directory\n3: No such process\n4: Interrupted system call\n5: I/O error\n13: Permission denied\n")
+halt("")
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.4/Result4.txt b/1088/CH23/EX23.4/Result4.txt
new file mode 100755
index 000000000..725f54933
--- /dev/null
+++ b/1088/CH23/EX23.4/Result4.txt
@@ -0,0 +1,91 @@
+ ans =
+
+ 1.
+
+-->exec('Example4.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 4 : Print all the error messages present in the system using strerror
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat show_errors.c # to open the file emp.lst /* Program: show_errors.c --Uses strerror to print all error messages */
+
+#include <stdio.h>
+
+int main(void) {
+ int i;
+ extern int sys_nerr; /* Total number of error messages */
+
+ for (i=0; i < sys_nerr; i++)
+ printf("%d: %s\n", i, strerror(i));
+ printf("Number of errors available: %d\n", sys_nerr);
+ exit(0);
+}
+
+ $ cc show_errors.c
+
+ $ a.out
+0: Error 0
+1: Not owner
+2:No such file or directory
+3: No such process
+4: Interrupted system call
+5: I/O error
+13: Permission denied
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.5/Example5.sce b/1088/CH23/EX23.5/Example5.sce
new file mode 100755
index 000000000..2bbbe3ea3
--- /dev/null
+++ b/1088/CH23/EX23.5/Example5.sce
@@ -0,0 +1,66 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 5 : Print all the system call errors with perror \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: show_errno.c -- Displaying system call errors with perror */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' int fd;'
+i=i+1;f(i)=' char* filename = '+ascii(34)+'non_existent_file'+ascii(34)+'; /* This file must not exist */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' fd = open(filename, O_RDONLY); /* File descriptor assigned first */'
+i=i+1;f(i)=' if (fd == -1) /* and then checked */'
+i=i+1;f(i)=' perror('+ascii(34)+'no_existent_file'+ascii(34)+');'
+i=i+1;f(i)=' if ((fd = open('+ascii(34)+'/etc/shadow'+ascii(34)+',O_RDONLY)) == -1) /* bOTH COMBINED HERE */'
+i=i+1;f(i)=' perror('+ascii(34)+'shadow'+ascii(34)+');'
+i=i+1;f(i)=' if ((fd = open('+ascii(34)+'show_errno.c'+ascii(34)+',O_WRONLY | O_CREAT | O_EXCL, 0744)) == -1)'
+i=i+1;f(i)=' perror('+ascii(34)+'show_errno.c'+ascii(34)+');'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+printf("\n\n$ cat show_errorno.c # to open the file emp.lst")
+halt(' ')
+u=mopen('show_errorno.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+halt('')
+disp('$ cc show_errorno.c')
+halt("")
+disp("$ a.out")
+halt("")
+printf("non_existent_file: No such file or directory\nshadow: Permission denied\nshow_errno.c: File exists\n ")
+halt("")
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.5/Result5.txt b/1088/CH23/EX23.5/Result5.txt
new file mode 100755
index 000000000..315047313
--- /dev/null
+++ b/1088/CH23/EX23.5/Result5.txt
@@ -0,0 +1,92 @@
+ ans =
+
+ 1.
+
+-->exec('Example5.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 5 : Print all the system call errors with perror
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat show_errorno.c # to open the file emp.lst /* Program: show_errno.c -- Displaying system call errors with perror */
+
+#include <fcntl.h>
+
+int main(int argc, char **argv) {
+ int fd;
+ char* filename = "non_existent_file"; /* This file must not exist */
+
+ fd = open(filename, O_RDONLY); /* File descriptor assigned first */
+ if (fd == -1) /* and then checked */
+ perror("no_existent_file");
+ if ((fd = open("/etc/shadow",O_RDONLY)) == -1) /* bOTH COMBINED HERE */
+ perror("shadow");
+ if ((fd = open("show_errno.c",O_WRONLY | O_CREAT | O_EXCL, 0744)) == -1)
+ perror("show_errno.c");
+ exit(0);
+}
+
+ $ cc show_errorno.c
+
+ $ a.out
+non_existent_file: No such file or directory
+shadow: Permission denied
+show_errno.c: File exists
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+
+-->diary(0)
diff --git a/1088/CH23/EX23.6/Example6.sce b/1088/CH23/EX23.6/Example6.sce
new file mode 100755
index 000000000..a8c2ec7f1
--- /dev/null
+++ b/1088/CH23/EX23.6/Example6.sce
@@ -0,0 +1,123 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 6 : Show the method of reversing a file using error handling alternatives \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: reverse_read2.c -- Reads a file in reverse - uses error handling */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <fcntl.h> /* For 0_RDONLY */'
+i=i+1;f(i)='#include <unistd.h> /* For STDOUT_FILENO */'
+i=i+1;f(i)='#include <errno.h> /* For ENOENT, errno, etc. */'
+i=i+1;f(i)='#include <stdio.h> /* For ENOENT, errno, etc. */'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, chr **argv) {'
+i=i+1;f(i)=' int size, fd;'
+i=i+1;f(i)=' char buf; /* Single-character buffer */'
+i=i+1;f(i)=' char *mesg = '+ascii(34)+'Not enough arguments\n'+ascii(34)+' ;'
+ i=i+1;f(i)=' '
+i=i+1;f(i)=' if (argc != 2) { /* Our own user-defined error message */'
+i=i+1;f(i)=' write(STDERR_FILENO, mesg, strlen(mesg)); /* Crude form of error*/'
+i=i+1;f(i)=' exit(1); /*handling using write*/'
+i=i+1;f(i)=' } /* Use fprintf instead*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if ((fd = open(argv[1],O_RDONLY)) == -1) {'
+i=i+1;f(i)=' if (errno == ENOENT) { /* Checking for specific error*/'
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'%s\n'+ascii(34)+',stderror(errno)); /*perror is better*/'
+i=i+1;f(i)=' exit(2);'
+i=i+1;f(i)=' } else {'
+i=i+1;f(i)=' perror(argv[1]); /* Using two library functions */'
+i=i+1;f(i)=' exit(3); /* perror and exit.often the */'
+i=i+1;f(i)=' } /* preferred way */'
+i=i+1;f(i)=' } '
+i=i+1;f(i)=' '
+i=i+1;f(i)=' lseek(fd, 1, SEEK_END); /* Pointer taken to EOF + 1 first */'
+i=i+1;f(i)=' while (lseek(fd, -2, SEEK_CUR) >=0) { /* and then back by two bytes */ '
+i=i+1;f(i)=' if (read(fd, &buf, 1) != 1) { /* A signal can create error here */'
+i=i+1;f(i)=' perror('+ascii(34)+'read'+ascii(34)+');'
+i=i+1;f(i)=' exit(4);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' if (write(STDOUT_FILENO, &buf, 1) != 1) { /* Disk may run out of space */'
+i=i+1;f(i)=' perror('+ascii(34)+'write'+ascii(34)+');'
+i=i+1;f(i)=' exit(5);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' close(fd); /*Can have error here too*/'
+i=i+1;f(i)=' exit(0); /* exit doesn'+ascii(39)+'t return - hence no error */'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat reverse_read2.c # to open the file emp.lst")
+halt(' ')
+u=mopen('reverse_read2.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+printf("\n$ ls \n")
+halt(' ')
+mode(0)
+ls
+mode(-1)
+nam=input("# Please enter a file from the above list : ",'s')
+printf("\n$ cat %s ",nam)
+halt(' ')
+v=mopen(nam,"rt")
+while ~meof(v)
+ [n,a]=mfscanf(v,"%c");
+ if meof(v) break
+ end
+ printf("%c",a)
+end
+mclose(v)
+halt("")
+printf("\n$ cc reverse_read2.c")
+halt("")
+printf("$ a.out %s \n......a blank line... The terminating \\n of the last line",nam)
+halt("")
+v=mopen(nam,"rt")
+mseek(-1,v,'end')
+siz=mtell(v)
+siz=siz-1
+while siz~=-1
+ [n,a]=mfscanf(v,"%c");
+ printf("%c",a)
+ mseek(siz,v)
+ siz=siz-1
+end
+mseek(0,v)
+ [n,a]=mfscanf(v,"%c");
+ printf("%c",a)
+
+mclose(v)
+halt(' ')
+
+
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.6/Result6.txt b/1088/CH23/EX23.6/Result6.txt
new file mode 100755
index 000000000..841add07e
--- /dev/null
+++ b/1088/CH23/EX23.6/Result6.txt
@@ -0,0 +1,176 @@
+ ans =
+
+ 1.
+
+-->exec('Example6.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 6 : Show the method of reversing a file using error handling alternatives
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat reverse_read2.c # to open the file emp.lst /* Program: reverse_read2.c -- Reads a file in reverse - uses error handling */
+
+#include <fcntl.h> /* For 0_RDONLY */
+#include <unistd.h> /* For STDOUT_FILENO */
+#include <errno.h> /* For ENOENT, errno, etc. */
+#include <stdio.h> /* For ENOENT, errno, etc. */
+
+int main(int argc, chr **argv) {
+ int size, fd;
+ char buf; /* Single-character buffer */
+ char *mesg = "Not enough arguments\n" ;
+
+ if (argc != 2) { /* Our own user-defined error message */
+ write(STDERR_FILENO, mesg, strlen(mesg)); /* Crude form of error*/
+ exit(1); /*handling using write*/
+ } /* Use fprintf instead*/
+
+ if ((fd = open(argv[1],O_RDONLY)) == -1) {
+ if (errno == ENOENT) { /* Checking for specific error*/
+ fprintf(stderr, "%s\n",stderror(errno)); /*perror is better*/
+ exit(2);
+ } else {
+ perror(argv[1]); /* Using two library functions */
+ exit(3); /* perror and exit.often the */
+ } /* preferred way */
+ }
+
+ lseek(fd, 1, SEEK_END); /* Pointer taken to EOF + 1 first */
+ while (lseek(fd, -2, SEEK_CUR) >=0) { /* and then back by two bytes */
+ if (read(fd, &buf, 1) != 1) { /* A signal can create error here */
+ perror("read");
+ exit(4);
+ }
+ if (write(STDOUT_FILENO, &buf, 1) != 1) { /* Disk may run out of space */
+ perror("write");
+ exit(5);
+ }
+ }
+ close(fd); /*Can have error here too*/
+ exit(0); /* exit doesn't return - hence no error */
+}
+
+$ ls
+ ans =
+
+!vv.txt !
+! !
+!reverse_read2.c !
+! !
+!Result6.txt !
+! !
+!Example9.sci !
+! !
+!Example8.sci !
+! !
+!Example7.sci !
+! !
+!Example6.sci !
+! !
+!Example2.sci !
+! !
+!Example13.sci !
+! !
+!Example12.sci !
+! !
+!Example11.sci !
+! !
+!Example10.sci !
+! !
+!ex9 !
+! !
+!ex8 !
+! !
+!ex7 !
+! !
+!ex6 !
+! !
+!ex5 !
+! !
+!ex4 !
+! !
+!ex3 !
+! !
+!ex2 !
+! !
+!ex13 !
+! !
+!ex12 !
+! !
+!ex11 !
+! !
+!ex10 !
+! !
+!ex1 !
+
+$ cat vv.txt hi there
+How are you
+I am fine
+Thank You
+Good Bye
+$ cc reverse_read2.c$ a.out vv.txt
+......a blank line... The terminating \n of the last lineeyB dooG
+
+uoY knahT
+
+ enif ma I
+
+uoy era woH
+
+ereht ih
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.7/Example7.sce b/1088/CH23/EX23.7/Example7.sce
new file mode 100755
index 000000000..b8b8d67cc
--- /dev/null
+++ b/1088/CH23/EX23.7/Example7.sce
@@ -0,0 +1,85 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 7 : Show the method of directory navigation with chdir and getcwd \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: dir.c -- Directory navigation with chdir and getcwd */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#define PATH_LENGTH 200'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *,int ); /* Prototyoe definition */'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' char olddir[PATH_LENGTH + 1]; /* Extra character for null */'
+i=i+1;f(i)=' char newdir[PATH_LENGTH + 1];'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (getcwd(olddir, PATH_LENGTH) == -1) /* Getting current directory */'
+i=i+1;f(i)=' quit('+ascii(34)+'getcwd'+ascii(34)+', 1);'
+i=i+1;f(i)=' printf('+ascii(34)+'pwd: %s\n'+ascii(34)+',olddir);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if ((chdir(argv[1]) == -1)) /* Changing to another directory */'
+i=i+1;f(i)=' quit('+ascii(34)+'chdir'+ascii(34)+', 2);'
+i=i+1;f(i)=' printf('+ascii(34)+'cd: %s\n'+ascii(34)+', argv[1]);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* getting new directory */'
+i=i+1;f(i)=' printf('+ascii(34)+'pwd: %s\n'+ascii(34)+',newdir);'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+printf("\n\n$ cat dir.c # to open the file emp.lst")
+halt(' ')
+u=mopen('dir.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc dir.c")
+ halt(' ')
+ disp("# Please enter the name of the directory which you want to go as the command line argument")
+ disp("")
+nam=input("$ a.out ",'s')
+ halt(' ')
+ pwd
+ back=ans
+ printf("pwd: %s\n",back)
+ printf("cd: %s\n",nam)
+ printf("pwd: %s Change of directory inside program\n",nam)
+ cd(nam)
+ halt("")
+ printf("$ pwd \n")
+ cd(back)
+ printf("%s ...is not available outside it\n",back)
+
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.7/Result7.txt b/1088/CH23/EX23.7/Result7.txt
new file mode 100755
index 000000000..71d664011
--- /dev/null
+++ b/1088/CH23/EX23.7/Result7.txt
@@ -0,0 +1,99 @@
+ ans =
+
+ 1.
+
+-->exec('Example7.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 7 : Show the method of directory navigation with chdir and getcwd
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat dir.c # to open the file emp.lst /* Program: dir.c -- Directory navigation with chdir and getcwd */
+
+#include <stdio.h>
+#define PATH_LENGTH 200
+
+void quit(char *,int ); /* Prototyoe definition */
+
+int main(int argc, char **argv) {
+ char olddir[PATH_LENGTH + 1]; /* Extra character for null */
+ char newdir[PATH_LENGTH + 1];
+
+ if (getcwd(olddir, PATH_LENGTH) == -1) /* Getting current directory */
+ quit("getcwd", 1);
+ printf("pwd: %s\n",olddir);
+
+ if ((chdir(argv[1]) == -1)) /* Changing to another directory */
+ quit("chdir", 2);
+ printf("cd: %s\n", argv[1]);
+
+ getcwd(newdir, PATH_LENGTH); /* getting new directory */
+ printf("pwd: %s\n",newdir);
+ exit(0);
+}
+ $ cc dir.c
+ # Please enter the name of the directory which you want to go as the command line argument
+
+
+ pwd: C:\Users\Pranav Bhat\Documents\TCPMUM\Chapter23
+cd: /
+pwd: / Change of directory inside program
+$ pwd
+C:\Users\Pranav Bhat\Documents\TCPMUM\Chapter23 ...is not available outside it
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.8/Example8.sce b/1088/CH23/EX23.8/Example8.sce
new file mode 100755
index 000000000..520ba69eb
--- /dev/null
+++ b/1088/CH23/EX23.8/Example8.sce
@@ -0,0 +1,76 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 8 : Show the method of using readdir to populate a dirent structure \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: lls.c -- Uses readdir to populate a dirent structure */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <dirent.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, int **argv) {'
+i=i+1;f(i)=' DIR *dir; /* Returned by opendir*/'
+i=i+1;f(i)=' struct dirent *direntry; /* Returned by readdir*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if ((dir = opendir(argv[1])) == NULL) /* Directory must exist and*/'
+i=i+1;f(i)=' quit('+ascii(34)+'opendir'+ascii(34)+', 1); /* have read permission*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' while ((direntry = readdir(dir)) != NULL) /* Till there are new entries*/'
+i=i+1;f(i)=' printf('+ascii(34)+'%10d %s\n'+ascii(34)+',direntry->d_ino,direntry->d_name);'
+i=i+1;f(i)=' closedir(dir);'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='} '
+ n=i
+printf("\n\n$ cat lls.c # to open the file emp.lst")
+halt(' ')
+u=mopen('lls.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc dir.c")
+ halt(' ')
+ disp("# Please enter the name of the directory which you want to go as the command line argument")
+ disp("")
+nam=input("$ a.out ",'s')
+ halt(' ')
+ pwd
+ back=ans
+ cd(nam)
+x=dir()
+dt=getdate(x.date);
+mprintf("%-20s : %05d-%03d-%03d %02d:%02d:%02d\n",x.name,dt(:,[1 2 6 7:9]))
+ halt("")
+ cd(back)
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.8/Result8.txt b/1088/CH23/EX23.8/Result8.txt
new file mode 100755
index 000000000..46a6329ec
--- /dev/null
+++ b/1088/CH23/EX23.8/Result8.txt
@@ -0,0 +1,137 @@
+ ans =
+
+ 1.
+
+-->exec('Example8.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 8 : Show the method of using readdir to populate a dirent structure
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat dir.c # to open the file emp.lst /* Program: lls.c -- Uses readdir to populate a dirent structure */
+
+#include <stdio.h>
+#include <dirent.h>
+
+int main(int argc, int **argv) {
+ DIR *dir; /* Returned by opendir*/
+ struct dirent *direntry; /* Returned by readdir*/
+
+ if ((dir = opendir(argv[1])) == NULL) /* Directory must exist and*/
+ quit("opendir", 1); /* have read permission*/
+
+ while ((direntry = readdir(dir)) != NULL) /* Till there are new entries*/
+ printf("%10d %s\n",direntry->d_ino,direntry->d_name);
+ closedir(dir);
+ exit(0);
+}
+ $ cc dir.c
+ # Please enter the name of the directory which you want to go as the command line argument
+
+
+ $Recycle.Bin : 02013-005-024 15:16:15
+$SysReset : 02013-005-025 13:33:44
+Boot : 02012-010-011 22:26:46
+bootmgr : 02012-007-026 09:14:30
+BOOTNXT : 02012-006-002 20:00:55
+BOOTSECT.BAK : 02012-010-010 05:37:57
+Dev-Cpp : 02013-006-020 20:08:08
+Documents and Settings : 02012-007-026 12:52:08
+Downloads : 02013-006-005 19:58:14
+Dwimperl : 02013-006-007 14:57:51
+eula.1028.txt : 02007-011-007 08:00:40
+eula.1031.txt : 02007-011-007 08:00:40
+eula.1033.txt : 02007-011-007 08:00:40
+eula.1036.txt : 02007-011-007 08:00:40
+eula.1040.txt : 02007-011-007 08:00:40
+eula.1041.txt : 02007-011-007 08:00:40
+eula.1042.txt : 02007-011-007 08:00:40
+eula.2052.txt : 02007-011-007 08:00:40
+eula.3082.txt : 02007-011-007 08:00:40
+globdata.ini : 02007-011-007 08:00:40
+hiberfil.sys : 02013-006-022 23:28:13
+install.exe : 02007-011-007 08:03:18
+install.ini : 02007-011-007 08:00:40
+install.res.1028.dll : 02007-011-007 08:03:18
+install.res.1031.dll : 02007-011-007 08:03:18
+install.res.1033.dll : 02007-011-007 08:03:18
+install.res.1036.dll : 02007-011-007 08:03:18
+install.res.1040.dll : 02007-011-007 08:03:18
+install.res.1041.dll : 02007-011-007 08:03:18
+install.res.1042.dll : 02007-011-007 08:03:18
+install.res.2052.dll : 02007-011-007 08:03:18
+install.res.3082.dll : 02007-011-007 08:03:18
+odf : 02013-005-026 19:47:02
+pagefile.sys : 02013-006-022 23:28:14
+PerfLogs : 02012-007-026 13:03:46
+Perl64 : 02013-006-007 14:45:48
+Program Files : 02013-006-015 21:23:32
+Program Files (x86) : 02013-006-020 18:47:25
+ProgramData : 02013-006-015 21:22:33
+Remote Programs : 02013-003-008 00:55:16
+S : 02013-005-026 00:36:20
+swapfile.sys : 02013-006-022 23:28:14
+System Volume Information : 02013-006-022 19:56:57
+UserGuidePDF : 02013-003-008 00:45:51
+Users : 02013-005-022 14:20:13
+VC_RED.cab : 02007-011-007 08:09:22
+VC_RED.MSI : 02007-011-007 08:12:28
+vcredist.bmp : 02007-011-007 08:00:40
+Windows : 02013-006-020 16:24:21
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)
diff --git a/1088/CH23/EX23.9/Example9.sce b/1088/CH23/EX23.9/Example9.sce
new file mode 100755
index 000000000..412f71a70
--- /dev/null
+++ b/1088/CH23/EX23.9/Example9.sce
@@ -0,0 +1,80 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 9 : Show the method of using lstatcall and struct stat to display file attributes\n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')
+halt("")
+disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')
+halt("")
+disp("4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+disp("5.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: attributes.c -- Uses lstat call and struct stat to display file attributes */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <sys/stath>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *,int);'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char**argv) {'
+i=i+1;f(i)=' struct stat statbuf; /*We'+ascii(39)+'ll use lstat to populate this*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (lstat(argv[1], &statbuf) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'Couldn'+ascii(39)+'t stat file'+ascii(34)+', 1);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' printf('+ascii(34)+'File: %s\n'+ascii(34)+',argv[1]);'
+i=i+1;f(i)=' printf('+ascii(34)+'Inode number: %d \n'+ascii(34)+',statbuf.st_ino);'
+i=i+1;f(i)=' printf('+ascii(34)+'UID: %d '+ascii(34)+',statbuf.st_uid);'
+i=i+1;f(i)=' printf('+ascii(34)+'GID: %d \n'+ascii(34)+',statbuf.st_gid);'
+i=i+1;f(i)=' printf('+ascii(34)+'Types and Permissions: %o\n'+ascii(34)+',statbuf.st_mode);'
+i=i+1;f(i)=' printf('+ascii(34)+'Number of links: %d \n'+ascii(34)+',statbuf.st_nlink);'
+i=i+1;f(i)=' printf('+ascii(34)+'Size in bytes: %d\n'+ascii(34)+',statbuf.st_size);'
+i=i+1;f(i)=' printf('+ascii(34)+'Blocks allocated: %d\n'+ascii(34)+',statbuf.st_blocks);'
+i=i+1;f(i)=' printf('+ascii(34)+'Last Modification Time: %s\n'+ascii(34)+',ctime(&statbuf.st_mtime));'
+i=i+1;f(i)=' printf('+ascii(34)+'Last Access Time: %s\n'+ascii(34)+',ctime(&statbuf.st_atime));'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+printf("\n\n$ cat attributes.c # to open the file emp.lst")
+halt(' ')
+u=mopen('attributes.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc dir.c")
+ halt(' ')
+ disp("")
+printf("\nHere it displays a mock value since it is windows\n\n")
+if getos()=='Windows' then
+ printf("\n$ a.out /etc/passwd\nFile: /etc/passwd\nInode number: 54412\nUID: 0 GID: 3\nType and Permissions: 100755\nNumber of links: 1")
+printf("\nSize in bytes: 10803\nBlocks allocated: 22\nLast Modification Time: Tue Nov 19 16:29:13 2002\nLast Access Time: Tue NOv 26 19:57:01 2002\n")
+else
+ printf("$ a.out /etc/passwd")
+ unix_w('cc attributes.c;a.out /etc/passwd')
+end
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH23/EX23.9/Result9.txt b/1088/CH23/EX23.9/Result9.txt
new file mode 100755
index 000000000..fda181567
--- /dev/null
+++ b/1088/CH23/EX23.9/Result9.txt
@@ -0,0 +1,108 @@
+ ans =
+
+ 1.
+
+-->exec('Example9.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 9 : Show the method of using lstatcall and struct stat to display file attributes
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat attributes.c # to open the file emp.lst /* Program: attributes.c -- Uses lstat call and struct stat to display file attributes */
+#include <stdio.h>
+#include <sys/stath>
+
+void quit(char *,int);
+
+int main(int argc, char**argv) {
+ struct stat statbuf; /*We'll use lstat to populate this*/
+
+ if (lstat(argv[1], &statbuf) == -1)
+ quit("Couldn't stat file", 1);
+
+ printf("File: %s\n",argv[1]);
+ printf("Inode number: %d \n",statbuf.st_ino);
+ printf("UID: %d ",statbuf.st_uid);
+ printf("GID: %d \n",statbuf.st_gid);
+ printf("Types and Permissions: %o\n",statbuf.st_mode);
+ printf("Number of links: %d \n",statbuf.st_nlink);
+ printf("Size in bytes: %d\n",statbuf.st_size);
+ printf("Blocks allocated: %d\n",statbuf.st_blocks);
+ printf("Last Modification Time: %s\n",ctime(&statbuf.st_mtime));
+ printf("Last Access Time: %s\n",ctime(&statbuf.st_atime));
+ exit(0);
+}
+ $ cc dir.c
+
+
+Here it displays a mock value since it is windows
+
+
+$ a.out /etc/passwd
+File: /etc/passwd
+Inode number: 54412
+UID: 0 GID: 3
+Type and Permissions: 100755
+Number of links: 1
+Size in bytes: 10803
+Blocks allocated: 22
+Last Modification Time: Tue Nov 19 16:29:13 2002
+Last Access Time: Tue NOv 26 19:57:01 2002
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+
+-->diary(0)