void flush(void) { int i; Char c, a; nanchors = 0; for(i=0; i<nchars; i++){ c = chars[i]; if(c == Estring){ /* next word is string to print */ iputs(&bout, (char*)chars[++i]); continue; } if(c == Epp){ iputrune(&bout, '\n'); iputs(&bout, TABLE "<tr height=5><td></table>"); iputrune(&bout, '\n'); continue; } a = c & ~0xFFFF; c &= 0xFFFF; /* * If we're going to something off after a space, * let's just turn it off before. */ if(c == ' ' && i<nchars-1 && (chars[i+1]&0xFFFF) >= 32) a ^= a & ~chars[i+1]; setattr(a); iputrune(&bout, c & 0xFFFF); } }
void prog7() { iputs("Hello there", 10); iputs("This will be indented 10 spaces by default"); iputs("This will be indented 5 spaces", 5); iputs("This is not indented", 0); }
void setattr(Char a) { Char on, off; int i, j; on = a & ~attr; off = attr & ~a; /* walk up the nest stack until we reach something we need to turn off. */ for(i=0; i<nnest; i++) if(off&(1<<nest[i])) break; /* turn off everything above that */ for(j=nnest-1; j>=i; j--) iputs(&bout, offattr[nest[j]]); /* turn on everything we just turned off but didn't want to */ for(j=i; j<nnest; j++) if(a&(1<<nest[j])) iputs(&bout, onattr[nest[j]]); else nest[j] = 0; /* shift the zeros (turned off things) up */ for(i=j=0; i<nnest; i++) if(nest[i] != 0) nest[j++] = nest[i]; nnest = j; /* now turn on the new attributes */ for(i=0; i<nelem(attrorder); i++){ j = attrorder[i]; if(on&(1<<j)){ if(j == Anchor) onattr[j] = anchors[nanchors++]; iputs(&bout, onattr[j]); if(nnest >= nelem(nest)) sysfatal("nesting too deep"); nest[nnest++] = j; } } attr = a; }
static int checkNodeListParms(IonParms *parms, char *wdName, unsigned long nodeNbr) { char *nodeListDir; char nodeListFileName[265]; int nodeListFile; int lineNbr = 0; int lineLen; char lineBuf[256]; unsigned long lineNodeNbr; int lineWmKey; char lineSdrName[MAX_SDR_NAME + 1]; char lineWdName[256]; int result; nodeListDir = getenv("ION_NODE_LIST_DIR"); if (nodeListDir == NULL) /* Single node on machine. */ { if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->wmKey != ION_DEFAULT_SM_KEY) { putErrmsg("Config parms wmKey != default.", itoa(ION_DEFAULT_SM_KEY)); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } if (strcmp(parms->sdrName, ION_DEFAULT_SDR_NAME) != 0) { putErrmsg("Config parms sdrName != default.", ION_DEFAULT_SDR_NAME); return -1; } return 0; } /* Configured for multi-node operation. */ isprintf(nodeListFileName, sizeof nodeListFileName, "%.255s%cion_nodes", nodeListDir, ION_PATH_DELIMITER); if (nodeNbr == 0) /* Just attaching. */ { nodeListFile = open(nodeListFileName, O_RDONLY, 0); } else /* Initializing the node. */ { nodeListFile = open(nodeListFileName, O_RDWR | O_CREAT, 00666); } if (nodeListFile < 0) { putSysErrmsg("Can't open ion_nodes file", nodeListFileName); writeMemo("[?] Remove ION_NODE_LIST_DIR from env?"); return -1; } while (1) { if (igets(nodeListFile, lineBuf, sizeof lineBuf, &lineLen) == NULL) { if (lineLen < 0) { close(nodeListFile); putErrmsg("Failed reading ion_nodes file.", nodeListFileName); return -1; } break; /* End of file. */ } lineNbr++; if (sscanf(lineBuf, "%lu %d %31s %255s", &lineNodeNbr, &lineWmKey, lineSdrName, lineWdName) < 4) { close(nodeListFile); putErrmsg("Syntax error at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (lineNodeNbr == nodeNbr) /* Match. */ { /* lineNodeNbr can't be zero (we never * write such lines to the file), so this * must be matching non-zero node numbers. * So we are re-initializing this node. */ close(nodeListFile); if (strcmp(lineWdName, wdName) != 0) { putErrmsg("CWD conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->wmKey == 0) { parms->wmKey = lineWmKey; } if (parms->wmKey != lineWmKey) { putErrmsg("WmKey conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, lineSdrName, sizeof parms->sdrName); } if (strcmp(parms->sdrName, lineSdrName) != 0) { putErrmsg("SdrName conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } return 0; } /* lineNodeNbr does not match nodeNbr (which may * be zero). */ if (strcmp(lineWdName, wdName) == 0) /* Match. */ { close(nodeListFile); if (nodeNbr == 0) /* Attaching. */ { parms->wmKey = lineWmKey; istrcpy(parms->sdrName, lineSdrName, MAX_SDR_NAME + 1); return 0; } /* Reinitialization conflict. */ putErrmsg("NodeNbr conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } /* Haven't found matching line yet. Continue. */ } /* No matching lines in file. */ if (nodeNbr == 0) /* Attaching to existing node. */ { close(nodeListFile); putErrmsg("No node has been initialized in this directory.", wdName); return -1; } /* Initializing, so append line to the nodes list file. */ if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } isprintf(lineBuf, sizeof lineBuf, "%lu %d %.31s %.255s\n", nodeNbr, parms->wmKey, parms->sdrName, wdName); result = iputs(nodeListFile, lineBuf); close(nodeListFile); if (result < 0) { putErrmsg("Failed writing to ion_nodes file.", NULL); return -1; } return 0; }
static void createIonConfigFiles() { uvast nodenbr = ION_NODE_NBR; char filenamebuf[80]; int fd; char *ionconfigLines[] = { "wmSize 300000\n", "configFlags 1\n", "heapWords 75000\n", "pathName /ion\n", }; int ionconfigLineCount = sizeof ionconfigLines / sizeof (char *); char *globalLines[] = { "a contact +0 +7200 19 19 100000\n" }; int globalLineCount = sizeof globalLines / sizeof (char *); char *ionsecrcLines[] = { "1\n", "a bspbabrule ipn:19.* ipn:19.* '' ''\n" }; int ionsecrcLineCount = sizeof ionsecrcLines / sizeof (char *); char *ltprcLines[] = { "1 20 64000\n", "a span 19 4 4000 4 4000 1084 2048 1 'pmqlso /ionpmq.19'\n", "w 1\n", "s 'pmqlsi /ionpmq.19'\n" }; int ltprcLineCount = sizeof ltprcLines / sizeof (char *); char *bprcLines[] = { "1\n", "a scheme ipn 'ipnfw' 'ipnadminep'\n", "a endpoint ipn:19.0 x\n", "a endpoint ipn:19.1 x\n", "a endpoint ipn:19.2 x\n", "a endpoint ipn:19.64 x\n", "a endpoint ipn:19.65 x\n", "a endpoint ipn:19.126 x\n", "a endpoint ipn:19.127 x\n", "a protocol ltp 1400 100\n", "a induct ltp 19 ltpcli\n", "a outduct ltp 19 ltpclo\n", "w 1\n" }; int bprcLineCount = sizeof bprcLines / sizeof (char *); char *ipnrcLines[] = { "a plan 19 ltp/19\n" }; int ipnrcLineCount = sizeof ipnrcLines / sizeof (char *); char linebuf[255]; char **line; int i; /* Keep all ION configuration files in one directory. */ if (mkdir("/ion", 0777) < 0) { perror("Can't create directory for config files"); return; } /* Create ionconfig file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionconfig", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionconfig file '%s'.\n", filenamebuf); return; } for (i = 0, line = ionconfigLines; i < ionconfigLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ionrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionrc file '%s'.\n", filenamebuf); return; } isprintf(linebuf, sizeof linebuf, "1 " UVAST_FIELDSPEC " /ion/node" UVAST_FIELDSPEC ".ionconfig\ns\n", nodenbr, nodenbr); oK(iputs(fd, linebuf)); close(fd); /* Create global.ionrc file. */ istrcpy(filenamebuf, "/ion/global.ionrc", sizeof filenamebuf); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create global.ionrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = globalLines; i < globalLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ionsecrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionsecrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionsecrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ionsecrcLines; i < ionsecrcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ltprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ltprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ltprc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ltprcLines; i < ltprcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ipnrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ipnrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ipnrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ipnrcLines; i < ipnrcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create bprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".bprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .bprc file '%s'.\n", filenamebuf); return; } for (i = 0, line = bprcLines; i < bprcLineCount; line++, i++) { oK(iputs(fd, *line)); } isprintf(linebuf, sizeof linebuf, "r 'ipnadmin /ion/node" UVAST_FIELDSPEC ".ipnrc'\ns\n", nodenbr); oK(iputs(fd, linebuf)); close(fd); #ifndef NASA_PROTECTED_FLIGHT_CODE /* Create cfdprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".cfdprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .cfdprc file '%s'.\n", filenamebuf); return; } oK(iputs(fd, "1\ns bputa\n")); close(fd); #endif }
int main(int argc, char **argv) #endif { char *wmspace; int wmid; PsmPartition wm = NULL; PsmMgtOutcome outcome; PsmAddress testlist; sm_SemId semaphore; int cycleNbr = 1; char fileName[256]; int outputFile; PsmAddress lineListElt; PsmAddress lineAddress; char *line; if (sm_ipc_init() < 0) { return 0; } if (sm_ShmAttach(0x1108, 10000000, &wmspace, &wmid) < 0) { PERROR("can't attach to shared memory"); return 0; } if (psm_manage(wmspace, 10000000, "file2sm", &wm, &outcome) < 0 || outcome == Refused) { PUTS("can't manage shared memory"); return 0; } testlist = psm_get_root(wm); if (testlist == 0) { testlist = sm_list_create(wm); if (testlist == 0) { PUTS("can't create shared memory list"); return 0; } psm_set_root(wm, testlist); } semaphore = sm_SemCreate(0x1101, SM_SEM_FIFO); if (semaphore < 0) { PUTS("can't create semaphore"); return 0; } PUTMEMO("Working on cycle", utoa(cycleNbr)); isprintf(fileName, sizeof fileName, "file_copy_%d", cycleNbr); outputFile = iopen(fileName, O_WRONLY | O_APPEND, 0666); if (outputFile < 0) { PERROR("can't open output file"); return 0; } while (1) { while (sm_list_length(wm, testlist) == 0) { sm_SemTake(semaphore); /* Wait for line. */ } lineListElt = sm_list_first(wm, testlist); lineAddress = sm_list_data(wm, lineListElt); line = psp(wm, lineAddress); /* Process text of line. */ if (strcmp(line, "*** End of the file ***\n") == 0) { /* Close file, open next one. */ close(outputFile); cycleNbr++; PUTMEMO("Working on cycle", utoa(cycleNbr)); isprintf(fileName, sizeof fileName, "file_copy_%d", cycleNbr); outputFile = iopen(fileName, O_WRONLY | O_APPEND, 0666); if (outputFile < 0) { PERROR("Can't open output file"); return 0; } } else /* Just write line to output file. */ { if (iputs(outputFile, line) < 0) { close(outputFile); PERROR("Can't write to output file"); return 0; } } /* Delete line from shared memory list. */ psm_free(wm, lineAddress); CHKZERO(sm_list_delete(wm, lineListElt, (SmListDeleteFn) NULL, NULL) == 0); } }