home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1996
/
ARCHIVE_96.iso
/
discs
/
shareware
/
share_46
/
showdir
/
c
/
showdir
Wrap
Text File
|
1991-11-24
|
5KB
|
136 lines
/*
* Module: showdir.c
* Created: 18th September, 1991.
* Last modified: 23rd September, 1991.
*
* Copyright (C) 1991 Neil Hoggarth.
*
* This text file is ANSI 'C' Source code.
*
* The program 'showdir' is a utility for computers running the RISC-OS
* operating system. The program accepts one argument, the name of a
* directory. This directory is searched for applications. An application
* is defined as a directory which has '!' as the first character in its
* file name. If any applications exist the associated '!boot' files are
* run. If a '!boot' file does not exist but a '!sprite" file does then
* the sprite is merged into the system sprite area using the 'IconSprites'
* command.
* The program therefore has the same effect as opening the given
* directory with the Desktop Filer but without displaying the contents in
* a window.
*
* When compiled this program should be linked to RISC_OSlib.o
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include "os.h"
enum{OTYPE_NULL,OTYPE_FILE,OTYPE_DIR};
static struct FileRecord {
int load; /* Load address */
int exec; /* Execution address */
int leng; /* Length */
int attr; /* File attributes */
int type; /* Object type */
char name[11]; /* Filename */
};
static int GetNextApp(char *dir,struct FileRecord *addr)
/*
* This function uses a RISC_OSlib "os_gbpb" call to search the directory
* 'dir' for the next object which is an application. The function exits
* if it finds an object which meets the definition of an application or
* if the entire directory has been searched. The return value will be a
* positive integer if an application has been found and -1 if the
* directory search has been completed.
*/
{
static os_gbpbstr gbpbio={
10, /* Read entries from specified dir. */
0, /* ptr to directory name. */
0, /* ptr to buffer for results. */
1, /* number of entries to read. */
0, /* offset into directory. */
sizeof(struct FileRecord), /* buffer length. */
"!*", /* Name to search for. */
};
gbpbio.file_handle=(int)dir;
gbpbio.data_addr=addr;
(void)os_gbpb(&gbpbio);
while(!(gbpbio.number==1 && addr->type==OTYPE_DIR) && gbpbio.seq_point!=-1)
(void)os_gbpb(&gbpbio);
return(gbpbio.seq_point);
}
static int ObjectType(char *fn)
/*
* This function uses a RISC_OSlib "os_file" call to find the type of an
* object, given the filename of the object.
*/
{
os_filestr fileio; /* control block for os_file call */
fileio.action=17; /* Read catalogue entry. */
fileio.name =fn; /* Name of object to search for. */
(void)os_file(&fileio);
return(fileio.action);
}
int main(int argc,char *argv[])
{
struct FileRecord buff; /* data buffer for os_gbpb call */
char bofile[256]; /* !boot filename */
char spfile[256]; /* !sprite filename */
char cmd[256]; /* command string */
if (argc!=2)
{
(void)fprintf(stderr,"%s: wrong number of arguments.\n",argv[0]);
(void)fprintf(stderr,"useage - %s <directory name>\n",argv[0]);
exit(1);
}
if (ObjectType(argv[1])!=OTYPE_DIR)
{
(void)fprintf(stderr,"%s: %s is not a directory.\n",argv[0],argv[1]);
exit(2);
}
while (GetNextApp(argv[1],&buff)!=-1)
{
(void)sprintf(bofile,"%s.%s.!boot",argv[1],buff.name);
(void)sprintf(spfile,"%s.%s.!sprite",argv[1],buff.name);
if (ObjectType(bofile)==OTYPE_FILE)
{
(void)sprintf(cmd,"Run %s",bofile);
(void)system(cmd);
}
else if (ObjectType(spfile)==OTYPE_FILE)
{
(void)sprintf(cmd,"IconSprites %s",spfile);
(void)system(cmd);
}
}
return(0);
}