Providers
Debian Linux
System76
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Grokipedia
Open Directory Project
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
nukeit.c
#include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <unistd.h> #include <string.h> #include <math.h> #include <ctype.h> #include "nukeit.h" enum {false, true }; void help(void) { puts("nukeit - provides time for low power microwave given instructions"); puts("for cooking with high power microwave.\n"); puts("Usage: nukeit [-i wattage] [-o wattage] [min [sec]]"); puts(" nukeit [-i wattage] [-o wattage] [min:sec]\n"); puts("(Defaults: 1100W->700W)\n"); puts("Compiled : " __DATE__); puts("Config File: " CONFIG_FILE ); puts(COPYRIGHT); return; } void version(void) { puts("NukeIt - Version " VERSION); puts("Compiled : " __DATE__); puts("Config File: " CONFIG_FILE ); puts(COPYRIGHT); return; } int spit_config(void) { /* return true if successful, false if unable to write the config. */ FILE *fp; if (fp=fopen(CONFIG_FILE, "w")) { /* We will assume that if we can open the file for writing that we will suceed. */ fprintf(fp, "# Michael J. Chappell\n"); fprintf(fp, "# NUKEITRC\n"); fprintf(fp, "\n"); fprintf(fp, "# HP=(High Wattage Microwave)\n"); fprintf(fp, "# LP=(Low Wattage Microwave)\n"); fprintf(fp, "HP=1100W\n"); fprintf(fp, "LP=700W\n"); fclose(fp); return true; } else { return false; } } float get_hp_wattage(FILE *fp) { float wattage = DEFAULT_HP_POWER; char *buffer; size_t s; char *pchar; int comment; if (fp) { rewind(fp); while (getline(&buffer, &s, fp)>-1) { comment = false; if (*buffer == '#') { comment = true; } if (!comment && (pchar = strstr(buffer, "HP="))) { pchar+=3; wattage = strtod(pchar, NULL); } free(buffer); /* getline() requires s=0 and buffer=NULL for our use here */ buffer = NULL; s = 0; } free(buffer); } return wattage; } float get_lp_wattage(FILE *fp) { float wattage = DEFAULT_LP_POWER; char *buffer; size_t s; char *pchar; int comment; if (fp) { rewind(fp); while (getline(&buffer, &s, fp)>-1) { comment = false; if (*buffer == '#') { comment = true; } if (!comment && (pchar = strstr(buffer, "LP="))) { pchar+=3; wattage = strtod(pchar, NULL); } free(buffer); /* getline() requires s=0 and buffer=NULL for our use here */ buffer = NULL; s = 0; } free(buffer); } return wattage; } int main(int argc, char **argv) { int hp_minutes=0, hp_seconds=0; int lp_minutes=0, lp_seconds=0; float hp_time=0.0, lp_time=0.0; float hp_power; float lp_power; char *ptr; int colon = false; FILE *fconfig; chdir(getenv("HOME")); if (fconfig = fopen(CONFIG_FILE, "r")) { hp_power = get_hp_wattage(fconfig); lp_power = get_lp_wattage(fconfig); fclose(fconfig); } else { fprintf(stderr, "No config file found (%s)\n", CONFIG_FILE); hp_power = DEFAULT_HP_POWER; lp_power = DEFAULT_LP_POWER; } /* Added for getopt */ int c; int index; opterr=0; char *hp_arg = NULL; char *lp_arg = NULL; while ((c = getopt (argc, argv, "cChHvVI:i:O:o:")) != -1) { switch (c) { case 'c': case 'C': if (spit_config()) { puts(CONFIG_FILE " written."); return EXIT_SUCCESS; } else { puts("Write to " CONFIG_FILE " failed."); return EXIT_FAILURE; } break; case 'i': case 'I': hp_arg = optarg; hp_power = (float)strtol(hp_arg, NULL, 10); break; case 'o': case 'O': lp_arg = optarg; lp_power = (float)strtol(lp_arg, NULL, 10); break; case 'h': case 'H': help(); return EXIT_SUCCESS; case 'v': case 'V': version(); return EXIT_SUCCESS; case '?': help(); return EXIT_FAILURE; } } /* printf("***\t argc: %d\toptind: %d\t***\n", argc, optind); */ index = optind; if (argc==index) { /* Request time from user */ printf("Input minutes and seconds in format M:S\n"); scanf("%d:%d", &hp_minutes, &hp_seconds); hp_time = 60*hp_minutes+hp_seconds; } else if (argc==(index+2)) { /* Minutes and seconds are separate arguments */ hp_minutes = atoi(argv[index]); hp_seconds = atoi(argv[index+1]); hp_time = 60*hp_minutes+hp_seconds; } else if (argc==(index+1)) { /* Minutes or Minutes:Seconds in one argument */ /* Minutes may be fractional */ hp_time = 60*atof(argv[index]); hp_minutes = (int)floor(hp_time/60); hp_seconds = (int)floor(hp_time-60*hp_minutes); /* Seconds are 0 unless we find a ':' */ ptr=argv[index]; while (*ptr) { if (*ptr++==':') { colon = true; break; } } if (colon) { hp_seconds = atoi(ptr); } else { hp_seconds = 0; } hp_time = hp_time+hp_seconds; } else { /* More than 2 arguments is incorrect usage */ help(); return EXIT_FAILURE; } if (hp_time<=0.0) { /* Time must be positive */ puts("Time must be greater than zero!"); return EXIT_FAILURE; } if ((hp_power<=0.0)||(lp_power<=0.0)) { puts("Wattage must be greater than zero!"); return EXIT_FAILURE; } /* Normalize the input time */ hp_time = floor(hp_time); hp_minutes = (int)hp_time/60; hp_seconds = (int)hp_time-60*hp_minutes; /* We should round the seconds as appropriate */ lp_time = hp_time*hp_power/lp_power+0.5; /* Normalize the output time */ lp_time = floor(lp_time); lp_minutes = (int)lp_time/60; lp_seconds = (int)lp_time-60*lp_minutes; printf("NukeIt - Microwave Times:\n"); printf("%4.0fW: %d:%02d (%2.4f minutes)\n", hp_power, hp_minutes, hp_seconds, hp_time/60); printf("%4.0fW: %d:%02d (%2.4f minutes)\n", lp_power, lp_minutes, lp_seconds, lp_time/60); return EXIT_SUCCESS; }
This source has been viewed 2 times.
Wednesday, 12 August 2026
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org