int main(int argc, char* argv[]){ if(argc!=2){ printf("Usage is makeLEDC and one of:\n"); printf(" on, off, flash or status\n"); printf(" e.g. makeLED flash\n"); return 2; } printf("Starting the makeLED program\n"); printf("The current LED Path is: " LED3_PATH "\n"); // select whether command is on, off, flash or status if(strcmp(argv[1],"on")==0){ printf("Turning the LED on\n"); removeTrigger(); writeLED("/brightness", "1"); } else if (strcmp(argv[1],"off")==0){ printf("Turning the LED off\n"); removeTrigger(); writeLED("/brightness", "0"); } else if (strcmp(argv[1],"flash")==0){ printf("Flashing the LED\n"); writeLED("/trigger", "timer"); writeLED("/delay_on", "50"); writeLED("/delay_off", "50"); } else if (strcmp(argv[1],"status")==0){ FILE* fp; // see writeLED function below for description char fullFileName[100]; char line[80]; sprintf(fullFileName, LED3_PATH "/trigger"); fp = fopen(fullFileName, "rt"); //reading text this time while (fgets(line, 80, fp) != NULL){ printf("%s", line); } fclose(fp); } else{ printf("Invalid command!\n"); } printf("Finished the makeLED Program\n"); return 0; }
int main (int argc, char *argv[]){ // puts (argv[0]); it's ./LED if (argc != 2){ printf("Error : wrong usage\n"); printf("./BashLED.sh followed by one of these cmd...\n-on\n-off\n-flash\n-status\ne.g. ./LED on\n"); exit(-1); } if (strcmp(argv[1], "on") == 0){ printf("turn on LED\n"); removeTrigger(); writeLedFile("brightness","1"); } else if (strcmp(argv[1], "off") == 0){ printf("turn off LED\n"); removeTrigger(); writeLedFile("brightness","0"); } else if (strcmp(argv[1], "flash") == 0){ printf("flash LED\n"); writeLedFile("trigger","timer"); writeLedFile("delay_on","50"); writeLedFile("delay_off","50"); } else if (strcmp(argv[1], "status") == 0){ printf("return status of LED\n"); readLedFile("trigger"); } else{ printf("Error:invalid cmd! argv[1]=%s\n", argv[1]); exit(2); } printf("job is done\n"); return 0; }
int patchEntities(double versionFile, char *mapName) { char patchFile[MAX_PATH_LENGTH], *line, *savePtr, itemName[MAX_VALUE_LENGTH]; char key[MAX_VALUE_LENGTH], value[MAX_VALUE_LENGTH]; int skipping = FALSE, x, y, read, found, saveMap; unsigned char *buffer; Entity *e; EntityList *el, *entities; Target *t; savePtr = NULL; snprintf(patchFile, sizeof(patchFile), "data/patch/%0.2f.dat", versionFile); saveMap = TRUE; if (existsInPak(patchFile) == TRUE) { buffer = loadFileFromPak(patchFile); line = strtok_r((char *)buffer, "\n", &savePtr); while (line != NULL) { if (line[strlen(line) - 1] == '\n') { line[strlen(line) - 1] = '\0'; } if (line[strlen(line) - 1] == '\r') { line[strlen(line) - 1] = '\0'; } sscanf(line, "%s", itemName); if (strcmpignorecase(itemName, "MAP_NAME") == 0) { sscanf(line, "%*s %s\n", itemName); skipping = strcmpignorecase(itemName, mapName) == 0 ? FALSE : TRUE; } else if (strcmpignorecase(itemName, "MODIFY_OBJECTIVE") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\" \"%[^\"]\"", key, value); modifyObjective(key, value); } else if (strcmpignorecase(itemName, "REMOVE_OBJECTIVE") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\"", key); removeObjective(key); } else if (strcmpignorecase(itemName, "REMOVE_TRIGGER") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\"", key); removeGlobalTrigger(key); removeTrigger(key); } else if (strcmpignorecase(line, "ADD_ENTITY") == 0 && skipping == FALSE) { loadResources(savePtr); } else if (strcmpignorecase(itemName, "REMOVE_ENTITY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %s %d %d", itemName, &x, &y); found = FALSE; e = getEntityByObjectiveName(itemName); if (e != NULL) { e->inUse = FALSE; found = TRUE; } if (found == FALSE) { t = getTargetByName(itemName); if (t != NULL) { t->active = FALSE; found = TRUE; } } if (found == FALSE && read == 3) { e = getEntityByStartXY(x, y); if (e != NULL) { e->inUse = FALSE; found = TRUE; } } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %s %s %s", itemName, key, value); if (strcmpignorecase(itemName, "PLAYER") == 0) { e = &player; } else { e = getEntityByObjectiveName(itemName); } if (e != NULL) { if (strcmpignorecase(value, "NULL") == 0) { STRNCPY(value, "", sizeof(value)); } setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY_BY_START") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d %s %[^\n]s", &x, &y, key, value); e = getEntityByStartXY(x, y); if (e != NULL) { setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY_BY_XY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d %s %[^\n]s", &x, &y, key, value); e = getEntityByXY(x, y); if (e != NULL) { setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "TRANSLATE_ENTITIES") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d", &x, &y); entities = getEntities(); player.x -= x; player.y -= y; for (el=entities->next;el!=NULL;el=el->next) { e = el->entity; e->x -= x; e->y -= y; if (e->startX - x > 0) { e->startX -= x; } if (e->startY - y > 0) { e->startY -= y; } if (e->endX - x > 0) { e->endX -= x; } if (e->endY - y > 0) { e->endY -= y; } } t = getTargets(); for (x=0;x<MAX_TARGETS;x++) { if (t[x].active == TRUE) { if (t[x].x - x > 0) { t[x].x -= x; } if (t[x].y - y > 0) { t[x].y -= y; } } } } else if (strcmpignorecase(itemName, "RENAME_MAP") == 0 && skipping == FALSE) { saveMap = FALSE; } line = strtok_r(NULL, "\n", &savePtr); } free(buffer); } return saveMap; }
vector<PTrigger> Square::removeTriggers() { vector<PTrigger> ret; for (Trigger* t : extractRefs(triggers)) ret.push_back(removeTrigger(t)); return ret; }
Trigger::~Trigger() { removeTrigger(this); delete _internals; }