diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..34bb861 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Authors + * Troy Engel - Beginning Code + * Bruce Smith - Unix porting diff --git a/BUGS b/BUGS new file mode 100644 index 0000000..92872b2 --- /dev/null +++ b/BUGS @@ -0,0 +1,6 @@ +Crash + * none + +Non-Crash + * none + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..21ab153 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..7452e9e --- /dev/null +++ b/ChangeLog @@ -0,0 +1,4 @@ +Sun Dec 13 1998 Troy Engel + * versioned to 0.5.3 + * initial public release + diff --git a/Makefile.vc6 b/Makefile.vc6 new file mode 100644 index 0000000..a096ea1 --- /dev/null +++ b/Makefile.vc6 @@ -0,0 +1,64 @@ +######################################################## +## Makefile for building gtkSlash.exe with MSVC6 +## Use: nmake -f makefile.vc6 [release | debug] +## (default is release) +## +## Comments to: Troy Engel + +## Adjust these to your machine: + +# path to +GLIB = ..\glib + +# path to +GTK = ..\gtk-plus + +# paths to .lib for gtk, gdk and glib +GLIBPATHR = ..\lib_release +GLIBPATHD = ..\lib_debug + +######################################################## +## Nothing more to do below this line! + +## Release +CCR = cl.exe /ML /O2 /D "NDEBUG" +LINKR = link.exe /incremental:no /libpath:$(GLIBPATHR) + +## Debug +CCD = cl.exe /MLd /Gm /ZI /Od /D "_DEBUG" /GZ +LINKD = link.exe /incremental:yes /debug /libpath:$(GLIBPATHD) + +CFLAGS = /nologo /W3 /GX /D "WIN32" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -I$(GLIB) -I$(GTK) +LFLAGS = /nologo /out:gtkslash.exe /subsystem:windows /machine:I386 +LINKLIBS = kernel32.lib glib-1.1.lib gdk-1.1.lib gtk-1.1.lib + +all : release + +release: gtkslashr.obj rcfuncsr.obj + $(LINKR) $(LFLAGS) $(LINKLIBS) gtkslash.obj rcfuncs.obj + +debug: gtkslashd.obj rcfuncsd.obj + $(LINKD) $(LFLAGS) $(LINKLIBS) gtkslash.obj rcfuncs.obj + +gtkslashr.obj : gtkslash.c + $(CCR) $(CFLAGS) gtkslash.c + +gtkslashd.obj : gtkslash.c + $(CCD) $(CFLAGS) gtkslash.c + +rcfuncsr.obj : rcfuncs.c + $(CCR) $(CFLAGS) rcfuncs.c + +rcfuncsd.obj : rcfuncs.c + $(CCD) $(CFLAGS) rcfuncs.c + +clean: + del gtkslash.exe + del gtkslash.obj + del rcfuncs.obj + del gtkslash.pdb + del gtkslash.ilk + del vc60.idb + del vc60.pdb + del vc60.pch + diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..703d3d9 --- /dev/null +++ b/NEWS @@ -0,0 +1,3 @@ +Version 0.5.3 + * initial public release + diff --git a/README b/README new file mode 100644 index 0000000..29982f0 --- /dev/null +++ b/README @@ -0,0 +1,54 @@ +gtkSlash - Slashdot headlines news-ticker + (c) 1998 Troy Engel + http://www.sonic.net/~tengel/gtkslash/ +----------------------------------------- + +12/13/98, v0.5.3 + + +General +------- +This program is based on original code from slashes.pl (c) +1998 Alex Shnitman . It's very simple - +it reads the 'ultramode.txt' file from /. and gives you a +nice little display unit locally. + +gtkSlash requires Gtk+ (http://www.gtk.org) and curl +(http://www.fts.frontec.se/~dast/curl/) for the display and +file retrieval, respectively. Additionally, if you want to +browse a news article from within gtkSlash you'll need some +sort of web browser. Currently it is working just fine with +Gtk 1.1.3 and curl 5.0. + +If you are on Windows, the Gtk+ version which has been used is +from Tor Lillqvist; he also ports Gdk and GIMP. If you don't +have these libs, you'll probably need them to compile as I am +unaware of anyone else who's done the porting. You can find +all these at (http://user.sgic.fi/~tml/gimp/win32/). I +developed this whole thing using his libraries from 11/21/98. + + +Configuration +------------- +The program will read the file ~/.gtkslashrc (*nix) or +~\_gtkslashrc (Windows) upon startup. If this file isn't +found, it will look in /etc/gtkslashrc (*nix) or +\gtkslashrc instead. A sample of this file has been +included as gtkslashrc, and is self-descriptive. Note: if +you want web-browsing capabilities, you have to check this +file and modify it accordingly - there is no default for the +web-browser or curl at this time. A GUI editor for this file +isn't done yet, maybe someday. + + +Reasons I did things +-------------------- +Curl is used specifically here instead of internal routines +because of a fundamental reason: don't reinvent the wheel. :) +Curl handles all kinds of stuff I'm not interested in +(proxies, firewalls, weird ports and socket problems, etc) +and is already portable across all kinds of platforms. It +works great for me on Windows, so I hope it works great for +you. And, uh, I'm a contributing author of sorts. :) (only a +bugfix or two...) + diff --git a/TODO b/TODO new file mode 100644 index 0000000..f17141f --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +As of 0.5.3 + * *nix portability + * GUI config editor like GIMP diff --git a/_gtkslashrc b/_gtkslashrc new file mode 100644 index 0000000..ceee126 --- /dev/null +++ b/_gtkslashrc @@ -0,0 +1,41 @@ +# Configuration file for gtkSlash +# +# System Wide: +# /etc/gtkslashrc +# \gtkslashrc +# +# Per user: +# /.gtkslashrc +# \_gtkslashrc + +# Number of seconds before a refresh is performed... +# Since ultramode.txt only updates once in 30 minutes, +# the timeout is set to that value. +# Default: 1800 +refresh-timeout 1800 + +# Netscape command, %s is replaced by the URL +# Default: none +browser-cmd "D:\Netscape\Program\netscape.exe %s" +#browser-cmd "/usr/X11R6/bin/netscape -remote 'OpenURL(%s, new_window)'"; + +# Curl command, %s is replaced by ~/ultramode.tmp +# Default: none +curl-cmd "C:\Util\curl.exe -s -o %s http://slashdot.org/ultramode.txt" +#curl-cmd "/usr/local/bin/curl -s -o %s http://slashdot.org/ultramode.txt" + +# If you'd like to run gtkslash in "compact" mode (without +# the buttons on the bottom & the column titles, and +# launching an article upon a click on its row) set this +# variable to ON. Default: OFF +compact-mode OFF + +# Number of fields in ultramode.txt, delimited by the %% +# identifier. There are 9 fields per record as of 12/9/98. +# Default: 9 +num-fields 9 + +# If you want the comments displayed 'flat' (ie, not in +# a threaded treeview mode) when going to /., set this to ON. +# Default: OFF +comments-flat OFF diff --git a/gtkslash.c b/gtkslash.c new file mode 100644 index 0000000..66371b9 --- /dev/null +++ b/gtkslash.c @@ -0,0 +1,500 @@ +/* gtkSlash - Slashdot headlines news-ticker + * (c) 1998 Troy Engel + * + * Based on original code from slashes.pl + * (c) 1998 Alex Shnitman + * + * Other cool code from gRun + * (c) 1998 Southern Gold Development + * + * This code is distributed under the terms of the GNU + * General Public License, etc etc. Use it, don't abuse it. + * See the file "Copying" for the entire GNU Public + * License policy. +*/ + +/* just what it says - good for layout development + * just remember to turn it off :P */ +/* #define _LOCAL_TEST_MODE */ + +#include + +#ifdef WIN32 +#include +#define DIR_CHAR "\\" +#define DOT_CHAR "_" +#else +/* TODO: add appropriate unix headers */ +#include +#define DIR_CHAR "/" +#define DOT_CHAR "." +/* these two allow Win people to "hide" a cmdline + * app. Provided here just so it works (could be used + * for the same thing in 'startApp' on unix?) + */ +#define SW_SHOWDEFAULT 0 +#define SW_HIDE 0 +#endif + +#include "rcfuncs.h" + +#define MAX_BUFF 1024 +#define APP_RC "gtkslashrc" + +/* localization, anyone? */ +#define MSG_TITLE "Slashdot Headlines" +#define MSG_INIT "Initializing..." +#define MSG_LOAD "Loading ultramode.txt..." +#define MSG_LOAD_ERR "Error loading ultramode.txt!" +#define MSG_RETRIEVE "Retrieving latest ultramode.txt..." +#define MSG_RETR_ERR "Error retrieving ultramode.txt!" +#define MSG_LAUNCH "Launching web browser..." +#define MSG_LAUNCH_ERR "Error launching browser!" +#define MSG_IDLE "Status: Idle (gtkSlash 0.5.3)" + +/* read in from the RC file */ +static gint refresh_timeout; +static gchar browser_cmd[MAX_BUFF]; +static gchar curl_cmd[MAX_BUFF]; +static BOOL compact_mode; +static gint num_fields; +static GtkWidget *status; +static BOOL comments_flat; + +/* retrieves a line from a linefeed delimited textfile */ +gchar *app_getLine(FILE *file) { + char *tmp, in; + int cnt = 0, retIn; + + if (feof(file)) { + return NULL; + } + else { + tmp = g_malloc(sizeof(char) * MAX_BUFF); + retIn = fread((void *) &in, sizeof(char), 1, file); + if (retIn != 1) { + g_free(tmp); + return NULL; + } + while ((in != '\n') && (cnt < MAX_BUFF)) { + tmp[cnt] = in; + cnt++; + retIn = fread((void *) &in, sizeof(char), 1, file); + if (retIn != 1) { + g_free(tmp); + return NULL; + } + } + if (cnt == MAX_BUFF) { + g_free(tmp); + return NULL; + } + tmp[cnt] = '\0'; + return tmp; + } +} + +/* loads ultramode.txt into our clist */ +BOOL app_loadFile(GtkWidget *list, const gchar *fname) { + gchar *line; + gchar *article[4], *link; + FILE *fHnd; + gint i; + + fHnd = fopen(fname, "rb"); + if (!fHnd) { + return FALSE; + } + line = app_getLine(fHnd); + if (!line) { + fclose(fHnd); + return FALSE; + } + /* loop till we find the first record delim */ + while (strncmp(line, "%%", 2) != 0) { + line = app_getLine(fHnd); + } + gtk_clist_clear(GTK_CLIST(list)); + gtk_clist_freeze(GTK_CLIST(list)); + while (line) { + for (i = 0 ; ifocus_row); + if (comments_flat) { + gchar *tmp; + tmp = strrchr(url, '.'); + url[tmp - url] = '\0'; + strcat(url, "_F.shtml"); + } + sprintf(cmd, browser_cmd, url); + gtk_label_set(GTK_LABEL(status), MSG_LAUNCH); + if (!app_startApp(cmd, FALSE, SW_SHOWDEFAULT)) + gtk_label_set(GTK_LABEL(status), MSG_LAUNCH_ERR); + gtk_timeout_add(1000*5, app_timer_idle, NULL); + return FALSE; +} + +/* sorting */ +void app_click_column(GtkCList *clist, gint column, gpointer data) { + if (column == clist->sort_column) { + clist->sort_type = (clist->sort_type == GTK_SORT_ASCENDING) ? + GTK_SORT_DESCENDING : GTK_SORT_ASCENDING; + } else { + gtk_clist_set_sort_column (clist, column); + } + gtk_clist_sort(clist); +} + +BOOL app_parse_rc() { + gchar *home_env, *fname; + gint retval; + + home_env = getenv("HOME"); + fname = g_malloc(sizeof(gchar) * (strlen(home_env) + 15)); + strcpy(fname, home_env); + strcat(fname, DIR_CHAR); + strcat(fname, DOT_CHAR); + strcat(fname, APP_RC); + + retval = RCInit(fname); + g_free(fname); + + /* if no personal file, look for system */ + if (!retval) { +#ifdef WIN32 + gchar tmp[MAX_BUFF]; + GetWindowsDirectory(tmp, sizeof(tmp)); + fname = g_malloc(sizeof(gchar) * (sizeof(tmp) + 1 + sizeof(APP_RC))); + strcpy(fname, tmp); +#else + fname = g_malloc(sizeof(gchar) * (4 + 1 + strlen(APP_RC))); + strcpy(fname, "/etc"); +#endif + strcat(fname, DIR_CHAR); + strcat(fname, APP_RC); + retval = RCInit(fname); + g_free(fname); + } + + refresh_timeout = RCGetInt("timeout-refresh", 1800); + compact_mode = RCGetBool("compact-mode", FALSE); + num_fields = RCGetInt("num-fields", 9); + RCGetString("browser-cmd", browser_cmd, "", sizeof(browser_cmd)); + RCGetString("curl-cmd", curl_cmd, "", sizeof(curl_cmd)); + comments_flat = RCGetBool("comments-flat", FALSE); + + RCShutDown(); + return retval; +} + +void app_window() { + GtkWidget *window, *vbox, *clist, *scrolled_win; + gchar *titles[4] = {"Title", "Author", "Topic", "Comments"}; + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), MSG_TITLE); + gtk_signal_connect(GTK_OBJECT(window), "destroy", (GtkSignalFunc) app_exit, NULL); + gtk_widget_set_usize(GTK_WIDGET(window), 550, 155); + gtk_window_set_policy(GTK_WINDOW (window), TRUE, TRUE, TRUE); + + vbox = gtk_vbox_new(FALSE, 5); + gtk_container_border_width (GTK_CONTAINER(vbox), 5); + gtk_container_add(GTK_CONTAINER(window), vbox); + gtk_widget_show(vbox); + + clist = gtk_clist_new_with_titles(4, titles); + gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE); + gtk_clist_set_column_width(GTK_CLIST(clist), 0, 250); + gtk_clist_set_column_width(GTK_CLIST(clist), 1, 70); + gtk_clist_set_column_width(GTK_CLIST(clist), 2, 100); + gtk_clist_set_column_width(GTK_CLIST(clist), 3, 10); + gtk_signal_connect(GTK_OBJECT (clist), "click_column", + (GtkSignalFunc)app_click_column, NULL); + gtk_widget_show(clist); + scrolled_win = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add(GTK_CONTAINER(scrolled_win), clist); + gtk_box_pack_start(GTK_BOX(vbox), scrolled_win, TRUE, TRUE, 0); + gtk_widget_show(scrolled_win); + + if (!compact_mode) { + GtkWidget *hbox, *but; + + hbox = gtk_hbox_new(FALSE, 0); + but = gtk_button_new_with_label("Refresh"); + gtk_widget_set_usize(GTK_WIDGET(but), 70, 24); + gtk_signal_connect(GTK_OBJECT(but), "clicked", (GtkSignalFunc) app_refresh, clist); + gtk_box_pack_start(GTK_BOX(hbox), but, FALSE, FALSE, 0); + gtk_widget_show(but); + + but = gtk_button_new_with_label("Read"); + gtk_widget_set_usize(GTK_WIDGET(but), 70, 24); + gtk_signal_connect(GTK_OBJECT(but), "clicked", (GtkSignalFunc) app_article_browse, (gpointer)clist); + gtk_box_pack_start(GTK_BOX(hbox), but, FALSE, FALSE, 0); + gtk_widget_show(but); + + status = gtk_label_new(MSG_INIT); + gtk_box_pack_start(GTK_BOX(hbox), status, FALSE, FALSE, 10); + gtk_widget_show(status); + + but = gtk_button_new_with_label("Quit"); + gtk_widget_set_usize(GTK_WIDGET(but), 70, 24); + gtk_signal_connect(GTK_OBJECT(but), "clicked", (GtkSignalFunc) app_exit, NULL); + gtk_box_pack_end(GTK_BOX(hbox), but, FALSE, FALSE, 0); + gtk_widget_show(but); + + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show(hbox); + } else { + gtk_clist_column_titles_hide(GTK_CLIST(clist)); + gtk_signal_connect(GTK_OBJECT(GTK_CLIST(clist)->selection), "select_row", (GtkSignalFunc) app_article_browse, (gpointer)clist); + status = gtk_label_new(""); + } + + gtk_timeout_add(1000*refresh_timeout, app_timer_refresh, clist); + + gtk_widget_show(window); + gtk_widget_draw_children(window); + app_refresh(NULL, clist); +} + +#ifdef WIN32 +int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) { +#else +void main(int argc, char **argv) { +#endif + +#ifdef WIN32 + /* parse into a command line ala argv, argc */ + char **argv, *work, *twrk; + int cnt, len, argc; + + len = strlen(lpCmdLine); + argc = 0; + for (cnt = 0; cnt < len; cnt++) { + if (lpCmdLine[cnt] == ' ') { + argc++; + } + } + argv = g_malloc(sizeof(char *) * (argc + 1)); + argv[argc] = NULL; + if (argc == 1) { + argv[0] = g_malloc(sizeof(char) * (len + 1)); + strcpy(argv[0], lpCmdLine); + } + else { + work = g_malloc(sizeof(char) * (len + 1)); + strcpy(work, lpCmdLine); + twrk = (char *) strtok(work, " "); + argv[0] = twrk; + cnt = 1; + while (twrk) { + twrk = (char *) strtok(NULL, " "); + argv[cnt] = twrk; + cnt++; + } + argv[cnt] = work; + } +#endif /* WIN32 */ + + gtk_init(&argc, &argv); + app_parse_rc(); + app_window(); + gtk_main(); +} diff --git a/rcfuncs.c b/rcfuncs.c new file mode 100644 index 0000000..760717c --- /dev/null +++ b/rcfuncs.c @@ -0,0 +1,332 @@ +/* + * rcfuncs - routines to parse generic RC files + * tengel@sonic.net + * + * This is taken from the LiteStep Shell Source code + * (http://www.litestep.net) and modified a bunch to meet + * our RC needs along with using gdk. + * + * This code is distributed under the terms of the GNU + * General Public License, etc etc. Use it, don't abuse it. + * See the file "Copying" for the entire GNU Public + * License policy. +*/ + +#include +#ifdef WIN32 +#include +#endif +#include +#include +#include "rcfuncs.h" + +#ifndef MAX_BUFF +#define MAX_BUFF 1024 +#endif + +static gchar **RCBuffer = NULL; +static gint RCLen = 0; + +FILE* RCOpen(const gchar *szFile) +{ + FILE *f = NULL; + + if (!szFile) + return f; + + /* make sure to open in text mode; in MS ANSI C, + * this will map our \n and \r\n for us. Valid + * in unix? */ + f = fopen(szFile, "rt"); + if (f) + fseek(f, 0, SEEK_SET); + + return f; +} + +BOOL RCClose(FILE *f) +{ + if (f) + fclose (f); + + return TRUE; +} + +/* Parses szString, splitting it up into tokens. Pays + * attention to single and double quotes. */ +gint RCTokenize(const gchar *szString, gchar **lpszBuffers, DWORD dwNumBuffers, gchar *szExtraParameters) +{ + gint index = 0; + gchar quoteChar = 0; + gchar buffer[MAX_BUFF]; + gchar output[MAX_BUFF]; + gchar *pOutput = NULL; + DWORD dwBufferCount = 0; + + strcpy(buffer, szString); + pOutput = output; + + while (buffer[index] && dwBufferCount < dwNumBuffers) { + BOOL skipWhitespace = FALSE; + + switch (buffer[index]) { + case '"': + case '\'': + { + if (!quoteChar) { + quoteChar = buffer[index]; + break; + } else { + if (quoteChar == buffer[index]) { + quoteChar = 0; + strcpy (*lpszBuffers, output); + lpszBuffers++; + dwBufferCount++; + + if (dwBufferCount < dwNumBuffers) + (*lpszBuffers)[0] = '\0'; + + pOutput = output; + *pOutput = '\0'; + skipWhitespace = TRUE; + break; + } else { + *pOutput++ = buffer[index]; + *pOutput = '\0'; + break; + } + } + } + case ' ': + case '\t': + { + if (!quoteChar) { + if (strlen (output)) { + strcpy (*lpszBuffers, output); + lpszBuffers++; + dwBufferCount++; + + if (dwBufferCount < dwNumBuffers) + (*lpszBuffers)[0] = '\0'; + + pOutput = output; + *pOutput = '\0'; + skipWhitespace = TRUE; + } + } else { + *pOutput++ = buffer[index]; + *pOutput = '\0'; + } + break; + } + default: + { + *pOutput++ = buffer[index]; + *pOutput = '\0'; + break; + } + } + + index++; + if (skipWhitespace) { + while(isspace(buffer[index])) { + index++; + } + } + } + + if (strlen (output)) { + if (dwBufferCount < dwNumBuffers) { + dwBufferCount++; + strcat(*lpszBuffers, output); + } + } + + if (szExtraParameters && dwBufferCount == dwNumBuffers) + strcpy (szExtraParameters, buffer + index); + + return dwBufferCount; +} + +gchar* RCFindLine(const gchar *lpKeyName) +{ + gint i; + gint l = strlen(lpKeyName); + + for (i = 0; i < RCLen; i++) { + if (!strnicmp(RCBuffer[i], lpKeyName, l)) + return RCBuffer[i]; + } + + return (gchar *) 0; +} + +gint RCGetInt(const gchar *lpKeyName, gint nDefault) +{ + gint val = nDefault; + gchar *line = NULL; + gchar token1[MAX_BUFF], token2[MAX_BUFF]; + gchar *tokens[2]; + + tokens[0] = token1; + tokens[1] = token2; + line = RCFindLine(lpKeyName); + if (line) { + gint count = 0; + token1[0] = token2[0] = '\0'; + count = RCTokenize(line, tokens, 2, NULL); + if (count < 2) + return val; + val = atoi(token2); + } + return val; +} + +BOOL RCGetBool(const gchar *lpKeyName, BOOL ifFound) +{ + gchar token1[MAX_BUFF], token2[MAX_BUFF]; + gchar *tokens[2]; + gchar *line = NULL; + + tokens[0] = token1; + tokens[1] = token2; + line = RCFindLine(lpKeyName); + if (line) { + gint count = 0; + token1[0] = token2[0] = '\0'; + count = RCTokenize (line, tokens, 2, NULL); + if (count < 2) + return ifFound; + if (strnicmp (token2, "OFF", 3) == 0) + return FALSE; + else + return TRUE; /* ON */ + } + return (ifFound); +} + +BOOL RCGetString(const gchar *lpKeyName, gchar *value, const gchar *defStr, gint maxLen) +{ + gchar token1[MAX_BUFF], token2[MAX_BUFF]; + gchar *tokens[2]; + gchar *line = NULL; + + tokens[0] = token1; + tokens[1] = token2; + strncpy(value, defStr, maxLen); + line = RCFindLine(lpKeyName); + if (line) { + gint count = 0; + token1[0] = token2[0] = '\0'; + count = RCTokenize (line, tokens, 2, NULL); + if (count < 2) + return FALSE; + RCVarExpansion(value, token2); + return TRUE; + } + return FALSE; +} + +void RCVarExpansion(gchar *buffer, const gchar *value) +{ + gint i=0, j=0; + gchar *startDollar, *endDollar; + gchar *string1; + gchar buf[255]; + gchar buf2[255]; + + strcpy(buffer, value); + if (startDollar = strchr(value, '$')) { + if (endDollar = strchr(&startDollar[1], '$')) { + i = strlen(startDollar) - strlen(endDollar) - 1; + j = strlen(value) - strlen(startDollar); + string1 = startDollar; + string1++; + strncpy(buf, string1, i); + buf[i]='\0'; + + RCGetString(buf, buf2, buf, 255); + if (value != startDollar) { + strncpy(buffer, value, j); + buffer[j] = '\0'; + } else { + strcpy(buffer, ""); + } + strcat(buffer, buf2); + strcat(buffer, ++endDollar); + } + } +} + +BOOL RCReadNextLine (FILE *f, gchar *szBuffer, DWORD dwLength) +{ + while (f && !feof (f)) { + gint length; + + if (!fgets(szBuffer, dwLength, f)) + break; + + length = strlen(szBuffer); + + // Skip any leading and trailing whitespace + while (length && isspace(szBuffer[0])) { + length--; + strcpy(szBuffer, szBuffer + 1); + } + + while (length && isspace(szBuffer[length-1])) + szBuffer[--length] = '\0'; + + if (length && szBuffer[0] != '#') + return TRUE; + } + + return FALSE; +} + +BOOL RCInit(const gchar *szPath) +{ + FILE* rc; + gchar buffer[MAX_BUFF]; + + if (RCLen) + return FALSE; + + rc = RCOpen(szPath); + if (!(rc)) + return FALSE; + + while (RCReadNextLine(rc, buffer, sizeof (buffer))) { + gchar *temp; + + if (buffer[0] == '*') + continue; + + temp = g_malloc(strlen(buffer) + 1); + strcpy(temp, buffer); + + if (!RCBuffer) + RCBuffer = g_malloc((RCLen + 1) * sizeof(gchar *)); + else + RCBuffer = g_realloc(RCBuffer, (RCLen + 1) * sizeof(gchar *)); + + RCBuffer[RCLen++] = temp; + } + + return RCClose(rc); +} + +void RCShutDown(void) +{ + gint loop; + + for (loop = 0; loop < RCLen; ++loop) + g_free(RCBuffer[loop]); + + if (RCBuffer) { + g_free(RCBuffer); + RCBuffer = NULL; + } + + RCLen = 0; +} diff --git a/rcfuncs.h b/rcfuncs.h new file mode 100644 index 0000000..7a9f058 --- /dev/null +++ b/rcfuncs.h @@ -0,0 +1,38 @@ +#ifndef _RCFUNCS_H_ +#define _RCFUNCS_H_ + +/* + * rcfuncs - routines to parse generic RC files + * tengel@sonic.net + * + * This is taken from the LiteStep Shell Source code + * (http://www.litestep.net) and modified a bunch to meet + * our RC needs along with using gdk. + * + * This code is distributed under the terms of the GNU + * General Public License, etc etc. Use it, don't abuse it. + * See the file "Copying" for the entire GNU Public + * License policy. +*/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +FILE* RCOpen(const gchar *szFile); +BOOL RCClose(FILE *f); +gint RCTokenize(const gchar *szString, gchar **lpszBuffers, DWORD dwNumBuffers, gchar *szExtraParameters); +gchar* RCFindLine(const gchar *lpKeyName); +gint RCGetInt(const gchar *lpKeyName, gint nDefault); +BOOL RCGetBool(const gchar *lpKeyName, BOOL ifFound); +BOOL RCGetString(const gchar *lpKeyName, gchar *value, const gchar *defStr, gint maxLen); +void RCVarExpansion(gchar *buffer, const gchar *value); +BOOL RCReadNextLine (FILE *f, gchar *szBuffer, DWORD dwLength); +BOOL RCInit(const gchar *szPath); +void RCShutDown(void); + +#ifdef __cplusplus +}; +#endif /* __cplusplus */ + +#endif /* _RCFUNCS_H_ */