/* $Header: sw.c,v 4.3.1.2 85/05/21 13:36:23 lwall Exp $
* Revision 4.3.1.2 85/05/21 13:36:23 lwall
* Sped up "rn -c" by not doing unnecessary initialization.
* Revision 4.3.1.1 85/05/10 11:40:38 lwall
* Revision 4.3 85/05/01 11:50:54 lwall
* Baseline for release with 4.3bsd.
sw_init(argc
,argv
,tcbufptr
)
if (argc
>= 2 && strEQ(argv
[1],"-c"))
checkflag
=TRUE
; /* so we can optimize for -c */
interp(*tcbufptr
,1024,GLOBINIT
);
safecpy(*tcbufptr
,getenv("RNINIT"),1024);
for (i
= 1; i
< argc
; i
++)
int initfd
= open(*tcbufptr
,0);
if (filestat
.st_size
> 1024)
*tcbufptr
= saferealloc(*tcbufptr
,(MEM_SIZE
)filestat
.st_size
);
read(initfd
,*tcbufptr
,(int)filestat
.st_size
);
(*tcbufptr
)[filestat
.st_size
-1] = '\0';
/* wipe out last newline */
printf(cantopen
,*tcbufptr
) FLUSH
;
/* decode a list of space separated switches */
char *tmplist
= safemalloc((MEM_SIZE
) strlen(swlist
) + 2);
/* semi-automatic string */
register char *p
, inquote
= 0;
for (p
=tmplist
; isspace(*p
); p
++) ; /* skip any initial spaces */
while (*p
) { /* "String, or nothing" */
if (!inquote
&& isspace(*p
)) { /* word delimiter? */
*p
++ = '\0'; /* chop here */
while (isspace(*p
)) /* these will be ignored later */
else if (inquote
== *p
) {
strcpy(p
,p
+1); /* delete trailing quote */
inquote
= 0; /* no longer quoting */
else if (!inquote
&& *p
== '"' || *p
== '\'') {
/* OK, I know when I am not wanted */
inquote
= *p
; /* remember single or double */
strcpy(p
,p
+1); /* delete the quote */
} /* (crude, but effective) */
else if (*p
== '\\') { /* quoted something? */
if (p
[1] == '\n') /* newline? */
strcpy(p
,p
+2); /* "I didn't see anything" */
strcpy(p
,p
+1); /* delete the backwhack */
p
++; /* leave the whatever alone */
p
++; /* normal char, leave it alone */
*++p
= '\0'; /* put an extra null on the end */
printf("Unmatched %c in switch\n",inquote
) FLUSH
;
for (p
= tmplist
; *p
; /* p += strlen(p)+1 */ ) {
while (*p
++) ; /* point at null + 1 */
free(tmplist
); /* this oughta be in Ada */
/* decode a single switch */
while (isspace(*s
)) /* ignore leading spaces */
printf("Switch: %s\n",s
) FLUSH
;
if (*s
!= '-' && *s
!= '+') { /* newsgroup pattern */
else { /* normal switch */
bool upordown
= *s
== '-' ? TRUE
: FALSE
;
while (*s
&& *s
!= '-' && *s
!= '+') s
++;
if (upordown
? strEQ(getenv("TERM"),tmpbuf
)
: strNE(getenv("TERM"),tmpbuf
) ) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (upordown
? (just_a_sec
*10 <= atoi(s
))
: (just_a_sec
*10 >= atoi(s
)) ) {
setenv("SAVEDIR", upordown
? "%p/%c" : "%p" );
setenv("SAVENAME", upordown
? "%a" : "%^C");
int flag
= (*s
== 'h' ? HT_HIDE
: HT_MAGIC
);
for (i
=HEAD_FIRST
; i
<HEAD_LAST
; i
++)
if (!len
|| strnEQ(s
,htype
[i
].ht_name
,len
))
htype
[i
].ht_flags
|= flag
;
htype
[i
].ht_flags
&= ~flag
;
muck_up_clear
= upordown
;
can_home_clear
= upordown
;
fputs("This isn't readnews. Don't use -n.\n\n",stdout
) FLUSH
;
printf("\nIgnoring unrecognized switch: -%c\n", *s
) FLUSH
;
printf("\nIgnoring -%c\n", *s
) FLUSH
;
/* print current switch values */
static char mp
[2] = {'+','-'};
fputs("\nCurrent switch settings:\n",stdout
);
printf("%c/ ", mp
[strEQ(getval("SAVEDIR",SAVEDIR
),"%p/%c")]);
printf("%cc ", mp
[checkflag
]);
printf("-C%d ", docheckwhen
);
printf("%ce ", mp
[erase_screen
]);
printf("-F\"%s\" ", indstr
);
for (i
=HEAD_FIRST
; i
<HEAD_LAST
; i
++)
mp
[htype
[i
].ht_flags
& HT_HIDE
], htype
[i
].ht_name
,
(! (i
% 5) ? '\n' : ' ') );
printf("-i%d ", initlines
);
printf("%cl ", mp
[muck_up_clear
]);
printf("%cL ", mp
[can_home_clear
]);
printf("-m%c ",marking
==UNDERLINE
?'u':'s');
printf("%cM ", mp
[mbox_always
]);
printf("%cN ", mp
[norm_always
]);
printf("%cr ", mp
[findlast
]);
printf("-s%d ", countdown
);
printf("%cs ", mp
[suppress_cn
]);
printf("%ct ", mp
[!verbose
]);
printf("%cT ", mp
[typeahead
]);
printf("%cv ", mp
[verify
]);
fputs("\n\n",stdout
) FLUSH
;
fputs("Current restriction:",stdout
);
for (i
=0; i
<maxngtodo
; i
++)
fputs("\n\n",stdout
) FLUSH
;
fputs("No restriction.\n\n",stdout
) FLUSH
;
cwd
= savestr(filexp("~/News"));
safecpy(tmpbuf
,filexp(cwd
),sizeof tmpbuf
);
if (makedir(tmpbuf
,MD_DIR
) < 0 || chdir(tmpbuf
) < 0) {
interp(cmd_buf
, (sizeof cmd_buf
), "%~/News");
if (makedir(cmd_buf
,MD_DIR
) < 0)
Cannot make directory %s--\n\
articles will be saved to %s\n\
Current directory %s is not writeable--\n\
articles will be saved to home directory\n\n\
printf("%s not writeable--using ~\n\n",tmpbuf
) FLUSH
;