Logo
~Apps~
~Projects~
~Contact~

aslist.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <sys/types.h>
00004 #include <sys/stat.h>
00005 #include <unistd.h>
00006 
00007 #include "a.h"
00008 #include "Parser.h"
00009 #include "ParserIO.h"
00010 
00011 
00012 class IOC : public ParserIO
00013 {
00014 public:
00015         int read_text(char *s,int *l) {
00016                 int i;
00017 
00018                 *l = read(0, s, *l);
00019                 if (*l > -1)
00020                         s[*l] = 0;
00021                 while (strlen(s) && (s[strlen(s) - 1] == 13 || s[strlen(s) - 1] == 10))
00022                         s[strlen(s) - 1] = 0;
00023                 for (i = 0; i < (int)strlen(s); i++)
00024                         if (s[i] >= 'a' && s[i] <= 'z')
00025                                 s[i] -= 32;
00026                 return *l;
00027         }
00028         int write_text(char *s,int l) {
00029                 s[l] = 0;
00030                 printf("%s",s);
00031                 fflush(stdout);
00032                 return 0;
00033         }
00034 };
00035 
00036 
00037 int main(int argc,char *argv[])
00038 {
00039         Parser cmdline;
00040         struct stat st;
00041         IOC ioc;
00042         int loop;
00043         int i;
00044         char slask[200];
00045         char *s;
00046 
00047         if (argc > 1)
00048         {
00049                 cmdline.SetParserIO(&ioc);
00050                 for (loop = 1; loop < argc; loop++)
00051                 {
00052                         s = strstr(argv[loop],"/");
00053                         if (s)
00054                         {
00055                                 *s = 0;
00056                                 chdir(argv[loop]);
00057                                 stat(s + 1,&st);
00058                         }
00059                         else
00060                         {
00061                                 stat(argv[loop],&st);
00062                         }
00063                         i = 0;
00064                         if (st.st_mode & 0100)
00065                                 i |= 1;
00066                         if (st.st_mode & 010)
00067                                 i |= 2;
00068                         if (st.st_mode & 01)
00069                                 i |= 4;
00070 // bits 0 .. 7 = tiabsrab
00071                         if ("TIABSRAB"[i] == 'A')
00072                         {
00073                                 sprintf(slask,"LOAD %s",s ? s + 1 : argv[loop]);
00074                                 cmdline.cmd( slask );
00075                                 strcpy(slask,"LIST");
00076                                 cmdline.cmd( slask );
00077                         }
00078                         if (s)
00079                         {
00080                                 chdir("..");
00081                         }
00082                 }
00083         } else
00084         {
00085                 printf("Usage: %s <A file> [-source]\n", *argv);
00086         }
00087         return 0;
00088 }
00089 
Page, code, and content Copyright (C) 2005 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4