perm filename DEFAU.SAI[LIB,AIL] blob sn#408153 filedate 1979-01-09 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	ENTRY DEFAULT!SWITCHES
C00009 ENDMK
C⊗;
ENTRY DEFAULT!SWITCHES;
BEGIN "DEFAULTS"
DEFINE LIBRARY!ENTRY = TRUE;
REQUIRE "SYS:STD.HDR" SOURCE!FILE;
INTERNAL SIMPLE BOOLEAN PROCEDURE default!switches
	(REFERENCE STRING switch!text; STRING prog!name, option!name(NULL));
! This procedure reads the user's file, SWITCH.INI, and looks for a
line of the form:

prog!name[:option!name]/switch1[:value1]/switch2[:value2] ...

a semicolon will mark the rest of the line as a comment, and if the last
non-comment, non-blank character is a hyphen, the next line will be taken
as a continuation line.  If this procedure finds a line matching its
input parameters, prog!name and option!name (note option!name is optional),
it will return TRUE, with the rest of the line in switch!text.  Otherwise
switch!text is NULL, and the procedure returns FALSE;

BEGIN "default!switches"
INTEGER channel,flag,count,brchar,eof,break!tab1,break!tab2,break!tab3;
LABEL cleanup!exit;
BOOLEAN result;
STRING instring, instr1, prgstring;
switch!text ← NULL;
result ← FALSE;
prog!name ← UPPERCASE(TRIM(prog!name));  ! don't be too picky;
IF LENGTH(option!name) > 0 THEN
   option!name ← UPPERCASE(TRIM(option!name));  ! this won't affect caller;
channel ← GETCHAN;  ! get a channel for the switch file;
IF channel < 0 THEN
   BEGIN
   USERERR(0,1,"No channel for default!switches.");
   RETURN(result)
   END;
break!tab1 ← GETBREAK;
break!tab2 ← GETBREAK;
break!tab3 ← GETBREAK;
SETBREAK(break!tab1, LF & FF, CR, "ISN");  ! gets a line of text;
SETBREAK(break!tab2, "/:", " ", "IR");  ! this gets program name from
			a line in the switch file;
SETBREAK(break!tab3, ";", NULL, "IS");  ! strips comments;
count ← 200;
eof ← TRUE;
flag ← TRUE;
OPEN(channel, "DSK", 0, 2, 0, count, brchar, eof);
IF eof THEN
   BEGIN
   USERERR(0, 1, "No DSK for default!switches");
   GO TO cleanup!exit
   END;
LOOKUP(channel, "SWITCH.INI", flag);
IF flag THEN GO TO cleanup!exit;  ! all this work for nothing;

WHILE TRUE DO
   BEGIN "main loop"
   instring ← INPUT(channel, break!tab1);  ! get a switch line;
   IF eof THEN
      BEGIN  ! we've come to the end of the file;
      IF LENGTH(instring) NEQ 0 THEN  ! it ended in the middle of a line;
	 USERERR(0, 1, "SWITCH.INI unexpected eof");
cleanup!exit:  ! jump here on error, or fall through on normal eof;
      RELBREAK(break!tab1);
      RELBREAK(break!tab2);
      RELBREAK(break!tab3);
      RELEASE(channel);
      RETURN(result)
      END;
   instring ← TRIM(SCAN(instring, break!tab3, brchar));  ! strip any
			comment or spaces at the end of the line;
   WHILE instring[INF TO INF] = "-" DO  ! pick up continuation lines;
      BEGIN "continuation lines"
      instr1 ← INPUT(channel, break!tab1);
      IF eof THEN
	 BEGIN
	 USERERR(0, 1, "SWITCH.INI eof in continuation line");
	 GO TO cleanup!exit
	 END;
      instring ← TRIM(instring[1 TO INF-1])  ! all but the final hyphen;
		 & TRIM(SCAN(instr1, break!tab3, brchar))
      END "continuation lines";

   ! see if this line is the requested one;
   prgstring ← UPPERCASE(SCAN(instring, break!tab2, brchar));
   IF brchar = 0 THEN
      USERERR(0, 1, "invalid line in SWITCH.INI");
   IF EQU(prgstring, prog!name) THEN  ! program name matches, see about option;
      BEGIN
      IF brchar = "/" THEN  ! no option in switch line;
         prgstring ← NULL  ! re-use prgstring for option name;
      ELSE
	 BEGIN   ! pick up option name from instring;
	 brchar ← LOP(instring);  ! dump initial colon;
	 prgstring ← UPPERCASE(SCAN(instring, break!tab2, brchar));
	 IF brchar = 0 OR brchar = ":" THEN  ! syntax error;
	    USERERR(0, 1, "line invalid in SWITCH.INI")
	 END;
      IF EQU(prgstring, option!name) THEN
	 BEGIN
	 IF result THEN USERERR(0, 1, "multiple definitions in SWITCH.INI");
	 result ← TRUE;
	 switch!text ← instring
	 END
      END
   END "main loop"
END "default!switches";
END "DEFAULTS"