static int NextLinkPos(int line, int nr) { char* linetxt; int linkcntr = 0; linetxt = GetHelpLine(line); while (*linetxt) { if (IsHlpReference(linetxt)) { if (linkcntr++ == nr) return linkcntr; else linetxt = PassHlpReferencePart(linetxt); } else if (IsFullLine(linetxt)) linetxt = PassHlpFullLinePart(linetxt); else if (IsHlpAsciiChar(linetxt)) linetxt = PassHlpAsciiChar(linetxt); else if (IsCenterOnLine(linetxt)) linetxt = PassCenterOnLinePart(linetxt); else linetxt = PassNextHelpPart(linetxt); } return 0; }
static int GetLinkIndex(struct LinkPosition* pos) { int linkcntr=0; char* linetxt = GetHelpLine(pos->line); while (*linetxt) { if (IsHlpReference(linetxt)) { linkcntr++; if (linkcntr == pos->nr) return GetHlpLinkIndex(linetxt); else linetxt = PassHlpReferencePart(linetxt); } else if (IsFullLine(linetxt)) linetxt = PassHlpFullLinePart(linetxt); else if (IsHlpAsciiChar(linetxt)) linetxt = PassHlpAsciiChar(linetxt); else if (IsCenterOnLine(linetxt)) linetxt = PassCenterOnLinePart(linetxt); else linetxt = PassNextHelpPart(linetxt); } return -1; }
static int SeekLinkNr(int line, int charpos) { int pos = -1; int linkcntr = 0; char* linetxt = GetHelpLine(line); while (*linetxt && (pos < charpos)) { if (IsHlpReference(linetxt)) { char *start, *end; GetHlpLinkCaption(linetxt, &start, &end); linkcntr++; pos += (int)(end - start); if (pos >= charpos) return linkcntr; linetxt = PassHlpReferencePart(linetxt); } else if (IsFullLine(linetxt)) linetxt = PassHlpFullLinePart(linetxt); else if (IsCenterOnLine(linetxt)) linetxt = PassCenterOnLinePart(linetxt); else if (IsHlpAsciiChar(linetxt)) { pos++; linetxt = PassHlpAsciiChar(linetxt); } else { char* next = PassNextHelpPart(linetxt); pos += (int)(next - linetxt); linetxt = next; } } return 0; }
static void DrawHelpLineParts(int line, int x, int y, int xlen) { int linkcntr = 0; char* linetxt = GetHelpLine(line); while (*linetxt) { if (IsHlpReference(linetxt)) { char *start, *end, sentinel; GetHlpLinkCaption(linetxt, &start, &end); sentinel = *end; *end = 0; linkcntr++; if ((line == CurrentLink.line) && (CurrentLink.nr == linkcntr)) DrawText(x, y, start, HILINKFORCOLOR, HILINKBACKCOLOR); else DrawText(x, y, start, LOLINKFORCOLOR, LOLINKBACKCOLOR); x += strlen(start); *end = sentinel; linetxt = PassHlpReferencePart(linetxt); } else if (IsFullLine(linetxt)) { DrawSequence(x, y, xlen-1, 'Ä', DIALOGFORCOLOR, DIALOGBACKCOLOR); linetxt = PassHlpFullLinePart(linetxt); } else if (IsHlpAsciiChar(linetxt)) { DrawSequence(x, y, 1, GetHlpAsciiChar(linetxt), DIALOGFORCOLOR, DIALOGBACKCOLOR); linetxt = PassHlpAsciiChar(linetxt); x++; } else if (IsCenterOnLine(linetxt)) { int centerx; char *begin, *end, sentinel; GetHlpTextToCenter(linetxt, &begin, &end); centerx = x + ((xlen / 2) - ((int)(end - begin) / 2)); sentinel = *end; *end = 0; if (centerx > x) DrawText(centerx, y, begin, DIALOGFORCOLOR, DIALOGBACKCOLOR); else DrawText(x, y, begin, DIALOGFORCOLOR, DIALOGBACKCOLOR); *end = sentinel; linetxt = PassCenterOnLinePart(linetxt); } else { char* next = PassNextHelpPart(linetxt); char sentinel = *next; *next = 0; DrawText(x, y, linetxt, DIALOGFORCOLOR, DIALOGBACKCOLOR); x += strlen(linetxt); *next = sentinel; linetxt = next; } } }
main(int argc, char *argv[]) { char *cp; int HelpCount = 0; long where; if (argc < 2) return -1; Argv = argv; if ((helpfp = OpenHelpFile(argv[1], "r+b")) == NULL) return -1; *hline = '\0'; while (*hline != '<') { if (GetHelpLine(hline) == NULL) { fclose(helpfp); return -1; } } while (*hline == '<') { if (strncmp(hline, "<end>", 5) == 0) break; /* -------- parse the help window's text name ----- */ if ((cp = strchr(hline, '>')) != NULL) { ThisHelp = calloc(1, sizeof(struct helps)); if (FirstHelp == NULL) FirstHelp = ThisHelp; *cp = '\0'; ThisHelp->hname=malloc(strlen(hline+1)+1); strcpy(ThisHelp->hname, hline+1); HelpFilePosition(&ThisHelp->hptr, &ThisHelp->bit); if (GetHelpLine(hline) == NULL) break; /* ------- build the help linked list entry --- */ while (*hline == '[') { HelpFilePosition(&ThisHelp->hptr, &ThisHelp->bit); /* ------ parse a comment ----- */ if (strncmp(hline, "[*]", 3) == 0) { ThisHelp->comment=malloc(strlen(hline+3)+1); strcpy(ThisHelp->comment, hline+3); if (GetHelpLine(hline) == NULL) break; continue; } /* ---- parse the <<prev button pointer ---- */ if (strncmp(hline, "[<<]", 4) == 0) { char *cp = strchr(hline+4, '<'); if (cp != NULL) { char *cp1 = strchr(cp, '>'); if (cp1 != NULL) { int len = (int) (cp1-cp); ThisHelp->PrevName=calloc(1,len); strncpy(ThisHelp->PrevName, cp+1,len-1); } } if (GetHelpLine(hline) == NULL) break; continue; } /* ---- parse the next>> button pointer ---- */ else if (strncmp(hline, "[>>]", 4) == 0) { char *cp = strchr(hline+4, '<'); if (cp != NULL) { char *cp1 = strchr(cp, '>'); if (cp1 != NULL) { int len = (int) (cp1-cp); ThisHelp->NextName=calloc(1,len); strncpy(ThisHelp->NextName, cp+1,len-1); } } if (GetHelpLine(hline) == NULL) break; continue; } else break; } ThisHelp->hheight = 0; ThisHelp->hwidth = 0; ThisHelp->NextHelp = NULL; /* ------ append entry to the linked list ------ */ if (LastHelp != NULL) LastHelp->NextHelp = ThisHelp; LastHelp = ThisHelp; HelpCount++; } /* -------- move to the next <helpname> token ------ */ if (GetHelpLine(hline) == NULL) strcpy(hline, "<end>"); while (*hline != '<') { ThisHelp->hwidth = max(ThisHelp->hwidth, HelpLength(hline)); ThisHelp->hheight++; if (GetHelpLine(hline) == NULL) strcpy(hline, "<end>"); } } /* --- append the help structures to the file --- */ fseek(helpfp, 0L, SEEK_END); where = ftell(helpfp); ThisHelp = FirstHelp; fwrite(&HelpCount, sizeof(int), 1, helpfp); while (ThisHelp != NULL) { ThisHelp->nexthlp = FindHelp(ThisHelp->NextName); ThisHelp->prevhlp = FindHelp(ThisHelp->PrevName); WriteText(ThisHelp->hname); WriteText(ThisHelp->comment); fwrite(&ThisHelp->hptr, sizeof(short)*5+sizeof(long), 1, helpfp); ThisHelp = ThisHelp->NextHelp; } fwrite(&where, sizeof(long), 1, helpfp); fclose(helpfp); return 0; }