summaryrefslogtreecommitdiff
path: root/1088/CH23/EX23.10/Result10.txt
blob: 0866933af51d30093b9b60d01b49269578ca2e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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)