/****************************************************************************** Program: Reboot File: reboot.c Description: Utility to reboot the system. Author: Francis G. Loch (fgl) Environment: StormC 3.0, 68040 @25MHz, 66mb RAM, AmigaOS 3.5. Notes: This program is still under development. Revisions: 2.0 (fgl) Program converted from Blitz Basic to C. 2.1 (fgl) Reboot can now be invoked from the CLI with an optional delay. Known bugs: Can sometimes cause the system to hang when started from WBStartup. ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include extern struct Library *SysBase; struct Library *IntuitionBase; struct Library *WorkbenchBase; struct EasyStruct reboot_req = { sizeof (struct EasyStruct), 0, "Reboot V2.1b - Copyright © 2000 Francis G. Loch", "Warning: reboot system?\n\nThis will cause all unsaved data to be lost!", "Reboot|Cancel", }; void ask_reboot() { LONG reply; reply = EasyRequest(NULL, &reboot_req, NULL, NULL, NULL); if (reply == 1) { ColdReboot(); } } /* Function: compare_string(s, t) Purpose: Compares two strings and returns NULL if they are identical. This function was created to decrease the size of the executable instead of using strcmp. */ int compare_string(register char *s, register char *t) { while (*s == *t) { if (!*s) return 0; /* End reached (*s == 0) */ s++; t++; } return (*s - *t); } void wbmain(struct WBStartup * argmsg) { struct MsgPort *myport = NULL; struct AppMenuItem *appitem = NULL; struct AppMessage *appmsg = NULL; BOOL quit = NULL; if (IntuitionBase = OpenLibrary("intuition.library",37)) { if (WorkbenchBase = OpenLibrary("workbench.library",37)) { if (myport = CreateMsgPort()) { appitem = AddAppMenuItemA(0L, NULL, "Reboot system", myport, NULL); if (appitem) { while (quit == NULL) { WaitPort(myport); while((appmsg = (struct AppMessage *) GetMsg(myport))) { ask_reboot(); } } } DeleteMsgPort(myport); } CloseLibrary(WorkbenchBase); } CloseLibrary(IntuitionBase); } } void main(int argc, char *argv[]) { int duration; if (argc > 1) { if (compare_string(argv[1], "?") == NULL) { PutStr("REBOOT V2.1 (beta release) - Copyright © 2000 Francis G. Loch\n\n"); PutStr("Usage from CLI: Reboot [delay]\n\n"); } else { duration = atoi(argv[1]) * 50; Delay(duration); ColdReboot(); } } else { ColdReboot(); } }