/* $Id: sw.c,v 3.0 1992/02/01 03:09:32 davison Trn $
/* This software is Copyright 1991 by Stan Barber.
* Permission is hereby granted to copy, reproduce, redistribute or otherwise
* use this software as long as: there is no monetary profit gained
* specifically from the use or reproduction of this software, it is not
* sold, rented, traded or otherwise marketed, and this copyright notice is
* included prominently in any copy made.
* The author make no claims as to the fitness or correctness of this software
* for any use whatsoever, and it is provided as is. Any use of this software
* is at the user's own risk.
sw_init(argc
,argv
,tcbufptr
)
if (argc
>= 2 && strEQ(argv
[1],"-c"))
checkflag
=TRUE
; /* so we can optimize for -c */
interp(*tcbufptr
,1024,GLOBINIT
);
if (!use_threads
|| !*safecpy(*tcbufptr
,getenv("TRNINIT"),1024))
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 *s
, *p
, inquote
= 0;
while (isspace(*s
)) s
++; /* skip any initial spaces */
while (*s
&& *s
++ != '\n') ; /* skip comments */
while (*p
) { /* "String, or nothing" */
if (!inquote
&& isspace(*p
)) { /* word delimiter? */
*p
++ = '\0'; /* chop here */
while (*s
&& *s
++ != '\n') ;
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");
thread_always
= upordown
;
auto_arrow_macros
= upordown
;
breadth_first
= upordown
;
bkgnd_spinner
= upordown
;
novice_delays
= !upordown
;
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
;
initlines_specified
= TRUE
;
dont_filter_control
= TRUE
;
muck_up_clear
= upordown
;
can_home_clear
= upordown
;
fputs("This isn't readnews. Don't use -n.\n\n",stdout
) FLUSH
;
if (*s
<= '9' && *s
>= '0') {
} while (*s
<= '9' && *s
>= '0');
|| (*++s
&& !set_sel_sort(*s
))) {
printf("\nIgnoring unrecognized -O option: %c\n", *s
) FLUSH
;
printf("\nIgnoring -O with %c\n", *s
) FLUSH
;
auto_select_postings
= upordown
;
unbroken_subjects
= upordown
;
if (*s
<= '9' && *s
>= '0') {
if ((max_tree_lines
= atoi(s
)) > 11)
} while (*s
<= '9' && *s
>= '0');
strncpy(select_order
, s
, 3);
if (*s
<= '9' && *s
>= '0') {
} while (*s
<= '9' && *s
>= '0');
* People want a way to avoid checking for new newsgroups on startup.
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("%ca ", mp
[thread_always
]);
printf("%cA ", mp
[auto_arrow_macros
]);
printf("%cb ", mp
[breadth_first
]);
printf("%cB ", mp
[bkgnd_spinner
]);
printf("%cc ", mp
[checkflag
]);
printf("-C%d ", docheckwhen
);
printf("%ce ", mp
[erase_screen
]);
printf("%cf ", mp
[!novice_delays
]);
printf("-F\"%s\" ", indstr
);
printf("%cG", mp
[fuzzyGet
]);
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("%cI ", mp
[append_unsub
]);
printf("%cj ", mp
[dont_filter_control
]);
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("-o%d ", olden_days
);
printf("%cp ", mp
[auto_select_postings
]);
printf("%cr ", mp
[findlast
]);
printf("-s%d ", countdown
);
printf("%cs ", mp
[suppress_cn
]);
printf("%ct ", mp
[!verbose
]);
printf("%cT ", mp
[typeahead
]);
printf("%cu ", mp
[unbroken_subjects
]);
printf("%cv ", mp
[verify
]);
printf("-x%d%s ",max_tree_lines
,select_order
);
printf("-X%d%c%c ",select_on
,end_select
,page_select
);
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
;