home *** CD-ROM | disk | FTP | other *** search
- /* lib.c */
- /*
-
- ##### # #
- # # # # #
- # # #
- # ## #### #### # ## ####
- # # # # # # # # # #
- # # # # # ### # # # #
- # # # # # # # # # #
- # ### # # # #### ##### ### ####
-
- -----------------------------------------------------------------------------
-
- This is source for use with the 'DeskLib' Wimp C programming library for
- Risc OS. I currently use v1.04 of DeskLib. This source is FreeWare, which
- means you can use it to write commercial applications, but you may not charge
- *in any way* for the distribution of this source. I (Tim Browse) retain
- all copyright on this source.
-
- This source is provided 'as is' and I offer no guarantees that is useful,
- bug-free, commented, that it will compile, or even that it exists.
-
- If it breaks in half, you own both pieces.
-
- All source © Tim Browse 1993
-
- -----------------------------------------------------------------------------
-
- */
-
- /* ANSI includes */
- #include "stdlib.h"
- #include "string.h"
-
- /* RISC_OSLib includes */
- #include "os.h"
- #include "swis.h"
-
- /* DeskLib includes */
- #include "DeskLib.Core.h"
- #include "DeskLib.Error.h"
-
- /* Timslib includes */
- #include "Lib.h"
-
- char *save_str(const char *src, int length)
- {
- int len = length;
- char *dest;
-
- if (src == NULL)
- return NULL;
-
- if (len == 0)
- len = strlen_cr(src) + 1;
-
- dest = (char *) malloc(len);
-
- if (dest == NULL)
- return NULL;
-
- memcpy(dest, src, len);
-
- /* make sure string is zero terminated */
- dest[len-1] = (char) 0;
-
- return dest;
- }
-
-
- int set_bits(int src, int mask, int set_bits)
- {
- return ((src & ~mask) | set_bits);
- }
-
- void asciiz_to_cr(char *s, int max_len)
- {
- int i = 0;
-
- while ((i < max_len) && (s[i] != '\0'))
- i++;
-
- if (i < max_len)
- s[i] = '\15'; /* CR */
- }
-
- int strlen_cr(const char *s)
- {
- char *p = (char *) s;
-
- /* Look for a Null or CR character... */
- while ((*p != '\0') && (*p != '\15'))
- p++;
-
- return (p-s);
- }
-
-
- typedef struct
- {
- int load_addr, exec_addr, length, fileattr, type;
- char name[11];
- } FILE_INFO;
-
-
- int get_filetype(char *dirname, char *leafname)
- {
- os_gbpbstr gbpb;
- FILE_INFO file_info;
-
- /* Read file info */
- gbpb.action = 10;
- gbpb.file_handle = (int) dirname;
- gbpb.data_addr = (void *) &file_info; /* Space for a full entry */
- gbpb.seq_point = 0; /* Start at beginning of directory */
- gbpb.buf_len = sizeof(file_info);
- gbpb.wild_fld = leafname;
-
- do
- {
- gbpb.number = 1; /* Only need one entry to be read */
- Error_Check(os_gbpb(&gbpb));
- }
- while ((gbpb.number == 0) && (gbpb.seq_point != -1));
-
- if (gbpb.number == 0)
- return -1;
- else
- return ((file_info.load_addr & 0xFFF00) >> 8);
- }
-