Update of /cvsroot/ro-oslib/OSLib/!OsLib/examples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22314/examples Added Files: !Agenda,fd7 !Make,fd7 .cvsignore AMUmakefile,fe1 Ex0.c Ex1.c Ex2.c GNUmakefile Helloworld.c P1-046.c P1-053.c P1-067.c P1-068.c P1-108.c P1-109.c P1-110.c P1-219.c P1-332.c P1-334.c P1-467.c P1-606.c P1-754.c P1-833.c P1-834.c P2-042.c P2-083.c P2-099.c P2-383.c P2-413.c P2-491.c P2-492.c P2-493.c P2-524.c P2-526.c P2-589.c P2-615.c P2-616.c P2-617.c P2-618.c P2-619.c P2-622.c P2-625.c P2-629.c P2-632.c P2-634.c P2-636.c P2-638.c P2-691.c P2-735.c P2-740.c P2-743.c P3-007.c P3-018.c P3-023.c P3-024.c P3-025.c P3-063.c P3-070.c P3-072.c P3-073.c P3-162.c P3-185.c P3-198.c P3-231.c P3-246.c P3-411.c P3-421.c P3-433.c P3-469.c P3-549.c P3-562.c P3-659.c P3-743.c Log Message: OSLib examples added back in --- NEW FILE: .cvsignore --- # examples/.cvsignore o o/* --- NEW FILE: P3-198.c --- #include "oslib/wimp.h" wimp_t task_from_icon (wimp_w w, wimp_i i) { wimp_message message; message.size = 20; message.your_ref = 0; /*rest not used*/ return wimp_send_message_to_window (wimp_USER_MESSAGE_ACKNOWLEDGE, &message, w, i); } --- NEW FILE: P1-834.c --- #include "oslib/colourtrans.h" #include "oslib/os.h" #include "oslib/osspriteop.h" extern osspriteop_area *Ram; extern osspriteop_trans_tab *Pix_Trans; void ex (void) /*ColourTrans can do this itself.*/ { osspriteop_header *sptr; sptr = (osspriteop_header *) ((char *) Ram + Ram->first); colourtrans_select_table_for_sprite (Ram, (osspriteop_id) sptr, colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE, Pix_Trans, colourtrans_GIVEN_SPRITE); } --- NEW FILE: P2-617.c --- #include <stdio.h> #include <stdlib.h> #include "oslib/econet.h" void ex1 (int status) { econet_convert_status_to_error (status, NULL, 0, 0, 0); } void ex2 (int status) { os_error error; econet_convert_status_to_error (status, &error, sizeof error, 0, 0); } void ex3 (int status, byte station, byte net) { os_error error; econet_convert_status_to_error (status, &error, sizeof error, station, net); } void ex4 (int status) { if (status == econet_STATUS_TRANSMITTED) { printf ("OK\n"); exit (0); } } --- NEW FILE: P3-562.c --- #include "oslib/os.h" #include "oslib/osfind.h" #include "oslib/pdriver.h" void skeleton (void) { pdriver_info (...); osfind_openout (..., "printer:", ...); pdriver_select_job (...); if (... driver supports pdriver_declare_font ...) { while (... fonts to be declared ...) pdriver_declare_font (...); pdriver_declare_font (...); } for (... each page to print ...) { do pdriver_give_rectangle (...); while (... rectangles to declare ...); pdriver_draw_page (...); while (... more rectangles to print ...) { ... plot returned rectangles using supported output calls ...; pdriver_get_rectangle (...); } } pdriver_end_job (...); osfind_close (...); } --- NEW FILE: P3-659.c --- #include "oslib/os.h" #include "oslib/osfind.h" #include "oslib/pdriver.h" extern os_error *Get_Document_Size (os_box *); extern os_error *Fit_Two_Pages (int x0, int y0, int x1, int y1, os_box *, os_hom_trfm *, os_coord *, os_coord *); extern os_error *Draw_Page (int page, os_box *); os_error *print_out (int first_page, int last_page, char *title, char *file_name, font_f *font_ptr) { os_error *error; os_f job, old_job; osbool done_openout = FALSE, done_select_job = FALSE, more; bits features; os_box box, printable, box2; os_hom_trfm trfm; os_coord o1, o2; int page, page_to_print; if ((error = xosfind_openout (osfind_NO_PATH | osfind_ERROR_IF_DIR | osfind_ERROR_IF_ABSENT, "printer:", NULL, &job)) != NULL) goto finish; done_openout = TRUE; if ((error = xpdriver_select_job (job, title, &old_job)) != NULL) goto finish; done_select_job = TRUE; /*This code is not explicitly in the BASIC, but PROCdeclarefonts must do something like this:*/ if ((error = xpdriver_info (NULL, NULL, NULL, &features, NULL, NULL, NULL, NULL)) != NULL) goto finish; if ((features & pdriver_FEATURE_DECLARE_FONT) != 0) do if ((error = xpdriver_declare_font (*font_ptr, NULL, 0)) != NULL) goto finish; while (*font_ptr++ != 0); if ((error = Get_Document_Size (&box)) != NULL) goto finish; if ((error = xpdriver_page_size (NULL, NULL, &printable.x0, &printable.y0, &printable.x1, &printable.y1)) != NULL) goto finish; if ((error = Fit_Two_Pages (printable.x0, printable.y0, printable.x1, printable.y1, &box, &trfm, &o1, &o2)) != NULL) goto finish; for (page = first_page; page <= last_page; page += 2) { if ((error = xpdriver_give_rectangle (page, &box, &trfm, &o1, os_COLOUR_WHITE)) != NULL) goto finish; if (page < last_page) if ((error = xpdriver_give_rectangle (page + 1, &box, &trfm, &o2, os_COLOUR_WHITE)) != NULL) goto finish; if ((error = xpdriver_draw_page (1, &box2, 0, NULL, &more, &page_to_print)) != NULL) goto finish; while (more) { if ((error = Draw_Page (page_to_print, &box2)) != NULL) goto finish; if ((error = xpdriver_get_rectangle (&box2, &more, &page_to_print)) != NULL) goto finish; } } finish: if (done_select_job) { os_error *error1; error1 = error == NULL? xpdriver_end_job (job): xpdriver_abort_job (job); if (error == NULL) error = error1; error1 = xpdriver_select_job (old_job, NULL, NULL); if (error == NULL) error = error1; } if (done_openout) { os_error *error1; error1 = xosfind_close (job); if (error == NULL) error = error1; } return error; } --- NEW FILE: P2-622.c --- /*Note there are bugs in the assembler: the receive block is not abandoned if econet_do_transmit() fails, and R6, R7 are the wrong way round in the call to Econet_DoTransmit.*/ #include "oslib/econet.h" #include "oslib/os.h" #define ENTRY_PORT 0x1Fu #define ERROR_NUMBER_BUFFER_OVERFLOW 1 extern byte Server_Station, Server_Net; extern int Server_Delay, Server_Tx_Delay, Server_Tx_Count; static os_error Buffer_Overflow_Error = {ERROR_NUMBER_BUFFER_OVERFLOW, "Command too long for buffer"}; os_error *example (char *text) { byte reply_port = 0, buffer [80]; os_error *error = NULL, error1; econet_rx_cb rx_cb = 0; int i,status; char c; if ((error = xeconet_allocate_port (&reply_port)) != NULL) goto finish; if ((error = xeconet_create_receive (reply_port, Server_Station, Server_Net, buffer, sizeof buffer, &rx_cb, NULL)) != NULL) goto finish; buffer [0] = reply_port; for (i = 1, c = *text++;; i++) { if (!(i < sizeof buffer)) { error = &Buffer_Overflow_Error; goto finish; } if (c < ' ') { buffer [i] = '\r'; break; } else buffer [i] = c; } if ((error = xeconet_do_transmit (NONE, ENTRY_PORT, Server_Station, Server_Net, buffer, sizeof buffer, Server_Tx_Count, Server_Tx_Delay, &status, NULL)) != NULL) goto finish; if (status != econet_STATUS_TRANSMITTED) { error = xeconet_convert_status_to_error (status, &error1, sizeof error1, Server_Station, Server_Net); goto finish; } if ((error = xeconet_wait_for_reception (rx_cb, Server_Delay, /*abort on excape?*/ FALSE, &status, NULL, NULL, NULL, NULL, NULL, NULL)) != NULL) goto finish; rx_cb = 0; if (status != econet_STATUS_RECEIVED) { error = xeconet_convert_status_to_error (status, &error1, sizeof error1, Server_Station, Server_Net); goto finish; } Server_Command_Port = *(int *) buffer; finish: if (error != NULL) { if (rx_cb != 0) { os_error *error1; error1 = xeconet_abandon_receive (rx_cb); if (error == NULL) error = error1; } if (reply_port != 0) { os_error *error1; error1 = xeconet_de_allocate_port (reply_port); if (error == NULL) error = error1; } } return error; } --- NEW FILE: P3-411.c --- #include <string.h> #include "oslib/os.h" extern char Old_Font_Path []; extern void Cache_List_Of_Fonts (void); void ex (void) { char buffer [0x200]; int used; os_gs_trans ("<Font$Prefix> and <Font$Path>", buffer, sizeof buffer - 1, &used); buffer [used] = '\0'; /*ensure there is a terminator (0 for C)*/ if (strcmp (buffer, Old_Font_Path) != 0) { strcpy (Old_Font_Path, buffer); Cache_List_Of_Fonts (); } } --- NEW FILE: P3-549.c --- #include "oslib/macros.h" #include "oslib/draw.h" #define PATH_LEN 256 static int Path [PATH_LEN/sizeof (int)], Path_Ptr = 0; static os_error Too_Small = {0, "Insufficient path buffer"}; void add (int value) { if (Path_Ptr + 1 > COUNT (Path)) os_generate_error (&Too_Small); Path [Path_Ptr++] = value; } int main (void) { int xsize, ysize, xscale, yscale; os_trfm trfm; draw_path *path = (draw_path *) Path; draw_line_style line_style; xsize = 210000, ysize = 160000; xscale = 1280*256/xsize << 16; yscale = 1024*256/ysize << 16; trfm.entries [0] [0] = xscale; trfm.entries [0] [1] = 0; trfm.entries [1] [0] = 0; trfm.entries [1] [1] = yscale; trfm.entries [2] [0] = 0; trfm.entries [2] [1] = 0; line_style.join_style = draw_JOIN_BEVELLED; line_style.end_cap_style = draw_CAP_ROUND; line_style.start_cap_style = draw_CAP_ROUND; line_style.reserved = 0; line_style.mitre_limit = 0; line_style.start_cap_width = 0; line_style.start_cap_length = 0; line_style.end_cap_width = 0; line_style.end_cap_length = 0; add (draw_MOVE_TO), add (80000), add (80000); add (draw_LINE_TO), add (80000), add (120000); add (draw_LINE_TO), add (170000), add (120000); add (draw_LINE_TO), add (170000), add (80000); add (draw_MOVE_TO), add (50000), add (50000); add (draw_BEZIER_TO), add (80000), add (80000), add (85000), add (30000), add (50000), add (60000); add (draw_CLOSE_GAP); add (draw_END_PATH), add (PATH_LEN - (Path_Ptr + 1)*sizeof (int)); os_writen ("\x1D\0\0\0\0", 5); draw_stroke (path, NONE, &trfm, xsize/640, 5000, &line_style, NULL); trfm.entries [2] [0] = 60 << 8; trfm.entries [2] [1] = -100 << 8; draw_stroke (path, NONE, &trfm, xsize/640, 2500, &line_style, NULL); return 0; } --- NEW FILE: P2-625.c --- #include <string.h> #include "oslib/econet.h" #include "oslib/os.h" #include "oslib/osbyte.h" #include "oslib/osmodule.h" #include "oslib/osword.h" typedef struct clock_list clock_list; extern int Event_Veneer (void); struct clock_list {clock_list *next; econet_tx_cb tx; os_date_and_time clock;}; extern byte Command_Port; extern econet_rx_cb Rx_Handle; extern clock_list *Tx_List; extern int Reply_Count, Reply_Delay; extern byte Buffer [80]; os_error *start (void) { os_error *error = NULL; if ((error = xos_claim (EventV, (void *) &Event_Veneer, NULL)) != NULL) goto finish; if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetRx, SKIP, NULL, NULL)) != NULL) goto finish; if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetTx, SKIP, NULL, NULL)) != NULL) goto finish; if ((error = xeconet_create_receive (Command_Port, 0, 0, Buffer, sizeof Buffer, &Rx_Handle, NULL)) != NULL) goto finish; finish: /*If error != NULL, should abandon receive (if created), disable enabled events and release EventV (if claimed) here.*/ return error; } os_error *event (int *event, econet_rx_cb rx, int status) /*or (int *event, econet_tx_cb tx, int status)*/ /*The mechanism by which event_handler() calls event() is not detailed here. Assume that if event is set to -1 on exit, the call is claimed.*/ { os_error *error = NULL; clock_list *clock_ptr; byte port, station, net, *buffer; oswordreadclock_utc_block utc; switch (*event) { case Event_EconetRx: if (rx == Rx_Handle) { if ((error = xeconet_read_receive (rx, NULL, NULL, &port, &station, &net, &buffer, NULL)) != NULL) goto finish; if ((error = xosmodule_alloc (sizeof *clock_ptr, (void **) &clock_ptr)) != NULL) goto finish; utc.op = oswordreadclock_OP_UTC; if ((error = xoswordreadclock_utc (&utc)) != NULL) goto finish; memcpy (clock_ptr->clock, utc.utc, sizeof (os_date_and_time)); if ((error = xeconet_start_transmit (0, Buffer [0], station, net, (byte *) &clock_ptr->clock, sizeof clock_ptr->clock, Reply_Count, Reply_Delay, &clock_ptr->tx, NULL)) != NULL) goto finish; /*Add the list to new record.*/ clock_ptr->next = Tx_List; Tx_List = clock_ptr; /*Now reopen the reception.*/ if ((error = xeconet_create_receive (Command_Port, 0, 0, Buffer, sizeof Buffer, &Rx_Handle, NULL)) != NULL) goto finish; /*claim vector*/ *event = -1; } break; case Event_EconetTx: { econet_tx_cb tx = (econet_tx_cb) rx; /*change of name only*/ clock_list **t; for (t = &Tx_List; *t != NULL; t = &(*t)->next) if ((*t)->tx == tx) { /*Remove from the list*/ *t = (*t)->next; (void) xeconet_abandon_transmit (tx, NULL); (void) xosmodule_free ((byte *) *t); } /*claim vector*/ *event = -1; } break; } finish: return error; } --- NEW FILE: P1-754.c --- #include <stdlib.h> #include "oslib/os.h" #include "oslib/osspriteop.h" extern osspriteop_area *My_Area; extern char My_Sprite []; extern os_error No_Memory; extern osbool Interested; void ex1 (void) { int r0, r1, r2, r3; osspriteop_switch_output_to_sprite (osspriteop_NAME, My_Area, (osspriteop_id) My_Sprite, NULL, &r0, &r1, &r2, &r3); /*... do whatever graphics we want ...*/ osspriteop_unswitch_output (r0, r1, r2, r3); } void ex2 (void) { osspriteop_save_area *save_area; int c0, c1, c2, c3; if ((save_area = malloc (osspriteop_read_save_area_size (osspriteop_NAME, My_Area, (osspriteop_id) My_Sprite))) == NULL) os_generate_error (&No_Memory); save_area->a [0] = 0; while (Interested) { osspriteop_switch_output_to_sprite (osspriteop_NAME, My_Area, (osspriteop_id) My_Sprite, save_area, &c0, &c1, &c2, &c3); /*... work on the sprite ...*/ osspriteop_unswitch_output (c0, c1, c2, c3); /*... talk to the user ...*/ } } --- NEW FILE: P2-740.c --- #include "oslib/hourglass.h" #include "oslib/os.h" void example (void) { hourglass_on (); hourglass_on (); hourglass_percentage (10); /*sets to 10*/ hourglass_percentage (20); /*sets to 20*/ hourglass_on (); hourglass_percentage (50); /*DOESN'T set to 50*/ hourglass_off (); hourglass_percentage (30); /*sets to 30*/ hourglass_off (); /*turns off percentages*/ hourglass_off (); /*turns off hourglass*/ } --- NEW FILE: P1-334.c --- #include "oslib/os.h" #include "oslib/osbyte.h" extern void Timer_Veneer (void); extern void *Alarm; extern void Call_Back_Veneer (void); extern void *Save_Block; extern void Event_Veneer (void); void add_call_back (void) /*The code to install the handler only.*/ { os_call_after (200, (void *) &Timer_Veneer, Alarm); } void call_back_handler (void) /*Installation code only.*/ { void *old_callbacks, *old_events; byte *old_buffer; osbool shift_pressed; old_callbacks = os_change_environment (os_HANDLER_CALL_BACK, (void *) &Call_Back_Veneer, 0, Save_Block, NULL, &old_buffer); old_events = os_change_environment (os_HANDLER_EVENT, (void *) &Event_Veneer, 0, 0, NULL, NULL); os_byte (osbyte_ENABLE_EVENT, Event_MouseTransition, SKIP, NULL, NULL); do os_byte (osbyte_IN_KEY, 0 ^ 0xFF, 0xFF, &shift_pressed, NULL); while (!shift_pressed); /*loop until shift*/ os_byte (osbyte_DISABLE_EVENT, Event_MouseTransition, SKIP, NULL, NULL); os_change_environment (os_HANDLER_EVENT, old_events, 0, 0, NULL, NULL); os_change_environment (os_HANDLER_CALL_BACK, old_callbacks, 0, old_buffer, NULL, NULL); } --- NEW FILE: P3-072.c --- #include <kernel.h> #include "oslib/os.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; extern char My_Command []; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_Reset: Task_Handle = 0; break; case Service_StartedWimp: if (Task_Handle == (wimp_t) -1) Task_Handle = 0; break; } } --- NEW FILE: P3-063.c --- #include <kernel.h> #include "oslib/os.h" #include "oslib/osmodule.h" #include "oslib/wimp.h" #define ENTRY_COMMAND 42 static char Title [] = "MyModule"; static wimp_t Task_Handle; /*This is a CMHG-style command entry point.*/ _kernel_oserror *main_command (char *tail, int argc, int cmd_no, void *workspace) { os_error *error = NULL; switch (cmd_no) { case ENTRY_COMMAND: if ((error = xosmodule_enter (Title, tail)) != NULL) goto finish; break; /*other commands*/ } finish: return (_kernel_oserror *) error; } /*This is the module's language entry point.*/ int main (void) { os_error *error = NULL; if (Task_Handle != 0) { wimp_t t = Task_Handle; Task_Handle = 0; if ((error = xwimp_close_down (t)) != NULL) goto finish; } /*Now claim any workspace etc required before initialising the WIMP*/ if ((error = xwimp_initialise (wimp_VERSION_RO3, Title, NULL, NULL, &Task_Handle)) != NULL) goto finish; /*Rest of the application.*/ finish: return 0; } --- NEW FILE: P3-025.c --- #include "oslib/os.h" #include "oslib/osspriteop.h" #include "oslib/wimp.h" int main (void) { osspriteop_area *rom; wimp_base_of_sprites (&rom, NULL); osspriteop_save_sprite_file (osspriteop_USER_AREA, rom, "WSprite"); return 0; } --- NEW FILE: P2-743.c --- #include "oslib/hourglass.h" #include "oslib/os.h" #include "oslib/osfile.h" extern byte Buffer []; extern os_error *Process_Byte (byte); os_error *do_load_and_process (char *file_name) { os_error *error = NULL; int i, size; osbool done_on = FALSE; if ((error = xosfile_load_stamped (file_name, Buffer, NULL, NULL, NULL, &size, NULL)) != NULL) goto finish; /*note that osfile_load loads a file at its load address*/ if (size != 0) { if ((error = xhourglass_on ()) != NULL) goto finish; done_on = TRUE; for (i = 0; i < size; i++) { if ((error = xhourglass_percentage (100*i/size)) != NULL) goto finish; if ((error = Process_Byte (Buffer [i])) != NULL) goto finish; } } finish: if (done_on) { os_error *error1; error1 = xhourglass_off (); if (error == NULL) error = error1; } return error; } --- NEW FILE: P2-042.c --- #include "oslib/os.h" #include "oslib/osfile.h" os_error *ex (char *file_name) { int obj_type; os_error *error = NULL; if ((error = xosfile_read_stamped (file_name, &obj_type, NULL, NULL, NULL, NULL, NULL)) != NULL) goto finish;; if (obj_type != osfile_IS_FILE) { error = xosfile_make_error (file_name, obj_type); goto finish; } finish: return error; } --- NEW FILE: P3-469.c --- #include "oslib/font.h" void ex (char *file_name) { font_un_cache_file (file_name, FALSE); /*... replace old file with new one ...*/ font_un_cache_file (file_name, TRUE); } --- NEW FILE: P2-735.c --- #include "oslib/hourglass.h" #include "oslib/os.h" #include "oslib/osfile.h" extern byte Buffer []; extern os_error *Process_Byte (byte); os_error *do_load_and_process (char *file_name) { os_error *error = NULL; int i, size; osbool done_on = FALSE; if ((error = xosfile_load_stamped (file_name, Buffer, NULL, NULL, NULL, &size, NULL)) != NULL) goto finish; /*note that osfile_load loads a file at its load address*/ if (size != 0) { if ((error = xhourglass_on ()) != NULL) goto finish; done_on = TRUE; for (i = 0; i < size; i++) if ((error = Process_Byte (Buffer [i])) != NULL) goto finish; } finish: if (done_on) { os_error *error1; error1 = xhourglass_off (); if (error == NULL) error = error1; } return error; } --- NEW FILE: P2-413.c --- #include <kernel.h> #include "oslib/resourcefs.h" extern resourcefs_file_list Files; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_ResourceFSStarting: (*(void (*) (resourcefs_file_list *, int, int, int)) regs->r [2]) (&Files, SKIP, SKIP, regs->r [3]); break; } } --- NEW FILE: P2-526.c --- #include "oslib/osfscontrol.h" extern int Image_File_Type; os_error *remove_image (void) { return xosfscontrol_deregister_image_fs (Image_File_Type); } --- NEW FILE: P1-606.c --- #include "oslib/os.h" int xwind_size (void) { int value_list [2]; static os_VDU_VAR_LIST (3) var_list = {os_MODEVAR_XEIG_FACTOR, os_MODEVAR_XWIND_LIMIT, -1}; os_read_vdu_variables ((os_vdu_var_list *) &var_list, value_list); return value_list [1] + 1 << value_list [0]; } --- NEW FILE: P2-691.c --- #include "oslib/econet.h" #include "oslib/messagetrans.h" #include "oslib/os.h" static os_error Error_No_Econet = {error_ECONET_NO_ECONET, "NoEco"}; os_error *has_econet (void) /*Return an error if no econet*/ { os_error *error = NULL, *error1; if ((error1 = xeconet_set_protection (NONE, ALL, NULL)) != NULL && error1->errnum == error_NO_SUCH_SWI) { error = xmessagetrans_error_lookup (&Error_No_Econet, NULL, NULL, 0, 0, 0, 0, 0); goto finish; } finish: return error; } --- NEW FILE: P3-018.c --- #include "oslib/os.h" #include "oslib/wimp.h" extern wimp_block Block; /*|Block| is the wimp_poll block*/ void redraw (void) { osbool more; for (more = wimp_redraw_window (&Block.redraw); more; more = wimp_get_rectangle (&Block.redraw)) { /*Redraw contents of appropriate window*/ } } --- NEW FILE: P1-332.c --- #include "oslib/os.h" void read_variable (void) { char value [255]; int context, len; context = 0; while (xos_read_var_val ("Sys$*", value, sizeof value - 1, context, os_VARTYPE_EXPANDED, &len, &context, NULL) == NULL) { os_writen (value, len); os_new_line (); } } extern void Code_Veneer (void); extern int Code_Size; void create_code_variable (void) /*Must be done in assembler. The creation part could be done like this, assuming Code_Veneer is the assembler code.*/ { os_set_var_val ("Mode", (void *) &Code_Veneer, Code_Size, 0, os_VARTYPE_CODE, NULL); } --- NEW FILE: P3-023.c --- #include <string.h> #include "oslib/macros.h" #include "oslib/os.h" #include "oslib/wimp.h" os_error *write_icon (wimp_w w, wimp_i i, char *buffer, char *string) { os_error *error = NULL; wimp_caret caret; strcpy (buffer, string); /*assume that these are 0-terminated, rather than 13 as in BASIC*/ if ((error = xwimp_get_caret_position (&caret)) != NULL) goto finish; if (w == caret.w && i == caret.i) { int len = strlen (buffer); if ((error = xwimp_set_caret_position (caret.w, caret.i, caret.pos.x, caret.pos.y, -1, MIN (caret.index, len))) != NULL) goto finish; } if ((error = xwimp_set_icon_state (w, i, NONE, NONE)) != NULL) goto finish; finish: return error; } --- NEW FILE: P1-467.c --- /*Example of how to use OS_ReadArgs in C.*/ #include <stdio.h> #include "oslib/macros.h" #include "oslib/os.h" int main (void) { struct {char *programme, *from, *to, *since; osbool help; os_gi *size; os_gs *name; char argd [1024];} argl; os_read_args ("programme/a,from/a,to/a,since/k,help/s,size/e,name/g", os_get_env (NULL, NULL), (char *) &argl, sizeof argl); /*Each structure element must correspond to the keyword in that place: keyword qualifier component type ------- --------- --------- ---- switch (/s) osbool expression (/e) os_gi string (/g) os_gs everything else char * */ printf ( "programme: %s\n" "from: %s\n" "to: %s\n" "since: %s\n" "help: %s\n" /*"size: %d\n" -- TV 20040707 */ "size: %hd\n" "name: %.*s\n", argl.programme, argl.from, argl.to, argl.since? argl.since: "(not given)", WHETHER (argl.help), argl.size? WORD (argl.size->i): -1, argl.name? /*SHORT*/ (argl.name->size): 80, argl.name? argl.name->s: "(not given)" ); /*Note use of WORD and SHORT, since these are not necessarily word- aligned pointers.*/ /* The logic of this statement escapes me; moreover, SHORT has to be commented out, else it gives a compiler warning. -- TV 20040707 */ return 0; } --- NEW FILE: P3-421.c --- #include "oslib/font.h" void apply_encoding (char *result, int size, char *original, char *encoding) /*There is a SWI to do this.*/ { font_apply_fields (original, encoding, result, size); } --- NEW FILE: P1-053.c --- #include "oslib/buffer.h" #include "oslib/os.h" #include "oslib/osbyte.h" void ex (void) { os_byte (osbyte_BUFFER_INSERT, buffer_KEYBOARD, 'A', NULL, NULL); } --- NEW FILE: P2-615.c --- #include <stdio.h> #include "oslib/econet.h" extern econet_tx_cb Tx_Cb; void ex1 (void) { byte buf [20]; Tx_Cb = econet_start_transmit (NONE, 99, 7, 0, buf, sizeof buf, 3, 100, NULL); } void ex2 (void) { int status; do { status = econet_poll_transmit (Tx_Cb); printf ("%d\n", status); } while (status == econet_STATUS_TX_READY || status == econet_STATUS_TRANSMITTING); } --- NEW FILE: P2-491.c --- #include <kernel.h> #include "oslib/filer.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; extern char My_Command []; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_StartFiler: if (Task_Handle == 0) { Task_Handle = (wimp_t) -1; regs->r [0] = (int) My_Command; regs->r [1] = FALSE; } break; } } --- NEW FILE: P1-108.c --- #include <stdio.h> #include "oslib/os.h" #include "oslib/territory.h" extern void Vector_Veneer (void); void ex (void) { char *lowercase_table, *uppercase_table, flag = 1, command [80]; os_error *error = NULL; osbool done_claim = FALSE; if ((error = xterritory_lower_case_table (territory_CURRENT, &lowercase_table)) != NULL) goto finish; if ((error = xterritory_upper_case_table (territory_CURRENT, &uppercase_table)) != NULL) goto finish; if ((error = xos_claim (WrchV, (void *) &Vector_Veneer, (byte *) &flag)) != NULL) goto finish; done_claim = TRUE; do { fgets (command, sizeof command - 1, stdin); if ((error = xos_cli (command)) != NULL) goto finish; } while (command [0] != '\n'); finish: if (done_claim) { os_error *error1; error1 = xos_release (WrchV, (void *) &Vector_Veneer, (byte *) &flag); if (error == NULL) error = error1; } if (error != NULL) os_generate_error (error); } --- NEW FILE: P1-109.c --- #include "oslib/os.h" os_error *read_palette (os_gcol entry_no, int entry_type, os_colour *on, os_colour *off) { os_error *error = NULL; osbool incomplete; if ((error = xpalettev_read_entry (entry_no, entry_type, on, off, &incomplete)) != NULL) goto finish; if (incomplete) { if ((error = xos_read_palette (entry_no, entry_type, on, off)) != NULL) goto finish; *on |= (*on & 0xF0F0F000) >> 4; *off |= (*off & 0xF0F0F000) >> 4; } finish: return error; } --- NEW FILE: P1-046.c --- #include "oslib/messagetrans.h" #include "oslib/os.h" extern void Acknowledge_Escape (void); static os_error Error = {error_ESCAPE, "Escape"}; /*error block for escape*/ void ex (void) { if ((os_read_escape_state () & _C) != NONE) { Acknowledge_Escape (); /*acknowledge it*/ os_generate_error (xmessagetrans_error_lookup (&Error, NULL, NULL, 0, SKIP, SKIP, SKIP, SKIP)); /* Exactly the same effect would be given by messagetrans_error_lookup (&Error, NULL, NULL, 0, SKIP, SKIP, SKIP, SKIP); */ } } --- NEW FILE: P3-024.c --- #include "oslib/os.h" #include "oslib/wimp.h" void delete_and_recreate (wimp_w w, wimp_i i) { /*to delete*/ wimp_set_icon_state (w, i, wimp_ICON_NEEDS_HELP | wimp_ICON_DELETED, wimp_ICON_NEEDS_HELP | wimp_ICON_DELETED); /*to recreate*/ wimp_set_icon_state (w, i, NONE, wimp_ICON_NEEDS_HELP | wimp_ICON_DELETED); } --- NEW FILE: P2-589.c --- #include <kernel.h> #include "oslib/filecore.h" #include "oslib/osfscontrol.h" extern char *Filing_System_Name; os_error *select (void) { return xosfscontrol_select_fs ((osfscontrol_id) Filing_System_Name); } #define Module_DiscOp 0x12345 /*My disc op SWI number*/ extern byte *Instance; /*This is a CMHG-style SWI entry point.*/ _kernel_oserror *main_swi (int swi, _kernel_swi_regs *regs, void *workspace) { os_error *error = NULL; switch (swi) { case Module_DiscOp & 0x3F: regs->r [8] = (int) Instance; if ((error = (os_error *) _kernel_swi (FileCore_DiscOp, regs, regs)) != NULL) goto finish; break; /*other SWI code*/ } finish: return (_kernel_oserror *) error; } --- NEW FILE: P1-833.c --- #include "oslib/os.h" #include "oslib/osspriteop.h" extern osspriteop_area *Ram; extern char Sprite_Name []; void ex (int height, int width, os_mode mode, os_palette *palette) { osspriteop_header *sptr; os_sprite_palette *pal; int i; osspriteop_create_sprite (osspriteop_NAME, Ram, Sprite_Name, /*create_palette?*/ FALSE, height, width, mode); sptr = (osspriteop_header *) ((char *) Ram + Ram->first); pal = (os_sprite_palette *) ((char *) sptr + sizeof (osspriteop_header)); sptr->image += 2048; sptr->mask += 2048; sptr->size += 2048; Ram->used += 2048; for (i = 0; i < 255; i++) pal->entries [i].on = pal->entries [i].off = palette->entries [i] & ~0xFFu; } --- NEW FILE: P2-083.c --- #include "oslib/osfscontrol.h" os_error *ex (char *command_tail_ptr, byte *execution_address, char *command_name_ptr) { os_error *error = NULL; os_error *(*fn) (void) = (os_error *(*) (void)) ((bits) execution_address & ~0xFC000003); /*address with no flags, user mode*/ if ((error = xosfscontrol_start_application (command_tail_ptr, (byte *) fn, command_name_ptr)) != NULL) goto finish; /*assume not in SVC mode (mode-switching harder in C)*/ /*Enter application: assume CAO is function address*/ error = (*fn) (); os_exit (error, 0); /*in case it returns*/ finish: return error; } --- NEW FILE: P3-070.c --- #include <kernel.h> #include "oslib/os.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; extern char My_Command []; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_StartWimp: if (Task_Handle == 0) Task_Handle = (wimp_t) -1; regs->r [0] = (int) My_Command; regs->r [1] = FALSE; break; } } --- NEW FILE: P3-743.c --- #include <stddef.h> #include <string.h> #include "oslib/os.h" #include "oslib/osmodule.h" #include "oslib/messagetrans.h" extern void *x_alloc (int); typedef struct desc desc; struct desc {messagetrans_control_block cb; char file_name [UNKNOWN];}; #define DESC(N) struct {messagetrans_control_block cb; char file_name [N];} #define SIZEOF_DESC(N) (offsetof (desc, file_name) + (N)) void ex (char *file_name) { bits flags; int size; char *buffer; desc *file_desc; messagetrans_file_info (file_name, &flags, &size); if ((flags & messagetrans_DIRECT_ACCESS) != NONE) buffer = NULL; else buffer = x_alloc (size); file_desc = osmodule_alloc (SIZEOF_DESC (strlen (file_name) + 1)); strcpy (file_desc->file_name, file_name); messagetrans_open_file (&file_desc->cb, file_desc->file_name, buffer); } --- NEW FILE: P2-619.c --- #include "oslib/econet.h" #include "oslib/os.h" os_error *tx (void) { byte buf [20]; int status; os_error *error = NULL; char text [50], *end; if ((error = xeconet_do_transmit (NONE, 99, 7, 0, buf, sizeof buf, 6, 100, &status, NULL)) != NULL) goto finish; if (status != econet_STATUS_TRANSMITTED) { if ((error = xos_convert_cardinal1 (status, text, sizeof text, &end)) != NULL) goto finish; if ((error = xeconet_convert_status_to_string (status, end, sizeof text - (end - text), 99, 7, NULL)) != NULL) goto finish; if ((error = xos_write0 (text)) != NULL) goto finish; } finish: return error; } --- NEW FILE: Helloworld.c --- #include "oslib/os.h" int main (void) { os_write0 ("Hello, World!\n\r"); return 0; } --- NEW FILE: P3-073.c --- #include <kernel.h> #include "oslib/os.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; extern char My_Command []; /*This is a CMHG-style termination entry point.*/ _kernel_oserror *main_terminate (osbool fatal, int instance, void *workspace) { os_error *error = NULL, *error1; if (Task_Handle != 0) { error1 = xwimp_close_down (Task_Handle); if (error == NULL) error = error1; } return (_kernel_oserror *) error; } --- NEW FILE: P2-618.c --- #include <stdio.h> #include "oslib/econet.h" #include "oslib/os.h" void tx1 (void) { byte buf [20]; int status; os_error error; status = econet_do_transmit (NONE, 99, 7, 0, buf, sizeof buf, 6, 100, NULL); if (status != econet_STATUS_TRANSMITTED) econet_convert_status_to_error (status, &error, sizeof error, SKIP, SKIP); } os_error *tx2 (void) { byte buf [20]; int status; os_error *error = NULL, error1; if ((error = xeconet_do_transmit (NONE, 99, 7, 0, buf, sizeof buf, 6, 100, &status, NULL)) != NULL) goto finish; if (status != econet_STATUS_TRANSMITTED) { error = xeconet_convert_status_to_error (status, &error1, sizeof error1, SKIP, SKIP); goto finish; } finish: return error; } --- NEW FILE: P2-634.c --- #include "oslib/buffer.h" #include "oslib/osbyte.h" os_error *insert_character (byte *buffer) { return xos_byte (osbyte_BUFFER_INSERT, buffer [4], buffer_KEYBOARD, NULL, NULL); } --- NEW FILE: Ex1.c --- /*52 instructions*/ #include "oslib/colourtrans.h" #include "oslib/font.h" #include "oslib/os.h" #include "oslib/pdriver.h" os_error *x (int page, char *t) { osbool more; os_box req; os_error *error = NULL; if ((error = xpdriver_draw_page (1, &req, page, NULL, &more, NULL)) != NULL) goto finish; while (more) { if ((error = xcolourtrans_set_gcol (os_COLOUR_BLACK, colourtrans_SET_FG, os_ACTION_OVERWRITE, NULL, NULL)) != NULL) goto finish; if ((error = xfont_paint (0, t, NONE, 0, 0, NULL, NULL, 0)) != NULL) goto finish; if ((error = xpdriver_get_rectangle (&req, &more, NULL)) != NULL) goto finish; } finish: return error; } --- NEW FILE: P2-632.c --- #include <string.h> #include "oslib/econet.h" #include "oslib/os.h" #include "oslib/osbyte.h" #include "oslib/osmodule.h" #include "oslib/osword.h" #define RPC_SEND_TIME 42 /*some number, unique for this net*/ typedef struct clock_list clock_list; struct clock_list {clock_list *next; econet_tx_cb tx; os_date_and_time clock;}; extern byte Command_Port; extern clock_list *Tx_List; extern int Reply_Count, Reply_Delay; extern byte Buffer [80]; extern void Event_Veneer (void); extern osbool Claimed_Flag; os_error *start (void) { os_error *error = NULL; if ((error = xos_claim (EventV, (void *) &Event_Veneer, NULL)) != NULL) goto finish; Claimed_Flag = TRUE; if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetUserRPC, SKIP, NULL, NULL)) != NULL) goto finish; if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetTx, SKIP, NULL, NULL)) != NULL) goto finish; finish: /*If error != NULL, should disable enabled events and release EventV (if claimed) here.*/ return error; } os_error *event (int *event, byte *args, int rpc, byte station, byte net) /*or (int *event, econet_tx_cb tx, int status)*/ /*The mechanism by which Event_Veneer() calls event() is not detailed here. Assume that if event is set to -1 on exit, the call is claimed.*/ { os_error *error = NULL; clock_list *clock_ptr; oswordreadclock_utc_block utc; switch (*event) { case Event_EconetUserRPC: if (rpc == RPC_SEND_TIME && args [0] == 1) { if ((error = xosmodule_alloc (sizeof *clock_ptr, (void **) &clock_ptr)) != NULL) goto finish; utc.op = oswordreadclock_OP_UTC; if ((error = xoswordreadclock_utc (&utc)) != NULL) goto finish; memcpy (clock_ptr->clock, utc.utc, sizeof (os_date_and_time)); if ((error = xeconet_start_transmit (0, args [1], station, net, (byte *) &clock_ptr->clock, sizeof clock_ptr->clock, Reply_Count, Reply_Delay, &clock_ptr->tx, NULL)) != NULL) goto finish; /*Add the list to new record.*/ clock_ptr->next = Tx_List; Tx_List = clock_ptr; /*claim vector*/ *event = -1; } break; case Event_EconetTx: { econet_tx_cb tx = (econet_tx_cb) args; clock_list **t; for (t = &Tx_List; *t != NULL; t = &(*t)->next) if ((*t)->tx == tx) { /*Remove from the list*/ *t = (*t)->next; (void) xeconet_abandon_transmit (tx, NULL); (void) xosmodule_free ((byte *) *t); } /*claim vector*/ *event = -1; } break; } finish: return error; } --- NEW FILE: Ex2.c --- /*44 instructions*/ #include "oslib/colourtrans.h" #include "oslib/font.h" #include "oslib/os.h" #include "oslib/pdriver.h" void x (int page, char *t) { osbool more; os_box req; for (pdriver_draw_page (1, /* number of copies */ &req, /* plotting rectangle */ page, /* page sequence number */ NULL, /* page number */ NULL /* returned identification for rectangle */ ); more; xpdriver_get_rectangle (&req, &more, NULL) ) { colourtrans_set_gcol (os_COLOUR_BLACK, colourtrans_SET_FG, os_ACTION_OVERWRITE, NULL); font_paint (0, t, NONE, 0, 0, NULL, NULL, 0); } } --- NEW FILE: P3-433.c --- #include "oslib/font.h" char *move_string (int move) { static char S [5]; char *p = S; *p++ = font_COMMAND_YMOVE; *p++ = move; *p++ = move >> 8; *p++ = move >> 16; return S; } --- NEW FILE: AMUmakefile,fe1 --- # Makefile for OSLib # *********************************** # *** C h a n g e L i s t *** # *********************************** # Date Name Description # ---- ---- ----------- # 16-Aug-94 JC Created. # 05-Sep-94 AMcC Added Generic RISC OS Build rules # 27th Feb 1995 JC Added Macros headers # 21st Jun 1995 JRC Split into 4 pieces # 11th Apr 2001 TV Amended Include path # removed dynamic dependencies; they don't help # 07th Jul 2004 TV Modifications in line with current working LIBDIR = INCLUDE = -IC:,OSLib: # # Generic options: # MKDIR = cdir WIPE = wipe WFLAGS = ~c~v # # Program specific options: # COMPONENT = OSLib EXAMPLES = \ o.Ex0 \ o.Ex1 \ o.Ex2 \ o.HelloWorld \ o.p1-046 \ o.p1-053 \ o.p1-067 \ o.p1-068 \ o.p1-108 \ o.p1-109 \ o.p1-110 \ o.p1-219 \ o.p1-332 \ o.p1-334 \ o.p1-467 \ o.p1-606 \ o.p1-754 \ o.p1-833 \ o.p1-834 \ o.p2-042 \ o.p2-083 \ o.p2-099 \ o.p2-383 \ o.p2-413 \ o.p2-491 \ o.p2-492 \ o.p2-493 \ o.p2-524 \ o.p2-526 \ o.p2-589 \ o.p2-615 \ o.p2-616 \ o.p2-617 \ o.p2-618 \ o.p2-619 \ o.p2-625 \ o.p2-629 \ o.p2-632 \ o.p2-634 \ o.p2-636 \ o.p2-638 \ o.p2-691 \ o.p2-735 \ o.p2-740 \ o.p2-743 \ o.p3-018 \ o.p3-023 \ o.p3-024 \ o.p3-025 \ o.p3-063 \ o.p3-070 \ o.p3-072 \ o.p3-073 \ o.p3-162 \ o.p3-185 \ o.p3-198 \ o.p3-231 \ o.p3-246 \ o.p3-411 \ o.p3-421 \ o.p3-433 \ o.p3-469 \ o.p3-549 \ o.p3-659 \ o.p3-743 all: ${EXAMPLES} examples: ${EXAMPLES} clean: ;${WIPE} o.* ${WFLAGS} .SUFFIXES: .c .o .c.o:; cc -c -throwback ${INCLUDE} -wp -fc -D__swi -o $@ $< # Create $@ #Truncate file since we don't actually need it #------------------------------------------------------------------------ # Dynamic dependencies: --- NEW FILE: Ex0.c --- /*56 instructions*/ #include <kernel.h> #include "oslib/colourtrans.h" #include "oslib/font.h" #include "oslib/os.h" #include "oslib/pdriver.h" _kernel_oserror *x (int page, char *t) { osbool more; os_box req; _kernel_oserror *oserror = NULL; _kernel_swi_regs swi_regs; swi_regs.r [0] = 1; swi_regs.r [1] = (int) &req; swi_regs.r [2] = page; swi_regs.r [3] = (int) NULL; if ((oserror = _kernel_swi (PDriver_DrawPage, &swi_regs, &swi_regs)) != NULL) goto finish; while (more) { swi_regs.r [0] = os_COLOUR_BLACK; swi_regs.r [3] = colourtrans_SET_FG; swi_regs.r [4] = os_ACTION_OVERWRITE; if ((oserror = _kernel_swi (ColourTrans_SetGCOL, &swi_regs, &swi_regs)) != NULL) goto finish; swi_regs.r [1] = (int) t; swi_regs.r [2] = NONE; swi_regs.r [3] = 0; swi_regs.r [4] = 0; if ((oserror = _kernel_swi (Font_Paint, &swi_regs, &swi_regs)) != NULL) goto finish; swi_regs.r [1] = (int) &req; if ((oserror = _kernel_swi (PDriver_GetRectangle, &swi_regs, &swi_regs)) != NULL) goto finish; more = swi_regs.r [0]; } finish: return oserror; } --- NEW FILE: P3-007.c --- #include "oslib/os.h" #include "oslib/wimp.h" int main (void) { osboolfinished = FALSE; wimp_block blk; /*get the block for wimp_poll()*/ int event; wimp_initialise (...); /*tell the wimp about the task*/ while (!finished) { wimp_poll (... &blk ... &event); switch (event) { case wimp_NULL_REASON_CODE: /*... do Wimp_NullReasonCode ...*/ break; case wimp_REDRAW_WINDOW_REQUEST: /*... do Wimp_RedrawWindowRequest ...*/ break; /*etc*/ } } wimp_close_down (...); return 0; } --- NEW FILE: P2-524.c --- #include "oslib/osfscontrol.h" extern char *Filing_System_Name; os_error *select (void) { return xosfscontrol_select_fs ((osfscontrol_id) Filing_System_Name); } os_error *remove (void) { return xosfscontrol_remove_fs (Filing_System_Name); } --- NEW FILE: P2-099.c --- #include "oslib/osfscontrol.h" char *fts (int fti) { static char file_type [9]; osfscontrol_read_file_type (fti, (bits *) &file_type [0], (bits *) &file_type [4]); file_type [8] = '\0'; return file_type; } --- NEW FILE: !Make,fd7 --- Echo <sys$Time> Making <Obey$Dir> ... Dir <Obey$Dir> SetEval OSLib$Slot 3*1024/2 Do WIMPSlot -min <OSLib$Slot>K Do WIMPSlot -max <OSLib$Slot>K Do AMU -f <Obey$Dir>.AMUmakefile -desktop -k examples Echo <Sys$Time> Done. --- NEW FILE: GNUmakefile --- # Makefile for OSLib examples # *********************************** # *** C h a n g e L i s t *** # *********************************** # Date Name Description # ---- ---- ----------- # 16-Aug-94 JC Created. # 05-Sep-94 AMcC Added Generic RISC OS Build rules # 27th Feb 1995 JC Added Macros headers # 21st Jun 1995 JRC Split into 4 pieces # 11th Apr 2001 TV Amended Include path # removed dynamic dependencies; they don't help # 07th Jul 2004 TV new version renamed GNUmakefile for builfing under GNU/Unix #------------------------------------------------------------------------ # paths & directories LIBDIR = ../release/unix/OSLib/ CROSSPATH = /home/riscos/cross INCLUDE = -I${LIBDIR} #------------------------------------------------------------------------ # tools AS = ${CROSSPATH}/bin/gcc -xassembler -Wa,${ASOPTIONS} GCC = ${CROSSPATH}/bin/gcc GPP = ${CROSSPATH}/bin/g++ LD = ${CROSSPATH}/bin/gcc RM = rm -f EXAMPLES = \ Ex0 \ Ex1 \ Ex2 \ Helloworld \ P1-046 \ P1-053 \ P1-067 \ P1-068 \ P1-108 \ P1-109 \ P1-110 \ P1-219 \ P1-332 \ P1-334 \ P1-467 \ P1-606 \ P1-754 \ P1-833 \ P1-834 \ P2-042 \ P2-083 \ P2-099 \ P2-383 \ P2-413 \ P2-491 \ P2-492 \ P2-493 \ P2-524 \ P2-526 \ P2-589 \ P2-615 \ P2-616 \ P2-617 \ P2-618 \ P2-619 \ P2-625 \ P2-629 \ P2-632 \ P2-634 \ P2-636 \ P2-638 \ P2-691 \ P2-735 \ P2-740 \ P2-743 \ P3-018 \ P3-023 \ P3-024 \ P3-025 \ P3-063 \ P3-070 \ P3-072 \ P3-073 \ P3-162 \ P3-185 \ P3-198 \ P3-231 \ P3-246 \ P3-411 \ P3-421 \ P3-433 \ P3-469 \ P3-549 \ P3-659 \ P3-743 all: examples examples: $(addsuffix .o,${EXAMPLES} ) clean: ;${RM} $(addsuffix .o,${EXAMPLES} ) .SUFFIXES: .c .o .c.o: ;${GCC} -c ${INCLUDE} -D__swi -o $@ $< #------------------------------------------------------------------------ # Dynamic dependencies: --- NEW FILE: P3-246.c --- /*This is a version using OSLib rather than RISC_OSLib. It emits the '/' ("run") (referred to in the text), checks that the environment variable exists before it dereferences it, and checks for the string being empty.*/ #include <stdlib.h> #include "oslib/fileswitch.h" #include "oslib/macros.h" #include "oslib/os.h" #include "oslib/wimp.h" os_error *save_desktop (os_f handle) { char *ptr; os_error *error = NULL; if ((ptr = getenv ("Edit$Dir")) != NULL && !EMPTY (ptr)) { if ((error = xos_bput ('/', handle)) != NULL) goto finish; while (*ptr != '\0') if ((error = xos_bput (*ptr++, handle)) != NULL) goto finish; if ((error = xos_bput ('\n', handle)) != NULL) goto finish; } finish: return error; } --- NEW FILE: P2-492.c --- #include <kernel.h> #include "oslib/filer.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_StartedFiler: if (Task_Handle == (wimp_t) -1) Task_Handle = (wimp_t) 0; break; case Service_Reset: Task_Handle = (wimp_t) 0; break; } } --- NEW FILE: P2-616.c --- #include <stdio.h> #include "oslib/econet.h" extern econet_tx_cb Tx_Cb; void ex1 (void) { printf ("The final status was %d\n", econet_abandon_transmit (Tx_Cb)); } void ex2 (void) { byte buf [20]; printf ("The final status was %d\n", econet_do_transmit (NONE, 99, 7, 0, buf, sizeof buf, 6, 100, NULL)); } --- NEW FILE: P2-383.c --- #include <string.h> #include "oslib/os.h" #include "oslib/netfs.h" os_error *read_file_server_version (void) { os_error *error = NULL; int rx_count; netfs_read_version version; if ((error = xnetfs_do_fs_op (netfs_FS_OP_READ_VERSION, (netfs_op *) &version, 0, sizeof version, NULL, &rx_count)) != NULL) goto finish; version AS reply.version [rx_count] = '\0'; if ((error = xos_write0 (version AS reply.version)) != NULL) goto finish; if ((error = xos_new_line ()) != NULL) goto finish; finish: return error; } os_error *print_station_number_of_user (char *user) { os_error *error = NULL; os_station_number station_number; netfs_read_user_info user_info; char net_station [os_NET_STATION_LIMIT + 1]; strcpy (user_info AS request.user_name, user); user_info AS request.user_name [strlen (user_info AS request.user_name)] = '\r'; if ((error = xnetfs_do_fs_op (netfs_FS_OP_READ_USER_INFO, (netfs_op *) &user_info, 0, sizeof user_info, NULL, NULL)) != NULL) goto finish; station_number.net = user_info AS reply.net; station_number.station = user_info AS reply.station; if ((error = xos_convert_net_station (&station_number, net_station, os_NET_STATION_LIMIT, NULL)) != NULL) goto finish; if ((error = xos_write0 (net_station)) != NULL) goto finish; if ((error = xos_new_line ()) != NULL) goto finish; finish: return error; } --- NEW FILE: P2-629.c --- #include <stdio.h> #include <string.h> #include "oslib/econet.h" #include "oslib/os.h" extern byte Rx_Buffer [10]; extern byte Tx_Buffer [10]; extern byte Net_To_Test_For; void ex (void) { byte port; econet_rx_cb rx_cb; int status; port = econet_allocate_port (); rx_cb = econet_create_receive (port, 0, 0, Rx_Buffer, sizeof Rx_Buffer, NULL); strcpy ((char *) Tx_Buffer, "Bridge"); Tx_Buffer [6] = port; Tx_Buffer [7] = Net_To_Test_For; (void) econet_do_transmit (0x83u, 0x9Cu, 0xFFu, 0xFFu, Tx_Buffer, sizeof Tx_Buffer, 5, 5, NULL); status = econet_wait_for_reception (rx_cb, 10, FALSE, NULL, NULL, NULL, NULL, NULL, NULL); if (status == econet_STATUS_RECEIVED) printf ("Net number %d exists.\n", Net_To_Test_For); econet_de_allocate_port (port); } --- NEW FILE: P1-110.c --- #include "oslib/os.h" #include "oslib/osword.h" os_error *read_palette (os_gcol gcol, int entry_type, int on, int off) { os_error *error = NULL; osbool incomplete; osword_palette_block entry; if ((error = xpalettev_set_entry (gcol, entry_type, on, off, &incomplete)) != NULL) goto finish; if (incomplete) { entry.gcol = gcol; entry.colour_number = entry_type; entry.r = (on & os_R) >> os_RSHIFT; entry.g = (on & os_G) >> os_GSHIFT; entry.b = (on & os_B) >> os_BSHIFT; if ((error = xosword_write_palette (&entry)) != NULL) goto finish; } finish: return error; } --- NEW FILE: P1-219.c --- #include <kernel.h> #include "oslib/messagetrans.h" #include "oslib/os.h" static os_error Bad_Swi = {error_NO_SUCH_SWI, "BadSwi"}; extern char Module_Title []; _kernel_oserror *main_swi (int swi, _kernel_swi_regs *regs, void *workspace) { os_error *error = NULL; switch (swi) { case 0: break; case 1: break; /*... other cases as required ...*/ default: error = xmessagetrans_error_lookup (&Bad_Swi, NULL, NULL, 0, Module_Title, SKIP, SKIP, SKIP); goto finish; break; } finish: return (_kernel_oserror *) error; } --- NEW FILE: P2-638.c --- #include "oslib/econet.h" #include "oslib/macros.h" #include "oslib/os.h" #define ERROR_NUMBER_SYNTAX 1 #define ERROR_NUMBER_UNABLE_TO_DEFAULT 2 static os_error Error_Get_Regs_Syntax = {ERROR_NUMBER_SYNTAX, "Syntax: *Command <station number>"}; static os_error Error_Unable_To_Default = { ERROR_NUMBER_UNABLE_TO_DEFAULT, "Either a station number or a full network address is required" }; os_error *command_start (char *buf, byte *station_out, byte *net_out) { os_error *error = NULL; int station, net; /*must be int to detect -1 returns*/ if (EMPTY (buf)) { error = &Error_Get_Regs_Syntax; goto finish; } if ((error = xeconet_read_station_number (buf, NULL, &station, &net)) != NULL) goto finish; if (station == -1) { error = &Error_Unable_To_Default; goto finish; } if (net == -1) net = 0; *station_out = (byte) station; /*narrowing cast*/ *net_out = (byte) net; finish: return error; } --- NEW FILE: P2-493.c --- #include <kernel.h> #include "oslib/filer.h" #include "oslib/wimp.h" extern wimp_t Task_Handle; /*This is a CMHG-style service entry point.*/ void main_service (int service, _kernel_swi_regs *regs, void *workspace) { switch (service) { case Service_FilerDying: if (!(Task_Handle == (wimp_t) 0 || Task_Handle == (wimp_t) -1)) (void) xwimp_close_down (Task_Handle); Task_Handle = 0; break; } } --- NEW FILE: P1-067.c --- #include "oslib/os.h" #include "oslib/osbyte.h" extern void My_Byte_Veneer (void); void ex (void) { os_claim (ByteV, (void *) &My_Byte_Veneer, NULL); } --- NEW FILE: !Agenda,fd7 --- Echo Making <Obey$Dir> ... Dir <Obey$Dir> SetEval OSLib$Slot 3*1024/2 Do WIMPSlot -min <OSLib$Slot>K Do WIMPSlot -max <OSLib$Slot>K Do AMU -f <Obey$Dir>.AMUmakefile -desktop -n examples --- NEW FILE: P1-068.c --- #include "oslib/os.h" #include "oslib/osbyte.h" extern void My_Byte_Veneer (void); void ex (void) { os_release (ByteV, (void *) &My_Byte_Veneer, NULL); } --- NEW FILE: P3-185.c --- #include "oslib/os.h" extern os_t Old_Time; void ex (void) { Old_Time += 100*((os_read_monotonic_time () - Old_Time - 1)/100 + 1); } --- NEW FILE: P3-231.c --- #include "oslib/os.h" #include "oslib/wimp.h" #define EXIT 6 /*position in Task Manager menu of Exit entry*/ extern wimp_block *Block; extern wimp_t Quit_Sender; extern wimp_message Pre_Quit_Block, Quit_Block; extern int Event, Pre_Quit_Ref, Quit_Ref; extern void Quit (void); void ex1 (void) { wimp_get_caret_position (&Block->caret); Block->key.c = wimp_KEY_SHIFT | wimp_KEY_CONTROL | wimp_KEY_F12; wimp_send_message (wimp_KEY_PRESSED, &Block->message, Quit_Sender); } void ex2 (void) { switch (Event) { case wimp_MENU_SELECTION: if (Block->selection.items [0] == EXIT) { wimp_send_message (wimp_USER_MESSAGE_RECORDED, &Pre_Quit_Block, wimp_BROADCAST); Pre_Quit_Ref = Pre_Quit_Block.my_ref; } break; case wimp_USER_MESSAGE_ACKNOWLEDGE: if (Block->message.my_ref == Pre_Quit_Ref) { wimp_send_message (wimp_USER_MESSAGE_RECORDED, &Quit_Block, wimp_BROADCAST); Quit_Ref = Quit_Block.my_ref; } else if (Block->message.action == message_QUIT && Block->message.my_ref == Quit_Ref) Quit (); break; case wimp_USER_MESSAGE: case wimp_USER_MESSAGE_RECORDED: if (Block->message.action == message_QUIT && Block->message.my_ref != Quit_Ref) Quit (); break; } } --- NEW FILE: P3-162.c --- #include "oslib/wimp.h" #define ICON_COUNT 12 void ex (wimp_w w) { wimp_i icons [ICON_COUNT]; wimp_which_icon (w, icons, wimp_ICON_SELECTED, wimp_ICON_SELECTED); /*|icons| contains all selected icons*/ wimp_which_icon (w, icons, wimp_ICON_ESG | wimp_ICON_SELECTED, 1 << wimp_ICON_ESG_SHIFT | wimp_ICON_SELECTED); /*|icons| contains selected icons with E S G 1*/ } --- NEW FILE: P2-636.c --- #include "oslib/econet.h" #include "oslib/os.h" extern byte Buffer [40]; static os_error *print_version (byte *); os_error *report_station_version (byte station, byte net) { os_error *error = NULL; int status; static os_error Error; if ((error = xeconet_do_immediate (econet_IMMEDIATE_MACHINE_PEEK, SKIP, station, net, Buffer, sizeof Buffer, 40, 5, &status, NULL)) != NULL) goto finish; if (status == econet_STATUS_TRANSMITTED) print_version (Buffer); else if (status == econet_STATUS_NOT_LISTENING) status = econet_STATUS_NOT_PRESENT; if ((error = xeconet_convert_status_to_error (status, &Error, sizeof Error, station, net)) != NULL) goto finish; error = &Error; finish: return error; } os_error *print_version (byte *buf) { os_error *error = NULL; if ((error = xos_convert_hex2 (buf [3], (char *) Buffer, sizeof Buffer, NULL)) != NULL) goto finish; if ((error = xos_write0 ((char *) Buffer)) != NULL) goto finish; if ((error = xos_writec ('.')) != NULL) goto finish; if ((error = xos_convert_hex2 (buf [2], (char *) Buffer, sizeof Buffer, NULL)) != NULL) goto finish; if ((error = xos_write0 ((char *) Buffer)) != NULL) goto finish; finish: return error; } |