home *** CD-ROM | disk | FTP | other *** search
- /*
- MCPBlankerOff by Leo Davidson
- A simple program written in ANSI C (but uses ReadArgs()) to control the
- state of MCP's screen blanker and dimmer (i.e. turn them on and off).
-
- $VER: MCPBlankerOff.c 1.1 (24.8.96)
-
- Public Domain.
- */
-
- #include <string.h>
- #include <stdio.h>
- #include <dos/dos.h>
- #include <proto/dos.h>
-
-
- // Version strings must be double null-terminated.
- static char Version[] = "$VER: MCPBlankerOff 1.1 (25.8.96)\0";
-
-
-
- // ReadArgs() commandline stuff
- char CommandTemplate[] = "ON/S,OFF/S,DIMMER/S";
- enum CmdTmpArgs {ARG_ON,ARG_OFF,ARG_DIMMER,ARG_TOTAL};
- LONG args[ARG_TOTAL];
- #define args_on (BOOL)args[ARG_ON]
- #define args_off (BOOL)args[ARG_OFF]
- #define args_dim (BOOL)args[ARG_DIMMER]
-
- #define CONFNAME "Env:MCP/MCP.Config"
- #define TEMPNAME "Env:MCP/MCP.Config.mcpblankeroff"
-
- extern struct Library *SysBase;
-
- #define BUFFERSIZE 1024
- char buffer[BUFFERSIZE];
-
- char blankerstr[] = "BLANKER=";
- char dimmerstr[] = "DIMMER=";
- #define blankerstr_len sizeof(blankerstr)/sizeof(char)
- #define dimmerstr_len sizeof(dimmerstr)/sizeof(char)
- #define NEWSTRING_ON "BLANKER=ON\n"
- #define NEWSTRING_OFF "BLANKER=OFF\n"
- #define NEWSTRINGD_ON "DIMMER=ON\n"
- #define NEWSTRINGD_OFF "DIMMER=OFF\n"
-
-
- ULONG main(void)
- {
- struct RDArgs *rda;
- FILE *infile;
- FILE *outfile;
-
- ULONG main_rc = RETURN_FAIL;
-
- if (!(rda = ReadArgs(CommandTemplate,args,NULL)))
- PrintFault(IoErr(),"MCPBlankerOff");
- else
- {
- if ( (args_on && args_off) || !(args_on || args_off) )
- printf("MCPBlankerOff: You must specify either \"on\" or \"off\".\n");
-
- else if ( rename(CONFNAME,TEMPNAME) )
- printf("MCPBlankerOff: Couldn't find MCP config file.\n");
-
- else if (! (infile = fopen(TEMPNAME,"r")) )
- printf("MCPBlankerOff: Couldn't find MCP config file.\n");
- else
- {
- if (! (outfile = fopen(CONFNAME,"w")) )
- {
- printf("MCPBlankerOff: Couldn't write new config file.\n");
- rename(TEMPNAME,CONFNAME);
- }
- else
- {
- while ( fgets(buffer,BUFFERSIZE,infile) )
- {
- if ( strncmp(buffer,blankerstr,blankerstr_len - 1) )
- {
- if ( (!args_dim) || \
- (strncmp(buffer,dimmerstr,dimmerstr_len - 1)) )
- fputs(buffer,outfile);
- else if (args_on)
- fputs(NEWSTRINGD_ON,outfile);
- else
- fputs(NEWSTRINGD_OFF,outfile);
- }
- else if (args_on)
- fputs(NEWSTRING_ON,outfile);
- else
- fputs(NEWSTRING_OFF,outfile);
- }
- fclose(outfile);
-
- if (! (feof(infile)) )
- {
- fclose(infile);
- printf("MCPBlankerOff: Error creating new config file.\n");
- remove(CONFNAME);
- rename(TEMPNAME,CONFNAME);
- }
- else
- {
- fclose(infile);
- remove(TEMPNAME);
- main_rc = RETURN_OK;
- }
- }
- if (infile)
- fclose(infile);
- }
- }
-
- return main_rc;
-
- }
-