home *** CD-ROM | disk | FTP | other *** search
- ;/* Execute to compile
- sc tlist.c OPTIMIZE OPTINLOCAL OPTTIME OPTSCHED IGNORE 73 LINK
- quit
- */
-
- /* typelist.c
- * Copyright © 1994 Uwe Röhm
- * Thanks to David N. Junod for his examinedt.c
- *
- * Scans all given File- and Dirnames and
- * prints their name, size, date and type (if possible).
- *
- */
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/libraries.h>
- #include <dos/dos.h>
- #include <dos/datetime.h>
- #include <dos/dosextens.h>
- #include <datatypes/datatypes.h>
- #include <datatypes/datatypesclass.h>
- #include <libraries/iffparse.h>
- #include <string.h>
- #include <stdio.h>
- #include <ctype.h>
-
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/datatypes_protos.h>
- #include <clib/iffparse_protos.h>
-
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/datatypes_pragmas.h>
- #include <pragmas/iffparse_pragmas.h>
- void __main(void);
-
-
- #define TEMPLATE "NAME/M,ALL/S,FILES/S,DIRS/S,NOSIZE/S,NOPROT/S,NODATE/S,NOCOMMENT/S,GROUP/S,HEADER/S,TOOLS/S,TAGS/S,CODE/S"
-
- extern struct Library *SysBase, *DOSBase;
- struct Library *DataTypesBase, *IFFParseBase;
-
- UBYTE Version[] = "\0$VER: tlist 1.3 (24.09.94) (c) 1994 by Uwe Röhm";
-
- /* String for leading spaces for sub-dirs, max. 40 subdirs allowed! */
- UBYTE SubDirSpaces[81] = "";
-
- LONG *Options[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- #define OPT_NAMES 0
- #define PrintAll (Options[1])
- #define PrintFile (Options[2] || !Options[3])
- #define PrintDir (Options[3] || !Options[2])
- #define PrintSize (!Options[4])
- #define PrintBits (!Options[5])
- #define PrintDate (!Options[6])
- #define PrintComment (!Options[7])
- #define PrintGroup (Options[8])
- #define PrintHeader (Options[9])
- #define PrintTools (Options[10])
- #define PrintTags (Options[11])
- #define PrintCode (Options[12])
-
- #define IsDir(x) (x->ap_Info.fib_DirEntryType > 0)
- #define IsFile(x) (x->ap_Info.fib_DirEntryType < 0)
- #define DidDir(x) (x->ap_Flags & APF_DIDDIR)
- #define IsWild(x) (x->ap_Flags & APF_ITSWILD)
-
- /* Value for hidden-protection-bit, which isn't defined in dos/dos.h */
- #define FIBF_HIDDEN (1 << 7)
-
- /*
- * Help functions
- */
- char *dump_mask( WORD *ptr, WORD len )
- {
- static char buffer[81];
- char c;
- WORD i;
-
- for ( i = 0; i < len; i++)
- {
- c = (char) *ptr;
- if ( isprint(c) )
- buffer[i] = c;
- else
- buffer[i] = '.';
- ptr++;
-
- } /* for i */
- buffer[len] = '\0';
-
- return buffer;
- }
-
-
- /*
- * Print Contents of Datatype-Header
- */
- void print_dtyp_dthd ( struct DataType *dtype )
- {
- UBYTE buf[8];
-
- Printf(" %-9s", dtype->dtn_Header->dth_BaseName);
- Printf(" %s", IDtoStr(dtype->dtn_Header->dth_ID, buf));
- Printf(" %ld", dtype->dtn_Header->dth_Priority);
-
- if ( !dtype->dtn_Header->dth_Flags )
- PutStr(" none");
- if ( dtype->dtn_Header->dth_Flags & DTF_BINARY )
- PutStr(" BINARY");
- if ( dtype->dtn_Header->dth_Flags & DTF_ASCII )
- PutStr(" ASCII");
- if ( dtype->dtn_Header->dth_Flags & DTF_IFF )
- PutStr(" IFF");
- if ( dtype->dtn_Header->dth_Flags & DTF_MISC )
- PutStr(" MISC");
- if ( dtype->dtn_Header->dth_Flags & DTF_CASE )
- PutStr(" CASE");
- if ( dtype->dtn_Header->dth_Flags & DTF_SYSTEM1 )
- PutStr(" SYSTEM1");
-
- if ( dtype->dtn_Header->dth_Pattern )
- Printf(",%s", dtype->dtn_Header->dth_Pattern);
- if ( dtype->dtn_Header->dth_MaskLen )
- Printf(",%ld: %s", dtype->dtn_Header->dth_MaskLen, dump_mask(dtype->dtn_Header->dth_Mask, dtype->dtn_Header->dth_MaskLen));
- }
-
- /*
- * Print Contents of Datatype-Tools-List
- */
- void print_dtyp_tool ( struct DataType *dtype )
- {
- struct ToolNode *tn;
-
- if ( IsListEmpty(&dtype->dtn_ToolList) )
- return;
- else for ( tn = (struct ToolNode *) dtype->dtn_ToolList.lh_Head;
- tn->tn_Node.ln_Succ;
- tn = (struct ToolNode *) tn->tn_Node.ln_Succ)
- {
- PutStr(SubDirSpaces);
- switch ( tn->tn_Tool.tn_Which)
- {
- case TW_INFO:
- PutStr("[INFO: ");
- break;
- case TW_BROWSE:
- PutStr("[BROWSE: ");
- break;
- case TW_EDIT:
- PutStr("[EDIT: ");
- break;
- case TW_PRINT:
- PutStr("[PRINT: ");
- break;
- case TW_MAIL:
- PutStr("[MAIL: ");
- break;
- default:
- PutStr("[unknown: ");
- break;
- }
-
- PutStr(tn->tn_Tool.tn_Program);
-
- PutStr(" (Flags: ");
- if ( tn->tn_Tool.tn_Flags == TF_RX )
- PutStr("RX ");
- if ( tn->tn_Tool.tn_Flags == TF_SHELL )
- PutStr("SHELL ");
- if ( tn->tn_Tool.tn_Flags == TF_WORKBENCH )
- PutStr("WORKBENCH ");
- if ( !tn->tn_Tool.tn_Flags )
- PutStr("none ");
- Printf("Length %ld)]\n", tn->tn_Length);
- }
- }
-
- /*
- * Print Contents of Datatype-Attributes-List
- */
- void print_dtyp_tags ( struct DataType *dtype )
- {
- struct TagItem *tag;
-
- for ( tag = dtype->dtn_AttrList; tag && tag->ti_Tag; tag++ )
- Printf("%s[TAG %lx DATA %lx]\n", SubDirSpaces, tag->ti_Tag, tag->ti_Data);
- }
-
- /*
- * Print Contents of Datatype-Code
- */
- void print_dtyp_code ( struct DataType *dtype )
- {
- if ( dtype->dtn_FunctionName )
- Printf("%s[Function: %s]\n", SubDirSpaces, dtype->dtn_FunctionName);
- if ( dtype->dtn_Length )
- Printf("[Code length: %ld]\n", dtype->dtn_Length);
- }
-
-
- void print_datatype_info ( BPTR dir, char *filename )
- {
- struct DataTypeHeader *dth;
- struct DataType *dtn;
- BPTR home, lock;
-
-
- home = CurrentDir(dir);
- if ( lock = Lock(filename, ACCESS_READ) )
- {
- if (dtn = ObtainDataTypeA (DTST_FILE, (APTR) lock, NULL))
- {
- dth = dtn->dtn_Header;
- Printf (" %s ", dth->dth_Name);
-
- if ( PrintGroup )
- Printf(" (%s, %s)", GetDTString (dth->dth_GroupID), GetDTString ((dth->dth_Flags & DTF_TYPE_MASK) + DTMSG_TYPE_OFFSET) );
-
- if ( PrintHeader )
- print_dtyp_dthd( dtn );
-
- PutStr("\n");
-
- if ( PrintTools )
- print_dtyp_tool( dtn );
-
- if ( PrintTags )
- print_dtyp_tags( dtn );
-
- if ( PrintCode )
- print_dtyp_code( dtn );
-
- ReleaseDataType (dtn);
-
- } /* if ObtainDataTypeA() */
- else
- Printf (" %s\n", GetDTString(DTERROR_UNKNOWN_DATATYPE));
-
- UnLock(lock);
-
- } /* if Lock() */
- else
- PutStr("\n"); /* finish current line */
-
- CurrentDir(home);
- }
-
- void print_protection_bits ( ULONG protection )
- {
- static char buffer[10]=" --------";
-
- buffer[1] = (protection & FIBF_HIDDEN) ? 'h' : '-';
- buffer[2] = (protection & FIBF_SCRIPT) ? 's' : '-';
- buffer[3] = (protection & FIBF_PURE) ? 'p' : '-';
- buffer[4] = (protection & FIBF_ARCHIVE) ? 'a' : '-';
- buffer[5] =!(protection & FIBF_READ) ? 'r' : '-';
- buffer[6] =!(protection & FIBF_WRITE) ? 'w' : '-';
- buffer[7] =!(protection & FIBF_EXECUTE) ? 'e' : '-';
- buffer[8] =!(protection & FIBF_DELETE) ? 'd' : '-';
-
- PutStr(buffer);
- }
-
- void print_date ( struct DateStamp *date )
- {
- struct DateTime dtime;
- UBYTE buffer[12];
-
- dtime.dat_Stamp = *date; /* datestamp to be converted */
- dtime.dat_Format = FORMAT_DOS; /* Format: dd-mmm-yy */
- dtime.dat_Flags = DTF_SUBST; /* create dayname if possible */
- dtime.dat_StrDate= buffer; /* only create datestring */
- dtime.dat_StrTime= NULL;
- dtime.dat_StrDay = NULL;
-
- DateToStr(&dtime);
- Printf(" %9s", buffer);
- }
-
-
- void scan_dir ( char *name )
- {
- struct AnchorPath *anchor;
- LONG indent = 0, error = 0;
-
-
- if ( anchor = (struct AnchorPath *) AllocMem(sizeof(struct AnchorPath), MEMF_CLEAR) )
- {
- anchor->ap_BreakBits = SIGBREAKF_CTRL_C;
-
- if ( (error = MatchFirst(name, anchor)) == 0 )
- {
- /* if the user gave a directory name without wildcard - enter it */
- if ( IsDir(anchor) && !IsWild(anchor) )
- {
- anchor->ap_Flags |= APF_DODIR;
- indent = 2;
- strcat(SubDirSpaces, " ");
- }
-
- while ( !error )
- {
- /*
- * APF_DIDDIR indicates that we used returned from a
- * directory. In that case we clear both APF_DIDDIR and
- * APF_DODIR, so we can start afresh with the next one.
- */
- if ( anchor->ap_Flags & APF_DIDDIR )
- {
- anchor->ap_Flags &= ~(APF_DODIR | APF_DIDDIR);
- indent -= 2;
- SubDirSpaces[indent] = '\0';
- }
- else
- if ( (IsDir(anchor) && PrintDir) || (IsFile(anchor) && PrintFile) )
- {
- /* again test for the case of a directory without wildcards */
- if ( !*anchor->ap_Info.fib_FileName )
- Printf("%-25s", name);
- else
- Printf("%s%-25s", SubDirSpaces, anchor->ap_Info.fib_FileName);
-
- if ( PrintSize )
- Printf("%7ld", anchor->ap_Info.fib_Size);
-
- if ( PrintBits )
- print_protection_bits(anchor->ap_Info.fib_Protection);
-
- if ( PrintDate )
- print_date(&anchor->ap_Info.fib_Date);
-
- print_datatype_info(anchor->ap_Current->an_Lock, anchor->ap_Info.fib_FileName);
-
- if ( PrintComment && anchor->ap_Info.fib_Comment[0] )
- Printf("%s: %s\n", SubDirSpaces, anchor->ap_Info.fib_Comment);
-
-
- /*
- * If the ALL keyword has been used and this is a directory
- * enter it by setting the APF_DODIR flag.
- */
- if (IsDir(anchor) && PrintAll)
- {
- anchor->ap_Flags |= APF_DODIR;
- indent += 2; /* indent sub-dirs */
- strcat(SubDirSpaces, " ");
- }
-
- } /* if PrintDir || PrintFile */
-
- error = MatchNext(anchor);
-
- } /* while !error */
-
- if (error != ERROR_NO_MORE_ENTRIES)
- PrintFault(error, NULL);
-
- MatchEnd(anchor);
-
- } /* if MatchFirst() */
- else if (error != ERROR_NO_MORE_ENTRIES)
- PrintFault(error, NULL);
-
- FreeMem(anchor, sizeof(struct AnchorPath));
-
- } /* if AllocMem() */
- else
- PrintFault(ERROR_NO_FREE_STORE, NULL);
- }
-
-
- void __main ()
- {
- struct RDArgs *rdargs;
- char **filename;
-
-
- if ( rdargs = ReadArgs(TEMPLATE, (LONG *) Options, NULL) )
- {
- if (DataTypesBase = OpenLibrary ("datatypes.library", 39))
- {
- if (IFFParseBase = OpenLibrary ("iffparse.library", 39))
- {
- /* scan all given dirs */
- filename = (char **) Options[OPT_NAMES];
- if ( filename == NULL )
- scan_dir("#?");
- else
- while ( *filename )
- scan_dir(*filename++);
-
- CloseLibrary (IFFParseBase);
-
- } /* if OpenLibrary() */
- else
- PutStr("Couldn't open iffparse.library V39\n");
-
- CloseLibrary (DataTypesBase);
- }
- else
- PutStr("Couldn't open datatypes.library V39\n");
-
- FreeArgs(rdargs);
-
- } /* if ReadArgs() */
- else
- PrintFault(IoErr(), NULL); /* prints the appropriate error message */
- }
-