Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : PCCAPP.ZIP
Filename : LS.CC

 
Output of file : LS.CC contained in archive : PCCAPP.ZIP
/*
* This file is part of the Choices Operating System
* Developed by: The TAPESTRY Parallel Computing Laboratory
* University of Illinois at Urbana-Champaign
* Department of Computer Science
* 1304 W. Springfield Ave.
* Urbana, IL 61801
*
* Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992
* The University of Illinois Board of Trustees.
* All Rights Reserved.
*
* Author: Lee Lup Yuen ([email protected])
* Project Manager and Principal Investigator: Roy Campbell ([email protected])
*
* Funded by: NSF TAPESTRY Grant No. 1-5-30035, NASA ICLASS Grant
* No. 1-5-25469 and No. NSG1471 and AT&T Metronet Grant No. 1-5-37411.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for educational, research, and non-profit purposes
* is hereby granted provided that the above copyright notice, the
* original authors names, and this permission notice appear in all such
* copies and supporting documentation; that no charge be made for such
* copies; and that the name of the University of Illinois not be used
* in advertising or publicity pertaining to distribution of the
* software without specific prior written permission. Any entity
* desiring permission to incorporate this software into commercial
* products should contact the Computing Research Laboratory, Department
* of Computer Science, University of Illinois, 1304 W. Springfield
* Avenue, Urbana, IL 61801. The University of Illinois makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/

#include "OutputStream.h"
#include "NameServer.h"
#include "VirtualPCInterface.h"
#include "VirtualPCArgs.h"
#include "String.h"

// Format of a DOS directory entry.
struct DirEntry
{
char internal [21];
unsigned int attribute:8;
unsigned int time:16;
unsigned int date:16;
char size [4]; // Can't use unsigned int here - g++ aligns 32-bit data.
char name [13];
};

void processEntry (DirEntry *entry);
void printEntries ();

int main (int argc, char **)
{
if (argc >= 2)
{
*StandardOutput << "Sorry, ls does not accept any arguments\n" << eor;
return 3;
}
VirtualPCInterface *virtualPC = (VirtualPCInterface *) StandardNameServer
-> lookup ("virtualPCInterface", "VirtualPCInterface");
Assert (virtualPC != 0);
VirtualPCArgs args;
// DOS will store info about directory entries in dirEntry.
DirEntry dirEntry;
// Tell DOS to search for the first dir entry matching "*.*".
args.set (rAX, 0x4e00); // DOS function 0x4e.
args.setConstBuffer (rDS, rDX, "*.*");
args.set (rCX, 0xffff);
args.setDTA ((char *) &dirEntry, sizeof (DirEntry));
int err = virtualPC -> executeVector (DOSVector, &args);
if (err) return 1;
for (;;)
{
// If carry flag is set, then no more files or error.
if (args.get (rFlags) & 1) break;
// We have found a match. Process it.
processEntry (&dirEntry);
// Tell DOS to search for the next matching dir entry.
args.reset ();
args.set (rAX, 0x4f00); // DOS function 0x4f.
args.setDTA ((char *) &dirEntry, sizeof (DirEntry));
err = virtualPC -> executeVector (DOSVector, &args);
if (err) return 2;
}
printEntries ();
return 0;
}

struct StringList
{
char str [13];
StringList *next;
};

StringList *entryNames = 0;

void processEntry (DirEntry *entry)
{
// Process a directory entry before printing it.
// Put entry name into correct upper/lowercase: ordinary files are
// all lowercase, directories are all lowercase except for the first
// letter. Make the whole name lowercase first.
for (char *name = entry -> name; *name != 0; name++)
if (*name >= 'A' && *name <= 'Z') *name = *name - 'A' + 'a';
// If it's a directory, make the first letter uppercase.
name = entry -> name;
if ((entry -> attribute & 16) && *name >= 'a' && *name <= 'z')
*name = *name - 'a' + 'A';
// Add the entry name into a sorted list for printing later.
StringList *newName = new StringList;
strcpy (newName -> str, name);
StringList *s = entryNames, *sPrev = 0;
while (s != 0)
{
if (strcmp (name, s -> str) < 0) break;
sPrev = s;
s = s -> next;
}
if (sPrev == 0)
{
newName -> next = entryNames;
entryNames = newName;
}
else
{
newName -> next = s;
sPrev -> next = newName;
}
}

static char spaces [] = " "; // 14 spaces.

void printEntries ()
{
// Print all the directory entries we have processed.
StringList *s = entryNames;
int col = 0;
while (s != 0)
{
char *name = s -> str;
// Print name and pad it with spaces to make 14 characters.
int spaceCount = 14 - strlen (name);
spaces [spaceCount] = 0;
*StandardOutput << name << spaces;
spaces [spaceCount] = ' ';
s = s -> next;
// Print 5 names in a column.
col = (col + 1) % 5;
if (col == 0) *StandardOutput << "\n" << eor;
}
if (col != 0) *StandardOutput << "\n" << eor;
}


  3 Responses to “Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : PCCAPP.ZIP
Filename : LS.CC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/